Pathfinder: Scale Strokes & Effects scales a Pathfinder effect's precision

The Pathfinder effects' `precision` is now a distance parameter, as Trap's
is, so `effect.list` lists it under `lengths`, Scale Strokes & Effects
scales it with the object, and the Appearance panel's effect fields show
it in document units. An effect saved without a precision gets the default it evaluates
with, scaled.
This commit is contained in:
dotCooCoo committed 2026-11-17 08:29:09 -08:00
1 parent 66f805f098
commit d8eae5b560
3 files changed
+33 -2

No files matched your search

+2
View File
@@ -111,6 +111,8 @@ fn lengths_of(id: &str) -> Lengths {
"sketch.tornEdges" => always(&["smoothness"]),
"sketch.waterPaper" => always(&["fiberLength"]),
TRAP => always(&["thickness", "precision"]),
// The Pathfinder Options' refit tolerance.
id if crate::takes_pathfinder_options(id) => always(&["precision"]),
RASTERIZE => always(&["addAround"]),
// The points one unit of the filter measures.
crate::SVG_FILTER => always(&["scale"]),
+7 -2
View File
@@ -120,7 +120,10 @@ pub fn new_effect(id: &str, params: &Value) -> Option<Effect> {
/// Scale the distance parameters of `e` by `s` (Scale Strokes & Effects; see
/// [`EffectInfo::lengths`]), and its sizes in raster pixels ([`crate::raster_px_range`]), which
/// keep their share of the object so. A distance left at its default is written out scaled; one
/// the effect doesn't have (Outline Stroke's weight following its stroke) stays absent.
/// the effect doesn't have (Outline Stroke's weight following its stroke) stays absent. A Pathfinder
/// effect without a `precision` gets the precision it evaluates with, scaled. Values are scaled
/// as stored, out of range or not, so a scale and its inverse restore them; evaluation applies
/// each effect's range.
pub fn scale_effect(e: &mut Effect, s: f64) {
let Some(info) = catalog_index().get(e.id.as_str()) else { return };
let merged = merged_params(&e.id, &e.params);
@@ -128,7 +131,9 @@ pub fn scale_effect(e: &mut Effect, s: f64) {
let mut keys: Vec<&str> = info.lengths.keys(relative).collect();
keys.extend(merged.as_object().into_iter().flat_map(|m| m.keys()).map(String::as_str).filter(|k| crate::raster_px_range(&e.id, k).is_some()));
for k in keys {
let v = util::num(&merged, k, f64::NAN);
let missing =
if k == "precision" && crate::takes_pathfinder_options(&e.id) { crate::PathfinderEffectOptions::default().precision } else { f64::NAN };
let v = util::num(&merged, k, missing);
if v.is_finite() {
if !e.params.is_object() {
e.params = Value::Object(Map::new());
+24
View File
@@ -2012,3 +2012,27 @@ fn color_halftones_radius_is_in_raster_pixels_not_a_distance() {
crate::scale_effect(&mut e, 2.0);
assert_eq!((e.params["maxRadius"].as_f64(), e.params["channel1"].as_f64()), (Some(20.0), Some(108.0)));
}
#[test]
fn a_pathfinder_effects_precision_is_a_distance_that_scales_with_the_object() {
for (id, _, _) in PATHFINDER_EFFECTS {
assert!(is_length(id, "precision", false), "{id}");
assert_eq!(length_range(id, "precision"), Some(PATHFINDER_EFFECT_PRECISION), "{id}");
assert!(!is_length(id, "removeRedundantPoints", false) && !is_length(id, "removeUnpainted", false), "{id}");
// Scale Strokes & Effects scales the tolerance with the geometry it is refit to.
let mut e = crate::new_effect(id, &json!({"precision": 0.5, "removeUnpainted": true})).unwrap();
crate::scale_effect(&mut e, 4.0);
assert_eq!(e.params["precision"].as_f64(), Some(2.0), "{id}");
assert_eq!(e.params["removeUnpainted"], json!(true), "{id}");
// An effect saved without the options scales the precision it evaluates with.
let mut e = crate::new_effect(id, &json!({})).unwrap();
crate::scale_effect(&mut e, 3.0);
let scaled = e.params["precision"].as_f64().unwrap_or(f64::NAN);
assert!((scaled - PathfinderEffectOptions::default().precision * 3.0).abs() < 1e-12, "{id}: {scaled}");
// A scale past the range and its inverse restore the precision, as with other distances.
let mut e = crate::new_effect(id, &json!({"precision": 8.0})).unwrap();
crate::scale_effect(&mut e, 2.0);
crate::scale_effect(&mut e, 0.5);
assert_eq!(e.params["precision"].as_f64(), Some(8.0), "{id}");
}
}