From f29ad93399ac18cc63b4b7886f20c7589289d948 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 22 Feb 2023 11:52:04 +0100 Subject: [PATCH] Inline `Curve` approximation --- .../fj-kernel/src/algorithms/approx/curve.rs | 32 -------------- .../fj-kernel/src/algorithms/approx/edge.rs | 43 ++++++++++++++++--- 2 files changed, 36 insertions(+), 39 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index f367a1f14..8e057247d 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -19,38 +19,6 @@ use crate::{ use super::{path::RangeOnPath, Approx, ApproxPoint, Tolerance}; -impl Approx for (&Handle, &Surface, Handle, RangeOnPath) { - type Approximation = CurveApprox; - type Cache = CurveCache; - - fn approx_with_cache( - self, - tolerance: impl Into, - cache: &mut Self::Cache, - ) -> Self::Approximation { - let (curve, surface, global_curve, range) = self; - - let global_curve_approx = match cache.get(global_curve.clone(), range) { - Some(approx) => approx, - None => { - let approx = - approx_global_curve(curve, surface, range, tolerance); - cache.insert(global_curve, range, approx) - } - }; - - CurveApprox::empty().with_points( - global_curve_approx.points.into_iter().map(|point| { - let point_surface = - curve.path().point_from_path_coords(point.local_form); - - ApproxPoint::new(point_surface, point.global_form) - .with_source((curve.clone(), point.local_form)) - }), - ) - } -} - pub(super) fn approx_global_curve( curve: &Curve, surface: &Surface, diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 10a047db2..b51b91ae6 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -35,13 +35,42 @@ impl Approx for (&Handle, &Surface) { half_edge.start_vertex().global_form().position(), ) .with_source((half_edge.clone(), half_edge.boundary()[0])); - let curve_approx = ( - half_edge.curve(), - surface, - half_edge.global_form().curve().clone(), - range, - ) - .approx_with_cache(tolerance, cache); + + let curve_approx = { + let global_curve_approx = match cache + .get(half_edge.global_form().curve().clone().clone(), range) + { + Some(approx) => approx, + None => { + let approx = super::curve::approx_global_curve( + half_edge.curve(), + surface, + range, + tolerance, + ); + cache.insert( + half_edge.global_form().curve().clone(), + range, + approx, + ) + } + }; + + CurveApprox::empty().with_points( + global_curve_approx.points.into_iter().map(|point| { + let point_surface = half_edge + .curve() + .path() + .point_from_path_coords(point.local_form); + + ApproxPoint::new(point_surface, point.global_form) + .with_source(( + half_edge.curve().clone(), + point.local_form, + )) + }), + ) + }; HalfEdgeApprox { first,