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

chore(geom): make Rectangle implementations consistent #22

Merged
merged 7 commits into from
Feb 20, 2021

Conversation

skaldarnar
Copy link
Member

@skaldarnar skaldarnar commented Feb 14, 2021

  • chore((Rectangleic, Rectanglefc, Rectangledc): align immutable interface classes
  • feat(Rectanglei): add missing API variants
  • style(Rectanglei): sort implementations according to interface
  • refactor(Rectanglei): use more forwarding instead of duplicate implementation

- chore((Rectangleic, Rectanglefc, Rectangledc): align immutable interface classes
- feat(Rectanglei): add missing API variants
- chore(Rectanglei): sort implementations according to interface
- refactor(Rectanglei): use more forwarding instead of duplicate implementations
Comment on lines 643 to 644
long dx = java.lang.Math.max(java.lang.Math.abs(2 * px - cx2) - getSizeX(), 0) / 2;
long dy = java.lang.Math.max(java.lang.Math.abs(2 * py - cy2) - getSizeY(), 0) / 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we using java.lang.Man.max I would use the one offered under joml.

Comment on lines 239 to 245
/**
* Check if this rectangle contains the given <code>point</code>.
*
* @param point
* the point to test
* @param point the point to test
* @return <code>true</code> iff this rectangle contains the point; <code>false</code> otherwise
*/
boolean containsPoint(Vector2ic point);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kind of hesitant about this function. might be a bit better to only accepting the floating point variations. did we decided if the edge of a Rectanglei is inclusive. to an extent the intersects is in a similar situation. is a rectangle intersecting if its only the edge? wonder if it would be better to just leave it up to the person using this rather then proving some concrete method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly the reasoning why this moved out of JOML and into our org. I think we should define the behavior to be used for Terasology so that we don't have any confusion about it throughout the code base.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used in BrowserWidget, DistrictOverlay and MinimapIconOverlay.

Copy link
Member Author

@skaldarnar skaldarnar Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about properties that should hold:

assertTrue(rect.contains(rect)); // rectangle should contain itself

Now I'm wondering which parts of the rectangle are inclusive and which are exclusive. I don't think we have to think about the edges on it's own, but only about the min and max corner:

assertTrue(rect.contains(rect.getMin(new Vector2i()));
assertTrue(rect.contains(rect.getMax(new Vector2i()));
// currently both hold	

If both are true, then there's an overlap/intersection between two rectangles right next to each other. If only one is, you can "tile" touching rectangles without intersection.

Rectanglei rectA = new Rectanglei(0, 0, 1, 1);
Rectanglei rectB = new Rectanglei(0, 1, 1, 2);

assertTrue(rectA.intersectsRectangle(rectB));
assertEquals(new Rectanglei(0, 1, 1, 1), rectA.intersection(rectB, new Rectanglei());

Given that one of the corners is exclusive, this would mean that a rectangle created from a point does not contain the point:

assertFalse(new Rectanglei(point).contains(point));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Started #23 for writing tests on Rectanglei to verify whatever our contract is going to be. Also gives an insight on how the current implementation behaves...

@jdrueckert jdrueckert merged commit 144ddb5 into main Feb 20, 2021
@jdrueckert jdrueckert deleted the chore/consistent-api-for-rectangle branch February 20, 2021 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants