Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ arbitrary = { version = "1.0.0", optional = true }
proptest = { version = "1.0.0", optional = true }
speedy = { version = "0.8.3", optional = true, default-features = false }
bytemuck = { version = "1.12.2", optional = true, default-features = false }
geo = { version = "0.24", optional = true }
robust = { version = "0.2", optional = true }

[dev-dependencies]
serde_test = "1.0"

[features]
default = ["std"]
std = ["num-traits/std"]
randtest = ["rand/std", "rand/std_rng"]
default = ["std"]
geo-interop = ["geo", "robust"]
std = ["num-traits/std"]
randtest = ["rand/std", "rand/std_rng"]
56 changes: 55 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ impl<T: Float> Ord for NotNan<T> {
}
}

#[allow(clippy::derive_hash_xor_eq)]
#[allow(clippy::derived_hash_with_manual_eq)]
impl<T: Float> Hash for NotNan<T> {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
Expand Down Expand Up @@ -2249,3 +2249,57 @@ mod impl_bytemuck {
assert!(try_cast::<f64, NotNan<f64>>(pi).is_ok());
}
}

#[cfg(feature = "geo")]
mod impl_geo {
use super::{Float, NotNan, OrderedFloat};
use geo::kernels::{HasKernel, Kernel, RobustKernel};
use geo::CoordNum;
use num_traits::NumCast;
use robust::{orient2d, Coord};

impl<T: Float + CoordNum + HasKernel> HasKernel for OrderedFloat<T> {
type Ker = RobustKernel;
}

impl<T: Float + CoordNum + HasKernel> HasKernel for NotNan<T> {
type Ker = NotNanRobustKernel;
}

#[derive(Default, Debug)]
pub struct NotNanRobustKernel;

impl<T> Kernel<NotNan<T>> for NotNanRobustKernel
where
T: Float + NumCast + CoordNum,
{
fn orient2d(
p: geo::Coord<NotNan<T>>,
q: geo::Coord<NotNan<T>>,
r: geo::Coord<NotNan<T>>,
) -> geo::Orientation {
let orientation = orient2d(
Coord {
x: <f64 as NumCast>::from(p.x).unwrap(),
y: <f64 as NumCast>::from(p.y).unwrap(),
},
Coord {
x: <f64 as NumCast>::from(q.x).unwrap(),
y: <f64 as NumCast>::from(q.y).unwrap(),
},
Coord {
x: <f64 as NumCast>::from(r.x).unwrap(),
y: <f64 as NumCast>::from(r.y).unwrap(),
},
);

if orientation > 0.0 {
geo::Orientation::CounterClockwise
} else if orientation < 0.0 {
geo::Orientation::Clockwise
} else {
geo::Orientation::Collinear
}
}
}
}