Skip to content

Commit

Permalink
Add OperationInSequence
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Nov 5, 2024
1 parent 8e134a4 commit ccf934c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions experiments/2024-10-30/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,32 @@ pub trait Operation {
fn vertices(&self) -> Vec<Vertex>;
fn triangles(&self) -> Vec<Triangle>;
}

pub struct OperationInSequence {
pub operation: Box<dyn Operation>,
pub previous: Option<Box<dyn Operation>>,
}

impl Operation for OperationInSequence {
fn vertices(&self) -> Vec<Vertex> {
let mut vertices = self
.previous
.as_ref()
.map(|op| op.vertices())
.unwrap_or_default();
vertices.extend(self.operation.vertices());

vertices
}

fn triangles(&self) -> Vec<Triangle> {
let mut triangles = self
.previous
.as_ref()
.map(|op| op.triangles())
.unwrap_or_default();
triangles.extend(self.operation.triangles());

triangles
}
}

0 comments on commit ccf934c

Please sign in to comment.