Skip to content

Commit 232fcb9

Browse files
Homer Reidstevengj
authored andcommitted
fixed incorrect computation of prism bounding box (#17)
1 parent 8690355 commit 232fcb9

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

utils/geom.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,25 +2108,22 @@ void get_prism_bounding_box(prism *prsm, geom_box *box)
21082108
int num_vertices = prsm->vertices.num_items;
21092109
double height = prsm->height;
21102110

2111-
// set x,y coordinates of low, high to bounding box
2112-
// of prism base polygon (in prism coordinate system)
2113-
vector3 low=vertices[0], high=vertices[0];
2114-
int nv;
2115-
for(nv=1; nv<num_vertices; nv++)
2116-
{ low.x = fmin(low.x, vertices[nv].x);
2117-
low.y = fmin(low.y, vertices[nv].y);
2118-
high.x = fmax(high.x, vertices[nv].x);
2119-
high.y = fmax(high.y, vertices[nv].y);
2120-
};
2121-
2122-
// set z coordinates of low, high to upper and lower
2123-
// prism surfaces (in prism coordinate system)
2124-
low.z = 0.0;
2125-
high.z = height;
2126-
2127-
// convert from prism coordinates to cartesian coordinates
2128-
box->low = prism_coordinate_p2c(prsm, low);
2129-
box->high = prism_coordinate_p2c(prsm, high);
2111+
box->low = box->high = prism_coordinate_p2c(prsm, vertices[0]);
2112+
int nv, fc;
2113+
for(nv=0; nv<num_vertices; nv++)
2114+
for(fc=0; fc<2; fc++) // 'floor,ceiling'
2115+
{ vector3 vp = vertices[nv];
2116+
if (fc==1) vp.z=height;
2117+
vector3 vc = prism_coordinate_p2c(prsm, vp);
2118+
2119+
box->low.x = fmin(box->low.x, vc.x);
2120+
box->low.y = fmin(box->low.y, vc.y);
2121+
box->low.z = fmin(box->low.z, vc.z);
2122+
2123+
box->high.x = fmax(box->high.x, vc.x);
2124+
box->high.y = fmax(box->high.y, vc.y);
2125+
box->high.z = fmax(box->high.z, vc.z);
2126+
}
21302127
}
21312128

21322129
/***************************************************************/

0 commit comments

Comments
 (0)