fix(precision): keep typed coordinates exact in f64 (#311)

Typed values were quantized to the f32 grid before reaching the
entity (e.g. a length of 2000.8 committed as 2000.8020), worsening
with magnitude. The interaction point layer was all glam::Vec3 (f32).

Two-layer fix:

1. Coordinate backbone -> f64. last_point, last_cursor_world,
   dyn_anchor, dyn_ref become DVec3; UcsXform transforms, parse_coord,
   the ucs helper fns, dyn_resolve_point, the OTRACK typed-distance
   paths, command-line coordinate entry and the coordinate readout all
   compute in f64. Screen/GPU/alignment stays f32 (snap engine, render
   geometry, projection, UCS-icon/viewcube drawing) with casts only at
   those boundaries.

2. Per-command committed storage -> DVec3. on_point already received a
   DVec3, but many command impls narrowed it back to f32 (let pt =
   pt.as_vec3(); Vec<Vec3> fields) and re-widened at build, quantizing
   the committed coordinate. Migrated PLINE, SPLINE, MLINE, LENGTHEN,
   INSERT, 3D primitives, every dimension/leader/mleader, ray, revcloud,
   wipeout, attdef, table, tolerance, array center, mview, plot_window,
   plus the QDIM_PLACE handler and qdim_collect_points. Preview,
   hit-test and rubber-band paths keep f32 at the boundary.

Hatch manual boundaries are left for a follow-up: HatchModel.boundary
is structurally Arc<Vec<[f32;2]>> and needs a model-level widen.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Opus 4.8 committed 2026-07-11 21:26:40 +03:00
1 parent 8ed10ceb2a
commit 57710eec2b
47 files changed
+699 -606

No files matched your search

+10 -8
View File
@@ -37,7 +37,7 @@ enum AddStep {
CollectPoints {
handle: Handle,
entity: EntityType,
pts: Vec<Vec3>,
pts: Vec<DVec3>,
},
}
@@ -84,7 +84,7 @@ impl CadCommand for MLeaderAddCommand {
CmdResult::NeedPoint
}
fn on_point(&mut self, pt: DVec3) -> CmdResult { let pt = pt.as_vec3();
fn on_point(&mut self, pt: DVec3) -> CmdResult {
match &mut self.step {
AddStep::PickArrowhead { handle, entity } => {
if let Some(ent) = entity.take() {
@@ -121,7 +121,7 @@ impl CadCommand for MLeaderAddCommand {
// Add a new leader root with the collected points
let points: Vec<Vector3> = pts
.iter()
.map(|p| Vector3::new(p.x as f64, p.y as f64, p.z as f64))
.map(|p| Vector3::new(p.x, p.y, p.z))
.collect();
let root = ml.context.add_leader_root();
root.create_line(points);
@@ -132,14 +132,16 @@ impl CadCommand for MLeaderAddCommand {
CmdResult::Cancel
}
fn on_mouse_move(&mut self, pt: DVec3) -> Option<WireModel> { let pt = pt.as_vec3();
fn on_mouse_move(&mut self, pt: DVec3) -> Option<WireModel> {
let existing_pts = match &self.step {
AddStep::CollectPoints { pts, .. } => pts.clone(),
_ => return None,
};
let mut all_pts = existing_pts;
all_pts.push(pt);
Some(preview_wire(&all_pts))
Some(preview_wire(
&all_pts.iter().map(|p| p.as_vec3()).collect::<Vec<_>>(),
))
}
fn inject_picked_entity(&mut self, entity: EntityType) {
@@ -275,7 +277,7 @@ pub fn tool_align() -> ToolDef {
enum AlignStep {
Gathering,
PickDirection { handles: Vec<Handle> },
PickEndDir { handles: Vec<Handle>, from: Vec3 },
PickEndDir { handles: Vec<Handle>, from: DVec3 },
}
pub struct MLeaderAlignCommand {
@@ -321,7 +323,7 @@ impl CadCommand for MLeaderAlignCommand {
CmdResult::NeedPoint
}
fn on_point(&mut self, pt: DVec3) -> CmdResult { let pt = pt.as_vec3();
fn on_point(&mut self, pt: DVec3) -> CmdResult {
match &mut self.step {
AlignStep::PickDirection { handles } => {
let h = handles.clone();
@@ -423,7 +425,7 @@ impl CadCommand for MLeaderCollectCommand {
CmdResult::NeedPoint
}
fn on_point(&mut self, pt: DVec3) -> CmdResult { let pt = pt.as_vec3();
fn on_point(&mut self, pt: DVec3) -> CmdResult {
if let CollectStep::PickLocation { handles } = &self.step {
let h = handles.clone();
// Build a new combined multileader at the collection point, delete originals.