From 74a97586a8878d3bedae6e3414b1021fb71dd5c8 Mon Sep 17 00:00:00 2001 From: jyviko <2501648+jyviko@users.noreply.github.com> Date: Wed, 28 Oct 2026 22:27:39 -0400 Subject: [PATCH] Wave 338/509: Tests: the saved fitted-letters design measures its closed form, its letter as conics (and 3 more) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. - 23bfa1cf7 jyviko: Tests: the saved fitted-letters design measures its closed form, its letter as conics - 0e3f01ec0 jyviko: Tests: a loft cut whose top is the basin's whole outline leaves the walls above as their own body - b3dfcf1ff jyviko: Tests: an engraved face's letters project as conics, their exact quadratic Béziers - 367beae69 jyviko: Viewport: the analysis legend stays above the floating History card again Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ --- crates/engine/src/cmd/features_more_tests.rs | 9 +++++- crates/engine/src/cmd/sketch_project_tests.rs | 32 +++++++++++++++---- crates/ui-egui/src/viewport.rs | 8 ++--- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/crates/engine/src/cmd/features_more_tests.rs b/crates/engine/src/cmd/features_more_tests.rs index 53db16ec3..aeb96898d 100644 --- a/crates/engine/src/cmd/features_more_tests.rs +++ b/crates/engine/src/cmd/features_more_tests.rs @@ -968,7 +968,14 @@ fn loft_cut_through_a_shelled_basin_in_either_order() { assert!(r.is_ok(), "{pad:?} reverse {reverse}: {r:?}"); let v = volume(&mut s); assert!((v - want).abs() < 1.0, "{pad:?} reverse {reverse}: {v} vs {want}"); - assert_eq!(measure(&mut s)["body_count"], 1); + // The loft's top section is the basin's whole outline at z = 10, so the cut leaves the + // walls above it touching the rest only along their outer rim: two bodies, as a cut's + // pieces are (18480 mm³ of walls from z = 10 to 30, and the floor part below). + let m = measure(&mut s); + assert_eq!(m["body_count"], 2, "{m}"); + let upper = + m["bodies"].as_array().unwrap().iter().find(|b| b["bbox"]["min"][2].as_f64().is_some_and(|z| (z - 10.0).abs() < 1e-9)).unwrap(); + assert!((upper["volume_mm3"].as_f64().unwrap() - 18480.0).abs() < 1e-6, "{upper}"); } } // As a new body and joined: a valid solid of positive volume either way. diff --git a/crates/engine/src/cmd/sketch_project_tests.rs b/crates/engine/src/cmd/sketch_project_tests.rs index 0ba5016f7..000d36759 100644 --- a/crates/engine/src/cmd/sketch_project_tests.rs +++ b/crates/engine/src/cmd/sketch_project_tests.rs @@ -709,11 +709,18 @@ fn a_face_engraved_with_text_projects_its_letters_exactly_and_extrudes() { assert!(r.error.is_none(), "{r:?}"); let face = before - volume(&mut s); assert!((face - taken).abs() < 1e-6 * before, "{face} {taken}"); - // Its sketch got the letters as Bézier pieces. + // Its sketch got the letters as their exact pieces: the outline's quadratic Béziers, which are + // parabolic arcs, come in as conics (or as control-point splines). let st = s.model.state(); let sketch = &st.sketches.last().unwrap().sketch; - let pieces = - sketch.curves.iter().filter(|c| c.link.is_some() && matches!(c.kind, solidcraft_sketch::CurveKind::Spline { control: true, .. })).count(); + let pieces = sketch + .curves + .iter() + .filter(|c| { + c.link.is_some() + && matches!(c.kind, solidcraft_sketch::CurveKind::Spline { control: true, .. } | solidcraft_sketch::CurveKind::Conic { .. }) + }) + .count(); assert!(pieces > 100, "{pieces}"); } @@ -731,12 +738,23 @@ fn a_face_sketch_saved_with_fitted_letters_reopens_and_builds_the_same() { let r = s.model.result(id).unwrap(); assert!(r.error.is_none(), "{name}: {:?}", r.error); } - // The build that saved it measured 5916.018831 mm³. - assert!((volume - 5916.018830904924).abs() < 1e-3, "{volume}"); + // The 30 x 20 x 10 block less the "S" 1 deep (its profile's exact area, Sketch2's smaller + // region) and the r 2 circle 3 deep, clear of the letter: 5916.010767. (The build that saved + // it measured 5916.018831, 8e-3 off; SMLib's integral is within 1e-8 of the closed form.) + let letter = s.model.state().sketches.iter().find(|k| k.name == "Sketch2").unwrap().profiles.iter().map(|p| p.area).fold(f64::INFINITY, f64::min); + let want = 6000.0 - letter - 3.0 * std::f64::consts::PI * 4.0; + assert!((volume - want).abs() < 1e-8 * 6000.0, "{volume} vs {want}"); + // The letter's exact pieces in the face's link: its quadratic Béziers, as conics (or splines). let st = s.model.state(); let sketch = &st.sketches.last().unwrap().sketch; - let pieces = - sketch.curves.iter().filter(|c| c.link.is_some() && matches!(c.kind, solidcraft_sketch::CurveKind::Spline { control: true, .. })).count(); + let pieces = sketch + .curves + .iter() + .filter(|c| { + c.link.is_some() + && matches!(c.kind, solidcraft_sketch::CurveKind::Spline { control: true, .. } | solidcraft_sketch::CurveKind::Conic { .. }) + }) + .count(); assert!(pieces > 0, "{pieces}"); } diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index 86eeba081..a9292ccf7 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -2642,9 +2642,6 @@ fn analysis_uniform(app: &SolveApp) -> [f32; 8] { solidcraft_gpu::view::analysis_uniform(app.session.analysis.map(|a| a.mode()), crate::access::map(app).as_ref()) } -/// While Draft, Accessibility or Curvature Map analysis is on, what each of its colours means and -/// the values it stands for, at the bottom left of the viewport (#973). The colours alone don't -/// say, and with colour vision loss they can be hard to tell apart. /// Why the model cannot be placed, across the bottom of the viewport, while it cannot: the /// viewport then shows no placed bodies (see `open_meshing::session_world`). fn placement_note(app: &SolveApp, painter: &egui::Painter, rect: Rect) { @@ -2654,6 +2651,9 @@ fn placement_note(app: &SolveApp, painter: &egui::Painter, rect: Rect) { painter.text(pos2(rect.center().x, rect.bottom() - 24.0), Align2::CENTER_BOTTOM, text, FontId::proportional(t.font_button), t.error); } +/// While Draft, Accessibility or Curvature Map analysis is on, what each of its colours means and +/// the values it stands for, at the bottom left of the viewport (#973). The colours alone don't +/// say, and with colour vision loss they can be hard to tell apart. fn analysis_legend(app: &SolveApp, painter: &egui::Painter, rect: Rect) { use solidcraft_engine::SurfaceAnalysis as A; let t = Tokens::get(); @@ -3967,7 +3967,7 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) { painter.add(egui_wgpu::Callback::new_paint_callback(rect, cb)); } let overlay_rect = crate::shell::bottom_overlay_rect(app, rect); - analysis_legend(app, &painter, rect); + analysis_legend(app, &painter, overlay_rect); placement_note(app, &painter, overlay_rect); crate::frame_rate::paint(app, ui, &painter, overlay_rect);