From a0904a918a0abfbeef18f998edff7f001c6dd949 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 6 Feb 2025 21:33:19 +0100 Subject: [PATCH] Prepare to show more operations in tree --- experiments/2024-12-09/src/geometry/mod.rs | 2 +- .../2024-12-09/src/geometry/operation.rs | 32 +++++++++++-------- .../2024-12-09/src/geometry/triangle.rs | 19 +++++++---- .../2024-12-09/src/topology/connect.rs | 16 ++++++---- experiments/2024-12-09/src/topology/face.rs | 16 ++++++---- experiments/2024-12-09/src/topology/solid.rs | 15 +++++---- experiments/2024-12-09/src/topology/sweep.rs | 16 ++++++---- experiments/2024-12-09/src/topology/vertex.rs | 16 ++++++---- experiments/2024-12-09/src/view.rs | 16 ++++++---- 9 files changed, 84 insertions(+), 64 deletions(-) diff --git a/experiments/2024-12-09/src/geometry/mod.rs b/experiments/2024-12-09/src/geometry/mod.rs index 4abb45971..270c9a588 100644 --- a/experiments/2024-12-09/src/geometry/mod.rs +++ b/experiments/2024-12-09/src/geometry/mod.rs @@ -4,7 +4,7 @@ mod tri_mesh; mod triangle; pub use self::{ - operation::{AnyOp, Handle, Operation}, + operation::{AnyOp, Handle, Operation, OperationOutput}, sketch::Sketch, tri_mesh::TriMesh, triangle::Triangle, diff --git a/experiments/2024-12-09/src/geometry/operation.rs b/experiments/2024-12-09/src/geometry/operation.rs index 89b4bf54d..8fa83614b 100644 --- a/experiments/2024-12-09/src/geometry/operation.rs +++ b/experiments/2024-12-09/src/geometry/operation.rs @@ -3,14 +3,6 @@ use std::{fmt, ops::Deref, rc::Rc}; use super::tri_mesh::TriMesh; pub trait Operation { - type Output - where - Self: Sized; - - fn output(&self) -> &Self::Output - where - Self: Sized; - fn display(&self, f: &mut fmt::Formatter) -> fmt::Result; fn tri_mesh(&self) -> TriMesh; fn children(&self) -> Vec; @@ -23,6 +15,16 @@ pub trait Operation { } } +pub trait OperationOutput: Operation { + type Output + where + Self: Sized; + + fn output(&self) -> &Self::Output + where + Self: Sized; +} + pub struct OperationDisplay<'r> { pub op: &'r dyn Operation, } @@ -88,12 +90,6 @@ impl AnyOp { } impl Operation for AnyOp { - type Output = Self; - - fn output(&self) -> &Self::Output { - self - } - fn display(&self, f: &mut fmt::Formatter) -> fmt::Result { self.inner.display(f)?; write!(f, " ({:?})", Rc::as_ptr(&self.inner))?; @@ -109,3 +105,11 @@ impl Operation for AnyOp { self.inner.children() } } + +impl OperationOutput for AnyOp { + type Output = Self; + + fn output(&self) -> &Self::Output { + self + } +} diff --git a/experiments/2024-12-09/src/geometry/triangle.rs b/experiments/2024-12-09/src/geometry/triangle.rs index 07df3481b..212484c71 100644 --- a/experiments/2024-12-09/src/geometry/triangle.rs +++ b/experiments/2024-12-09/src/geometry/triangle.rs @@ -2,7 +2,10 @@ use std::fmt; use crate::math::Point; -use super::{operation::AnyOp, Operation, TriMesh}; +use super::{ + operation::{AnyOp, OperationOutput}, + Operation, TriMesh, +}; #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] pub struct Triangle { @@ -21,12 +24,6 @@ where } impl Operation for Triangle { - type Output = Self; - - fn output(&self) -> &Self::Output { - self - } - fn display(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Triangle") } @@ -41,3 +38,11 @@ impl Operation for Triangle { Vec::new() } } + +impl OperationOutput for Triangle { + type Output = Self; + + fn output(&self) -> &Self::Output { + self + } +} diff --git a/experiments/2024-12-09/src/topology/connect.rs b/experiments/2024-12-09/src/topology/connect.rs index aabce78fd..df8bf2302 100644 --- a/experiments/2024-12-09/src/topology/connect.rs +++ b/experiments/2024-12-09/src/topology/connect.rs @@ -1,7 +1,7 @@ use std::fmt; use crate::{ - geometry::{AnyOp, Handle, Operation, TriMesh}, + geometry::{AnyOp, Handle, Operation, OperationOutput, TriMesh}, math::Plane, }; @@ -62,12 +62,6 @@ pub struct Connect { } impl Operation for Connect { - type Output = Solid; - - fn output(&self) -> &Self::Output { - &self.output - } - fn display(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Connect") } @@ -80,3 +74,11 @@ impl Operation for Connect { vec![self.output.to_any()] } } + +impl OperationOutput for Connect { + type Output = Solid; + + fn output(&self) -> &Self::Output { + &self.output + } +} diff --git a/experiments/2024-12-09/src/topology/face.rs b/experiments/2024-12-09/src/topology/face.rs index 9d72d0949..10b487b94 100644 --- a/experiments/2024-12-09/src/topology/face.rs +++ b/experiments/2024-12-09/src/topology/face.rs @@ -4,7 +4,7 @@ use itertools::Itertools; use spade::Triangulation; use crate::{ - geometry::{AnyOp, Handle, Operation, TriMesh, Triangle}, + geometry::{AnyOp, Handle, Operation, OperationOutput, TriMesh, Triangle}, math::{Plane, Point, Vector}, }; @@ -61,12 +61,6 @@ impl Face { } impl Operation for Face { - type Output = Self; - - fn output(&self) -> &Self::Output { - self - } - fn display(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Face") } @@ -126,6 +120,14 @@ impl Operation for Face { } } +impl OperationOutput for Face { + type Output = Self; + + fn output(&self) -> &Self::Output { + self + } +} + struct TriangulationPoint { point_surface: Point<2>, point_vertex: Point<3>, diff --git a/experiments/2024-12-09/src/topology/solid.rs b/experiments/2024-12-09/src/topology/solid.rs index 194de992f..66593b4ff 100644 --- a/experiments/2024-12-09/src/topology/solid.rs +++ b/experiments/2024-12-09/src/topology/solid.rs @@ -1,6 +1,6 @@ use std::fmt; -use crate::geometry::{AnyOp, Handle, Operation, TriMesh}; +use crate::geometry::{AnyOp, Handle, Operation, OperationOutput, TriMesh}; use super::face::Face; @@ -17,12 +17,6 @@ impl Solid { } impl Operation for Solid { - type Output = Self; - - fn output(&self) -> &Self::Output { - self - } - fn display(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Solid") } @@ -41,3 +35,10 @@ impl Operation for Solid { self.faces.iter().map(|face| face.to_any()).collect() } } +impl OperationOutput for Solid { + type Output = Self; + + fn output(&self) -> &Self::Output { + self + } +} diff --git a/experiments/2024-12-09/src/topology/sweep.rs b/experiments/2024-12-09/src/topology/sweep.rs index 81b670a9e..b0e3f2727 100644 --- a/experiments/2024-12-09/src/topology/sweep.rs +++ b/experiments/2024-12-09/src/topology/sweep.rs @@ -1,7 +1,7 @@ use std::fmt; use crate::{ - geometry::{AnyOp, Handle, Operation, TriMesh}, + geometry::{AnyOp, Handle, Operation, OperationOutput, TriMesh}, math::Vector, }; @@ -43,12 +43,6 @@ pub struct Sweep { } impl Operation for Sweep { - type Output = Solid; - - fn output(&self) -> &Self::Output { - self.output.output() - } - fn display(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Sweep") } @@ -61,3 +55,11 @@ impl Operation for Sweep { vec![self.output.to_any()] } } + +impl OperationOutput for Sweep { + type Output = Solid; + + fn output(&self) -> &Self::Output { + self.output.output() + } +} diff --git a/experiments/2024-12-09/src/topology/vertex.rs b/experiments/2024-12-09/src/topology/vertex.rs index 6ef5f5642..d8907533b 100644 --- a/experiments/2024-12-09/src/topology/vertex.rs +++ b/experiments/2024-12-09/src/topology/vertex.rs @@ -1,7 +1,7 @@ use std::fmt; use crate::{ - geometry::{AnyOp, Operation, TriMesh}, + geometry::{AnyOp, Operation, OperationOutput, TriMesh}, math::{Point, Vector}, }; @@ -30,12 +30,6 @@ where } impl Operation for Vertex { - type Output = Self; - - fn output(&self) -> &Self::Output { - self - } - fn display(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Vertex") } @@ -48,3 +42,11 @@ impl Operation for Vertex { Vec::new() } } + +impl OperationOutput for Vertex { + type Output = Self; + + fn output(&self) -> &Self::Output { + self + } +} diff --git a/experiments/2024-12-09/src/view.rs b/experiments/2024-12-09/src/view.rs index 347f86975..08456155a 100644 --- a/experiments/2024-12-09/src/view.rs +++ b/experiments/2024-12-09/src/view.rs @@ -1,6 +1,6 @@ use std::{fmt, iter}; -use crate::geometry::{AnyOp, Operation, TriMesh}; +use crate::geometry::{AnyOp, Operation, OperationOutput, TriMesh}; #[derive(Clone)] pub struct OperationView { @@ -119,12 +119,6 @@ impl OperationView { } impl Operation for OperationView { - type Output = Self; - - fn output(&self) -> &Self::Output { - self - } - fn display(&self, f: &mut fmt::Formatter) -> fmt::Result { self.operation.display(f) } @@ -137,3 +131,11 @@ impl Operation for OperationView { self.operation.children() } } + +impl OperationOutput for OperationView { + type Output = Self; + + fn output(&self) -> &Self::Output { + self + } +}