fj_kernel/algorithms/sweep/
mod.rs

1//! Sweeping objects along a path to create new objects
2
3mod curve;
4mod edge;
5mod face;
6mod sketch;
7mod vertex;
8
9use std::collections::BTreeMap;
10
11use fj_math::Vector;
12
13use crate::{
14    objects::{GlobalEdge, Vertex},
15    services::Services,
16    storage::{Handle, ObjectId},
17};
18
19/// Sweep an object along a path to create another object
20pub trait Sweep: Sized {
21    /// The object that is created by sweeping the implementing object
22    type Swept;
23
24    /// Sweep the object along the given path
25    fn sweep(
26        self,
27        path: impl Into<Vector<3>>,
28        services: &mut Services,
29    ) -> Self::Swept {
30        let mut cache = SweepCache::default();
31        self.sweep_with_cache(path, &mut cache, services)
32    }
33
34    /// Sweep the object along the given path, using the provided cache
35    fn sweep_with_cache(
36        self,
37        path: impl Into<Vector<3>>,
38        cache: &mut SweepCache,
39        services: &mut Services,
40    ) -> Self::Swept;
41}
42
43/// A cache used for sweeping
44///
45/// See [`Sweep`].
46#[derive(Default)]
47pub struct SweepCache {
48    /// Cache for global vertices
49    pub global_vertex: BTreeMap<ObjectId, Handle<Vertex>>,
50    /// Cache for global edges
51    pub global_edge: BTreeMap<ObjectId, Handle<GlobalEdge>>,
52}