mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Refactor the node macro and simply most of the node implementations (#1942)
* Add support structure for new node macro to gcore * Fix compile issues and code generation * Implement new node_fn macro * Implement property translation * Fix NodeIO type generation * Start translating math nodes * Move node implementation to outer scope to allow usage of local imports * Add expose attribute to allow controlling the parameter exposure * Add rust analyzer support for #[implementations] attribute * Migrate logic nodes * Handle where clause properly * Implement argument ident pattern preservation * Implement adjustment layer mapping * Fix node registry types * Fix module paths * Improve demo artwork comptibility * Improve macro error reporting * Fix handling of impl node implementations * Fix nodeio type computation * Fix opacity node and graph type resolution * Fix loading of demo artworks * Fix eslint * Fix typo in macro test * Remove node definitions for Adjustment Nodes * Fix type alias property generation and make adjustments footprint aware * Convert vector nodes * Implement path overrides * Fix stroke node * Fix painted dreams * Implement experimental type level specialization * Fix poisson disk sampling -> all demo artworks should work again * Port text node + make node macro more robust by implementing lifetime substitution * Fix vector node tests * Fix red dress demo + ci * Fix clippy warnings * Code review * Fix primary input issues * Improve math nodes and audit others * Set no_properties when no automatic properties are derived * Port vector generator nodes (could not derive all definitions yet) * Various QA changes and add min/max/mode_range to number parameters * Add min and max for f64 and u32 * Convert gpu nodes and clean up unused nodes * Partially port transform node * Allow implementations on call arg * Port path modify node * Start porting graphic element nodes * Transform nodes in graphic_element.rs * Port brush node * Port nodes in wasm_executior * Rename node macro * Fix formatting * Fix Mandelbrot node * Formatting * Fix Load Image and Load Resource nodes, add scope input to node macro * Remove unnecessary underscores * Begin attemping to make nodes resolution-aware * Infer a generic manual compositon type on generic call arg * Various fixes and work towards merging * Final changes for merge! * Fix tests, probably * More free line removals! --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use crate::{Node, NodeMut};
|
||||
use crate::Node;
|
||||
|
||||
/// This is how we can generically define composition of two nodes.
|
||||
/// This is done generically as shown: <https://files.keavon.com/-/SurprisedGaseousAnhinga/capture.png>
|
||||
@@ -42,18 +42,6 @@ where
|
||||
second.eval(arg)
|
||||
}
|
||||
}
|
||||
impl<'i, 'f: 'i, 's: 'i, Input: 'i, First, Second> NodeMut<'i, Input> for ComposeNode<First, Second, Input>
|
||||
where
|
||||
First: Node<'i, Input>,
|
||||
Second: NodeMut<'i, <First as Node<'i, Input>>::Output> + 'i,
|
||||
{
|
||||
type MutOutput = <Second as NodeMut<'i, <First as Node<'i, Input>>::Output>>::MutOutput;
|
||||
fn eval_mut(&'i mut self, input: Input) -> Self::MutOutput {
|
||||
let arg = self.first.eval(input);
|
||||
let second = &mut self.second;
|
||||
second.eval_mut(arg)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'i, First, Second, Input: 'i> ComposeNode<First, Second, Input> {
|
||||
pub const fn new(first: First, second: Second) -> Self {
|
||||
@@ -141,38 +129,6 @@ impl<'i, Root: Node<'i, I>, I: 'i + From<()>> ConsNode<I, Root> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ApplyNode<O, N> {
|
||||
pub node: N,
|
||||
_o: PhantomData<O>,
|
||||
}
|
||||
/*
|
||||
#[node_macro::node_fn(ApplyNode)]
|
||||
fn apply<In, N>(input: In, node: &'any_input N) -> ()
|
||||
where
|
||||
// TODO: try to allows this to return output other than ()
|
||||
N: for<'any_input> Node<'any_input, In, Output = ()>,
|
||||
{
|
||||
node.eval(input)
|
||||
}
|
||||
*/
|
||||
impl<'input, In: 'input, N: 'input, S0: 'input, O: 'input> Node<'input, In> for ApplyNode<O, S0>
|
||||
where
|
||||
N: Node<'input, In, Output = O>,
|
||||
S0: Node<'input, (), Output = &'input N>,
|
||||
{
|
||||
type Output = <N as Node<'input, In>>::Output;
|
||||
#[inline]
|
||||
fn eval(&'input self, input: In) -> Self::Output {
|
||||
let node = self.node.eval(());
|
||||
node.eval(input)
|
||||
}
|
||||
}
|
||||
impl<'input, S0: 'input, O: 'static> ApplyNode<O, S0> {
|
||||
pub const fn new(node: S0) -> Self {
|
||||
Self { node, _o: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
@@ -198,16 +154,4 @@ mod test {
|
||||
|
||||
assert_eq!(compose.eval(()), &5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(clippy::unit_cmp)]
|
||||
fn test_apply() {
|
||||
let mut array = [1, 2, 3];
|
||||
let slice = &mut array;
|
||||
let set_node = crate::storage::SetOwnedNode::new(slice);
|
||||
|
||||
let apply = ApplyNode::new(ValueNode::new(set_node));
|
||||
|
||||
assert_eq!(apply.eval((1, 2)), ());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user