Skip to content

Commit

Permalink
fix: Added explicit edge tests to eliminate light leaks at corners
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregungory committed Feb 12, 2021
1 parent 6308d95 commit cdd6e14
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/common/face.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static const char RCSid[] = "$Id: face.c,v 2.14 2020/06/14 02:10:44 greg Exp $";
static const char RCSid[] = "$Id: face.c,v 2.15 2021/02/12 00:47:33 greg Exp $";
#endif
/*
* face.c - routines dealing with polygonal faces.
Expand Down Expand Up @@ -98,7 +98,7 @@ getface( /* get arguments for a face */
if (f->nv > 3 && badvert)
objerror(o, WARNING, "non-planar vertex");
/* find axis */
f->ax = fabs(f->norm[0]) > fabs(f->norm[1]) ? 0 : 1;
f->ax = (fabs(f->norm[0]) > fabs(f->norm[1]));
if (fabs(f->norm[2]) > fabs(f->norm[f->ax]))
f->ax = 2;

Expand Down Expand Up @@ -144,11 +144,17 @@ inface( /* determine if point is in face */
tst = (p0[xi] > x) + (p1[xi] > x);
if (tst == 2)
ncross++;
else if (tst)
ncross += (p1[yi] > p0[yi]) ^
((p0[yi]-y)*(p1[xi]-x) >
(p0[xi]-x)*(p1[yi]-y));
}
else if (tst) {
double prodA = (p0[yi]-y)*(p1[xi]-x);
double prodB = (p0[xi]-x)*(p1[yi]-y);
if (FRELEQ(prodA, prodB))
return(1); /* edge case #1 */
ncross += (p1[yi] > p0[yi]) ^ (prodA > prodB);
} else if (FRELEQ(p0[xi], x) && FRELEQ(p1[xi], x))
return(1); /* edge case #2 */
} else if (FRELEQ(p0[yi], y) && FRELEQ(p1[yi], y) &&
(p0[xi] > x) ^ (p1[xi] > x))
return(1); /* edge case #3 */
p0 = p1;
p1 += 3;
}
Expand Down

0 comments on commit cdd6e14

Please sign in to comment.