JunoStorage.mesa

Coded June 81 by Greg Nelson.
Last edited by GNelson(?) September 14, 1982 4:38 pm
Last edited by Stolfi June 13, 1984 9:51:09 am PDT

Definitions of record types for (image points and expanded constraints/actions) used by JunoTop (via JunoImage, JunoAlgebra, and JunoOldSolver). Also allocation and deallocation procedures.

This module is logically superfluous. A cleaner idea woud be to keep only the x,y and solver stuff in the point records, and not have constraints and action records at all. The points of the current image chould be kept in an a-list, with the frozen and winding number stuff kept separately; the actions and constraints shuld be kept as symbolic expressions (see JunoAlgebra). However, that would require too much allocation.deallocation/narrowing, and might slow down Juno significantly.

DIRECTORY

Imager USING [Pair];

JunoStorage: DEFINITIONS =

BEGIN

- - - - COORDINATES

Coords: TYPE = Imager.Pair; -- RECORD[x, y: REAL]
Coordinates of a point in the Juno system (big points from lower left corner of picture)

IntCoords: TYPE = RECORD [x, y: INTEGER];
Coordinates of a point in the Juno system (big points from lower left corner of picture), rounded to nearest integer for efficiency reasons. (Are they worthwhile?)

- - - - POINTS

Point: TYPE = REF PointRec;

PointList: TYPE = RECORD [first, last: REF PointRec];
Connected by link field; last.link always NIL. Both NIL if list is empty.

PointRec: TYPE = RECORD

[coords: Coords ← [0, 0], -- coordinates of point.
frozen: BOOLFALSE, -- p was frozen by user.
visible: BOOLFALSE, -- false for control points of strings
link: Point, -- next point in list
-- Input/output data for JunoImage, JunoOldSolver and JunoBody:
wn: INTEGER ← 0, -- winding number (#0 for blue-selected points)
copy: Point ← NIL, -- copy of point, or target in point identification.
name: ATOMNIL, -- used when building procedures
fixed: BOOLFALSE, -- TRUE = don't solve for/don't locally declare this point.
-- Temporary mark used internally in JunoImage, JunoBody, JunoOldSolver:
mark: BOOLFALSE, -- general-purpose mark bit
-- Temporary data used only by JunoOldSolver:
xCol, yCol: INTEGER ← 0, -- columns corresp. to each coordinate in tableau
old: Coords ← [0, 0] -- round values of x, y in previous iteration.
];

NewPoint: PROC [coords: Coords, visible: BOOLFALSE] RETURNS [p: Point];
Creates a new point record (allocates from pool if available).
Sets the visible flag as specified, but does not paint p on the screen.

DeletePoint: PROC [p, ant: Point, list: PointList] RETURNS [newList: PointList];
Deletes the point p from the list. The parameter ant is optional; if not NIL, it must be that ant.link = p.

InsertPoint: PROC [p, ant: Point, list: PointList] RETURNS [newList: PointList];
Inserts the point p into the list, just after ant (if ant=NIL inserts at beginning)

GcPoints: PROC[start: Point, lim: Point ← NIL];
Returns to the pool all point records from start (incl.) to lim (excl).

- - - - REFERENCE FRAMES

Frame: TYPE = RECORD [org, hor, ver: Point]; -- reference frame for constraints & c

nullFrame: Frame = [NIL, NIL, NIL]; -- null reference frame

- - - - ITEMS (CONSTRAINTS AND ACTIONS)

Item: TYPE = REF ItemRec; -- to a constraint or action record

ItemKind: TYPE =

{hor, ver, para, perp, cong, at, ccw, -- constraints
draw, print, call, -- proper actions
font, size, face, justified, paint, width}; -- state-pushing actions

ConstrKind: TYPE = ItemKind[hor..ccw];
ActionKind: TYPE = ItemKind[draw..width];
ProperActionKind: TYPE = ItemKind[draw..call];
StatePushingActionKind: TYPE = ItemKind[font..width];

ItemList: TYPE = RECORD [first, last: Item];
Connected by link field; last.link always NIL. Both NIL if list is empty.

ItemRec: TYPE = RECORD

[link: Item,
kind: ItemKind,
frame: Frame ← [NIL, NIL, NIL], -- reference frame for constraints (and actions?)
args: ItemArgs -- action and constraint arguments
];

ItemArgs: TYPE = LIST OF REF ANY; -- arguments of constraints and actions:

hor: [i, j: Point] -- (i,j) horizontal
ver: [i, j: Point] -- (i,j) vertical
para: [i, j, k, l: Point] -- (i,j) parallel to (k,l)
perp: [i, j, k, l: Point] -- (i,j) perpendicular to (k,l)
cong: [i, j, k, l: Point] -- (i,j) congruent to (k,l)
at: [p: Point, x, y: REF REAL] -- p at (x,y) (relative to the given frame)
ccw: [i, j, k: Point] -- (i,j,k) to be counterclockwise (rel to frame)

draw: [p, q: Point] or [p, r, s, q: Point]
print: [p: Point, rope: ROPE]
call: [func: ATOM, p1, p2, ..., pn: Point] (where func is function name)

font: [font: ROPE]
size: [size: REF INT]
face: [face: ATOM] (one of $regular, $bold, $italic, $boldItalic)
paint: [color: ATOM] (one of $black, $white, $gray, $red, $orange, etc.)
width: [width: REF REAL]
justified: [justification: ATOM] (one of $left, $center, $right)

NewItem
: PROC [kind: ItemKind, args: ItemArgs, frame: Frame ← nullFrame]
RETURNS [item: Item];
Creates a new item record (allocates from pool if available).

DeleteItem
: PROC [item, ant: Item, list: ItemList] RETURNS [newList: ItemList];
Deletes the item from the list. The parameter ant is optional; if not NIL, it must be that ant.link = item.

InsertItem
: PROC [item, ant: Item, list: ItemList] RETURNS [newList: ItemList];
Inserts the item into the list, just after ant (if ant=NIL inserts at beginning)

GcItems: PROC[start: Item, lim: Item ← NIL];
Returns to the pool all item records from start (incl.) to lim (excl).
Also collects the top-level cells in the args list of each item.

- - - - LISTS

List: TYPE = LIST OF REF ANY;

Cons: PROC [first: REF ANY, rest: List] RETURNS [cons: List];
Same as built-in CONS, but allocates from pool if available.

GcList: PROC[start: List, lim: List ← NIL];
Returns to the pool all top-level cells in the list, from start (incl) to lim (excl).

END.