Fixed overdraw with duplicate points, fixed not drawing single point lines
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index dfbcbe3..7f3e32e 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -2951,6 +2951,7 @@ RenderDrawLinesWithRectsF(SDL_Renderer * renderer,
int i, nrects = 0;
int retval = 0;
SDL_bool isstack;
+ SDL_bool drew_line = SDL_FALSE;
SDL_bool draw_last = SDL_FALSE;
frects = SDL_small_alloc(SDL_FRect, count-1, &isstack);
@@ -2959,12 +2960,19 @@ RenderDrawLinesWithRectsF(SDL_Renderer * renderer,
}
for (i = 0; i < count-1; ++i) {
- if (i == count-2) {
- if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
+ SDL_bool same_x = (points[i].x == points[i+1].x);
+ 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;
}
+ } 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 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) {
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 maxX = SDL_max(points[i].x, points[i+1].x);
@@ -2991,6 +2999,7 @@ RenderDrawLinesWithRectsF(SDL_Renderer * renderer,
} else {
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) {