Tangent Circle Tool: a second click replaces the open radius dialog

A click that asks for the radius while the dialog is still open (as a control request can send) closes the open dialog and rolls its preview back, and the new dialog takes over its held answer. Before, the new dialog lost its state to the old dialog's cancel and its OK could not draw.
This commit is contained in:
dotCooCoo committed 2026-11-25 18:31:12 -08:00
1 parent d4acadfce9
commit e70619bc4a
2 files changed
+46 -3

No files matched your search

@@ -50,8 +50,18 @@ pub(crate) fn open(app: &mut VectorcraftApp, p: &Value) {
app.status("no window");
return;
};
// An open the host replaces leaves its preview behind unless it is rolled back here.
// A dialog still open from an earlier click closes without an answer, and its preview is rolled back. The new
// dialog has its id (the dialog's kind), so the earlier dialog's held answer, with its OK and cancel hook, serves
// the new one.
let mut held = None;
if let Some(mut old) = app.addon_dialogs.tangent_radius.take() {
if let Some(host) = app.dialogs() {
host.with(|h| {
h.cancel_by_id(&ctx, old.id);
let _ = h.take_by_id::<HostedParamDialog>(old.id);
});
held = Some(host);
}
take_preview(app, &mut old).cancel(app);
}
let lengths = general_lengths(app);
@@ -66,7 +76,11 @@ pub(crate) fn open(app: &mut VectorcraftApp, p: &Value) {
take_preview(app, &mut open).cancel(app);
}
});
match open_held_with(app, dialog, ok, HeldOptions { parent: None, cancel: Some(cancel) }) {
let opened = match held {
Some(host) => Some(host.with(|h| h.open(dialog.held_ok()))),
None => open_held_with(app, dialog, ok, HeldOptions { parent: None, cancel: Some(cancel) }),
};
match opened {
Some(id) => {
app.addon_dialogs.tangent_radius =
Some(Open { id, click: p.clone(), doc, tried: None, note: None, preview: LivePreview::default(), shown_in: doc });
@@ -387,6 +401,35 @@ mod tests {
assert_eq!(app.session.tool_options_of(tool::ID)["radius"], json!(tool::RADIUS));
}
#[test]
fn a_second_click_replaces_the_open_dialog() {
let mut app = app_with_lines(&[100, 140]);
let (paths, steps) = (count(&app), undo_steps(&app));
let open_ids = |app: &VectorcraftApp| app.dialogs().unwrap().with(|h| h.open_dialogs().iter().map(|d| d.id).collect::<Vec<_>>());
click(&mut app, 150.0, 100.0, false);
click(&mut app, 200.0, 140.0, false);
frame(&mut app);
assert_eq!(count(&app), paths + 1);
// The first line stays picked: another click on the second (as a control request can send while the dialog
// is open) asks again in one dialog, previewing one circle.
click(&mut app, 200.0, 140.0, false);
frame(&mut app);
assert_eq!(open_ids(&app).len(), 1);
assert!(is_open(&app));
assert_eq!(count(&app), paths + 1);
// Cancel closes it and rolls its preview back, with no undo step.
cancel(&app, dialog_id(&app));
frame(&mut app);
assert!(!is_open(&app));
assert!(open_ids(&app).is_empty());
assert_eq!((count(&app), undo_steps(&app)), (paths, steps));
// Asked again, OK draws one circle in one undo step.
click(&mut app, 200.0, 140.0, false);
frame(&mut app);
assert!(press_ok(&mut app), "{}", app.ui.status);
assert_eq!((count(&app), undo_steps(&app)), (paths + 1, steps + 1));
}
#[test]
fn a_switch_to_another_document_leaves_its_interaction_alone() {
let mut app = app_with_lines(&[100, 140]);
+1 -1
View File
@@ -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 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`, `a_switch_to_another_document_leaves_its_interaction_alone` 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`, `a_switch_to_another_document_leaves_its_interaction_alone`, `a_second_click_replaces_the_open_dialog` 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)