diff --git a/crates/engine/src/pointmod.rs b/crates/engine/src/pointmod.rs index 74c1ab0835..c45cac2d83 100644 --- a/crates/engine/src/pointmod.rs +++ b/crates/engine/src/pointmod.rs @@ -119,8 +119,10 @@ pub fn snap_name(m: u32) -> &'static str { mode::ALL.iter().find(|(b, _)| *b == m).map_or("None", |(_, n)| *n) } -/// The candidate snaps near `cursor` for Tab cycling: the snap [`crate::snap::osnap`] picks -/// first, then the closest snap of each other mode in `osmode`, nearest first, without repeats. +/// The candidate snaps near `cursor` for Tab cycling, as in AutoCAD: the snap +/// [`crate::snap::osnap`] picks first, then every other snap of `osmode` in the aperture (all the +/// endpoints, intersections …, and the closest snap of each mode for Nearest, deferred and +/// viewport snaps), nearest first, without repeats. pub fn snap_candidates(d: &Drawing, space: &Space, cursor: Vec2, aperture: f64, osmode: u32, base: Option, deferred: bool) -> Vec { if osmode & !mode::HATCH == 0 || osmode & mode::OFF != 0 { return Vec::new(); @@ -128,6 +130,10 @@ pub fn snap_candidates(d: &Drawing, space: &Space, cursor: Vec2, aperture: f64, let osnap = |m: u32| crate::snap::osnap(d, space, cursor, aperture, m, base, deferred); let extra = osmode & mode::HATCH; let mut per_mode: Vec = mode::ALL.iter().filter(|(b, _)| osmode & b != 0).filter_map(|(b, _)| osnap(*b | extra)).collect(); + let points = crate::snap::points_near(d, space, cursor, aperture, osmode, base); + per_mode.extend(points.into_iter().map(|(m, point)| SnapHit { point, mode: m, name: snap_name(m), viewport: None, deferred: None })); + // Stable: at equal distance a per-mode hit (which may carry its viewport or deferred curve) + // stays ahead of the same point found again, and the repeat is dropped. per_mode.sort_by(|a, b| a.point.dist(cursor).total_cmp(&b.point.dist(cursor))); let mut out: Vec = osnap(osmode).into_iter().collect(); for h in per_mode { diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index 3b38b976f6..3009f556ed 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -188,7 +188,7 @@ pub(crate) fn osnap_with_neighborhood( return (None, None); } let (mut best, near_prims) = match osnap_in_with_prims(d, space, ix, cursor, aperture, osmode, base, deferred, &[], None) { - Some((hit, prims)) => (hit, Some(prims)), + Some((hit, prims, _)) => (hit, Some(prims)), None => (None, None), }; let views = viewport::near(d, space, cursor, aperture); @@ -239,7 +239,21 @@ fn osnap_in( frozen: &[String], clip: Option, ) -> Option { - osnap_in_with_prims(d, space, ix, cursor, aperture, osmode, base, deferred, frozen, clip).and_then(|(hit, _)| hit) + osnap_in_with_prims(d, space, ix, cursor, aperture, osmode, base, deferred, frozen, clip).and_then(|(hit, _, _)| hit) +} + +/// Every snap point of `osmode` within `aperture` of `cursor` in `space`, unordered and with +/// repeats: what Tab cycles through ([`crate::pointmod::snap_candidates`]). Nearest and the +/// deferred snaps are left out (they have no fixed points), and so are layout viewports. +pub fn points_near(d: &Drawing, space: &Space, cursor: Vec2, aperture: f64, osmode: u32, base: Option) -> Vec<(u32, Vec2)> { + if osmode == 0 || osmode & mode::OFF != 0 || !cursor.is_finite() || !(aperture.is_finite() && aperture > 0.0) { + return Vec::new(); + } + let ix = crate::spatial::index(d, space); + let Some((_, _, cands)) = osnap_in_with_prims(d, space, &ix, cursor, aperture, osmode, base, false, &[], None) else { + return Vec::new(); + }; + cands.into_iter().filter(|(_, p)| p.is_finite() && p.dist(cursor) <= aperture).collect() } #[allow(clippy::too_many_arguments)] @@ -254,7 +268,7 @@ fn osnap_in_with_prims( deferred: bool, frozen: &[String], clip: Option, -) -> Option<(Option, Vec)> { +) -> Option<(Option, Vec, Vec<(u32, Vec2)>)> { let (mut cands, near_prims) = gather_in(d, space, ix, cursor, aperture, osmode, frozen)?; // Intersections between nearby primitives; Apparent Intersection also where their extensions // meet (lines extended, arcs as full circles: in 2D, the "apparent" crossing of objects @@ -292,8 +306,8 @@ fn osnap_in_with_prims( } } } - let hit = finish(cands, &near_prims, cursor, aperture, osmode, base, deferred, clip); - Some((hit, near_prims)) + let hit = finish(&mut cands, &near_prims, cursor, aperture, osmode, base, deferred, clip); + Some((hit, near_prims, cands)) } fn finite_intersection_probe(cursor: Vec2, aperture: f64) -> Option { @@ -405,10 +419,11 @@ fn gather_in( Some((cands, near_prims)) } -/// Picks the best of the gathered candidates, adding the base-dependent and deferred snaps. +/// Picks the best of the gathered candidates, adding the base-dependent snaps (to `cands`) and +/// the deferred ones. #[allow(clippy::too_many_arguments)] fn finish( - mut cands: Vec<(u32, Vec2)>, + cands: &mut Vec<(u32, Vec2)>, near_prims: &[Prim], cursor: Vec2, aperture: f64, diff --git a/crates/engine/tests/snap_overrides.rs b/crates/engine/tests/snap_overrides.rs index a02ab92da5..8bbe6369e5 100644 --- a/crates/engine/tests/snap_overrides.rs +++ b/crates/engine/tests/snap_overrides.rs @@ -105,6 +105,21 @@ fn tab_cycling_candidates_start_with_the_running_snap() { assert!(snap_candidates(d, &space, Vec2::new(50.0, 50.0), 0.125, osmode, None, false).is_empty()); } +#[test] +fn tab_cycling_offers_every_endpoint_in_the_aperture_nearest_first() { + let mut s = Session::new(); + s.script("LINE 0,0 10,0\n\nLINE 10.03,0 20,0\n\nLINE 9.95,0 9.95,-5\n\n").unwrap(); + let d = s.doc().unwrap(); + let space = s.space(); + let cands = snap_candidates(d, &space, Vec2::new(10.01, 0.0), 0.125, mode::END, None, false); + let points: Vec = cands.iter().map(|h| h.point).collect(); + assert_eq!(points.len(), 3, "{points:?}"); + for (p, x) in points.iter().zip([10.0, 10.03, 9.95]) { + assert!(near(*p, x, 0.0), "{points:?}"); + } + assert!(cands.iter().all(|h| h.mode == mode::END && h.name == "Endpoint"), "{cands:?}"); +} + #[test] fn a_command_keyword_wins_over_a_snap_word() { let mut s = drawing(); diff --git a/crates/ui-egui/tests/tab_snap_cycling.rs b/crates/ui-egui/tests/tab_snap_cycling.rs new file mode 100644 index 0000000000..680749b534 --- /dev/null +++ b/crates/ui-egui/tests/tab_snap_cycling.rs @@ -0,0 +1,117 @@ +//! Tab at a point prompt cycles through every object snap under the cursor, as in AutoCAD: all +//! the endpoints in the aperture, not only the closest snap of each mode (gaps.md U4). + +use cadcraft_engine::Session; +use cadcraft_engine::doc::{Common, Drawing, EntityKind, Line, Space}; +use cadcraft_engine::geom::Vec2; +use cadcraft_engine::snap::mode; +use cadcraft_ui_egui::{CadApp, Services}; +use egui::{Event, Modifiers, PointerButton, Pos2, vec2}; +use egui_kittest::Harness; +use serde_json::json; + +/// Three endpoints near 10,0: 10,0 (the nearest to the cursor), 10.03,0 and 9.95,0. Endpoint is +/// the only running snap, so every candidate is an endpoint. +fn harness() -> Harness<'static, CadApp> { + let mut d = Drawing::new_imperial(); + for (a, b) in [((0.0, 0.0), (10.0, 0.0)), ((10.03, 0.0), (20.0, 0.0)), ((9.95, 0.0), (9.95, -5.0))] { + let line = Line { a: Vec2::new(a.0, a.1).to3(0.0), b: Vec2::new(b.0, b.1).to3(0.0) }; + d.add(&Space::Model, Common::default(), EntityKind::Line(line)).unwrap(); + } + let mut session = Session::empty(); + session.open_drawing(d, "Tab snap cycling", None); + session.execute("view.set", &json!({"center":[10,0],"height":8})).unwrap(); + session.settings.osmode = mode::END; + session.settings.snapmode = false; + session.settings.orthomode = false; + let mut app = CadApp::new(session, Services::default()); + app.canvas.zoom_pending = false; + let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_ui_state( + |ui, app: &mut CadApp| { + app.logic(ui.ctx()); + app.ui(ui); + }, + app, + ); + h.run_steps(5); + h.state_mut().start("line"); + h.run_steps(2); + assert_eq!(h.state().session.running.as_ref().unwrap().id, "line"); + let ap = h.state().session.settings.aperture / h.state().canvas.xf.unwrap().scale; + assert!(ap > 0.07, "all three endpoints lie in the aperture ({ap})"); + h +} + +const CURSOR: Vec2 = Vec2::new(10.01, 0.0); + +fn hover(h: &mut Harness<'_, CadApp>, p: Vec2) -> Pos2 { + let pos = h.state().canvas.xf.unwrap().to_screen(p); + h.event(Event::PointerMoved(pos)); + h.run_steps(3); + pos +} + +/// Tab, as the command line receives it (`cmdline::capture_tab`). +fn tab(h: &mut Harness<'_, CadApp>) { + h.event(Event::Text("\t".into())); + h.run_steps(3); +} + +fn snapped(h: &Harness<'_, CadApp>) -> Vec2 { + let hit = h.state().canvas.snap.expect("a snap marker"); + assert_eq!(hit.mode, mode::END); + hit.point +} + +fn assert_at(got: Vec2, x: f64) { + assert!(got.near(Vec2::new(x, 0.0), 1e-9), "{got:?}, expected {x},0"); +} + +#[test] +fn tab_reaches_both_close_endpoints() { + let mut h = harness(); + hover(&mut h, CURSOR); + assert_at(snapped(&h), 10.0); + tab(&mut h); + assert_at(snapped(&h), 10.03); +} + +#[test] +fn tab_goes_from_the_nearest_out_and_back_to_the_first() { + let mut h = harness(); + hover(&mut h, CURSOR); + let mut seen = vec![snapped(&h)]; + for _ in 0..3 { + tab(&mut h); + seen.push(snapped(&h)); + } + for (got, x) in seen.into_iter().zip([10.0, 10.03, 9.95, 10.0]) { + assert_at(got, x); + } +} + +#[test] +fn moving_the_cursor_away_starts_the_cycle_over() { + let mut h = harness(); + hover(&mut h, CURSOR); + tab(&mut h); + assert_at(snapped(&h), 10.03); + hover(&mut h, Vec2::new(10.0, 2.0)); + assert!(h.state().canvas.snap.is_none()); + hover(&mut h, CURSOR); + assert_at(snapped(&h), 10.0); +} + +#[test] +fn a_click_places_the_candidate_tab_chose() { + let mut h = harness(); + let pos = hover(&mut h, CURSOR); + tab(&mut h); + assert_at(snapped(&h), 10.03); + for pressed in [true, false] { + h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }); + h.run_steps(2); + } + let base = h.state().session.current_prompt().and_then(|p| p.base).expect("LINE asks for the next point"); + assert_at(base, 10.03); +} diff --git a/docs/gaps.md b/docs/gaps.md index 0adb80f12e..4a9556acae 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -1,6 +1,6 @@ # Where CADCraft falls short of AutoCAD -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-12 · **Change:** minor (multiline attributes read, drawn and saved: F17 narrowed) · **Target:** Autodesk AutoCAD 2027 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-16 · **Change:** minor (Tab cycles through every object snap under the cursor: U4 closed) · **Target:** Autodesk AutoCAD 2027 Every known shortfall, one row each, ranked within each section by user impact. This is the work list: agents pick from here (top of a section first), and remove or update a row in the same PR @@ -53,7 +53,6 @@ Detail and evidence: [ui-parity.md](ui-parity.md). | # | Gap | User impact | Est. | |---|---|---|---| -| U4 | Tab snap cycling offers the closest snap of each mode, not every candidate. Typed snap overrides (`END`, `MID` … `NON`), the Shift/Ctrl+right-click snap menu and Tab cycling landed (#393), the menu's Temporary track point in #441 | Low | 1 | | U5 | Grip menus open on right-click only (no hover menu, no Ctrl to cycle the options); no multifunctional grips on dimensions, MLEADER, hatches or text; Add Vertex on an arc segment straightens it. Hot-grip options (Base point, Copy, Undo, Reference, eXit), multiple hot grips and the polyline/line/arc grip menus landed (#425) | Low-medium | 2–4 | | U6 | Selection: lasso; selection cycling (a list of overlapping objects, SELECTIONCYCLING); the CLass keyword; isolation saved with the drawing (OBJECTISOLATIONMODE 1) and the status-bar isolate button. Press-drag windows (#63), the W, C, F, WP and CP keywords (#226), BOX, AUto, SIngle, Multiple, Group, Add, Remove and Undo, SELECTSIMILAR, and ISOLATEOBJECTS/HIDEOBJECTS/UNISOLATEOBJECTS (#428) landed | Medium | 3–5 | | U7 | Right-click menus: no in-place layout tab rename or Move or Copy dialog, no Select All Layouts, no Paste to command line; palette menus are on the Layers rows and the Properties background only. The command menu (held right-click: Enter, Cancel, Recent Input, options, Snap Overrides, Pan/Zoom), the selection menu with object edits, command line, drawing tab, layout tab and palette menus landed (#512) | Low | 1–2 | @@ -145,6 +144,7 @@ Detail: [localization-parity.md](localization-parity.md). | Date | Change | Summary | |---|---|---| +| 2026-10-16 | minor | Tab at a point prompt cycles through every object snap under the cursor (all the endpoints, midpoints, intersections … in the aperture, nearest first), not only the closest snap of each mode: U4 closed | | 2026-10-12 | minor | Object transparency (entity, ByLayer, ByBlock) is drawn: on screen (TRANSPARENCYDISPLAY, on by default), in PNG/SVG exports, and in plots when the page setup's "Plot transparency" is on (PDF alpha, PNG blending, SVG opacity; PLOTTRANSPARENCYOVERRIDE): F14 narrowed | | 2026-10-12 | minor | Hatch and Gradient dialog (HATCH, GRADIENT; HPDLGMODE) and Hatch Edit dialog (HATCHEDIT, right-click, double-click a hatch): F13 narrowed to Preview, Inherit Properties and boundary add/remove in edit mode | | 2026-10-12 | minor | A bare system variable name typed at the command line (ORTHOMODE, GRIDMODE…) runs SETVAR on that variable, as in AutoCAD; U10 narrowed | diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 5495d4813f..4f539e3cf0 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -1,6 +1,6 @@ # UI parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-12 · **Change:** minor (animation effects follow the operating system's setting) · **Target:** Autodesk AutoCAD 2027 for Mac (26.0) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-16 · **Change:** minor (Tab cycles through every object snap under the cursor) · **Target:** Autodesk AutoCAD 2027 for Mac (26.0) How CADCraft's interaction compares with AutoCAD's: point entry, object snaps, tracking, dynamic input, grips, selection, the command line, chrome and navigation. A drafter's speed in AutoCAD @@ -75,7 +75,7 @@ ignored; there are no context menus. Remaining: **≈ 110–170 Opus 5.5 hours** | Parallel | yes, with parallel path | yes: rest on a line, then a path parallel to it runs through the base point (`snap/tracking.rs`) | | Temporary overrides typed at a prompt (`END`, `MID`, `INT` …) | yes | **no**: the text arrives as plain input | | Shift/Ctrl+right-click snap menu | yes | yes: From, Mid Between 2 Points, Point Filters, the snap modes, None, Osnap Settings; no Temporary track point yet (`context_menu.rs`) | -| Tab to cycle candidate snaps | yes | yes, through the closest snap of each running mode under the cursor (`pointmod::snap_candidates`) | +| Tab to cycle candidate snaps | yes | yes, through every snap of the running modes in the aperture, nearest first, back to the first after the last; moving the cursor out of the aperture starts over (`pointmod::snap_candidates`) | | AutoSnap marker, tooltip, magnet, aperture box | yes | marker per mode and name label; aperture from APERTURE; no magnet, no aperture box | | OSNAPZ, 3D object snaps | yes | no | @@ -202,6 +202,7 @@ down-arrow options menu (DYNPROMPT), and DYNDIM. | Date | Change | Summary | |---|---|---| +| 2026-10-16 | minor | Tab cycles through every object snap in the aperture (all the endpoints, intersections … nearest first), not only the closest of each mode | | 2026-10-12 | minor | Selected and hovered objects redrawn in the selection colour (text and arrowheads included); Options ▸ Selection laid out as AutoCAD's: Object grouping, Show grips, grip object limit, selection preview, Visual Effect Settings (selection area, preview filter) | | 2026-10-12 | minor | Animation effects (dialog and menu fades, smoothed wheel scrolling and ⌘/Ctrl+wheel zoom) follow the operating system's setting; View ▸ Accessibility ▸ Animation Effects chooses System, On or Off | | 2026-10-12 | minor | Hatch and Gradient / Hatch Edit dialogs (HATCH, GRADIENT, HATCHEDIT, double-click a hatch; HPDLGMODE) |