DIRECTORY Basics USING [BITAND], CD USING [Number, Orientation, Position, Rect, Transformation], Imager USING [Transformation]; CDBasics: CEDAR DEFINITIONS IMPORTS Basics = BEGIN Number: TYPE = CD.Number; Orientation: TYPE = CD.Orientation; Position: TYPE = CD.Position; Rect: TYPE = CD.Rect; Transformation: TYPE = CD.Transformation; maxnum: Number = LAST[Number]/2; --/2: poor man's arithmetic overflow protection minnum: Number = FIRST[Number]/2; highposition: Position = [maxnum, maxnum]; minposition: Position = [minnum, minnum]; empty: Rect = [maxnum, maxnum, minnum, minnum]; universe: Rect = [minnum, minnum, maxnum, maxnum]; OrderedIncreasing: PROC [p1, p2: Position] RETURNS [BOOL] = INLINE { RETURN [p1.x<=p2.x AND p1.y<=p2.y] }; Degenerated: PROC [r: Rect] RETURNS [BOOL] = INLINE { RETURN [r.x1>r.x2 OR r.y1>r.y2] }; NonEmpty: PROC [r: Rect] RETURNS [BOOL] = INLINE { RETURN [r.x1=b.x1 AND a.x2<=b.x2 AND a.y1>=b.y1 AND a.y2<=b.y2] }; InsidePos: PROC [p: Position, r: Rect] RETURNS [BOOL] = INLINE { RETURN[p.x>=r.x1 AND p.x<=r.x2 AND p.y>=r.y1 AND p.y<=r.y2] }; Intersection: PROC [r1, r2: Rect] RETURNS [Rect] = INLINE { RETURN [Rect[ x1: MAX[r1.x1, r2.x1], y1: MAX[r1.y1, r2.y1], x2: MIN[r1.x2, r2.x2], y2: MIN[r1.y2, r2.y2]]] }; SizeOfRect: PROC [r: Rect] RETURNS [Position] = INLINE { IF (r.x2<=r.x1) OR (r.y2<=r.y1) THEN RETURN [Position[x: 0, y: 0]] ELSE RETURN [Position[x: r.x2-r.x1, y: r.y2-r.y1]] }; BaseOfRect: PROC [r: Rect] RETURNS [Position] = INLINE { RETURN[Position[x: r.x1, y: r.y1]] }; RectAt: PROC [pos: Position, size: Position] RETURNS [Rect] = INLINE { RETURN [Rect[x1: pos.x, y1: pos.y, x2: pos.x+size.x, y2: pos.y+size.y]] }; ToRect: PROC [p1, p2: Position] RETURNS [Rect] = INLINE { RETURN [Rect[ x1: MIN[p1.x, p2.x], y1: MIN[p1.y, p2.y], x2: MAX[p1.x, p2.x], y2: MAX[p1.y, p2.y] ]] }; SubPoints: PROC [pos, neg: Position] RETURNS [Position] = INLINE { RETURN [Position[x: pos.x-neg.x, y: pos.y-neg.y]] }; AddPoints: PROC [p, s: Position] RETURNS [Position] = INLINE { RETURN [Position[x: p.x+s.x, y: p.y+s.y]] }; MinPoint: PROC[a, b: Position] RETURNS [Position] = INLINE { RETURN [Position[x: MIN[a.x, b.x], y: MIN[a.y, b.y]]] }; MaxPoint: PROC[a, b: Position] RETURNS [Position] = INLINE { RETURN [Position[x: MAX[a.x, b.x], y: MAX[a.y, b.y]]] }; NegOffset: PROC [off: Position] RETURNS [Position] = INLINE { RETURN [Position[x: -off.x, y: -off.y]] }; Surround: PROC [r1, r2: Rect] RETURNS [Rect] = INLINE { RETURN [Rect[ x1: MIN[r1.x1, r2.x1], y1: MIN[r1.y1, r2.y1], x2: MAX[r1.x2, r2.x2], y2: MAX[r1.y2, r2.y2]]] }; MoveRect: PROC [r: Rect, offset: Position] RETURNS [Rect] = INLINE { RETURN [Rect[ r.x1+offset.x, r.y1+offset.y, r.x2+offset.x, r.y2+offset.y]] }; Extend: PROC [r: Rect, ext: Number] RETURNS [Rect] = INLINE { RETURN [Rect[r.x1-ext, r.y1-ext, r.x2+ext, r.y2+ext]] }; Center: PROC [r: Rect] RETURNS [Position] = INLINE { RETURN[[(r.x1+r.x2)/2, (r.y1+r.y2)/2]] }; ReInterpreteRect: PROC [r: CD.Rect] RETURNS [CD.Rect] = INLINE { t: CD.Number; IF r.x1>r.x2 THEN {t_r.x1; r.x1_r.x2; r.x2_t}; IF r.y1>r.y2 THEN {t_r.y1; r.y1_r.y2; r.y2_t}; RETURN [r] }; DecomposeRect: PROC [r, test: Rect, inside, outside: PROC [Rect] _ Skip]; Skip: PROC [Rect]; MapRect: PROC [itemInCell: Rect, cellInWorld: Transformation] RETURNS [itemInWorld: Rect]; DeMapRect: PROC [itemInWorld: Rect, cellInWorld: Transformation] RETURNS [itemInCell: Rect]; MapPoint: PROC [pointInCell: Position, cellInWorld: Transformation] RETURNS [pointInWorld: Position]; DeMapPoint: PROC [pointInWorld: Position, cellInWorld: Transformation] RETURNS [pointInCell: Position]; OrientedPoint: PROC [pos: Position, orient: Orientation] RETURNS [Position]; OrientedSize: PROC [size: Position, orient: Orientation] RETURNS [Position] = INLINE { RETURN [IF IncludesOddRot90[orient] THEN [x: size.y, y: size.x] ELSE size] }; ComposeTransform: PROC [itemInCell, cellInWorld: Transformation] RETURNS [itemInWorld: Transformation]; InverseTransform: PROC [trans: Transformation] RETURNS [Transformation]; DecomposeTransform: PROC [itemInWorld, cellInWorld: Transformation] RETURNS [itemInCell: Transformation]; ImagerTransform: PROC [trans: CD.Transformation] RETURNS [Imager.Transformation]; ComposeOrient: PROC [itemInCell, cellInWorld: Orientation] RETURNS [itemInWorld: Orientation]; InverseOrient: PROC [orient: Orientation] RETURNS [inverse: Orientation]; DecomposeOrient: PROC [itemInWorld, cellInWorld: Orientation] RETURNS [itemInCell: Orientation]; IncludesOddRot90: PROC [orient: Orientation] RETURNS [BOOLEAN] = INLINE { RETURN [Basics.BITAND[ORD[orient], ORD[Orientation[rotate90]]]#0] }; IncludesMirrorX: PROC [orient: Orientation] RETURNS [BOOLEAN] = INLINE { RETURN [Basics.BITAND[ORD[orient], ORD[Orientation[mirrorX]]]#0] }; ConcentrateOnRotate90: PROC [orient: Orientation] RETURNS [Orientation] = INLINE { RETURN [VAL[Basics.BITAND[ORD[orient], 6]]] }; END. ¬CDBasics.mesa (part of ChipNDale) Copyright c 1983, 1984, 1986 by Xerox Corporation. All rights reserved. Created by Christian Jacobi, May 3, 1983 4:26 pm Last edited by: Christian Jacobi, October 23, 1986 10:03:59 am PDT --constants --predicats -- Returns p2>=p1 -- Returns r is degenerated [contains not even a single point or border] -- Returns r is not empty [contains more points than the border] -- This is NOT the inverse of Degenerated -- Returns r1 and r2 have some common points or border; [assumes r1, r2 normalized]. -- [TRUE if rects touch on a single point] -- Returns a inside of b (b inclusive border) -- Returns p inside of r (or p on border of r) --functions -- Returns intersection of r1 and r2 -- Returns position of rect -- Returns a rect with size "size" at position "pos"; -- Returns the rect between "pos1" and "pos2" -- pos displaced by -neg -- p displaced by d -- Returns r move by offset -- Returns r extended by ext in every direction -- If ext<0 it is the callers responsability that ext is not bigger than rect -- Returns center of rect r -- Changes coordinates to make rect not degenerated --higher level -- Calls inside [part of r inside of test] and outside [parts of r outside of test] -- [border points might be part of both calls] --Orientations -- Given an item in a cell [in "cell" coordinates], -- the position and orientation of an instance of that cell in "world" coordinates, -- returns the world coordinates of the item -- Given an item in world coordinates, the size of a cell, -- the position and orientation of an instance of that cell in "world" coordinates, -- returns the cell coordinates of that item. -- Given an point in a cell, -- the position and orientation of an instance of the cell in "world" coordinates, -- returns the world coordinates of the point. -- Given a point in world co-ordinates, -- the position and orientation of an instance of the cell in "world" coordinates, -- returns the cell coordinates of the point. --Maps a point on a transformation [[0,0], orient] -- Returns the size transformed by transformation "orient" -- composes transformations -- Returns the inverse transformation -- de-composes transformations -- Converts a ChipNDale Transformation into a corresponding Imager Transformation -- Returns the composite orientation obtained by first doing -- itemInCell and then cellInWorld -- For all orientations o1, ComposeOrient[o1, InverseOrient[o1]] = original. -- For all orientations o1 and o2, -- DecomposeOrient[ -- cellInWorld: o1, -- itemInWorld: ComposeOrient[cellInWorld: o1, itemInCell: o2] -- ] = o2. -- Returns orient includes an odd multiple of 90 degree -- Returns orient includes some mirroring -- Discard mirroring Κ F˜šœ!™!Jšœ Οmœ=™HJšœ0™0Icode™B—J˜šΟk œ˜ Jšœžœžœ˜Jšžœžœ7˜?Jšœžœ˜—J˜šΟnœžœž ˜Jšžœ ˜—Jšž˜J˜Jšœžœžœ˜Jšœ žœžœ ˜#Jšœ žœžœ ˜Jšœžœžœ˜Jšœžœžœ˜)J˜Jšœ ™ J˜Jšœžœ Οc/˜QJšœžœ ˜!Jšœ*˜*Jšœ)˜)Jšœ/˜/šœ2˜2J˜—J˜Jšœ ™ J˜š Ÿœžœžœžœžœ˜DJšœ™Jšžœ žœ ˜"Jšœ˜J˜—š Ÿ œžœ žœžœžœ˜5JšœH™HJšžœ žœ ˜Jšœ˜J˜—š Ÿœžœ žœžœžœ˜2Jšœ@™@Jšœ*™*Jšžœ žœ ˜ Jšœ˜J˜—š Ÿ œžœžœžœžœ˜8JšœU™UJ™*Jšžœžœžœžœ˜HJšœ˜J˜—š Ÿœžœžœžœžœ˜3Jšœ-™-Jšžœ žœ žœ žœ ˜?Jšœ˜J˜—š Ÿ œžœžœžœžœ˜@Jšœ.™.Jšžœ žœ žœ žœ ˜;Jšœ˜J˜—J˜Jšœ ™ J˜šŸ œžœžœ žœ˜;Jšœ$™$šžœ˜ Jšœžœ˜Jšœžœ˜Jšœžœ˜Jšœžœ˜—Jšœ˜J˜—šŸ œžœ žœžœ˜8Jšžœžœžœžœ˜BJšžœžœ'˜2Jšœ˜J˜—šŸ œžœ žœžœ˜8Jšœ™Jšžœ˜"Jšœ˜J˜—šŸœžœ!žœ žœ˜FJšœ6™6JšžœA˜GJšœ˜J˜—šŸœžœžœ žœ˜9Jšœ-™-šžœ˜ Jšœžœžœ˜*Jšœžœžœ ˜(Jšœ˜—Jšœ˜J˜—šŸ œžœžœžœ˜BJšœ™Jšžœ+˜1Jšœ˜J˜—šŸ œžœžœžœ˜>Jšœ™Jšžœ#˜)Jšœ˜J˜—šŸœžœžœžœ˜™>Kšœ ™ K˜—š Ÿœžœžœžœžœ˜IKšœ8™8Kšžœ žœžœ žœ˜AKšœ˜K˜—š Ÿœžœžœžœžœ˜HKšœ*™*Kšžœ žœžœ žœ˜@Kšœ˜K˜—šŸœžœžœžœ˜RKšœ™Kšžœžœžœžœ˜+Kšœ˜K˜—Jšžœ˜—…—&(