From d1d1f6d5615e2f36053c0b7b088aba53ded20500 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 28 Jun 2022 17:15:20 +0200 Subject: [PATCH 1/5] Refactor test not to rely on `Shape::update` --- crates/fj-kernel/src/validation/mod.rs | 37 +++++++++++++------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/crates/fj-kernel/src/validation/mod.rs b/crates/fj-kernel/src/validation/mod.rs index c1edaa597..a3e9b78ff 100644 --- a/crates/fj-kernel/src/validation/mod.rs +++ b/crates/fj-kernel/src/validation/mod.rs @@ -232,28 +232,29 @@ mod tests { #[test] fn coherence_edge() { - let mut shape = Shape::new(); - Edge::builder(&mut shape) - .build_line_segment_from_points([[0., 0., 0.], [1., 0., 0.]]) - .get(); + let mut tmp = Shape::new(); + + let a = Point::from([0., 0., 0.]); + let b = Point::from([1., 0., 0.]); + + let curve = { + let curve = tmp.insert(Curve::line_from_points([a, b])); + LocalForm::canonical_only(curve) + }; + + let a = tmp.insert(Vertex { point: a }); + let b = tmp.insert(Vertex { point: b }); let deviation = Scalar::from_f64(0.25); - shape.update().update_all(|edge: &mut Edge<3>| { - let original = edge.clone(); - *edge = Edge { - vertices: original.vertices.map(|vertex| { - LocalForm::new( - *vertex.local() + [deviation], - vertex.canonical(), - ) - }), - ..original - } - }); + let a = LocalForm::new(Point::from([Scalar::ZERO + deviation]), a); + let b = LocalForm::new(Point::from([Scalar::ONE]), b); + let vertices = VerticesOfEdge::from_vertices([a, b]); + + let edge = Edge { curve, vertices }; let result = validate( - shape.clone(), + edge.clone(), &ValidationConfig { identical_max_distance: deviation * 2., ..ValidationConfig::default() @@ -262,7 +263,7 @@ mod tests { assert!(result.is_ok()); let result = validate( - shape, + edge, &ValidationConfig { identical_max_distance: deviation / 2., ..ValidationConfig::default() From 9cded04202724a78ee07a3d30406203b31b165cd Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 28 Jun 2022 17:16:08 +0200 Subject: [PATCH 2/5] Remove `Shape::update` It is no longer being used. --- crates/fj-kernel/src/shape/api.rs | 10 +--------- crates/fj-kernel/src/shape/update.rs | 4 ---- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/crates/fj-kernel/src/shape/api.rs b/crates/fj-kernel/src/shape/api.rs index b7efff6b5..f85a5f1cd 100644 --- a/crates/fj-kernel/src/shape/api.rs +++ b/crates/fj-kernel/src/shape/api.rs @@ -4,7 +4,7 @@ use crate::objects::{Curve, Cycle, Edge, Face, Surface, Vertex}; use super::{ stores::{Store, Stores}, - Handle, Iter, Object, Update, + Handle, Iter, Object, }; /// The boundary representation of a shape @@ -144,14 +144,6 @@ impl Shape { } } - /// Update objects in the shape - /// - /// Returns [`Update`], and API that can be used to update objects in the - /// shape. - pub fn update(&mut self) -> Update { - Update::new(&mut self.stores) - } - /// Access an iterator over all curves /// /// The caller must not make any assumptions about the order of curves. diff --git a/crates/fj-kernel/src/shape/update.rs b/crates/fj-kernel/src/shape/update.rs index f332a9080..8218da478 100644 --- a/crates/fj-kernel/src/shape/update.rs +++ b/crates/fj-kernel/src/shape/update.rs @@ -8,10 +8,6 @@ pub struct Update<'r> { } impl<'r> Update<'r> { - pub(super) fn new(stores: &'r mut Stores) -> Self { - Self { stores } - } - /// Update all objects of a specific type pub fn update_all(self, f: impl FnMut(&mut T)) -> Self { self.stores.get::().update(f); From 496a693f86f894bd9474fc442fc54aa9f3d3d1cc Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 28 Jun 2022 17:16:53 +0200 Subject: [PATCH 3/5] Remove `shape::Update` It is no longer being used. --- crates/fj-kernel/src/shape/mod.rs | 2 -- crates/fj-kernel/src/shape/stores.rs | 9 --------- crates/fj-kernel/src/shape/update.rs | 16 ---------------- 3 files changed, 27 deletions(-) delete mode 100644 crates/fj-kernel/src/shape/update.rs diff --git a/crates/fj-kernel/src/shape/mod.rs b/crates/fj-kernel/src/shape/mod.rs index a410d6731..b71f45e78 100644 --- a/crates/fj-kernel/src/shape/mod.rs +++ b/crates/fj-kernel/src/shape/mod.rs @@ -6,12 +6,10 @@ mod api; mod local; mod object; mod stores; -mod update; pub use self::{ api::Shape, local::LocalForm, object::Object, stores::{Handle, Iter}, - update::Update, }; diff --git a/crates/fj-kernel/src/shape/stores.rs b/crates/fj-kernel/src/shape/stores.rs index 96d31668a..468781bbe 100644 --- a/crates/fj-kernel/src/shape/stores.rs +++ b/crates/fj-kernel/src/shape/stores.rs @@ -81,15 +81,6 @@ impl Store { } } - pub fn update(&mut self, mut f: F) - where - F: FnMut(&mut T), - { - for (_, object) in self.objects.write().iter_mut() { - f(object); - } - } - fn ptr(&self) -> *const () { Arc::as_ptr(&self.objects) as _ } diff --git a/crates/fj-kernel/src/shape/update.rs b/crates/fj-kernel/src/shape/update.rs deleted file mode 100644 index 8218da478..000000000 --- a/crates/fj-kernel/src/shape/update.rs +++ /dev/null @@ -1,16 +0,0 @@ -use super::{stores::Stores, Object}; - -/// API to update a `Shape` -/// -/// See [`Shape::update`]. -pub struct Update<'r> { - stores: &'r mut Stores, -} - -impl<'r> Update<'r> { - /// Update all objects of a specific type - pub fn update_all(self, f: impl FnMut(&mut T)) -> Self { - self.stores.get::().update(f); - self - } -} From 32d0ad95ce43f7b1565a783d3446f72a70de3ae2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 28 Jun 2022 17:19:28 +0200 Subject: [PATCH 4/5] Remove unused code --- crates/fj-kernel/src/shape/api.rs | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/crates/fj-kernel/src/shape/api.rs b/crates/fj-kernel/src/shape/api.rs index f85a5f1cd..c9e9df626 100644 --- a/crates/fj-kernel/src/shape/api.rs +++ b/crates/fj-kernel/src/shape/api.rs @@ -1,5 +1,3 @@ -use fj_math::Scalar; - use crate::objects::{Curve, Cycle, Edge, Face, Surface, Vertex}; use super::{ @@ -10,8 +8,6 @@ use super::{ /// The boundary representation of a shape #[derive(Clone, Debug)] pub struct Shape { - distinct_min_distance: Scalar, - stores: Stores, } @@ -19,11 +15,6 @@ impl Shape { /// Construct a new shape pub fn new() -> Self { Self { - // This should really come from `Self::DEFAULT_MIN_DISTANCE`, or a - // similarly named constant. Unfortunately `Scalar::from_f64` can't - // be `const` yet. - distinct_min_distance: Scalar::from_f64(5e-7), // 0.5 µm - stores: Stores { curves: Store::new(), surfaces: Store::new(), @@ -55,17 +46,6 @@ impl Shape { self } - /// Override the minimum distance between distinct objects - /// - /// Used for vertex validation, to determine whether vertices are unique. - pub fn with_distinct_min_distance( - mut self, - distinct_min_distance: impl Into, - ) -> Self { - self.distinct_min_distance = distinct_min_distance.into(); - self - } - /// Insert an object into the shape /// /// Validates the object, and returns an error if it is not valid. See the From c5cffd45625ee04035c3f235967bb66d72e9ddca Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 28 Jun 2022 17:20:00 +0200 Subject: [PATCH 5/5] Remove `Shape::merge_shape` It is no longer being used. --- crates/fj-kernel/src/shape/api.rs | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/crates/fj-kernel/src/shape/api.rs b/crates/fj-kernel/src/shape/api.rs index c9e9df626..733944715 100644 --- a/crates/fj-kernel/src/shape/api.rs +++ b/crates/fj-kernel/src/shape/api.rs @@ -99,31 +99,6 @@ impl Shape { object.merge_into(self) } - /// Merge the provided shape into this one - /// - /// Returns a [`Mapping`] that maps each object from the merged shape to the - /// merged objects in this shape. - pub fn merge_shape(&mut self, other: &Shape) { - for object in other.curves() { - object.get().merge_into(self); - } - for object in other.surfaces() { - object.get().merge_into(self); - } - for object in other.vertices() { - object.get().merge_into(self); - } - for object in other.edges() { - object.get().merge_into(self); - } - for object in other.cycles() { - object.get().merge_into(self); - } - for object in other.faces() { - object.get().merge_into(self); - } - } - /// Access an iterator over all curves /// /// The caller must not make any assumptions about the order of curves.