Skip to main content

triangulate

Function triangulate 

Source
pub fn triangulate(
    outer: &[[f64; 2]],
    holes: &[&[[f64; 2]]],
    out: &mut Vec<[u32; 3]>,
) -> Result<bool>
Expand description

Triangulates the polygon outer minus the polygons in holes, appending the triangles to out.

Vertices are numbered outer first, then each hole in order; a triangle is three such numbers. Triangles are counter-clockwise (positive area in a right-handed (x, y) frame) when the input is a simple polygon with simple holes inside it.

  • Either orientation is accepted: the outer ring is made counter-clockwise and the holes clockwise internally.
  • Consecutive equal points, including a last point equal to the first, count as one. The repeats keep their numbers but never appear in a triangle. Collinear vertices may also be left out of every triangle.
  • A ring with fewer than three distinct points has nothing to fill: such an outer gives no triangles and Ok(true), and such a hole is ignored. An outer whose points are all collinear also gives no triangles and Ok(true).
  • Any non-finite coordinate (NaN or infinite), in the outer ring or a hole, gives no triangles and Ok(false).

Returns Ok(false) when ear clipping could not finish (typically a self-intersecting ring) or a hole could not be bridged; the triangles found so far are kept in out. It never panics.

ยงErrors