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;
pub use self::{
operation::{AnyOp, Handle, Operation},
operation::{AnyOp, Handle, Operation, OperationOutput},
sketch::Sketch,
tri_mesh::TriMesh,
triangle::Triangle,

View File

@ -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<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 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
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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>,

View File

@ -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
}
}

View File

@ -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()
}
}

View File

@ -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
}
}

View File

@ -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
}
}