Inline Curve approximation

This commit is contained in:
Hanno Braun 2023-02-22 11:52:04 +01:00
parent 7c38fc2023
commit f29ad93399
2 changed files with 36 additions and 39 deletions

View File

@ -19,38 +19,6 @@ use crate::{
use super::{path::RangeOnPath, Approx, ApproxPoint, Tolerance};
impl Approx for (&Handle<Curve>, &Surface, Handle<GlobalCurve>, RangeOnPath) {
type Approximation = CurveApprox;
type Cache = CurveCache;
fn approx_with_cache(
self,
tolerance: impl Into<Tolerance>,
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,

View File

@ -35,13 +35,42 @@ impl Approx for (&Handle<HalfEdge>, &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,