mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-22 02:15:24 +01:00
Pathfinder: setting a precision past a scaled one is an edit
After Scale Strokes & Effects takes a Pathfinder effect's precision past 10 pt, the effect evaluates at 10 pt. `effect.setParams` with `precision: 10` now replaces the stored value and records an undo step, so a later scale starts from 10 pt. Values equal to the stored ones, and defaults given to an effect saved without options, are still no edit.
This commit is contained in:
1 parent
d8eae5b560
commit
ad3c0f0127
2 files changed
+32
-2
No files matched your search
@@ -912,7 +912,9 @@ pub(crate) fn set_params(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
|
||||
/// Does merging `params` into Pathfinder effect `e` leave it drawing as it does: the same Pathfinder
|
||||
/// Options ([`effects::PathfinderEffectOptions`], so an effect saved without them and given their
|
||||
/// defaults is unchanged) and every other value given equal to the one it has?
|
||||
/// defaults is unchanged), each option given equal to the one it stores (a precision that Scale
|
||||
/// Strokes & Effects took past its range evaluates at the bound but is still edited), and every
|
||||
/// other value given equal to the one it has?
|
||||
fn pathfinder_edit_changes_nothing(e: &Effect, params: &Value) -> bool {
|
||||
if !effects::takes_pathfinder_options(&e.id) {
|
||||
return false;
|
||||
@@ -924,7 +926,12 @@ fn pathfinder_edit_changes_nothing(e: &Effect, params: &Value) -> bool {
|
||||
m.extend(given.clone());
|
||||
}
|
||||
let others_same = given.iter().filter(|(k, _)| !effects::PATHFINDER_OPTION_KEYS.contains(&k.as_str())).all(|(k, v)| current.get(k) == Some(v));
|
||||
others_same && effects::PathfinderEffectOptions::from_params(¤t) == effects::PathfinderEffectOptions::from_params(&after)
|
||||
let same_value = |a: &Value, b: &Value| a == b || a.as_f64().is_some_and(|x| b.as_f64() == Some(x));
|
||||
let stored_same = given
|
||||
.iter()
|
||||
.filter(|(k, _)| effects::PATHFINDER_OPTION_KEYS.contains(&k.as_str()))
|
||||
.all(|(k, v)| e.params.get(k).is_none_or(|stored| same_value(stored, v)));
|
||||
others_same && stored_same && effects::PathfinderEffectOptions::from_params(¤t) == effects::PathfinderEffectOptions::from_params(&after)
|
||||
}
|
||||
|
||||
// ---------- Load Texture ----------
|
||||
|
||||
@@ -1913,6 +1913,29 @@ fn pathfinder_effect_options_edit_as_one_step_and_refuse_bad_values() {
|
||||
assert_eq!(first_effect_params(&s), json!({}), "undo restores the options");
|
||||
}
|
||||
|
||||
/// A precision that Scale Strokes & Effects took past the range evaluates at its bound, and setting
|
||||
/// the bound is still an edit: a later scale then starts from the value set.
|
||||
#[test]
|
||||
fn a_precision_set_after_a_scale_past_its_range_is_kept() {
|
||||
let mut s = session();
|
||||
let (a, b) = (rect(&mut s, 0.0, 0.0, 100.0, 100.0), rect(&mut s, 50.0, 50.0, 100.0, 100.0));
|
||||
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
|
||||
s.execute("effect.apply", &json!({"effect": "pathfinder.add", "params": {"precision": 8}})).unwrap();
|
||||
let precision = |s: &Session| first_effect_params(s)["precision"].as_f64();
|
||||
s.execute("object.scale", &json!({"sx": 200, "strokes": true})).unwrap();
|
||||
assert_eq!(precision(&s), Some(16.0));
|
||||
let steps = s.doc().unwrap().history.undo.len();
|
||||
let out = s.execute("effect.setParams", &json!({"index": 0, "params": {"precision": 10}})).unwrap();
|
||||
assert_ne!(out, json!({"ids": []}), "an edit");
|
||||
assert_eq!((precision(&s), s.doc().unwrap().history.undo.len()), (Some(10.0), steps + 1));
|
||||
s.execute("object.scale", &json!({"sx": 50, "strokes": true})).unwrap();
|
||||
assert_eq!(precision(&s), Some(5.0));
|
||||
// The value it stores is still no edit.
|
||||
let steps = s.doc().unwrap().history.undo.len();
|
||||
assert_eq!(s.execute("effect.setParams", &json!({"index": 0, "params": {"precision": 5}})).unwrap(), json!({"ids": []}));
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps);
|
||||
}
|
||||
|
||||
/// A single group containing multiple overlapping paths is accepted by Crop.
|
||||
#[test]
|
||||
fn crop_operates_on_a_single_selected_group_of_paths() {
|
||||
|
||||
Reference in new issue
Block a user