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 <[email protected]>
This commit is contained in:
1 parent
8ed10ceb2a
commit
57710eec2b
47 files changed
+699
-606
No files matched your search
@@ -10,10 +10,10 @@ use glam::{DVec3, Mat4, Vec3};
|
||||
/// World-space measurement axis for a linear dimension between `first` and
|
||||
/// `second`, chosen as the UCS X or Y axis (whichever the span is closer to).
|
||||
/// `ucs` is the UCS→wire affine; identity gives the world X/Y behaviour.
|
||||
fn measure_axis(first: Vec3, second: Vec3, ucs: Mat4) -> Vec3 {
|
||||
let ux = ucs.transform_vector3(Vec3::X).normalize_or(Vec3::X);
|
||||
let uy = ucs.transform_vector3(Vec3::Y).normalize_or(Vec3::Y);
|
||||
let du = ucs.inverse().transform_vector3(second - first);
|
||||
fn measure_axis(first: DVec3, second: DVec3, ucs: Mat4) -> DVec3 {
|
||||
let ux = ucs.transform_vector3(Vec3::X).normalize_or(Vec3::X).as_dvec3();
|
||||
let uy = ucs.transform_vector3(Vec3::Y).normalize_or(Vec3::Y).as_dvec3();
|
||||
let du = ucs.inverse().transform_vector3((second - first).as_vec3());
|
||||
if du.x.abs() >= du.y.abs() {
|
||||
ux
|
||||
} else {
|
||||
@@ -34,8 +34,8 @@ pub fn tool() -> ToolDef {
|
||||
|
||||
enum Step {
|
||||
FirstPoint,
|
||||
SecondPoint(Vec3),
|
||||
DimensionLine { first: Vec3, second: Vec3 },
|
||||
SecondPoint(DVec3),
|
||||
DimensionLine { first: DVec3, second: DVec3 },
|
||||
}
|
||||
|
||||
pub struct LinearDimensionCommand {
|
||||
@@ -91,7 +91,7 @@ impl CadCommand for LinearDimensionCommand {
|
||||
}
|
||||
}
|
||||
|
||||
fn on_point(&mut self, pt: DVec3) -> CmdResult { let pt = pt.as_vec3();
|
||||
fn on_point(&mut self, pt: DVec3) -> CmdResult {
|
||||
match self.step {
|
||||
Step::FirstPoint => {
|
||||
self.step = Step::SecondPoint(pt);
|
||||
@@ -106,7 +106,7 @@ impl CadCommand for LinearDimensionCommand {
|
||||
// Measure along the UCS axis the span is closest to; the DXF
|
||||
// rotation is that axis's angle in world space.
|
||||
let axis = measure_axis(first, second, self.ucs);
|
||||
dim.rotation = (axis.y as f64).atan2(axis.x as f64);
|
||||
dim.rotation = axis.y.atan2(axis.x);
|
||||
// Bake the UCS X-axis angle as the text rotation so the
|
||||
// measurement text reads horizontally in the UCS (i.e. square on
|
||||
// screen) regardless of the style's force-horizontal flags,
|
||||
@@ -200,7 +200,7 @@ impl CadCommand for LinearDimensionCommand {
|
||||
}
|
||||
}
|
||||
|
||||
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> {
|
||||
match self.step {
|
||||
Step::FirstPoint => None,
|
||||
Step::SecondPoint(first) => Some(preview_wire(vec![first, pt])),
|
||||
@@ -212,15 +212,18 @@ impl CadCommand for LinearDimensionCommand {
|
||||
}
|
||||
}
|
||||
|
||||
fn v3(pt: Vec3) -> Vector3 {
|
||||
Vector3::new(pt.x as f64, pt.y as f64, pt.z as f64)
|
||||
fn v3(pt: DVec3) -> Vector3 {
|
||||
Vector3::new(pt.x, pt.y, pt.z)
|
||||
}
|
||||
|
||||
fn preview_wire(points: Vec<Vec3>) -> WireModel {
|
||||
fn preview_wire(points: Vec<DVec3>) -> WireModel {
|
||||
WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "dimlinear_preview".to_string(),
|
||||
points: points.into_iter().map(|p| [p.x, p.y, p.z]).collect(),
|
||||
points: points
|
||||
.into_iter()
|
||||
.map(|p| [p.x as f32, p.y as f32, p.z as f32])
|
||||
.collect(),
|
||||
points_low: Vec::new(),
|
||||
color: WireModel::CYAN,
|
||||
selected: false,
|
||||
@@ -244,23 +247,23 @@ fn preview_wire(points: Vec<Vec3>) -> WireModel {
|
||||
/// single shared offset only lands both on the line when they are level, and
|
||||
/// tilts the dimension line when they are not (e.g. measuring across sloped
|
||||
/// points). See #181.
|
||||
fn dim_line_endpoints(first: Vec3, second: Vec3, def: Vec3, axis: Vec3) -> (Vec3, Vec3) {
|
||||
let perp = Vec3::new(-axis.y, axis.x, 0.0);
|
||||
fn dim_line_endpoints(first: DVec3, second: DVec3, def: DVec3, axis: DVec3) -> (DVec3, DVec3) {
|
||||
let perp = DVec3::new(-axis.y, axis.x, 0.0);
|
||||
let dperp = def.dot(perp);
|
||||
let d1 = first + perp * (dperp - first.dot(perp));
|
||||
let d2 = second + perp * (dperp - second.dot(perp));
|
||||
(d1, d2)
|
||||
}
|
||||
|
||||
fn linear_dimension_preview(first: Vec3, second: Vec3, def: Vec3, axis: Vec3) -> Vec<Vec3> {
|
||||
fn linear_dimension_preview(first: DVec3, second: DVec3, def: DVec3, axis: DVec3) -> Vec<DVec3> {
|
||||
let (d1, d2) = dim_line_endpoints(first, second, def, axis);
|
||||
let nan = Vec3::new(f32::NAN, f32::NAN, f32::NAN);
|
||||
let nan = DVec3::new(f64::NAN, f64::NAN, f64::NAN);
|
||||
vec![first, d1, nan, second, d2, nan, d1, d2]
|
||||
}
|
||||
|
||||
fn linear_text_pos(first: Vec3, second: Vec3, def: Vec3, axis: Vec3) -> Vec3 {
|
||||
fn linear_text_pos(first: DVec3, second: DVec3, def: DVec3, axis: DVec3) -> DVec3 {
|
||||
let (d1, d2) = dim_line_endpoints(first, second, def, axis);
|
||||
let perp = Vec3::new(-axis.y, axis.x, 0.0);
|
||||
let perp = DVec3::new(-axis.y, axis.x, 0.0);
|
||||
(d1 + d2) * 0.5 + perp * 0.15
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user