diff --git a/crates/parry2d/examples/point_in_poly2d.rs b/crates/parry2d/examples/point_in_poly2d.rs index c0e5cfd7..fc0a4cb0 100644 --- a/crates/parry2d/examples/point_in_poly2d.rs +++ b/crates/parry2d/examples/point_in_poly2d.rs @@ -29,13 +29,13 @@ async fn main() { .iter_mut() .for_each(|pt| *pt = animation_rotation * *pt); - draw_polygon(&polygon, RENDER_SCALE, polygon_render_pos, BLUE); + draw_polygon(polygon, RENDER_SCALE, polygon_render_pos, BLUE); /* * Compute polygon intersections. */ for point in &test_points { - if point_in_poly2d(point, &polygon) { + if point_in_poly2d(point, polygon) { draw_point(*point, RENDER_SCALE, polygon_render_pos, RED); } else { draw_point(*point, RENDER_SCALE, polygon_render_pos, GREEN); diff --git a/crates/parry2d/examples/raycasts_animated.rs b/crates/parry2d/examples/raycasts_animated.rs index 19999653..65b94042 100644 --- a/crates/parry2d/examples/raycasts_animated.rs +++ b/crates/parry2d/examples/raycasts_animated.rs @@ -83,7 +83,7 @@ async fn main() { fn draw_polygon( polygon: &[Point2], - pose: &Isometry, + pose: &Isometry, scale: f32, shift: Point2, color: Color, diff --git a/crates/parry2d/tests/geometry/epa_convergence.rs b/crates/parry2d/tests/geometry/epa_convergence.rs index e2206104..bf3c1ed5 100644 --- a/crates/parry2d/tests/geometry/epa_convergence.rs +++ b/crates/parry2d/tests/geometry/epa_convergence.rs @@ -1,6 +1,6 @@ use na::Vector2; use parry2d::{ - math::{Isometry, Point, Real}, + math::{Isometry, Point}, query, shape::{Capsule, ConvexPolygon, SharedShape}, }; @@ -9,10 +9,10 @@ use parry2d::{ #[test] fn capsule_convergence() { let shape1 = Capsule::new_y(5.0, 10.0); - let mut vec = Vec::>::with_capacity(3); - vec.push(Point::::new(64.0, 507.0)); - vec.push(Point::::new(440.0, 326.0)); - vec.push(Point::::new(1072.0, 507.0)); + let mut vec = Vec::::with_capacity(3); + vec.push(Point::new(64.0, 507.0)); + vec.push(Point::new(440.0, 326.0)); + vec.push(Point::new(1072.0, 507.0)); let shape2 = ConvexPolygon::from_convex_polyline(vec); let shape2 = shape2.unwrap(); let transform1 = Isometry::new(Vector2::new(381.592, 348.491), 0.0); diff --git a/crates/parry3d/benches/common/default_gen.rs b/crates/parry3d/benches/common/default_gen.rs index ed52d896..638ea2c7 100644 --- a/crates/parry3d/benches/common/default_gen.rs +++ b/crates/parry3d/benches/common/default_gen.rs @@ -64,10 +64,10 @@ where impl DefaultGen for Cuboid where - Standard: Distribution>, + Standard: Distribution, { fn generate(rng: &mut R) -> Cuboid { - Cuboid::new(rng.gen::>().abs()) + Cuboid::new(rng.gen::().abs()) } } @@ -77,8 +77,8 @@ where { fn generate(rng: &mut R) -> Capsule { Capsule::new( - rng.gen::>(), - rng.gen::>(), + rng.gen::(), + rng.gen::(), rng.gen::().abs(), ) } @@ -104,7 +104,7 @@ where impl DefaultGen for Segment where - Standard: Distribution>, + Standard: Distribution, { fn generate(rng: &mut R) -> Segment { Segment::new(rng.gen(), rng.gen()) @@ -113,7 +113,7 @@ where impl DefaultGen for Triangle where - Standard: Distribution>, + Standard: Distribution, { fn generate(rng: &mut R) -> Triangle { Triangle::new(rng.gen(), rng.gen(), rng.gen()) @@ -134,22 +134,22 @@ where impl DefaultGen for Ray where - Standard: Distribution>, + Standard: Distribution, { fn generate(rng: &mut R) -> Ray { // The generate ray will always point to the origin. - let shift = rng.gen::>() * na::convert::<_, Real>(10.0f64); + let shift = rng.gen::() * na::convert::<_, Real>(10.0f64); Ray::new(Point::origin() + shift, -shift) } } impl DefaultGen for Aabb where - Standard: Distribution>, + Standard: Distribution, { fn generate(rng: &mut R) -> Aabb { // an Aabb centered at the origin. - let half_extents = rng.gen::>().abs(); + let half_extents = rng.gen::().abs(); Aabb::new( Point::origin() + (-half_extents), Point::origin() + half_extents, diff --git a/crates/parry3d/examples/common_macroquad3d.rs b/crates/parry3d/examples/common_macroquad3d.rs index bd3617fa..6178e192 100644 --- a/crates/parry3d/examples/common_macroquad3d.rs +++ b/crates/parry3d/examples/common_macroquad3d.rs @@ -120,16 +120,13 @@ pub fn mquad_mesh_from_points( let vertices: Vec = mquad_compute_normals_and_bake_light(&mquad_points, &mquad_indices, light_pos); // Regenerate the index for each vertex. - let indices: Vec = (0..vertices.len() * 3) - .into_iter() - .map(|i| i as u16) - .collect(); - let mesh = Mesh { + let indices: Vec = (0..vertices.len() * 3).map(|i| i as u16).collect(); + + Mesh { vertices, indices, texture: None, - }; - mesh + } } /// Bakes light into vertices, using an hardcoded light strength. @@ -158,7 +155,7 @@ pub fn mquad_compute_normals_and_bake_light( vertices.push(Vertex { position: points[i as usize].position, uv: Vec2::ZERO, - color: color, + color, normal: Vec4::ZERO, }); } diff --git a/crates/parry3d/tests/geometry/cuboid_ray_cast.rs b/crates/parry3d/tests/geometry/cuboid_ray_cast.rs index 9c1cf7c2..3c350310 100644 --- a/crates/parry3d/tests/geometry/cuboid_ray_cast.rs +++ b/crates/parry3d/tests/geometry/cuboid_ray_cast.rs @@ -32,10 +32,12 @@ where let intersection = shape .cast_ray_and_get_normal(&position, &ray, std::f32::MAX, true) - .expect(&format!( - "Ray {:?} did not hit Shape {} rotated with {:?}", - ray, name, rotation - )); + .unwrap_or_else(|| { + panic!( + "Ray {:?} did not hit Shape {} rotated with {:?}", + ray, name, rotation + ) + }); let point = ray.origin + ray.dir * intersection.time_of_impact; let point_nudged_in = point + intersection.normal * -0.001; diff --git a/crates/parry3d/tests/geometry/epa3.rs b/crates/parry3d/tests/geometry/epa3.rs index e77c38f3..6fbb7b93 100644 --- a/crates/parry3d/tests/geometry/epa3.rs +++ b/crates/parry3d/tests/geometry/epa3.rs @@ -43,7 +43,7 @@ fn triangle_vertex_touches_triangle_edge_epa() { &Isometry3::identity(), &mesh1, &mesh2, - 0.00999999977, + 0.01, &mut VoronoiSimplex::new(), None, ); diff --git a/crates/parry3d/tests/geometry/time_of_impact3.rs b/crates/parry3d/tests/geometry/time_of_impact3.rs index 71cbcf45..b8eeac95 100644 --- a/crates/parry3d/tests/geometry/time_of_impact3.rs +++ b/crates/parry3d/tests/geometry/time_of_impact3.rs @@ -1,5 +1,4 @@ use na::{self, Isometry3, Vector3}; -use parry3d::math::Real; use parry3d::query::{self, ShapeCastOptions}; use parry3d::shape::{Ball, Cuboid}; @@ -56,7 +55,7 @@ fn ball_cuboid_toi() { assert_eq!(toi_intersecting, Some(0.0)); assert!(relative_eq!( toi_will_touch.unwrap(), - ((3.0 as Real).sqrt() - 1.0) / (ball_vel2 - cuboid_vel2).norm() + (3.0_f32.sqrt() - 1.0) / (ball_vel2 - cuboid_vel2).norm() )); assert_eq!(toi_wont_touch, None); } diff --git a/crates/parry3d/tests/geometry/trimesh_intersection.rs b/crates/parry3d/tests/geometry/trimesh_intersection.rs index 94df835c..134d1e36 100644 --- a/crates/parry3d/tests/geometry/trimesh_intersection.rs +++ b/crates/parry3d/tests/geometry/trimesh_intersection.rs @@ -1,9 +1,9 @@ use na::{Point3, Vector3}; -use parry3d::math::{Isometry, Real}; +use parry3d::math::Isometry; use parry3d::query::IntersectResult; use parry3d::shape::TriMesh; -fn build_diamond(position: &Isometry) -> TriMesh { +fn build_diamond(position: &Isometry) -> TriMesh { // Two tetrahedrons sharing a face let points = vec![ position * Point3::new(0.0, 2.0, 0.0), diff --git a/src/bounding_volume/aabb.rs b/src/bounding_volume/aabb.rs index d6d44426..5319fab4 100644 --- a/src/bounding_volume/aabb.rs +++ b/src/bounding_volume/aabb.rs @@ -26,8 +26,8 @@ use rkyv::{bytecheck, CheckBytes}; #[derive(Debug, PartialEq, Copy, Clone)] #[repr(C)] pub struct Aabb { - pub mins: Point, - pub maxs: Point, + pub mins: Point, + pub maxs: Point, } impl Aabb { @@ -92,7 +92,7 @@ impl Aabb { /// * `maxs` - position of the point with the highest coordinates. Each component of `mins` /// must be smaller than the related components of `maxs`. #[inline] - pub fn new(mins: Point, maxs: Point) -> Aabb { + pub fn new(mins: Point, maxs: Point) -> Aabb { Aabb { mins, maxs } } @@ -109,27 +109,27 @@ impl Aabb { /// Creates a new `Aabb` from its center and its half-extents. #[inline] - pub fn from_half_extents(center: Point, half_extents: Vector) -> Self { + pub fn from_half_extents(center: Point, half_extents: Vector) -> Self { Self::new(center - half_extents, center + half_extents) } /// Creates a new `Aabb` from a set of points. pub fn from_points<'a, I>(pts: I) -> Self where - I: IntoIterator>, + I: IntoIterator, { super::aabb_utils::local_point_cloud_aabb(pts) } /// The center of this `Aabb`. #[inline] - pub fn center(&self) -> Point { + pub fn center(&self) -> Point { na::center(&self.mins, &self.maxs) } /// The half extents of this `Aabb`. #[inline] - pub fn half_extents(&self) -> Vector { + pub fn half_extents(&self) -> Vector { let half: Real = na::convert::(0.5); (self.maxs - self.mins) * half } @@ -146,19 +146,19 @@ impl Aabb { /// The extents of this `Aabb`. #[inline] - pub fn extents(&self) -> Vector { + pub fn extents(&self) -> Vector { self.maxs - self.mins } /// Enlarges this `Aabb` so it also contains the point `pt`. - pub fn take_point(&mut self, pt: Point) { + pub fn take_point(&mut self, pt: Point) { self.mins = self.mins.coords.inf(&pt.coords).into(); self.maxs = self.maxs.coords.sup(&pt.coords).into(); } /// Computes the `Aabb` bounding `self` transformed by `m`. #[inline] - pub fn transform_by(&self, m: &Isometry) -> Self { + pub fn transform_by(&self, m: &Isometry) -> Self { let ls_center = self.center(); let center = m * ls_center; let ws_half_extents = m.absolute_transform_vector(&self.half_extents()); @@ -167,7 +167,7 @@ impl Aabb { } #[inline] - pub fn scaled(self, scale: &Vector) -> Self { + pub fn scaled(self, scale: &Vector) -> Self { let a = self.mins.coords.component_mul(scale); let b = self.maxs.coords.component_mul(scale); Self { @@ -184,7 +184,7 @@ impl Aabb { /// by its absolute value. #[inline] #[must_use] - pub fn scaled_wrt_center(self, scale: &Vector) -> Self { + pub fn scaled_wrt_center(self, scale: &Vector) -> Self { let center = self.center(); // Multiply the extents by the scale. Negative scaling might modify the half-extent // sign, so we take the absolute value. The AABB being symmetric that absolute value @@ -203,7 +203,7 @@ impl Aabb { /// Does this AABB contains a point expressed in the same coordinate frame as `self`? #[inline] - pub fn contains_local_point(&self, point: &Point) -> bool { + pub fn contains_local_point(&self, point: &Point) -> bool { for i in 0..DIM { if point[i] < self.mins[i] || point[i] > self.maxs[i] { return false; @@ -215,7 +215,7 @@ impl Aabb { /// Does this AABB intersects an AABB `aabb2` moving at velocity `vel12` relative to `self`? #[inline] - pub fn intersects_moving_aabb(&self, aabb2: &Self, vel12: Vector) -> bool { + pub fn intersects_moving_aabb(&self, aabb2: &Self, vel12: Vector) -> bool { // Minkowski sum. let msum = Aabb { mins: self.mins - aabb2.maxs.coords, @@ -311,7 +311,7 @@ impl Aabb { /// Computes the vertices of this `Aabb`. #[inline] #[cfg(feature = "dim2")] - pub fn vertices(&self) -> [Point; 4] { + pub fn vertices(&self) -> [Point; 4] { [ Point::new(self.mins.x, self.mins.y), Point::new(self.mins.x, self.maxs.y), @@ -323,7 +323,7 @@ impl Aabb { /// Computes the vertices of this `Aabb`. #[inline] #[cfg(feature = "dim3")] - pub fn vertices(&self) -> [Point; 8] { + pub fn vertices(&self) -> [Point; 8] { [ Point::new(self.mins.x, self.mins.y, self.mins.z), Point::new(self.maxs.x, self.mins.y, self.mins.z), @@ -399,7 +399,7 @@ impl Aabb { } /// Projects every point of `Aabb` on an arbitrary axis. - pub fn project_on_axis(&self, axis: &UnitVector) -> (Real, Real) { + pub fn project_on_axis(&self, axis: &UnitVector) -> (Real, Real) { let cuboid = Cuboid::new(self.half_extents()); let shift = cuboid .local_support_point_toward(axis) @@ -414,27 +414,27 @@ impl Aabb { #[cfg(feature = "std")] pub fn intersects_spiral( &self, - point: &Point, - center: &Point, - axis: &UnitVector, - linvel: &Vector, + point: &Point, + center: &Point, + axis: &UnitVector, + linvel: &Vector, angvel: Real, ) -> bool { use crate::utils::WBasis; use crate::utils::{Interval, IntervalFunction}; struct SpiralPlaneDistance { - center: Point, - tangents: [Vector; 2], - linvel: Vector, + center: Point, + tangents: [Vector; 2], + linvel: Vector, angvel: Real, point: na::Vector2, - plane: Vector, + plane: Vector, bias: Real, } impl SpiralPlaneDistance { - fn spiral_pt_at(&self, t: Real) -> Point { + fn spiral_pt_at(&self, t: Real) -> Point { let angle = t * self.angvel; // NOTE: we construct the rotation matrix explicitly here instead @@ -544,7 +544,7 @@ impl Aabb { impl BoundingVolume for Aabb { #[inline] - fn center(&self) -> Point { + fn center(&self) -> Point { self.center() } diff --git a/src/bounding_volume/aabb_ball.rs b/src/bounding_volume/aabb_ball.rs index 5d75021d..6dce408e 100644 --- a/src/bounding_volume/aabb_ball.rs +++ b/src/bounding_volume/aabb_ball.rs @@ -4,7 +4,7 @@ use crate::shape::Ball; /// Computes the Axis-Aligned Bounding Box of a ball transformed by `center`. #[inline] -pub fn ball_aabb(center: &Point, radius: Real) -> Aabb { +pub fn ball_aabb(center: &Point, radius: Real) -> Aabb { Aabb::new( *center + Vector::repeat(-radius), *center + Vector::repeat(radius), @@ -22,8 +22,8 @@ pub fn local_ball_aabb(radius: Real) -> Aabb { impl Ball { /// Computes the world-space [`Aabb`] of this ball transformed by `pos`. #[inline] - pub fn aabb(&self, pos: &Isometry) -> Aabb { - ball_aabb(&Point::::from(pos.translation.vector), self.radius) + pub fn aabb(&self, pos: &Isometry) -> Aabb { + ball_aabb(&Point::from(pos.translation.vector), self.radius) } /// Computes the local-space [`Aabb`] of this ball. diff --git a/src/bounding_volume/aabb_capsule.rs b/src/bounding_volume/aabb_capsule.rs index b735ab05..2b04a29c 100644 --- a/src/bounding_volume/aabb_capsule.rs +++ b/src/bounding_volume/aabb_capsule.rs @@ -1,11 +1,11 @@ use crate::bounding_volume::Aabb; -use crate::math::{Isometry, Real, Vector}; +use crate::math::{Isometry, Vector}; use crate::shape::Capsule; impl Capsule { /// The axis-aligned bounding box of this capsule. #[inline] - pub fn aabb(&self, pos: &Isometry) -> Aabb { + pub fn aabb(&self, pos: &Isometry) -> Aabb { self.transform_by(pos).local_aabb() } diff --git a/src/bounding_volume/aabb_convex_polygon.rs b/src/bounding_volume/aabb_convex_polygon.rs index 521dfc75..acaf879b 100644 --- a/src/bounding_volume/aabb_convex_polygon.rs +++ b/src/bounding_volume/aabb_convex_polygon.rs @@ -1,11 +1,11 @@ use crate::bounding_volume::Aabb; -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::shape::ConvexPolygon; impl ConvexPolygon { /// Computes the world-space [`Aabb`] of this convex polygon, transformed by `pos`. #[inline] - pub fn aabb(&self, pos: &Isometry) -> Aabb { + pub fn aabb(&self, pos: &Isometry) -> Aabb { super::details::point_cloud_aabb(pos, self.points()) } diff --git a/src/bounding_volume/aabb_convex_polyhedron.rs b/src/bounding_volume/aabb_convex_polyhedron.rs index 790cee5e..62bb4bdb 100644 --- a/src/bounding_volume/aabb_convex_polyhedron.rs +++ b/src/bounding_volume/aabb_convex_polyhedron.rs @@ -1,11 +1,11 @@ use crate::bounding_volume::Aabb; -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::shape::ConvexPolyhedron; impl ConvexPolyhedron { /// Computes the world-space [`Aabb`] of this convex polyhedron, transformed by `pos`. #[inline] - pub fn aabb(&self, pos: &Isometry) -> Aabb { + pub fn aabb(&self, pos: &Isometry) -> Aabb { super::details::point_cloud_aabb(pos, self.points()) } diff --git a/src/bounding_volume/aabb_cuboid.rs b/src/bounding_volume/aabb_cuboid.rs index 4bb2ebe2..6914f9c6 100644 --- a/src/bounding_volume/aabb_cuboid.rs +++ b/src/bounding_volume/aabb_cuboid.rs @@ -1,12 +1,12 @@ use crate::bounding_volume::Aabb; -use crate::math::{Isometry, Point, Real}; +use crate::math::{Isometry, Point}; use crate::shape::Cuboid; use crate::utils::IsometryOps; impl Cuboid { /// Computes the world-space [`Aabb`] of this cuboid, transformed by `pos`. #[inline] - pub fn aabb(&self, pos: &Isometry) -> Aabb { + pub fn aabb(&self, pos: &Isometry) -> Aabb { let center = Point::from(pos.translation.vector); let ws_half_extents = pos.absolute_transform_vector(&self.half_extents); diff --git a/src/bounding_volume/aabb_halfspace.rs b/src/bounding_volume/aabb_halfspace.rs index 017a04a0..2a9b8ce8 100644 --- a/src/bounding_volume/aabb_halfspace.rs +++ b/src/bounding_volume/aabb_halfspace.rs @@ -7,7 +7,7 @@ use na; impl HalfSpace { /// Computes the world-space [`Aabb`] of this half-space. #[inline] - pub fn aabb(&self, _pos: &Isometry) -> Aabb { + pub fn aabb(&self, _pos: &Isometry) -> Aabb { self.local_aabb() } diff --git a/src/bounding_volume/aabb_heightfield.rs b/src/bounding_volume/aabb_heightfield.rs index c97ae3ce..5bc5f49c 100644 --- a/src/bounding_volume/aabb_heightfield.rs +++ b/src/bounding_volume/aabb_heightfield.rs @@ -1,11 +1,11 @@ use crate::bounding_volume::Aabb; -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::shape::HeightField; impl HeightField { /// Computes the world-space [`Aabb`] of this heightfield, transformed by `pos`. #[inline] - pub fn aabb(&self, pos: &Isometry) -> Aabb { + pub fn aabb(&self, pos: &Isometry) -> Aabb { self.root_aabb().transform_by(pos) } diff --git a/src/bounding_volume/aabb_support_map.rs b/src/bounding_volume/aabb_support_map.rs index 754d8ff3..ea4958f5 100644 --- a/src/bounding_volume/aabb_support_map.rs +++ b/src/bounding_volume/aabb_support_map.rs @@ -1,6 +1,6 @@ use crate::bounding_volume; use crate::bounding_volume::Aabb; -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::shape::Segment; #[cfg(feature = "dim3")] use crate::shape::{Cone, Cylinder}; @@ -9,7 +9,7 @@ use crate::shape::{Cone, Cylinder}; impl Cone { /// Computes the world-space [`Aabb`] of this cone, transformed by `pos`. #[inline] - pub fn aabb(&self, pos: &Isometry) -> Aabb { + pub fn aabb(&self, pos: &Isometry) -> Aabb { bounding_volume::details::support_map_aabb(pos, self) } @@ -24,7 +24,7 @@ impl Cone { impl Cylinder { /// Computes the world-space [`Aabb`] of this cylinder, transformed by `pos`. #[inline] - pub fn aabb(&self, pos: &Isometry) -> Aabb { + pub fn aabb(&self, pos: &Isometry) -> Aabb { bounding_volume::details::support_map_aabb(pos, self) } @@ -38,7 +38,7 @@ impl Cylinder { impl Segment { /// Computes the world-space [`Aabb`] of this segment, transformed by `pos`. #[inline] - pub fn aabb(&self, pos: &Isometry) -> Aabb { + pub fn aabb(&self, pos: &Isometry) -> Aabb { self.transformed(pos).local_aabb() } diff --git a/src/bounding_volume/aabb_triangle.rs b/src/bounding_volume/aabb_triangle.rs index 1c8867c0..ec3c92aa 100644 --- a/src/bounding_volume/aabb_triangle.rs +++ b/src/bounding_volume/aabb_triangle.rs @@ -1,13 +1,13 @@ use crate::{ bounding_volume::Aabb, - math::{Isometry, Point, Real, DIM}, + math::{Isometry, Point, DIM}, shape::Triangle, }; impl Triangle { /// Computes the world-space [`Aabb`] of this triangle, transformed by `pos`. #[inline] - pub fn aabb(&self, pos: &Isometry) -> Aabb { + pub fn aabb(&self, pos: &Isometry) -> Aabb { self.transformed(pos).local_aabb() } diff --git a/src/bounding_volume/aabb_utils.rs b/src/bounding_volume/aabb_utils.rs index 79ac72d5..f87ab55d 100644 --- a/src/bounding_volume/aabb_utils.rs +++ b/src/bounding_volume/aabb_utils.rs @@ -1,19 +1,19 @@ use std::iter::IntoIterator; use crate::bounding_volume::Aabb; -use crate::math::{Isometry, Point, Real, Vector, DIM}; +use crate::math::{Isometry, Point, Vector, DIM}; use crate::shape::SupportMap; use na; /// Computes the [`Aabb`] of an [support mapped shape](SupportMap). #[cfg(feature = "dim3")] -pub fn support_map_aabb(m: &Isometry, i: &G) -> Aabb +pub fn support_map_aabb(m: &Isometry, i: &G) -> Aabb where G: SupportMap, { - let mut min = na::zero::>(); - let mut max = na::zero::>(); - let mut basis = na::zero::>(); + let mut min = na::zero::(); + let mut max = na::zero::(); + let mut basis = na::zero::(); for d in 0..DIM { // TODO: this could be further improved iterating on `m`'s columns, and passing @@ -35,9 +35,9 @@ pub fn local_support_map_aabb(i: &G) -> Aabb where G: SupportMap, { - let mut min = na::zero::>(); - let mut max = na::zero::>(); - let mut basis = na::zero::>(); + let mut min = na::zero::(); + let mut max = na::zero::(); + let mut basis = na::zero::(); for d in 0..DIM { // TODO: this could be further improved iterating on `m`'s columns, and passing @@ -55,9 +55,9 @@ where } /// Computes the [`Aabb`] of a set of points transformed by `m`. -pub fn point_cloud_aabb<'a, I>(m: &Isometry, pts: I) -> Aabb +pub fn point_cloud_aabb<'a, I>(m: &Isometry, pts: I) -> Aabb where - I: IntoIterator>, + I: IntoIterator, { let mut it = pts.into_iter(); @@ -65,8 +65,8 @@ where "Point cloud Aabb construction: the input iterator should yield at least one point.", ); let wp0 = m.transform_point(p0); - let mut min: Point = wp0; - let mut max: Point = wp0; + let mut min: Point = wp0; + let mut max: Point = wp0; for pt in it { let wpt = m * pt; @@ -80,15 +80,15 @@ where /// Computes the [`Aabb`] of a set of points. pub fn local_point_cloud_aabb<'a, I>(pts: I) -> Aabb where - I: IntoIterator>, + I: IntoIterator, { let mut it = pts.into_iter(); let p0 = it.next().expect( "Point cloud Aabb construction: the input iterator should yield at least one point.", ); - let mut min: Point = *p0; - let mut max: Point = *p0; + let mut min: Point = *p0; + let mut max: Point = *p0; for pt in it { min = min.inf(pt); diff --git a/src/bounding_volume/bounding_sphere.rs b/src/bounding_volume/bounding_sphere.rs index fc1e4a44..210a3c7b 100644 --- a/src/bounding_volume/bounding_sphere.rs +++ b/src/bounding_volume/bounding_sphere.rs @@ -19,19 +19,19 @@ use rkyv::{bytecheck, CheckBytes}; #[derive(Debug, PartialEq, Copy, Clone)] #[repr(C)] pub struct BoundingSphere { - pub center: Point, + pub center: Point, pub radius: Real, } impl BoundingSphere { /// Creates a new bounding sphere. - pub fn new(center: Point, radius: Real) -> BoundingSphere { + pub fn new(center: Point, radius: Real) -> BoundingSphere { BoundingSphere { center, radius } } /// The bounding sphere center. #[inline] - pub fn center(&self) -> &Point { + pub fn center(&self) -> &Point { &self.center } @@ -43,14 +43,14 @@ impl BoundingSphere { /// Transforms this bounding sphere by `m`. #[inline] - pub fn transform_by(&self, m: &Isometry) -> BoundingSphere { + pub fn transform_by(&self, m: &Isometry) -> BoundingSphere { BoundingSphere::new(m * self.center, self.radius) } } impl BoundingVolume for BoundingSphere { #[inline] - fn center(&self) -> Point { + fn center(&self) -> Point { *self.center() } diff --git a/src/bounding_volume/bounding_sphere_ball.rs b/src/bounding_volume/bounding_sphere_ball.rs index dde07cf2..55f3aa87 100644 --- a/src/bounding_volume/bounding_sphere_ball.rs +++ b/src/bounding_volume/bounding_sphere_ball.rs @@ -1,11 +1,11 @@ use crate::bounding_volume::BoundingSphere; -use crate::math::{Isometry, Point, Real}; +use crate::math::{Isometry, Point}; use crate::shape::Ball; impl Ball { /// Computes the world-space bounding sphere of this ball, transformed by `pos`. #[inline] - pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { + pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { let bv: BoundingSphere = self.local_bounding_sphere(); bv.transform_by(pos) } diff --git a/src/bounding_volume/bounding_sphere_capsule.rs b/src/bounding_volume/bounding_sphere_capsule.rs index 6b274859..9c5f9433 100644 --- a/src/bounding_volume/bounding_sphere_capsule.rs +++ b/src/bounding_volume/bounding_sphere_capsule.rs @@ -1,11 +1,11 @@ use crate::bounding_volume::BoundingSphere; -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::shape::Capsule; impl Capsule { /// Computes the world-space bounding sphere of this capsule, transformed by `pos`. #[inline] - pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { + pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { self.local_bounding_sphere().transform_by(pos) } diff --git a/src/bounding_volume/bounding_sphere_cone.rs b/src/bounding_volume/bounding_sphere_cone.rs index ae95802b..71482589 100644 --- a/src/bounding_volume/bounding_sphere_cone.rs +++ b/src/bounding_volume/bounding_sphere_cone.rs @@ -1,12 +1,12 @@ use crate::bounding_volume::BoundingSphere; -use crate::math::{Isometry, Point, Real}; +use crate::math::{Isometry, Point}; use crate::shape::Cone; use na::ComplexField; impl Cone { /// Computes the world-space bounding sphere of this cone, transformed by `pos`. #[inline] - pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { + pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { let bv: BoundingSphere = self.local_bounding_sphere(); bv.transform_by(pos) } diff --git a/src/bounding_volume/bounding_sphere_convex.rs b/src/bounding_volume/bounding_sphere_convex.rs index 793bd3ec..43c8fa68 100644 --- a/src/bounding_volume/bounding_sphere_convex.rs +++ b/src/bounding_volume/bounding_sphere_convex.rs @@ -1,12 +1,12 @@ use crate::bounding_volume; use crate::bounding_volume::BoundingSphere; -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::shape::ConvexPolyhedron; impl ConvexPolyhedron { /// Computes the world-space bounding sphere of this convex polyhedron, transformed by `pos`. #[inline] - pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { + pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { let bv: BoundingSphere = self.local_bounding_sphere(); bv.transform_by(pos) } diff --git a/src/bounding_volume/bounding_sphere_convex_polygon.rs b/src/bounding_volume/bounding_sphere_convex_polygon.rs index 1f1479a8..fa973f6a 100644 --- a/src/bounding_volume/bounding_sphere_convex_polygon.rs +++ b/src/bounding_volume/bounding_sphere_convex_polygon.rs @@ -1,12 +1,12 @@ use crate::bounding_volume; use crate::bounding_volume::BoundingSphere; -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::shape::ConvexPolygon; impl ConvexPolygon { /// Computes the world-space bounding sphere of this convex polygon, transformed by `pos`. #[inline] - pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { + pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { let bv: BoundingSphere = self.local_bounding_sphere(); bv.transform_by(pos) } diff --git a/src/bounding_volume/bounding_sphere_cuboid.rs b/src/bounding_volume/bounding_sphere_cuboid.rs index 00cf78ba..320610c1 100644 --- a/src/bounding_volume/bounding_sphere_cuboid.rs +++ b/src/bounding_volume/bounding_sphere_cuboid.rs @@ -1,11 +1,11 @@ use crate::bounding_volume::BoundingSphere; -use crate::math::{Isometry, Point, Real}; +use crate::math::{Isometry, Point}; use crate::shape::Cuboid; impl Cuboid { /// Computes the world-space bounding sphere of this cuboid, transformed by `pos`. #[inline] - pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { + pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { let bv: BoundingSphere = self.local_bounding_sphere(); bv.transform_by(pos) } diff --git a/src/bounding_volume/bounding_sphere_cylinder.rs b/src/bounding_volume/bounding_sphere_cylinder.rs index a2edafb1..a310962c 100644 --- a/src/bounding_volume/bounding_sphere_cylinder.rs +++ b/src/bounding_volume/bounding_sphere_cylinder.rs @@ -1,12 +1,12 @@ use crate::bounding_volume::BoundingSphere; -use crate::math::{Isometry, Point, Real}; +use crate::math::{Isometry, Point}; use crate::shape::Cylinder; use na::ComplexField; impl Cylinder { /// Computes the world-space bounding sphere of this cylinder, transformed by `pos`. #[inline] - pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { + pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { let bv: BoundingSphere = self.local_bounding_sphere(); bv.transform_by(pos) } diff --git a/src/bounding_volume/bounding_sphere_halfspace.rs b/src/bounding_volume/bounding_sphere_halfspace.rs index f383a1ae..8e587092 100644 --- a/src/bounding_volume/bounding_sphere_halfspace.rs +++ b/src/bounding_volume/bounding_sphere_halfspace.rs @@ -7,7 +7,7 @@ use num::Bounded; impl HalfSpace { /// Computes the world-space bounding sphere of this half-space, transformed by `pos`. #[inline] - pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { + pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { let bv: BoundingSphere = self.local_bounding_sphere(); bv.transform_by(pos) } diff --git a/src/bounding_volume/bounding_sphere_heightfield.rs b/src/bounding_volume/bounding_sphere_heightfield.rs index 714e369f..d4185c46 100644 --- a/src/bounding_volume/bounding_sphere_heightfield.rs +++ b/src/bounding_volume/bounding_sphere_heightfield.rs @@ -1,11 +1,11 @@ use crate::bounding_volume::BoundingSphere; -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::shape::HeightField; impl HeightField { /// Computes the world-space bounding sphere of this height-field, transformed by `pos`. #[inline] - pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { + pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { self.local_aabb().bounding_sphere().transform_by(pos) } diff --git a/src/bounding_volume/bounding_sphere_polyline.rs b/src/bounding_volume/bounding_sphere_polyline.rs index a9a62faf..dff0b41d 100644 --- a/src/bounding_volume/bounding_sphere_polyline.rs +++ b/src/bounding_volume/bounding_sphere_polyline.rs @@ -1,11 +1,11 @@ use crate::bounding_volume::BoundingSphere; -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::shape::Polyline; impl Polyline { /// Computes the world-space bounding sphere of this polyline, transformed by `pos`. #[inline] - pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { + pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { self.local_aabb().bounding_sphere().transform_by(pos) } diff --git a/src/bounding_volume/bounding_sphere_segment.rs b/src/bounding_volume/bounding_sphere_segment.rs index 4069280a..c7f5ddbd 100644 --- a/src/bounding_volume/bounding_sphere_segment.rs +++ b/src/bounding_volume/bounding_sphere_segment.rs @@ -1,12 +1,12 @@ use crate::bounding_volume; use crate::bounding_volume::BoundingSphere; -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::shape::Segment; impl Segment { /// Computes the world-space bounding sphere of this segment, transformed by `pos`. #[inline] - pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { + pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { let bv: BoundingSphere = self.local_bounding_sphere(); bv.transform_by(pos) } diff --git a/src/bounding_volume/bounding_sphere_triangle.rs b/src/bounding_volume/bounding_sphere_triangle.rs index 936a3435..78d0da59 100644 --- a/src/bounding_volume/bounding_sphere_triangle.rs +++ b/src/bounding_volume/bounding_sphere_triangle.rs @@ -1,12 +1,12 @@ use crate::bounding_volume; use crate::bounding_volume::BoundingSphere; -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::shape::Triangle; impl Triangle { /// Computes the world-space bounding sphere of this triangle, transformed by `pos`. #[inline] - pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { + pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { let bv: BoundingSphere = self.local_bounding_sphere(); bv.transform_by(pos) } diff --git a/src/bounding_volume/bounding_sphere_trimesh.rs b/src/bounding_volume/bounding_sphere_trimesh.rs index 6b1a4a7a..a6abd36a 100644 --- a/src/bounding_volume/bounding_sphere_trimesh.rs +++ b/src/bounding_volume/bounding_sphere_trimesh.rs @@ -1,11 +1,11 @@ use crate::bounding_volume::BoundingSphere; -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::shape::TriMesh; impl TriMesh { /// Computes the world-space bounding sphere of this triangle mesh, transformed by `pos`. #[inline] - pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { + pub fn bounding_sphere(&self, pos: &Isometry) -> BoundingSphere { self.local_aabb().bounding_sphere().transform_by(pos) } diff --git a/src/bounding_volume/bounding_sphere_utils.rs b/src/bounding_volume/bounding_sphere_utils.rs index 0a257bea..4a81c806 100644 --- a/src/bounding_volume/bounding_sphere_utils.rs +++ b/src/bounding_volume/bounding_sphere_utils.rs @@ -1,4 +1,4 @@ -use crate::math::{Point, Real}; +use crate::math::Point; use crate::utils; use na::{self, ComplexField}; @@ -6,10 +6,7 @@ use super::BoundingSphere; /// Computes the bounding sphere of a set of point, given its center. #[inline] -pub fn point_cloud_bounding_sphere_with_center( - pts: &[Point], - center: Point, -) -> BoundingSphere { +pub fn point_cloud_bounding_sphere_with_center(pts: &[Point], center: Point) -> BoundingSphere { let mut sqradius = 0.0; for pt in pts.iter() { @@ -24,6 +21,6 @@ pub fn point_cloud_bounding_sphere_with_center( /// Computes a bounding sphere of the specified set of point. #[inline] -pub fn point_cloud_bounding_sphere(pts: &[Point]) -> BoundingSphere { +pub fn point_cloud_bounding_sphere(pts: &[Point]) -> BoundingSphere { point_cloud_bounding_sphere_with_center(pts, utils::center(pts)) } diff --git a/src/bounding_volume/bounding_volume.rs b/src/bounding_volume/bounding_volume.rs index a9cd8b4b..c7921f04 100644 --- a/src/bounding_volume/bounding_volume.rs +++ b/src/bounding_volume/bounding_volume.rs @@ -9,7 +9,7 @@ pub trait BoundingVolume { // TODO: keep that ? What about non-spacial bounding volumes (e.g. bounding cones, curvature // bounds, etc.) ? /// Returns a point inside of this bounding volume. This is ideally its center. - fn center(&self) -> Point; + fn center(&self) -> Point; /// Checks if this bounding volume intersect with another one. fn intersects(&self, _: &Self) -> bool; diff --git a/src/bounding_volume/simd_aabb.rs b/src/bounding_volume/simd_aabb.rs index d07d6299..8d8b9468 100644 --- a/src/bounding_volume/simd_aabb.rs +++ b/src/bounding_volume/simd_aabb.rs @@ -1,5 +1,5 @@ use crate::bounding_volume::Aabb; -use crate::math::{Isometry, Point, Real, SimdBool, SimdReal, Vector, DIM, SIMD_WIDTH}; +use crate::math::{IsometryT, PointT, Real, SimdBool, SimdReal, VectorT, DIM, SIMD_WIDTH}; use crate::query::SimdRay; use crate::utils::{self, IsometryOps}; use num::{One, Zero}; @@ -14,9 +14,9 @@ use simba::simd::{SimdPartialOrd, SimdValue}; )] pub struct SimdAabb { /// The min coordinates of the Aabbs. - pub mins: Point, + pub mins: PointT, /// The max coordinates the Aabbs. - pub maxs: Point, + pub maxs: PointT, } #[cfg(feature = "serde-serialize")] @@ -27,12 +27,12 @@ impl serde::Serialize for SimdAabb { { use serde::ser::SerializeStruct; - let mins: Point<[Real; SIMD_WIDTH]> = Point::from( + let mins: PointT<[Real; SIMD_WIDTH]> = PointT::from( self.mins .coords .map(|e| array![|ii| e.extract(ii); SIMD_WIDTH]), ); - let maxs: Point<[Real; SIMD_WIDTH]> = Point::from( + let maxs: PointT<[Real; SIMD_WIDTH]> = PointT::from( self.maxs .coords .map(|e| array![|ii| e.extract(ii); SIMD_WIDTH]), @@ -74,8 +74,8 @@ impl<'de> serde::Deserialize<'de> for SimdAabb { where A: serde::de::MapAccess<'de>, { - let mut mins: Option> = None; - let mut maxs: Option> = None; + let mut mins: Option> = None; + let mut maxs: Option> = None; while let Some(key) = map.next_key()? { match key { @@ -105,10 +105,10 @@ impl<'de> serde::Deserialize<'de> for SimdAabb { where A: serde::de::SeqAccess<'de>, { - let mins: Point<[Real; SIMD_WIDTH]> = seq + let mins: PointT<[Real; SIMD_WIDTH]> = seq .next_element()? .ok_or_else(|| serde::de::Error::invalid_length(0, &self))?; - let maxs: Point<[Real; SIMD_WIDTH]> = seq + let maxs: PointT<[Real; SIMD_WIDTH]> = seq .next_element()? .ok_or_else(|| serde::de::Error::invalid_length(1, &self))?; let mins = mins.map(SimdReal::from); @@ -130,18 +130,18 @@ impl SimdAabb { /// Builds an SIMD aabb composed of four identical aabbs. pub fn splat(aabb: Aabb) -> Self { Self { - mins: Point::splat(aabb.mins), - maxs: Point::splat(aabb.maxs), + mins: PointT::splat(aabb.mins), + maxs: PointT::splat(aabb.maxs), } } /// The center of all the Aabbs represented by `self``. - pub fn center(&self) -> Point { + pub fn center(&self) -> PointT { na::center(&self.mins, &self.maxs) } /// The half-extents of all the Aabbs represented by `self``. - pub fn half_extents(&self) -> Vector { + pub fn half_extents(&self) -> VectorT { (self.maxs - self.mins) * SimdReal::splat(0.5) } @@ -151,7 +151,7 @@ impl SimdAabb { } /// Return the Aabb of the `self` transformed by the given isometry. - pub fn transform_by(&self, transform: &Isometry) -> Self { + pub fn transform_by(&self, transform: &IsometryT) -> Self { let ls_center = self.center(); let center = transform * ls_center; let ws_half_extents = transform.absolute_transform_vector(&self.half_extents()); @@ -163,7 +163,7 @@ impl SimdAabb { /// Returns a scaled version of this Aabb. #[inline] - pub fn scaled(self, scale: &Vector) -> Self { + pub fn scaled(self, scale: &VectorT) -> Self { let a = self.mins.coords.component_mul(scale); let b = self.maxs.coords.component_mul(scale); Self { @@ -174,8 +174,8 @@ impl SimdAabb { /// Enlarges this bounding volume by the given margin. pub fn loosen(&mut self, margin: SimdReal) { - self.mins -= Vector::repeat(margin); - self.maxs += Vector::repeat(margin); + self.mins -= VectorT::repeat(margin); + self.maxs += VectorT::repeat(margin); } /// Dilate all the Aabbs represented by `self`` by their extents multiplied @@ -243,7 +243,7 @@ impl SimdAabb { } /// Computes the distances between a point and all the Aabbs represented by `self`. - pub fn distance_to_local_point(&self, point: &Point) -> SimdReal { + pub fn distance_to_local_point(&self, point: &PointT) -> SimdReal { let mins_point = self.mins - point; let point_maxs = point - self.maxs; let shift = mins_point.sup(&point_maxs).sup(&na::zero()); @@ -255,12 +255,12 @@ impl SimdAabb { self.mins .coords .sup(&-self.maxs.coords) - .sup(&Vector::zeros()) + .sup(&VectorT::zeros()) .norm() } /// Check which Aabb represented by `self` contains the given `point`. - pub fn contains_local_point(&self, point: &Point) -> SimdBool { + pub fn contains_local_point(&self, point: &PointT) -> SimdBool { #[cfg(feature = "dim2")] return self.mins.x.simd_le(point.x) & self.mins.y.simd_le(point.y) @@ -355,8 +355,8 @@ impl From<[Aabb; SIMD_WIDTH]> for SimdAabb { let maxs = array![|ii| aabbs[ii].maxs; SIMD_WIDTH]; SimdAabb { - mins: Point::from(mins), - maxs: Point::from(maxs), + mins: PointT::from(mins), + maxs: PointT::from(maxs), } } } diff --git a/src/lib.rs b/src/lib.rs index ab47d350..f48b89c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,20 +112,26 @@ pub mod math { /// The dimension of the rotations. pub type AngDim = U3; + /// The point type, parameterized over its scalar type. + pub type PointT = Point3; + /// The point type. - pub type Point = Point3; + pub type Point = Point3; /// The angular vector type. - pub type AngVector = Vector3; + pub type AngVector = Vector3; + + /// The vector type, parameterized over its scalar type. + pub type VectorT = Vector3; /// The vector type. - pub type Vector = Vector3; + pub type Vector = Vector3; /// The unit vector type. - pub type UnitVector = UnitVector3; + pub type UnitVector = UnitVector3; /// The matrix type. - pub type Matrix = Matrix3; + pub type Matrix = Matrix3; /// The vector type with dimension `SpatialDim × 1`. pub type SpatialVector = Vector6; @@ -133,20 +139,23 @@ pub mod math { /// The orientation type. pub type Orientation = Vector3; + /// The transformation matrix type, parameterized over its scalar type. + pub type IsometryT = Isometry3; + /// The transformation matrix type. - pub type Isometry = Isometry3; + pub type Isometry = Isometry3; /// The rotation matrix type. - pub type Rotation = UnitQuaternion; + pub type Rotation = UnitQuaternion; /// The translation type. pub type Translation = Translation3; /// The angular inertia of a rigid body. - pub type AngularInertia = crate::utils::SdpMatrix3; + pub type AngularInertia = crate::utils::SdpMatrix3; /// The principal angular inertia of a rigid body. - pub type PrincipalAngularInertia = Vector3; + pub type PrincipalAngularInertia = Vector3; /// A matrix that represent the cross product with a given vector. pub type CrossMatrix = Matrix3; @@ -183,38 +192,47 @@ pub mod math { /// The dimension of the rotations. pub type AngDim = U1; + /// The point type, parameterized over its scalar type. + pub type PointT = Point2; + /// The point type. - pub type Point = Point2; + pub type Point = Point2; /// The angular vector type. - pub type AngVector = N; + pub type AngVector = Real; + + /// The vector type, parameterized over its scalar type. + pub type VectorT = Vector2; /// The vector type. - pub type Vector = Vector2; + pub type Vector = Vector2; /// The unit vector type. - pub type UnitVector = UnitVector2; + pub type UnitVector = UnitVector2; /// The matrix type. - pub type Matrix = Matrix2; + pub type Matrix = Matrix2; /// The orientation type. pub type Orientation = Vector1; + /// The transformation matrix type, parameterized over its scalar type. + pub type IsometryT = Isometry2; + /// The transformation matrix type. - pub type Isometry = Isometry2; + pub type Isometry = Isometry2; /// The rotation matrix type. - pub type Rotation = UnitComplex; + pub type Rotation = UnitComplex; /// The translation type. pub type Translation = Translation2; /// The angular inertia of a rigid body. - pub type AngularInertia = N; + pub type AngularInertia = Real; /// The principal angular inertia of a rigid body. - pub type PrincipalAngularInertia = N; + pub type PrincipalAngularInertia = Real; /// A matrix that represent the cross product with a given vector. pub type CrossMatrix = Vector2; @@ -228,7 +246,9 @@ pub mod math { #[cfg(not(feature = "simd-is-enabled"))] mod simd { + use simba::simd::AutoBoolx4; + /// The number of lanes of a SIMD number. pub const SIMD_WIDTH: usize = 4; /// SIMD_WIDTH - 1 diff --git a/src/mass_properties/mass_properties.rs b/src/mass_properties/mass_properties.rs index fa863f02..fd7662d7 100644 --- a/src/mass_properties/mass_properties.rs +++ b/src/mass_properties/mass_properties.rs @@ -22,7 +22,7 @@ const EPSILON: Real = f32::EPSILON as Real; /// The local mass properties of a rigid-body. pub struct MassProperties { /// The center of mass of a rigid-body expressed in its local-space. - pub local_com: Point, + pub local_com: Point, /// The inverse of the mass of a rigid-body. /// /// If this is zero, the rigid-body is assumed to have infinite mass. @@ -31,10 +31,10 @@ pub struct MassProperties { /// /// The angular inertia is calculated relative to [`Self::local_com`]. /// Components set to zero are assumed to be infinite along the corresponding principal axis. - pub inv_principal_inertia_sqrt: AngVector, + pub inv_principal_inertia_sqrt: AngVector, #[cfg(feature = "dim3")] /// The principal vectors of the local angular inertia tensor of the rigid-body. - pub principal_inertia_local_frame: Rotation, + pub principal_inertia_local_frame: Rotation, } impl MassProperties { @@ -42,7 +42,7 @@ impl MassProperties { /// /// The center-of-mass is specified in the local-space of the rigid-body. #[cfg(feature = "dim2")] - pub fn new(local_com: Point, mass: Real, principal_inertia: Real) -> Self { + pub fn new(local_com: Point, mass: Real, principal_inertia: Real) -> Self { let inv_mass = utils::inv(mass); let inv_principal_inertia_sqrt = utils::inv(ComplexField::sqrt(principal_inertia)); Self { @@ -58,7 +58,7 @@ impl MassProperties { /// The principal angular inertia are the angular inertia along the coordinate axes in the local-space /// of the rigid-body. #[cfg(feature = "dim3")] - pub fn new(local_com: Point, mass: Real, principal_inertia: AngVector) -> Self { + pub fn new(local_com: Point, mass: Real, principal_inertia: AngVector) -> Self { Self::with_principal_inertia_frame(local_com, mass, principal_inertia, Rotation::identity()) } @@ -69,10 +69,10 @@ impl MassProperties { /// the `principal_inertia_local_frame` expressed in the local-space of the rigid-body. #[cfg(feature = "dim3")] pub fn with_principal_inertia_frame( - local_com: Point, + local_com: Point, mass: Real, - principal_inertia: AngVector, - principal_inertia_local_frame: Rotation, + principal_inertia: AngVector, + principal_inertia_local_frame: Rotation, ) -> Self { let inv_mass = utils::inv(mass); let inv_principal_inertia_sqrt = @@ -90,7 +90,7 @@ impl MassProperties { /// The angular inertia matrix will be diagonalized in order to extract the principal inertia /// values and principal inertia frame. #[cfg(feature = "dim3")] - pub fn with_inertia_matrix(local_com: Point, mass: Real, inertia: Matrix3) -> Self { + pub fn with_inertia_matrix(local_com: Point, mass: Real, inertia: Matrix3) -> Self { let mut eigen = inertia.symmetric_eigen(); if eigen.eigenvectors.determinant() < 0.0 { @@ -119,7 +119,7 @@ impl MassProperties { } /// The angular inertia along the principal inertia axes and center of mass of the rigid-body. - pub fn principal_inertia(&self) -> AngVector { + pub fn principal_inertia(&self) -> AngVector { #[cfg(feature = "dim2")] return utils::inv(self.inv_principal_inertia_sqrt * self.inv_principal_inertia_sqrt); #[cfg(feature = "dim3")] @@ -127,19 +127,19 @@ impl MassProperties { } /// The world-space center of mass of the rigid-body. - pub fn world_com(&self, pos: &Isometry) -> Point { + pub fn world_com(&self, pos: &Isometry) -> Point { pos * self.local_com } #[cfg(feature = "dim2")] /// The world-space inverse angular inertia tensor of the rigid-body. - pub fn world_inv_inertia_sqrt(&self, _rot: &Rotation) -> AngularInertia { + pub fn world_inv_inertia_sqrt(&self, _rot: &Rotation) -> AngularInertia { self.inv_principal_inertia_sqrt } #[cfg(feature = "dim3")] /// The world-space inverse angular inertia tensor of the rigid-body. - pub fn world_inv_inertia_sqrt(&self, rot: &Rotation) -> AngularInertia { + pub fn world_inv_inertia_sqrt(&self, rot: &Rotation) -> AngularInertia { if !self.inv_principal_inertia_sqrt.is_zero() { let mut lhs = (rot * self.principal_inertia_local_frame) .to_rotation_matrix() @@ -183,7 +183,7 @@ impl MassProperties { } #[cfg(feature = "dim2")] - pub(crate) fn construct_shifted_inertia_matrix(&self, shift: Vector) -> Real { + pub(crate) fn construct_shifted_inertia_matrix(&self, shift: Vector) -> Real { let i = utils::inv(self.inv_principal_inertia_sqrt * self.inv_principal_inertia_sqrt); if self.inv_mass != 0.0 { @@ -195,7 +195,7 @@ impl MassProperties { } #[cfg(feature = "dim3")] - pub(crate) fn construct_shifted_inertia_matrix(&self, shift: Vector) -> Matrix3 { + pub(crate) fn construct_shifted_inertia_matrix(&self, shift: Vector) -> Matrix3 { let matrix = self.reconstruct_inertia_matrix(); if self.inv_mass != 0.0 { @@ -209,7 +209,7 @@ impl MassProperties { } /// Transform each element of the mass properties. - pub fn transform_by(&self, m: &Isometry) -> Self { + pub fn transform_by(&self, m: &Isometry) -> Self { // NOTE: we don't apply the parallel axis theorem here // because the center of mass is also transformed. Self { @@ -588,7 +588,7 @@ mod test { #[test] fn mass_properties_sum_no_nan() { - let mp: MassProperties = [MassProperties::zero()].iter().map(|v| *v).sum(); + let mp: MassProperties = [MassProperties::zero()].iter().copied().sum(); assert!(!mp.local_com.x.is_nan() && !mp.local_com.y.is_nan()); #[cfg(feature = "dim3")] assert!(!mp.local_com.z.is_nan()); diff --git a/src/mass_properties/mass_properties_ball.rs b/src/mass_properties/mass_properties_ball.rs index 2e457e88..eb54336a 100644 --- a/src/mass_properties/mass_properties_ball.rs +++ b/src/mass_properties/mass_properties_ball.rs @@ -7,7 +7,7 @@ use na::RealField; impl MassProperties { pub(crate) fn ball_volume_unit_angular_inertia( radius: Real, - ) -> (Real, PrincipalAngularInertia) { + ) -> (Real, PrincipalAngularInertia) { #[cfg(feature = "dim2")] { let volume = Real::pi() * radius * radius; diff --git a/src/mass_properties/mass_properties_capsule.rs b/src/mass_properties/mass_properties_capsule.rs index 6ae3ee1d..8b13d4f6 100644 --- a/src/mass_properties/mass_properties_capsule.rs +++ b/src/mass_properties/mass_properties_capsule.rs @@ -5,7 +5,7 @@ use crate::shape::Capsule; impl MassProperties { /// Computes the mass properties of a capsule. - pub fn from_capsule(density: Real, a: Point, b: Point, radius: Real) -> Self { + pub fn from_capsule(density: Real, a: Point, b: Point, radius: Real) -> Self { let half_height = (b - a).norm() / 2.0; let (cyl_vol, cyl_unit_i) = Self::cylinder_y_volume_unit_inertia(half_height, radius); let (ball_vol, ball_unit_i) = Self::ball_volume_unit_angular_inertia(radius); diff --git a/src/mass_properties/mass_properties_compound.rs b/src/mass_properties/mass_properties_compound.rs index d05d7d97..1ee8e3b9 100644 --- a/src/mass_properties/mass_properties_compound.rs +++ b/src/mass_properties/mass_properties_compound.rs @@ -4,7 +4,7 @@ use crate::shape::SharedShape; impl MassProperties { /// Computes the mass properties of a compound shape. - pub fn from_compound(density: Real, shapes: &[(Isometry, SharedShape)]) -> Self { + pub fn from_compound(density: Real, shapes: &[(Isometry, SharedShape)]) -> Self { shapes .iter() .map(|s| s.1.mass_properties(density).transform_by(&s.0)) diff --git a/src/mass_properties/mass_properties_cone.rs b/src/mass_properties/mass_properties_cone.rs index 8609b5da..6f6f760a 100644 --- a/src/mass_properties/mass_properties_cone.rs +++ b/src/mass_properties/mass_properties_cone.rs @@ -6,7 +6,7 @@ impl MassProperties { pub(crate) fn cone_y_volume_unit_inertia( half_height: Real, radius: Real, - ) -> (Real, PrincipalAngularInertia) { + ) -> (Real, PrincipalAngularInertia) { let volume = radius * radius * Real::pi() * half_height * 2.0 / 3.0; let sq_radius = radius * radius; let sq_height = half_height * half_height * 4.0; diff --git a/src/mass_properties/mass_properties_convex_polygon.rs b/src/mass_properties/mass_properties_convex_polygon.rs index 379366ef..c64b5b1b 100644 --- a/src/mass_properties/mass_properties_convex_polygon.rs +++ b/src/mass_properties/mass_properties_convex_polygon.rs @@ -4,7 +4,7 @@ use crate::shape::Triangle; impl MassProperties { /// Computes the mass properties of a convex polygon. - pub fn from_convex_polygon(density: Real, vertices: &[Point]) -> MassProperties { + pub fn from_convex_polygon(density: Real, vertices: &[Point]) -> MassProperties { let (area, com) = convex_polygon_area_and_center_of_mass(vertices); if area == 0.0 { @@ -27,9 +27,7 @@ impl MassProperties { } /// Computes the area and center-of-mass of a convex polygon. -pub fn convex_polygon_area_and_center_of_mass( - convex_polygon: &[Point], -) -> (Real, Point) { +pub fn convex_polygon_area_and_center_of_mass(convex_polygon: &[Point]) -> (Real, Point) { let geometric_center = convex_polygon .iter() .fold(Point::origin(), |e1, e2| e1 + e2.coords) diff --git a/src/mass_properties/mass_properties_convex_polyhedron.rs b/src/mass_properties/mass_properties_convex_polyhedron.rs index f160e262..928c90c8 100644 --- a/src/mass_properties/mass_properties_convex_polyhedron.rs +++ b/src/mass_properties/mass_properties_convex_polyhedron.rs @@ -5,7 +5,7 @@ impl MassProperties { /// Computes the mass properties of a convex polyhedron. pub fn from_convex_polyhedron( density: Real, - vertices: &[Point], + vertices: &[Point], indices: &[[u32; DIM]], ) -> MassProperties { Self::from_trimesh(density, vertices, indices) diff --git a/src/mass_properties/mass_properties_cuboid.rs b/src/mass_properties/mass_properties_cuboid.rs index d2882faa..88443beb 100644 --- a/src/mass_properties/mass_properties_cuboid.rs +++ b/src/mass_properties/mass_properties_cuboid.rs @@ -3,8 +3,8 @@ use crate::math::{Point, PrincipalAngularInertia, Real, Vector}; impl MassProperties { pub(crate) fn cuboid_volume_unit_inertia( - half_extents: Vector, - ) -> (Real, PrincipalAngularInertia) { + half_extents: Vector, + ) -> (Real, PrincipalAngularInertia) { #[cfg(feature = "dim2")] { let volume = half_extents.x * half_extents.y * 4.0; @@ -26,7 +26,7 @@ impl MassProperties { } /// Computes the mass properties of a cuboid. - pub fn from_cuboid(density: Real, half_extents: Vector) -> Self { + pub fn from_cuboid(density: Real, half_extents: Vector) -> Self { let (vol, unit_i) = Self::cuboid_volume_unit_inertia(half_extents); let mass = vol * density; Self::new(Point::origin(), mass, unit_i * mass) diff --git a/src/mass_properties/mass_properties_cylinder.rs b/src/mass_properties/mass_properties_cylinder.rs index a5b8a858..d1d8dd0f 100644 --- a/src/mass_properties/mass_properties_cylinder.rs +++ b/src/mass_properties/mass_properties_cylinder.rs @@ -10,7 +10,7 @@ impl MassProperties { pub(crate) fn cylinder_y_volume_unit_inertia( half_height: Real, radius: Real, - ) -> (Real, PrincipalAngularInertia) { + ) -> (Real, PrincipalAngularInertia) { #[cfg(feature = "dim2")] { Self::cuboid_volume_unit_inertia(Vector::new(radius, half_height)) diff --git a/src/mass_properties/mass_properties_triangle.rs b/src/mass_properties/mass_properties_triangle.rs index 4dc1f1a9..a3385b8f 100644 --- a/src/mass_properties/mass_properties_triangle.rs +++ b/src/mass_properties/mass_properties_triangle.rs @@ -4,12 +4,7 @@ use crate::shape::Triangle; impl MassProperties { /// Computes the mass properties of a triangle. - pub fn from_triangle( - density: Real, - a: &Point, - b: &Point, - c: &Point, - ) -> MassProperties { + pub fn from_triangle(density: Real, a: &Point, b: &Point, c: &Point) -> MassProperties { let triangle = Triangle::new(*a, *b, *c); let area = triangle.area(); let com = triangle.center(); diff --git a/src/mass_properties/mass_properties_trimesh2d.rs b/src/mass_properties/mass_properties_trimesh2d.rs index 215c9a8a..482c5bf3 100644 --- a/src/mass_properties/mass_properties_trimesh2d.rs +++ b/src/mass_properties/mass_properties_trimesh2d.rs @@ -4,11 +4,7 @@ use crate::shape::Triangle; impl MassProperties { /// Computes the mass properties of a triangle-mesh. - pub fn from_trimesh( - density: Real, - vertices: &[Point], - indices: &[[u32; 3]], - ) -> MassProperties { + pub fn from_trimesh(density: Real, vertices: &[Point], indices: &[[u32; 3]]) -> MassProperties { let (area, com) = trimesh_area_and_center_of_mass(vertices, indices); if area == 0.0 { @@ -35,10 +31,7 @@ impl MassProperties { } /// Computes the area and center-of-mass of a triangle-mesh. -pub fn trimesh_area_and_center_of_mass( - vertices: &[Point], - indices: &[[u32; 3]], -) -> (Real, Point) { +pub fn trimesh_area_and_center_of_mass(vertices: &[Point], indices: &[[u32; 3]]) -> (Real, Point) { let mut res = Point::origin(); let mut areasum = 0.0; diff --git a/src/mass_properties/mass_properties_trimesh3d.rs b/src/mass_properties/mass_properties_trimesh3d.rs index aa7416d9..3a27940e 100644 --- a/src/mass_properties/mass_properties_trimesh3d.rs +++ b/src/mass_properties/mass_properties_trimesh3d.rs @@ -7,7 +7,7 @@ impl MassProperties { /// Computes the mass properties of a triangle mesh. pub fn from_trimesh( density: Real, - vertices: &[Point], + vertices: &[Point], indices: &[[u32; DIM]], ) -> MassProperties { let (volume, com) = trimesh_signed_volume_and_center_of_mass(vertices, indices); @@ -36,12 +36,12 @@ impl MassProperties { /// Computes the unit inertia tensor of a tetrahedron, with regard to the given `point`. pub fn tetrahedron_unit_inertia_tensor_wrt_point( - point: &Point, - p1: &Point, - p2: &Point, - p3: &Point, - p4: &Point, -) -> Matrix { + point: &Point, + p1: &Point, + p2: &Point, + p3: &Point, + p4: &Point, +) -> Matrix { let p1 = p1 - point; let p2 = p2 - point; let p3 = p3 - point; @@ -153,9 +153,9 @@ pub fn tetrahedron_unit_inertia_tensor_wrt_point( /// Computes the volume and center-of-mass of a mesh. pub fn trimesh_signed_volume_and_center_of_mass( - vertices: &[Point], + vertices: &[Point], indices: &[[u32; DIM]], -) -> (Real, Point) { +) -> (Real, Point) { let geometric_center = crate::utils::center(vertices); let mut res = Point::origin(); diff --git a/src/partitioning/qbvh/build.rs b/src/partitioning/qbvh/build.rs index 1c4cdc16..5ca80ab9 100644 --- a/src/partitioning/qbvh/build.rs +++ b/src/partitioning/qbvh/build.rs @@ -34,7 +34,7 @@ pub trait QbvhDataSplitter { fn split_dataset<'idx>( &mut self, subdiv_dims: [usize; 2], - center: Point, + center: Point, indices: &'idx mut [usize], indices_workspace: &'idx mut Vec, proxies: BuilderProxies, @@ -62,7 +62,7 @@ impl QbvhDataSplitter for CenterDataSplitter { fn split_dataset<'idx>( &mut self, subdiv_dims: [usize; 2], - center: Point, + center: Point, indices: &'idx mut [usize], _: &'idx mut Vec, proxies: BuilderProxies, @@ -75,7 +75,7 @@ impl CenterDataSplitter { pub(crate) fn split_dataset_wo_workspace<'idx>( &self, subdiv_dims: [usize; 2], - center: Point, + center: Point, indices: &'idx mut [usize], aabbs: &[Aabb], ) -> [&'idx mut [usize]; 4] { @@ -130,7 +130,7 @@ where fn split_dataset<'idx>( &mut self, subdiv_dims: [usize; 2], - center: Point, + center: Point, indices: &'idx mut [usize], indices_workspace: &'idx mut Vec, mut proxies: BuilderProxies, diff --git a/src/partitioning/qbvh/qbvh.rs b/src/partitioning/qbvh/qbvh.rs index 705ad719..1c2d98c4 100644 --- a/src/partitioning/qbvh/qbvh.rs +++ b/src/partitioning/qbvh/qbvh.rs @@ -1,5 +1,5 @@ use crate::bounding_volume::{Aabb, SimdAabb}; -use crate::math::{Real, Vector}; +use crate::math::{Vector, VectorT}; use na::SimdValue; @@ -305,10 +305,10 @@ impl Qbvh { /// Computes a scaled version of this Qbvh. /// /// This will apply the scale to each Aabb on this BVH. - pub fn scaled(mut self, scale: &Vector) -> Self { + pub fn scaled(mut self, scale: &Vector) -> Self { self.root_aabb = self.root_aabb.scaled(scale); for node in &mut self.nodes { - node.simd_aabb = node.simd_aabb.scaled(&Vector::splat(*scale)); + node.simd_aabb = node.simd_aabb.scaled(&VectorT::splat(*scale)); } self } diff --git a/src/partitioning/qbvh/update/tests.rs b/src/partitioning/qbvh/update/tests.rs index 2f122b5d..13317252 100644 --- a/src/partitioning/qbvh/update/tests.rs +++ b/src/partitioning/qbvh/update/tests.rs @@ -213,7 +213,7 @@ impl QbvhTester { let mut qbvh = Qbvh::new(); let workspace = QbvhUpdateWorkspace::default(); let aabbs = self.aabbs.clone(); - qbvh.clear_and_rebuild(aabbs.iter().map(|(index, aabb)| (index, aabb.clone())), 0.0); + qbvh.clear_and_rebuild(aabbs.iter().map(|(index, aabb)| (index, *aabb)), 0.0); QbvhTester { qbvh, workspace, @@ -245,7 +245,7 @@ impl QbvhTester { *self .aabbs .get(*index) - .expect(&format!("invalid index {}", index)) + .unwrap_or_else(|| panic!("invalid index {}", index)) }); } @@ -281,7 +281,7 @@ fn generate_random_aabb(rng: &mut StdRng) -> Aabb { } } -impl<'q> ptree::TreeItem for QbvhTreeIterator<'q> { +impl ptree::TreeItem for QbvhTreeIterator<'_> { type Child = Self; fn write_self( diff --git a/src/partitioning/qbvh/utils.rs b/src/partitioning/qbvh/utils.rs index 129c2c0b..ff008bd1 100644 --- a/src/partitioning/qbvh/utils.rs +++ b/src/partitioning/qbvh/utils.rs @@ -1,10 +1,10 @@ use crate::bounding_volume::Aabb; -use crate::math::{Point, Real}; +use crate::math::Point; pub fn split_indices_wrt_dim<'a>( indices: &'a mut [usize], aabbs: &[Aabb], - split_point: &Point, + split_point: &Point, dim: usize, enable_fallback_split: bool, ) -> (&'a mut [usize], &'a mut [usize]) { diff --git a/src/query/clip/clip_aabb_line.rs b/src/query/clip/clip_aabb_line.rs index 724d3e74..d6e97d79 100644 --- a/src/query/clip/clip_aabb_line.rs +++ b/src/query/clip/clip_aabb_line.rs @@ -9,7 +9,7 @@ impl Aabb { /// /// Returns `None` if there is no intersection. #[inline] - pub fn clip_segment(&self, pa: &Point, pb: &Point) -> Option { + pub fn clip_segment(&self, pa: &Point, pb: &Point) -> Option { let ab = pb - pa; clip_aabb_line(self, pa, &ab) .map(|clip| Segment::new(pa + ab * (clip.0).0.max(0.0), pa + ab * (clip.1).0.min(1.0))) @@ -20,11 +20,7 @@ impl Aabb { /// The parameters are such that the point are given by `orig + dir * parameter`. /// Returns `None` if there is no intersection. #[inline] - pub fn clip_line_parameters( - &self, - orig: &Point, - dir: &Vector, - ) -> Option<(Real, Real)> { + pub fn clip_line_parameters(&self, orig: &Point, dir: &Vector) -> Option<(Real, Real)> { clip_aabb_line(self, orig, dir).map(|clip| ((clip.0).0, (clip.1).0)) } @@ -32,7 +28,7 @@ impl Aabb { /// /// Returns `None` if there is no intersection. #[inline] - pub fn clip_line(&self, orig: &Point, dir: &Vector) -> Option { + pub fn clip_line(&self, orig: &Point, dir: &Vector) -> Option { clip_aabb_line(self, orig, dir) .map(|clip| Segment::new(orig + dir * (clip.0).0, orig + dir * (clip.1).0)) } @@ -69,9 +65,9 @@ impl Aabb { /// Computes the segment given by the intersection of a line and an Aabb. pub fn clip_aabb_line( aabb: &Aabb, - origin: &Point, - dir: &Vector, -) -> Option<((Real, Vector, isize), (Real, Vector, isize))> { + origin: &Point, + dir: &Vector, +) -> Option<((Real, Vector, isize), (Real, Vector, isize))> { let mut tmax: Real = Bounded::max_value(); let mut tmin: Real = -tmax; let mut near_side = 0; diff --git a/src/query/clip/clip_aabb_polygon.rs b/src/query/clip/clip_aabb_polygon.rs index 92984512..94af142e 100644 --- a/src/query/clip/clip_aabb_polygon.rs +++ b/src/query/clip/clip_aabb_polygon.rs @@ -1,5 +1,5 @@ use crate::bounding_volume::Aabb; -use crate::math::{Point, Real, Vector}; +use crate::math::{Point, Vector}; impl Aabb { /// Computes the intersections between this Aabb and the given polygon. @@ -9,7 +9,7 @@ impl Aabb { /// In order to avoid internal allocations, uses `self.clip_polygon_with_workspace` /// instead. #[inline] - pub fn clip_polygon(&self, points: &mut Vec>) { + pub fn clip_polygon(&self, points: &mut Vec) { let mut workspace = Vec::new(); self.clip_polygon_with_workspace(points, &mut workspace) } @@ -19,11 +19,7 @@ impl Aabb { /// The results is written into `points` directly. The input points are /// assumed to form a convex polygon where all points lie on the same plane. #[inline] - pub fn clip_polygon_with_workspace( - &self, - points: &mut Vec>, - workspace: &mut Vec>, - ) { + pub fn clip_polygon_with_workspace(&self, points: &mut Vec, workspace: &mut Vec) { super::clip_halfspace_polygon(&self.mins, &-Vector::x(), points, workspace); super::clip_halfspace_polygon(&self.maxs, &Vector::x(), workspace, points); diff --git a/src/query/clip/clip_halfspace_polygon.rs b/src/query/clip/clip_halfspace_polygon.rs index 5a9e93a3..a16db293 100644 --- a/src/query/clip/clip_halfspace_polygon.rs +++ b/src/query/clip/clip_halfspace_polygon.rs @@ -1,4 +1,4 @@ -use crate::math::{Point, Real, Vector}; +use crate::math::{Point, Vector}; use crate::query::{self, Ray}; /// Cuts a polygon with the given half-space. @@ -8,10 +8,10 @@ use crate::query::{self, Ray}; /// the polygon. (Note that a point `pt` is considered as inside of /// the half-space if `normal.dot(&(pt - center)) <= 0.0`. pub fn clip_halfspace_polygon( - center: &Point, - normal: &Vector, - polygon: &[Point], - result: &mut Vec>, + center: &Point, + normal: &Vector, + polygon: &[Point], + result: &mut Vec, ) { result.clear(); @@ -19,7 +19,7 @@ pub fn clip_halfspace_polygon( return; } - let keep_point = |pt: &Point| (pt - center).dot(normal) <= 0.0; + let keep_point = |pt: &Point| (pt - center).dot(normal) <= 0.0; let last_pt = polygon.last().unwrap(); let mut last_keep = keep_point(last_pt); diff --git a/src/query/clip/clip_segment_segment.rs b/src/query/clip/clip_segment_segment.rs index 72f326b4..f6eb3435 100644 --- a/src/query/clip/clip_segment_segment.rs +++ b/src/query/clip/clip_segment_segment.rs @@ -1,4 +1,4 @@ -use crate::math::{Point, Real}; +use crate::math::Point; #[cfg(feature = "dim2")] use crate::{math::Vector, utils}; @@ -6,15 +6,15 @@ use crate::{math::Vector, utils}; // 0 = First vertex. // 1 = On the face. // 2 = Second vertex. -pub type ClippingPoints = (Point, Point, usize, usize); +pub type ClippingPoints = (Point, Point, usize, usize); /// Projects two segments on one another towards the direction `normal`, /// and compute their intersection. #[cfg(feature = "dim2")] pub fn clip_segment_segment_with_normal( - mut seg1: (Point, Point), - mut seg2: (Point, Point), - normal: Vector, + mut seg1: (Point, Point), + mut seg2: (Point, Point), + normal: Vector, ) -> Option<(ClippingPoints, ClippingPoints)> { use crate::utils::WBasis; let tangent = normal.orthonormal_basis()[0]; @@ -74,8 +74,8 @@ pub fn clip_segment_segment_with_normal( /// Projects two segments on one another and compute their intersection. pub fn clip_segment_segment( - mut seg1: (Point, Point), - mut seg2: (Point, Point), + mut seg1: (Point, Point), + mut seg2: (Point, Point), ) -> Option<(ClippingPoints, ClippingPoints)> { // NOTE: no need to normalize the tangent. let tangent1 = seg1.1 - seg1.0; diff --git a/src/query/closest_points/closest_points.rs b/src/query/closest_points/closest_points.rs index 987ebd71..f51774e4 100644 --- a/src/query/closest_points/closest_points.rs +++ b/src/query/closest_points/closest_points.rs @@ -1,4 +1,4 @@ -use crate::math::{Isometry, Point, Real}; +use crate::math::{Isometry, Point}; use std::mem; @@ -14,7 +14,7 @@ pub enum ClosestPoints { /// The two objects are intersecting. Intersecting, /// The two objects are non-intersecting but closer than a given user-defined distance. - WithinMargin(Point, Point), + WithinMargin(Point, Point), /// The two objects are non-intersecting and further than a given user-defined distance. Disjoint, } @@ -39,7 +39,7 @@ impl ClosestPoints { /// Transform the points in `self` by `pos1` and `pos2`. #[must_use] - pub fn transform_by(self, pos1: &Isometry, pos2: &Isometry) -> Self { + pub fn transform_by(self, pos1: &Isometry, pos2: &Isometry) -> Self { if let ClosestPoints::WithinMargin(p1, p2) = self { ClosestPoints::WithinMargin(pos1 * p1, pos2 * p2) } else { diff --git a/src/query/closest_points/closest_points_ball_ball.rs b/src/query/closest_points/closest_points_ball_ball.rs index 5a6c9420..52c98b74 100644 --- a/src/query/closest_points/closest_points_ball_ball.rs +++ b/src/query/closest_points/closest_points_ball_ball.rs @@ -7,7 +7,7 @@ use crate::shape::Ball; /// Each returned point is expressed on the local-space of the corresponding shape. #[inline] pub fn closest_points_ball_ball( - pos12: &Isometry, + pos12: &Isometry, b1: &Ball, b2: &Ball, margin: Real, diff --git a/src/query/closest_points/closest_points_ball_convex_polyhedron.rs b/src/query/closest_points/closest_points_ball_convex_polyhedron.rs index 49f59280..d6db547c 100644 --- a/src/query/closest_points/closest_points_ball_convex_polyhedron.rs +++ b/src/query/closest_points/closest_points_ball_convex_polyhedron.rs @@ -8,7 +8,7 @@ use crate::shape::{Ball, Shape}; /// both the ConvexPolyhedron and PointQuery traits. #[inline] pub fn closest_points_ball_convex_polyhedron( - pos12: &Isometry, + pos12: &Isometry, ball1: &Ball, shape2: &(impl Shape + ?Sized), prediction: Real, @@ -31,7 +31,7 @@ pub fn closest_points_ball_convex_polyhedron( /// both the ConvexPolyhedron and PointQuery traits. #[inline] pub fn closest_points_convex_polyhedron_ball( - pos12: &Isometry, + pos12: &Isometry, shape1: &(impl Shape + ?Sized), ball2: &Ball, prediction: Real, diff --git a/src/query/closest_points/closest_points_composite_shape_shape.rs b/src/query/closest_points/closest_points_composite_shape_shape.rs index e8e51906..4b4179c2 100644 --- a/src/query/closest_points/closest_points_composite_shape_shape.rs +++ b/src/query/closest_points/closest_points_composite_shape_shape.rs @@ -1,5 +1,5 @@ use crate::bounding_volume::SimdAabb; -use crate::math::{Isometry, Real, SimdBool, SimdReal, Vector, SIMD_WIDTH}; +use crate::math::{Isometry, Real, SimdBool, SimdReal, VectorT, SIMD_WIDTH}; use crate::partitioning::{SimdBestFirstVisitStatus, SimdBestFirstVisitor}; use crate::query::{ClosestPoints, QueryDispatcher}; use crate::shape::{Shape, TypedSimdCompositeShape}; @@ -10,7 +10,7 @@ use simba::simd::{SimdBool as _, SimdPartialOrd, SimdValue}; /// Closest points between a composite shape and any other shape. pub fn closest_points_composite_shape_shape( dispatcher: &D, - pos12: &Isometry, + pos12: &Isometry, g1: &G1, g2: &dyn Shape, margin: Real, @@ -32,7 +32,7 @@ where /// Closest points between a shape and a composite shape. pub fn closest_points_shape_composite_shape( dispatcher: &D, - pos12: &Isometry, + pos12: &Isometry, g1: &dyn Shape, g2: &G2, margin: Real, @@ -46,12 +46,12 @@ where /// A visitor for computing the closest points between a composite-shape and a shape. pub struct CompositeShapeAgainstShapeClosestPointsVisitor<'a, D: ?Sized, G1: ?Sized + 'a> { - msum_shift: Vector, - msum_margin: Vector, + msum_shift: VectorT, + msum_margin: VectorT, margin: Real, dispatcher: &'a D, - pos12: &'a Isometry, + pos12: &'a Isometry, g1: &'a G1, g2: &'a dyn Shape, } @@ -64,7 +64,7 @@ where /// Initializes a visitor for computing the closest points between a composite-shape and a shape. pub fn new( dispatcher: &'a D, - pos12: &'a Isometry, + pos12: &'a Isometry, g1: &'a G1, g2: &'a dyn Shape, margin: Real, @@ -72,8 +72,8 @@ where let ls_aabb2 = g2.compute_aabb(pos12); CompositeShapeAgainstShapeClosestPointsVisitor { - msum_shift: Vector::splat(-ls_aabb2.center().coords), - msum_margin: Vector::splat(ls_aabb2.half_extents()), + msum_shift: VectorT::splat(-ls_aabb2.center().coords), + msum_margin: VectorT::splat(ls_aabb2.half_extents()), margin, dispatcher, pos12, diff --git a/src/query/closest_points/closest_points_cuboid_cuboid.rs b/src/query/closest_points/closest_points_cuboid_cuboid.rs index 81173b3d..e201ae67 100644 --- a/src/query/closest_points/closest_points_cuboid_cuboid.rs +++ b/src/query/closest_points/closest_points_cuboid_cuboid.rs @@ -5,7 +5,7 @@ use crate::shape::{Cuboid, SupportMap}; /// Closest points between two cuboids. #[inline] pub fn closest_points_cuboid_cuboid( - pos12: &Isometry, + pos12: &Isometry, cuboid1: &Cuboid, cuboid2: &Cuboid, margin: Real, @@ -23,7 +23,7 @@ pub fn closest_points_cuboid_cuboid( } #[cfg(feature = "dim2")] - let sep3 = (-Real::MAX, crate::math::Vector::::y()); // This case does not exist in 2D. + let sep3 = (-Real::MAX, crate::math::Vector::y()); // This case does not exist in 2D. #[cfg(feature = "dim3")] let sep3 = sat::cuboid_cuboid_find_local_separating_edge_twoway(cuboid1, cuboid2, pos12); if sep3.0 > margin { diff --git a/src/query/closest_points/closest_points_cuboid_triangle.rs b/src/query/closest_points/closest_points_cuboid_triangle.rs index 0ac6449d..4f9b7764 100644 --- a/src/query/closest_points/closest_points_cuboid_triangle.rs +++ b/src/query/closest_points/closest_points_cuboid_triangle.rs @@ -5,7 +5,7 @@ use crate::shape::{Cuboid, SupportMap, Triangle}; /// Closest points between a cuboid and a triangle. #[inline] pub fn closest_points_cuboid_triangle( - pos12: &Isometry, + pos12: &Isometry, cuboid1: &Cuboid, triangle2: &Triangle, margin: Real, @@ -24,7 +24,7 @@ pub fn closest_points_cuboid_triangle( } #[cfg(feature = "dim2")] - let sep3 = (-Real::MAX, crate::math::Vector::::y()); // This case does not exist in 2D. + let sep3 = (-Real::MAX, crate::math::Vector::y()); // This case does not exist in 2D. #[cfg(feature = "dim3")] let sep3 = sat::cuboid_triangle_find_local_separating_edge_twoway(cuboid1, triangle2, pos12); if sep3.0 > margin { @@ -80,7 +80,7 @@ pub fn closest_points_cuboid_triangle( /// Closest points between a triangle and a cuboid. #[inline] pub fn closest_points_triangle_cuboid( - pos12: &Isometry, + pos12: &Isometry, triangle1: &Triangle, cuboid2: &Cuboid, margin: Real, diff --git a/src/query/closest_points/closest_points_halfspace_support_map.rs b/src/query/closest_points/closest_points_halfspace_support_map.rs index 75243bcd..96950dd3 100644 --- a/src/query/closest_points/closest_points_halfspace_support_map.rs +++ b/src/query/closest_points/closest_points_halfspace_support_map.rs @@ -5,7 +5,7 @@ use crate::shape::SupportMap; /// Closest points between a halfspace and a support-mapped shape (Cuboid, ConvexHull, etc.) pub fn closest_points_halfspace_support_map( - pos12: &Isometry, + pos12: &Isometry, halfspace: &HalfSpace, other: &G, margin: Real, @@ -33,7 +33,7 @@ pub fn closest_points_halfspace_support_map( /// Closest points between a support-mapped shape (Cuboid, ConvexHull, etc.) and a halfspace. pub fn closest_points_support_map_halfspace( - pos12: &Isometry, + pos12: &Isometry, other: &G, halfspace: &HalfSpace, margin: Real, diff --git a/src/query/closest_points/closest_points_line_line.rs b/src/query/closest_points/closest_points_line_line.rs index 9b6ef50a..0fea1d17 100644 --- a/src/query/closest_points/closest_points_line_line.rs +++ b/src/query/closest_points/closest_points_line_line.rs @@ -7,10 +7,10 @@ use crate::na::{Point as SPoint, SVector}; /// `orig1 + dir1 * res.0` and `orig2 + dir2 * res.1`. #[inline] pub fn closest_points_line_line_parameters( - orig1: &Point, - dir1: &Vector, - orig2: &Point, - dir2: &Vector, + orig1: &Point, + dir1: &Vector, + orig2: &Point, + dir2: &Vector, ) -> (Real, Real) { let res = closest_points_line_line_parameters_eps( orig1, @@ -75,11 +75,11 @@ pub fn closest_points_line_line_parameters_eps( /// Closest points between two segments. #[inline] pub fn closest_points_line_line( - orig1: &Point, - dir1: &Vector, - orig2: &Point, - dir2: &Vector, -) -> (Point, Point) { + orig1: &Point, + dir1: &Vector, + orig2: &Point, + dir2: &Vector, +) -> (Point, Point) { let (s, t) = closest_points_line_line_parameters(orig1, dir1, orig2, dir2); (*orig1 + *dir1 * s, *orig2 + *dir2 * t) } diff --git a/src/query/closest_points/closest_points_segment_segment.rs b/src/query/closest_points/closest_points_segment_segment.rs index 18168f75..da46d628 100644 --- a/src/query/closest_points/closest_points_segment_segment.rs +++ b/src/query/closest_points/closest_points_segment_segment.rs @@ -7,7 +7,7 @@ use na::{self, Point}; /// Closest points between segments. #[inline] pub fn closest_points_segment_segment( - pos12: &Isometry, + pos12: &Isometry, seg1: &Segment, seg2: &Segment, margin: Real, @@ -27,7 +27,7 @@ pub fn closest_points_segment_segment( /// Closest points between two segments. #[inline] pub fn closest_points_segment_segment_with_locations( - pos12: &Isometry, + pos12: &Isometry, seg1: &Segment, seg2: &Segment, ) -> (SegmentPointLocation, SegmentPointLocation) { diff --git a/src/query/closest_points/closest_points_shape_shape.rs b/src/query/closest_points/closest_points_shape_shape.rs index cb6d8db9..6e36bd1f 100644 --- a/src/query/closest_points/closest_points_shape_shape.rs +++ b/src/query/closest_points/closest_points_shape_shape.rs @@ -7,9 +7,9 @@ use crate::shape::Shape; /// Returns `ClosestPoints::Disjoint` if the objects are separated by a distance greater than `max_dist`. /// The result points in `ClosestPoints::WithinMargin` are expressed in world-space. pub fn closest_points( - pos1: &Isometry, + pos1: &Isometry, g1: &dyn Shape, - pos2: &Isometry, + pos2: &Isometry, g2: &dyn Shape, max_dist: Real, ) -> Result { diff --git a/src/query/closest_points/closest_points_support_map_support_map.rs b/src/query/closest_points/closest_points_support_map_support_map.rs index 5930b03a..976f9753 100644 --- a/src/query/closest_points/closest_points_support_map_support_map.rs +++ b/src/query/closest_points/closest_points_support_map_support_map.rs @@ -7,7 +7,7 @@ use na::Unit; /// Closest points between support-mapped shapes (`Cuboid`, `ConvexHull`, etc.) pub fn closest_points_support_map_support_map( - pos12: &Isometry, + pos12: &Isometry, g1: &G1, g2: &G2, prediction: Real, @@ -37,12 +37,12 @@ where /// /// This allows a more fine grained control other the underlying GJK algorigtm. pub fn closest_points_support_map_support_map_with_params( - pos12: &Isometry, + pos12: &Isometry, g1: &G1, g2: &G2, prediction: Real, simplex: &mut VoronoiSimplex, - init_dir: Option>, + init_dir: Option, ) -> GJKResult where G1: ?Sized + SupportMap, @@ -57,12 +57,7 @@ where if let Some(dir) = Unit::try_new(dir, crate::math::DEFAULT_EPSILON) { simplex.reset(CSOPoint::from_shapes(pos12, g1, g2, &dir)); } else { - simplex.reset(CSOPoint::from_shapes( - pos12, - g1, - g2, - &Vector::::x_axis(), - )); + simplex.reset(CSOPoint::from_shapes(pos12, g1, g2, &Vector::x_axis())); } gjk::closest_points(pos12, g1, g2, prediction, true, simplex) diff --git a/src/query/contact/contact.rs b/src/query/contact/contact.rs index fad4b976..679b8b1a 100644 --- a/src/query/contact/contact.rs +++ b/src/query/contact/contact.rs @@ -15,18 +15,18 @@ use rkyv::{bytecheck, CheckBytes}; )] pub struct Contact { /// Position of the contact on the first object. - pub point1: Point, + pub point1: Point, /// Position of the contact on the second object. - pub point2: Point, + pub point2: Point, /// Contact normal, pointing towards the exterior of the first shape. - pub normal1: Unit>, + pub normal1: Unit, /// Contact normal, pointing towards the exterior of the second shape. /// /// If these contact data are expressed in world-space, this normal is equal to `-normal1`. - pub normal2: Unit>, + pub normal2: Unit, /// Distance between the two contact points. /// @@ -38,10 +38,10 @@ impl Contact { /// Creates a new contact. #[inline] pub fn new( - point1: Point, - point2: Point, - normal1: Unit>, - normal2: Unit>, + point1: Point, + point2: Point, + normal1: Unit, + normal2: Unit, dist: Real, ) -> Self { Contact { @@ -72,7 +72,7 @@ impl Contact { /// Transform the points and normals from this contact by /// the given transformations. #[inline] - pub fn transform_by_mut(&mut self, pos1: &Isometry, pos2: &Isometry) { + pub fn transform_by_mut(&mut self, pos1: &Isometry, pos2: &Isometry) { self.point1 = pos1 * self.point1; self.point2 = pos2 * self.point2; self.normal1 = pos1 * self.normal1; @@ -80,7 +80,7 @@ impl Contact { } /// Transform `self.point1` and `self.normal1` by the `pos`. - pub fn transform1_by_mut(&mut self, pos: &Isometry) { + pub fn transform1_by_mut(&mut self, pos: &Isometry) { self.point1 = pos * self.point1; self.normal1 = pos * self.normal1; } diff --git a/src/query/contact/contact_ball_ball.rs b/src/query/contact/contact_ball_ball.rs index c4373592..c51e4cf2 100644 --- a/src/query/contact/contact_ball_ball.rs +++ b/src/query/contact/contact_ball_ball.rs @@ -7,7 +7,7 @@ use num::Zero; /// Contact between balls. #[inline] pub fn contact_ball_ball( - pos12: &Isometry, + pos12: &Isometry, b1: &Ball, b2: &Ball, prediction: Real, diff --git a/src/query/contact/contact_ball_convex_polyhedron.rs b/src/query/contact/contact_ball_convex_polyhedron.rs index 15786941..4331dbb6 100644 --- a/src/query/contact/contact_ball_convex_polyhedron.rs +++ b/src/query/contact/contact_ball_convex_polyhedron.rs @@ -10,7 +10,7 @@ use na::{self, Unit}; /// both the ConvexPolyhedron and PointQuery traits. #[inline] pub fn contact_ball_convex_polyhedron( - pos12: &Isometry, + pos12: &Isometry, ball1: &Ball, shape2: &(impl Shape + ?Sized), prediction: Real, @@ -24,7 +24,7 @@ pub fn contact_ball_convex_polyhedron( /// both the ConvexPolyhedron and PointQuery traits. #[inline] pub fn contact_convex_polyhedron_ball( - pos12: &Isometry, + pos12: &Isometry, shape1: &(impl Shape + ?Sized), ball2: &Ball, prediction: Real, diff --git a/src/query/contact/contact_composite_shape_shape.rs b/src/query/contact/contact_composite_shape_shape.rs index 82d46f71..529009cd 100644 --- a/src/query/contact/contact_composite_shape_shape.rs +++ b/src/query/contact/contact_composite_shape_shape.rs @@ -8,7 +8,7 @@ use crate::utils::IsometryOpt; /// Best contact between a composite shape (`Mesh`, `Compound`) and any other shape. pub fn contact_composite_shape_shape( dispatcher: &D, - pos12: &Isometry, + pos12: &Isometry, g1: &G1, g2: &dyn Shape, prediction: Real, @@ -48,7 +48,7 @@ where /// Best contact between a shape and a composite (`Mesh`, `Compound`) shape. pub fn contact_shape_composite_shape( dispatcher: &D, - pos12: &Isometry, + pos12: &Isometry, g1: &dyn Shape, g2: &G2, prediction: Real, diff --git a/src/query/contact/contact_cuboid_cuboid.rs b/src/query/contact/contact_cuboid_cuboid.rs index 00259f5d..0a17e4d2 100644 --- a/src/query/contact/contact_cuboid_cuboid.rs +++ b/src/query/contact/contact_cuboid_cuboid.rs @@ -7,7 +7,7 @@ use na::Unit; /// Contact between two cuboids. #[inline] pub fn contact_cuboid_cuboid( - pos12: &Isometry, + pos12: &Isometry, cuboid1: &Cuboid, cuboid2: &Cuboid, prediction: Real, @@ -25,7 +25,7 @@ pub fn contact_cuboid_cuboid( } #[cfg(feature = "dim2")] - let sep3 = (-Real::MAX, crate::math::Vector::::y()); // This case does not exist in 2D. + let sep3 = (-Real::MAX, crate::math::Vector::y()); // This case does not exist in 2D. #[cfg(feature = "dim3")] let sep3 = sat::cuboid_cuboid_find_local_separating_edge_twoway(cuboid1, cuboid2, pos12); if sep3.0 > prediction { diff --git a/src/query/contact/contact_halfspace_support_map.rs b/src/query/contact/contact_halfspace_support_map.rs index 9d8f40fa..d36784f7 100644 --- a/src/query/contact/contact_halfspace_support_map.rs +++ b/src/query/contact/contact_halfspace_support_map.rs @@ -4,7 +4,7 @@ use crate::shape::{HalfSpace, SupportMap}; /// Contact between a halfspace and a support-mapped shape (Cuboid, ConvexHull, etc.) pub fn contact_halfspace_support_map( - pos12: &Isometry, + pos12: &Isometry, halfspace: &HalfSpace, other: &G, prediction: Real, @@ -31,7 +31,7 @@ pub fn contact_halfspace_support_map( /// Contact between a support-mapped shape (Cuboid, ConvexHull, etc.) and a halfspace. pub fn contact_support_map_halfspace( - pos12: &Isometry, + pos12: &Isometry, other: &G, halfspace: &HalfSpace, prediction: Real, diff --git a/src/query/contact/contact_shape_shape.rs b/src/query/contact/contact_shape_shape.rs index f9fdb294..bae357ee 100644 --- a/src/query/contact/contact_shape_shape.rs +++ b/src/query/contact/contact_shape_shape.rs @@ -7,9 +7,9 @@ use crate::shape::Shape; /// Returns `None` if the objects are separated by a distance greater than `prediction`. /// The result is given in world-space. pub fn contact( - pos1: &Isometry, + pos1: &Isometry, g1: &dyn Shape, - pos2: &Isometry, + pos2: &Isometry, g2: &dyn Shape, prediction: Real, ) -> Result, Unsupported> { diff --git a/src/query/contact/contact_support_map_support_map.rs b/src/query/contact/contact_support_map_support_map.rs index 831ba246..74c41dc7 100644 --- a/src/query/contact/contact_support_map_support_map.rs +++ b/src/query/contact/contact_support_map_support_map.rs @@ -8,7 +8,7 @@ use na::Unit; /// Contact between support-mapped shapes (`Cuboid`, `ConvexHull`, etc.) pub fn contact_support_map_support_map( - pos12: &Isometry, + pos12: &Isometry, g1: &G1, g2: &G2, prediction: Real, @@ -38,12 +38,12 @@ where /// subsequent executions of the algorithm. It is also the contact /// normal (that points toward the outside of the first solid). pub fn contact_support_map_support_map_with_params( - pos12: &Isometry, + pos12: &Isometry, g1: &G1, g2: &G2, prediction: Real, simplex: &mut VoronoiSimplex, - init_dir: Option>>, + init_dir: Option>, ) -> GJKResult where G1: ?Sized + SupportMap, diff --git a/src/query/contact_manifolds/contact_manifold.rs b/src/query/contact_manifolds/contact_manifold.rs index ec0392a6..ee2f3a6a 100644 --- a/src/query/contact_manifolds/contact_manifold.rs +++ b/src/query/contact_manifolds/contact_manifold.rs @@ -11,9 +11,9 @@ use crate::shape::PackedFeatureId; /// A single contact between two shape. pub struct TrackedContact { /// The contact point in the local-space of the first shape. - pub local_p1: Point, + pub local_p1: Point, /// The contact point in the local-space of the second shape. - pub local_p2: Point, + pub local_p2: Point, /// The distance between the two contact points. pub dist: Real, @@ -28,8 +28,8 @@ pub struct TrackedContact { impl TrackedContact { /// Creates a new tracked contact. pub fn new( - local_p1: Point, - local_p2: Point, + local_p1: Point, + local_p2: Point, fid1: PackedFeatureId, fid2: PackedFeatureId, dist: Real, @@ -46,8 +46,8 @@ impl TrackedContact { /// Creates a new tracked contact where its input may need to be flipped. pub fn flipped( - local_p1: Point, - local_p2: Point, + local_p1: Point, + local_p2: Point, fid1: PackedFeatureId, fid2: PackedFeatureId, dist: Real, @@ -86,9 +86,9 @@ pub struct ContactManifold { #[cfg(feature = "dim3")] pub points: Vec>, /// The contact normal of all the contacts of this manifold, expressed in the local space of the first shape. - pub local_n1: Vector, + pub local_n1: Vector, /// The contact normal of all the contacts of this manifold, expressed in the local space of the second shape. - pub local_n2: Vector, + pub local_n2: Vector, /// The first subshape involved in this contact manifold. /// /// This is zero if the first shape is not a composite shape. @@ -99,10 +99,10 @@ pub struct ContactManifold { pub subshape2: u32, /// If the first shape involved is a composite shape, this contains the position of its subshape /// involved in this contact. - pub subshape_pos1: Option>, + pub subshape_pos1: Option, /// If the second shape involved is a composite shape, this contains the position of its subshape /// involved in this contact. - pub subshape_pos2: Option>, + pub subshape_pos2: Option, /// Additional tracked data associated to this contact manifold. pub data: ManifoldData, } @@ -178,7 +178,7 @@ impl ContactManifold) -> bool { + pub fn try_update_contacts(&mut self, pos12: &Isometry) -> bool { // const DOT_THRESHOLD: Real = 0.crate::COS_10_DEGREES; // const DOT_THRESHOLD: Real = crate::utils::COS_5_DEGREES; const DOT_THRESHOLD: Real = crate::utils::COS_1_DEGREES; @@ -190,7 +190,7 @@ impl ContactManifold, + pos12: &Isometry, angle_dot_threshold: Real, dist_sq_threshold: Real, ) -> bool { diff --git a/src/query/contact_manifolds/contact_manifolds_ball_ball.rs b/src/query/contact_manifolds/contact_manifolds_ball_ball.rs index 2cbcd761..b4c4845e 100644 --- a/src/query/contact_manifolds/contact_manifolds_ball_ball.rs +++ b/src/query/contact_manifolds/contact_manifolds_ball_ball.rs @@ -4,7 +4,7 @@ use crate::shape::{Ball, PackedFeatureId, Shape}; /// Computes the contact manifold between two balls given as `Shape` trait-objects. pub fn contact_manifold_ball_ball_shapes( - pos12: &Isometry, + pos12: &Isometry, shape1: &dyn Shape, shape2: &dyn Shape, prediction: Real, @@ -17,7 +17,7 @@ pub fn contact_manifold_ball_ball_shapes( - pos12: &Isometry, + pos12: &Isometry, ball1: &Ball, ball2: &Ball, prediction: Real, diff --git a/src/query/contact_manifolds/contact_manifolds_capsule_capsule.rs b/src/query/contact_manifolds/contact_manifolds_capsule_capsule.rs index a92fe01c..7c1ebbad 100644 --- a/src/query/contact_manifolds/contact_manifolds_capsule_capsule.rs +++ b/src/query/contact_manifolds/contact_manifolds_capsule_capsule.rs @@ -11,7 +11,7 @@ use na::ComplexField; // for .abs() /// Computes the contact manifold between two capsules given as `Shape` trait-objects. pub fn contact_manifold_capsule_capsule_shapes( - pos12: &Isometry, + pos12: &Isometry, shape1: &dyn Shape, shape2: &dyn Shape, prediction: Real, @@ -27,7 +27,7 @@ pub fn contact_manifold_capsule_capsule_shapes( /// Computes the contact manifold between two capsules. #[cfg(feature = "dim2")] pub fn contact_manifold_capsule_capsule<'a, ManifoldData, ContactData>( - pos12: &Isometry, + pos12: &Isometry, capsule1: &'a Capsule, capsule2: &'a Capsule, prediction: Real, @@ -135,7 +135,7 @@ pub fn contact_manifold_capsule_capsule<'a, ManifoldData, ContactData>( /// Computes the contact manifold between two capsules. #[cfg(feature = "dim3")] pub fn contact_manifold_capsule_capsule<'a, ManifoldData, ContactData>( - pos12: &Isometry, + pos12: &Isometry, capsule1: &'a Capsule, capsule2: &'a Capsule, prediction: Real, diff --git a/src/query/contact_manifolds/contact_manifolds_composite_shape_composite_shape.rs b/src/query/contact_manifolds/contact_manifolds_composite_shape_composite_shape.rs index 4be384ab..70e8c0cd 100644 --- a/src/query/contact_manifolds/contact_manifolds_composite_shape_composite_shape.rs +++ b/src/query/contact_manifolds/contact_manifolds_composite_shape_composite_shape.rs @@ -55,7 +55,7 @@ fn ensure_workspace_exists(workspace: &mut Option) { /// Computes the contact manifolds between two composite shapes. pub fn contact_manifolds_composite_shape_composite_shape<'a, ManifoldData, ContactData>( dispatcher: &dyn PersistentQueryDispatcher, - pos12: &Isometry, + pos12: &Isometry, mut composite1: &'a dyn SimdCompositeShape, mut composite2: &'a dyn SimdCompositeShape, prediction: Real, diff --git a/src/query/contact_manifolds/contact_manifolds_composite_shape_shape.rs b/src/query/contact_manifolds/contact_manifolds_composite_shape_shape.rs index a94c6193..daa2a3f7 100644 --- a/src/query/contact_manifolds/contact_manifolds_composite_shape_shape.rs +++ b/src/query/contact_manifolds/contact_manifolds_composite_shape_shape.rs @@ -55,7 +55,7 @@ fn ensure_workspace_exists(workspace: &mut Option) { /// Computes the contact manifolds between a composite shape and an abstract shape. pub fn contact_manifolds_composite_shape_shape( dispatcher: &dyn PersistentQueryDispatcher, - pos12: &Isometry, + pos12: &Isometry, composite1: &dyn SimdCompositeShape, shape2: &dyn Shape, prediction: Real, diff --git a/src/query/contact_manifolds/contact_manifolds_convex_ball.rs b/src/query/contact_manifolds/contact_manifolds_convex_ball.rs index 3fcbb772..7373d6d2 100644 --- a/src/query/contact_manifolds/contact_manifolds_convex_ball.rs +++ b/src/query/contact_manifolds/contact_manifolds_convex_ball.rs @@ -6,7 +6,7 @@ use na::Unit; /// Computes the contact manifold between a convex shape and a ball, both represented as a `Shape` trait-object. pub fn contact_manifold_convex_ball_shapes( - pos12: &Isometry, + pos12: &Isometry, shape1: &dyn Shape, shape2: &dyn Shape, normal_constraints1: Option<&dyn NormalConstraints>, @@ -43,7 +43,7 @@ pub fn contact_manifold_convex_ball_shapes( /// Computes the contact manifold between a convex shape and a ball. pub fn contact_manifold_convex_ball<'a, ManifoldData, ContactData, S1>( - pos12: &Isometry, + pos12: &Isometry, shape1: &'a S1, ball2: &'a Ball, normal_constraints1: Option<&dyn NormalConstraints>, diff --git a/src/query/contact_manifolds/contact_manifolds_cuboid_capsule.rs b/src/query/contact_manifolds/contact_manifolds_cuboid_capsule.rs index 0e814a79..7e740e13 100644 --- a/src/query/contact_manifolds/contact_manifolds_cuboid_capsule.rs +++ b/src/query/contact_manifolds/contact_manifolds_cuboid_capsule.rs @@ -8,7 +8,7 @@ use crate::shape::{CuboidFeature, CuboidFeatureFace}; /// Computes the contact manifold between a cuboid and a capsule, both represented as `Shape` trait-objects. pub fn contact_manifold_cuboid_capsule_shapes( - pos12: &Isometry, + pos12: &Isometry, shape1: &dyn Shape, shape2: &dyn Shape, prediction: Real, @@ -41,8 +41,8 @@ pub fn contact_manifold_cuboid_capsule_shapes( /// Computes the contact manifold between a cuboid and a capsule. pub fn contact_manifold_cuboid_capsule<'a, ManifoldData, ContactData>( - pos12: &Isometry, - pos21: &Isometry, + pos12: &Isometry, + pos21: &Isometry, cube1: &'a Cuboid, capsule2: &'a Capsule, prediction: Real, diff --git a/src/query/contact_manifolds/contact_manifolds_cuboid_cuboid.rs b/src/query/contact_manifolds/contact_manifolds_cuboid_cuboid.rs index bd8301ff..bbe0e5f3 100644 --- a/src/query/contact_manifolds/contact_manifolds_cuboid_cuboid.rs +++ b/src/query/contact_manifolds/contact_manifolds_cuboid_cuboid.rs @@ -6,7 +6,7 @@ use crate::shape::{Cuboid, PolygonalFeature, Shape}; /// Computes the contact manifold between two cuboids represented as `Shape` trait-objects. pub fn contact_manifold_cuboid_cuboid_shapes( - pos12: &Isometry, + pos12: &Isometry, g1: &dyn Shape, g2: &dyn Shape, prediction: Real, @@ -19,7 +19,7 @@ pub fn contact_manifold_cuboid_cuboid_shapes( - pos12: &Isometry, + pos12: &Isometry, cuboid1: &'a Cuboid, cuboid2: &'a Cuboid, prediction: Real, diff --git a/src/query/contact_manifolds/contact_manifolds_cuboid_triangle.rs b/src/query/contact_manifolds/contact_manifolds_cuboid_triangle.rs index eb2baa30..62622b33 100644 --- a/src/query/contact_manifolds/contact_manifolds_cuboid_triangle.rs +++ b/src/query/contact_manifolds/contact_manifolds_cuboid_triangle.rs @@ -8,7 +8,7 @@ use crate::shape::{Cuboid, Shape, Triangle}; /// Computes the contact manifold between a cuboid and a triangle represented as `Shape` trait-objects. pub fn contact_manifold_cuboid_triangle_shapes( - pos12: &Isometry, + pos12: &Isometry, shape1: &dyn Shape, shape2: &dyn Shape, normal_constraints1: Option<&dyn NormalConstraints>, @@ -47,8 +47,8 @@ pub fn contact_manifold_cuboid_triangle_shapes( /// Computes the contact manifold between a cuboid and a triangle. pub fn contact_manifold_cuboid_triangle<'a, ManifoldData, ContactData>( - pos12: &Isometry, - pos21: &Isometry, + pos12: &Isometry, + pos21: &Isometry, cuboid1: &'a Cuboid, triangle2: &'a Triangle, normal_constraints1: Option<&dyn NormalConstraints>, diff --git a/src/query/contact_manifolds/contact_manifolds_halfspace_pfm.rs b/src/query/contact_manifolds/contact_manifolds_halfspace_pfm.rs index 5d1651a6..a5d81cac 100644 --- a/src/query/contact_manifolds/contact_manifolds_halfspace_pfm.rs +++ b/src/query/contact_manifolds/contact_manifolds_halfspace_pfm.rs @@ -4,7 +4,7 @@ use crate::shape::{HalfSpace, PackedFeatureId, PolygonalFeature, PolygonalFeatur /// Computes the contact manifold between a convex shape and a ball, both represented as a `Shape` trait-object. pub fn contact_manifold_halfspace_pfm_shapes( - pos12: &Isometry, + pos12: &Isometry, shape1: &dyn Shape, shape2: &dyn Shape, prediction: Real, @@ -41,7 +41,7 @@ pub fn contact_manifold_halfspace_pfm_shapes( /// Computes the contact manifold between a convex shape and a ball. pub fn contact_manifold_halfspace_pfm<'a, ManifoldData, ContactData, S2>( - pos12: &Isometry, + pos12: &Isometry, halfspace1: &'a HalfSpace, pfm2: &'a S2, border_radius2: Real, diff --git a/src/query/contact_manifolds/contact_manifolds_heightfield_composite_shape.rs b/src/query/contact_manifolds/contact_manifolds_heightfield_composite_shape.rs index d5bcd58c..745d69af 100644 --- a/src/query/contact_manifolds/contact_manifolds_heightfield_composite_shape.rs +++ b/src/query/contact_manifolds/contact_manifolds_heightfield_composite_shape.rs @@ -57,8 +57,8 @@ fn ensure_workspace_exists(workspace: &mut Option) { /// Computes the contact manifold between an heightfield and a composite shape. pub fn contact_manifolds_heightfield_composite_shape( dispatcher: &dyn PersistentQueryDispatcher, - pos12: &Isometry, - pos21: &Isometry, + pos12: &Isometry, + pos21: &Isometry, heightfield1: &HeightField, composite2: &dyn SimdCompositeShape, prediction: Real, diff --git a/src/query/contact_manifolds/contact_manifolds_heightfield_shape.rs b/src/query/contact_manifolds/contact_manifolds_heightfield_shape.rs index bf63ed58..7c46ed83 100644 --- a/src/query/contact_manifolds/contact_manifolds_heightfield_shape.rs +++ b/src/query/contact_manifolds/contact_manifolds_heightfield_shape.rs @@ -39,7 +39,7 @@ impl HeightFieldShapeContactManifoldsWorkspace { /// Computes the contact manifold between an heightfield and a shape, both represented as `Shape` trait-objects. pub fn contact_manifolds_heightfield_shape_shapes( dispatcher: &dyn PersistentQueryDispatcher, - pos12: &Isometry, + pos12: &Isometry, shape1: &dyn Shape, shape2: &dyn Shape, prediction: Real, @@ -93,7 +93,7 @@ fn ensure_workspace_exists(workspace: &mut Option) { /// Computes the contact manifold between an heightfield and an abstract shape. pub fn contact_manifolds_heightfield_shape( dispatcher: &dyn PersistentQueryDispatcher, - pos12: &Isometry, + pos12: &Isometry, heightfield1: &HeightField, shape2: &dyn Shape, prediction: Real, diff --git a/src/query/contact_manifolds/contact_manifolds_pfm_pfm.rs b/src/query/contact_manifolds/contact_manifolds_pfm_pfm.rs index bb13a838..fbf2cd4d 100644 --- a/src/query/contact_manifolds/contact_manifolds_pfm_pfm.rs +++ b/src/query/contact_manifolds/contact_manifolds_pfm_pfm.rs @@ -11,7 +11,7 @@ use na::Unit; /// Computes the contact manifold between two convex shapes implementing the `PolygonalSupportMap` /// trait, both represented as `Shape` trait-objects. pub fn contact_manifold_pfm_pfm_shapes( - pos12: &Isometry, + pos12: &Isometry, shape1: &dyn Shape, shape2: &dyn Shape, normal_constraints1: Option<&dyn NormalConstraints>, @@ -42,7 +42,7 @@ pub fn contact_manifold_pfm_pfm_shapes( /// Computes the contact manifold between two convex shapes implementing the `PolygonalSupportMap` trait. pub fn contact_manifold_pfm_pfm<'a, ManifoldData, ContactData, S1, S2>( - pos12: &Isometry, + pos12: &Isometry, pfm1: &'a S1, border_radius1: Real, normal_constraints1: Option<&dyn NormalConstraints>, diff --git a/src/query/contact_manifolds/contact_manifolds_trimesh_shape.rs b/src/query/contact_manifolds/contact_manifolds_trimesh_shape.rs index 4531bf56..d082ae75 100644 --- a/src/query/contact_manifolds/contact_manifolds_trimesh_shape.rs +++ b/src/query/contact_manifolds/contact_manifolds_trimesh_shape.rs @@ -41,7 +41,7 @@ impl TriMeshShapeContactManifoldsWorkspace { /// Computes the contact manifold between a triangle-mesh an a shape, both represented as `Shape` trait-objects. pub fn contact_manifolds_trimesh_shape_shapes( dispatcher: &dyn PersistentQueryDispatcher, - pos12: &Isometry, + pos12: &Isometry, shape1: &dyn Shape, shape2: &dyn Shape, prediction: Real, @@ -86,7 +86,7 @@ fn ensure_workspace_exists(workspace: &mut Option) { /// Computes the contact manifold between a triangle-mesh and a shape. pub fn contact_manifolds_trimesh_shape( dispatcher: &dyn PersistentQueryDispatcher, - pos12: &Isometry, + pos12: &Isometry, trimesh1: &TriMesh, shape2: &dyn Shape, prediction: Real, diff --git a/src/query/contact_manifolds/normals_constraint.rs b/src/query/contact_manifolds/normals_constraint.rs index 1ecc19ba..1a86b09f 100644 --- a/src/query/contact_manifolds/normals_constraint.rs +++ b/src/query/contact_manifolds/normals_constraint.rs @@ -1,4 +1,4 @@ -use crate::math::{Isometry, Real, Vector}; +use crate::math::{Isometry, Vector}; // NOTE: the 'static requirement is only needed for the following impl to work: // impl<'a> TypedSimdCompositeShape for dyn SimdCompositeShape @@ -19,13 +19,13 @@ pub trait NormalConstraints: 'static { /// /// If this method returns `false` then the contacts associated to that normal should be /// considered invalid and be ignored by the collision-detection pipeline. - fn project_local_normal_mut(&self, normal: &mut Vector) -> bool; + fn project_local_normal_mut(&self, normal: &mut Vector) -> bool; /// Corrects or discards the specified normal (assumed to be unit-sized) based on the constraints /// encoded by `Self`. /// /// If this method returns `None` then the contacts associated to that normal should be /// considered invalid and be ignored by the collision-detection pipeline. - fn project_local_normal(&self, mut normal: Vector) -> Option> { + fn project_local_normal(&self, mut normal: Vector) -> Option { self.project_local_normal_mut(&mut normal).then_some(normal) } @@ -41,9 +41,9 @@ pub trait NormalConstraints: 'static { /// considered invalid and be ignored by the collision-detection pipeline. fn project_local_normal1( &self, - pos12: &Isometry, - normal1: &mut Vector, - normal2: &mut Vector, + pos12: &Isometry, + normal1: &mut Vector, + normal2: &mut Vector, ) -> bool { if !self.project_local_normal_mut(normal1) { return false; @@ -64,9 +64,9 @@ pub trait NormalConstraints: 'static { /// considered invalid and be ignored by the collision-detection pipeline. fn project_local_normal2( &self, - pos12: &Isometry, - normal1: &mut Vector, - normal2: &mut Vector, + pos12: &Isometry, + normal1: &mut Vector, + normal2: &mut Vector, ) -> bool { if !self.project_local_normal_mut(normal2) { return false; @@ -79,7 +79,7 @@ pub trait NormalConstraints: 'static { } impl NormalConstraints for () { - fn project_local_normal_mut(&self, _: &mut Vector) -> bool { + fn project_local_normal_mut(&self, _: &mut Vector) -> bool { true } } @@ -91,9 +91,9 @@ pub trait NormalConstraintsPair { /// This trait is mostly used internally to combine two [`NormalConstraints`] conveniently. fn project_local_normals( &self, - pos12: &Isometry, - normal1: &mut Vector, - normal2: &mut Vector, + pos12: &Isometry, + normal1: &mut Vector, + normal2: &mut Vector, ) -> bool; } @@ -107,9 +107,9 @@ impl NormalConstraintsPair { fn project_local_normals( &self, - pos12: &Isometry, - normal1: &mut Vector, - normal2: &mut Vector, + pos12: &Isometry, + normal1: &mut Vector, + normal2: &mut Vector, ) -> bool { if let Some(proj) = self.0 { if !proj.project_local_normal1(pos12, normal1, normal2) { diff --git a/src/query/contact_manifolds/polygon_polygon_contact_generator.rs b/src/query/contact_manifolds/polygon_polygon_contact_generator.rs index ac2c60f8..22100401 100644 --- a/src/query/contact_manifolds/polygon_polygon_contact_generator.rs +++ b/src/query/contact_manifolds/polygon_polygon_contact_generator.rs @@ -26,9 +26,9 @@ pub fn generate_contacts_polygon_polygon(_ctxt: &mut PrimitiveContactGenerationC fn generate_contacts<'a>( mut p1: &'a Polygon, - mut m1: &'a Isometry, + mut m1: &'a Isometry, mut p2: &'a Polygon, - mut m2: &'a Isometry, + mut m2: &'a Isometry, manifold: &'a mut ContactManifold, ) { let mut m12 = m1.inv_mul(&m2); diff --git a/src/query/default_query_dispatcher.rs b/src/query/default_query_dispatcher.rs index 19067c67..291f91ea 100644 --- a/src/query/default_query_dispatcher.rs +++ b/src/query/default_query_dispatcher.rs @@ -19,7 +19,7 @@ pub struct DefaultQueryDispatcher; impl QueryDispatcher for DefaultQueryDispatcher { fn intersection_test( &self, - pos12: &Isometry, + pos12: &Isometry, shape1: &dyn Shape, shape2: &dyn Shape, ) -> Result { @@ -83,7 +83,7 @@ impl QueryDispatcher for DefaultQueryDispatcher { /// Returns `0.0` if the objects are touching or penetrating. fn distance( &self, - pos12: &Isometry, + pos12: &Isometry, shape1: &dyn Shape, shape2: &dyn Shape, ) -> Result { @@ -139,7 +139,7 @@ impl QueryDispatcher for DefaultQueryDispatcher { fn contact( &self, - pos12: &Isometry, + pos12: &Isometry, shape1: &dyn Shape, shape2: &dyn Shape, prediction: Real, @@ -195,7 +195,7 @@ impl QueryDispatcher for DefaultQueryDispatcher { fn closest_points( &self, - pos12: &Isometry, + pos12: &Isometry, shape1: &dyn Shape, shape2: &dyn Shape, max_dist: Real, @@ -271,8 +271,8 @@ impl QueryDispatcher for DefaultQueryDispatcher { fn cast_shapes( &self, - pos12: &Isometry, - local_vel12: &Vector, + pos12: &Isometry, + local_vel12: &Vector, shape1: &dyn Shape, shape2: &dyn Shape, options: ShapeCastOptions, @@ -426,7 +426,7 @@ where { fn contact_manifolds( &self, - pos12: &Isometry, + pos12: &Isometry, shape1: &dyn Shape, shape2: &dyn Shape, prediction: Real, @@ -529,7 +529,7 @@ where fn contact_manifold_convex_convex( &self, - pos12: &Isometry, + pos12: &Isometry, shape1: &dyn Shape, shape2: &dyn Shape, normal_constraints1: Option<&dyn NormalConstraints>, diff --git a/src/query/distance/distance.rs b/src/query/distance/distance.rs index c23c5044..03a2fef2 100644 --- a/src/query/distance/distance.rs +++ b/src/query/distance/distance.rs @@ -7,9 +7,9 @@ use crate::shape::Shape; /// /// Returns `0.0` if the objects are touching or penetrating. pub fn distance( - pos1: &Isometry, + pos1: &Isometry, g1: &dyn Shape, - pos2: &Isometry, + pos2: &Isometry, g2: &dyn Shape, ) -> Result { let pos12 = pos1.inv_mul(pos2); diff --git a/src/query/distance/distance_ball_ball.rs b/src/query/distance/distance_ball_ball.rs index ca2fe05d..c3d1d268 100644 --- a/src/query/distance/distance_ball_ball.rs +++ b/src/query/distance/distance_ball_ball.rs @@ -4,7 +4,7 @@ use na::{self, ComplexField}; /// Distance between balls. #[inline] -pub fn distance_ball_ball(b1: &Ball, center2: &Point, b2: &Ball) -> Real { +pub fn distance_ball_ball(b1: &Ball, center2: &Point, b2: &Ball) -> Real { let r1 = b1.radius; let r2 = b2.radius; let distance_squared = center2.coords.norm_squared(); diff --git a/src/query/distance/distance_ball_convex_polyhedron.rs b/src/query/distance/distance_ball_convex_polyhedron.rs index 3b1f0f31..3c73fbf3 100644 --- a/src/query/distance/distance_ball_convex_polyhedron.rs +++ b/src/query/distance/distance_ball_convex_polyhedron.rs @@ -7,7 +7,7 @@ use crate::shape::{Ball, Shape}; /// both the ConvexPolyhedron and PointQuery traits. #[inline] pub fn distance_ball_convex_polyhedron( - pos12: &Isometry, + pos12: &Isometry, ball1: &Ball, shape2: &(impl Shape + ?Sized), ) -> Real { @@ -20,7 +20,7 @@ pub fn distance_ball_convex_polyhedron( /// both the ConvexPolyhedron and PointQuery traits. #[inline] pub fn distance_convex_polyhedron_ball( - pos12: &Isometry, + pos12: &Isometry, shape1: &(impl Shape + ?Sized), ball2: &Ball, ) -> Real { diff --git a/src/query/distance/distance_composite_shape_shape.rs b/src/query/distance/distance_composite_shape_shape.rs index 60153805..d6e6a651 100644 --- a/src/query/distance/distance_composite_shape_shape.rs +++ b/src/query/distance/distance_composite_shape_shape.rs @@ -1,5 +1,5 @@ use crate::bounding_volume::SimdAabb; -use crate::math::{Isometry, Real, SimdBool, SimdReal, Vector, SIMD_WIDTH}; +use crate::math::{Isometry, Real, SimdBool, SimdReal, VectorT, SIMD_WIDTH}; use crate::partitioning::{SimdBestFirstVisitStatus, SimdBestFirstVisitor}; use crate::query::QueryDispatcher; use crate::shape::{Shape, TypedSimdCompositeShape}; @@ -9,7 +9,7 @@ use simba::simd::{SimdBool as _, SimdPartialOrd, SimdValue}; /// Smallest distance between a composite shape and any other shape. pub fn distance_composite_shape_shape( dispatcher: &D, - pos12: &Isometry, + pos12: &Isometry, g1: &G1, g2: &dyn Shape, ) -> Real @@ -28,7 +28,7 @@ where /// Smallest distance between a shape and a composite shape. pub fn distance_shape_composite_shape( dispatcher: &D, - pos12: &Isometry, + pos12: &Isometry, g1: &dyn Shape, g2: &G2, ) -> Real @@ -41,29 +41,24 @@ where /// A visitor for computing the distance between a composite shape and a shape. pub struct CompositeShapeAgainstAnyDistanceVisitor<'a, D: ?Sized, G1: ?Sized + 'a> { - msum_shift: Vector, - msum_margin: Vector, + msum_shift: VectorT, + msum_margin: VectorT, dispatcher: &'a D, - pos12: &'a Isometry, + pos12: &'a Isometry, g1: &'a G1, g2: &'a dyn Shape, } impl<'a, D: ?Sized, G1: ?Sized + 'a> CompositeShapeAgainstAnyDistanceVisitor<'a, D, G1> { /// Initialize a visitor for computing the distance between a composite shape and a shape. - pub fn new( - dispatcher: &'a D, - pos12: &'a Isometry, - g1: &'a G1, - g2: &'a dyn Shape, - ) -> Self { + pub fn new(dispatcher: &'a D, pos12: &'a Isometry, g1: &'a G1, g2: &'a dyn Shape) -> Self { let ls_aabb2 = g2.compute_aabb(pos12); Self { dispatcher, - msum_shift: Vector::splat(-ls_aabb2.center().coords), - msum_margin: Vector::splat(ls_aabb2.half_extents()), + msum_shift: VectorT::splat(-ls_aabb2.center().coords), + msum_margin: VectorT::splat(ls_aabb2.half_extents()), pos12, g1, g2, diff --git a/src/query/distance/distance_cuboid_cuboid.rs b/src/query/distance/distance_cuboid_cuboid.rs index bfe4416c..5b2a35af 100644 --- a/src/query/distance/distance_cuboid_cuboid.rs +++ b/src/query/distance/distance_cuboid_cuboid.rs @@ -4,7 +4,7 @@ use crate::shape::Cuboid; /// Distance between two cuboids. #[inline] -pub fn distance_cuboid_cuboid(pos12: &Isometry, cuboid1: &Cuboid, cuboid2: &Cuboid) -> Real { +pub fn distance_cuboid_cuboid(pos12: &Isometry, cuboid1: &Cuboid, cuboid2: &Cuboid) -> Real { match crate::query::details::closest_points_cuboid_cuboid(pos12, cuboid1, cuboid2, Real::MAX) { ClosestPoints::WithinMargin(p1, p2) => na::distance(&p1, &(pos12 * p2)), _ => 0.0, diff --git a/src/query/distance/distance_halfspace_support_map.rs b/src/query/distance/distance_halfspace_support_map.rs index d77b6770..21876d3b 100644 --- a/src/query/distance/distance_halfspace_support_map.rs +++ b/src/query/distance/distance_halfspace_support_map.rs @@ -5,7 +5,7 @@ use na; /// Distance between a halfspace and a support-mapped shape. pub fn distance_halfspace_support_map( - pos12: &Isometry, + pos12: &Isometry, halfspace: &HalfSpace, other: &G, ) -> Real { @@ -15,7 +15,7 @@ pub fn distance_halfspace_support_map( /// Distance between a support-mapped shape and a halfspace. pub fn distance_support_map_halfspace( - pos12: &Isometry, + pos12: &Isometry, other: &G, halfspace: &HalfSpace, ) -> Real { diff --git a/src/query/distance/distance_segment_segment.rs b/src/query/distance/distance_segment_segment.rs index fb3966c8..26b8325e 100644 --- a/src/query/distance/distance_segment_segment.rs +++ b/src/query/distance/distance_segment_segment.rs @@ -4,11 +4,7 @@ use crate::shape::Segment; /// Distance between two segments. #[inline] -pub fn distance_segment_segment( - pos12: &Isometry, - segment1: &Segment, - segment2: &Segment, -) -> Real { +pub fn distance_segment_segment(pos12: &Isometry, segment1: &Segment, segment2: &Segment) -> Real { match crate::query::details::closest_points_segment_segment( pos12, segment1, diff --git a/src/query/distance/distance_support_map_support_map.rs b/src/query/distance/distance_support_map_support_map.rs index c0096ec3..30780f14 100644 --- a/src/query/distance/distance_support_map_support_map.rs +++ b/src/query/distance/distance_support_map_support_map.rs @@ -6,7 +6,7 @@ use na::{self, Unit}; use num::Bounded; /// Distance between support-mapped shapes. -pub fn distance_support_map_support_map(pos12: &Isometry, g1: &G1, g2: &G2) -> Real +pub fn distance_support_map_support_map(pos12: &Isometry, g1: &G1, g2: &G2) -> Real where G1: ?Sized + SupportMap, G2: ?Sized + SupportMap, @@ -18,11 +18,11 @@ where /// /// This allows a more fine grained control other the underlying GJK algorigtm. pub fn distance_support_map_support_map_with_params( - pos12: &Isometry, + pos12: &Isometry, g1: &G1, g2: &G2, simplex: &mut VoronoiSimplex, - init_dir: Option>, + init_dir: Option, ) -> Real where G1: ?Sized + SupportMap, @@ -34,12 +34,7 @@ where if let Some(dir) = Unit::try_new(dir, crate::math::DEFAULT_EPSILON) { simplex.reset(CSOPoint::from_shapes(pos12, g1, g2, &dir)); } else { - simplex.reset(CSOPoint::from_shapes( - pos12, - g1, - g2, - &Vector::::x_axis(), - )); + simplex.reset(CSOPoint::from_shapes(pos12, g1, g2, &Vector::x_axis())); } match gjk::closest_points(pos12, g1, g2, Real::max_value(), true, simplex) { diff --git a/src/query/epa/epa2.rs b/src/query/epa/epa2.rs index 49961a80..882d3ea4 100644 --- a/src/query/epa/epa2.rs +++ b/src/query/epa/epa2.rs @@ -52,8 +52,8 @@ impl Ord for FaceId { #[derive(Clone, Debug)] struct Face { pts: [usize; 2], - normal: Unit>, - proj: Point, + normal: Unit, + proj: Point, bcoords: [Real; 2], deleted: bool, } @@ -74,7 +74,7 @@ impl Face { pub fn new_with_proj( vertices: &[CSOPoint], - proj: Point, + proj: Point, bcoords: [Real; 2], pts: [usize; 2], ) -> Self { @@ -99,7 +99,7 @@ impl Face { } } - pub fn closest_points(&self, vertices: &[CSOPoint]) -> (Point, Point) { + pub fn closest_points(&self, vertices: &[CSOPoint]) -> (Point, Point) { ( vertices[self.pts[0]].orig1 * self.bcoords[0] + vertices[self.pts[1]].orig1.coords * self.bcoords[1], @@ -140,10 +140,10 @@ impl EPA { /// Return the projected point in the local-space of `g`. pub fn project_origin( &mut self, - m: &Isometry, + m: &Isometry, g: &G, simplex: &VoronoiSimplex, - ) -> Option> { + ) -> Option { self.closest_points(&m.inverse(), g, &ConstantOrigin, simplex) .map(|(p, _, _)| p) } @@ -154,11 +154,11 @@ impl EPA { /// Returns `None` if the EPA fails to converge or if `g1` and `g2` are not penetrating. pub fn closest_points( &mut self, - pos12: &Isometry, + pos12: &Isometry, g1: &G1, g2: &G2, simplex: &VoronoiSimplex, - ) -> Option<(Point, Point, Unit>)> + ) -> Option<(Point, Point, Unit)> where G1: ?Sized + SupportMap, G2: ?Sized + SupportMap, @@ -361,7 +361,7 @@ impl EPA { } } -fn project_origin(a: &Point, b: &Point) -> Option<(Point, [Real; 2])> { +fn project_origin(a: &Point, b: &Point) -> Option<(Point, [Real; 2])> { let ab = *b - *a; let ap = -a.coords; let ab_ap = ab.dot(&ap); diff --git a/src/query/epa/epa3.rs b/src/query/epa/epa3.rs index 5ed482d4..8c8b2bd2 100644 --- a/src/query/epa/epa3.rs +++ b/src/query/epa/epa3.rs @@ -52,7 +52,7 @@ impl Ord for FaceId { struct Face { pts: [usize; 3], adj: [usize; 3], - normal: Unit>, + normal: Unit, bcoords: [Real; 3], deleted: bool, } @@ -95,7 +95,7 @@ impl Face { vertices[pts[1]].point, vertices[pts[2]].point, ); - let (proj, loc) = tri.project_local_point_and_get_location(&Point::::origin(), true); + let (proj, loc) = tri.project_local_point_and_get_location(&Point::origin(), true); match loc { TrianglePointLocation::OnVertex(_) | TrianglePointLocation::OnEdge(_, _) => { @@ -103,7 +103,7 @@ impl Face { ( // barycentric_coordinates is guaranteed to work in OnVertex and OnEdge locations Self::new_with_proj(vertices, loc.barycentric_coordinates().unwrap(), pts, adj), - proj.is_inside_eps(&Point::::origin(), eps_tol), + proj.is_inside_eps(&Point::origin(), eps_tol), ) } TrianglePointLocation::OnFace(_, bcoords) => { @@ -113,7 +113,7 @@ impl Face { } } - pub fn closest_points(&self, vertices: &[CSOPoint]) -> (Point, Point) { + pub fn closest_points(&self, vertices: &[CSOPoint]) -> (Point, Point) { ( vertices[self.pts[0]].orig1 * self.bcoords[0] + vertices[self.pts[1]].orig1.coords * self.bcoords[1] @@ -205,10 +205,10 @@ impl EPA { /// Return the projected point in the local-space of `g`. pub fn project_origin( &mut self, - m: &Isometry, + m: &Isometry, g: &G, simplex: &VoronoiSimplex, - ) -> Option> { + ) -> Option { self.closest_points(&m.inverse(), g, &ConstantOrigin, simplex) .map(|(p, _, _)| p) } @@ -219,11 +219,11 @@ impl EPA { /// Returns `None` if the EPA fails to converge or if `g1` and `g2` are not penetrating. pub fn closest_points( &mut self, - pos12: &Isometry, + pos12: &Isometry, g1: &G1, g2: &G2, simplex: &VoronoiSimplex, - ) -> Option<(Point, Point, Unit>)> + ) -> Option<(Point, Point, Unit)> where G1: ?Sized + SupportMap, G2: ?Sized + SupportMap, @@ -241,7 +241,7 @@ impl EPA { } if simplex.dimension() == 0 { - let mut n: Vector = na::zero(); + let mut n: Vector = na::zero(); n[1] = 1.0; return Some((Point::origin(), Point::origin(), Unit::new_unchecked(n))); } else if simplex.dimension() == 3 { diff --git a/src/query/gjk/cso_point.rs b/src/query/gjk/cso_point.rs index 943f5b9d..c2c802d6 100644 --- a/src/query/gjk/cso_point.rs +++ b/src/query/gjk/cso_point.rs @@ -1,4 +1,4 @@ -use crate::math::{Isometry, Point, Real, Vector}; +use crate::math::{Isometry, Point, Vector}; use crate::shape::SupportMap; use na::Unit; use std::ops::Sub; @@ -13,16 +13,16 @@ use std::ops::Sub; pub struct CSOPoint { /// The point on the CSO. This is equal to `self.orig1 - self.orig2`, unless this CSOPoint /// has been translated with self.translate. - pub point: Point, + pub point: Point, /// The original point on the first shape used to compute `self.point`. - pub orig1: Point, + pub orig1: Point, /// The original point on the second shape used to compute `self.point`. - pub orig2: Point, + pub orig2: Point, } impl CSOPoint { /// Initializes a CSO point with `orig1 - orig2`. - pub fn new(orig1: Point, orig2: Point) -> Self { + pub fn new(orig1: Point, orig2: Point) -> Self { let point = Point::from(orig1 - orig2); Self::new_with_point(point, orig1, orig2) } @@ -30,7 +30,7 @@ impl CSOPoint { /// Initializes a CSO point with all information provided. /// /// It is assumed, but not checked, that `point == orig1 - orig2`. - pub fn new_with_point(point: Point, orig1: Point, orig2: Point) -> Self { + pub fn new_with_point(point: Point, orig1: Point, orig2: Point) -> Self { CSOPoint { point, orig1, @@ -39,7 +39,7 @@ impl CSOPoint { } /// Initializes a CSO point where both original points are equal. - pub fn single_point(point: Point) -> Self { + pub fn single_point(point: Point) -> Self { Self::new_with_point(point, point, Point::origin()) } @@ -50,10 +50,10 @@ impl CSOPoint { /// Computes the support point of the CSO of `g1` and `g2` toward the unit direction `dir`. pub fn from_shapes_toward( - pos12: &Isometry, + pos12: &Isometry, g1: &G1, g2: &G2, - dir: &Unit>, + dir: &Unit, ) -> Self where G1: ?Sized + SupportMap, @@ -66,7 +66,7 @@ impl CSOPoint { } /// Computes the support point of the CSO of `g1` and `g2` toward the direction `dir`. - pub fn from_shapes(pos12: &Isometry, g1: &G1, g2: &G2, dir: &Vector) -> Self + pub fn from_shapes(pos12: &Isometry, g1: &G1, g2: &G2, dir: &Vector) -> Self where G1: ?Sized + SupportMap, G2: ?Sized + SupportMap, @@ -78,21 +78,21 @@ impl CSOPoint { } /// Translate the CSO point. - pub fn translate(&self, dir: &Vector) -> Self { + pub fn translate(&self, dir: &Vector) -> Self { CSOPoint::new_with_point(self.point + dir, self.orig1, self.orig2) } /// Translate in-place the CSO point. - pub fn translate_mut(&mut self, dir: &Vector) { + pub fn translate_mut(&mut self, dir: &Vector) { self.point += dir; } } impl Sub for CSOPoint { - type Output = Vector; + type Output = Vector; #[inline] - fn sub(self, rhs: CSOPoint) -> Vector { + fn sub(self, rhs: CSOPoint) -> Vector { self.point - rhs.point } } diff --git a/src/query/gjk/gjk.rs b/src/query/gjk/gjk.rs index ebee30ae..a6b2545a 100644 --- a/src/query/gjk/gjk.rs +++ b/src/query/gjk/gjk.rs @@ -19,17 +19,17 @@ pub enum GJKResult { /// /// Both points and vector are expressed in the local-space of the first geometry involved /// in the GJK execution. - ClosestPoints(Point, Point, Unit>), + ClosestPoints(Point, Point, Unit), /// Result of the GJK algorithm when the origin is too close to the polytope but not inside of it. /// /// The returned vector is expressed in the local-space of the first geometry involved in the /// GJK execution. - Proximity(Unit>), + Proximity(Unit), /// Result of the GJK algorithm when the origin is too far away from the polytope. /// /// The returned vector is expressed in the local-space of the first geometry involved in the /// GJK execution. - NoIntersection(Unit>), + NoIntersection(Unit), } /// The absolute tolerance used by the GJK algorithm. @@ -47,10 +47,10 @@ pub fn eps_tol() -> Real { /// /// Return the projected point in the local-space of `g`. pub fn project_origin( - m: &Isometry, + m: &Isometry, g: &G, simplex: &mut VoronoiSimplex, -) -> Option> { +) -> Option { match closest_points( &m.inverse(), g, @@ -81,7 +81,7 @@ pub fn project_origin( /// compute the exact distance and return `GJKResult::Projection(point)` if the origin is closer /// than `max_dist` but not inside `shape`. pub fn closest_points( - pos12: &Isometry, + pos12: &Isometry, g1: &G1, g2: &G2, max_dist: Real, @@ -188,7 +188,7 @@ pub fn cast_local_ray( simplex: &mut VoronoiSimplex, ray: &Ray, max_time_of_impact: Real, -) -> Option<(Real, Vector)> { +) -> Option<(Real, Vector)> { let g2 = ConstantOrigin; minkowski_ray_cast( &Isometry::identity(), @@ -205,12 +205,12 @@ pub fn cast_local_ray( /// /// The `dir` vector must be expressed in the local-space of the first shape. pub fn directional_distance( - pos12: &Isometry, + pos12: &Isometry, g1: &G1, g2: &G2, - dir: &Vector, + dir: &Vector, simplex: &mut VoronoiSimplex, -) -> Option<(Real, Vector, Point, Point)> +) -> Option<(Real, Vector, Point, Point)> where G1: ?Sized + SupportMap, G2: ?Sized + SupportMap, @@ -233,13 +233,13 @@ where // Ray-cast on the Minkowski Difference `g1 - pos12 * g2`. fn minkowski_ray_cast( - pos12: &Isometry, + pos12: &Isometry, g1: &G1, g2: &G2, ray: &Ray, max_time_of_impact: Real, simplex: &mut VoronoiSimplex, -) -> Option<(Real, Vector)> +) -> Option<(Real, Vector)> where G1: ?Sized + SupportMap, G2: ?Sized + SupportMap, @@ -369,7 +369,7 @@ where } } -fn result(simplex: &VoronoiSimplex, prev: bool) -> (Point, Point) { +fn result(simplex: &VoronoiSimplex, prev: bool) -> (Point, Point) { let mut res = (Point::origin(), Point::origin()); if prev { for i in 0..simplex.prev_dimension() + 1 { diff --git a/src/query/gjk/special_support_maps.rs b/src/query/gjk/special_support_maps.rs index c9f3136c..e800606a 100644 --- a/src/query/gjk/special_support_maps.rs +++ b/src/query/gjk/special_support_maps.rs @@ -4,26 +4,26 @@ use crate::math::{Isometry, Point, Real, Vector}; use crate::shape::SupportMap; /// A support mapping that is a single point. -pub struct ConstantPoint(pub Point); +pub struct ConstantPoint(pub Point); impl SupportMap for ConstantPoint { #[inline] - fn support_point(&self, m: &Isometry, _: &Vector) -> Point { + fn support_point(&self, m: &Isometry, _: &Vector) -> Point { m * self.0 } #[inline] - fn support_point_toward(&self, m: &Isometry, _: &Unit>) -> Point { + fn support_point_toward(&self, m: &Isometry, _: &Unit) -> Point { m * self.0 } #[inline] - fn local_support_point(&self, _: &Vector) -> Point { + fn local_support_point(&self, _: &Vector) -> Point { self.0 } #[inline] - fn local_support_point_toward(&self, _: &Unit>) -> Point { + fn local_support_point_toward(&self, _: &Unit) -> Point { self.0 } } @@ -33,22 +33,22 @@ pub struct ConstantOrigin; impl SupportMap for ConstantOrigin { #[inline] - fn support_point(&self, m: &Isometry, _: &Vector) -> Point { + fn support_point(&self, m: &Isometry, _: &Vector) -> Point { m.translation.vector.into() } #[inline] - fn support_point_toward(&self, m: &Isometry, _: &Unit>) -> Point { + fn support_point_toward(&self, m: &Isometry, _: &Unit) -> Point { m.translation.vector.into() } #[inline] - fn local_support_point(&self, _: &Vector) -> Point { + fn local_support_point(&self, _: &Vector) -> Point { Point::origin() } #[inline] - fn local_support_point_toward(&self, _: &Unit>) -> Point { + fn local_support_point_toward(&self, _: &Unit) -> Point { Point::origin() } } @@ -63,22 +63,22 @@ pub struct DilatedShape<'a, S: ?Sized + SupportMap> { impl SupportMap for DilatedShape<'_, S> { #[inline] - fn support_point(&self, m: &Isometry, dir: &Vector) -> Point { + fn support_point(&self, m: &Isometry, dir: &Vector) -> Point { self.support_point_toward(m, &Unit::new_normalize(*dir)) } #[inline] - fn support_point_toward(&self, m: &Isometry, dir: &Unit>) -> Point { + fn support_point_toward(&self, m: &Isometry, dir: &Unit) -> Point { self.shape.support_point_toward(m, dir) + **dir * self.radius } #[inline] - fn local_support_point(&self, dir: &Vector) -> Point { + fn local_support_point(&self, dir: &Vector) -> Point { self.local_support_point_toward(&Unit::new_normalize(*dir)) } #[inline] - fn local_support_point_toward(&self, dir: &Unit>) -> Point { + fn local_support_point_toward(&self, dir: &Unit) -> Point { self.shape.local_support_point_toward(dir) + **dir * self.radius } } diff --git a/src/query/gjk/voronoi_simplex2.rs b/src/query/gjk/voronoi_simplex2.rs index e69d230a..c28793da 100644 --- a/src/query/gjk/voronoi_simplex2.rs +++ b/src/query/gjk/voronoi_simplex2.rs @@ -93,13 +93,13 @@ impl VoronoiSimplex { /// Returns the result of the projection or Point::origin() if the origin lies inside of the simplex. /// The state of the simplex before projection is saved, and can be retrieved using the methods prefixed /// by `prev_`. - pub fn project_origin_and_reduce(&mut self) -> Point { + pub fn project_origin_and_reduce(&mut self) -> Point { if self.dim == 0 { self.proj[0] = 1.0; self.vertices[0].point } else if self.dim == 1 { let (proj, location) = Segment::new(self.vertices[0].point, self.vertices[1].point) - .project_local_point_and_get_location(&Point::::origin(), true); + .project_local_point_and_get_location(&Point::origin(), true); match location { SegmentPointLocation::OnVertex(0) => { @@ -125,7 +125,7 @@ impl VoronoiSimplex { self.vertices[1].point, self.vertices[2].point, ) - .project_local_point_and_get_location(&Point::::origin(), true); + .project_local_point_and_get_location(&Point::origin(), true); match location { TrianglePointLocation::OnVertex(i) => { @@ -156,13 +156,12 @@ impl VoronoiSimplex { } /// Compute the projection of the origin on the boundary of this simplex. - pub fn project_origin(&mut self) -> Point { + pub fn project_origin(&mut self) -> Point { if self.dim == 0 { self.vertices[0].point } else if self.dim == 1 { let seg = Segment::new(self.vertices[0].point, self.vertices[1].point); - seg.project_local_point(&Point::::origin(), true) - .point + seg.project_local_point(&Point::origin(), true).point } else { assert!(self.dim == 2); let tri = Triangle::new( @@ -170,13 +169,12 @@ impl VoronoiSimplex { self.vertices[1].point, self.vertices[2].point, ); - tri.project_local_point(&Point::::origin(), true) - .point + tri.project_local_point(&Point::origin(), true).point } } /// Tests if the given point is already a vertex of this simplex. - pub fn contains_point(&self, pt: &Point) -> bool { + pub fn contains_point(&self, pt: &Point) -> bool { for i in 0..self.dim + 1 { if self.vertices[i].point == *pt { return true; diff --git a/src/query/gjk/voronoi_simplex3.rs b/src/query/gjk/voronoi_simplex3.rs index 8742e58d..622539d5 100644 --- a/src/query/gjk/voronoi_simplex3.rs +++ b/src/query/gjk/voronoi_simplex3.rs @@ -120,13 +120,13 @@ impl VoronoiSimplex { /// Returns the result of the projection or `Point::origin()` if the origin lies inside of the simplex. /// The state of the simplex before projection is saved, and can be retrieved using the methods prefixed /// by `prev_`. - pub fn project_origin_and_reduce(&mut self) -> Point { + pub fn project_origin_and_reduce(&mut self) -> Point { if self.dim == 0 { self.proj[0] = 1.0; self.vertices[0].point } else if self.dim == 1 { let (proj, location) = Segment::new(self.vertices[0].point, self.vertices[1].point) - .project_local_point_and_get_location(&Point::::origin(), true); + .project_local_point_and_get_location(&Point::origin(), true); match location { SegmentPointLocation::OnVertex(0) => { @@ -152,7 +152,7 @@ impl VoronoiSimplex { self.vertices[1].point, self.vertices[2].point, ) - .project_local_point_and_get_location(&Point::::origin(), true); + .project_local_point_and_get_location(&Point::origin(), true); match location { TrianglePointLocation::OnVertex(i) => { @@ -192,7 +192,7 @@ impl VoronoiSimplex { self.vertices[2].point, self.vertices[3].point, ) - .project_local_point_and_get_location(&Point::::origin(), true); + .project_local_point_and_get_location(&Point::origin(), true); match location { TetrahedronPointLocation::OnVertex(i) => { @@ -279,21 +279,19 @@ impl VoronoiSimplex { } /// Compute the projection of the origin on the boundary of this simplex. - pub fn project_origin(&mut self) -> Point { + pub fn project_origin(&mut self) -> Point { if self.dim == 0 { self.vertices[0].point } else if self.dim == 1 { let seg = Segment::new(self.vertices[0].point, self.vertices[1].point); - seg.project_local_point(&Point::::origin(), true) - .point + seg.project_local_point(&Point::origin(), true).point } else if self.dim == 2 { let tri = Triangle::new( self.vertices[0].point, self.vertices[1].point, self.vertices[2].point, ); - tri.project_local_point(&Point::::origin(), true) - .point + tri.project_local_point(&Point::origin(), true).point } else { let tetr = Tetrahedron::new( self.vertices[0].point, @@ -301,13 +299,12 @@ impl VoronoiSimplex { self.vertices[2].point, self.vertices[3].point, ); - tetr.project_local_point(&Point::::origin(), true) - .point + tetr.project_local_point(&Point::origin(), true).point } } /// Tests if the given point is already a vertex of this simplex. - pub fn contains_point(&self, pt: &Point) -> bool { + pub fn contains_point(&self, pt: &Point) -> bool { for i in 0..self.dim + 1 { if self.vertices[i].point == *pt { return true; diff --git a/src/query/intersection_test/intersection_test.rs b/src/query/intersection_test/intersection_test.rs index 8833cc30..750b6a46 100644 --- a/src/query/intersection_test/intersection_test.rs +++ b/src/query/intersection_test/intersection_test.rs @@ -1,12 +1,12 @@ -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::query::{DefaultQueryDispatcher, QueryDispatcher, Unsupported}; use crate::shape::Shape; /// Tests whether two shapes are intersecting. pub fn intersection_test( - pos1: &Isometry, + pos1: &Isometry, g1: &dyn Shape, - pos2: &Isometry, + pos2: &Isometry, g2: &dyn Shape, ) -> Result { let pos12 = pos1.inv_mul(pos2); diff --git a/src/query/intersection_test/intersection_test_ball_ball.rs b/src/query/intersection_test/intersection_test_ball_ball.rs index 2aed7829..d877f207 100644 --- a/src/query/intersection_test/intersection_test_ball_ball.rs +++ b/src/query/intersection_test/intersection_test_ball_ball.rs @@ -1,9 +1,9 @@ -use crate::math::{Point, Real}; +use crate::math::Point; use crate::shape::Ball; /// Intersection test between balls. #[inline] -pub fn intersection_test_ball_ball(center12: &Point, b1: &Ball, b2: &Ball) -> bool { +pub fn intersection_test_ball_ball(center12: &Point, b1: &Ball, b2: &Ball) -> bool { let r1 = b1.radius; let r2 = b2.radius; let distance_squared = center12.coords.norm_squared(); diff --git a/src/query/intersection_test/intersection_test_ball_point_query.rs b/src/query/intersection_test/intersection_test_ball_point_query.rs index 8dc68b7b..d811ff2e 100644 --- a/src/query/intersection_test/intersection_test_ball_point_query.rs +++ b/src/query/intersection_test/intersection_test_ball_point_query.rs @@ -1,10 +1,10 @@ -use crate::math::{Isometry, Point, Real}; +use crate::math::{Isometry, Point}; use crate::query::PointQuery; use crate::shape::Ball; /// Intersection test between a ball and a shape implementing the `PointQuery` trait. pub fn intersection_test_ball_point_query( - pos12: &Isometry, + pos12: &Isometry, ball1: &Ball, point_query2: &P, ) -> bool { @@ -13,7 +13,7 @@ pub fn intersection_test_ball_point_query( /// Intersection test between a shape implementing the `PointQuery` trait and a ball. pub fn intersection_test_point_query_ball( - pos12: &Isometry, + pos12: &Isometry, point_query1: &P, ball2: &Ball, ) -> bool { diff --git a/src/query/intersection_test/intersection_test_composite_shape_shape.rs b/src/query/intersection_test/intersection_test_composite_shape_shape.rs index ac6b0f70..1e3661da 100644 --- a/src/query/intersection_test/intersection_test_composite_shape_shape.rs +++ b/src/query/intersection_test/intersection_test_composite_shape_shape.rs @@ -1,5 +1,5 @@ use crate::bounding_volume::SimdAabb; -use crate::math::{Isometry, Real, SIMD_WIDTH}; +use crate::math::{Isometry, SIMD_WIDTH}; use crate::partitioning::{SimdVisitStatus, SimdVisitor}; use crate::query::QueryDispatcher; use crate::shape::{Shape, TypedSimdCompositeShape}; @@ -9,7 +9,7 @@ use simba::simd::SimdBool as _; /// Intersection test between a composite shape (`Mesh`, `Compound`) and any other shape. pub fn intersection_test_composite_shape_shape( dispatcher: &D, - pos12: &Isometry, + pos12: &Isometry, g1: &G1, g2: &dyn Shape, ) -> bool @@ -26,7 +26,7 @@ where /// Proximity between a shape and a composite (`Mesh`, `Compound`) shape. pub fn intersection_test_shape_composite_shape( dispatcher: &D, - pos12: &Isometry, + pos12: &Isometry, g1: &dyn Shape, g2: &G2, ) -> bool @@ -45,7 +45,7 @@ where ls_aabb2: SimdAabb, dispatcher: &'a D, - pos12: &'a Isometry, + pos12: &'a Isometry, g1: &'a G1, g2: &'a dyn Shape, @@ -63,7 +63,7 @@ where /// Initialize a visitor for checking if a composite-shape and a shape intersect. pub fn new( dispatcher: &'a D, - pos12: &'a Isometry, + pos12: &'a Isometry, g1: &'a G1, g2: &'a dyn Shape, ) -> IntersectionCompositeShapeShapeVisitor<'a, D, G1> { diff --git a/src/query/intersection_test/intersection_test_cuboid_cuboid.rs b/src/query/intersection_test/intersection_test_cuboid_cuboid.rs index ea9f7fab..e671ec73 100644 --- a/src/query/intersection_test/intersection_test_cuboid_cuboid.rs +++ b/src/query/intersection_test/intersection_test_cuboid_cuboid.rs @@ -1,11 +1,11 @@ -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::query::sat; use crate::shape::Cuboid; /// Intersection test between cuboids. #[inline] pub fn intersection_test_cuboid_cuboid( - pos12: &Isometry, + pos12: &Isometry, cuboid1: &Cuboid, cuboid2: &Cuboid, ) -> bool { diff --git a/src/query/intersection_test/intersection_test_cuboid_segment.rs b/src/query/intersection_test/intersection_test_cuboid_segment.rs index ee3fe146..3b7bc945 100644 --- a/src/query/intersection_test/intersection_test_cuboid_segment.rs +++ b/src/query/intersection_test/intersection_test_cuboid_segment.rs @@ -1,5 +1,5 @@ use crate::bounding_volume::Aabb; -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::query::sat; use crate::shape::{Cuboid, Segment}; @@ -13,7 +13,7 @@ pub fn intersection_test_aabb_segment(aabb1: &Aabb, segment2: &Segment) -> bool /// Test if a segment intersects a cuboid. #[inline] pub fn intersection_test_segment_cuboid( - pos12: &Isometry, + pos12: &Isometry, segment1: &Segment, cuboid2: &Cuboid, ) -> bool { @@ -23,7 +23,7 @@ pub fn intersection_test_segment_cuboid( /// Test if a segment intersects a cuboid. #[inline] pub fn intersection_test_cuboid_segment( - pos12: &Isometry, + pos12: &Isometry, cube1: &Cuboid, segment2: &Segment, ) -> bool { diff --git a/src/query/intersection_test/intersection_test_cuboid_triangle.rs b/src/query/intersection_test/intersection_test_cuboid_triangle.rs index fc6cf6d4..d773c838 100644 --- a/src/query/intersection_test/intersection_test_cuboid_triangle.rs +++ b/src/query/intersection_test/intersection_test_cuboid_triangle.rs @@ -1,5 +1,5 @@ use crate::bounding_volume::Aabb; -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::query::sat; use crate::shape::{Cuboid, Triangle}; @@ -13,7 +13,7 @@ pub fn intersection_test_aabb_triangle(aabb1: &Aabb, triangle2: &Triangle) -> bo /// Tests if a triangle intersects a cuboid. #[inline] pub fn intersection_test_triangle_cuboid( - pos12: &Isometry, + pos12: &Isometry, triangle1: &Triangle, cuboid2: &Cuboid, ) -> bool { @@ -23,7 +23,7 @@ pub fn intersection_test_triangle_cuboid( /// Tests if a triangle intersects an cuboid. #[inline] pub fn intersection_test_cuboid_triangle( - pos12: &Isometry, + pos12: &Isometry, cube1: &Cuboid, triangle2: &Triangle, ) -> bool { diff --git a/src/query/intersection_test/intersection_test_halfspace_support_map.rs b/src/query/intersection_test/intersection_test_halfspace_support_map.rs index e27eafa4..a55e4f35 100644 --- a/src/query/intersection_test/intersection_test_halfspace_support_map.rs +++ b/src/query/intersection_test/intersection_test_halfspace_support_map.rs @@ -1,10 +1,10 @@ -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::shape::HalfSpace; use crate::shape::SupportMap; /// Intersection test between a halfspace and a support-mapped shape (Cuboid, ConvexHull, etc.) pub fn intersection_test_halfspace_support_map( - pos12: &Isometry, + pos12: &Isometry, halfspace: &HalfSpace, other: &G, ) -> bool { @@ -14,7 +14,7 @@ pub fn intersection_test_halfspace_support_map( /// Intersection test between a support-mapped shape (Cuboid, ConvexHull, etc.) and a halfspace. pub fn intersection_test_support_map_halfspace( - pos12: &Isometry, + pos12: &Isometry, other: &G, halfspace: &HalfSpace, ) -> bool { diff --git a/src/query/intersection_test/intersection_test_polygon_polygon.rs b/src/query/intersection_test/intersection_test_polygon_polygon.rs index d84abfb6..3c3c2338 100644 --- a/src/query/intersection_test/intersection_test_polygon_polygon.rs +++ b/src/query/intersection_test/intersection_test_polygon_polygon.rs @@ -24,9 +24,9 @@ pub fn detect_proximity_polygon_polygon( fn detect_proximity<'a>( prediction_distance: Real, p1: &'a Polygon, - m1: &'a Isometry, + m1: &'a Isometry, p2: &'a Polygon, - m2: &'a Isometry, + m2: &'a Isometry, ) -> Proximity { let m12 = m1.inv_mul(&m2); let m21 = m12.inverse(); diff --git a/src/query/intersection_test/intersection_test_support_map_support_map.rs b/src/query/intersection_test/intersection_test_support_map_support_map.rs index db71997d..77820428 100644 --- a/src/query/intersection_test/intersection_test_support_map_support_map.rs +++ b/src/query/intersection_test/intersection_test_support_map_support_map.rs @@ -1,15 +1,11 @@ use na::{self, Unit}; -use crate::math::{Isometry, Real, Vector}; +use crate::math::{Isometry, Vector}; use crate::query::gjk::{self, CSOPoint, GJKResult, VoronoiSimplex}; use crate::shape::SupportMap; /// Intersection test between support-mapped shapes (`Cuboid`, `ConvexHull`, etc.) -pub fn intersection_test_support_map_support_map( - pos12: &Isometry, - g1: &G1, - g2: &G2, -) -> bool +pub fn intersection_test_support_map_support_map(pos12: &Isometry, g1: &G1, g2: &G2) -> bool where G1: ?Sized + SupportMap, G2: ?Sized + SupportMap, @@ -28,12 +24,12 @@ where /// /// This allows a more fine grained control other the underlying GJK algorithm. pub fn intersection_test_support_map_support_map_with_params( - pos12: &Isometry, + pos12: &Isometry, g1: &G1, g2: &G2, simplex: &mut VoronoiSimplex, - init_dir: Option>>, -) -> (bool, Unit>) + init_dir: Option>, +) -> (bool, Unit) where G1: ?Sized + SupportMap, G2: ?Sized + SupportMap, diff --git a/src/query/nonlinear_shape_cast/nonlinear_rigid_motion.rs b/src/query/nonlinear_shape_cast/nonlinear_rigid_motion.rs index 3a9e2de9..32af0919 100644 --- a/src/query/nonlinear_shape_cast/nonlinear_rigid_motion.rs +++ b/src/query/nonlinear_shape_cast/nonlinear_rigid_motion.rs @@ -4,28 +4,23 @@ use crate::math::{Isometry, Point, Real, Translation, Vector}; #[derive(Debug, Copy, Clone)] pub struct NonlinearRigidMotion { /// The starting isometry at `t = 0`. - pub start: Isometry, + pub start: Isometry, /// The local-space point at which the rotational part of this motion is applied. - pub local_center: Point, + pub local_center: Point, /// The translational velocity of this motion. - pub linvel: Vector, + pub linvel: Vector, /// The angular velocity of this motion. #[cfg(feature = "dim2")] pub angvel: Real, /// The angular velocity of this motion. #[cfg(feature = "dim3")] - pub angvel: Vector, + pub angvel: Vector, } impl NonlinearRigidMotion { /// Initialize a motion from a starting isometry and linear and angular velocities. #[cfg(feature = "dim2")] - pub fn new( - start: Isometry, - local_center: Point, - linvel: Vector, - angvel: Real, - ) -> Self { + pub fn new(start: Isometry, local_center: Point, linvel: Vector, angvel: Real) -> Self { NonlinearRigidMotion { start, local_center, @@ -36,12 +31,7 @@ impl NonlinearRigidMotion { /// Initialize a motion from a starting isometry and linear and angular velocities. #[cfg(feature = "dim3")] - pub fn new( - start: Isometry, - local_center: Point, - linvel: Vector, - angvel: Vector, - ) -> Self { + pub fn new(start: Isometry, local_center: Point, linvel: Vector, angvel: Vector) -> Self { NonlinearRigidMotion { start, local_center, @@ -56,7 +46,7 @@ impl NonlinearRigidMotion { } /// Create a `NonlinearRigidMotion` that always return `pos`. - pub fn constant_position(pos: Isometry) -> Self { + pub fn constant_position(pos: Isometry) -> Self { Self { start: pos, linvel: na::zero(), @@ -65,7 +55,7 @@ impl NonlinearRigidMotion { } } - fn set_start(&mut self, new_start: Isometry) { + fn set_start(&mut self, new_start: Isometry) { // NOTE: we need to adjust the local_center so that the angular // velocity is still expressed wrt. the original center. self.local_center = new_start.inverse_transform_point(&(self.start * self.local_center)); @@ -86,7 +76,7 @@ impl NonlinearRigidMotion { /// Appends a constant translation to this rigid-motion. #[must_use] - pub fn append_translation(&self, tra: Vector) -> Self { + pub fn append_translation(&self, tra: Vector) -> Self { let mut result = *self; result.set_start(Translation::from(tra) * result.start); result @@ -94,7 +84,7 @@ impl NonlinearRigidMotion { /// Prepends a constant translation to this rigid-motion. #[must_use] - pub fn prepend_translation(&self, tra: Vector) -> Self { + pub fn prepend_translation(&self, tra: Vector) -> Self { let mut result = *self; result.set_start(result.start * Translation::from(tra)); result @@ -102,7 +92,7 @@ impl NonlinearRigidMotion { /// Appends a constant isometry to this rigid-motion. #[must_use] - pub fn append(&self, iso: Isometry) -> Self { + pub fn append(&self, iso: Isometry) -> Self { let mut result = *self; result.set_start(iso * result.start); result @@ -110,14 +100,14 @@ impl NonlinearRigidMotion { /// Prepends a constant translation to this rigid-motion. #[must_use] - pub fn prepend(&self, iso: Isometry) -> Self { + pub fn prepend(&self, iso: Isometry) -> Self { let mut result = *self; result.set_start(result.start * iso); result } /// Computes the position at time `t` of a rigid-body following the motion described by `self`. - pub fn position_at_time(&self, t: Real) -> Isometry { + pub fn position_at_time(&self, t: Real) -> Isometry { let center = self.start * self.local_center; let shift = Translation::from(center.coords); (shift * Isometry::new(self.linvel * t, self.angvel * t)) * (shift.inverse() * self.start) diff --git a/src/query/nonlinear_shape_cast/nonlinear_shape_cast_composite_shape_shape.rs b/src/query/nonlinear_shape_cast/nonlinear_shape_cast_composite_shape_shape.rs index fd2cf9d7..9a7e5a8e 100644 --- a/src/query/nonlinear_shape_cast/nonlinear_shape_cast_composite_shape_shape.rs +++ b/src/query/nonlinear_shape_cast/nonlinear_shape_cast_composite_shape_shape.rs @@ -130,7 +130,7 @@ where let mut mask = [false; SIMD_WIDTH]; let mut results = [None; SIMD_WIDTH]; - // let centers1: [Point; SIMD_WIDTH] = bv.center().into(); + // let centers1: [Point; SIMD_WIDTH] = bv.center().into(); let centers1 = bv.center(); let radius1: [Real; SIMD_WIDTH] = bv.radius().into(); diff --git a/src/query/nonlinear_shape_cast/nonlinear_shape_cast_halfspace_support_map.rs b/src/query/nonlinear_shape_cast/nonlinear_shape_cast_halfspace_support_map.rs index 7d893841..f62cb154 100644 --- a/src/query/nonlinear_shape_cast/nonlinear_shape_cast_halfspace_support_map.rs +++ b/src/query/nonlinear_shape_cast/nonlinear_shape_cast_halfspace_support_map.rs @@ -7,8 +7,8 @@ use crate::shape::SupportMap; /// Time Of Impact of a halfspace with a support-mapped shape under a rigid motion (translation + rotation). pub fn cast_shapes_nonlinear_halfspace_support_map( - pos12: &Isometry, - vel12: &Vector, + pos12: &Isometry, + vel12: &Vector, halfspace: &HalfSpace, other: &G, ) -> Option { @@ -33,8 +33,8 @@ pub fn cast_shapes_nonlinear_halfspace_support_map( /// Time Of Impact of a halfspace with a support-mapped shape under a rigid motion (translation + rotation). pub fn cast_shapes_nonlinear_support_map_halfspace( - pos12: &Isometry, - vel12: &Vector, + pos12: &Isometry, + vel12: &Vector, other: &G, halfspace: &HalfSpace, ) -> Option { diff --git a/src/query/nonlinear_shape_cast/nonlinear_shape_cast_support_map_support_map.rs b/src/query/nonlinear_shape_cast/nonlinear_shape_cast_support_map_support_map.rs index a19a2a20..a002d91b 100644 --- a/src/query/nonlinear_shape_cast/nonlinear_shape_cast_support_map_support_map.rs +++ b/src/query/nonlinear_shape_cast/nonlinear_shape_cast_support_map_support_map.rs @@ -114,10 +114,10 @@ where let mut result = ShapeCastHit { time_of_impact: start_time, - normal1: Vector::::x_axis(), - normal2: Vector::::x_axis(), - witness1: Point::::origin(), - witness2: Point::::origin(), + normal1: Vector::x_axis(), + normal2: Vector::x_axis(), + witness1: Point::origin(), + witness2: Point::origin(), status: ShapeCastStatus::PenetratingOrWithinTargetDist, }; @@ -452,7 +452,7 @@ fn bisect( sm1: &SM1, motion2: &NonlinearRigidMotion, sm2: &SM2, - normal1: &Unit>, + normal1: &Unit, mut range: BisectionRange, ) -> (BisectionRange, usize) where diff --git a/src/query/point/point_aabb.rs b/src/query/point/point_aabb.rs index 52a3ede3..41227935 100644 --- a/src/query/point/point_aabb.rs +++ b/src/query/point/point_aabb.rs @@ -6,11 +6,7 @@ use crate::shape::FeatureId; use na; impl Aabb { - fn do_project_local_point( - &self, - pt: &Point, - solid: bool, - ) -> (bool, Point, Vector) { + fn do_project_local_point(&self, pt: &Point, solid: bool) -> (bool, Point, Vector) { let mins_pt = self.mins - pt; let pt_maxs = pt - self.maxs; let shift = mins_pt.sup(&na::zero()) - pt_maxs.sup(&na::zero()); @@ -44,7 +40,7 @@ impl Aabb { } } - let mut shift: Vector = na::zero(); + let mut shift: Vector = na::zero(); if is_mins { shift[best_id] = best; @@ -59,7 +55,7 @@ impl Aabb { impl PointQuery for Aabb { #[inline] - fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { let (inside, ls_pt, _) = self.do_project_local_point(pt, solid); PointProjection::new(inside, ls_pt) } @@ -67,10 +63,7 @@ impl PointQuery for Aabb { #[allow(unused_assignments)] // For last_zero_shift which is used only in 3D. #[allow(unused_variables)] // For last_zero_shift which is used only in 3D. #[inline] - fn project_local_point_and_get_feature( - &self, - pt: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, pt: &Point) -> (PointProjection, FeatureId) { let (inside, ls_pt, shift) = self.do_project_local_point(pt, false); let proj = PointProjection::new(inside, ls_pt); let mut nzero_shifts = 0; @@ -132,7 +125,7 @@ impl PointQuery for Aabb { } #[inline] - fn distance_to_local_point(&self, pt: &Point, solid: bool) -> Real { + fn distance_to_local_point(&self, pt: &Point, solid: bool) -> Real { let mins_pt = self.mins - pt; let pt_maxs = pt - self.maxs; let shift = mins_pt.sup(&pt_maxs).sup(&na::zero()); diff --git a/src/query/point/point_ball.rs b/src/query/point/point_ball.rs index b3ba0b82..901a1602 100644 --- a/src/query/point/point_ball.rs +++ b/src/query/point/point_ball.rs @@ -6,7 +6,7 @@ use crate::shape::{Ball, FeatureId}; impl PointQuery for Ball { #[inline] - fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { let distance_squared = pt.coords.norm_squared(); let inside = distance_squared <= self.radius * self.radius; @@ -21,15 +21,12 @@ impl PointQuery for Ball { } #[inline] - fn project_local_point_and_get_feature( - &self, - pt: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, pt: &Point) -> (PointProjection, FeatureId) { (self.project_local_point(pt, false), FeatureId::Face(0)) } #[inline] - fn distance_to_local_point(&self, pt: &Point, solid: bool) -> Real { + fn distance_to_local_point(&self, pt: &Point, solid: bool) -> Real { let dist = pt.coords.norm() - self.radius; if solid && dist < 0.0 { @@ -40,7 +37,7 @@ impl PointQuery for Ball { } #[inline] - fn contains_local_point(&self, pt: &Point) -> bool { + fn contains_local_point(&self, pt: &Point) -> bool { pt.coords.norm_squared() <= self.radius * self.radius } } diff --git a/src/query/point/point_bounding_sphere.rs b/src/query/point/point_bounding_sphere.rs index 7dda5a70..b087e3a2 100644 --- a/src/query/point/point_bounding_sphere.rs +++ b/src/query/point/point_bounding_sphere.rs @@ -5,7 +5,7 @@ use crate::shape::{Ball, FeatureId}; impl PointQuery for BoundingSphere { #[inline] - fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { let centered_pt = pt - self.center().coords; let mut proj = Ball::new(self.radius()).project_local_point(¢ered_pt, solid); @@ -14,21 +14,18 @@ impl PointQuery for BoundingSphere { } #[inline] - fn project_local_point_and_get_feature( - &self, - pt: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, pt: &Point) -> (PointProjection, FeatureId) { (self.project_local_point(pt, false), FeatureId::Face(0)) } #[inline] - fn distance_to_local_point(&self, pt: &Point, solid: bool) -> Real { + fn distance_to_local_point(&self, pt: &Point, solid: bool) -> Real { let centered_pt = pt - self.center().coords; Ball::new(self.radius()).distance_to_local_point(¢ered_pt, solid) } #[inline] - fn contains_local_point(&self, pt: &Point) -> bool { + fn contains_local_point(&self, pt: &Point) -> bool { let centered_pt = pt - self.center().coords; Ball::new(self.radius()).contains_local_point(¢ered_pt) } diff --git a/src/query/point/point_capsule.rs b/src/query/point/point_capsule.rs index 94cccefc..278841e7 100644 --- a/src/query/point/point_capsule.rs +++ b/src/query/point/point_capsule.rs @@ -6,7 +6,7 @@ use na::{self, Unit}; impl PointQuery for Capsule { #[inline] - fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { let seg = Segment::new(self.segment.a, self.segment.b); let proj = seg.project_local_point(pt, solid); let dproj = *pt - proj.point; @@ -42,10 +42,7 @@ impl PointQuery for Capsule { } #[inline] - fn project_local_point_and_get_feature( - &self, - pt: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, pt: &Point) -> (PointProjection, FeatureId) { (self.project_local_point(pt, false), FeatureId::Face(0)) } } diff --git a/src/query/point/point_composite_shape.rs b/src/query/point/point_composite_shape.rs index 979f942c..a365c2f5 100644 --- a/src/query/point/point_composite_shape.rs +++ b/src/query/point/point_composite_shape.rs @@ -1,7 +1,7 @@ #![allow(unused_parens)] // Needed by the macro. use crate::bounding_volume::SimdAabb; -use crate::math::{Point, Real, SimdReal, SIMD_WIDTH}; +use crate::math::{Point, PointT, Real, SimdReal, SIMD_WIDTH}; use crate::partitioning::{SimdBestFirstVisitStatus, SimdBestFirstVisitor}; use crate::query::visitors::CompositePointContainmentTest; use crate::query::{PointProjection, PointQuery, PointQueryWithLocation}; @@ -15,15 +15,12 @@ use crate::shape::{Compound, Polyline}; impl PointQuery for Polyline { #[inline] - fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { self.project_local_point_and_get_location(point, solid).0 } #[inline] - fn project_local_point_and_get_feature( - &self, - point: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, point: &Point) -> (PointProjection, FeatureId) { let mut visitor = PointCompositeShapeProjWithFeatureBestFirstVisitor::new(self, point, false); let (proj, (id, feature)) = self.qbvh().traverse_best_first(&mut visitor).unwrap().1; @@ -35,7 +32,7 @@ impl PointQuery for Polyline { // TODO: implement distance_to_point too? #[inline] - fn contains_local_point(&self, point: &Point) -> bool { + fn contains_local_point(&self, point: &Point) -> bool { let mut visitor = CompositePointContainmentTest::new(self, point); let _ = self.qbvh().traverse_depth_first(&mut visitor); visitor.found @@ -44,15 +41,12 @@ impl PointQuery for Polyline { impl PointQuery for TriMesh { #[inline] - fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { self.project_local_point_and_get_location(point, solid).0 } #[inline] - fn project_local_point_and_get_feature( - &self, - point: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, point: &Point) -> (PointProjection, FeatureId) { #[cfg(feature = "dim3")] if self.pseudo_normals().is_some() { // If we can, in 3D, take the pseudo-normals into account. @@ -73,7 +67,7 @@ impl PointQuery for TriMesh { // TODO: implement distance_to_point too? #[inline] - fn contains_local_point(&self, point: &Point) -> bool { + fn contains_local_point(&self, point: &Point) -> bool { #[cfg(feature = "dim3")] if self.pseudo_normals.is_some() { // If we can, in 3D, take the pseudo-normals into account. @@ -91,7 +85,7 @@ impl PointQuery for TriMesh { /// Projects a point on `self` transformed by `m`, unless the projection lies further than the given max distance. fn project_local_point_with_max_dist( &self, - pt: &Point, + pt: &Point, solid: bool, max_dist: Real, ) -> Option { @@ -102,21 +96,18 @@ impl PointQuery for TriMesh { impl PointQuery for Compound { #[inline] - fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { let mut visitor = PointCompositeShapeProjBestFirstVisitor::new(self, point, solid); self.qbvh().traverse_best_first(&mut visitor).unwrap().1 .0 } #[inline] - fn project_local_point_and_get_feature( - &self, - point: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, point: &Point) -> (PointProjection, FeatureId) { (self.project_local_point(point, false), FeatureId::Unknown) } #[inline] - fn contains_local_point(&self, point: &Point) -> bool { + fn contains_local_point(&self, point: &Point) -> bool { let mut visitor = CompositePointContainmentTest::new(self, point); let _ = self.qbvh().traverse_depth_first(&mut visitor); visitor.found @@ -129,7 +120,7 @@ impl PointQueryWithLocation for Polyline { #[inline] fn project_local_point_and_get_location( &self, - point: &Point, + point: &Point, solid: bool, ) -> (PointProjection, Self::Location) { let mut visitor = @@ -145,7 +136,7 @@ impl PointQueryWithLocation for TriMesh { #[allow(unused_mut)] // Because we need mut in 3D but not in 2D. fn project_local_point_and_get_location( &self, - point: &Point, + point: &Point, solid: bool, ) -> (PointProjection, Self::Location) { self.project_local_point_and_get_location_with_max_dist(point, solid, Real::MAX) @@ -155,7 +146,7 @@ impl PointQueryWithLocation for TriMesh { /// Projects a point on `self`, with a maximum projection distance. fn project_local_point_and_get_location_with_max_dist( &self, - point: &Point, + point: &Point, solid: bool, max_dist: Real, ) -> Option<(PointProjection, Self::Location)> { @@ -207,18 +198,18 @@ macro_rules! gen_visitor( /// A visitor for the projection of a point on a composite shape. pub struct $Visitor<'a, S> { shape: &'a S, - point: &'a Point, - simd_point: Point, + point: &'a Point, + simd_point: PointT, solid: bool, } impl<'a, S> $Visitor<'a, S> { /// Initialize a visitor for the projection of a point on a composite shape. - pub fn new(shape: &'a S, point: &'a Point, solid: bool) -> Self { + pub fn new(shape: &'a S, point: &'a Point, solid: bool) -> Self { Self { shape, point, - simd_point: Point::splat(*point), + simd_point: PointT::splat(*point), solid, } } diff --git a/src/query/point/point_cone.rs b/src/query/point/point_cone.rs index 8570daa0..74612d52 100644 --- a/src/query/point/point_cone.rs +++ b/src/query/point/point_cone.rs @@ -1,11 +1,11 @@ -use crate::math::{Point, Real, Vector}; +use crate::math::{Point, Vector}; use crate::query::{PointProjection, PointQuery}; use crate::shape::{Cone, FeatureId, Segment}; use na; impl PointQuery for Cone { #[inline] - fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { // Project on the basis. let mut dir_from_basis_center = pt.coords.xz(); let planar_dist_from_basis_center = dir_from_basis_center.normalize_mut(); @@ -62,10 +62,7 @@ impl PointQuery for Cone { } #[inline] - fn project_local_point_and_get_feature( - &self, - pt: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, pt: &Point) -> (PointProjection, FeatureId) { // TODO: get the actual feature. (self.project_local_point(pt, false), FeatureId::Unknown) } diff --git a/src/query/point/point_cuboid.rs b/src/query/point/point_cuboid.rs index 3625dc90..03c2db69 100644 --- a/src/query/point/point_cuboid.rs +++ b/src/query/point/point_cuboid.rs @@ -5,31 +5,28 @@ use crate::shape::{Cuboid, FeatureId}; impl PointQuery for Cuboid { #[inline] - fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { let dl = Point::from(-self.half_extents); let ur = Point::from(self.half_extents); Aabb::new(dl, ur).project_local_point(pt, solid) } #[inline] - fn project_local_point_and_get_feature( - &self, - pt: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, pt: &Point) -> (PointProjection, FeatureId) { let dl = Point::from(-self.half_extents); let ur = Point::from(self.half_extents); Aabb::new(dl, ur).project_local_point_and_get_feature(pt) } #[inline] - fn distance_to_local_point(&self, pt: &Point, solid: bool) -> Real { + fn distance_to_local_point(&self, pt: &Point, solid: bool) -> Real { let dl = Point::from(-self.half_extents); let ur = Point::from(self.half_extents); Aabb::new(dl, ur).distance_to_local_point(pt, solid) } #[inline] - fn contains_local_point(&self, pt: &Point) -> bool { + fn contains_local_point(&self, pt: &Point) -> bool { let dl = Point::from(-self.half_extents); let ur = Point::from(self.half_extents); Aabb::new(dl, ur).contains_local_point(pt) diff --git a/src/query/point/point_cylinder.rs b/src/query/point/point_cylinder.rs index d0e5b505..d2bfaabe 100644 --- a/src/query/point/point_cylinder.rs +++ b/src/query/point/point_cylinder.rs @@ -1,11 +1,11 @@ -use crate::math::{Point, Real}; +use crate::math::Point; use crate::query::{PointProjection, PointQuery}; use crate::shape::{Cylinder, FeatureId}; use na; impl PointQuery for Cylinder { #[inline] - fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { // Project on the basis. let mut dir_from_basis_center = pt.coords.xz(); let planar_dist_from_basis_center = dir_from_basis_center.normalize_mut(); @@ -71,10 +71,7 @@ impl PointQuery for Cylinder { } #[inline] - fn project_local_point_and_get_feature( - &self, - pt: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, pt: &Point) -> (PointProjection, FeatureId) { // TODO: get the actual feature. (self.project_local_point(pt, false), FeatureId::Unknown) } diff --git a/src/query/point/point_halfspace.rs b/src/query/point/point_halfspace.rs index a34b68b2..c83cc94e 100644 --- a/src/query/point/point_halfspace.rs +++ b/src/query/point/point_halfspace.rs @@ -4,7 +4,7 @@ use crate::shape::{FeatureId, HalfSpace}; impl PointQuery for HalfSpace { #[inline] - fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { let d = self.normal.dot(&pt.coords); let inside = d <= 0.0; @@ -16,15 +16,12 @@ impl PointQuery for HalfSpace { } #[inline] - fn project_local_point_and_get_feature( - &self, - pt: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, pt: &Point) -> (PointProjection, FeatureId) { (self.project_local_point(pt, false), FeatureId::Face(0)) } #[inline] - fn distance_to_local_point(&self, pt: &Point, solid: bool) -> Real { + fn distance_to_local_point(&self, pt: &Point, solid: bool) -> Real { let dist = self.normal.dot(&pt.coords); if dist < 0.0 && solid { @@ -36,7 +33,7 @@ impl PointQuery for HalfSpace { } #[inline] - fn contains_local_point(&self, pt: &Point) -> bool { + fn contains_local_point(&self, pt: &Point) -> bool { self.normal.dot(&pt.coords) <= 0.0 } } diff --git a/src/query/point/point_heightfield.rs b/src/query/point/point_heightfield.rs index ec0abccd..c9dc2215 100644 --- a/src/query/point/point_heightfield.rs +++ b/src/query/point/point_heightfield.rs @@ -8,7 +8,7 @@ use na::ComplexField; // For sqrt. impl PointQuery for HeightField { fn project_local_point_with_max_dist( &self, - pt: &Point, + pt: &Point, solid: bool, max_dist: Real, ) -> Option { @@ -33,7 +33,7 @@ impl PointQuery for HeightField { } #[inline] - fn project_local_point(&self, point: &Point, _: bool) -> PointProjection { + fn project_local_point(&self, point: &Point, _: bool) -> PointProjection { let mut smallest_dist = Real::MAX; let mut best_proj = PointProjection::new(false, *point); @@ -55,10 +55,7 @@ impl PointQuery for HeightField { } #[inline] - fn project_local_point_and_get_feature( - &self, - point: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, point: &Point) -> (PointProjection, FeatureId) { // TODO: compute the feature properly. (self.project_local_point(point, false), FeatureId::Unknown) } @@ -66,7 +63,7 @@ impl PointQuery for HeightField { // TODO: implement distance_to_point too? #[inline] - fn contains_local_point(&self, _point: &Point) -> bool { + fn contains_local_point(&self, _point: &Point) -> bool { false } } @@ -77,7 +74,7 @@ impl PointQueryWithLocation for HeightField { #[inline] fn project_local_point_and_get_location( &self, - _point: &Point, + _point: &Point, _: bool, ) -> (PointProjection, Self::Location) { unimplemented!() diff --git a/src/query/point/point_query.rs b/src/query/point/point_query.rs index 67428170..fe8376e8 100644 --- a/src/query/point/point_query.rs +++ b/src/query/point/point_query.rs @@ -17,17 +17,17 @@ pub struct PointProjection { /// Whether or not the point to project was inside of the shape. pub is_inside: bool, /// The projection result. - pub point: Point, + pub point: Point, } impl PointProjection { /// Initializes a new `PointProjection`. - pub fn new(is_inside: bool, point: Point) -> Self { + pub fn new(is_inside: bool, point: Point) -> Self { PointProjection { is_inside, point } } /// Transforms `self.point` by `pos`. - pub fn transform_by(&self, pos: &Isometry) -> Self { + pub fn transform_by(&self, pos: &Isometry) -> Self { PointProjection { is_inside: self.is_inside, point: pos * self.point, @@ -35,7 +35,7 @@ impl PointProjection { } /// Returns `true` if `Self::is_inside` is `true` or if the distance between the projected point and `point` is smaller than `min_dist`. - pub fn is_inside_eps(&self, original_point: &Point, min_dist: Real) -> bool { + pub fn is_inside_eps(&self, original_point: &Point, min_dist: Real) -> bool { self.is_inside || na::distance_squared(original_point, &self.point) < min_dist * min_dist } } @@ -47,7 +47,7 @@ pub trait PointQuery { /// The point is assumed to be expressed in the local-space of `self`. fn project_local_point_with_max_dist( &self, - pt: &Point, + pt: &Point, solid: bool, max_dist: Real, ) -> Option { @@ -62,8 +62,8 @@ pub trait PointQuery { /// Projects a point on `self` transformed by `m`, unless the projection lies further than the given max distance. fn project_point_with_max_dist( &self, - m: &Isometry, - pt: &Point, + m: &Isometry, + pt: &Point, solid: bool, max_dist: Real, ) -> Option { @@ -74,15 +74,14 @@ pub trait PointQuery { /// Projects a point on `self`. /// /// The point is assumed to be expressed in the local-space of `self`. - fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection; + fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection; /// Projects a point on the boundary of `self` and returns the id of the /// feature the point was projected on. - fn project_local_point_and_get_feature(&self, pt: &Point) - -> (PointProjection, FeatureId); + fn project_local_point_and_get_feature(&self, pt: &Point) -> (PointProjection, FeatureId); /// Computes the minimal distance between a point and `self`. - fn distance_to_local_point(&self, pt: &Point, solid: bool) -> Real { + fn distance_to_local_point(&self, pt: &Point, solid: bool) -> Real { let proj = self.project_local_point(pt, solid); let dist = na::distance(pt, &proj.point); @@ -94,19 +93,19 @@ pub trait PointQuery { } /// Tests if the given point is inside of `self`. - fn contains_local_point(&self, pt: &Point) -> bool { + fn contains_local_point(&self, pt: &Point) -> bool { self.project_local_point(pt, true).is_inside } /// Projects a point on `self` transformed by `m`. - fn project_point(&self, m: &Isometry, pt: &Point, solid: bool) -> PointProjection { + fn project_point(&self, m: &Isometry, pt: &Point, solid: bool) -> PointProjection { self.project_local_point(&m.inverse_transform_point(pt), solid) .transform_by(m) } /// Computes the minimal distance between a point and `self` transformed by `m`. #[inline] - fn distance_to_point(&self, m: &Isometry, pt: &Point, solid: bool) -> Real { + fn distance_to_point(&self, m: &Isometry, pt: &Point, solid: bool) -> Real { self.distance_to_local_point(&m.inverse_transform_point(pt), solid) } @@ -114,8 +113,8 @@ pub trait PointQuery { /// feature the point was projected on. fn project_point_and_get_feature( &self, - m: &Isometry, - pt: &Point, + m: &Isometry, + pt: &Point, ) -> (PointProjection, FeatureId) { let res = self.project_local_point_and_get_feature(&m.inverse_transform_point(pt)); (res.0.transform_by(m), res.1) @@ -123,7 +122,7 @@ pub trait PointQuery { /// Tests if the given point is inside of `self` transformed by `m`. #[inline] - fn contains_point(&self, m: &Isometry, pt: &Point) -> bool { + fn contains_point(&self, m: &Isometry, pt: &Point) -> bool { self.contains_local_point(&m.inverse_transform_point(pt)) } } @@ -154,15 +153,15 @@ pub trait PointQueryWithLocation { /// Projects a point on `self`. fn project_local_point_and_get_location( &self, - pt: &Point, + pt: &Point, solid: bool, ) -> (PointProjection, Self::Location); /// Projects a point on `self` transformed by `m`. fn project_point_and_get_location( &self, - m: &Isometry, - pt: &Point, + m: &Isometry, + pt: &Point, solid: bool, ) -> (PointProjection, Self::Location) { let res = self.project_local_point_and_get_location(&m.inverse_transform_point(pt), solid); @@ -172,7 +171,7 @@ pub trait PointQueryWithLocation { /// Projects a point on `self`, with a maximum projection distance. fn project_local_point_and_get_location_with_max_dist( &self, - pt: &Point, + pt: &Point, solid: bool, max_dist: Real, ) -> Option<(PointProjection, Self::Location)> { @@ -187,8 +186,8 @@ pub trait PointQueryWithLocation { /// Projects a point on `self` transformed by `m`, with a maximum projection distance. fn project_point_and_get_location_with_max_dist( &self, - m: &Isometry, - pt: &Point, + m: &Isometry, + pt: &Point, solid: bool, max_dist: Real, ) -> Option<(PointProjection, Self::Location)> { diff --git a/src/query/point/point_round_shape.rs b/src/query/point/point_round_shape.rs index 64eabfce..f7e404c3 100644 --- a/src/query/point/point_round_shape.rs +++ b/src/query/point/point_round_shape.rs @@ -1,4 +1,4 @@ -use crate::math::{Point, Real}; +use crate::math::Point; use crate::query::gjk::VoronoiSimplex; use crate::query::{PointProjection, PointQuery}; use crate::shape::{FeatureId, RoundShape, SupportMap}; @@ -7,7 +7,7 @@ use crate::shape::{FeatureId, RoundShape, SupportMap}; // call this and adjust the projected point accordingly. impl PointQuery for RoundShape { #[inline] - fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { #[cfg(not(feature = "std"))] // TODO: can’t be used without std because of EPA return unimplemented!( "The projection of points on a round shapes isn’t supported on no-std platforms yet." @@ -23,10 +23,7 @@ impl PointQuery for RoundShape { } #[inline] - fn project_local_point_and_get_feature( - &self, - point: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, point: &Point) -> (PointProjection, FeatureId) { (self.project_local_point(point, false), FeatureId::Unknown) } } diff --git a/src/query/point/point_segment.rs b/src/query/point/point_segment.rs index 03e00052..7aafd47c 100644 --- a/src/query/point/point_segment.rs +++ b/src/query/point/point_segment.rs @@ -1,18 +1,15 @@ -use crate::math::{Point, Real}; +use crate::math::Point; use crate::query::{PointProjection, PointQuery, PointQueryWithLocation}; use crate::shape::{FeatureId, Segment, SegmentPointLocation}; impl PointQuery for Segment { #[inline] - fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { self.project_local_point_and_get_location(pt, solid).0 } #[inline] - fn project_local_point_and_get_feature( - &self, - pt: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, pt: &Point) -> (PointProjection, FeatureId) { let (proj, loc) = self.project_local_point_and_get_location(pt, false); let feature = match loc { SegmentPointLocation::OnVertex(i) => FeatureId::Vertex(i), @@ -48,7 +45,7 @@ impl PointQueryWithLocation for Segment { #[inline] fn project_local_point_and_get_location( &self, - pt: &Point, + pt: &Point, _: bool, ) -> (PointProjection, Self::Location) { let ab = self.b - self.a; diff --git a/src/query/point/point_support_map.rs b/src/query/point/point_support_map.rs index 78e2a181..ae17f060 100644 --- a/src/query/point/point_support_map.rs +++ b/src/query/point/point_support_map.rs @@ -1,6 +1,6 @@ use na::Unit; -use crate::math::{Isometry, Point, Real, Vector}; +use crate::math::{Isometry, Point, Vector}; #[cfg(feature = "std")] use crate::query::epa::EPA; use crate::query::gjk::{self, CSOPoint, ConstantOrigin, VoronoiSimplex}; @@ -17,7 +17,7 @@ use crate::shape::{FeatureId, SupportMap}; pub fn local_point_projection_on_support_map( shape: &G, simplex: &mut VoronoiSimplex, - point: &Point, + point: &Point, solid: bool, ) -> PointProjection where @@ -54,15 +54,12 @@ where #[cfg(feature = "dim3")] impl PointQuery for ConvexPolyhedron { #[inline] - fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { local_point_projection_on_support_map(self, &mut VoronoiSimplex::new(), point, solid) } #[inline] - fn project_local_point_and_get_feature( - &self, - point: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, point: &Point) -> (PointProjection, FeatureId) { let proj = self.project_local_point(point, false); let dpt = *point - proj.point; let local_dir = if proj.is_inside { -dpt } else { dpt }; @@ -79,15 +76,12 @@ impl PointQuery for ConvexPolyhedron { #[cfg(feature = "dim2")] impl PointQuery for ConvexPolygon { #[inline] - fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { local_point_projection_on_support_map(self, &mut VoronoiSimplex::new(), point, solid) } #[inline] - fn project_local_point_and_get_feature( - &self, - point: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, point: &Point) -> (PointProjection, FeatureId) { let proj = self.project_local_point(point, false); let dpt = *point - proj.point; let local_dir = if proj.is_inside { -dpt } else { dpt }; diff --git a/src/query/point/point_tetrahedron.rs b/src/query/point/point_tetrahedron.rs index 2ace3e08..7df1b097 100644 --- a/src/query/point/point_tetrahedron.rs +++ b/src/query/point/point_tetrahedron.rs @@ -4,15 +4,12 @@ use crate::shape::{FeatureId, Tetrahedron, TetrahedronPointLocation}; impl PointQuery for Tetrahedron { #[inline] - fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { self.project_local_point_and_get_location(pt, solid).0 } #[inline] - fn project_local_point_and_get_feature( - &self, - pt: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, pt: &Point) -> (PointProjection, FeatureId) { let (proj, loc) = self.project_local_point_and_get_location(pt, false); let feature = match loc { TetrahedronPointLocation::OnVertex(i) => FeatureId::Vertex(i), @@ -31,7 +28,7 @@ impl PointQueryWithLocation for Tetrahedron { #[inline] fn project_local_point_and_get_location( &self, - pt: &Point, + pt: &Point, solid: bool, ) -> (PointProjection, Self::Location) { let ab = self.b - self.a; @@ -97,12 +94,12 @@ impl PointQueryWithLocation for Tetrahedron { #[inline(always)] fn check_edge( i: usize, - a: &Point, - _: &Point, - nabc: &Vector, - nabd: &Vector, - ap: &Vector, - ab: &Vector, + a: &Point, + _: &Point, + nabc: &Vector, + nabd: &Vector, + ap: &Vector, + ab: &Vector, ap_ab: Real, /*ap_ac: Real, ap_ad: Real,*/ bp_ab: Real, /*bp_ac: Real, bp_ad: Real*/ ) -> ( @@ -238,15 +235,15 @@ impl PointQueryWithLocation for Tetrahedron { #[inline(always)] fn check_face( i: usize, - a: &Point, - b: &Point, - c: &Point, - ap: &Vector, - bp: &Vector, - cp: &Vector, - ab: &Vector, - ac: &Vector, - ad: &Vector, + a: &Point, + b: &Point, + c: &Point, + ap: &Vector, + bp: &Vector, + cp: &Vector, + ab: &Vector, + ac: &Vector, + ad: &Vector, dabc: Real, dbca: Real, dacb: Real, diff --git a/src/query/point/point_triangle.rs b/src/query/point/point_triangle.rs index 576a13db..dfda0aa7 100644 --- a/src/query/point/point_triangle.rs +++ b/src/query/point/point_triangle.rs @@ -3,7 +3,7 @@ use crate::query::{PointProjection, PointQuery, PointQueryWithLocation}; use crate::shape::{FeatureId, Triangle, TrianglePointLocation}; #[inline] -fn compute_result(pt: &Point, proj: Point) -> PointProjection { +fn compute_result(pt: &Point, proj: Point) -> PointProjection { #[cfg(feature = "dim2")] { PointProjection::new(*pt == proj, proj) @@ -19,15 +19,12 @@ fn compute_result(pt: &Point, proj: Point) -> PointProjection { impl PointQuery for Triangle { #[inline] - fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { + fn project_local_point(&self, pt: &Point, solid: bool) -> PointProjection { self.project_local_point_and_get_location(pt, solid).0 } #[inline] - fn project_local_point_and_get_feature( - &self, - pt: &Point, - ) -> (PointProjection, FeatureId) { + fn project_local_point_and_get_feature(&self, pt: &Point) -> (PointProjection, FeatureId) { let (proj, loc) = if DIM == 2 { self.project_local_point_and_get_location(pt, false) } else { @@ -57,7 +54,7 @@ impl PointQueryWithLocation for Triangle { #[inline] fn project_local_point_and_get_location( &self, - pt: &Point, + pt: &Point, solid: bool, ) -> (PointProjection, Self::Location) { // To understand the ideas, consider reading the slides below @@ -109,12 +106,12 @@ impl PointQueryWithLocation for Triangle { // For 2D and 3D, it uses explicit cross/perp products that are // more numerically stable. fn stable_check_edges_voronoi( - ab: &Vector, - ac: &Vector, - bc: &Vector, - ap: &Vector, - bp: &Vector, - cp: &Vector, + ab: &Vector, + ac: &Vector, + bc: &Vector, + ap: &Vector, + bp: &Vector, + cp: &Vector, ab_ap: Real, ab_bp: Real, ac_ap: Real, diff --git a/src/query/query_dispatcher.rs b/src/query/query_dispatcher.rs index 6bd55496..384a58f9 100644 --- a/src/query/query_dispatcher.rs +++ b/src/query/query_dispatcher.rs @@ -20,7 +20,7 @@ pub trait PersistentQueryDispatcher: QueryD /// spatial and temporal coherence. fn contact_manifolds( &self, - pos12: &Isometry, + pos12: &Isometry, g1: &dyn Shape, g2: &dyn Shape, prediction: Real, @@ -31,7 +31,7 @@ pub trait PersistentQueryDispatcher: QueryD /// Computes the contact-manifold between two convex shapes. fn contact_manifold_convex_convex( &self, - pos12: &Isometry, + pos12: &Isometry, g1: &dyn Shape, g2: &dyn Shape, normal_constraints1: Option<&dyn NormalConstraints>, @@ -52,7 +52,7 @@ pub trait QueryDispatcher: Send + Sync { /// Tests whether two shapes are intersecting. fn intersection_test( &self, - pos12: &Isometry, + pos12: &Isometry, g1: &dyn Shape, g2: &dyn Shape, ) -> Result; @@ -62,7 +62,7 @@ pub trait QueryDispatcher: Send + Sync { /// Returns `0.0` if the objects are touching or penetrating. fn distance( &self, - pos12: &Isometry, + pos12: &Isometry, g1: &dyn Shape, g2: &dyn Shape, ) -> Result; @@ -72,7 +72,7 @@ pub trait QueryDispatcher: Send + Sync { /// Returns `None` if the objects are separated by a distance greater than `prediction`. fn contact( &self, - pos12: &Isometry, + pos12: &Isometry, g1: &dyn Shape, g2: &dyn Shape, prediction: Real, @@ -83,7 +83,7 @@ pub trait QueryDispatcher: Send + Sync { /// Returns `ClosestPoints::Disjoint` if the objects are separated by a distance greater than `max_dist`. fn closest_points( &self, - pos12: &Isometry, + pos12: &Isometry, g1: &dyn Shape, g2: &dyn Shape, max_dist: Real, @@ -105,8 +105,8 @@ pub trait QueryDispatcher: Send + Sync { /// detected is theater than this value. fn cast_shapes( &self, - pos12: &Isometry, - local_vel12: &Vector, + pos12: &Isometry, + local_vel12: &Vector, g1: &dyn Shape, g2: &dyn Shape, options: ShapeCastOptions, @@ -167,30 +167,30 @@ where U: QueryDispatcher, { chain_method!(intersection_test( - pos12: &Isometry, + pos12: &Isometry, g1: &dyn Shape, g2: &dyn Shape, ) -> bool); - chain_method!(distance(pos12: &Isometry, g1: &dyn Shape, g2: &dyn Shape,) -> Real); + chain_method!(distance(pos12: &Isometry, g1: &dyn Shape, g2: &dyn Shape,) -> Real); chain_method!(contact( - pos12: &Isometry, + pos12: &Isometry, g1: &dyn Shape, g2: &dyn Shape, prediction: Real, ) -> Option); chain_method!(closest_points( - pos12: &Isometry, + pos12: &Isometry, g1: &dyn Shape, g2: &dyn Shape, max_dist: Real, ) -> ClosestPoints); chain_method!(cast_shapes( - pos12: &Isometry, - vel12: &Vector, + pos12: &Isometry, + vel12: &Vector, g1: &dyn Shape, g2: &dyn Shape, options: ShapeCastOptions, @@ -215,7 +215,7 @@ where U: PersistentQueryDispatcher, { chain_method!(contact_manifolds( - pos12: &Isometry, + pos12: &Isometry, g1: &dyn Shape, g2: &dyn Shape, prediction: Real, @@ -224,7 +224,7 @@ where ) -> ()); chain_method!(contact_manifold_convex_convex( - pos12: &Isometry, + pos12: &Isometry, g1: &dyn Shape, g2: &dyn Shape, normal_constraints1: Option<&dyn NormalConstraints>, diff --git a/src/query/ray/ray.rs b/src/query/ray/ray.rs index d20bd478..99f4f1f9 100644 --- a/src/query/ray/ray.rs +++ b/src/query/ray/ray.rs @@ -17,26 +17,26 @@ use rkyv::{bytecheck, CheckBytes}; #[repr(C)] pub struct Ray { /// Starting point of the ray. - pub origin: Point, + pub origin: Point, /// Direction of the ray. - pub dir: Vector, + pub dir: Vector, } impl Ray { /// Creates a new ray starting from `origin` and with the direction `dir`. - pub fn new(origin: Point, dir: Vector) -> Ray { + pub fn new(origin: Point, dir: Vector) -> Ray { Ray { origin, dir } } /// Transforms this ray by the given isometry. #[inline] - pub fn transform_by(&self, m: &Isometry) -> Self { + pub fn transform_by(&self, m: &Isometry) -> Self { Self::new(m * self.origin, m * self.dir) } /// Transforms this ray by the inverse of the given isometry. #[inline] - pub fn inverse_transform_by(&self, m: &Isometry) -> Self { + pub fn inverse_transform_by(&self, m: &Isometry) -> Self { Self::new( m.inverse_transform_point(&self.origin), m.inverse_transform_vector(&self.dir), @@ -45,7 +45,7 @@ impl Ray { /// Translates this ray by the given vector. Its direction is left unchanged. #[inline] - pub fn translate_by(&self, v: Vector) -> Self { + pub fn translate_by(&self, v: Vector) -> Self { Self::new(self.origin + v, self.dir) } @@ -53,7 +53,7 @@ impl Ray { /// /// This computes `self.origin + self.dir * t`. #[inline] - pub fn point_at(&self, t: Real) -> Point { + pub fn point_at(&self, t: Real) -> Point { self.origin + self.dir * t } } @@ -80,7 +80,7 @@ pub struct RayIntersection { /// /// If the `time_of_impact` is exactly zero, the normal might not be reliable. // TODO: use a Unit instead. - pub normal: Vector, + pub normal: Vector, /// Feature at the intersection point. pub feature: FeatureId, @@ -90,7 +90,7 @@ impl RayIntersection { #[inline] /// Creates a new `RayIntersection`. #[cfg(feature = "dim3")] - pub fn new(time_of_impact: Real, normal: Vector, feature: FeatureId) -> RayIntersection { + pub fn new(time_of_impact: Real, normal: Vector, feature: FeatureId) -> RayIntersection { RayIntersection { time_of_impact, normal, @@ -101,7 +101,7 @@ impl RayIntersection { #[inline] /// Creates a new `RayIntersection`. #[cfg(feature = "dim2")] - pub fn new(time_of_impact: Real, normal: Vector, feature: FeatureId) -> RayIntersection { + pub fn new(time_of_impact: Real, normal: Vector, feature: FeatureId) -> RayIntersection { RayIntersection { time_of_impact, normal, @@ -110,7 +110,7 @@ impl RayIntersection { } #[inline] - pub fn transform_by(&self, transform: &Isometry) -> Self { + pub fn transform_by(&self, transform: &Isometry) -> Self { RayIntersection { time_of_impact: self.time_of_impact, normal: transform * self.normal, @@ -144,7 +144,7 @@ pub trait RayCast { /// Computes the time of impact between this transform shape and a ray. fn cast_ray( &self, - m: &Isometry, + m: &Isometry, ray: &Ray, max_time_of_impact: Real, solid: bool, @@ -156,7 +156,7 @@ pub trait RayCast { /// Computes the time of impact, and normal between this transformed shape and a ray. fn cast_ray_and_get_normal( &self, - m: &Isometry, + m: &Isometry, ray: &Ray, max_time_of_impact: Real, solid: bool, @@ -168,7 +168,7 @@ pub trait RayCast { /// Tests whether a ray intersects this transformed shape. #[inline] - fn intersects_ray(&self, m: &Isometry, ray: &Ray, max_time_of_impact: Real) -> bool { + fn intersects_ray(&self, m: &Isometry, ray: &Ray, max_time_of_impact: Real) -> bool { let ls_ray = ray.inverse_transform_by(m); self.intersects_local_ray(&ls_ray, max_time_of_impact) } diff --git a/src/query/ray/ray_aabb.rs b/src/query/ray/ray_aabb.rs index 3cb4be40..6766180d 100644 --- a/src/query/ray/ray_aabb.rs +++ b/src/query/ray/ray_aabb.rs @@ -72,7 +72,7 @@ fn ray_aabb( ray: &Ray, max_time_of_impact: Real, solid: bool, -) -> Option<(Real, Vector, isize)> { +) -> Option<(Real, Vector, isize)> { use crate::query::clip; clip::clip_aabb_line(aabb, &ray.origin, &ray.dir).and_then(|(near, far)| { if near.0 < 0.0 { diff --git a/src/query/ray/ray_ball.rs b/src/query/ray/ray_ball.rs index 1f8d0d0e..af4053fa 100644 --- a/src/query/ray/ray_ball.rs +++ b/src/query/ray/ray_ball.rs @@ -31,7 +31,7 @@ impl RayCast for Ball { /// The first result element is `true` if the ray started inside of the ball. #[inline] pub fn ray_toi_with_ball( - center: &Point, + center: &Point, radius: Real, ray: &Ray, solid: bool, @@ -79,7 +79,7 @@ pub fn ray_toi_with_ball( /// Computes the time of impact and contact normal of a ray on a ball. #[inline] pub fn ray_toi_and_normal_with_ball( - center: &Point, + center: &Point, radius: Real, ray: &Ray, solid: bool, diff --git a/src/query/ray/ray_halfspace.rs b/src/query/ray/ray_halfspace.rs index 5ec27df4..438ebfc2 100644 --- a/src/query/ray/ray_halfspace.rs +++ b/src/query/ray/ray_halfspace.rs @@ -7,10 +7,10 @@ use crate::shape::{FeatureId, HalfSpace}; /// Computes the time_of_impact of an unbounded line with a halfspace described by its center and normal. #[inline] pub fn line_toi_with_halfspace( - halfspace_center: &Point, - halfspace_normal: &Vector, - line_origin: &Point, - line_dir: &Vector, + halfspace_center: &Point, + halfspace_normal: &Vector, + line_origin: &Point, + line_dir: &Vector, ) -> Option { let dpos = *halfspace_center - *line_origin; let denom = halfspace_normal.dot(line_dir); @@ -24,11 +24,7 @@ pub fn line_toi_with_halfspace( /// Computes the time_of_impact of a ray with a halfspace described by its center and normal. #[inline] -pub fn ray_toi_with_halfspace( - center: &Point, - normal: &Vector, - ray: &Ray, -) -> Option { +pub fn ray_toi_with_halfspace(center: &Point, normal: &Vector, ray: &Ray) -> Option { if let Some(t) = line_toi_with_halfspace(center, normal, &ray.origin, &ray.dir) { if t >= 0.0 { return Some(t); diff --git a/src/query/ray/ray_triangle.rs b/src/query/ray/ray_triangle.rs index 602bab05..7b8203c5 100644 --- a/src/query/ray/ray_triangle.rs +++ b/src/query/ray/ray_triangle.rs @@ -71,9 +71,9 @@ impl RayCast for Triangle { /// the intersection point are returned. #[cfg(feature = "dim3")] pub fn local_ray_intersection_with_triangle( - a: &Point, - b: &Point, - c: &Point, + a: &Point, + b: &Point, + c: &Point, ray: &Ray, ) -> Option<(RayIntersection, Vector3)> { let ab = *b - *a; diff --git a/src/query/ray/simd_ray.rs b/src/query/ray/simd_ray.rs index 4557bea4..1080f42b 100644 --- a/src/query/ray/simd_ray.rs +++ b/src/query/ray/simd_ray.rs @@ -1,4 +1,4 @@ -use crate::math::{Point, SimdReal, Vector}; +use crate::math::{PointT, SimdReal, VectorT}; use crate::query::Ray; use simba::simd::SimdValue; @@ -6,17 +6,17 @@ use simba::simd::SimdValue; #[derive(Debug, Copy, Clone)] pub struct SimdRay { /// The origin of the rays represented as a single SIMD point. - pub origin: Point, + pub origin: PointT, /// The direction of the rays represented as a single SIMD vector. - pub dir: Vector, + pub dir: VectorT, } impl SimdRay { /// Creates a new SIMD ray with all its lanes filled with the same ray. pub fn splat(ray: Ray) -> Self { Self { - origin: Point::splat(ray.origin), - dir: Vector::splat(ray.dir), + origin: PointT::splat(ray.origin), + dir: VectorT::splat(ray.dir), } } } diff --git a/src/query/sat/sat_cuboid_cuboid.rs b/src/query/sat/sat_cuboid_cuboid.rs index 3015e3bc..32672593 100644 --- a/src/query/sat/sat_cuboid_cuboid.rs +++ b/src/query/sat/sat_cuboid_cuboid.rs @@ -8,9 +8,9 @@ use na::RealField; // For .copysign() pub fn cuboid_cuboid_compute_separation_wrt_local_line( cuboid1: &Cuboid, cuboid2: &Cuboid, - pos12: &Isometry, - axis1: &Vector, -) -> (Real, Vector) { + pos12: &Isometry, + axis1: &Vector, +) -> (Real, Vector) { #[expect(clippy::unnecessary_cast)] let signum = (1.0 as Real).copysign(pos12.translation.vector.dot(axis1)); let axis1 = axis1 * signum; @@ -30,8 +30,8 @@ pub fn cuboid_cuboid_compute_separation_wrt_local_line( pub fn cuboid_cuboid_find_local_separating_edge_twoway( cuboid1: &Cuboid, cuboid2: &Cuboid, - pos12: &Isometry, -) -> (Real, Vector) { + pos12: &Isometry, +) -> (Real, Vector) { use approx::AbsDiffEq; let mut best_separation = -Real::MAX; let mut best_dir = Vector::zeros(); @@ -82,8 +82,8 @@ pub fn cuboid_cuboid_find_local_separating_edge_twoway( pub fn cuboid_cuboid_find_local_separating_normal_oneway( cuboid1: &Cuboid, cuboid2: &Cuboid, - pos12: &Isometry, -) -> (Real, Vector) { + pos12: &Isometry, +) -> (Real, Vector) { let mut best_separation = -Real::MAX; let mut best_dir = Vector::zeros(); diff --git a/src/query/sat/sat_cuboid_point.rs b/src/query/sat/sat_cuboid_point.rs index d49abb64..664dccca 100644 --- a/src/query/sat/sat_cuboid_point.rs +++ b/src/query/sat/sat_cuboid_point.rs @@ -7,11 +7,11 @@ use na::Unit; // (therefore we can check only one normal direction). /// Computes the separation between a point and a cuboid, along the given direction `normal1`. pub fn point_cuboid_find_local_separating_normal_oneway( - point1: Point, - normal1: Option>>, + point1: Point, + normal1: Option>, shape2: &Cuboid, - pos12: &Isometry, -) -> (Real, Vector) { + pos12: &Isometry, +) -> (Real, Vector) { let mut best_separation = -Real::MAX; let mut best_dir = Vector::zeros(); diff --git a/src/query/sat/sat_cuboid_segment.rs b/src/query/sat/sat_cuboid_segment.rs index 1f0e08e7..cd82b540 100644 --- a/src/query/sat/sat_cuboid_segment.rs +++ b/src/query/sat/sat_cuboid_segment.rs @@ -10,8 +10,8 @@ use crate::shape::{Cuboid, Segment}; pub fn cuboid_segment_find_local_separating_edge_twoway( cube1: &Cuboid, segment2: &Segment, - pos12: &Isometry, -) -> (Real, Vector) { + pos12: &Isometry, +) -> (Real, Vector) { let x2 = pos12 * (segment2.b - segment2.a); let axes = [ @@ -31,8 +31,8 @@ pub fn cuboid_segment_find_local_separating_edge_twoway( pub fn segment_cuboid_find_local_separating_normal_oneway( segment1: &Segment, shape2: &Cuboid, - pos12: &Isometry, -) -> (Real, Vector) { + pos12: &Isometry, +) -> (Real, Vector) { sat::point_cuboid_find_local_separating_normal_oneway( segment1.a, segment1.normal(), diff --git a/src/query/sat/sat_cuboid_support_map.rs b/src/query/sat/sat_cuboid_support_map.rs index 9f21fa90..57d50aab 100644 --- a/src/query/sat/sat_cuboid_support_map.rs +++ b/src/query/sat/sat_cuboid_support_map.rs @@ -10,9 +10,9 @@ use na::Unit; pub fn cuboid_support_map_compute_separation_wrt_local_line( cube1: &Cuboid, shape2: &impl SupportMap, - pos12: &Isometry, - axis1: &Unit>, -) -> (Real, Unit>) { + pos12: &Isometry, + axis1: &Unit, +) -> (Real, Unit) { let axis1_2 = pos12.inverse_transform_unit_vector(axis1); let separation1 = { let axis2 = -axis1_2; @@ -44,9 +44,9 @@ pub fn cuboid_support_map_compute_separation_wrt_local_line( pub fn cuboid_support_map_find_local_separating_edge_twoway( cube1: &Cuboid, shape2: &impl SupportMap, - axes: &[Vector], - pos12: &Isometry, -) -> (Real, Vector) { + axes: &[Vector], + pos12: &Isometry, +) -> (Real, Vector) { use approx::AbsDiffEq; let mut best_separation = -Real::MAX; let mut best_dir = Vector::zeros(); @@ -72,8 +72,8 @@ pub fn cuboid_support_map_find_local_separating_edge_twoway( pub fn cuboid_support_map_find_local_separating_normal_oneway( cube1: &Cuboid, shape2: &S, - pos12: &Isometry, -) -> (Real, Vector) { + pos12: &Isometry, +) -> (Real, Vector) { let mut best_separation = -Real::MAX; let mut best_dir = Vector::zeros(); diff --git a/src/query/sat/sat_cuboid_triangle.rs b/src/query/sat/sat_cuboid_triangle.rs index e324d6da..0def70bd 100644 --- a/src/query/sat/sat_cuboid_triangle.rs +++ b/src/query/sat/sat_cuboid_triangle.rs @@ -16,8 +16,8 @@ use crate::shape::{Cuboid, SupportMap, Triangle}; pub fn cuboid_triangle_find_local_separating_edge_twoway( cube1: &Cuboid, triangle2: &Triangle, - pos12: &Isometry, -) -> (Real, Vector) { + pos12: &Isometry, +) -> (Real, Vector) { // NOTE: everything in this method will be expressed // in the local-space of the first triangle. So we // don't bother adding 2_1 suffixes (e.g. `a2_1`) to everything in @@ -99,8 +99,8 @@ pub fn cuboid_triangle_find_local_separating_edge_twoway( pub fn triangle_support_map_find_local_separating_normal_oneway( triangle1: &Triangle, shape2: &impl SupportMap, - pos12: &Isometry, -) -> (Real, Vector) { + pos12: &Isometry, +) -> (Real, Vector) { let mut best_sep = -Real::MAX; let mut best_normal = Vector::zeros(); @@ -125,8 +125,8 @@ pub fn triangle_support_map_find_local_separating_normal_oneway( pub fn triangle_cuboid_find_local_separating_normal_oneway( triangle1: &Triangle, shape2: &Cuboid, - pos12: &Isometry, -) -> (Real, Vector) { + pos12: &Isometry, +) -> (Real, Vector) { triangle_support_map_find_local_separating_normal_oneway(triangle1, shape2, pos12) } @@ -138,8 +138,8 @@ pub fn triangle_cuboid_find_local_separating_normal_oneway( pub fn triangle_cuboid_find_local_separating_normal_oneway( triangle1: &Triangle, shape2: &Cuboid, - pos12: &Isometry, -) -> (Real, Vector) { + pos12: &Isometry, +) -> (Real, Vector) { sat::point_cuboid_find_local_separating_normal_oneway( triangle1.a, triangle1.normal(), diff --git a/src/query/sat/sat_support_map_support_map.rs b/src/query/sat/sat_support_map_support_map.rs index 4f671dbf..b5a0f6ea 100644 --- a/src/query/sat/sat_support_map_support_map.rs +++ b/src/query/sat/sat_support_map_support_map.rs @@ -8,8 +8,8 @@ use na::Unit; pub fn support_map_support_map_compute_separation( sm1: &impl SupportMap, sm2: &impl SupportMap, - pos12: &Isometry, - dir1: &Unit>, + pos12: &Isometry, + dir1: &Unit, ) -> Real { let p1 = sm1.local_support_point_toward(dir1); let p2 = sm2.support_point_toward(pos12, &-*dir1); diff --git a/src/query/sat/sat_triangle_segment.rs b/src/query/sat/sat_triangle_segment.rs index ed0e7818..ad0dcbf3 100644 --- a/src/query/sat/sat_triangle_segment.rs +++ b/src/query/sat/sat_triangle_segment.rs @@ -9,8 +9,8 @@ use na::Unit; pub fn triangle_segment_find_local_separating_normal_oneway( triangle1: &Triangle, segment2: &Segment, - pos12: &Isometry, -) -> (Real, Vector) { + pos12: &Isometry, +) -> (Real, Vector) { if let Some(dir) = triangle1.normal() { let p2a = segment2.support_point_toward(pos12, &-dir); let p2b = segment2.support_point_toward(pos12, &dir); @@ -34,8 +34,8 @@ pub fn triangle_segment_find_local_separating_normal_oneway( pub fn segment_triangle_find_local_separating_edge_twoway( segment1: &Segment, triangle2: &Triangle, - pos12: &Isometry, -) -> (Real, Vector) { + pos12: &Isometry, +) -> (Real, Vector) { let x2 = pos12 * (triangle2.b - triangle2.a); let y2 = pos12 * (triangle2.c - triangle2.b); let z2 = pos12 * (triangle2.a - triangle2.c); diff --git a/src/query/shape_cast/shape_cast.rs b/src/query/shape_cast/shape_cast.rs index eb9eaaf9..00b0b3e7 100644 --- a/src/query/shape_cast/shape_cast.rs +++ b/src/query/shape_cast/shape_cast.rs @@ -37,25 +37,25 @@ pub struct ShapeCastHit { /// /// This value is unreliable if `status` is [`ShapeCastStatus::PenetratingOrWithinTargetDist`] /// and [`ShapeCastOptions::compute_impact_geometry_on_penetration`] was set to `false`. - pub witness1: Point, + pub witness1: Point, /// The local-space closest point on the second shape at the time of impact. /// /// This value is unreliable if `status` is [`ShapeCastStatus::PenetratingOrWithinTargetDist`] /// and both [`ShapeCastOptions::compute_impact_geometry_on_penetration`] was set to `false` /// when calling the time-of-impact function. - pub witness2: Point, + pub witness2: Point, /// The local-space outward normal on the first shape at the time of impact. /// /// This value is unreliable if `status` is [`ShapeCastStatus::PenetratingOrWithinTargetDist`] /// and both [`ShapeCastOptions::compute_impact_geometry_on_penetration`] was set to `false` /// when calling the time-of-impact function. - pub normal1: Unit>, + pub normal1: Unit, /// The local-space outward normal on the second shape at the time of impact. /// /// This value is unreliable if `status` is [`ShapeCastStatus::PenetratingOrWithinTargetDist`] /// and both [`ShapeCastOptions::compute_impact_geometry_on_penetration`] was set to `false` /// when calling the time-of-impact function. - pub normal2: Unit>, + pub normal2: Unit, /// The way the shape-casting algorithm terminated. pub status: ShapeCastStatus, } @@ -77,7 +77,7 @@ impl ShapeCastHit { } /// Transform `self.witness1` and `self.normal1` by `pos`. - pub fn transform1_by(&self, pos: &Isometry) -> Self { + pub fn transform1_by(&self, pos: &Isometry) -> Self { Self { time_of_impact: self.time_of_impact, witness1: pos * self.witness1, @@ -139,11 +139,11 @@ impl Default for ShapeCastOptions { /// Returns `0.0` if the objects are touching or closer than `options.target_distance`, /// or penetrating. pub fn cast_shapes( - pos1: &Isometry, - vel1: &Vector, + pos1: &Isometry, + vel1: &Vector, g1: &dyn Shape, - pos2: &Isometry, - vel2: &Vector, + pos2: &Isometry, + vel2: &Vector, g2: &dyn Shape, options: ShapeCastOptions, ) -> Result, Unsupported> { diff --git a/src/query/shape_cast/shape_cast_ball_ball.rs b/src/query/shape_cast/shape_cast_ball_ball.rs index 29d5204f..7be69f5f 100644 --- a/src/query/shape_cast/shape_cast_ball_ball.rs +++ b/src/query/shape_cast/shape_cast_ball_ball.rs @@ -1,6 +1,6 @@ use na::Unit; -use crate::math::{Isometry, Point, Real, Vector}; +use crate::math::{Isometry, Point, Vector}; use crate::query::details::ShapeCastOptions; use crate::query::{self, Ray, ShapeCastHit, ShapeCastStatus}; use crate::shape::Ball; @@ -9,8 +9,8 @@ use num::Zero; /// Time Of Impact of two balls under translational movement. #[inline] pub fn cast_shapes_ball_ball( - pos12: &Isometry, - vel12: &Vector, + pos12: &Isometry, + vel12: &Vector, b1: &Ball, b2: &Ball, options: ShapeCastOptions, diff --git a/src/query/shape_cast/shape_cast_composite_shape_shape.rs b/src/query/shape_cast/shape_cast_composite_shape_shape.rs index 3464213d..f7acb7db 100644 --- a/src/query/shape_cast/shape_cast_composite_shape_shape.rs +++ b/src/query/shape_cast/shape_cast_composite_shape_shape.rs @@ -1,5 +1,5 @@ use crate::bounding_volume::SimdAabb; -use crate::math::{Isometry, Point, Real, SimdBool, SimdReal, Vector, SIMD_WIDTH}; +use crate::math::{Isometry, Point, Real, SimdBool, SimdReal, Vector, VectorT, SIMD_WIDTH}; use crate::partitioning::{SimdBestFirstVisitStatus, SimdBestFirstVisitor}; use crate::query::shape_cast::ShapeCastOptions; use crate::query::{QueryDispatcher, Ray, ShapeCastHit, SimdRay}; @@ -9,8 +9,8 @@ use simba::simd::{SimdBool as _, SimdPartialOrd, SimdValue}; /// Time Of Impact of a composite shape with any other shape, under translational movement. pub fn cast_shapes_composite_shape_shape( dispatcher: &D, - pos12: &Isometry, - vel12: &Vector, + pos12: &Isometry, + vel12: &Vector, g1: &G1, g2: &dyn Shape, options: ShapeCastOptions, @@ -29,8 +29,8 @@ where /// Time Of Impact of any shape with a composite shape, under translational movement. pub fn cast_shapes_shape_composite_shape( dispatcher: &D, - pos12: &Isometry, - vel12: &Vector, + pos12: &Isometry, + vel12: &Vector, g1: &dyn Shape, g2: &G2, options: ShapeCastOptions, @@ -52,13 +52,13 @@ where /// A visitor used to find the time-of-impact between a composite shape and a shape. pub struct TOICompositeShapeShapeBestFirstVisitor<'a, D: ?Sized, G1: ?Sized + 'a> { - msum_shift: Vector, - msum_margin: Vector, + msum_shift: VectorT, + msum_margin: VectorT, ray: SimdRay, dispatcher: &'a D, - pos12: &'a Isometry, - vel12: &'a Vector, + pos12: &'a Isometry, + vel12: &'a Vector, g1: &'a G1, g2: &'a dyn Shape, options: ShapeCastOptions, @@ -72,8 +72,8 @@ where /// Creates a new visitor used to find the time-of-impact between a composite shape and a shape. pub fn new( dispatcher: &'a D, - pos12: &'a Isometry, - vel12: &'a Vector, + pos12: &'a Isometry, + vel12: &'a Vector, g1: &'a G1, g2: &'a dyn Shape, options: ShapeCastOptions, @@ -83,8 +83,8 @@ where TOICompositeShapeShapeBestFirstVisitor { dispatcher, - msum_shift: Vector::splat(-ls_aabb2.center().coords), - msum_margin: Vector::splat( + msum_shift: VectorT::splat(-ls_aabb2.center().coords), + msum_margin: VectorT::splat( ls_aabb2.half_extents() + Vector::repeat(options.target_distance), ), ray: SimdRay::splat(ray), diff --git a/src/query/shape_cast/shape_cast_halfspace_support_map.rs b/src/query/shape_cast/shape_cast_halfspace_support_map.rs index bbc4b0ce..ad1243b3 100644 --- a/src/query/shape_cast/shape_cast_halfspace_support_map.rs +++ b/src/query/shape_cast/shape_cast_halfspace_support_map.rs @@ -1,12 +1,12 @@ -use crate::math::{Isometry, Real, Vector}; +use crate::math::{Isometry, Vector}; use crate::query::details::ShapeCastOptions; use crate::query::{Ray, RayCast, ShapeCastHit, ShapeCastStatus}; use crate::shape::{HalfSpace, RoundShapeRef, SupportMap}; /// Time Of Impact of a halfspace with a support-mapped shape under translational movement. pub fn cast_shapes_halfspace_support_map( - pos12: &Isometry, - vel12: &Vector, + pos12: &Isometry, + vel12: &Vector, halfspace: &HalfSpace, other: &G, options: ShapeCastOptions, @@ -61,8 +61,8 @@ pub fn cast_shapes_halfspace_support_map( /// Time Of Impact of a halfspace with a support-mapped shape under translational movement. pub fn cast_shapes_support_map_halfspace( - pos12: &Isometry, - vel12: &Vector, + pos12: &Isometry, + vel12: &Vector, other: &G, halfspace: &HalfSpace, options: ShapeCastOptions, diff --git a/src/query/shape_cast/shape_cast_heightfield_shape.rs b/src/query/shape_cast/shape_cast_heightfield_shape.rs index 0f329f4e..cd79b079 100644 --- a/src/query/shape_cast/shape_cast_heightfield_shape.rs +++ b/src/query/shape_cast/shape_cast_heightfield_shape.rs @@ -10,8 +10,8 @@ use crate::{bounding_volume::Aabb, query::RayCast}; #[cfg(feature = "dim2")] pub fn cast_shapes_heightfield_shape( dispatcher: &D, - pos12: &Isometry, - vel12: &Vector, + pos12: &Isometry, + vel12: &Vector, heightfield1: &HeightField, g2: &dyn Shape, options: ShapeCastOptions, @@ -99,8 +99,8 @@ pub fn cast_shapes_heightfield_shape( #[cfg(feature = "dim3")] pub fn cast_shapes_heightfield_shape( dispatcher: &D, - pos12: &Isometry, - vel12: &Vector, + pos12: &Isometry, + vel12: &Vector, heightfield1: &HeightField, g2: &dyn Shape, options: ShapeCastOptions, @@ -263,8 +263,8 @@ pub fn cast_shapes_heightfield_shape( /// Time Of Impact between a moving shape and a heightfield. pub fn cast_shapes_shape_heightfield( dispatcher: &D, - pos12: &Isometry, - vel12: &Vector, + pos12: &Isometry, + vel12: &Vector, g1: &dyn Shape, heightfield2: &HeightField, options: ShapeCastOptions, diff --git a/src/query/shape_cast/shape_cast_support_map_support_map.rs b/src/query/shape_cast/shape_cast_support_map_support_map.rs index 7df76da1..59fa419a 100644 --- a/src/query/shape_cast/shape_cast_support_map_support_map.rs +++ b/src/query/shape_cast/shape_cast_support_map_support_map.rs @@ -10,8 +10,8 @@ use num::Zero; /// Time of impacts between two support-mapped shapes under translational movement. pub fn cast_shapes_support_map_support_map( - pos12: &Isometry, - vel12: &Vector, + pos12: &Isometry, + vel12: &Vector, g1: &G1, g2: &G2, options: ShapeCastOptions, diff --git a/src/query/split/split_segment.rs b/src/query/split/split_segment.rs index 6d2cb47a..15a182fc 100644 --- a/src/query/split/split_segment.rs +++ b/src/query/split/split_segment.rs @@ -22,7 +22,7 @@ impl Segment { /// the `bias` (i.e. the plane passes through the point equal to `normal * bias`). pub fn local_split( &self, - local_axis: &UnitVector, + local_axis: &UnitVector, bias: Real, epsilon: Real, ) -> SplitResult { @@ -38,10 +38,10 @@ impl Segment { /// parallel or near-parallel to the segment. pub fn local_split_and_get_intersection( &self, - local_axis: &UnitVector, + local_axis: &UnitVector, bias: Real, epsilon: Real, - ) -> (SplitResult, Option<(Point, Real)>) { + ) -> (SplitResult, Option<(Point, Real)>) { let dir = self.b - self.a; let a = bias - local_axis.dot(&self.a.coords); let b = local_axis.dot(&dir); diff --git a/src/query/split/split_trimesh.rs b/src/query/split/split_trimesh.rs index fa0e96df..07deff34 100644 --- a/src/query/split/split_trimesh.rs +++ b/src/query/split/split_trimesh.rs @@ -10,14 +10,14 @@ use std::cmp::Ordering; struct Triangulation { delaunay: ConstrainedDelaunayTriangulation>, - basis: [Vector; 2], - basis_origin: Point, + basis: [Vector; 2], + basis_origin: Point, spade2index: HashMap, index2spade: HashMap, } impl Triangulation { - fn new(axis: UnitVector, basis_origin: Point) -> Self { + fn new(axis: UnitVector, basis_origin: Point) -> Self { Triangulation { delaunay: ConstrainedDelaunayTriangulation::new(), basis: axis.orthonormal_basis(), @@ -27,12 +27,12 @@ impl Triangulation { } } - fn project(&self, pt: Point) -> spade::Point2 { + fn project(&self, pt: Point) -> spade::Point2 { let dpt = pt - self.basis_origin; spade::Point2::new(dpt.dot(&self.basis[0]), dpt.dot(&self.basis[1])) } - fn add_edge(&mut self, id1: u32, id2: u32, points: &[Point]) { + fn add_edge(&mut self, id1: u32, id2: u32, points: &[Point]) { let proj1 = self.project(points[id1 as usize]); let proj2 = self.project(points[id2 as usize]); @@ -75,8 +75,8 @@ impl TriMesh { /// and the `bias` (i.e. the plane passes through the point equal to `normal * bias`). pub fn split( &self, - position: &Isometry, - axis: &UnitVector, + position: &Isometry, + axis: &UnitVector, bias: Real, epsilon: Real, ) -> SplitResult { @@ -89,7 +89,7 @@ impl TriMesh { /// and the `bias` (i.e. the plane passes through the point equal to `normal * bias`). pub fn local_split( &self, - local_axis: &UnitVector, + local_axis: &UnitVector, bias: Real, epsilon: Real, ) -> SplitResult { @@ -367,8 +367,8 @@ impl TriMesh { /// (i.e. the plane passes through the point equal to `normal * bias`). pub fn intersection_with_plane( &self, - position: &Isometry, - axis: &UnitVector, + position: &Isometry, + axis: &UnitVector, bias: Real, epsilon: Real, ) -> IntersectResult { @@ -382,7 +382,7 @@ impl TriMesh { /// and the `bias` (i.e. the plane passes through the point equal to `normal * bias`). pub fn intersection_with_local_plane( &self, - local_axis: &UnitVector, + local_axis: &UnitVector, bias: Real, epsilon: Real, ) -> IntersectResult { @@ -607,7 +607,7 @@ impl TriMesh { /// Computes the intersection mesh between an Aabb and this mesh. pub fn intersection_with_aabb( &self, - position: &Isometry, + position: &Isometry, flip_mesh: bool, aabb: &Aabb, flip_cuboid: bool, @@ -628,10 +628,10 @@ impl TriMesh { /// Computes the intersection mesh between a cuboid and this mesh transformed by `position`. pub fn intersection_with_cuboid( &self, - position: &Isometry, + position: &Isometry, flip_mesh: bool, cuboid: &Cuboid, - cuboid_position: &Isometry, + cuboid_position: &Isometry, flip_cuboid: bool, epsilon: Real, ) -> Result, MeshIntersectionError> { @@ -649,7 +649,7 @@ impl TriMesh { &self, flip_mesh: bool, cuboid: &Cuboid, - cuboid_position: &Isometry, + cuboid_position: &Isometry, flip_cuboid: bool, _epsilon: Real, ) -> Result, MeshIntersectionError> { diff --git a/src/query/visitors/aabb_sets_interferences_collector.rs b/src/query/visitors/aabb_sets_interferences_collector.rs index e87bb484..a58a61f3 100644 --- a/src/query/visitors/aabb_sets_interferences_collector.rs +++ b/src/query/visitors/aabb_sets_interferences_collector.rs @@ -3,11 +3,11 @@ use crate::math::{Isometry, Matrix, Real}; /// Spatial partitioning data structure visitor collecting interferences with a given bounding volume. pub struct AabbSetsInterferencesCollector<'a, T: 'a> { /// The transform from the local-space of the second bounding volumes to the local space of the first. - pub ls_m2: &'a Isometry, + pub ls_m2: &'a Isometry, /// The absolute value of the rotation matrix representing `ls_m2.rotation`. /// /// Equals to `ls_m2.rotation.to_rotation.matrix().matrix().abs()`. - pub ls_m2_abs_rot: &'a Matrix, + pub ls_m2_abs_rot: &'a Matrix, /// A tolerance applied to the interference tests. /// /// Aabb pairs closer than `tolerance` will be reported as intersecting. @@ -21,8 +21,8 @@ impl<'a, T> AabbSetsInterferencesCollector<'a, T> { #[inline] pub fn new( tolerance: Real, - ls_m2: &'a Isometry, - ls_m2_abs_rot: &'a Matrix, + ls_m2: &'a Isometry, + ls_m2_abs_rot: &'a Matrix, collector: &'a mut Vec<(T, T)>, ) -> AabbSetsInterferencesCollector<'a, T> { AabbSetsInterferencesCollector { diff --git a/src/query/visitors/bounding_volume_intersections_simultaneous_visitor.rs b/src/query/visitors/bounding_volume_intersections_simultaneous_visitor.rs index d0e76dca..e4e90423 100644 --- a/src/query/visitors/bounding_volume_intersections_simultaneous_visitor.rs +++ b/src/query/visitors/bounding_volume_intersections_simultaneous_visitor.rs @@ -1,5 +1,5 @@ use crate::bounding_volume::SimdAabb; -use crate::math::{Isometry, Real, SimdReal, SIMD_WIDTH}; +use crate::math::{Isometry, IsometryT, SimdReal, SIMD_WIDTH}; use crate::partitioning::{SimdSimultaneousVisitStatus, SimdSimultaneousVisitor}; use na::SimdValue; use simba::simd::SimdBool as _; @@ -10,7 +10,7 @@ use crate::partitioning::{QbvhNode, SimdNodeIndex}; /// Spatial partitioning data structure visitor collecting interferences with a given bounding volume. pub struct BoundingVolumeIntersectionsSimultaneousVisitor { - pos12: Option>, + pos12: Option>, callback: F, _phantom: PhantomData<(T1, T2)>, } @@ -29,11 +29,11 @@ impl BoundingVolumeIntersectionsSimultaneousVisitor { /// Creates a new `BoundingVolumeIntersectionsSimultaneousVisitor`. #[inline] pub fn with_relative_pos( - pos12: Isometry, + pos12: Isometry, callback: F, ) -> BoundingVolumeIntersectionsSimultaneousVisitor { BoundingVolumeIntersectionsSimultaneousVisitor { - pos12: Some(Isometry::splat(pos12)), + pos12: Some(IsometryT::splat(pos12)), callback, _phantom: PhantomData, } diff --git a/src/query/visitors/composite_closest_point_visitor.rs b/src/query/visitors/composite_closest_point_visitor.rs index d523e892..a6a91725 100644 --- a/src/query/visitors/composite_closest_point_visitor.rs +++ b/src/query/visitors/composite_closest_point_visitor.rs @@ -1,5 +1,5 @@ use crate::bounding_volume::SimdAabb; -use crate::math::{Point, Real, SimdBool, SimdReal, SIMD_WIDTH}; +use crate::math::{Point, PointT, Real, SimdBool, SimdReal, SIMD_WIDTH}; use crate::partitioning::{SimdBestFirstVisitStatus, SimdBestFirstVisitor}; use crate::query::{PointProjection, PointQuery}; use crate::shape::SimdCompositeShape; @@ -9,18 +9,18 @@ use simba::simd::{SimdBool as _, SimdPartialOrd, SimdValue}; /// Best-first traversal visitor for computing the point closest to a composite shape. pub struct CompositeClosestPointVisitor<'a, S: 'a> { shape: &'a S, - point: &'a Point, - simd_point: Point, + point: &'a Point, + simd_point: PointT, solid: bool, } impl<'a, S> CompositeClosestPointVisitor<'a, S> { /// Initializes a visitor that allows the computation of the point closest to `point` on `shape`. - pub fn new(shape: &'a S, point: &'a Point, solid: bool) -> Self { + pub fn new(shape: &'a S, point: &'a Point, solid: bool) -> Self { CompositeClosestPointVisitor { shape, point, - simd_point: Point::splat(*point), + simd_point: PointT::splat(*point), solid, } } diff --git a/src/query/visitors/composite_point_containment_test.rs b/src/query/visitors/composite_point_containment_test.rs index 84818107..438a192a 100644 --- a/src/query/visitors/composite_point_containment_test.rs +++ b/src/query/visitors/composite_point_containment_test.rs @@ -1,5 +1,5 @@ use crate::bounding_volume::SimdAabb; -use crate::math::{Point, Real, SimdReal, SIMD_WIDTH}; +use crate::math::{Point, PointT, SimdReal, SIMD_WIDTH}; use crate::partitioning::{SimdVisitStatus, SimdVisitor}; use crate::query::point::point_query::PointQuery; use crate::shape::TypedSimdCompositeShape; @@ -11,7 +11,7 @@ pub struct CompositePointContainmentTest<'a, S: 'a> { /// The composite shape on which the point containment test should be performed. pub shape: &'a S, /// The point to be tested. - pub point: &'a Point, + pub point: &'a Point, /// A traversal will set this to `true` if the point is inside of `self.shape`. pub found: bool, } @@ -19,7 +19,7 @@ pub struct CompositePointContainmentTest<'a, S: 'a> { impl<'a, S> CompositePointContainmentTest<'a, S> { /// Creates a new visitor for the testing containment of the given `point` /// into the given `shape`. - pub fn new(shape: &'a S, point: &'a Point) -> Self { + pub fn new(shape: &'a S, point: &'a Point) -> Self { Self { shape, point, @@ -37,7 +37,7 @@ impl SimdVisitor bv: &SimdAabb, b: Option<[Option<&S::PartId>; SIMD_WIDTH]>, ) -> SimdVisitStatus { - let simd_point: Point = Point::splat(*self.point); + let simd_point: PointT = PointT::splat(*self.point); let mask = bv.contains_local_point(&simd_point); if let Some(data) = b { diff --git a/src/query/visitors/point_intersections_visitor.rs b/src/query/visitors/point_intersections_visitor.rs index 98dd3e14..39d4868b 100644 --- a/src/query/visitors/point_intersections_visitor.rs +++ b/src/query/visitors/point_intersections_visitor.rs @@ -1,5 +1,5 @@ use crate::bounding_volume::SimdAabb; -use crate::math::{Point, Real, SimdReal, SIMD_WIDTH}; +use crate::math::{Point, PointT, SimdReal, SIMD_WIDTH}; use crate::partitioning::{SimdVisitStatus, SimdVisitor}; use simba::simd::{SimdBool as _, SimdValue}; use std::marker::PhantomData; @@ -8,7 +8,7 @@ use std::marker::PhantomData; /// Spatial partitioning structure visitor collecting nodes that may contain a given point. pub struct PointIntersectionsVisitor<'a, T, F> { - simd_point: Point, + simd_point: PointT, /// Callback executed for each leaf which Aabb contains `self.point`. callback: &'a mut F, _phantom: PhantomData, @@ -20,9 +20,9 @@ where { /// Creates a new `PointIntersectionsVisitor`. #[inline] - pub fn new(point: &'a Point, callback: &'a mut F) -> PointIntersectionsVisitor<'a, T, F> { + pub fn new(point: &'a Point, callback: &'a mut F) -> PointIntersectionsVisitor<'a, T, F> { PointIntersectionsVisitor { - simd_point: Point::splat(*point), + simd_point: PointT::splat(*point), callback, _phantom: PhantomData, } diff --git a/src/shape/ball.rs b/src/shape/ball.rs index 677246ab..860010d4 100644 --- a/src/shape/ball.rs +++ b/src/shape/ball.rs @@ -37,7 +37,7 @@ impl Ball { #[inline] pub fn scaled( self, - scale: &Vector, + scale: &Vector, nsubdivs: u32, ) -> Option> { if scale.x != scale.y { @@ -64,7 +64,7 @@ impl Ball { #[inline] pub fn scaled( self, - scale: &Vector, + scale: &Vector, nsubdivs: u32, ) -> Option> { if scale.x != scale.y || scale.x != scale.z || scale.y != scale.z { @@ -84,22 +84,22 @@ impl Ball { impl SupportMap for Ball { #[inline] - fn support_point(&self, m: &Isometry, dir: &Vector) -> Point { + fn support_point(&self, m: &Isometry, dir: &Vector) -> Point { self.support_point_toward(m, &Unit::new_normalize(*dir)) } #[inline] - fn support_point_toward(&self, m: &Isometry, dir: &Unit>) -> Point { + fn support_point_toward(&self, m: &Isometry, dir: &Unit) -> Point { Point::from(m.translation.vector) + **dir * self.radius } #[inline] - fn local_support_point(&self, dir: &Vector) -> Point { + fn local_support_point(&self, dir: &Vector) -> Point { self.local_support_point_toward(&Unit::new_normalize(*dir)) } #[inline] - fn local_support_point_toward(&self, dir: &Unit>) -> Point { + fn local_support_point_toward(&self, dir: &Unit) -> Point { Point::from(**dir * self.radius) } } diff --git a/src/shape/capsule.rs b/src/shape/capsule.rs index 357e2571..c8dee663 100644 --- a/src/shape/capsule.rs +++ b/src/shape/capsule.rs @@ -46,7 +46,7 @@ impl Capsule { } /// Creates a new capsule defined as the segment between `a` and `b` and with the given `radius`. - pub fn new(a: Point, b: Point, radius: Real) -> Self { + pub fn new(a: Point, b: Point, radius: Real) -> Self { let segment = Segment::new(a, b); Self { segment, radius } } @@ -62,25 +62,25 @@ impl Capsule { } /// The center of this capsule. - pub fn center(&self) -> Point { + pub fn center(&self) -> Point { na::center(&self.segment.a, &self.segment.b) } /// Creates a new capsule equal to `self` with all its endpoints transformed by `pos`. - pub fn transform_by(&self, pos: &Isometry) -> Self { + pub fn transform_by(&self, pos: &Isometry) -> Self { Self::new(pos * self.segment.a, pos * self.segment.b, self.radius) } /// The transformation such that `t * Y` is collinear with `b - a` and `t * origin` equals /// the capsule's center. - pub fn canonical_transform(&self) -> Isometry { + pub fn canonical_transform(&self) -> Isometry { let tra = self.center().coords; let rot = self.rotation_wrt_y(); Isometry::from_parts(tra.into(), rot) } /// The rotation `r` such that `r * Y` is collinear with `b - a`. - pub fn rotation_wrt_y(&self) -> Rotation { + pub fn rotation_wrt_y(&self) -> Rotation { let mut dir = self.segment.b - self.segment.a; if dir.y < 0.0 { dir = -dir; @@ -98,7 +98,7 @@ impl Capsule { } /// The transform `t` such that `t * Y` is collinear with `b - a` and such that `t * origin = (b + a) / 2.0`. - pub fn transform_wrt_y(&self) -> Isometry { + pub fn transform_wrt_y(&self) -> Isometry { let rot = self.rotation_wrt_y(); Isometry::from_parts(self.center().coords.into(), rot) } @@ -112,7 +112,7 @@ impl Capsule { #[cfg(all(feature = "dim2", feature = "std"))] pub fn scaled( self, - scale: &Vector, + scale: &Vector, nsubdivs: u32, ) -> Option> { if scale.x != scale.y { @@ -142,7 +142,7 @@ impl Capsule { #[cfg(all(feature = "dim3", feature = "std"))] pub fn scaled( self, - scale: &Vector, + scale: &Vector, nsubdivs: u32, ) -> Option> { if scale.x != scale.y || scale.x != scale.z || scale.y != scale.z { @@ -165,12 +165,12 @@ impl Capsule { } impl SupportMap for Capsule { - fn local_support_point(&self, dir: &Vector) -> Point { + fn local_support_point(&self, dir: &Vector) -> Point { let dir = Unit::try_new(*dir, 0.0).unwrap_or(Vector::y_axis()); self.local_support_point_toward(&dir) } - fn local_support_point_toward(&self, dir: &Unit>) -> Point { + fn local_support_point_toward(&self, dir: &Unit) -> Point { if dir.dot(&self.segment.a.coords) > dir.dot(&self.segment.b.coords) { self.segment.a + **dir * self.radius } else { diff --git a/src/shape/composite_shape.rs b/src/shape/composite_shape.rs index db69e46d..b73c6ea8 100644 --- a/src/shape/composite_shape.rs +++ b/src/shape/composite_shape.rs @@ -1,4 +1,4 @@ -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::partitioning::{IndexedData, Qbvh}; use crate::query::details::NormalConstraints; use crate::shape::Shape; @@ -13,7 +13,7 @@ pub trait SimdCompositeShape { fn map_part_at( &self, shape_id: u32, - f: &mut dyn FnMut(Option<&Isometry>, &dyn Shape, Option<&dyn NormalConstraints>), + f: &mut dyn FnMut(Option<&Isometry>, &dyn Shape, Option<&dyn NormalConstraints>), ); /// Gets the acceleration structure of the composite shape. @@ -29,7 +29,7 @@ pub trait TypedSimdCompositeShape { fn map_typed_part_at( &self, shape_id: Self::PartId, - f: impl FnMut(Option<&Isometry>, &Self::PartShape, Option<&Self::PartNormalConstraints>), + f: impl FnMut(Option<&Isometry>, &Self::PartShape, Option<&Self::PartNormalConstraints>), ); // TODO: we need this method because the compiler won't want @@ -38,7 +38,7 @@ pub trait TypedSimdCompositeShape { fn map_untyped_part_at( &self, shape_id: Self::PartId, - f: impl FnMut(Option<&Isometry>, &dyn Shape, Option<&dyn NormalConstraints>), + f: impl FnMut(Option<&Isometry>, &dyn Shape, Option<&dyn NormalConstraints>), ); fn typed_qbvh(&self) -> &Qbvh; @@ -53,11 +53,7 @@ impl TypedSimdCompositeShape for dyn SimdCompositeShape + '_ { fn map_typed_part_at( &self, shape_id: u32, - mut f: impl FnMut( - Option<&Isometry>, - &Self::PartShape, - Option<&Self::PartNormalConstraints>, - ), + mut f: impl FnMut(Option<&Isometry>, &Self::PartShape, Option<&Self::PartNormalConstraints>), ) { self.map_part_at(shape_id, &mut f) } @@ -65,7 +61,7 @@ impl TypedSimdCompositeShape for dyn SimdCompositeShape + '_ { fn map_untyped_part_at( &self, shape_id: u32, - mut f: impl FnMut(Option<&Isometry>, &dyn Shape, Option<&dyn NormalConstraints>), + mut f: impl FnMut(Option<&Isometry>, &dyn Shape, Option<&dyn NormalConstraints>), ) { self.map_part_at(shape_id, &mut f) } diff --git a/src/shape/compound.rs b/src/shape/compound.rs index 7be11a95..b4649fed 100644 --- a/src/shape/compound.rs +++ b/src/shape/compound.rs @@ -3,7 +3,7 @@ //! use crate::bounding_volume::{Aabb, BoundingSphere, BoundingVolume}; -use crate::math::{Isometry, Real}; +use crate::math::Isometry; use crate::partitioning::Qbvh; use crate::query::details::NormalConstraints; #[cfg(feature = "dim2")] @@ -20,7 +20,7 @@ use crate::transformation::hertel_mehlhorn; #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Clone, Debug)] pub struct Compound { - shapes: Vec<(Isometry, SharedShape)>, + shapes: Vec<(Isometry, SharedShape)>, qbvh: Qbvh, aabbs: Vec, aabb: Aabb, @@ -31,7 +31,7 @@ impl Compound { /// /// Panics if the input vector is empty, of if some of the provided shapes /// are also composite shapes (nested composite shapes are not allowed). - pub fn new(shapes: Vec<(Isometry, SharedShape)>) -> Compound { + pub fn new(shapes: Vec<(Isometry, SharedShape)>) -> Compound { assert!( !shapes.is_empty(), "A compound shape must contain at least one shape." @@ -92,7 +92,7 @@ impl Compound { impl Compound { /// The shapes of this compound shape. #[inline] - pub fn shapes(&self) -> &[(Isometry, SharedShape)] { + pub fn shapes(&self) -> &[(Isometry, SharedShape)] { &self.shapes[..] } @@ -126,7 +126,7 @@ impl SimdCompositeShape for Compound { fn map_part_at( &self, shape_id: u32, - f: &mut dyn FnMut(Option<&Isometry>, &dyn Shape, Option<&dyn NormalConstraints>), + f: &mut dyn FnMut(Option<&Isometry>, &dyn Shape, Option<&dyn NormalConstraints>), ) { if let Some(shape) = self.shapes.get(shape_id as usize) { f(Some(&shape.0), &*shape.1, None) @@ -148,11 +148,7 @@ impl TypedSimdCompositeShape for Compound { fn map_typed_part_at( &self, i: u32, - mut f: impl FnMut( - Option<&Isometry>, - &Self::PartShape, - Option<&Self::PartNormalConstraints>, - ), + mut f: impl FnMut(Option<&Isometry>, &Self::PartShape, Option<&Self::PartNormalConstraints>), ) { if let Some((part_pos, part)) = self.shapes.get(i as usize) { f(Some(part_pos), &**part, None) @@ -163,7 +159,7 @@ impl TypedSimdCompositeShape for Compound { fn map_untyped_part_at( &self, i: u32, - mut f: impl FnMut(Option<&Isometry>, &Self::PartShape, Option<&dyn NormalConstraints>), + mut f: impl FnMut(Option<&Isometry>, &Self::PartShape, Option<&dyn NormalConstraints>), ) { if let Some((part_pos, part)) = self.shapes.get(i as usize) { f(Some(part_pos), &**part, None) diff --git a/src/shape/cone.rs b/src/shape/cone.rs index beeabb6a..ef310e3c 100644 --- a/src/shape/cone.rs +++ b/src/shape/cone.rs @@ -54,7 +54,7 @@ impl Cone { #[inline] pub fn scaled( self, - scale: &Vector, + scale: &Vector, nsubdivs: u32, ) -> Option> { // NOTE: if the y scale is negative, the result cone points downwards, @@ -78,7 +78,7 @@ impl Cone { impl SupportMap for Cone { #[inline] - fn local_support_point(&self, dir: &Vector) -> Point { + fn local_support_point(&self, dir: &Vector) -> Point { let mut vres = *dir; vres[1] = 0.0; diff --git a/src/shape/convex_polygon.rs b/src/shape/convex_polygon.rs index 8a5825ac..26fbf08c 100644 --- a/src/shape/convex_polygon.rs +++ b/src/shape/convex_polygon.rs @@ -12,8 +12,8 @@ use na::{self, ComplexField, RealField, Unit}; )] #[derive(Clone, Debug)] pub struct ConvexPolygon { - points: Vec>, - normals: Vec>>, + points: Vec, + normals: Vec>, } impl ConvexPolygon { @@ -21,7 +21,7 @@ impl ConvexPolygon { /// /// This explicitly computes the convex hull of the given set of points. /// Returns `None` if the convex hull computation failed. - pub fn from_convex_hull(points: &[Point]) -> Option { + pub fn from_convex_hull(points: &[Point]) -> Option { let vertices = crate::transformation::convex_hull(points); Self::from_convex_polyline(vertices) } @@ -31,7 +31,7 @@ impl ConvexPolygon { /// /// Convexity of the input polyline is not checked. /// Returns `None` if all points form an almost flat line. - pub fn from_convex_polyline(mut points: Vec>) -> Option { + pub fn from_convex_polyline(mut points: Vec) -> Option { if points.is_empty() { return None; } @@ -75,13 +75,13 @@ impl ConvexPolygon { /// The vertices of this convex polygon. #[inline] - pub fn points(&self) -> &[Point] { + pub fn points(&self) -> &[Point] { &self.points } /// The normals of the edges of this convex polygon. #[inline] - pub fn normals(&self) -> &[Unit>] { + pub fn normals(&self) -> &[Unit] { &self.normals } @@ -89,7 +89,7 @@ impl ConvexPolygon { /// /// Returns `None` if the result had degenerate normals (for example if /// the scaling factor along one axis is zero). - pub fn scaled(mut self, scale: &Vector) -> Option { + pub fn scaled(mut self, scale: &Vector) -> Option { self.points .iter_mut() .for_each(|pt| pt.coords.component_mul_assign(scale)); @@ -137,7 +137,7 @@ impl ConvexPolygon { } /// Get the ID of the feature with a normal that maximizes the dot product with `local_dir`. - pub fn support_feature_id_toward(&self, local_dir: &Unit>) -> FeatureId { + pub fn support_feature_id_toward(&self, local_dir: &Unit) -> FeatureId { let eps: Real = Real::pi() / 180.0; let ceps = ComplexField::cos(eps); @@ -157,7 +157,7 @@ impl ConvexPolygon { } /// The normal of the given feature. - pub fn feature_normal(&self, feature: FeatureId) -> Option>> { + pub fn feature_normal(&self, feature: FeatureId) -> Option> { match feature { FeatureId::Face(id) => Some(self.normals[id as usize]), FeatureId::Vertex(id2) => { @@ -177,13 +177,13 @@ impl ConvexPolygon { impl SupportMap for ConvexPolygon { #[inline] - fn local_support_point(&self, dir: &Vector) -> Point { + fn local_support_point(&self, dir: &Vector) -> Point { utils::point_cloud_support_point(dir, self.points()) } } impl PolygonalFeatureMap for ConvexPolygon { - fn local_support_feature(&self, dir: &Unit>, out_feature: &mut PolygonalFeature) { + fn local_support_feature(&self, dir: &Unit, out_feature: &mut PolygonalFeature) { let cuboid = crate::shape::Cuboid::new(self.points[2].coords); cuboid.local_support_feature(dir, out_feature); let mut best_face = 0; @@ -211,7 +211,7 @@ impl PolygonalFeatureMap for ConvexPolygon { /* impl ConvexPolyhedron for ConvexPolygon { - fn vertex(&self, id: FeatureId) -> Point { + fn vertex(&self, id: FeatureId) -> Point { self.points[id.unwrap_vertex() as usize] } @@ -231,8 +231,8 @@ impl ConvexPolyhedron for ConvexPolygon { fn support_face_toward( &self, - m: &Isometry, - dir: &Unit>, + m: &Isometry, + dir: &Unit, out: &mut ConvexPolygonalFeature, ) { let ls_dir = m.inverse_transform_vector(dir); @@ -254,8 +254,8 @@ impl ConvexPolyhedron for ConvexPolygon { fn support_feature_toward( &self, - transform: &Isometry, - dir: &Unit>, + transform: &Isometry, + dir: &Unit, _angle: Real, out: &mut ConvexPolygonalFeature, ) { @@ -264,7 +264,7 @@ impl ConvexPolyhedron for ConvexPolygon { self.support_face_toward(transform, dir, out) } - fn support_feature_id_toward(&self, local_dir: &Unit>) -> FeatureId { + fn support_feature_id_toward(&self, local_dir: &Unit) -> FeatureId { let eps: Real = na::convert::(f64::consts::PI / 180.0); let ceps = ComplexField::cos(eps); @@ -300,7 +300,7 @@ mod tests { .unwrap(); let offsetted = polygon.offsetted(0.5); - let expected = vec![ + let expected = [ Point::new(2.207, 0.5), Point::new(-2.207, 0.5), Point::new(0., -1.707), diff --git a/src/shape/convex_polyhedron.rs b/src/shape/convex_polyhedron.rs index ed907e19..487dfb99 100644 --- a/src/shape/convex_polyhedron.rs +++ b/src/shape/convex_polyhedron.rs @@ -34,7 +34,7 @@ pub struct Vertex { pub struct Edge { pub vertices: Point2, pub faces: Point2, - pub dir: Unit>, + pub dir: Unit, deleted: bool, } @@ -58,7 +58,7 @@ impl Edge { pub struct Face { pub first_vertex_or_edge: u32, pub num_vertices_or_edges: u32, - pub normal: Unit>, + pub normal: Unit, } #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] @@ -71,7 +71,7 @@ pub struct Face { struct Triangle { vertices: [u32; 3], edges: [u32; 3], - normal: Vector, + normal: Vector, parent_face: Option, is_degenerate: bool, } @@ -97,7 +97,7 @@ impl Triangle { #[derive(PartialEq, Debug, Clone)] /// A convex polyhedron without degenerate faces. pub struct ConvexPolyhedron { - points: Vec>, + points: Vec, vertices: Vec, faces: Vec, edges: Vec, @@ -116,7 +116,7 @@ impl ConvexPolyhedron { /// /// This explicitly computes the convex hull of the given set of points. Use /// Returns `None` if the convex hull computation failed. - pub fn from_convex_hull(points: &[Point]) -> Option { + pub fn from_convex_hull(points: &[Point]) -> Option { crate::transformation::try_convex_hull(points) .ok() .and_then(|(vertices, indices)| Self::from_convex_mesh(vertices, &indices)) @@ -131,7 +131,7 @@ impl ConvexPolyhedron { /// /// Returns `None` if the given solid is not manifold (contains t-junctions, not closed, etc.) pub fn from_convex_mesh( - points: Vec>, + points: Vec, indices: &[[u32; DIM]], ) -> Option { let eps = ComplexField::sqrt(crate::math::DEFAULT_EPSILON); @@ -396,7 +396,7 @@ impl ConvexPolyhedron { /// The set of vertices of this convex polyhedron. #[inline] - pub fn points(&self) -> &[Point] { + pub fn points(&self) -> &[Point] { &self.points[..] } @@ -440,7 +440,7 @@ impl ConvexPolyhedron { /// /// Returns `None` if the result had degenerate normals (for example if /// the scaling factor along one axis is zero). - pub fn scaled(mut self, scale: &Vector) -> Option { + pub fn scaled(mut self, scale: &Vector) -> Option { self.points .iter_mut() .for_each(|pt| pt.coords.component_mul_assign(scale)); @@ -456,11 +456,7 @@ impl ConvexPolyhedron { Some(self) } - fn support_feature_id_toward_eps( - &self, - local_dir: &Unit>, - eps: Real, - ) -> FeatureId { + fn support_feature_id_toward_eps(&self, local_dir: &Unit, eps: Real) -> FeatureId { let (seps, ceps) = ComplexField::sin_cos(eps); let support_pt_id = utils::point_cloud_support_point_id(local_dir.as_ref(), &self.points); let vertex = &self.vertices[support_pt_id]; @@ -490,13 +486,13 @@ impl ConvexPolyhedron { } /// Computes the ID of the features with a normal that maximize the dot-product with `local_dir`. - pub fn support_feature_id_toward(&self, local_dir: &Unit>) -> FeatureId { + pub fn support_feature_id_toward(&self, local_dir: &Unit) -> FeatureId { let eps: Real = na::convert::(f64::consts::PI / 180.0); self.support_feature_id_toward_eps(local_dir, eps) } /// The normal of the given feature. - pub fn feature_normal(&self, feature: FeatureId) -> Option>> { + pub fn feature_normal(&self, feature: FeatureId) -> Option> { match feature { FeatureId::Face(id) => Some(self.faces[id as usize].normal), FeatureId::Edge(id) => { @@ -525,13 +521,13 @@ impl ConvexPolyhedron { impl SupportMap for ConvexPolyhedron { #[inline] - fn local_support_point(&self, dir: &Vector) -> Point { + fn local_support_point(&self, dir: &Vector) -> Point { utils::point_cloud_support_point(dir, self.points()) } } impl PolygonalFeatureMap for ConvexPolyhedron { - fn local_support_feature(&self, dir: &Unit>, out_feature: &mut PolygonalFeature) { + fn local_support_feature(&self, dir: &Unit, out_feature: &mut PolygonalFeature) { let mut best_fid = 0; let mut best_dot = self.faces[0].normal.dot(dir); @@ -571,11 +567,11 @@ impl PolygonalFeatureMap for ConvexPolyhedron { /* impl ConvexPolyhedron for ConvexPolyhedron { - fn vertex(&self, id: FeatureId) -> Point { + fn vertex(&self, id: FeatureId) -> Point { self.points[id.unwrap_vertex() as usize] } - fn edge(&self, id: FeatureId) -> (Point, Point, FeatureId, FeatureId) { + fn edge(&self, id: FeatureId) -> (Point, Point, FeatureId, FeatureId) { let edge = &self.edges[id.unwrap_edge() as usize]; let v1 = edge.vertices[0]; let v2 = edge.vertices[1]; @@ -609,8 +605,8 @@ impl ConvexPolyhedron for ConvexPolyhedron { fn support_face_toward( &self, - m: &Isometry, - dir: &Unit>, + m: &Isometry, + dir: &Unit, out: &mut ConvexPolygonalFeature, ) { let ls_dir = m.inverse_transform_vector(dir); @@ -633,8 +629,8 @@ impl ConvexPolyhedron for ConvexPolyhedron { fn support_feature_toward( &self, - transform: &Isometry, - dir: &Unit>, + transform: &Isometry, + dir: &Unit, angle: Real, out: &mut ConvexPolygonalFeature, ) { diff --git a/src/shape/cuboid.rs b/src/shape/cuboid.rs index e03e27dc..e76497dd 100644 --- a/src/shape/cuboid.rs +++ b/src/shape/cuboid.rs @@ -1,6 +1,6 @@ //! Support mapping based Cuboid shape. -use crate::math::{Point, Real, Vector}; +use crate::math::{Point, Vector}; #[cfg(feature = "dim3")] use crate::shape::Segment; use crate::shape::{FeatureId, PackedFeatureId, PolygonalFeature, SupportMap}; @@ -25,19 +25,19 @@ use rkyv::{bytecheck, CheckBytes}; #[repr(C)] pub struct Cuboid { /// The half-extents of the cuboid. - pub half_extents: Vector, + pub half_extents: Vector, } impl Cuboid { /// Creates a new box from its half-extents. Half-extents are the box half-width along each /// axis. Each half-extent must be positive. #[inline] - pub fn new(half_extents: Vector) -> Cuboid { + pub fn new(half_extents: Vector) -> Cuboid { Cuboid { half_extents } } /// Computes a scaled version of this cuboid. - pub fn scaled(self, scale: &Vector) -> Self { + pub fn scaled(self, scale: &Vector) -> Self { let new_hext = self.half_extents.component_mul(scale); Self { half_extents: new_hext, @@ -47,7 +47,7 @@ impl Cuboid { /// Return the id of the vertex of this cuboid with a normal that maximizes /// the dot product with `dir`. #[cfg(feature = "dim2")] - pub fn vertex_feature_id(vertex: Point) -> u32 { + pub fn vertex_feature_id(vertex: Point) -> u32 { // TODO: is this still correct with the f64 version? #[allow(clippy::unnecessary_cast)] // Unnecessary for f32 but necessary for f64. { @@ -58,7 +58,7 @@ impl Cuboid { /// Return the feature of this cuboid with a normal that maximizes /// the dot product with `dir`. #[cfg(feature = "dim2")] - pub fn support_feature(&self, local_dir: Vector) -> PolygonalFeature { + pub fn support_feature(&self, local_dir: Vector) -> PolygonalFeature { // In 2D, it is best for stability to always return a face. // It won't have any notable impact on performances anyway. self.support_face(local_dir) @@ -67,7 +67,7 @@ impl Cuboid { /// Return the face of this cuboid with a normal that maximizes /// the dot product with `local_dir`. #[cfg(feature = "dim2")] - pub fn support_face(&self, local_dir: Vector) -> PolygonalFeature { + pub fn support_face(&self, local_dir: Vector) -> PolygonalFeature { let he = self.half_extents; let i = local_dir.iamin(); let j = (i + 1) % 2; @@ -93,7 +93,7 @@ impl Cuboid { /// Return the face of this cuboid with a normal that maximizes /// the dot product with `local_dir`. #[cfg(feature = "dim3")] - pub fn support_feature(&self, local_dir: Vector) -> PolygonalFeature { + pub fn support_feature(&self, local_dir: Vector) -> PolygonalFeature { // TODO: this should actually return the feature. // And we should change all the callers of this method to use // `.support_face` instead of this method to preserve their old behavior. @@ -119,7 +119,7 @@ impl Cuboid { } // #[cfg(feature = "dim3") - // pub(crate) fn support_vertex(&self, local_dir: Vector) -> CuboidFeatureVertex { + // pub(crate) fn support_vertex(&self, local_dir: Vector) -> CuboidFeatureVertex { // let vertex = local_support_point(self, local_dir); // let vid = vertex_feature_id(vertex); // @@ -129,7 +129,7 @@ impl Cuboid { /// Return the edge segment of this cuboid with a normal cone containing /// a direction that that maximizes the dot product with `local_dir`. #[cfg(feature = "dim3")] - pub fn local_support_edge_segment(&self, local_dir: Vector) -> Segment { + pub fn local_support_edge_segment(&self, local_dir: Vector) -> Segment { let he = self.half_extents; let i = local_dir.iamin(); let j = (i + 1) % 3; @@ -147,13 +147,13 @@ impl Cuboid { /// Computes the face with a normal that maximizes the dot-product with `local_dir`. #[cfg(feature = "dim3")] - pub fn support_face(&self, local_dir: Vector) -> PolygonalFeature { + pub fn support_face(&self, local_dir: Vector) -> PolygonalFeature { // NOTE: can we use the orthonormal basis of local_dir // to make this AoSoA friendly? let he = self.half_extents; let iamax = local_dir.iamax(); #[expect(clippy::unnecessary_cast)] - let sign = (1.0 as Real).copysign(local_dir[iamax]); + let sign = (1.0 as crate::math::Real).copysign(local_dir[iamax]); let vertices = match iamax { 0 => [ @@ -238,10 +238,10 @@ impl Cuboid { /// The normal of the given feature of this shape. #[cfg(feature = "dim2")] - pub fn feature_normal(&self, feature: FeatureId) -> Option>> { + pub fn feature_normal(&self, feature: FeatureId) -> Option> { match feature { FeatureId::Face(id) => { - let mut dir: Vector = na::zero(); + let mut dir: Vector = na::zero(); if id < 2 { dir[id as usize] = 1.0; @@ -251,7 +251,7 @@ impl Cuboid { Some(Unit::new_unchecked(dir)) } FeatureId::Vertex(id) => { - let mut dir: Vector = na::zero(); + let mut dir: Vector = na::zero(); match id { 0b00 => { @@ -281,10 +281,10 @@ impl Cuboid { /// The normal of the given feature of this shape. #[cfg(feature = "dim3")] - pub fn feature_normal(&self, feature: FeatureId) -> Option>> { + pub fn feature_normal(&self, feature: FeatureId) -> Option> { match feature { FeatureId::Face(id) => { - let mut dir: Vector = na::zero(); + let mut dir: Vector = na::zero(); if id < 3 { dir[id as usize] = 1.0; @@ -299,7 +299,7 @@ impl Cuboid { let face2 = (edge + 2) % 3; let signs = id >> 2; - let mut dir: Vector = na::zero(); + let mut dir: Vector = na::zero(); if signs & (1 << face1) != 0 { dir[face1 as usize] = -1.0 @@ -316,7 +316,7 @@ impl Cuboid { Some(Unit::new_normalize(dir)) } FeatureId::Vertex(id) => { - let mut dir: Vector = na::zero(); + let mut dir: Vector = na::zero(); for i in 0..3 { if id & (1 << i) != 0 { dir[i] = -1.0; @@ -334,14 +334,14 @@ impl Cuboid { impl SupportMap for Cuboid { #[inline] - fn local_support_point(&self, dir: &Vector) -> Point { + fn local_support_point(&self, dir: &Vector) -> Point { dir.copy_sign_to(self.half_extents).into() } } /* impl ConvexPolyhedron for Cuboid { - fn vertex(&self, id: FeatureId) -> Point { + fn vertex(&self, id: FeatureId) -> Point { let vid = id.unwrap_vertex(); let mut res = self.half_extents; @@ -355,7 +355,7 @@ impl ConvexPolyhedron for Cuboid { } #[cfg(feature = "dim3")] - fn edge(&self, id: FeatureId) -> (Point, Point, FeatureId, FeatureId) { + fn edge(&self, id: FeatureId) -> (Point, Point, FeatureId, FeatureId) { let eid = id.unwrap_edge(); let mut res = self.half_extents; @@ -419,7 +419,7 @@ impl ConvexPolyhedron for Cuboid { out.push(p1, FeatureId::Vertex(vertex_id1)); out.push(p2, FeatureId::Vertex(vertex_id2)); - let mut normal: Vector = na::zero(); + let mut normal: Vector = na::zero(); normal[i1] = sign; out.set_normal(Unit::new_unchecked(normal)); out.set_feature_id(FeatureId::Face(i as u32)); @@ -473,7 +473,7 @@ impl ConvexPolyhedron for Cuboid { edge_i3 as u32 | ((vertex_id & mask_i3) << 2), )); - let mut normal: Vector = na::zero(); + let mut normal: Vector = na::zero(); normal[i1] = sign; out.set_normal(Unit::new_unchecked(normal)); @@ -489,8 +489,8 @@ impl ConvexPolyhedron for Cuboid { fn support_face_toward( &self, - m: &Isometry, - dir: &Unit>, + m: &Isometry, + dir: &Unit, out: &mut ConvexPolygonalFeature, ) { out.clear(); @@ -519,8 +519,8 @@ impl ConvexPolyhedron for Cuboid { fn support_feature_toward( &self, - m: &Isometry, - dir: &Unit>, + m: &Isometry, + dir: &Unit, angle: Real, out: &mut ConvexPolygonalFeature, ) { @@ -615,7 +615,7 @@ impl ConvexPolyhedron for Cuboid { } } - fn support_feature_id_toward(&self, local_dir: &Unit>) -> FeatureId { + fn support_feature_id_toward(&self, local_dir: &Unit) -> FeatureId { let one_degree: Real = na::convert::(f64::consts::PI / 180.0); let cang = ComplexField::cos(one_degree); diff --git a/src/shape/cylinder.rs b/src/shape/cylinder.rs index fb4c5444..b81e5b24 100644 --- a/src/shape/cylinder.rs +++ b/src/shape/cylinder.rs @@ -56,7 +56,7 @@ impl Cylinder { #[inline] pub fn scaled( self, - scale: &Vector, + scale: &Vector, nsubdivs: u32, ) -> Option> { if scale.x != scale.z { @@ -77,7 +77,7 @@ impl Cylinder { } impl SupportMap for Cylinder { - fn local_support_point(&self, dir: &Vector) -> Point { + fn local_support_point(&self, dir: &Vector) -> Point { let mut vres = *dir; vres[1] = 0.0; diff --git a/src/shape/half_space.rs b/src/shape/half_space.rs index cdcbf50a..22f8b1b5 100644 --- a/src/shape/half_space.rs +++ b/src/shape/half_space.rs @@ -1,5 +1,5 @@ //! Support mapping based HalfSpace shape. -use crate::math::{Real, Vector}; +use crate::math::Vector; use na::Unit; #[cfg(feature = "rkyv")] @@ -16,13 +16,13 @@ use rkyv::{bytecheck, CheckBytes}; #[repr(C)] pub struct HalfSpace { /// The halfspace planar boundary's outward normal. - pub normal: Unit>, + pub normal: Unit, } impl HalfSpace { /// Builds a new halfspace from its center and its normal. #[inline] - pub fn new(normal: Unit>) -> HalfSpace { + pub fn new(normal: Unit) -> HalfSpace { HalfSpace { normal } } @@ -30,7 +30,7 @@ impl HalfSpace { /// /// Returns `None` if `self.normal` scaled by `scale` is zero (the scaled half-space /// degenerates to a single point). - pub fn scaled(self, scale: &Vector) -> Option { + pub fn scaled(self, scale: &Vector) -> Option { Unit::try_new(self.normal.component_mul(scale), 0.0).map(|normal| Self { normal }) } } diff --git a/src/shape/heightfield2.rs b/src/shape/heightfield2.rs index 245cc4cc..2410466c 100644 --- a/src/shape/heightfield2.rs +++ b/src/shape/heightfield2.rs @@ -29,14 +29,14 @@ pub struct HeightField { heights: DVector, status: DVector, - scale: Vector, + scale: Vector, aabb: Aabb, } #[cfg(feature = "std")] impl HeightField { /// Creates a new 2D heightfield with the given heights and scale factor. - pub fn new(heights: DVector, scale: Vector) -> Self { + pub fn new(heights: DVector, scale: Vector) -> Self { assert!( heights.len() > 1, "A heightfield heights must have at least 2 elements." @@ -72,12 +72,12 @@ impl HeightField { } /// The scale factor applied to this heightfield. - pub fn scale(&self) -> &Vector { + pub fn scale(&self) -> &Vector { &self.scale } /// Sets the scale factor applied to this heightfield. - pub fn set_scale(&mut self, new_scale: Vector) { + pub fn set_scale(&mut self, new_scale: Vector) { let ratio = new_scale.component_div(&self.scale); self.aabb.mins.coords.component_mul_assign(&ratio); self.aabb.maxs.coords.component_mul_assign(&ratio); @@ -85,7 +85,7 @@ impl HeightField { } /// Returns a scaled version of this heightfield. - pub fn scaled(mut self, scale: &Vector) -> Self { + pub fn scaled(mut self, scale: &Vector) -> Self { self.set_scale(self.scale.component_mul(scale)); self } diff --git a/src/shape/heightfield3.rs b/src/shape/heightfield3.rs index 58c1b01b..69471eeb 100644 --- a/src/shape/heightfield3.rs +++ b/src/shape/heightfield3.rs @@ -70,7 +70,7 @@ pub struct HeightField { heights: DMatrix, status: DMatrix, - scale: Vector, + scale: Vector, aabb: Aabb, num_triangles: usize, flags: HeightFieldFlags, @@ -79,16 +79,12 @@ pub struct HeightField { #[cfg(feature = "std")] impl HeightField { /// Initializes a new heightfield with the given heights, scaling factor, and flags. - pub fn new(heights: DMatrix, scale: Vector) -> Self { + pub fn new(heights: DMatrix, scale: Vector) -> Self { Self::with_flags(heights, scale, HeightFieldFlags::empty()) } /// Initializes a new heightfield with the given heights and a scaling factor. - pub fn with_flags( - heights: DMatrix, - scale: Vector, - flags: HeightFieldFlags, - ) -> Self { + pub fn with_flags(heights: DMatrix, scale: Vector, flags: HeightFieldFlags) -> Self { assert!( heights.nrows() > 1 && heights.ncols() > 1, "A heightfield heights must have at least 2 rows and columns." @@ -429,7 +425,7 @@ impl HeightField { // (+/-X, +/-Z, or a combination of both). So this bivector // calculation could be simplified/optimized quite a bit. // Computes the pseudo-normal of an edge where the adjacent triangle is missing. - let bivector = |v: Vector| tri_normal.cross(&v).cross(&tri_normal).normalize(); + let bivector = |v: Vector| tri_normal.cross(&v).cross(&tri_normal).normalize(); // Pseudo-normal computed from an adjacent triangle’s normal and the current triangle’s normal. let adj_pseudo_normal = |adj: Option| { adj.map(|adj| adj.normal().map(|n| *n).unwrap_or(tri_normal)) @@ -547,12 +543,12 @@ impl HeightField { } /// The scale factor applied to this heightfield. - pub fn scale(&self) -> &Vector { + pub fn scale(&self) -> &Vector { &self.scale } /// Sets the scale factor applied to this heightfield. - pub fn set_scale(&mut self, new_scale: Vector) { + pub fn set_scale(&mut self, new_scale: Vector) { let ratio = new_scale.component_div(&self.scale); self.aabb.mins.coords.component_mul_assign(&ratio); self.aabb.maxs.coords.component_mul_assign(&ratio); @@ -560,7 +556,7 @@ impl HeightField { } /// Returns a scaled version of this heightfield. - pub fn scaled(mut self, scale: &Vector) -> Self { + pub fn scaled(mut self, scale: &Vector) -> Self { self.set_scale(self.scale.component_mul(scale)); self } diff --git a/src/shape/polygon.rs b/src/shape/polygon.rs index 70749199..6179f5f4 100644 --- a/src/shape/polygon.rs +++ b/src/shape/polygon.rs @@ -12,8 +12,8 @@ use parry::bounding_volume::Aabb; )] /// A convex planar polygon. pub struct Polygon { - pub(crate) vertices: Vec>, - pub(crate) normals: Vec>, + pub(crate) vertices: Vec, + pub(crate) normals: Vec, } impl Polygon { @@ -27,12 +27,12 @@ impl Polygon { /// The vertices must form a convex polygon. /// /// One normal must be provided per edge and mut point towards the outside of the polygon. - pub fn new(vertices: Vec>, normals: Vec>) -> Self { + pub fn new(vertices: Vec, normals: Vec) -> Self { Self { vertices, normals } } /// Compute the axis-aligned bounding box of the polygon. - pub fn aabb(&self, pos: &Isometry) -> Aabb { + pub fn aabb(&self, pos: &Isometry) -> Aabb { let p0 = pos * self.vertices[0]; let mut mins = p0; let mut maxs = p0; @@ -47,11 +47,11 @@ impl Polygon { } /// The vertices of this polygon. - pub fn vertices(&self) -> &[Point] { + pub fn vertices(&self) -> &[Point] { &self.vertices } - pub(crate) fn support_point(&self, dir: &Vector) -> usize { + pub(crate) fn support_point(&self, dir: &Vector) -> usize { let mut best_dot = -Real::MAX; let mut best_i = 0; @@ -66,7 +66,7 @@ impl Polygon { best_i } - pub(crate) fn support_face(&self, dir: &Vector) -> usize { + pub(crate) fn support_face(&self, dir: &Vector) -> usize { let mut max_dot = -Real::MAX; let mut max_dot_i = 0; diff --git a/src/shape/polygonal_feature2d.rs b/src/shape/polygonal_feature2d.rs index 65e33b45..c5370d1b 100644 --- a/src/shape/polygonal_feature2d.rs +++ b/src/shape/polygonal_feature2d.rs @@ -1,4 +1,4 @@ -use crate::math::{Isometry, Point, Real, Vector}; +use crate::math::{Isometry, Point, Vector}; #[cfg(feature = "std")] use crate::query::{self, ContactManifold, TrackedContact}; use crate::shape::{PackedFeatureId, Segment}; @@ -8,7 +8,7 @@ use crate::shape::{PackedFeatureId, Segment}; #[derive(Debug)] pub struct PolygonalFeature { /// Up to two vertices forming this polygonal feature. - pub vertices: [Point; 2], + pub vertices: [Point; 2], /// The feature IDs of this polygon's vertices. pub vids: [PackedFeatureId; 2], /// The feature ID of this polygonal feature. @@ -41,7 +41,7 @@ impl From for PolygonalFeature { impl PolygonalFeature { /// Transforms the vertices of `self` by the given position `pos`. - pub fn transform_by(&mut self, pos: &Isometry) { + pub fn transform_by(&mut self, pos: &Isometry) { self.vertices[0] = pos * self.vertices[0]; self.vertices[1] = pos * self.vertices[1]; } @@ -49,10 +49,10 @@ impl PolygonalFeature { /// Computes the contacts between two polygonal features. #[cfg(feature = "std")] pub fn contacts( - pos12: &Isometry, - pos21: &Isometry, - sep_axis1: &Vector, - sep_axis2: &Vector, + pos12: &Isometry, + pos21: &Isometry, + sep_axis1: &Vector, + sep_axis2: &Vector, feature1: &Self, feature2: &Self, manifold: &mut ContactManifold, @@ -77,9 +77,9 @@ impl PolygonalFeature { /// This method assume we already know that at least one contact exists. #[cfg(feature = "std")] pub fn face_vertex_contacts( - pos12: &Isometry, + pos12: &Isometry, face1: &Self, - sep_axis1: &Vector, + sep_axis1: &Vector, vertex2: &Self, manifold: &mut ContactManifold, flipped: bool, @@ -107,9 +107,9 @@ impl PolygonalFeature { /// Computes the contacts between two polygonal faces. #[cfg(feature = "std")] pub fn face_face_contacts( - pos12: &Isometry, + pos12: &Isometry, face1: &Self, - normal1: &Vector, + normal1: &Vector, face2: &Self, manifold: &mut ContactManifold, flipped: bool, diff --git a/src/shape/polygonal_feature3d.rs b/src/shape/polygonal_feature3d.rs index ccc195f1..a2b87ebc 100644 --- a/src/shape/polygonal_feature3d.rs +++ b/src/shape/polygonal_feature3d.rs @@ -11,7 +11,7 @@ use na::Point2; #[derive(Debug, Clone)] pub struct PolygonalFeature { /// Up to four vertices forming this polygonal feature. - pub vertices: [Point; 4], + pub vertices: [Point; 4], /// The feature IDs of this polygon's vertices. pub vids: [PackedFeatureId; 4], /// The feature IDs of this polygon's edges. @@ -65,7 +65,7 @@ impl PolygonalFeature { } /// Transform each vertex of this polygonal feature by the given position `pos`. - pub fn transform_by(&mut self, pos: &Isometry) { + pub fn transform_by(&mut self, pos: &Isometry) { for p in &mut self.vertices[0..self.num_vertices] { *p = pos * *p; } @@ -74,10 +74,10 @@ impl PolygonalFeature { /// Computes all the contacts between two polygonal features. #[cfg(feature = "std")] pub fn contacts( - pos12: &Isometry, - _pos21: &Isometry, - sep_axis1: &Vector, - _sep_axis2: &Vector, + pos12: &Isometry, + _pos21: &Isometry, + sep_axis1: &Vector, + _sep_axis2: &Vector, feature1: &Self, feature2: &Self, manifold: &mut ContactManifold, @@ -93,9 +93,9 @@ impl PolygonalFeature { #[cfg(feature = "std")] fn contacts_edge_edge( - pos12: &Isometry, + pos12: &Isometry, face1: &PolygonalFeature, - sep_axis1: &Vector, + sep_axis1: &Vector, face2: &PolygonalFeature, manifold: &mut ContactManifold, flipped: bool, @@ -206,9 +206,9 @@ impl PolygonalFeature { #[cfg(feature = "std")] fn contacts_face_face( - pos12: &Isometry, + pos12: &Isometry, face1: &PolygonalFeature, - sep_axis1: &Vector, + sep_axis1: &Vector, face2: &PolygonalFeature, manifold: &mut ContactManifold, flipped: bool, diff --git a/src/shape/polygonal_feature_map.rs b/src/shape/polygonal_feature_map.rs index d5c331e7..f22185ad 100644 --- a/src/shape/polygonal_feature_map.rs +++ b/src/shape/polygonal_feature_map.rs @@ -1,10 +1,11 @@ -use crate::math::{Real, Vector}; +use crate::math::Vector; use crate::shape::{Cuboid, PolygonalFeature, Segment, SupportMap, Triangle}; use na::Unit; #[cfg(feature = "dim3")] use { crate::{ math::Point, + math::Real, shape::{Cone, Cylinder, PackedFeatureId}, }, approx::AbsDiffEq, @@ -16,7 +17,7 @@ use na::{ComplexField, RealField}; // for .abs() and .copysign() /// Trait implemented by convex shapes with features with polyhedral approximations. pub trait PolygonalFeatureMap: SupportMap { /// Compute the support polygonal face of `self` towards the `dir`. - fn local_support_feature(&self, dir: &Unit>, out_feature: &mut PolygonalFeature); + fn local_support_feature(&self, dir: &Unit, out_feature: &mut PolygonalFeature); // TODO: this is currently just a workaround for https://github.com/dimforge/rapier/issues/417 // until we get a better way to deal with the issue without breaking internal edges @@ -28,26 +29,26 @@ pub trait PolygonalFeatureMap: SupportMap { } impl PolygonalFeatureMap for Segment { - fn local_support_feature(&self, _: &Unit>, out_feature: &mut PolygonalFeature) { + fn local_support_feature(&self, _: &Unit, out_feature: &mut PolygonalFeature) { *out_feature = PolygonalFeature::from(*self); } } impl PolygonalFeatureMap for Triangle { - fn local_support_feature(&self, dir: &Unit>, out_feature: &mut PolygonalFeature) { + fn local_support_feature(&self, dir: &Unit, out_feature: &mut PolygonalFeature) { *out_feature = self.support_face(**dir); } } impl PolygonalFeatureMap for Cuboid { - fn local_support_feature(&self, dir: &Unit>, out_feature: &mut PolygonalFeature) { + fn local_support_feature(&self, dir: &Unit, out_feature: &mut PolygonalFeature) { *out_feature = self.support_face(**dir); } } #[cfg(feature = "dim3")] impl PolygonalFeatureMap for Cylinder { - fn local_support_feature(&self, dir: &Unit>, out_features: &mut PolygonalFeature) { + fn local_support_feature(&self, dir: &Unit, out_features: &mut PolygonalFeature) { use na::Vector2; // About feature ids. @@ -106,7 +107,7 @@ impl PolygonalFeatureMap for Cylinder { #[cfg(feature = "dim3")] impl PolygonalFeatureMap for Cone { - fn local_support_feature(&self, dir: &Unit>, out_features: &mut PolygonalFeature) { + fn local_support_feature(&self, dir: &Unit, out_features: &mut PolygonalFeature) { use na::Vector2; // About feature ids. It is very similar to the feature ids of cylinders. diff --git a/src/shape/polyline.rs b/src/shape/polyline.rs index 46662e12..a213908b 100644 --- a/src/shape/polyline.rs +++ b/src/shape/polyline.rs @@ -1,5 +1,5 @@ use crate::bounding_volume::Aabb; -use crate::math::{Isometry, Point, Real, Vector}; +use crate::math::{Isometry, Point, Vector}; use crate::partitioning::Qbvh; use crate::query::{PointProjection, PointQueryWithLocation}; use crate::shape::composite_shape::SimdCompositeShape; @@ -19,13 +19,13 @@ use na::ComplexField; // for .abs() /// A polyline. pub struct Polyline { qbvh: Qbvh, - vertices: Vec>, + vertices: Vec, indices: Vec<[u32; 2]>, } impl Polyline { /// Creates a new polyline from a vertex buffer and an index buffer. - pub fn new(vertices: Vec>, indices: Option>) -> Self { + pub fn new(vertices: Vec, indices: Option>) -> Self { let indices = indices.unwrap_or_else(|| (0..vertices.len() as u32 - 1).map(|i| [i, i + 1]).collect()); let data = indices.iter().enumerate().map(|(i, idx)| { @@ -47,7 +47,7 @@ impl Polyline { } /// Compute the axis-aligned bounding box of this polyline. - pub fn aabb(&self, pos: &Isometry) -> Aabb { + pub fn aabb(&self, pos: &Isometry) -> Aabb { self.qbvh.root_aabb().transform_by(pos) } @@ -98,7 +98,7 @@ impl Polyline { } /// The vertex buffer of this mesh. - pub fn vertices(&self) -> &[Point] { + pub fn vertices(&self) -> &[Point] { &self.vertices[..] } @@ -117,7 +117,7 @@ impl Polyline { } /// Computes a scaled version of this polyline. - pub fn scaled(mut self, scale: &Vector) -> Self { + pub fn scaled(mut self, scale: &Vector) -> Self { self.vertices .iter_mut() .for_each(|pt| pt.coords.component_mul_assign(scale)); @@ -223,7 +223,7 @@ impl Polyline { /// These properties are not checked. pub fn project_local_point_assuming_solid_interior_ccw( &self, - point: Point, + point: Point, #[cfg(feature = "dim3")] axis: u8, ) -> (PointProjection, (u32, SegmentPointLocation)) { let mut proj = self.project_local_point_and_get_location(&point, false); @@ -283,7 +283,7 @@ impl SimdCompositeShape for Polyline { fn map_part_at( &self, i: u32, - f: &mut dyn FnMut(Option<&Isometry>, &dyn Shape, Option<&dyn NormalConstraints>), + f: &mut dyn FnMut(Option<&Isometry>, &dyn Shape, Option<&dyn NormalConstraints>), ) { let tri = self.segment(i); f(None, &tri, None) @@ -303,11 +303,7 @@ impl TypedSimdCompositeShape for Polyline { fn map_typed_part_at( &self, i: u32, - mut f: impl FnMut( - Option<&Isometry>, - &Self::PartShape, - Option<&Self::PartNormalConstraints>, - ), + mut f: impl FnMut(Option<&Isometry>, &Self::PartShape, Option<&Self::PartNormalConstraints>), ) { let seg = self.segment(i); f(None, &seg, None) @@ -317,7 +313,7 @@ impl TypedSimdCompositeShape for Polyline { fn map_untyped_part_at( &self, i: u32, - mut f: impl FnMut(Option<&Isometry>, &dyn Shape, Option<&dyn NormalConstraints>), + mut f: impl FnMut(Option<&Isometry>, &dyn Shape, Option<&dyn NormalConstraints>), ) { let seg = self.segment(i); f(None, &seg, None) diff --git a/src/shape/round_shape.rs b/src/shape/round_shape.rs index ddf2859f..0641692c 100644 --- a/src/shape/round_shape.rs +++ b/src/shape/round_shape.rs @@ -19,11 +19,11 @@ pub struct RoundShape { } impl SupportMap for RoundShape { - fn local_support_point(&self, dir: &Vector) -> Point { + fn local_support_point(&self, dir: &Vector) -> Point { self.local_support_point_toward(&Unit::new_normalize(*dir)) } - fn local_support_point_toward(&self, dir: &Unit>) -> Point { + fn local_support_point_toward(&self, dir: &Unit) -> Point { self.inner_shape.local_support_point_toward(dir) + **dir * self.border_radius } } @@ -37,11 +37,11 @@ pub(crate) struct RoundShapeRef<'a, S: ?Sized> { } impl SupportMap for RoundShapeRef<'_, S> { - fn local_support_point(&self, dir: &Vector) -> Point { + fn local_support_point(&self, dir: &Vector) -> Point { self.local_support_point_toward(&Unit::new_normalize(*dir)) } - fn local_support_point_toward(&self, dir: &Unit>) -> Point { + fn local_support_point_toward(&self, dir: &Unit) -> Point { self.inner_shape.local_support_point_toward(dir) + **dir * self.border_radius } } diff --git a/src/shape/segment.rs b/src/shape/segment.rs index 41b598cc..71982e3d 100644 --- a/src/shape/segment.rs +++ b/src/shape/segment.rs @@ -21,9 +21,9 @@ use rkyv::{bytecheck, CheckBytes}; #[repr(C)] pub struct Segment { /// The segment first point. - pub a: Point, + pub a: Point, /// The segment second point. - pub b: Point, + pub b: Point, } /// Logical description of the location of a point on a triangle. @@ -55,17 +55,17 @@ impl SegmentPointLocation { impl Segment { /// Creates a new segment from two points. #[inline] - pub fn new(a: Point, b: Point) -> Segment { + pub fn new(a: Point, b: Point) -> Segment { Segment { a, b } } /// Creates the reference to a segment from the reference to an array of two points. - pub fn from_array(arr: &[Point; 2]) -> &Segment { + pub fn from_array(arr: &[Point; 2]) -> &Segment { unsafe { mem::transmute(arr) } } /// Computes a scaled version of this segment. - pub fn scaled(self, scale: &Vector) -> Self { + pub fn scaled(self, scale: &Vector) -> Self { Self::new( na::Scale::from(*scale) * self.a, na::Scale::from(*scale) * self.b, @@ -75,7 +75,7 @@ impl Segment { /// The direction of this segment scaled by its length. /// /// Points from `self.a` toward `self.b`. - pub fn scaled_direction(&self) -> Vector { + pub fn scaled_direction(&self) -> Vector { self.b - self.a } @@ -93,13 +93,13 @@ impl Segment { /// /// Points from `self.a()` toward `self.b()`. /// Returns `None` is both points are equal. - pub fn direction(&self) -> Option>> { + pub fn direction(&self) -> Option> { Unit::try_new(self.scaled_direction(), crate::math::DEFAULT_EPSILON) } /// In 2D, the not-normalized counterclockwise normal of this segment. #[cfg(feature = "dim2")] - pub fn scaled_normal(&self) -> Vector { + pub fn scaled_normal(&self) -> Vector { let dir = self.scaled_direction(); Vector::new(dir.y, -dir.x) } @@ -107,7 +107,7 @@ impl Segment { /// The not-normalized counterclockwise normal of this segment, assuming it lies on the plane /// with the normal collinear to the given axis (0 = X, 1 = Y, 2 = Z). #[cfg(feature = "dim3")] - pub fn scaled_planar_normal(&self, plane_axis: u8) -> Vector { + pub fn scaled_planar_normal(&self, plane_axis: u8) -> Vector { let dir = self.scaled_direction(); match plane_axis { 0 => Vector::new(0.0, dir.z, -dir.y), @@ -119,20 +119,20 @@ impl Segment { /// In 2D, the normalized counterclockwise normal of this segment. #[cfg(feature = "dim2")] - pub fn normal(&self) -> Option>> { + pub fn normal(&self) -> Option> { Unit::try_new(self.scaled_normal(), crate::math::DEFAULT_EPSILON) } /// Returns `None`. Exists only for API similarity with the 2D parry. #[cfg(feature = "dim3")] - pub fn normal(&self) -> Option>> { + pub fn normal(&self) -> Option> { None } /// The normalized counterclockwise normal of this segment, assuming it lies on the plane /// with the normal collinear to the given axis (0 = X, 1 = Y, 2 = Z). #[cfg(feature = "dim3")] - pub fn planar_normal(&self, plane_axis: u8) -> Option>> { + pub fn planar_normal(&self, plane_axis: u8) -> Option> { Unit::try_new( self.scaled_planar_normal(plane_axis), crate::math::DEFAULT_EPSILON, @@ -140,12 +140,12 @@ impl Segment { } /// Applies the isometry `m` to the vertices of this segment and returns the resulting segment. - pub fn transformed(&self, m: &Isometry) -> Self { + pub fn transformed(&self, m: &Isometry) -> Self { Segment::new(m * self.a, m * self.b) } /// Computes the point at the given location. - pub fn point_at(&self, location: &SegmentPointLocation) -> Point { + pub fn point_at(&self, location: &SegmentPointLocation) -> Point { match *location { SegmentPointLocation::OnVertex(0) => self.a, SegmentPointLocation::OnVertex(1) => self.b, @@ -157,7 +157,7 @@ impl Segment { } /// The normal of the given feature of this shape. - pub fn feature_normal(&self, feature: FeatureId) -> Option>> { + pub fn feature_normal(&self, feature: FeatureId) -> Option> { if let Some(direction) = self.direction() { match feature { FeatureId::Vertex(id) => { @@ -196,7 +196,7 @@ impl Segment { impl SupportMap for Segment { #[inline] - fn local_support_point(&self, dir: &Vector) -> Point { + fn local_support_point(&self, dir: &Vector) -> Point { if self.a.coords.dot(dir) > self.b.coords.dot(dir) { self.a } else { @@ -205,15 +205,15 @@ impl SupportMap for Segment { } } -impl From<[Point; 2]> for Segment { - fn from(arr: [Point; 2]) -> Self { +impl From<[Point; 2]> for Segment { + fn from(arr: [Point; 2]) -> Self { *Self::from_array(&arr) } } /* impl ConvexPolyhedron for Segment { - fn vertex(&self, id: FeatureId) -> Point { + fn vertex(&self, id: FeatureId) -> Point { if id.unwrap_vertex() == 0 { self.a } else { @@ -222,7 +222,7 @@ impl ConvexPolyhedron for Segment { } #[cfg(feature = "dim3")] - fn edge(&self, _: FeatureId) -> (Point, Point, FeatureId, FeatureId) { + fn edge(&self, _: FeatureId) -> (Point, Point, FeatureId, FeatureId) { (self.a, self.b, FeatureId::Vertex(0), FeatureId::Vertex(1)) } @@ -260,8 +260,8 @@ impl ConvexPolyhedron for Segment { #[cfg(feature = "dim2")] fn support_face_toward( &self, - m: &Isometry, - dir: &Unit>, + m: &Isometry, + dir: &Unit, face: &mut ConvexPolygonalFeature, ) { let seg_dir = self.scaled_direction(); @@ -277,8 +277,8 @@ impl ConvexPolyhedron for Segment { #[cfg(feature = "dim3")] fn support_face_toward( &self, - m: &Isometry, - _: &Unit>, + m: &Isometry, + _: &Unit, face: &mut ConvexPolygonalFeature, ) { face.clear(); @@ -291,8 +291,8 @@ impl ConvexPolyhedron for Segment { fn support_feature_toward( &self, - transform: &Isometry, - dir: &Unit>, + transform: &Isometry, + dir: &Unit, eps: Real, face: &mut ConvexPolygonalFeature, ) { @@ -329,7 +329,7 @@ impl ConvexPolyhedron for Segment { } } - fn support_feature_id_toward(&self, local_dir: &Unit>) -> FeatureId { + fn support_feature_id_toward(&self, local_dir: &Unit) -> FeatureId { if let Some(seg_dir) = self.direction() { let eps: Real = na::convert::(f64::consts::PI / 180.0); let seps = ComplexField::sin(eps); diff --git a/src/shape/shape.rs b/src/shape/shape.rs index 23a7a074..7d71436a 100644 --- a/src/shape/shape.rs +++ b/src/shape/shape.rs @@ -349,14 +349,14 @@ pub trait Shape: RayCast + PointQuery + DowncastSync { /// if a non-uniform scale is provided and Self as a [`Ball`], then the result will be discretized /// (based on the `num_subdivisions` parameter) as a `ConvexPolyhedron` (in 3D) or `ConvexPolygon` (in 2D). #[cfg(feature = "std")] - fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option>; + fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option>; /// Computes the [`Aabb`] of this shape with the given position. - fn compute_aabb(&self, position: &Isometry) -> Aabb { + fn compute_aabb(&self, position: &Isometry) -> Aabb { self.compute_local_aabb().transform_by(position) } /// Computes the bounding-sphere of this shape with the given position. - fn compute_bounding_sphere(&self, position: &Isometry) -> BoundingSphere { + fn compute_bounding_sphere(&self, position: &Isometry) -> BoundingSphere { self.compute_local_bounding_sphere().transform_by(position) } @@ -408,17 +408,13 @@ pub trait Shape: RayCast + PointQuery + DowncastSync { // } /// The shape's normal at the given point located on a specific feature. - fn feature_normal_at_point( - &self, - _feature: FeatureId, - _point: &Point, - ) -> Option>> { + fn feature_normal_at_point(&self, _feature: FeatureId, _point: &Point) -> Option> { None } /// Computes the swept [`Aabb`] of this shape, i.e., the space it would occupy by moving from /// the given start position to the given end position. - fn compute_swept_aabb(&self, start_pos: &Isometry, end_pos: &Isometry) -> Aabb { + fn compute_swept_aabb(&self, start_pos: &Isometry, end_pos: &Isometry) -> Aabb { let aabb1 = self.compute_aabb(start_pos); let aabb2 = self.compute_aabb(end_pos); aabb1.merged(&aabb2) @@ -655,7 +651,7 @@ impl Shape for Ball { } #[cfg(feature = "std")] - fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { + fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { let scaled = self.scaled(scale, num_subdivisions)?; Some(scaled.either::<_, _, Box>(|x| Box::new(x), |x| Box::new(x))) } @@ -668,7 +664,7 @@ impl Shape for Ball { self.local_bounding_sphere() } - fn compute_aabb(&self, position: &Isometry) -> Aabb { + fn compute_aabb(&self, position: &Isometry) -> Aabb { self.aabb(position) } @@ -702,11 +698,7 @@ impl Shape for Ball { /// The shape's normal at the given point located on a specific feature. #[inline] - fn feature_normal_at_point( - &self, - _: FeatureId, - point: &Point, - ) -> Option>> { + fn feature_normal_at_point(&self, _: FeatureId, point: &Point) -> Option> { Unit::try_new(point.coords, crate::math::DEFAULT_EPSILON) } } @@ -718,7 +710,7 @@ impl Shape for Cuboid { } #[cfg(feature = "std")] - fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { + fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { Some(Box::new(self.scaled(scale))) } @@ -730,7 +722,7 @@ impl Shape for Cuboid { self.local_bounding_sphere() } - fn compute_aabb(&self, position: &Isometry) -> Aabb { + fn compute_aabb(&self, position: &Isometry) -> Aabb { self.aabb(position) } @@ -766,11 +758,7 @@ impl Shape for Cuboid { Some((self as &dyn PolygonalFeatureMap, 0.0)) } - fn feature_normal_at_point( - &self, - feature: FeatureId, - _point: &Point, - ) -> Option>> { + fn feature_normal_at_point(&self, feature: FeatureId, _point: &Point) -> Option> { self.feature_normal(feature) } } @@ -782,7 +770,7 @@ impl Shape for Capsule { } #[cfg(feature = "std")] - fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { + fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { let scaled = self.scaled(scale, num_subdivisions)?; Some(scaled.either::<_, _, Box>(|x| Box::new(x), |x| Box::new(x))) } @@ -795,7 +783,7 @@ impl Shape for Capsule { self.local_bounding_sphere() } - fn compute_aabb(&self, position: &Isometry) -> Aabb { + fn compute_aabb(&self, position: &Isometry) -> Aabb { self.aabb(position) } @@ -839,7 +827,7 @@ impl Shape for Triangle { } #[cfg(feature = "std")] - fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { + fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { Some(Box::new(self.scaled(scale))) } @@ -851,7 +839,7 @@ impl Shape for Triangle { self.local_bounding_sphere() } - fn compute_aabb(&self, position: &Isometry) -> Aabb { + fn compute_aabb(&self, position: &Isometry) -> Aabb { self.aabb(position) } @@ -891,11 +879,7 @@ impl Shape for Triangle { Some((self as &dyn PolygonalFeatureMap, 0.0)) } - fn feature_normal_at_point( - &self, - _feature: FeatureId, - _point: &Point, - ) -> Option>> { + fn feature_normal_at_point(&self, _feature: FeatureId, _point: &Point) -> Option> { #[cfg(feature = "dim2")] return None; #[cfg(feature = "dim3")] @@ -910,7 +894,7 @@ impl Shape for Segment { } #[cfg(feature = "std")] - fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { + fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { Some(Box::new(self.scaled(scale))) } @@ -922,7 +906,7 @@ impl Shape for Segment { self.local_bounding_sphere() } - fn compute_aabb(&self, position: &Isometry) -> Aabb { + fn compute_aabb(&self, position: &Isometry) -> Aabb { self.aabb(position) } @@ -958,11 +942,7 @@ impl Shape for Segment { Some((self as &dyn PolygonalFeatureMap, 0.0)) } - fn feature_normal_at_point( - &self, - feature: FeatureId, - _point: &Point, - ) -> Option>> { + fn feature_normal_at_point(&self, feature: FeatureId, _point: &Point) -> Option> { self.feature_normal(feature) } } @@ -973,7 +953,7 @@ impl Shape for Compound { Box::new(self.clone()) } - fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { + fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { use super::SharedShape; let scaled: Vec<_> = self @@ -1001,7 +981,7 @@ impl Shape for Compound { self.local_bounding_sphere() } - fn compute_aabb(&self, position: &Isometry) -> Aabb { + fn compute_aabb(&self, position: &Isometry) -> Aabb { self.local_aabb().transform_by(position) } @@ -1041,7 +1021,7 @@ impl Shape for Polyline { Box::new(self.clone()) } - fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { + fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { Some(Box::new(self.clone().scaled(scale))) } @@ -1053,7 +1033,7 @@ impl Shape for Polyline { self.local_bounding_sphere() } - fn compute_aabb(&self, position: &Isometry) -> Aabb { + fn compute_aabb(&self, position: &Isometry) -> Aabb { self.aabb(position) } @@ -1091,7 +1071,7 @@ impl Shape for TriMesh { Box::new(self.clone()) } - fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { + fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { Some(Box::new(self.clone().scaled(scale))) } @@ -1103,7 +1083,7 @@ impl Shape for TriMesh { self.local_bounding_sphere() } - fn compute_aabb(&self, position: &Isometry) -> Aabb { + fn compute_aabb(&self, position: &Isometry) -> Aabb { self.aabb(position) } @@ -1131,11 +1111,7 @@ impl Shape for TriMesh { } /// Gets the normal of the triangle represented by `feature`. - fn feature_normal_at_point( - &self, - _feature: FeatureId, - _point: &Point, - ) -> Option>> { + fn feature_normal_at_point(&self, _feature: FeatureId, _point: &Point) -> Option> { #[cfg(feature = "dim2")] return None; #[cfg(feature = "dim3")] @@ -1154,7 +1130,7 @@ impl Shape for HeightField { Box::new(self.clone()) } - fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { + fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { Some(Box::new(self.clone().scaled(scale))) } @@ -1166,7 +1142,7 @@ impl Shape for HeightField { self.local_bounding_sphere() } - fn compute_aabb(&self, position: &Isometry) -> Aabb { + fn compute_aabb(&self, position: &Isometry) -> Aabb { self.aabb(position) } @@ -1200,7 +1176,7 @@ impl Shape for ConvexPolygon { Box::new(self.clone()) } - fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { + fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { Some(Box::new(self.clone().scaled(scale)?)) } @@ -1212,7 +1188,7 @@ impl Shape for ConvexPolygon { self.local_bounding_sphere() } - fn compute_aabb(&self, position: &Isometry) -> Aabb { + fn compute_aabb(&self, position: &Isometry) -> Aabb { self.aabb(position) } @@ -1251,11 +1227,7 @@ impl Shape for ConvexPolygon { Some((self as &dyn PolygonalFeatureMap, 0.0)) } - fn feature_normal_at_point( - &self, - feature: FeatureId, - _point: &Point, - ) -> Option>> { + fn feature_normal_at_point(&self, feature: FeatureId, _point: &Point) -> Option> { self.feature_normal(feature) } } @@ -1267,7 +1239,7 @@ impl Shape for ConvexPolyhedron { Box::new(self.clone()) } - fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { + fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { Some(Box::new(self.clone().scaled(scale)?)) } @@ -1279,7 +1251,7 @@ impl Shape for ConvexPolyhedron { self.local_bounding_sphere() } - fn compute_aabb(&self, position: &Isometry) -> Aabb { + fn compute_aabb(&self, position: &Isometry) -> Aabb { self.aabb(position) } @@ -1319,11 +1291,7 @@ impl Shape for ConvexPolyhedron { Some((self as &dyn PolygonalFeatureMap, 0.0)) } - fn feature_normal_at_point( - &self, - feature: FeatureId, - _point: &Point, - ) -> Option>> { + fn feature_normal_at_point(&self, feature: FeatureId, _point: &Point) -> Option> { self.feature_normal(feature) } } @@ -1336,7 +1304,7 @@ impl Shape for Cylinder { } #[cfg(feature = "std")] - fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { + fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { let scaled = self.scaled(scale, num_subdivisions)?; Some(scaled.either::<_, _, Box>(|x| Box::new(x), |x| Box::new(x))) } @@ -1349,7 +1317,7 @@ impl Shape for Cylinder { self.local_bounding_sphere() } - fn compute_aabb(&self, position: &Isometry) -> Aabb { + fn compute_aabb(&self, position: &Isometry) -> Aabb { self.aabb(position) } @@ -1394,7 +1362,7 @@ impl Shape for Cone { } #[cfg(feature = "std")] - fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { + fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { let scaled = self.scaled(scale, num_subdivisions)?; Some(scaled.either::<_, _, Box>(|x| Box::new(x), |x| Box::new(x))) } @@ -1407,7 +1375,7 @@ impl Shape for Cone { self.local_bounding_sphere() } - fn compute_aabb(&self, position: &Isometry) -> Aabb { + fn compute_aabb(&self, position: &Isometry) -> Aabb { self.aabb(position) } @@ -1454,7 +1422,7 @@ impl Shape for HalfSpace { } #[cfg(feature = "std")] - fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { + fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { Some(Box::new(self.scaled(scale)?)) } @@ -1466,7 +1434,7 @@ impl Shape for HalfSpace { self.local_bounding_sphere() } - fn compute_aabb(&self, position: &Isometry) -> Aabb { + fn compute_aabb(&self, position: &Isometry) -> Aabb { self.aabb(position) } @@ -1507,7 +1475,7 @@ macro_rules! impl_shape_for_round_shape( } #[cfg(feature = "std")] - fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { + fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { $t(self, scale, num_subdivisions) } @@ -1519,7 +1487,7 @@ macro_rules! impl_shape_for_round_shape( self.inner_shape.local_bounding_sphere().loosened(self.border_radius) } - fn compute_aabb(&self, position: &Isometry) -> Aabb { + fn compute_aabb(&self, position: &Isometry) -> Aabb { self.inner_shape.aabb(position).loosened(self.border_radius) } @@ -1563,7 +1531,7 @@ macro_rules! impl_shape_for_round_shape( impl_shape_for_round_shape!( Cuboid, RoundCuboid, - (|this: &Self, scale: &Vector, _num_subdivisions: u32| { + (|this: &Self, scale: &Vector, _num_subdivisions: u32| { let shape = RoundShape { border_radius: this.border_radius, inner_shape: this.inner_shape.scaled(scale), @@ -1575,7 +1543,7 @@ impl_shape_for_round_shape!( impl_shape_for_round_shape!( Triangle, RoundTriangle, - (|this: &Self, scale: &Vector, _num_subdivisions: u32| { + (|this: &Self, scale: &Vector, _num_subdivisions: u32| { let shape = RoundShape { border_radius: this.border_radius, inner_shape: this.inner_shape.scaled(scale), @@ -1589,7 +1557,7 @@ impl_shape_for_round_shape!( impl_shape_for_round_shape!( ConvexPolygon, RoundConvexPolygon, - (|this: &Self, scale: &Vector, _num_subdivisions: u32| { + (|this: &Self, scale: &Vector, _num_subdivisions: u32| { let shape = RoundShape { border_radius: this.border_radius, inner_shape: this.inner_shape.clone().scaled(scale)?, @@ -1602,7 +1570,7 @@ impl_shape_for_round_shape!( impl_shape_for_round_shape!( Cylinder, RoundCylinder, - (|this: &Self, scale: &Vector, num_subdivisions: u32| { + (|this: &Self, scale: &Vector, num_subdivisions: u32| { Some( this.inner_shape .scaled(scale, num_subdivisions)? @@ -1627,7 +1595,7 @@ impl_shape_for_round_shape!( impl_shape_for_round_shape!( Cone, RoundCone, - (|this: &Self, scale: &Vector, num_subdivisions: u32| { + (|this: &Self, scale: &Vector, num_subdivisions: u32| { Some( this.inner_shape .scaled(scale, num_subdivisions)? @@ -1654,7 +1622,7 @@ impl_shape_for_round_shape!( impl_shape_for_round_shape!( ConvexPolyhedron, RoundConvexPolyhedron, - (|this: &Self, scale: &Vector, _num_subdivisions: u32| { + (|this: &Self, scale: &Vector, _num_subdivisions: u32| { let shape = RoundShape { border_radius: this.border_radius, inner_shape: this.inner_shape.clone().scaled(scale)?, diff --git a/src/shape/shared_shape.rs b/src/shape/shared_shape.rs index eb2beeff..f32e20bf 100644 --- a/src/shape/shared_shape.rs +++ b/src/shape/shared_shape.rs @@ -60,7 +60,7 @@ impl SharedShape { } /// Initialize a compound shape defined by its subshapes. - pub fn compound(shapes: Vec<(Isometry, SharedShape)>) -> Self { + pub fn compound(shapes: Vec<(Isometry, SharedShape)>) -> Self { let raw_shapes = shapes.into_iter().map(|s| (s.0, s.1)).collect(); let compound = Compound::new(raw_shapes); SharedShape(Arc::new(compound)) @@ -72,7 +72,7 @@ impl SharedShape { } /// Initialize a plane shape defined by its outward normal. - pub fn halfspace(outward_normal: Unit>) -> Self { + pub fn halfspace(outward_normal: Unit) -> Self { SharedShape(Arc::new(HalfSpace::new(outward_normal))) } @@ -143,7 +143,7 @@ impl SharedShape { } /// Initialize a capsule shape from its endpoints and radius. - pub fn capsule(a: Point, b: Point, radius: Real) -> Self { + pub fn capsule(a: Point, b: Point, radius: Real) -> Self { SharedShape(Arc::new(Capsule::new(a, b, radius))) } @@ -167,21 +167,16 @@ impl SharedShape { } /// Initialize a segment shape from its endpoints. - pub fn segment(a: Point, b: Point) -> Self { + pub fn segment(a: Point, b: Point) -> Self { SharedShape(Arc::new(Segment::new(a, b))) } /// Initializes a triangle shape. - pub fn triangle(a: Point, b: Point, c: Point) -> Self { + pub fn triangle(a: Point, b: Point, c: Point) -> Self { SharedShape(Arc::new(Triangle::new(a, b, c))) } /// Initializes a triangle shape with round corners. - pub fn round_triangle( - a: Point, - b: Point, - c: Point, - border_radius: Real, - ) -> Self { + pub fn round_triangle(a: Point, b: Point, c: Point, border_radius: Real) -> Self { SharedShape(Arc::new(RoundShape { inner_shape: Triangle::new(a, b, c), border_radius, @@ -191,13 +186,13 @@ impl SharedShape { /// Initializes a polyline shape defined by its vertex and index buffers. /// /// If no index buffer is provided, the polyline is assumed to describe a line strip. - pub fn polyline(vertices: Vec>, indices: Option>) -> Self { + pub fn polyline(vertices: Vec, indices: Option>) -> Self { SharedShape(Arc::new(Polyline::new(vertices, indices))) } /// Initializes a triangle mesh shape defined by its vertex and index buffers. pub fn trimesh( - vertices: Vec>, + vertices: Vec, indices: Vec<[u32; 3]>, ) -> Result { Ok(SharedShape(Arc::new(TriMesh::new(vertices, indices)?))) @@ -206,7 +201,7 @@ impl SharedShape { /// Initializes a triangle mesh shape defined by its vertex and index buffers and /// pre-processing flags. pub fn trimesh_with_flags( - vertices: Vec>, + vertices: Vec, indices: Vec<[u32; 3]>, flags: TriMeshFlags, ) -> Result { @@ -217,14 +212,14 @@ impl SharedShape { /// Initializes a compound shape obtained from the decomposition of the given trimesh (in 3D) or /// polyline (in 2D) into convex parts. - pub fn convex_decomposition(vertices: &[Point], indices: &[[u32; DIM]]) -> Self { + pub fn convex_decomposition(vertices: &[Point], indices: &[[u32; DIM]]) -> Self { Self::convex_decomposition_with_params(vertices, indices, &VHACDParameters::default()) } /// Initializes a compound shape obtained from the decomposition of the given trimesh (in 3D) or /// polyline (in 2D) into convex parts dilated with round corners. pub fn round_convex_decomposition( - vertices: &[Point], + vertices: &[Point], indices: &[[u32; DIM]], border_radius: Real, ) -> Self { @@ -239,7 +234,7 @@ impl SharedShape { /// Initializes a compound shape obtained from the decomposition of the given trimesh (in 3D) or /// polyline (in 2D) into convex parts. pub fn convex_decomposition_with_params( - vertices: &[Point], + vertices: &[Point], indices: &[[u32; DIM]], params: &VHACDParameters, ) -> Self { @@ -266,7 +261,7 @@ impl SharedShape { /// Initializes a compound shape obtained from the decomposition of the given trimesh (in 3D) or /// polyline (in 2D) into convex parts dilated with round corners. pub fn round_convex_decomposition_with_params( - vertices: &[Point], + vertices: &[Point], indices: &[[u32; DIM]], params: &VHACDParameters, border_radius: Real, @@ -292,7 +287,7 @@ impl SharedShape { } /// Creates a new shared shape that is the convex-hull of the given points. - pub fn convex_hull(points: &[Point]) -> Option { + pub fn convex_hull(points: &[Point]) -> Option { #[cfg(feature = "dim2")] return ConvexPolygon::from_convex_hull(points).map(|ch| SharedShape(Arc::new(ch))); #[cfg(feature = "dim3")] @@ -303,7 +298,7 @@ impl SharedShape { /// given set of points assumed to form a convex polyline (no convex-hull will be automatically /// computed). #[cfg(feature = "dim2")] - pub fn convex_polyline(points: Vec>) -> Option { + pub fn convex_polyline(points: Vec) -> Option { ConvexPolygon::from_convex_polyline(points).map(|ch| SharedShape(Arc::new(ch))) } @@ -311,13 +306,13 @@ impl SharedShape { /// given set of points assumed to form a convex mesh (no convex-hull will be automatically /// computed). #[cfg(feature = "dim3")] - pub fn convex_mesh(points: Vec>, indices: &[[u32; 3]]) -> Option { + pub fn convex_mesh(points: Vec, indices: &[[u32; 3]]) -> Option { ConvexPolyhedron::from_convex_mesh(points, indices).map(|ch| SharedShape(Arc::new(ch))) } /// Creates a new shared shape with rounded corners that is the /// convex-hull of the given points, dilated by `border_radius`. - pub fn round_convex_hull(points: &[Point], border_radius: Real) -> Option { + pub fn round_convex_hull(points: &[Point], border_radius: Real) -> Option { #[cfg(feature = "dim2")] return ConvexPolygon::from_convex_hull(points).map(|ch| { SharedShape(Arc::new(RoundShape { @@ -338,7 +333,7 @@ impl SharedShape { /// given set of points assumed to form a convex polyline (no convex-hull will be automatically /// computed). #[cfg(feature = "dim2")] - pub fn round_convex_polyline(points: Vec>, border_radius: Real) -> Option { + pub fn round_convex_polyline(points: Vec, border_radius: Real) -> Option { ConvexPolygon::from_convex_polyline(points).map(|ch| { SharedShape(Arc::new(RoundShape { inner_shape: ch, @@ -352,7 +347,7 @@ impl SharedShape { /// computed). #[cfg(feature = "dim3")] pub fn round_convex_mesh( - points: Vec>, + points: Vec, indices: &[[u32; 3]], border_radius: Real, ) -> Option { @@ -367,14 +362,14 @@ impl SharedShape { /// Initializes a heightfield shape defined by its set of height and a scale /// factor along each coordinate axis. #[cfg(feature = "dim2")] - pub fn heightfield(heights: na::DVector, scale: Vector) -> Self { + pub fn heightfield(heights: na::DVector, scale: Vector) -> Self { SharedShape(Arc::new(HeightField::new(heights, scale))) } /// Initializes a heightfield shape on the x-z plane defined by its set of height and a scale /// factor along each coordinate axis. #[cfg(feature = "dim3")] - pub fn heightfield(heights: na::DMatrix, scale: Vector) -> Self { + pub fn heightfield(heights: na::DMatrix, scale: Vector) -> Self { SharedShape(Arc::new(HeightField::new(heights, scale))) } @@ -383,7 +378,7 @@ impl SharedShape { #[cfg(feature = "dim3")] pub fn heightfield_with_flags( heights: na::DMatrix, - scale: Vector, + scale: Vector, flags: HeightFieldFlags, ) -> Self { SharedShape(Arc::new(HeightField::with_flags(heights, scale, flags))) diff --git a/src/shape/support_map.rs b/src/shape/support_map.rs index a153016f..003f34f6 100644 --- a/src/shape/support_map.rs +++ b/src/shape/support_map.rs @@ -1,6 +1,6 @@ //! Traits for support mapping based shapes. -use crate::math::{Isometry, Point, Real, Vector}; +use crate::math::{Isometry, Point, Vector}; use na::Unit; /// Traits of convex shapes representable by a support mapping function. @@ -12,10 +12,10 @@ pub trait SupportMap { // // A support function is a function associating a vector to the shape point which maximizes // their dot product. - fn local_support_point(&self, dir: &Vector) -> Point; + fn local_support_point(&self, dir: &Vector) -> Point; /// Same as `self.local_support_point` except that `dir` is normalized. - fn local_support_point_toward(&self, dir: &Unit>) -> Point { + fn local_support_point_toward(&self, dir: &Unit) -> Point { self.local_support_point(dir.as_ref()) } @@ -23,17 +23,13 @@ pub trait SupportMap { // // A support function is a function associating a vector to the shape point which maximizes // their dot product. - fn support_point(&self, transform: &Isometry, dir: &Vector) -> Point { + fn support_point(&self, transform: &Isometry, dir: &Vector) -> Point { let local_dir = transform.inverse_transform_vector(dir); transform * self.local_support_point(&local_dir) } /// Same as `self.support_point` except that `dir` is normalized. - fn support_point_toward( - &self, - transform: &Isometry, - dir: &Unit>, - ) -> Point { + fn support_point_toward(&self, transform: &Isometry, dir: &Unit) -> Point { let local_dir = Unit::new_unchecked(transform.inverse_transform_vector(dir)); transform * self.local_support_point_toward(&local_dir) } diff --git a/src/shape/tetrahedron.rs b/src/shape/tetrahedron.rs index 649fda40..75dbc0e5 100644 --- a/src/shape/tetrahedron.rs +++ b/src/shape/tetrahedron.rs @@ -24,13 +24,13 @@ use rkyv::{bytecheck, CheckBytes}; #[repr(C)] pub struct Tetrahedron { /// The tetrahedron's first point. - pub a: Point, + pub a: Point, /// The tetrahedron's second point. - pub b: Point, + pub b: Point, /// The tetrahedron's third point. - pub c: Point, + pub c: Point, /// The tetrahedron's fourth point. - pub d: Point, + pub d: Point, } /// Logical description of the location of a point on a triangle. @@ -107,12 +107,12 @@ impl TetrahedronPointLocation { impl Tetrahedron { /// Creates a tetrahedron from four points. #[inline] - pub fn new(a: Point, b: Point, c: Point, d: Point) -> Tetrahedron { + pub fn new(a: Point, b: Point, c: Point, d: Point) -> Tetrahedron { Tetrahedron { a, b, c, d } } /// Creates the reference to a tetrahedron from the reference to an array of four points. - pub fn from_array(arr: &[Point; 4]) -> &Tetrahedron { + pub fn from_array(arr: &[Point; 4]) -> &Tetrahedron { unsafe { mem::transmute(arr) } } @@ -191,7 +191,7 @@ impl Tetrahedron { /// Computes the barycentric coordinates of the given point in the coordinate system of this tetrahedron. /// /// Returns `None` if this tetrahedron is degenerate. - pub fn barycentric_coordinates(&self, p: &Point) -> Option<[Real; 4]> { + pub fn barycentric_coordinates(&self, p: &Point) -> Option<[Real; 4]> { let ab = self.b - self.a; let ac = self.c - self.a; let ad = self.d - self.a; @@ -233,7 +233,7 @@ impl Tetrahedron { /// Computes the center of this tetrahedron. #[inline] - pub fn center(&self) -> Point { + pub fn center(&self) -> Point { utils::center(&[self.a, self.b, self.c, self.d]) } } diff --git a/src/shape/triangle.rs b/src/shape/triangle.rs index 4e23530c..55d064c7 100644 --- a/src/shape/triangle.rs +++ b/src/shape/triangle.rs @@ -30,11 +30,11 @@ use rkyv::{bytecheck, CheckBytes}; #[repr(C)] pub struct Triangle { /// The triangle first point. - pub a: Point, + pub a: Point, /// The triangle second point. - pub b: Point, + pub b: Point, /// The triangle third point. - pub c: Point, + pub c: Point, } /// Description of the location of a point on a triangle. @@ -110,8 +110,8 @@ pub enum TriangleOrientation { Degenerate, } -impl From<[Point; 3]> for Triangle { - fn from(arr: [Point; 3]) -> Self { +impl From<[Point; 3]> for Triangle { + fn from(arr: [Point; 3]) -> Self { *Self::from_array(&arr) } } @@ -119,18 +119,18 @@ impl From<[Point; 3]> for Triangle { impl Triangle { /// Creates a triangle from three points. #[inline] - pub fn new(a: Point, b: Point, c: Point) -> Triangle { + pub fn new(a: Point, b: Point, c: Point) -> Triangle { Triangle { a, b, c } } /// Creates the reference to a triangle from the reference to an array of three points. - pub fn from_array(arr: &[Point; 3]) -> &Triangle { + pub fn from_array(arr: &[Point; 3]) -> &Triangle { unsafe { mem::transmute(arr) } } /// Reference to an array containing the three vertices of this triangle. #[inline] - pub fn vertices(&self) -> &[Point; 3] { + pub fn vertices(&self) -> &[Point; 3] { unsafe { mem::transmute(self) } } @@ -140,7 +140,7 @@ impl Triangle { /// product). #[inline] #[cfg(feature = "dim3")] - pub fn normal(&self) -> Option>> { + pub fn normal(&self) -> Option> { Unit::try_new(self.scaled_normal(), crate::math::DEFAULT_EPSILON) } @@ -155,7 +155,7 @@ impl Triangle { } /// Computes a scaled version of this triangle. - pub fn scaled(self, scale: &Vector) -> Self { + pub fn scaled(self, scale: &Vector) -> Self { Self::new( na::Scale::from(*scale) * self.a, na::Scale::from(*scale) * self.b, @@ -165,19 +165,19 @@ impl Triangle { /// Returns a new triangle with vertices transformed by `m`. #[inline] - pub fn transformed(&self, m: &Isometry) -> Self { + pub fn transformed(&self, m: &Isometry) -> Self { Triangle::new(m * self.a, m * self.b, m * self.c) } /// The three edges scaled directions of this triangle: [B - A, C - B, A - C]. #[inline] - pub fn edges_scaled_directions(&self) -> [Vector; 3] { + pub fn edges_scaled_directions(&self) -> [Vector; 3] { [self.b - self.a, self.c - self.b, self.a - self.c] } /// Return the edge segment of this cuboid with a normal cone containing /// a direction that that maximizes the dot product with `local_dir`. - pub fn local_support_edge_segment(&self, dir: Vector) -> Segment { + pub fn local_support_edge_segment(&self, dir: Vector) -> Segment { let dots = na::Vector3::new( dir.dot(&self.a.coords), dir.dot(&self.b.coords), @@ -194,14 +194,14 @@ impl Triangle { /// Return the face of this triangle with a normal that maximizes /// the dot product with `dir`. #[cfg(feature = "dim3")] - pub fn support_face(&self, _dir: Vector) -> PolygonalFeature { + pub fn support_face(&self, _dir: Vector) -> PolygonalFeature { PolygonalFeature::from(*self) } /// Return the face of this triangle with a normal that maximizes /// the dot product with `dir`. #[cfg(feature = "dim2")] - pub fn support_face(&self, dir: Vector) -> PolygonalFeature { + pub fn support_face(&self, dir: Vector) -> PolygonalFeature { let mut best = 0; let mut best_dot = -Real::MAX; @@ -238,7 +238,7 @@ impl Triangle { /// [`Triangle::robust_scaled_normal`]. #[inline] #[cfg(feature = "dim3")] - pub fn scaled_normal(&self) -> Vector { + pub fn scaled_normal(&self) -> Vector { let ab = self.b - self.a; let ac = self.c - self.a; ab.cross(&ac) @@ -272,7 +272,7 @@ impl Triangle { /// This computes the min and max values of the dot products between each /// vertex of this triangle and `dir`. #[inline] - pub fn extents_on_dir(&self, dir: &Unit>) -> (Real, Real) { + pub fn extents_on_dir(&self, dir: &Unit) -> (Real, Real) { let a = self.a.coords.dot(dir); let b = self.b.coords.dot(dir); let c = self.c.coords.dot(dir); @@ -298,7 +298,7 @@ impl Triangle { } // // #[cfg(feature = "dim3")] - // fn support_feature_id_toward(&self, local_dir: &Unit>, eps: Real) -> FeatureId { + // fn support_feature_id_toward(&self, local_dir: &Unit, eps: Real) -> FeatureId { // if let Some(normal) = self.normal() { // let (seps, ceps) = ComplexField::sin_cos(eps); // @@ -387,7 +387,7 @@ impl Triangle { /// The geometric center of this triangle. #[inline] - pub fn center(&self) -> Point { + pub fn center(&self) -> Point { utils::center(&[self.a, self.b, self.c]) } @@ -400,7 +400,7 @@ impl Triangle { } /// The circumcircle of this triangle. - pub fn circumcircle(&self) -> (Point, Real) { + pub fn circumcircle(&self) -> (Point, Real) { let a = self.a - self.c; let b = self.b - self.c; @@ -482,7 +482,7 @@ impl Triangle { /// Tests if a point is inside of this triangle. #[cfg(feature = "dim2")] - pub fn contains_point(&self, p: &Point) -> bool { + pub fn contains_point(&self, p: &Point) -> bool { let ab = self.b - self.a; let bc = self.c - self.b; let ca = self.a - self.c; @@ -496,7 +496,7 @@ impl Triangle { /// Tests if a point is inside of this triangle. #[cfg(feature = "dim3")] - pub fn contains_point(&self, p: &Point) -> bool { + pub fn contains_point(&self, p: &Point) -> bool { const EPS: Real = crate::math::DEFAULT_EPSILON; let vb = self.b - self.a; @@ -540,7 +540,7 @@ impl Triangle { /// The normal of the given feature of this shape. #[cfg(feature = "dim3")] - pub fn feature_normal(&self, _: FeatureId) -> Option>> { + pub fn feature_normal(&self, _: FeatureId) -> Option> { self.normal() } @@ -613,7 +613,7 @@ impl Triangle { impl SupportMap for Triangle { #[inline] - fn local_support_point(&self, dir: &Vector) -> Point { + fn local_support_point(&self, dir: &Vector) -> Point { let d1 = self.a.coords.dot(dir); let d2 = self.b.coords.dot(dir); let d3 = self.c.coords.dot(dir); @@ -635,7 +635,7 @@ impl SupportMap for Triangle { /* #[cfg(feature = "dim3")] impl ConvexPolyhedron for Triangle { - fn vertex(&self, id: FeatureId) -> Point { + fn vertex(&self, id: FeatureId) -> Point { match id.unwrap_vertex() { 0 => self.a, 1 => self.b, @@ -643,7 +643,7 @@ impl ConvexPolyhedron for Triangle { _ => panic!("Triangle vertex index out of bounds."), } } - fn edge(&self, id: FeatureId) -> (Point, Point, FeatureId, FeatureId) { + fn edge(&self, id: FeatureId) -> (Point, Point, FeatureId, FeatureId) { match id.unwrap_edge() { 0 => (self.a, self.b, FeatureId::Vertex(0), FeatureId::Vertex(1)), 1 => (self.b, self.c, FeatureId::Vertex(1), FeatureId::Vertex(2)), @@ -689,8 +689,8 @@ impl ConvexPolyhedron for Triangle { fn support_face_toward( &self, - m: &Isometry, - dir: &Unit>, + m: &Isometry, + dir: &Unit, face: &mut ConvexPolygonalFeature, ) { let normal = self.scaled_normal(); @@ -705,8 +705,8 @@ impl ConvexPolyhedron for Triangle { fn support_feature_toward( &self, - transform: &Isometry, - dir: &Unit>, + transform: &Isometry, + dir: &Unit, eps: Real, out: &mut ConvexPolygonalFeature, ) { @@ -732,7 +732,7 @@ impl ConvexPolyhedron for Triangle { } } - fn support_feature_id_toward(&self, local_dir: &Unit>) -> FeatureId { + fn support_feature_id_toward(&self, local_dir: &Unit) -> FeatureId { self.support_feature_id_toward(local_dir, na::convert::(f64::consts::PI / 180.0)) } } diff --git a/src/shape/triangle_pseudo_normals.rs b/src/shape/triangle_pseudo_normals.rs index 927d7333..a4207347 100644 --- a/src/shape/triangle_pseudo_normals.rs +++ b/src/shape/triangle_pseudo_normals.rs @@ -1,4 +1,4 @@ -use crate::math::{Real, UnitVector, Vector}; +use crate::math::{UnitVector, Vector}; use na::Vector3; #[cfg(feature = "std")] @@ -19,20 +19,20 @@ use crate::query::details::NormalConstraints; #[derive(Clone, Debug)] pub struct TrianglePseudoNormals { /// The triangle’s face normal. - pub face: UnitVector, + pub face: UnitVector, // TODO: if we switch this to providing pseudo-normals in a specific order // (e.g. in the same order as the triangle’s edges), then we should // think of fixing that order in the heightfield // triangle_pseudo_normals code. /// The edges pseudo-normals, in no particular order. - pub edges: [UnitVector; 3], + pub edges: [UnitVector; 3], } #[cfg(feature = "std")] impl NormalConstraints for TrianglePseudoNormals { /// Projects the given direction to it is contained in the polygonal /// cone defined `self`. - fn project_local_normal_mut(&self, dir: &mut Vector) -> bool { + fn project_local_normal_mut(&self, dir: &mut Vector) -> bool { let dot_face = dir.dot(&self.face); // Find the closest pseudo-normal. @@ -101,11 +101,11 @@ mod test { use super::NormalConstraints; - fn bisector(v1: Vector, v2: Vector) -> Vector { + fn bisector(v1: Vector, v2: Vector) -> Vector { (v1 + v2).normalize() } - fn bisector_y(v: Vector) -> Vector { + fn bisector_y(v: Vector) -> Vector { bisector(v, Vector::y()) } @@ -125,8 +125,8 @@ mod test { #[test] fn edge_pseudo_normals_projection_strictly_positive() { - let bisector = |v1: Vector, v2: Vector| (v1 + v2).normalize(); - let bisector_y = |v: Vector| bisector(v, Vector::y()); + let bisector = |v1: Vector, v2: Vector| (v1 + v2).normalize(); + let bisector_y = |v: Vector| bisector(v, Vector::y()); // The normal cones for this test will be fully contained in the +Y half-space. let cones_ref_dir = [ diff --git a/src/shape/trimesh.rs b/src/shape/trimesh.rs index 83b7c7ab..1e038ea7 100644 --- a/src/shape/trimesh.rs +++ b/src/shape/trimesh.rs @@ -1,5 +1,5 @@ use crate::bounding_volume::Aabb; -use crate::math::{Isometry, Point, Real, Vector}; +use crate::math::{Isometry, Point, Vector}; use crate::partitioning::Qbvh; use crate::shape::{FeatureId, Shape, Triangle, TrianglePseudoNormals, TypedSimdCompositeShape}; use crate::utils::HashablePartialEq; @@ -66,9 +66,9 @@ pub enum TriMeshBuilderError { #[cfg(feature = "dim3")] pub struct TriMeshPseudoNormals { /// The pseudo-normals of the vertices. - pub vertices_pseudo_normal: Vec>, + pub vertices_pseudo_normal: Vec, /// The pseudo-normals of the edges. - pub edges_pseudo_normal: Vec<[Vector; 3]>, + pub edges_pseudo_normal: Vec<[Vector; 3]>, } /// The connected-components of a triangle mesh. @@ -102,7 +102,7 @@ impl TriMeshConnectedComponents { /// /// The `mesh` must be the one used to generate `self`, otherwise it might panic or produce an /// unexpected result. - pub fn to_mesh_buffers(&self, mesh: &TriMesh) -> Vec<(Vec>, Vec<[u32; 3]>)> { + pub fn to_mesh_buffers(&self, mesh: &TriMesh) -> Vec<(Vec, Vec<[u32; 3]>)> { let mut result = vec![]; let mut new_vtx_index: Vec<_> = vec![u32::MAX; mesh.vertices.len()]; @@ -284,7 +284,7 @@ bitflags::bitflags! { /// A triangle mesh. pub struct TriMesh { qbvh: Qbvh, - vertices: Vec>, + vertices: Vec, indices: Vec<[u32; 3]>, #[cfg(feature = "dim3")] pub(crate) pseudo_normals: Option, @@ -301,16 +301,13 @@ impl fmt::Debug for TriMesh { impl TriMesh { /// Creates a new triangle mesh from a vertex buffer and an index buffer. - pub fn new( - vertices: Vec>, - indices: Vec<[u32; 3]>, - ) -> Result { + pub fn new(vertices: Vec, indices: Vec<[u32; 3]>) -> Result { Self::with_flags(vertices, indices, TriMeshFlags::empty()) } /// Creates a new triangle mesh from a vertex buffer and an index buffer, and flags controlling optional properties. pub fn with_flags( - vertices: Vec>, + vertices: Vec, indices: Vec<[u32; 3]>, flags: TriMeshFlags, ) -> Result { @@ -395,7 +392,7 @@ impl TriMesh { } /// Transforms in-place the vertices of this triangle mesh. - pub fn transform_vertices(&mut self, transform: &Isometry) { + pub fn transform_vertices(&mut self, transform: &Isometry) { self.vertices .iter_mut() .for_each(|pt| *pt = transform * *pt); @@ -417,7 +414,7 @@ impl TriMesh { } /// Returns a scaled version of this triangle mesh. - pub fn scaled(mut self, scale: &Vector) -> Self { + pub fn scaled(mut self, scale: &Vector) -> Self { self.vertices .iter_mut() .for_each(|pt| pt.coords.component_mul_assign(scale)); @@ -470,7 +467,7 @@ impl TriMesh { /// /// This operation may fail if the input polygon is invalid, e.g. it is non-simple or has zero surface area. #[cfg(feature = "dim2")] - pub fn from_polygon(vertices: Vec>) -> Option { + pub fn from_polygon(vertices: Vec) -> Option { triangulate_ear_clipping(&vertices).map(|indices| Self::new(vertices, indices).unwrap()) } @@ -545,9 +542,9 @@ impl TriMesh { let mut triangle_set = HashSet::default(); fn resolve_coord_id( - coord: &Point, - vtx_to_id: &mut HashMap>, u32>, - new_vertices: &mut Vec>, + coord: &Point, + vtx_to_id: &mut HashMap, u32>, + new_vertices: &mut Vec, ) -> u32 { let key = HashablePartialEq::new(*coord); let id = match vtx_to_id.entry(key) { @@ -936,7 +933,7 @@ impl TriMesh { #[cfg(feature = "dim3")] /// Gets the normal of the triangle represented by `feature`. - pub fn feature_normal(&self, feature: FeatureId) -> Option>> { + pub fn feature_normal(&self, feature: FeatureId) -> Option> { match feature { FeatureId::Face(i) => self .triangle(i % self.num_triangles() as u32) @@ -953,7 +950,7 @@ impl TriMesh { } /// Compute the axis-aligned bounding box of this triangle mesh. - pub fn aabb(&self, pos: &Isometry) -> Aabb { + pub fn aabb(&self, pos: &Isometry) -> Aabb { self.qbvh.root_aabb().transform_by(pos) } @@ -1025,7 +1022,7 @@ impl TriMesh { } /// The vertex buffer of this mesh. - pub fn vertices(&self) -> &[Point] { + pub fn vertices(&self) -> &[Point] { &self.vertices } @@ -1082,7 +1079,7 @@ impl SimdCompositeShape for TriMesh { fn map_part_at( &self, i: u32, - f: &mut dyn FnMut(Option<&Isometry>, &dyn Shape, Option<&dyn NormalConstraints>), + f: &mut dyn FnMut(Option<&Isometry>, &dyn Shape, Option<&dyn NormalConstraints>), ) { let tri = self.triangle(i); let normals = self.triangle_normal_constraints(i); @@ -1107,11 +1104,7 @@ impl TypedSimdCompositeShape for TriMesh { fn map_typed_part_at( &self, i: u32, - mut f: impl FnMut( - Option<&Isometry>, - &Self::PartShape, - Option<&Self::PartNormalConstraints>, - ), + mut f: impl FnMut(Option<&Isometry>, &Self::PartShape, Option<&Self::PartNormalConstraints>), ) { let tri = self.triangle(i); let pseudo_normals = self.triangle_normal_constraints(i); @@ -1122,7 +1115,7 @@ impl TypedSimdCompositeShape for TriMesh { fn map_untyped_part_at( &self, i: u32, - mut f: impl FnMut(Option<&Isometry>, &dyn Shape, Option<&dyn NormalConstraints>), + mut f: impl FnMut(Option<&Isometry>, &dyn Shape, Option<&dyn NormalConstraints>), ) { let tri = self.triangle(i); let pseudo_normals = self.triangle_normal_constraints(i); diff --git a/src/transformation/convex_hull_utils.rs b/src/transformation/convex_hull_utils.rs index 20fcf370..56ba236a 100644 --- a/src/transformation/convex_hull_utils.rs +++ b/src/transformation/convex_hull_utils.rs @@ -76,7 +76,7 @@ where /// Scale and center the given set of point depending on their Aabb. #[cfg(feature = "dim3")] -pub fn normalize(coords: &mut [Point]) -> (Point, Real) { +pub fn normalize(coords: &mut [Point]) -> (Point, Real) { let aabb = bounding_volume::details::local_point_cloud_aabb(&*coords); let diag = na::distance(&aabb.mins, &aabb.maxs); let center = aabb.center(); diff --git a/src/transformation/ear_clipping.rs b/src/transformation/ear_clipping.rs index d4527a56..a589a043 100644 --- a/src/transformation/ear_clipping.rs +++ b/src/transformation/ear_clipping.rs @@ -22,7 +22,7 @@ struct VertexInfo { } /// Updates the fields `pointiness` and `is_ear` for a given vertex index. -fn update_vertex(idx: usize, vertex_info: &mut VertexInfo, points: &[Point]) -> bool { +fn update_vertex(idx: usize, vertex_info: &mut VertexInfo, points: &[Point]) -> bool { // Get the point and its neighbors. let p = points[idx]; let p1 = points[vertex_info.p_prev]; @@ -54,7 +54,7 @@ fn update_vertex(idx: usize, vertex_info: &mut VertexInfo, points: &[Point } /// Ear clipping triangulation algorithm. -pub(crate) fn triangulate_ear_clipping(vertices: &[Point]) -> Option> { +pub(crate) fn triangulate_ear_clipping(vertices: &[Point]) -> Option> { let n_vertices = vertices.len(); // Create a new vector to hold the information about vertices. diff --git a/src/transformation/hertel_mehlhorn.rs b/src/transformation/hertel_mehlhorn.rs index 208b9193..867a221b 100644 --- a/src/transformation/hertel_mehlhorn.rs +++ b/src/transformation/hertel_mehlhorn.rs @@ -1,7 +1,7 @@ //! Hertel-Mehlhorn algorithm for convex partitioning. //! Based on , contributed by embotech AG. -use crate::math::{Point, Real}; +use crate::math::Point; use crate::utils::point_in_triangle::{corner_direction, Orientation}; /// Checks if the counter-clockwise polygon `poly` has an edge going counter-clockwise from `p1` to `p2`. @@ -27,7 +27,7 @@ fn find_edge_index_in_polygon(p1: u32, p2: u32, indices: &[u32]) -> Option<(usiz /// partitioning. /// /// This algorithm is described in . -pub fn hertel_mehlhorn(vertices: &[Point], indices: &[[u32; 3]]) -> Vec>> { +pub fn hertel_mehlhorn(vertices: &[Point], indices: &[[u32; 3]]) -> Vec> { hertel_mehlhorn_idx(vertices, indices) .into_iter() .map(|poly_indices| { @@ -40,7 +40,7 @@ pub fn hertel_mehlhorn(vertices: &[Point], indices: &[[u32; 3]]) -> Vec], indices: &[[u32; 3]]) -> Vec> { +pub fn hertel_mehlhorn_idx(vertices: &[Point], indices: &[[u32; 3]]) -> Vec> { let mut indices: Vec> = indices.iter().map(|indices| indices.to_vec()).collect(); // Iterate over all polygons. let mut i_poly1 = 0; diff --git a/src/transformation/mesh_intersection/mesh_intersection.rs b/src/transformation/mesh_intersection/mesh_intersection.rs index b83f539b..24a567db 100644 --- a/src/transformation/mesh_intersection/mesh_intersection.rs +++ b/src/transformation/mesh_intersection/mesh_intersection.rs @@ -66,10 +66,10 @@ impl Default for MeshIntersectionTolerances { /// The meshes must be oriented, have their half-edge topology computed, and must not be self-intersecting. /// The result mesh vertex coordinates are given in the local-space of `mesh1`. pub fn intersect_meshes( - pos1: &Isometry, + pos1: &Isometry, mesh1: &TriMesh, flip1: bool, - pos2: &Isometry, + pos2: &Isometry, mesh2: &TriMesh, flip2: bool, ) -> Result, MeshIntersectionError> { @@ -89,10 +89,10 @@ pub fn intersect_meshes( /// It allows to specify epsilons for how the algorithm will behave. /// See `MeshIntersectionTolerances` for details. pub fn intersect_meshes_with_tolerances( - pos1: &Isometry, + pos1: &Isometry, mesh1: &TriMesh, flip1: bool, - pos2: &Isometry, + pos2: &Isometry, mesh2: &TriMesh, flip2: bool, tolerances: MeshIntersectionTolerances, @@ -289,7 +289,7 @@ pub fn intersect_meshes_with_tolerances( } fn extract_connected_components( - pos12: &Isometry, + pos12: &Isometry, mesh1: &TriMesh, mesh2: &TriMesh, flip2: bool, @@ -617,8 +617,8 @@ fn merge_triangle_sets( mesh1: &TriMesh, mesh2: &TriMesh, triangle_constraints: &BTreeMap<&u32, Vec<[Point3; 2]>>, - pos1: &Isometry, - pos2: &Isometry, + pos1: &Isometry, + pos2: &Isometry, flip1: bool, flip2: bool, metadata: &MeshIntersectionTolerances, diff --git a/src/transformation/mesh_intersection/triangle_triangle_intersection.rs b/src/transformation/mesh_intersection/triangle_triangle_intersection.rs index 7e3d6d01..69274afd 100644 --- a/src/transformation/mesh_intersection/triangle_triangle_intersection.rs +++ b/src/transformation/mesh_intersection/triangle_triangle_intersection.rs @@ -11,7 +11,7 @@ use na::Point2; #[derive(Copy, Clone, Debug, Default)] pub struct TriangleTriangleIntersectionPoint { - pub p1: Point, + pub p1: Point, } #[derive(Clone, Debug)] @@ -118,7 +118,7 @@ pub(crate) fn triangle_triangle_intersection( let unit_normal2 = normal2.normalize(); if (tri1.a - tri2.a).dot(&unit_normal2) < EPS { let basis = unit_normal2.orthonormal_basis(); - let proj = |vect: Vector| Point2::new(vect.dot(&basis[0]), vect.dot(&basis[1])); + let proj = |vect: Vector| Point2::new(vect.dot(&basis[0]), vect.dot(&basis[1])); let mut intersections = vec![]; @@ -135,7 +135,7 @@ pub(crate) fn triangle_triangle_intersection( proj(tri2.c - tri2.a), ]; - let convert_loc = |loc, pts: &[Point; 3]| match loc { + let convert_loc = |loc, pts: &[Point; 3]| match loc { PolylinePointLocation::OnVertex(vid) => (FeatureId::Vertex(vid as u32), pts[vid]), PolylinePointLocation::OnEdge(vid1, vid2, bcoords) => ( match (vid1, vid2) { @@ -190,12 +190,12 @@ pub(crate) fn triangle_triangle_intersection( } fn segment_plane_intersection( - plane_center: &Point, - plane_normal: &Vector, + plane_center: &Point, + plane_normal: &Vector, segment: &Segment, eid: u32, vids: (u32, u32), -) -> Option<(Point, FeatureId)> { +) -> Option<(Point, FeatureId)> { let dir = segment.b - segment.a; let dir_norm = dir.norm(); @@ -229,7 +229,7 @@ fn debug_check_intersections( poly2: &[Point2], // Projection of tri2 on the basis `basis2` with the origin at tri2.a. intersections: &[TriangleTriangleIntersectionPoint], ) { - let proj = |vect: Vector| Point2::new(vect.dot(&basis[0]), vect.dot(&basis[1])); + let proj = |vect: Vector| Point2::new(vect.dot(&basis[0]), vect.dot(&basis[1])); let mut incorrect = false; for pt in intersections { if !tri1 diff --git a/src/transformation/polygon_intersection.rs b/src/transformation/polygon_intersection.rs index a770ae4b..4ceab441 100644 --- a/src/transformation/polygon_intersection.rs +++ b/src/transformation/polygon_intersection.rs @@ -670,50 +670,50 @@ mod test { let tris = [ ( Triangle::new( - Point2::new(-0.0008759537858568062, -2.0103871966663305), - Point2::new(0.3903908709629763, -1.3421764825890266), - Point2::new(1.3380817875388151, -2.0098007857739013), + Point2::new(-0.000_875_953_76, -2.010_387_2), + Point2::new(0.390_390_87, -1.342_176_4), + Point2::new(1.338_081_8, -2.009_800_7), ), Triangle::new( Point2::new(0.0, -0.0), - Point2::new(-0.0008759537858568062, -2.0103871966663305), - Point2::new(1.9991979155226394, -2.009511242880474), + Point2::new(-0.000_875_953_76, -2.010_387_2), + Point2::new(1.999_198, -2.009_511_2), ), ), ( Triangle::new( - Point2::new(0.7319315811016305, -0.00004046981523721891), - Point2::new(2.0004914907008944, -0.00011061077714557787), - Point2::new(1.1848406021956144, -0.8155712451545468), + Point2::new(0.731_931_57, -0.000_040_469_815), + Point2::new(2.000_491_4, -0.000_110_610_774), + Point2::new(1.184_840_6, -0.815_571_25), ), Triangle::new( Point2::new(0.0, 0.0), - Point2::new(0.00011061077714557787, -2.000024893134292), - Point2::new(2.0004914907008944, -0.00011061077714557787), + Point2::new(0.000_110_610_774, -2.000_024_8), + Point2::new(2.000_491_4, -0.000_110_610_774), ), ), ( Triangle::new( - Point2::new(-0.000049995168258705205, -0.9898801451981707), + Point2::new(-0.000_049_995_168, -0.989_880_14), Point2::new(0.0, -0.0), - Point2::new(0.583013294019752, -1.4170136900568633), + Point2::new(0.583_013_3, -1.417_013_6), ), Triangle::new( Point2::new(0.0, -0.0), - Point2::new(-0.00010101395240669591, -2.000027389553894), - Point2::new(2.000372544168497, 0.00010101395240669591), + Point2::new(-0.000_101_013_95, -2.000_027_4), + Point2::new(2.000_372_6, 0.000_101_013_95), ), ), ( Triangle::new( - Point2::new(-0.940565646581769, -0.939804943675256), + Point2::new(-0.940_565_65, -0.939_805), Point2::new(0.0, -0.0), - Point2::new(-0.001533592366792066, -0.9283586484736431), + Point2::new(-0.001_533_592_4, -0.928_358_7), ), Triangle::new( Point2::new(0.0, -0.0), - Point2::new(-2.00752629829582, -2.0059026672784825), - Point2::new(-0.0033081650580626698, -2.0025945022204197), + Point2::new(-2.007_526_4, -2.005_902_8), + Point2::new(-0.003_308_165_1, -2.002_594_5), ), ), ]; @@ -745,10 +745,10 @@ mod test { .is_inside_eps(pt, 1.0e-5)) ); for pt in &inter { - let proj1 = tri1.project_local_point(&pt, false); - let proj2 = tri2.project_local_point(&pt, false); - assert!(proj1.is_inside_eps(&pt, 1.0e-5)); - assert!(proj2.is_inside_eps(&pt, 1.0e-5)); + let proj1 = tri1.project_local_point(pt, false); + let proj2 = tri2.project_local_point(pt, false); + assert!(proj1.is_inside_eps(pt, 1.0e-5)); + assert!(proj2.is_inside_eps(pt, 1.0e-5)); } } } diff --git a/src/transformation/to_outline/ball_to_outline.rs b/src/transformation/to_outline/ball_to_outline.rs index 0d645efc..61887b28 100644 --- a/src/transformation/to_outline/ball_to_outline.rs +++ b/src/transformation/to_outline/ball_to_outline.rs @@ -45,7 +45,7 @@ fn unit_sphere_outline(nsubdiv: u32) -> (Vec>, Vec<[u32; 2]>) { /// Creates an hemisphere with a radius of 0.5. pub(crate) fn push_unit_hemisphere_outline( nsubdiv: u32, - pts: &mut Vec>, + pts: &mut Vec, idx: &mut Vec<[u32; 2]>, ) { let base_idx = pts.len() as u32; diff --git a/src/transformation/to_outline/cuboid_to_outline.rs b/src/transformation/to_outline/cuboid_to_outline.rs index 0552d07a..d4c342e5 100644 --- a/src/transformation/to_outline/cuboid_to_outline.rs +++ b/src/transformation/to_outline/cuboid_to_outline.rs @@ -1,11 +1,11 @@ use crate::bounding_volume::Aabb; -use crate::math::{Point, Real, Vector}; +use crate::math::{Point, Vector}; use crate::shape::Cuboid; use crate::transformation::utils; impl Aabb { /// Outlines this Aabb’s shape using polylines. - pub fn to_outline(&self) -> (Vec>, Vec<[u32; 2]>) { + pub fn to_outline(&self) -> (Vec, Vec<[u32; 2]>) { let center = self.center(); let half_extents = self.half_extents(); let mut cube_mesh = Cuboid::new(half_extents).to_outline(); @@ -16,7 +16,7 @@ impl Aabb { impl Cuboid { /// Outlines this cuboid’s shape using polylines. - pub fn to_outline(&self) -> (Vec>, Vec<[u32; 2]>) { + pub fn to_outline(&self) -> (Vec, Vec<[u32; 2]>) { let (vtx, idx) = unit_cuboid_outline(); (utils::scaled(vtx, self.half_extents * 2.0), idx) } @@ -27,7 +27,7 @@ impl Cuboid { * * The cuboid is centered at the origin, and has its half extents set to 0.5. */ -fn unit_cuboid_outline() -> (Vec>, Vec<[u32; 2]>) { +fn unit_cuboid_outline() -> (Vec, Vec<[u32; 2]>) { let aabb = Aabb::from_half_extents(Point::origin(), Vector::repeat(0.5)); ( aabb.vertices().to_vec(), diff --git a/src/transformation/to_outline/round_cuboid_to_outline.rs b/src/transformation/to_outline/round_cuboid_to_outline.rs index 13165c1b..84f5b7cc 100644 --- a/src/transformation/to_outline/round_cuboid_to_outline.rs +++ b/src/transformation/to_outline/round_cuboid_to_outline.rs @@ -1,11 +1,11 @@ use crate::bounding_volume::Aabb; -use crate::math::{Point, Real, Vector}; +use crate::math::{Point, Vector}; use crate::shape::RoundCuboid; use crate::transformation::utils; impl RoundCuboid { /// Outlines this round cuboid’s surface with polylines. - pub fn to_outline(&self, nsubdivs: u32) -> (Vec>, Vec<[u32; 2]>) { + pub fn to_outline(&self, nsubdivs: u32) -> (Vec, Vec<[u32; 2]>) { let aabb = Aabb::from_half_extents(Point::origin(), self.inner_shape.half_extents); let aabb_vtx = aabb.vertices(); let fidx = Aabb::FACES_VERTEX_IDS; diff --git a/src/transformation/to_outline/round_triangle_to_outline.rs b/src/transformation/to_outline/round_triangle_to_outline.rs index a2c12e6c..c159cc48 100644 --- a/src/transformation/to_outline/round_triangle_to_outline.rs +++ b/src/transformation/to_outline/round_triangle_to_outline.rs @@ -5,7 +5,7 @@ use crate::transformation::utils; impl RoundTriangle { /// Outlines this round triangle’s surface with polylines. - pub fn to_outline(&self, nsubdivs: u32) -> (Vec>, Vec<[u32; 2]>) { + pub fn to_outline(&self, nsubdivs: u32) -> (Vec, Vec<[u32; 2]>) { let tri = &self.inner_shape; let n = tri .normal() diff --git a/src/transformation/to_trimesh/ball_to_trimesh.rs b/src/transformation/to_trimesh/ball_to_trimesh.rs index 58f94e69..4b7c0c48 100644 --- a/src/transformation/to_trimesh/ball_to_trimesh.rs +++ b/src/transformation/to_trimesh/ball_to_trimesh.rs @@ -66,7 +66,7 @@ fn unit_sphere(ntheta_subdiv: u32, nphi_subdiv: u32) -> (Vec>, Vec< pub(crate) fn unit_hemisphere( ntheta_subdiv: u32, nphi_subdiv: u32, -) -> (Vec>, Vec<[u32; DIM]>) { +) -> (Vec, Vec<[u32; DIM]>) { let two_pi = Real::two_pi(); let pi_two = Real::frac_pi_2(); let dtheta = two_pi / (ntheta_subdiv as Real); diff --git a/src/transformation/to_trimesh/cuboid_to_trimesh.rs b/src/transformation/to_trimesh/cuboid_to_trimesh.rs index 5132cf17..814a6a48 100644 --- a/src/transformation/to_trimesh/cuboid_to_trimesh.rs +++ b/src/transformation/to_trimesh/cuboid_to_trimesh.rs @@ -1,11 +1,11 @@ use crate::bounding_volume::Aabb; -use crate::math::{Point, Real}; +use crate::math::Point; use crate::shape::Cuboid; use crate::transformation::utils; impl Aabb { /// Discretize the boundary of this Aabb as a triangle-mesh. - pub fn to_trimesh(&self) -> (Vec>, Vec<[u32; 3]>) { + pub fn to_trimesh(&self) -> (Vec, Vec<[u32; 3]>) { let center = self.center(); let half_extents = self.half_extents(); let mut cube_mesh = Cuboid::new(half_extents).to_trimesh(); @@ -16,7 +16,7 @@ impl Aabb { impl Cuboid { /// Discretize the boundary of this cuboid as a triangle-mesh. - pub fn to_trimesh(&self) -> (Vec>, Vec<[u32; 3]>) { + pub fn to_trimesh(&self) -> (Vec, Vec<[u32; 3]>) { let (vtx, idx) = unit_cuboid(); (utils::scaled(vtx, self.half_extents * 2.0), idx) } @@ -25,7 +25,7 @@ impl Cuboid { /// Generates a cuboid shape with a split index buffer. /// /// The cuboid is centered at the origin, and has its half extents set to 0.5. -fn unit_cuboid() -> (Vec>, Vec<[u32; 3]>) { +fn unit_cuboid() -> (Vec, Vec<[u32; 3]>) { #[cfg(feature = "dim3")] { let mut coords = Vec::with_capacity(8); diff --git a/src/transformation/utils.rs b/src/transformation/utils.rs index 210f8da1..0fa7f6bc 100644 --- a/src/transformation/utils.rs +++ b/src/transformation/utils.rs @@ -6,18 +6,18 @@ use crate::na::ComplexField; use {crate::math::DIM, num::Zero}; /// Applies in-place a transformation to an array of points. -pub fn transform(points: &mut [Point], m: Isometry) { +pub fn transform(points: &mut [Point], m: Isometry) { points.iter_mut().for_each(|p| *p = m * *p); } /// Returns the transformed version of a vector of points. -pub fn transformed(mut points: Vec>, m: Isometry) -> Vec> { +pub fn transformed(mut points: Vec, m: Isometry) -> Vec { transform(&mut points, m); points } /// Returns the transformed version of a vector of points. -pub fn scaled(mut points: Vec>, scale: Vector) -> Vec> { +pub fn scaled(mut points: Vec, scale: Vector) -> Vec { points .iter_mut() .for_each(|p| p.coords.component_mul_assign(&scale)); @@ -28,7 +28,7 @@ pub fn scaled(mut points: Vec>, scale: Vector) -> Vec>) { +pub fn push_circle(radius: Real, nsubdiv: u32, dtheta: Real, y: Real, out: &mut Vec) { let mut curr_theta = Real::zero(); for _ in 0..nsubdiv { @@ -45,7 +45,7 @@ pub fn push_circle(radius: Real, nsubdiv: u32, dtheta: Real, y: Real, out: &mut /// The circle is contained on the plane spanned by the `x` and `y` axis. #[inline] #[cfg(feature = "dim2")] -pub fn push_xy_arc(radius: Real, nsubdiv: u32, dtheta: Real, out: &mut Vec>) { +pub fn push_xy_arc(radius: Real, nsubdiv: u32, dtheta: Real, out: &mut Vec) { let mut curr_theta: Real = 0.0; for _ in 0..nsubdiv { @@ -183,11 +183,11 @@ pub fn push_open_circle_outline_indices(indices: &mut Vec<[u32; 2]>, range: std: /// the `start` and `end` points). #[cfg(feature = "dim3")] pub fn push_arc_and_idx( - center: Point, + center: Point, start: u32, end: u32, nsubdivs: u32, - out_vtx: &mut Vec>, + out_vtx: &mut Vec, out_idx: &mut Vec<[u32; 2]>, ) { let base = out_vtx.len() as u32; @@ -204,13 +204,7 @@ pub fn push_arc_and_idx( /// Pushes to `out` a set of points forming an arc starting at `start`, ending at `end` with /// revolution center at `center`. The curve is approximated by pushing `nsubdivs` points. /// The `start` and `end` point are not pushed to `out`. -pub fn push_arc( - center: Point, - start: Point, - end: Point, - nsubdivs: u32, - out: &mut Vec>, -) { +pub fn push_arc(center: Point, start: Point, end: Point, nsubdivs: u32, out: &mut Vec) { assert!(nsubdivs > 0); if let (Some((start_dir, start_len)), Some((end_dir, end_len))) = ( na::Unit::try_new_and_get(start - center, 0.0), @@ -268,7 +262,7 @@ pub fn apply_revolution( collapse_top: bool, circle_ranges: &[std::ops::Range], nsubdivs: u32, - out_vtx: &mut Vec>, // Must be set to the half-profile. + out_vtx: &mut Vec, // Must be set to the half-profile. out_idx: &mut Vec<[u32; 2]>, ) { use na::RealField; diff --git a/src/transformation/vhacd/vhacd.rs b/src/transformation/vhacd/vhacd.rs index 79271b82..de004485 100644 --- a/src/transformation/vhacd/vhacd.rs +++ b/src/transformation/vhacd/vhacd.rs @@ -22,13 +22,13 @@ use crate::transformation::voxelization::{VoxelSet, VoxelizedVolume}; use std::sync::Arc; #[cfg(feature = "dim2")] -type ConvexHull = Vec>; +type ConvexHull = Vec; #[cfg(feature = "dim3")] -type ConvexHull = (Vec>, Vec<[u32; 3]>); +type ConvexHull = (Vec, Vec<[u32; 3]>); #[derive(Copy, Clone, Debug)] pub(crate) struct CutPlane { - pub abc: Vector, + pub abc: Vector, pub d: Real, pub axis: u8, pub index: u32, @@ -56,7 +56,7 @@ impl VHACD { /// hulls resulting from the convex decomposition will use the voxels vertices). pub fn decompose( params: &VHACDParameters, - points: &[Point], + points: &[Point], indices: &[[u32; DIM]], keep_voxel_to_primitives_map: bool, ) -> Self { @@ -103,7 +103,7 @@ impl VHACD { } #[cfg(feature = "dim2")] - fn compute_preferred_cutting_direction(eigenvalues: &Vector) -> (Vector, Real) { + fn compute_preferred_cutting_direction(eigenvalues: &Vector) -> (Vector, Real) { let vx = eigenvalues.y * eigenvalues.y; let vy = eigenvalues.x * eigenvalues.x; @@ -129,7 +129,7 @@ impl VHACD { } #[cfg(feature = "dim3")] - fn compute_preferred_cutting_direction(eigenvalues: &Vector) -> (Vector, Real) { + fn compute_preferred_cutting_direction(eigenvalues: &Vector) -> (Vector, Real) { let vx = (eigenvalues.y - eigenvalues.z) * (eigenvalues.y - eigenvalues.z); let vy = (eigenvalues.x - eigenvalues.z) * (eigenvalues.x - eigenvalues.z); let vz = (eigenvalues.x - eigenvalues.y) * (eigenvalues.x - eigenvalues.y); @@ -194,7 +194,7 @@ impl VHACD { input_voxels: &VoxelSet, input_voxels_ch: &ConvexHull, planes: &[CutPlane], - preferred_cutting_direction: &Vector, + preferred_cutting_direction: &Vector, w: Real, alpha: Real, beta: Real, @@ -463,9 +463,9 @@ impl VHACD { /// `self`. pub fn compute_primitive_intersections( &self, - points: &[Point], + points: &[Point], indices: &[[u32; DIM]], - ) -> Vec>> { + ) -> Vec> { self.voxel_parts .iter() .map(|part| part.compute_primitive_intersections(points, indices)) @@ -480,9 +480,9 @@ impl VHACD { #[cfg(feature = "dim2")] pub fn compute_exact_convex_hulls( &self, - points: &[Point], + points: &[Point], indices: &[[u32; DIM]], - ) -> Vec>> { + ) -> Vec> { self.voxel_parts .iter() .map(|part| part.compute_exact_convex_hull(points, indices)) @@ -497,9 +497,9 @@ impl VHACD { #[cfg(feature = "dim3")] pub fn compute_exact_convex_hulls( &self, - points: &[Point], + points: &[Point], indices: &[[u32; DIM]], - ) -> Vec<(Vec>, Vec<[u32; DIM]>)> { + ) -> Vec<(Vec, Vec<[u32; DIM]>)> { self.voxel_parts .iter() .map(|part| part.compute_exact_convex_hull(points, indices)) @@ -512,7 +512,7 @@ impl VHACD { /// Use `compute_exact_convex_hulls` instead if the original polyline/trimesh geometry /// needs to be taken into account. #[cfg(feature = "dim2")] - pub fn compute_convex_hulls(&self, downsampling: u32) -> Vec>> { + pub fn compute_convex_hulls(&self, downsampling: u32) -> Vec> { let downsampling = downsampling.max(1); self.voxel_parts .iter() @@ -526,10 +526,7 @@ impl VHACD { /// Use `compute_exact_convex_hulls` instead if the original polyline/trimesh geometry /// needs to be taken into account. #[cfg(feature = "dim3")] - pub fn compute_convex_hulls( - &self, - downsampling: u32, - ) -> Vec<(Vec>, Vec<[u32; DIM]>)> { + pub fn compute_convex_hulls(&self, downsampling: u32) -> Vec<(Vec, Vec<[u32; DIM]>)> { let downsampling = downsampling.max(1); self.voxel_parts .iter() @@ -543,10 +540,10 @@ fn compute_concavity(volume: Real, volume_ch: Real, volume0: Real) -> Real { } fn clip_mesh( - points: &[Point], + points: &[Point], plane: &CutPlane, - positive_part: &mut Vec>, - negative_part: &mut Vec>, + positive_part: &mut Vec, + negative_part: &mut Vec, ) { for pt in points { let d = plane.abc.dot(&pt.coords) + plane.d; @@ -563,7 +560,7 @@ fn clip_mesh( } #[cfg(feature = "dim2")] -fn convex_hull(vertices: &[Point]) -> Vec> { +fn convex_hull(vertices: &[Point]) -> Vec { if vertices.len() > 1 { crate::transformation::convex_hull(vertices) } else { @@ -572,7 +569,7 @@ fn convex_hull(vertices: &[Point]) -> Vec> { } #[cfg(feature = "dim3")] -fn convex_hull(vertices: &[Point]) -> (Vec>, Vec<[u32; DIM]>) { +fn convex_hull(vertices: &[Point]) -> (Vec, Vec<[u32; DIM]>) { if vertices.len() > 2 { crate::transformation::convex_hull(vertices) } else { @@ -581,7 +578,7 @@ fn convex_hull(vertices: &[Point]) -> (Vec>, Vec<[u32; DIM]>) } #[cfg(feature = "dim2")] -fn compute_volume(polygon: &[Point]) -> Real { +fn compute_volume(polygon: &[Point]) -> Real { if !polygon.is_empty() { crate::mass_properties::details::convex_polygon_area_and_center_of_mass(polygon).0 } else { @@ -590,7 +587,7 @@ fn compute_volume(polygon: &[Point]) -> Real { } #[cfg(feature = "dim3")] -fn compute_volume(mesh: &(Vec>, Vec<[u32; DIM]>)) -> Real { +fn compute_volume(mesh: &(Vec, Vec<[u32; DIM]>)) -> Real { if !mesh.0.is_empty() { crate::mass_properties::details::trimesh_signed_volume_and_center_of_mass(&mesh.0, &mesh.1) .0 diff --git a/src/transformation/voxelization/voxel_set.rs b/src/transformation/voxelization/voxel_set.rs index 5b37ff00..e0e84009 100644 --- a/src/transformation/voxelization/voxel_set.rs +++ b/src/transformation/voxelization/voxel_set.rs @@ -18,20 +18,20 @@ use super::{FillMode, VoxelizedVolume}; use crate::bounding_volume::Aabb; -use crate::math::{Matrix, Point, Real, Vector, DIM}; +use crate::math::{Matrix, Point, PointT, Real, Vector, VectorT, DIM}; use crate::transformation::vhacd::CutPlane; use std::sync::Arc; #[cfg(feature = "dim2")] -type ConvexHull = Vec>; +type ConvexHull = Vec; #[cfg(feature = "dim3")] -type ConvexHull = (Vec>, Vec<[u32; DIM]>); +type ConvexHull = (Vec, Vec<[u32; DIM]>); /// A voxel. #[derive(Copy, Clone, Debug)] pub struct Voxel { /// The integer coordinates of the voxel as part of the voxel grid. - pub coords: Point, + pub coords: PointT, /// Is this voxel on the surface of the volume (i.e. not inside of it)? pub is_on_surface: bool, /// Range of indices (to be looked up into the `VoxelSet` primitive map) @@ -42,7 +42,7 @@ pub struct Voxel { impl Default for Voxel { fn default() -> Self { Self { - coords: Point::origin(), + coords: PointT::origin(), is_on_surface: false, intersections_range: (0, 0), } @@ -54,12 +54,12 @@ impl Default for Voxel { /// It only contains voxels that are considered as "full" after a voxelization. pub struct VoxelSet { /// The 3D origin of this voxel-set. - pub origin: Point, + pub origin: Point, /// The scale factor between the voxel integer coordinates and their /// actual float world-space coordinates. pub scale: Real, - pub(crate) min_bb_voxels: Point, - pub(crate) max_bb_voxels: Point, + pub(crate) min_bb_voxels: PointT, + pub(crate) max_bb_voxels: PointT, pub(crate) voxels: Vec, pub(crate) intersections: Arc>, pub(crate) primitive_classes: Arc>, @@ -76,8 +76,8 @@ impl VoxelSet { pub fn new() -> Self { Self { origin: Point::origin(), - min_bb_voxels: Point::origin(), - max_bb_voxels: Vector::repeat(1).into(), + min_bb_voxels: PointT::origin(), + max_bb_voxels: VectorT::repeat(1).into(), scale: 1.0, voxels: Vec::new(), intersections: Arc::new(Vec::new()), @@ -111,7 +111,7 @@ impl VoxelSet { /// * `keep_voxel_to_primitives_map` - If set to `true` a map between the voxels /// and the primitives (3D triangles or 2D segments) it intersects will be computed. pub fn voxelize( - points: &[Point], + points: &[Point], indices: &[[u32; DIM]], resolution: u32, fill_mode: FillMode, @@ -128,12 +128,12 @@ impl VoxelSet { } /// The minimal coordinates of the integer bounding-box of the voxels in this set. - pub fn min_bb_voxels(&self) -> Point { + pub fn min_bb_voxels(&self) -> PointT { self.min_bb_voxels } /// The maximal coordinates of the integer bounding-box of the voxels in this set. - pub fn max_bb_voxels(&self) -> Point { + pub fn max_bb_voxels(&self) -> PointT { self.max_bb_voxels } @@ -142,11 +142,11 @@ impl VoxelSet { self.voxel_volume() * self.voxels.len() as Real } - fn get_voxel_point(&self, voxel: &Voxel) -> Point { + fn get_voxel_point(&self, voxel: &Voxel) -> Point { self.get_point(na::convert(voxel.coords)) } - pub(crate) fn get_point(&self, voxel: Point) -> Point { + pub(crate) fn get_point(&self, voxel: Point) -> Point { self.origin + voxel.coords * self.scale } @@ -194,9 +194,9 @@ impl VoxelSet { #[cfg(feature = "dim2")] pub fn compute_exact_convex_hull( &self, - points: &[Point], + points: &[Point], indices: &[[u32; DIM]], - ) -> Vec> { + ) -> Vec { self.do_compute_exact_convex_hull(points, indices) } @@ -207,17 +207,13 @@ impl VoxelSet { #[cfg(feature = "dim3")] pub fn compute_exact_convex_hull( &self, - points: &[Point], + points: &[Point], indices: &[[u32; DIM]], - ) -> (Vec>, Vec<[u32; DIM]>) { + ) -> (Vec, Vec<[u32; DIM]>) { self.do_compute_exact_convex_hull(points, indices) } - fn do_compute_exact_convex_hull( - &self, - points: &[Point], - indices: &[[u32; DIM]], - ) -> ConvexHull { + fn do_compute_exact_convex_hull(&self, points: &[Point], indices: &[[u32; DIM]]) -> ConvexHull { assert!(!self.intersections.is_empty(), "Cannot compute exact convex hull without voxel-to-primitives-map. Consider passing voxel_to_primitives_map = true to the voxelizer."); let mut surface_points = Vec::new(); @@ -305,9 +301,9 @@ impl VoxelSet { /// `voxel_to_primitives_map = true`. pub fn compute_primitive_intersections( &self, - points: &[Point], + points: &[Point], indices: &[[u32; DIM]], - ) -> Vec> { + ) -> Vec { assert!(!self.intersections.is_empty(), "Cannot compute primitive intersections voxel-to-primitives-map. Consider passing voxel_to_primitives_map = true to the voxelizer."); let mut surface_points = Vec::new(); @@ -361,7 +357,7 @@ impl VoxelSet { /// regular intervals. Useful to save some computation times if an exact result isn't need. /// Use `0` to make sure no voxel is being ignored. #[cfg(feature = "dim2")] - pub fn compute_convex_hull(&self, sampling: u32) -> Vec> { + pub fn compute_convex_hull(&self, sampling: u32) -> Vec { let mut points = Vec::new(); // Grab all the points. @@ -385,7 +381,7 @@ impl VoxelSet { /// regular intervals. Useful to save some computation times if an exact result isn't need. /// Use `0` to make sure no voxel is being ignored. #[cfg(feature = "dim3")] - pub fn compute_convex_hull(&self, sampling: u32) -> (Vec>, Vec<[u32; DIM]>) { + pub fn compute_convex_hull(&self, sampling: u32) -> (Vec, Vec<[u32; DIM]>) { let mut points = Vec::new(); // Grab all the points. @@ -403,7 +399,7 @@ impl VoxelSet { } /// Gets the vertices of the given voxel. - fn map_voxel_points(&self, voxel: &Voxel, mut f: impl FnMut(Point)) { + fn map_voxel_points(&self, voxel: &Voxel, mut f: impl FnMut(Point)) { let ijk = voxel.coords.coords.map(|e| e as Real); #[cfg(feature = "dim2")] @@ -434,8 +430,8 @@ impl VoxelSet { pub(crate) fn intersect( &self, plane: &CutPlane, - positive_pts: &mut Vec>, - negative_pts: &mut Vec>, + positive_pts: &mut Vec, + negative_pts: &mut Vec, sampling: u32, ) { let num_voxels = self.voxels.len(); @@ -566,7 +562,7 @@ impl VoxelSet { &self, base_index: u32, is_on_surface: bool, - ) -> (Vec>, Vec<[u32; DIM]>) { + ) -> (Vec, Vec<[u32; DIM]>) { let mut vertices = Vec::new(); let mut indices = Vec::new(); @@ -592,7 +588,7 @@ impl VoxelSet { (vertices, indices) } - pub(crate) fn compute_principal_axes(&self) -> Vector { + pub(crate) fn compute_principal_axes(&self) -> Vector { let num_voxels = self.voxels.len(); if num_voxels == 0 { return Vector::zeros(); @@ -645,7 +641,7 @@ impl VoxelSet { } #[cfg(feature = "dim2")] -fn convex_hull(vertices: &[Point]) -> Vec> { +fn convex_hull(vertices: &[Point]) -> Vec { if vertices.len() > 1 { crate::transformation::convex_hull(vertices) } else { @@ -654,7 +650,7 @@ fn convex_hull(vertices: &[Point]) -> Vec> { } #[cfg(feature = "dim3")] -fn convex_hull(vertices: &[Point]) -> (Vec>, Vec<[u32; DIM]>) { +fn convex_hull(vertices: &[Point]) -> (Vec, Vec<[u32; DIM]>) { if vertices.len() > 2 { crate::transformation::convex_hull(vertices) } else { diff --git a/src/transformation/voxelization/voxelized_volume.rs b/src/transformation/voxelization/voxelized_volume.rs index 12e6a3be..32a1c358 100644 --- a/src/transformation/voxelization/voxelized_volume.rs +++ b/src/transformation/voxelization/voxelized_volume.rs @@ -17,7 +17,7 @@ // > THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. use crate::bounding_volume::Aabb; -use crate::math::{Point, Real, Vector, DIM}; +use crate::math::{Point, PointT, Real, Vector, VectorT, DIM}; use crate::query; use crate::transformation::voxelization::{Voxel, VoxelSet}; use std::sync::Arc; @@ -107,7 +107,7 @@ struct VoxelData { /// A cubic volume filled with voxels. pub struct VoxelizedVolume { - origin: Point, + origin: Point, scale: Real, resolution: [u32; DIM], values: Vec, @@ -130,7 +130,7 @@ impl VoxelizedVolume { /// * `keep_voxel_to_primitives_map` - If set to `true` a map between the voxels /// and the primitives (3D triangles or 2D segments) it intersects will be computed. pub fn voxelize( - points: &[Point], + points: &[Point], indices: &[[u32; DIM]], resolution: u32, fill_mode: FillMode, @@ -190,8 +190,8 @@ impl VoxelizedVolume { let mut tri_pts = [Point::origin(); DIM]; let box_half_size = Vector::repeat(0.5); - let mut ijk0 = Vector::repeat(0u32); - let mut ijk1 = Vector::repeat(0u32); + let mut ijk0 = VectorT::repeat(0u32); + let mut ijk1 = VectorT::repeat(0u32); let detect_self_intersections = fill_mode.detect_self_intersections(); #[cfg(feature = "dim2")] @@ -214,9 +214,9 @@ impl VoxelizedVolume { assert!(k < result.resolution[2]); #[cfg(feature = "dim2")] - let ijk = Vector::new(i, j); + let ijk = VectorT::new(i, j); #[cfg(feature = "dim3")] - let ijk = Vector::new(i, j, k); + let ijk = VectorT::new(i, j, k); if c == 0 { ijk0 = ijk; @@ -230,7 +230,7 @@ impl VoxelizedVolume { ijk0.apply(|e| *e = e.saturating_sub(1)); ijk1 = ijk1 .map(|e| e + 1) - .inf(&Point::from(result.resolution).coords); + .inf(&PointT::from(result.resolution).coords); #[cfg(feature = "dim2")] let range_k = 0..1; @@ -739,7 +739,7 @@ impl VoxelizedVolume { /// This conversion is extremely naive: it will simply collect all the 12 triangles forming /// the faces of each voxel. No actual boundary extraction is done. #[cfg(feature = "dim3")] - pub fn to_trimesh(&self, value: VoxelValue) -> (Vec>, Vec<[u32; DIM]>) { + pub fn to_trimesh(&self, value: VoxelValue) -> (Vec, Vec<[u32; DIM]>) { let mut vertices = Vec::new(); let mut indices = Vec::new(); @@ -807,9 +807,9 @@ impl From for VoxelSet { let id = shape.voxel_index(i, j, k) as usize; let value = shape.values[id]; #[cfg(feature = "dim2")] - let coords = Point::new(i, j); + let coords = PointT::new(i, j); #[cfg(feature = "dim3")] - let coords = Point::new(i, j, k); + let coords = PointT::new(i, j, k); if value == VoxelValue::PrimitiveInsideSurface { let voxel = Voxel { @@ -863,7 +863,7 @@ impl From for VoxelSet { fn traceRay( mesh: &RaycastMesh, start: Real, - dir: &Vector, + dir: &Vector, inside_count: &mut u32, outside_count: &mut u32, ) { diff --git a/src/utils/ccw_face_normal.rs b/src/utils/ccw_face_normal.rs index 182ad5c1..f3f6fe7d 100644 --- a/src/utils/ccw_face_normal.rs +++ b/src/utils/ccw_face_normal.rs @@ -1,4 +1,4 @@ -use crate::math::{Point, Real, Vector}; +use crate::math::{Point, Vector}; use na::Unit; /// Computes the direction pointing toward the right-hand-side of an oriented segment. @@ -6,7 +6,7 @@ use na::Unit; /// Returns `None` if the segment is degenerate. #[inline] #[cfg(feature = "dim2")] -pub fn ccw_face_normal(pts: [&Point; 2]) -> Option>> { +pub fn ccw_face_normal(pts: [&Point; 2]) -> Option> { let ab = pts[1] - pts[0]; let res = Vector::new(ab[1], -ab[0]); @@ -18,7 +18,7 @@ pub fn ccw_face_normal(pts: [&Point; 2]) -> Option>> { /// Returns `None` if the triangle is degenerate. #[inline] #[cfg(feature = "dim3")] -pub fn ccw_face_normal(pts: [&Point; 3]) -> Option>> { +pub fn ccw_face_normal(pts: [&Point; 3]) -> Option> { let ab = pts[1] - pts[0]; let ac = pts[2] - pts[0]; let res = ab.cross(&ac); diff --git a/src/utils/center.rs b/src/utils/center.rs index 6f9c5209..49e83e53 100644 --- a/src/utils/center.rs +++ b/src/utils/center.rs @@ -3,7 +3,7 @@ use na; /// Computes the center of a set of point. #[inline] -pub fn center(pts: &[Point]) -> Point { +pub fn center(pts: &[Point]) -> Point { assert!( !pts.is_empty(), "Cannot compute the center of less than 1 point." diff --git a/src/utils/cleanup.rs b/src/utils/cleanup.rs index 1c51a146..0946e1fa 100644 --- a/src/utils/cleanup.rs +++ b/src/utils/cleanup.rs @@ -1,8 +1,8 @@ -use crate::math::{Point, Real}; +use crate::math::Point; use std::iter; /// Given an index buffer, remove from `points` every point that is not indexed. -pub fn remove_unused_points(points: &mut Vec>, idx: &mut [[u32; 3]]) { +pub fn remove_unused_points(points: &mut Vec, idx: &mut [[u32; 3]]) { let mut used: Vec = iter::repeat(false).take(points.len()).collect(); let mut remap: Vec = (0..points.len()).collect(); let used = &mut used[..]; diff --git a/src/utils/cov.rs b/src/utils/cov.rs index b52d925a..8e16467c 100644 --- a/src/utils/cov.rs +++ b/src/utils/cov.rs @@ -1,14 +1,14 @@ use crate::math::{Matrix, Point, Real}; /// Computes the covariance matrix of a set of points. -pub fn cov(pts: &[Point]) -> Matrix { +pub fn cov(pts: &[Point]) -> Matrix { center_cov(pts).1 } /// Computes the center and the covariance matrix of a set of points. -pub fn center_cov(pts: &[Point]) -> (Point, Matrix) { +pub fn center_cov(pts: &[Point]) -> (Point, Matrix) { let center = crate::utils::center(pts); - let mut cov: Matrix = na::zero(); + let mut cov: Matrix = na::zero(); let normalizer: Real = 1.0 / (pts.len() as Real); for p in pts.iter() { diff --git a/src/utils/isometry_ops.rs b/src/utils/isometry_ops.rs index 6b9403f8..d240dce1 100644 --- a/src/utils/isometry_ops.rs +++ b/src/utils/isometry_ops.rs @@ -1,4 +1,5 @@ use crate::math::{Isometry, Point, Real, SimdReal, Vector}; +use crate::math::{IsometryT, VectorT}; use na::SimdComplexField; use na::Unit; // for .abs() @@ -9,19 +10,19 @@ use na::ComplexField; pub trait IsometryOps { /// Transform a vector by the absolute value of the homogeneous matrix /// equivalent to `self`. - fn absolute_transform_vector(&self, v: &Vector) -> Vector; + fn absolute_transform_vector(&self, v: &VectorT) -> VectorT; } -impl IsometryOps for Isometry { +impl IsometryOps for Isometry { #[inline] - fn absolute_transform_vector(&self, v: &Vector) -> Vector { + fn absolute_transform_vector(&self, v: &Vector) -> Vector { self.rotation.to_rotation_matrix().into_inner().abs() * *v } } -impl IsometryOps for Isometry { +impl IsometryOps for IsometryT { #[inline] - fn absolute_transform_vector(&self, v: &Vector) -> Vector { + fn absolute_transform_vector(&self, v: &VectorT) -> VectorT { self.rotation .to_rotation_matrix() .into_inner() @@ -34,26 +35,26 @@ impl IsometryOps for Isometry { /// where `None` is assumed to be equivalent to the identity. pub trait IsometryOpt { /// Computes `self.inverse() * rhs`. - fn inv_mul(self, rhs: &Isometry) -> Isometry; + fn inv_mul(self, rhs: &Isometry) -> Isometry; /// Computes `rhs * self`. - fn prepend_to(self, rhs: &Isometry) -> Isometry; + fn prepend_to(self, rhs: &Isometry) -> Isometry; /// Computes `self * p`. - fn transform_point(self, p: &Point) -> Point; + fn transform_point(self, p: &Point) -> Point; /// Computes `self * v`. - fn transform_vector(self, v: &Vector) -> Vector; + fn transform_vector(self, v: &Vector) -> Vector; /// Computes `self * v`. - fn transform_unit_vector(self, v: &Unit>) -> Unit>; + fn transform_unit_vector(self, v: &Unit) -> Unit; /// Computes `self.inverse() * p`. - fn inverse_transform_point(self, p: &Point) -> Point; + fn inverse_transform_point(self, p: &Point) -> Point; /// Computes `self.inverse() * v`. - fn inverse_transform_vector(self, v: &Vector) -> Vector; + fn inverse_transform_vector(self, v: &Vector) -> Vector; /// Computes `self.inverse() * v`. - fn inverse_transform_unit_vector(self, v: &Unit>) -> Unit>; + fn inverse_transform_unit_vector(self, v: &Unit) -> Unit; } -impl IsometryOpt for Option<&Isometry> { +impl IsometryOpt for Option<&Isometry> { #[inline] - fn inv_mul(self, rhs: &Isometry) -> Isometry { + fn inv_mul(self, rhs: &Isometry) -> Isometry { if let Some(iso) = self { iso.inv_mul(rhs) } else { @@ -62,7 +63,7 @@ impl IsometryOpt for Option<&Isometry> { } #[inline] - fn prepend_to(self, rhs: &Isometry) -> Isometry { + fn prepend_to(self, rhs: &Isometry) -> Isometry { if let Some(iso) = self { rhs * iso } else { @@ -71,7 +72,7 @@ impl IsometryOpt for Option<&Isometry> { } #[inline] - fn transform_point(self, p: &Point) -> Point { + fn transform_point(self, p: &Point) -> Point { if let Some(iso) = self { iso * p } else { @@ -80,7 +81,7 @@ impl IsometryOpt for Option<&Isometry> { } #[inline] - fn transform_vector(self, v: &Vector) -> Vector { + fn transform_vector(self, v: &Vector) -> Vector { if let Some(iso) = self { iso * v } else { @@ -89,7 +90,7 @@ impl IsometryOpt for Option<&Isometry> { } #[inline] - fn transform_unit_vector(self, v: &Unit>) -> Unit> { + fn transform_unit_vector(self, v: &Unit) -> Unit { if let Some(iso) = self { iso * v } else { @@ -98,7 +99,7 @@ impl IsometryOpt for Option<&Isometry> { } #[inline] - fn inverse_transform_point(self, p: &Point) -> Point { + fn inverse_transform_point(self, p: &Point) -> Point { if let Some(iso) = self { iso.inverse_transform_point(p) } else { @@ -107,7 +108,7 @@ impl IsometryOpt for Option<&Isometry> { } #[inline] - fn inverse_transform_vector(self, v: &Vector) -> Vector { + fn inverse_transform_vector(self, v: &Vector) -> Vector { if let Some(iso) = self { iso.inverse_transform_vector(v) } else { @@ -116,7 +117,7 @@ impl IsometryOpt for Option<&Isometry> { } #[inline] - fn inverse_transform_unit_vector(self, v: &Unit>) -> Unit> { + fn inverse_transform_unit_vector(self, v: &Unit) -> Unit { if let Some(iso) = self { iso.inverse_transform_unit_vector(v) } else { @@ -125,9 +126,9 @@ impl IsometryOpt for Option<&Isometry> { } } -impl IsometryOpt for Option> { +impl IsometryOpt for Option { #[inline] - fn inv_mul(self, rhs: &Isometry) -> Isometry { + fn inv_mul(self, rhs: &Isometry) -> Isometry { if let Some(iso) = self { iso.inv_mul(rhs) } else { @@ -136,7 +137,7 @@ impl IsometryOpt for Option> { } #[inline] - fn prepend_to(self, rhs: &Isometry) -> Isometry { + fn prepend_to(self, rhs: &Isometry) -> Isometry { if let Some(iso) = self { rhs * iso } else { @@ -145,7 +146,7 @@ impl IsometryOpt for Option> { } #[inline] - fn transform_point(self, p: &Point) -> Point { + fn transform_point(self, p: &Point) -> Point { if let Some(iso) = self { iso * p } else { @@ -154,7 +155,7 @@ impl IsometryOpt for Option> { } #[inline] - fn transform_vector(self, v: &Vector) -> Vector { + fn transform_vector(self, v: &Vector) -> Vector { if let Some(iso) = self { iso * v } else { @@ -163,7 +164,7 @@ impl IsometryOpt for Option> { } #[inline] - fn transform_unit_vector(self, v: &Unit>) -> Unit> { + fn transform_unit_vector(self, v: &Unit) -> Unit { if let Some(iso) = self { iso * v } else { @@ -172,7 +173,7 @@ impl IsometryOpt for Option> { } #[inline] - fn inverse_transform_point(self, p: &Point) -> Point { + fn inverse_transform_point(self, p: &Point) -> Point { if let Some(iso) = self { iso.inverse_transform_point(p) } else { @@ -181,7 +182,7 @@ impl IsometryOpt for Option> { } #[inline] - fn inverse_transform_vector(self, v: &Vector) -> Vector { + fn inverse_transform_vector(self, v: &Vector) -> Vector { if let Some(iso) = self { iso.inverse_transform_vector(v) } else { @@ -190,7 +191,7 @@ impl IsometryOpt for Option> { } #[inline] - fn inverse_transform_unit_vector(self, v: &Unit>) -> Unit> { + fn inverse_transform_unit_vector(self, v: &Unit) -> Unit { if let Some(iso) = self { iso.inverse_transform_unit_vector(v) } else { diff --git a/src/utils/obb.rs b/src/utils/obb.rs index 5e6a816b..6cccb13a 100644 --- a/src/utils/obb.rs +++ b/src/utils/obb.rs @@ -5,7 +5,7 @@ use crate::shape::Cuboid; /// /// The returned OBB is not guaranteed to be the smallest enclosing OBB. /// Though it should be a pretty good on for most purposes. -pub fn obb(pts: &[Point]) -> (Isometry, Cuboid) { +pub fn obb(pts: &[Point]) -> (Isometry, Cuboid) { let cov = crate::utils::cov(pts); let mut eigv = cov.symmetric_eigen().eigenvectors; diff --git a/src/utils/point_cloud_support_point.rs b/src/utils/point_cloud_support_point.rs index e4be18aa..998aba0c 100644 --- a/src/utils/point_cloud_support_point.rs +++ b/src/utils/point_cloud_support_point.rs @@ -1,8 +1,8 @@ -use crate::math::{Point, Real, Vector}; +use crate::math::{Point, Vector}; /// Computes the index of the support point of a cloud of points. #[inline] -pub fn point_cloud_support_point_id(dir: &Vector, points: &[Point]) -> usize { +pub fn point_cloud_support_point_id(dir: &Vector, points: &[Point]) -> usize { let mut best_pt = 0; let mut best_dot = points[0].coords.dot(dir); @@ -20,6 +20,6 @@ pub fn point_cloud_support_point_id(dir: &Vector, points: &[Point]) /// Computes the support point of a cloud of points. #[inline] -pub fn point_cloud_support_point(dir: &Vector, points: &[Point]) -> Point { +pub fn point_cloud_support_point(dir: &Vector, points: &[Point]) -> Point { points[point_cloud_support_point_id(dir, points)] } diff --git a/src/utils/point_in_poly2d.rs b/src/utils/point_in_poly2d.rs index 97e70bb4..49fd60f7 100644 --- a/src/utils/point_in_poly2d.rs +++ b/src/utils/point_in_poly2d.rs @@ -82,71 +82,71 @@ mod tests { #[test] fn point_in_poly2d_concave() { let poly = [ - [615.4741821289063, 279.4120788574219], - [617.95947265625, 281.8973693847656], - [624.1727294921875, 288.73193359375], - [626.6580200195313, 292.4598693847656], - [634.7352294921875, 302.40106201171875], - [637.8418579101563, 306.7503356933594], - [642.8124389648438, 312.96356201171875], - [652.7536010742188, 330.98193359375], - [654.6176147460938, 334.7098693847656], - [661.4521484375, 349.0003356933594], - [666.4227294921875, 360.18414306640625], - [670.1506958007813, 367.6400451660156], - [675.1212768554688, 381.30914306640625], - [678.2279052734375, 391.2503356933594], - [681.33447265625, 402.43414306640625], - [683.81982421875, 414.23931884765625], - [685.0624389648438, 422.3165283203125], - [685.6837768554688, 431.0150146484375], - [686.3051147460938, 442.8201904296875], - [685.6837768554688, 454.0040283203125], - [683.81982421875, 460.83856201171875], - [679.4705200195313, 470.77972412109375], - [674.4999389648438, 480.720947265625], - [670.1506958007813, 486.93414306640625], - [662.073486328125, 497.49664306640625], - [659.5881958007813, 499.36065673828125], - [653.3749389648438, 503.70989990234375], - [647.7830200195313, 506.1951904296875], - [642.8124389648438, 507.43780517578125], - [631.6286010742188, 508.05914306640625], - [621.0661010742188, 508.05914306640625], - [605.5330200195313, 508.05914306640625], - [596.2131958007813, 508.05914306640625], - [586.893310546875, 508.05914306640625], - [578.8161010742188, 508.05914306640625], - [571.3602294921875, 506.1951904296875], - [559.5551147460938, 499.36065673828125], - [557.0697631835938, 497.49664306640625], - [542.1580200195313, 484.4488525390625], - [534.7021484375, 476.37164306640625], - [532.8381958007813, 473.8863525390625], - [527.2462768554688, 466.43048095703125], - [522.2756958007813, 450.89739990234375], - [521.6543579101563, 444.06280517578125], - [521.0330200195313, 431.6363525390625], - [521.6543579101563, 422.93780517578125], - [523.518310546875, 409.26873779296875], - [527.2462768554688, 397.46356201171875], - [532.8381958007813, 385.6584167480469], - [540.9154052734375, 373.23193359375], - [547.1286010742188, 365.77606201171875], - [559.5551147460938, 354.59222412109375], - [573.2241821289063, 342.165771484375], - [575.70947265625, 339.68048095703125], - [584.4080200195313, 331.603271484375], - [597.455810546875, 317.3128356933594], - [601.8051147460938, 311.7209167480469], - [607.39697265625, 303.6437072753906], - [611.7462768554688, 296.1878356933594], - [614.2315673828125, 288.1106262207031], - [615.4741821289063, 280.65472412109375], - [615.4741821289063, 279.4120788574219], + [615.474_2, 279.412_08], + [617.959_5, 281.897_37], + [624.172_7, 288.731_93], + [626.658, 292.459_87], + [634.735_2, 302.401_06], + [637.841_86, 306.750_34], + [642.812_44, 312.963_56], + [652.753_6, 330.981_93], + [654.617_6, 334.709_87], + [661.452_15, 349.000_34], + [666.422_7, 360.184_14], + [670.150_7, 367.640_05], + [675.121_3, 381.309_14], + [678.227_9, 391.250_34], + [681.334_5, 402.434_14], + [683.819_8, 414.239_32], + [685.062_44, 422.316_53], + [685.683_8, 431.015], + [686.305_1, 442.820_2], + [685.683_8, 454.004_03], + [683.819_8, 460.838_56], + [679.470_5, 470.779_72], + [674.499_94, 480.720_95], + [670.150_7, 486.934_14], + [662.073_5, 497.496_64], + [659.588_2, 499.360_66], + [653.374_94, 503.709_9], + [647.783, 506.195_2], + [642.812_44, 507.437_8], + [631.628_6, 508.059_14], + [621.066_1, 508.059_14], + [605.533, 508.059_14], + [596.213_2, 508.059_14], + [586.893_3, 508.059_14], + [578.816_1, 508.059_14], + [571.360_2, 506.195_2], + [559.555_1, 499.360_66], + [557.069_76, 497.496_64], + [542.158, 484.448_85], + [534.702_15, 476.371_64], + [532.838_2, 473.886_35], + [527.246_3, 466.430_48], + [522.275_7, 450.897_4], + [521.654_36, 444.062_8], + [521.033, 431.636_35], + [521.654_36, 422.937_8], + [523.518_3, 409.268_74], + [527.246_3, 397.463_56], + [532.838_2, 385.658_42], + [540.915_4, 373.231_93], + [547.128_6, 365.776_06], + [559.555_1, 354.592_22], + [573.224_2, 342.165_77], + [575.709_5, 339.680_48], + [584.408, 331.603_27], + [597.455_8, 317.312_84], + [601.805_1, 311.720_92], + [607.397, 303.643_7], + [611.746_3, 296.187_84], + [614.231_57, 288.110_63], + [615.474_2, 280.654_72], + [615.474_2, 279.412_08], ] .map(Point2::from); - let pt = Point2::from([596.0181884765625, 427.9162902832031]); + let pt = Point2::from([596.018_2, 427.916_3]); assert!(point_in_poly2d(&pt, &poly)); } diff --git a/src/utils/point_in_triangle.rs b/src/utils/point_in_triangle.rs index dffcc2d8..533d74d5 100644 --- a/src/utils/point_in_triangle.rs +++ b/src/utils/point_in_triangle.rs @@ -28,7 +28,7 @@ pub enum Orientation { /// . . /// . o p3 /// o p1 -pub fn corner_direction(p1: &Point, p2: &Point, p3: &Point) -> Orientation { +pub fn corner_direction(p1: &Point, p2: &Point, p3: &Point) -> Orientation { let v1 = p1 - p2; let v2 = p3 - p2; let cross: Real = v1.perp(&v2); @@ -45,12 +45,7 @@ pub fn corner_direction(p1: &Point, p2: &Point, p3: &Point) -> /// Returns `true` if point `p` is in triangle with corners `v1`, `v2` and `v3`. /// Returns `None` if the triangle is invalid i.e. all points are the same or on a straight line. -pub fn is_point_in_triangle( - p: &Point, - v1: &Point, - v2: &Point, - v3: &Point, -) -> Option { +pub fn is_point_in_triangle(p: &Point, v1: &Point, v2: &Point, v3: &Point) -> Option { let d1 = corner_direction(p, v1, v2); let d2 = corner_direction(p, v2, v3); let d3 = corner_direction(p, v3, v1);