ConvexHull

Struct ConvexHull 

Source
pub struct ConvexHull { /* private fields */ }
Expand description

A ConvexHull represents the convex hull of a set of points.

It provides methods to access hull properties, check if points are inside the hull, and access hull facets and vertices.

Implementations§

Source§

impl ConvexHull

Source

pub fn new(points: &ArrayView2<'_, f64>) -> SpatialResult<Self>

Create a new ConvexHull from a set of points.

§Arguments
  • points - Input points (shape: npoints x n_dim)
§Returns
  • Result containing a ConvexHull instance or an error
§Errors
  • Returns error if hull computation fails or input is invalid
§Examples
use scirs2_spatial::convex_hull::ConvexHull;
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 = ConvexHull::new(&points.view()).unwrap();
Source

pub fn new_with_algorithm( points: &ArrayView2<'_, f64>, algorithm: ConvexHullAlgorithm, ) -> SpatialResult<Self>

Create a new ConvexHull from a set of points using a specific algorithm.

§Arguments
  • points - Input points (shape: npoints x n_dim)
  • algorithm - Algorithm to use for convex hull computation
§Returns
  • Result containing a ConvexHull instance or an error
§Errors
  • Returns error if hull computation fails or input is invalid
  • Returns error if algorithm is not supported for the given dimensionality
§Examples
use scirs2_spatial::convex_hull::{ConvexHull, ConvexHullAlgorithm};
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 = ConvexHull::new_with_algorithm(&points.view(), ConvexHullAlgorithm::GrahamScan).unwrap();
Source

pub fn vertices(&self) -> Vec<Vec<f64>>

Get the vertices of the convex hull

§Returns
  • Array of vertices of the convex hull
§Examples
use scirs2_spatial::convex_hull::ConvexHull;
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 = ConvexHull::new(&points.view()).unwrap();

// The hull vertices should be the corners, not the interior point
// The number of vertices can vary depending on QHull implementation
assert!(hull.vertices().len() >= 3);
Source

pub fn vertices_array(&self) -> Array2<f64>

Get the vertices of the convex hull as an Array2

§Returns
  • Array2 of shape (n_vertices, n_dim) containing the vertices of the convex hull
Source

pub fn vertex_indices(&self) -> &[usize]

Get the indices of the vertices of the convex hull

§Returns
  • Vector of indices of the hull vertices (into the original points array)
§Examples
use scirs2_spatial::convex_hull::ConvexHull;
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 = ConvexHull::new(&points.view()).unwrap();

// Get the vertex indices of the hull
let vertices = hull.vertex_indices();
println!("Convex hull vertices: {:?}", vertices);
Source

pub fn simplices(&self) -> &[Vec<usize>]

Get the simplices (facets) of the convex hull

§Returns
  • Vector of simplices, where each simplex is a vector of vertex indices
§Examples
use scirs2_spatial::convex_hull::ConvexHull;
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 = ConvexHull::new(&points.view()).unwrap();

// For a 2D hull, examine the simplices
for simplex in hull.simplices() {
    // Print each simplex
    println!("Simplex: {:?}", simplex);
}
Source

pub fn ndim(&self) -> usize

Get the dimensionality of the convex hull

§Returns
  • Number of dimensions of the convex hull
§Examples
use scirs2_spatial::convex_hull::ConvexHull;
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 = ConvexHull::new(&points.view()).unwrap();

assert_eq!(hull.ndim(), 2);
Source

pub fn contains<T: AsRef<[f64]>>(&self, point: T) -> SpatialResult<bool>

Check if a point is inside the convex hull

§Arguments
  • point - The point to check
§Returns
  • Result containing a boolean indicating if the point is inside the hull
§Errors
  • Returns error if point dimension doesn’t match hull dimension
§Examples
use scirs2_spatial::convex_hull::ConvexHull;
use scirs2_core::ndarray::array;

let points = array![[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]];
let hull = ConvexHull::new(&points.view()).unwrap();

// Check a point inside the hull
// Result may vary depending on QHull implementation and special case handling
let inside = hull.contains(&[0.25, 0.25]).unwrap();
println!("Point [0.25, 0.25] inside: {}", inside);

// Check a point outside the hull
assert!(!hull.contains(&[2.0, 2.0]).unwrap());
Source

pub fn volume(&self) -> SpatialResult<f64>

Get the volume of the convex hull

For 2D hulls, this returns the area. For 3D hulls, this returns the volume. For higher dimensions, this returns the hypervolume.

§Returns
  • Result containing the volume/area of the convex hull
§Errors
  • Returns error if volume computation fails
§Examples
use scirs2_spatial::convex_hull::ConvexHull;
use scirs2_core::ndarray::array;

// Create a square with area 1
let points = array![[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]];
let hull = ConvexHull::new(&points.view()).unwrap();

let area = hull.volume().unwrap();
assert!((area - 1.0).abs() < 1e-10);
Source

pub fn area(&self) -> SpatialResult<f64>

Get the surface area of the convex hull

For 2D hulls, this returns the perimeter. For 3D hulls, this returns the surface area. For higher dimensions, this returns the surface hypervolume.

§Returns
  • Result containing the surface area/perimeter of the convex hull
§Errors
  • Returns error if area computation fails
§Examples
use scirs2_spatial::convex_hull::ConvexHull;
use scirs2_core::ndarray::array;

// Create a 3D cube
let points = array![
    [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0], [0.0, 1.0, 0.0],
    [0.0, 0.0, 1.0], [1.0, 0.0, 1.0], [1.0, 1.0, 1.0], [0.0, 1.0, 1.0]
];
let hull = ConvexHull::new(&points.view()).unwrap();

// Surface area of the cube should be 6 square units
let area = hull.area().unwrap();
assert!((area - 6.0).abs() < 1e-10);
Source

pub fn extract_equations(qh: &Qh<'_>, ndim: usize) -> Option<Array2<f64>>

Extract facet equations from the Qhull instance

§Arguments
  • qh - Qhull instance
  • ndim - Dimensionality of the hull
§Returns
  • Option containing an Array2 of shape (n_facets, ndim+1) with the equations of the hull facets or None if equations cannot be extracted

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V