-
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
Point in triangle and rect performance improvements #1057
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
730fc39
Improve perf for triangle contains point
b4l fc132ad
Improve perf for triangle intersects point
b4l d06e5f0
Improve coordinate position for rect and triangle
b4l 3b70fe6
Inline point intersects rect
b4l 6f838a5
Simplify polygon intersects coord
b4l f446ad6
Add benches
b4l 617cddc
Merge branch 'main' into triangle
urschrei cdc1df3
Fix benchmark imports
urschrei 369f663
Merge branch 'main' into triangle
urschrei 17bd4cc
Use robust predicates
b4l a71eb13
Apply clippy fixes
b4l dc70bb7
Add changelog entry
b4l 6bf3f31
Merge branch 'main' into triangle
b4l 654af8b
Merge branch 'main' into triangle
frewsxcv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#[macro_use] | ||
extern crate criterion; | ||
extern crate geo; | ||
|
||
use geo::{ | ||
coordinate_position::CoordPos, BoundingRect, Centroid, CoordinatePosition, Point, Rect, | ||
Triangle, | ||
}; | ||
|
||
use criterion::Criterion; | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
c.bench_function("Point position to rect", |bencher| { | ||
let plot_centroids: Vec<Point> = geo_test_fixtures::nl_plots() | ||
.iter() | ||
.map(|plot| plot.centroid().unwrap()) | ||
.collect(); | ||
let zone_bbox: Vec<Rect> = geo_test_fixtures::nl_zones() | ||
.iter() | ||
.map(|plot| plot.bounding_rect().unwrap()) | ||
.collect(); | ||
bencher.iter(|| { | ||
let mut inside = 0; | ||
let mut outsied = 0; | ||
let mut boundary = 0; | ||
|
||
for a in &plot_centroids { | ||
for b in &zone_bbox { | ||
match criterion::black_box(b).coordinate_position(criterion::black_box(&a.0)) { | ||
CoordPos::OnBoundary => boundary += 1, | ||
CoordPos::Inside => inside += 1, | ||
CoordPos::Outside => outsied += 1, | ||
} | ||
} | ||
} | ||
|
||
assert_eq!(inside, 2246); | ||
assert_eq!(outsied, 26510); | ||
assert_eq!(boundary, 0); | ||
}); | ||
}); | ||
|
||
c.bench_function("Point in triangle", |bencher| { | ||
let triangle = Triangle::from([(0., 0.), (10., 0.), (5., 10.)]); | ||
let point = Point::new(5., 5.); | ||
|
||
bencher.iter(|| { | ||
assert!( | ||
criterion::black_box(&triangle).coordinate_position(criterion::black_box(&point.0)) | ||
!= CoordPos::Outside | ||
); | ||
}); | ||
}); | ||
|
||
c.bench_function("Point on triangle boundary", |bencher| { | ||
let triangle = Triangle::from([(0., 0.), (10., 0.), (6., 10.)]); | ||
let point = Point::new(3., 5.); | ||
|
||
bencher.iter(|| { | ||
assert!( | ||
criterion::black_box(&triangle).coordinate_position(criterion::black_box(&point.0)) | ||
== CoordPos::OnBoundary | ||
); | ||
}); | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Let's go with this impl. if it's correct, rather than the non-robust one.
For quick intro. to robust, you may want to refer this example that explains why it's important.