This commit is contained in:
Hanno Braun 2025-01-21 20:29:21 +01:00
parent b916746ea8
commit 85b29fc4f1
3 changed files with 3 additions and 87 deletions

View File

@ -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,

View File

@ -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),
}
}
}

View File

@ -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)
}