Add Poisson-disk sampling node and Bezier-rs 0.4 release (#1586)

* Add Poisson-disk sampling node and Bezier-rs 0.4 release

* Additional optimizations

* More performance optimizations with help from 0Hypercube

* Add comments
This commit is contained in:
Keavon Chambers
2024-01-28 02:25:46 -08:00
committed by GitHub
parent a7bf6e2459
commit 6b6accfb91
21 changed files with 778 additions and 50 deletions

View File

@@ -52,16 +52,13 @@ image = { workspace = true, optional = true, default-features = false, features
"png",
] }
specta = { workspace = true, optional = true }
rustybuzz = { workspace = true, optional = true }
num-derive = { workspace = true }
num-traits = { workspace = true, default-features = false, features = ["i128"] }
wasm-bindgen = { workspace = true, optional = true }
js-sys = { workspace = true, optional = true }
usvg = { workspace = true }
rand = { workspace = true, default-features = false, features = ["std_rng"] }
[dependencies.web-sys]
workspace = true

View File

@@ -483,7 +483,7 @@ impl Color {
if luminance <= 0.008856 {
(luminance * 903.3) / 100.
} else {
(luminance.powf(1. / 3.) * 116. - 16.) / 100.
(luminance.cbrt() * 116. - 16.) / 100.
}
}

View File

@@ -7,6 +7,7 @@ use core::future::Future;
use bezier_rs::{Subpath, SubpathTValue, TValue};
use glam::{DAffine2, DVec2};
use rand::{Rng, SeedableRng};
#[derive(Debug, Clone, Copy)]
pub struct SetFillNode<FillType, SolidColor, GradientType, Start, End, Transform, Positions> {
@@ -276,6 +277,30 @@ async fn sample_points<FV: Future<Output = VectorData>, FL: Future<Output = Vec<
vector_data
}
#[derive(Debug, Clone, Copy)]
pub struct PoissonDiskPoints<SeparationDiskDiameter> {
separation_disk_diameter: SeparationDiskDiameter,
}
#[node_macro::node_fn(PoissonDiskPoints)]
fn poisson_disk_points(mut vector_data: VectorData, separation_disk_diameter: f32) -> VectorData {
let mut rng = rand::rngs::StdRng::seed_from_u64(0);
for subpath in &mut vector_data.subpaths.iter_mut() {
if subpath.manipulator_groups().len() < 3 {
continue;
}
subpath.apply_transform(vector_data.transform);
let points = subpath.poisson_disk_points(separation_disk_diameter as f64, || rng.gen::<f64>()).into_iter().map(|point| point.into());
*subpath = Subpath::from_anchors(points, false);
subpath.apply_transform(vector_data.transform.inverse());
}
vector_data
}
#[derive(Debug, Clone, Copy)]
pub struct LengthsOfSegmentsOfSubpaths;
@@ -323,8 +348,10 @@ async fn morph<SourceFuture: Future<Output = VectorData>, TargetFuture: Future<O
source: impl Node<Footprint, Output = SourceFuture>,
target: impl Node<Footprint, Output = TargetFuture>,
start_index: u32,
time: f64,
time: f32,
) -> VectorData {
let time = time as f64;
let mut source = self.source.eval(footprint).await;
let mut target = self.target.eval(footprint).await;

View File

@@ -28,19 +28,19 @@ wayland = []
[dependencies]
fastnoise-lite = { workspace = true }
rand = { workspace = true, features = [
rand = { workspace = true, default-features = false, features = [
"alloc",
"small_rng",
], default-features = false }
] }
rand_chacha = { workspace = true }
autoquant = { git = "https://github.com/truedoctor/autoquant", optional = true, features = [
"fitting",
] }
graphene-core = { path = "../gcore", features = [
graphene-core = { path = "../gcore", default-features = false, features = [
"std",
"serde",
"alloc",
], default-features = false }
] }
dyn-any = { path = "../../libraries/dyn-any", features = ["derive"] }
graph-craft = { path = "../graph-craft", features = ["serde"] }
vulkan-executor = { path = "../vulkan-executor", optional = true }

View File

@@ -735,9 +735,10 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
async_node!(graphene_core::vector::CopyToPoints<_, _>, input: Footprint, output: VectorData, fn_params: [Footprint => VectorData, Footprint => VectorData]),
async_node!(graphene_core::vector::CopyToPoints<_, _>, input: Footprint, output: GraphicGroup, fn_params: [Footprint => VectorData, Footprint => GraphicGroup]),
async_node!(graphene_core::vector::SamplePoints<_, _, _, _, _, _>, input: Footprint, output: VectorData, fn_params: [Footprint => VectorData, () => f32, () => f32, () => f32, () => bool, Footprint => Vec<Vec<f64>>]),
register_node!(graphene_core::vector::PoissonDiskPoints<_>, input: VectorData, params: [f32]),
register_node!(graphene_core::vector::LengthsOfSegmentsOfSubpaths, input: VectorData, params: []),
register_node!(graphene_core::vector::SplinesFromPointsNode, input: VectorData, params: []),
async_node!(graphene_core::vector::MorphNode<_, _, _, _>, input: Footprint, output: VectorData, fn_params: [Footprint => VectorData, Footprint => VectorData, () => u32, () => f64]),
async_node!(graphene_core::vector::MorphNode<_, _, _, _>, input: Footprint, output: VectorData, fn_params: [Footprint => VectorData, Footprint => VectorData, () => u32, () => f32]),
register_node!(graphene_core::vector::generator_nodes::CircleGenerator<_>, input: (), params: [f32]),
register_node!(graphene_core::vector::generator_nodes::EllipseGenerator<_, _>, input: (), params: [f32, f32]),
register_node!(graphene_core::vector::generator_nodes::RectangleGenerator<_, _>, input: (), params: [f32, f32]),