Prepare to lift fmt::Display requirement

This commit is contained in:
Hanno Braun 2025-01-17 19:58:34 +01:00
parent 62e5e8db95
commit 183d834b3d
6 changed files with 29 additions and 0 deletions

View File

@ -3,6 +3,7 @@ use std::{fmt, ops::Deref, rc::Rc};
use super::tri_mesh::TriMesh;
pub trait Operation: fmt::Display {
fn label(&self) -> &'static str;
fn tri_mesh(&self) -> TriMesh;
fn children(&self) -> Vec<AnyOp>;
}
@ -68,6 +69,10 @@ impl fmt::Display for AnyOp {
}
impl Operation for AnyOp {
fn label(&self) -> &'static str {
self.inner.label()
}
fn tri_mesh(&self) -> TriMesh {
self.inner.tri_mesh()
}

View File

@ -31,6 +31,10 @@ impl fmt::Display for Shape {
}
impl Operation for Shape {
fn label(&self) -> &'static str {
"Shape"
}
fn tri_mesh(&self) -> TriMesh {
if let Some(op) = self.sequence.last() {
op.tri_mesh()
@ -54,6 +58,10 @@ struct OperationInSequence {
}
impl Operation for OperationInSequence {
fn label(&self) -> &'static str {
self.operation.label()
}
fn tri_mesh(&self) -> TriMesh {
let mesh = if let Some(op) = &self.previous {
op.tri_mesh()

View File

@ -27,6 +27,10 @@ impl fmt::Display for Triangle {
}
impl Operation for Triangle {
fn label(&self) -> &'static str {
"Triangle"
}
fn tri_mesh(&self) -> TriMesh {
TriMesh {
triangles: vec![self.clone()],

View File

@ -47,6 +47,10 @@ impl fmt::Display for Face {
}
impl Operation for Face {
fn label(&self) -> &'static str {
"Face"
}
fn tri_mesh(&self) -> TriMesh {
// This is a placeholder implementation that only supports convex faces.

View File

@ -29,6 +29,10 @@ impl fmt::Display for Vertex {
}
impl Operation for Vertex {
fn label(&self) -> &'static str {
"Vertex"
}
fn tri_mesh(&self) -> TriMesh {
TriMesh::new()
}

View File

@ -128,6 +128,10 @@ impl fmt::Display for OperationView {
}
impl Operation for OperationView {
fn label(&self) -> &'static str {
self.operation.label()
}
fn tri_mesh(&self) -> TriMesh {
self.operation.tri_mesh()
}