Merge pull request #7253 from ncic/pencil-no-guides

Pencil: ignores Smart Guides and Snap to Point
This commit is contained in:
BFlat
2026-11-15 05:26:52 +07:00
committed by GitHub
4 changed files with 95 additions and 50 deletions
+26 -27
View File
@@ -6,9 +6,9 @@
//! points with straight segments and the release fits them; Alt on release (or ending near the start) closes the path, and starting
//! near an end of a selected open path continues it. Shift held at the press draws a straight
//! Pencil line at 45° steps from the Constrain Angle instead, and Alt held at the press (with Alt
//! key toggles to Smooth Tool off) draws a straight line at any angle. The Pencil's new path starts and ends on
//! Smart Guides ([`DrawSnap`]: an anchor, a path, in line with the art), hovering too; the points
//! between follow the hand. The Paintbrush records the pen pressure of each point (a stroke a pen
//! key toggles to Smooth Tool off) draws a straight line at any angle. The Pencil ignores Smart
//! Guides and Snap to Point: it shows no Smart Guides, hovering or drawing, and its ends follow the
//! hand. Snap to Grid and Snap to Pixel still move its ends (`grid_snaps`). The Paintbrush records the pen pressure of each point (a stroke a pen
//! pressed less than fully on sends `[x, y, pressure]` points) for pressure-sensitive brushes, and
//! the pen's tilt and barrel rotation where the pen reads them (`[x, y, pressure, tiltX, tiltY,
//! rotation]` points, `null` for what a point lacks) for brushes that vary with them. The Blob
@@ -860,27 +860,29 @@ impl GestureTool {
}
}
/// Do the ends of its strokes snap (the Pencil)?
fn snaps(&self) -> bool {
self.id == "pencil"
}
/// Does a straight Knife cut snap to anchors and paths? Only with Smart Guides on, which Snap to
/// Pixel (for drawing) and Snap to Grid turn off (`PointSnap::new`). Its ends snap as the
/// Pencil's straight line's do: the press, and the release unless Shift keeps it on a 45° step.
/// Pixel (for drawing) and Snap to Grid turn off (`PointSnap::new`). Its ends snap: the press,
/// and the release unless Shift keeps it on a 45° step.
fn knife_snaps(&self, cx: &ToolContext) -> bool {
self.id == "knife" && self.straight && cx.smart_guides && !cx.snaps_to_pixel(crate::PixelOp::Drawing) && !cx.snap_to_grid
}
/// Does the end of a straight line snap: the Pencil's Alt line's, or a straight Knife cut's
/// without Shift?
/// Do the Pencil's ends snap? Only to the grid or to pixels, with View → Snap to Grid or Snap
/// to Pixel on: those are separate from Smart Guides (and turn them off), and the grid case is
/// its own question (#2958). Smart Guides and Snap to Point never move them.
fn grid_snaps(&self, cx: &ToolContext) -> bool {
self.id == "pencil" && (cx.snap_to_grid || cx.snaps_to_pixel(crate::PixelOp::Drawing))
}
/// Does the end of a straight line without Shift snap: the Pencil's Alt line's to the grid or
/// pixels, a straight Knife cut's to anchors and paths?
fn line_end_snaps(&self, cx: &ToolContext) -> bool {
self.straight && self.unconstrained && (self.snaps() || self.knife_snaps(cx))
self.straight && self.unconstrained && (self.grid_snaps(cx) || self.knife_snaps(cx))
}
/// Where a stroke or straight line released at `p` ends: where it snaps when its end snaps.
fn release_end(&mut self, cx: &ToolContext, p: Point) -> Point {
if (self.snaps() && !self.smoothing && !self.straight) || self.line_end_snaps(cx) { self.snap.drag(cx, p, None) } else { p }
if (self.grid_snaps(cx) && !self.smoothing && !self.straight) || self.line_end_snaps(cx) { self.snap.drag(cx, p, None) } else { p }
}
/// Is a straight line with its end at `end` back at its press point (within a pixel), so that
@@ -1299,10 +1301,6 @@ impl Tool for GestureTool {
self.tip_at = (!ev.mods.cmd && !self.blob_alt_smooths(ev.mods)).then_some(p);
}
match ev.kind {
PointerKind::Move if self.snaps() => {
self.snap.hover(cx, p, &[], None);
vec![]
}
PointerKind::Down => {
self.active = true;
self.began = false;
@@ -1326,11 +1324,12 @@ impl Tool for GestureTool {
_ => vec![],
};
self.redraw = if self.draws_path() && !self.smoothing && self.extend.is_none() { self.find_redraw(cx, p) } else { None };
// A path continued starts at its end, one redrawn on it; a new one where it snaps.
// A straight line is constrained from the end it continues, so it starts there.
// A path continued starts at its end, one redrawn on it; a new one at the press,
// or on the grid or a pixel when they snap. A straight line is constrained from the
// end it continues, so it starts there.
let start = if let Some((_, _, end)) = extend.filter(|_| self.straight) {
end
} else if self.snaps() && !self.smoothing && self.extend.is_none() && self.redraw.is_none() {
} else if self.grid_snaps(cx) && !self.smoothing && self.extend.is_none() && self.redraw.is_none() {
self.snap.press(cx, p, &[], None)
} else if self.knife_snaps(cx) {
// A straight Knife cut, its overlay and Shift's 45° steps start from the snapped point.
@@ -1354,13 +1353,13 @@ impl Tool for GestureTool {
self.moved |= self.points.first().is_some_and(|start| p.distance(*start) > vectorcraft_geom::EPS);
let p = self.constrained(cx, p, ev.mods);
let mut end = p;
if self.snaps() && !self.smoothing && !self.straight {
// Where the stroke would end: shown, taken on release.
if self.grid_snaps(cx) && !self.smoothing && !self.straight {
// Where the stroke would end on the grid or a pixel: taken on release.
end = self.snap.drag(cx, p, None);
}
let p = if self.line_end_snaps(cx) {
// Alt's line ends where a stroke would, and a Knife cut's on the anchors and
// paths its press snaps to: shown, taken on release.
// Alt's line ends on the grid or a pixel when they snap, and a Knife cut on the
// anchors and paths its press snaps to: shown, taken on release.
self.snap.drag(cx, p, None)
} else {
p
@@ -1382,7 +1381,7 @@ impl Tool for GestureTool {
} else if self.points.last().is_some_and(|l| l.distance(p) < cx.tol(1.0)) || self.points.len() >= crate::MAX_STROKE_SAMPLES {
// A release here keeps the last point unless it snaps (`Up`), so the ring
// follows the point `finish` will test.
let kept = self.points.last().copied().filter(|l| l.distance(p) < cx.tol(1.0) && !self.snaps());
let kept = self.points.last().copied().filter(|l| l.distance(p) < cx.tol(1.0) && !self.grid_snaps(cx));
let release_end = kept.unwrap_or(end);
self.near_start = self.release_closes_near_start(cx, release_end);
self.connects = self.connects_at(cx, release_end).is_some();
@@ -1439,7 +1438,7 @@ impl Tool for GestureTool {
}
} else if self.points.last().is_some_and(|l| l.distance(p) >= cx.tol(1.0)) {
self.push(end, ev);
} else if self.snaps()
} else if self.grid_snaps(cx)
&& !self.smoothing
&& self.points.len() > 1
&& let Some(last) = self.points.last_mut()
+60 -17
View File
@@ -22,25 +22,67 @@ fn drag_held(t: &mut GestureTool, cx: &ToolContext, pts: &[(f64, f64)], m: Mods)
v
}
/// The Pencil's new path starts and ends on Smart Guides (#506), the points between where
/// the hand went.
/// The Pencil follows the hand from the press to the release: it ignores Smart Guides and Snap to Point and shows no
/// Smart Guides, hovering or drawing over the art, with Smart Guides on or with only Snap to Point.
#[test]
fn pencil_ends_snap_to_smart_guides() {
fn pencil_follows_the_hand_and_shows_no_smart_guides() {
let (d, _) = doc_with_rect();
let s = Selection::default();
let p = paint();
let cx = cx(&d, &s, &p);
let mut t = GestureTool::new("pencil");
let acts = drag(&mut t, &cx, &[(102.0, 98.0), (151.0, 300.0), (250.0, 320.0), (198.0, 203.0)], Mods::default());
let Some(Action::Preview(_, v)) = acts.last().and_then(|a| a.first()) else { panic!("{acts:?}") };
assert_eq!(v["points"], json!([[100.0, 100.0], [151.0, 300.0], [250.0, 320.0], [200.0, 200.0]]));
let on = cx(&d, &s, &p);
let snap_to_point = ToolContext { smart_guides: false, ..cx(&d, &s, &p) };
// Near the corners at (100, 100) and (200, 200), within Snap to Point's 2 px of them.
let hand = [(101.0, 99.0), (151.0, 300.0), (250.0, 320.0), (199.0, 201.0)];
for cx in [&on, &snap_to_point] {
let mut t = GestureTool::new("pencil");
t.pointer(cx, &PointerEvent::new(PointerKind::Move, hand[0].0, hand[0].1));
assert!(t.overlays(cx).is_empty(), "hovering: {:?}", t.overlays(cx));
t.pointer(cx, &PointerEvent::new(PointerKind::Down, hand[0].0, hand[0].1));
for &(x, y) in &hand[1..] {
t.pointer(cx, &PointerEvent::new(PointerKind::Drag, x, y));
assert!(t.snap.guides().is_empty(), "drawing: {:?}", t.snap.guides());
}
let last = hand[hand.len() - 1];
let acts = t.pointer(cx, &PointerEvent::new(PointerKind::Up, last.0, last.1));
let Some(Action::Preview(_, v)) = acts.first() else { panic!("{acts:?}") };
assert_eq!(v["points"], json!(hand.map(|(x, y)| [x, y])));
}
// The Paintbrush follows the hand all the way.
let mut t = GestureTool::new("paintbrush");
let acts = drag(&mut t, &cx, &[(102.0, 98.0), (151.0, 300.0)], Mods::default());
let acts = drag(&mut t, &on, &[(102.0, 98.0), (151.0, 300.0)], Mods::default());
let Some(Action::Preview(_, v)) = acts.last().and_then(|a| a.first()) else { panic!("{acts:?}") };
assert_eq!(v["points"][0], json!([102.0, 98.0]));
}
/// Snap to Grid and Snap to Pixel are not Smart Guides: they still move the Pencil's ends (and an
/// Alt line's), while the points between follow the hand.
#[test]
fn pencil_ends_still_snap_to_the_grid_and_pixels() {
let (d, _) = doc_with_rect();
let s = Selection::default();
let p = paint();
let grid = ToolContext { snap_to_grid: true, ..cx(&d, &s, &p) };
let pixel = ToolContext { snap_to_pixel: true, ..cx(&d, &s, &p) };
let on = |cx: &ToolContext, q: (f64, f64)| match cx.snap_to_grid {
true => vectorcraft_geom::snap::snap_point_to_grid(Point::new(q.0, q.1), cx.grid_step()),
false => Point::new(q.0.round(), q.1.round()),
};
let hand = [(301.3, 302.6), (351.4, 420.2), (447.7, 452.9)];
for cx in [&grid, &pixel] {
let (first, last) = (on(cx, hand[0]), on(cx, hand[2]));
assert!(first != Point::new(hand[0].0, hand[0].1) && last != Point::new(hand[2].0, hand[2].1));
let mut t = GestureTool::new("pencil");
let acts = drag(&mut t, cx, &hand, Mods::default());
let Some(Action::Preview(_, v)) = acts.last().and_then(|a| a.first()) else { panic!("{acts:?}") };
assert_eq!(v["points"], json!([[first.x, first.y], [351.4, 420.2], [last.x, last.y]]));
// Alt's straight line ends on the grid or a pixel too.
let mut t = GestureTool::new("pencil");
let acts = drag_held(&mut t, cx, &[hand[0], hand[2]], Mods { alt: true, ..Mods::default() });
let Some(Action::Preview(_, v)) = acts.last().and_then(|a| a.first()) else { panic!("{acts:?}") };
assert_eq!(v["points"][1], json!([last.x, last.y]));
}
}
/// #852: the Paintbrush sends each point's pen pressure; a mouse (always fully pressed) and
/// the Pencil send plain points.
#[test]
@@ -693,10 +735,10 @@ fn pencil_shift_draws_a_straight_line_at_45_degree_steps() {
}
}
/// #3799: a Shift line leaves no Smart Guides of its press on screen while it is dragged
/// (its end doesn't snap), and Alt at its release leaves it open.
/// #3799: a Shift line shows no Smart Guides, at its press or while it is dragged, and Alt at its
/// release leaves it open.
#[test]
fn pencil_shift_line_drops_the_press_guides_and_stays_open_with_alt() {
fn pencil_shift_line_shows_no_guides_and_stays_open_with_alt() {
let (d, _) = doc_with_rect();
let s = Selection::default();
let p = paint();
@@ -704,7 +746,7 @@ fn pencil_shift_line_drops_the_press_guides_and_stays_open_with_alt() {
let shift = Mods { shift: true, ..Default::default() };
let mut t = GestureTool::new("pencil");
t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 102.0, 98.0).with_mods(shift));
assert!(!t.overlays(&cx).is_empty(), "the press snaps to the corner and shows it");
assert!(t.snap.guides().is_empty(), "the press: {:?}", t.snap.guides());
t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 300.0, 140.0).with_mods(shift));
assert!(t.overlays(&cx).is_empty(), "{:?}", t.overlays(&cx));
let shift_alt = Mods { shift: true, alt: true, ..Default::default() };
@@ -1745,10 +1787,11 @@ fn paintbrush_alt_with_a_two_anchor_curve_selected_smooths() {
}
}
/// #3799: Alt's line starts and ends on Smart Guides as a stroke does, and pressed on an end of
/// a selected open path it continues the path from that end to the pointer.
/// #3799: Alt's line runs from the press to the pointer as a stroke does, snapping to nothing,
/// and pressed on an end of a selected open path it continues the path from that end to the
/// pointer.
#[test]
fn pencil_alt_line_snaps_its_ends_and_continues_a_selected_path() {
fn pencil_alt_line_follows_the_hand_and_continues_a_selected_path() {
let (mut d, _) = doc_with_rect();
let alt = Mods { alt: true, ..Default::default() };
let p = paint();
@@ -1758,7 +1801,7 @@ fn pencil_alt_line_snaps_its_ends_and_continues_a_selected_path() {
let mut t = GestureTool::new("pencil");
let acts = drag_held(&mut t, &cx, &[(102.0, 98.0), (151.0, 300.0), (198.0, 203.0)], alt);
let Some(Action::Preview(_, v)) = acts.last().and_then(|a| a.first()) else { panic!("{acts:?}") };
assert_eq!(v["points"], json!([[100.0, 100.0], [200.0, 200.0]]));
assert_eq!(v["points"], json!([[102.0, 98.0], [198.0, 203.0]]));
}
let l = d.layers[0].id;
let id = d.alloc_id();
+6 -3
View File
@@ -1,6 +1,6 @@
# VectorCraft MCP server
> **Last updated:** 2026-11-14 · **Change:** Pencil continuation, straight-line and closing cursors; scores and estimates unchanged; no response-shape change. Previously: Snap to Point with Smart Guides off draws no Smart Guides labels or lines, #7250; no response-shape change. Previously: Envelopes: a top object's side whose pieces are all one curve split at anchors follows that curve's parameter (#7097); existing response shapes retained.
> **Last updated:** 2026-11-14 · **Change:** Pencil ignores Smart Guides and Snap to Point and shows no Smart Guides, #7252; no response-shape change. Previously: Pencil continuation, straight-line and closing cursors; scores and estimates unchanged; no response-shape change. Previously: Snap to Point with Smart Guides off draws no Smart Guides labels or lines, #7250; no response-shape change. Previously: Envelopes: a top object's side whose pieces are all one curve split at anchors follows that curve's parameter (#7097); existing response shapes retained.
`vectorcraft-cli mcp` runs a [Model Context Protocol](https://modelcontextprotocol.io) server on stdio
(newline-delimited JSON-RPC 2.0; see [Protocol](#protocol) for version negotiation). Agents use it to
@@ -6317,9 +6317,11 @@ snap the pointer as drawing tools do, so dragging a corner onto another object's
```
Every point a drawing tool places snaps the same way, through one snapper (#506): the Pen's and Curvature tool's
anchors, the Pencil's first and last point, the shape tools' start and dragged corner or radius (`rectangle`,
anchors, the shape tools' start and dragged corner or radius (`rectangle`,
`roundedRectangle`, `ellipse`, `polygon`, `star`, `lineSegment`, `arc`, `spiral`, `rectangularGrid`, `polarGrid`), the
Type tool's click and frame, and a new artboard's corners. The point lands on another object's anchor, centre or
Type tool's click and frame, and a new artboard's corners. The Pencil ignores Smart Guides and Snap to Point and
shows no Smart Guides: its strokes and straight lines follow the hand (Snap to Grid and Snap to Pixel still move
their ends). The point lands on another object's anchor, centre or
path ("anchor", "center", "path"), else lines up with the anchors, edges and centres of the art and the artboards (a
line from the target and "align"); the Pen's lands on the path being drawn too, so a click on its first anchor closes
it exactly. With `mods.shift` the point keeps to its 45° step from the anchor before it (from `constrainAngle`; a box
@@ -11991,6 +11993,7 @@ the error text. The interactive fallback applies only to ordinary File > Save, n
| Date | Change |
|---|---|
| 2026-11-13 | The Pencil ignores Smart Guides and Snap to Point and shows no Smart Guides; Snap to Grid and Snap to Pixel still move its ends (#7252). |
| 2026-11-13 | `path.freehand`: `closed`, when given, decides whether a stroke that continues a path (`extend`) closes it; the Pencil and the Paintbrush send it by Close Paths When Ends Are Within. |
| 2026-11-13 | Snap to Point with Smart Guides off draws no Smart Guides labels or lines (#7250). |
| 2026-11-13 | Envelopes: a top object's side whose pieces are all one curve split at anchors follows that curve's parameter (#7097). |
File diff suppressed because one or more lines are too long