Skip to content

Commit a0904a9

Browse files
committed
Prepare to show more operations in tree
1 parent 676fc85 commit a0904a9

File tree

9 files changed

+84
-64
lines changed

9 files changed

+84
-64
lines changed

experiments/2024-12-09/src/geometry/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod tri_mesh;
44
mod triangle;
55

66
pub use self::{
7-
operation::{AnyOp, Handle, Operation},
7+
operation::{AnyOp, Handle, Operation, OperationOutput},
88
sketch::Sketch,
99
tri_mesh::TriMesh,
1010
triangle::Triangle,

experiments/2024-12-09/src/geometry/operation.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ use std::{fmt, ops::Deref, rc::Rc};
33
use super::tri_mesh::TriMesh;
44

55
pub trait Operation {
6-
type Output
7-
where
8-
Self: Sized;
9-
10-
fn output(&self) -> &Self::Output
11-
where
12-
Self: Sized;
13-
146
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result;
157
fn tri_mesh(&self) -> TriMesh;
168
fn children(&self) -> Vec<AnyOp>;
@@ -23,6 +15,16 @@ pub trait Operation {
2315
}
2416
}
2517

18+
pub trait OperationOutput: Operation {
19+
type Output
20+
where
21+
Self: Sized;
22+
23+
fn output(&self) -> &Self::Output
24+
where
25+
Self: Sized;
26+
}
27+
2628
pub struct OperationDisplay<'r> {
2729
pub op: &'r dyn Operation,
2830
}
@@ -88,12 +90,6 @@ impl AnyOp {
8890
}
8991

9092
impl Operation for AnyOp {
91-
type Output = Self;
92-
93-
fn output(&self) -> &Self::Output {
94-
self
95-
}
96-
9793
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
9894
self.inner.display(f)?;
9995
write!(f, " ({:?})", Rc::as_ptr(&self.inner))?;
@@ -109,3 +105,11 @@ impl Operation for AnyOp {
109105
self.inner.children()
110106
}
111107
}
108+
109+
impl OperationOutput for AnyOp {
110+
type Output = Self;
111+
112+
fn output(&self) -> &Self::Output {
113+
self
114+
}
115+
}

experiments/2024-12-09/src/geometry/triangle.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use std::fmt;
22

33
use crate::math::Point;
44

5-
use super::{operation::AnyOp, Operation, TriMesh};
5+
use super::{
6+
operation::{AnyOp, OperationOutput},
7+
Operation, TriMesh,
8+
};
69

710
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
811
pub struct Triangle {
@@ -21,12 +24,6 @@ where
2124
}
2225

2326
impl Operation for Triangle {
24-
type Output = Self;
25-
26-
fn output(&self) -> &Self::Output {
27-
self
28-
}
29-
3027
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
3128
write!(f, "Triangle")
3229
}
@@ -41,3 +38,11 @@ impl Operation for Triangle {
4138
Vec::new()
4239
}
4340
}
41+
42+
impl OperationOutput for Triangle {
43+
type Output = Self;
44+
45+
fn output(&self) -> &Self::Output {
46+
self
47+
}
48+
}

experiments/2024-12-09/src/topology/connect.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt;
22

33
use crate::{
4-
geometry::{AnyOp, Handle, Operation, TriMesh},
4+
geometry::{AnyOp, Handle, Operation, OperationOutput, TriMesh},
55
math::Plane,
66
};
77

@@ -62,12 +62,6 @@ pub struct Connect {
6262
}
6363

6464
impl Operation for Connect {
65-
type Output = Solid;
66-
67-
fn output(&self) -> &Self::Output {
68-
&self.output
69-
}
70-
7165
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
7266
write!(f, "Connect")
7367
}
@@ -80,3 +74,11 @@ impl Operation for Connect {
8074
vec![self.output.to_any()]
8175
}
8276
}
77+
78+
impl OperationOutput for Connect {
79+
type Output = Solid;
80+
81+
fn output(&self) -> &Self::Output {
82+
&self.output
83+
}
84+
}

experiments/2024-12-09/src/topology/face.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use itertools::Itertools;
44
use spade::Triangulation;
55

66
use crate::{
7-
geometry::{AnyOp, Handle, Operation, TriMesh, Triangle},
7+
geometry::{AnyOp, Handle, Operation, OperationOutput, TriMesh, Triangle},
88
math::{Plane, Point, Vector},
99
};
1010

