mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-15 11:45:54 +00:00
Inline Curve
approximation
This commit is contained in:
parent
7c38fc2023
commit
f29ad93399
@ -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,
|
||||
|
@ -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 = (
|
||||
|
||||
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,
|
||||
)
|
||||
.approx_with_cache(tolerance, cache);
|
||||
}
|
||||
};
|
||||
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user