mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-21 01:44:57 +01:00
Use Drawing pixel snapping options consistently for Scissors
This commit is contained in:
1 parent
bdae835305
commit
c4e36de0f0
2 files changed
+47
-4
No files matched your search
@@ -20,7 +20,7 @@ use vectorcraft_geom::Point;
|
||||
use super::{hit_anchor, hit_segment, insert_anchor, remove_anchor};
|
||||
use crate::direct::hit_handle;
|
||||
use crate::guides::{DrawSnap, HandleSnap};
|
||||
use crate::{Action, Cursor, Mods, Overlay, PointerEvent, PointerKind, Tool, ToolContext, ToolKey};
|
||||
use crate::{Action, Cursor, Mods, Overlay, PointerEvent, PointerKind, PixelOp, Tool, ToolContext, ToolKey};
|
||||
use vectorcraft_geom::constrain_angle_from;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -158,7 +158,7 @@ impl AnchorTool {
|
||||
fn resolve_scissors_snap(&mut self, cx: &ToolContext, raw: Point, snapped: Point) -> Point {
|
||||
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.snap_to_pixel && !cx.snap_to_grid && snapped != raw && !eligible(snapped) && eligible(raw);
|
||||
(cx.smart_guides || cx.snap_to_point) && !cx.snaps_to_pixel(PixelOp::Drawing) && !cx.snap_to_grid && snapped != raw && !eligible(snapped) && eligible(raw);
|
||||
let snapped = if fallback {
|
||||
self.scissors_snap.clear();
|
||||
raw
|
||||
@@ -175,7 +175,7 @@ impl AnchorTool {
|
||||
/// paths; there the ordinary full pick radius keeps the existing selected-path priority.
|
||||
fn scissors_segment(cx: &ToolContext, p: Point) -> Option<(NodeId, usize, usize, f64)> {
|
||||
let tol = cx.pick_tol();
|
||||
if cx.smart_guides || cx.snap_to_point || cx.snap_to_pixel || cx.snap_to_grid {
|
||||
if cx.smart_guides || cx.snap_to_point || cx.snaps_to_pixel(PixelOp::Drawing) || cx.snap_to_grid {
|
||||
super::segment_in(cx, super::candidate_paths(cx), p, tol.min(1e-6)).or_else(|| hit_segment(cx, p, tol))
|
||||
} else {
|
||||
hit_segment(cx, p, tol)
|
||||
@@ -192,7 +192,7 @@ impl AnchorTool {
|
||||
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.snap_to_pixel || cx.snap_to_grid;
|
||||
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}))];
|
||||
|
||||
@@ -920,3 +920,46 @@ fn anchor_point_shift_drag_honors_measurement_labels() {
|
||||
assert!(t.overlays(&on).iter().any(|o| matches!(o, Overlay::Measure { text, .. } if text == &want)));
|
||||
assert!(!t.overlays(&off).iter().any(|o| matches!(o, Overlay::Measure { .. })));
|
||||
}
|
||||
|
||||
/// Disabled Drawing pixel snapping must behave like the same effective art-snap mode.
|
||||
/// Drawing enabled is the ordinary pixel-priority control at this integer cut point.
|
||||
#[test]
|
||||
fn scissors_drawing_pixel_option_keeps_valid_isolated_cuts() {
|
||||
let (mut d, rect) = doc_with_rect();
|
||||
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();
|
||||
let mut selected = Selection::default();
|
||||
selected.set([rect]);
|
||||
let paint = paint();
|
||||
let at = Point::new(150.0, 100.0);
|
||||
for drawing in [true, false] {
|
||||
let c = ToolContext {
|
||||
isolation: Some(rect),
|
||||
smart_guides: true,
|
||||
snap_to_point: true,
|
||||
snap_to_pixel: true,
|
||||
pixel_snap: crate::PixelSnap { drawing, ..Default::default() },
|
||||
snap_to_grid: false,
|
||||
..cx(&d, &selected, &paint)
|
||||
};
|
||||
let mut tool = AnchorTool::new("scissors");
|
||||
tool.pointer(&c, &PointerEvent::new(PointerKind::Move, at.x, at.y));
|
||||
let labels = scissors_labels(&tool, &c);
|
||||
let cursor = tool.cursor(&c, at, Mods::default());
|
||||
let actions = tool.pointer(&c, &PointerEvent::new(PointerKind::Down, at.x, at.y));
|
||||
assert!(!actions.is_empty(), "drawing={drawing}: expected a valid isolated cut");
|
||||
assert!(scissors_cut_at(&d, rect, &actions).distance(at) < 1e-6, "drawing={drawing}: {actions:?}");
|
||||
assert_eq!(cursor, Cursor::Scissors, "drawing={drawing}");
|
||||
assert!(labels.is_empty(), "rejected outside snap must not guide the raw cut: {labels:?}");
|
||||
assert!(scissors_labels(&tool, &c).is_empty(), "the press also discards its rejected guide");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user