pub fn compute_graham_scan(
points: &ArrayView2<'_, f64>,
) -> SpatialResult<ConvexHull>Expand description
Compute convex hull using Graham scan algorithm (2D only)
The Graham scan algorithm works by:
- Finding the bottommost point (lowest y-coordinate, then leftmost x)
- Sorting all other points by polar angle with respect to the start point
- Using a stack to eliminate points that create clockwise turns
§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::graham_scan::compute_graham_scan;
use ndarray::array;
let points = array![[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [0.5, 0.5]];
let hull = compute_graham_scan(&points.view()).unwrap();
assert_eq!(hull.ndim(), 2);
assert_eq!(hull.vertex_indices().len(), 3); // Excludes interior point