mirror of
https://github.com/hannobraun/Fornjot
synced 2025-11-15 03:20:07 +00:00
Convert method into function
This makes room for simplifying the function, having it return something else than a full `Approximation`.
This commit is contained in:
parent
4f18b05223
commit
e22fec9e79
@ -24,27 +24,6 @@ pub struct Approximation {
|
||||
}
|
||||
|
||||
impl Approximation {
|
||||
/// Compute an approximation for a cycle
|
||||
///
|
||||
/// `tolerance` defines how far the approximation is allowed to deviate from
|
||||
/// the actual cycle.
|
||||
pub fn for_cycle(cycle: &Cycle, tolerance: Scalar) -> Self {
|
||||
let mut points = HashSet::new();
|
||||
let mut segments = HashSet::new();
|
||||
|
||||
for edge in cycle.edges() {
|
||||
let mut edge_points = Vec::new();
|
||||
edge.curve().approx(tolerance, &mut edge_points);
|
||||
|
||||
let approx = approximate_edge(edge_points, edge.vertices());
|
||||
|
||||
points.extend(approx.points);
|
||||
segments.extend(approx.segments);
|
||||
}
|
||||
|
||||
Self { points, segments }
|
||||
}
|
||||
|
||||
/// Compute an approximation for a face
|
||||
///
|
||||
/// `tolerance` defines how far the approximation is allowed to deviate from
|
||||
@ -67,7 +46,7 @@ impl Approximation {
|
||||
let mut segments = HashSet::new();
|
||||
|
||||
for cycle in face.cycles() {
|
||||
let approx = Self::for_cycle(&cycle, tolerance);
|
||||
let approx = approximate_cycle(&cycle, tolerance);
|
||||
|
||||
points.extend(approx.points);
|
||||
segments.extend(approx.segments);
|
||||
@ -118,6 +97,27 @@ fn approximate_edge(
|
||||
}
|
||||
}
|
||||
|
||||
/// Compute an approximation for a cycle
|
||||
///
|
||||
/// `tolerance` defines how far the approximation is allowed to deviate from the
|
||||
/// actual cycle.
|
||||
pub fn approximate_cycle(cycle: &Cycle, tolerance: Scalar) -> Approximation {
|
||||
let mut points = HashSet::new();
|
||||
let mut segments = HashSet::new();
|
||||
|
||||
for edge in cycle.edges() {
|
||||
let mut edge_points = Vec::new();
|
||||
edge.curve().approx(tolerance, &mut edge_points);
|
||||
|
||||
let approx = approximate_edge(edge_points, edge.vertices());
|
||||
|
||||
points.extend(approx.points);
|
||||
segments.extend(approx.segments);
|
||||
}
|
||||
|
||||
Approximation { points, segments }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use fj_math::{Point, Scalar, Segment};
|
||||
|
||||
@ -8,7 +8,7 @@ use crate::{
|
||||
topology::{Cycle, Edge, Face, Vertex},
|
||||
};
|
||||
|
||||
use super::approximation::Approximation;
|
||||
use super::approximation::approximate_cycle;
|
||||
|
||||
/// Create a new shape by sweeping an existing one
|
||||
pub fn sweep_shape(
|
||||
@ -144,8 +144,7 @@ pub fn sweep_shape(
|
||||
// This is the last piece of code that still uses the triangle
|
||||
// representation.
|
||||
|
||||
let approx =
|
||||
Approximation::for_cycle(&cycle_source.get(), tolerance);
|
||||
let approx = approximate_cycle(&cycle_source.get(), tolerance);
|
||||
|
||||
let mut quads = Vec::new();
|
||||
for segment in approx.segments {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user