--- ray/src/common/clip.c 1989/02/02 10:33:01 1.1 +++ ray/src/common/clip.c 2003/02/25 02:47:21 2.4 @@ -1,25 +1,28 @@ -/* Copyright (c) 1986 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: clip.c,v 2.4 2003/02/25 02:47:21 greg Exp $"; #endif - /* * clip.c - routine to clip 3D line segments to a box. - * - * 8/28/85 */ +#include "copyright.h" + +#include "fvect.h" + #include "plocate.h" +#define MAXITER 6 /* maximum possible number of iterations */ + +int clip(ep1, ep2, min, max) /* clip a line segment to a box */ -double *ep1, *ep2; -double min[3], max[3]; +FLOAT *ep1, *ep2; +FVECT min, max; { + int itlim = MAXITER; int loc1, loc2; int accept; - double *dp; + FLOAT *dp; double d; register int i, j; @@ -39,6 +42,9 @@ double min[3], max[3]; while (!((accept = !(loc1 | loc2)) || (loc1 & loc2))) { + if (itlim-- <= 0) /* past theoretical limit? */ + return(0); /* quit fooling around */ + if (!loc1) { /* make sure first point is outside */ dp = ep1; ep1 = ep2; ep2 = dp; i = loc1; loc1 = loc2; loc2 = i;