--- ray/src/common/clip.c 1989/02/02 10:33:01 1.1 +++ ray/src/common/clip.c 1993/12/19 22:49:28 2.2 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1993 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -10,16 +10,21 @@ static char SCCSid[] = "$SunId$ LBL"; * 8/28/85 */ +#include "fvect.h" + #include "plocate.h" +#define MAXITER 6 /* maximum possible number of iterations */ + 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 +44,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;