The Magnetic Lasso closes within 8 screen points of its first point, so a click where the outline began closes it

This commit is contained in:
aiongg
2026-11-17 04:04:56 +00:00
parent db1020b203
commit 759abc01ab
2 changed files with 24 additions and 6 deletions
+10 -6
View File
@@ -9,7 +9,7 @@ use egui::{CornerRadius, Pos2, Rect as ScreenRect, Vec2};
use kurbo::Point;
use serde::{Deserialize, Serialize};
use super::lasso::{DraftKey, draft_command, outline_access, reach};
use super::lasso::{DraftKey, draft_command, outline_access};
use super::{Place, Report, SelectEvent, SelectPhase, SelectToolPass, SelectionProbe, SelectionShape};
/// Where the magnetic lasso cursor's icon touches the document: the icon's own origin.
@@ -521,7 +521,7 @@ impl<T: EdgeTracer> CanvasTool for SelectToolPass<'_, MagneticLassoTool<T>> {
});
return ToolAction::Claimed;
};
if pointer.clicks >= 2 || o.near_start(p, close_radius(cx, &place)) {
if pointer.clicks >= 2 || o.near_start(p, close_radius(&place)) {
tool.close(pointer.mods.alt);
return ToolAction::Claimed;
}
@@ -635,7 +635,7 @@ impl<T: EdgeTracer> CanvasTool for SelectToolPass<'_, MagneticLassoTool<T>> {
draw.stroke(&square, StrokeWidth::Thin, style.color(overlay.handle_stroke));
}
if let Some(pointer) = cx.pointer
&& o.near_start(place.doc(pointer.pos), close_radius(cx, &place))
&& o.near_start(place.doc(pointer.pos), close_radius(&place))
{
// The closing cursor: a small circle beside the pointer.
let ring = PaintShape::Circle(pointer.pos + side, tokens.shape.radius.sm);
@@ -656,7 +656,11 @@ impl<T: EdgeTracer> CanvasTool for SelectToolPass<'_, MagneticLassoTool<T>> {
}
}
/// How near the first point a press closes the outline, in document units.
fn close_radius(cx: &ToolContext<'_>, place: &Place) -> f64 {
reach(cx).close / place.zoom().max(0.01)
/// How near the first point a press closes the outline, in screen points. Wider than the slop: the first point snaps
/// to the edge, a few points from the press that placed it, and a press back where the outline began closes it.
const CLOSE_REACH: f64 = 8.0;
/// [`CLOSE_REACH`] in document units.
fn close_radius(place: &Place) -> f64 {
CLOSE_REACH / place.zoom().max(0.01)
}
+14
View File
@@ -891,6 +891,20 @@ fn magnetic_closes_by_start_click_double_click_or_enter_and_retracts_to_the_firs
assert!(rig.tool_mut().events().is_empty(), "retracting commits nothing");
}
// The first point snaps to the edge a few points from the press that placed it, farther than the slop: a click back
// where the outline began closes it, as a click on the start itself does.
#[trial]
fn a_click_where_the_magnetic_outline_began_closes_it() {
let (mut rig, _) = magnetic();
let began = CENTRE + circle_offset(0.0) * ((RADIUS + 5.0) / RADIUS);
click(&mut rig, pt(began), NONE);
glide_along(&mut rig, 0.0, std::f64::consts::TAU);
rig.fixture().advance(1.0);
click(&mut rig, pt(began), NONE);
let points = committed_polygon(&rig.tool_mut().events());
assert!(points.len() >= 3 && points.iter().all(|&p| on_circle(p)), "a click where the outline began closes: {points:?}");
}
// `[` and `]` change the width by 1 within 1..=256 while an outline is open.
// With `pressure_width` on, a pen sample at pressure 0.5 halves the searched width (minus one); a mouse sample never