-
Notifications
You must be signed in to change notification settings - Fork 205
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
Polygon in Rect performance improvements #1192
Conversation
I suspect you're right that some of our predicates could be optimized for Rects, but A couple of cases that seem like they might be wrong with your implementation:
|
Thank you so much! This is exactly the kind of feedback I was hoping for! 👍 You're right that my first implementation was inconsistent to what I had a look at the DE-9IM again and AFAICT I've now implemented it correctly.
The new implementation is slightly slower than my first try, but still much faster than the original one: Before:
After:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you've done it, by jove.
I'm going to leave this open for a couple days in case anyone else wants to weigh in. This stuff is really tricky. But this is a big win!
I wonder if using edit: For the record, I'd be more than happy to merge this as is, but just food for thought if you're thinking about pursuing more work like this. |
Thanks for the review. I've integrated your comments.
Maybe ... but then we'd have to go through the points again to check if they lie inside the rectangle's interior. The way it is now, we can just use one for loop.
Yes, it would be fun to optimize this predicate for the other geometry types as well. If it's not too much trouble for you, I'd prefer if you could merge this PR first. I'll create a new PR for the other geometries in the next few weeks. |
This is a delightful improvement! |
CHANGES.md
if knowledge of this change could be valuable to users.This PR improves the performance of the
Polygon
inRect
check:Before:
After:
I have an application where I need to perform this check millions of times and this small improvement shaves off several seconds for me.
I think the same can be done for the other geometry types (
LineString
inRect
,MultiPolygon
inRect
, etc.), but I wanted to get your feedback on this one first.