Skip to main content

continuous_line2_aabb2

Function continuous_line2_aabb2 

Source
pub fn continuous_line2_aabb2<S>(
    line: Line2<S>,
    aabb: Aabb2<S>,
) -> Option<(Line2Point<S>, Line2Point<S>)>
where S: OrderedRing + Debug,
Expand description

Compute the intersection of a 2D line with a 2D AABB (rectangle).

If the line and AABB intersect, the two intersection points are returned with the scalar parameter corresponding to that point along the line.

let aabb = Aabb2::with_minmax ([-1.0, -1.0].into(), [1.0, 1.0].into()).unwrap();
let line = Line2::new  ([0.0, 0.0].into(), Unit2::axis_x());
assert_eq!(
  continuous_line2_aabb2 (line, aabb).unwrap(),
  ( (-1.0, [-1.0, 0.0].into()),
    ( 1.0, [ 1.0, 0.0].into())
  )
);

Returns None if the line and AABB are tangent:

let aabb = Aabb2::with_minmax ([-1.0, -1.0].into(), [1.0, 1.0].into()).unwrap();
let line = Line2::new  ([0.0, 1.0].into(), Unit2::axis_x());
assert_eq!(continuous_line2_aabb2 (line, aabb), None);