forked from 1b-agent/opencadstudio-upstream
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]>
207 lines
6.2 KiB
Rust
207 lines
6.2 KiB
Rust
// Ray / XLine draw commands.
|
|
//
|
|
// RAY — semi-infinite line: click base point, then click direction point.
|
|
// Produces a Ray entity; repeats until Enter/Esc.
|
|
// XLINE — infinite construction line: same two-click pattern, yields XLine.
|
|
|
|
use acadrust::entities::{Ray as RayEnt, XLine as XLineEnt};
|
|
use acadrust::types::Vector3;
|
|
use acadrust::EntityType;
|
|
|
|
use crate::command::{CadCommand, CmdResult};
|
|
use crate::scene::model::wire_model::WireModel;
|
|
use glam::DVec3;
|
|
|
|
const DISPLAY_EXTENT: f32 = 1_000_000.0;
|
|
|
|
// ── RAY ───────────────────────────────────────────────────────────────────
|
|
|
|
pub struct RayCommand {
|
|
base: Option<DVec3>,
|
|
}
|
|
|
|
impl RayCommand {
|
|
pub fn new() -> Self {
|
|
Self { base: None }
|
|
}
|
|
}
|
|
|
|
impl CadCommand for RayCommand {
|
|
fn name(&self) -> &'static str {
|
|
"RAY"
|
|
}
|
|
|
|
fn prompt(&self) -> String {
|
|
if self.base.is_none() {
|
|
"RAY Specify start point:".into()
|
|
} else {
|
|
"RAY Specify through point:".into()
|
|
}
|
|
}
|
|
|
|
fn options(&self) -> Vec<crate::command::CmdOption> {
|
|
use crate::command::CmdOption;
|
|
if self.base.is_some() {
|
|
vec![CmdOption::enter("Done")]
|
|
} else {
|
|
vec![]
|
|
}
|
|
}
|
|
|
|
fn on_point(&mut self, pt: DVec3) -> CmdResult {
|
|
if let Some(base) = self.base {
|
|
let dir = pt - base;
|
|
let len = dir.length();
|
|
if len < 1e-6 {
|
|
return CmdResult::NeedPoint;
|
|
}
|
|
let dir_n = dir / len;
|
|
let ray = RayEnt::new(
|
|
Vector3::new(base.x, base.y, base.z),
|
|
Vector3::new(dir_n.x, dir_n.y, dir_n.z),
|
|
);
|
|
// Stay active: new base = same base (can keep clicking through points)
|
|
// Actually AutoCAD prompts for new start after each ray — reset base.
|
|
self.base = None;
|
|
CmdResult::CommitEntity(EntityType::Ray(ray))
|
|
} else {
|
|
self.base = Some(pt);
|
|
CmdResult::NeedPoint
|
|
}
|
|
}
|
|
|
|
fn on_enter(&mut self) -> CmdResult {
|
|
CmdResult::Cancel
|
|
}
|
|
|
|
fn on_escape(&mut self) -> CmdResult {
|
|
CmdResult::Cancel
|
|
}
|
|
|
|
fn on_mouse_move(&mut self, pt: DVec3) -> Option<WireModel> {
|
|
let pt = pt.as_vec3();
|
|
let base = self.base?.as_vec3();
|
|
let dir = (pt - base).normalize_or_zero();
|
|
let far = base + dir * DISPLAY_EXTENT;
|
|
Some(WireModel {
|
|
text_verts: Vec::new(),
|
|
name: "ray_preview".into(),
|
|
points: vec![[base.x, base.y, base.z], [far.x, far.y, far.z]],
|
|
points_low: Vec::new(),
|
|
color: WireModel::CYAN,
|
|
selected: false,
|
|
pattern_length: 0.0,
|
|
pattern: [0.0; 8],
|
|
line_weight_px: 1.0,
|
|
snap_pts: vec![],
|
|
tangent_geoms: vec![],
|
|
aci: 0,
|
|
key_vertices: vec![],
|
|
aabb: WireModel::UNBOUNDED_AABB,
|
|
plinegen: true,
|
|
vp_scissor: None,
|
|
fill_tris: vec![],
|
|
fill_tris_low: Vec::new(),
|
|
})
|
|
}
|
|
}
|
|
|
|
// ── XLINE ─────────────────────────────────────────────────────────────────
|
|
|
|
pub struct XLineCommand {
|
|
base: Option<DVec3>,
|
|
}
|
|
|
|
impl XLineCommand {
|
|
pub fn new() -> Self {
|
|
Self { base: None }
|
|
}
|
|
}
|
|
|
|
impl CadCommand for XLineCommand {
|
|
fn name(&self) -> &'static str {
|
|
"XLINE"
|
|
}
|
|
|
|
fn prompt(&self) -> String {
|
|
if self.base.is_none() {
|
|
"XLINE Specify a point:".into()
|
|
} else {
|
|
"XLINE Specify through point:".into()
|
|
}
|
|
}
|
|
|
|
fn options(&self) -> Vec<crate::command::CmdOption> {
|
|
use crate::command::CmdOption;
|
|
if self.base.is_some() {
|
|
vec![CmdOption::enter("Done")]
|
|
} else {
|
|
vec![]
|
|
}
|
|
}
|
|
|
|
fn on_point(&mut self, pt: DVec3) -> CmdResult {
|
|
if let Some(base) = self.base {
|
|
let dir = pt - base;
|
|
let len = dir.length();
|
|
if len < 1e-6 {
|
|
return CmdResult::NeedPoint;
|
|
}
|
|
let dir_n = dir / len;
|
|
let xline = XLineEnt::new(
|
|
Vector3::new(base.x, base.y, base.z),
|
|
Vector3::new(dir_n.x, dir_n.y, dir_n.z),
|
|
);
|
|
self.base = None;
|
|
CmdResult::CommitEntity(EntityType::XLine(xline))
|
|
} else {
|
|
self.base = Some(pt);
|
|
CmdResult::NeedPoint
|
|
}
|
|
}
|
|
|
|
fn on_enter(&mut self) -> CmdResult {
|
|
CmdResult::Cancel
|
|
}
|
|
|
|
fn on_escape(&mut self) -> CmdResult {
|
|
CmdResult::Cancel
|
|
}
|
|
|
|
fn on_mouse_move(&mut self, pt: DVec3) -> Option<WireModel> {
|
|
let pt = pt.as_vec3();
|
|
let base = self.base?.as_vec3();
|
|
let dir = (pt - base).normalize_or_zero();
|
|
let far_pos = base + dir * DISPLAY_EXTENT;
|
|
let far_neg = base - dir * DISPLAY_EXTENT;
|
|
Some(WireModel {
|
|
text_verts: Vec::new(),
|
|
name: "xline_preview".into(),
|
|
points: vec![
|
|
[far_neg.x, far_neg.y, far_neg.z],
|
|
[far_pos.x, far_pos.y, far_pos.z],
|
|
],
|
|
points_low: Vec::new(),
|
|
color: WireModel::CYAN,
|
|
selected: false,
|
|
pattern_length: 0.0,
|
|
pattern: [0.0; 8],
|
|
line_weight_px: 1.0,
|
|
snap_pts: vec![],
|
|
tangent_geoms: vec![],
|
|
aci: 0,
|
|
key_vertices: vec![],
|
|
aabb: WireModel::UNBOUNDED_AABB,
|
|
plinegen: true,
|
|
vp_scissor: None,
|
|
fill_tris: vec![],
|
|
fill_tris_low: Vec::new(),
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
// ── Autocomplete registry ─────────────────────────────────
|
|
inventory::submit!(crate::command::CommandRegistration { names: &["RAY"] }); // RayCommand
|
|
inventory::submit!(crate::command::CommandRegistration { names: &["CONSTRUCTIONLINE", "XLINE"] }); // XLineCommand
|