mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-08 08:15:55 +00:00
Refer to Triangle
via new Handle
This commit is contained in:
parent
b368105d34
commit
1122367341
@ -8,6 +8,41 @@ pub trait Operation: fmt::Display {
|
||||
fn children(&self) -> Vec<HandleAny>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub struct Handle<T> {
|
||||
inner: Rc<T>,
|
||||
}
|
||||
|
||||
impl<T> Handle<T> {
|
||||
pub fn new(inner: T) -> Self {
|
||||
Self {
|
||||
inner: Rc::new(inner),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_any(&self) -> HandleAny
|
||||
where
|
||||
T: Operation + 'static,
|
||||
{
|
||||
self.clone().into_any()
|
||||
}
|
||||
|
||||
pub fn into_any(self) -> HandleAny
|
||||
where
|
||||
T: Operation + 'static,
|
||||
{
|
||||
HandleAny { inner: self.inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Clone for Handle<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
inner: self.inner.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct HandleAny {
|
||||
inner: Rc<dyn Operation>,
|
||||
|
@ -2,7 +2,10 @@ use std::fmt;
|
||||
|
||||
use tuples::CombinRight;
|
||||
|
||||
use super::{operation::HandleAny, Operation, Triangle, Vertex};
|
||||
use super::{
|
||||
operation::{Handle, HandleAny},
|
||||
Operation, Triangle, Vertex,
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Shape {
|
||||
@ -33,11 +36,11 @@ impl Shape {
|
||||
pub fn triangle(
|
||||
&mut self,
|
||||
triangle: impl Into<Triangle>,
|
||||
) -> OperationResult<(Triangle,)> {
|
||||
let triangle = triangle.into();
|
||||
) -> OperationResult<(Handle<Triangle>,)> {
|
||||
let triangle = Handle::new(triangle.into());
|
||||
|
||||
self.operations.push(OperationInSequence {
|
||||
operation: HandleAny::new(triangle.clone()),
|
||||
operation: triangle.to_any(),
|
||||
previous: self
|
||||
.operations
|
||||
.last()
|
||||
@ -138,7 +141,7 @@ impl<'r, T> OperationResult<'r, T> {
|
||||
triangle: impl Into<Triangle>,
|
||||
) -> OperationResult<'r, T::Out>
|
||||
where
|
||||
T: CombinRight<Triangle>,
|
||||
T: CombinRight<Handle<Triangle>>,
|
||||
{
|
||||
let OperationResult {
|
||||
results: (triangle,),
|
||||
|
Loading…
Reference in New Issue
Block a user