Function geo::algorithm::line_intersection::line_intersection[][src]

pub fn line_intersection<F>(
    p: Line<F>,
    q: Line<F>
) -> Option<LineIntersection<F>> where
    F: GeoFloat

Returns the intersection between two Lines.

Lines can intersect in a Point or, for Collinear lines, in a Line. See LineIntersection for more details about the result.

Examples

use geo::{Line, Coordinate};
use geo::algorithm::line_intersection::{line_intersection, LineIntersection};

let line_1 = Line::new(Coordinate {x: 0.0, y: 0.0}, Coordinate { x: 5.0, y: 5.0 } );
let line_2 = Line::new(Coordinate {x: 0.0, y: 5.0}, Coordinate { x: 5.0, y: 0.0 } );
let expected = LineIntersection::SinglePoint { intersection: Coordinate { x: 2.5, y: 2.5 }, is_proper: true };
assert_eq!(line_intersection(line_1, line_2), Some(expected));

let line_1 = Line::new(Coordinate {x: 0.0, y: 0.0}, Coordinate { x: 5.0, y: 5.0 } );
let line_2 = Line::new(Coordinate {x: 0.0, y: 1.0}, Coordinate { x: 5.0, y: 6.0 } );
assert_eq!(line_intersection(line_1, line_2), None);

let line_1 = Line::new(Coordinate {x: 0.0, y: 0.0}, Coordinate { x: 5.0, y: 5.0 } );
let line_2 = Line::new(Coordinate {x: 5.0, y: 5.0}, Coordinate { x: 5.0, y: 0.0 } );
let expected = LineIntersection::SinglePoint { intersection: Coordinate { x: 5.0, y: 5.0 }, is_proper: false };
assert_eq!(line_intersection(line_1, line_2), Some(expected));

let line_1 = Line::new(Coordinate {x: 0.0, y: 0.0}, Coordinate { x: 5.0, y: 5.0 } );
let line_2 = Line::new(Coordinate {x: 3.0, y: 3.0}, Coordinate { x: 6.0, y: 6.0 } );
let expected = LineIntersection::Collinear { intersection: Line::new(Coordinate { x: 3.0, y: 3.0 }, Coordinate { x: 5.0, y: 5.0 })};
assert_eq!(line_intersection(line_1, line_2), Some(expected));

Strongly inspired by, and meant to produce the same results as, JTS’s RobustLineIntersector.