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

From 1f32dd8edcf2a7882378e5ff6d616d0382103c9c Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 9 Jan 2022 06:36:18 -0800
Subject: [PATCH] Fixed overdraw with duplicate points, fixed not drawing
 single point lines

---
 src/render/SDL_render.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index dfbcbe3f566..7f3e32e5067 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) {