fix: harden the issue-fix wave after full adversarial review

Five reviewers (PDF, snap, commands, otrack/help, printing) covered the
eight issue-fix commits; every blocker and major is fixed here.

Printing (#1261 follow-up):
- printto params now quote the printer name and pad the empty driver/
  port slots handlers substitute ("Microsoft Print to PDF" was split
  into three arguments and the job silently lost).
- Level-2 enumeration also merges when the level-4 list omits the
  configured default, not only when it is empty; a level-2 error no
  longer discards the default-printer merge.
- The printer list loads in a background task instead of blocking the
  UI thread (level-2 queries can wait out RPC timeouts).
- CTB registration: collisions keep the existing file but now say so,
  and only container-parsed tables are registered (the permissive
  zlib heuristic stays session-only so junk cannot persist).

Snapping (#1030/#1319 follow-up):
- Edge-wire key_vertices gain NaN separators: junctions between
  unrelated mesh edges no longer fabricate phantom midpoints.
- The wire cap counts segments (not separator points) and decimates
  instead of dropping, so dense meshes keep partial endpoint coverage
  instead of losing snap entirely.
- f64 endpoint recovery is a one-shot per-wire map instead of an
  O(points x geoms) rescan on every mouse move.

Commands (#1082 class): the same typed-value-on-web bug also hit
CYLINDER/BOX/WEDGE/CONE/PYRAMID heights, HELIX final height (wrong
value, not just dropped), and SWEEP reference/new lengths — all now
commit as text at exactly those steps, each pinned by a regression
test that fails without the override (plus the missing native-route
twin for EXTRUDE).

PDF (#702 follow-up): heavy CTB pens bypass the Form XObject (their
half-width exceeds the /BBox SDF margin and was flat-chopped), CTM
scale entries round to 4 significant digits (0.01 quantized small
text by ~1%), degenerate quads skip emission, the atlas snapshot is
taken once per export instead of per text entity, and the rounding
comments no longer conflate page points with glyph-plane units.

OTRACK (#1313 follow-up): the guide's polar quantization diverges
from the snapper's drafting-gated polar during window-corner drags —
documented; an orphaned grid-step doc block is reunited with its
function.
This commit is contained in:
Afonsop committed 2026-09-17 18:42:15 +01:00
1 parent 5ea4294d3d
commit d135b15ab6
18 files changed
+1326 -138

No files matched your search

+472
View File
@@ -1771,4 +1771,476 @@ mod tests {
"EXTRUDE must finish after the typed height"
);
}
/// (min, max) of `coord` over every wire point of the Solid3D entities in
/// tab 0's document. Lets the typed-value regression tests below assert
/// the committed geometry (the height / swept size), not just that some
/// solid appeared.
fn solid_wire_extent(
app: &OpenCADStudio,
coord: impl Fn(&acadrust::types::Vector3) -> f64,
) -> Option<(f64, f64)> {
let mut extent: Option<(f64, f64)> = None;
for entity in app.tabs[0].scene.document.entities() {
let acadrust::EntityType::Solid3D(solid) = entity else {
continue;
};
for point in solid.wires.iter().flat_map(|wire| wire.points.iter()) {
let value = coord(point);
extent = Some(match extent {
Some((low, high)) => (low.min(value), high.max(value)),
None => (value, value),
});
}
}
extent
}
fn solid_count(app: &OpenCADStudio) -> usize {
app.tabs[0]
.scene
.document
.entities()
.filter(|e| matches!(e, acadrust::EntityType::Solid3D(_)))
.count()
}
/// The native twin of `extrude_typed_height_from_dyn_field`: the same
/// EXTRUDE Height step driven through the focused command line
/// (`CommandInput` → `CommandSubmit`) — the route a desktop user whose
/// command line holds keyboard focus takes. Both routes must extrude by
/// the typed height (#1082).
#[test]
fn extrude_typed_height_from_command_line() {
use crate::app::Message;
let mut app = OpenCADStudio::new_for_test();
app.automation_op(r#"{"op":"new"}"#);
// A closed rectangle in the XY plane.
use acadrust::entities::LwVertex;
use acadrust::types::Vector2;
let rect = acadrust::LwPolyline {
vertices: [
(-10.0, -10.0),
(10.0, -10.0),
(10.0, 10.0),
(-10.0, 10.0),
]
.iter()
.map(|(x, y)| LwVertex::new(Vector2::new(*x, *y)))
.collect(),
is_closed: true,
..Default::default()
};
let handle = app.tabs[0]
.scene
.document
.add_entity(acadrust::EntityType::LwPolyline(rect))
.unwrap();
let _ = app.update(Message::CommandInput("EXTRUDE".to_string()));
let _ = app.update(Message::CommandSubmit);
let _ = app.feed_command(crate::command::StepInput::EntityPick(
handle,
glam::DVec3::new(-10.0, -10.0, 0.0),
));
// Bare Enter finishes selection → Height step.
let _ = app.update(Message::CommandFinalize);
// Focused command line: the typed height goes through the input
// widget, not the dynamic-input field buffer.
let _ = app.update(Message::CommandInput("5".to_string()));
let _ = app.update(Message::CommandSubmit);
let (min_z, max_z) =
solid_wire_extent(&app, |p| p.z).expect("typed height must extrude");
assert!(
(max_z - min_z - 5.0).abs() < 1e-6,
"extruded extent must be the typed 5, got {min_z}..{max_z}"
);
assert!(
app.tabs[0].active_cmd.is_none(),
"EXTRUDE must finish after the typed height"
);
}
/// Issue #1082 class regression for CYLINDER: the Height prompt accepts
/// keyword letters (2Point/Axis), so on web the typed digits land in the
/// dynamic-input Height box and the commit must parse them as the scalar
/// height instead of resolving an in-plane point whose height is ~0.
#[test]
fn cylinder_typed_height_from_dyn_field() {
use crate::app::Message;
let mut app = OpenCADStudio::new_for_test();
app.automation_op(r#"{"op":"new"}"#);
let _ = app.update(Message::CommandInput("CYLINDER".to_string()));
let _ = app.update(Message::CommandSubmit);
// Base center and radius through the command line.
let _ = app.update(Message::CommandInput("0,0".to_string()));
let _ = app.update(Message::CommandSubmit);
let _ = app.update(Message::CommandInput("3".to_string()));
let _ = app.update(Message::CommandSubmit);
// → Height step with a Height dynamic-input box.
assert!(
app.tabs[0]
.dyn_fields
.iter()
.any(|f| f.role == crate::command::DynRole::Height)
);
for ch in ["5"] {
let _ = app.update(Message::CommandAppendChar(ch.to_string()));
}
assert_eq!(app.command_line.input, "");
assert!(
app.tabs[0]
.dyn_fields
.iter()
.any(|f| f.buffer.as_deref() == Some("5"))
);
let _ = app.update(Message::CommandFinalize);
let (min_z, max_z) = solid_wire_extent(&app, |p| p.z)
.expect("typed height must build the cylinder");
assert!(
(max_z - 5.0).abs() < 1e-6 && min_z.abs() < 1e-6,
"cylinder height must be the typed 5, got {min_z}..{max_z}"
);
assert!(
app.tabs[0].active_cmd.is_none(),
"CYLINDER must finish after the typed height"
);
}
/// Issue #1082 class regression for BOX (and WEDGE, which shares
/// `BoxStep::Height`): the typed height must commit as the scalar height,
/// not resolve to an in-plane point whose plane-normal ordinate is ~0.
#[test]
fn box_and_wedge_typed_height_from_dyn_field() {
use crate::app::Message;
let mut app = OpenCADStudio::new_for_test();
app.automation_op(r#"{"op":"new"}"#);
// ── BOX: 10×5 footprint, typed height 7 ──────────────────────────
let _ = app.update(Message::CommandInput("BOX".to_string()));
let _ = app.update(Message::CommandSubmit);
let _ = app.update(Message::CommandInput("0,0".to_string()));
let _ = app.update(Message::CommandSubmit);
let _ = app.update(Message::CommandInput("10,5".to_string()));
let _ = app.update(Message::CommandSubmit);
assert!(
app.tabs[0]
.dyn_fields
.iter()
.any(|f| f.role == crate::command::DynRole::Height)
);
for ch in ["7"] {
let _ = app.update(Message::CommandAppendChar(ch.to_string()));
}
let _ = app.update(Message::CommandFinalize);
assert_eq!(solid_count(&app), 1, "BOX must commit after the typed height");
let (min_x, max_x) = solid_wire_extent(&app, |p| p.x).expect("box solid");
let (min_y, max_y) = solid_wire_extent(&app, |p| p.y).expect("box solid");
let (min_z, max_z) = solid_wire_extent(&app, |p| p.z).expect("box solid");
assert!(
(min_x - 0.0).abs() < 1e-6
&& (max_x - 10.0).abs() < 1e-6
&& (min_y - 0.0).abs() < 1e-6
&& (max_y - 5.0).abs() < 1e-6,
"box footprint must stay 10×5, got x {min_x}..{max_x}, y {min_y}..{max_y}"
);
assert!(
(min_z - 0.0).abs() < 1e-6 && (max_z - 7.0).abs() < 1e-6,
"box height must be the typed 7, got {min_z}..{max_z}"
);
assert!(app.tabs[0].active_cmd.is_none());
// ── WEDGE: same Height step (BoxStep::Height), typed height 9 ────
let _ = app.update(Message::CommandInput("WEDGE".to_string()));
let _ = app.update(Message::CommandSubmit);
let _ = app.update(Message::CommandInput("0,0".to_string()));
let _ = app.update(Message::CommandSubmit);
let _ = app.update(Message::CommandInput("10,5".to_string()));
let _ = app.update(Message::CommandSubmit);
assert!(
app.tabs[0]
.dyn_fields
.iter()
.any(|f| f.role == crate::command::DynRole::Height)
);
for ch in ["9"] {
let _ = app.update(Message::CommandAppendChar(ch.to_string()));
}
let _ = app.update(Message::CommandFinalize);
assert_eq!(solid_count(&app), 2, "WEDGE must commit after the typed height");
let (min_z, max_z) = solid_wire_extent(&app, |p| p.z).expect("wedge solid");
assert!(
(min_z - 0.0).abs() < 1e-6 && (max_z - 9.0).abs() < 1e-6,
"wedge height must be the typed 9 (aggregate over both solids), got {min_z}..{max_z}"
);
assert!(app.tabs[0].active_cmd.is_none());
}
/// Issue #1082 class regression for CONE and PYRAMID: their Height (and
/// HeightAfterTopRadius) prompts accept keyword letters, so the typed
/// digits must commit through `on_text_input` as the scalar height. Both
/// legs drive the Top-radius sub-prompt first so the committed solid is a
/// frustum whose top face lands in the wireframe (an apex cone's wires
/// carry only the base ellipse), and so the shared
/// `HeightAfterTopRadius` arm is covered too.
#[test]
fn cone_and_pyramid_typed_height_from_dyn_field() {
use crate::app::Message;
let mut app = OpenCADStudio::new_for_test();
app.automation_op(r#"{"op":"new"}"#);
// ── CONE: base center 0,0 radius 3, top radius 1, typed height 5 ─
let _ = app.update(Message::CommandInput("CONE".to_string()));
let _ = app.update(Message::CommandSubmit);
let _ = app.update(Message::CommandInput("0,0".to_string()));
let _ = app.update(Message::CommandSubmit);
let _ = app.update(Message::CommandInput("3".to_string()));
let _ = app.update(Message::CommandSubmit);
assert!(
app.tabs[0]
.dyn_fields
.iter()
.any(|f| f.role == crate::command::DynRole::Height)
);
// Top-radius sub-prompt, then the height (HeightAfterTopRadius).
let _ = app.update(Message::CommandInput("T".to_string()));
let _ = app.update(Message::CommandSubmit);
let _ = app.update(Message::CommandInput("1".to_string()));
let _ = app.update(Message::CommandSubmit);
assert!(
app.tabs[0]
.dyn_fields
.iter()
.any(|f| f.role == crate::command::DynRole::Height)
);
for ch in ["5"] {
let _ = app.update(Message::CommandAppendChar(ch.to_string()));
}
let _ = app.update(Message::CommandFinalize);
assert_eq!(solid_count(&app), 1, "CONE must commit after the typed height");
let (min_z, max_z) = solid_wire_extent(&app, |p| p.z).expect("cone solid");
let (.., max_r) = solid_wire_extent(&app, |p| p.x.hypot(p.y)).expect("cone solid");
assert!(
(max_r - 3.0).abs() < 1e-6,
"cone base radius must stay 3, got {max_r}"
);
assert!(
min_z.abs() < 1e-6 && (max_z - 5.0).abs() < 1e-6,
"cone height must be the typed 5, got {min_z}..{max_z}"
);
assert!(app.tabs[0].active_cmd.is_none());
// ── PYRAMID: base center 0,0 radius 3, top radius 2, typed height 8
let _ = app.update(Message::CommandInput("PYRAMID".to_string()));
let _ = app.update(Message::CommandSubmit);
let _ = app.update(Message::CommandInput("0,0".to_string()));
let _ = app.update(Message::CommandSubmit);
let _ = app.update(Message::CommandInput("3".to_string()));
let _ = app.update(Message::CommandSubmit);
assert!(
app.tabs[0]
.dyn_fields
.iter()
.any(|f| f.role == crate::command::DynRole::Height)
);
let _ = app.update(Message::CommandInput("T".to_string()));
let _ = app.update(Message::CommandSubmit);
let _ = app.update(Message::CommandInput("2".to_string()));
let _ = app.update(Message::CommandSubmit);
assert!(
app.tabs[0]
.dyn_fields
.iter()
.any(|f| f.role == crate::command::DynRole::Height)
);
for ch in ["8"] {
let _ = app.update(Message::CommandAppendChar(ch.to_string()));
}
let _ = app.update(Message::CommandFinalize);
assert_eq!(
solid_count(&app),
2,
"PYRAMID must commit after the typed height"
);
let (min_z, max_z) = solid_wire_extent(&app, |p| p.z).expect("pyramid solid");
assert!(
min_z.abs() < 1e-6 && (max_z - 8.0).abs() < 1e-6,
"pyramid height must be the typed 8 (aggregate over both solids), got {min_z}..{max_z}"
);
assert!(app.tabs[0].active_cmd.is_none());
}
/// Issue #1082 class regression for HELIX: at the Final (height) prompt
/// the unfixed dyn commit resolves the typed span into an in-plane point
/// anchored at the last pick and commits that point's distance from the
/// center as the height — a wrong value whenever the previous pick wasn't
/// the center. Entering the top radius through its dynamic box anchors
/// the height prompt at (3,0,0), setting up exactly that case.
#[test]
fn helix_typed_height_from_dyn_field() {
use crate::app::Message;
let mut app = OpenCADStudio::new_for_test();
app.automation_op(r#"{"op":"new"}"#);
let _ = app.update(Message::CommandInput("HELIX".to_string()));
let _ = app.update(Message::CommandSubmit);
// Center, then a typed base radius.
let _ = app.update(Message::CommandInput("0,0".to_string()));
let _ = app.update(Message::CommandSubmit);
let _ = app.update(Message::CommandInput("2".to_string()));
let _ = app.update(Message::CommandSubmit);
// Pick the top radius through the dynamic-input field (the only web
// route): the resolved point (3,0,0) becomes the anchor/last point,
// off the center — exactly the case where an unfixed point-resolved
// typed height would commit the wrong value.
for ch in ["3"] {
let _ = app.update(Message::CommandAppendChar(ch.to_string()));
}
let _ = app.update(Message::CommandFinalize);
// → Final step with a Distance dynamic-input box.
assert!(
app.tabs[0]
.dyn_fields
.iter()
.any(|f| f.role == crate::command::DynRole::Distance)
);
assert_eq!(app.last_point, Some(glam::DVec3::new(3.0, 0.0, 0.0)));
for ch in ["5"] {
let _ = app.update(Message::CommandAppendChar(ch.to_string()));
}
assert_eq!(app.command_line.input, "");
assert!(
app.tabs[0]
.dyn_fields
.iter()
.any(|f| f.buffer.as_deref() == Some("5"))
);
let _ = app.update(Message::CommandFinalize);
let helix = app.tabs[0]
.scene
.document
.entities()
.find_map(|e| match e {
acadrust::EntityType::Helix(helix) => Some(helix.clone()),
_ => None,
})
.expect("typed height must create the helix");
let height = helix.turn_height * helix.turns;
assert!(
(height - 5.0).abs() < 1e-6,
"helix height must be the typed 5, got {height}"
);
assert!(
(helix.axis_vector.z - 1.0).abs() < 1e-9,
"helix axis must stay the plane normal"
);
assert!(
app.tabs[0].active_cmd.is_none(),
"HELIX must finish after the typed height"
);
}
/// Issue #1082 class regression for SWEEP's reference-scale prompts: the
/// typed reference length must be parsed as a length (advancing to the
/// new-length prompt), and the typed new length must set the scale
/// (new/reference) — visible in the swept solid's size. Unfixed, the
/// typed reference length is dropped as a stray first reference point.
#[test]
fn sweep_typed_scale_lengths_from_dyn_field() {
use crate::app::Message;
use acadrust::types::Vector3;
let mut app = OpenCADStudio::new_for_test();
app.automation_op(r#"{"op":"new"}"#);
// A unit circle profile swept along a vertical line path.
let mut circle = acadrust::Circle::new();
circle.radius = 1.0;
let profile = app.tabs[0]
.scene
.document
.add_entity(acadrust::EntityType::Circle(circle))
.unwrap();
let path = app.tabs[0]
.scene
.document
.add_entity(acadrust::EntityType::Line(acadrust::Line::from_points(
Vector3::new(0.0, 0.0, 0.0),
Vector3::new(0.0, 0.0, 10.0),
)))
.unwrap();
let _ = app.update(Message::CommandInput("SWEEP".to_string()));
let _ = app.update(Message::CommandSubmit);
// Select the profile, bare Enter finishes selection → path prompt.
let _ = app.feed_command(crate::command::StepInput::SelectionComplete(vec![profile]));
let _ = app.update(Message::CommandFinalize);
// Enter the reference-scale sub-prompt through the command line.
let _ = app.update(Message::CommandInput("SCALE".to_string()));
let _ = app.update(Message::CommandSubmit);
let _ = app.update(Message::CommandInput("REFERENCE".to_string()));
let _ = app.update(Message::CommandSubmit);
// → ReferenceLength prompt with dynamic-input boxes showing.
assert!(!app.tabs[0].dyn_fields.is_empty());
// Typed reference length 2 commits through the dyn-field buffer.
for ch in ["2"] {
let _ = app.update(Message::CommandAppendChar(ch.to_string()));
}
assert_eq!(app.command_line.input, "");
let _ = app.update(Message::CommandFinalize);
let prompt = app.tabs[0]
.active_cmd
.as_ref()
.map(|c| c.prompt())
.unwrap_or_default();
assert!(
prompt.to_lowercase().contains("new length"),
"typed reference length must advance to the new-length prompt, got: {prompt}"
);
// Typed new length 6 → scale 6/2 = 3 → back to the path prompt.
for ch in ["6"] {
let _ = app.update(Message::CommandAppendChar(ch.to_string()));
}
let _ = app.update(Message::CommandFinalize);
let prompt = app.tabs[0]
.active_cmd
.as_ref()
.map(|c| c.prompt())
.unwrap_or_default();
assert!(
prompt.to_lowercase().contains("sweep path"),
"typed new length must return to the path prompt, got: {prompt}"
);
// Picking the path finishes the sweep: the unit circle must have been
// scaled by 3, so the swept solid's wires reach radius 3.
let _ = app.feed_command(crate::command::StepInput::EntityPick(
path,
glam::DVec3::new(0.0, 0.0, 5.0),
));
let (.., max_r) = solid_wire_extent(&app, |p| p.x.hypot(p.y))
.expect("sweep must create a solid");
assert!(
(max_r - 3.0).abs() < 1e-3,
"swept radius must be the profile 1 × scale 3, got {max_r}"
);
assert!(
app.tabs[0].active_cmd.is_none(),
"SWEEP must finish after the path pick"
);
}
}
+11 -2
View File
@@ -3260,6 +3260,11 @@ pub enum Message {
/// Web never constructs it — printing opens the PDF preview instead.
#[cfg_attr(target_arch = "wasm32", allow(dead_code))]
PrintResult(Result<String, String>),
/// Printers enumerated off the UI thread for the Plot dialog's dropdown;
/// the dialog opens immediately and the list lands whenever the spooler
/// query finishes. Web never constructs it — it has no system printers.
#[cfg_attr(target_arch = "wasm32", allow(dead_code))]
PrintersListed(Vec<String>),
/// Open the full Plot / Print dialog (seeds state from the layout).
PlotDialogOpen,
/// An edit inside the Plot / Print dialog.
@@ -3290,8 +3295,12 @@ pub enum Message {
/// Open file dialog to load a CTB/STB plot style table.
PlotStyleLoad,
/// Callback when the user picks (or cancels) a CTB/STB file.
/// `Ok(None)` = cancelled; `Err` = the picked file failed to parse.
PlotStyleLoaded(Result<Option<crate::io::plot_style::PlotStyleTable>, String>),
/// `Ok(None)` = cancelled; `Err` = the picked file failed to parse. The
/// table carries an optional non-fatal note for the command line (e.g.
/// registration kept an already-registered table of the same name).
PlotStyleLoaded(
Result<Option<(crate::io::plot_style::PlotStyleTable, Option<String>)>, String>,
),
/// Clear the active plot style table.
PlotStyleClear,
/// Open/close the Plot Style panel.
+15 -1
View File
@@ -4041,7 +4041,6 @@ impl OpenCADStudio {
.collect();
// Keep session-only choices while loading drawing fields from the layout.
let d = &mut self.plot_dialog;
d.printers = crate::io::print_to_printer::list_printers();
d.plot_styles = crate::io::plot_style::available_ctb_names();
d.scales = scales;
d.plot_views = plot_views;
@@ -4124,6 +4123,21 @@ impl OpenCADStudio {
}
}
self.active_modal = Some(crate::app::ModalKind::Plot);
// Enumerating printers can block for seconds on spooler RPC (dead
// print servers), so it must not run on the UI thread: open the
// dialog immediately and let the printer dropdown populate when the
// worker replies with Message::PrintersListed. The list is session
// state on the dialog, so the late assignment re-renders the pick
// list without touching the user's selection. Native only — the web
// build has no system printers and offers PDF output alone.
#[cfg(not(target_arch = "wasm32"))]
{
background_task(
crate::io::print_to_printer::list_printers,
Message::PrintersListed,
)
}
#[cfg(target_arch = "wasm32")]
Task::none()
}
+13 -1
View File
@@ -8335,12 +8335,19 @@ impl OpenCADStudio {
.push_error(crate::tf!("Print failed: {e}").as_ref());
Task::none()
}
// The printer list arrives after the Plot dialog already opened
// (enumeration runs off the UI thread); assigning it re-renders
// the dropdown while leaving the user's selection untouched.
Message::PrintersListed(printers) => {
self.plot_dialog.printers = printers;
Task::none()
}
// ── Plot Style Table ──────────────────────────────────────────────
Message::PlotStyleLoad => {
Task::perform(crate::io::pick_plot_style(), Message::PlotStyleLoaded)
}
Message::PlotStyleLoaded(Ok(Some(table))) => {
Message::PlotStyleLoaded(Ok(Some((table, note)))) => {
if table.is_stb {
self.command_line.push_error(
crate::t!(
@@ -8364,6 +8371,11 @@ impl OpenCADStudio {
)
.as_ref(),
);
// Non-fatal registration feedback — e.g. the picked file was
// already registered and the existing table was kept.
if let Some(note) = note {
self.command_line.push_info(&note);
}
self.active_plot_style = Some(table);
self.plot_dialog.plot_styles = crate::io::plot_style::available_ctb_names();
Task::none()
+3
View File
@@ -771,6 +771,9 @@ bg={bg_ms:.1}ms n={view_count}"
// state machine stay untouched.
let (_, (ux, uy, _)) = self.drafting_grid_basis(i);
let (ux, uy) = (ux.as_dvec3(), uy.as_dvec3());
// Guides quantize to the polar increment even
// while a window-corner drag suppresses polar in
// the snapper (drafting gate) — cosmetic only.
let step = self.polar_mode.then_some(self.polar_increment_deg);
let perp_on =
self.snapper.is_on(crate::snap::SnapType::Perpendicular);