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, 1985 by Xerox Corporation. All rights reserved. Michael Plass, December 30, 1983 2:22 pm Doug Wyatt, March 7, 1985 2:38:55 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. May be raised by Validate. 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. Κό˜code™Kšœ Οmœ7™BK™(K™(—K™K™*K™BK˜šΟk ˜ Kšœžœ˜'—K˜KšΠblœžœž ˜"Kšœž˜head™ šœžœ"˜7Kšžœžœžœ™0K˜—šœ žœžœžœ˜(™>Kšœžœžœ™BKšž™Kšœ™—K˜—šΟnœžœžœ ˜4K™-K™—šœžœ˜K™——šœ™š œžœ˜šœžœΟc˜%Kšœžœ žœ žœ‘&˜SKšœžœžœ‘)˜SKšœ˜—Kšœžœ ˜Kšœz™zK˜—Kš  œžœ$žœ ˜I—šœ™š œžœžœžœ˜7Kšœ‡™‡K˜——šœ™š œžœ žœ žœ ˜0K˜—š œžœžœ ˜.K˜—š  œžœžœ ˜5K˜—š  œžœžœ ˜3K˜——šœ™š œžœ$žœ˜8K˜—š   œžœžœžœžœ ˜NKšœ€™€——šœ™š  œžœžœ˜?K˜—š  œžœžœžœ˜2K˜—š  œžœžœžœ˜1K˜—š  œžœžœžœ žœ˜NK˜—šœ žœ'˜7K˜—š  œžœžœ˜>šœ'™'Kšœ™Kšœ™Kšœ™—Kšœ-™-—K˜—K˜Kšžœ˜—…—f Ύ