From ded236151a4719892b8f6905db4dd2a8176e5c79 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 19 Oct 2022 14:55:38 +0200 Subject: [PATCH] Fix `GlobalVertex` duplication in sweep algorithm --- crates/fj-kernel/src/algorithms/sweep/mod.rs | 12 ++++++++++-- crates/fj-kernel/src/algorithms/sweep/vertex.rs | 14 +++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/mod.rs b/crates/fj-kernel/src/algorithms/sweep/mod.rs index e0063c36f..d7ba6fc1a 100644 --- a/crates/fj-kernel/src/algorithms/sweep/mod.rs +++ b/crates/fj-kernel/src/algorithms/sweep/mod.rs @@ -6,9 +6,14 @@ mod face; mod sketch; mod vertex; +use std::collections::BTreeMap; + use fj_math::Vector; -use crate::objects::Objects; +use crate::{ + objects::{GlobalVertex, Objects}, + storage::{Handle, ObjectId}, +}; /// Sweep an object along a path to create another object pub trait Sweep: Sized { @@ -38,4 +43,7 @@ pub trait Sweep: Sized { /// /// See [`Sweep`]. #[derive(Default)] -pub struct SweepCache; +pub struct SweepCache { + /// Cache for global vertices + pub global_vertex: BTreeMap>, +} diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 0dda7d114..24c35f3ca 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -126,14 +126,22 @@ impl Sweep for Handle { fn sweep_with_cache( self, path: impl Into>, - _: &mut SweepCache, + cache: &mut SweepCache, objects: &Objects, ) -> Self::Swept { let curve = GlobalCurve::new(objects); let a = self.clone(); - let b = - GlobalVertex::from_position(self.position() + path.into(), objects); + let b = cache + .global_vertex + .entry(self.id()) + .or_insert_with(|| { + GlobalVertex::from_position( + self.position() + path.into(), + objects, + ) + }) + .clone(); let vertices = [a, b]; let global_edge = GlobalEdge::new(curve, vertices.clone());