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

More LineString iterators #705

Merged
merged 12 commits into from
Jan 6, 2022
Prev Previous commit
Next Next commit
Implement IntoIter for a borrowed LineString
  • Loading branch information
urschrei committed Dec 28, 2021
commit 696253d14bd393b7ab14ef07d37e20642608ea0f
11 changes: 10 additions & 1 deletion geo-types/src/line_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,16 @@ impl<T: CoordNum> IntoIterator for LineString<T> {
}
}

/// Mutably iterate over all the [Coordinate](struct.Coordinates.html)s in this `LineString`.
impl<'a, T: CoordNum> IntoIterator for &'a LineString<T> {
type Item = &'a Coordinate<T>;
type IntoIter = CoordinatesIter<'a, T>;

fn into_iter(self) -> Self::IntoIter {
CoordinatesIter(self.0.iter())
}
}

/// Mutably iterate over all the [Coordinate](struct.Coordinates.html)s in this [LineString].
impl<'a, T: CoordNum> IntoIterator for &'a mut LineString<T> {
type Item = &'a mut Coordinate<T>;
type IntoIter = ::std::slice::IterMut<'a, Coordinate<T>>;
Expand Down
4 changes: 2 additions & 2 deletions geo-types/src/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ where
.map(|(idx, _)| {
let prev_1 = self.previous_vertex(idx);
let prev_2 = self.previous_vertex(prev_1);
Point(self.exterior.0[prev_2])
.cross_prod(Point(self.exterior.0[prev_1]), Point(self.exterior.0[idx]))
Point(self.exterior[prev_2])
.cross_prod(Point(self.exterior[prev_1]), Point(self.exterior[idx]))
})
// accumulate and check cross-product result signs in a single pass
// positive implies ccw convexity, negative implies cw convexity
Expand Down
4 changes: 2 additions & 2 deletions geo-types/src/private_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn line_string_bounding_rect<T>(line_string: &LineString<T>) -> Option<Rect<
where
T: CoordNum,
{
get_bounding_rect(line_string.0.iter().cloned())
get_bounding_rect(line_string.iter().cloned())
}

pub fn line_bounding_rect<T>(line: Line<T>) -> Rect<T>
Expand Down Expand Up @@ -132,7 +132,7 @@ where
}
// LineString with one point equal p
if line_string.0.len() == 1 {
return point_contains_point(Point(line_string.0[0]), point);
return point_contains_point(Point(line_string[0]), point);
}
// check if point is a vertex
if line_string.0.contains(&point.0) {
Expand Down