Function try_convex_hull

Source
pub fn try_convex_hull(
    points: &[Point3<f32>],
) -> Result<(Vec<Point3<f32>>, Vec<[u32; 3]>), ConvexHullError>
Expand description

Computes the convex hull of a set of 3D points, with error handling.

This is the safe version of convex_hull that returns a Result instead of panicking on degenerate inputs.

§Arguments

  • points - The input points (must have at least 3 points)

§Returns

  • Ok((vertices, indices)) - Successfully computed convex hull
  • Err(ConvexHullError::IncompleteInput) - Less than 3 input points
  • Err(ConvexHullError::...) - Other errors (degenerate geometry, numerical issues)

§Example

use parry3d::transformation::try_convex_hull;
use nalgebra::Point3;

// Valid input
let points = vec![
    Point3::origin(),
    Point3::new(1.0, 0.0, 0.0),
    Point3::new(0.0, 1.0, 0.0),
    Point3::new(0.0, 0.0, 1.0),
];

match try_convex_hull(&points) {
    Ok((vertices, indices)) => {
        println!("Hull: {} vertices, {} faces", vertices.len(), indices.len());
    }
    Err(e) => {
        println!("Failed: {:?}", e);
    }
}

// Degenerate input (too few points)
let bad_points = vec![Point3::origin(), Point3::new(1.0, 0.0, 0.0)];
assert!(try_convex_hull(&bad_points).is_err());