collision-rs
collision-rs copied to clipboard
Line3.intersects(AABB3)
I need to test if an AABB3 intersects OR contains a Line3, so I wrote this patch
/// Tests if the AABB contains OR intersects a line.
fn intersects(&self, aabb: &Aabb3<S>) -> bool {...
This seems to be in line with how AABB3.intersects(AABB3)
and Sphere3.intersects(Sphere3)
works:
let aabb = Aabb3::new(Point3::new(0., 0., 0.), Point3::new(10., 10., 10.));
let entirely_inside = Aabb3::new(Point3::new(4., 4., 4.), Point3::new(6., 6., 6.));
let partly_outside = Aabb3::new(Point3::new(4., 4., 4.), Point3::new(6., 6., 60.));
assert!(aabb.intersects(&entirely_inside));
assert!(aabb.intersects(&partly_outside));
let sphere = Sphere {center: Point3::new(0f64, 0f64, 0f64),radius: 1f64,};
let entirely_inside = Sphere {center: Point3::new(0.5f64, 0f64, 0f64),radius: 0.001f64,};
let partly_outside = Sphere {center: Point3::new(0.5f64, 0f64, 0f64),radius: 1f64,};
assert!(sphere.intersects(&entirely_inside));
assert!(sphere.intersects(&partly_outside));
But does a line, entirely contained within an AABB, really intersect it? I would have difficulties pointing at any intersection point. If it does, maybe this should be clearly documented in the trait? Or maybe I should have implement some other trait?
I guess one could interpret intersection as "if anything occupies any part of the volume(for 3d) or area(for 2d) of an AABB, it's a hit"
Anyhow, could someone check if my patch is something you want include (or give some feedback)? I'd be happy to make a PR.
P. S. There is an issue I've noticed: If the Line skims the surface of the AABB it will not register as an intersection. But the same is true for Ray.intersects(AABB)
tests (#27).
P.S.S In the process I implemented Try_From(Line)->Ray
(Euclidian). Turns out I could not use it, but it is still in there.