+////////// INTERSECTION ////////////////////////////////////////////////////////
+
+#[derive(Debug)]
+pub enum Intersection {
+ Point(Point<f64>),
+ //Line(Point<f64>, Point<f64>), // TODO: overlapping collinear
+ None,
+}
+
+impl Intersection {
+ pub fn lines(p1: Point<f64>, p2: Point<f64>, p3: Point<f64>, p4: Point<f64>) -> Intersection {
+ let s1 = p2 - p1;
+ let s2 = p4 - p3;
+
+ let denomimator = -s2.x * s1.y + s1.x * s2.y;
+ if denomimator != 0.0 {
+ let s = (-s1.y * (p1.x - p3.x) + s1.x * (p1.y - p3.y)) / denomimator;
+ let t = ( s2.x * (p1.y - p3.y) - s2.y * (p1.x - p3.x)) / denomimator;
+
+ if s >= 0.0 && s <= 1.0 && t >= 0.0 && t <= 1.0 {
+ return Intersection::Point(p1 + (s1 * t))
+ }
+ }
+
+ Intersection::None
+ }
+}
+
+////////// DIMENSION ///////////////////////////////////////////////////////////
+