Skip to content

Commit

Permalink
Fix Sweep edge duplication
Browse files Browse the repository at this point in the history
Fixed cycle builder like you commented, global_edge order, and added
an edge cache.
PS: We might want to make the `SweepCache` more general
  • Loading branch information
A-Walrus committed Mar 20, 2023
1 parent 2977ab5 commit 1a6ca8f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ impl Sweep for (&HalfEdge, &Handle<Vertex>, &Surface, Option<Color>) {
[
Some(edge.global_form().clone()),
Some(edge_up),
Some(edge_down),
None,
Some(edge_down),
],
)
};
Expand Down
4 changes: 3 additions & 1 deletion crates/fj-kernel/src/algorithms/sweep/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -47,4 +47,6 @@ pub trait Sweep: Sized {
pub struct SweepCache {
/// Cache for global vertices
pub global_vertex: BTreeMap<ObjectId, Handle<Vertex>>,
/// Cache for global edges
pub global_edge: BTreeMap<ObjectId, Handle<GlobalEdge>>,
}
6 changes: 5 additions & 1 deletion crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ impl Sweep for Handle<Vertex> {
.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
Expand Down
3 changes: 2 additions & 1 deletion crates/fj-kernel/src/builder/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 1a6ca8f

Please sign in to comment.