DIRECTORY CD USING [Number, DesignNumber, Position, DesignPosition, Rect, DesignRect]; CDInline: CEDAR DEFINITIONS = BEGIN maxnum: CD.DesignNumber = LAST[CD.DesignNumber]/2; minnum: CD.DesignNumber = FIRST[CD.DesignNumber]/2; highposition: CD.DesignPosition = [maxnum, maxnum]; minposition: CD.DesignPosition = [minnum, minnum]; empty: CD.DesignRect = [maxnum, maxnum, minnum, minnum]; universe: CD.DesignRect = [minnum, minnum, maxnum, maxnum]; OrderedIncreasing: PROC [p1, p2: CD.Position] RETURNS [BOOLEAN] = INLINE {RETURN [(p1.x<=p2.x) AND (p1.y<=p2.y)]}; NonEmpty: PROC[r: CD.Rect] RETURNS [BOOLEAN] = INLINE BEGIN RETURN [(r.x1=b.x1) AND (a.x2<=b.x2) AND (a.y1>=b.y1) AND (a.y2<=b.y2)]}; InsidePos: PROC [p: CD.Position, r: CD.Rect] RETURNS [BOOLEAN] = 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: CD.Rect] RETURNS [CD.Rect] = INLINE BEGIN RETURN [CD.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]]] END; SizeOfRect: PROCEDURE[r: CD.Rect] RETURNS [CD.Position] = INLINE BEGIN IF (r.x2<=r.x1) OR (r.y2<=r.y1) THEN RETURN [CD.Position[x: 0, y: 0]] ELSE RETURN [CD.Position[x: r.x2-r.x1, y: r.y2-r.y1]] END; BaseOfAnyRect: PROCEDURE[r: CD.Rect] RETURNS [CD.Position] = INLINE {RETURN [CD.Position[x: MIN[r.x2, r.x1], y: MIN[r.y2, r.y1]]]}; BaseOfRect: PROCEDURE[r: CD.Rect] RETURNS [CD.Position] = INLINE {RETURN[CD.Position[x: r.x1, y: r.y1]]}; RectAt: PROC [pos: CD.Position, size: CD.Position] RETURNS [CD.Rect] = INLINE {RETURN [CD.Rect[x1: pos.x, y1: pos.y, x2: pos.x+size.x, y2: pos.y+size.y]]}; ToRect: PROC [p1, p2: CD.Position] RETURNS [CD.Rect] = INLINE BEGIN RETURN [CD.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] ]] END; NormalizeRect: PROC [r: CD.Rect] RETURNS [CD.Rect] = INLINE BEGIN 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] END; SubPoints: PROC [pos, neg: CD.Position] RETURNS [CD.Position] = INLINE {RETURN [CD.Position[x: pos.x-neg.x, y: pos.y-neg.y]]}; AddPoints: PROC [p, s: CD.Position] RETURNS [CD.Position] = INLINE {RETURN [CD.Position[x: p.x+s.x, y: p.y+s.y]]}; AddSize: PROC [p, s: CD.Position] RETURNS [CD.Position] = INLINE {RETURN [CD.Position[x: p.x+s.x, y: p.y+s.y]]}; MinPoint: PROC[a, b: CD.Position] RETURNS [CD.Position] = INLINE {RETURN [CD.Position[x: MIN[a.x, b.x], y: MIN[a.y, b.y]]]}; MaxPoint: PROC[a, b: CD.Position] RETURNS [CD.Position] = INLINE {RETURN [CD.Position[x: MAX[a.x, b.x], y: MAX[a.y, b.y]]]}; NegOffset: PROC [off: CD.Position] RETURNS [CD.Position] = INLINE {RETURN [CD.Position[x: -off.x, y: -off.y]]}; Surround: PROC [r1, r2: CD.Rect] RETURNS [CD.Rect] = INLINE BEGIN RETURN [CD.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]]] END; MoveRect: PROC [r: CD.Rect, offset: CD.Position] RETURNS [CD.Rect] = INLINE BEGIN RETURN [CD.Rect[ r.x1+offset.x, r.y1+offset.y, r.x2+offset.x, r.y2+offset.y]] END; Extend: PROC [r: CD.Rect, ext: CD.Number] RETURNS [CD.Rect] = INLINE {RETURN [CD.Rect[r.x1-ext, r.y1-ext, r.x2+ext, r.y2+ext]]}; Center: PROC [r: CD.Rect] RETURNS [CD.Position] = INLINE {RETURN[[(r.x1+r.x2)/2, (r.y1+r.y2)/2]]}; END. Ê-- CDInline.mesa (part of Chipndale) -- by Christian Jacobi, May 3, 1983 4:26 pm -- Last Edited by Christian Jacobi, November 21, 1983 3:18 pm --constants --predicats --p2>=p1 --returns r is not empty --assumes r normalized --returns r1 and r2 have some common points or border; assumes r1, r2 normalized. --returns TRUE if rect only touches 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, also if non normalized --returns position of rect --returns a rect with size "size" at position "pos"; --returns the rect between "pos1" and "pos2" --r may be not normalized --pos displaced by -neg --p displaced by d --highpoint of rect with size s is at p --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 ÊߘJšœ$™$Jšœ+™+Jšœ=™=J˜šÏk œ˜ JšœœD˜LJ˜—JšÏnœœ œ˜Jš˜J˜Jšœ ™ J˜Jšœœœœ˜2Jšœœœœ˜3Jšœœ#˜3Jšœ œ#˜2Jšœœ/˜8Jšœ œ/˜;J˜J˜Jšœ ™ J˜š žœœ œ œœ˜AJšœ™Jšœœœ˜0J˜—š žœœœœœ˜.Jšœ™Jšœ™Jšœœ˜ Jšœœ ˜$Jšœ˜J˜—š ž œœ œœœ˜4JšœR™RJ™5Jš œœœœœ˜ZJ˜—š žœœœœœ˜0Jšœ,™,Jš œœœœœ˜QJ˜—š ž œœœœœœ˜@Jšœ-™-Jš œœ œ œ œ˜MJ˜—Jšœ ™ J˜š ž œœ œœœ˜7Jšœ#™#Jšœ˜ šœœ˜Jšœœ˜Jšœœ˜Jšœœ˜Jšœœ˜—Jšœ˜J˜—š ž œ œœœœ ˜9Jšœ˜ Jš œœœœœ˜EJšœœœ&˜5Jšœ˜J˜—š ž œ œœœœ ˜J˜—š ž œœœ œœ ˜;Jšœ™Jšœœœ$˜6J˜—š žœœœ œœ ˜9Jšœ'™'Jšœœœ$˜6J˜—š žœœœ œœ ˜9Jš œœœ œœ˜BJ˜—š žœœœ œœ ˜9Jš œœœ œœ˜BJ˜—š ž œœœ œœ ˜:Jšœœœ"˜4J˜—š žœœ œœœ˜4šœ˜ Jšœœ˜Jšœœ˜Jšœœ˜Jšœœ˜Jšœœ˜—Jšœ˜J˜—š žœœœœ œœ˜DJšœ™Jšœ˜ šœœ˜J˜J˜J˜J˜—Jšœ˜J˜—š žœœœ œ œœ˜=Jšœ.™.JšœL™LJšœœœ0˜BJ˜—š žœœœœœ ˜1Jšœ™Jšœœ"˜0J˜—Jšœ˜—…— æ