mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-21 18:04:03 +01:00
Symbols: Average keeps opacities below the Screener's 5% minimum
The Symbol Screener with Method Average, and the Symbol Sprayer with Screen: Average, clamped the averaged opacity to the Screener's 5% minimum. A new instance sprayed beside invisible ones became visible, and instances below 5% were raised instead of moving toward their mean. Averages now stay within 0..1; the non-average Screener still stops at 5%. docs/mcp.md also states that the User Defined Styler applies the whole style whatever the intensity or pen pressure.
This commit is contained in:
1 parent
7d0aef8bc5
commit
6d470d9878
3 files changed
+31
-3
No files matched your search
@@ -1008,7 +1008,7 @@ pub(super) fn symbol_spray(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if modes.screen
|
||||
&& let Some(m) = near
|
||||
{
|
||||
n.opacity = (m.opacity as f32).clamp(0.05, 1.0);
|
||||
n.opacity = (m.opacity as f32).clamp(0.0, 1.0);
|
||||
}
|
||||
// The stain and the style are both the instance's fill: the style, set last, replaces
|
||||
// the stain, an averaged one too when the instances under the brush have a fill.
|
||||
@@ -1254,7 +1254,8 @@ pub(super) fn symbol_adjust(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
_ => {
|
||||
let step = (0.1 * w * share) as f32;
|
||||
n.opacity = match &avg {
|
||||
Some((t, _)) => (n.opacity + ((t.opacity - f64::from(n.opacity)) * w.min(1.0)) as f32).clamp(0.05, 1.0),
|
||||
// The mean may be below the 5% the Screener otherwise stops at.
|
||||
Some((t, _)) => (n.opacity + ((t.opacity - f64::from(n.opacity)) * w.min(1.0)) as f32).clamp(0.0, 1.0),
|
||||
None if alt => (n.opacity + step).min(1.0),
|
||||
None => (n.opacity - step).max(0.05),
|
||||
};
|
||||
|
||||
@@ -119,6 +119,30 @@ fn average_brings_the_instances_under_the_brush_toward_their_mean() {
|
||||
assert!(pa > oa && pb < 1.0 && (pa - pb).abs() < (1.0 - oa) / 2.0, "{pa} {pb} from {oa}");
|
||||
}
|
||||
|
||||
/// Average opacities below the Symbol Screener's least opacity (5%) stay below it: with the Screener
|
||||
/// the instances meet at their mean, and a sprayed instance takes the mean of those under the brush.
|
||||
#[test]
|
||||
fn average_keeps_opacities_below_the_screeners_least() {
|
||||
let mut s = session();
|
||||
let set = NodeId(s.execute("symbol.spray", &json!({"name": "Dot", "points": [[200, 150]], "radius": 4})).unwrap()["id"].as_u64().unwrap());
|
||||
let a = members(&s, set)[0];
|
||||
let b = dot(&mut s, 220.0, 150.0);
|
||||
for (id, opacity) in [(a, 0), (b, 2)] {
|
||||
s.select(|_, sel| sel.set([id])).unwrap();
|
||||
s.execute("transparency.set", &json!({"opacity": opacity})).unwrap();
|
||||
}
|
||||
s.select(|_, sel| sel.set([set])).unwrap();
|
||||
// A new instance beside the invisible one takes its opacity.
|
||||
s.execute("symbol.spray", &json!({"name": "Dot", "points": [[185, 150]], "radius": 20})).unwrap();
|
||||
let sprayed = *members(&s, set).last().unwrap();
|
||||
assert_eq!(node(&s, sprayed).opacity, 0.0);
|
||||
// The Screener with Average brings 0% and 2% toward 1%, not up to 5%.
|
||||
s.select(|_, sel| sel.clear()).unwrap();
|
||||
adjust(&mut s, json!({"tool": "screen", "points": [[210, 150]], "radius": 40, "intensity": 10, "method": "average"}));
|
||||
let (pa, pb) = (node(&s, a).opacity, node(&s, b).opacity);
|
||||
assert!(pa > 0.0 && pa < 0.02 && pb < 0.02 && pb > 0.0, "{pa} {pb}");
|
||||
}
|
||||
|
||||
/// Average over instances that already have the mean, or a stroke over no instance, changes
|
||||
/// nothing and adds no undo step.
|
||||
#[test]
|
||||
|
||||
+4
-1
@@ -3427,7 +3427,10 @@ already walks Image Trace. Short agent entry points:
|
||||
Scruncher its distance from their middle toward their mean distance, the Sizer the geometric mean of their sizes,
|
||||
the Spinner their mean direction, the Stainer and the Styler their mean amount, the Screener their mean opacity.
|
||||
`alt` does not reverse it. An instance already at the mean is left as it is, and no undo step is added when
|
||||
no instance changes.
|
||||
no instance changes. The Screener's average, and the opacity a sprayed instance takes as its average, can be
|
||||
below the 5% that the Screener otherwise stops at.
|
||||
- With `userDefined` the Styler gives each instance under the brush the whole style, whatever the intensity or the
|
||||
pen pressure; `random` scales each instance's share by the brush strength there.
|
||||
- With `proportional` false a drag resizes along its own direction (a level drag the width, an upright one the
|
||||
height) and one point resizes both. With `affectsDensity` an instance also moves away from the point as it grows
|
||||
and toward it as it shrinks.
|
||||
|
||||
Reference in new issue
Block a user