Merge pull request #9792 from dotCooCoo/fix/scatter-spacing-stroked-art

Brushes: Scatter brush copies of stroked art are spaced by their stroked width
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-27 21:41:29 -08:00
commit 09bb1855de
3 files changed
+21 -2

No files matched your search

+1 -1
View File
@@ -309,7 +309,7 @@ pub struct Scatter {
pub art: Node,
/// Size range in percent of the art.
pub size: (f64, f64),
/// Spacing range in percent of the (scaled) art width.
/// Spacing range in percent of the (scaled) art width, its strokes included.
pub spacing: (f64, f64),
/// Perpendicular offset range in percent of the (scaled) art height.
pub scatter: (f64, f64),
+16
View File
@@ -272,6 +272,22 @@ fn scatter_count_and_spacing() {
assert_eq!(out.len(), 5);
}
#[test]
fn scatter_spaces_stroked_art_by_its_stroked_width() {
let art = Node::path(
NodeId(0),
shapes::rectangle(Rect::new(0.0, -2.0, 10.0, 2.0)),
Appearance::basic(Paint::solid(Color::BLACK), Paint::solid(Color::BLACK), 2.0),
);
let b = Brush { name: "s".into(), kind: BrushKind::Scatter(Scatter { art, colorization: Colorization::None, ..Default::default() }) };
let out = stroke_pieces(&Document::new(1.0, 1.0), &b, &line(0.0, 0.0, 120.0, 0.0), &stroke(1.0));
let boxes: Vec<Rect> = out.iter().filter_map(Node::visual_bounds).collect();
assert!(boxes.len() > 1, "{boxes:?}");
for w in boxes.windows(2) {
assert!(near(w[1].x0, w[0].x1, 1e-6), "stroked copies at 100% spacing touch: {boxes:?}");
}
}
#[test]
fn scatter_is_deterministic_and_randomised() {
let b = Brush {
+4 -1
View File
@@ -540,7 +540,10 @@ fn vary(rng: &mut Rng, (a, b): (f64, f64), mode: Variation, pen: PenAt) -> f64 {
pub(crate) fn scatter(sc: &Scatter, bp: &BezPath, weight: f64, stroke: &StrokeLayer, name: &str) -> Vec<Node> {
let Some(b) = sc.art.geometric_bounds() else { return vec![] };
let (aw, ah) = (b.width().max(1e-3), b.height().max(1e-3));
// Copies are spaced by the width of the art with its strokes, so at 100% spacing stroked
// copies touch instead of overlapping by the stroke.
let aw = sc.art.visual_bounds().unwrap_or(b).width().max(1e-3);
let ah = b.height().max(1e-3);
let mut rng = Rng::new(seed_of(bp, name));
let [size_mode, spacing_mode, scatter_mode, rotation_mode] = sc.modes();
let mut out = Budget::default();