-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2008 from hannobraun/approx
Prepare for more sophisticated curve approximation caching
- Loading branch information
Showing
3 changed files
with
65 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
//! Curve approximation | ||
|
||
mod cache; | ||
mod segment; | ||
|
||
pub use self::segment::CurveApproxSegment; | ||
pub use self::{cache::CurveApproxCache, segment::CurveApproxSegment}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::collections::BTreeMap; | ||
|
||
use fj_math::Point; | ||
|
||
use crate::{ | ||
geometry::CurveBoundary, | ||
objects::Curve, | ||
storage::{Handle, HandleWrapper}, | ||
}; | ||
|
||
use super::CurveApproxSegment; | ||
|
||
/// Cache for curve approximations | ||
#[derive(Default)] | ||
pub struct CurveApproxCache { | ||
inner: BTreeMap< | ||
(HandleWrapper<Curve>, CurveBoundary<Point<1>>), | ||
CurveApproxSegment, | ||
>, | ||
} | ||
|
||
impl CurveApproxCache { | ||
/// Get an approximation from the cache | ||
pub fn get( | ||
&self, | ||
curve: &Handle<Curve>, | ||
boundary: &CurveBoundary<Point<1>>, | ||
) -> Option<CurveApproxSegment> { | ||
if let Some(approx) = self.inner.get(&(curve.clone().into(), *boundary)) | ||
{ | ||
return Some(approx.clone()); | ||
} | ||
if let Some(approx) = | ||
self.inner.get(&(curve.clone().into(), boundary.reverse())) | ||
{ | ||
// If we have a cache entry for the reverse boundary, we need to use | ||
// that too! | ||
return Some(approx.clone().reverse()); | ||
} | ||
|
||
None | ||
} | ||
|
||
/// Insert an approximated segment of the curve into the cache | ||
pub fn insert( | ||
&mut self, | ||
curve: Handle<Curve>, | ||
new_segment: CurveApproxSegment, | ||
) -> Option<CurveApproxSegment> { | ||
self.inner | ||
.insert((curve.into(), new_segment.boundary), new_segment) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters