Merge pull request #2273 from hannobraun/geometry

Make minor cleanups in approximation code
This commit is contained in:
Hanno Braun 2024-03-18 14:20:15 +01:00 committed by GitHub
commit 192ca743f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 18 deletions

View File

@ -29,8 +29,8 @@ impl Approx for (&Cycle, &SurfaceGeometry) {
let half_edges = cycle let half_edges = cycle
.half_edges() .half_edges()
.iter() .iter()
.map(|edge| { .map(|half_edge| {
(edge.deref(), surface) (half_edge.deref(), surface)
.approx_with_cache(tolerance, cache, core) .approx_with_cache(tolerance, cache, core)
}) })
.collect(); .collect();

View File

@ -22,31 +22,41 @@ impl Approx for (&HalfEdge, &SurfaceGeometry) {
cache: &mut Self::Cache, cache: &mut Self::Cache,
core: &mut Core, core: &mut Core,
) -> Self::Approximation { ) -> Self::Approximation {
let (edge, surface) = self; let (half_edge, surface) = self;
let tolerance = tolerance.into(); let tolerance = tolerance.into();
let start_position_surface = edge.start_position(); let start_position_surface = half_edge.start_position();
let start_position = match cache.start_position.get(edge.start_vertex()) let start_position =
{ match cache.start_position.get(half_edge.start_vertex()) {
Some(position) => position, Some(position) => position,
None => { None => {
let position_global = let position_global = surface
surface.point_from_surface_coords(start_position_surface); .point_from_surface_coords(start_position_surface);
cache cache.start_position.insert(
.start_position half_edge.start_vertex().clone(),
.insert(edge.start_vertex().clone(), position_global) position_global,
)
} }
}; };
let first = ApproxPoint::new(start_position_surface, start_position); let first = ApproxPoint::new(start_position_surface, start_position);
let rest = { let rest = {
let approx = (edge.curve(), edge.path(), surface, edge.boundary()) let approx = (
.approx_with_cache(tolerance, &mut cache.curve, core); half_edge.curve(),
half_edge.path(),
surface,
half_edge.boundary(),
)
.approx_with_cache(
tolerance,
&mut cache.curve,
core,
);
approx.points.into_iter().map(|point| { approx.points.into_iter().map(|point| {
let point_surface = let point_surface =
edge.path().point_from_path_coords(point.local_form); half_edge.path().point_from_path_coords(point.local_form);
ApproxPoint::new(point_surface, point.global_form) ApproxPoint::new(point_surface, point.global_form)
}) })