-- CGArea.mesa
-- Last edit by Doug Wyatt, August 23, 1982 3:27 pm

DIRECTORY
GraphicsBasic USING [Box, Trap, Vec];

CGArea: CEDAR DEFINITIONS = { OPEN GraphicsBasic;

-- An Area consists of a set of disjoint trapezoids sorted by lowest y.

-- Types

Ref: TYPE = REF Rep;
Rep: TYPE = RECORD [size: NAT, box: REF Box, data: Data];

Item: TYPE = REF Trap;

Data: TYPE = REF DataRep;
DataRep: TYPE = RECORD [data: SEQUENCE space: NAT OF Item];

Error: ERROR[type: ErrorType];
ErrorType: TYPE = {emptyQueue, bug};

-- Operations

New: PROC [size: NAT ← 0] RETURNS [Ref];
-- create a new area with given initial size

Size: PROC [self: Ref] RETURNS [NAT] = INLINE { RETURN[self.size] };
-- return number of items in queue

Reset: PROC [self: Ref] = INLINE { self.size ← 0 };
-- empty the queue

Empty: PROC [self: Ref] RETURNS [BOOLEAN] = INLINE { RETURN[self.size = 0] };
-- return true if queue is empty, false if not empty

Insert: PROC [self: Ref, trap: Trap];
-- insert a new trapezoid into the queue

InsertBox: PROC [self: Ref, box: Box] = INLINE { Insert[self,[
ybot: box.ymin, xbotL: box.xmin, xbotR: box.xmax,
ytop: box.ymax, xtopL: box.xmin, xtopR: box.xmax,
rectangle: TRUE]] };
-- insert a new rectangle into the queue

InsertLine: PROC [self: Ref, p,q: Vec];
-- insert a new line into the queue

Bounds: PROC [self: Ref] RETURNS [Box] = INLINE { RETURN[self.box^] };
-- return bounding box for all items inserted since last Reset

NextY: PROC [self: Ref] RETURNS[REAL];
-- return lowest y of next trapezoid in queue
-- Errors: emptyQueue

Remove: PROC [self: Ref] RETURNS[Trap];
-- remove next trapezoid from queue
-- Errors: emptyQueue

}.