mirror of
https://github.com/hannobraun/Fornjot
synced 2025-06-18 09:18:59 +00:00
Add Operation::children
This commit is contained in:
parent
20025690de
commit
a9bcd5df1b
@ -5,4 +5,5 @@ use super::{Triangle, Vertex};
|
||||
pub trait Operation: fmt::Display {
|
||||
fn vertices(&self, vertices: &mut Vec<Vertex>);
|
||||
fn triangles(&self, triangles: &mut Vec<Triangle>);
|
||||
fn children(&self) -> Vec<Box<dyn Operation>>;
|
||||
}
|
||||
|
@ -73,6 +73,13 @@ impl Operation for OpsLog {
|
||||
op.triangles(triangles);
|
||||
}
|
||||
}
|
||||
|
||||
fn children(&self) -> Vec<Box<dyn Operation>> {
|
||||
self.operations
|
||||
.iter()
|
||||
.map(|op| Box::new(op.clone()) as _)
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -95,6 +102,10 @@ impl Operation for OperationInSequence {
|
||||
}
|
||||
self.operation.triangles(triangles);
|
||||
}
|
||||
|
||||
fn children(&self) -> Vec<Box<dyn Operation>> {
|
||||
self.operation.children()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for OperationInSequence {
|
||||
@ -154,6 +165,7 @@ pub struct ClonedOperation {
|
||||
pub description: String,
|
||||
pub vertices: Vec<Vertex>,
|
||||
pub triangles: Vec<Triangle>,
|
||||
pub children: Vec<ClonedOperation>,
|
||||
}
|
||||
|
||||
impl ClonedOperation {
|
||||
@ -164,10 +176,17 @@ impl ClonedOperation {
|
||||
let mut triangles = Vec::new();
|
||||
op.triangles(&mut triangles);
|
||||
|
||||
let children = op
|
||||
.children()
|
||||
.into_iter()
|
||||
.map(|op| Self::from_op(op.as_ref()))
|
||||
.collect();
|
||||
|
||||
Self {
|
||||
description: op.to_string(),
|
||||
vertices,
|
||||
triangles,
|
||||
children,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -186,4 +205,11 @@ impl Operation for ClonedOperation {
|
||||
fn triangles(&self, triangles: &mut Vec<Triangle>) {
|
||||
triangles.extend(&self.triangles);
|
||||
}
|
||||
|
||||
fn children(&self) -> Vec<Box<dyn Operation>> {
|
||||
self.children
|
||||
.iter()
|
||||
.map(|op| Box::new(op.clone()) as _)
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,10 @@ impl Operation for Vertex {
|
||||
}
|
||||
|
||||
fn triangles(&self, _: &mut Vec<Triangle>) {}
|
||||
|
||||
fn children(&self) -> Vec<Box<dyn Operation>> {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
@ -64,4 +68,8 @@ impl Operation for Triangle {
|
||||
fn triangles(&self, triangles: &mut Vec<Triangle>) {
|
||||
triangles.push(*self)
|
||||
}
|
||||
|
||||
fn children(&self) -> Vec<Box<dyn Operation>> {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user