Skip to main content

segment_intersections

Function segment_intersections 

Source
pub fn segment_intersections(
    segments: &[[Point2; 2]],
) -> Result<SegmentIntersections, SegmentSweepError>
Expand description

Every intersection among segments, exactly, by a Bentley–Ottmann sweep in O((n + k) log n) time for k reported incidences.

A point is reported when at least two segments contain it and it is an endpoint of one of them or a proper crossing of two, with every segment through it. Each maximal collinear piece covered by a constant set of two or more segments is reported as a SegmentOverlap; its ends are input endpoints and are reported as points too. A zero-length segment is a point (SegmentLocation::Degenerate) and takes no part in overlaps.

Every decision is an exact sign, so no tolerance enters. Crossings are ExactPoint2 rationals; IntersectionPoint::rounded is their correctly rounded value, and an input endpoint comes back bit for bit. Output order is deterministic: points in lexicographic order (x, then y), incidences by segment index.

§Errors

SegmentSweepError::NonFinite when a coordinate is NaN or infinite.