try_convex_hull

Function try_convex_hull 

Source
pub fn try_convex_hull(
    points: &[Vector3],
) -> Result<(Vec<Vector3>, 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 parry3d::math::Vector;

// Valid input
let points = vec![
    Vector::ZERO,
    Vector::new(1.0, 0.0, 0.0),
    Vector::new(0.0, 1.0, 0.0),
    Vector::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![Vector::ZERO, Vector::new(1.0, 0.0, 0.0)];
assert!(try_convex_hull(&bad_points).is_err());