DIRECTORY ImagerPixelMap USING [DeviceRectangle]; ImagerManhattan: CEDAR DEFINITIONS ~ BEGIN DeviceRectangle: TYPE ~ ImagerPixelMap.DeviceRectangle; Polygon: TYPE ~ LIST OF DeviceRectangle; Validate: PROC [polygon: Polygon] RETURNS [Polygon]; InvalidManhattanPolygon: ERROR; CreateFromRuns: PROC [ runs: PROC[ -- Create calls this back run: PROC[sMin, fMin: INTEGER, fSize: NAT], -- client calls this from inside runs. repeat: PROC[timesToRepeatScanline: NAT] -- client calls this to repeat a scanline ] ] RETURNS [Polygon]; CreateFromBox: PROC [deviceRectangle: DeviceRectangle] RETURNS [Polygon]; Destroy: PROC [rectangleList: LIST OF DeviceRectangle]; Copy: PROC [polygon: Polygon] RETURNS [Polygon]; Union: PROC [a, b: Polygon] RETURNS [Polygon]; Intersection: PROC [a, b: Polygon] RETURNS [Polygon]; Difference: PROC [a, b: Polygon] RETURNS [Polygon]; Shift: PROC [polygon: Polygon, sShift, fShift: INTEGER]; Canonicalize: PROC [rectangleList: LIST OF DeviceRectangle] RETURNS [Polygon]; BoundingBox: PROC [polygon: Polygon] RETURNS [DeviceRectangle]; CountBoxes: PROC [polygon: Polygon] RETURNS [INT]; CountRuns: PROC [polygon: Polygon] RETURNS [INT]; MapRuns: PROC [polygon: Polygon, run: PROC [sMin, fMin: INTEGER, fSize: NAT]]; Visibility: TYPE ~ {visible, partlyVisible, invisible}; IsVisible: PROC [mask, clipper: Polygon] RETURNS [Visibility]; END. <ImagerManhattan.mesa Copyright c 1984 Xerox Corporation. All rights reserved. Michael Plass, December 30, 1983 2:22 pm Doug Wyatt, November 1, 1984 4:37:35 pm PST Provides operations on manhattan polygons. The coordinates are given in terms of s and f (for slow and fast). Data types RECORD [sMin, fMin: INTEGER, sSize, fSize: NAT]; If a and b are consecutive boxes in the list, must have either a.sMin = b.sMin AND a.sSize = b.sSize AND a.fMin+a.fSize <= b.fMin OR a.sMin+a.sSize <= b.sMin Checks that the above invariant is satisfied. Polygon Creation The runs proc should call run for each run, in non-descreasing s. It may call repeat to duplicate a scanline just entered. Polygon Destruction Puts the nodes on an avail list to be re-used; much faster than letting the garbage collector do the work, but don't destroy a list unless you are sure nobody is depending on it. (The avail list nodes will get garbage collected eventually if they are unneeded.) Making new Polygons from old Modifying existing Polygons Turns a list of arbitrary rectangles into a valid Polygon. Re-uses the storage, so copy first if rectangleList might be shared. Extracting info from Polygons SELECT Intersection[mask, clipper] FROM = empty => invisible, = mask => visible, ENDCASE => partlyVisible; N. B. will return invisible if mask is empty. ÊᘙJšœ Ïmœ.™9J™(J™+J™—J™nJ˜šÏk ˜ Jšœžœ˜'—J˜Jšœž˜"Jšž˜head2™ šœžœ"˜7Jšžœžœžœ™0J˜—šœ žœžœžœ˜(™>Jšœžœžœ™BJšž™Jšœ™—J˜—šÏnœžœžœ ˜4J™-Jšœžœ˜——šœ™šŸœžœ˜šœžœÏc˜%Jšœžœ žœ žœ &˜SJšœžœžœ )˜SJšœ˜—Jšœžœ ˜Jšœz™zJ˜—JšŸ œžœ$žœ ˜I—šœ™šŸœžœžœžœ˜7Jšœ‡™‡J˜——šœ™šŸœžœ žœ žœ ˜0J˜—šŸœžœžœ ˜.J˜—šŸ œžœžœ ˜5J˜—šŸ œžœžœ ˜3J˜——šœ™šŸœžœ$žœ˜8J˜—š Ÿ œžœžœžœžœ ˜NJšœ€™€——šœ™šŸ œžœžœ˜?J˜—šŸ œžœžœžœ˜2J˜—šŸ œžœžœžœ˜1J˜—š Ÿœžœžœžœ žœ˜NJ˜—šœ žœ'˜7J˜—šŸ œžœžœ˜>šœ'™'Jšœ™Jšœ™Jšœ™—Jšœ-™-——J˜Jšžœ˜—…—f ƒ