forked from 1b-agent/opencadstudio-upstream
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:
1 parent
8ed10ceb2a
commit
57710eec2b
47 files changed
+699
-606
No files matched your search
@@ -10,17 +10,17 @@
|
||||
// With 2 pairs: translate + rotate (+ optional uniform scale to fit)
|
||||
|
||||
use acadrust::Handle;
|
||||
use glam::{DVec3, Vec3};
|
||||
use glam::DVec3;
|
||||
|
||||
use crate::command::{CadCommand, CmdResult, EntityTransform};
|
||||
|
||||
pub struct AlignCommand {
|
||||
state: AlignState,
|
||||
handles: Vec<Handle>,
|
||||
src1: Option<Vec3>,
|
||||
dst1: Option<Vec3>,
|
||||
src2: Option<Vec3>,
|
||||
dst2: Option<Vec3>,
|
||||
src1: Option<DVec3>,
|
||||
dst1: Option<DVec3>,
|
||||
src2: Option<DVec3>,
|
||||
dst2: Option<DVec3>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
@@ -74,7 +74,7 @@ impl CadCommand for AlignCommand {
|
||||
CmdResult::NeedPoint
|
||||
}
|
||||
|
||||
fn on_point(&mut self, pt: DVec3) -> CmdResult { let pt = pt.as_vec3();
|
||||
fn on_point(&mut self, pt: DVec3) -> CmdResult {
|
||||
match self.state {
|
||||
AlignState::Gathering => CmdResult::NeedPoint,
|
||||
AlignState::Src1 => {
|
||||
@@ -117,7 +117,7 @@ impl CadCommand for AlignCommand {
|
||||
let delta = d - s;
|
||||
CmdResult::TransformSelected(
|
||||
self.handles.clone(),
|
||||
EntityTransform::Translate(delta.as_dvec3()),
|
||||
EntityTransform::Translate(delta),
|
||||
)
|
||||
}
|
||||
_ => CmdResult::Cancel,
|
||||
@@ -163,7 +163,7 @@ impl AlignCommand {
|
||||
let delta = d1 - s1;
|
||||
return CmdResult::TransformSelected(
|
||||
self.handles.clone(),
|
||||
EntityTransform::Translate(delta.as_dvec3()),
|
||||
EntityTransform::Translate(delta),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -182,10 +182,12 @@ impl AlignCommand {
|
||||
// Compose via AlignTransform CmdResult
|
||||
CmdResult::AlignSelected {
|
||||
handles: self.handles.clone(),
|
||||
src1: s1.as_dvec3(),
|
||||
dst1: d1.as_dvec3(),
|
||||
angle_rad: angle,
|
||||
scale: scale_factor,
|
||||
src1: s1,
|
||||
dst1: d1,
|
||||
// Reference points (src1/dst1) stay f64 exact; the derived
|
||||
// similarity scalars feed the f32 EntityTransform, so downcast here.
|
||||
angle_rad: angle as f32,
|
||||
scale: scale_factor as f32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user