From ccf934c6f3c0876dcdd5f0eeafd13cf315d94dff Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 5 Nov 2024 19:46:19 +0100 Subject: [PATCH] Add `OperationInSequence` --- experiments/2024-10-30/src/geometry.rs | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/experiments/2024-10-30/src/geometry.rs b/experiments/2024-10-30/src/geometry.rs index dbdd7668b..0f7f48acc 100644 --- a/experiments/2024-10-30/src/geometry.rs +++ b/experiments/2024-10-30/src/geometry.rs @@ -48,3 +48,32 @@ pub trait Operation { fn vertices(&self) -> Vec; fn triangles(&self) -> Vec; } + +pub struct OperationInSequence { + pub operation: Box, + pub previous: Option>, +} + +impl Operation for OperationInSequence { + fn vertices(&self) -> Vec { + let mut vertices = self + .previous + .as_ref() + .map(|op| op.vertices()) + .unwrap_or_default(); + vertices.extend(self.operation.vertices()); + + vertices + } + + fn triangles(&self) -> Vec { + let mut triangles = self + .previous + .as_ref() + .map(|op| op.triangles()) + .unwrap_or_default(); + triangles.extend(self.operation.triangles()); + + triangles + } +}