Prepare to refer to Vertex by Handle

This commit is contained in:
Hanno Braun 2024-12-13 20:13:14 +01:00
parent 1122367341
commit f66603375b
3 changed files with 20 additions and 4 deletions

View File

@ -20,6 +20,13 @@ impl<T> Handle<T> {
}
}
pub fn get(&self) -> T
where
T: Copy,
{
*self.as_ref()
}
pub fn to_any(&self) -> HandleAny
where
T: Operation + 'static,
@ -35,6 +42,12 @@ impl<T> Handle<T> {
}
}
impl<T> AsRef<T> for Handle<T> {
fn as_ref(&self) -> &T {
self.inner.as_ref()
}
}
impl<T> Clone for Handle<T> {
fn clone(&self) -> Self {
Self {

View File

@ -16,11 +16,11 @@ impl Shape {
pub fn vertex(
&mut self,
vertex: impl Into<Vertex>,
) -> OperationResult<(Vertex,)> {
let vertex = vertex.into();
) -> OperationResult<(Handle<Vertex>,)> {
let vertex = Handle::new(vertex.into());
self.operations.push(OperationInSequence {
operation: HandleAny::new(vertex),
operation: vertex.to_any(),
previous: self
.operations
.last()
@ -124,7 +124,7 @@ impl<'r, T> OperationResult<'r, T> {
vertex: impl Into<Vertex>,
) -> OperationResult<'r, T::Out>
where
T: CombinRight<Vertex>,
T: CombinRight<Handle<Vertex>>,
{
let OperationResult {
results: (vertex,), ..

View File

@ -12,6 +12,9 @@ pub fn model(shape: &mut Shape) {
.vertex([0.5, 0.5, 0.5])
.results();
let [a, b, c, d, e, f, g, h] =
[a, b, c, d, e, f, g, h].map(|vertex| vertex.get());
shape
.triangle([a, e, g]) // left
.triangle([a, g, c])