diff --git a/crates/tools/src/addons/tangent_circle.rs b/crates/tools/src/addons/tangent_circle.rs index e57740e5a7..c4771344ae 100644 --- a/crates/tools/src/addons/tangent_circle.rs +++ b/crates/tools/src/addons/tangent_circle.rs @@ -167,7 +167,11 @@ fn second_set_at(doc: &Document, first: Place, second: Place) -> Vec { } let (id, subpath, i) = second; let Some(sp) = doc.node(id).and_then(|n| n.path_data()).and_then(|p| p.subpaths.get(subpath)) else { return vec![] }; + // A subpath edited down to no segments (while the radius dialog is open) has nothing to touch. let n = sp.segment_count(); + if n == 0 { + return vec![]; + } let mut indices = vec![i]; if i > 0 || sp.closed { indices.push((i + n - 1) % n); @@ -766,6 +770,11 @@ mod tests { assert!(!segments_unchanged(&doc_at(a, b), &p), "{a} {b}"); } assert!(!segments_unchanged(&Document::new(500.0, 500.0), &p)); + // The second line edited down to a closed subpath without segments: changed. + let mut emptied = d.clone(); + let (second, ..) = place_of(&p["places"][1]).unwrap(); + emptied.node_mut(second).and_then(|n| n.path_data_mut()).unwrap().subpaths[0] = SubPath::polyline(&[], true); + assert!(!segments_unchanged(&emptied, &p)); // Parameters the tool did not write. for key in ["places", "first", "second"] { let mut q = p.clone(); diff --git a/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs b/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs index b0d45c2389..a0be51829f 100644 --- a/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs +++ b/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs @@ -113,6 +113,12 @@ fn circle(app: &VectorcraftApp, open: &mut Open, fields: &DialogFields) -> Resul found.map(|points| (r, points)).ok_or_else(no_circle) } +/// Why the active document cannot take a new circle now: its target layer is locked or hidden. The draw would be +/// refused, with or without a preview. +fn target_refusal(app: &VectorcraftApp) -> Option { + app.session.doc().ok()?.target_parent().err().map(|e| e.to_string()) +} + /// The words the dialog shows for `why` ([`circle`]'s error), in the interface's language. fn shown(why: &str) -> String { if why == tangent_circle::NO_CIRCLE { tl!(tangent_circle::NO_CIRCLE).to_string() } else { crate::i18n::msg(why) } @@ -140,7 +146,9 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &egui::Context) { }; let _ = preview.run(app, previewed.0, "Tangent Circle", DRAW, &previewed.1); open.preview = preview; - open.note = found.err(); + // A target layer locked or hidden after the circle previewed refuses the draw: OK stays off. The preview stays, + // since rolling it back would also roll back the edit that locked or hid the layer. + open.note = found.err().or_else(|| target_refusal(app)); let ready = open.note.as_deref().map_or(Ok(()), |why| Err(Label::from(shown(why)))); app.addon_dialogs.tangent_radius = Some(open); host.with(|h| { @@ -362,6 +370,31 @@ mod tests { assert_eq!(app.session.tool_options_of(tool::ID)["radius"], json!(tool::RADIUS)); } + #[test] + fn a_circle_the_target_layer_cannot_take_shows_why_and_leaves_ok_off() { + let mut app = app_with_lines(&[100, 140]); + let paths = count(&app); + click(&mut app, 150.0, 100.0, false); + click(&mut app, 200.0, 140.0, false); + frame(&mut app); + assert_eq!(note(&app), None); + assert_eq!(count(&app), paths + 1); + // A control request locks the only layer while the dialog is open: no layer takes the circle, and OK is off. + app.run("layer.setProps", json!({"locked": true})).unwrap(); + let steps = undo_steps(&app); + frame(&mut app); + assert!(note(&app).is_some_and(|n| n.contains("locked")), "{:?}", note(&app)); + press_ok_while_off(&mut app); + assert_eq!((count(&app), undo_steps(&app)), (paths + 1, steps)); + // Unlocked again at the same radius: previewed, and OK draws the circle. + app.run("layer.setProps", json!({"locked": false})).unwrap(); + frame(&mut app); + assert_eq!(note(&app), None); + assert_eq!(count(&app), paths + 1); + assert!(press_ok(&mut app), "{}", app.ui.status); + assert_eq!(count(&app), paths + 1); + } + #[test] fn a_radius_that_is_not_a_number_is_refused_and_keeps_the_circle() { let mut app = app_with_lines(&[100, 140]); diff --git a/docs/mcp.md b/docs/mcp.md index 089c971747..3e95f10cc0 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -15003,7 +15003,8 @@ Tools: which sets the radius, draws at once. The dialog's Radius starts at the radius of the circle found, and each radius previews the circle of that radius touching the second segments nearest the click, anywhere along the first segment (at the radius it opened with, the circle found). A radius that gives no circle there shows the note and leaves OK - off, as do an edit to either segment's path after the click and another active document; one outside 0.01 to + off, as do an edit to either segment's path after the click and another active document; a circle the target layer + cannot take (locked or hidden) shows why and leaves OK off; a radius outside 0.01 to 1000000 pt, typed or set, shows the radius error and leaves OK off, except the radius the dialog opened with. `ui.dialog.set` gives an error for a radius that is not a number. OK draws the circle in one undo step, with `shape.circleThroughPoints`, and with `autoUpdateDefault` on also sets `radius` to the radius given when diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 9ff0b33a31..9ad4f4f030 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -3057,7 +3057,7 @@ A VectorCraft addition, not a feature of the reference app, so no area score mov A VectorCraft addition, so no area score moves. The Tangent Circle Tool (`tangentCircle`; Object › Plug-ins › Path Precision Tools and the All Tools drawer) draws a circle on two clicked path segments: tangent to the first at the point clicked (its center on the normal there) and touching the second segment or one beside it on its subpath, the touch nearest the pointer winning. Shift gives the circle the tool's radius, and a drag from the second segment sets the radius to the drag's length (Shift: steps of 1, 2 or 5 times a power of 10 pt, at least 4 screen pixels; Cmd/Ctrl: a tenth of the movement); with a radius the circle may touch the first segment anywhere along it. Before the click the circle shows with its center, radii and radius, or a note says there is none. The circles are found by sampling the distance to the second segments along the first segment's normal (or along the first segment, for a radius) and taking the places where it equals the radius (samples, bisection where it crosses, and a search where it only touches). Left out are circles whose nearest point of the second segments is not on the circle (within a millionth of the radius: where the first segment turns back on itself the distance jumps past the radius without a touch), circles that cross the first segment, circles that touch both segments at one point, circles without a finite radius above 0, circles too small or too large for three of their points to give them back in floating point, and circles that would reach past the canvas; a circle found twice (the same center, touching the first segment at the same point) is kept once. The circle is a new ellipse with the current paint, one undo step; the first segment stays picked until it is drawn, also when drawing fails or the press is canceled, and the circles are looked for again when a live preview, or one that was canceled, changes either segment without an undo step (a changed first segment is forgotten). Tests: `tangent_circle::tests` in `vectorcraft-pathops` (parallel and crossing lines, a curved second segment, a corner's fillet, lines twice the radius apart, a touch between the places tried, the ends of a line with its handles on its anchors, a circle that crosses the first segment, a first segment that turns back, no circle), `addons::tangent_circle::tests` in `vectorcraft-tools` (two clicks, Shift and the radius option, a drag with Shift and Cmd/Ctrl, no circle and Escape, a canceled press, a canceled preview, a circle its three points cannot draw, a circle past the canvas), the session test for a failed draw in `vectorcraft-engine` and the Path Precision Tools menu, options, drawer and catalog tests in `vectorcraft-ui-egui`. Commands: `docs/mcp.md` › Path Precision Tools add-on. -Ask For Circle Radius and Auto-Update Default (2026-11-20): two options of the tool (`askRadius`, `autoUpdateDefault`, both off to start with). With Ask For Circle Radius on, a click on the second segment that finds a circle, with or without Shift, opens a Tangent Circle dialog at that circle's radius instead of drawing; a drag draws at once. Each radius typed previews the circle of that radius nearest the click, a radius with no circle there, an edit to either segment after the click, or another active document, shows the note and leaves OK off, a radius typed outside 0.01 to 1,000,000 pt (other than the click's own) shows an error and leaves OK off, OK draws the circle in one undo step, and Cancel draws nothing and keeps the first segment picked. With Auto-Update Default on, OK also makes the radius given the tool's Shift radius. Tests: `ask_for_circle_radius_opens_the_dialog_after_a_click_but_not_after_a_drag` and `the_radius_dialog_knows_when_its_segments_changed` in `vectorcraft-tools`, and `the_radius_dialog_previews_says_when_there_is_none_cancels_and_draws_on_ok`, `another_document_or_a_segment_changed_after_the_click_gives_no_circle`, `a_click_found_radius_outside_the_tool_range_can_be_drawn` and `a_radius_that_is_not_a_number_is_refused_and_keeps_the_circle` in `vectorcraft-ui-egui`. +Ask For Circle Radius and Auto-Update Default (2026-11-20): two options of the tool (`askRadius`, `autoUpdateDefault`, both off to start with). With Ask For Circle Radius on, a click on the second segment that finds a circle, with or without Shift, opens a Tangent Circle dialog at that circle's radius instead of drawing; a drag draws at once. Each radius typed previews the circle of that radius nearest the click, a radius with no circle there, an edit to either segment after the click, or another active document, shows the note and leaves OK off, a target layer that is locked or hidden says so and leaves OK off, a radius typed outside 0.01 to 1,000,000 pt (other than the click's own) shows an error and leaves OK off, OK draws the circle in one undo step, and Cancel draws nothing and keeps the first segment picked. With Auto-Update Default on, OK also makes the radius given the tool's Shift radius. Tests: `ask_for_circle_radius_opens_the_dialog_after_a_click_but_not_after_a_drag` and `the_radius_dialog_knows_when_its_segments_changed` in `vectorcraft-tools`, and `the_radius_dialog_previews_says_when_there_is_none_cancels_and_draws_on_ok`, `another_document_or_a_segment_changed_after_the_click_gives_no_circle`, `a_click_found_radius_outside_the_tool_range_can_be_drawn`, `a_circle_the_target_layer_cannot_take_shows_why_and_leaves_ok_off` and `a_radius_that_is_not_a_number_is_refused_and_keeps_the_circle` in `vectorcraft-ui-egui`. ## Path Precision Tools add-on: Trim at Crossings (2026-11-13)