Skip to content

Commit 5b5272e

Browse files
committed
Scanline rasterization edge case fix
1 parent 5427fe8 commit 5b5272e

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

core/edge-segments.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ int QuadraticSegment::scanlineIntersections(double x[3], int dy[3], double y) co
228228
if (solutions >= 2 && t[0] > t[1])
229229
tmp = t[0], t[0] = t[1], t[1] = tmp;
230230
for (int i = 0; i < solutions && total < 2; ++i) {
231-
if (t[i] > 0 && t[i] < 1) {
231+
if (t[i] >= 0 && t[i] <= 1) {
232232
x[total] = p[0].x+2*t[i]*ab.x+t[i]*t[i]*br.x;
233233
if (nextDY*(ab.y+t[i]*br.y) >= 0) {
234234
dy[total++] = nextDY;
@@ -253,8 +253,11 @@ int QuadraticSegment::scanlineIntersections(double x[3], int dy[3], double y) co
253253
if (nextDY != (y >= p[2].y ? 1 : -1)) {
254254
if (total > 0)
255255
--total;
256-
else
256+
else {
257+
if (fabs(p[2].y-y) < fabs(p[0].y-y))
258+
x[total] = p[2].x;
257259
dy[total++] = nextDY;
260+
}
258261
}
259262
return total;
260263
}
@@ -287,7 +290,7 @@ int CubicSegment::scanlineIntersections(double x[3], int dy[3], double y) const
287290
}
288291
}
289292
for (int i = 0; i < solutions && total < 3; ++i) {
290-
if (t[i] > 0 && t[i] < 1) {
293+
if (t[i] >= 0 && t[i] <= 1) {
291294
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;
292295
if (nextDY*(ab.y+2*t[i]*br.y+t[i]*t[i]*as.y) >= 0) {
293296
dy[total++] = nextDY;
@@ -312,8 +315,11 @@ int CubicSegment::scanlineIntersections(double x[3], int dy[3], double y) const
312315
if (nextDY != (y >= p[3].y ? 1 : -1)) {
313316
if (total > 0)
314317
--total;
315-
else
318+
else {
319+
if (fabs(p[3].y-y) < fabs(p[0].y-y))
320+
x[total] = p[3].x;
316321
dy[total++] = nextDY;
322+
}
317323
}
318324
return total;
319325
}

0 commit comments

Comments
 (0)