--- ray/src/common/face.c 2003/03/14 21:27:45 2.9 +++ ray/src/common/face.c 2016/09/16 15:09:21 2.13 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: face.c,v 2.9 2003/03/14 21:27:45 greg Exp $"; +static const char RCSid[] = "$Id: face.c,v 2.13 2016/09/16 15:09:21 greg Exp $"; #endif /* * face.c - routines dealing with polygonal faces. @@ -32,14 +32,15 @@ static const char RCSid[] = "$Id: face.c,v 2.9 2003/03 FACE * -getface(o) /* get arguments for a face */ -OBJREC *o; +getface( /* get arguments for a face */ + OBJREC *o +) { double d1; - int badvert; + int smalloff, badvert; FVECT v1, v2, v3; - register FACE *f; - register int i; + FACE *f; + int i; if ((f = (FACE *)o->os) != NULL) return(f); /* already done */ @@ -84,9 +85,13 @@ OBJREC *o; /* compute offset */ badvert = 0; f->offset = DOT(f->norm, VERTEX(f,0)); + smalloff = fabs(f->offset) <= VERTEPS; for (i = 1; i < f->nv; i++) { d1 = DOT(f->norm, VERTEX(f,i)); - badvert += fabs(1.0 - d1*i/f->offset) > VERTEPS; + if (smalloff) + badvert += fabs(d1 - f->offset/i) > VERTEPS; + else + badvert += fabs(1.0 - d1*i/f->offset) > VERTEPS; f->offset += d1; } f->offset /= (double)f->nv; @@ -102,8 +107,9 @@ OBJREC *o; void -freeface(o) /* free memory associated with face */ -OBJREC *o; +freeface( /* free memory associated with face */ + OBJREC *o +) { if (o->os == NULL) return; @@ -113,18 +119,19 @@ OBJREC *o; int -inface(p, f) /* determine if point is in face */ -FVECT p; -FACE *f; +inface( /* 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; + int xi, yi; + RREAL *p0, *p1; - xi = (f->ax+1)%3; - yi = (f->ax+2)%3; + if ((xi = f->ax + 1) >= 3) xi -= 3; + if ((yi = xi + 1) >= 3) yi -= 3; x = p[xi]; y = p[yi]; n = f->nv;