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
+15
-14
@@ -11,7 +11,7 @@ use acadrust::EntityType;
|
||||
use crate::command::{CadCommand, CmdResult};
|
||||
use crate::modules::{IconKind, ModuleEvent, ToolDef};
|
||||
use crate::scene::model::wire_model::WireModel;
|
||||
use glam::{DVec3, Vec3};
|
||||
use glam::DVec3;
|
||||
|
||||
// ── Ribbon definition ─────────────────────────────────────────────────────
|
||||
|
||||
@@ -27,7 +27,7 @@ pub fn tool() -> ToolDef {
|
||||
// ── Command ───────────────────────────────────────────────────────────────
|
||||
|
||||
pub struct MviewCommand {
|
||||
corner1: Option<Vec3>,
|
||||
corner1: Option<DVec3>,
|
||||
}
|
||||
|
||||
impl MviewCommand {
|
||||
@@ -49,16 +49,16 @@ impl CadCommand for MviewCommand {
|
||||
}
|
||||
}
|
||||
|
||||
fn on_point(&mut self, pt: DVec3) -> CmdResult { let pt = pt.as_vec3();
|
||||
fn on_point(&mut self, pt: DVec3) -> CmdResult {
|
||||
if let Some(c1) = self.corner1 {
|
||||
let w = (pt.x - c1.x).abs() as f64;
|
||||
let h = (pt.y - c1.y).abs() as f64;
|
||||
let w = (pt.x - c1.x).abs();
|
||||
let h = (pt.y - c1.y).abs();
|
||||
if w < 1.0 || h < 1.0 {
|
||||
return CmdResult::Cancel;
|
||||
}
|
||||
let cx = ((c1.x + pt.x) / 2.0) as f64;
|
||||
let cy = ((c1.y + pt.y) / 2.0) as f64;
|
||||
let cz = c1.z as f64;
|
||||
let cx = (c1.x + pt.x) / 2.0;
|
||||
let cy = (c1.y + pt.y) / 2.0;
|
||||
let cz = c1.z;
|
||||
|
||||
let mut vp = Viewport::new();
|
||||
vp.center = Vector3::new(cx, cy, cz);
|
||||
@@ -77,17 +77,18 @@ impl CadCommand for MviewCommand {
|
||||
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 pt = pt.as_vec3();
|
||||
let c1 = self.corner1?;
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "mview_preview".to_string(),
|
||||
points: vec![
|
||||
[c1.x, c1.y, c1.z],
|
||||
[pt.x, c1.y, c1.z],
|
||||
[pt.x, pt.y, c1.z],
|
||||
[c1.x, pt.y, c1.z],
|
||||
[c1.x, c1.y, c1.z],
|
||||
[c1.x as f32, c1.y as f32, c1.z as f32],
|
||||
[pt.x, c1.y as f32, c1.z as f32],
|
||||
[pt.x, pt.y, c1.z as f32],
|
||||
[c1.x as f32, pt.y, c1.z as f32],
|
||||
[c1.x as f32, c1.y as f32, c1.z as f32],
|
||||
],
|
||||
points_low: Vec::new(),
|
||||
color: WireModel::CYAN,
|
||||
|
||||
Reference in new issue
Block a user