Skip to content

Commit

Permalink
Adds basic mint interoperability.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stoeoef committed Jul 25, 2024
1 parent dd6cf1a commit cef6de4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion src/delaunay_core/bulk_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ where
None
}

pub struct PointWithIndex<V> {
pub(crate) struct PointWithIndex<V> {
data: V,
index: usize,
}
Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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;

Expand Down
27 changes: 27 additions & 0 deletions src/mint_support.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use crate::{HasPosition, SpadeNum};

impl<S> HasPosition for mint::Point2<S>
where
S: SpadeNum,
{
type Scalar = S;

fn position(&self) -> crate::Point2<Self::Scalar> {
(*self).into()
}
}

impl<S> From<mint::Point2<S>> for crate::Point2<S> {
fn from(value: mint::Point2<S>) -> Self {
crate::Point2::new(value.x, value.y)
}
}

impl<S> From<crate::Point2<S>> for mint::Point2<S> {
fn from(value: crate::Point2<S>) -> Self {
mint::Point2 {
x: value.x,
y: value.y,
}
}
}
2 changes: 1 addition & 1 deletion src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<S: SpadeNum> From<(S, S)> for Point2<S> {
}
}

/// An object with position.
/// An object with a position.
///
/// Vertices need to implement this trait to allow being inserted into triangulations.
pub trait HasPosition {
Expand Down

0 comments on commit cef6de4

Please sign in to comment.