use super::{CoordNum, Kernel, Orientation};
use crate::Coord;
use num_traits::{Float, NumCast};
#[derive(Default, Debug)]
pub struct RobustKernel;
impl<T> Kernel<T> for RobustKernel
where
T: CoordNum + Float,
{
fn orient2d(p: Coord<T>, q: Coord<T>, r: Coord<T>) -> Orientation {
use robust::{orient2d, Coord};
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. {
Orientation::Clockwise
} else if orientation > 0. {
Orientation::CounterClockwise
} else {
Orientation::Collinear
}
}
}