Compare commits

...
3 changed files with 29 additions and 2 deletions
+16 -1
View File
@@ -5801,15 +5801,30 @@ 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() });
assert_eq!(s.tool.press_point_cap(), tools::MAX_GESTURE_POINTS);
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);
}
+12
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.
@@ -310,6 +313,15 @@ impl ToolState {
pub fn drawing_freeform(&self) -> bool {
matches!(self.drag, Some(Drag::Freeform { .. }))
}
/// Most vertices freeform presses place: [`MAX_GESTURE_POINTS`], or a smaller cap a test sets.
pub(crate) fn press_point_cap(&self) -> usize {
#[cfg(test)]
if let Some(cap) = self.freeform_press_point_cap {
return cap;
}
MAX_GESTURE_POINTS
}
}
/// Handle positions in slide coordinates for a box (8 resize + rotate).
+1 -1
View File
@@ -262,7 +262,7 @@ 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;
self.tool.press_added_vertex = points.len() < self.tool.press_point_cap();
if self.tool.press_added_vertex {
points.push(p);
}