Skip to main content

parry3d/query/intersection_test/
intersection_test_ball_point_query.rs

1use crate::math::Pose;
2use crate::query::{PointQuery, ShapeIntersection};
3use crate::shape::Ball;
4
5/// Intersection test between a ball and a shape implementing the `PointQuery` trait.
6pub fn intersection_test_ball_point_query<P: ?Sized + PointQuery>(
7    pos12: &Pose,
8    ball1: &Ball,
9    point_query2: &P,
10) -> ShapeIntersection {
11    intersection_test_point_query_ball(&pos12.inverse(), point_query2, ball1).swapped()
12}
13
14/// Intersection test between a shape implementing the `PointQuery` trait and a ball.
15pub fn intersection_test_point_query_ball<P: ?Sized + PointQuery>(
16    pos12: &Pose,
17    point_query1: &P,
18    ball2: &Ball,
19) -> ShapeIntersection {
20    let local_p2_1 = pos12.translation;
21    let proj = point_query1.project_local_point(local_p2_1, true);
22    let intersecting =
23        proj.is_inside || (local_p2_1 - proj.point).length_squared() <= ball2.radius * ball2.radius;
24    // The projection knows which sub-shape of `point_query1` answered.
25    ShapeIntersection::new(intersecting).with_subshapes(proj.subshape, 0)
26}