mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Brushes: saturation jitter keeps a swatch link when the saturation stays
A copy whose saturation jitter would move a color past full saturation (or past the largest Lab a and b) left the color as it was but still dropped its swatch link, so a spot or global color lost its link in those copies. Such a copy now keeps the color and its link, as brightness jitter does for a color already at black or at full brightness.
This commit is contained in:
1 parent
0a74dcc564
commit
4901407eac
2 files changed
+38
-3
No files matched your search
@@ -212,7 +212,8 @@ const LAB_AB_MAX: f64 = 127.0;
|
||||
/// so its hue and brightness stay: RGB in HSB of its values, CMYK over C, M and Y with K kept, Lab
|
||||
/// by moving its chroma (the length of a and b) by `points` with its lightness and hue angle kept.
|
||||
/// The result stays between no saturation and full. `None` for a color without a hue (white,
|
||||
/// black and grays, which have no saturation to move).
|
||||
/// black and grays, which have no saturation to move) and for one whose saturation stays as it is
|
||||
/// (already at the end it would move past), so such a color keeps its swatch link.
|
||||
fn saturated(c: &Color, points: f32) -> Option<Color> {
|
||||
if !points.is_finite() || vectorcraft_color::recolor::Neutral::of(c).is_some() {
|
||||
return None;
|
||||
@@ -220,7 +221,8 @@ fn saturated(c: &Color, points: f32) -> Option<Color> {
|
||||
let by = points / 100.0;
|
||||
let move_by = |v: [f32; 3]| {
|
||||
let [h, s, b] = vectorcraft_color::rgb_to_hsb(v);
|
||||
(s > 0.0).then(|| vectorcraft_color::hsb_to_rgb([h, (s + by).clamp(0.0, 1.0), b]))
|
||||
let to = (s + by).clamp(0.0, 1.0);
|
||||
(s > 0.0 && to != s).then(|| vectorcraft_color::hsb_to_rgb([h, to, b]))
|
||||
};
|
||||
match *c {
|
||||
Color::Rgb { r, g, b } => move_by([r, g, b]).map(|[r, g, b]| Color::rgb(r, g, b)),
|
||||
@@ -236,7 +238,7 @@ fn saturated(c: &Color, points: f32) -> Option<Color> {
|
||||
// already reaches past that does not grow.
|
||||
let fit = (LAB_AB_MAX / a.abs().max(b.abs())).max(1.0);
|
||||
let scale = ((chroma + f64::from(points)).max(0.0) / chroma).min(fit);
|
||||
Some(Color::lab(l, (a * scale) as f32, (b * scale) as f32))
|
||||
(scale != 1.0).then(|| Color::lab(l, (a * scale) as f32, (b * scale) as f32))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1566,6 +1566,39 @@ fn brightness_jitter_moves_after_the_colorization_in_each_model() {
|
||||
assert!(lab.iter().all(|c| matches!(*c, Color::Lab { l, a, b } if a == 40.0 && b == 30.0 && (l - 50.0).abs() <= 20.001)), "{lab:?}");
|
||||
}
|
||||
|
||||
/// A swatch-linked color already at the end a copy's saturation or brightness moves toward stays as
|
||||
/// it is and keeps its link; the copies that move it lose the link.
|
||||
#[test]
|
||||
fn jitter_at_a_limit_keeps_the_swatch_link() {
|
||||
let doc = Document::new(1.0, 1.0);
|
||||
let path = line(0.0, 0.0, 200.0, 0.0);
|
||||
// Full red (full saturation and brightness), full magenta and yellow ink, and a Lab red whose a
|
||||
// is at its largest: saturation that grows and brightness that grows leave them as they are.
|
||||
for (color, saturation_jitter, brightness_jitter) in [
|
||||
(Color::rgb(1.0, 0.0, 0.0), 50.0, 0.0),
|
||||
(Color::cmyk(0.0, 1.0, 1.0, 0.0), 50.0, 0.0),
|
||||
(Color::lab(50.0, 127.0, 0.0), 50.0, 0.0),
|
||||
(Color::rgb(1.0, 0.0, 0.0), 0.0, 50.0),
|
||||
(Color::lab(100.0, 20.0, 10.0), 0.0, 50.0),
|
||||
] {
|
||||
let linked = Paint::Solid { color, swatch: Some("Spot".into()), tint: 1.0 };
|
||||
let mut art = rect_art(10.0, 4.0);
|
||||
art.appearance.set_fill(linked.clone());
|
||||
let mut s = Scatter { art, saturation_jitter, ..Default::default() };
|
||||
s.brightness_jitter = brightness_jitter;
|
||||
let out = stroke_pieces(&doc, &Brush { name: "s".into(), kind: BrushKind::Scatter(s) }, &path, &stroke(1.0));
|
||||
let (mut kept, mut moved) = (0, 0);
|
||||
for n in &out {
|
||||
match n.appearance.fill_paint() {
|
||||
p if p == linked => kept += 1,
|
||||
Paint::Solid { color: c, swatch: None, .. } if c != color => moved += 1,
|
||||
p => panic!("{color:?}: {p:?}"),
|
||||
}
|
||||
}
|
||||
assert!(kept > 0 && moved > 0, "{color:?}: {kept} kept, {moved} moved");
|
||||
}
|
||||
}
|
||||
|
||||
/// An instance whose fill has an opacity of 0 does not stain its symbol's art, so the art keeps its
|
||||
/// swatch links.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user