Skip to content

Commit

Permalink
Scanline rasterization edge case fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Chlumsky committed Mar 8, 2020
1 parent 5427fe8 commit 5b5272e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions core/edge-segments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ int QuadraticSegment::scanlineIntersections(double x[3], int dy[3], double y) co
if (solutions >= 2 && t[0] > t[1])
tmp = t[0], t[0] = t[1], t[1] = tmp;
for (int i = 0; i < solutions && total < 2; ++i) {
if (t[i] > 0 && t[i] < 1) {
if (t[i] >= 0 && t[i] <= 1) {
x[total] = p[0].x+2*t[i]*ab.x+t[i]*t[i]*br.x;
if (nextDY*(ab.y+t[i]*br.y) >= 0) {
dy[total++] = nextDY;
Expand All @@ -253,8 +253,11 @@ int QuadraticSegment::scanlineIntersections(double x[3], int dy[3], double y) co
if (nextDY != (y >= p[2].y ? 1 : -1)) {
if (total > 0)
--total;
else
else {
if (fabs(p[2].y-y) < fabs(p[0].y-y))
x[total] = p[2].x;
dy[total++] = nextDY;
}
}
return total;
}
Expand Down Expand Up @@ -287,7 +290,7 @@ int CubicSegment::scanlineIntersections(double x[3], int dy[3], double y) const
}
}
for (int i = 0; i < solutions && total < 3; ++i) {
if (t[i] > 0 && t[i] < 1) {
if (t[i] >= 0 && t[i] <= 1) {
x[total] = p[0].x+3*t[i]*ab.x+3*t[i]*t[i]*br.x+t[i]*t[i]*t[i]*as.x;
if (nextDY*(ab.y+2*t[i]*br.y+t[i]*t[i]*as.y) >= 0) {
dy[total++] = nextDY;
Expand All @@ -312,8 +315,11 @@ int CubicSegment::scanlineIntersections(double x[3], int dy[3], double y) const
if (nextDY != (y >= p[3].y ? 1 : -1)) {
if (total > 0)
--total;
else
else {
if (fabs(p[3].y-y) < fabs(p[0].y-y))
x[total] = p[3].x;
dy[total++] = nextDY;
}
}
return total;
}
Expand Down

0 comments on commit 5b5272e

Please sign in to comment.