JunoImage.mesa

Last Hacked by: Jorge Stolfi June 4, 1984 11:57:29 pm PDT

Procedures to manipulate and traverse the current Juno image.

DIRECTORY

JunoStorage USING [Point, Coords, Action, Constr, IntCoords],
JunoOldSolver USING [Outcome];

JunoImage: DEFINITIONS

=

BEGIN

OPEN

Stor: JunoStorage,
Solv: JunoOldSolver;

- - - - IMPORTED TYPES

Point: TYPE = Stor.Point;

Coords: TYPE = Stor.Coords;

IntCoords: TYPE = Stor.IntCoords;

Action: TYPE = Stor.Action;

Constr: TYPE = Stor.Constr;

- - - - THE CURRENT IMAGE

The current image consists of a list of points, and a list of constraints and a list of actions involving those points.

PurgeImage: PROC;
Discards and reclaims all points, actions and constraints in the current image

- - - - IMAGE POINTS

AddPoint: PROC [p: Point];
Adds p to the current image.

RemovePoint: PROC [p: Point];
Removes the point from the image and reclaims it.
Assumes it does not occur in any constraint or action.

SortPoints: PUBLIC PROC;
Sorts the points from left to right.
Is automatically called by SolveImage, and is not necessary after inserting a new point, but must be called explicitly after other changes to the coordinates of existing points.

- - - - CONSTRAINTS

AddConstr: PROC [c: Constr];
Adds the given constraint to the curren image.

- - - - ACTIONS

AddAction: PROC [a: Action];
Allocates new action and appends it to the image actions.
If doIt=TRUE, also executes the action.

- - - - ELEMENT ENUMERATION

EnumPoints: PROC [Proc: PointVisitProc];
Calls Proc for all point on the image.
Proc should not insert or delete points.

PointVisitProc: TYPE = PROC [p: Point];

ReplacePoints: PROC [Proc: PointReplaceProc];
Replaces p by Proc[p] for each point in image.
If Proc[p] = NIL, deletes and reclaims point.
Proc should not change the other constraint arguments.

PointReplaceProc: TYPE = PROC [p: Point] RETURNS [pNew: Point];

EnumConstrs: PROC [Proc: ConstrVisitProc];
Calls Proc for each constraint on the image.
Proc should not insert or delete constraints.

ConstrVisitProc: TYPE = PROC [c: Constr];

EnumConstrPoints: PROC [c: Constr, Proc: PointVisitProc];
CAlls Proc[p] for each point in arguments of the c.
Proc should not change the constraint arguments.

ReplaceConstrPoints: PROC [c: Constr, Proc: PointReplaceProc];
Replaces p by Proc[p] for each point in arguments of the c.
Proc should not return NIL.
Proc should not change the other constraint arguments.

EnumActions: PROC [Proc: ActionVisitProc];
Calls Proc for each action on the image.
Proc should not insert or delete actions.

ActionVisitProc: TYPE = PROC [a: Action];

EnumActionPoints: PROC [a: Action, Proc: PointVisitProc];
Calls PointVisitProc for each point in the arguments of the action.
Proc should not insert affect any arguments of a.

ReplaceActionPoints: PROC [a: Action, Proc: PointReplaceProc];
Replaces p by Proc[p] for each point in the arguments of the action.
Proc should not return NIL.
Proc should not affect any other arguments of a.

- - - - POINT LOCATION

FindPoint
: PROC [coords: Coords, wound: BOOLFALSE] RETURNS [champ: Point];
This procedure finds the point closest to x, y in the current image.
If wound=TRUE then considers only points with non-zero winding number

- - - - BALOON SELECTION

BaloonSelect: PROC [start: IntCoords, NextPoint: NextPointProc];
The effect of BaloonSelect is to collect the vertices of a polygon (starting with xS, yS and continuing as specified by the NextPoint procedure), and set the wn (winding number) field for all image points contained in the polygon.
The NextPoint procedure should return lastPoint = TRUE if coords is the last point. (BaloonSelect will close the polygon automatically)

NextPointProc: TYPE = PROC RETURNS [coords: IntCoords, lastPoint: BOOL];

AnyWoundPoints: PROC RETURNS [BOOL];
Returns TRUE if there are any points in the image with nonzero winding number.

