compute_jarvis_march

Function compute_jarvis_march 

Source
pub fn compute_jarvis_march(
    points: &ArrayView2<'_, f64>,
) -> SpatialResult<ConvexHull>
Expand description

Compute convex hull using Jarvis march (Gift Wrapping) algorithm (2D only)

The Jarvis march algorithm works by:

  1. Finding the leftmost point
  2. From each hull point, finding the most counterclockwise point
  3. Continuing until we wrap back to the starting point

Time complexity: O(nh) where n is the number of points and h is the number of hull points. This makes it optimal for small hull sizes.

§Arguments

  • points - Input points (shape: npoints x 2)

§Returns

  • Result containing a ConvexHull instance or an error

§Errors

  • Returns error if fewer than 3 points are provided
  • Only works for 2D points

§Examples

use scirs2_spatial::convex_hull::algorithms::jarvis_march::compute_jarvis_march;
use scirs2_core::ndarray::array;

let points = array![[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [0.5, 0.5]];
let hull = compute_jarvis_march(&points.view()).unwrap();
assert_eq!(hull.ndim(), 2);
assert_eq!(hull.vertex_indices().len(), 3); // Excludes interior point