Adjacent Rectangles intersect.

Anonymous avatarAnonymous 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. Zolomon

    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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.