mirror of
https://github.com/hannobraun/Fornjot
synced 2025-10-13 03:18:02 +00:00
Consolidate redundant code
This commit is contained in:
parent
5b8938f376
commit
ea3a198bbb
@ -97,12 +97,10 @@ impl<'r, T> ShapeExtender<'r, (), T> {
|
||||
}
|
||||
|
||||
impl<'r, NewOps, T> ShapeExtender<'r, NewOps, T> {
|
||||
pub fn vertex(
|
||||
self,
|
||||
vertex: impl Into<Vertex>,
|
||||
) -> ShapeExtender<'r, NewOps::Out, T>
|
||||
pub fn add(self, vertex: impl Into<T>) -> ShapeExtender<'r, NewOps::Out, T>
|
||||
where
|
||||
NewOps: CombinRight<Handle<Vertex>>,
|
||||
NewOps: CombinRight<Handle<T>>,
|
||||
T: Operation + 'static,
|
||||
{
|
||||
let vertex = Handle::new(vertex.into());
|
||||
|
||||
@ -118,27 +116,6 @@ impl<'r, NewOps, T> ShapeExtender<'r, NewOps, T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn triangle(
|
||||
self,
|
||||
triangle: impl Into<Triangle>,
|
||||
) -> ShapeExtender<'r, NewOps::Out, T>
|
||||
where
|
||||
NewOps: CombinRight<Handle<Triangle>>,
|
||||
{
|
||||
let triangle = Handle::new(triangle.into());
|
||||
|
||||
self.sequence.push(OperationInSequence {
|
||||
operation: triangle.to_any(),
|
||||
previous: self.sequence.last().map(|op| HandleAny::new(op.clone())),
|
||||
});
|
||||
|
||||
ShapeExtender {
|
||||
sequence: self.sequence,
|
||||
new_ops: self.new_ops.push_right(triangle),
|
||||
_t: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_new_ops(self) -> NewOps {
|
||||
self.new_ops
|
||||
}
|
||||
|
@ -9,28 +9,28 @@ pub fn model(shape: &mut Shape) {
|
||||
|
||||
let (a, b, c, d, e, f, g, h) = shape
|
||||
.extend_with(&mut vertices)
|
||||
.vertex([-0.5, -0.5, -0.5])
|
||||
.vertex([0.5, -0.5, -0.5])
|
||||
.vertex([-0.5, 0.5, -0.5])
|
||||
.vertex([0.5, 0.5, -0.5])
|
||||
.vertex([-0.5, -0.5, 0.5])
|
||||
.vertex([0.5, -0.5, 0.5])
|
||||
.vertex([-0.5, 0.5, 0.5])
|
||||
.vertex([0.5, 0.5, 0.5])
|
||||
.add([-0.5, -0.5, -0.5])
|
||||
.add([0.5, -0.5, -0.5])
|
||||
.add([-0.5, 0.5, -0.5])
|
||||
.add([0.5, 0.5, -0.5])
|
||||
.add([-0.5, -0.5, 0.5])
|
||||
.add([0.5, -0.5, 0.5])
|
||||
.add([-0.5, 0.5, 0.5])
|
||||
.add([0.5, 0.5, 0.5])
|
||||
.get_new_ops();
|
||||
|
||||
shape
|
||||
.extend_with(&mut triangles)
|
||||
.triangle([&a, &e, &g]) // left
|
||||
.triangle([&a, &g, &c])
|
||||
.triangle([&b, &d, &h]) // right
|
||||
.triangle([&b, &h, &f])
|
||||
.triangle([&a, &b, &f]) // front
|
||||
.triangle([&a, &f, &e])
|
||||
.triangle([&c, &h, &d]) // back
|
||||
.triangle([&c, &g, &h])
|
||||
.triangle([&a, &c, &b]) // bottom
|
||||
.triangle([&b, &c, &d])
|
||||
.triangle([&e, &f, &h]) // top
|
||||
.triangle([&e, &h, &g]);
|
||||
.add([&a, &e, &g]) // left
|
||||
.add([&a, &g, &c])
|
||||
.add([&b, &d, &h]) // right
|
||||
.add([&b, &h, &f])
|
||||
.add([&a, &b, &f]) // front
|
||||
.add([&a, &f, &e])
|
||||
.add([&c, &h, &d]) // back
|
||||
.add([&c, &g, &h])
|
||||
.add([&a, &c, &b]) // bottom
|
||||
.add([&b, &c, &d])
|
||||
.add([&e, &f, &h]) // top
|
||||
.add([&e, &h, &g]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user