mirror of
https://github.com/hannobraun/Fornjot
synced 2025-11-14 11:00:06 +00:00
Simplify approximate_edge
This commit is contained in:
parent
6854755be4
commit
6d50d25146
@ -59,7 +59,7 @@ impl Approximation {
|
|||||||
fn approximate_edge(
|
fn approximate_edge(
|
||||||
mut points: Vec<Point<3>>,
|
mut points: Vec<Point<3>>,
|
||||||
vertices: Option<[Vertex; 2]>,
|
vertices: Option<[Vertex; 2]>,
|
||||||
) -> Approximation {
|
) -> Vec<Point<3>> {
|
||||||
// Insert the exact vertices of this edge into the approximation. This means
|
// Insert the exact vertices of this edge into the approximation. This means
|
||||||
// we don't rely on the curve approximation to deliver accurate
|
// we don't rely on the curve approximation to deliver accurate
|
||||||
// representations of these vertices, which they might not be able to do.
|
// representations of these vertices, which they might not be able to do.
|
||||||
@ -82,18 +82,7 @@ fn approximate_edge(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut segments = HashSet::new();
|
points
|
||||||
for segment in points.windows(2) {
|
|
||||||
let p0 = segment[0];
|
|
||||||
let p1 = segment[1];
|
|
||||||
|
|
||||||
segments.insert(Segment::from([p0, p1]));
|
|
||||||
}
|
|
||||||
|
|
||||||
Approximation {
|
|
||||||
points: points.into_iter().collect(),
|
|
||||||
segments,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compute an approximation for a cycle
|
/// Compute an approximation for a cycle
|
||||||
@ -108,10 +97,18 @@ pub fn approximate_cycle(cycle: &Cycle, tolerance: Scalar) -> Approximation {
|
|||||||
let mut edge_points = Vec::new();
|
let mut edge_points = Vec::new();
|
||||||
edge.curve().approx(tolerance, &mut edge_points);
|
edge.curve().approx(tolerance, &mut edge_points);
|
||||||
|
|
||||||
let approx = approximate_edge(edge_points, edge.vertices());
|
let edge_points = approximate_edge(edge_points, edge.vertices());
|
||||||
|
|
||||||
points.extend(approx.points);
|
let mut edge_segments = Vec::new();
|
||||||
segments.extend(approx.segments);
|
for segment in edge_points.windows(2) {
|
||||||
|
let p0 = segment[0];
|
||||||
|
let p1 = segment[1];
|
||||||
|
|
||||||
|
edge_segments.push(Segment::from([p0, p1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
points.extend(edge_points);
|
||||||
|
segments.extend(edge_segments);
|
||||||
}
|
}
|
||||||
|
|
||||||
Approximation { points, segments }
|
Approximation { points, segments }
|
||||||
@ -153,24 +150,11 @@ mod tests {
|
|||||||
points.clone(),
|
points.clone(),
|
||||||
Some([v1.get().clone(), v2.get().clone()])
|
Some([v1.get().clone(), v2.get().clone()])
|
||||||
),
|
),
|
||||||
Approximation {
|
vec![a, b, c, d],
|
||||||
points: set![a, b, c, d],
|
|
||||||
segments: set![
|
|
||||||
Segment::from([a, b]),
|
|
||||||
Segment::from([b, c]),
|
|
||||||
Segment::from([c, d]),
|
|
||||||
],
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Continuous edge
|
// Continuous edge
|
||||||
assert_eq!(
|
assert_eq!(super::approximate_edge(points, None), vec![b, c, b],);
|
||||||
super::approximate_edge(points, None),
|
|
||||||
Approximation {
|
|
||||||
points: set![b, c],
|
|
||||||
segments: set![Segment::from([b, c]), Segment::from([c, b])],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user