Merge pull request #9987 from dotCooCoo/fix/jitter-keeps-link-when-unchanged

Brushes: a jitter too small to change a color keeps its swatch link
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-28 13:38:39 -08:00
commit 455e441ca9
2 files changed
+28 -1

No files matched your search

+4 -1
View File
@@ -267,10 +267,13 @@ fn turned(c: &Color, degrees: f32) -> Option<Color> {
}
}
/// Replace a solid paint's color with what `adjust` gives for it, dropping its swatch link.
/// Replace a solid paint's color with what `adjust` gives for it, dropping its swatch link. A
/// color that comes back unchanged (an amount too small to move its components) keeps the paint
/// and its link.
fn recolor_paint(p: &mut Paint, adjust: &dyn Fn(&Color) -> Option<Color>) {
if let Paint::Solid { color, .. } = p
&& let Some(c) = adjust(color)
&& c != *color
{
*p = Paint::solid(c);
}
+24
View File
@@ -1599,6 +1599,30 @@ fn jitter_at_a_limit_keeps_the_swatch_link() {
}
}
/// A hue or saturation jitter too small to move a Lab color's components gives each copy the color
/// it had, and the copies keep the swatch link.
#[test]
fn jitter_too_small_to_change_a_color_keeps_the_swatch_link() {
let linked = Paint::Solid { color: Color::lab(50.0, 64.0, 0.0), swatch: Some("Spot".into()), tint: 1.0 };
// 1e-50 degrees turns a and b by less than an f32 holds; 1e-6 points scales the chroma by
// 1 + 1.6e-8, which rounds back to the same f32 components.
type Jitter = fn(&mut [Node], f64, u64);
let jitters: [(&str, Jitter, f64); 2] = [("hue", crate::colorize::jitter_hues, 1e-50), ("saturation", crate::colorize::jitter_saturations, 1e-6)];
for (name, jitter, amount) in jitters {
let mut copies: Vec<Node> = (0..8)
.map(|_| {
let mut art = rect_art(10.0, 4.0);
art.appearance.set_fill(linked.clone());
art
})
.collect();
jitter(&mut copies, amount, 7);
for n in &copies {
assert_eq!(n.appearance.fill_paint(), linked, "{name}");
}
}
}
/// An instance whose fill has an opacity of 0 does not stain its symbol's art, so the art keeps its
/// swatch links.
#[test]