Skip to content

Commit

Permalink
Migrate to point id
Browse files Browse the repository at this point in the history
  • Loading branch information
0HyperCube authored and Keavon committed Mar 25, 2024
1 parent 659ab16 commit 16feea5
Show file tree
Hide file tree
Showing 36 changed files with 172,156 additions and 427 deletions.
33,959 changes: 33,958 additions & 1 deletion demo-artwork/just-a-potted-cactus.graphite

Large diffs are not rendered by default.

9,289 changes: 9,288 additions & 1 deletion demo-artwork/procedural-string-lights.graphite

Large diffs are not rendered by default.

63,084 changes: 63,083 additions & 1 deletion demo-artwork/red-dress.graphite

Large diffs are not rendered by default.

65,425 changes: 65,424 additions & 1 deletion demo-artwork/valley-of-spires.graphite

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use graph_craft::document::NodeId;
use graphene_core::raster::BlendMode;
use graphene_core::raster::ImageFrame;
use graphene_core::text::Font;
use graphene_core::uuid::ManipulatorGroupId;
use graphene_core::vector::brush_stroke::BrushStroke;
use graphene_core::vector::style::{Fill, Stroke};
use graphene_core::vector::PointId;
use graphene_core::{Artboard, Color};

use glam::{DAffine2, DVec2, IVec2};
Expand Down Expand Up @@ -83,7 +83,7 @@ pub enum GraphOperationMessage {
},
NewVectorLayer {
id: NodeId,
subpaths: Vec<Subpath<ManipulatorGroupId>>,
subpaths: Vec<Subpath<PointId>>,
parent: LayerNodeIdentifier,
insert_index: isize,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use bezier_rs::{ManipulatorGroup, Subpath};
use graph_craft::document::{generate_uuid, NodeId, NodeInput, NodeNetwork};
use graphene_core::renderer::Quad;
use graphene_core::text::Font;
use graphene_core::uuid::ManipulatorGroupId;
use graphene_core::vector::style::{Fill, Gradient, GradientType, LineCap, LineJoin, Stroke};
use graphene_core::Color;
use graphene_std::vector::PointId;

use glam::{DAffine2, DVec2, IVec2};

Expand Down Expand Up @@ -411,7 +411,7 @@ fn apply_usvg_fill(fill: &Option<usvg::Fill>, modify_inputs: &mut ModifyInputsCo
}
}

fn convert_usvg_path(path: &usvg::Path) -> Vec<Subpath<ManipulatorGroupId>> {
fn convert_usvg_path(path: &usvg::Path) -> Vec<Subpath<PointId>> {
let mut subpaths = Vec::new();
let mut groups = Vec::new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::messages::portfolio::document::utility_types::document_metadata::{Doc

use bezier_rs::{ManipulatorGroup, Subpath};
use graph_craft::document::{value::TaggedValue, NodeInput};
use graphene_core::uuid::ManipulatorGroupId;
use graphene_core::vector::PointId;
use graphene_core::vector::{ManipulatorPointId, SelectedType};

use glam::{DAffine2, DVec2};
Expand Down Expand Up @@ -184,7 +184,7 @@ fn clamp_bounds(bounds_min: DVec2, mut bounds_max: DVec2) -> [DVec2; 2] {
[bounds_min, bounds_max]
}
/// Returns corners of all subpaths
fn subpath_bounds(subpaths: &[Subpath<ManipulatorGroupId>]) -> [DVec2; 2] {
fn subpath_bounds(subpaths: &[Subpath<PointId>]) -> [DVec2; 2] {
subpaths
.iter()
.filter_map(|subpath| subpath.bounding_box())
Expand All @@ -193,26 +193,26 @@ fn subpath_bounds(subpaths: &[Subpath<ManipulatorGroupId>]) -> [DVec2; 2] {
}

/// Returns corners of all subpaths (but expanded to avoid division-by-zero errors)
pub fn nonzero_subpath_bounds(subpaths: &[Subpath<ManipulatorGroupId>]) -> [DVec2; 2] {
pub fn nonzero_subpath_bounds(subpaths: &[Subpath<PointId>]) -> [DVec2; 2] {
let [bounds_min, bounds_max] = subpath_bounds(subpaths);
clamp_bounds(bounds_min, bounds_max)
}

pub struct VectorModificationState<'a> {
pub subpaths: &'a mut Vec<Subpath<ManipulatorGroupId>>,
pub colinear_manipulators: &'a mut Vec<ManipulatorGroupId>,
pub subpaths: &'a mut Vec<Subpath<PointId>>,
pub colinear_manipulators: &'a mut Vec<PointId>,
}
impl<'a> VectorModificationState<'a> {
fn insert_start(&mut self, subpath_index: usize, manipulator_group: ManipulatorGroup<ManipulatorGroupId>) {
fn insert_start(&mut self, subpath_index: usize, manipulator_group: ManipulatorGroup<PointId>) {
self.subpaths[subpath_index].insert_manipulator_group(0, manipulator_group)
}

fn insert_end(&mut self, subpath_index: usize, manipulator_group: ManipulatorGroup<ManipulatorGroupId>) {
fn insert_end(&mut self, subpath_index: usize, manipulator_group: ManipulatorGroup<PointId>) {
let subpath = &mut self.subpaths[subpath_index];
subpath.insert_manipulator_group(subpath.len(), manipulator_group)
}

fn insert(&mut self, manipulator_group: ManipulatorGroup<ManipulatorGroupId>, after_id: ManipulatorGroupId) {
fn insert(&mut self, manipulator_group: ManipulatorGroup<PointId>, after_id: PointId) {
for subpath in self.subpaths.iter_mut() {
if let Some(index) = subpath.manipulator_index_from_id(after_id) {
subpath.insert_manipulator_group(index + 1, manipulator_group);
Expand All @@ -221,7 +221,7 @@ impl<'a> VectorModificationState<'a> {
}
}

fn remove_group(&mut self, id: ManipulatorGroupId) {
fn remove_group(&mut self, id: PointId) {
for subpath in self.subpaths.iter_mut() {
if let Some(index) = subpath.manipulator_index_from_id(id) {
subpath.remove_manipulator_group(index);
Expand All @@ -247,15 +247,15 @@ impl<'a> VectorModificationState<'a> {
}
}

fn set_manipulator_colinear_handles_state(&mut self, id: ManipulatorGroupId, colinear: bool) {
fn set_manipulator_colinear_handles_state(&mut self, id: PointId, colinear: bool) {
if !colinear {
self.colinear_manipulators.retain(|&manipulator_group_id| manipulator_group_id != id);
} else if !self.colinear_manipulators.contains(&id) {
self.colinear_manipulators.push(id);
}
}

fn toggle_manipulator_colinear_handles_state(&mut self, id: ManipulatorGroupId) {
fn toggle_manipulator_colinear_handles_state(&mut self, id: PointId) {
if self.colinear_manipulators.contains(&id) {
self.colinear_manipulators.retain(|&manipulator_group_id| manipulator_group_id != id);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use graph_craft::document::value::TaggedValue;
use graph_craft::document::{generate_uuid, DocumentNode, NodeId, NodeInput, NodeNetwork, NodeOutput};
use graphene_core::raster::{BlendMode, ImageFrame};
use graphene_core::text::Font;
use graphene_core::uuid::ManipulatorGroupId;
use graphene_core::vector::brush_stroke::BrushStroke;
use graphene_core::vector::style::{Fill, FillType, Stroke};
use graphene_core::vector::PointId;
use graphene_core::{Artboard, Color};
use graphene_std::vector::ManipulatorPointId;

Expand All @@ -25,20 +25,20 @@ pub enum TransformIn {
Viewport,
}

type ManipulatorGroup = bezier_rs::ManipulatorGroup<ManipulatorGroupId>;
type ManipulatorGroup = bezier_rs::ManipulatorGroup<PointId>;

#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub enum VectorDataModification {
AddEndManipulatorGroup { subpath_index: usize, manipulator_group: ManipulatorGroup },
AddManipulatorGroup { manipulator_group: ManipulatorGroup, after_id: ManipulatorGroupId },
AddManipulatorGroup { manipulator_group: ManipulatorGroup, after_id: PointId },
AddStartManipulatorGroup { subpath_index: usize, manipulator_group: ManipulatorGroup },
RemoveManipulatorGroup { id: ManipulatorGroupId },
RemoveManipulatorGroup { id: PointId },
RemoveManipulatorPoint { point: ManipulatorPointId },
SetClosed { index: usize, closed: bool },
SetManipulatorColinearHandlesState { id: ManipulatorGroupId, colinear: bool },
SetManipulatorColinearHandlesState { id: PointId, colinear: bool },
SetManipulatorPosition { point: ManipulatorPointId, position: DVec2 },
ToggleManipulatorColinearHandlesState { id: ManipulatorGroupId },
UpdateSubpaths { subpaths: Vec<Subpath<ManipulatorGroupId>> },
ToggleManipulatorColinearHandlesState { id: PointId },
UpdateSubpaths { subpaths: Vec<Subpath<PointId>> },
}

pub struct ModifyInputsContext<'a> {
Expand Down Expand Up @@ -206,7 +206,7 @@ impl<'a> ModifyInputsContext<'a> {
self.insert_node_before(NodeId(generate_uuid()), layer, 0, artboard_node, IVec2::new(-8, 0))
}

pub fn insert_vector_data(&mut self, subpaths: Vec<Subpath<ManipulatorGroupId>>, layer: NodeId) {
pub fn insert_vector_data(&mut self, subpaths: Vec<Subpath<PointId>>, layer: NodeId) {
let shape = {
let node_type = resolve_document_node_type("Shape").expect("Shape node does not exist");
node_type.to_document_node_default_inputs([Some(NodeInput::value(TaggedValue::Subpaths(subpaths), false))], Default::default())
Expand Down Expand Up @@ -481,7 +481,7 @@ impl<'a> ModifyInputsContext<'a> {
let [mut new_bounds_min, mut new_bounds_max] = [DVec2::ZERO, DVec2::ONE];
let mut empty = false;

self.modify_inputs("Shape", false, |inputs, _node_id, _metadata| {
self.modify_inputs("Vector Modify", false, |inputs, _node_id, _metadata| {
let [subpaths, colinear_manipulators] = inputs.as_mut_slice() else {
panic!("Shape does not have both `subpath` and `colinear_manipulators` inputs");
};
Expand All @@ -494,7 +494,7 @@ impl<'a> ModifyInputsContext<'a> {
return;
};
let NodeInput::Value {
tagged_value: TaggedValue::ManipulatorGroupIds(colinear_manipulators),
tagged_value: TaggedValue::PointIds(colinear_manipulators),
..
} = colinear_manipulators
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2417,8 +2417,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
DocumentNode {
name: "Path Generator".to_string(),
inputs: vec![
NodeInput::Network(concrete!(Vec<bezier_rs::Subpath<graphene_core::uuid::ManipulatorGroupId>>)),
NodeInput::Network(concrete!(Vec<graphene_core::uuid::ManipulatorGroupId>)),
NodeInput::Network(concrete!(Vec<bezier_rs::Subpath<graphene_core::vector::PointId>>)),
NodeInput::Network(concrete!(Vec<graphene_core::vector::PointId>)),
],
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::vector::generator_nodes::PathGenerator<_>")),
..Default::default()
Expand All @@ -2439,7 +2439,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
}),
inputs: vec![
DocumentInputType::value("Path Data", TaggedValue::Subpaths(vec![]), false),
DocumentInputType::value("Colinear Manipulators", TaggedValue::ManipulatorGroupIds(vec![]), false),
DocumentInputType::value("Colinear Manipulators", TaggedValue::PointIds(vec![]), false),
],
outputs: vec![DocumentOutputType::new("Vector", FrontendGraphDataType::Subpath)],
..Default::default()
Expand All @@ -2448,8 +2448,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "Path Modify",
category: "Vector",
implementation: DocumentNodeImplementation::Network(NodeNetwork {
inputs: vec![NodeId(0), NodeId(1)],
outputs: vec![NodeOutput::new(NodeId(1), 0)],
imports: vec![NodeId(0), NodeId(1)],
exports: vec![NodeOutput::new(NodeId(1), 0)],
nodes: vec![
DocumentNode {
inputs: vec![NodeInput::Network(concrete!(VectorData))],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn path_overlays(document: &DocumentMessageHandler, shape_editor: &mut Shape
let is_selected = |selected: Option<&SelectedLayerState>, point: ManipulatorPointId| selected.is_some_and(|selected| selected.is_selected(point));
overlay_context.outline(vector_data.stroke_bezier_paths(), transform);

let mut manipulator_overlay = |manipulator_group: &bezier_rs::ManipulatorGroup<graphene_std::vector::PointId>| {
for manipulator_group in vector_data.manipulator_groups() {
let anchor = manipulator_group.anchor;
let anchor_position = transform.transform_point2(anchor);

Expand All @@ -51,12 +51,6 @@ pub fn path_overlays(document: &DocumentMessageHandler, shape_editor: &mut Shape
}

overlay_context.manipulator_anchor(anchor_position, is_selected(selected, ManipulatorPointId::new(manipulator_group.id.into(), SelectedType::Anchor)), None);
};

for subpath in vector_data.stroke_bezier_paths() {
for manipulator in subpath.manipulator_groups() {
manipulator_overlay(manipulator);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::messages::prelude::Message;

use bezier_rs::Subpath;
use graphene_core::renderer::Quad;
use graphene_std::vector::PointId;

use core::borrow::Borrow;
use core::f64::consts::PI;
Expand Down Expand Up @@ -114,7 +115,7 @@ impl OverlayContext {
self.render_context.stroke();
}

pub fn outline<'a, Id: bezier_rs::Identifier>(&mut self, subpaths: impl Iterator<Item = impl Borrow<Subpath<Id>>>, transform: DAffine2) {
pub fn outline<'a>(&mut self, subpaths: impl Iterator<Item = impl Borrow<Subpath<PointId>>>, transform: DAffine2) {
self.render_context.begin_path();
for subpath in subpaths {
let subpath = subpath.borrow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl DocumentMetadata {

/// Get vector data after the modification is appled
pub fn compute_modified_vector(&self, layer: LayerNodeIdentifier, network: &NodeNetwork) -> Option<VectorData> {
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer, network)?;
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer, network);

if let Some(vector_data) = graph_layer.node_id("Path Modify").and_then(|node| self.vector_modify.get(&node)) {
let mut modified = vector_data.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ use bezier_rs::{ManipulatorGroup, Subpath};
use graph_craft::document::{value::TaggedValue, DocumentNode, NodeId, NodeInput, NodeNetwork};
use graphene_core::raster::{BlendMode, ImageFrame};
use graphene_core::text::Font;
use graphene_core::uuid::ManipulatorGroupId;
use graphene_core::vector::style::{FillType, Gradient};
use graphene_core::vector::PointId;
use graphene_core::Color;

use glam::DVec2;
use std::collections::VecDeque;

/// Create a new vector layer from a vector of [`bezier_rs::Subpath`].
pub fn new_vector_layer(subpaths: Vec<Subpath<ManipulatorGroupId>>, id: NodeId, parent: LayerNodeIdentifier, responses: &mut VecDeque<Message>) -> LayerNodeIdentifier {
pub fn new_vector_layer(subpaths: Vec<Subpath<PointId>>, id: NodeId, parent: LayerNodeIdentifier, responses: &mut VecDeque<Message>) -> LayerNodeIdentifier {
let insert_index = -1;
responses.add(GraphOperationMessage::NewVectorLayer { id, subpaths, parent, insert_index });
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: vec![id] });
Expand Down Expand Up @@ -48,7 +48,7 @@ pub fn new_svg_layer(svg: String, transform: glam::DAffine2, id: NodeId, parent:
}

/// Batch set all of the manipulator groups to set their colinear handle state on a specific layer
pub fn set_manipulator_colinear_handles_state(manipulator_groups: &[ManipulatorGroup<ManipulatorGroupId>], layer: LayerNodeIdentifier, colinear: bool, responses: &mut VecDeque<Message>) {
pub fn set_manipulator_colinear_handles_state(manipulator_groups: &[ManipulatorGroup<PointId>], layer: LayerNodeIdentifier, colinear: bool, responses: &mut VecDeque<Message>) {
for manipulator_group in manipulator_groups {
responses.add(GraphOperationMessage::Vector {
layer,
Expand All @@ -58,7 +58,7 @@ pub fn set_manipulator_colinear_handles_state(manipulator_groups: &[ManipulatorG
}

/// Locate the subpaths from the shape nodes of a particular layer
pub fn get_subpaths(layer: LayerNodeIdentifier, document_network: &NodeNetwork) -> Option<&Vec<Subpath<ManipulatorGroupId>>> {
pub fn get_subpaths(layer: LayerNodeIdentifier, document_network: &NodeNetwork) -> Option<&Vec<Subpath<PointId>>> {
let path_data_node_input_index = 0;
if let TaggedValue::Subpaths(subpaths) = NodeGraphLayer::new(layer, document_network).find_input("Shape", path_data_node_input_index)? {
Some(subpaths)
Expand All @@ -84,12 +84,13 @@ pub fn get_viewport_pivot(layer: LayerNodeIdentifier, document_network: &NodeNet
}

/// Get the manipulator groups that currently have colinear handles for a particular layer from the shape node
pub fn get_colinear_manipulators(layer: LayerNodeIdentifier, document_network: &NodeNetwork) -> Option<&Vec<ManipulatorGroupId>> {
pub fn get_colinear_manipulators(layer: LayerNodeIdentifier, document_network: &NodeNetwork) -> &Vec<PointId> {
let colinear_manipulators_node_input_index = 1;
if let TaggedValue::ManipulatorGroupIds(manipulator_groups) = NodeGraphLayer::new(layer, document_network).find_input("Shape", colinear_manipulators_node_input_index)? {
Some(manipulator_groups)
if let Some(TaggedValue::PointIds(manipulator_groups)) = NodeGraphLayer::new(layer, document_network).find_input("Shape", colinear_manipulators_node_input_index) {
manipulator_groups
} else {
None
static DEFAULT: &'static Vec<PointId> = &Vec::new();
DEFAULT
}
}

Expand Down Expand Up @@ -209,12 +210,12 @@ pub fn is_layer_fed_by_node_of_name(layer: LayerNodeIdentifier, document_network
}

/// Convert subpaths to an iterator of manipulator groups
pub fn get_manipulator_groups(subpaths: &[Subpath<ManipulatorGroupId>]) -> impl Iterator<Item = &bezier_rs::ManipulatorGroup<ManipulatorGroupId>> + DoubleEndedIterator {
pub fn get_manipulator_groups(subpaths: &[Subpath<PointId>]) -> impl Iterator<Item = &bezier_rs::ManipulatorGroup<PointId>> + DoubleEndedIterator {
subpaths.iter().flat_map(|subpath| subpath.manipulator_groups())
}

/// Find a manipulator group with a specific id from several subpaths
pub fn get_manipulator_from_id(subpaths: &[Subpath<ManipulatorGroupId>], id: ManipulatorGroupId) -> Option<&bezier_rs::ManipulatorGroup<ManipulatorGroupId>> {
pub fn get_manipulator_from_id(subpaths: &[Subpath<PointId>], id: PointId) -> Option<&bezier_rs::ManipulatorGroup<PointId>> {
subpaths.iter().find_map(|subpath| subpath.manipulator_from_id(id))
}

Expand Down

0 comments on commit 16feea5

Please sign in to comment.