2018-10-29 04:37:04 +03:00
|
|
|
extern crate aabb_quadtree;
|
2018-06-29 05:48:11 +03:00
|
|
|
extern crate dimensioned;
|
2018-10-31 01:52:17 +03:00
|
|
|
extern crate geo;
|
2018-06-29 05:48:11 +03:00
|
|
|
extern crate ordered_float;
|
|
|
|
extern crate rand;
|
|
|
|
extern crate serde;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
|
|
|
|
mod angle;
|
2018-09-18 23:49:45 +03:00
|
|
|
mod circle;
|
2018-06-29 05:48:11 +03:00
|
|
|
mod gps;
|
|
|
|
mod line;
|
2018-08-09 00:19:09 +03:00
|
|
|
mod polygon;
|
2018-06-29 05:48:11 +03:00
|
|
|
mod polyline;
|
|
|
|
mod pt;
|
|
|
|
|
|
|
|
pub use angle::Angle;
|
2018-09-18 23:49:45 +03:00
|
|
|
pub use circle::Circle;
|
2018-08-07 23:22:24 +03:00
|
|
|
use dimensioned::si;
|
2018-10-29 22:35:39 +03:00
|
|
|
pub use gps::{GPSBounds, LonLat};
|
2018-06-29 05:48:11 +03:00
|
|
|
pub use line::Line;
|
2018-08-09 19:24:12 +03:00
|
|
|
pub use polygon::{Polygon, Triangle};
|
2018-06-29 05:48:11 +03:00
|
|
|
pub use polyline::PolyLine;
|
2018-10-29 22:35:39 +03:00
|
|
|
pub use pt::{Bounds, HashablePt2D, Pt2D};
|
2018-08-07 23:22:24 +03:00
|
|
|
use std::marker;
|
|
|
|
|
2018-10-18 01:18:35 +03:00
|
|
|
// About 0.4 inches... which is quite tiny on the scale of things. :)
|
2018-08-16 01:37:07 +03:00
|
|
|
pub const EPSILON_DIST: si::Meter<f64> = si::Meter {
|
2018-09-09 01:35:30 +03:00
|
|
|
value_unsafe: 0.01,
|
2018-08-07 23:22:24 +03:00
|
|
|
_marker: marker::PhantomData,
|
|
|
|
};
|
|
|
|
|
|
|
|
// NOT segment. Fails for parallel lines.
|
|
|
|
// https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line
|
|
|
|
pub(crate) fn line_intersection(l1: &Line, l2: &Line) -> Option<Pt2D> {
|
|
|
|
let x1 = l1.pt1().x();
|
|
|
|
let y1 = l1.pt1().y();
|
|
|
|
let x2 = l1.pt2().x();
|
|
|
|
let y2 = l1.pt2().y();
|
|
|
|
|
|
|
|
let x3 = l2.pt1().x();
|
|
|
|
let y3 = l2.pt1().y();
|
|
|
|
let x4 = l2.pt2().x();
|
|
|
|
let y4 = l2.pt2().y();
|
|
|
|
|
|
|
|
let numer_x = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4);
|
|
|
|
let numer_y = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4);
|
|
|
|
let denom = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
|
|
|
|
if denom == 0.0 {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(Pt2D::new(numer_x / denom, numer_y / denom))
|
|
|
|
}
|
|
|
|
}
|