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

Add the Length trait and implement Length for LineString and MultiLineString #44

Merged
merged 6 commits into from
Jul 21, 2016

Conversation

zarch
Copy link
Contributor

@zarch zarch commented Jul 18, 2016

No description provided.

@@ -0,0 +1,82 @@
use num::{Float};

Choose a reason for hiding this comment

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

You don't need the extra braces here: use num::Float;

let ipoints = vect.iter().zip(vect[1..].iter());
ipoints.fold(T::zero(), |total_length, (p1, p2)| total_length + p1.distance(&p2))
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This might be simpler if you used slice::windows here.

@@ -26,26 +26,20 @@ pub trait Length<T, RHS = Self> {
impl<T> Length<T> for LineString<T>
where T: Float
{
///
/// Length of a LineString.
///
fn length(&self) -> T {
let vect = &self.0;
if vect.is_empty() || vect.len() == 1 {
Copy link
Member

Choose a reason for hiding this comment

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

This if can be removed

@frewsxcv
Copy link
Member

Looks good to me, will wait until tonight to merge in case anyone else has comments.

@frewsxcv frewsxcv merged commit b8466ab into georust:master Jul 21, 2016
@zarch zarch deleted the length branch July 21, 2016 05:14
nyurik pushed a commit to nyurik/geo that referenced this pull request Mar 19, 2022
update to the last geo_types version
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.

3 participants