From 72c15521f9ae6a30fd87f9755e9e4c148a938df9 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 8 Feb 2022 16:57:25 +0100 Subject: [PATCH] Use `Approximation::for_edge` in production code --- src/kernel/approximation.rs | 1 - src/kernel/topology/edges.rs | 35 +---------------------------------- 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/src/kernel/approximation.rs b/src/kernel/approximation.rs index c42794ace0..886f3f3892 100644 --- a/src/kernel/approximation.rs +++ b/src/kernel/approximation.rs @@ -32,7 +32,6 @@ impl Approximation { /// /// `tolerance` defines how far the approximation is allowed to deviate from /// the actual edge. - #[cfg(test)] pub fn for_edge(edge: &Edge, tolerance: f64) -> Self { let mut points = Vec::new(); edge.curve.approx(tolerance, &mut points); diff --git a/src/kernel/topology/edges.rs b/src/kernel/topology/edges.rs index 7f1f740022..e49022e6ef 100644 --- a/src/kernel/topology/edges.rs +++ b/src/kernel/topology/edges.rs @@ -100,7 +100,7 @@ impl Cycle { let mut segments = Vec::new(); for edge in &self.edges { - let approx = edge.approx(tolerance); + let approx = Approximation::for_edge(&edge, tolerance); points.extend(approx.points); segments.extend(approx.segments); @@ -170,37 +170,4 @@ impl Edge { pub fn reverse(&mut self) { self.reverse = !self.reverse; } - - /// Compute an approximation of the edge - /// - /// `tolerance` defines how far the approximation is allowed to deviate from - /// the actual edge. - pub fn approx(&self, tolerance: f64) -> Approximation { - let mut points = Vec::new(); - self.curve.approx(tolerance, &mut points); - - if self.reverse { - points.reverse() - } - - let mut segment_vertices = points.clone(); - if self.vertices.is_none() { - // The edge has no vertices, which means it connects to itself. We - // need to reflect that in the approximation. - - if let Some(&vertex) = points.first() { - segment_vertices.push(vertex); - } - } - - let mut segments = Vec::new(); - for segment in segment_vertices.windows(2) { - let v0 = segment[0]; - let v1 = segment[1]; - - segments.push([v0, v1].into()); - } - - Approximation { points, segments } - } }