Skip to content

Commit

Permalink
Update Handle<T>, so that T is the output type
Browse files Browse the repository at this point in the history
`Handle<T>` is a type that serves as a handle (as the name suggests) for
operations. So far, the operation that a `Handle<T>` referred to, was
always of type `T`. This is a problem, given what I'm trying to do with
operations in this experiment.

Unlike the current mainline code, where operations are just
"code that transforms objects", I want to reify operations. They should
be concrete things that you can see (right now, in the debug viewer's
operation tree) and (later on) refer to and build upon.

Let's use the example of translating faces, to understand what the
problem is.

If the translate operation is just a piece of code that transforms one
face into another, then any other operation that expects to operate on a
face can receive the output of that operation. Because it's just a face.

But if the translate operation is a concrete thing in a tree of
operations, then it's not as simple. Because that other operation, that
expects to operate on a face, it can't _just_ operate on faces. It needs
to be able to operate on any nested operation that _produces_ a face.
Like our example translate operation.

And this is what this change to `Handle<T>` enables. Where previously,
its type would have been `Handle<Translate>`, because `Translate` (in
this example) is the operation it refers to; it's now `Handle<Face>`,
because `Face` is the output that `Translate` produces.

So this new version of `Handle<T>` abstracts over the concrete operation
it refers to, only exposing what that operation's output is. That means
our example `Translate` operation can now be treated just like a `Face`,
or any other operation that produces a `Face`.
  • Loading branch information
hannobraun committed Feb 10, 2025
1 parent d8c5117 commit 4083d2b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
16 changes: 5 additions & 11 deletions experiments/2024-12-09/src/geometry/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,21 @@ impl fmt::Display for OperationDisplay<'_> {
}

pub struct Handle<T> {
inner: Rc<T>,
inner: Rc<dyn OperationOutput<T>>,
}

impl<T> Handle<T> {
pub fn new(inner: T) -> Self {
pub fn new(inner: impl OperationOutput<T> + 'static) -> Self {
Self {
inner: Rc::new(inner),
}
}

pub fn to_any(&self) -> AnyOp
where
T: Operation + 'static,
{
pub fn to_any(&self) -> AnyOp {
self.clone().into_any()
}

pub fn into_any(self) -> AnyOp
where
T: Operation + 'static,
{
pub fn into_any(self) -> AnyOp {
AnyOp { inner: self.inner }
}
}
Expand All @@ -67,7 +61,7 @@ impl<T> Deref for Handle<T> {
type Target = T;

fn deref(&self) -> &T {
self.inner.as_ref()
self.inner.output()
}
}

Expand Down
8 changes: 2 additions & 6 deletions experiments/2024-12-09/src/topology/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ use crate::{
math::Vector,
};

use super::{
connect::{Connect, ConnectExt},
face::Face,
solid::Solid,
};
use super::{connect::ConnectExt, face::Face, solid::Solid};

pub trait SweepExt {
/// # Sweep a face along a path, creating a solid
Expand Down Expand Up @@ -39,7 +35,7 @@ impl SweepExt for Handle<Face> {
}

pub struct Sweep {
pub output: Handle<Connect>,
pub output: Handle<Solid>,
}

impl Operation for Sweep {
Expand Down

0 comments on commit 4083d2b

Please sign in to comment.