Skip to content

Commit

Permalink
Rewrite Polygon structure to enforce closed LineString rings.
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Jan 21, 2019
1 parent a64dc8d commit 98bb29c
Show file tree
Hide file tree
Showing 21 changed files with 454 additions and 145 deletions.
4 changes: 2 additions & 2 deletions geo-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ mod test {
])];
let p = Polygon::new(exterior.clone(), interiors.clone());

assert_eq!(p.exterior, exterior);
assert_eq!(p.interiors, interiors);
assert_eq!(p.exterior(), &exterior);
assert_eq!(p.interiors(), &interiors[..]);
}

#[test]
Expand Down
11 changes: 11 additions & 0 deletions geo-types/src/line_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ impl<T: CoordinateType> LineString<T> {
}
})
}

/// Close the `LineString`. Specifically, if the `LineString` has is at least one coordinate,
/// and the value of the first coordinate does not equal the value of the last coordinate, then
/// a new coordinate is added to the end with the value of the first coordinate.
pub(crate) fn close(&mut self) {
if let (Some(first), Some(last)) = (self.0.first().map(|n| *n), self.0.last().map(|n| *n)) {
if first != last {
self.0.push(first);
}
}
}
}

/// Turn a `Vec` of `Point`-ish objects into a `LineString`.
Expand Down
Loading

0 comments on commit 98bb29c

Please sign in to comment.