Skip to content

Commit 2974887

Browse files
committed
Restructure document node implementation
* Implement topological sort * Enforce the usage of type annotations * Add complete test case
1 parent 1a4a0db commit 2974887

File tree

12 files changed

+663
-385
lines changed

12 files changed

+663
-385
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node-graph/gcore/src/ops.rs

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,21 @@ impl<'n, L: Add<R, Output = O> + 'n + Copy, R: Copy, O: 'n> Node<&'n (L, R)> for
3030
}
3131
}
3232

33-
// Unfortunatly we can't impl the AddNode as we get
34-
// `upstream crates may add a new impl of trait `core::ops::Add` for type `alloc::boxed::Box<(dyn dyn_any::DynAny<'_> + 'static)>` in future versions`
35-
pub struct DynamicAddNode;
33+
#[cfg(feature = "std")]
34+
pub mod dynamic {
35+
use super::*;
36+
37+
// Unfortunatly we can't impl the AddNode as we get
38+
// `upstream crates may add a new impl of trait `core::ops::Add` for type `alloc::boxed::Box<(dyn dyn_any::DynAny<'_> + 'static)>` in future versions`
39+
pub struct DynamicAddNode;
3640

37-
// Alias for a dynamic type
38-
pub type Dynamic<'a> = alloc::boxed::Box<dyn dyn_any::DynAny<'a> + 'a>;
41+
// Alias for a dynamic type
42+
pub type Dynamic<'a> = alloc::boxed::Box<dyn dyn_any::DynAny<'a> + 'a>;
3943

40-
/// Resolves the dynamic types for a dynamic node.
41-
///
42-
/// Macro uses format `BaseNode => (arg1: u32) (arg1: i32)`
43-
macro_rules! resolve_dynamic_types {
44+
/// Resolves the dynamic types for a dynamic node.
45+
///
46+
/// Macro uses format `BaseNode => (arg1: u32) (arg1: i32)`
47+
macro_rules! resolve_dynamic_types {
4448
($node:ident => $(($($arg:ident : $t:ty),*))*) => {
4549
$(
4650
// Check for each possible set of arguments if their types match the arguments given
@@ -55,24 +59,25 @@ macro_rules! resolve_dynamic_types {
5559
};
5660
}
5761

58-
impl<'n> Node<(Dynamic<'n>, Dynamic<'n>)> for DynamicAddNode {
59-
type Output = Dynamic<'n>;
60-
fn eval(self, (left, right): (Dynamic, Dynamic)) -> Self::Output {
61-
resolve_dynamic_types! { AddNode =>
62-
(left: usize, right: usize)
63-
(left: u8, right: u8)
64-
(left: u16, right: u16)
65-
(left: u32, right: u32)
66-
(left: u64, right: u64)
67-
(left: u128, right: u128)
68-
(left: isize, right: isize)
69-
(left: i8, right: i8)
70-
(left: i16, right: i16)
71-
(left: i32, right: i32)
72-
(left: i64, right: i64)
73-
(left: i128, right: i128)
74-
(left: f32, right: f32)
75-
(left: f64, right: f64) }
62+
impl<'n> Node<(Dynamic<'n>, Dynamic<'n>)> for DynamicAddNode {
63+
type Output = Dynamic<'n>;
64+
fn eval(self, (left, right): (Dynamic, Dynamic)) -> Self::Output {
65+
resolve_dynamic_types! { AddNode =>
66+
(left: usize, right: usize)
67+
(left: u8, right: u8)
68+
(left: u16, right: u16)
69+
(left: u32, right: u32)
70+
(left: u64, right: u64)
71+
(left: u128, right: u128)
72+
(left: isize, right: isize)
73+
(left: i8, right: i8)
74+
(left: i16, right: i16)
75+
(left: i32, right: i32)
76+
(left: i64, right: i64)
77+
(left: i128, right: i128)
78+
(left: f32, right: f32)
79+
(left: f64, right: f64) }
80+
}
7681
}
7782
}
7883

node-graph/gcore/src/raster/color.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(feature = "std")]
12
use dyn_any::{DynAny, StaticType};
23
use serde::{Deserialize, Serialize};
34

@@ -6,7 +7,8 @@ use serde::{Deserialize, Serialize};
67
/// The other components (RGB) are stored as `f32` that range from `0.0` up to `f32::MAX`,
78
/// the values encode the brightness of each channel proportional to the light intensity in cd/m² (nits) in HDR, and `0.0` (black) to `1.0` (white) in SDR color.
89
#[repr(C)]
9-
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize, DynAny)]
10+
#[cfg_attr(feature = "std", derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize, DynAny))]
11+
#[cfg_attr(not(feature = "std"), derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize))]
1012
pub struct Color {
1113
red: f32,
1214
green: f32,

node-graph/graph-craft/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ dyn-any = { path = "../../libraries/dyn-any" }
1313
num-traits = "0.2"
1414
borrow_stack = { path = "../borrow_stack" }
1515
dyn-clone = "1.0"
16+
rand_chacha = "0.3.1"

0 commit comments

Comments
 (0)