From 82c2bf3315b555a0ca70e046a69f459ddf483659 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Tue, 1 Dec 2026 10:47:12 +0100 Subject: [PATCH] Tests: use a small press cap and keep the real freeform command cap check --- crates/engine/src/tests.rs | 16 +++++++++++++++- crates/engine/src/tools.rs | 3 +++ crates/engine/src/tools/pointer.rs | 5 ++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index cb530ab1c..f0881e43f 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -5801,15 +5801,29 @@ fn a_long_ink_stroke_is_extended_in_place_and_capped() { fn double_clicking_a_capped_freeform_keeps_its_vertices() { let mut s = session(); let ev = |kind, x: f64, y: f64| tools::PointerEvent { kind, x, y, mods: Default::default(), tol: 3.0, pressure: None }; + let point_cap = 16; s.set_tool(tools::ToolKind::Shape { preset: "freeform".into() }); + s.tool.freeform_press_point_cap = Some(point_cap); s.pointer(ev(tools::PointerKind::Down, 100.0, 100.0)).unwrap(); // Densely clicked vertices, each within the double-click tolerance of the last. - for i in 0..tools::MAX_GESTURE_POINTS + 10 { + // The first press counts toward the cap, so 11 of these presses add no point. + for i in 0..point_cap + 10 { s.pointer(ev(tools::PointerKind::Down, 300.0 + i as f64 * 0.001, 100.0)).unwrap(); } s.pointer(ev(tools::PointerKind::DoubleClick, 300.0, 100.0)).unwrap(); let st = s.doc().unwrap(); let deckcraft_model::Geom::Custom { paths } = &st.shapes().last().unwrap().geom else { panic!("no freeform") }; + assert_eq!(paths[0].d.matches(" L ").count(), point_cap - 1); +} + +#[test] +fn freeform_command_keeps_points_up_to_the_gesture_cap() { + let mut s = session(); + // Send one point beyond the real cap to check that the command keeps as many as the tool can draw. + let points: Vec<_> = (0..=tools::MAX_GESTURE_POINTS).map(|i| [i % 500, i / 500]).collect(); + let r = s.execute("shape.freeform", &json!({"points": points, "closed": false, "smooth": false})).unwrap(); + let id = ShapeId(r["id"].as_u64().unwrap() as u32); + let deckcraft_model::Geom::Custom { paths } = &s.doc().unwrap().shape(id).unwrap().geom else { panic!("no freeform") }; assert_eq!(paths[0].d.matches(" L ").count(), tools::MAX_GESTURE_POINTS - 1); } diff --git a/crates/engine/src/tools.rs b/crates/engine/src/tools.rs index fb889fd36..13a85c1ce 100644 --- a/crates/engine/src/tools.rs +++ b/crates/engine/src/tools.rs @@ -274,6 +274,9 @@ pub struct ToolState { pub path_closing: bool, /// Whether the last freeform press added a vertex (it adds none at the point cap). pub press_added_vertex: bool, + /// A smaller cap for tests that exercise freeform presses. + #[cfg(test)] + pub(crate) freeform_press_point_cap: Option, /// The shape in Edit Points: its vertices are handles instead of the box's. pub edit_points: Option, /// The vertex (path, index) whose control handles show in Edit Points. diff --git a/crates/engine/src/tools/pointer.rs b/crates/engine/src/tools/pointer.rs index da3745f08..9d8264831 100644 --- a/crates/engine/src/tools/pointer.rs +++ b/crates/engine/src/tools/pointer.rs @@ -262,7 +262,10 @@ impl Session { self.tool.drag = Some(Drag::Freeform { mode, points, pressed: false }); return self.finish_freeform(true); } - self.tool.press_added_vertex = points.len() < super::MAX_GESTURE_POINTS; + let point_cap = super::MAX_GESTURE_POINTS; + #[cfg(test)] + let point_cap = self.tool.freeform_press_point_cap.unwrap_or(point_cap); + self.tool.press_added_vertex = points.len() < point_cap; if self.tool.press_added_vertex { points.push(p); }