pub fn point_on_surface<G, P>(polygon: &G) -> Option<P>Expand description
A point guaranteed to lie in the interior of polygon, or None
for a degenerate (zero-area) polygon.
Sweeps a horizontal line at the average of the exterior ring’s minimum and maximum y, collects the x-values where it crosses the boundary (exterior and holes), and returns the midpoint of the widest gap between consecutive crossings that lies in the interior.
Mirrors boost::geometry::point_on_surface
(algorithms/point_on_surface.hpp).
§Examples
use geometry_cs::Cartesian;
use geometry_model::{polygon, Point2D, Polygon};
use geometry_overlay::surface_point::point_on_surface;
use geometry_trait::Point as _;
type P = Point2D<f64, Cartesian>;
let pg: Polygon<P> = polygon![[(0.0, 0.0), (4.0, 0.0), (4.0, 4.0), (0.0, 4.0), (0.0, 0.0)]];
let p = point_on_surface(&pg).unwrap();
// The representative point is inside the square.
assert!(p.get::<0>() > 0.0 && p.get::<0>() < 4.0);
assert!(p.get::<1>() > 0.0 && p.get::<1>() < 4.0);