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

Incorrect result for horizontal line search #91

Closed
WinsenRC opened this issue Jun 25, 2019 · 4 comments
Closed

Incorrect result for horizontal line search #91

WinsenRC opened this issue Jun 25, 2019 · 4 comments
Labels

Comments

@WinsenRC
Copy link

Hi,
Thanks for this awesome library, with lots of cool features.

I found the search result for horizontal line is empty, might because it got a special bound box which height value is 0. Thus the RectangleUtil.outcode() always return OUT_TOP | OUT_BOTTOM.

Here's my test code:

 
RTree rtree = RTree.star().create();
Line simLine = Geometries.line(40.0d, -20.0d, 45.0d, -40.0d);
rtree = rtree.add(1, simLine);
Line segLine = Geometries.line(35.0d, -25.0d, 45.0d, -25.0d);
List> result = rtree.search(segLine)
            .toList()
            .toBlocking()
            .single();
@davidmoten
Copy link
Owner

That's interesting! The code for this is copied from java.awt.geom.Rectangle2D.Double and I notice that this fails too:

Rectangle2D.Double r = new Rectangle2D.Double(35.0d, -25.0d, 45.0d, -25.0d);
assertTrue(r.intersectsLine(40.0d, -20.0d, 45.0d, -40.0d));

Perhaps you've stumbled across a JDK bug?

@WinsenRC
Copy link
Author

I found some information from JDK API doc.

https://docs.oracle.com/javase/8/docs/api/java/awt/Rectangle.html

A Rectangle whose width or height is exactly zero has location along those axes with zero dimension, but is otherwise considered empty. The isEmpty() method will return true for such a Rectangle. Methods which test if an empty Rectangle contains or intersects a point or rectangle will always return false if either dimension is zero. Methods which combine such a Rectangle with a point or rectangle will include the location of the Rectangle on that axis in the result as if the add(Point) method were being called.

If a bound box has either zero-width or zero-height, the Java 2D would treat it as non-existence, thus any logical test gets failed on it. This behaviours might not be what we expected.

@davidmoten
Copy link
Owner

Righto, thanks for finding that doc. I guess we are going to need some new code. Perhaps we just use rectangle.intersectsLine || line.intersectsLine as the test with Java 2d code?

@davidmoten
Copy link
Owner

Fixed by #92

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