From eeb686f1648112f29da93cc6fe706298e697adfd Mon Sep 17 00:00:00 2001 From: Frank <58932224+plexi32@users.noreply.github.com> Date: Wed, 4 Nov 2026 07:38:21 +0000 Subject: [PATCH] Measure: a circle and a line now show 'Line to centre' instead of 'Center to center' (#11524) * Measure: a circle and a line show 'Line to centre' instead of 'Centre to centre' Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Measure: US spelling for Line to center, UK in en-GB Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- .../pending/measure-line-to-centre.json | 29 +++++++++++++++++++ crates/ui-egui/src/dialogs_dense.rs | 5 ++-- crates/ui-egui/src/quick_measure.rs | 13 ++++++++- crates/ui-egui/src/quick_measure_tests.rs | 18 ++++++++++++ 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 assets/locales/pending/measure-line-to-centre.json diff --git a/assets/locales/pending/measure-line-to-centre.json b/assets/locales/pending/measure-line-to-centre.json new file mode 100644 index 000000000..78de95661 --- /dev/null +++ b/assets/locales/pending/measure-line-to-centre.json @@ -0,0 +1,29 @@ +{ + "ar": { + "measure.line_to_centre": "من الخط إلى المركز" + }, + "de": { + "measure.line_to_centre": "Linie zum Mittelpunkt" + }, + "en": { + "measure.line_to_centre": "Line to center" + }, + "en-GB": { + "measure.line_to_centre": "Line to centre" + }, + "he": { + "measure.line_to_centre": "מהקו למרכז" + }, + "ja": { + "measure.line_to_centre": "線から中心まで" + }, + "ko": { + "measure.line_to_centre": "선에서 중심까지" + }, + "vi": { + "measure.line_to_centre": "Từ đường đến tâm" + }, + "zh": { + "measure.line_to_centre": "线到圆心" + } +} diff --git a/crates/ui-egui/src/dialogs_dense.rs b/crates/ui-egui/src/dialogs_dense.rs index e56c86b7c..d9a494918 100644 --- a/crates/ui-egui/src/dialogs_dense.rs +++ b/crates/ui-egui/src/dialogs_dense.rs @@ -1119,11 +1119,12 @@ fn measure_rows(app: &SolveApp, ui: &mut egui::Ui, r: Option<&Value>, show: &mut if let Some((now, d, a, b)) = shown_distance(r, *show) { if r.get("center_distance").is_some() { // Centre, min and max all listed; the chosen one is drawn and broken into ΔX/Y/Z. + let centre_label = crate::quick_measure::centre_distance_label(r); for (which, label, key) in - [(Shown::Centre, "Centre to centre", "center_distance"), (Shown::Min, "Min", "distance_mm"), (Shown::Max, "Max", "max")] + [(Shown::Centre, centre_label, "center_distance"), (Shown::Min, tr("Min"), "distance_mm"), (Shown::Max, tr("Max"), "max")] { let Some(v) = r.get(key).filter(|v| v.is_number()) else { continue }; - if ui_kit::list_picker(ui, key, &format!("{} {}", tr(label), mm(v)), now == which).clicked() { + if ui_kit::list_picker(ui, key, &format!("{} {}", label, mm(v)), now == which).clicked() { *show = Some(which); } } diff --git a/crates/ui-egui/src/quick_measure.rs b/crates/ui-egui/src/quick_measure.rs index a212c0030..f2e82a04f 100644 --- a/crates/ui-egui/src/quick_measure.rs +++ b/crates/ui-egui/src/quick_measure.rs @@ -173,6 +173,17 @@ pub(crate) fn item_lines(app: &SolveApp, it: &Value) -> Vec { lines } +/// The label of a pair's centre distance: from a straight edge to a circle's centre, or +/// centre to centre. +pub(crate) fn centre_distance_label(r: &Value) -> &'static str { + let is_circle = |item: &Value| item.get("round").and_then(Value::as_str) == Some("circle"); + let is_line = |item: &Value| matches!(item.get("type").and_then(Value::as_str), Some("edge" | "sketch_curve")) && item.get("round").is_none(); + match r["items"].as_array().map(Vec::as_slice) { + Some([a, b]) if (is_circle(a) && is_line(b)) || (is_circle(b) && is_line(a)) => crate::i18n::tr("measure.line_to_centre"), + _ => crate::i18n::tr("Centre to centre"), + } +} + /// The readout's rows for a measurement. fn lines(app: &SolveApp, r: &Value) -> Vec<(String, String)> { let split = |line: String| match line.split_once(" ") { @@ -193,7 +204,7 @@ fn lines(app: &SolveApp, r: &Value) -> Vec<(String, String)> { } let mut rows = Vec::new(); if let Some(d) = r["center_distance"].as_f64() { - rows.push((crate::i18n::tr("Centre to centre").to_string(), crate::prefs::show_mm(app, d, 1))); + rows.push((centre_distance_label(r).to_string(), crate::prefs::show_mm(app, d, 1))); } if let Some(d) = r["distance_mm"].as_f64() { rows.push((crate::i18n::tr_label("Distance").to_string(), crate::prefs::show_mm(app, d, 1))); diff --git a/crates/ui-egui/src/quick_measure_tests.rs b/crates/ui-egui/src/quick_measure_tests.rs index f4b6729e6..0b4473ea6 100644 --- a/crates/ui-egui/src/quick_measure_tests.rs +++ b/crates/ui-egui/src/quick_measure_tests.rs @@ -131,6 +131,24 @@ fn two_points_show_their_distance() { assert!(rows.contains(&row("Distance", crate::prefs::show_mm(&h.app, 1400f64.sqrt(), 1))), "{rows:?}"); } +/// A circle and a line: the distance from the line to the circle's centre is named so. +#[test] +fn a_circle_and_a_line_show_the_distance_from_the_line_to_the_centre() { + let mut h = harness(); + h.app.run("sketch.create", json!({"plane": "XY"})).unwrap(); + h.app.run("sketch.circle.center", json!({"center": [0, 0], "radius": 5})).unwrap(); + h.app.run("sketch.line", json!({"points": [[20, 0], [30, 0]]})).unwrap(); + h.app.session.selection = ["c1", "l1"].into_iter().map(|id| Sel::SketchCurve { id: id.into(), sketch: None }).collect(); + let rows = readout(&mut h); + assert!(rows.contains(&row("Line to center", crate::prefs::show_mm(&h.app, 20.0, 1))), "{rows:?}"); + assert!(!rows.iter().any(|(l, _)| l == crate::i18n::tr("Centre to centre")), "{rows:?}"); + + h.app.run("sketch.circle.center", json!({"center": [50, 0], "radius": 5})).unwrap(); + h.app.session.selection = ["c1", "c2"].into_iter().map(|id| Sel::SketchCurve { id: id.into(), sketch: None }).collect(); + let rows = readout(&mut h); + assert!(rows.iter().any(|(l, _)| l == crate::i18n::tr("Centre to centre")), "two circles still measure centre to centre: {rows:?}"); +} + #[test] fn several_edges_show_their_count_and_total_length() { let mut h = block();