From d657ecec4addae3fc1b51c4e28b29494e1f58021 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 1 Apr 2022 17:23:58 +0200 Subject: [PATCH] Replace `Topology::add_cycle` with `Shape::insert` --- fj-kernel/src/algorithms/approximation.rs | 2 +- fj-kernel/src/algorithms/sweep.rs | 13 ++++-------- fj-kernel/src/shape/topology.rs | 25 +++-------------------- fj-operations/src/circle.rs | 5 +---- fj-operations/src/difference_2d.rs | 2 +- fj-operations/src/group.rs | 3 +-- fj-operations/src/sketch.rs | 2 +- 7 files changed, 12 insertions(+), 40 deletions(-) diff --git a/fj-kernel/src/algorithms/approximation.rs b/fj-kernel/src/algorithms/approximation.rs index be105b297..bb5e5b42e 100644 --- a/fj-kernel/src/algorithms/approximation.rs +++ b/fj-kernel/src/algorithms/approximation.rs @@ -176,7 +176,7 @@ mod tests { let da = Edge::build(&mut shape).line_segment_from_vertices([v4, v1])?; - let abcd = shape.topology().add_cycle(Cycle { + let abcd = shape.insert(Cycle { edges: vec![ab, bc, cd, da], })?; diff --git a/fj-kernel/src/algorithms/sweep.rs b/fj-kernel/src/algorithms/sweep.rs index f86e71140..8ed99213a 100644 --- a/fj-kernel/src/algorithms/sweep.rs +++ b/fj-kernel/src/algorithms/sweep.rs @@ -77,15 +77,11 @@ pub fn sweep_shape( let edges_top = source_to_top.edges_for_cycle(&cycle_source); let cycle_bottom = target - .topology() - .add_cycle(Cycle { + .insert(Cycle { edges: edges_bottom, }) .unwrap(); - let cycle_top = target - .topology() - .add_cycle(Cycle { edges: edges_top }) - .unwrap(); + let cycle_top = target.insert(Cycle { edges: edges_top }).unwrap(); source_to_bottom .cycles @@ -237,8 +233,7 @@ pub fn sweep_shape( .unwrap(); let cycle = target - .topology() - .add_cycle(Cycle { + .insert(Cycle { edges: vec![ bottom_edge, top_edge, @@ -406,7 +401,7 @@ mod tests { let ca = Edge::build(&mut shape) .line_segment_from_vertices([c.clone(), a.clone()])?; - let cycles = shape.topology().add_cycle(Cycle { + let cycles = shape.insert(Cycle { edges: vec![ab, bc, ca], })?; diff --git a/fj-kernel/src/shape/topology.rs b/fj-kernel/src/shape/topology.rs index e6a612000..e08638bed 100644 --- a/fj-kernel/src/shape/topology.rs +++ b/fj-kernel/src/shape/topology.rs @@ -14,23 +14,6 @@ pub struct Topology<'r> { } impl Topology<'_> { - /// Add a cycle to the shape - /// - /// Validates that the cycle is structurally sound (i.e. the edges it refers - /// to are part of the shape). Returns an error, if that is not the case. - /// - /// # Implementation note - /// - /// The validation of the cycle should be extended to cover more cases: - /// - That those edges form a cycle. - /// - That the cycle is not self-overlapping. - /// - That there exists no duplicate cycle, with the same edges. - pub fn add_cycle(&mut self, cycle: Cycle) -> ValidationResult { - cycle.validate(self.min_distance, &self.stores)?; - let handle = self.stores.cycles.insert(cycle); - Ok(handle) - } - /// Add a face to the shape /// /// Validates that the face is structurally sound (i.e. the surface and @@ -153,8 +136,7 @@ mod tests { // Trying to refer to edge that is not from the same shape. Should fail. let edge = other.add_edge()?; let err = shape - .topology() - .add_cycle(Cycle { + .insert(Cycle { edges: vec![edge.clone()], }) .unwrap_err(); @@ -162,7 +144,7 @@ mod tests { // Referring to edge that *is* from the same shape. Should work. let edge = shape.add_edge()?; - shape.topology().add_cycle(Cycle { edges: vec![edge] })?; + shape.insert(Cycle { edges: vec![edge] })?; Ok(()) } @@ -239,8 +221,7 @@ mod tests { fn add_cycle(&mut self) -> anyhow::Result> { let edge = self.add_edge()?; - let cycle = - self.topology().add_cycle(Cycle { edges: vec![edge] })?; + let cycle = self.insert(Cycle { edges: vec![edge] })?; Ok(cycle) } } diff --git a/fj-operations/src/circle.rs b/fj-operations/src/circle.rs index 9dadbfc91..9f301ee04 100644 --- a/fj-operations/src/circle.rs +++ b/fj-operations/src/circle.rs @@ -18,10 +18,7 @@ impl ToShape for fj::Circle { let edge = Edge::build(&mut shape) .circle(Scalar::from_f64(self.radius())) .unwrap(); - shape - .topology() - .add_cycle(Cycle { edges: vec![edge] }) - .unwrap(); + shape.insert(Cycle { edges: vec![edge] }).unwrap(); let cycles = shape.topology().cycles().collect(); let surface = shape.insert(Surface::x_y_plane()).unwrap(); diff --git a/fj-operations/src/difference_2d.rs b/fj-operations/src/difference_2d.rs index 106691e23..2001d7870 100644 --- a/fj-operations/src/difference_2d.rs +++ b/fj-operations/src/difference_2d.rs @@ -109,5 +109,5 @@ fn add_cycle( edges.push(edge); } - shape.topology().add_cycle(Cycle { edges }).unwrap() + shape.insert(Cycle { edges }).unwrap() } diff --git a/fj-operations/src/group.rs b/fj-operations/src/group.rs index 0ccd59f85..168ce1893 100644 --- a/fj-operations/src/group.rs +++ b/fj-operations/src/group.rs @@ -73,8 +73,7 @@ fn copy_shape(mut orig: Shape, target: &mut Shape) { } for cycle_orig in orig.topology().cycles() { let cycle = target - .topology() - .add_cycle(Cycle { + .insert(Cycle { edges: cycle_orig .get() .edges diff --git a/fj-operations/src/sketch.rs b/fj-operations/src/sketch.rs index aa8e5515d..6e48c484e 100644 --- a/fj-operations/src/sketch.rs +++ b/fj-operations/src/sketch.rs @@ -42,7 +42,7 @@ impl ToShape for fj::Sketch { edges.push(edge); } - shape.topology().add_cycle(Cycle { edges }).unwrap(); + shape.insert(Cycle { edges }).unwrap(); }; let surface = shape.insert(Surface::x_y_plane()).unwrap();