mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-03 17:38:27 +00:00
Create Handle
s directly
This is preparation for removing the storage code.
This commit is contained in:
parent
f67ecef793
commit
b23eec5d41
@ -14,7 +14,7 @@ impl Sketch {
|
||||
pub fn to_face(
|
||||
&self,
|
||||
surface: Handle<Plane>,
|
||||
vertices: &mut Store<Vertex>,
|
||||
_: &mut Store<Vertex>,
|
||||
) -> Face {
|
||||
let vertices = self
|
||||
.points
|
||||
@ -23,7 +23,7 @@ impl Sketch {
|
||||
.map(|point| {
|
||||
let point = surface.point_from_local(point);
|
||||
let vertex = Vertex::from(point);
|
||||
vertices.insert(vertex)
|
||||
Handle::new(vertex)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
geometry::{AnyOp, Sketch},
|
||||
geometry::{AnyOp, Handle, Sketch},
|
||||
math::{Bivector, Plane, Point, Vector},
|
||||
storage::Stores,
|
||||
topology::sweep::SweepExt,
|
||||
@ -12,7 +12,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.surfaces.insert(Plane {
|
||||
let surface = Handle::new(Plane {
|
||||
origin: Point::from([0., 0., 0.5]),
|
||||
coords: Bivector {
|
||||
a: Vector::from([1., 0., 0.]),
|
||||
@ -23,7 +23,7 @@ pub fn model() -> AnyOp {
|
||||
sketch.to_face(surface, &mut stores.vertices)
|
||||
};
|
||||
|
||||
let top = stores.faces.insert(top);
|
||||
let top = Handle::new(top);
|
||||
|
||||
let solid = top.sweep(
|
||||
[0., 0., -1.],
|
||||
|
@ -1,7 +1,6 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use crate::{
|
||||
geometry::Handle,
|
||||
math::Plane,
|
||||
topology::{face::Face, vertex::Vertex},
|
||||
};
|
||||
@ -27,10 +26,6 @@ impl<T> Store<T> {
|
||||
pub fn new() -> Self {
|
||||
Self { _t: PhantomData }
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, op: T) -> Handle<T> {
|
||||
Handle::new(op)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Default for Store<T> {
|
||||
|
@ -40,9 +40,9 @@ impl Face {
|
||||
.map(|(a, b)| [a, b])
|
||||
}
|
||||
|
||||
pub fn flip(&self, surfaces: &mut Store<Plane>) -> Self {
|
||||
pub fn flip(&self, _: &mut Store<Plane>) -> Self {
|
||||
Self {
|
||||
surface: surfaces.insert(self.surface.flip()),
|
||||
surface: Handle::new(self.surface.flip()),
|
||||
vertices: self.vertices.clone(),
|
||||
}
|
||||
}
|
||||
@ -50,17 +50,17 @@ impl Face {
|
||||
pub fn translate(
|
||||
&self,
|
||||
offset: impl Into<Vector<3>>,
|
||||
surfaces: &mut Store<Plane>,
|
||||
vertices: &mut Store<Vertex>,
|
||||
_: &mut Store<Plane>,
|
||||
_: &mut Store<Vertex>,
|
||||
) -> Self {
|
||||
let offset = offset.into();
|
||||
|
||||
Self {
|
||||
surface: surfaces.insert(self.surface.translate(offset)),
|
||||
surface: Handle::new(self.surface.translate(offset)),
|
||||
vertices: self
|
||||
.vertices
|
||||
.iter()
|
||||
.map(|vertex| vertices.insert(vertex.translate(offset)))
|
||||
.map(|vertex| Handle::new(vertex.translate(offset)))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ impl Solid {
|
||||
/// this operation.
|
||||
pub fn connect_faces(
|
||||
[a, b]: [Handle<Face>; 2],
|
||||
faces: &mut Store<Face>,
|
||||
surfaces: &mut Store<Plane>,
|
||||
_: &mut Store<Face>,
|
||||
_: &mut Store<Plane>,
|
||||
) -> Self {
|
||||
assert_eq!(
|
||||
a.vertices().count(),
|
||||
@ -50,14 +50,14 @@ impl Solid {
|
||||
.half_edges()
|
||||
.zip(b.half_edges())
|
||||
.map(|([q, r], [t, s])| {
|
||||
let surface = surfaces.insert(Plane::from_points(
|
||||
let surface = Handle::new(Plane::from_points(
|
||||
[q, r, s].map(|vertex| vertex.point),
|
||||
));
|
||||
let face = Face::new(
|
||||
surface,
|
||||
[q, r, s, t].map(|vertex| vertex.clone()),
|
||||
);
|
||||
faces.insert(face)
|
||||
Handle::new(face)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
@ -38,8 +38,9 @@ impl SweepExt for Handle<Face> {
|
||||
vertices: &mut Store<Vertex>,
|
||||
) -> Sweep {
|
||||
let bottom = self;
|
||||
let top = faces
|
||||
.insert(bottom.flip(surfaces).translate(path, surfaces, vertices));
|
||||
let top = Handle::new(
|
||||
bottom.flip(surfaces).translate(path, surfaces, vertices),
|
||||
);
|
||||
|
||||
let solid = Solid::connect_faces([top, bottom], faces, surfaces);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user