Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge pull request #1088 from vangel76/fix-1042-vertex-over-bounds

Brandon Thomas3e6d07af0e1f
diff --cc crates/ui-egui/src/panels/viewer.rs
index fe583c8ce,707f9a818..a7336aaf2
--- a/crates/ui-egui/src/panels/viewer.rs
+++ b/crates/ui-egui/src/panels/viewer.rs
@@@ -2638,48 -2630,22 +2657,64 @@@ mod tests
use super::*;
use effectcraft_engine::geom::{Mat4, vec3};
+ /// The Rotation tool counts past a full turn in both directions, as in After Effects: the
+ /// pointer going round the anchor 1.5 turns clockwise gives 540°, then back 2 turns gives
+ /// −180°, with no jump where atan2 wraps from 180° to −180°.
+ #[test]
+ fn rotate_tool_accumulates_revolutions() {
+ // Screen y points down, so a growing atan2 angle is clockwise on screen.
+ let drag = |start: f64, steps: &[f64]| {
+ let (mut last, mut turned, mut out) = (start, 0.0, vec![]);
+ for &a in steps {
+ // atan2's range: (−180°, 180°].
+ let a = (a + 180.0).rem_euclid(360.0) - 180.0;
+ turned += turn_delta(last, a);
+ last = a;
+ out.push(turned);
+ }
+ (last, turned, out)
+ };
+ let cw: Vec<f64> = (1..=54).map(|i| i as f64 * 10.0).collect();
+ let (last, turned, seq) = drag(0.0, &cw);
+ assert!((turned - 540.0).abs() < 1e-9, "{turned}");
+ assert!(seq.windows(2).all(|w| (w[1] - w[0] - 10.0).abs() < 1e-9), "no jump: {seq:?}");
+ assert!((rotate_value(0.0, turned, false) - 540.0).abs() < 1e-9);
+ let ccw: Vec<f64> = (1..=72).map(|i| 540.0 - i as f64 * 10.0).collect();
+ let (_, back, seq) = drag(last, &ccw);
+ assert!(seq.windows(2).all(|w| (w[1] - w[0] + 10.0).abs() < 1e-9), "no jump: {seq:?}");
+ let total = turned + back;
+ assert!((total + 180.0).abs() < 1e-9, "{total}");
+ assert!((rotate_value(30.0, total, false) + 150.0).abs() < 1e-9);
+ // Shift snaps the accumulated value, not a wrapped one.
+ assert_eq!(rotate_value(0.0, 400.0, true), 405.0);
+ assert_eq!(rotate_value(0.0, -400.0, true), -405.0);
+ // Across the seam: 170° → −170° is +20°, and back is −20°; exactly half a turn is +180°.
+ assert!((turn_delta(170.0, -170.0) - 20.0).abs() < 1e-9);
+ assert!((turn_delta(-170.0, 170.0) + 20.0).abs() < 1e-9);
+ assert_eq!(turn_delta(0.0, 180.0), 180.0);
+ assert_eq!(turn_delta(0.0, -180.0), 180.0);
+ // Never crash or poison the value on non-finite input.
+ assert_eq!(turn_delta(f64::NAN, 10.0), 0.0);
+ assert_eq!(turn_delta(0.0, f64::INFINITY), 0.0);
+ assert_eq!(rotate_value(15.0, f64::NAN, false), 15.0);
+ }
+
+ /// #1042: a path vertex lying under, or just beside, a bounding-box handle is grabbed
+ /// instead of the handle; away from every handle the reach is unchanged.
+ #[test]
+ fn vertex_reaches_as_far_as_a_box_handle_over_it() {
+ let handle = pos2(100.0, 100.0);
+ let vertex = pos2(100.0, 100.0);
+ // The press lands 8 points off the vertex, still on the handle's square.
+ let press = pos2(108.0, 100.0);
+ let pick = |p: Pos2, handles: &[Pos2]| vertex.distance(p) < vertex_grab_radius(p, handles.iter().copied());
+ assert!(handle.distance(press) < HANDLE + 2.0, "the handle would take this press");
+ assert!(pick(press, &[handle]), "the vertex wins over the handle");
+ assert!(!pick(press, &[]), "no handle there: the usual reach");
+ assert!(pick(pos2(105.0, 100.0), &[]));
+ assert!(!pick(pos2(120.0, 100.0), &[handle]), "past the handle: nothing");
+ }
+
/// #882: the frame's corner sits on a physical pixel at any display scaling, so 100 % maps
/// comp pixels 1:1 onto screen pixels.
#[test]