diff --git a/experiments/2024-12-09/src/model.rs b/experiments/2024-12-09/src/model.rs index fcdceedf2..386ad7093 100644 --- a/experiments/2024-12-09/src/model.rs +++ b/experiments/2024-12-09/src/model.rs @@ -3,24 +3,21 @@ use itertools::Itertools; use crate::{ geometry::{Shape, Sketch, Triangle}, math::{Bivector, Plane, Point, Vector}, - storage::Store, - topology::{Face, Vertex}, + storage::Stores, + topology::Face, }; pub fn model(shape: &mut Shape) { - let mut faces = Store::::new(); - let mut surfaces = Store::::new(); - let mut vertices = Store::::new(); - let mut triangles = Store::::new(); + let mut stores = Stores::new(); - let bottom = surfaces.insert(Plane { + let bottom = stores.get().insert(Plane { origin: Point::from([0., 0., -0.5]), coords: Bivector { a: Vector::from([1., 0., 0.]), b: Vector::from([0., -1., 0.]), }, }); - let top = surfaces.insert(Plane { + let top = stores.get().insert(Plane { origin: Point::from([0., 0., 0.5]), coords: Bivector { a: Vector::from([1., 0., 0.]), @@ -32,10 +29,10 @@ pub fn model(shape: &mut Shape) { Sketch::from([[-0.5, -0.5], [0.5, -0.5], [0.5, 0.5], [-0.5, 0.5]]); let [bottom, top] = - [bottom, top].map(|plane| Face::new(&sketch, plane, &mut vertices)); + [bottom, top].map(|plane| Face::new(&sketch, plane, stores.get())); let (bottom, top) = shape - .extend_with(&mut faces) + .extend_with(stores.get::()) .add(bottom) .add(top) .get_added(); @@ -47,7 +44,7 @@ pub fn model(shape: &mut Shape) { [a, b, c, d, e, f, g, h].map(|vertex| vertex.point); shape - .extend_with(&mut triangles) + .extend_with(stores.get::()) .add([d, e, h]) // left .add([d, h, a]) .add([c, b, g]) // right diff --git a/experiments/2024-12-09/src/storage.rs b/experiments/2024-12-09/src/storage.rs index f262b2d30..44b86e6d3 100644 --- a/experiments/2024-12-09/src/storage.rs +++ b/experiments/2024-12-09/src/storage.rs @@ -1,7 +1,24 @@ use std::marker::PhantomData; +use anymap3::AnyMap; + use crate::geometry::Handle; +#[derive(Default)] +pub struct Stores { + inner: AnyMap, +} + +impl Stores { + pub fn new() -> Self { + Self::default() + } + + pub fn get(&mut self) -> &mut Store { + self.inner.entry::>().or_default() + } +} + pub struct Store { _t: PhantomData, }