wip(f64): convert command layer to DVec3 (in progress)

Migrate the command/snap/grip/cursor chain from f32 Vec3 to f64 DVec3 so
picked points, snaps and grip drags stay precise at UTM-scale coordinates
(f32 quantizes to ~0.5 m there).

Done so far:
- command/mod.rs: EntityTransform, CmdResult points, CadCommand point
  methods, TangentObject already DVec3 (radius f64).
- snap: SnapResult.world DVec3; world_to_screen/try_pt DVec3.
- GripApply -> DVec3; grip find/state (GripEdit) f64; camera
  pick_on_plane_f64 / pick_on_target_plane_f64; scene paper_to_model_f64.
- update.rs click + mouse-move + grip-drag pipelines route precise DVec3
  to on_point/on_preview_wires/on_entity_pick; ortho/polar cast at the
  UcsXform boundary only.
- cmd_result dispatch, transform helpers, dimension/arc/circle/multileader
  apply_grip, circle/arc/ellipse/shapes draw commands, array modify.

Tree does NOT compile yet (~236 errors remain across modify/annotate/
insert command files + entity apply_grip impls); committed at user request
to checkpoint progress.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-06-24 03:32:11 +03:00
commit 3da71698b1
18 changed files with 626 additions and 587 deletions

View file

