Tests: spiral decay is per full wind on main, so four segments give the decay

This commit is contained in:
FredApps
2026-11-14 11:35:04 +01:00
parent 4db24740e4
commit 4552915aae
2 changed files with 6 additions and 3 deletions
+3 -1
View File
@@ -290,9 +290,11 @@ fn legacy_spiral_decay_preferences_report_the_ratio_drawn_after_reopening() {
assert_eq!(anchors.len(), 5);
assert!(!path.is_closed());
let center = Point::new(200.0, 200.0);
// The path runs from the centre end outwards, and decay is per full wind: four quarter-turn
// segments give the decay.
for pair in anchors.windows(2) {
let ratio = pair[0].p.distance(center) / pair[1].p.distance(center);
assert!((100.0 * ratio - decay).abs() < 1e-10);
assert!((100.0 * ratio.powi(4) - decay).abs() < 1e-9);
}
assert_eq!(s.prefs.tool_settings["spiral"]["decay"], json!(99.99));
s.execute("edit.undo", &json!({})).unwrap();
+3 -2
View File
@@ -545,12 +545,13 @@ mod tests {
let (id, params) = t.command(Point::ZERO, Point::new(100.0, 0.0), Mods::default());
assert_eq!(id, "shape.spiral");
assert_eq!(params["decay"], json!(expected));
// Inspect the actual adjacent radii, not a second copy of the tool's clamp.
// Inspect the actual adjacent radii, not a second copy of the tool's clamp. Decay is per full
// wind and a segment is a quarter turn, so four segments give the decay.
let path = vectorcraft_geom::shapes::spiral(Point::ZERO, 100.0, params["decay"].as_f64().unwrap(), 2, true);
let anchors = &path.subpaths[0].anchors;
let outer = anchors[2].p.distance(Point::ZERO);
let next = anchors[1].p.distance(Point::ZERO);
assert!((100.0 * next / outer - expected).abs() < 1e-10);
assert!((100.0 * (next / outer).powi(4) - expected).abs() < 1e-9);
}
for invalid in [Value::Null, json!("80"), json!(false), json!({})] {
t.set_option("decay", &invalid);