From 1a6ca8f751c4c6bc1f5de4edb77eb2a405f656e0 Mon Sep 17 00:00:00 2001 From: A-Walrus Date: Mon, 20 Mar 2023 16:24:10 +0200 Subject: [PATCH] Fix Sweep edge duplication Fixed cycle builder like you commented, global_edge order, and added an edge cache. PS: We might want to make the `SweepCache` more general --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 2 +- crates/fj-kernel/src/algorithms/sweep/mod.rs | 4 +++- crates/fj-kernel/src/algorithms/sweep/vertex.rs | 6 +++++- crates/fj-kernel/src/builder/cycle.rs | 3 ++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index dfe033f8dc..e52bd5db5f 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -37,8 +37,8 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { [ Some(edge.global_form().clone()), Some(edge_up), - Some(edge_down), None, + Some(edge_down), ], ) }; diff --git a/crates/fj-kernel/src/algorithms/sweep/mod.rs b/crates/fj-kernel/src/algorithms/sweep/mod.rs index e2e98704ab..6cdc144308 100644 --- a/crates/fj-kernel/src/algorithms/sweep/mod.rs +++ b/crates/fj-kernel/src/algorithms/sweep/mod.rs @@ -11,7 +11,7 @@ use std::collections::BTreeMap; use fj_math::Vector; use crate::{ - objects::{Objects, Vertex}, + objects::{GlobalEdge, Objects, Vertex}, services::Service, storage::{Handle, ObjectId}, }; @@ -47,4 +47,6 @@ pub trait Sweep: Sized { pub struct SweepCache { /// Cache for global vertices pub global_vertex: BTreeMap>, + /// Cache for global edges + pub global_edge: BTreeMap>, } diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 868f8e9ef7..d2f86193c2 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -26,7 +26,11 @@ impl Sweep for Handle { .clone(); let vertices = [a, b]; - let global_edge = GlobalEdge::new().insert(objects); + let global_edge = cache + .global_edge + .entry(self.id()) + .or_insert_with(|| GlobalEdge::new().insert(objects)) + .clone(); // The vertices of the returned `GlobalEdge` are in normalized order, // which means the order can't be relied upon by the caller. Return the diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 2f5a8cbb17..92fc63cd89 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -44,9 +44,10 @@ impl CycleBuilder { let half_edges = edges .into_iter() .circular_tuple_windows() - .map(|((prev, _, _), (_, curve, boundary))| { + .map(|((prev, _, _), (half_edge, curve, boundary))| { HalfEdgeBuilder::new(curve, boundary) .with_start_vertex(prev.start_vertex().clone()) + .with_global_form(half_edge.global_form().clone()) }) .collect();