We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2012 - Algorithm logic getting wrong in ComputeOutCode
Summary: Algorithm logic getting wrong in ComputeOutCode
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.0
Hardware: x86 Linux
: P2 blocker
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-06 02:02 UTC by Nitz
Modified: 2013-10-21 07:26 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nitz 2013-08-06 02:02:29 UTC
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!
Comment 1 Sam Lantinga 2013-10-21 07:26:19 UTC
Fixed, thanks!
http://hg.libsdl.org/SDL/rev/f92ba4923dcd