Scanline rasterization edge case fix

This commit is contained in:
Viktor Chlumský 2020-03-08 23:34:51 +01:00
parent 5427fe8f5a
commit 5b5272e7a8
1 changed files with 10 additions and 4 deletions

View File

@ -228,7 +228,7 @@ int QuadraticSegment::scanlineIntersections(double x[3], int dy[3], double y) co
if (solutions >= 2 && t[0] > t[1]) if (solutions >= 2 && t[0] > t[1])
tmp = t[0], t[0] = t[1], t[1] = tmp; tmp = t[0], t[0] = t[1], t[1] = tmp;
for (int i = 0; i < solutions && total < 2; ++i) { 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; 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) { if (nextDY*(ab.y+t[i]*br.y) >= 0) {
dy[total++] = nextDY; 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 (nextDY != (y >= p[2].y ? 1 : -1)) {
if (total > 0) if (total > 0)
--total; --total;
else else {
if (fabs(p[2].y-y) < fabs(p[0].y-y))
x[total] = p[2].x;
dy[total++] = nextDY; dy[total++] = nextDY;
}
} }
return total; 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) { 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; 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) { if (nextDY*(ab.y+2*t[i]*br.y+t[i]*t[i]*as.y) >= 0) {
dy[total++] = nextDY; 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 (nextDY != (y >= p[3].y ? 1 : -1)) {
if (total > 0) if (total > 0)
--total; --total;
else else {
if (fabs(p[3].y-y) < fabs(p[0].y-y))
x[total] = p[3].x;
dy[total++] = nextDY; dy[total++] = nextDY;
}
} }
return total; return total;
} }