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

+16 -16
View File
@@ -31,7 +31,7 @@ pub fn tool() -> ToolDef {
}
pub struct LeaderCommand {
verts: Vec<Vec3>,
verts: Vec<DVec3>,
ucs: Mat4,
}
@@ -61,7 +61,7 @@ impl CadCommand for LeaderCommand {
}
}
fn on_point(&mut self, pt: DVec3) -> CmdResult { let pt = pt.as_vec3();
fn on_point(&mut self, pt: DVec3) -> CmdResult {
self.verts.push(pt);
CmdResult::NeedPoint
}
@@ -85,24 +85,24 @@ impl CadCommand for LeaderCommand {
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> {
if self.verts.is_empty() {
return None;
}
let mut pts = self.verts.clone();
pts.push(pt);
let mut pts: Vec<Vec3> = self.verts.iter().map(|p| p.as_vec3()).collect();
pts.push(pt.as_vec3());
Some(preview_wire(&pts))
}
}
// ── Helpers ─────────────────────────────────────────────────────────────────
fn v3(p: Vec3) -> Vector3 {
Vector3::new(p.x as f64, p.y as f64, p.z as f64)
fn dv3(p: DVec3) -> Vector3 {
Vector3::new(p.x, p.y, p.z)
}
fn build_leader(verts: &[Vec3], ucs: Mat4) -> Leader {
let mut l = Leader::from_vertices(verts.iter().map(|p| v3(*p)).collect());
fn build_leader(verts: &[DVec3], ucs: Mat4) -> Leader {
let mut l = Leader::from_vertices(verts.iter().map(|p| dv3(*p)).collect());
l.creation_type = LeaderCreationType::WithText;
l.hookline_enabled = true;
// The hookline / text read along the UCS X axis (DXF "horizontal direction
@@ -116,17 +116,17 @@ fn build_leader(verts: &[Vec3], ucs: Mat4) -> Leader {
/// keeps the text reading away from the leader (text to the right of a
/// left-pointing landing, to the left of a right-pointing one).
fn annotation_anchor(
verts: &[Vec3],
verts: &[DVec3],
text_height: f64,
ucs: Mat4,
) -> (Vec3, AttachmentPoint) {
) -> (DVec3, AttachmentPoint) {
let last = *verts.last().unwrap();
let prev = verts[verts.len() - 2];
// Side + landing run along the UCS X axis (identity = world).
let ux = ucs.transform_vector3(Vec3::X).normalize_or(Vec3::X);
let ux = ucs.transform_vector3(Vec3::X).normalize_or(Vec3::X).as_dvec3();
let to_right = (last - prev).dot(ux) >= 0.0;
let sign = if to_right { 1.0_f32 } else { -1.0_f32 };
let anchor = last + ux * (sign * text_height as f32 * 1.5);
let sign = if to_right { 1.0_f64 } else { -1.0_f64 };
let anchor = last + ux * (sign * text_height * 1.5);
let attach = if to_right {
AttachmentPoint::MiddleLeft
} else {
@@ -137,14 +137,14 @@ fn annotation_anchor(
fn build_mtext(
text: &str,
pos: Vec3,
pos: DVec3,
height: f64,
attach: AttachmentPoint,
ucs: Mat4,
) -> MText {
let mut m = MText::new();
m.value = text.to_string();
m.insertion_point = v3(pos);
m.insertion_point = dv3(pos);
m.height = height;
m.attachment_point = attach;
// Text reads along the UCS X axis.