Skip to content

Commit

Permalink
Implement IntoIter for a borrowed LineString
Browse files Browse the repository at this point in the history
  • Loading branch information
urschrei committed Dec 28, 2021
1 parent 61482cc commit 0571bf7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
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

0 comments on commit 0571bf7

Please sign in to comment.