From 2574d0ce8f64be31dfdd7417502a0dcc19f57b88 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Sep 2022 17:02:19 +0200 Subject: [PATCH 1/8] Make `Approx` generic over cache used --- crates/fj-kernel/src/algorithms/approx/curve.rs | 6 ++++-- crates/fj-kernel/src/algorithms/approx/cycle.rs | 3 ++- crates/fj-kernel/src/algorithms/approx/edge.rs | 3 ++- crates/fj-kernel/src/algorithms/approx/face.rs | 6 ++++-- crates/fj-kernel/src/algorithms/approx/mod.rs | 7 +++++-- crates/fj-kernel/src/algorithms/approx/path.rs | 3 ++- crates/fj-kernel/src/algorithms/approx/shell.rs | 3 ++- crates/fj-kernel/src/algorithms/approx/sketch.rs | 3 ++- crates/fj-kernel/src/algorithms/approx/solid.rs | 3 ++- 9 files changed, 25 insertions(+), 12 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index 430615d09..ddd235b59 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -15,11 +15,12 @@ use super::{path::RangeOnPath, Approx, ApproxCache, ApproxPoint, Tolerance}; impl Approx for (&Curve, RangeOnPath) { type Approximation = CurveApprox; + type Cache = ApproxCache; fn approx_with_cache( self, tolerance: impl Into, - cache: &mut ApproxCache, + cache: &mut Self::Cache, ) -> Self::Approximation { let (curve, range) = self; @@ -46,11 +47,12 @@ impl Approx for (&Curve, RangeOnPath) { impl Approx for (&GlobalCurve, RangeOnPath) { type Approximation = GlobalCurveApprox; + type Cache = ApproxCache; fn approx_with_cache( self, tolerance: impl Into, - cache: &mut ApproxCache, + cache: &mut Self::Cache, ) -> Self::Approximation { let (curve, range) = self; diff --git a/crates/fj-kernel/src/algorithms/approx/cycle.rs b/crates/fj-kernel/src/algorithms/approx/cycle.rs index a93e2efe3..2164ea2df 100644 --- a/crates/fj-kernel/src/algorithms/approx/cycle.rs +++ b/crates/fj-kernel/src/algorithms/approx/cycle.rs @@ -12,11 +12,12 @@ use super::{ impl Approx for &Cycle { type Approximation = CycleApprox; + type Cache = ApproxCache; fn approx_with_cache( self, tolerance: impl Into, - cache: &mut ApproxCache, + cache: &mut Self::Cache, ) -> Self::Approximation { let tolerance = tolerance.into(); diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 8cabf2b30..8f1622ce5 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -14,11 +14,12 @@ use super::{ impl Approx for &HalfEdge { type Approximation = HalfEdgeApprox; + type Cache = ApproxCache; fn approx_with_cache( self, tolerance: impl Into, - cache: &mut ApproxCache, + cache: &mut Self::Cache, ) -> Self::Approximation { let &[a, b] = self.vertices(); let range = RangeOnPath::new([a, b].map(|vertex| vertex.position())); diff --git a/crates/fj-kernel/src/algorithms/approx/face.rs b/crates/fj-kernel/src/algorithms/approx/face.rs index 672daa0e0..43ae38716 100644 --- a/crates/fj-kernel/src/algorithms/approx/face.rs +++ b/crates/fj-kernel/src/algorithms/approx/face.rs @@ -15,11 +15,12 @@ use super::{cycle::CycleApprox, Approx, ApproxCache, ApproxPoint, Tolerance}; impl Approx for &Faces { type Approximation = BTreeSet; + type Cache = ApproxCache; fn approx_with_cache( self, tolerance: impl Into, - cache: &mut ApproxCache, + cache: &mut Self::Cache, ) -> Self::Approximation { let tolerance = tolerance.into(); @@ -66,11 +67,12 @@ impl Approx for &Faces { impl Approx for &Face { type Approximation = FaceApprox; + type Cache = ApproxCache; fn approx_with_cache( self, tolerance: impl Into, - cache: &mut ApproxCache, + cache: &mut Self::Cache, ) -> Self::Approximation { let tolerance = tolerance.into(); diff --git a/crates/fj-kernel/src/algorithms/approx/mod.rs b/crates/fj-kernel/src/algorithms/approx/mod.rs index 40b41e6e7..cfe2ba070 100644 --- a/crates/fj-kernel/src/algorithms/approx/mod.rs +++ b/crates/fj-kernel/src/algorithms/approx/mod.rs @@ -31,12 +31,15 @@ pub trait Approx: Sized { /// The approximation of the object type Approximation; + /// The cache used to cache approximation results + type Cache: Default; + /// Approximate the object /// /// `tolerance` defines how far the approximation is allowed to deviate from /// the actual object. fn approx(self, tolerance: impl Into) -> Self::Approximation { - let mut cache = ApproxCache::new(); + let mut cache = Self::Cache::default(); self.approx_with_cache(tolerance, &mut cache) } @@ -44,7 +47,7 @@ pub trait Approx: Sized { fn approx_with_cache( self, tolerance: impl Into, - cache: &mut ApproxCache, + cache: &mut Self::Cache, ) -> Self::Approximation; } diff --git a/crates/fj-kernel/src/algorithms/approx/path.rs b/crates/fj-kernel/src/algorithms/approx/path.rs index 222928d97..37e7b3abd 100644 --- a/crates/fj-kernel/src/algorithms/approx/path.rs +++ b/crates/fj-kernel/src/algorithms/approx/path.rs @@ -36,11 +36,12 @@ use super::{Approx, ApproxCache, Tolerance}; impl Approx for (GlobalPath, RangeOnPath) { type Approximation = Vec<(Point<1>, Point<3>)>; + type Cache = ApproxCache; fn approx_with_cache( self, tolerance: impl Into, - _: &mut ApproxCache, + _: &mut Self::Cache, ) -> Self::Approximation { let (path, range) = self; diff --git a/crates/fj-kernel/src/algorithms/approx/shell.rs b/crates/fj-kernel/src/algorithms/approx/shell.rs index fda8fe99e..fd2cc4b8a 100644 --- a/crates/fj-kernel/src/algorithms/approx/shell.rs +++ b/crates/fj-kernel/src/algorithms/approx/shell.rs @@ -8,11 +8,12 @@ use super::{face::FaceApprox, Approx, ApproxCache, Tolerance}; impl Approx for &Shell { type Approximation = BTreeSet; + type Cache = ApproxCache; fn approx_with_cache( self, tolerance: impl Into, - cache: &mut ApproxCache, + cache: &mut Self::Cache, ) -> Self::Approximation { self.faces().approx_with_cache(tolerance, cache) } diff --git a/crates/fj-kernel/src/algorithms/approx/sketch.rs b/crates/fj-kernel/src/algorithms/approx/sketch.rs index 4826b1eba..7047db1bb 100644 --- a/crates/fj-kernel/src/algorithms/approx/sketch.rs +++ b/crates/fj-kernel/src/algorithms/approx/sketch.rs @@ -8,11 +8,12 @@ use super::{face::FaceApprox, Approx, ApproxCache, Tolerance}; impl Approx for &Sketch { type Approximation = BTreeSet; + type Cache = ApproxCache; fn approx_with_cache( self, tolerance: impl Into, - cache: &mut ApproxCache, + cache: &mut Self::Cache, ) -> Self::Approximation { self.faces().approx_with_cache(tolerance, cache) } diff --git a/crates/fj-kernel/src/algorithms/approx/solid.rs b/crates/fj-kernel/src/algorithms/approx/solid.rs index b92ebd4cd..dced3e488 100644 --- a/crates/fj-kernel/src/algorithms/approx/solid.rs +++ b/crates/fj-kernel/src/algorithms/approx/solid.rs @@ -8,11 +8,12 @@ use super::{face::FaceApprox, Approx, ApproxCache, Tolerance}; impl Approx for &Solid { type Approximation = BTreeSet; + type Cache = ApproxCache; fn approx_with_cache( self, tolerance: impl Into, - cache: &mut ApproxCache, + cache: &mut Self::Cache, ) -> Self::Approximation { let tolerance = tolerance.into(); From 133601d438d80e56d85cefebe8a8fc5b7c5e4a2b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Sep 2022 17:03:04 +0200 Subject: [PATCH 2/8] Extend doc comment --- crates/fj-kernel/src/algorithms/approx/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/fj-kernel/src/algorithms/approx/mod.rs b/crates/fj-kernel/src/algorithms/approx/mod.rs index cfe2ba070..88f5f1de0 100644 --- a/crates/fj-kernel/src/algorithms/approx/mod.rs +++ b/crates/fj-kernel/src/algorithms/approx/mod.rs @@ -44,6 +44,9 @@ pub trait Approx: Sized { } /// Approximate the object, using the provided cache + /// + /// This is a lower-level method that allows some degree of control over + /// caching. Callers might consider using [`Approx::approx`] instead. fn approx_with_cache( self, tolerance: impl Into, From 44dff9065127b872a67b49f0284d38c996368479 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Sep 2022 17:06:32 +0200 Subject: [PATCH 3/8] Don't accept approx cache where it isn't used --- crates/fj-kernel/src/algorithms/approx/curve.rs | 4 ++-- crates/fj-kernel/src/algorithms/approx/path.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index ddd235b59..612da5303 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -29,7 +29,7 @@ impl Approx for (&Curve, RangeOnPath) { Some(approx) => approx, None => { let approx = (curve.global_form(), range) - .approx_with_cache(tolerance, cache); + .approx_with_cache(tolerance, &mut ()); cache.insert_global_curve(cache_key, approx) } }; @@ -47,7 +47,7 @@ impl Approx for (&Curve, RangeOnPath) { impl Approx for (&GlobalCurve, RangeOnPath) { type Approximation = GlobalCurveApprox; - type Cache = ApproxCache; + type Cache = (); fn approx_with_cache( self, diff --git a/crates/fj-kernel/src/algorithms/approx/path.rs b/crates/fj-kernel/src/algorithms/approx/path.rs index 37e7b3abd..db2191364 100644 --- a/crates/fj-kernel/src/algorithms/approx/path.rs +++ b/crates/fj-kernel/src/algorithms/approx/path.rs @@ -32,16 +32,16 @@ use fj_math::{Circle, Point, Scalar}; use crate::path::GlobalPath; -use super::{Approx, ApproxCache, Tolerance}; +use super::{Approx, Tolerance}; impl Approx for (GlobalPath, RangeOnPath) { type Approximation = Vec<(Point<1>, Point<3>)>; - type Cache = ApproxCache; + type Cache = (); fn approx_with_cache( self, tolerance: impl Into, - _: &mut Self::Cache, + (): &mut Self::Cache, ) -> Self::Approximation { let (path, range) = self; From db3f8ccb6b1261ddacef089207fc98718caae2d5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Sep 2022 17:08:36 +0200 Subject: [PATCH 4/8] Move `ApproxCache` to where it is used --- .../fj-kernel/src/algorithms/approx/curve.rs | 35 ++++++++++++++++++- .../fj-kernel/src/algorithms/approx/cycle.rs | 2 +- .../fj-kernel/src/algorithms/approx/edge.rs | 5 +-- .../fj-kernel/src/algorithms/approx/face.rs | 4 ++- crates/fj-kernel/src/algorithms/approx/mod.rs | 35 +------------------ .../fj-kernel/src/algorithms/approx/shell.rs | 2 +- .../fj-kernel/src/algorithms/approx/sketch.rs | 2 +- .../fj-kernel/src/algorithms/approx/solid.rs | 2 +- 8 files changed, 45 insertions(+), 42 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index 612da5303..ccef35b5b 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -9,9 +9,11 @@ //! done, to give the caller (who knows the boundary anyway) more options on how //! to further process the approximation. +use std::collections::BTreeMap; + use crate::objects::{Curve, GlobalCurve}; -use super::{path::RangeOnPath, Approx, ApproxCache, ApproxPoint, Tolerance}; +use super::{path::RangeOnPath, Approx, ApproxPoint, Tolerance}; impl Approx for (&Curve, RangeOnPath) { type Approximation = CurveApprox; @@ -91,6 +93,37 @@ impl CurveApprox { } } +/// A cache for results of an approximation +#[derive(Default)] +pub struct ApproxCache { + global_curve: BTreeMap<(GlobalCurve, RangeOnPath), GlobalCurveApprox>, +} + +impl ApproxCache { + /// Create an empty cache + pub fn new() -> Self { + Self::default() + } + + /// Insert the approximation of a [`GlobalCurve`] + pub fn insert_global_curve( + &mut self, + key: (GlobalCurve, RangeOnPath), + approx: GlobalCurveApprox, + ) -> GlobalCurveApprox { + self.global_curve.insert(key, approx.clone()); + approx + } + + /// Access the approximation for the given [`GlobalCurve`], if available + pub fn global_curve( + &self, + key: (GlobalCurve, RangeOnPath), + ) -> Option { + self.global_curve.get(&key).cloned() + } +} + /// An approximation of a [`GlobalCurve`] #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct GlobalCurveApprox { diff --git a/crates/fj-kernel/src/algorithms/approx/cycle.rs b/crates/fj-kernel/src/algorithms/approx/cycle.rs index 2164ea2df..cfb53ebe9 100644 --- a/crates/fj-kernel/src/algorithms/approx/cycle.rs +++ b/crates/fj-kernel/src/algorithms/approx/cycle.rs @@ -7,7 +7,7 @@ use fj_math::Segment; use crate::objects::Cycle; use super::{ - edge::HalfEdgeApprox, Approx, ApproxCache, ApproxPoint, Tolerance, + curve::ApproxCache, edge::HalfEdgeApprox, Approx, ApproxPoint, Tolerance, }; impl Approx for &Cycle { diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 8f1622ce5..34d785877 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -8,8 +8,9 @@ use crate::objects::HalfEdge; use super::{ - curve::CurveApprox, path::RangeOnPath, Approx, ApproxCache, ApproxPoint, - Tolerance, + curve::{ApproxCache, CurveApprox}, + path::RangeOnPath, + Approx, ApproxPoint, Tolerance, }; impl Approx for &HalfEdge { diff --git a/crates/fj-kernel/src/algorithms/approx/face.rs b/crates/fj-kernel/src/algorithms/approx/face.rs index 43ae38716..f18b91fdb 100644 --- a/crates/fj-kernel/src/algorithms/approx/face.rs +++ b/crates/fj-kernel/src/algorithms/approx/face.rs @@ -11,7 +11,9 @@ use crate::{ objects::{Face, Faces, Handedness}, }; -use super::{cycle::CycleApprox, Approx, ApproxCache, ApproxPoint, Tolerance}; +use super::{ + curve::ApproxCache, cycle::CycleApprox, Approx, ApproxPoint, Tolerance, +}; impl Approx for &Faces { type Approximation = BTreeSet; diff --git a/crates/fj-kernel/src/algorithms/approx/mod.rs b/crates/fj-kernel/src/algorithms/approx/mod.rs index 88f5f1de0..45721d18d 100644 --- a/crates/fj-kernel/src/algorithms/approx/mod.rs +++ b/crates/fj-kernel/src/algorithms/approx/mod.rs @@ -13,7 +13,6 @@ pub mod tolerance; use std::{ any::Any, cmp::Ordering, - collections::BTreeMap, fmt::Debug, hash::{Hash, Hasher}, rc::Rc, @@ -21,10 +20,9 @@ use std::{ use fj_math::Point; -use crate::objects::{Curve, GlobalCurve}; +use crate::objects::Curve; pub use self::tolerance::{InvalidTolerance, Tolerance}; -use self::{curve::GlobalCurveApprox, path::RangeOnPath}; /// Approximate an object pub trait Approx: Sized { @@ -54,37 +52,6 @@ pub trait Approx: Sized { ) -> Self::Approximation; } -/// A cache for results of an approximation -#[derive(Default)] -pub struct ApproxCache { - global_curve: BTreeMap<(GlobalCurve, RangeOnPath), GlobalCurveApprox>, -} - -impl ApproxCache { - /// Create an empty cache - pub fn new() -> Self { - Self::default() - } - - /// Insert the approximation of a [`GlobalCurve`] - pub fn insert_global_curve( - &mut self, - key: (GlobalCurve, RangeOnPath), - approx: GlobalCurveApprox, - ) -> GlobalCurveApprox { - self.global_curve.insert(key, approx.clone()); - approx - } - - /// Access the approximation for the given [`GlobalCurve`], if available - pub fn global_curve( - &self, - key: (GlobalCurve, RangeOnPath), - ) -> Option { - self.global_curve.get(&key).cloned() - } -} - /// A point from an approximation, with local and global forms #[derive(Debug, Clone)] pub struct ApproxPoint { diff --git a/crates/fj-kernel/src/algorithms/approx/shell.rs b/crates/fj-kernel/src/algorithms/approx/shell.rs index fd2cc4b8a..3e2d849b4 100644 --- a/crates/fj-kernel/src/algorithms/approx/shell.rs +++ b/crates/fj-kernel/src/algorithms/approx/shell.rs @@ -4,7 +4,7 @@ use std::collections::BTreeSet; use crate::objects::Shell; -use super::{face::FaceApprox, Approx, ApproxCache, Tolerance}; +use super::{curve::ApproxCache, face::FaceApprox, Approx, Tolerance}; impl Approx for &Shell { type Approximation = BTreeSet; diff --git a/crates/fj-kernel/src/algorithms/approx/sketch.rs b/crates/fj-kernel/src/algorithms/approx/sketch.rs index 7047db1bb..04959c7e1 100644 --- a/crates/fj-kernel/src/algorithms/approx/sketch.rs +++ b/crates/fj-kernel/src/algorithms/approx/sketch.rs @@ -4,7 +4,7 @@ use std::collections::BTreeSet; use crate::objects::Sketch; -use super::{face::FaceApprox, Approx, ApproxCache, Tolerance}; +use super::{curve::ApproxCache, face::FaceApprox, Approx, Tolerance}; impl Approx for &Sketch { type Approximation = BTreeSet; diff --git a/crates/fj-kernel/src/algorithms/approx/solid.rs b/crates/fj-kernel/src/algorithms/approx/solid.rs index dced3e488..4109c0f2f 100644 --- a/crates/fj-kernel/src/algorithms/approx/solid.rs +++ b/crates/fj-kernel/src/algorithms/approx/solid.rs @@ -4,7 +4,7 @@ use std::collections::BTreeSet; use crate::objects::Solid; -use super::{face::FaceApprox, Approx, ApproxCache, Tolerance}; +use super::{curve::ApproxCache, face::FaceApprox, Approx, Tolerance}; impl Approx for &Solid { type Approximation = BTreeSet; From 31b44de631c283eec75f2d91006081656bcf3fd9 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Sep 2022 17:09:19 +0200 Subject: [PATCH 5/8] Rename `ApproxCache` The new name is more specific. --- crates/fj-kernel/src/algorithms/approx/curve.rs | 6 +++--- crates/fj-kernel/src/algorithms/approx/cycle.rs | 4 ++-- crates/fj-kernel/src/algorithms/approx/edge.rs | 4 ++-- crates/fj-kernel/src/algorithms/approx/face.rs | 6 +++--- crates/fj-kernel/src/algorithms/approx/shell.rs | 4 ++-- crates/fj-kernel/src/algorithms/approx/sketch.rs | 4 ++-- crates/fj-kernel/src/algorithms/approx/solid.rs | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index ccef35b5b..8b380861d 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -17,7 +17,7 @@ use super::{path::RangeOnPath, Approx, ApproxPoint, Tolerance}; impl Approx for (&Curve, RangeOnPath) { type Approximation = CurveApprox; - type Cache = ApproxCache; + type Cache = CurveCache; fn approx_with_cache( self, @@ -95,11 +95,11 @@ impl CurveApprox { /// A cache for results of an approximation #[derive(Default)] -pub struct ApproxCache { +pub struct CurveCache { global_curve: BTreeMap<(GlobalCurve, RangeOnPath), GlobalCurveApprox>, } -impl ApproxCache { +impl CurveCache { /// Create an empty cache pub fn new() -> Self { Self::default() diff --git a/crates/fj-kernel/src/algorithms/approx/cycle.rs b/crates/fj-kernel/src/algorithms/approx/cycle.rs index cfb53ebe9..9d398f2bc 100644 --- a/crates/fj-kernel/src/algorithms/approx/cycle.rs +++ b/crates/fj-kernel/src/algorithms/approx/cycle.rs @@ -7,12 +7,12 @@ use fj_math::Segment; use crate::objects::Cycle; use super::{ - curve::ApproxCache, edge::HalfEdgeApprox, Approx, ApproxPoint, Tolerance, + curve::CurveCache, edge::HalfEdgeApprox, Approx, ApproxPoint, Tolerance, }; impl Approx for &Cycle { type Approximation = CycleApprox; - type Cache = ApproxCache; + type Cache = CurveCache; fn approx_with_cache( self, diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 34d785877..63bbca52e 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -8,14 +8,14 @@ use crate::objects::HalfEdge; use super::{ - curve::{ApproxCache, CurveApprox}, + curve::{CurveApprox, CurveCache}, path::RangeOnPath, Approx, ApproxPoint, Tolerance, }; impl Approx for &HalfEdge { type Approximation = HalfEdgeApprox; - type Cache = ApproxCache; + type Cache = CurveCache; fn approx_with_cache( self, diff --git a/crates/fj-kernel/src/algorithms/approx/face.rs b/crates/fj-kernel/src/algorithms/approx/face.rs index f18b91fdb..90981c860 100644 --- a/crates/fj-kernel/src/algorithms/approx/face.rs +++ b/crates/fj-kernel/src/algorithms/approx/face.rs @@ -12,12 +12,12 @@ use crate::{ }; use super::{ - curve::ApproxCache, cycle::CycleApprox, Approx, ApproxPoint, Tolerance, + curve::CurveCache, cycle::CycleApprox, Approx, ApproxPoint, Tolerance, }; impl Approx for &Faces { type Approximation = BTreeSet; - type Cache = ApproxCache; + type Cache = CurveCache; fn approx_with_cache( self, @@ -69,7 +69,7 @@ impl Approx for &Faces { impl Approx for &Face { type Approximation = FaceApprox; - type Cache = ApproxCache; + type Cache = CurveCache; fn approx_with_cache( self, diff --git a/crates/fj-kernel/src/algorithms/approx/shell.rs b/crates/fj-kernel/src/algorithms/approx/shell.rs index 3e2d849b4..f3262c1d2 100644 --- a/crates/fj-kernel/src/algorithms/approx/shell.rs +++ b/crates/fj-kernel/src/algorithms/approx/shell.rs @@ -4,11 +4,11 @@ use std::collections::BTreeSet; use crate::objects::Shell; -use super::{curve::ApproxCache, face::FaceApprox, Approx, Tolerance}; +use super::{curve::CurveCache, face::FaceApprox, Approx, Tolerance}; impl Approx for &Shell { type Approximation = BTreeSet; - type Cache = ApproxCache; + type Cache = CurveCache; fn approx_with_cache( self, diff --git a/crates/fj-kernel/src/algorithms/approx/sketch.rs b/crates/fj-kernel/src/algorithms/approx/sketch.rs index 04959c7e1..4cf8e89df 100644 --- a/crates/fj-kernel/src/algorithms/approx/sketch.rs +++ b/crates/fj-kernel/src/algorithms/approx/sketch.rs @@ -4,11 +4,11 @@ use std::collections::BTreeSet; use crate::objects::Sketch; -use super::{curve::ApproxCache, face::FaceApprox, Approx, Tolerance}; +use super::{curve::CurveCache, face::FaceApprox, Approx, Tolerance}; impl Approx for &Sketch { type Approximation = BTreeSet; - type Cache = ApproxCache; + type Cache = CurveCache; fn approx_with_cache( self, diff --git a/crates/fj-kernel/src/algorithms/approx/solid.rs b/crates/fj-kernel/src/algorithms/approx/solid.rs index 4109c0f2f..2077c5666 100644 --- a/crates/fj-kernel/src/algorithms/approx/solid.rs +++ b/crates/fj-kernel/src/algorithms/approx/solid.rs @@ -4,11 +4,11 @@ use std::collections::BTreeSet; use crate::objects::Solid; -use super::{curve::ApproxCache, face::FaceApprox, Approx, Tolerance}; +use super::{curve::CurveCache, face::FaceApprox, Approx, Tolerance}; impl Approx for &Solid { type Approximation = BTreeSet; - type Cache = ApproxCache; + type Cache = CurveCache; fn approx_with_cache( self, From 1560bdcbe0b0f550cb4fde2f70030b3736571c3f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Sep 2022 17:09:56 +0200 Subject: [PATCH 6/8] Simplify struct field name --- crates/fj-kernel/src/algorithms/approx/curve.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index 8b380861d..f47741583 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -96,7 +96,7 @@ impl CurveApprox { /// A cache for results of an approximation #[derive(Default)] pub struct CurveCache { - global_curve: BTreeMap<(GlobalCurve, RangeOnPath), GlobalCurveApprox>, + inner: BTreeMap<(GlobalCurve, RangeOnPath), GlobalCurveApprox>, } impl CurveCache { @@ -111,7 +111,7 @@ impl CurveCache { key: (GlobalCurve, RangeOnPath), approx: GlobalCurveApprox, ) -> GlobalCurveApprox { - self.global_curve.insert(key, approx.clone()); + self.inner.insert(key, approx.clone()); approx } @@ -120,7 +120,7 @@ impl CurveCache { &self, key: (GlobalCurve, RangeOnPath), ) -> Option { - self.global_curve.get(&key).cloned() + self.inner.get(&key).cloned() } } From ac0004256eb7fc0f9aaee4f7bdebd15fbd8878bc Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Sep 2022 17:10:15 +0200 Subject: [PATCH 7/8] Simplify method name --- crates/fj-kernel/src/algorithms/approx/curve.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index f47741583..1a04ccbdb 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -32,7 +32,7 @@ impl Approx for (&Curve, RangeOnPath) { None => { let approx = (curve.global_form(), range) .approx_with_cache(tolerance, &mut ()); - cache.insert_global_curve(cache_key, approx) + cache.insert(cache_key, approx) } }; @@ -106,7 +106,7 @@ impl CurveCache { } /// Insert the approximation of a [`GlobalCurve`] - pub fn insert_global_curve( + pub fn insert( &mut self, key: (GlobalCurve, RangeOnPath), approx: GlobalCurveApprox, From dc5d7b3fe93eadf6da18955409de209810a0cacc Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Sep 2022 17:10:39 +0200 Subject: [PATCH 8/8] Simplify method name --- crates/fj-kernel/src/algorithms/approx/curve.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index 1a04ccbdb..775d02d42 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -27,7 +27,7 @@ impl Approx for (&Curve, RangeOnPath) { let (curve, range) = self; let cache_key = (*curve.global_form(), range); - let global_curve_approx = match cache.global_curve(cache_key) { + let global_curve_approx = match cache.get(cache_key) { Some(approx) => approx, None => { let approx = (curve.global_form(), range) @@ -116,7 +116,7 @@ impl CurveCache { } /// Access the approximation for the given [`GlobalCurve`], if available - pub fn global_curve( + pub fn get( &self, key: (GlobalCurve, RangeOnPath), ) -> Option {