SDL: Fixed Cohen-Sutherland out code computation for float line intersection

From d7be7fc168f2077accfe12a0de376082a1650b29 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 13 Oct 2024 12:44:02 -0700
Subject: [PATCH] Fixed Cohen-Sutherland out code computation for float line
 intersection

Fixes https://github.com/libsdl-org/SDL/issues/10866
---
 src/video/SDL_rect_impl.h  |  4 ++--
 test/testautomation_rect.c | 11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/video/SDL_rect_impl.h b/src/video/SDL_rect_impl.h
index 8ed8f84e6e899..46d56ea06601e 100644
--- a/src/video/SDL_rect_impl.h
+++ b/src/video/SDL_rect_impl.h
@@ -297,12 +297,12 @@ static int COMPUTEOUTCODE(const RECTTYPE *rect, SCALARTYPE x, SCALARTYPE y)
     int code = 0;
     if (y < rect->y) {
         code |= CODE_TOP;
-    } else if (y >= rect->y + rect->h) {
+    } else if (y > (rect->y + rect->h - ENCLOSEPOINTS_EPSILON)) {
         code |= CODE_BOTTOM;
     }
     if (x < rect->x) {
         code |= CODE_LEFT;
-    } else if (x >= rect->x + rect->w) {
+    } else if (x > (rect->x + rect->w - ENCLOSEPOINTS_EPSILON)) {
         code |= CODE_RIGHT;
     }
     return code;
diff --git a/test/testautomation_rect.c b/test/testautomation_rect.c
index 5c278e295e04e..34673705a2d8a 100644
--- a/test/testautomation_rect.c
+++ b/test/testautomation_rect.c
@@ -93,6 +93,17 @@ static int SDLCALL rect_testIntersectRectAndLineFloat(void *arg)
     intersected = SDL_GetRectAndLineIntersectionFloat(&rect, &x1, &y1, &x2, &y2);
     validateIntersectRectAndLineFloatResults(intersected, true, &rect, x1, y1, x2, y2, 2.5f, 6.0f, 2.75f, 6.0f);
 
+    x1 = 456.0f;
+    y1 = 592.0f;
+    x2 = 160.0f;
+    y2 = 670.0f;
+    rect.x = 300.0f;
+    rect.y = 592.0f;
+    rect.w = 64.0f;
+    rect.h = 64.0f;
+    intersected = SDL_GetRectAndLineIntersectionFloat(&rect, &x1, &y1, &x2, &y2);
+    validateIntersectRectAndLineFloatResults(intersected, true, &rect, x1, y1, x2, y2, 364.0f, 616.243225f, 300.0f, 633.108093f);
+
     return TEST_COMPLETED;
 }