BuildGridCells:
PROC [grid: Grid3d] ~ {
xSize: REAL ¬ (grid.box.max.x - grid.box.min.x)/REAL[grid.xRes];
ySize: REAL ¬ (grid.box.max.y - grid.box.min.y)/REAL[grid.yRes];
zSize: REAL ¬ (grid.box.max.z - grid.box.min.z)/REAL[grid.zRes];
min, max: Triple;
FOR x:
INT
IN [0 .. grid.xRes)
DO
min.x ¬ x * xSize;
max.x ¬ min.x + xSize;
FOR y:
INT
IN [0 .. grid.yRes)
DO
min.y ¬ y * ySize;
max.y ¬ min.y + ySize;
FOR z:
INT
IN [0 .. grid.zRes)
DO
cellIndex: INT ¬ GridIndexFromXYZ[grid, x, y, z];
min.z ¬ z * zSize;
max.z ¬ min.z + zSize;
grid.cellData[cellIndex] ¬ NEW[CellDataRep ¬ []];
grid.cellData[cellIndex].box ¬ G3dBox.BoxFromPoints[min, max];
grid.cellData[cellIndex].objects ¬ NIL;
ENDLOOP;
ENDLOOP;
ENDLOOP;
};
BoxCornerSignsDiffer:
PROC [box: Box, plane: Plane]
RETURNS [
BOOL] ~ {
sign0: G3dPlane.Sign ¬ G3dPlane.Side[box.min, plane];
IF sign0 # G3dPlane.Side[[box.min.x, box.max.y, box.min.z], plane] THEN RETURN [TRUE];
IF sign0 # G3dPlane.Side[[box.min.x, box.max.y, box.max.z], plane] THEN RETURN [TRUE];
IF sign0 # G3dPlane.Side[[box.min.x, box.min.y, box.max.z], plane] THEN RETURN [TRUE];
IF sign0 # G3dPlane.Side[[box.max.x, box.min.y, box.min.z], plane] THEN RETURN [TRUE];
IF sign0 # G3dPlane.Side[[box.max.x, box.max.y, box.min.z], plane] THEN RETURN [TRUE];
IF sign0 # G3dPlane.Side[[box.max.x, box.max.y, box.max.z], plane] THEN RETURN [TRUE];
IF sign0 # G3dPlane.Side[[box.max.x, box.min.y, box.max.z], plane] THEN RETURN [TRUE];
RETURN[FALSE];
};