DEFINITION MODULE GKSClip;

(*
    Title: 	GKS Shape Clipping
    LastEdit:	"Tue Feb 26 14:21:45 1985"
    Author: 	jd
		Cambridge University Computer Laboratory
*)

(* This module deals with clipping of 2-D Cartesian coordinate shapes *)


FROM Vector IMPORT RVEC, RBOX;

EXPORT QUALIFIED
    InPolygon, ClipLine, ClipBox, ClipPoints, ClipPolyLine, ClipPolygon;


PROCEDURE InPolygon (VAR p: RVEC; high: INTEGER;
        VAR poly: ARRAY OF RVEC): BOOLEAN;

(* These procedures return TRUE unless no visible points are returned *)

PROCEDURE ClipLine (VAR start, end: RVEC; VAR against: RBOX):BOOLEAN;

PROCEDURE ClipBox (VAR r: RBOX; VAR against: RBOX): BOOLEAN;

PROCEDURE ClipPoints (fromhigh: INTEGER; VAR from: ARRAY OF RVEC;
        VAR tohigh: INTEGER; VAR to: ARRAY OF RVEC;
        VAR against: RBOX): BOOLEAN;

        (* Clips the points in from [0..fromhigh] against the box,
           returning in to [0..tohigh] those which lie within it or on the
           boundary. No new points are added. On entry tohigh is the maximum
            usable entry in to, and on exit it is the highest entry used.
        *)

PROCEDURE ClipPolyLine (VAR fromlow, fromhigh: INTEGER;
        VAR from: ARRAY OF RVEC; VAR tohigh: INTEGER;
        VAR to: ARRAY OF RVEC; VAR against: RBOX): BOOLEAN;

        (* Clips the line in from [fromlow..fromhigh] against the box,
           returning in to [0..tohigh] the first visible line segment.
           This will in general be less than the entire line, and
           fromlow will have been incremented on exit. Tohigh should be the
           maximum number of entries in to on entry, and on exit is the actual
           maximum used. By repeatedly calling this routine until it returns
           FALSE, the sequence of visible line segments can be extracted.
        *)
    
PROCEDURE ClipPolygon (fromhigh: INTEGER; VAR from: ARRAY OF RVEC;
        VAR tohigh: INTEGER; VAR to: ARRAY OF RVEC;
        VAR against: RBOX): BOOLEAN;

        (* Clips the polygon in from [0..fromhigh] against the box,
           returning the intersection polygon in to [0..tohigh]. In general,
           vertices of the polygon may be both added and deleted. On entry,
           tohigh is the maximum number of entries in to, and on exit is the
           number actually used.
        *)


END GKSClip.
