From cf88ded74144bba68f8c3974df2f40d38c400374 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 9 Feb 2022 14:21:59 +0100 Subject: [PATCH] Fix handling of duplicate points in approximation This is the edge case being tracked in #138. --- src/kernel/approximation.rs | 5 +---- src/kernel/topology/edges.rs | 26 +------------------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/src/kernel/approximation.rs b/src/kernel/approximation.rs index 954b32f2e1..6669bd2522 100644 --- a/src/kernel/approximation.rs +++ b/src/kernel/approximation.rs @@ -5,9 +5,7 @@ use parry3d_f64::shape::Segment; use crate::math::Point; -#[cfg(test)] -use super::topology::edges::Cycle; -use super::topology::edges::Edge; +use super::topology::edges::{Cycle, Edge}; /// An approximation of an edge, multiple edges, or a face #[derive(Debug, PartialEq)] @@ -67,7 +65,6 @@ impl Approximation { /// /// `tolerance` defines how far the approximation is allowed to deviate from /// the actual cycle. - #[cfg(test)] pub fn for_cycle(cycle: &Cycle, tolerance: f64) -> Self { let mut points = Vec::new(); let mut segments = Vec::new(); diff --git a/src/kernel/topology/edges.rs b/src/kernel/topology/edges.rs index e49022e6ef..b6f3cfb180 100644 --- a/src/kernel/topology/edges.rs +++ b/src/kernel/topology/edges.rs @@ -70,7 +70,7 @@ impl Edges { let mut segments = Vec::new(); for cycle in &self.cycles { - let approx = cycle.approx(tolerance); + let approx = Approximation::for_cycle(cycle, tolerance); points.extend(approx.points); segments.extend(approx.segments); @@ -90,30 +90,6 @@ pub struct Cycle { pub edges: Vec, } -impl Cycle { - /// Compute an approximation of the cycle - /// - /// `tolerance` defines how far the approximation is allowed to deviate from - /// the actual cycle. - pub fn approx(&self, tolerance: f64) -> Approximation { - let mut points = Vec::new(); - let mut segments = Vec::new(); - - for edge in &self.edges { - let approx = Approximation::for_edge(&edge, tolerance); - - points.extend(approx.points); - segments.extend(approx.segments); - } - - // As this is a cycle, the last vertex of an edge could be identical to - // the first vertex of the next. Let's remove those duplicates. - points.dedup(); - - Approximation { points, segments } - } -} - /// An edge of a shape #[derive(Clone, Debug)] pub struct Edge {