convert line ends
[canaan.git] / prj / cam / src / csg / csgbbox.c
blob63bc31d5d3785ea66bfc3c76432dbaf02899e07f
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
7 #include <lg.h>
8 #include <csg.h>
9 #include <bspdata.h>
10 #include <csgutil.h>
11 #include <csgbbox.h>
12 #include <memall.h>
13 #include <dbmem.h> // must be last header!
15 void compute_ph_bounds_init(BspVertex *minv, BspVertex *maxv)
17 minv->x = minv->y = minv->z = 1e20;
18 maxv->x = maxv->y = maxv->z = -1e20;
21 void compute_ph_bounds_more(PortalPolygon *poly, BspVertex *minv, BspVertex *maxv)
23 PortalPolyEdge *edge = poly->edge, *first = edge;
24 do {
25 if (edge->data->start.x < minv->x) minv->x = edge->data->start.x;
26 if (edge->data-> end.x < minv->x) minv->x = edge->data->end.x;
27 if (edge->data->start.x > maxv->x) maxv->x = edge->data->start.x;
28 if (edge->data-> end.x > maxv->x) maxv->x = edge->data->end.x;
30 if (edge->data->start.y < minv->y) minv->y = edge->data->start.y;
31 if (edge->data-> end.y < minv->y) minv->y = edge->data->end.y;
32 if (edge->data->start.y > maxv->y) maxv->y = edge->data->start.y;
33 if (edge->data-> end.y > maxv->y) maxv->y = edge->data->end.y;
35 if (edge->data->start.z < minv->z) minv->z = edge->data->start.z;
36 if (edge->data-> end.z < minv->z) minv->z = edge->data->end.z;
37 if (edge->data->start.z > maxv->z) maxv->z = edge->data->start.z;
38 if (edge->data-> end.z > maxv->z) maxv->z = edge->data->end.z;
40 edge = edge->poly_next;
41 } while (edge != first);
44 void compute_poly_bbox(PortalPolygon *poly, BspVertex *minv, BspVertex *maxv)
46 compute_ph_bounds_init(minv, maxv);
47 compute_ph_bounds_more(poly, minv, maxv);
50 void compute_ph_bbox(PortalPolyhedron *ph, BspVertex *minv, BspVertex *maxv)
52 PortalPolygon *p = ph->poly;
53 compute_ph_bounds_init(minv, maxv);
54 do {
55 compute_ph_bounds_more(p, minv, maxv);
56 p = GetPhNext(p, ph);
57 } while (p != ph->poly);