From 16bd590f4105de53fae26635c516a231bd526a1c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 01:10:37 -0800 Subject: [PATCH 1/9] Tangent Circle Tool: Ask For Circle Radius asks for the radius after a click Two new tool options, both off by default. With Ask For Circle Radius (`askRadius`) 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, which sets the radius itself, still draws at once. Each radius typed previews the circle of that radius nearest the click. A radius with no circle there shows the tool's note and leaves OK off; a radius outside 0.01 to 1000000 pt, other than the one the dialog opened with, is an error. OK draws the circle in one undo step, and Cancel draws nothing and keeps the first segment picked. With Auto-Update Default (`autoUpdateDefault`) on, OK also makes the radius given the tool's Shift radius. Both options persist with the tool's radius, show in the tool's options dialog and reject values that are not true or false. Part of #7178. --- crates/tools/src/addons/tangent_circle.rs | 204 +++++++++++++- crates/tools/src/settings.rs | 2 +- crates/ui-egui/src/addons/pathtools.rs | 14 +- .../addons/pathtools/tangent_circle_radius.rs | 259 ++++++++++++++++++ crates/ui-egui/src/addons/pathtools/tests.rs | 14 +- crates/ui-egui/src/dialogs.rs | 1 + crates/ui-egui/src/dialogs/form.rs | 8 + crates/ui-egui/src/dialogs/tools.rs | 5 + crates/ui-egui/src/i18n/bg.tsv | 2 + crates/ui-egui/src/i18n/bs.tsv | 2 + crates/ui-egui/src/i18n/ca.tsv | 2 + crates/ui-egui/src/i18n/cs.tsv | 2 + crates/ui-egui/src/i18n/da.tsv | 2 + crates/ui-egui/src/i18n/de.tsv | 2 + crates/ui-egui/src/i18n/el.tsv | 2 + crates/ui-egui/src/i18n/es.tsv | 2 + crates/ui-egui/src/i18n/fi.tsv | 2 + crates/ui-egui/src/i18n/fr.tsv | 2 + crates/ui-egui/src/i18n/gu.tsv | 2 + crates/ui-egui/src/i18n/hi.tsv | 2 + crates/ui-egui/src/i18n/hu.tsv | 2 + crates/ui-egui/src/i18n/id.tsv | 2 + crates/ui-egui/src/i18n/it.tsv | 2 + crates/ui-egui/src/i18n/ja.tsv | 2 + crates/ui-egui/src/i18n/ka.tsv | 2 + crates/ui-egui/src/i18n/ko.tsv | 2 + crates/ui-egui/src/i18n/nl.tsv | 2 + crates/ui-egui/src/i18n/pl.tsv | 2 + crates/ui-egui/src/i18n/pt-br.tsv | 2 + crates/ui-egui/src/i18n/ru.tsv | 2 + crates/ui-egui/src/i18n/sv.tsv | 2 + crates/ui-egui/src/i18n/tr.tsv | 2 + crates/ui-egui/src/i18n/uk.tsv | 2 + crates/ui-egui/src/i18n/vi.tsv | 2 + crates/ui-egui/src/i18n/zh-hans.tsv | 2 + crates/ui-egui/src/i18n/zh-hant.tsv | 2 + docs/mcp.md | 15 +- docs/target-app-parity.md | 2 + 38 files changed, 560 insertions(+), 20 deletions(-) create mode 100644 crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs diff --git a/crates/tools/src/addons/tangent_circle.rs b/crates/tools/src/addons/tangent_circle.rs index b40cffd8e7..5ccc3815de 100644 --- a/crates/tools/src/addons/tangent_circle.rs +++ b/crates/tools/src/addons/tangent_circle.rs @@ -15,7 +15,10 @@ //! press on the second segment is dropped. Escape, an edit or Undo outside the tool, another //! document, or a change to the first segment that leaves no undo step (a live preview, or one that //! was canceled) forgets the first segment. The circles are looked for again whenever either -//! segment's shape differs from the one they were found on. +//! segment's shape differs from the one they were found on. With the `askRadius` option on, a click +//! on the second segment (not a drag, which sets the radius itself) opens the [`RADIUS_DIALOG`] +//! instead of drawing: it starts at the radius of the circle found and draws the circle of the radius +//! typed ([`radius_circle`]); the first segment stays picked until it does. use kurbo::{CubicBez, Shape}; use serde_json::{Value, json}; @@ -39,6 +42,9 @@ const STEP_PX: f64 = 4.0; const SLOW: f64 = 0.1; /// The note shown over a second segment that gives no circle. pub const NO_CIRCLE: &str = "No tangent circle here"; +/// The dialog a click on the second segment opens with `askRadius` on: its parameters hold the two +/// segments, the click and the circle found ([`radius_circle`]). +pub const RADIUS_DIALOG: &str = "tangentCircleRadius"; const BLUE: [u8; 3] = [0x4f, 0x9d, 0xff]; const RED: [u8; 3] = [0xe0, 0x3c, 0x3c]; const GREY: [u8; 3] = [0x80, 0x80, 0x80]; @@ -72,6 +78,10 @@ struct Press { pub struct TangentCircleTool { radius: f64, + /// Whether a click on the second segment asks for the radius (`askRadius`), and whether the + /// radius given there becomes `radius` (`autoUpdateDefault`, which the dialog reads). + ask_radius: bool, + auto_update: bool, first: Option, hover: Option, press: Option, @@ -91,7 +101,19 @@ type CacheKey = (NodeId, usize, usize, Option, CubicBez, Vec); impl Default for TangentCircleTool { fn default() -> Self { - Self { radius: RADIUS, first: None, hover: None, press: None, picking: false, found: None, looked: false, pointer: Point::ZERO, cache: None } + Self { + radius: RADIUS, + ask_radius: false, + auto_update: false, + first: None, + hover: None, + press: None, + picking: false, + found: None, + looked: false, + pointer: Point::ZERO, + cache: None, + } } } @@ -196,6 +218,67 @@ fn segment_path(c: &CubicBez) -> BezPath { bp } +fn point_json(p: Point) -> Value { + json!([p.x, p.y]) +} + +fn curve_json(c: &CubicBez) -> Value { + json!([point_json(c.p0), point_json(c.p1), point_json(c.p2), point_json(c.p3)]) +} + +/// A finite point written by [`point_json`]. +fn point_of(v: &Value) -> Option { + let [x, y] = v.as_array()?.as_slice() else { return None }; + let p = Point::new(x.as_f64()?, y.as_f64()?); + (p.x.is_finite() && p.y.is_finite()).then_some(p) +} + +/// A segment written by [`curve_json`]. +fn curve_of(v: &Value) -> Option { + let [a, b, c, d] = v.as_array()?.as_slice() else { return None }; + Some(CubicBez::new(point_of(a)?, point_of(b)?, point_of(c)?, point_of(d)?)) +} + +/// The [`RADIUS_DIALOG`]'s parameters for circle `c`, found by a click at `at` on `first` and the +/// segments `second`, which `points` (from [`draw`]) draws: the segments, the click, the circle's +/// radius and points, and the tolerance [`draw`] checked them with. +fn dialog_params(first: &CubicBez, second: &[CubicBez], at: Point, c: &SegmentCircle, points: &Value, tol: f64) -> Value { + json!({ + "first": curve_json(first), + "second": second.iter().map(curve_json).collect::>(), + "at": point_json(at), + "radius": c.circle.radius, + "points": points, + "tol": tol, + }) +} + +/// The `shape.circleThroughPoints` parameters that draw the circle of `radius` the [`RADIUS_DIALOG`] +/// opened with parameters `p` gives: at the radius the click found, the circle found; at any other, +/// the circle of `radius` touching the second segments nearest the click, anywhere along the first +/// segment (as with Shift). None for a radius that is not a finite number above 0, when no circle of +/// that radius can be drawn there, or for parameters the tool did not write. +pub fn radius_circle(p: &Value, radius: f64) -> Option { + if !(radius.is_finite() && radius > 0.0) { + return None; + } + if p.get("radius").and_then(Value::as_f64) == Some(radius) { + let points = p.get("points")?; + let [a, b, c] = points.as_array()?.as_slice() else { return None }; + return [a, b, c].into_iter().all(|q| point_of(q).is_some()).then(|| json!({ "points": points })); + } + let first = curve_of(p.get("first")?)?; + // The second segment and at most one on either side of it. + let second: Vec = p.get("second")?.as_array().filter(|s| (1..=3).contains(&s.len()))?.iter().map(curve_of).collect::>()?; + let at = point_of(p.get("at")?)?; + let tol = p.get("tol").and_then(Value::as_f64).filter(|t| t.is_finite() && *t > 0.0)?; + let c = nearest_to(circles_of_radius(first, &second, radius), at, tol)?; + match draw(&c, tol)? { + Action::Exec(_, params) => Some(params), + _ => None, + } +} + impl TangentCircleTool { /// The radius a drag gives, with Shift in round steps. fn shown_radius(cx: &ToolContext, r: f64, shift: bool) -> f64 { @@ -335,14 +418,23 @@ impl Tool for TangentCircleTool { // The release's own position and keys set the radius of a drag. self.drag_to(cx, ev); self.picking = false; - if self.press.take().is_none() { - return vec![]; - } + let Some(press) = self.press.take() else { return vec![] }; // No circle, or one the three points cannot draw: the first segment stays picked, // for another try. It also stays when the command fails: only a drawn circle tells // the tool (`notify`) to forget it. - let Some(action) = self.found.take().and_then(|c| draw(&c, cx.tol(DRAW_PX))) else { return vec![] }; + let tol = cx.tol(DRAW_PX); + let Some((c, action)) = self.found.take().and_then(|c| draw(&c, tol).map(|a| (c, a))) else { return vec![] }; self.looked = false; + // Asked for: a click, not a drag (which set the radius), opens the radius dialog, + // which draws the circle. Until then the first segment stays picked, so Cancel + // leaves it for another try. + if self.ask_radius + && press.radius.is_none() + && let (Some(first), Action::Exec(_, drawn)) = (&self.first, &action) + { + let params = dialog_params(&first.curve, &press.second, press.at, &c, &drawn["points"], tol); + return vec![Action::Dialog(RADIUS_DIALOG.into(), params)]; + } vec![action, Action::Notify(DRAWN.into())] } // The canvas sends a double-click after the second click's `Up`, which drew the circle. @@ -439,14 +531,19 @@ impl Tool for TangentCircleTool { } fn options(&self) -> Value { - json!({ "radius": self.radius }) + json!({ "radius": self.radius, "askRadius": self.ask_radius, "autoUpdateDefault": self.auto_update }) } fn set_option(&mut self, key: &str, v: &Value) { - if key == "radius" - && let Some(r) = v.as_f64().filter(|r| (RADIUS_RANGE.0..=RADIUS_RANGE.1).contains(r)) - { - self.radius = r; + match (key, v) { + ("radius", _) => { + if let Some(r) = v.as_f64().filter(|r| (RADIUS_RANGE.0..=RADIUS_RANGE.1).contains(r)) { + self.radius = r; + } + } + ("askRadius", Value::Bool(b)) => self.ask_radius = *b, + ("autoUpdateDefault", Value::Bool(b)) => self.auto_update = *b, + _ => {} } } @@ -454,6 +551,7 @@ impl Tool for TangentCircleTool { use crate::option_check as c; match key { "radius" => c::number(key, v, RADIUS_RANGE.0, RADIUS_RANGE.1), + "askRadius" | "autoUpdateDefault" => c::boolean(key, v), _ => Err(c::unknown(key)), } } @@ -520,6 +618,90 @@ mod tests { [(a.0, b.0), (a.1, b.1), (a.2, b.2), (a.3, b.3)].iter().all(|(x, y)| (x - y).abs() < 1e-4) } + /// The circle `shape.circleThroughPoints` parameters `p` draw, as [`drawn`] gives it. + fn boxed(p: &Value) -> (f64, f64, f64, f64) { + drawn(&[Action::Exec("shape.circleThroughPoints".into(), p.clone()), Action::Notify(DRAWN.into())]) + } + + /// The radius dialog's parameters in `actions`, which hold nothing else. + fn asked(actions: &[Action]) -> Value { + let [Action::Dialog(kind, p)] = actions else { panic!("{actions:?}") }; + assert_eq!(kind, RADIUS_DIALOG); + p.clone() + } + + #[test] + fn ask_for_circle_radius_opens_the_dialog_after_a_click_but_not_after_a_drag() { + let d = doc(); + let (sel, p) = (Selection::default(), paint()); + let cx = cx(&d, &sel, &p); + let mut t = TangentCircleTool::default(); + assert_eq!((t.options()["askRadius"].clone(), t.options()["autoUpdateDefault"].clone()), (json!(false), json!(false))); + for key in ["askRadius", "autoUpdateDefault"] { + assert_eq!(t.check_option(key, &json!(true)), Ok(())); + for bad in [json!(1), json!("true"), Value::Null] { + assert_eq!(t.check_option(key, &bad), Err(format!("`{key}` must be true or false")), "{bad}"); + t.set_option(key, &bad); + assert_eq!(t.options()[key], json!(false), "{bad}"); + } + t.set_option(key, &json!(true)); + assert_eq!(t.options()[key], json!(true)); + } + // A click on the second line: the dialog, at the click's circle (radius 20), and nothing + // drawn yet; the first segment stays picked. + t.pointer(&cx, &ev(PointerKind::Down, 150.0, 101.0)); + t.pointer(&cx, &ev(PointerKind::Up, 150.0, 101.0)); + t.pointer(&cx, &ev(PointerKind::Down, 200.0, 139.0)); + let p = asked(&up(&mut t, &cx, &ev(PointerKind::Up, 200.0, 139.0))); + assert!((p["radius"].as_f64().unwrap() - 20.0).abs() < 1e-6, "{p}"); + assert!(t.first.is_some() && !t.busy()); + let r = p["radius"].as_f64().unwrap(); + assert!(close(boxed(&radius_circle(&p, r).unwrap()), (130.0, 100.0, 40.0, 40.0)), "{p}"); + // Lines 40 pt apart take no other radius; nor is there a circle without a radius above 0. + for no in [25.0, 0.0, -20.0, f64::NAN, f64::INFINITY] { + assert_eq!(radius_circle(&p, no), None, "{no}"); + } + // Shift on the L's corner: the dialog at the tool's radius, and another radius gives that + // radius's fillet. + t.key(&cx, ToolKey::Escape, Mods::default()); + t.pointer(&cx, &ev(PointerKind::Down, 150.0, 300.0)); + t.pointer(&cx, &ev(PointerKind::Up, 150.0, 300.0)); + t.pointer(&cx, &shifted(PointerKind::Down, 300.0, 350.0)); + let p = asked(&up(&mut t, &cx, &shifted(PointerKind::Up, 300.0, 350.0))); + assert_eq!(p["radius"], json!(RADIUS)); + assert!(close(boxed(&radius_circle(&p, RADIUS).unwrap()), (300.0 - 72.0, 300.0, 72.0, 72.0)), "{p}"); + assert!(close(boxed(&radius_circle(&p, 10.0).unwrap()), (280.0, 300.0, 20.0, 20.0)), "{p}"); + // Parameters the tool did not write give no circle. + assert_eq!(radius_circle(&json!({}), 10.0), None); + let second = p["second"].as_array().unwrap()[0].clone(); + for (key, bad) in [ + ("second", json!([])), + ("second", json!([second, second, second, second])), + ("at", json!([1.0])), + ("tol", json!(0)), + ("first", json!("x")), + ("points", json!([[0, 0]])), + ] { + let mut q = p.clone(); + q[key] = bad; + let r = if key == "points" { RADIUS } else { 10.0 }; + assert_eq!(radius_circle(&q, r), None, "{key}"); + } + // A drag sets the radius itself: drawn at once, with no dialog. + t.pointer(&cx, &ev(PointerKind::Down, 300.0, 350.0)); + t.pointer(&cx, &ev(PointerKind::Drag, 300.0, 365.0)); + let released = up(&mut t, &cx, &ev(PointerKind::Up, 300.0, 365.0)); + assert!(close(drawn(&released), (300.0 - 30.0, 300.0, 30.0, 30.0)), "{released:?}"); + assert!(t.first.is_none()); + // A click that finds no circle opens no dialog. + t.set_option("radius", &json!(5)); + t.pointer(&cx, &ev(PointerKind::Down, 150.0, 101.0)); + t.pointer(&cx, &ev(PointerKind::Up, 150.0, 101.0)); + t.pointer(&cx, &shifted(PointerKind::Down, 200.0, 139.0)); + assert!(t.pointer(&cx, &shifted(PointerKind::Up, 200.0, 139.0)).is_empty()); + assert!(t.first.is_some()); + } + #[test] fn two_clicks_draw_the_circle_tangent_at_the_first_click() { let d = doc(); diff --git a/crates/tools/src/settings.rs b/crates/tools/src/settings.rs index 1d9d8c4a54..3576d03379 100644 --- a/crates/tools/src/settings.rs +++ b/crates/tools/src/settings.rs @@ -108,7 +108,7 @@ const ROWS: &[Row] = &[ (&[crate::addons::extend_path::ID], None, &["mode"]), (&[crate::addons::corner_tool::ID], None, &["radius", "kind"]), (&[crate::addons::shared_edge::ID], None, &["diameter", "tolerance", "together"]), - (&[crate::addons::tangent_circle::ID], None, &["radius"]), + (&[crate::addons::tangent_circle::ID], None, &["radius", "askRadius", "autoUpdateDefault"]), (&[crate::addons::smart_pen::ID], None, &["next"]), // The kind first: a new kind resets the values after it. (&[crate::addons::parametric_shape::ID], None, &["kind", "count", "a", "b", "radius", "width", "height", "rotation"]), diff --git a/crates/ui-egui/src/addons/pathtools.rs b/crates/ui-egui/src/addons/pathtools.rs index 3e7b864c05..f1933770bb 100644 --- a/crates/ui-egui/src/addons/pathtools.rs +++ b/crates/ui-egui/src/addons/pathtools.rs @@ -3,8 +3,9 @@ //! Dashes ([`dashes`]), Expand Dashes into Paths, Smooth Bridge ([`bridge`]), Convert to Parametric Shape, Tangent Circle… ([`tangent_circle`]), Add Bounding Rectangle… and Add Bounding Circle…; the Anchor Inspector panel (the selected //! anchor's position and handles as numbers, the add-on's anchor edits, the Corner Tool's values, //! [`corner`], and the Shared Edge Merge Tool's, [`shared_edge`]); the Parametric Shape panel -//! ([`shape`]); and its tools' options dialog (a double-click on the tool). Everything acts through `addon.pathtools.*` and -//! `tool.setOption`. +//! ([`shape`]); its tools' options dialog (a double-click on the tool); and the Tangent Circle Tool's radius dialog +//! ([`tangent_circle_radius`]). Everything acts through `addon.pathtools.*` and `tool.setOption`, except that the radius +//! dialog draws its circle with `shape.circleThroughPoints`. pub mod bridge; pub mod corner; @@ -13,6 +14,7 @@ pub mod set_corners; pub mod shape; pub mod shared_edge; pub mod tangent_circle; +pub mod tangent_circle_radius; use egui::Ui; use serde_json::{Map, Value, json}; @@ -245,6 +247,14 @@ fn body(_app: &mut VectorcraftApp, ui: &mut Ui, d: &mut Dialog) -> bool { d.fields.insert("radius".into(), json!(x)); } }); + if widgets::check(ui, tl!("Ask For Circle Radius"), d.bool("askRadius"), true) { + let on = !d.bool("askRadius"); + d.fields.insert("askRadius".into(), json!(on)); + } + if widgets::check(ui, tl!("Auto-Update Default"), d.bool("autoUpdateDefault"), true) { + let on = !d.bool("autoUpdateDefault"); + d.fields.insert("autoUpdateDefault".into(), json!(on)); + } return false; } let rows = [ diff --git a/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs b/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs new file mode 100644 index 0000000000..bc1b6d5992 --- /dev/null +++ b/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs @@ -0,0 +1,259 @@ +//! The Tangent Circle Tool's radius dialog, which a click on the second segment opens when the +//! tool's Ask For Circle Radius option is on. It starts at the radius of the circle the click found, +//! and each radius previews on the canvas the circle of that radius touching the two segments +//! nearest the click ([`tangent_circle::radius_circle`]). A radius that gives no circle there shows +//! the tool's note and leaves OK off. OK draws the circle with `shape.circleThroughPoints` in one +//! undo step, and with Auto-Update Default on also sets the tool's `radius` to the one given; Cancel +//! draws nothing. + +use egui::Ui; +use serde_json::{Value, json}; +use vectorcraft_tools::addons::tangent_circle; + +use crate::VectorcraftApp; +use crate::dialogs::{DialogSpec, form}; +use crate::state::Dialog; +use crate::theme::Tokens; +use crate::widgets; + +/// The dialog's kind. +pub const KIND: &str = tangent_circle::RADIUS_DIALOG; +/// The command that draws the circle. +const DRAW: &str = "shape.circleThroughPoints"; +const LABEL_W: f32 = 60.0; +const FIELD_W: f32 = 90.0; +/// What the tool found (a private field): the segments, the click and its circle. +const CLICK: &str = "__click"; +/// The radius the circle was last looked for at, and the circle's parameters for [`DRAW`] (null: +/// none) (private fields). +const TRIED: &str = "__tried"; +const CIRCLE: &str = "__circle"; +/// The error for a radius outside the tool's range. +const RADIUS_RANGE: &str = "`radius` must be from 0.01 to 1000000 pt"; + +/// Open the dialog on what the tool found (its [`tangent_circle::RADIUS_DIALOG`] parameters). +pub(crate) fn open(app: &mut VectorcraftApp, p: &Value) { + let radius = p.get("radius").cloned().unwrap_or(json!(tangent_circle::RADIUS)); + app.ui.dialog = Some(Dialog::new(KIND, json!({ "radius": radius, "preview": true, CLICK: p }))); +} + +pub(crate) const SPEC: DialogSpec = DialogSpec { + heading: |_| tl!("Tangent Circle").to_string(), + body, + confirm, + preview: true, + ok_enabled: Some(|_, d| circle_of(d).is_some_and(|c| c.is_ok_and(|c| c.is_some()))), + min_width: 280.0, + ..DialogSpec::FORM +}; + +/// Whether `r` is in the tool's radius range. +fn in_range(r: f64) -> bool { + let (lo, hi) = tangent_circle::RADIUS_RANGE; + (lo..=hi).contains(&r) +} + +/// The radius typed, when it is in the tool's range or is the radius of the circle the click found +/// (which a click without Shift may find outside that range). +fn radius(d: &Dialog) -> Result { + let found = d.fields.get(CLICK).and_then(|p| p.get("radius")).and_then(Value::as_f64); + d.fields.get("radius").and_then(Value::as_f64).filter(|r| in_range(*r) || Some(*r) == found).ok_or_else(|| RADIUS_RANGE.to_string()) +} + +/// The circle last looked for, when it was looked for at the radius the dialog holds: its [`DRAW`] +/// parameters, or none. +fn circle_of(d: &Dialog) -> Option, String>> { + let r = match radius(d) { + Ok(r) => r, + Err(e) => return Some(Err(e)), + }; + (d.fields.get(TRIED).and_then(Value::as_f64) == Some(r)).then(|| Ok(d.fields.get(CIRCLE).filter(|c| !c.is_null()).cloned())) +} + +/// The circle at the radius the dialog holds, looked for again only when the radius changed. +fn circle(d: &mut Dialog) -> Result, String> { + if let Some(found) = circle_of(d) { + return found; + } + let r = radius(d)?; + let found = d.fields.get(CLICK).and_then(|p| tangent_circle::radius_circle(p, r)); + d.fields.insert(TRIED.into(), json!(r)); + d.fields.insert(CIRCLE.into(), found.clone().unwrap_or(Value::Null)); + Ok(found) +} + +fn body(app: &mut VectorcraftApp, ui: &mut Ui, d: &mut Dialog) -> bool { + let unit = app.session.general_unit(); + let (lo, hi) = tangent_circle::RADIUS_RANGE; + widgets::label_row(ui, tl!("Radius:"), LABEL_W, |ui| { + form::length_within(ui, d, "radius", unit, FIELD_W, Some(lo..=hi)); + }); + let note = match circle(d) { + Ok(Some(points)) => { + form::preview_without_check(app, d, "Tangent Circle", DRAW, points); + return false; + } + Ok(None) => tl!(tangent_circle::NO_CIRCLE).to_string(), + Err(e) => crate::i18n::msg(&e), + }; + form::rollback_preview(app, d); + ui.add_space(6.0); + ui.label(egui::RichText::new(note).color(Tokens::get(ui.ctx()).error)); + false +} + +/// OK: draw the circle (keeping its preview) and close; with Auto-Update Default on, the radius +/// becomes the tool's when it is in the tool's range. Without a circle the dialog stays open. +fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { + let mut d = d.clone(); + let r = radius(&d)?; + let points = circle(&mut d)?.ok_or_else(|| tangent_circle::NO_CIRCLE.to_string())?; + let auto = app.session.tool_options_of(tangent_circle::ID).get("autoUpdateDefault").and_then(Value::as_bool) == Some(true); + form::commit_preview(app, DRAW, points)?; + if auto && in_range(r) { + app.run("tool.setOption", json!({ "tool": tangent_circle::ID, "key": "radius", "value": r }))?; + } + Ok(Value::Null) +} + +#[cfg(test)] +mod tests { + use serde_json::{Value, json}; + use vectorcraft_engine::{Session, ViewInfo}; + use vectorcraft_tools::addons::tangent_circle as tool; + use vectorcraft_tools::{PointerEvent, PointerKind}; + + use crate::VectorcraftApp; + use crate::tests_labels::painted_text; + + fn count(app: &VectorcraftApp) -> usize { + app.session.doc().unwrap().doc.layers[0].children().unwrap().len() + } + + fn undo_steps(app: &VectorcraftApp) -> usize { + app.session.doc().unwrap().history.undo.len() + } + + /// A click with the active tool at (`x`, `y`), Shift held when `shift`, with what it asks the + /// interface for done. + fn click(app: &mut VectorcraftApp, x: f64, y: f64, shift: bool) { + for kind in [PointerKind::Down, PointerKind::Up] { + let mut ev = PointerEvent::new(kind, x, y); + ev.mods.shift = shift; + let r = app.session.pointer(&ev, ViewInfo::default()); + crate::canvas::apply_requests(app, r); + } + } + + /// A frame of the open dialog: the text it shows. + fn frame(app: &mut VectorcraftApp) -> String { + painted_text(app, |app, ui| crate::dialogs::show(app, ui.ctx())) + } + + fn set_radius(app: &mut VectorcraftApp, r: Value) { + app.ui.dialog.as_mut().unwrap().fields.insert("radius".into(), r); + } + + fn ok_enabled(app: &VectorcraftApp) -> bool { + super::SPEC.ok_enabled.is_some_and(|f| f(app, app.ui.dialog.as_ref().unwrap())) + } + + #[test] + fn the_radius_dialog_previews_says_when_there_is_none_cancels_and_draws_on_ok() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 500, "height": 500})).unwrap(); + for (a, b) in [((100, 100), (300, 100)), ((100, 140), (300, 140))] { + app.run("path.create", json!({"anchors": [{"x": a.0, "y": a.1}, {"x": b.0, "y": b.1}]})).unwrap(); + } + app.run("path.create", json!({"anchors": [{"x": 100, "y": 300}, {"x": 300, "y": 300}, {"x": 300, "y": 400}]})).unwrap(); + app.session.select_tool(tool::ID, ViewInfo::default()).unwrap(); + app.run("tool.setOption", json!({"tool": tool::ID, "key": "askRadius", "value": true})).unwrap(); + let (paths, steps) = (count(&app), undo_steps(&app)); + // A click on each line: the dialog at the click's circle (radius 20), previewed. + click(&mut app, 150.0, 100.0, false); + click(&mut app, 200.0, 140.0, false); + assert_eq!(app.ui.dialog.as_ref().map(|d| d.kind.as_str()), Some(super::KIND)); + assert!((app.ui.dialog.as_ref().unwrap().f64("radius", 0.0) - 20.0).abs() < 1e-6); + let shown = frame(&mut app); + for s in ["Tangent Circle", "Radius:"] { + assert!(shown.contains(s), "{s} in {shown}"); + } + assert_eq!(count(&app), paths + 1, "previewed: {}", app.ui.status); + assert!(ok_enabled(&app)); + // Lines 40 pt apart take no other radius: the note, nothing previewed, and OK off. + set_radius(&mut app, json!(25)); + assert!(frame(&mut app).contains(tool::NO_CIRCLE)); + assert_eq!(count(&app), paths); + assert!(!ok_enabled(&app)); + assert_eq!(crate::dialogs::confirm(&mut app), Err(tool::NO_CIRCLE.to_string())); + assert!(app.ui.dialog.is_some() && count(&app) == paths); + // A radius that is not a number in the tool's range (as a control request can set it) is an + // error. + for bad in [json!(0), json!(-20), json!(2e6), json!("x"), Value::Null] { + set_radius(&mut app, bad.clone()); + assert!(frame(&mut app).contains(super::RADIUS_RANGE), "{bad}"); + assert!(!ok_enabled(&app), "{bad}"); + assert_eq!(crate::dialogs::confirm(&mut app), Err(super::RADIUS_RANGE.to_string()), "{bad}"); + assert_eq!(count(&app), paths, "{bad}"); + } + // Back at 20, previewed again; Cancel draws nothing and leaves no undo step. + set_radius(&mut app, json!(20)); + frame(&mut app); + assert_eq!(count(&app), paths + 1); + crate::dialogs::cancel(&mut app); + assert!(app.ui.dialog.is_none()); + assert_eq!((count(&app), undo_steps(&app)), (paths, steps)); + // The first line stays picked: a click on the second asks again, and OK draws the circle in + // one undo step; the tool's radius stays. + click(&mut app, 200.0, 140.0, false); + frame(&mut app); + crate::dialogs::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + assert_eq!((count(&app), undo_steps(&app)), (paths + 1, steps + 1)); + let b = app.session.doc().unwrap().doc.bounds_of(&[app.session.doc().unwrap().doc.layers[0].children().unwrap()[paths].id], false).unwrap(); + assert!((b.x0 - 130.0).abs() < 1e-3 && (b.y0 - 100.0).abs() < 1e-3 && (b.width() - 40.0).abs() < 1e-3, "{b:?}"); + assert_eq!(app.session.tool_options_of(tool::ID)["radius"], json!(tool::RADIUS)); + // Auto-Update Default: Shift in the L's corner asks at the tool's radius; Cancel keeps the + // tool's radius, and OK with another radius draws that fillet and makes it the tool's. + app.run("tool.setOption", json!({"tool": tool::ID, "key": "autoUpdateDefault", "value": true})).unwrap(); + click(&mut app, 150.0, 300.0, false); + click(&mut app, 300.0, 350.0, true); + assert_eq!(app.ui.dialog.as_ref().unwrap().f64("radius", 0.0), tool::RADIUS); + set_radius(&mut app, json!(12)); + frame(&mut app); + crate::dialogs::cancel(&mut app); + assert_eq!(app.session.tool_options_of(tool::ID)["radius"], json!(tool::RADIUS)); + click(&mut app, 300.0, 350.0, true); + set_radius(&mut app, json!(10)); + frame(&mut app); + crate::dialogs::confirm(&mut app).unwrap(); + assert_eq!((count(&app), undo_steps(&app)), (paths + 2, steps + 2)); + assert_eq!(app.session.tool_options_of(tool::ID)["radius"], json!(10.0)); + } + + #[test] + fn a_click_found_radius_outside_the_tool_range_can_be_drawn() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 500, "height": 500})).unwrap(); + // Lines 2,400,000 pt apart: a click on each finds the circle of radius 1,200,000, past the + // largest radius the tool takes. + for y in [100, 2_400_100] { + app.run("path.create", json!({"anchors": [{"x": 100, "y": y}, {"x": 300, "y": y}]})).unwrap(); + } + app.session.select_tool(tool::ID, ViewInfo::default()).unwrap(); + for key in ["askRadius", "autoUpdateDefault"] { + app.run("tool.setOption", json!({"tool": tool::ID, "key": key, "value": true})).unwrap(); + } + let (paths, steps) = (count(&app), undo_steps(&app)); + click(&mut app, 150.0, 100.0, false); + click(&mut app, 200.0, 2_400_100.0, false); + assert!((app.ui.dialog.as_ref().unwrap().f64("radius", 0.0) - 1_200_000.0).abs() < 1e-3, "{}", app.ui.status); + frame(&mut app); + assert!(ok_enabled(&app)); + // OK draws it; the tool's radius stays, since the tool does not take that radius. + crate::dialogs::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + assert_eq!((count(&app), undo_steps(&app)), (paths + 1, steps + 1)); + assert_eq!(app.session.tool_options_of(tool::ID)["radius"], json!(tool::RADIUS)); + } +} diff --git a/crates/ui-egui/src/addons/pathtools/tests.rs b/crates/ui-egui/src/addons/pathtools/tests.rs index 2c49c661fe..2d83329e24 100644 --- a/crates/ui-egui/src/addons/pathtools/tests.rs +++ b/crates/ui-egui/src/addons/pathtools/tests.rs @@ -99,14 +99,20 @@ fn double_clicking_the_brush_opens_its_options_and_ok_sets_them() { app.ui.dialog.as_mut().unwrap().fields.insert("mode".into(), json!("arc")); crate::dialogs::confirm(&mut app).unwrap(); assert_eq!(app.session.tool_options_of("extendPath")["mode"], json!("arc")); - // The Tangent Circle tool's radius for Shift. + // The Tangent Circle tool's radius for Shift, Ask For Circle Radius and Auto-Update Default. app.run("tool.options", json!({"tool": "tangentCircle"})).unwrap(); assert_eq!(app.ui.dialog.as_ref().unwrap().f64("radius", 0.0), 36.0); let text = painted_text(&mut app, |app, ui| crate::dialogs::show(app, ui.ctx())); - assert!(text.contains("Tangent Circle Tool Options") && text.contains("Radius:"), "{text}"); - app.ui.dialog.as_mut().unwrap().fields.insert("radius".into(), json!(12.5)); + for s in ["Tangent Circle Tool Options", "Radius:", "Ask For Circle Radius", "Auto-Update Default"] { + assert!(text.contains(s), "{s} in {text}"); + } + let d = app.ui.dialog.as_mut().unwrap(); + assert!(!d.bool("askRadius") && !d.bool("autoUpdateDefault")); + d.fields.insert("radius".into(), json!(12.5)); + d.fields.insert("askRadius".into(), json!(true)); crate::dialogs::confirm(&mut app).unwrap(); - assert_eq!(app.session.tool_options_of("tangentCircle")["radius"], json!(12.5)); + let o = app.session.tool_options_of("tangentCircle"); + assert_eq!((o["radius"].clone(), o["askRadius"].clone(), o["autoUpdateDefault"].clone()), (json!(12.5), json!(true), json!(false))); assert!(app.run("tool.options", json!({"tool": "measureInspect"})).is_err()); } diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index a24755ab12..afd89e6cb9 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -509,6 +509,7 @@ registry! { DivideDashes: [crate::addons::pathtools::dashes::KIND] => crate::addons::pathtools::dashes::SPEC, SmoothBridge: [crate::addons::pathtools::bridge::KIND] => crate::addons::pathtools::bridge::SPEC, TangentCircle: [crate::addons::pathtools::tangent_circle::KIND] => crate::addons::pathtools::tangent_circle::SPEC, + TangentCircleRadius: [crate::addons::pathtools::tangent_circle_radius::KIND] => crate::addons::pathtools::tangent_circle_radius::SPEC, SetCorners: [crate::addons::pathtools::set_corners::KIND] => crate::addons::pathtools::set_corners::SPEC, NearestSwatch: [crate::addons::color::nearest::KIND] => crate::addons::color::nearest::SPEC, SwatchLegend: [crate::addons::color::legend::KIND] => crate::addons::color::legend::SPEC, diff --git a/crates/ui-egui/src/dialogs/form.rs b/crates/ui-egui/src/dialogs/form.rs index f19cd18cda..be6e1f390c 100644 --- a/crates/ui-egui/src/dialogs/form.rs +++ b/crates/ui-egui/src/dialogs/form.rs @@ -1049,6 +1049,14 @@ pub(crate) fn preview_without_check(app: &mut crate::VectorcraftApp, d: &mut Dia let _ = preview_or_rollback(app, d, label, cmd, params); } +/// Roll back the preview [`preview_without_check`] runs, for values that give nothing to preview: +/// the next preview starts again from the document as it was. +pub(crate) fn rollback_preview(app: &mut crate::VectorcraftApp, d: &mut Dialog) { + if d.fields.remove(PREVIEWED).is_some() { + let _ = app.session.cancel_interaction(); + } +} + /// [`preview_now`] while Preview is on; off, it rolls the preview back. fn preview_or_rollback(app: &mut crate::VectorcraftApp, d: &mut Dialog, label: &str, cmd: &str, params: Value) -> Option { if !d.bool("preview") { diff --git a/crates/ui-egui/src/dialogs/tools.rs b/crates/ui-egui/src/dialogs/tools.rs index 0ad9ed936c..e6addca10c 100644 --- a/crates/ui-egui/src/dialogs/tools.rs +++ b/crates/ui-egui/src/dialogs/tools.rs @@ -171,6 +171,11 @@ pub fn open_tool_dialog(app: &mut VectorcraftApp, kind: &str, p: Value) { } return; } + // A Tangent Circle Tool click with Ask For Circle Radius on: the circle's radius. + crate::addons::pathtools::tangent_circle_radius::KIND => { + crate::addons::pathtools::tangent_circle_radius::open(app, &p); + return; + } // A click or double-click that would edit type set in fonts that aren't available. vectorcraft_tools::text::MISSING_FONT_EDIT => { super::confirm::ask_missing_font_edit(app, &p); diff --git a/crates/ui-egui/src/i18n/bg.tsv b/crates/ui-egui/src/i18n/bg.tsv index 167737554d..797a2b2017 100644 --- a/crates/ui-egui/src/i18n/bg.tsv +++ b/crates/ui-egui/src/i18n/bg.tsv @@ -7587,6 +7587,8 @@ breakText Glyphs Глифи Tangent Circle Допирателна окръжност Tangent Circle Tool Инструмент „Допирателна окръжност“ No tangent circle here Тук няма допирателна окръжност + Ask For Circle Radius Питане за радиуса на окръжността + Auto-Update Default Автоматично обновяване на стойността по подразбиране Circle: Окръжност: @msg `ids` names an object twice `ids` посочва обект два пъти @msg select two or three paths or compound paths изберете два или три пътя или съставни пътя diff --git a/crates/ui-egui/src/i18n/bs.tsv b/crates/ui-egui/src/i18n/bs.tsv index a9d6e35ed8..db61b3aed3 100644 --- a/crates/ui-egui/src/i18n/bs.tsv +++ b/crates/ui-egui/src/i18n/bs.tsv @@ -7636,6 +7636,8 @@ shape Open Otvoren Tangent Circle Tangentna kružnica Tangent Circle Tool Alat tangentna kružnica No tangent circle here Ovdje nema tangentne kružnice + Ask For Circle Radius Pitaj za poluprečnik kružnice + Auto-Update Default Automatski ažuriraj zadanu vrijednost Circle: Kružnica: @msg `ids` names an object twice `ids` navodi objekat dvaput @msg select two or three paths or compound paths odaberite dvije ili tri putanje ili složene putanje diff --git a/crates/ui-egui/src/i18n/ca.tsv b/crates/ui-egui/src/i18n/ca.tsv index e4271f7926..eff5103a3b 100644 --- a/crates/ui-egui/src/i18n/ca.tsv +++ b/crates/ui-egui/src/i18n/ca.tsv @@ -8468,6 +8468,8 @@ breakText Glyphs Glifs Tangent Circle Cercle tangent Tangent Circle Tool Eina de cercle tangent No tangent circle here Aquí no hi ha cap cercle tangent + Ask For Circle Radius Demana el radi del cercle + Auto-Update Default Actualitza automàticament el valor predeterminat Circle: Cercle: @msg `ids` names an object twice `ids` indica un objecte dues vegades @msg select two or three paths or compound paths seleccioneu dos o tres camins o camins compostos diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index 488df173c3..105be5cac2 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -8449,6 +8449,8 @@ breakText Glyphs Glyfy Tangent Circle Tečná kružnice Tangent Circle Tool Nástroj Tečná kružnice No tangent circle here Zde není žádná tečná kružnice + Ask For Circle Radius Ptát se na poloměr kružnice + Auto-Update Default Automaticky aktualizovat výchozí hodnotu Circle: Kružnice: @msg `ids` names an object twice `ids` uvádí některý objekt dvakrát @msg select two or three paths or compound paths vyberte dvě nebo tři cesty nebo složené cesty diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index 302ab6aa69..6396024ada 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -10505,6 +10505,8 @@ breakText Glyphs Glyffer Tangent Circle Tangentcirkel Tangent Circle Tool Tangentcirkel-værktøj No tangent circle here Ingen tangentcirkel her + Ask For Circle Radius Spørg om cirklens radius + Auto-Update Default Opdater standard automatisk Circle: Cirkel: @msg `ids` names an object twice `ids` nævner et objekt to gange @msg select two or three paths or compound paths vælg to eller tre stier eller sammensatte stier diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index 9482345f18..61d3b10d1d 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -8074,6 +8074,8 @@ breakText Glyphs Glyphen Tangent Circle Tangentialkreis Tangent Circle Tool Tangentialkreis-Werkzeug No tangent circle here Hier kein Tangentialkreis + Ask For Circle Radius Nach Kreisradius fragen + Auto-Update Default Standardwert automatisch aktualisieren Circle: Kreis: @msg `ids` names an object twice `ids` nennt ein Objekt zweimal @msg select two or three paths or compound paths wählen Sie zwei oder drei Pfade oder zusammengesetzte Pfade aus diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index 434d0cc0b8..c008194ebd 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -8440,6 +8440,8 @@ breakText Glyphs Γλύφοι Tangent Circle Εφαπτόμενος κύκλος Tangent Circle Tool Εφαπτόμενος κύκλος (Tangent Circle Tool) No tangent circle here Δεν υπάρχει εφαπτόμενος κύκλος εδώ + Ask For Circle Radius Ερώτηση για την ακτίνα του κύκλου + Auto-Update Default Αυτόματη ενημέρωση προεπιλογής Circle: Κύκλος: @msg `ids` names an object twice το `ids` αναφέρει ένα αντικείμενο δύο φορές @msg select two or three paths or compound paths επιλέξτε δύο ή τρεις διαδρομές ή σύνθετες διαδρομές diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index 3f83e928e4..6e59438927 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -8426,6 +8426,8 @@ breakText Glyphs Glifos Tangent Circle Círculo tangente Tangent Circle Tool Herramienta Círculo tangente No tangent circle here No hay círculo tangente aquí + Ask For Circle Radius Preguntar el radio del círculo + Auto-Update Default Actualizar automáticamente el valor predeterminado Circle: Círculo: @msg `ids` names an object twice `ids` indica un objeto dos veces @msg select two or three paths or compound paths seleccione dos o tres trazados o trazados compuestos diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index a4d85b23e8..9cb0a278dc 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -8516,6 +8516,8 @@ breakText Glyphs Merkit Tangent Circle Sivuava ympyrä Tangent Circle Tool Sivuava ympyrä -työkalu No tangent circle here Tässä ei ole sivuavaa ympyrää + Ask For Circle Radius Kysy ympyrän säde + Auto-Update Default Päivitä oletus automaattisesti Circle: Ympyrä: @msg `ids` names an object twice `ids` mainitsee saman objektin kahdesti @msg select two or three paths or compound paths valitse kaksi tai kolme polkua tai yhdistelmäpolkua diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index 8f56486157..5c13273bde 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -8445,6 +8445,8 @@ breakText Glyphs Glyphes Tangent Circle Cercle tangent Tangent Circle Tool Outil Cercle tangent No tangent circle here Aucun cercle tangent ici + Ask For Circle Radius Demander le rayon du cercle + Auto-Update Default Mettre à jour automatiquement la valeur par défaut Circle: Cercle : @msg `ids` names an object twice `ids` désigne deux fois le même objet @msg select two or three paths or compound paths sélectionnez deux ou trois tracés ou tracés transparents diff --git a/crates/ui-egui/src/i18n/gu.tsv b/crates/ui-egui/src/i18n/gu.tsv index 0bb7c9b71f..5cc465adf3 100644 --- a/crates/ui-egui/src/i18n/gu.tsv +++ b/crates/ui-egui/src/i18n/gu.tsv @@ -4336,6 +4336,8 @@ arrowhead Feather પીંછું Tangent Circle સ્પર્શક વર્તુળ Tangent Circle Tool સ્પર્શક વર્તુળ ટૂલ No tangent circle here અહીં કોઈ સ્પર્શક વર્તુળ નથી + Ask For Circle Radius વર્તુળની ત્રિજ્યા પૂછો + Auto-Update Default ડિફૉલ્ટ આપમેળે અપડેટ કરો Tangent Circle… સ્પર્શક વર્તુળ… Taper ટેપર Target લક્ષ્ય diff --git a/crates/ui-egui/src/i18n/hi.tsv b/crates/ui-egui/src/i18n/hi.tsv index e9509d9202..404c9c0fae 100644 --- a/crates/ui-egui/src/i18n/hi.tsv +++ b/crates/ui-egui/src/i18n/hi.tsv @@ -5889,6 +5889,8 @@ arrowhead Feather पंख Tangent Circle स्पर्शी वृत्त Tangent Circle Tool स्पर्शी वृत्त टूल No tangent circle here यहाँ कोई स्पर्शी वृत्त नहीं है + Ask For Circle Radius वृत्त की त्रिज्या पूछें + Auto-Update Default डिफ़ॉल्ट स्वचालित रूप से अपडेट करें Tangent Circle… स्पर्शी वृत्त… Taper टेपर Target लक्ष्य diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index 87f050ef0d..f5b9232d45 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -8435,6 +8435,8 @@ breakText Glyphs Glifák Tangent Circle Érintőkör Tangent Circle Tool Érintőkör eszköz No tangent circle here Itt nincs érintőkör + Ask For Circle Radius Kérdés a kör sugaráról + Auto-Update Default Alapértelmezett érték automatikus frissítése Circle: Kör: @msg `ids` names an object twice `ids`: egy objektumot kétszer nevez meg @msg select two or three paths or compound paths jelölj ki két vagy három útvonalat vagy összetett útvonalat diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index 924d3d80b5..364bc3bae8 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -8290,6 +8290,8 @@ breakText Glyphs Glif Tangent Circle Lingkaran singgung Tangent Circle Tool Alat lingkaran singgung No tangent circle here Tidak ada lingkaran singgung di sini + Ask For Circle Radius Tanyakan Radius Lingkaran + Auto-Update Default Perbarui Default Otomatis Circle: Lingkaran: @msg `ids` names an object twice `ids` menyebut satu objek dua kali @msg select two or three paths or compound paths pilih dua atau tiga jalur atau jalur gabungan diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index 5f47e3f117..81823d1b5f 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -8112,6 +8112,8 @@ breakText Glyphs Glifi Tangent Circle Cerchio tangente Tangent Circle Tool Strumento Cerchio tangente No tangent circle here Nessun cerchio tangente qui + Ask For Circle Radius Chiedi il raggio del cerchio + Auto-Update Default Aggiorna automaticamente il valore predefinito Circle: Cerchio: @msg `ids` names an object twice `ids` indica due volte lo stesso oggetto @msg select two or three paths or compound paths seleziona due o tre tracciati o tracciati composti diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 9a1b5f6354..6c4dc97248 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -10001,6 +10001,8 @@ breakText Glyphs 字形 Tangent Circle 接円 Tangent Circle Tool 接円ツール No tangent circle here ここに接円はありません + Ask For Circle Radius 円の半径を確認 + Auto-Update Default デフォルトを自動更新 Circle: 円: @msg `ids` names an object twice `ids` に同じオブジェクトが 2 回指定されています @msg select two or three paths or compound paths パスまたは複合パスを 2 つか 3 つ選択してください diff --git a/crates/ui-egui/src/i18n/ka.tsv b/crates/ui-egui/src/i18n/ka.tsv index 8eeacee621..5a7507f429 100644 --- a/crates/ui-egui/src/i18n/ka.tsv +++ b/crates/ui-egui/src/i18n/ka.tsv @@ -10623,6 +10623,8 @@ breakText Glyphs გლიფები Tangent Circle მხები წრე Tangent Circle Tool მხები წრის ხელსაწყო No tangent circle here აქ მხები წრე არ არის + Ask For Circle Radius წრის რადიუსის კითხვა + Auto-Update Default ნაგულისხმევის ავტომატური განახლება Circle: წრე: @msg `ids` names an object twice `ids` ერთსა და იმავე ობიექტს ორჯერ მიუთითებს @msg select two or three paths or compound paths მონიშნეთ ორი ან სამი ტრაექტორია ან შედგენილი ტრაექტორია diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index 57e0b8be10..483cb08228 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -8084,6 +8084,8 @@ breakText Glyphs 글리프 Tangent Circle 접원 Tangent Circle Tool 접원 도구 No tangent circle here 여기에는 접원이 없음 + Ask For Circle Radius 원 반지름 묻기 + Auto-Update Default 기본값 자동 업데이트 Circle: 원: @msg `ids` names an object twice `ids`에 같은 오브젝트가 두 번 있습니다 @msg select two or three paths or compound paths 패스나 컴파운드 패스를 두 개 또는 세 개 선택하세요 diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index 5ed5cdc3e0..b9147289a4 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -10343,6 +10343,8 @@ breakText Glyphs Glyphs Tangent Circle Raakcirkel Tangent Circle Tool Raakcirkel-gereedschap No tangent circle here Hier geen raakcirkel + Ask For Circle Radius Vragen naar cirkelradius + Auto-Update Default Standaard automatisch bijwerken Circle: Cirkel: @msg `ids` names an object twice `ids` noemt een object twee keer @msg select two or three paths or compound paths selecteer twee of drie paden of samengestelde paden diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index 74029133dc..8a59fca111 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -8308,6 +8308,8 @@ breakText Glyphs Glify Tangent Circle Okrąg styczny Tangent Circle Tool Narzędzie Okrąg styczny No tangent circle here Brak okręgu stycznego w tym miejscu + Ask For Circle Radius Pytaj o promień okręgu + Auto-Update Default Automatycznie aktualizuj wartość domyślną Circle: Okrąg: @msg `ids` names an object twice `ids` wskazuje ten sam obiekt dwa razy @msg select two or three paths or compound paths zaznacz dwie lub trzy ścieżki lub ścieżki złożone diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index a1747af0b2..447da1dfff 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -8468,6 +8468,8 @@ breakText Glyphs Glifos Tangent Circle Círculo tangente Tangent Circle Tool Ferramenta Círculo tangente No tangent circle here Nenhum círculo tangente aqui + Ask For Circle Radius Perguntar o Raio do Círculo + Auto-Update Default Atualizar o Padrão Automaticamente Circle: Círculo: @msg `ids` names an object twice `ids` indica um objeto duas vezes @msg select two or three paths or compound paths selecione dois ou três caminhos ou caminhos compostos diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index ca0c8d5145..b657fcc52f 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -8440,6 +8440,8 @@ breakText Glyphs Глифы Tangent Circle Касательная окружность Tangent Circle Tool Инструмент «Касательная окружность» No tangent circle here Здесь нет касательной окружности + Ask For Circle Radius Запрашивать радиус окружности + Auto-Update Default Автоматически обновлять значение по умолчанию Circle: Окружность: @msg `ids` names an object twice `ids` указывает объект дважды @msg select two or three paths or compound paths выделите два или три контура или составных контура diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index c26474cf93..2a152f819e 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -8484,6 +8484,8 @@ breakText Glyphs Glyfer Tangent Circle Tangentcirkel Tangent Circle Tool Tangentcirkelverktyget No tangent circle here Ingen tangentcirkel här + Ask For Circle Radius Fråga efter cirkelradie + Auto-Update Default Uppdatera standard automatiskt Circle: Cirkel: @msg `ids` names an object twice `ids` anger ett objekt två gånger @msg select two or three paths or compound paths markera två eller tre banor eller sammansatta banor diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index 82186ebcdd..b431a70dc1 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -10339,6 +10339,8 @@ breakText Glyphs Glifler Tangent Circle Teğet Daire Tangent Circle Tool Teğet Daire Aracı No tangent circle here Burada teğet daire yok + Ask For Circle Radius Daire Yarıçapını Sor + Auto-Update Default Varsayılanı Otomatik Güncelle Circle: Daire: @msg `ids` names an object twice `ids` bir nesneyi iki kez belirtiyor @msg select two or three paths or compound paths iki veya üç yol ya da bileşik yol seçin diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index de3329ef10..03c5daa27e 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -8094,6 +8094,8 @@ breakText Glyphs Гліфи Tangent Circle Дотичне коло Tangent Circle Tool Інструмент «Дотичне коло» No tangent circle here Тут немає дотичного кола + Ask For Circle Radius Запитувати радіус кола + Auto-Update Default Автоматично оновлювати значення за замовчуванням Circle: Коло: @msg `ids` names an object twice `ids` указує об’єкт двічі @msg select two or three paths or compound paths виділіть два або три контури чи складені контури diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index 675143a8d6..f7556a0633 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -8140,6 +8140,8 @@ breakText Glyphs Glyph Tangent Circle Đường tròn tiếp xúc Tangent Circle Tool Công cụ Đường tròn tiếp xúc No tangent circle here Không có đường tròn tiếp xúc ở đây + Ask For Circle Radius Hỏi bán kính đường tròn + Auto-Update Default Tự động cập nhật mặc định Circle: Đường tròn: @msg `ids` names an object twice `ids` nêu một đối tượng hai lần @msg select two or three paths or compound paths chọn hai hoặc ba đường dẫn hoặc đường dẫn phức hợp diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index 57f6a4403b..43e0258fad 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -8318,6 +8318,8 @@ breakText Glyphs 字形 Tangent Circle 相切圆 Tangent Circle Tool 相切圆工具 No tangent circle here 此处没有相切圆 + Ask For Circle Radius 询问圆半径 + Auto-Update Default 自动更新默认值 Circle: 圆: @msg `ids` names an object twice `ids` 重复指定了同一个对象 @msg select two or three paths or compound paths 请选择两个或三个路径或复合路径 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index 9834c17ea6..b69db647b4 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -8142,6 +8142,8 @@ breakText Glyphs 字符 Tangent Circle 相切圓 Tangent Circle Tool 相切圓工具 No tangent circle here 此處沒有相切圓 + Ask For Circle Radius 詢問圓半徑 + Auto-Update Default 自動更新預設值 Circle: 圓: @msg `ids` names an object twice `ids` 將同一個物件指定了兩次 @msg select two or three paths or compound paths 請選取兩個或三個路徑或複合路徑 diff --git a/docs/mcp.md b/docs/mcp.md index 5032690fc6..7823ccaa24 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -14566,8 +14566,19 @@ Tools: change to the first segment that makes no undo step (a live preview, or one that was canceled) forgets the first segment. The circle is looked for again whenever either segment no longer has the shape it was found on, so a canceled preview does not leave a circle worked out on the previewed paths. - Option (`tool.setOption`, or a double-click on the tool): `radius` (pt, 0.01 to 1000000, 36). `tool.setOption` - gives an error for a value outside that range or one that is not a number, and for any other option. + Options (`tool.setOption`, or a double-click on the tool): `radius` (pt, 0.01 to 1000000, 36), `askRadius` (Ask For + Circle Radius, true or false, false) and `autoUpdateDefault` (Auto-Update Default, true or false, false). + `tool.setOption` gives an error for a radius outside that range or one that is not a number, for a value of the other + two that is not true or false, and for any other option. With `askRadius` on, a click on the second segment that finds + a circle (with or without Shift) opens the Tangent Circle dialog (`tangentCircleRadius`) instead of drawing; a drag, + 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, and one outside 0.01 to 1000000 pt (or not a number, as `ui.dialog.set` can give) shows the radius error, except + the radius the dialog opened with; OK then gives that error and the dialog stays open. OK draws the circle in one undo + step, with `shape.circleThroughPoints`, and with `autoUpdateDefault` on also sets `radius` to the radius given when + it is in that range. Cancel draws nothing, leaves no undo step and + keeps the first segment picked. - **Trim at Crossings Tool** (`trimAtCrossings`): removes stretches of paths between the places where they are crossed, on any path that can be edited, selected or not. A click runs `addon.pathtools.trim` with `at`, for the path within 4 screen pixels of the pointer. A drag draws a rectangle and runs it with `rect` on release; once the pointer has diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index f8a3dc84a0..05e32366ce 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2997,6 +2997,8 @@ 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 shows the note 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` in `vectorcraft-tools` and `the_radius_dialog_previews_says_when_there_is_none_cancels_and_draws_on_ok` in `vectorcraft-ui-egui`. + ## Path Precision Tools add-on: Trim at Crossings (2026-11-13) A VectorCraft addition, not a feature of the reference app, so no area score moves. Object › Plug-ins › Path Precision Tools › Trim at Crossings Tool (also in the Scissors tool's group in both shipped toolbars, after the Knife, since 2026-11-16; a toolbar edited before keeps its saved layout until Reset Toolbar; no shortcut) removes stretches of paths between the places where they are crossed by another path or by themselves, on any path that can be edited, selected or not. A click removes the stretch under the pointer, a drag removes every stretch its rectangle touches, and an Alt-drag removes every stretch its freehand line crosses; each is one undo step, and Escape during a drag removes nothing. A closed path that loses a stretch becomes open, an open path that loses a middle stretch becomes two paths with its appearance in its place in the stacking order, a path that nothing crosses is removed whole, and the stretches that stay get no new anchors. Hidden and locked paths, guides and clipping paths are not trimmed and do not count as crossing. Add Points at / Split at Crossings share the crossing search: segments that meet at an anchor now count where they cross again elsewhere, and with Self Crossings a curved segment that loops over itself crosses itself. Command `addon.pathtools.trim`; `vectorcraft_pathops::addons::pathtools::{crossings_on, spans, without_spans}`. Hovering shows in red the stretch a click would remove, worked out by the same code the command uses (`vectorcraft_tools::addons::trim::plan`), and a drag that reaches at most 32 paths shows what its release would remove; a preview spends at most a twentieth of the crossing work a click may (2026-11-15; tests `hovering_*`, `in_isolation_mode_*`, `a_path_whose_crossings_*` and `a_small_drag_*` in `addons::trim` in `vectorcraft-tools`, `hovering_with_the_tool_shows_the_stretch_its_click_removes` and `what_the_tool_shows_*` in `vectorcraft-engine`). Not yet: crossings with type, images and symbol instances. Tests: `crossings_on_*`, `segments_*`, `a_segment_that_loops_over_itself_crosses_itself`, `one_work_budget_*`, `spans_divide_*`, `a_subpath_without_*` and `a_slice_*` in `addons::pathtools::tests` in `vectorcraft-pathops`, `addons::trim` in `vectorcraft-tools` (click, rectangle, freehand line, Escape), `cmd::addons::pathtools::trim::tests` in `vectorcraft-engine` (a middle and an end stretch, a closed path opening, a rectangle and a line as one undo step, locked and hidden paths, guides and clipping paths, paths nothing crosses, compound path members, the selection, 3,000 other paths, a path too large to search left alone until touched, bad params refused), `the_plugins_submenu_selects_the_tools_and_opens_the_anchor_inspector` in `vectorcraft-ui-egui`, `edit_toolbar::tests` and `command_sweep`. Commands: `docs/mcp.md` › Path Precision Tools add-on. The tool shows the Knife's cursor, now drawn as a knife with the blade's point on the hotspot (2026-11-16; tests `trim_at_crossings_is_in_the_scissors_flyout` and `a_saved_toolbar_without_trim_at_crossings_keeps_its_layout` in `edit_toolbar::tests`, `trim_at_crossings_is_in_the_scissors_group_once` in `addons::tests`, `headless_backend_methods` in `vectorcraft-mcp`, `the_knife_shows_a_knife_with_its_point_on_the_hotspot` in `cursors::tests` and `drawing_tools_show_their_own_cursor` in `vectorcraft-tools`). From 8bea29062f3a22261cffcc51e02c2b9c2fb869c4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 02:30:20 -0800 Subject: [PATCH 2/9] Tangent Circle Tool: a radius typed outside the tool's range shows the error The dialog's Radius field kept a typed radius inside 0.01 to 1000000 pt, so typing 0 drew a 0.01 pt circle and the radius error never showed. The field now keeps the radius as typed: one outside the range shows the error and leaves OK off. --- .../addons/pathtools/tangent_circle_radius.rs | 67 ++++++++++++++++++- docs/target-app-parity.md | 2 +- 2 files changed, 66 insertions(+), 3 deletions(-) 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 bc1b6d5992..7c953fbed2 100644 --- a/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs +++ b/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs @@ -84,9 +84,9 @@ fn circle(d: &mut Dialog) -> Result, String> { fn body(app: &mut VectorcraftApp, ui: &mut Ui, d: &mut Dialog) -> bool { let unit = app.session.general_unit(); - let (lo, hi) = tangent_circle::RADIUS_RANGE; + // The field keeps a radius as typed, so one outside the tool's range shows [`RADIUS_RANGE`]. widgets::label_row(ui, tl!("Radius:"), LABEL_W, |ui| { - form::length_within(ui, d, "radius", unit, FIELD_W, Some(lo..=hi)); + form::length_within(ui, d, "radius", unit, FIELD_W, None); }); let note = match circle(d) { Ok(Some(points)) => { @@ -158,6 +158,69 @@ mod tests { super::SPEC.ok_enabled.is_some_and(|f| f(app, app.ui.dialog.as_ref().unwrap())) } + /// Click the dialog's Radius field, select its text, type `text` over it and press Tab. + fn type_radius(app: &mut VectorcraftApp, text: &str) { + let ctx = egui::Context::default(); + ctx.enable_accesskit(); + crate::theme::install_fonts(&ctx); + let mut time = 0.0; + let mut run = |app: &mut VectorcraftApp, events: Vec| { + time += 0.1; + let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1280.0, 900.0)); + let input = egui::RawInput { events, time: Some(time), screen_rect: Some(screen), ..Default::default() }; + let mut out = ctx.run_ui(input, |ui| crate::dialogs::show(app, ui.ctx())); + out.textures_delta.clear(); + out + }; + run(app, vec![]); + let out = run(app, vec![]); + let nodes = &out.platform_output.accesskit_update.as_ref().expect("an accessibility tree").nodes; + // The Radius field is the dialog's only text field. + let fields: Vec<_> = nodes.iter().filter(|(_, n)| n.role() == egui::accesskit::Role::TextInput).filter_map(|(_, n)| n.bounds()).collect(); + let [b] = fields[..] else { panic!("one text field, not {fields:?}") }; + let at = egui::pos2((b.x0 + b.x1) as f32 * 0.5, (b.y0 + b.y1) as f32 * 0.5); + for pressed in [true, false] { + let button = egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }; + run(app, vec![egui::Event::PointerMoved(at), button]); + } + let all = egui::Modifiers { ctrl: true, command: true, ..Default::default() }; + let select_all = egui::Event::Key { key: egui::Key::A, physical_key: None, pressed: true, repeat: false, modifiers: all }; + run(app, vec![select_all, egui::Event::Text(text.into())]); + for pressed in [true, false] { + run(app, vec![egui::Event::Key { key: egui::Key::Tab, physical_key: None, pressed, repeat: false, modifiers: Default::default() }]); + } + run(app, vec![]); + } + + #[test] + fn a_radius_typed_outside_the_tool_range_shows_the_error_and_leaves_ok_off() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 500, "height": 500})).unwrap(); + for y in [100, 140] { + app.run("path.create", json!({"anchors": [{"x": 100, "y": y}, {"x": 300, "y": y}]})).unwrap(); + } + app.session.select_tool(tool::ID, ViewInfo::default()).unwrap(); + app.run("tool.setOption", json!({"tool": tool::ID, "key": "askRadius", "value": true})).unwrap(); + let paths = count(&app); + click(&mut app, 150.0, 100.0, false); + click(&mut app, 200.0, 140.0, false); + frame(&mut app); + assert!(ok_enabled(&app)); + // A radius typed in the field is kept as typed, not moved into the tool's range. + for (typed, kept) in [("0", 0.0), ("-20", -20.0), ("2000000", 2e6)] { + type_radius(&mut app, typed); + assert_eq!(app.ui.dialog.as_ref().unwrap().f64("radius", f64::NAN), kept, "{typed}"); + assert!(frame(&mut app).contains(super::RADIUS_RANGE), "{typed}"); + assert!(!ok_enabled(&app), "{typed}"); + assert_eq!(count(&app), paths, "{typed}"); + } + // Typing the click's radius again previews its circle and turns OK on. + type_radius(&mut app, "20"); + frame(&mut app); + assert!(ok_enabled(&app)); + assert_eq!(count(&app), paths + 1); + } + #[test] fn the_radius_dialog_previews_says_when_there_is_none_cancels_and_draws_on_ok() { let mut app = VectorcraftApp::new(Session::new(), Default::default()); diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 05e32366ce..007d573a48 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2997,7 +2997,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 shows the note 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` in `vectorcraft-tools` and `the_radius_dialog_previews_says_when_there_is_none_cancels_and_draws_on_ok` 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 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` in `vectorcraft-tools` and `the_radius_dialog_previews_says_when_there_is_none_cancels_and_draws_on_ok` and `a_radius_typed_outside_the_tool_range_shows_the_error_and_leaves_ok_off` in `vectorcraft-ui-egui`. ## Path Precision Tools add-on: Trim at Crossings (2026-11-13) From 9bb2e0dbfe8b90171ae2c27af6167014fe8e9f0a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 03:13:54 -0800 Subject: [PATCH 3/9] Tangent Circle Tool: the radius dialog draws nothing after its segments change The dialog kept the segments it was opened on, so a control request that edited either path, or a switch to another document with the same paths, left it previewing and drawing a circle that no longer touched them. It now records the segments' places and the document, and shows the note with OK off when either segment differs or another document is active. --- crates/tools/src/addons/tangent_circle.rs | 100 +++++++++++++++--- .../addons/pathtools/tangent_circle_radius.rs | 76 +++++++++++-- docs/mcp.md | 5 +- docs/target-app-parity.md | 2 +- 4 files changed, 155 insertions(+), 28 deletions(-) diff --git a/crates/tools/src/addons/tangent_circle.rs b/crates/tools/src/addons/tangent_circle.rs index 5ccc3815de..e57740e5a7 100644 --- a/crates/tools/src/addons/tangent_circle.rs +++ b/crates/tools/src/addons/tangent_circle.rs @@ -18,11 +18,12 @@ //! segment's shape differs from the one they were found on. With the `askRadius` option on, a click //! on the second segment (not a drag, which sets the radius itself) opens the [`RADIUS_DIALOG`] //! instead of drawing: it starts at the radius of the circle found and draws the circle of the radius -//! typed ([`radius_circle`]); the first segment stays picked until it does. +//! typed ([`radius_circle`]); the first segment stays picked until it does. While the dialog is open, +//! an edit to either segment leaves it without a circle ([`segments_unchanged`]). use kurbo::{CubicBez, Shape}; use serde_json::{Value, json}; -use vectorcraft_doc::NodeId; +use vectorcraft_doc::{Document, NodeId}; use vectorcraft_geom::{BezPath, ParamCurve, Point}; use vectorcraft_pathops::addons::pathtools::{SegmentCircle, circles_of_radius, circles_through}; @@ -128,10 +129,24 @@ fn pick_at(cx: &ToolContext, p: Point) -> Option { Some(Pick { id, subpath, segment, t, p: curve.eval(t), curve }) } +/// A segment's place in the document: its path, subpath and index. +type Place = (NodeId, usize, usize); + +impl Pick { + fn place(&self) -> Place { + (self.id, self.subpath, self.segment) + } +} + /// The document's segment at `pick` as it is now: none when its path, subpath or segment is gone. fn segment_now(cx: &ToolContext, pick: &Pick) -> Option { - let sp = cx.doc.node(pick.id)?.path_data()?.subpaths.get(pick.subpath)?; - (pick.segment < sp.segment_count()).then(|| sp.segment(pick.segment)) + segment_at(cx.doc, pick.place()) +} + +/// The segment of `doc` at `place`: none when its path, subpath or segment is gone. +fn segment_at(doc: &Document, (id, subpath, segment): Place) -> Option { + let sp = doc.node(id)?.path_data()?.subpaths.get(subpath)?; + (segment < sp.segment_count()).then(|| sp.segment(segment)) } /// Whether the document's segment at `pick` still has the shape it had when it was picked. @@ -142,12 +157,17 @@ fn unchanged(cx: &ToolContext, pick: &Pick) -> bool { /// The segments a circle may touch when `second` is picked: it and the segments on either side of /// it, without `first`. None when `second` is the first segment again. fn second_set(cx: &ToolContext, first: &Pick, second: &Pick) -> Vec { - if (first.id, first.subpath, first.segment) == (second.id, second.subpath, second.segment) { + second_set_at(cx.doc, first.place(), second.place()) +} + +/// [`second_set`] for the segments of `doc` at `first` and `second`. +fn second_set_at(doc: &Document, first: Place, second: Place) -> Vec { + if first == second { return vec![]; } - let Some(sp) = cx.doc.node(second.id).and_then(|n| n.path_data()).and_then(|p| p.subpaths.get(second.subpath)) else { return 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![] }; let n = sp.segment_count(); - let i = second.segment; let mut indices = vec![i]; if i > 0 || sp.closed { indices.push((i + n - 1) % n); @@ -157,7 +177,7 @@ fn second_set(cx: &ToolContext, first: &Pick, second: &Pick) -> Vec { } indices.sort_unstable(); indices.dedup(); - let is_first = |k: usize| first.id == second.id && first.subpath == second.subpath && first.segment == k; + let is_first = |k: usize| first == (id, subpath, k); indices.into_iter().filter(|k| *k < n && !is_first(*k)).map(|k| sp.segment(k)).collect() } @@ -239,13 +259,26 @@ fn curve_of(v: &Value) -> Option { Some(CubicBez::new(point_of(a)?, point_of(b)?, point_of(c)?, point_of(d)?)) } -/// The [`RADIUS_DIALOG`]'s parameters for circle `c`, found by a click at `at` on `first` and the -/// segments `second`, which `points` (from [`draw`]) draws: the segments, the click, the circle's -/// radius and points, and the tolerance [`draw`] checked them with. -fn dialog_params(first: &CubicBez, second: &[CubicBez], at: Point, c: &SegmentCircle, points: &Value, tol: f64) -> Value { +fn place_json((id, subpath, segment): Place) -> Value { + json!([id.0, subpath, segment]) +} + +/// A place written by [`place_json`]. +fn place_of(v: &Value) -> Option { + let [id, subpath, segment] = v.as_array()?.as_slice() else { return None }; + let index = |v: &Value| v.as_u64().and_then(|i| usize::try_from(i).ok()); + Some((NodeId(id.as_u64()?), index(subpath)?, index(segment)?)) +} + +/// The [`RADIUS_DIALOG`]'s parameters for circle `c`, found by a click at `at` on `first` and on +/// `picked`, whose segments a circle may touch are `second`, which `points` (from [`draw`]) draws: +/// the segments and their places, the click, the circle's radius and points, and the tolerance +/// [`draw`] checked them with. +fn dialog_params(first: &Pick, picked: &Pick, second: &[CubicBez], at: Point, c: &SegmentCircle, points: &Value, tol: f64) -> Value { json!({ - "first": curve_json(first), + "first": curve_json(&first.curve), "second": second.iter().map(curve_json).collect::>(), + "places": [place_json(first.place()), place_json(picked.place())], "at": point_json(at), "radius": c.circle.radius, "points": points, @@ -253,6 +286,19 @@ fn dialog_params(first: &CubicBez, second: &[CubicBez], at: Point, c: &SegmentCi }) } +/// Whether the segments the [`RADIUS_DIALOG`] opened with parameters `p` holds are still those of +/// `doc`: false when a path was edited or removed since the click, in another document, or for +/// parameters the tool did not write. +pub fn segments_unchanged(doc: &Document, p: &Value) -> bool { + let check = || -> Option { + let [first, second] = p.get("places")?.as_array()?.as_slice() else { return None }; + let (first, second) = (place_of(first)?, place_of(second)?); + let second_then: Vec = p.get("second")?.as_array()?.iter().map(curve_of).collect::>()?; + Some(segment_at(doc, first)? == curve_of(p.get("first")?)? && second_then == second_set_at(doc, first, second)) + }; + check() == Some(true) +} + /// The `shape.circleThroughPoints` parameters that draw the circle of `radius` the [`RADIUS_DIALOG`] /// opened with parameters `p` gives: at the radius the click found, the circle found; at any other, /// the circle of `radius` touching the second segments nearest the click, anywhere along the first @@ -432,7 +478,7 @@ impl Tool for TangentCircleTool { && press.radius.is_none() && let (Some(first), Action::Exec(_, drawn)) = (&self.first, &action) { - let params = dialog_params(&first.curve, &press.second, press.at, &c, &drawn["points"], tol); + let params = dialog_params(first, &press.pick, &press.second, press.at, &c, &drawn["points"], tol); return vec![Action::Dialog(RADIUS_DIALOG.into(), params)]; } vec![action, Action::Notify(DRAWN.into())] @@ -702,6 +748,32 @@ mod tests { assert!(t.first.is_some()); } + #[test] + fn the_radius_dialog_knows_when_its_segments_changed() { + let d = doc(); + let (sel, p) = (Selection::default(), paint()); + let cx = cx(&d, &sel, &p); + let mut t = TangentCircleTool::default(); + t.set_option("askRadius", &json!(true)); + t.pointer(&cx, &ev(PointerKind::Down, 150.0, 101.0)); + t.pointer(&cx, &ev(PointerKind::Up, 150.0, 101.0)); + t.pointer(&cx, &ev(PointerKind::Down, 200.0, 139.0)); + let p = asked(&up(&mut t, &cx, &ev(PointerKind::Up, 200.0, 139.0))); + assert!(segments_unchanged(&d, &p)); + assert!(segments_unchanged(&doc_at(100.0, 140.0), &p), "the same paths"); + // Either line moved, or another document: changed. + for (a, b) in [(100.0, 150.0), (110.0, 140.0)] { + assert!(!segments_unchanged(&doc_at(a, b), &p), "{a} {b}"); + } + assert!(!segments_unchanged(&Document::new(500.0, 500.0), &p)); + // Parameters the tool did not write. + for key in ["places", "first", "second"] { + let mut q = p.clone(); + q[key] = json!("x"); + assert!(!segments_unchanged(&d, &q), "{key}"); + } + } + #[test] fn two_clicks_draw_the_circle_tangent_at_the_first_click() { let d = doc(); 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 7c953fbed2..f64042bc3c 100644 --- a/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs +++ b/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs @@ -2,12 +2,13 @@ //! tool's Ask For Circle Radius option is on. It starts at the radius of the circle the click found, //! and each radius previews on the canvas the circle of that radius touching the two segments //! nearest the click ([`tangent_circle::radius_circle`]). A radius that gives no circle there shows -//! the tool's note and leaves OK off. OK draws the circle with `shape.circleThroughPoints` in one -//! undo step, and with Auto-Update Default on also sets the tool's `radius` to the one given; Cancel -//! draws nothing. +//! the tool's note and leaves OK off, as does an edit to either segment after the click. OK draws +//! the circle with `shape.circleThroughPoints` in one undo step, and with Auto-Update Default on +//! also sets the tool's `radius` to the one given; Cancel draws nothing. use egui::Ui; use serde_json::{Value, json}; +use vectorcraft_doc::Document; use vectorcraft_tools::addons::tangent_circle; use crate::VectorcraftApp; @@ -28,13 +29,16 @@ const CLICK: &str = "__click"; /// none) (private fields). const TRIED: &str = "__tried"; const CIRCLE: &str = "__circle"; +/// The id of the document the click was in (`DocState::uid`; a private field). +const DOC: &str = "__doc"; /// The error for a radius outside the tool's range. const RADIUS_RANGE: &str = "`radius` must be from 0.01 to 1000000 pt"; /// Open the dialog on what the tool found (its [`tangent_circle::RADIUS_DIALOG`] parameters). pub(crate) fn open(app: &mut VectorcraftApp, p: &Value) { let radius = p.get("radius").cloned().unwrap_or(json!(tangent_circle::RADIUS)); - app.ui.dialog = Some(Dialog::new(KIND, json!({ "radius": radius, "preview": true, CLICK: p }))); + let doc = app.session.doc().ok().map(|s| s.uid); + app.ui.dialog = Some(Dialog::new(KIND, json!({ "radius": radius, "preview": true, CLICK: p, DOC: doc }))); } pub(crate) const SPEC: DialogSpec = DialogSpec { @@ -42,11 +46,18 @@ pub(crate) const SPEC: DialogSpec = DialogSpec { body, confirm, preview: true, - ok_enabled: Some(|_, d| circle_of(d).is_some_and(|c| c.is_ok_and(|c| c.is_some()))), + ok_enabled: Some(|app, d| circle_of(doc(app, d), d).is_some_and(|c| c.is_ok_and(|c| c.is_some()))), min_width: 280.0, ..DialogSpec::FORM }; +/// The document the click was in, while it is the active one. A preview adds the circle to it and +/// leaves the two segments as they are. +fn doc<'a>(app: &'a VectorcraftApp, d: &Dialog) -> Option<&'a Document> { + let clicked = d.fields.get(DOC).and_then(Value::as_u64)?; + app.session.doc().ok().filter(|s| s.uid == clicked).map(|s| &*s.doc) +} + /// Whether `r` is in the tool's radius range. fn in_range(r: f64) -> bool { let (lo, hi) = tangent_circle::RADIUS_RANGE; @@ -61,18 +72,23 @@ fn radius(d: &Dialog) -> Result { } /// The circle last looked for, when it was looked for at the radius the dialog holds: its [`DRAW`] -/// parameters, or none. -fn circle_of(d: &Dialog) -> Option, String>> { +/// parameters, or none. None too without the document clicked in (`doc`), or when either segment in +/// it is no longer the one clicked (a control request edited or removed its path). +fn circle_of(doc: Option<&Document>, d: &Dialog) -> Option, String>> { let r = match radius(d) { Ok(r) => r, Err(e) => return Some(Err(e)), }; + let click = d.fields.get(CLICK).unwrap_or(&Value::Null); + if !doc.is_some_and(|doc| tangent_circle::segments_unchanged(doc, click)) { + return Some(Ok(None)); + } (d.fields.get(TRIED).and_then(Value::as_f64) == Some(r)).then(|| Ok(d.fields.get(CIRCLE).filter(|c| !c.is_null()).cloned())) } /// The circle at the radius the dialog holds, looked for again only when the radius changed. -fn circle(d: &mut Dialog) -> Result, String> { - if let Some(found) = circle_of(d) { +fn circle(doc: Option<&Document>, d: &mut Dialog) -> Result, String> { + if let Some(found) = circle_of(doc, d) { return found; } let r = radius(d)?; @@ -88,7 +104,7 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui, d: &mut Dialog) -> bool { widgets::label_row(ui, tl!("Radius:"), LABEL_W, |ui| { form::length_within(ui, d, "radius", unit, FIELD_W, None); }); - let note = match circle(d) { + let note = match circle(doc(app, d), d) { Ok(Some(points)) => { form::preview_without_check(app, d, "Tangent Circle", DRAW, points); return false; @@ -107,7 +123,7 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui, d: &mut Dialog) -> bool { fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { let mut d = d.clone(); let r = radius(&d)?; - let points = circle(&mut d)?.ok_or_else(|| tangent_circle::NO_CIRCLE.to_string())?; + let points = circle(doc(app, &d), &mut d)?.ok_or_else(|| tangent_circle::NO_CIRCLE.to_string())?; let auto = app.session.tool_options_of(tangent_circle::ID).get("autoUpdateDefault").and_then(Value::as_bool) == Some(true); form::commit_preview(app, DRAW, points)?; if auto && in_range(r) { @@ -221,6 +237,44 @@ mod tests { assert_eq!(count(&app), paths + 1); } + #[test] + fn another_document_or_a_segment_changed_after_the_click_gives_no_circle() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 500, "height": 500})).unwrap(); + for y in [100, 140] { + app.run("path.create", json!({"anchors": [{"x": 100, "y": y}, {"x": 300, "y": y}]})).unwrap(); + } + app.session.select_tool(tool::ID, ViewInfo::default()).unwrap(); + app.run("tool.setOption", json!({"tool": tool::ID, "key": "askRadius", "value": true})).unwrap(); + let paths = count(&app); + click(&mut app, 150.0, 100.0, false); + click(&mut app, 200.0, 140.0, false); + frame(&mut app); + assert!(ok_enabled(&app)); + assert_eq!(count(&app), paths + 1); + // Clicked in another document than the active one: no circle and OK off, until that one is + // active again. + let clicked = app.ui.dialog.as_ref().unwrap().fields[super::DOC].clone(); + assert_eq!(clicked, json!(app.session.doc().unwrap().uid)); + app.ui.dialog.as_mut().unwrap().fields.insert(super::DOC.into(), json!(clicked.as_u64().unwrap() + 1)); + assert!(frame(&mut app).contains(tool::NO_CIRCLE)); + assert_eq!(count(&app), paths); + assert!(!ok_enabled(&app)); + app.ui.dialog.as_mut().unwrap().fields.insert(super::DOC.into(), clicked); + frame(&mut app); + assert!(ok_enabled(&app)); + assert_eq!(count(&app), paths + 1); + // The dialog holds a first segment the document no longer has (as when a control request + // moves that line): no circle, nothing previewed, OK off and refused. + let d = app.ui.dialog.as_mut().unwrap(); + d.fields.get_mut(super::CLICK).unwrap()["first"] = json!([[100.0, 110.0], [100.0, 110.0], [300.0, 110.0], [300.0, 110.0]]); + assert!(frame(&mut app).contains(tool::NO_CIRCLE)); + assert_eq!(count(&app), paths); + assert!(!ok_enabled(&app)); + assert_eq!(crate::dialogs::confirm(&mut app), Err(tool::NO_CIRCLE.to_string())); + assert_eq!(count(&app), paths); + } + #[test] fn the_radius_dialog_previews_says_when_there_is_none_cancels_and_draws_on_ok() { let mut app = VectorcraftApp::new(Session::new(), Default::default()); diff --git a/docs/mcp.md b/docs/mcp.md index 7823ccaa24..2dd4e1087c 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -14574,8 +14574,9 @@ 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, and one outside 0.01 to 1000000 pt (or not a number, as `ui.dialog.set` can give) shows the radius error, except - the radius the dialog opened with; OK then gives that error and the dialog stays open. OK draws the circle in one undo + off, as do an edit to either segment's path after the click and another active document; one outside 0.01 to + 1000000 pt, typed or set (or not a number, as `ui.dialog.set` can give), shows the radius error, except the radius the + dialog opened with; OK then gives that error and the dialog stays open. OK draws the circle in one undo step, with `shape.circleThroughPoints`, and with `autoUpdateDefault` on also sets `radius` to the radius given when it is in that range. Cancel draws nothing, leaves no undo step and keeps the first segment picked. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 007d573a48..e1469ce595 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2997,7 +2997,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 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` in `vectorcraft-tools` and `the_radius_dialog_previews_says_when_there_is_none_cancels_and_draws_on_ok` and `a_radius_typed_outside_the_tool_range_shows_the_error_and_leaves_ok_off` 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 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`, `a_radius_typed_outside_the_tool_range_shows_the_error_and_leaves_ok_off` and `another_document_or_a_segment_changed_after_the_click_gives_no_circle` in `vectorcraft-ui-egui`. ## Path Precision Tools add-on: Trim at Crossings (2026-11-13) From 7b580467d721cafa943777ed6cebb9c47c35a0cc Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 17:17:27 -0800 Subject: [PATCH 4/9] Tangent Circle Tool: the radius dialog keeps OK off on a locked or hidden layer A target layer locked or hidden while the radius dialog is open now shows why in the dialog and leaves OK off, instead of offering a draw that fails. A second segment's subpath edited down to no segments gives no circle instead of panicking. --- crates/tools/src/addons/tangent_circle.rs | 9 +++++ .../addons/pathtools/tangent_circle_radius.rs | 35 ++++++++++++++++++- docs/mcp.md | 3 +- docs/target-app-parity.md | 2 +- 4 files changed, 46 insertions(+), 3 deletions(-) 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) From d4acadfce9991e7bbec04db90007cb35e47aab9c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 17:39:26 -0800 Subject: [PATCH 5/9] Tangent Circle Tool: the radius dialog leaves another document's interaction alone After a switch to another document, the radius dialog forgets its preview instead of rolling back, since the switch already rolled it back in the document clicked in. Rolling back would cancel an interaction of the document now active. --- .../addons/pathtools/tangent_circle_radius.rs | 54 ++++++++++++++++--- docs/target-app-parity.md | 2 +- 2 files changed, 49 insertions(+), 7 deletions(-) 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 a0be51829f..f96ada64eb 100644 --- a/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs +++ b/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs @@ -38,6 +38,8 @@ pub(crate) struct Open { /// under its rows with OK off; `None` while there is one. note: Option, preview: LivePreview, + /// The document that was active when the preview last ran (`DocState::uid`). + shown_in: Option, } /// Open the dialog on what the tool found (its [`tangent_circle::RADIUS_DIALOG`] parameters). @@ -49,8 +51,8 @@ pub(crate) fn open(app: &mut VectorcraftApp, p: &Value) { return; }; // An open the host replaces leaves its preview behind unless it is rolled back here. - if let Some(old) = app.addon_dialogs.tangent_radius.take() { - old.preview.cancel(app); + if let Some(mut old) = app.addon_dialogs.tangent_radius.take() { + take_preview(app, &mut old).cancel(app); } let lengths = general_lengths(app); let fields = DialogFields::from_pairs([("radius", FieldValue::Number(radius))]); @@ -60,13 +62,14 @@ pub(crate) fn open(app: &mut VectorcraftApp, p: &Value) { ParamDialog::new(KIND, tl!("Tangent Circle"), rows).values(Bind::bound(fields)).previews(true) }); let cancel: Box = Box::new(|app| { - if let Some(open) = app.addon_dialogs.tangent_radius.take() { - open.preview.cancel(app); + if let Some(mut open) = app.addon_dialogs.tangent_radius.take() { + take_preview(app, &mut open).cancel(app); } }); match open_held_with(app, dialog, ok, HeldOptions { parent: None, cancel: Some(cancel) }) { Some(id) => { - app.addon_dialogs.tangent_radius = Some(Open { id, click: p.clone(), doc, tried: None, note: None, preview: LivePreview::default() }); + app.addon_dialogs.tangent_radius = + Some(Open { id, click: p.clone(), doc, tried: None, note: None, preview: LivePreview::default(), shown_in: doc }); } None => app.status("no window"), } @@ -79,6 +82,19 @@ fn doc<'a>(app: &'a VectorcraftApp, open: &Open) -> Option<&'a Document> { app.session.doc().ok().filter(|s| s.uid == clicked).map(|s| &*s.doc) } +/// The id of the active document (`DocState::uid`). +fn active_uid(app: &VectorcraftApp) -> Option { + app.session.doc().ok().map(|s| s.uid) +} + +/// The dialog's live preview, taken out of `open`. With another document active than the one it previewed in, the +/// preview is forgotten instead: the switch already rolled it back there, and rolling back here would cancel an +/// interaction of the document now active. +fn take_preview(app: &VectorcraftApp, open: &mut Open) -> LivePreview { + let preview = std::mem::take(&mut open.preview); + if open.shown_in == active_uid(app) { preview } else { LivePreview::default() } +} + /// Whether `r` is in the tool's radius range. fn in_range(r: f64) -> bool { let (lo, hi) = tangent_circle::RADIUS_RANGE; @@ -137,7 +153,7 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &egui::Context) { app.addon_dialogs.tangent_radius = Some(open); return; }; - let mut preview = std::mem::take(&mut open.preview); + let mut preview = take_preview(app, &mut open); let found = circle(app, &mut open, &fields); // Without a circle the preview rolls back; the preview reports its own failures on the status line. let previewed = match &found { @@ -146,6 +162,7 @@ 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.shown_in = active_uid(app); // 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)); @@ -370,6 +387,31 @@ mod tests { assert_eq!(app.session.tool_options_of(tool::ID)["radius"], json!(tool::RADIUS)); } + #[test] + fn a_switch_to_another_document_leaves_its_interaction_alone() { + 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!(count(&app), paths + 1); + // Another document comes to the front (which rolls the preview back in the first) and starts an interaction + // of its own before the dialog's next frame: the dialog leaves that interaction running. + app.run("file.new", json!({"width": 300, "height": 300})).unwrap(); + app.begin_interaction("Other").unwrap(); + app.session.preview("path.create", &json!({"anchors": [{"x": 10, "y": 10}, {"x": 50, "y": 10}]})).unwrap(); + frame(&mut app); + assert_eq!(note(&app).as_deref(), Some(tool::NO_CIRCLE)); + assert!(app.session.in_interaction()); + assert_eq!(count(&app), 1); + // Cancel leaves it running too. + cancel(&app, dialog_id(&app)); + frame(&mut app); + assert!(!is_open(&app)); + assert!(app.session.in_interaction()); + assert_eq!(count(&app), 1); + } + #[test] fn a_circle_the_target_layer_cannot_take_shows_why_and_leaves_ok_off() { let mut app = app_with_lines(&[100, 140]); diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 9ad4f4f030..28033fbc9b 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 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`. +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`. ## Path Precision Tools add-on: Trim at Crossings (2026-11-13) From e70619bc4a527420db46050b6fad3b04e75cb124 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 18:31:12 -0800 Subject: [PATCH 6/9] 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. --- .../addons/pathtools/tangent_circle_radius.rs | 47 ++++++++++++++++++- docs/target-app-parity.md | 2 +- 2 files changed, 46 insertions(+), 3 deletions(-) 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 f96ada64eb..50032e300d 100644 --- a/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs +++ b/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs @@ -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::(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::>()); + 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]); diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 28033fbc9b..a5dd8d1db7 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 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) From 45b671a22b8857a33318ea4612f9ff5ef43ccaf0 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 22:13:31 -0800 Subject: [PATCH 7/9] Tangent Circle Tool: the radius dialog keeps its preview after a failed OK OK hands the dialog's live preview a copy to commit, so a draw that is refused leaves the dialog owning the interaction it started, and Cancel or a radius with no circle still ends it. New test: a_failed_ok_keeps_the_preview_for_cancel. docs/target-app-parity.md and the module doc now say that Auto-Update Default sets the tool's Shift radius only for a radius from 0.01 to 1,000,000 pt. --- .../addons/pathtools/tangent_circle_radius.rs | 39 +++++++++++++++++-- docs/target-app-parity.md | 2 +- 2 files changed, 37 insertions(+), 4 deletions(-) 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 50032e300d..e77ea59286 100644 --- a/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs +++ b/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs @@ -4,7 +4,7 @@ //! nearest the click ([`tangent_circle::radius_circle`]). A radius that gives no circle there shows //! the tool's note and leaves OK off, as does an edit to either segment after the click. OK draws //! the circle with `shape.circleThroughPoints` in one undo step, and with Auto-Update Default on -//! also sets the tool's `radius` to the one given; Cancel draws nothing. +//! also sets the tool's `radius` to the one given when it is in the tool's range; Cancel draws nothing. use craft::ui::contract::Bind; use craft::ui::dialog::DialogId; @@ -202,8 +202,8 @@ fn ok(app: &mut VectorcraftApp, result: &ParamResult) -> Result<(), String> { } }; let auto = app.session.tool_options_of(tangent_circle::ID).get("autoUpdateDefault").and_then(Value::as_bool) == Some(true); - let preview = std::mem::take(&mut open.preview); - if let Err(e) = preview.commit(app, DRAW, points) { + // A failed commit leaves the interaction running: the dialog keeps its preview, so Cancel still ends it. + if let Err(e) = open.preview.clone().commit(app, DRAW, points) { app.addon_dialogs.tangent_radius = Some(open); return Err(e); } @@ -382,6 +382,39 @@ mod tests { assert_eq!(count(&app), paths); } + #[test] + fn a_failed_ok_keeps_the_preview_for_cancel() { + let mut app = app_with_lines(&[100, 140]); + let (paths, steps) = (count(&app), undo_steps(&app)); + 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 layer the preview started from is locked before OK, so OK's draw is refused and the dialog stays open. + { + let st = app.session.doc_mut().unwrap(); + let layer = st.doc.layers[0].id; + let it = st.interaction.as_mut().unwrap(); + std::sync::Arc::make_mut(&mut it.doc).node_mut(layer).unwrap().locked = true; + } + let id = dialog_id(&app); + assert!(confirm(&app, id), "OK is on"); + frame(&mut app); + assert!(is_open(&app)); + assert!(app.session.in_interaction()); + // The dialog still owns the interaction: a radius with no circle there ends it. + set(&app, id, "radius", json!(25)); + frame(&mut app); + assert_eq!(note(&app).as_deref(), Some(tool::NO_CIRCLE)); + assert!(!app.session.in_interaction()); + // Cancel closes it with nothing drawn and no undo step. + cancel(&app, id); + frame(&mut app); + assert!(!is_open(&app)); + assert!(!app.session.in_interaction()); + assert_eq!((count(&app), undo_steps(&app)), (paths, steps)); + } + #[test] fn a_click_found_radius_outside_the_tool_range_can_be_drawn() { // Lines 2,400,000 pt apart: a click on each finds the circle of radius 1,200,000, past the diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 49f56abbf7..8953bf2a73 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -3078,7 +3078,7 @@ A VectorCraft addition, so no area score moves. The Tangent Circle Tool (`tangen The tool's options dialog also sets the preview and how a segment is picked, the options the help page lists (https://docs.astutegraphics.com/subscribe/tangent-circle-tool): Circle Center and Circle Radii Lines (`center`, `radii`) show or hide the center cross and the radii, Color (`color`: red, blue, magenta, green, black or gray) colors the circle, the cross, the radii and the note, Snap Tolerance (`snapTolerance`, screen pixels) is how near the pointer picks a segment with Smart Guides on, the Smart Guides Snapping Tolerance counting when it is larger, and Snap When Smart Guides Are Off (`snapWithoutGuides`) keeps that reach with Smart Guides off; without it the Selection Tolerance applies. Of the segments within reach the nearest is picked. The defaults (both shown, red, 3 px, snapping on) and the 0 to 25 px range are VectorCraft's own; they are kept with the preferences, and `tool.setOption` gives an error for a value an option does not take. Tests: `addons::tangent_circle::tests` in `vectorcraft-tools` (the preview options, the snapping reach, the options' values) and `the_tangent_circle_options_set_the_preview_and_snapping` 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`. +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 when it is from 0.01 to 1,000,000 pt. 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_failed_ok_keeps_the_preview_for_cancel`, `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) From 2978eb831a6d72ba765c654f2c8a8e872272496f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 00:47:35 -0800 Subject: [PATCH 8/9] Tangent Circle Tool: test Cancel straight after a refused OK --- .../addons/pathtools/tangent_circle_radius.rs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) 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 e77ea59286..7a58e65095 100644 --- a/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs +++ b/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs @@ -415,6 +415,33 @@ mod tests { assert_eq!((count(&app), undo_steps(&app)), (paths, steps)); } + #[test] + fn cancel_right_after_a_failed_ok_rolls_the_preview_back() { + let mut app = app_with_lines(&[100, 140]); + let (paths, steps) = (count(&app), undo_steps(&app)); + 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); + { + let st = app.session.doc_mut().unwrap(); + let layer = st.doc.layers[0].id; + let it = st.interaction.as_mut().unwrap(); + std::sync::Arc::make_mut(&mut it.doc).node_mut(layer).unwrap().locked = true; + } + let id = dialog_id(&app); + assert!(confirm(&app, id), "OK is on"); + frame(&mut app); + assert!(is_open(&app)); + assert!(app.session.in_interaction()); + // Cancel is the next press after the refused OK, with no radius change or other frame in between. + cancel(&app, id); + frame(&mut app); + assert!(!is_open(&app)); + assert!(!app.session.in_interaction()); + assert_eq!((count(&app), undo_steps(&app)), (paths, steps)); + } + #[test] fn a_click_found_radius_outside_the_tool_range_can_be_drawn() { // Lines 2,400,000 pt apart: a click on each finds the circle of radius 1,200,000, past the From f0b6f5208aece024d9d0d762828fdbff841923bb Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 27 Nov 2026 22:35:31 -0800 Subject: [PATCH 9/9] Tangent Circle Tool: a second click opens the radius dialog as a new held dialog The dialog host now ties each held record to one opening of a dialog, and drops a record whose dialog was opened again under the same id. Reopening the radius dialog straight through the host left the new opening with no record, so its Cancel never cleared the open dialog (a_second_click_replaces_the_open_dialog failed). The dialog now opens the replacement with open_held_with, which gives it its own OK and cancel hook. --- .../src/addons/pathtools/tangent_circle_radius.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) 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 7a58e65095..92ad231a96 100644 --- a/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs +++ b/crates/ui-egui/src/addons/pathtools/tangent_circle_radius.rs @@ -51,16 +51,13 @@ pub(crate) fn open(app: &mut VectorcraftApp, p: &Value) { return; }; // 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; + // dialog has the same id (the dialog's kind), and its own held answer and cancel hook replace the earlier ones. 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::(old.id); }); - held = Some(host); } take_preview(app, &mut old).cancel(app); } @@ -76,11 +73,7 @@ pub(crate) fn open(app: &mut VectorcraftApp, p: &Value) { take_preview(app, &mut open).cancel(app); } }); - 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 { + match open_held_with(app, dialog, ok, HeldOptions { parent: None, cancel: Some(cancel) }) { Some(id) => { app.addon_dialogs.tangent_radius = Some(Open { id, click: p.clone(), doc, tried: None, note: None, preview: LivePreview::default(), shown_in: doc });