mirror of
https://github.com/hannobraun/Fornjot
synced 2025-11-11 09:30:25 +00:00
Simplify approximate_cycle
This commit is contained in:
parent
6d50d25146
commit
d5876b9650
@ -46,10 +46,18 @@ impl Approximation {
|
|||||||
let mut segments = HashSet::new();
|
let mut segments = HashSet::new();
|
||||||
|
|
||||||
for cycle in face.cycles() {
|
for cycle in face.cycles() {
|
||||||
let approx = approximate_cycle(&cycle, tolerance);
|
let cycle_points = approximate_cycle(&cycle, tolerance);
|
||||||
|
|
||||||
points.extend(approx.points);
|
let mut cycle_segments = Vec::new();
|
||||||
segments.extend(approx.segments);
|
for segment in cycle_points.windows(2) {
|
||||||
|
let p0 = segment[0];
|
||||||
|
let p1 = segment[1];
|
||||||
|
|
||||||
|
cycle_segments.push(Segment::from([p0, p1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
points.extend(cycle_points);
|
||||||
|
segments.extend(cycle_segments);
|
||||||
}
|
}
|
||||||
|
|
||||||
Self { points, segments }
|
Self { points, segments }
|
||||||
@ -89,9 +97,8 @@ fn approximate_edge(
|
|||||||
///
|
///
|
||||||
/// `tolerance` defines how far the approximation is allowed to deviate from the
|
/// `tolerance` defines how far the approximation is allowed to deviate from the
|
||||||
/// actual cycle.
|
/// actual cycle.
|
||||||
pub fn approximate_cycle(cycle: &Cycle, tolerance: Scalar) -> Approximation {
|
pub fn approximate_cycle(cycle: &Cycle, tolerance: Scalar) -> Vec<Point<3>> {
|
||||||
let mut points = HashSet::new();
|
let mut points = Vec::new();
|
||||||
let mut segments = HashSet::new();
|
|
||||||
|
|
||||||
for edge in cycle.edges() {
|
for edge in cycle.edges() {
|
||||||
let mut edge_points = Vec::new();
|
let mut edge_points = Vec::new();
|
||||||
@ -99,19 +106,12 @@ pub fn approximate_cycle(cycle: &Cycle, tolerance: Scalar) -> Approximation {
|
|||||||
|
|
||||||
let edge_points = approximate_edge(edge_points, edge.vertices());
|
let edge_points = approximate_edge(edge_points, edge.vertices());
|
||||||
|
|
||||||
let mut edge_segments = Vec::new();
|
|
||||||
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);
|
points.extend(edge_points);
|
||||||
segments.extend(edge_segments);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Approximation { points, segments }
|
points.dedup();
|
||||||
|
|
||||||
|
points
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use fj_math::{Scalar, Transform, Triangle, Vector};
|
use fj_math::{Scalar, Segment, Transform, Triangle, Vector};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
geometry::{Surface, SweptCurve},
|
geometry::{Surface, SweptCurve},
|
||||||
@ -147,7 +147,9 @@ pub fn sweep_shape(
|
|||||||
let approx = approximate_cycle(&cycle_source.get(), tolerance);
|
let approx = approximate_cycle(&cycle_source.get(), tolerance);
|
||||||
|
|
||||||
let mut quads = Vec::new();
|
let mut quads = Vec::new();
|
||||||
for segment in approx.segments {
|
for segment in approx.windows(2) {
|
||||||
|
let segment = Segment::from_points([segment[0], segment[1]]);
|
||||||
|
|
||||||
let [v0, v1] = segment.points();
|
let [v0, v1] = segment.points();
|
||||||
let [v3, v2] = {
|
let [v3, v2] = {
|
||||||
let segment = Transform::translation(path)
|
let segment = Transform::translation(path)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user