Geom2D.Mesa, from [Ivy]<Spreitzer>Random>Cedar>Geom2D.DF
Last Edited by: Spreitzer, April 16, 1983 1:11 pm
some two dimensional geometry
DIRECTORY
Graphics;
Geom2D: CEDAR DEFINITIONS =
BEGIN
Singularity: SIGNAL;
Number: TYPE = REAL;
Vec: TYPE = RECORD [x, y: Number];
VecList: TYPE = LIST OF Vec;
ZeroVec: Vec = [0, 0];
Line: TYPE = RECORD [from, to: Vec]; --directed line segment
Area: TYPE = Graphics.Box;
AreaList: TYPE = LIST OF Area;
ZeroArea: Area = [0, 0, 0, 0];
Axis: TYPE = {X, Y};
Dir: TYPE = [-1..1];
Direction: TYPE = RECORD [axis: Axis, sgn: Dir];
Transform: TYPE = RECORD [a, b, c, d, e, f: Number];
a b 0
c d 0
e f 1
id: Transform = [1, 0, 0, 1, 0, 0];
posX: Direction = [X, 1];
negX: Direction = [X, -1];
posY: Direction = [Y, 1];
negY: Direction = [Y, -1];
Plus, Minus, Project: PROCEDURE [Vec, Vec] RETURNS [Vec];
Normalize: PROCEDURE [Vec] RETURNS [Vec];
Displace: PROCEDURE [Vec, Area] RETURNS [Area];
Scale: PROCEDURE [Vec, Number] RETURNS [Vec];
Dot: PROCEDURE [Vec, Vec] RETURNS [Number];
Length: PROCEDURE [Vec] RETURNS [Number];
DirectionOf: PROCEDURE [Vec] RETURNS [Direction];
BloatLine: PROCEDURE [Line, Number] RETURNS [Area];
BloatVec: PROCEDURE [Vec, Number] RETURNS [Area];
UnitNormalToward: PROCEDURE [Line, Vec] RETURNS [Vec];
In: PROCEDURE [Vec, Area] RETURNS [BOOLEAN];
SweepBounds: PROCEDURE [Area, Area] RETURNS [Area];
UpdateBounds: PROCEDURE [Area, Area] RETURNS [Area]; --mbb of both--
UpdateFBounds: PROCEDURE [Area, FBounds] RETURNS [FBounds];
Parallel: PROCEDURE [Vec, Vec] RETURNS [BOOLEAN];  --cross product = 0
Translate: PROCEDURE [Transform, Number, Number] RETURNS [Transform];
TranslateV: PROCEDURE [Transform, Vec] RETURNS [Transform];
ScaleT: PROCEDURE [Transform, Number] RETURNS [Transform];
ScaleTXY: PROCEDURE [Transform, Number, Number] RETURNS [Transform];
RotateBy90s: PROCEDURE [Transform, INTEGER] RETURNS [Transform];
counterclockwise
RotateDegrees: PROCEDURE [Transform, Number--degrees--] RETURNS [Transform];
Inverse: PROCEDURE [Transform] RETURNS [Transform];
MapVec: PROCEDURE [Transform, Vec] RETURNS [Vec];
MapVecs: PROCEDURE [Transform, VecList] RETURNS [VecList];
MapArea: PROCEDURE [Transform, Area] RETURNS [Area];
MapAreas: PROCEDURE [Transform, AreaList] RETURNS [AreaList];
Concat: PROCEDURE [Transform, Transform] RETURNS [Transform];
ExtremaRec: TYPE = RECORD [minD, maxD: Number, minV, maxV: Vec];
StartExtreme: PROCEDURE [n, v: Vec] RETURNS [ExtremaRec] = INLINE
{d: Number ← Dot[n, v];
RETURN [[d, d, v, v]]};
Extreme: PROCEDURE [n, v: Vec, e: ExtremaRec]
RETURNS [ExtremaRec] = INLINE
{d: Number ← Dot[n, v];
IF d < e.minD THEN RETURN [[d, e.maxD, v, e.maxV]]
ELSE IF d > e.maxD THEN RETURN [[e.minD, d, e.minV, v]]
ELSE RETURN [e]};
ExtremaOfBounds: PROCEDURE [a: Area, n: Vec] RETURNS [min, max: Vec] = INLINE
{e: ExtremaRec ← n.Extreme[[a.xmin, a.ymin],
n.Extreme[[a.xmin, a.ymax],
n.Extreme[[a.xmax, a.ymin],
n.StartExtreme[[a.xmax, a.ymax]]]]];
RETURN [e.minV, e.maxV]};
FBounds: TYPE = RECORD [defined: BOOLEANFALSE,
area: Area ← ZeroArea];
END.