Rename JointHandle -> ImpulseJointHandle

This commit is contained in:
Sébastien Crozet
2022-01-25 22:58:18 +01:00
committed by Sébastien Crozet
parent 22f21c14b8
commit 0bb0e412e6
3 changed files with 22 additions and 19 deletions

View File

@@ -1,4 +1,4 @@
use crate::dynamics::{JointData, JointHandle, RigidBodyHandle}; use crate::dynamics::{ImpulseJointHandle, JointData, RigidBodyHandle};
use crate::math::{Real, SpacialVector}; use crate::math::{Real, SpacialVector};
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
@@ -14,7 +14,7 @@ pub struct ImpulseJoint {
pub impulses: SpacialVector<Real>, pub impulses: SpacialVector<Real>,
// A joint needs to know its handle to simplify its removal. // A joint needs to know its handle to simplify its removal.
pub(crate) handle: JointHandle, pub(crate) handle: ImpulseJointHandle,
#[cfg(feature = "parallel")] #[cfg(feature = "parallel")]
pub(crate) constraint_index: usize, pub(crate) constraint_index: usize,
} }

View File

@@ -11,9 +11,9 @@ use crate::dynamics::{JointData, RigidBodyHandle};
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[repr(transparent)] #[repr(transparent)]
pub struct JointHandle(pub crate::data::arena::Index); pub struct ImpulseJointHandle(pub crate::data::arena::Index);
impl JointHandle { impl ImpulseJointHandle {
/// Converts this handle into its (index, generation) components. /// Converts this handle into its (index, generation) components.
pub fn into_raw_parts(self) -> (u32, u32) { pub fn into_raw_parts(self) -> (u32, u32) {
self.0.into_raw_parts() self.0.into_raw_parts()
@@ -82,18 +82,18 @@ impl ImpulseJointSet {
} }
/// Is the given joint handle valid? /// Is the given joint handle valid?
pub fn contains(&self, handle: JointHandle) -> bool { pub fn contains(&self, handle: ImpulseJointHandle) -> bool {
self.joint_ids.contains(handle.0) self.joint_ids.contains(handle.0)
} }
/// Gets the joint with the given handle. /// Gets the joint with the given handle.
pub fn get(&self, handle: JointHandle) -> Option<&ImpulseJoint> { pub fn get(&self, handle: ImpulseJointHandle) -> Option<&ImpulseJoint> {
let id = self.joint_ids.get(handle.0)?; let id = self.joint_ids.get(handle.0)?;
self.joint_graph.graph.edge_weight(*id) self.joint_graph.graph.edge_weight(*id)
} }
/// Gets a mutable reference to the joint with the given handle. /// Gets a mutable reference to the joint with the given handle.
pub fn get_mut(&mut self, handle: JointHandle) -> Option<&mut ImpulseJoint> { pub fn get_mut(&mut self, handle: ImpulseJointHandle) -> Option<&mut ImpulseJoint> {
let id = self.joint_ids.get(handle.0)?; let id = self.joint_ids.get(handle.0)?;
self.joint_graph.graph.edge_weight_mut(*id) self.joint_graph.graph.edge_weight_mut(*id)
} }
@@ -107,11 +107,11 @@ impl ImpulseJointSet {
/// ///
/// Using this is discouraged in favor of `self.get(handle)` which does not /// Using this is discouraged in favor of `self.get(handle)` which does not
/// suffer form the ABA problem. /// suffer form the ABA problem.
pub fn get_unknown_gen(&self, i: u32) -> Option<(&ImpulseJoint, JointHandle)> { pub fn get_unknown_gen(&self, i: u32) -> Option<(&ImpulseJoint, ImpulseJointHandle)> {
let (id, handle) = self.joint_ids.get_unknown_gen(i)?; let (id, handle) = self.joint_ids.get_unknown_gen(i)?;
Some(( Some((
self.joint_graph.graph.edge_weight(*id)?, self.joint_graph.graph.edge_weight(*id)?,
JointHandle(handle), ImpulseJointHandle(handle),
)) ))
} }
@@ -124,16 +124,19 @@ impl ImpulseJointSet {
/// ///
/// Using this is discouraged in favor of `self.get_mut(handle)` which does not /// Using this is discouraged in favor of `self.get_mut(handle)` which does not
/// suffer form the ABA problem. /// suffer form the ABA problem.
pub fn get_unknown_gen_mut(&mut self, i: u32) -> Option<(&mut ImpulseJoint, JointHandle)> { pub fn get_unknown_gen_mut(
&mut self,
i: u32,
) -> Option<(&mut ImpulseJoint, ImpulseJointHandle)> {
let (id, handle) = self.joint_ids.get_unknown_gen(i)?; let (id, handle) = self.joint_ids.get_unknown_gen(i)?;
Some(( Some((
self.joint_graph.graph.edge_weight_mut(*id)?, self.joint_graph.graph.edge_weight_mut(*id)?,
JointHandle(handle), ImpulseJointHandle(handle),
)) ))
} }
/// Iterates through all the joint on this set. /// Iterates through all the joint on this set.
pub fn iter(&self) -> impl Iterator<Item = (JointHandle, &ImpulseJoint)> { pub fn iter(&self) -> impl Iterator<Item = (ImpulseJointHandle, &ImpulseJoint)> {
self.joint_graph self.joint_graph
.graph .graph
.edges .edges
@@ -142,7 +145,7 @@ impl ImpulseJointSet {
} }
/// Iterates mutably through all the joint on this set. /// Iterates mutably through all the joint on this set.
pub fn iter_mut(&mut self) -> impl Iterator<Item = (JointHandle, &mut ImpulseJoint)> { pub fn iter_mut(&mut self) -> impl Iterator<Item = (ImpulseJointHandle, &mut ImpulseJoint)> {
self.joint_graph self.joint_graph
.graph .graph
.edges .edges
@@ -175,7 +178,7 @@ impl ImpulseJointSet {
body1: RigidBodyHandle, body1: RigidBodyHandle,
body2: RigidBodyHandle, body2: RigidBodyHandle,
data: impl Into<JointData>, data: impl Into<JointData>,
) -> JointHandle { ) -> ImpulseJointHandle {
let data = data.into(); let data = data.into();
let handle = self.joint_ids.insert(0.into()); let handle = self.joint_ids.insert(0.into());
let joint = ImpulseJoint { let joint = ImpulseJoint {
@@ -183,7 +186,7 @@ impl ImpulseJointSet {
body2, body2,
data, data,
impulses: na::zero(), impulses: na::zero(),
handle: JointHandle(handle), handle: ImpulseJointHandle(handle),
#[cfg(feature = "parallel")] #[cfg(feature = "parallel")]
constraint_index: 0, constraint_index: 0,
}; };
@@ -209,7 +212,7 @@ impl ImpulseJointSet {
} }
self.joint_ids[handle] = self.joint_graph.add_edge(graph_index1, graph_index2, joint); self.joint_ids[handle] = self.joint_graph.add_edge(graph_index1, graph_index2, joint);
JointHandle(handle) ImpulseJointHandle(handle)
} }
/// Retrieve all the impulse_joints happening between two active bodies. /// Retrieve all the impulse_joints happening between two active bodies.
@@ -264,7 +267,7 @@ impl ImpulseJointSet {
/// automatically woken up. /// automatically woken up.
pub fn remove<Bodies>( pub fn remove<Bodies>(
&mut self, &mut self,
handle: JointHandle, handle: ImpulseJointHandle,
islands: &mut IslandManager, islands: &mut IslandManager,
bodies: &mut Bodies, bodies: &mut Bodies,
wake_up: bool, wake_up: bool,
@@ -306,7 +309,7 @@ impl ImpulseJointSet {
handle: RigidBodyHandle, handle: RigidBodyHandle,
islands: &mut IslandManager, islands: &mut IslandManager,
bodies: &mut Bodies, bodies: &mut Bodies,
) -> Vec<JointHandle> ) -> Vec<ImpulseJointHandle>
where where
Bodies: ComponentSetMut<RigidBodyActivation> Bodies: ComponentSetMut<RigidBodyActivation>
+ ComponentSet<RigidBodyType> + ComponentSet<RigidBodyType>

View File

@@ -1,5 +1,5 @@
pub use self::impulse_joint::ImpulseJoint; pub use self::impulse_joint::ImpulseJoint;
pub use self::impulse_joint_set::{ImpulseJointSet, JointHandle}; pub use self::impulse_joint_set::{ImpulseJointHandle, ImpulseJointSet};
pub(crate) use self::impulse_joint_set::{JointGraphEdge, JointIndex}; pub(crate) use self::impulse_joint_set::{JointGraphEdge, JointIndex};
mod impulse_joint; mod impulse_joint;