From 5b5272e7a8bd71a6c7f55951659df69a355486c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Chlumsk=C3=BD?= Date: Sun, 8 Mar 2020 23:34:51 +0100 Subject: [PATCH] Scanline rasterization edge case fix --- core/edge-segments.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/edge-segments.cpp b/core/edge-segments.cpp index c57d783f..0bdaaaac 100644 --- a/core/edge-segments.cpp +++ b/core/edge-segments.cpp @@ -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; @@ -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; } @@ -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; @@ -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; }