From 3ea4802a53c808fe87710a7190b3be0f5566758f Mon Sep 17 00:00:00 2001 From: ham9zah Date: Tue, 13 Oct 2026 11:26:02 +0300 Subject: [PATCH] Pen: test that a click after a smooth anchor curves from its side only Covers the Illustrator behaviour that a corner placed after a smooth anchor has no handles, so the segment is shaped by the previous outgoing handle alone. Co-Authored-By: Claude Sonnet 5.5 --- crates/engine/tests/pen_click_after_smooth.rs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 crates/engine/tests/pen_click_after_smooth.rs diff --git a/crates/engine/tests/pen_click_after_smooth.rs b/crates/engine/tests/pen_click_after_smooth.rs new file mode 100644 index 00000000..d36a701b --- /dev/null +++ b/crates/engine/tests/pen_click_after_smooth.rs @@ -0,0 +1,37 @@ +//! A click after a smooth anchor: the new corner has no handles, so the segment curves from the previous anchor's side only. +#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] + +use serde_json::json; +use vectorcraft_doc::NodeKind; +use vectorcraft_engine::{Session, ViewInfo}; +use vectorcraft_geom::Point; +use vectorcraft_tools::{PointerEvent, PointerKind}; + +#[test] +fn click_after_a_smooth_anchor_curves_from_its_side_only() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 600})).unwrap(); + let view = ViewInfo { zoom: 1.0, smart_guides: false, snap_to_grid: false, snap_to_pixel: false, snap_to_point: false, ..Default::default() }; + s.select_tool("pen", view).unwrap(); + let mut at = |kind, x, y| s.pointer(&PointerEvent::new(kind, x, y), view).unwrap(); + // Press and drag out a smooth anchor at (100, 100), then click a corner at (300, 100). + at(PointerKind::Down, 100.0, 100.0); + at(PointerKind::Drag, 150.0, 60.0); + at(PointerKind::Up, 150.0, 60.0); + at(PointerKind::Down, 300.0, 100.0); + at(PointerKind::Up, 300.0, 100.0); + + let mut path = None; + s.doc().unwrap().doc.walk(|n| { + if let NodeKind::Path { path: p, .. } = &n.kind { + path = Some(p.clone()); + } + }); + let sp = &path.unwrap().subpaths[0]; + let (a, b) = (&sp.anchors[0], &sp.anchors[1]); + assert_eq!(a.h_out, Point::new(150.0, 60.0), "the outgoing handle stays where the drag left it"); + assert_eq!(a.h_in, Point::new(50.0, 140.0), "mirrored through the anchor"); + assert!(!b.has_in() && !b.has_out(), "a click places a corner without handles"); + assert!(!sp.segment_is_line(0), "the segment is a curve, shaped by the previous anchor's handle only"); + assert_eq!(sp.segment(0).p2, b.p); +}