-- CGClipper.mesa
-- Last changed by Doug Wyatt, August 23, 1982 3:33 pm

DIRECTORY
CGArea USING [Ref],
CGReducer USING [Edge, Ref],
GraphicsBasic USING [Box, Vec];

CGClipper: CEDAR DEFINITIONS = { OPEN GraphicsBasic;

Ref: TYPE = REF Rep;
Rep: TYPE = RECORD [
isbox: BOOLEAN, -- is the clipping area a single box?
isallboxes: BOOLEAN, -- are all clipping regions boxes?
size: NAT, -- length of clipping list
data: Data, -- list of clipping trapezoids
box: REF Box -- bounding box for clipper
];

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

Node: TYPE = REF NodeRep;
NodeRep: TYPE = RECORD [
isbox: BOOLEAN,
ymin,ymax,xmin,xmax: REAL,
edgeL,edgeR: CGReducer.Edge
];

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

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

Empty: PROC[self: Ref] RETURNS[BOOLEAN] = INLINE { RETURN[self.size=0] };
-- is the current clip area empty?

IsBox: PROC[self: Ref] RETURNS[BOOLEAN] = INLINE { RETURN[self.isbox] };
-- is the current clip area a single rectangle?

IsAllBoxes: PROC[self: Ref] RETURNS[BOOLEAN] = INLINE { RETURN[self.isallboxes] };
-- are all pieces of the current clip area rectangles?

Bounds: PROC[self: Ref] RETURNS[Box] = INLINE { RETURN[self.box^] };
-- get bounds of the current clipping area

TestPoint: PROC[self: Ref, p: Vec] RETURNS[BOOLEAN];
-- return TRUE iff the given point is within the clip area

TestBox: PROC[self: Ref, box: Box, reducer: CGReducer.Ref] RETURNS[BOOLEAN];
-- test the given box against the clip area
-- load relevant clipping edges into reducer
-- return TRUE iff any edges were loaded

GenerateBox: PROC[self: Ref, box: Box, reducer: CGReducer.Ref, area: CGArea.Ref];

GenerateLine: PROC[self: Ref, p,q: Vec, area: CGArea.Ref];

Load: PROC[self: Ref, reducer: CGReducer.Ref];
-- load all clipping edges into reducer

SetBox: PROC[self: Ref, box: Box];
-- set the clip area to the given box

SetArea: PROC[self: Ref, area: CGArea.Ref];
-- set the clip area to the given area

Copy: PROC[self: Ref] RETURNS[Ref];
-- make a copy of the clipper

Assign: PROC[self: Ref, copy: Ref];
-- assign the clip area from another clipper

}.