| Summary: | Algorithm logic getting wrong in ComputeOutCode | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Nitz <nitin.j4> |
| Component: | video | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | blocker | ||
| Priority: | P2 | ||
| Version: | 2.0.0 | ||
| Hardware: | x86 | ||
| OS: | Linux | ||
Fixed, thanks! http://hg.libsdl.org/SDL/rev/f92ba4923dcd |
I was going through the SDL_IntersectRectAndLine function and wondered to see the ComputeOutCode function implementation. Currently the function is: static int ComputeOutCode(const SDL_Rect * rect, int x, int y) { int code = 0; if (y < 0) { code |= CODE_TOP; } else if (y >= rect->y + rect->h) { code |= CODE_BOTTOM; } if (x < 0) { code |= CODE_LEFT; } else if (x >= rect->x + rect->w) { code |= CODE_RIGHT; } return code; } 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. Modified code should be: static int ComputeOutCode(const SDL_Rect * rect, int x, int y) { int code = 0; if (y < rect->y) { code |= CODE_TOP; } else if (y >= rect->y + rect->h) { code |= CODE_BOTTOM; } if (x < rect->x) { code |= CODE_LEFT; } else if (x >= rect->x + rect->w) { code |= CODE_RIGHT; } return code; } Thanks!