Function polylabel::polylabel
[−]
[src]
pub fn polylabel<T>(polygon: &Polygon<T>, tolerance: &T) -> Point<T> where T: Float + FromPrimitive
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 ls = LineString(coords.iter().map(|e| Point::new(e.0, e.1)).collect()); let poly = Polygon(ls, 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));