mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-01 21:05:54 +00:00
Simplify
This commit is contained in:
parent
b916746ea8
commit
85b29fc4f1
@ -1,12 +1,10 @@
|
||||
mod operation;
|
||||
mod shape;
|
||||
mod sketch;
|
||||
mod tri_mesh;
|
||||
mod triangle;
|
||||
|
||||
pub use self::{
|
||||
operation::{AnyOp, Handle, Operation},
|
||||
shape::Shape,
|
||||
sketch::Sketch,
|
||||
tri_mesh::TriMesh,
|
||||
triangle::Triangle,
|
||||
|
@ -1,80 +0,0 @@
|
||||
use tuples::CombinRight;
|
||||
|
||||
use crate::storage::Store;
|
||||
|
||||
use super::{
|
||||
operation::{AnyOp, Handle},
|
||||
tri_mesh::TriMesh,
|
||||
Operation,
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Shape {
|
||||
children: Vec<AnyOp>,
|
||||
}
|
||||
|
||||
impl Shape {
|
||||
pub fn extend_with<'r, T>(
|
||||
&'r mut self,
|
||||
store: &'r mut Store<T>,
|
||||
) -> ShapeExtender<'r, (), T> {
|
||||
ShapeExtender::new(store, &mut self.children)
|
||||
}
|
||||
}
|
||||
|
||||
impl Operation for Shape {
|
||||
fn label(&self) -> &'static str {
|
||||
"Shape"
|
||||
}
|
||||
|
||||
fn tri_mesh(&self) -> TriMesh {
|
||||
let mut tri_mesh = TriMesh::new();
|
||||
|
||||
for op in &self.children {
|
||||
tri_mesh = tri_mesh.merge(op.tri_mesh());
|
||||
}
|
||||
|
||||
tri_mesh
|
||||
}
|
||||
|
||||
fn children(&self) -> Vec<AnyOp> {
|
||||
self.children
|
||||
.iter()
|
||||
.map(|op| AnyOp::new(op.clone()))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ShapeExtender<'r, NewOps, T> {
|
||||
store: &'r mut Store<T>,
|
||||
ops: &'r mut Vec<AnyOp>,
|
||||
new_ops: NewOps,
|
||||
}
|
||||
|
||||
impl<'r, T> ShapeExtender<'r, (), T> {
|
||||
fn new(store: &'r mut Store<T>, ops: &'r mut Vec<AnyOp>) -> Self {
|
||||
Self {
|
||||
store,
|
||||
ops,
|
||||
new_ops: (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r, NewOps, T> ShapeExtender<'r, NewOps, T> {
|
||||
pub fn add(self, op: impl Into<T>) -> ShapeExtender<'r, NewOps::Out, T>
|
||||
where
|
||||
NewOps: CombinRight<Handle<T>>,
|
||||
T: Operation + 'static,
|
||||
{
|
||||
let op = self.store.insert(op.into());
|
||||
|
||||
self.ops.push(op.to_any());
|
||||
|
||||
ShapeExtender {
|
||||
store: self.store,
|
||||
ops: self.ops,
|
||||
new_ops: self.new_ops.push_right(op),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::{
|
||||
geometry::{Shape, Sketch},
|
||||
geometry::{AnyOp, Sketch},
|
||||
math::{Bivector, Plane, Point, Vector},
|
||||
storage::Stores,
|
||||
topology::{Face, Solid},
|
||||
};
|
||||
|
||||
pub fn model() -> Shape {
|
||||
pub fn model() -> AnyOp {
|
||||
let mut stores = Stores::new();
|
||||
|
||||
let top = {
|
||||
@ -44,7 +44,5 @@ pub fn model() -> Shape {
|
||||
.map(|face| stores.get().insert(face)),
|
||||
);
|
||||
|
||||
let mut shape = Shape::default();
|
||||
shape.extend_with(stores.get::<Solid>()).add(solid);
|
||||
shape
|
||||
AnyOp::new(solid)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user