DIRECTORY Rope, HerculesStorage, HerculesAlgebra USING[Frame, Matrix]; HerculesImage: DEFINITIONS = BEGIN OPEN HerculesStorage, Alg: HerculesAlgebra; image: Image; -- The current image AddPoint: PROC [p: PointPtr]; -- Adds the given point to the image, in proper x-order SortPoints: PROC; -- Sorts list of points points by increasing x-coordinate. -- Useful after moves and constraint solving. AddConstr: PROC [c: ConstrPtr]; -- Adds the given constraint to the image. AddAction: PROC [a: ActionPtr]; -- Adds the given action to the image (in chronological order). PushImage: PROC; -- saves current image (i.e., its points, constraints, and actions) and makes it empty PopImage: PROC; -- restores last saved image PurgeImage: PROC; -- makes current image to be empty PointOp: TYPE = PROC [p, pAnt: PointPtr]; EnumeratePoints: PROC [Op: PointOp]; ConstrOp: TYPE = PROC [c, cAnt: ConstrPtr]; EnumerateConstrs: PROC [Op: ConstrOp]; ActionOp: TYPE = PROC [a, aAnt: ActionPtr]; EnumerateActions: PROC [Op: ActionOp]; FindPoint: PROC [x, y: REAL, wound: BOOL _ FALSE] RETURNS [champ: PointPtr]; -- 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. NextPointProc: TYPE = PROC RETURNS [x, y: INTEGER, lastPoint: BOOL]; BaloonSelect: PROC [xS, yS: INTEGER, 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 x, y is the last point. -- (BaloonSelect will close the polygon automatically) AnyWoundPoints: PROC RETURNS [BOOL]; -- Returns TRUE if there are any points in the image with nonzero winding number. ConstrIsWound: PROC [c: ConstrPtr] RETURNS [wound: BOOL]; -- Returns TRUE if all points entering into the constraint c have wn # 0. ActionIsWound: PROC [a: ActionPtr] 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. 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. TransformWoundPoints: PROC[mat: REF Alg.Matrix]; -- Applies the given transformation to all points p with p.wn#0. MoveWoundPoints: PROC [source, dest: Alg.Frame] RETURNS [singular: BOOL]; -- This procedure assumes source and dest are frames with same number of points. It -- (a) computes a transform that takes the source frame to the destination frame, -- (b) applies the transform to all points with wn#0, and -- (c) identifies the source points with the dest points (i.e. replaces the former by the latter -- in all constraints and actions of the current image). -- This procedure assumes all copy links are NIL on entry, all points in the source frame -- have wn#0, and all points in the dest frame have wn=0. -- It returns singular = TRUE if the source frame is degenerate. CopyWoundItems: 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. IdentifyPoints: PROC; -- For every point p such that p.copy#NIL, replaces p by p.copy -- in all constraints and actions. Then sets -- Also sets p.copy _ NIL for all points p in the image END. úHerculesImage.mesa (pieces of JunoStorage.mesa), coded June 81 by Greg Nelson. The current (unnamed) image and related procedures Last Edited by: GNelson, September 14, 1982 4: 38 pm Last Edited by: Stolfi, February 22, 1984 5:49 am - - - - THE CURRENT IMAGE - - - - IMAGE SAVE AND RESTORE - - - - IMAGE ELEMENT ENUMERATION The following procedures are useful for scanning the list of points, constraints or actions of the current image. EnumerateXXX (where XXX is Points, Constrs, or Actions) takes as an argument a XXXOp procedure that does the required operation on a given object. The XXXOp procedure is given both the object and the one before it on the corresponding list, so it can efficiently delete the given element, or insert new ones just before or after it, by calling DeleteXXX or InsertXXX. EnumerateXXX is smart enough to not get confused by deletions and insertions: each element in the ORIGINAL list is visited once, and new elements inserted during the enumeration are NOT visited. However, the XXXOp procedure should NOT use AddXXX. - - - - POINT LOCATION - - - - BALOON SELECTION - - - - OPERATIONS ON BALOON-SELECTED ITEMS Edited on February 4, 1984 4:23 am, by Stolfi changes to: imagePoints, imageConstraints, imageActions, procedures (replace pointLpad, pointRpad, itemLpad, itemRpad, lambdaAlist), AddPoint, AddHor, AddVer, AddPara, AddPerp, AddCong, AddAt, AddCcw, AddEdge, AddArc, AddString, AddAppl (argument changes), HasDef (deleted (never defined?)), AddDef (replaced by AddProcDef; parameter change), GetBody, GetLocals (replaced by GetProcDef), PushImage, PopImage, PurgeImage (replace PushState, PopState, ResetJunoStorage), InsertPoint, SortPoints (moved here from JunoBody), AddPoint (added visible parameter) Edited on February 6, 1984 7:19 pm, by Stolfi changes to: image, procedures (replace imagePoints, imageConstraints, imageActions; made readonly), AddConstr, AddAction (new - replace AddHor, AddVer, AddPara, AddPerp, AddCong, AddAt, AddCcw, AddEdge, AddArc, AddString, AddAppl), AddPoint (requires point to be created outside), ConstrOp, EnumerateConstrs, ActionOp, EnumerateActions, (copyed from ItemOperation, EnumerateItems of JunoBody, split in two), PointOp, EnumeratePoints (new), InsertPoint, DeletePoint, DeleteConstr, InsertConstr, DeleteAction, InsertAction (new), DeleteWoundItems, TransformWoundPoints, CopyWoundItems, IdentifyPoints (replace Delete, TransformPoints, Copy, Identify of old JunoBody), ConstrIsWound, ActionIsWound (new) Edited on February 8, 1984 6:11 pm, by Stolfi changes to: MoveWoundPoints (new - part of MovePointsInBaloon from HerculesTop), GetProcDef (replaced by GetDef of HerculesStorage), AddPoint, SortPoints, DeletePoint, InsertPoint, AddConstr, DeleteConstr, InsertConstr, AddAction, DeleteAction, InsertAction, Image (moved to HerculesStorage), procedures (type is Alist), AddPoint, SortPoints, AddConstr, AddAction (deleted list parameter and result, now operate only on current image), Lambda (new), AddProcDef (parm change, alist format change), Ê ˜JšœN™NJ™Jšœ4™4Jšœ5™5J™2JšÏk œG˜PJšœ œ˜Jšœœ(˜2J™JšœÏc˜$JšÏnœœž7˜WJ˜JšŸ œœžk˜~Jšœ˜JšŸ œœž*˜JJ˜JšŸ œœž?˜_J˜J™JšŸ œœžWœ˜kJšŸœœžœ˜1JšŸ œœž#œ˜8™"Jš œrÏr œ œ œ œ œ?™…Jšœ œ¼ œ œ™ÝJš  œÊ œ œ ™û—JšŸœœœ˜+JšŸœœ˜$J˜JšÏbœœœ˜-JšŸœœ˜&J˜JšŸœœœ˜-JšŸœœ˜&J˜J™JšŸ œœœ œœœžPœž>˜ãJ˜J™Jš Ÿ œ œœœ œ˜EJšŸ œœ œ!žœ žkÐcr ž" žOœž ¢ žœ ž"œž¢ ž&œ˜àJš ŸœœœœžT˜yJ˜J™,Jš Ðbn œœœ œž;¢ž¢ž˜†J˜Jš £ œœœ œž@¢ž¢ž˜ˆJ˜Jš Ÿœœž¢ž¢žœ˜IJš Ÿœœž¢ž­¢žœ˜ìJš Ÿœœœž2¢ž¢žœ˜uJšŸœœœ œž¬œž¹¢ž¢ž¢ž ¢žGœ˜ËJšŸœœž%¢ž¢žƒ¢ž¢ž¢ ž¢žœ˜«JšŸœœž¢ž¢ž¢ž>œž¢žœ˜ÁJšœ˜J™™-JšAœ   œ œ  œ  œ   œ  œ œ œ  œ œ œ œ œ œ œ œ œ œ œ  œ œ8 œ  œ œ  œ  œ  œ œ  œ   œ œ œY™«—J˜™-JšSœ  œ  œ   œ œ  œ *œ œ œ œ œ œ œ œ œ  œ œ œ) œ œ œ œ  œ œ œ œ  œ  œ  œ  œ  œ  œ œ œ œ œ  œ œ œ œ  œ  œ™½—J™™-Jš5œ  œ œ  œ  œ œ œ œ  œ  œ  œ  œ  œ  œ  œ  œ  œ œ  œ  œ  œ œ  œ  œ  œI œ  œ$™ð——…—, 0