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

@ -66,7 +66,7 @@ fn add_network() -> NodeNetwork {
}]
.into_iter()
.enumerate()
.map(|(i, n)| (i as u64, n))
.map(|(id, node)| (id as NodeId, node))
.collect(),
}
}

View file

@ -16,7 +16,8 @@ use alloc::vec::Vec;
/// This data structure is somewhat similar to a linked list in terms of invariants.
/// The downside is that currently it requires a lot of iteration.
type ElementId = u64;
// TODO: Convert from a type alias to a newtype
pub type ElementId = u64;
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, specta::Type, Hash)]
pub struct IdBackedVec<T> {
/// Contained elements
@ -124,7 +125,7 @@ impl<T> IdBackedVec<T> {
}
/// Enumerate the ids and elements in this container `(&ElementId, &T)`
pub fn enumerate(&self) -> core::iter::Zip<core::slice::Iter<u64>, core::slice::Iter<T>> {
pub fn enumerate(&self) -> core::iter::Zip<core::slice::Iter<ElementId>, core::slice::Iter<T>> {
self.element_ids.iter().zip(self.elements.iter())
}

View file

@ -54,7 +54,7 @@ impl core::hash::Hash for Gradient {
}
impl Gradient {
/// Constructs a new gradient with the colors at 0 and 1 specified.
pub fn new(start: DVec2, start_color: Color, end: DVec2, end_color: Color, transform: DAffine2, _uuid: u64, gradient_type: GradientType) -> Self {
pub fn new(start: DVec2, start_color: Color, end: DVec2, end_color: Color, transform: DAffine2, gradient_type: GradientType) -> Self {
Gradient {
start,
end,

View file

@ -1,7 +1,7 @@
use super::consts::ManipulatorType;
use super::id_vec::IdBackedVec;
use super::manipulator_group::ManipulatorGroup;
use super::manipulator_point::ManipulatorPoint;
use super::{consts::ManipulatorType, id_vec::ElementId};
use crate::uuid::ManipulatorGroupId;
use alloc::string::String;
@ -204,7 +204,7 @@ impl Subpath {
/// Delete the selected points from the [Subpath]
pub fn delete_selected(&mut self) {
let mut ids_to_delete: Vec<u64> = vec![];
let mut ids_to_delete: Vec<ElementId> = vec![];
for (id, manipulator_group) in self.manipulator_groups_mut().enumerate_mut() {
if manipulator_group.is_anchor_selected() {
ids_to_delete.push(*id);
@ -228,7 +228,7 @@ impl Subpath {
// ** SELECTION OF POINTS **
/// Set a single point to a chosen selection state by providing `(manipulator group ID, manipulator type)`.
pub fn select_point(&mut self, point: (u64, ManipulatorType), selected: bool) -> Option<&mut ManipulatorGroup> {
pub fn select_point(&mut self, point: (ElementId, ManipulatorType), selected: bool) -> Option<&mut ManipulatorGroup> {
let (manipulator_group_id, point_id) = point;
if let Some(manipulator_group) = self.manipulator_groups_mut().by_id_mut(manipulator_group_id) {
manipulator_group.select_point(point_id as usize, selected);
@ -240,7 +240,7 @@ impl Subpath {
}
/// Set points in the [Subpath] to a chosen selection state, given by `(manipulator group ID, manipulator type)`.
pub fn select_points(&mut self, points: &[(u64, ManipulatorType)], selected: bool) {
pub fn select_points(&mut self, points: &[(ElementId, ManipulatorType)], selected: bool) {
points.iter().for_each(|point| {
self.select_point(*point, selected);
});

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 {

View file

@ -246,7 +246,7 @@ async fn create_compute_pass_descriptor<T: Clone + Pixel + StaticTypeSized>(
]
.into_iter()
.enumerate()
.map(|(i, n)| (i as u64, n))
.map(|(id, node)| (id as NodeId, node))
.collect(),
..Default::default()
};
@ -464,7 +464,7 @@ async fn blend_gpu_image(foreground: ImageFrame<Color>, background: ImageFrame<C
}]
.into_iter()
.enumerate()
.map(|(i, n)| (i as u64, n))
.map(|(id, node)| (id as NodeId, node))
.collect(),
..Default::default()
};

View file

@ -274,7 +274,6 @@ pub async fn imaginate<'a, P: Pixel>(
negative_prompt: impl Future<Output = String>,
adapt_input_image: impl Future<Output = bool>,
image_creativity: impl Future<Output = f32>,
masking_layer: impl Future<Output = Option<Vec<u64>>>,
inpaint: impl Future<Output = bool>,
mask_blur: impl Future<Output = f32>,
mask_starting_fill: impl Future<Output = ImaginateMaskStartingFill>,
@ -305,7 +304,6 @@ pub async fn imaginate<'a, P: Pixel>(
negative_prompt,
adapt_input_image,
image_creativity,
masking_layer,
inpaint,
mask_blur,
mask_starting_fill,
@ -343,7 +341,6 @@ async fn imaginate_maybe_fail<'a, P: Pixel, F: Fn(ImaginateStatus)>(
negative_prompt: impl Future<Output = String>,
adapt_input_image: impl Future<Output = bool>,
image_creativity: impl Future<Output = f32>,
_masking_layer: impl Future<Output = Option<Vec<u64>>>,
_inpaint: impl Future<Output = bool>,
_mask_blur: impl Future<Output = f32>,
_mask_starting_fill: impl Future<Output = ImaginateMaskStartingFill>,

View file

@ -533,7 +533,6 @@ generate_imaginate_node! {
negative_prompt: NegativePrompt: String,
adapt_input_image: AdaptInputImage: bool,
image_creativity: ImageCreativity: f32,
masking_layer: MaskingLayer: Option<Vec<u64>>,
inpaint: Inpaint: bool,
mask_blur: MaskBlur: f32,
mask_starting_fill: MaskStartingFill: ImaginateMaskStartingFill,

View file

@ -605,14 +605,14 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
NodeIOTypes::new(concrete!(()), concrete!(WasmEditorApi), vec![fn_type!(Option<WasmEditorApi>, WasmEditorApi)]),
),
(
ProtoNodeIdentifier::new("graphene_std::raster::ImaginateNode<_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _>"),
ProtoNodeIdentifier::new("graphene_std::raster::ImaginateNode<_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _>"),
|args: Vec<graph_craft::proto::SharedNodeContainer>| {
Box::pin(async move {
use graphene_std::raster::ImaginateNode;
macro_rules! instantiate_imaginate_node {
($($i:expr,)*) => { ImaginateNode::new($(graphene_std::any::input_node(args[$i].clone()),)* ) };
}
let node: ImaginateNode<Color, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _> = instantiate_imaginate_node!(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,);
let node: ImaginateNode<Color, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _> = instantiate_imaginate_node!(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,);
let any = graphene_std::any::DynAnyNode::new(node);
any.into_type_erased()
})
@ -632,7 +632,6 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
fn_type!(String),
fn_type!(bool),
fn_type!(f32),
fn_type!(Option<Vec<u64>>),
fn_type!(bool),
fn_type!(f32),
fn_type!(ImaginateMaskStartingFill),