Skip to content

Commit

Permalink
Fix handling of duplicate points in approximation
Browse files Browse the repository at this point in the history
This is the edge case being tracked in #138.
  • Loading branch information
hannobraun committed Feb 9, 2022
1 parent ae05d14 commit cf88ded
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 29 deletions.
5 changes: 1 addition & 4 deletions src/kernel/approximation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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();
Expand Down
26 changes: 1 addition & 25 deletions src/kernel/topology/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -90,30 +90,6 @@ pub struct Cycle {
pub edges: Vec<Edge>,
}

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 {
Expand Down

0 comments on commit cf88ded

Please sign in to comment.