Skip to main content

triangulate_polygon_with_holes

Function triangulate_polygon_with_holes 

Source
pub fn triangulate_polygon_with_holes(
    exterior: &[GeoCoord],
    holes: &[&[GeoCoord]],
) -> Vec<u32>
Expand description

Triangulate a polygon with interior rings (holes).

The exterior ring and each hole are provided as separate slices. Closing duplicate vertices are stripped automatically. Winding order is normalised internally (exterior CCW, holes CW).

Returns indices into a combined vertex array where the exterior ring vertices come first (0..exterior.effective_len), followed by hole vertices in order.

ยงExample

use rustial_engine::triangulate_polygon_with_holes;
use rustial_engine::GeoCoord;

let exterior = vec![
    GeoCoord::from_lat_lon(0.0, 0.0),
    GeoCoord::from_lat_lon(0.0, 4.0),
    GeoCoord::from_lat_lon(4.0, 4.0),
    GeoCoord::from_lat_lon(4.0, 0.0),
];
let hole = vec![
    GeoCoord::from_lat_lon(1.0, 1.0),
    GeoCoord::from_lat_lon(1.0, 3.0),
    GeoCoord::from_lat_lon(3.0, 3.0),
    GeoCoord::from_lat_lon(3.0, 1.0),
];
let indices = triangulate_polygon_with_holes(&exterior, &[&hole]);
assert!(!indices.is_empty());