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

Iterate over points using windows instead of zip #50

Merged
merged 2 commits into from
Jul 23, 2016

Conversation

zarch
Copy link
Contributor

@zarch zarch commented Jul 22, 2016

Use windows instead of zip to iterate over points. It seems also slightly faster from my bench.

running 2 tests
test bench_win ... bench: 154,231,376 ns/iter (+/- 9,710,675)
test bench_zip ... bench: 173,904,730 ns/iter (+/- 61,305,779)

@@ -25,8 +25,8 @@ fn get_linestring_area<T>(linestring: &LineString<T>) -> T where T: Float {
return T::zero();
}
let mut tmp = T::zero();
for (p1, p2) in linestring.0.iter().zip(linestring.0[1..].iter()) {
tmp = tmp + (p1.x() * p2.y() - p2.x() * p1.y());
for ps in linestring.0.windows(2).into_iter() {
Copy link
Member

Choose a reason for hiding this comment

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

FYI, you should be able to just do for ps in linestring.0.windows(2) here. Using a for loop will automatically call IntoIterator for the item being interated over

https://doc.rust-lang.org/std/iter/index.html#for-loops-and-intoiterator

@frewsxcv
Copy link
Member

Thanks! It's great that simplifying the logic here results in better performance

@frewsxcv frewsxcv merged commit 7b106fb into georust:master Jul 23, 2016
nyurik pushed a commit to nyurik/geo that referenced this pull request Mar 19, 2022
67: Minimal support for JTS extensions r=michaelkirk a=rmanoka

Refer discussion in georust#50 

+ support LINEARRING by parsing it as a LINESTRING
+ test LINEARRING parsing

- [x] I agree to follow the project's [code of conduct](https://github.com/georust/geo/blob/master/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: Rajsekar Manokaran <rajsekar@gmail.com>
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.

2 participants