DIRECTORY D2Basic USING [Number, Coord, Rect]; CornerStitching: CEDAR DEFINITIONS = BEGIN Number: TYPE = D2Basic.Number; Coord: TYPE = D2Basic.Coord; Rect: TYPE = D2Basic.Rect; DumpCache: PROCEDURE; NewTesselation: PROCEDURE [data: REF_NIL, stopFlag: REF BOOL_NIL] RETURNS [REF Tesselation]; FreeTesselation: PROCEDURE [plane: REF Tesselation, freeCache: BOOLEAN _ TRUE]; ChangeRect: PROCEDURE [plane: REF Tesselation, rect: Rect, newValue: REF ANY _ NIL]; FuncChangeRect: PROCEDURE [plane: REF Tesselation, rect: Rect, perTile: PerTileChangeProc, data: REF ANY _ NIL]; PerTileChangeProc: TYPE = PROCEDURE [plane: REF Tesselation, rect: Rect, oldValue: REF ANY, data: REF ANY]; InlineChangeTile: PRIVATE PROCEDURE [plane: REF Tesselation, tile: TilePtr, newValue: REF ANY] = INLINE { TRUSTED { ChangeUnsafe: ERROR ~ CODE; IF tile.ne.value = newValue OR tile.sw.value = newValue OR (tile.en.value = newValue AND tile.en.pos.x = tile.pos.x AND tile.en.ne.pos.x = tile.ne.pos.x) OR (tile.ws.value = newValue AND tile.ws.pos.x = tile.pos.x AND tile.ws.ne.pos.x = tile.ne.pos.x) THEN ERROR ChangeUnsafe }; tile.value _ newValue }; PerTileProc: TYPE = PROCEDURE [tile: TilePtr, data: REF ANY]; EnumerateArea: PROCEDURE [plane: REF Tesselation, rect: Rect, perTile: PerTileProc _ NIL, data: REF ANY _ NIL, backgroundValue: REF ANY _ NIL] RETURNS [REF ANY]; TileAt: PROCEDURE [plane: REF Tesselation, pos: Coord] RETURNS [TilePtr]; ENorthNeighbour: PROCEDURE [tile: TilePtr] RETURNS [TilePtr] = INLINE { RETURN [tile.en] }; NEastNeighbour: PROCEDURE [tile: TilePtr] RETURNS [TilePtr] = INLINE { TRUSTED { RETURN [LOOPHOLE[tile.ne]] } }; WSouthNeighbour: PROCEDURE [tile: TilePtr] RETURNS [TilePtr] = INLINE { TRUSTED { RETURN [LOOPHOLE[tile.ws]] } }; SWestNeighbour: PROCEDURE [tile: TilePtr] RETURNS [TilePtr] = INLINE { RETURN [tile.sw] }; Value: PROCEDURE [tile: TilePtr] RETURNS [REF ANY] = INLINE { RETURN [tile.value] }; Area: PROCEDURE [tile: TilePtr] RETURNS [Rect] = INLINE { RETURN [[WestEdge[tile], SouthEdge[tile], EastEdge[tile], NorthEdge[tile]]] }; NorthEdge: PROCEDURE [t: TilePtr] RETURNS [Number] = INLINE {RETURN [t.en.pos.y]}; EastEdge: PROCEDURE [t: TilePtr] RETURNS [Number] = INLINE {TRUSTED { RETURN [t.ne.pos.x] }}; SouthEdge: PROCEDURE [t: TilePtr] RETURNS [Number] = INLINE {RETURN [t.pos.y]}; WestEdge: PROCEDURE [t: TilePtr] RETURNS [Number] = INLINE {RETURN [t.pos.x]}; AreaEmpty: PROCEDURE [plane: REF Tesselation, rect: Rect, backgroundValue: REF ANY _ NIL] RETURNS [BOOLEAN]; ContentsBound: PROCEDURE [plane: REF Tesselation, rect: Rect, backgroundValue: REF ANY _ NIL] RETURNS [bBox: Rect]; TileValue: ERROR; TileDeleted: ERROR; TilePtr: TYPE = REF Tile; Tile: TYPE = RECORD [ en, sw: REF Tile _ NIL, ne, ws: LONG POINTER TO Tile _ NIL, pos: Coord, value: REF ANY _ NIL -- NIL for space tiles ]; Region: TYPE = RECORD [ rect: Rect, value: REF ANY _ NIL -- NIL for space tiles ]; Tesselation: TYPE = PRIVATE RECORD [ southEast, current: REF Tile _, tilesInTesselationCount: INT _ 1, stopFlag: REF BOOL, data: REF ]; END. àCornerStitching.mesa Copyright c 1983, 1985 by Xerox Corporation. All rights reserved. Written by Mark Shand, September 12, 1983 11:40 pm Last Edited by: McCreight, November 28, 1983 5:53 pm Last Edited by: Jacobi, February 24, 1984 12:14 pm Last Edited by: Shand, June 1, 1984 2:20:32 pm PDT Last Edited by: Jacobi, April 11, 1985 2:50:37 pm PST --WARNING: Conventions are different from D2Basic and ChipNDale -- Clean up. -- Creating Tile Worlds. -- Modifying the Tile World. -- Let a client change a tile provided it doesn't violate invariants. May raise ERROR ChangeUnsafe -- Tile Enumeration routines. -- Enumeration routines take a backgroundValue parameter, tiles with this value are ignored. If you want every tile, set backgroundValue to some value you know no tile has (e.g. NEW[INT]). perTile is called for each Tile found. If perTile = NIL then returns LIST OF REF Region, the list contains each tile not of backgroundValue clipped to rect. If ChangeRect is called from perTile during an Enumeration results are unpredictable! -- In EnumerateArea the order of enumeration is well defined. A tile appears in the enumeration immediately after the last of its children. Where tileA is defined to be a child of tileB iff its sw stitch points to tileB. Children are ordered such that the southernmost is the last. For tiles touching the western and southern borders these rules do not apply, these tiles are parent-less. Such tiles appear at some point after all the parent-less tiles touching touching a given parent-less tile's northern and western borders have been enumerated. -- If perTile = NIL then returns LIST OF REF Region; -- Stepping from Tile to Tile. -- Co-ordinates increase from south to north, and west to east. All tile worlds are bordered by tile at 'infinity' (i.e. INT.FIRST or INT.LAST), so bounded searches never need worry about tile = NIL. The tiles at infinity are not stitched to tiles in the Tesselation, rather they are stitched to each other in the manner of the bevelled edges of a picture frame. The meanings of the Stepping routines are as follows ... -- ENorthNeighbour  eastern most tile to the north -- NEastNeighbour  northern most tile to the east -- WSouthNeighbour  western most tile to the south -- SWestNeighbour  southern most tile to the west -- Tile Enquiries -- Area Enquiries. -- ContentsBound returns a minimal bounding box for non-backgroundValue tiles in rect -- ERROR Codes. -- Types. -- Corner stitching is too circular for the current implementation of Cedar safestorage (too many tiles are pinned) so some of the stitches are pointers (idea courtesy of Mark Brown). We are careful to stitch in a way that connects every tile through a chain of REFs to the southeast tile, which we hang on to in the Tesselation record. Actually there is one benefit, now to free a Tesselation you only need drop this REF. -- Always leave tile in second direction, i.e en = NorthEast corner, facing North; -- ne faces East. --data and stopflag used by clients ʼ˜™Jšœ Ïmœ7™BJ™2J™4J™2J™2J™5J™—šÏk ˜ Jšœžœ˜$—J˜JšÏbœžœž œ˜%Jšž˜˜Jšœžœ˜Jšœžœ˜šœžœ˜JšžÐbkœ6™?J˜——™ JšÏn œž œ˜—J™šÏc™š¡œž œžœžœ žœžœžœ˜BJšžœžœ˜—Jš ¡œž œ žœžœžœ˜O—J™š¢™Jš ¡ œž œ žœ$žœžœžœ˜TJš ¡œž œ žœ<žœžœžœ˜pJ˜Jšœžœž œ žœ$žœžœžœžœ˜kJ˜š¡œžœž œ žœ'žœžœžœ˜iJšœQžœ ™cšžœ˜ Jšœžœžœ˜šžœ˜Jšžœ˜Jšžœžœžœ"˜aJšžœžœžœ#ž˜fJšžœ ˜—J˜—Jšœ˜J˜——J™š¢™Jšœ³™³J˜Jš œ žœž œžœžœ˜=J™Jšœ©™©J˜š¡ œž œ žœ1žœžœžœžœžœžœžœžœžœžœ˜¡Jšœ4™4—J˜Jš¡œž œ žœžœ ˜I—J™š¢™šœ¦™¦Jšœ3™3Jšœ2™2Jšœ3™3Jšœ2™2—J˜š¡œž œžœ žœ˜GJšžœ ˜J˜—š¡œž œžœ žœ˜FJšžœžœžœ ˜&J˜—š¡œž œžœ žœ˜GJšžœžœžœ ˜&J˜—š¡œž œžœ žœ˜FJšžœ ˜J˜——J™šœ™š ¡œž œžœžœžœžœ˜=Jšžœ ˜J˜—š¡œž œžœ žœ˜9JšžœE˜KJ˜—J˜Jš ¡ œž œžœ žœžœ˜RJš ¡œž œžœ žœžœžœ˜]Jš ¡ œž œžœ žœžœ ˜OJš ¡œž œžœ žœžœ ˜N—J™š¢™Jš¡ œž œ žœ+žœžœžœžœžœ˜lš¡ œž œ žœ+žœžœžœžœ˜sJšœU™U——J™š¢™Jšœ žœ˜Jšœ žœ˜—J™šœ ™ J™¨J˜Jšœ žœžœ˜šœžœžœ˜JšœS™SJšœ™Jšœžœžœ˜Jš œžœžœžœžœ˜#Jšœ ˜ Jšœžœžœžœ¢˜+J˜—J˜šœžœžœ˜Jšœ ˜ Jšœžœžœžœ¢˜+J˜—J˜šœ žœžœžœ˜$Jšœžœ˜Jšœžœ˜!Jšœ žœžœ˜Jšœž˜ Jšœ˜Jšœ#™#——J˜Jšžœ˜—…— ø”