mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-28 22:30:47 -08:00
Smart Guides: a move lines up geometric edges with Use Preview Bounds on
With Use Preview Bounds on, a move lined up the outside of the selection's stroke with the other art's geometric bounds, which Smart Guides always use for the targets. A stroked object then stopped half a stroke short of the edge it showed a guide for, or overlapped it by that much. The moved selection's geometric bounds now line up with the targets' geometric bounds whatever Use Preview Bounds says. Snap to Grid, Snap to Pixel and the ruler guides still use the bounds the bounding box shows. Part of #6436.
This commit is contained in:
1 parent
98c3a3fe08
commit
2eb79ddfb4
2 files changed
+43
-3
No files matched your search
@@ -262,6 +262,9 @@ fn distance_overlays(cx: &ToolContext, to: DistanceTo) -> Vec<Overlay> {
|
||||
/// it snaps to the original too.
|
||||
pub(crate) struct MoveSnap {
|
||||
bounds: Option<Rect>,
|
||||
/// The selection's geometric bounds, which Smart Guides line up with the other art's geometric
|
||||
/// bounds and space evenly between them, whether Use Preview Bounds is on or off (#6436).
|
||||
edges: Option<Rect>,
|
||||
targets: Option<Targets>,
|
||||
points: Option<Targets>,
|
||||
/// The targets and points for a copy, gathered with the others before the previews move the
|
||||
@@ -300,6 +303,7 @@ impl MoveSnap {
|
||||
let points = |exclude: &[NodeId]| if cx.snap_to_grid { None } else { Targets::snap_to_point(cx, exclude) };
|
||||
Self {
|
||||
bounds: selection_bounds(cx),
|
||||
edges: guides.then(|| cx.doc.bounds_of(&cx.selection.objects, false)).flatten(),
|
||||
targets: guides.then(|| for_move(cx, &cx.selection.objects)),
|
||||
points: points(&cx.selection.objects),
|
||||
copy_targets: guides.then(|| for_move(cx, &[])),
|
||||
@@ -312,7 +316,7 @@ impl MoveSnap {
|
||||
/// Snap to Grid and Snap to Pixel alone, for a move whose box is `bounds`: the grid lands an
|
||||
/// edge of the box on a gridline, and pixels put its top-left on whole pixels.
|
||||
pub(crate) fn grid_only(bounds: Option<Rect>) -> Self {
|
||||
Self { bounds, targets: None, points: None, copy_targets: None, copy_points: None, rulers: None, by_edge: false }
|
||||
Self { bounds, edges: None, targets: None, points: None, copy_targets: None, copy_points: None, rulers: None, by_edge: false }
|
||||
}
|
||||
|
||||
/// The ruler guides stopped showing since the move began (View › Hide Guides, or Trim View,
|
||||
@@ -353,7 +357,7 @@ impl MoveSnap {
|
||||
// The grabbed anchor landed on a path or a crossing, which a ruler guide does not pull
|
||||
// it off.
|
||||
let mut on_path = false;
|
||||
if let (Some(t), Some(b)) = (targets, self.bounds) {
|
||||
if let (Some(t), Some(b)) = (targets, self.edges) {
|
||||
// The point the selection was grabbed by, near another object's anchor or centre,
|
||||
// lands on it, rather than the bounds lining up a little beside it (#955).
|
||||
if t.has_point_near(start + d, cx.snap_tol()) {
|
||||
@@ -434,7 +438,7 @@ impl MoveSnap {
|
||||
d = q - start;
|
||||
guides = ov;
|
||||
}
|
||||
if let (Some(t), Some(b)) = (targets, self.bounds) {
|
||||
if let (Some(t), Some(b)) = (targets, self.edges) {
|
||||
if t.has_point_near(start + d, cx.snap_tol()) {
|
||||
let (q, ov) = t.snap_point_along(start + d, u, cx.snap_tol());
|
||||
d = q - start;
|
||||
|
||||
@@ -1255,6 +1255,42 @@ fn an_alt_copy_snaps_to_the_original_left_behind() {
|
||||
assert_eq!(dx(&t.pointer(&c, &ev(PointerKind::Drag, 253.0, 150.0))), 103.0);
|
||||
}
|
||||
|
||||
/// With Use Preview Bounds on, Smart Guides line up the moved selection's geometric bounds with
|
||||
/// the other art's, as they do with it off: an edge lands exactly on the other path's edge, and the
|
||||
/// edge of a stroke does not pull it there (#6436).
|
||||
#[test]
|
||||
fn a_move_lines_up_geometric_edges_with_use_preview_bounds_on() {
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
use vectorcraft_doc::{Appearance, Node};
|
||||
// An artboard whose edges and center are out of reach, and two rectangles stroked 20 pt.
|
||||
let mut d = Document::new(1000.0, 1000.0);
|
||||
let l = d.layers[0].id;
|
||||
let mut add = |r: Rect| {
|
||||
let id = d.alloc_id();
|
||||
let wide = Appearance::basic(Paint::solid(Color::WHITE), Paint::solid(Color::BLACK), 20.0);
|
||||
d.insert(Some(l), 0, Node::path(id, vectorcraft_geom::shapes::rectangle(r), wide)).unwrap();
|
||||
id
|
||||
};
|
||||
let a = add(Rect::new(100.0, 100.0, 200.0, 200.0));
|
||||
add(Rect::new(300.0, 100.0, 400.0, 200.0));
|
||||
let s = Selection { objects: vec![a], ..Default::default() };
|
||||
let p = paint();
|
||||
for preview in [false, true] {
|
||||
let c = ToolContext { preview_bounds: preview, ..cx(&d, &s, &p) };
|
||||
let dragged = |to: f64| {
|
||||
let mut t = SelectionTool::default();
|
||||
t.pointer(&c, &ev(PointerKind::Down, 150.0, 150.0));
|
||||
let a = t.pointer(&c, &ev(PointerKind::Drag, to, 150.0));
|
||||
let Some(Action::Preview(_, v)) = a.last() else { panic!("{a:?}") };
|
||||
(v["matrix"][4].as_f64().unwrap(), v["matrix"][5].as_f64().unwrap())
|
||||
};
|
||||
// The right edge, 1 pt short of the other rectangle's left edge (x = 300), lands on it.
|
||||
assert_eq!(dragged(249.0), (100.0, 0.0), "preview {preview}");
|
||||
// 9 pt short, it stays where it is dragged, though the edge of its stroke is 1 pt past there.
|
||||
assert_eq!(dragged(241.0), (91.0, 0.0), "preview {preview}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Smart Guides › Snap to Last Location: a move that comes within Snapping Tolerance of where it
|
||||
/// began goes back there, labeled "last location", a Shift move too; farther out, with the option
|
||||
/// or Smart Guides off, it stays where it is dragged, and an Alt copy snaps as it does with the
|
||||
|
||||
Reference in new issue
Block a user