From c149115bb4090f908ccbe447ff15aef6b53ee9a1 Mon Sep 17 00:00:00 2001 From: Sybrand Aarnoutse Date: Tue, 9 Jul 2019 12:34:16 +0200 Subject: [PATCH 1/2] deny bare trait objects also added `dyn` to fix errors where necessary --- src/detection/activation_manager.rs | 4 +- src/joint/cartesian_joint.rs | 2 +- src/joint/fixed_joint.rs | 2 +- src/joint/free_joint.rs | 2 +- src/joint/joint.rs | 2 +- src/joint/prismatic_joint.rs | 2 +- src/joint/revolute_joint.rs | 2 +- src/joint/unit_constraint.rs | 16 ++--- src/lib.rs | 16 ++--- src/material/material.rs | 28 ++++----- src/object/body.rs | 12 ++-- src/object/body_set.rs | 14 ++--- src/object/collider.rs | 28 ++++----- src/object/fem_surface.rs | 14 ++--- src/object/ground.rs | 10 ++-- src/object/mass_constraint_system.rs | 14 ++--- src/object/mass_spring_system.rs | 14 ++--- src/object/multibody.rs | 18 +++--- src/object/multibody_link.rs | 8 +-- src/object/rigid_body.rs | 12 ++-- src/solver/helper.rs | 88 ++++++++++++++-------------- src/solver/moreau_jean_solver.rs | 14 ++--- src/solver/nonlinear_sor_prox.rs | 2 +- src/solver/signorini_model.rs | 8 +-- src/utils/user_data.rs | 14 ++--- src/volumetric/volumetric_convex2.rs | 4 +- src/volumetric/volumetric_shape.rs | 2 +- src/world/world.rs | 30 +++++----- 28 files changed, 192 insertions(+), 190 deletions(-) diff --git a/src/detection/activation_manager.rs b/src/detection/activation_manager.rs index 874c3f030..1fe9c41bd 100644 --- a/src/detection/activation_manager.rs +++ b/src/detection/activation_manager.rs @@ -45,7 +45,7 @@ impl ActivationManager { self.to_activate.push(handle); } - fn update_energy(&self, body: &mut Body) { + fn update_energy(&self, body: &mut dyn Body) { // FIXME: avoid the Copy when NLL lands ? let status = *body.activation_status(); @@ -63,7 +63,7 @@ impl ActivationManager { &mut self, bodies: &mut BodySet, cworld: &ColliderWorld, - constraints: &Slab>>, + constraints: &Slab>>, active_bodies: &mut Vec, ) { /* diff --git a/src/joint/cartesian_joint.rs b/src/joint/cartesian_joint.rs index 61ae2e23e..75ad9d8fb 100644 --- a/src/joint/cartesian_joint.rs +++ b/src/joint/cartesian_joint.rs @@ -19,7 +19,7 @@ impl CartesianJoint { impl Joint for CartesianJoint { #[inline] - fn clone(&self) -> Box> { + fn clone(&self) -> Box> { Box::new(*self) } diff --git a/src/joint/fixed_joint.rs b/src/joint/fixed_joint.rs index c06e04aa2..4a45d54ac 100644 --- a/src/joint/fixed_joint.rs +++ b/src/joint/fixed_joint.rs @@ -24,7 +24,7 @@ impl FixedJoint { impl Joint for FixedJoint { #[inline] - fn clone(&self) -> Box> { + fn clone(&self) -> Box> { Box::new(*self) } diff --git a/src/joint/free_joint.rs b/src/joint/free_joint.rs index 40cb0a9fe..b295bba8a 100644 --- a/src/joint/free_joint.rs +++ b/src/joint/free_joint.rs @@ -29,7 +29,7 @@ impl FreeJoint { impl Joint for FreeJoint { #[inline] - fn clone(&self) -> Box> { + fn clone(&self) -> Box> { Box::new(*self) } diff --git a/src/joint/joint.rs b/src/joint/joint.rs index a7226a180..879aa89c2 100644 --- a/src/joint/joint.rs +++ b/src/joint/joint.rs @@ -85,7 +85,7 @@ pub trait Joint: Downcast + Send + Sync { None } - fn clone(&self) -> Box>; + fn clone(&self) -> Box>; } impl_downcast!(Joint where N: RealField); diff --git a/src/joint/prismatic_joint.rs b/src/joint/prismatic_joint.rs index c6a10775c..f5da26bb0 100644 --- a/src/joint/prismatic_joint.rs +++ b/src/joint/prismatic_joint.rs @@ -139,7 +139,7 @@ impl PrismaticJoint { impl Joint for PrismaticJoint { #[inline] - fn clone(&self) -> Box> { + fn clone(&self) -> Box> { Box::new(*self) } diff --git a/src/joint/revolute_joint.rs b/src/joint/revolute_joint.rs index 2b28a1be0..6ccf0496a 100644 --- a/src/joint/revolute_joint.rs +++ b/src/joint/revolute_joint.rs @@ -178,7 +178,7 @@ impl RevoluteJoint { impl Joint for RevoluteJoint { #[inline] - fn clone(&self) -> Box> { + fn clone(&self) -> Box> { Box::new(*self) } diff --git a/src/joint/unit_constraint.rs b/src/joint/unit_constraint.rs index 8ee6c3af9..978f56c53 100644 --- a/src/joint/unit_constraint.rs +++ b/src/joint/unit_constraint.rs @@ -6,10 +6,10 @@ use crate::solver::{helper, BilateralConstraint, BilateralGroundConstraint, Cons ForceDirection, GenericNonlinearConstraint, ImpulseLimits, IntegrationParameters}; pub fn build_linear_limits_velocity_constraint( - body1: &Body, - part1: &BodyPart, - body2: &Body, - part2: &BodyPart, + body1: &dyn Body, + part1: &dyn BodyPart, + body2: &dyn Body, + part2: &dyn BodyPart, assembly_id1: usize, assembly_id2: usize, anchor1: &Point, @@ -123,10 +123,10 @@ pub fn build_linear_limits_velocity_constraint( pub fn build_linear_limits_position_constraint( params: &IntegrationParameters, - body1: &Body, - part1: &BodyPart, - body2: &Body, - part2: &BodyPart, + body1: &dyn Body, + part1: &dyn BodyPart, + body2: &dyn Body, + part2: &dyn BodyPart, anchor1: &Point, anchor2: &Point, axis: &Unit>, diff --git a/src/lib.rs b/src/lib.rs index 418a2ffec..a58a106c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,6 +61,8 @@ The libraries needed to compile the physics engine are: The libraries needed to compile the examples are: */ + +#![deny(bare_trait_objects)] #![deny(non_camel_case_types)] #![deny(unused_parens)] #![deny(non_upper_case_globals)] @@ -214,25 +216,25 @@ macro_rules! user_data_accessors( () => { /// Retrieves a reference to the user-defined user-data attached to this object. #[inline] - pub fn user_data(&self) -> Option<&(Any + Send + Sync)> { + pub fn user_data(&self) -> Option<&(dyn Any + Send + Sync)> { self.user_data.as_ref().map(|d| &**d) } /// Retrieves a mutable reference to the user-defined user-data attached to this object. #[inline] - pub fn user_data_mut(&mut self) -> Option<&mut (Any + Send + Sync)> { + pub fn user_data_mut(&mut self) -> Option<&mut (dyn Any + Send + Sync)> { self.user_data.as_mut().map(|d| &mut **d) } /// Sets the user-defined data attached to this object. #[inline] - pub fn set_user_data(&mut self, data: Option>) -> Option> { + pub fn set_user_data(&mut self, data: Option>) -> Option> { std::mem::replace(&mut self.user_data, data) } /// Replace by `None` the user-defined data attached to this object and returns the old value. #[inline] - pub fn take_user_data(&mut self) -> Option> { + pub fn take_user_data(&mut self) -> Option> { self.user_data.take() } } @@ -243,18 +245,18 @@ macro_rules! user_data_desc_accessors( () => { /// Sets a user-data to be attached to the object being built. pub fn user_data(mut self, data: impl UserData) -> Self { - self.user_data = Some(UserDataBox(Box::new(data) as Box)); + self.user_data = Some(UserDataBox(Box::new(data) as Box)); self } /// Sets the user-data to be attached to the object being built. pub fn set_user_data(&mut self, data: Option) -> &mut Self { - self.user_data = data.map(|data| UserDataBox(Box::new(data) as Box)); + self.user_data = data.map(|data| UserDataBox(Box::new(data) as Box)); self } /// Reference to the user-data to be attached to the object being built. - pub fn get_user_data(&self) -> Option<&(Any + Send + Sync)> { + pub fn get_user_data(&self) -> Option<&(dyn Any + Send + Sync)> { self.user_data.as_ref().map(|data| data.0.as_any()) } } diff --git a/src/material/material.rs b/src/material/material.rs index 6d5f74484..91c3a661b 100644 --- a/src/material/material.rs +++ b/src/material/material.rs @@ -13,9 +13,9 @@ use crate::math::Vector; #[derive(Copy, Clone)] pub struct MaterialContext<'a, N: RealField> { /// One of the two bodies involved in the contact. - pub body: &'a Body, + pub body: &'a dyn Body, /// One of the two bodies part involved in the contact. - pub body_part: &'a BodyPart, + pub body_part: &'a dyn BodyPart, /// One of the two colliders involved in the contact. pub collider: &'a Collider, /// The contact. @@ -28,7 +28,7 @@ pub struct MaterialContext<'a, N: RealField> { } impl<'a, N: RealField> MaterialContext<'a, N> { - pub(crate) fn new(body: &'a Body, body_part: &'a BodyPart, collider: &'a Collider, contact: &'a TrackedContact, is_first: bool) -> Self { + pub(crate) fn new(body: &'a dyn Body, body_part: &'a dyn BodyPart, collider: &'a Collider, contact: &'a TrackedContact, is_first: bool) -> Self { MaterialContext { body, body_part, @@ -93,7 +93,7 @@ pub struct LocalMaterialProperties { /// An utility trait to clone material trait-objects. pub trait MaterialClone { /// Clone a material trait-object. - fn clone_box(&self) -> Box> { + fn clone_box(&self) -> Box> { unimplemented!() } } @@ -102,7 +102,7 @@ pub trait MaterialClone { pub type MaterialId = u32; impl + Clone> MaterialClone for T { - fn clone_box(&self) -> Box> { + fn clone_box(&self) -> Box> { Box::new(self.clone()) } } @@ -115,13 +115,13 @@ pub trait Material: Downcast + Send + Sync + MaterialClone { impl_downcast!(Material where N: RealField); -impl Clone for Box> { - fn clone(&self) -> Box> { +impl Clone for Box> { + fn clone(&self) -> Box> { self.clone_box() } } -impl Material { +impl dyn Material { /// Combine two materials given their contexts and a material lookup table. pub fn combine( table: &MaterialsCoefficientsTable, @@ -169,7 +169,7 @@ impl Material { /// /// This can be mutated using COW. #[derive(Clone)] -pub struct MaterialHandle(Arc>>); +pub struct MaterialHandle(Arc>>); impl MaterialHandle { /// Creates a sharable shape handle from a shape. @@ -178,23 +178,23 @@ impl MaterialHandle { MaterialHandle(Arc::new(Box::new(material))) } - pub(crate) fn make_mut(&mut self) -> &mut Material { + pub(crate) fn make_mut(&mut self) -> &mut dyn Material { &mut **Arc::make_mut(&mut self.0) } } -impl AsRef> for MaterialHandle { +impl AsRef> for MaterialHandle { #[inline] - fn as_ref(&self) -> &Material { + fn as_ref(&self) -> &dyn Material { &*self.deref() } } impl Deref for MaterialHandle { - type Target = Material; + type Target = dyn Material; #[inline] - fn deref(&self) -> &Material { + fn deref(&self) -> &dyn Material { &**self.0.deref() } } \ No newline at end of file diff --git a/src/object/body.rs b/src/object/body.rs index 51c05d8a3..0ddf6131b 100644 --- a/src/object/body.rs +++ b/src/object/body.rs @@ -174,7 +174,7 @@ pub trait Body: Downcast + Send + Sync { fn deactivate(&mut self); /// A reference to the specified body part. - fn part(&self, i: usize) -> Option<&BodyPart>; + fn part(&self, i: usize) -> Option<&dyn BodyPart>; /// If this is a deformable body, returns its deformed positions. fn deformed_positions(&self) -> Option<(DeformationsType, &[N])>; @@ -189,7 +189,7 @@ pub trait Body: Downcast + Send + Sync { /// If the force is a torque, it is applied at the center of mass of the body part. fn fill_constraint_geometry( &self, - part: &BodyPart, + part: &dyn BodyPart, ndofs: usize, // FIXME: keep this parameter? center: &Point, dir: &ForceDirection, @@ -202,13 +202,13 @@ pub trait Body: Downcast + Send + Sync { ); /// Transform the given point expressed in material coordinates to world-space. - fn world_point_at_material_point(&self, part: &BodyPart, point: &Point) -> Point; + fn world_point_at_material_point(&self, part: &dyn BodyPart, point: &Point) -> Point; /// Transform the given point expressed in material coordinates to world-space. - fn position_at_material_point(&self, part: &BodyPart, point: &Point) -> Isometry; + fn position_at_material_point(&self, part: &dyn BodyPart, point: &Point) -> Isometry; /// Transform the given point expressed in material coordinates to world-space. - fn material_point_at_world_point(&self, part: &BodyPart, point: &Point) -> Point; + fn material_point_at_world_point(&self, part: &dyn BodyPart, point: &Point) -> Point; /// Returns `true` if this bodies contains internal constraints that need to be solved. fn has_active_internal_constraints(&mut self) -> bool; @@ -246,7 +246,7 @@ pub trait Body: Downcast + Send + Sync { /// /// This will return a zero velocity for any body with a status different than `BodyStatus::Dynamic`. #[inline] - fn status_dependent_body_part_velocity(&self, part: &BodyPart) -> Velocity { + fn status_dependent_body_part_velocity(&self, part: &dyn BodyPart) -> Velocity { if self.is_dynamic() { part.velocity() } else { diff --git a/src/object/body_set.rs b/src/object/body_set.rs index 297d41f34..897b08af5 100644 --- a/src/object/body_set.rs +++ b/src/object/body_set.rs @@ -115,7 +115,7 @@ pub trait BodyDesc { /// A set containing all the bodies added to the world. pub struct BodySet { ground: Ground, - bodies: Slab>>, + bodies: Slab>>, } impl BodySet { @@ -160,7 +160,7 @@ impl BodySet { /// /// Returns `None` if the body is not found. #[inline] - pub fn body(&self, handle: BodyHandle) -> Option<&Body> { + pub fn body(&self, handle: BodyHandle) -> Option<&dyn Body> { if handle.is_ground() { Some(&self.ground) } else { @@ -172,7 +172,7 @@ impl BodySet { /// /// Returns `None` if the body is not found. #[inline] - pub fn body_mut(&mut self, handle: BodyHandle) -> Option<&mut Body> { + pub fn body_mut(&mut self, handle: BodyHandle) -> Option<&mut dyn Body> { if handle.is_ground() { Some(&mut self.ground) } else { @@ -182,18 +182,18 @@ impl BodySet { /// Iterator yielding all the bodies on this set. #[inline] - pub fn bodies(&self) -> impl Iterator> { + pub fn bodies(&self) -> impl Iterator> { self.bodies.iter().map(|e| &**e.1) } /// Mutable iterator yielding all the bodies on this set. #[inline] - pub fn bodies_mut(&mut self) -> impl Iterator> { + pub fn bodies_mut(&mut self) -> impl Iterator> { self.bodies.iter_mut().map(|e| &mut **e.1) } } /// Iterator yielding all the bodies on a body set. -pub type Bodies<'a, N> = Iter<'a, Box>>; +pub type Bodies<'a, N> = Iter<'a, Box>>; /// Mutable iterator yielding all the bodies on a body set. -pub type BodiesMut<'a, N> = IterMut<'a, Box>>; +pub type BodiesMut<'a, N> = IterMut<'a, Box>>; diff --git a/src/object/collider.rs b/src/object/collider.rs index b697d6d70..87385b0f3 100644 --- a/src/object/collider.rs +++ b/src/object/collider.rs @@ -62,7 +62,7 @@ pub struct ColliderData { // NOTE: needed for the collision filter. body_status_dependent_ndofs: usize, material: MaterialHandle, - user_data: Option>, + user_data: Option>, } impl ColliderData { @@ -129,7 +129,7 @@ impl ColliderData { /// The material of this collider. #[inline] - pub fn material(&self) -> &Material { + pub fn material(&self) -> &dyn Material { &*self.material } @@ -139,7 +139,7 @@ impl ColliderData { /// before returning the mutable reference (this effectively call /// the `Arc::make_mut` method to get a copy-on-write behavior). #[inline] - pub fn material_mut(&mut self) -> &mut Material { + pub fn material_mut(&mut self) -> &mut dyn Material { self.material.make_mut() } @@ -177,25 +177,25 @@ impl Collider { */ /// The user-data attached to this collider. #[inline] - pub fn user_data(&self) -> Option<&(Any + Send + Sync)> { + pub fn user_data(&self) -> Option<&(dyn Any + Send + Sync)> { self.0.data().user_data.as_ref().map(|d| &**d) } /// Mutable reference to the user-data attached to this collider. #[inline] - pub fn user_data_mut(&mut self) -> Option<&mut (Any + Send + Sync)> { + pub fn user_data_mut(&mut self) -> Option<&mut (dyn Any + Send + Sync)> { self.0.data_mut().user_data.as_mut().map(|d| &mut **d) } /// Sets the user-data attached to this collider. #[inline] - pub fn set_user_data(&mut self, data: Option>) -> Option> { + pub fn set_user_data(&mut self, data: Option>) -> Option> { std::mem::replace(&mut self.0.data_mut().user_data, data) } /// Replace the user-data of this collider by `None` and returns the old value. #[inline] - pub fn take_user_data(&mut self) -> Option> { + pub fn take_user_data(&mut self) -> Option> { self.0.data_mut().user_data.take() } @@ -227,7 +227,7 @@ impl Collider { /// The material of this collider. #[inline] - pub fn material(&self) -> &Material { + pub fn material(&self) -> &dyn Material { self.0.data().material() } @@ -406,10 +406,10 @@ impl ColliderDesc { ); desc_custom_getters!( - self.get_shape: &Shape | { &*self.shape } + self.get_shape: &dyn Shape | { &*self.shape } self.get_name: &str | { &self.name } self.get_translation: &Vector | { &self.position.translation.vector } - self.get_material: Option<&Material> | { self.material.as_ref().map(|m| &**m) } + self.get_material: Option<&dyn Material> | { self.material.as_ref().map(|m| &**m) } ); desc_getters!( @@ -441,7 +441,7 @@ impl ColliderDesc { // Returns `None` if the given body part does not exist. pub(crate) fn build_with_infos<'w>(&self, parent: BodyPartHandle, - body: &mut Body, + body: &mut dyn Body, cworld: &'w mut ColliderWorld) -> Option<&'w mut Collider> { let query = if self.is_sensor { @@ -551,9 +551,9 @@ impl DeformableColliderDesc { ); desc_custom_getters!( - self.get_shape: &Shape | { &*self.shape } + self.get_shape: &dyn Shape | { &*self.shape } self.get_name: &str | { &self.name } - self.get_material: Option<&Material> | { self.material.as_ref().map(|m| &**m) } + self.get_material: Option<&dyn Material> | { self.material.as_ref().map(|m| &**m) } ); @@ -573,7 +573,7 @@ impl DeformableColliderDesc { } pub(crate) fn build_with_infos<'w>(&self, - parent: &Body, + parent: &dyn Body, cworld: &'w mut ColliderWorld) -> &'w mut Collider { let query = if self.is_sensor { diff --git a/src/object/fem_surface.rs b/src/object/fem_surface.rs index dafbbd762..8def5e03f 100644 --- a/src/object/fem_surface.rs +++ b/src/object/fem_surface.rs @@ -74,7 +74,7 @@ pub struct FEMSurface { update_status: BodyUpdateStatus, - user_data: Option>, + user_data: Option>, } impl FEMSurface { @@ -777,29 +777,29 @@ impl Body for FEMSurface { self.activation.set_deactivation_threshold(threshold) } - fn part(&self, id: usize) -> Option<&BodyPart> { - self.elements.get(id).map(|b| b as &BodyPart) + fn part(&self, id: usize) -> Option<&dyn BodyPart> { + self.elements.get(id).map(|b| b as &dyn BodyPart) } - fn world_point_at_material_point(&self, part: &BodyPart, point: &Point) -> Point { + fn world_point_at_material_point(&self, part: &dyn BodyPart, point: &Point) -> Point { let elt = part.downcast_ref::>().expect("The provided body part must be a triangular element"); fem_helper::world_point_at_material_point(FiniteElementIndices::Triangle(elt.indices), &self.positions, point) } - fn position_at_material_point(&self, part: &BodyPart, point: &Point) -> Isometry { + fn position_at_material_point(&self, part: &dyn BodyPart, point: &Point) -> Isometry { let elt = part.downcast_ref::>().expect("The provided body part must be a triangular element"); let pt = fem_helper::world_point_at_material_point(FiniteElementIndices::Triangle(elt.indices), &self.positions, point); Isometry::from_parts(Translation::from(pt.coords), na::one()) } - fn material_point_at_world_point(&self, part: &BodyPart, point: &Point) -> Point { + fn material_point_at_world_point(&self, part: &dyn BodyPart, point: &Point) -> Point { let elt = part.downcast_ref::>().expect("The provided body part must be a triangular element"); fem_helper::material_point_at_world_point(FiniteElementIndices::Triangle(elt.indices), &self.positions, point) } fn fill_constraint_geometry( &self, - part: &BodyPart, + part: &dyn BodyPart, _: usize, // FIXME: keep this parameter? center: &Point, force_dir: &ForceDirection, diff --git a/src/object/ground.rs b/src/object/ground.rs index 84dbe20a0..912625aab 100644 --- a/src/object/ground.rs +++ b/src/object/ground.rs @@ -68,7 +68,7 @@ impl Body for Ground { } #[inline] - fn part(&self, _: usize) -> Option<&BodyPart> { + fn part(&self, _: usize) -> Option<&dyn BodyPart> { Some(self) } @@ -174,17 +174,17 @@ impl Body for Ground { fn set_deactivation_threshold(&mut self, _: Option) {} #[inline] - fn world_point_at_material_point(&self, _: &BodyPart, point: &Point) -> Point { + fn world_point_at_material_point(&self, _: &dyn BodyPart, point: &Point) -> Point { *point } #[inline] - fn position_at_material_point(&self, _: &BodyPart, point: &Point) -> Isometry { + fn position_at_material_point(&self, _: &dyn BodyPart, point: &Point) -> Isometry { Isometry::from_parts(Translation::from(point.coords), na::one()) } #[inline] - fn material_point_at_world_point(&self, _: &BodyPart, point: &Point) -> Point { + fn material_point_at_world_point(&self, _: &dyn BodyPart, point: &Point) -> Point { *point } @@ -192,7 +192,7 @@ impl Body for Ground { #[inline] fn fill_constraint_geometry( &self, - _: &BodyPart, + _: &dyn BodyPart, _: usize, // FIXME: keep this parameter? _: &Point, _: &ForceDirection, diff --git a/src/object/mass_constraint_system.rs b/src/object/mass_constraint_system.rs index 53d1b3cf2..af1f953ac 100644 --- a/src/object/mass_constraint_system.rs +++ b/src/object/mass_constraint_system.rs @@ -98,7 +98,7 @@ pub struct MassConstraintSystem { plasticity_creep: N, plasticity_max_force: N, - user_data: Option>, + user_data: Option>, } @@ -500,8 +500,8 @@ impl Body for MassConstraintSystem { self.velocities.fill(N::zero()); } - fn part(&self, id: usize) -> Option<&BodyPart> { - self.elements.get(id).map(|e| e as &BodyPart) + fn part(&self, id: usize) -> Option<&dyn BodyPart> { + self.elements.get(id).map(|e| e as &dyn BodyPart) } fn deformed_positions(&self) -> Option<(DeformationsType, &[N])> { @@ -513,25 +513,25 @@ impl Body for MassConstraintSystem { Some((DeformationsType::Vectors, self.positions.as_mut_slice())) } - fn world_point_at_material_point(&self, part: &BodyPart, point: &Point) -> Point { + fn world_point_at_material_point(&self, part: &dyn BodyPart, point: &Point) -> Point { let elt = part.downcast_ref::>().expect("The provided body part must be a mass-constraint element"); fem_helper::world_point_at_material_point(elt.indices, &self.positions, point) } - fn position_at_material_point(&self, part: &BodyPart, point: &Point) -> Isometry { + fn position_at_material_point(&self, part: &dyn BodyPart, point: &Point) -> Isometry { let elt = part.downcast_ref::>().expect("The provided body part must be a mass-constraint element"); let pt = fem_helper::world_point_at_material_point(elt.indices, &self.positions, point); Isometry::from_parts(Translation::from(pt.coords), na::one()) } - fn material_point_at_world_point(&self, part: &BodyPart, point: &Point) -> Point { + fn material_point_at_world_point(&self, part: &dyn BodyPart, point: &Point) -> Point { let elt = part.downcast_ref::>().expect("The provided body part must be a mass-constraint element"); fem_helper::material_point_at_world_point(elt.indices, &self.positions, point) } fn fill_constraint_geometry( &self, - part: &BodyPart, + part: &dyn BodyPart, _: usize, // FIXME: keep this parameter? center: &Point, force_dir: &ForceDirection, diff --git a/src/object/mass_spring_system.rs b/src/object/mass_spring_system.rs index fa6c9766c..80d49ed84 100644 --- a/src/object/mass_spring_system.rs +++ b/src/object/mass_spring_system.rs @@ -89,7 +89,7 @@ pub struct MassSpringSystem { plasticity_creep: N, plasticity_max_force: N, - user_data: Option>, + user_data: Option>, } fn key(i: usize, j: usize) -> (usize, usize) { @@ -597,8 +597,8 @@ impl Body for MassSpringSystem { self.velocities.fill(N::zero()); } - fn part(&self, id: usize) -> Option<&BodyPart> { - self.elements.get(id).map(|e| e as &BodyPart) + fn part(&self, id: usize) -> Option<&dyn BodyPart> { + self.elements.get(id).map(|e| e as &dyn BodyPart) } fn deformed_positions(&self) -> Option<(DeformationsType, &[N])> { @@ -610,25 +610,25 @@ impl Body for MassSpringSystem { Some((DeformationsType::Vectors, self.positions.as_mut_slice())) } - fn world_point_at_material_point(&self, part: &BodyPart, point: &Point) -> Point { + fn world_point_at_material_point(&self, part: &dyn BodyPart, point: &Point) -> Point { let elt = part.downcast_ref::>().expect("The provided body part must be a mass-spring element"); fem_helper::world_point_at_material_point(elt.indices, &self.positions, point) } - fn position_at_material_point(&self, part: &BodyPart, point: &Point) -> Isometry { + fn position_at_material_point(&self, part: &dyn BodyPart, point: &Point) -> Isometry { let elt = part.downcast_ref::>().expect("The provided body part must be a mass-spring element"); let pt = fem_helper::world_point_at_material_point(elt.indices, &self.positions, point); Isometry::from_parts(Translation::from(pt.coords), na::one()) } - fn material_point_at_world_point(&self, part: &BodyPart, point: &Point) -> Point { + fn material_point_at_world_point(&self, part: &dyn BodyPart, point: &Point) -> Point { let elt = part.downcast_ref::>().expect("The provided body part must be a mass-spring element"); fem_helper::material_point_at_world_point(elt.indices, &self.positions, point) } fn fill_constraint_geometry( &self, - part: &BodyPart, + part: &dyn BodyPart, _: usize, // FIXME: keep this parameter? center: &Point, force_dir: &ForceDirection, diff --git a/src/object/multibody.rs b/src/object/multibody.rs index 7e79d6025..5cc229cc6 100644 --- a/src/object/multibody.rs +++ b/src/object/multibody.rs @@ -36,7 +36,7 @@ pub struct Multibody { activation: ActivationStatus, ndofs: usize, companion_id: usize, - user_data: Option>, + user_data: Option>, /* * Workspaces. @@ -165,7 +165,7 @@ impl Multibody { fn add_link( &mut self, parent: BodyPartHandle, - mut dof: Box>, + mut dof: Box>, parent_shift: Vector, body_shift: Vector, local_inertia: Inertia, @@ -760,8 +760,8 @@ impl Body for Multibody { } #[inline] - fn part(&self, id: usize) -> Option<&BodyPart> { - self.link(id).map(|l| l as &BodyPart) + fn part(&self, id: usize) -> Option<&dyn BodyPart> { + self.link(id).map(|l| l as &dyn BodyPart) } #[inline] @@ -926,26 +926,26 @@ impl Body for Multibody { } #[inline] - fn world_point_at_material_point(&self, part: &BodyPart, point: &Point) -> Point { + fn world_point_at_material_point(&self, part: &dyn BodyPart, point: &Point) -> Point { let link = part.downcast_ref::>().expect("The provided body part must be a multibody link"); link.local_to_world * point } #[inline] - fn position_at_material_point(&self, part: &BodyPart, point: &Point) -> Isometry { + fn position_at_material_point(&self, part: &dyn BodyPart, point: &Point) -> Isometry { let link = part.downcast_ref::>().expect("The provided body part must be a multibody link"); link.local_to_world * Translation::from(point.coords) } #[inline] - fn material_point_at_world_point(&self, part: &BodyPart, point: &Point) -> Point { + fn material_point_at_world_point(&self, part: &dyn BodyPart, point: &Point) -> Point { let link = part.downcast_ref::>().expect("The provided body part must be a multibody link"); link.local_to_world.inverse_transform_point(point) } fn fill_constraint_geometry( &self, - part: &BodyPart, + part: &dyn BodyPart, ndofs: usize, // FIXME: keep this parameter? point: &Point, force_dir: &ForceDirection, @@ -1191,7 +1191,7 @@ impl Body for Multibody { pub struct MultibodyDesc<'a, N: RealField> { name: String, children: Vec>, - joint: Box>, + joint: Box>, velocity: Velocity, local_inertia: Inertia, local_center_of_mass: Point, diff --git a/src/object/multibody_link.rs b/src/object/multibody_link.rs index 9d9cb756a..34ab302a4 100644 --- a/src/object/multibody_link.rs +++ b/src/object/multibody_link.rs @@ -19,7 +19,7 @@ pub struct MultibodyLink { // XXX: rename to "joint". // (And rename the full-coordinates joint constraints JointConstraint). pub(crate) parent_internal_id: usize, - pub(crate) dof: Box>, + pub(crate) dof: Box>, pub(crate) parent_shift: Vector, pub(crate) body_shift: Vector, @@ -50,7 +50,7 @@ impl MultibodyLink { impulse_id: usize, multibody_handle: BodyHandle, parent_internal_id: usize, - dof: Box>, + dof: Box>, parent_shift: Vector, body_shift: Vector, parent_to_world: Isometry, @@ -98,13 +98,13 @@ impl MultibodyLink { /// Reference to the joint attaching this link to its parent. #[inline] - pub fn joint(&self) -> &Joint { + pub fn joint(&self) -> &dyn Joint { &*self.dof } /// Mutable reference to the joint attaching this link to its parent. #[inline] - pub fn joint_mut(&mut self) -> &mut Joint { + pub fn joint_mut(&mut self) -> &mut dyn Joint { &mut *self.dof } diff --git a/src/object/rigid_body.rs b/src/object/rigid_body.rs index b16772c28..ff76e4988 100644 --- a/src/object/rigid_body.rs +++ b/src/object/rigid_body.rs @@ -37,7 +37,7 @@ pub struct RigidBody { jacobian_mask: SpatialVector, companion_id: usize, update_status: BodyUpdateStatus, - user_data: Option> + user_data: Option> } impl RigidBody { @@ -487,7 +487,7 @@ impl Body for RigidBody { } #[inline] - fn part(&self, _: usize) -> Option<&BodyPart> { + fn part(&self, _: usize) -> Option<&dyn BodyPart> { Some(self) } @@ -497,17 +497,17 @@ impl Body for RigidBody { } #[inline] - fn world_point_at_material_point(&self, _: &BodyPart, point: &Point) -> Point { + fn world_point_at_material_point(&self, _: &dyn BodyPart, point: &Point) -> Point { self.position * point } #[inline] - fn position_at_material_point(&self, _: &BodyPart, point: &Point) -> Isometry { + fn position_at_material_point(&self, _: &dyn BodyPart, point: &Point) -> Isometry { self.position * Translation::from(point.coords) } #[inline] - fn material_point_at_world_point(&self, _: &BodyPart, point: &Point) -> Point { + fn material_point_at_world_point(&self, _: &dyn BodyPart, point: &Point) -> Point { self.position.inverse_transform_point(point) } @@ -524,7 +524,7 @@ impl Body for RigidBody { #[inline] fn fill_constraint_geometry( &self, - _: &BodyPart, + _: &dyn BodyPart, _: usize, point: &Point, force_dir: &ForceDirection, diff --git a/src/solver/helper.rs b/src/solver/helper.rs index 29f00f98f..7ce699627 100644 --- a/src/solver/helper.rs +++ b/src/solver/helper.rs @@ -54,10 +54,10 @@ impl Neg for ForceDirection { /// Every input are expressed in world-space. #[inline] pub fn constraint_pair_geometry( - body1: &Body, - part1: &BodyPart, - body2: &Body, - part2: &BodyPart, + body1: &dyn Body, + part1: &dyn BodyPart, + body2: &dyn Body, + part2: &dyn BodyPart, center1: &Point, center2: &Point, dir: &ForceDirection, @@ -139,8 +139,8 @@ pub fn constraint_pair_geometry( /// constraint (a constraint between a dynamic body and one without any degree of freedom). #[inline] pub fn constraints_are_ground_constraints( - body1: &Body, - body2: &Body, + body1: &dyn Body, + body2: &dyn Body, ) -> bool { body1.status_dependent_ndofs() == 0 || body2.status_dependent_ndofs() == 0 } @@ -148,8 +148,8 @@ pub fn constraints_are_ground_constraints( /// Retrieve the external velocity subvectors for the given bodies. #[inline(always)] pub fn split_ext_vels<'a, N: RealField>( - body1: &Body, - body2: &Body, + body1: &dyn Body, + body2: &dyn Body, assembly_id1: usize, assembly_id2: usize, ext_vels: &'a DVector) @@ -164,10 +164,10 @@ pub fn split_ext_vels<'a, N: RealField>( /// /// All inputs mut be given in world-space. pub fn cancel_relative_linear_velocity_wrt_axis( - body1: &Body, - part1: &BodyPart, - body2: &Body, - part2: &BodyPart, + body1: &dyn Body, + part1: &dyn BodyPart, + body2: &dyn Body, + part2: &dyn BodyPart, assembly_id1: usize, assembly_id2: usize, anchor1: &Point, @@ -239,10 +239,10 @@ pub fn cancel_relative_linear_velocity_wrt_axis( /// /// All inputs mut be given in world-space. pub fn cancel_relative_linear_velocity( - body1: &Body, - part1: &BodyPart, - body2: &Body, - part2: &BodyPart, + body1: &dyn Body, + part1: &dyn BodyPart, + body2: &dyn Body, + part2: &dyn BodyPart, assembly_id1: usize, assembly_id2: usize, anchor1: &Point, @@ -287,10 +287,10 @@ pub fn cancel_relative_linear_velocity( /// All inputs mut be given in world-space. pub fn cancel_relative_translation_wrt_axis( params: &IntegrationParameters, - body1: &Body, - part1: &BodyPart, - body2: &Body, - part2: &BodyPart, + body1: &dyn Body, + part1: &dyn BodyPart, + body2: &dyn Body, + part2: &dyn BodyPart, anchor1: &Point, anchor2: &Point, axis: &Unit>, @@ -349,10 +349,10 @@ pub fn cancel_relative_translation_wrt_axis( /// All inputs mut be given in world-space. pub fn cancel_relative_translation( params: &IntegrationParameters, - body1: &Body, - part1: &BodyPart, - body2: &Body, - part2: &BodyPart, + body1: &dyn Body, + part1: &dyn BodyPart, + body2: &dyn Body, + part2: &dyn BodyPart, anchor1: &Point, anchor2: &Point, jacobians: &mut [N], @@ -402,10 +402,10 @@ pub fn cancel_relative_translation( /// /// All inputs mut be given in world-space. pub fn cancel_relative_angular_velocity_wrt_axis( - body1: &Body, - part1: &BodyPart, - body2: &Body, - part2: &BodyPart, + body1: &dyn Body, + part1: &dyn BodyPart, + body2: &dyn Body, + part2: &dyn BodyPart, assembly_id1: usize, assembly_id2: usize, anchor1: &Point, @@ -477,10 +477,10 @@ pub fn cancel_relative_angular_velocity_wrt_axis( /// /// All inputs mut be given in world-space. pub fn cancel_relative_angular_velocity( - body1: &Body, - part1: &BodyPart, - body2: &Body, - part2: &BodyPart, + body1: &dyn Body, + part1: &dyn BodyPart, + body2: &dyn Body, + part2: &dyn BodyPart, assembly_id1: usize, assembly_id2: usize, anchor1: &Point, @@ -525,10 +525,10 @@ pub fn cancel_relative_angular_velocity( /// All inputs mut be given in world-space. pub fn cancel_relative_rotation( params: &IntegrationParameters, - body1: &Body, - part1: &BodyPart, - body2: &Body, - part2: &BodyPart, + body1: &dyn Body, + part1: &dyn BodyPart, + body2: &dyn Body, + part2: &dyn BodyPart, anchor1: &Point, anchor2: &Point, rotation1: &Rotation, @@ -730,10 +730,10 @@ pub fn align_axis( /// /// All inputs mut be given in world-space. pub fn restrict_relative_linear_velocity_to_axis( - body1: &Body, - part1: &BodyPart, - body2: &Body, - part2: &BodyPart, + body1: &dyn Body, + part1: &dyn BodyPart, + body2: &dyn Body, + part2: &dyn BodyPart, assembly_id1: usize, assembly_id2: usize, anchor1: &Point, @@ -814,10 +814,10 @@ pub fn restrict_relative_linear_velocity_to_axis( /// All inputs mut be given in world-space. pub fn project_anchor_to_axis( params: &IntegrationParameters, - body1: &Body, - part1: &BodyPart, - body2: &Body, - part2: &BodyPart, + body1: &dyn Body, + part1: &dyn BodyPart, + body2: &dyn Body, + part2: &dyn BodyPart, anchor1: &Point, anchor2: &Point, axis1: &Unit>, diff --git a/src/solver/moreau_jean_solver.rs b/src/solver/moreau_jean_solver.rs index 782d662d4..61e5cefcd 100644 --- a/src/solver/moreau_jean_solver.rs +++ b/src/solver/moreau_jean_solver.rs @@ -16,14 +16,14 @@ pub struct MoreauJeanSolver { // FIXME: use a Vec or a DVector? mj_lambda_vel: DVector, ext_vels: DVector, - contact_model: Box>, + contact_model: Box>, constraints: ConstraintSet, internal_constraints: Vec, } impl MoreauJeanSolver { /// Create a new time-stepping scheme with the given contact model. - pub fn new(contact_model: Box>) -> Self { + pub fn new(contact_model: Box>) -> Self { let constraints = ConstraintSet::new(); MoreauJeanSolver { @@ -37,7 +37,7 @@ impl MoreauJeanSolver { } /// Sets the contact model. - pub fn set_contact_model(&mut self, model: Box>) { + pub fn set_contact_model(&mut self, model: Box>) { self.contact_model = model } @@ -46,7 +46,7 @@ impl MoreauJeanSolver { &mut self, counters: &mut Counters, bodies: &mut BodySet, - joints: &mut Slab>>, + joints: &mut Slab>>, manifolds: &[ColliderContactManifold], island: &[BodyHandle], params: &IntegrationParameters, @@ -79,7 +79,7 @@ impl MoreauJeanSolver { params: &IntegrationParameters, coefficients: &MaterialsCoefficientsTable, bodies: &mut BodySet, - joints: &mut Slab>>, + joints: &mut Slab>>, manifolds: &[ColliderContactManifold], island: &[BodyHandle], ) { @@ -225,7 +225,7 @@ impl MoreauJeanSolver { params: &IntegrationParameters, cworld: &ColliderWorld, bodies: &mut BodySet, - joints: &mut Slab>>, + joints: &mut Slab>>, ) { NonlinearSORProx::solve( params, @@ -242,7 +242,7 @@ impl MoreauJeanSolver { fn save_cache( &mut self, bodies: &mut BodySet, - joints: &mut Slab>>, + joints: &mut Slab>>, ) { self.contact_model.cache_impulses(&self.constraints); diff --git a/src/solver/nonlinear_sor_prox.rs b/src/solver/nonlinear_sor_prox.rs index 453f2488c..ed9bc3632 100644 --- a/src/solver/nonlinear_sor_prox.rs +++ b/src/solver/nonlinear_sor_prox.rs @@ -19,7 +19,7 @@ impl NonlinearSORProx { cworld: &ColliderWorld, bodies: &mut BodySet, constraints: &mut [NonlinearUnilateralConstraint], - joints_constraints: &Slab>>, // FIXME: ugly, use a slice of refs instead. + joints_constraints: &Slab>>, // FIXME: ugly, use a slice of refs instead. internal_constraints: &[BodyHandle], jacobians: &mut [N], max_iter: usize, diff --git a/src/solver/signorini_model.rs b/src/solver/signorini_model.rs index 2a3354c2f..f8f8c8541 100644 --- a/src/solver/signorini_model.rs +++ b/src/solver/signorini_model.rs @@ -32,10 +32,10 @@ impl SignoriniModel { /// Build a non-penetration velocity-based constraint for the given contact. pub fn build_velocity_constraint( params: &IntegrationParameters, - body1: &Body, - part1: &BodyPart, - body2: &Body, - part2: &BodyPart, + body1: &dyn Body, + part1: &dyn BodyPart, + body2: &dyn Body, + part2: &dyn BodyPart, props: &LocalMaterialProperties, manifold: &ColliderContactManifold, ext_vels: &DVector, diff --git a/src/utils/user_data.rs b/src/utils/user_data.rs index 8855353f9..704ea7b50 100644 --- a/src/utils/user_data.rs +++ b/src/utils/user_data.rs @@ -4,26 +4,26 @@ use std::any::Any; /// Trait to be implemented by user-defined data. pub trait UserData: Any + Send + Sync { /// Clone this trait-object. - fn clone_boxed(&self) -> Box; + fn clone_boxed(&self) -> Box; /// Clone as its super-trait trait objects. - fn to_any(&self) -> Box; + fn to_any(&self) -> Box; /// Downcast to Any. - fn as_any(&self) -> &(Any + Send + Sync); + fn as_any(&self) -> &(dyn Any + Send + Sync); } impl UserData for T { #[inline] - fn clone_boxed(&self) -> Box { + fn clone_boxed(&self) -> Box { Box::new(self.clone()) } #[inline] - fn to_any(&self) -> Box { + fn to_any(&self) -> Box { Box::new(self.clone()) } #[inline] - fn as_any(&self) -> &(Any + Send + Sync) { + fn as_any(&self) -> &(dyn Any + Send + Sync) { self } } @@ -31,7 +31,7 @@ impl UserData for T { // We need this because we must not implement Clone for Box // directly otherwise Box would implement UserData too and // we want to avoid the user mistakenly nesting user-datas. -pub(crate) struct UserDataBox(pub Box); +pub(crate) struct UserDataBox(pub Box); impl Clone for UserDataBox { #[inline] diff --git a/src/volumetric/volumetric_convex2.rs b/src/volumetric/volumetric_convex2.rs index 96aa37f05..1b3ef3a69 100644 --- a/src/volumetric/volumetric_convex2.rs +++ b/src/volumetric/volumetric_convex2.rs @@ -156,9 +156,9 @@ impl Volumetric for ConvexPolygon { #[cfg(test)] mod test { - use na::{self, Matrix1, Point2, Vector2, Vector3}; + use na::{self, Matrix1, Point2, Vector2}; use ncollide::shape::{Cuboid, ConvexPolygon}; - use ncollide::procedural; + use crate::volumetric::Volumetric; #[test] diff --git a/src/volumetric/volumetric_shape.rs b/src/volumetric/volumetric_shape.rs index 8b708a091..b580e6fd3 100644 --- a/src/volumetric/volumetric_shape.rs +++ b/src/volumetric/volumetric_shape.rs @@ -49,7 +49,7 @@ macro_rules! dispatch( } ); -impl Volumetric for Shape { +impl Volumetric for dyn Shape { fn area(&self) -> N { dispatch!(Point, AngularInertia, self.area()) } diff --git a/src/world/world.rs b/src/world/world.rs index 7644c2cdc..418edc5c6 100644 --- a/src/world/world.rs +++ b/src/world/world.rs @@ -30,8 +30,8 @@ pub struct World { // FIXME: set those two parameters per-collider? prediction: N, gravity: Vector, - constraints: Slab>>, - forces: Slab>>, + constraints: Slab>>, + forces: Slab>>, params: IntegrationParameters, } @@ -149,12 +149,12 @@ impl World { } /// Get a reference to the specified constraint. - pub fn constraint(&self, handle: ConstraintHandle) -> &JointConstraint { + pub fn constraint(&self, handle: ConstraintHandle) -> &dyn JointConstraint { &*self.constraints[handle] } /// Get a mutable reference to the specified constraint. - pub fn constraint_mut(&mut self, handle: ConstraintHandle) -> &mut JointConstraint { + pub fn constraint_mut(&mut self, handle: ConstraintHandle) -> &mut dyn JointConstraint { let (anchor1, anchor2) = self.constraints[handle].anchors(); self.activate_body(anchor1.0); self.activate_body(anchor2.0); @@ -162,7 +162,7 @@ impl World { } /// Remove the specified constraint from the world. - pub fn remove_constraint(&mut self, handle: ConstraintHandle) -> Box> { + pub fn remove_constraint(&mut self, handle: ConstraintHandle) -> Box> { let constraint = self.constraints.remove(handle); let (anchor1, anchor2) = constraint.anchors(); self.activate_body(anchor1.0); @@ -197,12 +197,12 @@ impl World { } /// Retrieve a reference to the specified force generator. - pub fn force_generator(&self, handle: ForceGeneratorHandle) -> &ForceGenerator { + pub fn force_generator(&self, handle: ForceGeneratorHandle) -> &dyn ForceGenerator { &*self.forces[handle] } /// Retrieve a mutable reference to the specified force generator. - pub fn force_generator_mut(&mut self, handle: ForceGeneratorHandle) -> &mut ForceGenerator { + pub fn force_generator_mut(&mut self, handle: ForceGeneratorHandle) -> &mut dyn ForceGenerator { &mut *self.forces[handle] } @@ -210,7 +210,7 @@ impl World { pub fn remove_force_generator( &mut self, handle: ForceGeneratorHandle, - ) -> Box> { + ) -> Box> { self.forces.remove(handle) } @@ -425,12 +425,12 @@ impl World { } /// Get a reference to the specified body. - pub fn body(&self, handle: BodyHandle) -> Option<&Body> { + pub fn body(&self, handle: BodyHandle) -> Option<&dyn Body> { self.bodies.body(handle) } /// Get a mutable reference to the specified body. - pub fn body_mut(&mut self, handle: BodyHandle) -> Option<&mut Body> { + pub fn body_mut(&mut self, handle: BodyHandle) -> Option<&mut dyn Body> { self.bodies.body_mut(handle) } @@ -511,18 +511,18 @@ impl World { } /// An iterator through all the bodies on this world. - pub fn bodies(&self) -> impl Iterator> { self.bodies.bodies() } + pub fn bodies(&self) -> impl Iterator> { self.bodies.bodies() } /// A mutable iterator through all the bodies on this world. - pub fn bodies_mut(&mut self) -> impl Iterator> { self.bodies.bodies_mut() } + pub fn bodies_mut(&mut self) -> impl Iterator> { self.bodies.bodies_mut() } /// An iterator through all the bodies with the given name. - pub fn bodies_with_name<'a>(&'a self, name: &'a str) -> impl Iterator> { + pub fn bodies_with_name<'a>(&'a self, name: &'a str) -> impl Iterator> { self.bodies().filter(move |b| b.name() == name) } /// An iterator through all the bodies with the given name. - pub fn bodies_with_name_mut<'a>(&'a mut self, name: &'a str) -> impl Iterator> { + pub fn bodies_with_name_mut<'a>(&'a mut self, name: &'a str) -> impl Iterator> { self.bodies_mut().filter(move |b| b.name() == name) } @@ -549,6 +549,6 @@ mod test { #[test] fn world_is_send_sync() { - let _ = Box::new(World::::new()) as Box; + let _ = Box::new(World::::new()) as Box; } } From dfec4ff37d11da24e276cff6ecc270c6af918b85 Mon Sep 17 00:00:00 2001 From: Sybrand Aarnoutse Date: Tue, 9 Jul 2019 21:58:11 +0200 Subject: [PATCH 2/2] fix nphysics3d, testbeds and examples3d --- examples3d/constraints3.rs | 4 ++-- examples3d/convex_decomposition3.rs | 4 ++-- examples3d/fem_volume3.rs | 2 +- examples3d/known_bug_excentric_convex3.rs | 6 +++--- nphysics_testbed2d/src/engine.rs | 6 +++--- nphysics_testbed2d/src/testbed.rs | 18 ++++++++--------- nphysics_testbed2d/src/world_owner.rs | 12 ++++++------ nphysics_testbed3d/src/engine.rs | 14 ++++++------- nphysics_testbed3d/src/testbed.rs | 18 ++++++++--------- nphysics_testbed3d/src/world_owner.rs | 12 ++++++------ src/joint/ball_joint.rs | 2 +- src/joint/cylindrical_joint.rs | 2 +- src/joint/helical_joint.rs | 2 +- src/joint/pin_slot_joint.rs | 2 +- src/joint/planar_joint.rs | 2 +- src/joint/rectangular_joint.rs | 2 +- src/joint/universal_joint.rs | 2 +- src/object/fem_volume.rs | 14 ++++++------- src/solver/helper.rs | 24 +++++++++++------------ 19 files changed, 74 insertions(+), 74 deletions(-) diff --git a/examples3d/constraints3.rs b/examples3d/constraints3.rs index 20eba53be..db36c50a9 100644 --- a/examples3d/constraints3.rs +++ b/examples3d/constraints3.rs @@ -3,12 +3,12 @@ extern crate ncollide3d; extern crate nphysics3d; extern crate nphysics_testbed3d; -use na::{Isometry3, Point3, Vector3}; +use na::{Point3, Vector3}; use ncollide3d::shape::{Cuboid, ShapeHandle}; use nphysics3d::joint::{BallConstraint, PinSlotConstraint, PlanarConstraint, PrismaticConstraint, RectangularConstraint, RevoluteConstraint, UniversalConstraint}; use nphysics3d::object::{BodyPartHandle, ColliderDesc, RigidBodyDesc}; -use nphysics3d::volumetric::Volumetric; + use nphysics3d::world::World; use nphysics_testbed3d::Testbed; use std::f32::consts::{FRAC_PI_2, PI}; diff --git a/examples3d/convex_decomposition3.rs b/examples3d/convex_decomposition3.rs index bc83394ab..743a329cf 100644 --- a/examples3d/convex_decomposition3.rs +++ b/examples3d/convex_decomposition3.rs @@ -6,12 +6,12 @@ extern crate nphysics_testbed3d; extern crate rand; use std::path::Path; -use na::{Isometry3, Point3, Translation3, Vector3}; +use na::{Point3, Translation3, Vector3}; use kiss3d::loader::obj; use ncollide3d::shape::{Compound, ConvexHull, Cuboid, ShapeHandle}; use ncollide3d::procedural::TriMesh; use ncollide3d::transformation; -use ncollide3d::bounding_volume::{self, BoundingVolume, AABB}; +use ncollide3d::bounding_volume::{self, BoundingVolume}; use nphysics3d::world::World; use nphysics3d::object::{ColliderDesc, RigidBodyDesc}; use nphysics_testbed3d::Testbed; diff --git a/examples3d/fem_volume3.rs b/examples3d/fem_volume3.rs index f94af4ed6..fb05b7026 100644 --- a/examples3d/fem_volume3.rs +++ b/examples3d/fem_volume3.rs @@ -3,7 +3,7 @@ extern crate ncollide3d; extern crate nphysics3d; extern crate nphysics_testbed3d; -use na::{Point3, Vector3, Point4}; +use na::{Point3, Vector3}; use ncollide3d::shape::{Cuboid, ShapeHandle}; use nphysics3d::object::{FEMVolumeDesc, ColliderDesc}; use nphysics3d::world::World; diff --git a/examples3d/known_bug_excentric_convex3.rs b/examples3d/known_bug_excentric_convex3.rs index a949169fe..368382c11 100644 --- a/examples3d/known_bug_excentric_convex3.rs +++ b/examples3d/known_bug_excentric_convex3.rs @@ -24,12 +24,12 @@ extern crate ncollide3d; extern crate nphysics3d; extern crate nphysics_testbed3d; -use na::{Isometry3, Point3, Vector3}; +use na::{Point3, Vector3}; use ncollide3d::shape::{ConvexHull, Cuboid, ShapeHandle}; -use ncollide3d::procedural; + use nphysics3d::world::World; use nphysics3d::object::{ColliderDesc, RigidBodyDesc}; -use nphysics3d::volumetric::Volumetric; + use nphysics_testbed3d::Testbed; diff --git a/nphysics_testbed2d/src/engine.rs b/nphysics_testbed2d/src/engine.rs index c5f243429..9aa7ae228 100644 --- a/nphysics_testbed2d/src/engine.rs +++ b/nphysics_testbed2d/src/engine.rs @@ -213,7 +213,7 @@ impl GraphicsManager { object: ColliderHandle, world: &World, delta: Isometry2, - shape: &Shape, + shape: &dyn Shape, color: Point3, out: &mut Vec, ) { @@ -429,8 +429,8 @@ impl GraphicsManager { // } // } - pub fn camera_mut<'a>(&'a mut self) -> &'a mut PlanarCamera { - &mut self.camera as &'a mut PlanarCamera + pub fn camera_mut<'a>(&'a mut self) -> &'a mut dyn PlanarCamera { + &mut self.camera as &'a mut dyn PlanarCamera } pub fn look_at(&mut self, at: Point2, zoom: f32) { diff --git a/nphysics_testbed2d/src/testbed.rs b/nphysics_testbed2d/src/testbed.rs index f78144dd7..c12173cc7 100644 --- a/nphysics_testbed2d/src/testbed.rs +++ b/nphysics_testbed2d/src/testbed.rs @@ -91,11 +91,11 @@ pub struct Testbed { cursor_pos: Point2, grabbed_object: Option, grabbed_object_constraint: Option, - world: Box, + world: Box, drawing_ray: Option>, } -type Callbacks = Vec>; +type Callbacks = Vec>; impl Testbed { pub fn new_empty() -> Testbed { @@ -130,7 +130,7 @@ impl Testbed { Testbed::new_with_world_owner(Box::new(world)) } - pub fn new_with_world_owner(world_owner: Box) -> Testbed { + pub fn new_with_world_owner(world_owner: Box) -> Testbed { let mut res = Testbed::new_empty(); res.set_world_owner(world_owner); @@ -154,7 +154,7 @@ impl Testbed { self.set_world_owner(Box::new(world)); } - pub fn set_world_owner(&mut self, world: Box) { + pub fn set_world_owner(&mut self, world: Box) { self.world = world; let mut world = self.world.get_mut(); world.enable_performance_counters(); @@ -179,7 +179,7 @@ impl Testbed { self.graphics.set_collider_color(collider, color); } - pub fn world(&self) -> &Box { + pub fn world(&self) -> &Box { &self.world } @@ -214,7 +214,7 @@ impl Testbed { res } - pub fn add_callback( + pub fn add_callback( &mut self, callback: F, ) { @@ -242,9 +242,9 @@ impl Testbed { } type CameraEffects<'a> = ( - Option<&'a mut Camera>, - Option<&'a mut PlanarCamera>, - Option<&'a mut PostProcessingEffect>, + Option<&'a mut dyn Camera>, + Option<&'a mut dyn PlanarCamera>, + Option<&'a mut dyn PostProcessingEffect>, ); impl State for Testbed { diff --git a/nphysics_testbed2d/src/world_owner.rs b/nphysics_testbed2d/src/world_owner.rs index 791e211fd..909ae4cdf 100644 --- a/nphysics_testbed2d/src/world_owner.rs +++ b/nphysics_testbed2d/src/world_owner.rs @@ -9,26 +9,26 @@ use std::sync::RwLock; pub trait WorldOwner { // FIXME: avoid the systematic Box by using associated type // which also requires the testbed to be parametrized by the world type. - fn get<'a: 'b, 'b>(&'a self) -> Box> + 'b>; - fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box> + 'b>; + fn get<'a: 'b, 'b>(&'a self) -> Box> + 'b>; + fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box> + 'b>; } impl WorldOwner for World { - fn get<'a: 'b, 'b>(&'a self) -> Box> + 'b> { + fn get<'a: 'b, 'b>(&'a self) -> Box> + 'b> { Box::new(self) } - fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box> + 'b> { + fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box> + 'b> { Box::new(self) } } impl WorldOwner for Arc>> { - fn get<'a: 'b, 'b>(&'a self) -> Box> + 'b> { + fn get<'a: 'b, 'b>(&'a self) -> Box> + 'b> { Box::new(self.read().unwrap()) } - fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box> + 'b> { + fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box> + 'b> { Box::new(self.write().unwrap()) } } diff --git a/nphysics_testbed3d/src/engine.rs b/nphysics_testbed3d/src/engine.rs index 39dbb9a6b..2b33cf692 100644 --- a/nphysics_testbed3d/src/engine.rs +++ b/nphysics_testbed3d/src/engine.rs @@ -213,7 +213,7 @@ impl GraphicsManager { object: ColliderHandle, world: &World, delta: Isometry3, - shape: &Shape, + shape: &dyn Shape, color: Point3, out: &mut Vec, ) { @@ -443,19 +443,19 @@ impl GraphicsManager { self.curr_is_arc_ball = !self.curr_is_arc_ball; } - pub fn camera<'a>(&'a self) -> &'a Camera { + pub fn camera<'a>(&'a self) -> &'a dyn Camera { if self.curr_is_arc_ball { - &self.arc_ball as &'a Camera + &self.arc_ball as &'a dyn Camera } else { - &self.first_person as &'a Camera + &self.first_person as &'a dyn Camera } } - pub fn camera_mut<'a>(&'a mut self) -> &'a mut Camera { + pub fn camera_mut<'a>(&'a mut self) -> &'a mut dyn Camera { if self.curr_is_arc_ball { - &mut self.arc_ball as &'a mut Camera + &mut self.arc_ball as &'a mut dyn Camera } else { - &mut self.first_person as &'a mut Camera + &mut self.first_person as &'a mut dyn Camera } } diff --git a/nphysics_testbed3d/src/testbed.rs b/nphysics_testbed3d/src/testbed.rs index 7443fd7c5..b0795f6c8 100644 --- a/nphysics_testbed3d/src/testbed.rs +++ b/nphysics_testbed3d/src/testbed.rs @@ -81,7 +81,7 @@ fn usage(exe_name: &str) { } pub struct Testbed { - world: Box, + world: Box, window: Option>, graphics: GraphicsManager, nsteps: usize, @@ -99,7 +99,7 @@ pub struct Testbed { grabbed_object_plane: (Point3, Vector3), } -type Callbacks = Vec>; +type Callbacks = Vec>; impl Testbed { pub fn new_empty() -> Testbed { @@ -134,7 +134,7 @@ impl Testbed { Self::new_with_world_owner(Box::new(world)) } - pub fn new_with_world_owner(world: Box) -> Self { + pub fn new_with_world_owner(world: Box) -> Self { let mut res = Testbed::new_empty(); res.set_world_owner(world); @@ -157,7 +157,7 @@ impl Testbed { self.set_world_owner(Box::new(world)) } - pub fn set_world_owner(&mut self, world: Box) { + pub fn set_world_owner(&mut self, world: Box) { self.world = world; let mut world = self.world.get_mut(); world.enable_performance_counters(); @@ -182,7 +182,7 @@ impl Testbed { self.graphics.set_collider_color(collider, color); } - pub fn world(&self) -> &Box { + pub fn world(&self) -> &Box { &self.world } @@ -217,7 +217,7 @@ impl Testbed { res } - pub fn add_callback( + pub fn add_callback( &mut self, callback: F, ) { @@ -245,9 +245,9 @@ impl Testbed { } type CameraEffects<'a> = ( - Option<&'a mut Camera>, - Option<&'a mut PlanarCamera>, - Option<&'a mut PostProcessingEffect>, + Option<&'a mut dyn Camera>, + Option<&'a mut dyn PlanarCamera>, + Option<&'a mut dyn PostProcessingEffect>, ); impl State for Testbed { diff --git a/nphysics_testbed3d/src/world_owner.rs b/nphysics_testbed3d/src/world_owner.rs index 9aec2f877..6e24ae071 100644 --- a/nphysics_testbed3d/src/world_owner.rs +++ b/nphysics_testbed3d/src/world_owner.rs @@ -9,26 +9,26 @@ use std::sync::RwLock; pub trait WorldOwner { // FIXME: avoid the systematic Box by using associated type // which also requires the testbed to be parametrized by the world type. - fn get<'a: 'b, 'b>(&'a self) -> Box> + 'b>; - fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box> + 'b>; + fn get<'a: 'b, 'b>(&'a self) -> Box> + 'b>; + fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box> + 'b>; } impl WorldOwner for World { - fn get<'a: 'b, 'b>(&'a self) -> Box> + 'b> { + fn get<'a: 'b, 'b>(&'a self) -> Box> + 'b> { Box::new(self) } - fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box> + 'b> { + fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box> + 'b> { Box::new(self) } } impl WorldOwner for Arc>> { - fn get<'a: 'b, 'b>(&'a self) -> Box> + 'b> { + fn get<'a: 'b, 'b>(&'a self) -> Box> + 'b> { Box::new(self.read().unwrap()) } - fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box> + 'b> { + fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box> + 'b> { Box::new(self.write().unwrap()) } } diff --git a/src/joint/ball_joint.rs b/src/joint/ball_joint.rs index c61ee891c..eec3b2e8d 100644 --- a/src/joint/ball_joint.rs +++ b/src/joint/ball_joint.rs @@ -30,7 +30,7 @@ impl BallJoint { impl Joint for BallJoint { #[inline] - fn clone(&self) -> Box> { + fn clone(&self) -> Box> { Box::new(*self) } diff --git a/src/joint/cylindrical_joint.rs b/src/joint/cylindrical_joint.rs index 7d188303b..11ab132d9 100644 --- a/src/joint/cylindrical_joint.rs +++ b/src/joint/cylindrical_joint.rs @@ -26,7 +26,7 @@ impl CylindricalJoint { impl Joint for CylindricalJoint { #[inline] - fn clone(&self) -> Box> { + fn clone(&self) -> Box> { Box::new(*self) } diff --git a/src/joint/helical_joint.rs b/src/joint/helical_joint.rs index 001bb959c..23619fec8 100644 --- a/src/joint/helical_joint.rs +++ b/src/joint/helical_joint.rs @@ -40,7 +40,7 @@ impl HelicalJoint { impl Joint for HelicalJoint { #[inline] - fn clone(&self) -> Box> { + fn clone(&self) -> Box> { Box::new(*self) } diff --git a/src/joint/pin_slot_joint.rs b/src/joint/pin_slot_joint.rs index 22f7eb72d..db54bb90b 100644 --- a/src/joint/pin_slot_joint.rs +++ b/src/joint/pin_slot_joint.rs @@ -37,7 +37,7 @@ impl PinSlotJoint { impl Joint for PinSlotJoint { #[inline] - fn clone(&self) -> Box> { + fn clone(&self) -> Box> { Box::new(*self) } diff --git a/src/joint/planar_joint.rs b/src/joint/planar_joint.rs index c24aed2c0..b1816e3a5 100644 --- a/src/joint/planar_joint.rs +++ b/src/joint/planar_joint.rs @@ -44,7 +44,7 @@ impl PlanarJoint { impl Joint for PlanarJoint { #[inline] - fn clone(&self) -> Box> { + fn clone(&self) -> Box> { Box::new(*self) } diff --git a/src/joint/rectangular_joint.rs b/src/joint/rectangular_joint.rs index c8e1c3f87..f5a25174d 100644 --- a/src/joint/rectangular_joint.rs +++ b/src/joint/rectangular_joint.rs @@ -26,7 +26,7 @@ impl RectangularJoint { impl Joint for RectangularJoint { #[inline] - fn clone(&self) -> Box> { + fn clone(&self) -> Box> { Box::new(*self) } diff --git a/src/joint/universal_joint.rs b/src/joint/universal_joint.rs index 5c6d86852..34de8a203 100644 --- a/src/joint/universal_joint.rs +++ b/src/joint/universal_joint.rs @@ -31,7 +31,7 @@ impl UniversalJoint { impl Joint for UniversalJoint { #[inline] - fn clone(&self) -> Box> { + fn clone(&self) -> Box> { Box::new(*self) } diff --git a/src/object/fem_volume.rs b/src/object/fem_volume.rs index ef3c1895a..d42c03b0a 100644 --- a/src/object/fem_volume.rs +++ b/src/object/fem_volume.rs @@ -74,7 +74,7 @@ pub struct FEMVolume { status: BodyStatus, update_status: BodyUpdateStatus, - user_data: Option>, + user_data: Option>, } impl FEMVolume { @@ -834,29 +834,29 @@ impl Body for FEMVolume { self.activation.set_deactivation_threshold(threshold) } - fn part(&self, id: usize) -> Option<&BodyPart> { - self.elements.get(id).map(|e| e as &BodyPart) + fn part(&self, id: usize) -> Option<&dyn BodyPart> { + self.elements.get(id).map(|e| e as &dyn BodyPart) } - fn world_point_at_material_point(&self, part: &BodyPart, point: &Point3) -> Point3 { + fn world_point_at_material_point(&self, part: &dyn BodyPart, point: &Point3) -> Point3 { let elt = part.downcast_ref::>().expect("The provided body part must be tetrahedral element"); fem_helper::world_point_at_material_point(FiniteElementIndices::Tetrahedron(elt.indices), &self.positions, point) } - fn position_at_material_point(&self, part: &BodyPart, point: &Point3) -> Isometry3 { + fn position_at_material_point(&self, part: &dyn BodyPart, point: &Point3) -> Isometry3 { let elt = part.downcast_ref::>().expect("The provided body part must be a tetrahedral element"); let pt = fem_helper::world_point_at_material_point(FiniteElementIndices::Tetrahedron(elt.indices), &self.positions, point); Isometry3::from_parts(Translation3::from(pt.coords), na::one()) } - fn material_point_at_world_point(&self, part: &BodyPart, point: &Point3) -> Point3 { + fn material_point_at_world_point(&self, part: &dyn BodyPart, point: &Point3) -> Point3 { let elt = part.downcast_ref::>().expect("The provided body part must be tetrahedral element"); fem_helper::material_point_at_world_point(FiniteElementIndices::Tetrahedron(elt.indices), &self.positions, point) } fn fill_constraint_geometry( &self, - part: &BodyPart, + part: &dyn BodyPart, _: usize, // FIXME: keep this parameter? center: &Point3, force_dir: &ForceDirection, diff --git a/src/solver/helper.rs b/src/solver/helper.rs index 7ce699627..ffbc1c8ef 100644 --- a/src/solver/helper.rs +++ b/src/solver/helper.rs @@ -581,10 +581,10 @@ pub fn cancel_relative_rotation( /// All inputs mut be given in world-space. #[cfg(feature = "dim3")] pub fn restrict_relative_angular_velocity_to_axis( - body1: &Body, - part1: &BodyPart, - body2: &Body, - part2: &BodyPart, + body1: &dyn Body, + part1: &dyn BodyPart, + body2: &dyn Body, + part2: &dyn BodyPart, assembly_id1: usize, assembly_id2: usize, axis: &Unit>, @@ -665,10 +665,10 @@ pub fn restrict_relative_angular_velocity_to_axis( #[cfg(feature = "dim3")] pub fn align_axis( params: &IntegrationParameters, - body1: &Body, - part1: &BodyPart, - body2: &Body, - part2: &BodyPart, + body1: &dyn Body, + part1: &dyn BodyPart, + body2: &dyn Body, + part2: &dyn BodyPart, anchor1: &Point, anchor2: &Point, axis1: &Unit>, @@ -873,10 +873,10 @@ pub fn project_anchor_to_axis( #[cfg(feature = "dim3")] pub fn restore_angle_between_axis( params: &IntegrationParameters, - body1: &Body, - part1: &BodyPart, - body2: &Body, - part2: &BodyPart, + body1: &dyn Body, + part1: &dyn BodyPart, + body2: &dyn Body, + part2: &dyn BodyPart, anchor1: &Point, anchor2: &Point, axis1: &Unit>,