mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Code review, remove identity test
This commit is contained in:
@@ -1,6 +1,30 @@
|
||||
use crate::Node;
|
||||
use crate::{
|
||||
Node,
|
||||
registry::{Any, DynFuture, SharedNodeContainer},
|
||||
};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub struct IdentityNode {
|
||||
value: SharedNodeContainer,
|
||||
}
|
||||
|
||||
impl<'i> Node<'i, Any<'i>> for IdentityNode {
|
||||
type Output = DynFuture<'i, Any<'i>>;
|
||||
fn eval(&'i self, input: Any<'i>) -> Self::Output {
|
||||
Box::pin(async move { self.value.eval(input).await })
|
||||
}
|
||||
}
|
||||
|
||||
impl IdentityNode {
|
||||
pub const fn new(value: SharedNodeContainer) -> Self {
|
||||
IdentityNode { value }
|
||||
}
|
||||
}
|
||||
|
||||
pub mod identity {
|
||||
pub const IDENTIFIER: crate::ProtoNodeIdentifier = crate::ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode");
|
||||
}
|
||||
|
||||
// Type
|
||||
// TODO: Document this
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||
@@ -135,13 +159,3 @@ impl<'input, I: 'input + Convert<_O> + Sync + Send, _O: 'input> Node<'input, I>
|
||||
Box::pin(async move { input.convert() })
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
pub fn identity_node() {
|
||||
assert_eq!(identity(&4), &4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use glam::IVec2;
|
||||
use graphene_core::memo::MemoHashGuard;
|
||||
pub use graphene_core::uuid::NodeId;
|
||||
pub use graphene_core::uuid::generate_uuid;
|
||||
use graphene_core::{Cow, MemoHash, ProtoNodeIdentifier, Type};
|
||||
use graphene_core::{Cow, MemoHash, ProtoNodeIdentifier, Type, ops};
|
||||
use log::Metadata;
|
||||
use rustc_hash::FxHashMap;
|
||||
use std::collections::HashMap;
|
||||
@@ -460,7 +460,7 @@ pub enum DocumentNodeImplementation {
|
||||
|
||||
impl Default for DocumentNodeImplementation {
|
||||
fn default() -> Self {
|
||||
Self::ProtoNode(ProtoNodeIdentifier::new("graphene_std::any::IdentityNode"))
|
||||
Self::ProtoNode(ops::identity::IDENTIFIER)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -916,7 +916,7 @@ impl NodeNetwork {
|
||||
return;
|
||||
};
|
||||
// If the node is hidden, replace it with an identity node
|
||||
let identity_node = DocumentNodeImplementation::ProtoNode("graphene_std::any::IdentityNode".into());
|
||||
let identity_node = DocumentNodeImplementation::ProtoNode(ops::identity::IDENTIFIER);
|
||||
if !node.visible && node.implementation != identity_node {
|
||||
node.implementation = identity_node;
|
||||
|
||||
@@ -1092,7 +1092,7 @@ impl NodeNetwork {
|
||||
fn remove_id_node(&mut self, id: NodeId) -> Result<(), String> {
|
||||
let node = self.nodes.get(&id).ok_or_else(|| format!("Node with id {id} does not exist"))?.clone();
|
||||
if let DocumentNodeImplementation::ProtoNode(ident) = &node.implementation {
|
||||
if ident.name == "graphene_std::any::IdentityNode" {
|
||||
if ident.name == ops::identity::IDENTIFIER.name {
|
||||
assert_eq!(node.inputs.len(), 1, "Id node has more than one input");
|
||||
if let NodeInput::Node { node_id, output_index, .. } = node.inputs[0] {
|
||||
let node_input_output_index = output_index;
|
||||
@@ -1139,13 +1139,13 @@ impl NodeNetwork {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Strips out any [`graphene_std::any::IdentityNode`]s that are unnecessary.
|
||||
/// Strips out any [`graphene_std::ops::IdentityNode`]s that are unnecessary.
|
||||
pub fn remove_redundant_id_nodes(&mut self) {
|
||||
let id_nodes = self
|
||||
.nodes
|
||||
.iter()
|
||||
.filter(|(_, node)| {
|
||||
matches!(&node.implementation, DocumentNodeImplementation::ProtoNode(ident) if ident == &ProtoNodeIdentifier::new("graphene_std::any::IdentityNode"))
|
||||
matches!(&node.implementation, DocumentNodeImplementation::ProtoNode(ident) if ident == &ops::identity::IDENTIFIER)
|
||||
&& node.inputs.len() == 1
|
||||
&& matches!(node.inputs[0], NodeInput::Node { .. })
|
||||
})
|
||||
@@ -1333,7 +1333,7 @@ mod test {
|
||||
fn extract_node() {
|
||||
let id_node = DocumentNode {
|
||||
inputs: vec![],
|
||||
implementation: DocumentNodeImplementation::ProtoNode("graphene_std::any::IdentityNode".into()),
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ops::identity::IDENTIFIER),
|
||||
..Default::default()
|
||||
};
|
||||
// TODO: Extend test cases to test nested network
|
||||
@@ -1535,13 +1535,7 @@ mod test {
|
||||
NodeId(1),
|
||||
DocumentNode {
|
||||
inputs: vec![NodeInput::network(concrete!(u32), 0)],
|
||||
<<<<<<< HEAD
|
||||
implementation: DocumentNodeImplementation::ProtoNode(graphene_core::ops::identity::IDENTIFIER),
|
||||
||||||| parent of 8e045313 (Migrate pass through and value node to identity implementation)
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
|
||||
=======
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::any::IdentityNode")),
|
||||
>>>>>>> 8e045313 (Migrate pass through and value node to identity implementation)
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
@@ -1549,13 +1543,7 @@ mod test {
|
||||
NodeId(2),
|
||||
DocumentNode {
|
||||
inputs: vec![NodeInput::network(concrete!(u32), 1)],
|
||||
<<<<<<< HEAD
|
||||
implementation: DocumentNodeImplementation::ProtoNode(graphene_core::ops::identity::IDENTIFIER),
|
||||
||||||| parent of 8e045313 (Migrate pass through and value node to identity implementation)
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
|
||||
=======
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::any::IdentityNode")),
|
||||
>>>>>>> 8e045313 (Migrate pass through and value node to identity implementation)
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
@@ -1582,13 +1570,7 @@ mod test {
|
||||
NodeId(2),
|
||||
DocumentNode {
|
||||
inputs: vec![result_node_input],
|
||||
<<<<<<< HEAD
|
||||
implementation: DocumentNodeImplementation::ProtoNode(graphene_core::ops::identity::IDENTIFIER),
|
||||
||||||| parent of 8e045313 (Migrate pass through and value node to identity implementation)
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
|
||||
=======
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::any::IdentityNode")),
|
||||
>>>>>>> 8e045313 (Migrate pass through and value node to identity implementation)
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
|
||||
@@ -143,7 +143,7 @@ pub struct ProtoNode {
|
||||
impl Default for ProtoNode {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
identifier: ProtoNodeIdentifier::new("graphene_std::any::IdentityNode"),
|
||||
identifier: ops::identity::IDENTIFIER,
|
||||
construction_args: ConstructionArgs::Value(value::TaggedValue::U32(0).into()),
|
||||
input: ProtoNodeInput::None,
|
||||
original_location: OriginalLocation::default(),
|
||||
|
||||
@@ -46,20 +46,3 @@ pub fn input_node<O: StaticType>(n: SharedNodeContainer) -> DowncastBothNode<(),
|
||||
pub fn downcast_node<I: StaticType, O: StaticType>(n: SharedNodeContainer) -> DowncastBothNode<I, O> {
|
||||
DowncastBothNode::new(n)
|
||||
}
|
||||
|
||||
pub struct IdentityNode {
|
||||
value: SharedNodeContainer,
|
||||
}
|
||||
|
||||
impl<'i> Node<'i, Any<'i>> for IdentityNode {
|
||||
type Output = DynFuture<'i, Any<'i>>;
|
||||
fn eval(&'i self, input: Any<'i>) -> Self::Output {
|
||||
Box::pin(async move { self.value.eval(input).await })
|
||||
}
|
||||
}
|
||||
|
||||
impl IdentityNode {
|
||||
pub const fn new(value: SharedNodeContainer) -> Self {
|
||||
IdentityNode { value }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,7 @@ mod tests {
|
||||
NodeId(0),
|
||||
DocumentNode {
|
||||
inputs: vec![NodeInput::network(concrete!(u32), 0)],
|
||||
<<<<<<< HEAD
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ops::identity::IDENTIFIER),
|
||||
||||||| parent of 8e045313 (Migrate pass through and value node to identity implementation)
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
|
||||
=======
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::any::IdentityNode")),
|
||||
>>>>>>> 8e045313 (Migrate pass through and value node to identity implementation)
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
|
||||
@@ -14,8 +14,9 @@ use graphene_std::Context;
|
||||
use graphene_std::GraphicElement;
|
||||
#[cfg(feature = "gpu")]
|
||||
use graphene_std::any::DowncastBothNode;
|
||||
use graphene_std::any::{ComposeTypeErased, DynAnyNode, IdentityNode, IntoTypeErasedNode};
|
||||
use graphene_std::any::{ComposeTypeErased, DynAnyNode, IntoTypeErasedNode};
|
||||
use graphene_std::application_io::{ImageTexture, SurfaceFrame};
|
||||
use graphene_std::ops::IdentityNode;
|
||||
#[cfg(feature = "gpu")]
|
||||
use graphene_std::wasm_application_io::{WasmEditorApi, WasmSurfaceHandle};
|
||||
use node_registry_macros::{async_node, convert_node, into_node};
|
||||
@@ -115,7 +116,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
|
||||
),
|
||||
),
|
||||
(
|
||||
ProtoNodeIdentifier::new("graphene_std::any::IdentityNode"),
|
||||
graphene_std::ops::identity::IDENTIFIER,
|
||||
|args| {
|
||||
Box::pin(async move {
|
||||
let node = IdentityNode::new(args[0].clone());
|
||||
|
||||
@@ -68,13 +68,7 @@ pub fn wrap_network_in_scope(mut network: NodeNetwork, editor_api: Arc<WasmEdito
|
||||
inner_network,
|
||||
render_node,
|
||||
DocumentNode {
|
||||
<<<<<<< HEAD
|
||||
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::ops::identity::IDENTIFIER),
|
||||
||||||| parent of 8e045313 (Migrate pass through and value node to identity implementation)
|
||||
implementation: DocumentNodeImplementation::proto("graphene_core::ops::IdentityNode"),
|
||||
=======
|
||||
implementation: DocumentNodeImplementation::proto("graphene_std::any::IdentityNode"),
|
||||
>>>>>>> 8e045313 (Migrate pass through and value node to identity implementation)
|
||||
inputs: vec![NodeInput::value(TaggedValue::EditorApi(editor_api), false)],
|
||||
..Default::default()
|
||||
},
|
||||
|
||||
@@ -49,13 +49,7 @@ pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNod
|
||||
let input_count = inputs.len();
|
||||
let network_inputs = (0..input_count).map(|i| NodeInput::node(NodeId(i as u64), 0)).collect();
|
||||
|
||||
<<<<<<< HEAD
|
||||
let identity_node = ops::identity::IDENTIFIER;
|
||||
||||||| parent of 8e045313 (Migrate pass through and value node to identity implementation)
|
||||
let identity_node = ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode");
|
||||
=======
|
||||
let identity_node = ProtoNodeIdentifier::new("graphene_std::any::IdentityNode");
|
||||
>>>>>>> 8e045313 (Migrate pass through and value node to identity implementation)
|
||||
|
||||
let into_node_registry = &interpreted_executor::node_registry::NODE_REGISTRY;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user