Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom TypedShape to reference dyn Shape instead #216

Merged
merged 6 commits into from
Jul 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
DeserializableTypedShape
Neo-Zhixing committed Jul 2, 2024
commit ca06b105a8aba00e793e695d65e88d3a6ea15398
2 changes: 1 addition & 1 deletion src/query/contact_manifolds/contact_manifolds_workspace.rs
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ impl DeserializableWorkspaceData {
DeserializableWorkspaceData::CompositeShapeShapeContactManifoldsWorkspace(w) => {
Some(ContactManifoldsWorkspace(Box::new(w)))
}
DeserializableWorkspaceData::Custom(_) => None,
DeserializableWorkspaceData::Custom => None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand that custom shapes are (currently) not supported by serialization/deserialization ? (at least here specifically)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct. And this is the same behavior as before.

}
}
}
18 changes: 11 additions & 7 deletions src/shape/shape.rs
Original file line number Diff line number Diff line change
@@ -150,7 +150,7 @@ pub enum TypedShape<'a> {
#[cfg(feature = "dim2")]
#[cfg(feature = "std")]
RoundConvexPolygon(&'a RoundConvexPolygon),
/// A custom user-defined shape with a type identified by a number.
/// A custom user-defined shape.
Custom(&'a dyn Shape),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can a dyn Shape serialize/deserialize ?

Copy link
Member

@sebcrozet sebcrozet Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vrixyz This would be difficult due to the Deserialize trait bound having a lifetime. This is generally worked around using erased_serde but some additional steps are needed to make deserialization actually work. This sounds out of the scope of this PR.

}
impl Debug for TypedShape<'_> {
@@ -188,10 +188,14 @@ impl Debug for TypedShape<'_> {
Self::RoundCone(arg0) => f.debug_tuple("RoundCone").field(arg0).finish(),
#[cfg(feature = "dim3")]
#[cfg(feature = "std")]
Self::RoundConvexPolyhedron(arg0) => f.debug_tuple("RoundConvexPolyhedron").field(arg0).finish(),
Self::RoundConvexPolyhedron(arg0) => {
f.debug_tuple("RoundConvexPolyhedron").field(arg0).finish()
}
#[cfg(feature = "dim2")]
#[cfg(feature = "std")]
Self::RoundConvexPolygon(arg0) => f.debug_tuple("RoundConvexPolygon").field(arg0).finish(),
Self::RoundConvexPolygon(arg0) => {
f.debug_tuple("RoundConvexPolygon").field(arg0).finish()
}
Self::Custom(_) => f.debug_tuple("Custom").finish(),
}
}
@@ -263,9 +267,9 @@ pub(crate) enum DeserializableTypedShape {
#[cfg(feature = "dim2")]
#[cfg(feature = "std")]
RoundConvexPolygon(RoundConvexPolygon),
/// A custom user-defined shape identified by a number.
#[allow(dead_code)] // The u32 is needed to match `TypedShape`.
Custom(u32),
/// A custom user-defined shape.
#[allow(dead_code)]
Custom,
}

#[cfg(feature = "serde-serialize")]
@@ -309,7 +313,7 @@ impl DeserializableTypedShape {
#[cfg(feature = "dim2")]
#[cfg(feature = "std")]
DeserializableTypedShape::RoundConvexPolygon(s) => Some(SharedShape::new(s)),
DeserializableTypedShape::Custom(_) => None,
DeserializableTypedShape::Custom => None,
}
}
}