diff --git a/crates/fj-kernel/src/objects/full/edge.rs b/crates/fj-kernel/src/objects/full/edge.rs index 65216649b..893aaef70 100644 --- a/crates/fj-kernel/src/objects/full/edge.rs +++ b/crates/fj-kernel/src/objects/full/edge.rs @@ -105,6 +105,20 @@ impl HalfEdge { /// /// See [`HalfEdge`]'s documentation for more information on the relationship /// between [`HalfEdge`] and `GlobalEdge`. +/// +/// # Equality +/// +/// `GlobalEdge` contains no data and exists purely to be used within a +/// `Handle`, where `Handle::id` can be used to compare different instances of +/// `GlobalEdge`. +/// +/// If `GlobalEdge` had `Eq`/`PartialEq` implementations, it containing no data +/// would mean that all instances of `GlobalEdge` would be considered equal. +/// This would be very error-prone. +/// +/// If you need to reference a `GlobalEdge` from a struct that needs to derive +/// `Eq`/`Ord`/..., you can use `HandleWrapper` to do that. It will +/// use `Handle::id` to provide those `Eq`/`Ord`/... implementations. #[derive(Clone, Debug, Default, Hash)] pub struct GlobalEdge {} diff --git a/crates/fj-kernel/src/objects/full/vertex.rs b/crates/fj-kernel/src/objects/full/vertex.rs index ee44ab0bf..10d5a80f6 100644 --- a/crates/fj-kernel/src/objects/full/vertex.rs +++ b/crates/fj-kernel/src/objects/full/vertex.rs @@ -15,6 +15,19 @@ /// between distinct vertices can be configured using the respective field in /// [`ValidationConfig`]. /// +/// # Equality +/// +/// `Vertex` contains no data and exists purely to be used within a `Handle`, +/// where `Handle::id` can be used to compare different instances of `Vertex`. +/// +/// If `Vertex` had `Eq`/`PartialEq` implementations, it containing no data +/// would mean that all instances of `Vertex` would be considered equal. This +/// would be very error-prone. +/// +/// If you need to reference a `Vertex` from a struct that needs to derive +/// `Eq`/`Ord`/..., you can use `HandleWrapper` to do that. It will +/// use `Handle::id` to provide those `Eq`/`Ord`/... implementations. +/// /// [`ValidationConfig`]: crate::validate::ValidationConfig #[derive(Clone, Copy, Debug, Default, Hash)] pub struct Vertex {} diff --git a/crates/fj-kernel/src/objects/object.rs b/crates/fj-kernel/src/objects/object.rs index 2c22aa16f..22c9d16f2 100644 --- a/crates/fj-kernel/src/objects/object.rs +++ b/crates/fj-kernel/src/objects/object.rs @@ -3,7 +3,7 @@ use crate::{ Cycle, Face, GlobalEdge, HalfEdge, Objects, Shell, Sketch, Solid, Surface, Vertex, }, - storage::{Handle, ObjectId}, + storage::{Handle, HandleWrapper, ObjectId}, validate::{Validate, ValidationError}, }; @@ -14,7 +14,7 @@ macro_rules! object { /// This enum is generic over the form that the object takes. An /// `Object` contains bare objects, like `Curve`. An /// `Object` contains handles, like `Handle`. - #[derive(Clone, Debug)] + #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] pub enum Object { $( #[doc = concat!("A ", $name)] @@ -39,8 +39,10 @@ macro_rules! object { match self { $( Self::$ty((handle, object)) => { - objects.$store.insert(handle.clone(), object); - handle.into() + objects.$store.insert( + handle.clone().into(), object + ); + handle.0.into() } )* } @@ -60,7 +62,7 @@ macro_rules! object { fn from(object: Object) -> Self { match object { $( - Object::$ty((handle, _)) => Self::$ty(handle), + Object::$ty((handle, _)) => Self::$ty(handle.into()), )* } } @@ -75,13 +77,13 @@ macro_rules! object { impl From> for Object { fn from(object: Handle<$ty>) -> Self { - Self::$ty(object) + Self::$ty(object.into()) } } impl From<(Handle<$ty>, $ty)> for Object { fn from((handle, object): (Handle<$ty>, $ty)) -> Self { - Self::$ty((handle, object)) + Self::$ty((handle.into(), object)) } } )* @@ -110,7 +112,7 @@ pub trait Form { } /// Implementation of [`Form`] for bare objects -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] pub struct Bare; impl Form for Bare { @@ -118,17 +120,17 @@ impl Form for Bare { } /// Implementation of [`Form`] for objects behind a handle -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] pub struct BehindHandle; impl Form for BehindHandle { - type Form = Handle; + type Form = HandleWrapper; } /// Implementation of [`Form`] for objects that are paired with their handle -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] pub struct WithHandle; impl Form for WithHandle { - type Form = (Handle, T); + type Form = (HandleWrapper, T); }