Delaunay

Struct Delaunay 

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

Structure for storing and querying a Delaunay triangulation

The Delaunay triangulation of a set of points is a triangulation such that no point is inside the circumcircle of any triangle (in 2D) or circumsphere of any tetrahedron (in 3D).

This implementation uses the Qhull library (via qhull-rs) to compute Delaunay triangulations efficiently.

Implementations§

Source§

impl Delaunay

Source

pub fn new(points: &Array2<f64>) -> SpatialResult<Self>

Create a new Delaunay triangulation

§Arguments
  • points - The points to triangulate, shape (npoints, ndim)
§Returns
  • A new Delaunay triangulation or an error
§Examples
use scirs2_spatial::delaunay::Delaunay;
use scirs2_core::ndarray::array;

let points = array![
    [0.0, 0.0],
    [1.0, 0.0],
    [0.0, 1.0],
    [1.0, 1.0]
];

let tri = Delaunay::new(&points).unwrap();
let simplices = tri.simplices();
println!("Triangles: {:?}", simplices);
Source

pub fn new_constrained( points: &Array2<f64>, constraints: Vec<(usize, usize)>, ) -> SpatialResult<Self>

Create a new constrained Delaunay triangulation

§Arguments
  • points - The points to triangulate, shape (npoints, ndim)
  • constraints - Vector of constraint edges, each edge is a pair of point indices
§Returns
  • A new constrained Delaunay triangulation or an error
§Note

Currently only supports 2D constrained Delaunay triangulation. Constraints are edges that must be present in the final triangulation.

§Examples
use scirs2_spatial::delaunay::Delaunay;
use scirs2_core::ndarray::array;

let points = array![
    [0.0, 0.0],
    [1.0, 0.0],
    [1.0, 1.0],
    [0.0, 1.0],
    [0.5, 0.5]
];

// Add constraint edges forming a square boundary
let constraints = vec![(0, 1), (1, 2), (2, 3), (3, 0)];

let tri = Delaunay::new_constrained(&points, constraints).unwrap();
let simplices = tri.simplices();
println!("Constrained triangles: {:?}", simplices);
Source

pub fn constraints(&self) -> &[(usize, usize)]

Get the constraint edges

§Returns
  • Vector of constraint edges as pairs of point indices
Source

pub fn npoints(&self) -> usize

Get the number of points

§Returns
  • Number of points in the triangulation
Source

pub fn ndim(&self) -> usize

Get the dimension of the points

§Returns
  • Number of dimensions of the points
Source

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

Get the points used for triangulation

§Returns
  • Array of points
Source

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

Get the simplices (triangles in 2D, tetrahedra in 3D, etc.)

§Returns
  • Vector of simplices, where each simplex is a vector of vertex indices
Source

pub fn neighbors(&self) -> &[Vec<i64>]

Get the neighbors of each simplex

§Returns
  • Vector of neighbor indices for each simplex
Source

pub fn find_simplex(&self, point: &[f64]) -> Option<usize>

Find the simplex containing a given point

§Arguments
  • point - The point to locate
§Returns
  • The index of the simplex containing the point, or None if not found
§Examples
use scirs2_spatial::delaunay::Delaunay;
use scirs2_core::ndarray::array;

let points = array![
    [0.0, 0.0],
    [1.0, 0.0],
    [0.0, 1.0],
    [1.0, 1.0]
];

let tri = Delaunay::new(&points).unwrap();
// Try to find which triangle contains the point [0.25, 0.25]
if let Some(idx) = tri.find_simplex(&[0.25, 0.25]) {
    println!("Point is in simplex {}", idx);
}
Source

pub fn convex_hull(&self) -> Vec<usize>

Compute the convex hull of the points

§Returns
  • Indices of the points forming the convex hull
§Examples
use scirs2_spatial::delaunay::Delaunay;
use scirs2_core::ndarray::array;

let points = array![
    [0.0, 0.0],
    [1.0, 0.0],
    [0.0, 1.0],
    [0.5, 0.5]  // Interior point
];

let tri = Delaunay::new(&points).unwrap();
let hull = tri.convex_hull();

// The hull should be the three corner points, excluding the interior point
assert_eq!(hull.len(), 3);

Trait Implementations§

Source§

impl Clone for Delaunay

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Delaunay

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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