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

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_types::coord;
use geo::{Line, Coord};
use geo::line_intersection::{line_intersection, LineIntersection};

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

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

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

let line_1 = Line::new(coord! {x: 0.0, y: 0.0}, coord! { x: 5.0, y: 5.0 } );
let line_2 = Line::new(coord! {x: 3.0, y: 3.0}, coord! { x: 6.0, y: 6.0 } );
let expected = LineIntersection::Collinear { intersection: Line::new(coord! { x: 3.0, y: 3.0 }, coord! { 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.