Measure: number the two picks in the view (#6020) (#6021)

* claim: #6020

* Measure: number the two picks in the view (#6020)

"1" and "2" beside the measured line's ends, as the panel lists the
picks, each just past its end so it stays off the line and its length.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Frank
2026-10-28 16:05:22 +00:00
committed by GitHub
parent c8c9534022
commit 8e26fe9388
2 changed files with 50 additions and 0 deletions
+19
View File
@@ -1281,6 +1281,7 @@ fn measure_line(app: &SolveApp, painter: &egui::Painter, proj: &Proj, r: &serde_
for s in [sa, sb] {
painter.circle(s, 3.5, t.manipulator, Stroke::new(1.0, Color32::WHITE));
}
pick_numbers(painter, sa, sb);
let mid = sa + (sb - sa) * 0.5 + vec2(10.0, -14.0);
let galley = painter.layout_no_wrap(crate::prefs::show_mm(app, d, 1), egui::FontId::proportional(crate::theme::Tokens::get().font_label), t.text);
let rect = egui::Rect::from_min_size(mid, galley.size() + vec2(10.0, 6.0));
@@ -1292,6 +1293,24 @@ fn measure_line(app: &SolveApp, painter: &egui::Painter, proj: &Proj, r: &serde_
painter.galley(rect.min + vec2(5.0, 3.0), galley, t.text);
}
/// "1" and "2" beside the measured line's ends (#6020), as the panel lists the picks: each just
/// past its end, away from the line and its length in the middle.
fn pick_numbers(painter: &egui::Painter, sa: Pos2, sb: Pos2) {
let t = Tokens::get();
let along = (sb - sa).normalized();
// Ends on one spot (or one behind the other): side by side above it.
let (out_a, out_b) = if along.is_finite() && along.length_sq() > 0.5 { (-along, along) } else { (vec2(-0.7, -0.7), vec2(0.7, -0.7)) };
for (n, at, out) in [("1", sa, out_a), ("2", sb, out_b)] {
let galley = painter.layout_no_wrap(n.to_string(), egui::FontId::proportional(t.font_label), t.text);
let size = galley.size() + vec2(8.0, 4.0);
let side = size.x.max(size.y);
let rect = egui::Rect::from_center_size(at + out * (side * 0.5 + 8.0), vec2(side, size.y));
painter.rect(rect, t.radius_sm.saturating_sub(1), t.overlay, Stroke::new(1.0, t.manipulator), egui::StrokeKind::Inside);
painter.galley(rect.center() - galley.size() * 0.5, galley, t.text);
crate::scenario::publish_target(&format!("measure:item:{n}"), rect);
}
}
/// A world-axis-aligned chain between the same two measured points. Zero-length and
/// view-aligned legs still get a label; labels move apart when their projections coincide.
fn measure_components(app: &SolveApp, painter: &egui::Painter, proj: &Proj, a: Vec3, b: Vec3, total: egui::Rect) {
@@ -179,6 +179,37 @@ fn measurement_axis_distances_can_be_disabled_saved_and_restored_in_preferences(
assert!(h.app.preferences.measure_axis_distances, "Cancel restores the last Apply");
}
/// The view numbers the picks as the panel does (#6020): "1" beside the first pick's end of the
/// line, "2" beside the second's, in every view and whichever way round they were picked, clear
/// of the distance label.
#[test]
fn the_view_numbers_the_two_picks() {
for reverse in [false, true] {
let (a, b) = ([0., 0., 0.], [-3., 4., -12.]);
let (first, second) = if reverse { (b, a) } else { (a, b) };
let mut h = vertex_measurement(first, second);
for view in ["iso", "top", "front", "right"] {
h.call("ui.view", json!({"view": view}));
let texts = painted_text(&mut h);
assert!(texts.iter().any(|t| t == "1") && texts.iter().any(|t| t == "2"), "{view}: {texts:?}");
let mut at = |p: [f64; 3]| {
let r = h.call("ui.at", json!({ "world": p }))["result"].clone();
egui::pos2(r[0].as_f64().unwrap() as f32, r[1].as_f64().unwrap() as f32)
};
let (pa, pb) = (at(first), at(second));
let label = crate::scenario::rect_of("measure:label").unwrap();
for (n, own, other) in [("1", pa, pb), ("2", pb, pa)] {
let r = crate::scenario::rect_of(&format!("measure:item:{n}")).unwrap();
assert!(r.center().distance(own) < r.center().distance(other), "{view}, reverse={reverse}: {n} beside its own pick");
assert!(r.center().distance(own) < 40.0, "{view}: {n} is {} from its pick", r.center().distance(own));
assert!(!r.intersects(label), "{view}: {n} covers the distance");
}
}
h.call("ui.key", json!({"key": "Escape"}));
assert!(crate::scenario::handles("measure:item:1").is_empty(), "the numbers go with the measure");
}
}
#[test]
fn the_distance_row_has_a_copy_button_that_copies_the_shown_value() {
let mut h = vertex_measurement([0., 0., 0.], [3., 4., 0.]);