DIRECTORY CSBaseType USING [Number, Coord, Rect] ; CornerStitching: CEDAR DEFINITIONS ~ BEGIN DumpCache: PROCEDURE; NewTesselation: PROCEDURE 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]; ChangeTile: 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: PRIVATE TYPE ~ RECORD [ en, sw: REF Tile _ NIL, ne, ws: LONG POINTER TO Tile _ NIL, pos: Coord, value: REF ANY _ NIL -- NIL for space tiles ]; Number: TYPE ~ CSBaseType.Number; Coord: TYPE ~ CSBaseType.Coord; Rect: TYPE ~ CSBaseType.Rect; Region: TYPE ~ RECORD [ rect: Rect, value: REF ANY _ NIL -- NIL for space tiles ]; Tesselation: TYPE ~ PRIVATE RECORD [ southEast, current: REF Tile _, tilesInTesselationCount: INT _ 1 ]; END. -- CornerStitching.mesa -- 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 -- 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. Κ&˜J™J™5J™7J™5J™5Icode˜šΟk ˜ Kšœ œ˜&Kšœ˜—IunitšΡaoxœœ œ˜*™ KšΟn œ œ˜—šΟc™KšŸœ œœœ˜4Kš Ÿœ œ œœœ˜O—š ™Kš Ÿ œ œ œ$œœœ˜TKš Ÿœ œ œ<œœœ˜pKšœœ œ œ$œœœœ˜kš Ÿ œ œ œ'œœœ˜[KšœQœ ™cšœ˜ Kšœœœ˜šœ˜Kšœ˜Kšœœœ"˜aKšœœœ#˜fKšœ ˜—K˜—Kšœ˜K˜——š ™Jšœ³™³Kš œ œ œœœ˜=Jšœ©™©šŸ œ œ œ1œœœœœœœœœœ˜‘Kšœ4™4—KšŸœ œ œœ ˜I—š ™šœ¦™¦Jšœ3™3Jšœ2™2Jšœ3™3Jšœ2™2—šŸœ œœ œ˜GKšœ ˜K˜—šŸœ œœ œ˜FKšœœœ ˜&K˜—šŸœ œœ œ˜GKšœœœ ˜&K˜—šŸœ œœ œ˜FKšœ ˜K˜——šœ™š Ÿœ œœœœœ˜=Kšœ ˜K˜—šŸœ œœ œ˜9KšœG˜MK˜—Kš Ÿ œ œœ œœ˜RKš Ÿœ œœ œœœ˜_Kš Ÿ œ œœ œœ ˜OKš Ÿœ œœ œœ ˜N—š ™KšŸ œ œ œ+œœœœœ˜lšŸ œ œ œ+œœœœ˜sJšœU™U——š ™Kšœ œ˜Kšœ œ˜—šœ ™ J™¨Kšœ œœ˜šœœœœ˜Jšœa™aKšœœœ˜Kš œœœœœ˜#Kšœ ˜ Kšœœœœ ˜+K˜—Kšœœ˜!Kšœœ˜Kšœœ˜šœœœ˜Jšœ ˜ Kšœœœœ ˜+K˜—šœ œœœ˜$Kšœœ˜Kšœœ˜ Kšœ˜——Kšœ˜—…— ¬Φ