Skip to content

Commit

Permalink
Switch to the Robust crate for predicate checks
Browse files Browse the repository at this point in the history
  • Loading branch information
urschrei committed Aug 21, 2020
1 parent f6a5b0a commit 0c3c191
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions geo-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ approx = "0.3"
num-traits = "0.2"
serde = { version = "1", optional = true, features = ["derive"] }
rstar = { version = "0.8", optional = true }
robust = "0.2.2"

[dev-dependencies]
approx = "0.3"
17 changes: 15 additions & 2 deletions geo-types/src/point.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{Coordinate, CoordinateType};
use num_traits::NumCast;
use num_traits::Float;
use robust::{orient2d, Coord};
use std::ops::Add;
use std::ops::Neg;
use std::ops::Sub;
Expand Down Expand Up @@ -242,8 +244,19 @@ where
/// assert_eq!(cross, 2.0)
/// ```
pub fn cross_prod(self, point_b: Point<T>, point_c: Point<T>) -> T {
(point_b.x() - self.x()) * (point_c.y() - self.y())
- (point_b.y() - self.y()) * (point_c.x() - self.x())
let pa: Coord<f64> = Coord {
x: NumCast::from(self.x()).unwrap(),
y: NumCast::from(self.y()).unwrap(),
};
let pb: Coord<f64> = Coord {
x: NumCast::from(point_b.x()).unwrap(),
y: NumCast::from(point_b.y()).unwrap(),
};
let pc: Coord<f64> = Coord {
x: NumCast::from(point_c.x()).unwrap(),
y: NumCast::from(point_c.y()).unwrap(),
};
T::from(orient2d(pa, pb, pc)).unwrap()
}
}

Expand Down

0 comments on commit 0c3c191

Please sign in to comment.