@@ -61,12 +61,6 @@ impl Face {
6161
}
6262

6363
impl Operation for Face {
64-
type Output = Self;
65-
66-
fn output(&self) -> &Self::Output {
67-
self
68-
}
69-
7064
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
7165
write!(f, "Face")
7266
}
@@ -126,6 +120,14 @@ impl Operation for Face {
126120
}
127121
}
128122

123+
impl OperationOutput for Face {
124+
type Output = Self;
125+
126+
fn output(&self) -> &Self::Output {
127+
self
128+
}
129+
}
130+
129131
struct TriangulationPoint {
130132
point_surface: Point<2>,
131133
point_vertex: Point<3>,

experiments/2024-12-09/src/topology/solid.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::fmt;
22

3-
use crate::geometry::{AnyOp, Handle, Operation, TriMesh};
3+
use crate::geometry::{AnyOp, Handle, Operation, OperationOutput, TriMesh};
44

55
use super::face::Face;
66

@@ -17,12 +17,6 @@ impl Solid {
1717
}
1818

1919
impl Operation for Solid {
20-
type Output = Self;
21-
22-
fn output(&self) -> &Self::Output {
23-
self
24-
}
25-
2620
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
2721
write!(f, "Solid")
2822
}
@@ -41,3 +35,10 @@ impl Operation for Solid {
4135
self.faces.iter().map(|face| face.to_any()).collect()
4236
}
4337
}
38+
impl OperationOutput for Solid {
39+
type Output = Self;
40+
41+
fn output(&self) -> &Self::Output {
42+
self
43+
}
44+
}

experiments/2024-12-09/src/topology/sweep.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt;
22

33
use crate::{
4-
geometry::{AnyOp, Handle, Operation, TriMesh},
4+
geometry::{AnyOp, Handle, Operation, OperationOutput, TriMesh},
55
math::Vector,
66
};
77

@@ -43,12 +43,6 @@ pub struct Sweep {
4343
}
4444

4545
impl Operation for Sweep {
46-
type Output = Solid;
47-
48-
fn output(&self) -> &Self::Output {
49-
self.output.output()
50-
}
51-
5246
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
5347
write!(f, "Sweep")
5448
}
@@ -61,3 +55,11 @@ impl Operation for Sweep {
6155
vec![self.output.to_any()]
6256
}
6357
}
58+
59+
impl OperationOutput for Sweep {
60+
type Output = Solid;
61+
62+
fn output(&self) -> &Self::Output {
63+
self.output.output()
64+
}
65+
}

experiments/2024-12-09/src/topology/vertex.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt;
22

33
use crate::{
4-
geometry::{AnyOp, Operation, TriMesh},
4+
geometry::{AnyOp, Operation, OperationOutput, TriMesh},
55
math::{Point, Vector},
66
};
77

@@ -30,12 +30,6 @@ where
3030
}
3131

3232
impl Operation for Vertex {
33-
type Output = Self;
34-
35-
fn output(&self) -> &Self::Output {
36-
self
37-
}
38-
3933
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
4034
write!(f, "Vertex")
4135
}
@@ -48,3 +42,11 @@ impl Operation for Vertex {
4842
Vec::new()
4943
}
5044
}
45+
46+
impl OperationOutput for Vertex {
47+
type Output = Self;
48+
49+
fn output(&self) -> &Self::Output {
50+
self
51+
}
52+
}

experiments/2024-12-09/src/view.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{fmt, iter};
22

3-
use crate::geometry::{AnyOp, Operation, TriMesh};
3+
use crate::geometry::{AnyOp, Operation, OperationOutput, TriMesh};
44

55
#[derive(Clone)]
66
pub struct OperationView {
@@ -119,12 +119,6 @@ impl OperationView {
119119
}
120120

121121
impl Operation for OperationView {
122-
type Output = Self;
123-
124-
fn output(&self) -> &Self::Output {
125-
self
126-
}
127-
128122
fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
129123
self.operation.display(f)
130124
}
@@ -137,3 +131,11 @@ impl Operation for OperationView {
137131
self.operation.children()
138132
}
139133
}
134+
135+
impl OperationOutput for OperationView {
136+
type Output = Self;
137+
138+
fn output(&self) -> &Self::Output {
139+
self
140+
}
141+
}

0 commit comments

Comments
 (0)