Crate line_intersection [] [src]

This crate is a tiny utility library for finding the intersection two 2D line segments, rays, or complete lines. You'll need the geo crate to use this crate, because this library uses geo's data structures.

To use this library, construct a LineSegment<T: num_traits::Float> and relate it with another LineSegment. This will return a LineRelation<T>, which covers all the possible relations between those two lines.

LineRelation<T> provides unique_intersection, if all you care about is finding a unique intersection, and (for example) you don't care to distinguish cases where there are zero or an infinite number of intersections.

Here's an example of usage:

extern crate geo;
extern crate line_intersection;

fn main() {
    // find the intersection of a line segment and an infinite line
    use line_intersection::{LineInterval, LineRelation};
    use geo::{Coordinate, Line, Point};

    let segment = LineInterval::line_segment(Line {
        start: (0.0, 0.0).into(),
        end: (3.0, 3.0).into(),

    let line = LineInterval::line(Line {
        start: (2.0, 0.0).into(),
        end: (2.0, 0.1).into(),

    let intersection = segment.relate(&line).unique_intersection();
    assert_eq!(Some(Point(Coordinate { x: 2.0, y: 2.0 })), intersection);



An interval (continuous subset) of a line.



The relationship between two line segments.