fj_core/algorithms/approx/
vertex.rs

1//! Vertex approximation
2
3use std::collections::BTreeMap;
4
5use fj_math::Point;
6
7use crate::{
8    objects::Vertex,
9    storage::{Handle, HandleWrapper},
10};
11
12/// Cache for vertex approximations
13#[derive(Default)]
14pub struct VertexApproxCache {
15    inner: BTreeMap<HandleWrapper<Vertex>, Point<3>>,
16}
17
18impl VertexApproxCache {
19    /// Get an approximated vertex from the cache
20    pub fn get(&self, handle: &Handle<Vertex>) -> Option<Point<3>> {
21        self.inner.get(&handle.clone().into()).cloned()
22    }
23
24    /// Insert an approximated vertex into the cache
25    pub fn insert(
26        &mut self,
27        handle: Handle<Vertex>,
28        position: Point<3>,
29    ) -> Point<3> {
30        self.inner
31            .insert(handle.clone().into(), position)
32            .unwrap_or(position)
33    }
34}