From e45cbb106bf601a4c496a60eadefd2ac7accd88a Mon Sep 17 00:00:00 2001 From: yoriswind Date: Sat, 28 Nov 2026 08:14:22 -0800 Subject: [PATCH] Use the brush short axis for dab spacing --- .../src/brush_spacing_elliptic_tip_tests.rs | 41 +++++++++++++++++++ crates/paint/src/dynamics.rs | 5 ++- crates/paint/src/lib.rs | 3 ++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 crates/paint/src/brush_spacing_elliptic_tip_tests.rs diff --git a/crates/paint/src/brush_spacing_elliptic_tip_tests.rs b/crates/paint/src/brush_spacing_elliptic_tip_tests.rs new file mode 100644 index 0000000000..7f7d01b1cd --- /dev/null +++ b/crates/paint/src/brush_spacing_elliptic_tip_tests.rs @@ -0,0 +1,41 @@ +//! #17310: own synthetic strokes exercise the measured short-axis spacing law. + +use photocraft_color::PixelFormat; +use photocraft_raster::Surface; + +use crate::{BrushSettings, Stroke, StrokePoint, dabs, render_stroke}; + +#[test] +fn flattened_tip_spacing_uses_the_short_axis_at_both_angles_and_directions() { + for angle in [0.0, 90.0] { + for vertical in [false, true] { + let brush = BrushSettings { size: 40.0, roundness: 0.2, angle, spacing: 1.5, seed: 17310, ..BrushSettings::default() }; + let points = if vertical { + vec![StrokePoint::new(100.0, 100.0, 1.0), StrokePoint::new(100.0, 400.0, 1.0)] + } else { + vec![StrokePoint::new(100.0, 100.0, 1.0), StrokePoint::new(400.0, 100.0, 1.0)] + }; + let steps = dabs(&Stroke { brush, points }); + assert_eq!(steps.len(), 26, "{angle} degrees, vertical={vertical}"); + for (index, dab) in steps.iter().enumerate() { + let coordinate = if vertical { dab.center.y } else { dab.center.x }; + assert!((coordinate - (100.0 + 12.0 * index as f64)).abs() < 1e-4); + } + } + } +} + +#[test] +fn half_roundness_stays_continuous_and_round_tips_keep_their_last_dab() { + let points = [StrokePoint::new(100.0, 100.0, 1.0), StrokePoint::new(400.0, 100.0, 1.0)]; + let brush = BrushSettings { size: 40.0, roundness: 0.5, spacing: 1.5, seed: 17310, ..BrushSettings::default() }; + let mut surface = Surface::new(PixelFormat::RGBA32F); + render_stroke(&mut surface, &brush, &points, None, false, 1.0); + for x in 100..=400 { + assert!(surface.rgba(x, 100)[3] > 0.5, "gap at {x}"); + } + let round = BrushSettings { size: 20.0, roundness: 1.0, spacing: 2.0, ..brush }; + let steps = dabs(&Stroke { brush: round, points: points.to_vec() }); + assert_eq!(steps.len(), 8); + assert!((steps.last().unwrap().center.x - 380.0).abs() < 1e-4); +} diff --git a/crates/paint/src/dynamics.rs b/crates/paint/src/dynamics.rs index 0428ea9edd..6bc9dbfb5c 100644 --- a/crates/paint/src/dynamics.rs +++ b/crates/paint/src/dynamics.rs @@ -593,11 +593,12 @@ pub fn base_diameter(b: &BrushSettings, s: &StepInput) -> f32 { b.size * f } -/// Distance to the next step at `p`: the diameter there times the spacing. +/// Distance to the next step at `p`: the pre-jitter short axis times the spacing. fn step_len_for(brush: &BrushSettings, p: &StrokePoint) -> f64 { let s = StepInput { point: *p, direction: 0.0, initial_direction: 0.0, step: 0 }; let d = base_diameter(brush, &s).max(1.0); - f64::from(d * brush.spacing.max(0.01)).max(0.5) + let short_axis = d * brush.roundness.clamp(0.01, 1.0); + f64::from(short_axis * brush.spacing.max(0.01)).max(0.5) } /// Builds the primary dabs of a step (Shape Dynamics, Scattering, Transfer, Color, Texture depth). diff --git a/crates/paint/src/lib.rs b/crates/paint/src/lib.rs index d82132f3c6..3ae776ea5f 100644 --- a/crates/paint/src/lib.rs +++ b/crates/paint/src/lib.rs @@ -417,3 +417,6 @@ mod mixer_load_supply_tests; #[cfg(test)] mod smoothing_catch_up_default_tests; + +#[cfg(test)] +mod brush_spacing_elliptic_tip_tests;