From 2fa1396c38edb505e8582ddfd6c49c40aa974f35 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 20 Sep 2022 17:09:47 +0200 Subject: [PATCH 1/2] Return `Handle`s from `GlobalCurveIter` This is what objects are actually referencing, so it makes sense to return it. --- crates/fj-kernel/src/iter.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index e3d28144c..5f6bf4796 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -52,7 +52,7 @@ pub trait ObjectIters<'r> { } /// Iterate over all global curves - fn global_curve_iter(&'r self) -> Iter<&'r GlobalCurve> { + fn global_curve_iter(&'r self) -> Iter<&'r Handle> { let mut iter = Iter::empty(); for object in self.referenced_objects() { @@ -187,7 +187,7 @@ impl<'r> ObjectIters<'r> for Handle { Vec::new() } - fn global_curve_iter(&'r self) -> Iter<&'r GlobalCurve> { + fn global_curve_iter(&'r self) -> Iter<&'r Handle> { Iter::from_object(self) } } From ec4b3c24be46db65f9e1f07269359c93fdaa15b5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 20 Sep 2022 17:20:02 +0200 Subject: [PATCH 2/2] Use `GlobalCurve` identity for iter dedup --- crates/fj-kernel/src/iter.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 5f6bf4796..7d4d35518 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -56,7 +56,7 @@ pub trait ObjectIters<'r> { let mut iter = Iter::empty(); for object in self.referenced_objects() { - iter = iter.with(object.global_curve_iter()); + iter = iter.with_handles(object.global_curve_iter()); } iter @@ -337,6 +337,18 @@ impl Iter { } } +impl Iter<&'_ Handle> { + fn with_handles(mut self, other: Self) -> Self { + for handle in other { + if !self.0.iter().any(|h| h.id() == handle.id()) { + self.0.push_back(handle); + } + } + + self + } +} + impl Iterator for Iter { type Item = T;