JunoImage.mesa

Last Hacked by: Jorge Stolfi June 13, 1984 9:00:35 am PDT

Procedures to manipulate and traverse the current Juno image.

DIRECTORY

JunoStorage USING [Point, Coords, Item, 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;

Item: TYPE = Stor.Item;

- - - - 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.

- - - - ITEMS (ACTIONS AND CONSTRAINTS)

AddItem: PROC [item: Item];
Adds the given item to the current image.

- - - - 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/action arguments.

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

EnumItems: PROC [Proc: ItemVisitProc];
Calls Proc for each constraint/action on the image.
Proc should not insert or delete constraints/actions.

ItemVisitProc: TYPE = PROC [item: Item];

EnumItemPoints: PROC [item: Item, Proc: PointVisitProc];
CAlls Proc[p] for each point in arguments of the item.
Proc should not change the constraint/action arguments.

ReplaceItemPoints: PROC [item: Item, Proc: PointReplaceProc];
Replaces p by Proc[p] for each point in arguments of the item.
Proc should not return NIL.
Proc should not change the other constraint/action arguments.

- - - - 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.

ItemIsWound
: PROC [item: Item] RETURNS [wound: BOOL];
Returns TRUE if all points entering into the item 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 constraints/actions to unwound points).
Deletes also all actions and constraints involving only wound points (except graphics state-pushing actions such as set font, set color, etc).
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/action all of whose arguments have been copied, and appends those constraints and actions at the end of the respective lists.
All graphics state-pushing actions are copied, too.
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.