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/kinds/cycle.rs b/crates/fj-core/src/objects/kinds/cycle.rs index f8f92db16..61bb4179a 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::{HalfEdge, ObjectSet}, 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..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::Handles, Cycle}, + objects::{Cycle, ObjectSet}, 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..fd6b8574b 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::{Face, ObjectSet}, 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..5f4a29d60 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::{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..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::Handles, Shell}, + objects::{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..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::Handles, 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 85% rename from crates/fj-core/src/objects/handles.rs rename to crates/fj-core/src/objects/object_set.rs index 6ebce9b4f..f8928e0d3 100644 --- a/crates/fj-core/src/objects/handles.rs +++ b/crates/fj-core/src/objects/object_set.rs @@ -4,27 +4,26 @@ 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 /// 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*. // // 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>, } -impl Handles { - /// Create a new instances of `Handles` from an iterator over `Handle` +impl ObjectSet { + /// Create an instances of `ObjectSet` from an iterator over `Handle` /// /// # Panics /// @@ -39,7 +38,7 @@ impl Handles { for handle in handles { if added.contains(&handle) { panic!( - "Constructing `HandleSet` with duplicate handle: {:?}", + "Constructing `ObjectSet` with duplicate handle: {:?}", handle ); } @@ -51,7 +50,7 @@ impl Handles { 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,14 +102,14 @@ impl Handles { /// 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"); + assert!(!self.is_empty(), "`ObjectSet` must not be empty"); let index = index % self.len(); self.nth(index) @@ -130,17 +129,17 @@ impl Handles { .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. /// @@ -191,7 +190,7 @@ impl Handles { } } -impl FromIterator> for Handles +impl FromIterator> for ObjectSet where O: Debug + Ord, { @@ -200,7 +199,7 @@ where } } -impl IntoIterator for Handles { +impl IntoIterator for ObjectSet { type Item = Handle; type IntoIter = vec::IntoIter>; @@ -209,7 +208,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. //