Tests: use a small press cap and keep the real freeform command cap check

This commit is contained in:
skylartaylor
2026-12-01 10:47:12 +01:00
parent 56d84237ad
commit 82c2bf3315
3 changed files with 22 additions and 2 deletions
+15 -1
View File
@@ -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);
}
+3
View File
@@ -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<usize>,
/// The shape in Edit Points: its vertices are handles instead of the box's.
pub edit_points: Option<ShapeId>,
/// The vertex (path, index) whose control handles show in Edit Points.
+4 -1
View File
@@ -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);
}