mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-04 13:30:48 +00:00
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:
parent
a7bf6e2459
commit
6b6accfb91
21 changed files with 778 additions and 50 deletions
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue