diff --git a/crates/fj-core/src/objects/is_object.rs b/crates/fj-core/src/objects/is_object.rs new file mode 100644 index 000000000..0c1328083 --- /dev/null +++ b/crates/fj-core/src/objects/is_object.rs @@ -0,0 +1,99 @@ +use crate::storage::Handle; + +use super::{ + Curve, Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid, Surface, Vertex, +}; + +/// A trait implemented for all object types +/// +/// This trait is implemented for both `T` and `Handle`, where `T` is the +/// type of any bare object. The `BareObject` associated type provides access to +/// the bare object type. +/// +/// This is a piece of infrastructure that is useful for other traits, which +/// would otherwise have to duplicate its functionality. Users are unlikely to +/// be affected by this trait. +pub trait IsObject { + /// The type of the bare object + type BareObject; +} + +impl IsObject for Curve { + type BareObject = Curve; +} + +impl IsObject for Cycle { + type BareObject = Cycle; +} + +impl IsObject for Face { + type BareObject = Face; +} + +impl IsObject for HalfEdge { + type BareObject = HalfEdge; +} + +impl IsObject for Region { + type BareObject = Region; +} + +impl IsObject for Shell { + type BareObject = Shell; +} + +impl IsObject for Sketch { + type BareObject = Sketch; +} + +impl IsObject for Solid { + type BareObject = Solid; +} + +impl IsObject for Surface { + type BareObject = Surface; +} + +impl IsObject for Vertex { + type BareObject = Vertex; +} + +impl IsObject for Handle { + type BareObject = Curve; +} + +impl IsObject for Handle { + type BareObject = Cycle; +} + +impl IsObject for Handle { + type BareObject = Face; +} + +impl IsObject for Handle { + type BareObject = HalfEdge; +} + +impl IsObject for Handle { + type BareObject = Region; +} + +impl IsObject for Handle { + type BareObject = Shell; +} + +impl IsObject for Handle { + type BareObject = Sketch; +} + +impl IsObject for Handle { + type BareObject = Solid; +} + +impl IsObject for Handle { + type BareObject = Surface; +} + +impl IsObject for Handle { + type BareObject = Vertex; +} diff --git a/crates/fj-core/src/objects/mod.rs b/crates/fj-core/src/objects/mod.rs index f74b043b5..a34ee7d7b 100644 --- a/crates/fj-core/src/objects/mod.rs +++ b/crates/fj-core/src/objects/mod.rs @@ -39,12 +39,14 @@ //! //! [`Handle`]: crate::storage::Handle +mod is_object; mod kinds; mod object; mod object_set; mod stores; pub use self::{ + is_object::IsObject, kinds::{ curve::Curve, cycle::Cycle, diff --git a/crates/fj-core/src/operations/replace/curve.rs b/crates/fj-core/src/operations/replace/curve.rs index 784253f9a..f817452e8 100644 --- a/crates/fj-core/src/operations/replace/curve.rs +++ b/crates/fj-core/src/operations/replace/curve.rs @@ -1,7 +1,9 @@ use std::ops::Deref; use crate::{ - objects::{Curve, Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid}, + objects::{ + Curve, Cycle, Face, HalfEdge, IsObject, Region, Shell, Sketch, Solid, + }, operations::{insert::Insert, update::UpdateHalfEdge}, services::Services, storage::Handle, @@ -14,10 +16,7 @@ use super::ReplaceOutput; /// See [module documentation] for more information. /// /// [module documentation]: super -pub trait ReplaceCurve: Sized { - /// The bare object type that this trait is implemented for - type BareObject; - +pub trait ReplaceCurve: IsObject + Sized { /// Replace the curve #[must_use] fn replace_curve( @@ -29,8 +28,6 @@ pub trait ReplaceCurve: Sized { } impl ReplaceCurve for HalfEdge { - type BareObject = Self; - fn replace_curve( &self, original: &Handle, @@ -46,8 +43,6 @@ impl ReplaceCurve for HalfEdge { } impl ReplaceCurve for Cycle { - type BareObject = Self; - fn replace_curve( &self, original: &Handle, @@ -80,8 +75,6 @@ impl ReplaceCurve for Cycle { } impl ReplaceCurve for Region { - type BareObject = Self; - fn replace_curve( &self, original: &Handle, @@ -124,8 +117,6 @@ impl ReplaceCurve for Region { } impl ReplaceCurve for Sketch { - type BareObject = Self; - fn replace_curve( &self, original: &Handle, @@ -155,8 +146,6 @@ impl ReplaceCurve for Sketch { } impl ReplaceCurve for Face { - type BareObject = Self; - fn replace_curve( &self, original: &Handle, @@ -180,8 +169,6 @@ impl ReplaceCurve for Face { } impl ReplaceCurve for Shell { - type BareObject = Self; - fn replace_curve( &self, original: &Handle, @@ -210,8 +197,6 @@ impl ReplaceCurve for Shell { } impl ReplaceCurve for Solid { - type BareObject = Self; - fn replace_curve( &self, original: &Handle, @@ -241,8 +226,6 @@ impl ReplaceCurve for Solid { } impl ReplaceCurve for Handle { - type BareObject = HalfEdge; - fn replace_curve( &self, original: &Handle, @@ -256,8 +239,6 @@ impl ReplaceCurve for Handle { } impl ReplaceCurve for Handle { - type BareObject = Cycle; - fn replace_curve( &self, original: &Handle, @@ -271,8 +252,6 @@ impl ReplaceCurve for Handle { } impl ReplaceCurve for Handle { - type BareObject = Region; - fn replace_curve( &self, original: &Handle, @@ -286,8 +265,6 @@ impl ReplaceCurve for Handle { } impl ReplaceCurve for Handle { - type BareObject = Sketch; - fn replace_curve( &self, original: &Handle, @@ -301,8 +278,6 @@ impl ReplaceCurve for Handle { } impl ReplaceCurve for Handle { - type BareObject = Face; - fn replace_curve( &self, original: &Handle, @@ -316,8 +291,6 @@ impl ReplaceCurve for Handle { } impl ReplaceCurve for Handle { - type BareObject = Shell; - fn replace_curve( &self, original: &Handle, @@ -331,8 +304,6 @@ impl ReplaceCurve for Handle { } impl ReplaceCurve for Handle { - type BareObject = Solid; - fn replace_curve( &self, original: &Handle, diff --git a/crates/fj-core/src/operations/replace/half_edge.rs b/crates/fj-core/src/operations/replace/half_edge.rs index 848c3c261..55c1864ae 100644 --- a/crates/fj-core/src/operations/replace/half_edge.rs +++ b/crates/fj-core/src/operations/replace/half_edge.rs @@ -1,7 +1,7 @@ use std::ops::Deref; use crate::{ - objects::{Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid}, + objects::{Cycle, Face, HalfEdge, IsObject, Region, Shell, Sketch, Solid}, operations::insert::Insert, services::Services, storage::Handle, @@ -14,10 +14,7 @@ use super::ReplaceOutput; /// See [module documentation] for more information. /// /// [module documentation]: super -pub trait ReplaceHalfEdge: Sized { - /// The bare object type that this trait is implemented for - type BareObject; - +pub trait ReplaceHalfEdge: IsObject + Sized { /// Replace the half-edge #[must_use] fn replace_half_edge( @@ -29,8 +26,6 @@ pub trait ReplaceHalfEdge: Sized { } impl ReplaceHalfEdge for Cycle { - type BareObject = Self; - fn replace_half_edge( &self, original: &Handle, @@ -48,8 +43,6 @@ impl ReplaceHalfEdge for Cycle { } impl ReplaceHalfEdge for Region { - type BareObject = Self; - fn replace_half_edge( &self, original: &Handle, @@ -95,8 +88,6 @@ impl ReplaceHalfEdge for Region { } impl ReplaceHalfEdge for Sketch { - type BareObject = Self; - fn replace_half_edge( &self, original: &Handle, @@ -129,8 +120,6 @@ impl ReplaceHalfEdge for Sketch { } impl ReplaceHalfEdge for Face { - type BareObject = Self; - fn replace_half_edge( &self, original: &Handle, @@ -155,8 +144,6 @@ impl ReplaceHalfEdge for Face { } impl ReplaceHalfEdge for Shell { - type BareObject = Self; - fn replace_half_edge( &self, original: &Handle, @@ -188,8 +175,6 @@ impl ReplaceHalfEdge for Shell { } impl ReplaceHalfEdge for Solid { - type BareObject = Self; - fn replace_half_edge( &self, original: &Handle, @@ -222,8 +207,6 @@ impl ReplaceHalfEdge for Solid { } impl ReplaceHalfEdge for Handle { - type BareObject = Cycle; - fn replace_half_edge( &self, original: &Handle, @@ -237,8 +220,6 @@ impl ReplaceHalfEdge for Handle { } impl ReplaceHalfEdge for Handle { - type BareObject = Region; - fn replace_half_edge( &self, original: &Handle, @@ -252,8 +233,6 @@ impl ReplaceHalfEdge for Handle { } impl ReplaceHalfEdge for Handle { - type BareObject = Sketch; - fn replace_half_edge( &self, original: &Handle, @@ -267,8 +246,6 @@ impl ReplaceHalfEdge for Handle { } impl ReplaceHalfEdge for Handle { - type BareObject = Face; - fn replace_half_edge( &self, original: &Handle, @@ -282,8 +259,6 @@ impl ReplaceHalfEdge for Handle { } impl ReplaceHalfEdge for Handle { - type BareObject = Shell; - fn replace_half_edge( &self, original: &Handle, @@ -297,8 +272,6 @@ impl ReplaceHalfEdge for Handle { } impl ReplaceHalfEdge for Handle { - type BareObject = Solid; - fn replace_half_edge( &self, original: &Handle, diff --git a/crates/fj-core/src/operations/replace/vertex.rs b/crates/fj-core/src/operations/replace/vertex.rs index be5120aae..fad7ad591 100644 --- a/crates/fj-core/src/operations/replace/vertex.rs +++ b/crates/fj-core/src/operations/replace/vertex.rs @@ -1,7 +1,9 @@ use std::ops::Deref; use crate::{ - objects::{Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid, Vertex}, + objects::{ + Cycle, Face, HalfEdge, IsObject, Region, Shell, Sketch, Solid, Vertex, + }, operations::{insert::Insert, update::UpdateHalfEdge}, services::Services, storage::Handle, @@ -14,10 +16,7 @@ use super::ReplaceOutput; /// See [module documentation] for more information. /// /// [module documentation]: super -pub trait ReplaceVertex: Sized { - /// The bare object type that this trait is implemented for - type BareObject; - +pub trait ReplaceVertex: IsObject + Sized { /// Replace the vertex #[must_use] fn replace_vertex( @@ -29,8 +28,6 @@ pub trait ReplaceVertex: Sized { } impl ReplaceVertex for HalfEdge { - type BareObject = Self; - fn replace_vertex( &self, original: &Handle, @@ -46,8 +43,6 @@ impl ReplaceVertex for HalfEdge { } impl ReplaceVertex for Cycle { - type BareObject = Self; - fn replace_vertex( &self, original: &Handle, @@ -80,8 +75,6 @@ impl ReplaceVertex for Cycle { } impl ReplaceVertex for Region { - type BareObject = Self; - fn replace_vertex( &self, original: &Handle, @@ -124,8 +117,6 @@ impl ReplaceVertex for Region { } impl ReplaceVertex for Sketch { - type BareObject = Self; - fn replace_vertex( &self, original: &Handle, @@ -155,8 +146,6 @@ impl ReplaceVertex for Sketch { } impl ReplaceVertex for Face { - type BareObject = Self; - fn replace_vertex( &self, original: &Handle, @@ -181,8 +170,6 @@ impl ReplaceVertex for Face { } impl ReplaceVertex for Shell { - type BareObject = Self; - fn replace_vertex( &self, original: &Handle, @@ -211,8 +198,6 @@ impl ReplaceVertex for Shell { } impl ReplaceVertex for Solid { - type BareObject = Self; - fn replace_vertex( &self, original: &Handle, @@ -242,8 +227,6 @@ impl ReplaceVertex for Solid { } impl ReplaceVertex for Handle { - type BareObject = HalfEdge; - fn replace_vertex( &self, original: &Handle, @@ -257,8 +240,6 @@ impl ReplaceVertex for Handle { } impl ReplaceVertex for Handle { - type BareObject = Cycle; - fn replace_vertex( &self, original: &Handle, @@ -272,8 +253,6 @@ impl ReplaceVertex for Handle { } impl ReplaceVertex for Handle { - type BareObject = Region; - fn replace_vertex( &self, original: &Handle, @@ -287,8 +266,6 @@ impl ReplaceVertex for Handle { } impl ReplaceVertex for Handle { - type BareObject = Sketch; - fn replace_vertex( &self, original: &Handle, @@ -318,8 +295,6 @@ impl ReplaceVertex for Handle { } impl ReplaceVertex for Handle { - type BareObject = Face; - fn replace_vertex( &self, original: &Handle, @@ -333,8 +308,6 @@ impl ReplaceVertex for Handle { } impl ReplaceVertex for Handle { - type BareObject = Shell; - fn replace_vertex( &self, original: &Handle, @@ -348,8 +321,6 @@ impl ReplaceVertex for Handle { } impl ReplaceVertex for Handle { - type BareObject = Solid; - fn replace_vertex( &self, original: &Handle,