--- ray/src/common/clip.c 1991/10/23 13:43:31 1.2 +++ ray/src/common/clip.c 2003/06/26 00:58:09 2.5 @@ -1,27 +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.5 2003/06/26 00:58:09 schorsch 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 */ -FLOAT *ep1, *ep2; +RREAL *ep1, *ep2; FVECT min, max; { + int itlim = MAXITER; int loc1, loc2; int accept; - FLOAT *dp; + RREAL *dp; double d; register int i, j; @@ -41,6 +42,9 @@ FVECT min, max; 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;