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
impl Delaunay
Sourcepub fn new(points: &Array2<f64>) -> SpatialResult<Self>
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);Sourcepub fn new_constrained(
points: &Array2<f64>,
constraints: Vec<(usize, usize)>,
) -> SpatialResult<Self>
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);Sourcepub fn constraints(&self) -> &[(usize, usize)]
pub fn constraints(&self) -> &[(usize, usize)]
Sourcepub fn simplices(&self) -> &[Vec<usize>]
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
Sourcepub fn find_simplex(&self, point: &[f64]) -> Option<usize>
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);
}Sourcepub fn convex_hull(&self) -> Vec<usize>
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§
Auto Trait Implementations§
impl !Freeze for Delaunay
impl !RefUnwindSafe for Delaunay
impl !Send for Delaunay
impl !Sync for Delaunay
impl Unpin for Delaunay
impl UnwindSafe for Delaunay
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.