fix(render): preserve f64 precision until world_offset subtraction

Entity converters were casting WCS coordinates to f32 before the renderer
subtracted world_offset, which destroyed sub-unit precision on drawings
sitting at large coordinates (typical UTM-style CAD files). The multileader
case made it visible — glyphs warped under rotation — but every entity
that emits TruckObject::Lines/SegmentedLines/key_vertices/fill_tris was
affected.

Type changes (in src/scene/acad_to_truck.rs):
- TruckObject::Lines / SegmentedLines: Vec<[f32; 3]> → Vec<[f64; 3]>
- TruckEntity::key_vertices / fill_tris: f32 → f64

All ~17 producer files updated to keep WCS coordinates in f64 right up to
the TruckEntity boundary. The consumer in scene/tessellate.rs now performs
`(x - ox) as f32` (f64 subtract, then cast) for points, key_vertices, and
fill_tris — preserving precision near the camera origin even when the
drawing sits at million-unit coordinates.

catmull_rom_pts (multileader spline) is now f64; the scene path widens its
offset-relative f32 ctrl points to f64 around the call and narrows back at
the output.

Notes:
- Table layout still uses glam::Vec3 (f32) internally; widened to f64 only
  at the TruckEntity boundary for type compatibility. Separate cleanup to
  switch its internal math to f64 is tracked.
- snap_pts and tangent_geoms remain f32 — they are UI feedback (snap
  candidates, tangent hints) and the precision is sufficient there.
This commit is contained in:
Hakan Seven 2026-05-12 23:47:40 +03:00
commit 288ccff95a
20 changed files with 371 additions and 360 deletions

View file

@ -51,38 +51,26 @@ fn to_truck(arc: &Arc) -> TruckEntity {
let n = 32usize;
let ccw_end = if ea >= sa { ea } else { ea + TAU };
let (start_a, end_a) = (sa, ccw_end);
let mut pts: Vec<[f32; 3]> = Vec::with_capacity((n + 1) * 2 + 8);
let mut pts: Vec<[f64; 3]> = Vec::with_capacity((n + 1) * 2 + 8);
for i in 0..=n {
let a = start_a + (end_a - start_a) * (i as f64 / n as f64);
let p = arc_pt(a);
pts.push([p.x as f32, p.y as f32, p.z as f32]);
pts.push([p.x, p.y, p.z]);
}
pts.push([f32::NAN; 3]);
pts.push([f64::NAN; 3]);
for i in 0..=n {
let a = start_a + (end_a - start_a) * (i as f64 / n as f64);
let p = arc_pt(a);
pts.push([
(p.x + t * nx) as f32,
(p.y + t * ny) as f32,
(p.z + t * nz) as f32,
]);
pts.push([p.x + t * nx, p.y + t * ny, p.z + t * nz]);
}
pts.push([f32::NAN; 3]);
pts.push([f64::NAN; 3]);
let ps = arc_pt(sa);
pts.push([ps.x as f32, ps.y as f32, ps.z as f32]);
pts.push([
(ps.x + t * nx) as f32,
(ps.y + t * ny) as f32,
(ps.z + t * nz) as f32,
]);
pts.push([f32::NAN; 3]);
pts.push([ps.x, ps.y, ps.z]);
pts.push([ps.x + t * nx, ps.y + t * ny, ps.z + t * nz]);
pts.push([f64::NAN; 3]);
let pe = arc_pt(ea);
pts.push([pe.x as f32, pe.y as f32, pe.z as f32]);
pts.push([
(pe.x + t * nx) as f32,
(pe.y + t * ny) as f32,
(pe.z + t * nz) as f32,
]);
pts.push([pe.x, pe.y, pe.z]);
pts.push([pe.x + t * nx, pe.y + t * ny, pe.z + t * nz]);
return TruckEntity {
object: TruckObject::Lines(pts),
snap_pts: vec![(cv, SnapHint::Center)],