File: SVPolygon2d.mesa
Last edited by Bier on June 1, 1984 4:47:15 pm PDT
Author: Eric Bier on June 26, 1984 11:17:23 am PDT
Contents: Routines for creating, manipulating, and playing with polygons. Part of the SolidViews package.
DIRECTORY
SV2d;
SVPolygon2d: DEFINITIONS =
BEGIN
Point2d: TYPE = SV2d.Point2d;
Polygon: TYPE = REF PolygonObj;
PolygonObj: TYPE = SV2d.PolygonObj;
Path: TYPE = REF PathObj;
PathObj: TYPE = SV2d.PathObj;
TrigPolygon: TYPE = REF TrigPolygonObj;
TrigPolygonObj: TYPE = SV2d.TrigPolygonObj;
POLYGONS
CreatePoly: PROC [len: NAT] RETURNS [poly: Polygon];
CopyPoly: PROC [poly: Polygon] RETURNS [copy: Polygon];
CircumHexagon: PROC [r: REAL] RETURNS [hex: Polygon];
Creates a hexigon which circumscribes the circle whose center is on the origin and whose radius is r.
ClearPoly: PROC [poly: Polygon];
AddPolyPoint: PROC [poly: Polygon, point: Point2d] RETURNS [polyPlusPoint: Polygon];
PutPolyPoint: PROC [poly: Polygon, index: NAT, point: Point2d] RETURNS [newPoly: Polygon];
IsClockwisePoly: PROC [poly: Polygon] RETURNS [BOOL];
InvertPoly: PROC [poly: Polygon] RETURNS [ylop: Polygon];
From clockwise to counter-clockwise or vice-versa
InvertPolyInPlace: PROC [poly: Polygon];
PartPolyGetsPartPath: PROC [fromPath: Path, fromStart: NAT, toPoly: Polygon, toStart: NAT, duration: NAT] RETURNS [newPoly: Polygon];
toPoly in range [toStart..toStart+duration-1] gets
fromPath in range [fromStart..fromStart+duration-1];
PartPolyGetsPartPoly: PROC [fromPoly: Polygon, fromStart: NAT, toPoly: Polygon, toStart: NAT, duration: NAT] RETURNS [newPoly: Polygon];
toPoly in range [toStart..toStart+duration-1] gets
fromPoly in range [fromStart..fromStart+duration-1];
PathToPolygon: PROC [path: Path] RETURNS [poly: Polygon];
TRIG POLYGONS (a richer [and slower] structure)
PolygonToTrigPolygon: PROC [poly: Polygon] RETURNS [trigPoly: TrigPolygon];
PATHS (open version of a polygon)
CreatePath: PROC [len: NAT] RETURNS [path: Path];
CopyPath: PROC [path: Path] RETURNS [copy: Path];
ClearPath: PROC [path: Path];
AddPathPoint: PROC [path: Path, point: Point2d] RETURNS [pathPlusPoint: Path];
InsertPathPoint: PROC [path: Path, point: Point2d] RETURNS [newPath: Path];
SplicePathPoint: PROC [path: Path, point: Point2d, index: INTEGER] RETURNS [newPath: Path];
AttemptToSplicePastEndOfPath: ERROR;
DeletePathPoint: PROC [path: Path, index: NAT] RETURNS [newPath: Path];
PutPathPoint: PROC [path: Path, index: NAT, point: Point2d];
ConcatPath: PROC [path1, path2: Path] RETURNS [cat: Path];
SubPath: PROC [path: Path, lo, hi: NAT] RETURNS [subpath: Path];
SubPathOfPoly: PROC [poly: Polygon, lo, hi: NAT] RETURNS [subpath: Path];
ShiftUpPath: PROC [path: Path, startAt: NAT, by: NAT];
ShiftDownPath: PROC [path: Path, startAt: NAT, by: NAT];
startAt the index of the highest element which should be shifted down. Must be greater than zero.
ShiftingDataOffLeftEnd: ERROR;
ShiftingDownNonExistentElements: ERROR;
PolygonToPath: PROC [poly: Polygon] RETURNS [path: Path];
PartPathGetsPartPath: PROC [fromPath: Path, fromStart: NAT, toPath: Path, toStart: NAT, duration: NAT] RETURNS [newPath: Path];
toPath in range [toStart..toStart+duration-1] gets fromPath in range [fromStart..fromStart+duration-1]; fromPath gets result.
PointPolyClass: TYPE = {in, on, out};
DifferenceAngles: PROC [c, v: REAL] RETURNS [cMinusV: REAL];
c and v must be angles in the range -180 < theta <= 180.
dt will be in the rangle -180< dt <= 180.
we always choose the shortest way around the circle from v to c.
CirclePointInPoly: PROC [point: Point2d, poly: Polygon] RETURNS [class: PointPolyClass];
SquarePointInPoly: PROC [point: Point2d, poly: Polygon] RETURNS [class: PointPolyClass];
BoysePointInPoly: PROC [point: Point2d, poly: Polygon] RETURNS [class: PointPolyClass];
SignedArea: PROC [poly: Polygon] RETURNS [area: REAL];
ClockwisePerimeterAroundUnitSquare: PROC [from, to: Point2d] RETURNS [perim: REAL];
END.