Fixed bug 2012 - Algorithm logic getting wrong in ComputeOutCode
authorSam Lantinga <slouken@libsdl.org>
Mon, 21 Oct 2013 00:25:43 -0700
changeset 7868 f92ba4923dcd
parent 7867 d9d50f52a686
child 7869 6871ab38d224
Fixed bug 2012 - Algorithm logic getting wrong in ComputeOutCode Nitz I was going through the SDL_IntersectRectAndLine function and wondered to see the ComputeOutCode function implementation. The problem in this algo is, x and y axis are getting check with respect to 0, Which is wrong, it should be get checked with respect to rectangle x and y axis.
src/video/SDL_rect.c
--- a/src/video/SDL_rect.c	Mon Oct 21 00:22:07 2013 -0700
+++ b/src/video/SDL_rect.c	Mon Oct 21 00:25:43 2013 -0700
@@ -296,15 +296,16 @@
 #define CODE_LEFT   4
 #define CODE_RIGHT  8
 
-static int ComputeOutCode(const SDL_Rect * rect, int x, int y)
+static int
+ComputeOutCode(const SDL_Rect * rect, int x, int y)
 {
     int code = 0;
-    if (y < 0) {
+    if (y < rect->y) {
         code |= CODE_TOP;
     } else if (y >= rect->y + rect->h) {
         code |= CODE_BOTTOM;
     }
-    if (x < 0) {
+    if (x < rect->x) {
         code |= CODE_LEFT;
     } else if (x >= rect->x + rect->w) {
         code |= CODE_RIGHT;