Fixed overdraw with duplicate points, fixed not drawing single point lines

This commit is contained in:
Sam Lantinga 2022-01-09 06:36:18 -08:00
parent 5d07c03613
commit 1f32dd8edc
1 changed files with 13 additions and 4 deletions

View File

@ -2951,6 +2951,7 @@ RenderDrawLinesWithRectsF(SDL_Renderer * renderer,
int i, nrects = 0; int i, nrects = 0;
int retval = 0; int retval = 0;
SDL_bool isstack; SDL_bool isstack;
SDL_bool drew_line = SDL_FALSE;
SDL_bool draw_last = SDL_FALSE; SDL_bool draw_last = SDL_FALSE;
frects = SDL_small_alloc(SDL_FRect, count-1, &isstack); frects = SDL_small_alloc(SDL_FRect, count-1, &isstack);
@ -2959,12 +2960,19 @@ RenderDrawLinesWithRectsF(SDL_Renderer * renderer,
} }
for (i = 0; i < count-1; ++i) { for (i = 0; i < count-1; ++i) {
if (i == count-2) { SDL_bool same_x = (points[i].x == points[i+1].x);
if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) { SDL_bool same_y = (points[i].y == points[i+1].y);
if (i == (count - 2)) {
if (!drew_line || points[i+1].x != points[0].x || points[i+1].y != points[0].y) {
draw_last = SDL_TRUE; draw_last = SDL_TRUE;
} }
} else {
if (same_x && same_y) {
continue;
} }
if (points[i].x == points[i+1].x) { }
if (same_x) {
const float minY = SDL_min(points[i].y, points[i+1].y); const float minY = SDL_min(points[i].y, points[i+1].y);
const float maxY = SDL_max(points[i].y, points[i+1].y); const float maxY = SDL_max(points[i].y, points[i+1].y);
@ -2976,7 +2984,7 @@ RenderDrawLinesWithRectsF(SDL_Renderer * renderer,
if (!draw_last && points[i+1].y < points[i].y) { if (!draw_last && points[i+1].y < points[i].y) {
frect->y += scale_y; frect->y += scale_y;
} }
} else if (points[i].y == points[i+1].y) { } else if (same_y) {
const float minX = SDL_min(points[i].x, points[i+1].x); const float minX = SDL_min(points[i].x, points[i+1].x);
const float maxX = SDL_max(points[i].x, points[i+1].x); const float maxX = SDL_max(points[i].x, points[i+1].x);
@ -2991,6 +2999,7 @@ RenderDrawLinesWithRectsF(SDL_Renderer * renderer,
} else { } else {
retval += plotLineBresenham(renderer, points[i].x, points[i].y, points[i+1].x, points[i+1].y, draw_last); retval += plotLineBresenham(renderer, points[i].x, points[i].y, points[i+1].x, points[i+1].y, draw_last);
} }
drew_line = SDL_TRUE;
} }
if (nrects) { if (nrects) {