-- COGCartImpl.mesa: Basic geometrical operations in Cartesian coordinates (implem.)
-- last modified by Stolfi - September 20, 1982 7:27 pm
-- To do: use a better random number generator
DIRECTORY
COGCart;
COGCartImpl: CEDAR PROGRAM
IMPORTS COGCart
EXPORTS COGCart
= BEGIN OPEN COGCart;
Convex: PUBLIC PROC [a, b, c: Point] RETURNS [BOOLEAN] =
{RETURN [PositiveAngle[Sub[c, b], Sub[b, a]]]};
Bisector: PUBLIC PROC [a, b: Point] RETURNS [Line] =
{v: Vector = Sub [a,b];
RETURN [[-v.y, v.x, -a.x*b.y+b.x*a.y]]};
Intercept: PUBLIC PROC [r, s: Line] RETURNS [Point] =
{-- check for parallels!
det: REAL = r.a*s.b-s.a*r.b;
RETURN [[(s.b*r.c-r.b*s.c)/det, (r.a*s.c-s.a*r.c)/det]]};
CircumCenter: PUBLIC PROC [a, b, c: Point] RETURNS [Vector] =
{-- check for colinearity!
RETURN [Intercept[Bisector[a, b], Bisector[b, c]]]};
BoxToBoxScale: PUBLIC PROC [bo, bd: Box, mf: REAL ← 0.1] RETURNS [sf: ScaleFactors] =
{s: REAL = (1.0-2.0*mf)* MIN
[(bd.max.x-bd.min.x)/(bo.max.x-bo.min.x),
(bd.max.y-bd.min.y)/(bo.max.y-bo.min.y)];
bdcenx: REAL = (bd.max.x+bd.min.x)/2.0; -- center of bd
bdceny: REAL = (bd.max.y+bd.min.y)/2.0;
bocenx: REAL = (bo.max.x+bo.min.x)/2.0; -- center of bo
boceny: REAL = (bo.max.y+bo.min.y)/2.0;
sf.sx ← sf.sy ← s;
sf.tx ← bdcenx-bocenx*s; sf.ty ← bdceny-boceny*s};
END.