Adjacent Rectangles intersect.

Create issue
Issue #33 new
Former user created an issue

If we have two rectangles, r1 and r2, such that

r1 = new Rectangle(60,60,20,20); r2 = new Rectangle(80,60,20,20);

r1.intersects(r2) returns true; r2.intersects(r1) also returns true.

This doesn't seem quite right to me.

Comments (2)

  1. Bengt Ericsson

    Well, they are intersecting!

    If the second rectangle would be place at (81, 60) then they wouldn't intersect.

    60+20 = 80, which means that they intersect. You need to add +1 to x position of the second triangle, or -1 to the width of the first, for them not to intersect. This is common practice through all graphics libraries.

  2. Adam Badawy

    No, you're entirely incorrect. When I create a new rectangle, the constructor parameters are x-position, y-position, width, and height. If I make a rectangle like so:

    Rectangle r1 = new Rectangle(0,0,20,16);

    This means that the rectangle will occupy all positions from x = 0 to x = 19 (20 pixels, the width) and y = 0 to y = 15 (16 pixels, the height).

    Furthermore, if my game is tiled 20x20, my walls should have a width and height of 20 without intersecting each other.

    Can you point me to what graphics library has this illogical practice?

  3. Log in to comment