Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Handles to ObjectSet #2109

Merged
merged 6 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/fj-core/src/algorithms/approx/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -16,7 +16,7 @@ use super::{
Tolerance,
};

impl Approx for &Handles<Face> {
impl Approx for &ObjectSet<Face> {
type Approximation = BTreeSet<FaceApprox>;
type Cache = HalfEdgeApproxCache;

Expand Down
6 changes: 3 additions & 3 deletions crates/fj-core/src/objects/kinds/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HalfEdge>,
half_edges: ObjectSet<HalfEdge>,
}

impl Cycle {
Expand All @@ -20,7 +20,7 @@ impl Cycle {
}

/// Access the edges that make up the cycle
pub fn half_edges(&self) -> &Handles<HalfEdge> {
pub fn half_edges(&self) -> &ObjectSet<HalfEdge> {
&self.half_edges
}

Expand Down
6 changes: 3 additions & 3 deletions crates/fj-core/src/objects/kinds/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use fj_interop::mesh::Color;

use crate::{
objects::{handles::Handles, Cycle},
objects::{Cycle, ObjectSet},
storage::Handle,
};

Expand All @@ -17,7 +17,7 @@ use crate::{
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Region {
exterior: Handle<Cycle>,
interiors: Handles<Cycle>,
interiors: ObjectSet<Cycle>,
color: Option<Color>,
}

Expand All @@ -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<Cycle> {
pub fn interiors(&self) -> &ObjectSet<Cycle> {
&self.interiors
}

Expand Down
6 changes: 3 additions & 3 deletions crates/fj-core/src/objects/kinds/shell.rs
Original file line number Diff line number Diff line change
@@ -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<Face>,
faces: ObjectSet<Face>,
}

impl Shell {
Expand All @@ -18,7 +18,7 @@ impl Shell {
}

/// Access the faces of the shell
pub fn faces(&self) -> &Handles<Face> {
pub fn faces(&self) -> &ObjectSet<Face> {
&self.faces
}
}
6 changes: 3 additions & 3 deletions crates/fj-core/src/objects/kinds/sketch.rs
Original file line number Diff line number Diff line change
@@ -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<Region>,
regions: ObjectSet<Region>,
}

impl Sketch {
Expand All @@ -18,7 +18,7 @@ impl Sketch {
}

/// Access the regions of the sketch
pub fn regions(&self) -> &Handles<Region> {
pub fn regions(&self) -> &ObjectSet<Region> {
&self.regions
}
}
6 changes: 3 additions & 3 deletions crates/fj-core/src/objects/kinds/solid.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
objects::{handles::Handles, Shell},
objects::{ObjectSet, Shell},
storage::Handle,
};

Expand All @@ -13,7 +13,7 @@ use crate::{
/// not currently validated.
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Solid {
shells: Handles<Shell>,
shells: ObjectSet<Shell>,
}

impl Solid {
Expand All @@ -25,7 +25,7 @@ impl Solid {
}

/// Access the solid's shells
pub fn shells(&self) -> &Handles<Shell> {
pub fn shells(&self) -> &ObjectSet<Shell> {
&self.shells
}
}
4 changes: 2 additions & 2 deletions crates/fj-core/src/objects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -59,5 +58,6 @@ pub use self::{
vertex::Vertex,
},
object::{Bare, BehindHandle, Form, Object, WithHandle},
object_set::ObjectSet,
stores::{Objects, Surfaces},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
pub struct ObjectSet<T> {
// 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<Handle<T>>,
}

impl<T> Handles<T> {
/// Create a new instances of `Handles` from an iterator over `Handle<T>`
impl<T> ObjectSet<T> {
/// Create an instances of `ObjectSet` from an iterator over `Handle<T>`
///
/// # Panics
///
Expand All @@ -39,7 +38,7 @@ impl<T> Handles<T> {
for handle in handles {
if added.contains(&handle) {
panic!(
"Constructing `HandleSet` with duplicate handle: {:?}",
"Constructing `ObjectSet` with duplicate handle: {:?}",
handle
);
}
Expand All @@ -51,7 +50,7 @@ impl<T> Handles<T> {
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()
}
Expand Down Expand Up @@ -103,14 +102,14 @@ impl<T> Handles<T> {

/// 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<T> {
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)
Expand All @@ -130,17 +129,17 @@ impl<T> Handles<T> {
.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<Handle<T>> {
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<Item = (&Handle<T>, &Handle<T>)> {
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.
///
Expand Down Expand Up @@ -191,7 +190,7 @@ impl<T> Handles<T> {
}
}

impl<O> FromIterator<Handle<O>> for Handles<O>
impl<O> FromIterator<Handle<O>> for ObjectSet<O>
where
O: Debug + Ord,
{
Expand All @@ -200,7 +199,7 @@ where
}
}

impl<T> IntoIterator for Handles<T> {
impl<T> IntoIterator for ObjectSet<T> {
type Item = Handle<T>;
type IntoIter = vec::IntoIter<Handle<T>>;

Expand All @@ -209,7 +208,7 @@ impl<T> IntoIterator for Handles<T> {
}
}

impl<'r, T> IntoIterator for &'r Handles<T> {
impl<'r, T> IntoIterator for &'r ObjectSet<T> {
// You might wonder why we're returning references to handles here, when
// `Handle` already is kind of reference, and easily cloned.
//
Expand Down