Skip to content

Commit 3f272e6

Browse files
Homer Reidstevengj
authored andcommitted
initial optimization of revised intersect_line_segment_with_prism (#21)
* update point_in_prism to avoid double-counting of polygon edge intersections when plumb lines pass through vertices * revised normal_to_object implementation for prisms to account for in-plane distance from point to prism face when determining closest face * re-updated normal_to_prism to behave correctly when the projection of the point into the plane does not lie within the prism face in question * updates * revise algorithm for intersecting line segment with prism * overhauled intersect_line_segment_with_prism to do the full exact calculation with no approximations or assumptions about proximity * update acquisition of array slices for DFT fields to behave properly in the presence of symmetries (2) * update to intersect_line_segment_with_prism to fix failing unit test * remove memory allocation from intersect_line_segment_with_prism
1 parent e8bfa49 commit 3f272e6

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

utils/geom.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,7 @@ int intersect_line_with_prism(prism *prsm, vector3 p, vector3 d, double *slist)
22812281
/***************************************************************/
22822282
double intersect_line_segment_with_prism(prism *prsm, vector3 p, vector3 d, double a, double b)
22832283
{
2284-
double *slist = (double *)malloc( (2+prsm->vertices.num_items)*sizeof(double) );
2284+
double *slist=prsm->workspace.items;
22852285
int num_intersections=intersect_line_with_prism(prsm, p, d, slist);
22862286

22872287
// na=smallest index such that slist[na] > a
@@ -2292,9 +2292,7 @@ double intersect_line_segment_with_prism(prism *prsm, vector3 p, vector3 d, doub
22922292
na=ns;
22932293

22942294
if (na==-1)
2295-
{ free(slist);
2296-
return 0.0;
2297-
}
2295+
return 0.0;
22982296

22992297
int inside = ( (na%2)==0 ? 0 : 1);
23002298
double last_s=a;
@@ -2306,7 +2304,6 @@ double intersect_line_segment_with_prism(prism *prsm, vector3 p, vector3 d, doub
23062304
inside = (1-inside);
23072305
last_s = this_s;
23082306
}
2309-
free(slist);
23102307
return ds > 0.0 ? ds : 0.0;
23112308
}
23122309

@@ -2577,6 +2574,11 @@ geometric_object make_prism(material_type material,
25772574
for(nv=0; nv<num_vertices; nv++)
25782575
prsm->vertices.items[nv] = prism_coordinate_c2p(prsm,vertices[nv]);
25792576

2577+
// workspace is an internally-stored double-valued array of length num_vertices+2
2578+
// that is used by some geometry routines
2579+
prsm->workspace.num_items = num_vertices+2;
2580+
prsm->workspace.items = (double *)malloc( (num_vertices+2)*sizeof(double) );
2581+
25802582
// note the center and centroid are different!
25812583
vector3 center = vector3_plus(centroid, vector3_scale(0.5*height,zhat) );
25822584
geometric_object o=make_geometric_object(material, center);

utils/geom.scm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
(define-property vertices '() (make-list-type 'vector3))
9494
(define-property centroid (vector3 0 0 0) 'vector3)
9595
(define-property height 0 'number)
96+
(define-property workspace '() (make-list-type 'number))
9697
(define-property m_c2p identity_matrix 'matrix3x3)
9798
(define-property m_p2c identity_matrix 'matrix3x3))
9899

0 commit comments

Comments
 (0)