--- ray/src/common/face.c 1996/03/22 09:01:16 2.5 +++ ray/src/common/face.c 2003/03/12 17:26:58 2.8 @@ -1,15 +1,12 @@ -/* Copyright (c) 1995 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: face.c,v 2.8 2003/03/12 17:26:58 greg Exp $"; #endif - /* * face.c - routines dealing with polygonal faces. - * - * 8/30/85 */ +#include "copyright.h" + #include "standard.h" #include "object.h" @@ -104,6 +101,7 @@ OBJREC *o; } +void freeface(o) /* free memory associated with face */ OBJREC *o; { @@ -114,12 +112,14 @@ OBJREC *o; } +int inface(p, f) /* determine if point is in face */ FVECT p; FACE *f; { int ncross, n; double x, y; + int tst; register int xi, yi; register FLOAT *p0, *p1; @@ -133,13 +133,15 @@ FACE *f; ncross = 0; /* positive x axis cross test */ while (n--) { - if ((p0[yi] > y) ^ (p1[yi] > y)) - if (p0[xi] > x && p1[xi] > x) + if ((p0[yi] > y) ^ (p1[yi] > y)) { + tst = (p0[xi] > x) + (p1[xi] > x); + if (tst == 2) ncross++; - else if (p0[xi] > x || p1[xi] > x) + else if (tst) ncross += (p1[yi] > p0[yi]) ^ ((p0[yi]-y)*(p1[xi]-x) > (p0[xi]-x)*(p1[yi]-y)); + } p0 = p1; p1 += 3; }