Scissors: preview the actual cut point

Show the native point marker at the existing cut target, respecting consumer endpoint eligibility/canonicalization and current snapping/selection. Keep cut commands unchanged.

Closes #8655.
This commit is contained in:
yoriswind
2026-11-19 20:00:59 +00:00
parent 6e0e953f92
commit 36bde202eb
7 changed files with 505 additions and 22 deletions
+176
View File
@@ -154,3 +154,179 @@ fn scissors_cuts_after_a_command_settles_a_deferred_move() {
assert_eq!(session.doc().unwrap().history.undo.len(), undo_before + 1);
}
}
/// Real Session composition: the hovered feedback must be the endpoint the actual split creates,
/// while the selected crossing owner, history and Undo/Redo contracts remain intact.
#[test]
fn review_8655_scissors_session_feedback_is_the_committed_cut_endpoint() {
let mut observed = Vec::new();
for pixel_preview in [true, false] {
let mut session = Session::new();
session.execute("file.new", &json!({"width":800,"height":600})).unwrap();
let rectangle =
NodeId(session.execute("shape.rectangle", &json!({"x":100,"y":100,"width":100,"height":100})).unwrap()["id"].as_u64().unwrap());
let crossing = NodeId(session.execute("shape.line", &json!({"x1":145,"y1":90,"x2":165,"y2":130})).unwrap()["id"].as_u64().unwrap());
session.execute("select.set", &json!({"ids":[rectangle.0]})).unwrap();
let view = ViewInfo { pixel_preview, ..ViewInfo::default() };
session.select_tool("scissors", view).unwrap();
let original = path(&session, rectangle);
let other = path(&session, crossing);
let selection_before = session.doc().unwrap().selection.clone();
let undo_before = session.doc().unwrap().history.undo.len();
let raw = Point::new(152.0, 101.5);
session.pointer(&PointerEvent::new(PointerKind::Move, raw.x, raw.y), view).unwrap();
let overlays = session.overlays(view);
let markers: Vec<_> = overlays
.iter()
.filter_map(|o| match o {
Overlay::Anchor { p, color, filled: false, size } if *color == vectorcraft_tools::draw2::FEEDBACK && *size == 7.0 => Some(*p),
_ => None,
})
.collect();
let intersection = overlays.iter().any(|o| matches!(o, Overlay::Label { text, .. } if text == "intersect"));
assert_eq!(intersection, !pixel_preview, "CONTROL: native view boundary retains Smart Guides policy");
for kind in [PointerKind::Down, PointerKind::Up] {
session.pointer(&PointerEvent::new(kind, raw.x, raw.y), view).unwrap();
}
let opened = path(&session, rectangle);
assert!(!opened.is_closed());
let anchors = &opened.subpaths[0].anchors;
assert_eq!(anchors.len(), 6);
let cut = anchors[0].p;
assert_eq!(anchors.last().unwrap().p, cut);
let expected = Point::new(if pixel_preview { 152.0 } else { 150.0 }, 100.0);
assert!(cut.distance(expected) < 1e-6, "CONTROL: actual cut geometry respects view snapping");
assert!(cut.distance(raw) > 1.0, "CONTROL: feedback is projected to the path, not raw input");
let selection_after = session.doc().unwrap().selection.clone();
assert_eq!(selection_after.objects, [rectangle]);
assert_eq!(selection_after.partial(rectangle).unwrap().iter().copied().collect::<Vec<_>>(), [(0, 0)]);
assert!(selection_after.segments.is_empty());
assert_eq!(path(&session, crossing), other);
assert_eq!(session.doc().unwrap().history.undo.len(), undo_before + 1);
assert!(
session.overlays(view).iter().all(|o| !matches!(o, Overlay::Anchor { color, filled:false, size, .. }
if *color == vectorcraft_tools::draw2::FEEDBACK && *size == 7.0)),
"CONTROL: Up clears cut feedback"
);
session.execute("edit.undo", &json!({})).unwrap();
assert_eq!(path(&session, rectangle), original);
assert_eq!(path(&session, crossing), other);
assert_eq!(session.doc().unwrap().selection, selection_before);
assert_eq!(session.doc().unwrap().history.undo.len(), undo_before);
session.execute("edit.redo", &json!({})).unwrap();
assert_eq!(path(&session, rectangle), opened);
assert_eq!(path(&session, crossing), other);
assert_eq!(session.doc().unwrap().selection, selection_after);
assert_eq!(session.doc().unwrap().history.undo.len(), undo_before + 1);
observed.push((pixel_preview, markers, cut));
}
let endpoint_controls = review_8655_session_endpoint_controls();
for (pixel_preview, markers, cut) in observed {
assert_eq!(markers.len(), 1, "REGRESSION: Pixel Preview{pixel_preview} needs one hollow7px FEEDBACK anchor");
assert!(markers[0].distance(cut) < 1e-6, "REGRESSION: preview{markers:?} must mark the actual committed endpoint{cut:?}");
}
for (markers, cut) in endpoint_controls {
assert_eq!(markers.len(), 1, "a successful interior/canonicalized cut has one marker");
assert!(markers[0].distance(cut) < 1e-6, "marker{markers:?} must equal the actual Engine cut{cut:?}");
}
}
fn review_8655_session_markers(overlays: &[Overlay]) -> Vec<Point> {
overlays
.iter()
.filter_map(|o| match o {
Overlay::Anchor { p, color, filled: false, size } if *color == vectorcraft_tools::draw2::FEEDBACK && *size == 7.0 => Some(*p),
_ => None,
})
.collect()
}
fn review_8655_session_endpoint_controls() -> Vec<(Vec<Point>, Point)> {
let mut session = Session::new();
session.execute("file.new", &json!({"width":800,"height":600})).unwrap();
let line = NodeId(session.execute("shape.line", &json!({"x1":100,"y1":300,"x2":200,"y2":300})).unwrap()["id"].as_u64().unwrap());
session.execute("select.set", &json!({"ids":[line.0]})).unwrap();
let view = ViewInfo { smart_guides: false, snap_to_point: false, snap_to_grid: false, snap_to_pixel: false, ..ViewInfo::default() };
session.select_tool("scissors", view).unwrap();
let original = path(&session, line);
let document = json!(session.doc().unwrap().doc.as_ref());
let selection = session.doc().unwrap().selection.clone();
let undo = session.doc().unwrap().history.undo.len();
let redo = session.doc().unwrap().history.redo.len();
assert!(!original.is_closed());
assert_eq!(original.subpaths[0].anchors.len(), 2, "CONTROL: ordinary minimal drawable open line");
for endpoint in [Point::new(100.0, 300.0), Point::new(200.0, 300.0)] {
session.pointer(&PointerEvent::new(PointerKind::Move, endpoint.x, endpoint.y), view).unwrap();
let endpoint_markers = review_8655_session_markers(&session.overlays(view));
let error = session.pointer(&PointerEvent::new(PointerKind::Down, endpoint.x, endpoint.y), view).unwrap_err();
assert!(error.to_string().contains("cannot split an open path at its end point"), "CONTROL: preserve baseline endpoint error: {error}");
assert_eq!(json!(session.doc().unwrap().doc.as_ref()), document, "a failed endpoint cut changes no document data");
assert_eq!(session.doc().unwrap().selection, selection);
assert_eq!(session.doc().unwrap().history.undo.len(), undo);
assert_eq!(session.doc().unwrap().history.redo.len(), redo);
assert!(endpoint_markers.is_empty(), "an endpoint that Engine rejects has no successful-cut feedback");
session.pointer(&PointerEvent::new(PointerKind::Up, endpoint.x, endpoint.y), view).unwrap();
}
let interior = Point::new(150.0, 300.0);
session.pointer(&PointerEvent::new(PointerKind::Move, interior.x, interior.y), view).unwrap();
let interior_markers = review_8655_session_markers(&session.overlays(view));
for kind in [PointerKind::Down, PointerKind::Up] {
session.pointer(&PointerEvent::new(kind, interior.x, interior.y), view).unwrap();
}
let right_id = session.doc().unwrap().selection.objects[0];
assert_ne!(right_id, line);
let right = path(&session, right_id);
let left = path(&session, line);
let actual_interior = right.subpaths[0].anchors[0].p;
assert!(actual_interior.distance(interior) < 1e-6);
assert_eq!(left.subpaths[0].anchors.last().unwrap().p, actual_interior);
assert_eq!(session.doc().unwrap().history.undo.len(), undo + 1);
session.execute("edit.undo", &json!({})).unwrap();
assert_eq!(path(&session, line), original);
assert!(session.doc().unwrap().doc.node(right_id).is_none());
assert_eq!(session.doc().unwrap().selection, selection);
let closed = NodeId(
session
.execute(
"path.create",
&json!({"d":"M99.99995 100 C133.33328333333333 100 166.66661666666666 100 199.99995 100 L199.99995 200 L99.99995 200 Z"}),
)
.unwrap()["id"]
.as_u64()
.unwrap(),
);
let mut prefs = session.prefs.clone();
prefs.gridline_every = 10.0;
prefs.grid_subdivisions = 1;
session.apply_prefs(prefs);
assert_eq!(session.doc().unwrap().doc.grid.spacing, 10.0);
assert_eq!(session.doc().unwrap().doc.grid.subdivisions, 1);
session.execute("select.set", &json!({"ids":[closed.0]})).unwrap();
let grid = ViewInfo { snap_to_grid: true, ..view };
let original_closed = path(&session, closed);
assert!(original_closed.is_closed());
let canonical = original_closed.subpaths[0].anchors[0].p;
let (_, segment, t, projected, _) = original_closed.nearest(Point::new(100.0, 100.0)).unwrap();
assert_eq!(segment, 0);
assert!(t > 0.0 && t <= 1e-6, "CONTROL: stored native cubic reaches actual canonicalization threshold: {t}");
assert!(projected.distance(canonical) > 1e-5, "CONTROL: projected point differs from canonical stored anchor");
let raw = Point::new(100.1, 100.2);
session.pointer(&PointerEvent::new(PointerKind::Move, raw.x, raw.y), grid).unwrap();
let canonical_markers = review_8655_session_markers(&session.overlays(grid));
let before = session.doc().unwrap().history.undo.len();
for kind in [PointerKind::Down, PointerKind::Up] {
session.pointer(&PointerEvent::new(kind, raw.x, raw.y), grid).unwrap();
}
let opened = path(&session, closed);
assert!(!opened.is_closed());
let anchors = &opened.subpaths[0].anchors;
assert_eq!(anchors.first().unwrap().p, canonical, "Engine commits the original anchor rather than curve.eval(t)");
assert_eq!(anchors.last().unwrap().p, canonical);
assert_eq!(session.doc().unwrap().history.undo.len(), before + 1);
session.execute("edit.undo", &json!({})).unwrap();
assert_eq!(path(&session, closed), original_closed);
session.execute("edit.redo", &json!({})).unwrap();
assert_eq!(path(&session, closed), opened);
vec![(interior_markers, actual_interior), (canonical_markers, canonical)]
}
+74 -16
View File
@@ -16,9 +16,9 @@
use serde_json::json;
use vectorcraft_doc::NodeId;
use vectorcraft_geom::Point;
use vectorcraft_geom::{ParamCurve, Point};
use super::{hit_anchor, hit_segment, insert_anchor, remove_anchor};
use super::{FEEDBACK, hit_anchor, hit_segment, insert_anchor, remove_anchor};
use crate::direct::hit_handle;
use crate::guides::{DrawSnap, HandleSnap};
use crate::{Action, Cursor, Mods, Overlay, PixelOp, PointerEvent, PointerKind, Tool, ToolContext, ToolKey};
@@ -95,10 +95,48 @@ enum SpaceResume {
SpineHandle { id: NodeId, ai: usize, out: bool },
}
/// A cut chosen with the same anchor/segment priority for preview and press.
enum ScissorsCut {
Anchor { id: NodeId, si: usize, ai: usize },
Segment { id: NodeId, si: usize, seg: usize, t: f64 },
}
impl ScissorsCut {
fn point(&self, cx: &ToolContext) -> Option<Point> {
let (id, si) = match *self {
Self::Anchor { id, si, .. } | Self::Segment { id, si, .. } => (id, si),
};
let sp = cx.doc.node(id)?.path_data()?.subpaths.get(si)?;
if sp.anchors.len() < 2 {
return None;
}
let ai = match *self {
Self::Anchor { ai, .. } => ai,
Self::Segment { seg, t, .. } => {
if seg >= sp.segment_count() || !(0.0..=1.0).contains(&t) {
return None;
}
// path.split canonicalizes cuts near segment ends to the existing anchor.
if t <= 1e-6 {
seg
} else if t >= 1.0 - 1e-6 {
(seg + 1) % sp.anchors.len()
} else {
return Some(sp.segment(seg).eval(t));
}
}
};
let anchor = sp.anchors.get(ai)?;
// An open path cannot be split at either of its existing end points.
(sp.closed || (ai > 0 && ai + 1 < sp.anchors.len())).then_some(anchor.p)
}
}
/// The cursor reuses the last hover's point, with DrawSnap checking its target inputs. The
/// Scissors-only inputs also bind the resolved point to the current cut eligibility.
struct ScissorsHover {
raw: Point,
shared: Point,
snapped: Point,
zoom: f64,
isolation: Option<NodeId>,
@@ -160,7 +198,7 @@ impl AnchorTool {
/// Keep a shared art snap unless it prevents a cut the raw pointer could make. Outside art
/// still supplies alignment and intersection guides; pixel and grid snapping keep precedence.
fn resolve_scissors_snap(&mut self, cx: &ToolContext, raw: Point, snapped: Point) -> Point {
fn scissors_point(cx: &ToolContext, raw: Point, snapped: Point) -> (Point, bool) {
let eligible = |p| hit_anchor(cx, p, 0.0).is_some() || hit_segment(cx, p, cx.pick_tol()).is_some();
let fallback = (cx.smart_guides || cx.snap_to_point)
&& !cx.snaps_to_pixel(PixelOp::Drawing)
@@ -168,14 +206,16 @@ impl AnchorTool {
&& snapped != raw
&& !eligible(snapped)
&& eligible(raw);
let snapped = if fallback {
(if fallback { raw } else { snapped }, fallback)
}
fn resolve_scissors_snap(&mut self, cx: &ToolContext, raw: Point, shared: Point) -> Point {
let (snapped, fallback) = Self::scissors_point(cx, raw, shared);
if fallback {
self.scissors_snap.clear();
raw
} else {
snapped
};
}
self.scissors_hover =
Some(ScissorsHover { raw, snapped, zoom: cx.zoom, isolation: cx.isolation, selection_tolerance: cx.selection_tolerance });
Some(ScissorsHover { raw, shared, snapped, zoom: cx.zoom, isolation: cx.isolation, selection_tolerance: cx.selection_tolerance });
snapped
}
@@ -198,18 +238,27 @@ impl AnchorTool {
}
let snapped = self.scissors_snap.press(cx, p, &[], None);
let p = self.resolve_scissors_snap(cx, p, snapped);
match Self::scissors_cut(cx, p) {
Some(ScissorsCut::Anchor { id, si, ai }) => {
vec![Action::Exec("path.split".into(), json!({"id": id.0, "subpath": si, "anchor": ai}))]
}
Some(ScissorsCut::Segment { id, si, seg, t }) => {
vec![Action::Exec("path.split".into(), json!({"id": id.0, "subpath": si, "segment": seg, "t": t}))]
}
None => vec![],
}
}
fn scissors_cut(cx: &ToolContext, p: Point) -> Option<ScissorsCut> {
let point = cx.point_tol();
// A path snap must not be pulled to a nearby anchor by the larger pick radius.
// Shared anchor targets and the path's anchors use the same stored coordinates.
let snapping = cx.smart_guides || cx.snap_to_point || cx.snaps_to_pixel(PixelOp::Drawing) || cx.snap_to_grid;
let anchor_tol = if snapping { 0.0 } else { point };
if let Some((id, si, ai)) = hit_anchor(cx, p, anchor_tol) {
return vec![Action::Exec("path.split".into(), json!({"id": id.0, "subpath": si, "anchor": ai}))];
}
match Self::scissors_segment(cx, p) {
Some((id, si, seg, t)) => vec![Action::Exec("path.split".into(), json!({"id": id.0, "subpath": si, "segment": seg, "t": t}))],
None => vec![],
return Some(ScissorsCut::Anchor { id, si, ai });
}
Self::scissors_segment(cx, p).map(|(id, si, seg, t)| ScissorsCut::Segment { id, si, seg, t })
}
/// The Anchor Point tool as the Pen lends it with Alt held: an Alt-drag on a handle moves only
@@ -694,8 +743,17 @@ impl Tool for AnchorTool {
if matches!(self.state, State::Handle { .. }) {
out.extend(self.guides.iter().cloned());
}
if self.id == "scissors" && self.current_scissors_hover(cx).is_some() {
out.extend_from_slice(self.scissors_snap.guides());
if self.id == "scissors"
&& let Some(h) = self.current_scissors_hover(cx)
{
// Selection priority can change without changing DrawSnap's geometry key.
let (p, _) = Self::scissors_point(cx, h.raw, h.shared);
if p == h.snapped {
out.extend_from_slice(self.scissors_snap.guides());
}
if let Some(p) = Self::scissors_cut(cx, p).and_then(|cut| cut.point(cx)) {
out.push(Overlay::Anchor { p, color: FEEDBACK, filled: false, size: 7.0 });
}
}
if cx.measurement_labels
&& let Some((p, dx, dy)) = self.measure
+236
View File
@@ -1049,3 +1049,239 @@ fn anchor_point_alt_drag_links_a_blend_spine_handle() {
);
assert_eq!(tool.pointer(&c, &PointerEvent::new(PointerKind::Up, 190.0, 350.0).with_mods(alt)), vec![Action::Commit]);
}
fn review_8655_markers(tool: &AnchorTool, context: &ToolContext) -> Vec<Point> {
tool.overlays(context)
.into_iter()
.filter_map(|overlay| match overlay {
Overlay::Anchor { p, color, filled: false, size } if color == crate::draw2::FEEDBACK && size == 7.0 => Some(p),
_ => None,
})
.collect()
}
/// Compare the public overlay to geometry reconstructed from the real path.split action,
/// including points projected off the raw pointer and a rejected outside-art snap.
#[test]
fn review_8655_scissors_marker_matches_the_fresh_split_geometry() {
let paint = paint();
let mut observed = Vec::new();
for scenario in 0..5 {
let (mut d, mut target, mut selected) = if scenario == 1 {
scissors_crossing()
} else {
let (d, id) = doc_with_rect();
(d, id, Selection::default())
};
if scenario == 3 {
let outside = d.alloc_id();
d.insert(
Some(d.layers[0].id),
1,
vectorcraft_doc::Node::path(
outside,
vectorcraft_geom::shapes::line(Point::new(150.0, 103.5), Point::new(350.0, 350.0)),
vectorcraft_doc::Appearance::default_art(),
),
)
.unwrap();
} else if scenario == 4 {
let mut curve = vectorcraft_geom::SubPath::polyline(&[Point::new(100.0, 300.0), Point::new(200.0, 300.0)], false);
curve.anchors[0].h_out = Point::new(120.0, 340.0);
curve.anchors[1].h_in = Point::new(180.0, 340.0);
target = d.alloc_id();
d.insert(
Some(d.layers[0].id),
1,
vectorcraft_doc::Node::path(target, vectorcraft_geom::PathData::single(curve), vectorcraft_doc::Appearance::default_art()),
)
.unwrap();
}
selected.set([target]);
let (at, expected) = match scenario {
0 => (Point::new(152.0, 101.5), Point::new(152.0, 100.0)),
1 => (Point::new(152.0, 101.5), Point::new(150.0, 100.0)),
2 => (Point::new(200.0, 104.25), Point::new(200.0, 100.0)),
3 => (Point::new(150.0, 100.0), Point::new(150.0, 100.0)),
_ => (Point::new(150.0, 331.5), Point::new(150.0, 330.0)),
};
let snapping = scenario == 1 || scenario == 3;
let context = ToolContext {
smart_guides: snapping,
snap_to_point: snapping,
snap_to_pixel: false,
snap_to_grid: false,
isolation: (scenario == 3).then_some(target),
..cx(&d, &selected, &paint)
};
let mut tool = AnchorTool::new("scissors");
assert!(tool.pointer(&context, &PointerEvent::new(PointerKind::Move, at.x, at.y)).is_empty());
let markers = review_8655_markers(&tool, &context);
let labels = scissors_labels(&tool, &context);
if scenario == 1 {
assert_eq!(labels, [("intersect".to_string(), expected)], "CONTROL: existing intersection guides remain");
} else {
assert!(labels.is_empty(), "CONTROL: off/rejected snapping adds no guide: {labels:?}");
}
assert_eq!(tool.cursor(&context, at, Mods::default()), Cursor::Scissors);
let actions = tool.pointer(&context, &PointerEvent::new(PointerKind::Down, at.x, at.y));
let cut = scissors_cut_at(&d, target, &actions);
assert!(cut.distance(expected) < 1e-5, "CONTROL: scenario{scenario} actual split {cut:?}, expected{expected:?}");
if scenario == 2 {
assert!(matches!(&actions[..], [Action::Exec(_, args)] if args["anchor"] == 1), "CONTROL: the actual stored anchor wins");
}
if scenario == 0 || scenario == 4 {
assert!(cut.distance(at) > 1.0, "CONTROL: preview must show the path projection, not the raw point");
}
observed.push((scenario, markers, cut));
}
observed.extend(review_8655_endpoint_action_controls());
// Every split/guide control above executes before the missing-feedback oracle on old code.
for (scenario, markers, cut) in observed {
assert_eq!(markers.len(), 1, "REGRESSION: scenario{scenario} needs exactly one hollow7px FEEDBACK anchor: {markers:?}");
assert!(markers[0].distance(cut) < 1e-6, "REGRESSION: marker and actual fresh split disagree: {markers:?} versus{cut:?}");
}
}
#[test]
fn review_8655_scissors_selection_change_cannot_reuse_the_wrong_marker() {
let (mut d, rectangle) = doc_with_rect();
let line = d.alloc_id();
d.insert(
Some(d.layers[0].id),
1,
vectorcraft_doc::Node::path(
line,
vectorcraft_geom::shapes::line(Point::new(120.0, 102.0), Point::new(240.0, 102.0)),
vectorcraft_doc::Appearance::default_art(),
),
)
.unwrap();
let mut rectangle_selected = Selection::default();
rectangle_selected.set([rectangle]);
let mut line_selected = Selection::default();
line_selected.set([line]);
let paint = paint();
// Only the selection changes: these contexts have the same document and DrawSnap key inputs.
let before = ToolContext { smart_guides: false, snap_to_point: false, ..cx(&d, &rectangle_selected, &paint) };
let after = ToolContext { smart_guides: false, snap_to_point: false, ..cx(&d, &line_selected, &paint) };
assert_eq!(before.revision, after.revision);
assert!(std::ptr::eq(before.doc, after.doc));
let at = Point::new(150.0, 101.6);
let mut tool = AnchorTool::new("scissors");
tool.pointer(&before, &PointerEvent::new(PointerKind::Move, at.x, at.y));
let old_markers = review_8655_markers(&tool, &before);
let mut fresh = AnchorTool::new("scissors");
let old_cut = scissors_cut_at(&d, rectangle, &fresh.pointer(&before, &PointerEvent::new(PointerKind::Down, at.x, at.y)));
let new_cut = scissors_cut_at(&d, line, &fresh.pointer(&after, &PointerEvent::new(PointerKind::Down, at.x, at.y)));
assert!(old_cut.distance(Point::new(150.0, 100.0)) < 1e-6, "CONTROL: selected rectangle beats nearer unselected line");
assert!(new_cut.distance(Point::new(150.0, 102.0)) < 1e-6, "CONTROL: fresh selection changes the actual split owner");
assert!(old_cut.distance(new_cut) > 1.0);
let stale = review_8655_markers(&tool, &after);
assert!(stale.iter().all(|p| p.distance(new_cut) < 1e-6), "no unchanged-key selection switch may show the old cut point: {stale:?}");
tool.pointer(&after, &PointerEvent::new(PointerKind::Move, at.x, at.y));
let new_markers = review_8655_markers(&tool, &after);
let actions = tool.pointer(&after, &PointerEvent::new(PointerKind::Down, at.x, at.y));
assert!(scissors_cut_at(&d, line, &actions).distance(new_cut) < 1e-6);
assert_eq!(old_markers.len(), 1, "REGRESSION: valid first selection has feedback");
assert!(old_markers[0].distance(old_cut) < 1e-6);
assert_eq!(new_markers.len(), 1, "REGRESSION: a fresh hover uses the fresh selected owner");
assert!(new_markers[0].distance(new_cut) < 1e-6);
}
#[test]
fn review_8655_scissors_feedback_clears_on_miss_alt_stale_and_leave() {
let (d, _) = doc_with_rect();
let selected = Selection::default();
let paint = paint();
let context = ToolContext { smart_guides: false, snap_to_point: false, ..cx(&d, &selected, &paint) };
let at = Point::new(170.0, 201.0);
let mut tool = AnchorTool::new("scissors");
tool.pointer(&context, &PointerEvent::new(PointerKind::Move, at.x, at.y));
let valid = review_8655_markers(&tool, &context);
// A context change must not keep a geometrically obsolete point visible before rehover.
let stale = ToolContext { zoom: 2.0, smart_guides: false, snap_to_point: false, ..cx(&d, &selected, &paint) };
assert!(tool.overlays(&stale).is_empty(), "CONTROL: stale zoom shows neither guides nor marker");
tool.pointer(&context, &PointerEvent::new(PointerKind::Move, 20.0, 20.0));
assert!(tool.pointer(&context, &PointerEvent::new(PointerKind::Down, 20.0, 20.0)).is_empty());
assert!(tool.overlays(&context).is_empty(), "CONTROL: a true miss has no cut feedback");
tool.pointer(&context, &PointerEvent::new(PointerKind::Move, at.x, at.y));
let alt = Mods { alt: true, ..Mods::default() };
let event = PointerEvent::new(PointerKind::Down, at.x, at.y);
let mut add = AnchorTool::new("addAnchor");
assert_eq!(tool.pointer(&context, &event.with_mods(alt)), add.pointer(&context, &event), "CONTROL: Alt remains Add Anchor Point");
assert!(tool.overlays(&context).is_empty(), "CONTROL: Alt has no Scissors marker");
tool.pointer(&context, &PointerEvent::new(PointerKind::Move, at.x, at.y));
tool.hover_ended(&context);
assert!(tool.overlays(&context).is_empty(), "CONTROL: leaving clears the marker and guides");
assert_eq!(valid.len(), 1, "REGRESSION: the initial valid cut needs visible feedback");
assert!(valid[0].distance(Point::new(170.0, 200.0)) < 1e-6);
}
/// The successful point is owned by path.split's consumer, including endpoint rejection and
/// its canonical anchor threshold. Keep the emitted Down action itself unchanged.
fn review_8655_endpoint_action_controls() -> Vec<(usize, Vec<Point>, Point)> {
let paint = paint();
let (open_doc, rectangle, selected) = scissors_crossing();
let open_cx = ToolContext { smart_guides: false, snap_to_point: false, ..cx(&open_doc, &selected, &paint) };
let mut tool = AnchorTool::new("scissors");
for (anchor, endpoint) in [(0, Point::new(145.0, 90.0)), (1, Point::new(165.0, 130.0))] {
tool.pointer(&open_cx, &PointerEvent::new(PointerKind::Move, endpoint.x, endpoint.y));
let endpoint_markers = review_8655_markers(&tool, &open_cx);
let actions = tool.pointer(&open_cx, &PointerEvent::new(PointerKind::Down, endpoint.x, endpoint.y));
let [Action::Exec(command, args)] = &actions[..] else { panic!("CONTROL: preserve the original endpoint Down action: {actions:?}") };
assert_eq!(command, "path.split");
assert_eq!(args["anchor"], anchor);
let owner = NodeId(args["id"].as_u64().unwrap());
assert_ne!(owner, rectangle);
assert!(!open_doc.node(owner).unwrap().path_data().unwrap().subpaths[0].closed);
assert_eq!(scissors_cut_at(&open_doc, owner, &actions), endpoint);
assert!(endpoint_markers.is_empty(), "an open path's end point has no successful-cut marker");
tool.pointer(&open_cx, &PointerEvent::new(PointerKind::Up, endpoint.x, endpoint.y));
}
let interior = Point::new(155.0, 110.0);
tool.pointer(&open_cx, &PointerEvent::new(PointerKind::Move, interior.x, interior.y));
let interior_markers = review_8655_markers(&tool, &open_cx);
let actions = tool.pointer(&open_cx, &PointerEvent::new(PointerKind::Down, interior.x, interior.y));
let [Action::Exec(_, args)] = &actions[..] else { panic!("CONTROL: interior open path emits split: {actions:?}") };
assert!(args.get("segment").is_some());
let owner = NodeId(args["id"].as_u64().unwrap());
assert!(scissors_cut_at(&open_doc, owner, &actions).distance(interior) < 1e-6);
let (mut d, other_rectangle) = doc_with_rect();
// Keep the unrelated fixture rectangle away: its exact(100,100) anchor must not steal
// the grid contact from the selected near-endpoint cubic.
d.node_mut(other_rectangle).unwrap().transform(vectorcraft_geom::Affine::translate((0.0, 250.0)), true);
d.grid = vectorcraft_doc::GridPrefs { spacing: 10.0, subdivisions: 1 };
let start = Point::new(99.99995, 100.0);
// Explicit collinear cubic handles make t linear; a handle-free rectangle's cubic t
// would be about0.000408 here and would not exercise the consumer's1e-6 threshold.
let path = vectorcraft_geom::PathData::from_bezpath(&vectorcraft_geom::BezPath::from_vec(vec![
vectorcraft_geom::PathEl::MoveTo(start),
vectorcraft_geom::PathEl::CurveTo(Point::new(133.33328333333333, 100.0), Point::new(166.66661666666666, 100.0), Point::new(199.99995, 100.0)),
vectorcraft_geom::PathEl::LineTo(Point::new(199.99995, 200.0)),
vectorcraft_geom::PathEl::LineTo(Point::new(99.99995, 200.0)),
vectorcraft_geom::PathEl::ClosePath,
]));
let id = d.alloc_id();
d.insert(Some(d.layers[0].id), 1, vectorcraft_doc::Node::path(id, path, vectorcraft_doc::Appearance::default_art())).unwrap();
let mut selected = Selection::default();
selected.set([id]);
let context = ToolContext { snap_to_grid: true, smart_guides: false, snap_to_point: false, ..cx(&d, &selected, &paint) };
let raw = Point::new(100.1, 100.2);
let mut tool = AnchorTool::new("scissors");
tool.pointer(&context, &PointerEvent::new(PointerKind::Move, raw.x, raw.y));
let markers = review_8655_markers(&tool, &context);
let actions = tool.pointer(&context, &PointerEvent::new(PointerKind::Down, raw.x, raw.y));
let [Action::Exec(command, args)] = &actions[..] else { panic!("CONTROL: near-end grid contact emits split: {actions:?}") };
assert_eq!(command, "path.split");
assert_eq!(args["id"], id.0);
assert_eq!(args["segment"], 0);
let t = args["t"].as_f64().unwrap();
assert!(t > 0.0 && t <= 1e-6, "CONTROL: actual emitted t reaches the consumer's anchor canonicalization: {t}");
let projected = scissors_cut_at(&d, id, &actions);
assert!(projected.distance(Point::new(100.0, 100.0)) < 1e-6);
assert!(projected.distance(start) > 1e-5, "CONTROL: raw curve evaluation differs from the committed canonical anchor");
assert!(scissors_labels(&tool, &context).is_empty(), "grid contact adds no Smart Guide label");
vec![(5, interior_markers, interior), (6, markers, start)]
}
+4 -1
View File
File diff suppressed because one or more lines are too long
+5 -2
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+5 -1
View File
File diff suppressed because one or more lines are too long