parry2d/query/point/
point_heightfield.rs1use crate::bounding_volume::Aabb;
2#[cfg(not(feature = "std"))]
3use crate::math::ComplexField;
4use crate::math::{Real, Vector};
5use crate::query::{PointProjection, PointQuery, PointQueryWithLocation};
6use crate::shape::{FeatureId, HeightField, TrianglePointLocation}; impl PointQuery for HeightField {
9 fn project_local_point_with_max_dist(
10 &self,
11 pt: Vector,
12 solid: bool,
13 max_dist: Real,
14 ) -> Option<PointProjection> {
15 let aabb = Aabb::new(pt - Vector::splat(max_dist), pt + Vector::splat(max_dist));
16 let mut sq_smallest_dist = Real::MAX;
17 let mut best_proj = None;
18
19 self.map_elements_in_local_aabb(&aabb, &mut |_, triangle| {
20 let proj = triangle.project_local_point(pt, solid);
21 let sq_dist = (pt - proj.point).length_squared();
22
23 if sq_dist < sq_smallest_dist {
24 sq_smallest_dist = sq_dist;
25
26 if sq_dist.sqrt() <= max_dist {
27 best_proj = Some(proj);
28 }
29 }
30 });
31
32 best_proj
33 }
34
35 #[inline]
36 fn project_local_point(&self, point: Vector, _: bool) -> PointProjection {
37 let mut smallest_dist = Real::MAX;
38 let mut best_proj = PointProjection::new(false, point);
39
40 #[cfg(feature = "dim2")]
41 let iter = self.segments();
42 #[cfg(feature = "dim3")]
43 let iter = self.triangles();
44 for elt in iter {
45 let proj = elt.project_local_point(point, false);
46 let dist = (point - proj.point).length_squared();
47
48 if dist < smallest_dist {
49 smallest_dist = dist;
50 best_proj = proj;
51 }
52 }
53
54 best_proj
55 }
56
57 #[inline]
58 fn project_local_point_and_get_feature(&self, point: Vector) -> (PointProjection, FeatureId) {
59 (self.project_local_point(point, false), FeatureId::Unknown)
61 }
62
63 #[inline]
66 fn contains_local_point(&self, _point: Vector) -> bool {
67 false
68 }
69}
70
71impl PointQueryWithLocation for HeightField {
72 type Location = (usize, TrianglePointLocation);
73
74 #[inline]
75 fn project_local_point_and_get_location(
76 &self,
77 _point: Vector,
78 _: bool,
79 ) -> (PointProjection, Self::Location) {
80 unimplemented!()
81 }
82}