ConstrIsWound
: PROC [c: Constr] RETURNS [wound: BOOL];
Returns TRUE if all points entering into the constraint c have wn # 0.

ActionIsWound
: PROC [a: Action] RETURNS [wound: BOOL];
Returns TRUE if all points athat are arguments to the action a have wn # 0.

UnwindAllPoints
: PROC;
Sets p.wn=0 for all points p in the image.

- - - - OPERATIONS ON BALOON-SELECTED POINTS

DeleteWoundItems
: PROC;
Deletes all points with wn # 0 (unless connected by actions/constraints to unwound points).
Deletes also all actions and constraints involving only wound points.
After the call all points have wn=0.

DuplicateWoundItems
: PROC;
Creates a new copy of every point p with p.wn#0. Also creates a new copy of any constraint all of whose arguments have been copied.
After the call every copied point has p.copy pointing to its copy, p.wn set to zero, and
p.copy.wn set to the original p.wn.

- - - - POINT IDENTIFICATION

IdentifyPoints
: PROC;
For every point p such that p.copy#NIL, replaces p by p.copy in all constraints and actions.
Also sets p.copy ← NIL for all points p in the image

- - - - CONSTRAINT SOLVING

SolveImage: PROC [eps: REAL] RETURNS [outcome: Solv.Outcome];

Solves the image constraints for all image points that have p.fixed=FALSE.

Reorders the points according to their new coordinates.

Does NOT refresh the image on the screen.

END.

- - - - JUNK

AddNewVer: PROC [i,j: Point];

AddNewPara: PROC [i,j,k,l: Point];

AddNewPerp: PROC [i,j,k,l: Point];

AddNewCong: PROC [i,j,k,l: Point];

AddNewAt: PROC [p: Point, x, y: REAL];

AddNewCcw: PROC [i,j,k: Point];

ConstrPtr: TYPE = REF ConstrRec; -- to some kind of constraint record

ConstrList: TYPE = REF ConstrPtr; -- linked by link field.

NewHor: PROC [i,j: Point] RETURNS [ap: ApplPtr];

NewVer: PROC [i,j: Point] RETURNS [ap: ApplPtr];

NewPara: PROC [i,j,k,l: Point] RETURNS [ap: ApplPtr];

NewPerp: PROC [i,j,k,l: Point] RETURNS [ap: ApplPtr];

NewCong: PROC [i,j,k,l: Point] RETURNS [ap: ApplPtr];

NewAt: PROC [p: Point, x, y: REAL] RETURNS [ap: ApplPtr];

NewCcw: PROC [i,j,k: Point] RETURNS [ap: ApplPtr];

DeleteConstr: PROC [c, cAnt: ConstrPtr, list: ConstrList] RETURNS [newList: ConstrList];
Deletes the constraint c from the list. If cAnt is not NIL, it should be the previous constraint in list.

InsertConstr: PROC [c, cAnt: ConstrPtr, list: ConstrList] RETURNS [newList: ConstrList];
Inserts the constraint c into the list, just after cAnt (if cAnt=NIL inserts at beginning)

GcConstr: PROC[pf, pl: ConstrList];
Garbage-collects all elements in the list starting with pf and ending with pl.

ActionPtr: TYPE = REF ActionRec; -- to some kind of action record

ActionList: TYPE = RECORD
[first, last: ActionPtr]; -- linked by link field in chronological (painting) order.;

ActionRec: TYPE = RECORD
[link: ActionPtr,
op: ATOM, -- operation (usually atom, the function name)
larg, rarg: Alg.Value ← NIL -- left- and right-arguments
];

NewAction: PROC [op: Alg.Se, arg: Alg.Value] RETURNS [ap: ActionPtr];

DeleteAction: PROC [a, aAnt: ActionPtr, list: ActionList] RETURNS [newList: ActionList];
Deletes the action a from the list. If aAnt is not NIL, it should be the previous action in list.

InsertAction: PROC [a, aAnt: ActionPtr, list: ActionList] RETURNS [newList: ActionList];
Inserts the action a into the list, just after aAnt (if aAnt=NIL inserts at beginning)

GcAction: PROC[af, al: ActionPtr];
Garbage-collects all elements in the list starting with a and ending with al.