ncollide3d/query/point/
point_heightfield.rs
1use crate::math::{Isometry, Point};
2use crate::query::{PointProjection, PointQuery, PointQueryWithLocation};
3use crate::shape::{FeatureId, HeightField, TrianglePointLocation};
4use na::{self, RealField};
5
6impl<N: RealField + Copy> PointQuery<N> for HeightField<N> {
7 #[inline]
8 fn project_point(&self, m: &Isometry<N>, point: &Point<N>, _: bool) -> PointProjection<N> {
9 let mut smallest_dist = N::max_value().unwrap();
10 let mut best_proj = PointProjection::new(false, *point);
11
12 #[cfg(feature = "dim2")]
13 let iter = self.segments();
14 #[cfg(feature = "dim3")]
15 let iter = self.triangles();
16 for elt in iter {
17 let proj = elt.project_point(m, point, false);
18 let dist = na::distance_squared(point, &proj.point);
19
20 if dist < smallest_dist {
21 smallest_dist = dist;
22 best_proj = proj;
23 }
24 }
25
26 best_proj
27 }
28
29 #[inline]
30 fn project_point_with_feature(
31 &self,
32 m: &Isometry<N>,
33 point: &Point<N>,
34 ) -> (PointProjection<N>, FeatureId) {
35 (self.project_point(m, point, false), FeatureId::Unknown)
37 }
38
39 #[inline]
42 fn contains_point(&self, _m: &Isometry<N>, _point: &Point<N>) -> bool {
43 false
44 }
45}
46
47impl<N: RealField + Copy> PointQueryWithLocation<N> for HeightField<N> {
48 type Location = (usize, TrianglePointLocation<N>);
49
50 #[inline]
51 fn project_point_with_location(
52 &self,
53 _m: &Isometry<N>,
54 _point: &Point<N>,
55 _: bool,
56 ) -> (PointProjection<N>, Self::Location) {
57 unimplemented!()
58 }
59}