-- File: SVBoundBox.mesa
-- Last edited by Bier on December 18, 1982 1:15 am
-- Author: Eric Bier on June 23, 1983 2:24 pm
-- Contents: Procedures for creating bounding polyhedra of master objects, and for deriving "3-d" bounding boxes from these polyhedra. Procedures for combining these bounding boxes with union, intersection and difference operators.

DIRECTORY
 CoordSys,
 CSGGraphics,
 Graphics,
 Matrix3d,
 SV2d,
 SVPolygon3d;

SVBoundBox: DEFINITIONS =
BEGIN

Camera: TYPE = CSGGraphics.Camera;
CoordSystem: TYPE = REF CoordSysObj;
CoordSysObj: TYPE = CoordSys.CoordSysObj;
Point2d: TYPE = SV2d.Point2d;
Point3d: TYPE = Matrix3d.Point3d;
Poly3d: TYPE = SVPolygon3d.Poly3d;

BoundHedron: TYPE = REF BoundHedronObj;
BoundHedronObj: TYPE = RECORD [
 len: NAT,
 seq: SEQUENCE maxVerts: NAT OF Point3d];

BoundBox: TYPE = REF BoundBoxObj;
BoundBoxObj: TYPE = RECORD [
 minVert: Point3d, -- min x, y and z makes this lower-left-deep
 maxVert: Point3d]; -- max x, y and z makes this upper-right-shallow

CreateBoundHedron: PROC [len: NAT] RETURNS [bh: BoundHedron];
AddBoundHedronPoint: PROC [bh: BoundHedron, point: Point3d];
AddBoundHedronPoly: PROC [bh: BoundHedron, poly: Poly3d];
RectangularBoundHedron: PROC [sx, sy, sz: REAL] RETURNS [bh: BoundHedron];
-- rectangular parallelpiped centered on the origin with dimensions given
RectangularBoundHedron2: PROC [x1, x2, y1, y2, z1, z2: REAL] RETURNS [bh: BoundHedron];
-- like RectangularBoundHedron but use limits given instead of centering on origin
PyramidBoundHedron: PROC [sx, sy, sz: REAL] RETURNS [bh: BoundHedron];
-- A pyramid with base of size sx by sz on the y=0 plane and tip at [0, sy, 0].
HexagonalBoundHedron: PROC [r, hOver2: REAL] RETURNS [bh: BoundHedron];
-- A vertical hexagonal prism, ie the shape which would be produced by sweeping the hexagon (which circumscribes the circle x^2 + z^2 = r^2) from [0, -h/2, 0] to [0, h/2, 0].
HexPyramidBoundHedron: PROC [r, h: REAL] RETURNS [bh: BoundHedron];
-- A pyramid having a hexagonal base of inner radius r on the y = 0 plane (centered on [0,0,]) and having tip at [0, h, 0]
GeneralConeBoundHedron: PROC [r1, h1, r2, h2: REAL] RETURNS [bh: BoundHedron];
-- Bounds a cone slice (cone around y axis) with radius r1 at y=h1 and radius r2 at y = h2. Currently uses two hexagons. Octagons may follow.
DiskBoundHedron: PROC [r, h: REAL] RETURNS [bh: BoundHedron];
-- Bounds a disk (centered on y axis) with radius r at y = h;
ClearBoundHedron: PROC [bh: BoundHedron];
DrawBoundHedron: PROC [dc: Graphics.Context, bh: BoundHedron, localWRTWorld: CoordSystem, camera: Camera, screen: CoordSystem];

BoundBoxFromBoundHedron: PROC [bh: BoundHedron, camera: Camera, localCS: CoordSystem] RETURNS [boundBox: BoundBox];
BoundBoxFromValues: PROC [minX, minY, maxX, maxY: REAL] RETURNS [boundBox: BoundBox];
PointInBoundBox: PROC [cameraPoint: Point2d, boundBox: BoundBox] RETURNS [BOOL];
UnionCombineBoundBoxes: PROC [bb1, bb2: BoundBox] RETURNS [newBB: BoundBox];
IntersectionCombineBoundBoxes: PROC [bb1, bb2: BoundBox] RETURNS [newBB: BoundBox];
DifferenceCombineBoundBoxes: PROC [bb1, bb2: BoundBox] RETURNS [newBB: BoundBox];
DrawBoundBox: PROC [dc: Graphics.Context, boundBox: BoundBox, screen: CoordSystem];
ComplementBoundBox: PROC [dc: Graphics.Context, boundBox: BoundBox, screen: CoordSystem];

END.