Convert u64 IDs to newtypes (#1532)

This commit is contained in:
Keavon Chambers
2023-12-22 03:24:13 -08:00
committed by GitHub
parent 7bfe0ce55b
commit 34f952bad1
38 changed files with 565 additions and 446 deletions
@@ -174,8 +174,8 @@ fn root_network() -> NodeNetwork {
name: "Output".into(),
inputs: vec![NodeInput::value(TaggedValue::GraphicGroup(Default::default()), true), NodeInput::Network(concrete!(WasmEditorApi))],
implementation: graph_craft::document::DocumentNodeImplementation::Network(NodeNetwork {
inputs: vec![3, 0],
outputs: vec![NodeOutput::new(3, 0)],
inputs: vec![NodeId(3), NodeId(0)],
outputs: vec![NodeOutput::new(NodeId(3), 0)],
nodes: [
DocumentNode {
name: "EditorApi".to_string(),
@@ -185,7 +185,7 @@ fn root_network() -> NodeNetwork {
},
DocumentNode {
name: "Create Canvas".to_string(),
inputs: vec![NodeInput::node(0, 0)],
inputs: vec![NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_std::wasm_application_io::CreateSurfaceNode")),
skip_deduplication: true,
..Default::default()
@@ -193,16 +193,16 @@ fn root_network() -> NodeNetwork {
DocumentNode {
name: "Cache".to_string(),
manual_composition: Some(concrete!(())),
inputs: vec![NodeInput::node(1, 0)],
inputs: vec![NodeInput::node(NodeId(1), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode<_, _>")),
..Default::default()
},
DocumentNode {
name: "RenderNode".to_string(),
inputs: vec![
NodeInput::node(0, 0),
NodeInput::node(NodeId(0), 0),
NodeInput::Network(graphene_core::Type::Fn(Box::new(concrete!(Footprint)), Box::new(generic!(T)))),
NodeInput::node(2, 0),
NodeInput::node(NodeId(2), 0),
],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_std::wasm_application_io::RenderNode<_, _, _>")),
..Default::default()
@@ -210,7 +210,7 @@ fn root_network() -> NodeNetwork {
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
}),
@@ -345,7 +345,7 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
}
CommitTransaction => (),
CreateEmptyFolder { parent } => {
let id = generate_uuid();
let id = NodeId(generate_uuid());
responses.add(GraphOperationMessage::NewCustomLayer {
id,
@@ -416,7 +416,7 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
// TODO: Add code that changes the insert index of the new folder based on the selected layer
let parent = self.metadata().deepest_common_ancestor(self.metadata().selected_layers(), true).unwrap_or(LayerNodeIdentifier::ROOT);
let folder_id = generate_uuid();
let folder_id = NodeId(generate_uuid());
responses.add(PortfolioMessage::Copy { clipboard: Clipboard::Internal });
responses.add(DocumentMessage::DeleteSelectedLayers);
@@ -547,7 +547,7 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
let image_frame = ImageFrame { image, ..Default::default() };
use crate::messages::tool::common_functionality::graph_modification_utils;
let layer = graph_modification_utils::new_image_layer(image_frame, generate_uuid(), self.new_layer_parent(), responses);
let layer = graph_modification_utils::new_image_layer(image_frame, NodeId(generate_uuid()), self.new_layer_parent(), responses);
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: vec![layer.to_node()] });
@@ -907,14 +907,14 @@ impl DocumentMessageHandler {
path.push(layer_node);
// TODO: Skip if folder is not expanded.
structure.push(LayerNodeIdentifier::new_unchecked(space));
structure.push(LayerNodeIdentifier::new_unchecked(NodeId(space)));
self.serialize_structure(layer_node, structure, data, path);
space = 0;
path.pop();
}
}
structure.push(LayerNodeIdentifier::new_unchecked(space | 1 << 63));
structure.push(LayerNodeIdentifier::new_unchecked(NodeId(space | 1 << 63)));
}
/// Serializes the layer structure into a condensed 1D structure.
@@ -954,10 +954,10 @@ impl DocumentMessageHandler {
let mut data = Vec::new();
self.serialize_structure(self.metadata().root(), &mut structure, &mut data, &mut vec![]);
structure[0] = LayerNodeIdentifier::new_unchecked(structure.len() as NodeId - 1);
structure[0] = LayerNodeIdentifier::new_unchecked(NodeId(structure.len() as u64 - 1));
structure.extend(data);
structure.iter().map(|id| id.to_node()).collect::<Vec<_>>().as_slice().into()
structure.iter().map(|id| id.to_node().0).collect::<Vec<_>>().as_slice().into()
}
/// Places a document into the history system
@@ -118,7 +118,7 @@ impl<'a> ModifyInputsContext<'a> {
} else {
// The user has connected another node to the output. Insert a layer node between the output and the node.
let node = resolve_document_node_type("Layer").expect("Layer node").default_document_node();
let node_id = self.insert_between(generate_uuid(), NodeOutput::new(node_id, output_index), output, node, 0, 0, IVec2::new(-8, 0))?;
let node_id = self.insert_between(NodeId(generate_uuid()), NodeOutput::new(node_id, output_index), output, node, 0, 0, IVec2::new(-8, 0))?;
sibling_layer = Some(NodeOutput::new(node_id, 0));
}
@@ -182,7 +182,7 @@ impl<'a> ModifyInputsContext<'a> {
Default::default(),
);
self.responses.add(NodeGraphMessage::SendGraph { should_rerender: true });
self.insert_node_before(generate_uuid(), layer, 0, artboard_node, IVec2::new(-8, 0))
self.insert_node_before(NodeId(generate_uuid()), layer, 0, artboard_node, IVec2::new(-8, 0))
}
fn insert_vector_data(&mut self, subpaths: Vec<Subpath<ManipulatorGroupId>>, layer: NodeId) {
@@ -195,15 +195,15 @@ impl<'a> ModifyInputsContext<'a> {
let fill = resolve_document_node_type("Fill").expect("Fill node does not exist").default_document_node();
let stroke = resolve_document_node_type("Stroke").expect("Stroke node does not exist").default_document_node();
let stroke_id = generate_uuid();
let stroke_id = NodeId(generate_uuid());
self.insert_node_before(stroke_id, layer, 0, stroke, IVec2::new(-8, 0));
let fill_id = generate_uuid();
let fill_id = NodeId(generate_uuid());
self.insert_node_before(fill_id, stroke_id, 0, fill, IVec2::new(-8, 0));
let transform_id = generate_uuid();
let transform_id = NodeId(generate_uuid());
self.insert_node_before(transform_id, fill_id, 0, transform, IVec2::new(-8, 0));
let cull_id = generate_uuid();
let cull_id = NodeId(generate_uuid());
self.insert_node_before(cull_id, transform_id, 0, cull, IVec2::new(-8, 0));
let shape_id = generate_uuid();
let shape_id = NodeId(generate_uuid());
self.insert_node_before(shape_id, cull_id, 0, shape, IVec2::new(-8, 0));
self.responses.add(NodeGraphMessage::SendGraph { should_rerender: true });
}
@@ -223,15 +223,15 @@ impl<'a> ModifyInputsContext<'a> {
let fill = resolve_document_node_type("Fill").expect("Fill node does not exist").default_document_node();
let stroke = resolve_document_node_type("Stroke").expect("Stroke node does not exist").default_document_node();
let stroke_id = generate_uuid();
let stroke_id = NodeId(generate_uuid());
self.insert_node_before(stroke_id, layer, 0, stroke, IVec2::new(-8, 0));
let fill_id = generate_uuid();
let fill_id = NodeId(generate_uuid());
self.insert_node_before(fill_id, stroke_id, 0, fill, IVec2::new(-8, 0));
let transform_id = generate_uuid();
let transform_id = NodeId(generate_uuid());
self.insert_node_before(transform_id, fill_id, 0, transform, IVec2::new(-8, 0));
let cull_id = generate_uuid();
let cull_id = NodeId(generate_uuid());
self.insert_node_before(cull_id, transform_id, 0, cull, IVec2::new(-8, 0));
let text_id = generate_uuid();
let text_id = NodeId(generate_uuid());
self.insert_node_before(text_id, cull_id, 0, text, IVec2::new(-8, 0));
self.responses.add(NodeGraphMessage::SendGraph { should_rerender: true });
}
@@ -244,11 +244,11 @@ impl<'a> ModifyInputsContext<'a> {
let sample = resolve_document_node_type("Sample").expect("Sample node does not exist").default_document_node();
let transform = resolve_document_node_type("Transform").expect("Transform node does not exist").default_document_node();
let transform_id = generate_uuid();
let transform_id = NodeId(generate_uuid());
self.insert_node_before(transform_id, layer, 0, transform, IVec2::new(-8, 0));
let sample_id = generate_uuid();
let sample_id = NodeId(generate_uuid());
self.insert_node_before(sample_id, transform_id, 0, sample, IVec2::new(-8, 0));
let image_id = generate_uuid();
let image_id = NodeId(generate_uuid());
self.insert_node_before(image_id, sample_id, 0, image, IVec2::new(-8, 0));
self.responses.add(NodeGraphMessage::SendGraph { should_rerender: true });
}
@@ -283,7 +283,7 @@ impl<'a> ModifyInputsContext<'a> {
let metadata = output_node.metadata.clone();
let new_input = output_node.inputs.first().cloned().filter(|input| input.as_node().is_some());
let node_id = generate_uuid();
let node_id = NodeId(generate_uuid());
output_node.inputs[0] = NodeInput::node(node_id, 0);
@@ -678,10 +678,10 @@ impl MessageHandler<GraphOperationMessage, (&mut NodeNetwork, &mut DocumentMetad
let mut modify_inputs = ModifyInputsContext::new(document_network, document_metadata, node_graph, responses);
if let Some(layer) = modify_inputs.create_layer_with_insert_index(id, insert_index, parent) {
let new_ids: HashMap<_, _> = nodes.iter().map(|(&id, _)| (id, crate::application::generate_uuid())).collect();
let new_ids: HashMap<_, _> = nodes.iter().map(|(&id, _)| (id, NodeId(generate_uuid()))).collect();
let shift = nodes
.get(&0)
.get(&NodeId(0))
.and_then(|node| {
modify_inputs
.document_network
@@ -704,7 +704,7 @@ impl MessageHandler<GraphOperationMessage, (&mut NodeNetwork, &mut DocumentMetad
}
if let Some(layer_node) = modify_inputs.document_network.nodes.get_mut(&layer) {
if let Some(&input) = new_ids.get(&0) {
if let Some(&input) = new_ids.get(&NodeId(0)) {
layer_node.inputs[0] = NodeInput::node(input, 0)
}
}
@@ -1,5 +1,6 @@
pub use self::document_node_types::*;
use super::load_network_structure;
use crate::application::generate_uuid;
use crate::messages::input_mapper::utility_types::macros::action_keys;
use crate::messages::layout::utility_types::widget_prelude::*;
use crate::messages::portfolio::document::utility_types::document_metadata::{DocumentMetadata, LayerNodeIdentifier};
@@ -512,7 +513,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
};
// Collect the selected nodes
let new_ids = &metadata.selected_nodes().copied().enumerate().map(|(new, old)| (old, new as NodeId)).collect();
let new_ids = &metadata.selected_nodes().copied().enumerate().map(|(new, old)| (old, NodeId(new as u64))).collect();
let copied_nodes: Vec<_> = Self::copy_nodes(network, new_ids).collect();
// Prefix to show that this is nodes
@@ -522,7 +523,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
responses.add(FrontendMessage::TriggerTextCopy { copy_text });
}
NodeGraphMessage::CreateNode { node_id, node_type, x, y } => {
let node_id = node_id.unwrap_or_else(crate::application::generate_uuid);
let node_id = node_id.unwrap_or_else(|| NodeId(generate_uuid()));
let Some(document_node_type) = document_node_types::resolve_document_node_type(&node_type) else {
responses.add(DialogMessage::DisplayDialogError {
@@ -608,7 +609,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
if let Some(network) = document_network.nested_network(&self.network) {
responses.add(DocumentMessage::StartTransaction);
let new_ids = &metadata.selected_nodes().map(|&id| (id, crate::application::generate_uuid())).collect();
let new_ids = &metadata.selected_nodes().map(|&id| (id, NodeId(generate_uuid()))).collect();
metadata.clear_selected_nodes();
responses.add(BroadcastEvent::SelectionChanged);
@@ -722,7 +723,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
responses.add(DocumentMessage::StartTransaction);
let new_ids: HashMap<_, _> = data.iter().map(|&(id, _)| (id, crate::application::generate_uuid())).collect();
let new_ids: HashMap<_, _> = data.iter().map(|&(id, _)| (id, NodeId(generate_uuid()))).collect();
for (old_id, mut document_node) in data {
// Shift copied node
document_node.metadata.position += shift;
@@ -203,11 +203,11 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "Layer",
category: "General",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![0, 2],
outputs: vec![NodeOutput::new(2, 0)],
inputs: vec![NodeId(0), NodeId(2)],
outputs: vec![NodeOutput::new(NodeId(2), 0)],
nodes: [
(
0,
NodeId(0),
DocumentNode {
name: "To Graphic Element".to_string(),
inputs: vec![NodeInput::Network(generic!(T))],
@@ -217,19 +217,19 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
),
// The monitor node is used to display a thumbnail in the UI.
(
1,
NodeId(1),
DocumentNode {
inputs: vec![NodeInput::node(0, 0)],
inputs: vec![NodeInput::node(NodeId(0), 0)],
..monitor_node()
},
),
(
2,
NodeId(2),
DocumentNode {
name: "ConstructLayer".to_string(),
manual_composition: Some(concrete!(Footprint)),
inputs: vec![
NodeInput::node(1, 0),
NodeInput::node(NodeId(1), 0),
NodeInput::Network(graphene_core::Type::Fn(Box::new(concrete!(Footprint)), Box::new(concrete!(graphene_core::GraphicGroup)))),
],
implementation: DocumentNodeImplementation::proto("graphene_core::ConstructLayerNode<_, _>"),
@@ -284,8 +284,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "Load Image",
category: "Structural",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![0, 0],
outputs: vec![NodeOutput::new(1, 0)],
inputs: vec![NodeId(0), NodeId(0)],
outputs: vec![NodeOutput::new(NodeId(1), 0)],
nodes: [
DocumentNode {
name: "Load Resource".to_string(),
@@ -295,14 +295,14 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
},
DocumentNode {
name: "Decode Image".to_string(),
inputs: vec![NodeInput::node(0, 0)],
inputs: vec![NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_std::wasm_application_io::DecodeImageNode")),
..Default::default()
},
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
}),
@@ -329,8 +329,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "Create Canvas",
category: "Structural",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![0],
outputs: vec![NodeOutput::new(1, 0)],
inputs: vec![NodeId(0)],
outputs: vec![NodeOutput::new(NodeId(1), 0)],
nodes: [
DocumentNode {
name: "Create Canvas".to_string(),
@@ -342,14 +342,14 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
DocumentNode {
name: "Cache".to_string(),
manual_composition: Some(concrete!(())),
inputs: vec![NodeInput::node(0, 0)],
inputs: vec![NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode<_, _>")),
..Default::default()
},
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
}),
@@ -368,8 +368,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "Draw Canvas",
category: "Structural",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![0, 2],
outputs: vec![NodeOutput::new(3, 0)],
inputs: vec![NodeId(0), NodeId(2)],
outputs: vec![NodeOutput::new(NodeId(3), 0)],
nodes: [
DocumentNode {
name: "Convert Image Frame".to_string(),
@@ -387,20 +387,20 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
DocumentNode {
name: "Cache".to_string(),
manual_composition: Some(concrete!(())),
inputs: vec![NodeInput::node(1, 0)],
inputs: vec![NodeInput::node(NodeId(1), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode<_, _>")),
..Default::default()
},
DocumentNode {
name: "Draw Canvas".to_string(),
inputs: vec![NodeInput::node(0, 0), NodeInput::node(2, 0)],
inputs: vec![NodeInput::node(NodeId(0), 0), NodeInput::node(NodeId(2), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_std::wasm_application_io::DrawImageFrameNode<_>")),
..Default::default()
},
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
}),
@@ -426,8 +426,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "Begin Scope",
category: "Ignore",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![0],
outputs: vec![NodeOutput::new(1, 0), NodeOutput::new(2, 0)],
inputs: vec![NodeId(0)],
outputs: vec![NodeOutput::new(NodeId(1), 0), NodeOutput::new(NodeId(2), 0)],
nodes: [
DocumentNode {
name: "SetNode".to_string(),
@@ -437,21 +437,21 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
},
DocumentNode {
name: "LetNode".to_string(),
inputs: vec![NodeInput::node(0, 0)],
inputs: vec![NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::LetNode<_>")),
..Default::default()
},
DocumentNode {
name: "RefNode".to_string(),
manual_composition: Some(concrete!(())),
inputs: vec![NodeInput::lambda(1, 0)],
inputs: vec![NodeInput::lambda(NodeId(1), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::RefNode<_, _>")),
..Default::default()
},
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
@@ -501,8 +501,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "Output",
category: "Ignore",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![3, 0],
outputs: vec![NodeOutput::new(4, 0)],
inputs: vec![NodeId(3), NodeId(0)],
outputs: vec![NodeOutput::new(NodeId(4), 0)],
nodes: [
DocumentNode {
name: "EditorApi".to_string(),
@@ -512,7 +512,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
},
DocumentNode {
name: "Create Canvas".to_string(),
inputs: vec![NodeInput::node(0, 0)],
inputs: vec![NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_std::wasm_application_io::CreateSurfaceNode")),
skip_deduplication: true,
..Default::default()
@@ -520,7 +520,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
DocumentNode {
name: "Cache".to_string(),
manual_composition: Some(concrete!(())),
inputs: vec![NodeInput::node(1, 0)],
inputs: vec![NodeInput::node(NodeId(1), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode<_, _>")),
..Default::default()
},
@@ -532,14 +532,14 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
},
DocumentNode {
name: "RenderNode".to_string(),
inputs: vec![NodeInput::node(0, 0), NodeInput::node(3, 0), NodeInput::node(2, 0)],
inputs: vec![NodeInput::node(NodeId(0), 0), NodeInput::node(NodeId(3), 0), NodeInput::node(NodeId(2), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_std::wasm_application_io::RenderNode<_, _>")),
..Default::default()
},
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
}),
@@ -809,8 +809,13 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "Split Channels",
category: "Image Adjustments",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![0],
outputs: vec![NodeOutput::new(1, 0), NodeOutput::new(2, 0), NodeOutput::new(3, 0), NodeOutput::new(4, 0)],
inputs: vec![NodeId(0)],
outputs: vec![
NodeOutput::new(NodeId(1), 0),
NodeOutput::new(NodeId(2), 0),
NodeOutput::new(NodeId(3), 0),
NodeOutput::new(NodeId(4), 0),
],
nodes: [
// The input image feeds into the identity, then we take its passed-through value when the other channels are reading from it instead of the original input.
// We do this for technical restrictions imposed by Graphene which doesn't allow an input to feed into multiple interior nodes in the subgraph.
@@ -823,32 +828,32 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
},
DocumentNode {
name: "RedNode".to_string(),
inputs: vec![NodeInput::node(0, 0), NodeInput::value(TaggedValue::RedGreenBlue(RedGreenBlue::Red), false)],
inputs: vec![NodeInput::node(NodeId(0), 0), NodeInput::value(TaggedValue::RedGreenBlue(RedGreenBlue::Red), false)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::raster::ExtractChannelNode<_>")),
..Default::default()
},
DocumentNode {
name: "GreenNode".to_string(),
inputs: vec![NodeInput::node(0, 0), NodeInput::value(TaggedValue::RedGreenBlue(RedGreenBlue::Green), false)],
inputs: vec![NodeInput::node(NodeId(0), 0), NodeInput::value(TaggedValue::RedGreenBlue(RedGreenBlue::Green), false)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::raster::ExtractChannelNode<_>")),
..Default::default()
},
DocumentNode {
name: "BlueNode".to_string(),
inputs: vec![NodeInput::node(0, 0), NodeInput::value(TaggedValue::RedGreenBlue(RedGreenBlue::Blue), false)],
inputs: vec![NodeInput::node(NodeId(0), 0), NodeInput::value(TaggedValue::RedGreenBlue(RedGreenBlue::Blue), false)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::raster::ExtractChannelNode<_>")),
..Default::default()
},
DocumentNode {
name: "AlphaNode".to_string(),
inputs: vec![NodeInput::node(0, 0)],
inputs: vec![NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::raster::ExtractAlphaNode<>")),
..Default::default()
},
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
@@ -913,8 +918,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "Uniform",
category: "Gpu",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![1, 0],
outputs: vec![NodeOutput::new(2, 0)],
inputs: vec![NodeId(1), NodeId(0)],
outputs: vec![NodeOutput::new(NodeId(2), 0)],
nodes: [
DocumentNode {
name: "Extract Executor".to_string(),
@@ -924,21 +929,21 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
},
DocumentNode {
name: "Create Uniform".to_string(),
inputs: vec![NodeInput::Network(generic!(T)), NodeInput::node(0, 0)],
inputs: vec![NodeInput::Network(generic!(T)), NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("gpu_executor::UniformNode<_>")),
..Default::default()
},
DocumentNode {
name: "Cache".to_string(),
manual_composition: Some(concrete!(())),
inputs: vec![NodeInput::node(1, 0)],
inputs: vec![NodeInput::node(NodeId(1), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode<_, _>")),
..Default::default()
},
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
}),
@@ -965,8 +970,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "Storage",
category: "Gpu",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![1, 0],
outputs: vec![NodeOutput::new(2, 0)],
inputs: vec![NodeId(1), NodeId(0)],
outputs: vec![NodeOutput::new(NodeId(2), 0)],
nodes: [
DocumentNode {
name: "Extract Executor".to_string(),
@@ -976,21 +981,21 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
},
DocumentNode {
name: "Create Storage".to_string(),
inputs: vec![NodeInput::Network(concrete!(Vec<u8>)), NodeInput::node(0, 0)],
inputs: vec![NodeInput::Network(concrete!(Vec<u8>)), NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("gpu_executor::StorageNode<_>")),
..Default::default()
},
DocumentNode {
name: "Cache".to_string(),
manual_composition: Some(concrete!(())),
inputs: vec![NodeInput::node(1, 0)],
inputs: vec![NodeInput::node(NodeId(1), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode<_, _>")),
..Default::default()
},
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
}),
@@ -1017,8 +1022,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "CreateOutputBuffer",
category: "Gpu",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![1, 1, 0],
outputs: vec![NodeOutput::new(2, 0)],
inputs: vec![NodeId(1), NodeId(1), NodeId(0)],
outputs: vec![NodeOutput::new(NodeId(2), 0)],
nodes: [
DocumentNode {
name: "Extract Executor".to_string(),
@@ -1028,21 +1033,21 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
},
DocumentNode {
name: "Create Output Buffer".to_string(),
inputs: vec![NodeInput::Network(concrete!(usize)), NodeInput::node(0, 0), NodeInput::Network(concrete!(Type))],
inputs: vec![NodeInput::Network(concrete!(usize)), NodeInput::node(NodeId(0), 0), NodeInput::Network(concrete!(Type))],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("gpu_executor::CreateOutputBufferNode<_, _>")),
..Default::default()
},
DocumentNode {
name: "Cache".to_string(),
manual_composition: Some(concrete!(())),
inputs: vec![NodeInput::node(1, 0)],
inputs: vec![NodeInput::node(NodeId(1), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode<_, _>")),
..Default::default()
},
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
}),
@@ -1075,8 +1080,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "CreateComputePass",
category: "Gpu",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![1, 0, 1, 1],
outputs: vec![NodeOutput::new(2, 0)],
inputs: vec![NodeId(1), NodeId(0), NodeId(1), NodeId(1)],
outputs: vec![NodeOutput::new(NodeId(2), 0)],
nodes: [
DocumentNode {
name: "Extract Executor".to_string(),
@@ -1088,7 +1093,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "Create Compute Pass".to_string(),
inputs: vec![
NodeInput::Network(concrete!(gpu_executor::PipelineLayout<WgpuExecutor>)),
NodeInput::node(0, 0),
NodeInput::node(NodeId(0), 0),
NodeInput::Network(concrete!(ShaderInput<WgpuExecutor>)),
NodeInput::Network(concrete!(gpu_executor::ComputePassDimensions)),
],
@@ -1098,14 +1103,14 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
DocumentNode {
name: "Cache".to_string(),
manual_composition: Some(concrete!(())),
inputs: vec![NodeInput::node(1, 0)],
inputs: vec![NodeInput::node(NodeId(1), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode<_, _>")),
..Default::default()
},
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
}),
@@ -1177,8 +1182,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "ExecuteComputePipeline",
category: "Gpu",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![1, 0],
outputs: vec![NodeOutput::new(2, 0)],
inputs: vec![NodeId(1), NodeId(0)],
outputs: vec![NodeOutput::new(NodeId(2), 0)],
nodes: [
DocumentNode {
name: "Extract Executor".to_string(),
@@ -1188,21 +1193,21 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
},
DocumentNode {
name: "Execute Compute Pipeline".to_string(),
inputs: vec![NodeInput::Network(concrete!(<WgpuExecutor as GpuExecutor>::CommandBuffer)), NodeInput::node(0, 0)],
inputs: vec![NodeInput::Network(concrete!(<WgpuExecutor as GpuExecutor>::CommandBuffer)), NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("gpu_executor::ExecuteComputePipelineNode<_>")),
..Default::default()
},
DocumentNode {
name: "Cache".to_string(),
manual_composition: Some(concrete!(())),
inputs: vec![NodeInput::node(1, 0)],
inputs: vec![NodeInput::node(NodeId(1), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode<_, _>")),
..Default::default()
},
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
}),
@@ -1229,8 +1234,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "ReadOutputBuffer",
category: "Gpu",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![1, 0],
outputs: vec![NodeOutput::new(2, 0)],
inputs: vec![NodeId(1), NodeId(0)],
outputs: vec![NodeOutput::new(NodeId(2), 0)],
nodes: [
DocumentNode {
name: "Extract Executor".to_string(),
@@ -1240,21 +1245,21 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
},
DocumentNode {
name: "Read Output Buffer".to_string(),
inputs: vec![NodeInput::Network(concrete!(Arc<ShaderInput<WgpuExecutor>>)), NodeInput::node(0, 0)],
inputs: vec![NodeInput::Network(concrete!(Arc<ShaderInput<WgpuExecutor>>)), NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("gpu_executor::ReadOutputBufferNode<_, _>")),
..Default::default()
},
DocumentNode {
name: "Cache".to_string(),
manual_composition: Some(concrete!(())),
inputs: vec![NodeInput::node(1, 0)],
inputs: vec![NodeInput::node(NodeId(1), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode<_, _>")),
..Default::default()
},
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
}),
@@ -1281,8 +1286,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "CreateGpuSurface",
category: "Gpu",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![0],
outputs: vec![NodeOutput::new(1, 0)],
inputs: vec![NodeId(0)],
outputs: vec![NodeOutput::new(NodeId(1), 0)],
nodes: [
DocumentNode {
name: "Create Gpu Surface".to_string(),
@@ -1293,14 +1298,14 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
DocumentNode {
name: "Cache".to_string(),
manual_composition: Some(concrete!(())),
inputs: vec![NodeInput::node(0, 0)],
inputs: vec![NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode<_, _>")),
..Default::default()
},
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
}),
@@ -1320,8 +1325,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "RenderTexture",
category: "Gpu",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![1, 1, 0],
outputs: vec![NodeOutput::new(1, 0)],
inputs: vec![NodeId(1), NodeId(1), NodeId(0)],
outputs: vec![NodeOutput::new(NodeId(1), 0)],
nodes: [
DocumentNode {
name: "Extract Executor".to_string(),
@@ -1334,7 +1339,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
inputs: vec![
NodeInput::Network(concrete!(ShaderInputFrame<WgpuExecutor>)),
NodeInput::Network(concrete!(Arc<SurfaceHandle<<WgpuExecutor as GpuExecutor>::Surface>>)),
NodeInput::node(0, 0),
NodeInput::node(NodeId(0), 0),
],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("gpu_executor::RenderTextureNode<_, _>")),
..Default::default()
@@ -1342,7 +1347,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
}),
@@ -1374,8 +1379,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "UploadTexture",
category: "Gpu",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![1, 0],
outputs: vec![NodeOutput::new(2, 0)],
inputs: vec![NodeId(1), NodeId(0)],
outputs: vec![NodeOutput::new(NodeId(2), 0)],
nodes: [
DocumentNode {
name: "Extract Executor".to_string(),
@@ -1385,21 +1390,21 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
},
DocumentNode {
name: "Upload Texture".to_string(),
inputs: vec![NodeInput::Network(concrete!(ImageFrame<Color>)), NodeInput::node(0, 0)],
inputs: vec![NodeInput::Network(concrete!(ImageFrame<Color>)), NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("gpu_executor::UploadTextureNode<_>")),
..Default::default()
},
DocumentNode {
name: "Cache".to_string(),
manual_composition: Some(concrete!(())),
inputs: vec![NodeInput::node(1, 0)],
inputs: vec![NodeInput::node(NodeId(1), 0)],
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode<_, _>")),
..Default::default()
},
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
}),
@@ -2149,8 +2154,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "Transform",
category: "Transform",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![0, 1, 1, 1, 1, 1],
outputs: vec![NodeOutput::new(1, 0)],
inputs: vec![NodeId(0), NodeId(1), NodeId(1), NodeId(1), NodeId(1), NodeId(1)],
outputs: vec![NodeOutput::new(NodeId(1), 0)],
nodes: [
DocumentNode {
inputs: vec![NodeInput::Network(concrete!(VectorData))],
@@ -2159,7 +2164,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
DocumentNode {
name: "Transform".to_string(),
inputs: vec![
NodeInput::node(0, 0),
NodeInput::node(NodeId(0), 0),
NodeInput::Network(concrete!(DVec2)),
NodeInput::Network(concrete!(f32)),
NodeInput::Network(concrete!(DVec2)),
@@ -2173,7 +2178,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
]
.into_iter()
.enumerate()
.map(|(id, node)| (id as NodeId, node))
.map(|(id, node)| (NodeId(id as u64), node))
.collect(),
..Default::default()
}),
@@ -2375,22 +2380,40 @@ pub static IMAGINATE_NODE: Lazy<DocumentNodeDefinition> = Lazy::new(|| DocumentN
name: "Imaginate",
category: "Image Synthesis",
implementation: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
outputs: vec![NodeOutput::new(1, 0)],
inputs: vec![
NodeId(0),
NodeId(1),
NodeId(1),
NodeId(1),
NodeId(1),
NodeId(1),
NodeId(1),
NodeId(1),
NodeId(1),
NodeId(1),
NodeId(1),
NodeId(1),
NodeId(1),
NodeId(1),
NodeId(1),
NodeId(1),
NodeId(1),
],
outputs: vec![NodeOutput::new(NodeId(1), 0)],
nodes: [
(
0,
NodeId(0),
DocumentNode {
inputs: vec![NodeInput::Network(concrete!(ImageFrame<Color>))],
..monitor_node()
},
),
(
1,
NodeId(1),
DocumentNode {
name: "Imaginate".into(),
inputs: vec![
NodeInput::node(0, 0),
NodeInput::node(NodeId(0), 0),
NodeInput::Network(concrete!(WasmEditorApi)),
NodeInput::Network(concrete!(ImaginateController)),
NodeInput::Network(concrete!(f64)),
@@ -2468,9 +2491,9 @@ impl DocumentNodeDefinition {
/*
NodeNetwork {
inputs: (0..num_inputs).map(|_| 0).collect(),
outputs: vec![NodeOutput::new(0, 0)],
outputs: vec![NodeOutput::new(NodeId(0), 0)],
nodes: [(
0,
NodeId(0),
DocumentNode {
name: format!("{}_impl", self.name),
// TODO: Allow inserting nodes that contain other nodes.
@@ -2483,8 +2506,6 @@ impl DocumentNodeDefinition {
.collect(),
..Default::default()
}
}
*/
NodeImplementation::Extract => return DocumentNodeImplementation::Extract,
};
@@ -2555,7 +2576,7 @@ pub fn wrap_network_in_scope(mut network: NodeNetwork, hash: u64) -> NodeNetwork
let inner_network = DocumentNode {
name: "Scope".to_string(),
implementation: DocumentNodeImplementation::Network(network),
inputs: core::iter::repeat(NodeInput::node(0, 1)).take(len).collect(),
inputs: core::iter::repeat(NodeInput::node(NodeId(0), 1)).take(len).collect(),
..Default::default()
};
@@ -2563,7 +2584,7 @@ pub fn wrap_network_in_scope(mut network: NodeNetwork, hash: u64) -> NodeNetwork
.expect("Begin Scope node type not found")
.to_document_node(vec![input_type.unwrap()], DocumentNodeMetadata::default());
if let DocumentNodeImplementation::Network(g) = &mut begin_scope.implementation {
if let Some(node) = g.nodes.get_mut(&0) {
if let Some(node) = g.nodes.get_mut(&NodeId(0)) {
node.world_state_hash = hash;
}
}
@@ -2574,20 +2595,20 @@ pub fn wrap_network_in_scope(mut network: NodeNetwork, hash: u64) -> NodeNetwork
inner_network,
resolve_document_node_type("End Scope")
.expect("End Scope node type not found")
.to_document_node(vec![NodeInput::node(0, 0), NodeInput::node(1, 0)], DocumentNodeMetadata::default()),
.to_document_node(vec![NodeInput::node(NodeId(0), 0), NodeInput::node(NodeId(1), 0)], DocumentNodeMetadata::default()),
];
NodeNetwork {
inputs: vec![0],
outputs: vec![NodeOutput::new(2, 0)],
nodes: nodes.into_iter().enumerate().map(|(id, node)| (id as NodeId, node)).collect(),
inputs: vec![NodeId(0)],
outputs: vec![NodeOutput::new(NodeId(2), 0)],
nodes: nodes.into_iter().enumerate().map(|(id, node)| (NodeId(id as u64), node)).collect(),
..Default::default()
}
}
pub fn new_image_network(output_offset: i32, output_node_id: NodeId) -> NodeNetwork {
let mut network = NodeNetwork {
inputs: vec![0],
inputs: vec![NodeId(0)],
..Default::default()
};
network.push_node(
@@ -2611,7 +2632,7 @@ pub fn new_text_network(text: String, font: Font, size: f64) -> NodeNetwork {
let output = resolve_document_node_type("Output").expect("Output node does not exist");
let mut network = NodeNetwork {
inputs: vec![0],
inputs: vec![NodeId(0)],
..Default::default()
};
network.push_node(text_generator.to_document_node(
@@ -363,12 +363,12 @@ impl core::fmt::Debug for LayerNodeIdentifier {
}
impl LayerNodeIdentifier {
pub const ROOT: Self = LayerNodeIdentifier::new_unchecked(0);
pub const ROOT: Self = LayerNodeIdentifier::new_unchecked(NodeId(0));
/// Construct a [`LayerNodeIdentifier`] without checking if it is a layer node
pub const fn new_unchecked(node_id: NodeId) -> Self {
// Safety: will always be >=1
Self(unsafe { NonZeroU64::new_unchecked(node_id + 1) })
Self(unsafe { NonZeroU64::new_unchecked(node_id.0 + 1) })
}
/// Construct a [`LayerNodeIdentifier`], debug asserting that it is a layer node
@@ -384,7 +384,7 @@ impl LayerNodeIdentifier {
/// Access the node id of this layer
pub fn to_node(self) -> NodeId {
u64::from(self.0) - 1
NodeId(u64::from(self.0) - 1)
}
/// Access the parent layer if possible
@@ -662,32 +662,44 @@ fn test_tree() {
let mut document_metadata = DocumentMetadata::default();
let root = document_metadata.root();
let document_metadata = &mut document_metadata;
root.push_child(document_metadata, LayerNodeIdentifier::new_unchecked(3));
assert_eq!(root.children(document_metadata).collect::<Vec<_>>(), vec![LayerNodeIdentifier::new_unchecked(3)]);
root.push_child(document_metadata, LayerNodeIdentifier::new_unchecked(6));
assert_eq!(root.children(document_metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(), vec![3, 6]);
assert_eq!(root.decendants(document_metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(), vec![3, 6]);
LayerNodeIdentifier::new_unchecked(3).add_after(document_metadata, LayerNodeIdentifier::new_unchecked(4));
LayerNodeIdentifier::new_unchecked(3).add_before(document_metadata, LayerNodeIdentifier::new_unchecked(2));
LayerNodeIdentifier::new_unchecked(6).add_before(document_metadata, LayerNodeIdentifier::new_unchecked(5));
LayerNodeIdentifier::new_unchecked(6).add_after(document_metadata, LayerNodeIdentifier::new_unchecked(9));
LayerNodeIdentifier::new_unchecked(6).push_child(document_metadata, LayerNodeIdentifier::new_unchecked(8));
LayerNodeIdentifier::new_unchecked(6).push_front_child(document_metadata, LayerNodeIdentifier::new_unchecked(7));
root.push_front_child(document_metadata, LayerNodeIdentifier::new_unchecked(1));
assert_eq!(root.children(document_metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(), vec![1, 2, 3, 4, 5, 6, 9]);
root.push_child(document_metadata, LayerNodeIdentifier::new_unchecked(NodeId(3)));
assert_eq!(root.children(document_metadata).collect::<Vec<_>>(), vec![LayerNodeIdentifier::new_unchecked(NodeId(3))]);
root.push_child(document_metadata, LayerNodeIdentifier::new_unchecked(NodeId(6)));
assert_eq!(root.children(document_metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(), vec![NodeId(3), NodeId(6)]);
assert_eq!(root.decendants(document_metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(), vec![NodeId(3), NodeId(6)]);
LayerNodeIdentifier::new_unchecked(NodeId(3)).add_after(document_metadata, LayerNodeIdentifier::new_unchecked(NodeId(4)));
LayerNodeIdentifier::new_unchecked(NodeId(3)).add_before(document_metadata, LayerNodeIdentifier::new_unchecked(NodeId(2)));
LayerNodeIdentifier::new_unchecked(NodeId(6)).add_before(document_metadata, LayerNodeIdentifier::new_unchecked(NodeId(5)));
LayerNodeIdentifier::new_unchecked(NodeId(6)).add_after(document_metadata, LayerNodeIdentifier::new_unchecked(NodeId(9)));
LayerNodeIdentifier::new_unchecked(NodeId(6)).push_child(document_metadata, LayerNodeIdentifier::new_unchecked(NodeId(8)));
LayerNodeIdentifier::new_unchecked(NodeId(6)).push_front_child(document_metadata, LayerNodeIdentifier::new_unchecked(NodeId(7)));
root.push_front_child(document_metadata, LayerNodeIdentifier::new_unchecked(NodeId(1)));
assert_eq!(
root.children(document_metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(),
vec![NodeId(1), NodeId(2), NodeId(3), NodeId(4), NodeId(5), NodeId(6), NodeId(9)]
);
assert_eq!(
root.decendants(document_metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(),
vec![1, 2, 3, 4, 5, 6, 7, 8, 9]
vec![NodeId(1), NodeId(2), NodeId(3), NodeId(4), NodeId(5), NodeId(6), NodeId(7), NodeId(8), NodeId(9)]
);
assert_eq!(
root.decendants(document_metadata).map(LayerNodeIdentifier::to_node).rev().collect::<Vec<_>>(),
vec![9, 8, 7, 6, 5, 4, 3, 2, 1]
vec![NodeId(9), NodeId(8), NodeId(7), NodeId(6), NodeId(5), NodeId(4), NodeId(3), NodeId(2), NodeId(1)]
);
assert!(root.children(document_metadata).all(|child| child.parent(document_metadata) == Some(root)));
LayerNodeIdentifier::new_unchecked(6).delete(document_metadata);
LayerNodeIdentifier::new_unchecked(1).delete(document_metadata);
LayerNodeIdentifier::new_unchecked(9).push_child(document_metadata, LayerNodeIdentifier::new_unchecked(10));
assert_eq!(root.children(document_metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(), vec![2, 3, 4, 5, 9]);
assert_eq!(root.decendants(document_metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(), vec![2, 3, 4, 5, 9, 10]);
assert_eq!(root.decendants(document_metadata).map(LayerNodeIdentifier::to_node).rev().collect::<Vec<_>>(), vec![10, 9, 5, 4, 3, 2]);
LayerNodeIdentifier::new_unchecked(NodeId(6)).delete(document_metadata);
LayerNodeIdentifier::new_unchecked(NodeId(1)).delete(document_metadata);
LayerNodeIdentifier::new_unchecked(NodeId(9)).push_child(document_metadata, LayerNodeIdentifier::new_unchecked(NodeId(10)));
assert_eq!(
root.children(document_metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(),
vec![NodeId(2), NodeId(3), NodeId(4), NodeId(5), NodeId(9)]
);
assert_eq!(
root.decendants(document_metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(),
vec![NodeId(2), NodeId(3), NodeId(4), NodeId(5), NodeId(9), NodeId(10)]
);
assert_eq!(
root.decendants(document_metadata).map(LayerNodeIdentifier::to_node).rev().collect::<Vec<_>>(),
vec![NodeId(10), NodeId(9), NodeId(5), NodeId(4), NodeId(3), NodeId(2)]
);
}
@@ -4,6 +4,10 @@ use glam::DVec2;
use serde::{Deserialize, Serialize};
use std::fmt;
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize, specta::Type)]
pub struct DocumentId(pub u64);
#[derive(PartialEq, Eq, Clone, Copy, Debug, Serialize, Deserialize, Hash)]
pub enum FlipAxis {
X,