-
Notifications
You must be signed in to change notification settings - Fork 199
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
Reimplement coord_pos_relative_to_ring using wn algo #972
Conversation
Getting 6 test failures which I'm as of yet mystified about. |
Found the problem, was porting error. Then I found that I could use some preexisting bits of code instead. |
Looks like this improves performance significantly (~40% !) at least for the intersection bench. My results:
|
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.
Just a minor query from me
@@ -100,7 +100,7 @@ where | |||
// Helper function to check point lies inside rect given by | |||
// bounds. The first bound need not be min. | |||
#[inline] | |||
fn point_in_rect<T>(value: Coord<T>, bound_1: Coord<T>, bound_2: Coord<T>) -> bool | |||
pub fn point_in_rect<T>(value: Coord<T>, bound_1: Coord<T>, bound_2: Coord<T>) -> bool |
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.
Can this be made pub crate
?
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.
doesn't appear so on naive try
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.
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.
This is really exciting, thanks @bjornhartell!
I'm running some benches locally, because I want to see how it affects other algorithms, like the GeometryGraph stuff, which has a pretty comprehensive test suite (lifted from JTS) and uses Intersects under the hood.
} | ||
} | ||
if crossings % 2 == 1 { | ||
if wn != 0 { |
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.
Clarity nit: it's a tiny bit easier to read this without the negation:
if wn == 0 {
CoordPos::Outside
} else {
CoordPos::Inside
}
let mut crossings = 0; | ||
// Use winding number algorithm with on boundary short-cicuit | ||
// See: https://en.wikipedia.org/wiki/Point_in_polygon#Winding_number_algorithm | ||
let mut wn = 0; |
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.
Please prefer more explicable names, unless it's extremely local (like a one line closure):
let mut wn = 0; | |
let mut winding_number = 0; |
As well as a 40-50% improvement for our I did see some regressions across the boolean-ops benches. Is anyone else able to reproduce?: bench snippet
I'm not sure what accounts for it. Note the bops benchs are currently mislabled |
Those regressions are very surprising – I can't think of any obvious explanation. @rmanoka any ideas about what could be going on? |
I'm actually really skeptical of my results on that bops bench. For example, I think these "regressed" benches are actually testing an old unchanged version of geo-types (via the Maybe it's just ghosts in the machine... 👻 |
Yeah actually, I don't have any concerns about the boolean ops "regressions" relating to this PR. I think it's just spurious. I did: pub fn coord_pos_relative_to_ring<T>(coord: Coord<T>, linestring: &LineString<T>) -> CoordPos
where
T: GeoNum,
{
+ panic!("in coord_pos_relative_to_ring");
|
bors r+ |
Build succeeded: |
Ugh I saw the approve and didn't pay attention to the nits. I'll clean those up in the morning. |
No worries! If it was anything I felt strongly about I wouldn't have marked it as "approved". |
I did this in #975. |
975: fix nits from #972 r=urschrei a=michaelkirk - [x] I agree to follow the project's [code of conduct](https://github.com/georust/geo/blob/main/CODE_OF_CONDUCT.md). - [x] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users. --- Co-authored-by: Michael Kirk <michael.code@endoftheworl.de>
Doing this mostly for fun but AFAIK the winding number algo is superior to the ray-intersection algo.