diff --git a/crates/fj-kernel/src/shape/api.rs b/crates/fj-kernel/src/shape/api.rs index 03cc6f3b2f..83f261ddc8 100644 --- a/crates/fj-kernel/src/shape/api.rs +++ b/crates/fj-kernel/src/shape/api.rs @@ -51,6 +51,26 @@ impl Shape { } } + /// Assign a label to the shape + /// + /// The assigned label will be part of the `Debug` representation of + /// `Handle`s, making it way easier to understand which `Handle`s belong to + /// which `Shape`. + pub fn with_label(mut self, label: impl Into) -> Self { + let label = label.into(); + + self.stores.points.label = Some(label.clone()); + self.stores.curves.label = Some(label.clone()); + self.stores.surfaces.label = Some(label.clone()); + + self.stores.vertices.label = Some(label.clone()); + self.stores.edges.label = Some(label.clone()); + self.stores.cycles.label = Some(label.clone()); + self.stores.faces.label = Some(label); + + self + } + /// Override the minimum distance between distinct objects /// /// Used for vertex validation, to determine whether vertices are unique. diff --git a/crates/fj-kernel/src/shape/stores.rs b/crates/fj-kernel/src/shape/stores.rs index b46482c290..f69a2f66f1 100644 --- a/crates/fj-kernel/src/shape/stores.rs +++ b/crates/fj-kernel/src/shape/stores.rs @@ -51,12 +51,14 @@ impl Stores { #[derive(Debug)] pub struct Store { + pub(super) label: Option, objects: Arc>>, } impl Store { pub fn new() -> Self { Self { + label: None, objects: Arc::new(RwLock::new(SlotMap::new())), } } @@ -109,6 +111,7 @@ impl Store { impl Clone for Store { fn clone(&self) -> Self { Self { + label: self.label.clone().map(|label| format!("{} (clone)", label)), objects: self.objects.clone(), } } @@ -211,7 +214,10 @@ where T: fmt::Debug, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_tuple("Handle").field(&self.get()).finish() + f.debug_struct("Handle") + .field("shape", &self.store.label.as_deref().unwrap_or("unnamed")) + .field("object", &self.get()) + .finish() } } diff --git a/crates/fj-operations/src/shape_processor.rs b/crates/fj-operations/src/shape_processor.rs index 8d26eb0108..d3693da849 100644 --- a/crates/fj-operations/src/shape_processor.rs +++ b/crates/fj-operations/src/shape_processor.rs @@ -68,6 +68,7 @@ pub struct ProcessedShape { } /// A shape processing error +#[allow(clippy::large_enum_variant)] #[derive(Debug, thiserror::Error)] pub enum Error { /// Error converting to shape @@ -75,6 +76,6 @@ pub enum Error { ToShape(#[from] ValidationError), /// Model has zero size - #[error("Model has an zero size")] + #[error("Model has zero size")] Extent(#[from] InvalidTolerance), }