Retire layer paths used throughout the code (#1531)

* Part 1

* Part 2

* Part 3

* Part 4

* Part 5

* Part 6

* Part 7

* Part 8
This commit is contained in:
Keavon Chambers 2023-12-21 19:32:46 -08:00 committed by GitHub
parent 5c7e04a725
commit 7bfe0ce55b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
73 changed files with 532 additions and 798 deletions

View file

@ -12,11 +12,12 @@ use std::hash::{Hash, Hasher};
pub mod value;
// TODO: Convert from a type alias to a newtype
pub type NodeId = u64;
/// Hash two IDs together, returning a new ID that is always consistant for two input IDs in a specific order.
/// This is used during [`NodeNetwork::flatten`] in order to ensure consistant yet non-conflicting IDs for inner networks.
fn merge_ids(a: u64, b: u64) -> u64 {
fn merge_ids(a: NodeId, b: NodeId) -> NodeId {
let mut hasher = DefaultHasher::new();
a.hash(&mut hasher);
b.hash(&mut hasher);
@ -639,7 +640,7 @@ impl NodeNetwork {
}
/// Gives an iterator to all nodes connected to the given nodes by all inputs (primary or primary + secondary depending on `only_follow_primary` choice), traversing backwards upstream starting from the given node's inputs.
pub fn upstream_flow_back_from_nodes(&self, node_ids: Vec<NodeId>, only_follow_primary: bool) -> impl Iterator<Item = (&DocumentNode, u64)> {
pub fn upstream_flow_back_from_nodes(&self, node_ids: Vec<NodeId>, only_follow_primary: bool) -> impl Iterator<Item = (&DocumentNode, NodeId)> {
FlowIter {
stack: node_ids,
network: self,
@ -654,13 +655,13 @@ impl NodeNetwork {
/// Check there are no cycles in the graph (this should never happen).
pub fn is_acyclic(&self) -> bool {
let mut dependencies: HashMap<u64, Vec<u64>> = HashMap::new();
let mut dependencies: HashMap<NodeId, Vec<NodeId>> = HashMap::new();
for (node_id, node) in &self.nodes {
dependencies.insert(
*node_id,
node.inputs
.iter()
.filter_map(|input| if let NodeInput::Node { node_id: ref_id, .. } = input { Some(*ref_id) } else { None })
.filter_map(|input| if let NodeInput::Node { node_id, .. } = input { Some(*node_id) } else { None })
.collect(),
);
}
@ -734,11 +735,12 @@ impl NodeNetwork {
/// Collect a hashmap of nodes with a list of the nodes that use it as input
pub fn collect_outwards_links(&self) -> HashMap<NodeId, Vec<NodeId>> {
let mut outwards_links: HashMap<u64, Vec<u64>> = HashMap::new();
for (node_id, node) in &self.nodes {
let mut outwards_links: HashMap<NodeId, Vec<NodeId>> = HashMap::new();
for (current_node_id, node) in &self.nodes {
for input in &node.inputs {
if let NodeInput::Node { node_id: ref_id, .. } = input {
outwards_links.entry(*ref_id).or_default().push(*node_id)
if let NodeInput::Node { node_id, .. } = input {
let outward_links_entry = outwards_links.entry(*node_id).or_default();
outward_links_entry.push(*current_node_id);
}
}
}

View file

@ -38,7 +38,6 @@ pub enum TaggedValue {
ImaginateSamplingMethod(ImaginateSamplingMethod),
ImaginateMaskStartingFill(ImaginateMaskStartingFill),
ImaginateController(ImaginateController),
LayerPath(Option<Vec<u64>>),
VectorData(graphene_core::vector::VectorData),
Fill(graphene_core::vector::style::Fill),
Stroke(graphene_core::vector::style::Stroke),
@ -104,7 +103,6 @@ impl Hash for TaggedValue {
Self::ImaginateSamplingMethod(x) => x.hash(state),
Self::ImaginateMaskStartingFill(x) => x.hash(state),
Self::ImaginateController(x) => x.hash(state),
Self::LayerPath(x) => x.hash(state),
Self::ImageFrame(x) => x.hash(state),
Self::VectorData(x) => x.hash(state),
Self::Fill(x) => x.hash(state),
@ -179,7 +177,6 @@ impl<'a> TaggedValue {
TaggedValue::ImaginateSamplingMethod(x) => Box::new(x),
TaggedValue::ImaginateMaskStartingFill(x) => Box::new(x),
TaggedValue::ImaginateController(x) => Box::new(x),
TaggedValue::LayerPath(x) => Box::new(x),
TaggedValue::VectorData(x) => Box::new(x),
TaggedValue::Fill(x) => Box::new(x),
TaggedValue::Stroke(x) => Box::new(x),
@ -252,7 +249,6 @@ impl<'a> TaggedValue {
TaggedValue::ImaginateSamplingMethod(_) => concrete!(ImaginateSamplingMethod),
TaggedValue::ImaginateMaskStartingFill(_) => concrete!(ImaginateMaskStartingFill),
TaggedValue::ImaginateController(_) => concrete!(ImaginateController),
TaggedValue::LayerPath(_) => concrete!(Option<Vec<u64>>),
TaggedValue::DAffine2(_) => concrete!(DAffine2),
TaggedValue::LuminanceCalculation(_) => concrete!(LuminanceCalculation),
TaggedValue::VectorData(_) => concrete!(graphene_core::vector::VectorData),
@ -316,7 +312,6 @@ impl<'a> TaggedValue {
x if x == TypeId::of::<ImaginateSamplingMethod>() => Ok(TaggedValue::ImaginateSamplingMethod(*downcast(input).unwrap())),
x if x == TypeId::of::<ImaginateMaskStartingFill>() => Ok(TaggedValue::ImaginateMaskStartingFill(*downcast(input).unwrap())),
x if x == TypeId::of::<ImaginateController>() => Ok(TaggedValue::ImaginateController(*downcast(input).unwrap())),
x if x == TypeId::of::<Option<Vec<u64>>>() => Ok(TaggedValue::LayerPath(*downcast(input).unwrap())),
x if x == TypeId::of::<DAffine2>() => Ok(TaggedValue::DAffine2(*downcast(input).unwrap())),
x if x == TypeId::of::<LuminanceCalculation>() => Ok(TaggedValue::LuminanceCalculation(*downcast(input).unwrap())),
x if x == TypeId::of::<graphene_core::vector::VectorData>() => Ok(TaggedValue::VectorData(*downcast(input).unwrap())),

View file

@ -207,7 +207,8 @@ pub struct ProtoNode {
pub identifier: ProtoNodeIdentifier,
pub document_node_path: Vec<NodeId>,
pub skip_deduplication: bool,
/// Represents a global state on which the node depends. This is a hack, TODO: figure out a proper solution
// TODO: This is a hack, figure out a proper solution
/// Represents a global state on which the node depends.
pub world_state_hash: u64,
}
@ -412,7 +413,7 @@ impl ProtoNetwork {
}
/// Update all of the references to a node ID in the graph with a new ID named `compose_node_id`.
fn replace_node_id(&mut self, outwards_edges: &HashMap<u64, Vec<u64>>, node_id: u64, compose_node_id: u64, skip_lambdas: bool) {
fn replace_node_id(&mut self, outwards_edges: &HashMap<NodeId, Vec<NodeId>>, node_id: NodeId, compose_node_id: NodeId, skip_lambdas: bool) {
// Update references in other nodes to use the new compose node
if let Some(referring_nodes) = outwards_edges.get(&node_id) {
for &referring_node_id in referring_nodes {