From 0bae575cf380723b6cf7171827565106820a4ded Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Nov 2023 13:55:33 +0100 Subject: [PATCH 1/6] Rename `Handles` to `ObjectSet` The name `ObjectSet` has recently been freed up, and I believe it's much more appropriate here than `Handles`. See the already existing documentation of `Handles`/`ObjectSet` for supporting evidence. --- crates/fj-core/src/algorithms/approx/face.rs | 4 ++-- crates/fj-core/src/objects/handles.rs | 10 +++++----- crates/fj-core/src/objects/kinds/cycle.rs | 6 +++--- crates/fj-core/src/objects/kinds/region.rs | 6 +++--- crates/fj-core/src/objects/kinds/shell.rs | 6 +++--- crates/fj-core/src/objects/kinds/sketch.rs | 6 +++--- crates/fj-core/src/objects/kinds/solid.rs | 6 +++--- crates/fj-core/src/objects/mod.rs | 2 +- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/crates/fj-core/src/algorithms/approx/face.rs b/crates/fj-core/src/algorithms/approx/face.rs index aedccf6a5..d94372f84 100644 --- a/crates/fj-core/src/algorithms/approx/face.rs +++ b/crates/fj-core/src/algorithms/approx/face.rs @@ -7,7 +7,7 @@ use std::{collections::BTreeSet, ops::Deref}; use fj_interop::mesh::Color; use crate::{ - objects::{Face, Handedness, Handles}, + objects::{Face, Handedness, ObjectSet}, validate::ValidationConfig, }; @@ -16,7 +16,7 @@ use super::{ Tolerance, }; -impl Approx for &Handles { +impl Approx for &ObjectSet { type Approximation = BTreeSet; type Cache = HalfEdgeApproxCache; diff --git a/crates/fj-core/src/objects/handles.rs b/crates/fj-core/src/objects/handles.rs index 6ebce9b4f..b956a66b8 100644 --- a/crates/fj-core/src/objects/handles.rs +++ b/crates/fj-core/src/objects/handles.rs @@ -10,7 +10,7 @@ use crate::storage::Handle; /// objects of the same type. It is a set, not containing any duplicate /// elements, and it maintains the insertion order of those elements. #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] -pub struct Handles { +pub struct ObjectSet { // This is supposed to be a set data structure, so what is that `Vec` doing // here? Well, it's here because we need it to preserve insertion order, but // that doesn't explain why it is here *alone*. @@ -23,7 +23,7 @@ pub struct Handles { inner: Vec>, } -impl Handles { +impl ObjectSet { /// Create a new instances of `Handles` from an iterator over `Handle` /// /// # Panics @@ -191,7 +191,7 @@ impl Handles { } } -impl FromIterator> for Handles +impl FromIterator> for ObjectSet where O: Debug + Ord, { @@ -200,7 +200,7 @@ where } } -impl IntoIterator for Handles { +impl IntoIterator for ObjectSet { type Item = Handle; type IntoIter = vec::IntoIter>; @@ -209,7 +209,7 @@ impl IntoIterator for Handles { } } -impl<'r, T> IntoIterator for &'r Handles { +impl<'r, T> IntoIterator for &'r ObjectSet { // You might wonder why we're returning references to handles here, when // `Handle` already is kind of reference, and easily cloned. // diff --git a/crates/fj-core/src/objects/kinds/cycle.rs b/crates/fj-core/src/objects/kinds/cycle.rs index f8f92db16..dbc3778c3 100644 --- a/crates/fj-core/src/objects/kinds/cycle.rs +++ b/crates/fj-core/src/objects/kinds/cycle.rs @@ -2,14 +2,14 @@ use fj_math::{Scalar, Winding}; use crate::{ geometry::SurfacePath, - objects::{handles::Handles, HalfEdge}, + objects::{handles::ObjectSet, HalfEdge}, storage::Handle, }; /// A cycle of connected edges #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct Cycle { - half_edges: Handles, + half_edges: ObjectSet, } impl Cycle { @@ -20,7 +20,7 @@ impl Cycle { } /// Access the edges that make up the cycle - pub fn half_edges(&self) -> &Handles { + pub fn half_edges(&self) -> &ObjectSet { &self.half_edges } diff --git a/crates/fj-core/src/objects/kinds/region.rs b/crates/fj-core/src/objects/kinds/region.rs index a15cc40cf..9a5e5fd45 100644 --- a/crates/fj-core/src/objects/kinds/region.rs +++ b/crates/fj-core/src/objects/kinds/region.rs @@ -2,7 +2,7 @@ use fj_interop::mesh::Color; use crate::{ - objects::{handles::Handles, Cycle}, + objects::{handles::ObjectSet, Cycle}, storage::Handle, }; @@ -17,7 +17,7 @@ use crate::{ #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct Region { exterior: Handle, - interiors: Handles, + interiors: ObjectSet, color: Option, } @@ -43,7 +43,7 @@ impl Region { /// Access the cycles that bound the region on the inside /// /// Each of these cycles defines a hole in the region . - pub fn interiors(&self) -> &Handles { + pub fn interiors(&self) -> &ObjectSet { &self.interiors } diff --git a/crates/fj-core/src/objects/kinds/shell.rs b/crates/fj-core/src/objects/kinds/shell.rs index c905cf70b..1500b074c 100644 --- a/crates/fj-core/src/objects/kinds/shell.rs +++ b/crates/fj-core/src/objects/kinds/shell.rs @@ -1,12 +1,12 @@ use crate::{ - objects::{handles::Handles, Face}, + objects::{handles::ObjectSet, Face}, storage::Handle, }; /// A 3-dimensional closed shell #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct Shell { - faces: Handles, + faces: ObjectSet, } impl Shell { @@ -18,7 +18,7 @@ impl Shell { } /// Access the faces of the shell - pub fn faces(&self) -> &Handles { + pub fn faces(&self) -> &ObjectSet { &self.faces } } diff --git a/crates/fj-core/src/objects/kinds/sketch.rs b/crates/fj-core/src/objects/kinds/sketch.rs index f6d19d22b..a65d6daf2 100644 --- a/crates/fj-core/src/objects/kinds/sketch.rs +++ b/crates/fj-core/src/objects/kinds/sketch.rs @@ -1,12 +1,12 @@ use crate::{ - objects::{handles::Handles, Region}, + objects::{handles::ObjectSet, Region}, storage::Handle, }; /// A 2-dimensional shape #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct Sketch { - regions: Handles, + regions: ObjectSet, } impl Sketch { @@ -18,7 +18,7 @@ impl Sketch { } /// Access the regions of the sketch - pub fn regions(&self) -> &Handles { + pub fn regions(&self) -> &ObjectSet { &self.regions } } diff --git a/crates/fj-core/src/objects/kinds/solid.rs b/crates/fj-core/src/objects/kinds/solid.rs index 203ca6189..6a6fd449e 100644 --- a/crates/fj-core/src/objects/kinds/solid.rs +++ b/crates/fj-core/src/objects/kinds/solid.rs @@ -1,5 +1,5 @@ use crate::{ - objects::{handles::Handles, Shell}, + objects::{handles::ObjectSet, Shell}, storage::Handle, }; @@ -13,7 +13,7 @@ use crate::{ /// not currently validated. #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct Solid { - shells: Handles, + shells: ObjectSet, } impl Solid { @@ -25,7 +25,7 @@ impl Solid { } /// Access the solid's shells - pub fn shells(&self) -> &Handles { + pub fn shells(&self) -> &ObjectSet { &self.shells } } diff --git a/crates/fj-core/src/objects/mod.rs b/crates/fj-core/src/objects/mod.rs index be6383c04..888f90693 100644 --- a/crates/fj-core/src/objects/mod.rs +++ b/crates/fj-core/src/objects/mod.rs @@ -45,7 +45,7 @@ mod object; mod stores; pub use self::{ - handles::Handles, + handles::ObjectSet, kinds::{ curve::Curve, cycle::Cycle, From c38ba17f2a255fd5f737cab8e610cef986eb3072 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Nov 2023 13:58:32 +0100 Subject: [PATCH 2/6] Simplify imports --- crates/fj-core/src/objects/kinds/cycle.rs | 2 +- crates/fj-core/src/objects/kinds/region.rs | 2 +- crates/fj-core/src/objects/kinds/shell.rs | 2 +- crates/fj-core/src/objects/kinds/sketch.rs | 2 +- crates/fj-core/src/objects/kinds/solid.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/fj-core/src/objects/kinds/cycle.rs b/crates/fj-core/src/objects/kinds/cycle.rs index dbc3778c3..61bb4179a 100644 --- a/crates/fj-core/src/objects/kinds/cycle.rs +++ b/crates/fj-core/src/objects/kinds/cycle.rs @@ -2,7 +2,7 @@ use fj_math::{Scalar, Winding}; use crate::{ geometry::SurfacePath, - objects::{handles::ObjectSet, HalfEdge}, + objects::{HalfEdge, ObjectSet}, storage::Handle, }; diff --git a/crates/fj-core/src/objects/kinds/region.rs b/crates/fj-core/src/objects/kinds/region.rs index 9a5e5fd45..4744aa11b 100644 --- a/crates/fj-core/src/objects/kinds/region.rs +++ b/crates/fj-core/src/objects/kinds/region.rs @@ -2,7 +2,7 @@ use fj_interop::mesh::Color; use crate::{ - objects::{handles::ObjectSet, Cycle}, + objects::{Cycle, ObjectSet}, storage::Handle, }; diff --git a/crates/fj-core/src/objects/kinds/shell.rs b/crates/fj-core/src/objects/kinds/shell.rs index 1500b074c..fd6b8574b 100644 --- a/crates/fj-core/src/objects/kinds/shell.rs +++ b/crates/fj-core/src/objects/kinds/shell.rs @@ -1,5 +1,5 @@ use crate::{ - objects::{handles::ObjectSet, Face}, + objects::{Face, ObjectSet}, storage::Handle, }; diff --git a/crates/fj-core/src/objects/kinds/sketch.rs b/crates/fj-core/src/objects/kinds/sketch.rs index a65d6daf2..5f4a29d60 100644 --- a/crates/fj-core/src/objects/kinds/sketch.rs +++ b/crates/fj-core/src/objects/kinds/sketch.rs @@ -1,5 +1,5 @@ use crate::{ - objects::{handles::ObjectSet, Region}, + objects::{ObjectSet, Region}, storage::Handle, }; diff --git a/crates/fj-core/src/objects/kinds/solid.rs b/crates/fj-core/src/objects/kinds/solid.rs index 6a6fd449e..589c45191 100644 --- a/crates/fj-core/src/objects/kinds/solid.rs +++ b/crates/fj-core/src/objects/kinds/solid.rs @@ -1,5 +1,5 @@ use crate::{ - objects::{handles::ObjectSet, Shell}, + objects::{ObjectSet, Shell}, storage::Handle, }; From bd6fa31a13aa61b856fe21bdb33f9265c862f072 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Nov 2023 14:00:22 +0100 Subject: [PATCH 3/6] Update module name --- crates/fj-core/src/objects/mod.rs | 4 ++-- crates/fj-core/src/objects/{handles.rs => object_set.rs} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename crates/fj-core/src/objects/{handles.rs => object_set.rs} (100%) diff --git a/crates/fj-core/src/objects/mod.rs b/crates/fj-core/src/objects/mod.rs index 888f90693..c4dccaa02 100644 --- a/crates/fj-core/src/objects/mod.rs +++ b/crates/fj-core/src/objects/mod.rs @@ -39,13 +39,12 @@ //! //! [`Handle`]: crate::storage::Handle -mod handles; mod kinds; mod object; +mod object_set; mod stores; pub use self::{ - handles::ObjectSet, kinds::{ curve::Curve, cycle::Cycle, @@ -59,5 +58,6 @@ pub use self::{ vertex::Vertex, }, object::{Bare, BehindHandle, Form, Object, WithHandle}, + object_set::ObjectSet, stores::{Objects, Surfaces}, }; diff --git a/crates/fj-core/src/objects/handles.rs b/crates/fj-core/src/objects/object_set.rs similarity index 100% rename from crates/fj-core/src/objects/handles.rs rename to crates/fj-core/src/objects/object_set.rs From 7626ed4db6ff29a0f36655370d85fc336da5f454 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Nov 2023 14:05:49 +0100 Subject: [PATCH 4/6] Update documentation of `ObjectSet` --- crates/fj-core/src/objects/object_set.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/fj-core/src/objects/object_set.rs b/crates/fj-core/src/objects/object_set.rs index b956a66b8..8b2efb1ee 100644 --- a/crates/fj-core/src/objects/object_set.rs +++ b/crates/fj-core/src/objects/object_set.rs @@ -4,7 +4,7 @@ use itertools::Itertools; use crate::storage::Handle; -/// An ordered set of object handles +/// An ordered set of objects /// /// This is the data structure used by all objects that reference multiple /// objects of the same type. It is a set, not containing any duplicate @@ -24,7 +24,7 @@ pub struct ObjectSet { } impl ObjectSet { - /// Create a new instances of `Handles` from an iterator over `Handle` + /// Create an instances of `ObjectSet` from an iterator over `Handle` /// /// # Panics /// @@ -51,7 +51,7 @@ impl ObjectSet { Self { inner } } - /// Return the number of handles in this set + /// Return the number of objects in this set pub fn len(&self) -> usize { self.inner.len() } @@ -103,12 +103,12 @@ impl ObjectSet { /// Return the n-th item, treating the index space as circular /// - /// If the length of `Handles` is `i`, then retrieving the i-th edge using - /// this method, is the same as retrieving the 0-th one. + /// If the length of `ObjectSet` is `i`, then retrieving the i-th edge using + /// this method, is the same as retrieving the 0-th one, and so on. /// /// # Panics /// - /// Panics, if `Handles` is empty. + /// Panics, if `ObjectSet` is empty. pub fn nth_circular(&self, index: usize) -> &Handle { assert!(!self.is_empty(), "`Handles` must not be empty"); @@ -130,17 +130,17 @@ impl ObjectSet { .map(|index| self.nth_circular(index + 1)) } - /// Access an iterator over the handles + /// Access an iterator over the objects pub fn iter(&self) -> slice::Iter> { self.inner.iter() } - /// Return iterator over the pairs of all handles + /// Access an iterator over the neighboring pairs of all contained objects pub fn pairs(&self) -> impl Iterator, &Handle)> { self.iter().circular_tuple_windows() } - /// Create a new instance in which the provided item has been replaced + /// Create a new instance in which the provided object has been replaced /// /// Returns `None`, if the provided item is not present. /// From c2b2fb483c880664e9d930d6ade526a0c32b3b6b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Nov 2023 14:06:14 +0100 Subject: [PATCH 5/6] Update comment --- crates/fj-core/src/objects/object_set.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/fj-core/src/objects/object_set.rs b/crates/fj-core/src/objects/object_set.rs index 8b2efb1ee..e56b10112 100644 --- a/crates/fj-core/src/objects/object_set.rs +++ b/crates/fj-core/src/objects/object_set.rs @@ -17,9 +17,8 @@ pub struct ObjectSet { // // If you look closely, you'll notice that this is an immutable data // structure (since it is used in objects, and objects themselves are - // immutable). We make sure there are no duplicates when this is - // constructed (see the `FromIterator` implementation below), but after - // that, we're fine. + // immutable). We need to make sure there are no duplicates when this is + // constructed (see the constructor below), but after that, we're fine. inner: Vec>, } From 580f3f4c24f3c9e5aa559b4fff19112399cb7d8c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Nov 2023 14:06:21 +0100 Subject: [PATCH 6/6] Update panic messages --- crates/fj-core/src/objects/object_set.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/objects/object_set.rs b/crates/fj-core/src/objects/object_set.rs index e56b10112..f8928e0d3 100644 --- a/crates/fj-core/src/objects/object_set.rs +++ b/crates/fj-core/src/objects/object_set.rs @@ -38,7 +38,7 @@ impl ObjectSet { for handle in handles { if added.contains(&handle) { panic!( - "Constructing `HandleSet` with duplicate handle: {:?}", + "Constructing `ObjectSet` with duplicate handle: {:?}", handle ); } @@ -109,7 +109,7 @@ impl ObjectSet { /// /// Panics, if `ObjectSet` is empty. pub fn nth_circular(&self, index: usize) -> &Handle { - assert!(!self.is_empty(), "`Handles` must not be empty"); + assert!(!self.is_empty(), "`ObjectSet` must not be empty"); let index = index % self.len(); self.nth(index)