From 70a836b2b7374a8bd9f6f3a560cda346ffd7beba Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 20 Jul 2022 16:36:51 +0200 Subject: [PATCH 1/4] Update comment --- crates/fj-kernel/src/iter.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 60fa34b52..a5f0a3a4a 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -654,11 +654,7 @@ impl<'r> ObjectIters<'r> for Vertex { } } -// This implementation exists to paper over the lack of any "top-level" objects -// that are an entry point into a shape (basically, the lack of `Sketch` and -// `Solid`). -// -// It is also very useful in test code. +// This implementation is useful for test code. impl<'r, T, O> ObjectIters<'r> for T where T: 'r, From 7d6580baafdcd7f978763a19c5f36343f5d0a386 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 21 Jul 2022 11:40:03 +0200 Subject: [PATCH 2/4] Add `ObjectIters::referenced_objects` --- crates/fj-kernel/src/iter.rs | 83 ++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index a5f0a3a4a..77af487a8 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -11,6 +11,9 @@ use crate::objects::{ /// Implemented for all object types. An implementation must return itself, in /// addition to any other objects it references. pub trait ObjectIters<'r> { + /// Return all objects being referenced + fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters>; + /// Iterate over all curves fn curve_iter(&'r self) -> Iter<&'r Curve<3>>; @@ -40,6 +43,10 @@ pub trait ObjectIters<'r> { } impl<'r> ObjectIters<'r> for Curve<3> { + fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { + Vec::new() + } + fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { Iter::from_object(self) } @@ -78,6 +85,16 @@ impl<'r> ObjectIters<'r> for Curve<3> { } impl<'r> ObjectIters<'r> for Cycle { + fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { + let mut objects = Vec::new(); + + for edge in self.edges() { + objects.push(edge as &dyn ObjectIters); + } + + objects + } + fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { let mut iter = Iter::empty(); @@ -164,6 +181,16 @@ impl<'r> ObjectIters<'r> for Cycle { } impl<'r> ObjectIters<'r> for Edge { + fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { + let mut objects = vec![self.curve().global() as &dyn ObjectIters]; + + for vertex in self.vertices().iter() { + objects.push(vertex); + } + + objects + } + fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { let mut iter = Iter::empty().with(self.curve().global().curve_iter()); @@ -251,6 +278,20 @@ impl<'r> ObjectIters<'r> for Edge { } impl<'r> ObjectIters<'r> for Face { + fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { + if self.triangles().is_some() { + return Vec::new(); + } + + let mut objects = vec![self.surface() as &dyn ObjectIters]; + + for cycle in self.all_cycles() { + objects.push(cycle); + } + + objects + } + fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { if self.triangles().is_some() { return Iter::empty(); @@ -369,6 +410,10 @@ impl<'r> ObjectIters<'r> for Face { } impl<'r> ObjectIters<'r> for GlobalVertex { + fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { + Vec::new() + } + fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { Iter::empty() } @@ -407,6 +452,16 @@ impl<'r> ObjectIters<'r> for GlobalVertex { } impl<'r> ObjectIters<'r> for Sketch { + fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { + let mut objects = Vec::new(); + + for face in self.faces() { + objects.push(face as &dyn ObjectIters); + } + + objects + } + fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { let mut iter = Iter::empty(); @@ -493,6 +548,16 @@ impl<'r> ObjectIters<'r> for Sketch { } impl<'r> ObjectIters<'r> for Solid { + fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { + let mut objects = Vec::new(); + + for face in self.faces() { + objects.push(face as &dyn ObjectIters); + } + + objects + } + fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { let mut iter = Iter::empty(); @@ -579,6 +644,10 @@ impl<'r> ObjectIters<'r> for Solid { } impl<'r> ObjectIters<'r> for Surface { + fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { + Vec::new() + } + fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { Iter::empty() } @@ -617,6 +686,10 @@ impl<'r> ObjectIters<'r> for Surface { } impl<'r> ObjectIters<'r> for Vertex { + fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { + vec![self.global() as &dyn ObjectIters] + } + fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { self.global().curve_iter() } @@ -661,6 +734,16 @@ where O: ObjectIters<'r> + 'r, &'r T: IntoIterator, { + fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { + let mut objects = Vec::new(); + + for object in self.into_iter() { + objects.push(object as &dyn ObjectIters); + } + + objects + } + fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { let mut iter = Iter::empty(); From ddb0251fe5ae8430891fadbaffa655fcbecb0bd2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 21 Jul 2022 11:52:49 +0200 Subject: [PATCH 3/4] Add default impls for most `ObjectIters` methods --- crates/fj-kernel/src/iter.rs | 90 ++++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 9 deletions(-) diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 77af487a8..593f347a8 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -15,31 +15,103 @@ pub trait ObjectIters<'r> { fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters>; /// Iterate over all curves - fn curve_iter(&'r self) -> Iter<&'r Curve<3>>; + fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { + let mut iter = Iter::empty(); + + for object in self.referenced_objects() { + iter = iter.with(object.curve_iter()); + } + + iter + } /// Iterate over all cycles - fn cycle_iter(&'r self) -> Iter<&'r Cycle>; + fn cycle_iter(&'r self) -> Iter<&'r Cycle> { + let mut iter = Iter::empty(); + + for object in self.referenced_objects() { + iter = iter.with(object.cycle_iter()); + } + + iter + } /// Iterate over all edges - fn edge_iter(&'r self) -> Iter<&'r Edge>; + fn edge_iter(&'r self) -> Iter<&'r Edge> { + let mut iter = Iter::empty(); + + for object in self.referenced_objects() { + iter = iter.with(object.edge_iter()); + } + + iter + } /// Iterate over all faces - fn face_iter(&'r self) -> Iter<&'r Face>; + fn face_iter(&'r self) -> Iter<&'r Face> { + let mut iter = Iter::empty(); + + for object in self.referenced_objects() { + iter = iter.with(object.face_iter()); + } + + iter + } /// Iterate over all global vertices - fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex>; + fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> { + let mut iter = Iter::empty(); + + for object in self.referenced_objects() { + iter = iter.with(object.global_vertex_iter()); + } + + iter + } /// Iterate over all sketches - fn sketch_iter(&'r self) -> Iter<&'r Sketch>; + fn sketch_iter(&'r self) -> Iter<&'r Sketch> { + let mut iter = Iter::empty(); + + for object in self.referenced_objects() { + iter = iter.with(object.sketch_iter()); + } + + iter + } /// Iterate over all solids - fn solid_iter(&'r self) -> Iter<&'r Solid>; + fn solid_iter(&'r self) -> Iter<&'r Solid> { + let mut iter = Iter::empty(); + + for object in self.referenced_objects() { + iter = iter.with(object.solid_iter()); + } + + iter + } /// Iterate over all surfaces - fn surface_iter(&'r self) -> Iter<&'r Surface>; + fn surface_iter(&'r self) -> Iter<&'r Surface> { + let mut iter = Iter::empty(); + + for object in self.referenced_objects() { + iter = iter.with(object.surface_iter()); + } + + iter + } /// Iterator over all vertices - fn vertex_iter(&'r self) -> Iter<&'r Vertex>; + fn vertex_iter(&'r self) -> Iter<&'r Vertex> { + let mut iter = Iter::empty(); + + for object in self.referenced_objects() { + iter = iter.with(object.vertex_iter()); + } + + iter + } } impl<'r> ObjectIters<'r> for Curve<3> { From 5b26c232b826b56aa2198f3e5700377cb89984ac Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 21 Jul 2022 11:53:43 +0200 Subject: [PATCH 4/4] Remove redundant `ObjectIters` method impls --- crates/fj-kernel/src/iter.rs | 745 +++-------------------------------- 1 file changed, 47 insertions(+), 698 deletions(-) diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 593f347a8..643d13b30 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -122,596 +122,99 @@ impl<'r> ObjectIters<'r> for Curve<3> { fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { Iter::from_object(self) } +} - fn cycle_iter(&'r self) -> Iter<&'r Cycle> { - Iter::empty() - } - - fn edge_iter(&'r self) -> Iter<&'r Edge> { - Iter::empty() - } - - fn face_iter(&'r self) -> Iter<&'r Face> { - Iter::empty() - } - - fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> { - Iter::empty() - } - - fn sketch_iter(&'r self) -> Iter<&'r Sketch> { - Iter::empty() - } - - fn solid_iter(&'r self) -> Iter<&'r Solid> { - Iter::empty() - } - - fn surface_iter(&'r self) -> Iter<&'r Surface> { - Iter::empty() - } - - fn vertex_iter(&'r self) -> Iter<&'r Vertex> { - Iter::empty() - } -} - -impl<'r> ObjectIters<'r> for Cycle { - fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { - let mut objects = Vec::new(); - - for edge in self.edges() { - objects.push(edge as &dyn ObjectIters); - } - - objects - } - - fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { - let mut iter = Iter::empty(); - - for edge in self.edges() { - iter = iter.with(edge.curve_iter()); - } - - iter - } - - fn cycle_iter(&'r self) -> Iter<&'r Cycle> { - Iter::from_object(self) - } - - fn edge_iter(&'r self) -> Iter<&'r Edge> { - let mut iter = Iter::empty(); - - for edge in self.edges() { - iter = iter.with(edge.edge_iter()); - } - - iter - } - - fn face_iter(&'r self) -> Iter<&'r Face> { - let mut iter = Iter::empty(); - - for edge in self.edges() { - iter = iter.with(edge.face_iter()); - } - - iter - } - - fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> { - let mut iter = Iter::empty(); - - for edge in self.edges() { - iter = iter.with(edge.global_vertex_iter()); - } - - iter - } - - fn sketch_iter(&'r self) -> Iter<&'r Sketch> { - let mut iter = Iter::empty(); - - for edge in self.edges() { - iter = iter.with(edge.sketch_iter()); - } - - iter - } - - fn solid_iter(&'r self) -> Iter<&'r Solid> { - let mut iter = Iter::empty(); - - for edge in self.edges() { - iter = iter.with(edge.solid_iter()); - } - - iter - } - - fn surface_iter(&'r self) -> Iter<&'r Surface> { - let mut iter = Iter::empty(); - - for edge in self.edges() { - iter = iter.with(edge.surface_iter()); - } - - iter - } - - fn vertex_iter(&'r self) -> Iter<&'r Vertex> { - let mut iter = Iter::empty(); - - for edge in self.edges() { - iter = iter.with(edge.vertex_iter()); - } - - iter - } -} - -impl<'r> ObjectIters<'r> for Edge { - fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { - let mut objects = vec![self.curve().global() as &dyn ObjectIters]; - - for vertex in self.vertices().iter() { - objects.push(vertex); - } - - objects - } - - fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { - let mut iter = Iter::empty().with(self.curve().global().curve_iter()); - - for vertex in self.vertices().iter() { - iter = iter.with(vertex.curve_iter()); - } - - iter - } - - fn cycle_iter(&'r self) -> Iter<&'r Cycle> { - let mut iter = Iter::empty().with(self.curve().global().cycle_iter()); - - for vertex in self.vertices().iter() { - iter = iter.with(vertex.cycle_iter()); - } - - iter - } - - fn edge_iter(&'r self) -> Iter<&'r Edge> { - Iter::from_object(self) - } - - fn face_iter(&'r self) -> Iter<&'r Face> { - let mut iter = Iter::empty().with(self.curve().global().face_iter()); - - for vertex in self.vertices().iter() { - iter = iter.with(vertex.face_iter()); - } - - iter - } - - fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> { - let mut iter = - Iter::empty().with(self.curve().global().global_vertex_iter()); - - for vertex in self.vertices().iter() { - iter = iter.with(vertex.global_vertex_iter()); - } - - iter - } - - fn sketch_iter(&'r self) -> Iter<&'r Sketch> { - let mut iter = Iter::empty().with(self.curve().global().sketch_iter()); - - for vertex in self.vertices().iter() { - iter = iter.with(vertex.sketch_iter()); - } - - iter - } - - fn solid_iter(&'r self) -> Iter<&'r Solid> { - let mut iter = Iter::empty().with(self.curve().global().solid_iter()); - - for vertex in self.vertices().iter() { - iter = iter.with(vertex.solid_iter()); - } - - iter - } - - fn surface_iter(&'r self) -> Iter<&'r Surface> { - let mut iter = Iter::empty().with(self.curve().global().surface_iter()); - - for vertex in self.vertices().iter() { - iter = iter.with(vertex.surface_iter()); - } - - iter - } - - fn vertex_iter(&'r self) -> Iter<&'r Vertex> { - let mut iter = Iter::empty().with(self.curve().global().vertex_iter()); - - for vertex in self.vertices().iter() { - iter = iter.with(vertex.vertex_iter()); - } - - iter - } -} - -impl<'r> ObjectIters<'r> for Face { - fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { - if self.triangles().is_some() { - return Vec::new(); - } - - let mut objects = vec![self.surface() as &dyn ObjectIters]; - - for cycle in self.all_cycles() { - objects.push(cycle); - } - - objects - } - - fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { - if self.triangles().is_some() { - return Iter::empty(); - } - - let mut iter = Iter::empty().with(self.surface().curve_iter()); - - for cycle in self.all_cycles() { - iter = iter.with(cycle.curve_iter()); - } - - iter - } - - fn cycle_iter(&'r self) -> Iter<&'r Cycle> { - if self.triangles().is_some() { - return Iter::empty(); - } - - let mut iter = Iter::empty().with(self.surface().cycle_iter()); - - for cycle in self.all_cycles() { - iter = iter.with(cycle.cycle_iter()); - } - - iter - } - - fn edge_iter(&'r self) -> Iter<&'r Edge> { - if self.triangles().is_some() { - return Iter::empty(); - } - - let mut iter = Iter::empty().with(self.surface().edge_iter()); - - for cycle in self.all_cycles() { - iter = iter.with(cycle.edge_iter()); - } - - iter - } - - fn face_iter(&'r self) -> Iter<&'r Face> { - Iter::from_object(self) - } - - fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> { - if self.triangles().is_some() { - return Iter::empty(); - } - - let mut iter = Iter::empty().with(self.surface().global_vertex_iter()); - - for cycle in self.all_cycles() { - iter = iter.with(cycle.global_vertex_iter()); - } - - iter - } - - fn sketch_iter(&'r self) -> Iter<&'r Sketch> { - if self.triangles().is_some() { - return Iter::empty(); - } - - let mut iter = Iter::empty().with(self.surface().sketch_iter()); - - for cycle in self.all_cycles() { - iter = iter.with(cycle.sketch_iter()); - } - - iter - } - - fn solid_iter(&'r self) -> Iter<&'r Solid> { - if self.triangles().is_some() { - return Iter::empty(); - } - - let mut iter = Iter::empty().with(self.surface().solid_iter()); - - for cycle in self.all_cycles() { - iter = iter.with(cycle.solid_iter()); - } - - iter - } - - fn surface_iter(&'r self) -> Iter<&'r Surface> { - if self.triangles().is_some() { - return Iter::empty(); - } - - let mut iter = Iter::empty().with(self.surface().surface_iter()); - - for cycle in self.all_cycles() { - iter = iter.with(cycle.surface_iter()); - } - - iter - } - - fn vertex_iter(&'r self) -> Iter<&'r Vertex> { - if self.triangles().is_some() { - return Iter::empty(); - } - - let mut iter = Iter::empty().with(self.surface().vertex_iter()); - - for cycle in self.all_cycles() { - iter = iter.with(cycle.vertex_iter()); - } - - iter - } -} - -impl<'r> ObjectIters<'r> for GlobalVertex { - fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { - Vec::new() - } - - fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { - Iter::empty() - } - - fn cycle_iter(&'r self) -> Iter<&'r Cycle> { - Iter::empty() - } - - fn edge_iter(&'r self) -> Iter<&'r Edge> { - Iter::empty() - } - - fn face_iter(&'r self) -> Iter<&'r Face> { - Iter::empty() - } - - fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> { - Iter::from_object(self) - } - - fn sketch_iter(&'r self) -> Iter<&'r Sketch> { - Iter::empty() - } - - fn solid_iter(&'r self) -> Iter<&'r Solid> { - Iter::empty() - } - - fn surface_iter(&'r self) -> Iter<&'r Surface> { - Iter::empty() - } - - fn vertex_iter(&'r self) -> Iter<&'r Vertex> { - Iter::empty() - } -} - -impl<'r> ObjectIters<'r> for Sketch { - fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { - let mut objects = Vec::new(); - - for face in self.faces() { - objects.push(face as &dyn ObjectIters); - } - - objects - } - - fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { - let mut iter = Iter::empty(); - - for edge in self.faces() { - iter = iter.with(edge.curve_iter()); - } - - iter - } - - fn cycle_iter(&'r self) -> Iter<&'r Cycle> { - let mut iter = Iter::empty(); - - for edge in self.faces() { - iter = iter.with(edge.cycle_iter()); - } - - iter - } - - fn edge_iter(&'r self) -> Iter<&'r Edge> { - let mut iter = Iter::empty(); - - for edge in self.faces() { - iter = iter.with(edge.edge_iter()); - } - - iter - } - - fn face_iter(&'r self) -> Iter<&'r Face> { - let mut iter = Iter::empty(); - - for edge in self.faces() { - iter = iter.with(edge.face_iter()); - } - - iter - } - - fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> { - let mut iter = Iter::empty(); +impl<'r> ObjectIters<'r> for Cycle { + fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { + let mut objects = Vec::new(); - for edge in self.faces() { - iter = iter.with(edge.global_vertex_iter()); + for edge in self.edges() { + objects.push(edge as &dyn ObjectIters); } - iter + objects } - fn sketch_iter(&'r self) -> Iter<&'r Sketch> { + fn cycle_iter(&'r self) -> Iter<&'r Cycle> { Iter::from_object(self) } - - fn solid_iter(&'r self) -> Iter<&'r Solid> { - let mut iter = Iter::empty(); - - for edge in self.faces() { - iter = iter.with(edge.solid_iter()); - } - - iter - } - - fn surface_iter(&'r self) -> Iter<&'r Surface> { - let mut iter = Iter::empty(); - - for edge in self.faces() { - iter = iter.with(edge.surface_iter()); - } - - iter - } - - fn vertex_iter(&'r self) -> Iter<&'r Vertex> { - let mut iter = Iter::empty(); - - for edge in self.faces() { - iter = iter.with(edge.vertex_iter()); - } - - iter - } } -impl<'r> ObjectIters<'r> for Solid { +impl<'r> ObjectIters<'r> for Edge { fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { - let mut objects = Vec::new(); + let mut objects = vec![self.curve().global() as &dyn ObjectIters]; - for face in self.faces() { - objects.push(face as &dyn ObjectIters); + for vertex in self.vertices().iter() { + objects.push(vertex); } objects } - fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { - let mut iter = Iter::empty(); - - for edge in self.faces() { - iter = iter.with(edge.curve_iter()); - } - - iter + fn edge_iter(&'r self) -> Iter<&'r Edge> { + Iter::from_object(self) } +} - fn cycle_iter(&'r self) -> Iter<&'r Cycle> { - let mut iter = Iter::empty(); - - for edge in self.faces() { - iter = iter.with(edge.cycle_iter()); +impl<'r> ObjectIters<'r> for Face { + fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { + if self.triangles().is_some() { + return Vec::new(); } - iter - } - - fn edge_iter(&'r self) -> Iter<&'r Edge> { - let mut iter = Iter::empty(); + let mut objects = vec![self.surface() as &dyn ObjectIters]; - for edge in self.faces() { - iter = iter.with(edge.edge_iter()); + for cycle in self.all_cycles() { + objects.push(cycle); } - iter + objects } fn face_iter(&'r self) -> Iter<&'r Face> { - let mut iter = Iter::empty(); - - for edge in self.faces() { - iter = iter.with(edge.face_iter()); - } + Iter::from_object(self) + } +} - iter +impl<'r> ObjectIters<'r> for GlobalVertex { + fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { + Vec::new() } fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> { - let mut iter = Iter::empty(); - - for edge in self.faces() { - iter = iter.with(edge.global_vertex_iter()); - } - - iter + Iter::from_object(self) } +} - fn sketch_iter(&'r self) -> Iter<&'r Sketch> { - let mut iter = Iter::empty(); +impl<'r> ObjectIters<'r> for Sketch { + fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { + let mut objects = Vec::new(); - for edge in self.faces() { - iter = iter.with(edge.sketch_iter()); + for face in self.faces() { + objects.push(face as &dyn ObjectIters); } - iter + objects } - fn solid_iter(&'r self) -> Iter<&'r Solid> { + fn sketch_iter(&'r self) -> Iter<&'r Sketch> { Iter::from_object(self) } +} - fn surface_iter(&'r self) -> Iter<&'r Surface> { - let mut iter = Iter::empty(); +impl<'r> ObjectIters<'r> for Solid { + fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { + let mut objects = Vec::new(); - for edge in self.faces() { - iter = iter.with(edge.surface_iter()); + for face in self.faces() { + objects.push(face as &dyn ObjectIters); } - iter + objects } - fn vertex_iter(&'r self) -> Iter<&'r Vertex> { - let mut iter = Iter::empty(); - - for edge in self.faces() { - iter = iter.with(edge.vertex_iter()); - } - - iter + fn solid_iter(&'r self) -> Iter<&'r Solid> { + Iter::from_object(self) } } @@ -720,41 +223,9 @@ impl<'r> ObjectIters<'r> for Surface { Vec::new() } - fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { - Iter::empty() - } - - fn cycle_iter(&'r self) -> Iter<&'r Cycle> { - Iter::empty() - } - - fn edge_iter(&'r self) -> Iter<&'r Edge> { - Iter::empty() - } - - fn face_iter(&'r self) -> Iter<&'r Face> { - Iter::empty() - } - - fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> { - Iter::empty() - } - - fn sketch_iter(&'r self) -> Iter<&'r Sketch> { - Iter::empty() - } - - fn solid_iter(&'r self) -> Iter<&'r Solid> { - Iter::empty() - } - fn surface_iter(&'r self) -> Iter<&'r Surface> { Iter::from_object(self) } - - fn vertex_iter(&'r self) -> Iter<&'r Vertex> { - Iter::empty() - } } impl<'r> ObjectIters<'r> for Vertex { @@ -762,38 +233,6 @@ impl<'r> ObjectIters<'r> for Vertex { vec![self.global() as &dyn ObjectIters] } - fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { - self.global().curve_iter() - } - - fn cycle_iter(&'r self) -> Iter<&'r Cycle> { - self.global().cycle_iter() - } - - fn edge_iter(&'r self) -> Iter<&'r Edge> { - self.global().edge_iter() - } - - fn face_iter(&'r self) -> Iter<&'r Face> { - self.global().face_iter() - } - - fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> { - self.global().global_vertex_iter() - } - - fn sketch_iter(&'r self) -> Iter<&'r Sketch> { - self.global().sketch_iter() - } - - fn solid_iter(&'r self) -> Iter<&'r Solid> { - self.global().solid_iter() - } - - fn surface_iter(&'r self) -> Iter<&'r Surface> { - self.global().surface_iter() - } - fn vertex_iter(&'r self) -> Iter<&'r Vertex> { Iter::from_object(self) } @@ -815,96 +254,6 @@ where objects } - - fn curve_iter(&'r self) -> Iter<&'r Curve<3>> { - let mut iter = Iter::empty(); - - for object in self.into_iter() { - iter = iter.with(object.curve_iter()); - } - - iter - } - - fn cycle_iter(&'r self) -> Iter<&'r Cycle> { - let mut iter = Iter::empty(); - - for object in self.into_iter() { - iter = iter.with(object.cycle_iter()); - } - - iter - } - - fn edge_iter(&'r self) -> Iter<&'r Edge> { - let mut iter = Iter::empty(); - - for object in self.into_iter() { - iter = iter.with(object.edge_iter()); - } - - iter - } - - fn face_iter(&'r self) -> Iter<&'r Face> { - let mut iter = Iter::empty(); - - for object in self.into_iter() { - iter = iter.with(object.face_iter()); - } - - iter - } - - fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> { - let mut iter = Iter::empty(); - - for object in self.into_iter() { - iter = iter.with(object.global_vertex_iter()); - } - - iter - } - - fn sketch_iter(&'r self) -> Iter<&'r Sketch> { - let mut iter = Iter::empty(); - - for object in self.into_iter() { - iter = iter.with(object.sketch_iter()); - } - - iter - } - - fn solid_iter(&'r self) -> Iter<&'r Solid> { - let mut iter = Iter::empty(); - - for object in self.into_iter() { - iter = iter.with(object.solid_iter()); - } - - iter - } - - fn surface_iter(&'r self) -> Iter<&'r Surface> { - let mut iter = Iter::empty(); - - for object in self.into_iter() { - iter = iter.with(object.surface_iter()); - } - - iter - } - - fn vertex_iter(&'r self) -> Iter<&'r Vertex> { - let mut iter = Iter::empty(); - - for object in self.into_iter() { - iter = iter.with(object.vertex_iter()); - } - - iter - } } /// An iterator over objects