Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rectangle.contains produces incorrect results #227

Closed
BenjaminAmos opened this issue Apr 26, 2020 · 1 comment
Closed

Rectangle.contains produces incorrect results #227

BenjaminAmos opened this issue Apr 26, 2020 · 1 comment
Labels

Comments

@BenjaminAmos
Copy link

The Rectangle.contains methods appear to be using some subtly incorrect logic. Currently it is:

return x >= minX && y >= minX && x < maxX && y < maxY;

return x >= minX && y >= minX && x < maxX && y < maxY;

return x >= minX && y >= minX && x < maxX && y < maxY;

But it should be:

return x >= minX && y >= minY && x < maxX && y < maxY; 

The y >= minX part is incorrect, as it is comparing separate axes together, which was probably not intended. This leads to incorrect results being produced.

The following test case should reproduce the issue:

public class RectangleContainsTest extends TestCase {
    public static void testContainsWithInsidePoint () {
        Rectangled testA = new Rectangled (-5, -10, +5, +10);
        Rectanglef testB = new Rectanglef (-5, -10, +5, +10);
        Rectanglei testC = new Rectanglei (-5, -10, +5, +10);

        assertTrue (testA.contains(+4, -6));
        assertTrue (testB.contains(+4, -6));
        assertTrue (testC.contains(+4, -6));
    }
}
@httpdigest httpdigest added the bug label Apr 26, 2020
@httpdigest httpdigest added this to the 1.9.25 release milestone Apr 26, 2020
@httpdigest
Copy link
Member

Thanks for reporting this! Fix will be up shortly as new 1.9.25-SNAPSHOT version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants