Skip to content

Refactor vector data type from document-legacy into node graph #1057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions document-legacy/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
use graphene_core::raster::color::Color;

// RENDERING
pub const LAYER_OUTLINE_STROKE_COLOR: Color = Color::BLACK;
pub const LAYER_OUTLINE_STROKE_WEIGHT: f64 = 1.;

// BOOLEAN OPERATIONS

// Bezier curve intersection algorithm
Expand Down
9 changes: 8 additions & 1 deletion document-legacy/src/layers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ pub mod layer_info;
pub mod nodegraph_layer;
/// Contains the [ShapeLayer](shape_layer::ShapeLayer) type, a generic SVG element defined using Bezier paths.
pub mod shape_layer;
pub mod style;
/// Contains the [TextLayer](text_layer::TextLayer) type.
pub mod text_layer;

mod render_data;
pub use render_data::RenderData;

pub mod style {
pub use super::RenderData;
pub use graphene_core::vector::style::*;
}
22 changes: 22 additions & 0 deletions document-legacy/src/layers/render_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use super::style::ViewMode;
use super::text_layer::FontCache;

use glam::DVec2;

/// Contains metadata for rendering the document as an svg
#[derive(Debug, Clone, Copy)]
pub struct RenderData<'a> {
pub font_cache: &'a FontCache,
pub view_mode: ViewMode,
pub culling_bounds: Option<[DVec2; 2]>,
}

impl<'a> RenderData<'a> {
pub fn new(font_cache: &'a FontCache, view_mode: ViewMode, culling_bounds: Option<[DVec2; 2]>) -> Self {
Self {
font_cache,
view_mode,
culling_bounds,
}
}
}
2 changes: 0 additions & 2 deletions editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ serde_json = { version = "1.0" }
graphite-proc-macros = { path = "../proc-macros" }
bezier-rs = { path = "../libraries/bezier-rs" }
glam = { version="0.22", features = ["serde"] }
rand_chacha = "0.3.1"
spin = "0.9.2"
kurbo = { git = "https://github.com/linebender/kurbo.git", features = [
"serde",
] }
Expand Down
25 changes: 1 addition & 24 deletions editor/src/application.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
use crate::dispatcher::Dispatcher;
use crate::messages::prelude::*;

use rand_chacha::rand_core::{RngCore, SeedableRng};
use rand_chacha::ChaCha20Rng;
use spin::Mutex;
use std::cell::Cell;

static RNG: Mutex<Option<ChaCha20Rng>> = Mutex::new(None);
thread_local! {
pub static UUID_SEED: Cell<Option<u64>> = Cell::new(None);
}
pub use graphene_core::uuid::*;

// TODO: serialize with serde to save the current editor state
pub struct Editor {
Expand Down Expand Up @@ -39,21 +31,6 @@ impl Default for Editor {
}
}

pub fn set_uuid_seed(random_seed: u64) {
UUID_SEED.with(|seed| seed.set(Some(random_seed)))
}

pub fn generate_uuid() -> u64 {
let mut lock = RNG.lock();
if lock.is_none() {
UUID_SEED.with(|seed| {
let random_seed = seed.get().expect("Random seed not set before editor was initialized");
*lock = Some(ChaCha20Rng::seed_from_u64(random_seed));
})
}
lock.as_mut().map(ChaCha20Rng::next_u64).unwrap()
}

pub fn release_series() -> String {
format!("Release Series: {}", env!("GRAPHITE_RELEASE_SERIES"))
}
Expand Down
2 changes: 2 additions & 0 deletions node-graph/gcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ kurbo = { git = "https://github.com/linebender/kurbo.git", features = [
"serde",
], optional = true }
glam = { version = "^0.22", default-features = false, features = ["scalar-math", "libm"]}
rand_chacha = "0.3.1"
spin = "0.9.2"
node-macro = {path = "../node-macro"}
specta.workspace = true
once_cell = { version = "1.17.0", default-features = false }
Expand Down
5 changes: 5 additions & 0 deletions node-graph/gcore/src/consts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::raster::Color;

// RENDERING
pub const LAYER_OUTLINE_STROKE_COLOR: Color = Color::BLACK;
pub const LAYER_OUTLINE_STROKE_WEIGHT: f64 = 1.;
2 changes: 2 additions & 0 deletions node-graph/gcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern crate alloc;
#[cfg(feature = "log")]
extern crate log;

pub mod consts;
pub mod generic;
pub mod ops;
pub mod structural;
Expand All @@ -22,6 +23,7 @@ pub mod raster;
pub mod vector;

use core::any::TypeId;
pub use raster::Color;

// pub trait Node: for<'n> NodeIO<'n> {
pub trait Node<'i, Input: 'i>: 'i {
Expand Down
2 changes: 1 addition & 1 deletion node-graph/gcore/src/raster/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct Color {
alpha: f32,
}

#[allow(clippy::derive_hash_xor_eq)]
#[allow(clippy::derived_hash_with_manual_eq)]
impl Hash for Color {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.red.to_bits().hash(state);
Expand Down
38 changes: 38 additions & 0 deletions node-graph/gcore/src/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,41 @@ mod u64_string {
u64::from_str(&s).map_err(serde::de::Error::custom)
}
}

mod uuid_generation {
use core::cell::Cell;
use rand_chacha::rand_core::{RngCore, SeedableRng};
use rand_chacha::ChaCha20Rng;
use spin::Mutex;

static RNG: Mutex<Option<ChaCha20Rng>> = Mutex::new(None);
thread_local! {
pub static UUID_SEED: Cell<Option<u64>> = Cell::new(None);
}

pub fn set_uuid_seed(random_seed: u64) {
UUID_SEED.with(|seed| seed.set(Some(random_seed)))
}

pub fn generate_uuid() -> u64 {
let mut lock = RNG.lock();
if lock.is_none() {
UUID_SEED.with(|seed| {
let random_seed = seed.get().unwrap_or(42);
*lock = Some(ChaCha20Rng::seed_from_u64(random_seed));
})
}
lock.as_mut().map(ChaCha20Rng::next_u64).expect("uuid mutex poisoned")
}
}

pub use uuid_generation::*;

#[derive(Clone, Copy, PartialEq, Eq)]
pub struct ManipulatorGroupId(u64);

impl bezier_rs::Identifier for ManipulatorGroupId {
fn new() -> Self {
Self(generate_uuid())
}
}
12 changes: 11 additions & 1 deletion node-graph/gcore/src/vector/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
pub mod consts;
pub mod generator_nodes;
pub mod id_vec;
pub mod manipulator_group;
pub mod manipulator_point;

pub mod style;
pub use style::PathStyle;

pub mod subpath;
pub use subpath::Subpath;

mod vector_data;
pub use vector_data::VectorData;

mod id_vec;
pub use id_vec::IdBackedVec;
Loading