1 |
– |
/* Copyright (c) 1986 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* clip.c - routine to clip 3D line segments to a box. |
9 |
– |
* |
10 |
– |
* 8/28/85 |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
|
#include "fvect.h" |
11 |
|
|
12 |
|
#include "plocate.h" |
13 |
|
|
14 |
+ |
#define MAXITER 6 /* maximum possible number of iterations */ |
15 |
|
|
16 |
+ |
|
17 |
+ |
int |
18 |
|
clip(ep1, ep2, min, max) /* clip a line segment to a box */ |
19 |
|
FLOAT *ep1, *ep2; |
20 |
|
FVECT min, max; |
21 |
|
{ |
22 |
+ |
int itlim = MAXITER; |
23 |
|
int loc1, loc2; |
24 |
|
int accept; |
25 |
|
FLOAT *dp; |
42 |
|
|
43 |
|
while (!((accept = !(loc1 | loc2)) || (loc1 & loc2))) { |
44 |
|
|
45 |
+ |
if (itlim-- <= 0) /* past theoretical limit? */ |
46 |
+ |
return(0); /* quit fooling around */ |
47 |
+ |
|
48 |
|
if (!loc1) { /* make sure first point is outside */ |
49 |
|
dp = ep1; ep1 = ep2; ep2 = dp; |
50 |
|
i = loc1; loc1 = loc2; loc2 = i; |