pub fn polylabel(polygon: &Polygon, tolerance: f64) -> PointExpand description
Calculate a Polygon’s ideal label position by calculating its ✨pole of inaccessibility✨
The calculation uses an iterative grid-based algorithm.
§Examples
use polylabel::polylabel;
extern crate geo;
use self::geo::{Point, LineString, Polygon};
// An approximate `L` shape
let coords = vec![
(0.0, 0.0),
(4.0, 0.0),
(4.0, 1.0),
(1.0, 1.0),
(1.0, 4.0),
(0.0, 4.0),
(0.0, 0.0)];
let poly = Polygon::new(coords.into(), vec![]);
// Its centroid lies outside the polygon
assert_eq!(poly.centroid(), Point::new(1.3571428571428572, 1.3571428571428572));
let label_position = polylabel(&poly, &1.0);
// Optimum label position is inside the polygon
assert_eq!(label_position, Point::new(0.5625, 0.5625));