diff --git a/Cargo.toml b/Cargo.toml index 4606d1a..fa45ac3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,12 @@ version = "1.0.0" default-features = false features = ["derive", "alloc"] +[dependencies.mint] +package = "mint" +optional = true +default-features = false +version = "0.5.9" + [workspace] members = ["delaunay_compare"] diff --git a/src/delaunay_core/bulk_load.rs b/src/delaunay_core/bulk_load.rs index 1fade0e..3643370 100644 --- a/src/delaunay_core/bulk_load.rs +++ b/src/delaunay_core/bulk_load.rs @@ -339,7 +339,7 @@ where None } -pub struct PointWithIndex { +pub(crate) struct PointWithIndex { data: V, index: usize, } diff --git a/src/lib.rs b/src/lib.rs index f2978c3..472a081 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,15 @@ //! * Serde support with the `serde` feature. //! * `no_std` support with `default-features = false` //! * Natural neighbor interpolation: [NaturalNeighbor] +//! +//! # Cargo features +//! +//! These features are disabled by default and need to be enabled in your `Cargo.toml`: +//! - `serde`: Enable (de)serialization of (constrained) Delaunay triangulations with the +//! [Serde](https://docs.rs/serde/latest/serde/) crate +//! - `mint`: Enables rudimentary [mint](https://docs.rs/mint/latest/mint/) interoperability by +//! implementing the `From` and `Into` conversion traits between `spade::Point2` and +//! `mint::Point2`. Also implements [HasPosition] for `mint::Point2`. #![no_std] #![forbid(unsafe_code)] @@ -59,6 +68,8 @@ pub use delaunay_core::TriangulationExt; pub(crate) use delaunay_core::RemovalResult; +#[cfg(feature = "mint")] +mod mint_support; #[cfg(test)] mod test_utilities; diff --git a/src/mint_support.rs b/src/mint_support.rs new file mode 100644 index 0000000..d8cd7b1 --- /dev/null +++ b/src/mint_support.rs @@ -0,0 +1,27 @@ +use crate::{HasPosition, SpadeNum}; + +impl HasPosition for mint::Point2 +where + S: SpadeNum, +{ + type Scalar = S; + + fn position(&self) -> crate::Point2 { + (*self).into() + } +} + +impl From> for crate::Point2 { + fn from(value: mint::Point2) -> Self { + crate::Point2::new(value.x, value.y) + } +} + +impl From> for mint::Point2 { + fn from(value: crate::Point2) -> Self { + mint::Point2 { + x: value.x, + y: value.y, + } + } +} diff --git a/src/point.rs b/src/point.rs index a435eb4..29f611c 100644 --- a/src/point.rs +++ b/src/point.rs @@ -116,7 +116,7 @@ impl From<(S, S)> for Point2 { } } -/// An object with position. +/// An object with a position. /// /// Vertices need to implement this trait to allow being inserted into triangulations. pub trait HasPosition {