Add boolean operations (#1759)

This commit is contained in:
Keavon Chambers
2024-05-25 22:02:00 -07:00
committed by GitHub
parent c80de41d28
commit d40fb6caad
19 changed files with 409 additions and 55 deletions

View File

@@ -16,6 +16,13 @@ pub mod value;
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize, specta::Type)]
pub struct NodeId(pub u64);
// TODO: Find and replace all `NodeId(generate_uuid())` with `NodeId::new()`.
impl NodeId {
pub fn new() -> Self {
Self(generate_uuid())
}
}
impl core::fmt::Display for NodeId {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.0)

View File

@@ -78,6 +78,7 @@ pub enum TaggedValue {
RenderOutput(RenderOutput),
Palette(Vec<Color>),
CentroidType(graphene_core::vector::misc::CentroidType),
BooleanOperation(graphene_core::vector::misc::BooleanOperation),
}
#[allow(clippy::derived_hash_with_manual_eq)]
@@ -158,6 +159,7 @@ impl Hash for TaggedValue {
Self::RenderOutput(x) => x.hash(state),
Self::Palette(x) => x.hash(state),
Self::CentroidType(x) => x.hash(state),
Self::BooleanOperation(x) => x.hash(state),
}
}
}
@@ -225,6 +227,7 @@ impl<'a> TaggedValue {
TaggedValue::RenderOutput(x) => Box::new(x),
TaggedValue::Palette(x) => Box::new(x),
TaggedValue::CentroidType(x) => Box::new(x),
TaggedValue::BooleanOperation(x) => Box::new(x),
}
}
@@ -303,6 +306,7 @@ impl<'a> TaggedValue {
TaggedValue::RenderOutput(_) => concrete!(RenderOutput),
TaggedValue::Palette(_) => concrete!(Vec<Color>),
TaggedValue::CentroidType(_) => concrete!(graphene_core::vector::misc::CentroidType),
TaggedValue::BooleanOperation(_) => concrete!(graphene_core::vector::misc::BooleanOperation),
}
}
@@ -371,6 +375,7 @@ impl<'a> TaggedValue {
x if x == TypeId::of::<graphene_core::transform::Footprint>() => Ok(TaggedValue::Footprint(*downcast(input).unwrap())),
x if x == TypeId::of::<Vec<Color>>() => Ok(TaggedValue::Palette(*downcast(input).unwrap())),
x if x == TypeId::of::<graphene_core::vector::misc::CentroidType>() => Ok(TaggedValue::CentroidType(*downcast(input).unwrap())),
x if x == TypeId::of::<graphene_core::vector::misc::BooleanOperation>() => Ok(TaggedValue::BooleanOperation(*downcast(input).unwrap())),
_ => Err(format!("Cannot convert {:?} to TaggedValue", DynAny::type_name(input.as_ref()))),
}
}