Skip to main content

dd_delaunay/
lib.rs

1//! # dd-delaunay
2//!
3//! This is a library for computing the Delaunay triangulation of a set of n-dimensional points
4//! in a [simplicial complex](https://en.wikipedia.org/wiki/Simplicial_complex)
5//! inspired by [CGAL](https://www.cgal.org).
6//!
7//! # Features
8//! * d-dimensional Delaunay triangulations
9//! * Arbitrary data types associated with vertices and cells
10//! * Serialization/Deserialization with [serde](https://serde.rs)
11
12#[cfg(feature = "serde")]
13use serde::{de::DeserializeOwned, Serialize};
14
15#[macro_use]
16extern crate derive_builder;
17
18/// The main module of the library. This module contains the public interface
19/// for the library.
20pub mod delaunay_core {
21    pub mod cell;
22    pub mod facet;
23    pub mod matrix;
24    pub mod point;
25    pub mod triangulation_data_structure;
26    pub mod utilities;
27    pub mod vertex;
28    // Re-export the `delaunay_core` modules.
29    pub use cell::*;
30    pub use facet::*;
31    pub use matrix::*;
32    pub use point::*;
33    pub use triangulation_data_structure::*;
34    pub use utilities::*;
35    pub use vertex::*;
36}
37
38// Make use of serde when enabled
39/// The bounds of coord arrays
40#[cfg(feature = "serde")]
41pub trait Coord: Copy + Default + DeserializeOwned + Serialize + Sized {}
42/// The bounds of coord arrays
43#[cfg(not(feature = "serde"))]
44pub trait Coord: Copy + Default + Sized {}
45
46#[cfg(feature = "serde")]
47impl<T: Copy + Default + DeserializeOwned + Serialize + Sized> Coord for T {}
48#[cfg(not(feature = "serde"))]
49impl<T: Copy + Default + Sized> Coord for T {}
50
51/// The bounds of `f64` coord arrays
52#[cfg(feature = "serde")]
53pub trait Coordf64: Default + DeserializeOwned + Serialize + Sized {}
54/// The bounds of `f64` coord arrays
55#[cfg(not(feature = "serde"))]
56pub trait Coordf64: Default + Sized {}
57
58#[cfg(feature = "serde")]
59impl<T: Default + DeserializeOwned + Serialize + Sized> Coordf64 for T {}
60#[cfg(not(feature = "serde"))]
61impl<T: Default + Sized> Coordf64 for T {}
62
63/// The function `is_normal` checks that structs implement `auto` traits.
64/// Traits are checked at compile time, so this function is only used for
65/// testing.
66#[allow(clippy::extra_unused_type_parameters, unused)]
67fn is_normal<T: Sized + Send + Sync + Unpin>() -> bool {
68    true
69}
70
71#[cfg(test)]
72mod lib_tests {
73    use crate::{
74        delaunay_core::{
75            cell::Cell, facet::Facet, point::Point, triangulation_data_structure::Tds,
76            vertex::Vertex,
77        },
78        is_normal,
79    };
80
81    #[test]
82    fn normal_types() {
83        assert!(is_normal::<Point<f64, 3>>());
84        assert!(is_normal::<Point<f32, 3>>());
85        assert!(is_normal::<Vertex<f64, Option<()>, 3>>());
86        assert!(is_normal::<Facet<f64, Option<()>, Option<()>, 3>>());
87        assert!(is_normal::<Cell<f64, Option<()>, Option<()>, 4>>());
88        assert!(is_normal::<Tds<f64, Option<()>, Option<()>, 4>>());
89    }
90}