Skip to main content

convex_hull_2d

Function convex_hull_2d 

Source
pub fn convex_hull_2d(points: &[(f64, f64)]) -> IgraphResult<ConvexHullResult>
Expand description

Compute the convex hull of a set of 2D points.

Uses the Graham scan algorithm. The input is a slice of (x, y) coordinate pairs. Returns the indices and coordinates of the hull vertices in counter-clockwise order.

§Errors

  • InvalidArgument if any coordinate is NaN.

§Examples

use rust_igraph::convex_hull_2d;

let points = vec![(0.0, 0.0), (1.0, 0.0), (0.5, 1.0), (0.5, 0.5)];
let hull = convex_hull_2d(&points).unwrap();
// The interior point (0.5, 0.5) is not on the hull.
assert_eq!(hull.hull_vertices.len(), 3);