Skip to content

Commit

Permalink
Merge pull request #666 from hannobraun/shape
Browse files Browse the repository at this point in the history
Make it possible to assign labels to `Shape`s
  • Loading branch information
hannobraun authored Jun 3, 2022
2 parents 4494207 + b10f2e4 commit aaeae74
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
20 changes: 20 additions & 0 deletions crates/fj-kernel/src/shape/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> 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.
Expand Down
8 changes: 7 additions & 1 deletion crates/fj-kernel/src/shape/stores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ impl Stores {

#[derive(Debug)]
pub struct Store<T: Object> {
pub(super) label: Option<String>,
objects: Arc<RwLock<Objects<T>>>,
}

impl<T: Object> Store<T> {
pub fn new() -> Self {
Self {
label: None,
objects: Arc::new(RwLock::new(SlotMap::new())),
}
}
Expand Down Expand Up @@ -109,6 +111,7 @@ impl<T: Object> Store<T> {
impl<T: Object> Clone for Store<T> {
fn clone(&self) -> Self {
Self {
label: self.label.clone().map(|label| format!("{} (clone)", label)),
objects: self.objects.clone(),
}
}
Expand Down Expand Up @@ -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()
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/fj-operations/src/shape_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ pub struct ProcessedShape {
}

/// A shape processing error
#[allow(clippy::large_enum_variant)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// Error converting to shape
#[error("Error converting to shape")]
ToShape(#[from] ValidationError),

/// Model has zero size
#[error("Model has an zero size")]
#[error("Model has zero size")]
Extent(#[from] InvalidTolerance),
}

0 comments on commit aaeae74

Please sign in to comment.