[−][src]Function polylabel::polylabel
pub fn polylabel<T>(
polygon: &Polygon<T>,
tolerance: &T
) -> Result<Point<T>, PolylabelError> where
T: Float + FromPrimitive + Signed + Sum,
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 geo::{Point, LineString, Polygon}; use geo::prelude::*; // 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().unwrap(), Point::new(1.3571428571428572, 1.3571428571428572)); let label_position = polylabel(&poly, &0.1).unwrap(); // Optimum label position is inside the polygon assert_eq!(label_position, Point::new(0.5625, 0.5625));