pub fn segment_intersection<S, P>(a: &S, b: &S) -> SegmentIntersection<P>Expand description
Intersect two segments a and b.
Returns SegmentIntersection::Disjoint,
SegmentIntersection::Single,
SegmentIntersection::Collinear, or
SegmentIntersection::OutOfRange.
Mirrors the segment-segment arm of Boost’s Cartesian intersection
strategy (strategy/cartesian/intersection.hpp). Cartesian only;
the point type must be constructible (PointMut + Default) so
a computed intersection point can be returned in the caller’s own
point type, exactly as Boost returns points of the input type.
§Examples
use geometry_cs::Cartesian;
use geometry_model::{Point2D, Segment};
use geometry_overlay::predicate::segment_intersection::{
segment_intersection, SegmentIntersection,
};
type P = Point2D<f64, Cartesian>;
// An "X" crossing at (1, 1).
let a = Segment::new(P::new(0.0, 0.0), P::new(2.0, 2.0));
let b = Segment::new(P::new(0.0, 2.0), P::new(2.0, 0.0));
match segment_intersection(&a, &b) {
SegmentIntersection::Single(p) => {
use geometry_trait::Point as _;
assert_eq!(p.get::<0>(), 1.0);
assert_eq!(p.get::<1>(), 1.0);
}
other => panic!("expected a single crossing, got {other:?}"),
}