Skip to content

Commit

Permalink
Revert change to use geo::Centroid for Polygon::center. It may be a b…
Browse files Browse the repository at this point in the history
…it slower, and most callers of center() just need something 'vaguely' in the middle of the polygon. #951

I didn't regenerate anything based on this change; not sure anything
would be affected anyway.
  • Loading branch information
dabreegster committed Sep 12, 2022
1 parent d2981a9 commit 272e18e
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions geom/src/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,9 @@ impl Polygon {
self.rings.remove(0)
}

/// The [centroid](https://docs.rs/geo/latest/geo/algorithm/centroid/trait.Centroid.html)
/// Returns the arithmetic mean of the outer ring's points. The result could wind up inside a
/// hole in the polygon. Consider using `polylabel` too.
pub fn center(&self) -> Pt2D {
use geo::Centroid;

if let Some(pt) = self.to_geo().centroid() {
return pt.into();
}
// TODO Not sure when centroid could fail. Fall back to just finding the center of the
// outer ring.
let mut pts = self.get_outer_ring().clone().into_points();
pts.pop();
Pt2D::center(&pts)
Expand Down

0 comments on commit 272e18e

Please sign in to comment.