Skip to content

Commit

Permalink
We actually do want to enforce strictness for Rings sometimes -- foun…
Browse files Browse the repository at this point in the history
…d a case with the speed controls rendering. #1061
  • Loading branch information
dabreegster committed Feb 9, 2023
1 parent 11f37f1 commit 2895759
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion geom/src/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Polygon {

/// Top-left at the origin. Doesn't take Distance, because this is usually pixels, actually.
pub fn maybe_rectangle(width: f64, height: f64) -> Result<Self> {
Ring::new(vec![
Ring::strict_new(vec![
Pt2D::new(0.0, 0.0),
Pt2D::new(width, 0.0),
Pt2D::new(width, height),
Expand Down
8 changes: 8 additions & 0 deletions geom/src/ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ impl Ring {
Ok(result)
}

pub fn strict_new(pts: Vec<Pt2D>) -> Result<Self> {
// Enforce no duplicate adjacent points
if let Some(pair) = pts.windows(2).find(|pair| pair[0] == pair[1]) {
bail!("Ring has duplicate adjacent points near {}", pair[0]);
}
Self::new(pts)
}

pub fn must_new(pts: Vec<Pt2D>) -> Ring {
Ring::new(pts).unwrap()
}
Expand Down

0 comments on commit 2895759

Please sign in to comment.