mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Add Anchor Point: drive the handle-pull tests through the canvas (#12707)
The drag moved into the shared overlay (storytold/craft-libs#2285, not merged yet, which adds PathEdit::PullAnchor for PhotoCraft to map). The tests now click through the canvas; the ones that need the pull are ignored until the craft-libs pin carries it. The plain-click neighbour runs now. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
c7ffd92d2e
commit
34276a0a72
2 files changed
+22
-129
No files matched your search
@@ -1,7 +1,8 @@
|
||||
//! #12707: a drag from a segment with Add Anchor Point inserts the anchor and pulls out its
|
||||
//! handles, as the Pen does: the outgoing handle follows the pointer and the incoming one mirrors
|
||||
//! it. ⇧ turns the handle to 45°, ⌥ breaks the pair, Space moves the anchor; the add and the drag
|
||||
//! are one history step, Add Anchor Point.
|
||||
//! it. ⇧ turns the handle to 45°, ⌥ breaks the pair; the add and the drag are one history step,
|
||||
//! Add Anchor Point. The drag is the overlay's (`PathEdit::PullAnchor`, storytold/craft-libs#2285);
|
||||
//! the tests that need it stay ignored until the craft-libs pin carries it and PhotoCraft maps it.
|
||||
|
||||
use egui::Modifiers;
|
||||
use photocraft_doc::Knot;
|
||||
@@ -9,13 +10,13 @@ use photocraft_geom::Point;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::canvas::{ToolEvent, tool_event};
|
||||
use crate::canvas::testing;
|
||||
use crate::direct_select::PathRef;
|
||||
use crate::state::Tool;
|
||||
|
||||
/// 600 x 600 with the closed corner square (100,300) (300,300) (300,500) (100,500) as the saved
|
||||
/// path "Path 1", selected in the Paths panel, and Add Anchor Point picked.
|
||||
fn square() -> PhotocraftApp {
|
||||
fn square() -> Box<PhotocraftApp> {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.session.execute("file.new", json!({"width": 600, "height": 600})).unwrap();
|
||||
app.sync_views();
|
||||
@@ -40,15 +41,15 @@ fn undo_label(app: &PhotocraftApp) -> Option<String> {
|
||||
}
|
||||
|
||||
fn down(app: &mut PhotocraftApp, at: [f64; 2]) {
|
||||
tool_event(app, ToolEvent::Down { x: at[0], y: at[1], pressure: 1.0 }, Modifiers::NONE);
|
||||
testing::press(app, at, Modifiers::NONE);
|
||||
}
|
||||
|
||||
fn to(app: &mut PhotocraftApp, at: [f64; 2], mods: Modifiers) {
|
||||
tool_event(app, ToolEvent::Move { x: at[0], y: at[1], pressure: 1.0 }, mods);
|
||||
testing::move_to(app, at, mods);
|
||||
}
|
||||
|
||||
fn up(app: &mut PhotocraftApp, at: [f64; 2], mods: Modifiers) {
|
||||
tool_event(app, ToolEvent::Up { x: at[0], y: at[1] }, mods);
|
||||
testing::release(app, at, mods);
|
||||
}
|
||||
|
||||
/// The knot at `anchor` (within a pixel) on `path`.
|
||||
@@ -64,6 +65,7 @@ fn assert_knot(k: &Knot, anchor: [f64; 2], out: [f64; 2], inc: [f64; 2]) {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "needs storytold/craft-libs#2285 in the craft-libs pin and its PathEdit::PullAnchor mapped"]
|
||||
fn a_drag_from_the_bottom_edge_pulls_out_mirrored_handles_in_one_step() {
|
||||
let mut app = square();
|
||||
let (before, n) = (saved(&app), steps(&app));
|
||||
@@ -83,6 +85,7 @@ fn a_drag_from_the_bottom_edge_pulls_out_mirrored_handles_in_one_step() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "needs storytold/craft-libs#2285 in the craft-libs pin and its PathEdit::PullAnchor mapped"]
|
||||
fn shift_turns_the_handle_to_45_degrees_and_the_in_handle_mirrors_it() {
|
||||
// The anchor goes in at (200,500); the drags are offsets from it.
|
||||
for (d, want) in [
|
||||
@@ -103,6 +106,7 @@ fn shift_turns_the_handle_to_45_degrees_and_the_in_handle_mirrors_it() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "needs storytold/craft-libs#2285 in the craft-libs pin and its PathEdit::PullAnchor mapped"]
|
||||
fn alt_during_the_drag_breaks_the_pair_so_only_the_out_handle_follows() {
|
||||
let mut app = square();
|
||||
let n = steps(&app);
|
||||
@@ -117,99 +121,7 @@ fn alt_during_the_drag_breaks_the_pair_so_only_the_out_handle_follows() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn space_moves_the_anchor_with_its_handles_and_letting_go_returns_to_the_handle() {
|
||||
let mut app = square();
|
||||
let n = steps(&app);
|
||||
down(&mut app, [300.0, 400.0]);
|
||||
to(&mut app, [340.0, 400.0], Modifiers::NONE);
|
||||
assert!(crate::anchor_tools::set_reposition(&mut app, true), "the canvas keeps Space from panning");
|
||||
to(&mut app, [340.0, 420.0], Modifiers::NONE);
|
||||
to(&mut app, [340.0, 440.0], Modifiers::NONE);
|
||||
crate::anchor_tools::set_reposition(&mut app, false);
|
||||
to(&mut app, [352.0, 440.0], Modifiers::NONE);
|
||||
up(&mut app, [352.0, 440.0], Modifiers::NONE);
|
||||
let k = knot_at(&saved(&app), [300.0, 440.0]);
|
||||
assert_knot(&k, [300.0, 440.0], [352.0, 440.0], [248.0, 440.0]);
|
||||
assert_eq!((steps(&app), undo_label(&app).as_deref()), (n + 1, Some("Add Anchor Point")));
|
||||
assert!(!crate::anchor_tools::set_reposition(&mut app, true), "no drag, nothing to reposition");
|
||||
}
|
||||
|
||||
/// A pull whose anchor Space moved is kept when the pointer comes back to the press point before
|
||||
/// the release: the release is not a click.
|
||||
#[test]
|
||||
fn space_moves_are_kept_when_the_pointer_returns_to_the_press() {
|
||||
let mut app = square();
|
||||
down(&mut app, [300.0, 400.0]);
|
||||
to(&mut app, [340.0, 400.0], Modifiers::NONE);
|
||||
crate::anchor_tools::set_reposition(&mut app, true);
|
||||
to(&mut app, [340.0, 440.0], Modifiers::NONE);
|
||||
crate::anchor_tools::set_reposition(&mut app, false);
|
||||
to(&mut app, [300.0, 400.0], Modifiers::NONE);
|
||||
up(&mut app, [300.0, 400.0], Modifiers::NONE);
|
||||
let k = knot_at(&saved(&app), [300.0, 440.0]);
|
||||
assert_knot(&k, [300.0, 440.0], [300.0, 400.0], [300.0, 480.0]);
|
||||
}
|
||||
|
||||
/// The Space case through the real canvas: the held key reaches the drag, and the view does not pan.
|
||||
#[test]
|
||||
fn space_in_the_canvas_moves_the_anchor_instead_of_panning() {
|
||||
use egui::{Event, Key, PointerButton, pos2};
|
||||
let mut a = square();
|
||||
a.ui.extras.rulers = false;
|
||||
a.ui.views = vec![crate::state::View {
|
||||
zoom: 1.0,
|
||||
center: [300.0, 300.0],
|
||||
fit_pending: false,
|
||||
fill_pending: false,
|
||||
doc_size: [600, 600],
|
||||
rotation: 0.0,
|
||||
zoom_animating: false,
|
||||
zoom_anchor: None,
|
||||
display_camera: None,
|
||||
zoom_transition: None,
|
||||
}];
|
||||
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(600.0, 600.0)).build_ui_state(
|
||||
|ui, app: &mut PhotocraftApp| {
|
||||
let v = app.ui.views[0].clone();
|
||||
crate::canvas::canvas_view(app, ui, 0, ui.max_rect(), v, true);
|
||||
},
|
||||
a,
|
||||
);
|
||||
h.run_steps(2);
|
||||
let rect = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(600.0, 600.0));
|
||||
let xf = crate::canvas::ViewXform { rect, zoom: 1.0, center: [300.0, 300.0], flip: false, rotation: 0.0, aspect: 1.0 };
|
||||
let button = |pos, pressed| Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE };
|
||||
let space = |pressed| Event::Key { key: Key::Space, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE };
|
||||
let press = xf.to_screen(300.0, 400.0);
|
||||
h.event(Event::PointerMoved(press));
|
||||
h.step();
|
||||
h.event(button(press, true));
|
||||
h.step();
|
||||
let mv = |h: &mut egui_kittest::Harness<'_, PhotocraftApp>, x: f32, y: f32| {
|
||||
let p = xf.to_screen(x, y);
|
||||
h.event(Event::PointerMoved(pos2(p.x, p.y)));
|
||||
h.step();
|
||||
};
|
||||
for x in [320.0, 340.0] {
|
||||
mv(&mut h, x, 400.0);
|
||||
}
|
||||
h.event(space(true));
|
||||
h.step();
|
||||
for y in [420.0, 440.0] {
|
||||
mv(&mut h, 340.0, y);
|
||||
}
|
||||
h.event(space(false));
|
||||
h.step();
|
||||
mv(&mut h, 352.0, 440.0);
|
||||
let end = xf.to_screen(352.0, 440.0);
|
||||
h.event(button(end, false));
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().ui.views[0].center, [300.0, 300.0], "Space did not pan");
|
||||
let k = knot_at(&saved(h.state()), [300.0, 440.0]);
|
||||
assert_knot(&k, [300.0, 440.0], [352.0, 440.0], [248.0, 440.0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "needs storytold/craft-libs#2285 in the craft-libs pin and its PathEdit::PullAnchor mapped"]
|
||||
fn the_drag_works_on_a_shape_layers_path_in_one_step() {
|
||||
// 800 x 600, a shape from (450,100) to (650,250), made the active layer.
|
||||
let (mut app, shape) = super::delete_anchor_targeted_path_tests::setup(Tool::AddAnchorPoint);
|
||||
@@ -236,34 +148,12 @@ fn a_click_without_movement_keeps_the_plain_add() {
|
||||
let n = steps(&app);
|
||||
down(&mut app, [200.0, 500.0]);
|
||||
up(&mut app, [200.0, 500.0], Modifiers::NONE);
|
||||
assert_eq!(saved(&app), want, "only the add");
|
||||
// Only the add: the canvas maps the click in f32, so the anchor lands within a hundredth of a pixel.
|
||||
let got = saved(&app);
|
||||
assert_eq!(got.subpaths[0].knots.len(), want.subpaths[0].knots.len(), "one anchor added");
|
||||
for (g, w) in got.subpaths[0].knots.iter().zip(&want.subpaths[0].knots) {
|
||||
let near = |p: Point, q: Point| (p.x - q.x).hypot(p.y - q.y) < 0.01;
|
||||
assert!(near(g.anchor, w.anchor) && near(g.in_ctrl, w.in_ctrl) && near(g.out_ctrl, w.out_ctrl) && g.smooth == w.smooth, "{g:?} vs {w:?}");
|
||||
}
|
||||
assert_eq!((steps(&app), undo_label(&app).as_deref()), (n + 1, Some("Add Anchor Point")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_finite_pointer_positions_leave_the_drag_alone() {
|
||||
let mut app = square();
|
||||
down(&mut app, [200.0, 500.0]);
|
||||
to(&mut app, [200.0, 560.0], Modifiers::NONE);
|
||||
to(&mut app, [f64::NAN, f64::INFINITY], Modifiers::SHIFT);
|
||||
up(&mut app, [200.0, 560.0], Modifiers::NONE);
|
||||
assert_knot(&knot_at(&saved(&app), [200.0, 500.0]), [200.0, 500.0], [200.0, 560.0], [200.0, 440.0]);
|
||||
}
|
||||
|
||||
/// The Space case driven by an agent: `ui.pointer` with `space: true` moves the anchor.
|
||||
#[test]
|
||||
fn an_agents_space_moves_the_anchor() {
|
||||
let mut app = square();
|
||||
let ctx = egui::Context::default();
|
||||
let pointer = |app: &mut PhotocraftApp, params: serde_json::Value| {
|
||||
let (req, _rx) = crate::control::ControlRequest::new("ui.pointer", params);
|
||||
match crate::control::handle(app, &ctx, &req) {
|
||||
crate::control::Outcome::Done(v) => assert_eq!(v["ok"], true, "{v}"),
|
||||
_ => panic!("expected an immediate reply"),
|
||||
}
|
||||
};
|
||||
pointer(&mut app, json!({"events": [{"kind": "down", "x": 300, "y": 400}, {"kind": "move", "x": 340, "y": 400}]}));
|
||||
pointer(&mut app, json!({"space": true, "events": [{"kind": "move", "x": 340, "y": 440}]}));
|
||||
pointer(&mut app, json!({"events": [{"kind": "move", "x": 352, "y": 440}, {"kind": "up", "x": 352, "y": 440}]}));
|
||||
assert_knot(&knot_at(&saved(&app), [300.0, 440.0]), [300.0, 440.0], [352.0, 440.0], [248.0, 440.0]);
|
||||
}
|
||||
@@ -344,6 +344,9 @@ fn edit_draft(app: &mut PhotocraftApp, edit: impl FnOnce(&mut EditPath) -> bool)
|
||||
#[path = "../anchor_tools/add_anchor_delete_key_tests.rs"]
|
||||
mod add_anchor_delete_key_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "../anchor_tools/add_anchor_drag_tests.rs"]
|
||||
mod add_anchor_drag_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "../anchor_tools/add_anchor_lock_tests.rs"]
|
||||
mod add_anchor_lock_tests;
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in new issue
Block a user