@ -157,37 +157,37 @@ fn apply_geom_prop(arc: &mut Arc, field: &str, value: &str) {
fn apply_grip(arc: &mut Arc, grip_id: usize, apply: GripApply) {
match (grip_id, apply) {
(0, GripApply::Translate(d)) => {
arc.center.x += d.x as f64;
arc.center.y += d.y as f64;
arc.center.z += d.z as f64;
arc.center.x += d.x;
arc.center.y += d.y;
arc.center.z += d.z;
}
(0, GripApply::Absolute(p)) => {
arc.center.x = p.x as f64;
arc.center.y = p.y as f64;
arc.center.z = p.z as f64;
arc.center.x = p.x;
arc.center.y = p.y;
arc.center.z = p.z;
}
(1, GripApply::Absolute(p)) => {
let dx = p.x - arc.center.x as f32;
let dy = p.y - arc.center.y as f32;
arc.start_angle = (dy as f64).atan2(dx as f64);
let dx = p.x - arc.center.x;
let dy = p.y - arc.center.y;
arc.start_angle = dy.atan2(dx);
}
(2, GripApply::Absolute(p)) => {
let dx = p.x - arc.center.x as f32;
let dy = p.y - arc.center.y as f32;
arc.end_angle = (dy as f64).atan2(dx as f64);
let dx = p.x - arc.center.x;
let dy = p.y - arc.center.y;
arc.end_angle = dy.atan2(dx);
}
(3, GripApply::Translate(d)) => {
let sa = arc.start_angle as f32;
let ea = arc.end_angle as f32;
let span = angle_span(sa, ea);
let sa = arc.start_angle;
let ea = arc.end_angle;
let span = angle_span(sa as f32, ea as f32) as f64;
let mid_a = sa + span * 0.5;
let current_mid_x = arc.center.x as f32 + arc.radius as f32 * mid_a.cos();
let current_mid_y = arc.center.y as f32 + arc.radius as f32 * mid_a.sin();
let current_mid_x = arc.center.x + arc.radius * mid_a.cos();
let current_mid_y = arc.center.y + arc.radius * mid_a.sin();
let new_mid_x = current_mid_x + d.x;
let new_mid_y = current_mid_y + d.y;
let dx = new_mid_x - arc.center.x as f32;
let dy = new_mid_y - arc.center.y as f32;
let new_r = (dx * dx + dy * dy).sqrt() as f64;
let dx = new_mid_x - arc.center.x;
let dy = new_mid_y - arc.center.y;
let new_r = (dx * dx + dy * dy).sqrt();
if new_r > 1e-6 {
arc.radius = new_r;
}

View file

@ -166,11 +166,9 @@ fn apply_grip(circle: &mut Circle, grip_id: usize, apply: GripApply) {
circle.center.z += d.z as f64;
}
(1..=4, GripApply::Absolute(p)) => {
let cx = circle.center.x as f32;
let cy = circle.center.y as f32;
let dx = p.x - cx;
let dy = p.y - cy;
circle.radius = ((dx * dx + dy * dy) as f64).sqrt();
let dx = p.x - circle.center.x;
let dy = p.y - circle.center.y;
circle.radius = (dx * dx + dy * dy).sqrt();
}
_ => {}
}

View file

@ -3,7 +3,7 @@ use acadrust::entities::{
DimensionDiameter, DimensionLinear, DimensionOrdinate, DimensionRadius,
};
use acadrust::Entity;
use glam::Vec3;
use glam::{DVec3, Vec3};
use crate::command::EntityTransform;
use crate::entities::common::{
@ -540,21 +540,22 @@ where
}
}
fn rotate_point(p: &mut acadrust::types::Vector3, center: Vec3, angle_rad: f32) {
let dx = p.x as f32 - center.x;
let dy = p.y as f32 - center.y;
let (s, c) = angle_rad.sin_cos();
p.x = (center.x + dx * c - dy * s) as f64;
p.y = (center.y + dx * s + dy * c) as f64;
fn rotate_point(p: &mut acadrust::types::Vector3, center: DVec3, angle_rad: f32) {
let dx = p.x - center.x;
let dy = p.y - center.y;
let (s, c) = (angle_rad as f64).sin_cos();
p.x = center.x + dx * c - dy * s;
p.y = center.y + dx * s + dy * c;
}
fn scale_point(p: &mut acadrust::types::Vector3, center: Vec3, factor: f32) {
p.x = (center.x + (p.x as f32 - center.x) * factor) as f64;
p.y = (center.y + (p.y as f32 - center.y) * factor) as f64;
p.z = (center.z + (p.z as f32 - center.z) * factor) as f64;
fn scale_point(p: &mut acadrust::types::Vector3, center: DVec3, factor: f32) {
let f = factor as f64;
p.x = center.x + (p.x - center.x) * f;
p.y = center.y + (p.y - center.y) * f;
p.z = center.z + (p.z - center.z) * f;
}
fn mirror_point(p: &mut acadrust::types::Vector3, p1: Vec3, p2: Vec3) {
fn mirror_point(p: &mut acadrust::types::Vector3, p1: DVec3, p2: DVec3) {
crate::scene::view::transform::reflect_xy_point(&mut p.x, &mut p.y, p1, p2);
}
@ -582,16 +583,16 @@ fn dv3(v: &acadrust::types::Vector3) -> glam::DVec3 {
glam::DVec3::new(v.x, v.y, v.z)
}
fn set_v3(target: &mut acadrust::types::Vector3, p: Vec3) {
target.x = p.x as f64;
target.y = p.y as f64;
target.z = p.z as f64;
fn set_v3(target: &mut acadrust::types::Vector3, p: DVec3) {
target.x = p.x;
target.y = p.y;
target.z = p.z;
}
fn translate_v3(target: &mut acadrust::types::Vector3, d: Vec3) {
target.x += d.x as f64;
target.y += d.y as f64;
target.z += d.z as f64;
fn translate_v3(target: &mut acadrust::types::Vector3, d: DVec3) {
target.x += d.x;
target.y += d.y;
target.z += d.z;
}
fn apply_to_v3(target: &mut acadrust::types::Vector3, apply: &GripApply) {

View file

@ -24,7 +24,7 @@ pub(crate) fn mleader_v_anchor(attach: TextAttachmentType) -> MTextVAnchor {
| TextAttachmentType::BottomOfTopLineUnderlineAll => MTextVAnchor::BottomOfTopLine,
}
}
use glam::Vec3;
use glam::{DVec3, Vec3};
use crate::command::EntityTransform;
use crate::entities::common::{
@ -920,9 +920,9 @@ fn apply_transform(ml: &mut MultiLeader, t: &EntityTransform) {
/// Reflect a direction (not position) vector across the mirror line p1→p2.
/// Reflecting a direction is the same as reflecting `p1 + dir` then subtracting
/// the reflection of `p1`, which simplifies to reflecting around the origin.
fn reflect_xy_direction(dx: &mut f64, dy: &mut f64, p1: Vec3, p2: Vec3) {
let zero = Vec3::ZERO;
let p2_rel = Vec3::new(p2.x - p1.x, p2.y - p1.y, 0.0);
fn reflect_xy_direction(dx: &mut f64, dy: &mut f64, p1: DVec3, p2: DVec3) {
let zero = DVec3::ZERO;
let p2_rel = DVec3::new(p2.x - p1.x, p2.y - p1.y, 0.0);
let mut tip_x = *dx;
let mut tip_y = *dy;
crate::scene::view::transform::reflect_xy_point(&mut tip_x, &mut tip_y, zero, p2_rel);