From 9ac29b061391624517a6d5b1759aa770cea17863 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 22 Feb 2023 12:14:49 +0100 Subject: [PATCH] Merge `CurveApprox` into `HalfEdgeApprox` --- .../fj-kernel/src/algorithms/approx/curve.rs | 23 ------------- .../fj-kernel/src/algorithms/approx/edge.rs | 32 ++++++++----------- 2 files changed, 13 insertions(+), 42 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index 5fcdb2933..1bf0bb0db 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -18,29 +18,6 @@ use crate::{ use super::{path::RangeOnPath, ApproxPoint}; -/// An approximation of a [`Curve`] -#[derive(Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] -pub struct CurveApprox { - /// The points that approximate the curve - pub points: Vec>, -} - -impl CurveApprox { - /// Create an empty instance of `CurveApprox` - pub fn empty() -> Self { - Self { points: Vec::new() } - } - - /// Add points to the approximation - pub fn with_points( - mut self, - points: impl IntoIterator>, - ) -> Self { - self.points.extend(points); - self - } -} - /// A cache for results of an approximation #[derive(Default)] pub struct CurveCache { diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 68ce4f163..bc0eb1757 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -12,7 +12,7 @@ use crate::{ }; use super::{ - curve::{CurveApprox, CurveCache, GlobalCurveApprox}, + curve::{CurveCache, GlobalCurveApprox}, path::RangeOnPath, Approx, ApproxPoint, Tolerance, }; @@ -57,8 +57,10 @@ impl Approx for (&Handle, &Surface) { } }; - CurveApprox::empty().with_points( - global_curve_approx.points.into_iter().map(|point| { + global_curve_approx + .points + .into_iter() + .map(|point| { let point_surface = half_edge .curve() .path() @@ -69,8 +71,8 @@ impl Approx for (&Handle, &Surface) { half_edge.curve().clone(), point.local_form, )) - }), - ) + }) + .collect() }; HalfEdgeApprox { @@ -87,7 +89,7 @@ pub struct HalfEdgeApprox { pub first: ApproxPoint<2>, /// The approximation of the edge's curve - pub curve_approx: CurveApprox, + pub curve_approx: Vec>, } impl HalfEdgeApprox { @@ -96,7 +98,7 @@ impl HalfEdgeApprox { let mut points = Vec::new(); points.push(self.first.clone()); - points.extend(self.curve_approx.points.clone()); + points.extend(self.curve_approx.clone()); points } @@ -193,8 +195,6 @@ mod tests { services::Services, }; - use super::CurveApprox; - #[test] fn approx_line_on_flat_surface() { let mut services = Services::new(); @@ -214,7 +214,7 @@ mod tests { let tolerance = 1.; let approx = (&half_edge, surface.deref()).approx(tolerance); - assert_eq!(approx.curve_approx, CurveApprox::empty()); + assert_eq!(approx.curve_approx, Vec::new()); } #[test] @@ -241,7 +241,7 @@ mod tests { let tolerance = 1.; let approx = (&half_edge, surface.deref()).approx(tolerance); - assert_eq!(approx.curve_approx, CurveApprox::empty()); + assert_eq!(approx.curve_approx, Vec::new()); } #[test] @@ -285,10 +285,7 @@ mod tests { ApproxPoint::new(point_surface, point_global) }) .collect::>(); - assert_eq!( - approx.curve_approx, - CurveApprox::empty().with_points(expected_approx) - ); + assert_eq!(approx.curve_approx, expected_approx); } #[test] @@ -321,9 +318,6 @@ mod tests { ApproxPoint::new(point_surface, point_global) }) .collect::>(); - assert_eq!( - approx.curve_approx, - CurveApprox::empty().with_points(expected_approx) - ); + assert_eq!(approx.curve_approx, expected_approx); } }