--- ray/src/common/clip.c 1991/11/12 17:00:44 2.1 +++ ray/src/common/clip.c 2003/02/25 02:47:21 2.4 @@ -1,24 +1,25 @@ -/* 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 */ FLOAT *ep1, *ep2; FVECT min, max; { + int itlim = MAXITER; int loc1, loc2; int accept; FLOAT *dp; @@ -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;