Skip to content

Commit

Permalink
Fix GlobalVertex duplication in sweep algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Oct 19, 2022
1 parent 5d42eb7 commit ded2361
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 10 additions & 2 deletions crates/fj-kernel/src/algorithms/sweep/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<ObjectId, Handle<GlobalVertex>>,
}
14 changes: 11 additions & 3 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,22 @@ impl Sweep for Handle<GlobalVertex> {
fn sweep_with_cache(
self,
path: impl Into<Vector<3>>,
_: &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());
Expand Down

0 comments on commit ded2361

Please sign in to comment.