From e18dc38c75a64d2f035bc3690c0bfaa235ea8cff Mon Sep 17 00:00:00 2001 From: whatf0xx Date: Sun, 25 Feb 2024 18:07:01 +0100 Subject: [PATCH] Implemented Debug for TypedShape by deriving Debug on enum variants, except TriMesh which has a dummy implementation. --- src/shape/compound.rs | 2 +- src/shape/polyline.rs | 2 +- src/shape/shape.rs | 2 +- src/shape/shared_shape.rs | 8 ++++---- src/shape/trimesh.rs | 7 +++++++ 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/shape/compound.rs b/src/shape/compound.rs index 3b89d04d..9e6c1ca4 100644 --- a/src/shape/compound.rs +++ b/src/shape/compound.rs @@ -18,7 +18,7 @@ use crate::utils::DefaultStorage; /// the main way of creating a concave shape from convex parts. Each parts can have its own /// delta transformation to shift or rotate it with regard to the other shapes. #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Compound { shapes: Vec<(Isometry, SharedShape)>, qbvh: Qbvh, diff --git a/src/shape/polyline.rs b/src/shape/polyline.rs index ab07f5d5..ee29839f 100644 --- a/src/shape/polyline.rs +++ b/src/shape/polyline.rs @@ -9,7 +9,7 @@ use crate::utils::DefaultStorage; #[cfg(not(feature = "std"))] use na::ComplexField; // for .abs() -#[derive(Clone)] +#[derive(Clone, Debug)] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "rkyv", diff --git a/src/shape/shape.rs b/src/shape/shape.rs index e77b6b93..3755b68e 100644 --- a/src/shape/shape.rs +++ b/src/shape/shape.rs @@ -85,7 +85,7 @@ pub enum ShapeType { Custom, } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] #[cfg_attr(feature = "serde-serialize", derive(Serialize))] /// Enum representing the shape with its actual type pub enum TypedShape<'a> { diff --git a/src/shape/shared_shape.rs b/src/shape/shared_shape.rs index 5d77ad20..e445be74 100644 --- a/src/shape/shared_shape.rs +++ b/src/shape/shared_shape.rs @@ -5,15 +5,15 @@ use crate::shape::ConvexPolygon; use crate::shape::DeserializableTypedShape; use crate::shape::{ Ball, Capsule, Compound, Cuboid, HalfSpace, HeightField, Polyline, RoundShape, Segment, Shape, - TriMesh, TriMeshFlags, Triangle, ShapeType + TriMesh, TriMeshFlags, Triangle, TypedShape, }; #[cfg(feature = "dim3")] use crate::shape::{Cone, ConvexPolyhedron, Cylinder}; use crate::transformation::vhacd::{VHACDParameters, VHACD}; use na::Unit; +use std::fmt; use std::ops::Deref; use std::sync::Arc; -use std::fmt; /// The shape of a collider. #[derive(Clone)] @@ -34,8 +34,8 @@ impl AsRef for SharedShape { impl fmt::Debug for SharedShape { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let shape_type: ShapeType = (*self.0).shape_type(); - write!(f, "SharedShape ( Arc<{:?}> )", shape_type) + let typed_shape: TypedShape = (*self.0).as_typed_shape(); + write!(f, "SharedShape ( Arc<{:?}> )", typed_shape) } } diff --git a/src/shape/trimesh.rs b/src/shape/trimesh.rs index 44b79f6c..f5b86e72 100644 --- a/src/shape/trimesh.rs +++ b/src/shape/trimesh.rs @@ -4,6 +4,7 @@ use crate::partitioning::QbvhStorage; use crate::partitioning::{GenericQbvh, Qbvh}; use crate::shape::trimesh_storage::TriMeshStorage; use crate::shape::{FeatureId, Shape, Triangle, TypedSimdCompositeShape}; +use std::fmt; use crate::utils::{Array1, DefaultStorage, HashablePartialEq}; #[cfg(feature = "dim3")] @@ -358,6 +359,12 @@ pub struct GenericTriMesh { flags: TriMeshFlags, } +impl fmt::Debug for GenericTriMesh { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "GenericTriMesh") + } +} + /// A triangle-mesh. pub type TriMesh = GenericTriMesh; #[cfg(feature = "cuda")]