Skip to content

Commit

Permalink
Use Approximation::for_edge in production code
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Feb 8, 2022
1 parent 6726c2b commit 72c1552
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 35 deletions.
1 change: 0 additions & 1 deletion src/kernel/approximation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
35 changes: 1 addition & 34 deletions src/kernel/topology/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 }
}
}

0 comments on commit 72c1552

Please sign in to comment.