DIRECTORY ImagerBasic USING [Visibility, DeviceRectangle]; ImagerManhattan: CEDAR DEFINITIONS ~ BEGIN DeviceRectangle: TYPE ~ ImagerBasic.DeviceRectangle; Visibility: TYPE ~ ImagerBasic.Visibility; 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]]; IsVisible: PROC [mask, clipper: Polygon] RETURNS [Visibility]; END. úImagerManhattan.mesa Michael Plass, December 30, 1983 2:22 pm 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]; {visible, partlyVisible, invisible}; 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™J™(J™nJ˜JšÏk œ œ˜:J˜Jšœ˜*head2™ šœœ˜4Jšœœœ™0J˜—šœ œ˜*Jšœ$™$J˜—šœ œœœ˜(™>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˜—šž œœœ˜>šœ'™'Jšœ™Jšœ™Jšœ™—Jšœ-™-——J˜Jšœ˜—…—^