mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-13 10:45:51 +00:00
Replace AnyMap
in Stores
Using this approach, accessing a store required borrowing all of `Stores`. This caused problems, as multiple stores couldn't get bored separately. Or when using iterators and closures.
This commit is contained in:
parent
1fa9e15acd
commit
3e1afe5f88
@ -14,7 +14,7 @@ pub fn model() -> AnyOp {
|
||||
let sketch =
|
||||
Sketch::from([[-0.5, -0.5], [0.5, -0.5], [0.5, 0.5], [-0.5, 0.5]]);
|
||||
|
||||
let surface = stores.get().insert(Plane {
|
||||
let surface = stores.surfaces.insert(Plane {
|
||||
origin: Point::from([0., 0., 0.5]),
|
||||
coords: Bivector {
|
||||
a: Vector::from([1., 0., 0.]),
|
||||
@ -22,9 +22,11 @@ pub fn model() -> AnyOp {
|
||||
},
|
||||
});
|
||||
|
||||
sketch.to_face(surface, stores.get())
|
||||
sketch.to_face(surface, &mut stores.vertices)
|
||||
};
|
||||
let bottom = top.flip(stores.get()).translate([0., 0., -1.], &mut stores);
|
||||
let bottom = top
|
||||
.flip(&mut stores.surfaces)
|
||||
.translate([0., 0., -1.], &mut stores);
|
||||
|
||||
let [a, b, c, d] = bottom.vertices().collect_array().unwrap();
|
||||
let [e, f, g, h] = top.vertices().collect_array().unwrap();
|
||||
@ -32,7 +34,7 @@ pub fn model() -> AnyOp {
|
||||
let [left, right, front, back] =
|
||||
[[a, e, h, d], [b, c, g, f], [a, b, f, e], [c, d, h, g]].map(
|
||||
|[q, r, s, t]| {
|
||||
let surface = stores.get().insert(Plane::from_points(
|
||||
let surface = stores.surfaces.insert(Plane::from_points(
|
||||
[q, r, s].map(|vertex| vertex.point),
|
||||
));
|
||||
Face::new(surface, [q, r, s, t].map(|vertex| vertex.clone()))
|
||||
@ -41,7 +43,7 @@ pub fn model() -> AnyOp {
|
||||
|
||||
let solid = Solid::new(
|
||||
[bottom, top, left, right, front, back]
|
||||
.map(|face| stores.get().insert(face)),
|
||||
.map(|face| stores.faces.insert(face)),
|
||||
);
|
||||
|
||||
AnyOp::new(solid)
|
||||
|
@ -1,22 +1,22 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use anymap3::AnyMap;
|
||||
|
||||
use crate::geometry::Handle;
|
||||
use crate::{
|
||||
geometry::Handle,
|
||||
math::Plane,
|
||||
topology::{Face, Vertex},
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Stores {
|
||||
inner: AnyMap,
|
||||
pub faces: Store<Face>,
|
||||
pub surfaces: Store<Plane>,
|
||||
pub vertices: Store<Vertex>,
|
||||
}
|
||||
|
||||
impl Stores {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn get<T: 'static>(&mut self) -> &mut Store<T> {
|
||||
self.inner.entry::<Store<T>>().or_default()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Store<T> {
|
||||
|
@ -44,11 +44,11 @@ impl Face {
|
||||
let offset = offset.into();
|
||||
|
||||
Self {
|
||||
surface: stores.get().insert(self.surface.translate(offset)),
|
||||
surface: stores.surfaces.insert(self.surface.translate(offset)),
|
||||
vertices: self
|
||||
.vertices
|
||||
.iter()
|
||||
.map(|vertex| stores.get().insert(vertex.translate(offset)))
|
||||
.map(|vertex| stores.vertices.insert(vertex.translate(offset)))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user