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

@ -9,14 +9,14 @@ use crate::scene::object::{GripApply, GripDef, PropSection};
use crate::scene::wire_model::SnapHint;
fn to_truck(ole: &Ole2Frame) -> TruckEntity {
let x0 = ole.upper_left_corner.x as f32;
let y0 = ole.lower_right_corner.y as f32;
let x1 = ole.lower_right_corner.x as f32;
let y1 = ole.upper_left_corner.y as f32;
let z = ole.upper_left_corner.z as f32;
let x0 = ole.upper_left_corner.x;
let y0 = ole.lower_right_corner.y;
let x1 = ole.lower_right_corner.x;
let y1 = ole.upper_left_corner.y;
let z = ole.upper_left_corner.z;
if (x1 - x0).abs() < 1e-6 && (y1 - y0).abs() < 1e-6 {
let s = 0.5_f32;
let s = 0.5_f64;
return TruckEntity {
object: TruckObject::Lines(vec![[-s, 0.0, z], [s, 0.0, z]]),
snap_pts: vec![],
@ -28,7 +28,7 @@ fn to_truck(ole: &Ole2Frame) -> TruckEntity {
let cx = (x0 + x1) * 0.5;
let cy = (y0 + y1) * 0.5;
let pts = vec![
let pts: Vec<[f64; 3]> = vec![
// Rectangle
[x0, y0, z],
[x1, y0, z],
@ -41,11 +41,11 @@ fn to_truck(ole: &Ole2Frame) -> TruckEntity {
// Diagonal X
[x0, y0, z],
[x1, y1, z],
[f32::NAN; 3],
[f64::NAN; 3],
[x1, y0, z],
[x0, y1, z],
];
let center = Vec3::new(cx, cy, z);
let center = Vec3::new(cx as f32, cy as f32, z as f32);
TruckEntity {
object: TruckObject::Lines(pts),
snap_pts: vec![(center, SnapHint::Center)],