Prepare to show more operations in tree

This commit is contained in:
Hanno Braun 2025-02-06 21:33:19 +01:00
parent 676fc85f92
commit a0904a918a
9 changed files with 84 additions and 64 deletions

View File

@ -4,7 +4,7 @@ mod tri_mesh;
mod triangle; mod triangle;
pub use self::{ pub use self::{
operation::{AnyOp, Handle, Operation}, operation::{AnyOp, Handle, Operation, OperationOutput},
sketch::Sketch, sketch::Sketch,
tri_mesh::TriMesh, tri_mesh::TriMesh,
triangle::Triangle, triangle::Triangle,

View File

@ -3,14 +3,6 @@ use std::{fmt, ops::Deref, rc::Rc};
use super::tri_mesh::TriMesh; use super::tri_mesh::TriMesh;
pub trait Operation { 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 display(&self, f: &mut fmt::Formatter) -> fmt::Result;
fn tri_mesh(&self) -> TriMesh; fn tri_mesh(&self) -> TriMesh;
fn children(&self) -> Vec<AnyOp>; fn children(&self) -> Vec<AnyOp>;
@ -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 struct OperationDisplay<'r> {
pub op: &'r dyn Operation, pub op: &'r dyn Operation,
} }
@ -88,12 +90,6 @@ impl AnyOp {
} }
impl Operation for AnyOp { impl Operation for AnyOp {
type Output = Self;
fn output(&self) -> &Self::Output {
self
}
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result { fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.inner.display(f)?; self.inner.display(f)?;
write!(f, " ({:?})", Rc::as_ptr(&self.inner))?; write!(f, " ({:?})", Rc::as_ptr(&self.inner))?;
@ -109,3 +105,11 @@ impl Operation for AnyOp {
self.inner.children() self.inner.children()
} }
} }
impl OperationOutput for AnyOp {
type Output = Self;
fn output(&self) -> &Self::Output {
self
}
}

View File

@ -2,7 +2,10 @@ use std::fmt;
use crate::math::Point; use crate::math::Point;
use super::{operation::AnyOp, Operation, TriMesh}; use super::{
operation::{AnyOp, OperationOutput},
Operation, TriMesh,
};
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct Triangle { pub struct Triangle {
@ -21,12 +24,6 @@ where
} }
impl Operation for Triangle { impl Operation for Triangle {
type Output = Self;
fn output(&self) -> &Self::Output {
self
}
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result { fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Triangle") write!(f, "Triangle")
} }
@ -41,3 +38,11 @@ impl Operation for Triangle {
Vec::new() Vec::new()
} }
} }
impl OperationOutput for Triangle {
type Output = Self;
fn output(&self) -> &Self::Output {
self
}
}

View File

@ -1,7 +1,7 @@
use std::fmt; use std::fmt;
use crate::{ use crate::{
geometry::{AnyOp, Handle, Operation, TriMesh}, geometry::{AnyOp, Handle, Operation, OperationOutput, TriMesh},
math::Plane, math::Plane,
}; };
@ -62,12 +62,6 @@ pub struct Connect {
} }
impl Operation for Connect { impl Operation for Connect {
type Output = Solid;
fn output(&self) -> &Self::Output {
&self.output
}
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result { fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Connect") write!(f, "Connect")
} }
@ -80,3 +74,11 @@ impl Operation for Connect {
vec![self.output.to_any()] vec![self.output.to_any()]
} }
} }
impl OperationOutput for Connect {
type Output = Solid;
fn output(&self) -> &Self::Output {
&self.output
}
}

View File

@ -4,7 +4,7 @@ use itertools::Itertools;
use spade::Triangulation; use spade::Triangulation;
use crate::{ use crate::{
geometry::{AnyOp, Handle, Operation, TriMesh, Triangle}, geometry::{AnyOp, Handle, Operation, OperationOutput, TriMesh, Triangle},
math::{Plane, Point, Vector}, math::{Plane, Point, Vector},
}; };
@ -61,12 +61,6 @@ impl Face {
} }
impl Operation for Face { impl Operation for Face {
type Output = Self;
fn output(&self) -> &Self::Output {
self
}
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result { fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Face") 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 { struct TriangulationPoint {
point_surface: Point<2>, point_surface: Point<2>,
point_vertex: Point<3>, point_vertex: Point<3>,

View File

@ -1,6 +1,6 @@
use std::fmt; use std::fmt;
use crate::geometry::{AnyOp, Handle, Operation, TriMesh}; use crate::geometry::{AnyOp, Handle, Operation, OperationOutput, TriMesh};
use super::face::Face; use super::face::Face;
@ -17,12 +17,6 @@ impl Solid {
} }
impl Operation for Solid { impl Operation for Solid {
type Output = Self;
fn output(&self) -> &Self::Output {
self
}
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result { fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Solid") write!(f, "Solid")
} }
@ -41,3 +35,10 @@ impl Operation for Solid {
self.faces.iter().map(|face| face.to_any()).collect() self.faces.iter().map(|face| face.to_any()).collect()
} }
} }
impl OperationOutput for Solid {
type Output = Self;
fn output(&self) -> &Self::Output {
self
}
}

View File

@ -1,7 +1,7 @@
use std::fmt; use std::fmt;
use crate::{ use crate::{
geometry::{AnyOp, Handle, Operation, TriMesh}, geometry::{AnyOp, Handle, Operation, OperationOutput, TriMesh},
math::Vector, math::Vector,
}; };
@ -43,12 +43,6 @@ pub struct Sweep {
} }
impl Operation for 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 { fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Sweep") write!(f, "Sweep")
} }
@ -61,3 +55,11 @@ impl Operation for Sweep {
vec![self.output.to_any()] vec![self.output.to_any()]
} }
} }
impl OperationOutput for Sweep {
type Output = Solid;
fn output(&self) -> &Self::Output {
self.output.output()
}
}

View File

@ -1,7 +1,7 @@
use std::fmt; use std::fmt;
use crate::{ use crate::{
geometry::{AnyOp, Operation, TriMesh}, geometry::{AnyOp, Operation, OperationOutput, TriMesh},
math::{Point, Vector}, math::{Point, Vector},
}; };
@ -30,12 +30,6 @@ where
} }
impl Operation for Vertex { impl Operation for Vertex {
type Output = Self;
fn output(&self) -> &Self::Output {
self
}
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result { fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Vertex") write!(f, "Vertex")
} }
@ -48,3 +42,11 @@ impl Operation for Vertex {
Vec::new() Vec::new()
} }
} }
impl OperationOutput for Vertex {
type Output = Self;
fn output(&self) -> &Self::Output {
self
}
}

View File

@ -1,6 +1,6 @@
use std::{fmt, iter}; use std::{fmt, iter};
use crate::geometry::{AnyOp, Operation, TriMesh}; use crate::geometry::{AnyOp, Operation, OperationOutput, TriMesh};
#[derive(Clone)] #[derive(Clone)]
pub struct OperationView { pub struct OperationView {
@ -119,12 +119,6 @@ impl OperationView {
} }
impl Operation for OperationView { impl Operation for OperationView {
type Output = Self;
fn output(&self) -> &Self::Output {
self
}
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result { fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.operation.display(f) self.operation.display(f)
} }
@ -137,3 +131,11 @@ impl Operation for OperationView {
self.operation.children() self.operation.children()
} }
} }
impl OperationOutput for OperationView {
type Output = Self;
fn output(&self) -> &Self::Output {
self
}
}