forked from 1b-agent/opencadstudio-upstream
refactor(snap): widen snap_pts to f64 (world_offset removal P2)
WireModel/LocalWire/TruckEntity snap buffers and the producers/consumers now carry snap candidates as DVec3 (offset_snap_pts, dimension/multileader producers, block-cache transform, pick/xclip, snap module). Still offset-relative, so behaviour is unchanged — this just lets the snap transport survive the upcoming switch to absolute coordinates without an extra f32 quantization. The snap module still resolves in f32 (as_vec3 at entry), matching today's precision. Co-Authored-By: Claude Opus 4.7 <[email protected]>
This commit is contained in:
1 parent
ab7cd63dec
commit
a7a1fac09a
8 files changed
+30
-26
No files matched your search
@@ -1837,12 +1837,12 @@ fn append_angular_dimension(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dimension_snap_pts(dim: &Dimension, world_offset: [f64; 3]) -> Vec<(Vec3, SnapHint)> {
|
fn dimension_snap_pts(dim: &Dimension, world_offset: [f64; 3]) -> Vec<(glam::DVec3, SnapHint)> {
|
||||||
let lv = |v: acadrust::types::Vector3| {
|
let lv = |v: acadrust::types::Vector3| {
|
||||||
Vec3::new(
|
glam::DVec3::new(
|
||||||
(v.x - world_offset[0]) as f32,
|
v.x - world_offset[0],
|
||||||
(v.y - world_offset[1]) as f32,
|
v.y - world_offset[1],
|
||||||
(v.z - world_offset[2]) as f32,
|
v.z - world_offset[2],
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
let node = |v: acadrust::types::Vector3| (lv(v), SnapHint::Node);
|
let node = |v: acadrust::types::Vector3| (lv(v), SnapHint::Node);
|
||||||
|
|||||||
@@ -77,10 +77,11 @@ fn to_truck(ml: &MultiLeader, document: &acadrust::CadDocument) -> Option<TruckE
|
|||||||
let mut points: Vec<[f64; 3]> = Vec::new();
|
let mut points: Vec<[f64; 3]> = Vec::new();
|
||||||
let mut tangents: Vec<TangentGeom> = Vec::new();
|
let mut tangents: Vec<TangentGeom> = Vec::new();
|
||||||
let mut key_verts: Vec<[f64; 3]> = Vec::new();
|
let mut key_verts: Vec<[f64; 3]> = Vec::new();
|
||||||
|
// This builds a TruckEntity (snap_pts in Vec3); tessellate's
|
||||||
|
// offset_snap_pts widens it to the f64 WireModel buffer afterwards.
|
||||||
let mut snap_pts: Vec<(Vec3, SnapHint)> = Vec::new();
|
let mut snap_pts: Vec<(Vec3, SnapHint)> = Vec::new();
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
|
|
||||||
// snap_pts uses f32 (UI-only); cast at construction.
|
|
||||||
let node = |arr: [f64; 3]| {
|
let node = |arr: [f64; 3]| {
|
||||||
(
|
(
|
||||||
Vec3::new(arr[0] as f32, arr[1] as f32, arr[2] as f32),
|
Vec3::new(arr[0] as f32, arr[1] as f32, arr[2] as f32),
|
||||||
@@ -1168,7 +1169,7 @@ impl MultiLeaderTess for MultiLeader {
|
|||||||
// ── Leader / arrow / dogleg points ───────────────────────────────────────
|
// ── Leader / arrow / dogleg points ───────────────────────────────────────
|
||||||
let mut points: Vec<[f32; 3]> = Vec::new();
|
let mut points: Vec<[f32; 3]> = Vec::new();
|
||||||
let mut key_verts: Vec<[f32; 3]> = Vec::new();
|
let mut key_verts: Vec<[f32; 3]> = Vec::new();
|
||||||
let mut snap_pts: Vec<(Vec3, SnapHint)> = Vec::new();
|
let mut snap_pts: Vec<(glam::DVec3, SnapHint)> = Vec::new();
|
||||||
let mut tangents: Vec<TangentGeom> = Vec::new();
|
let mut tangents: Vec<TangentGeom> = Vec::new();
|
||||||
let mut arrow_fill: Vec<[f32; 3]> = Vec::new();
|
let mut arrow_fill: Vec<[f32; 3]> = Vec::new();
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
@@ -1194,7 +1195,7 @@ impl MultiLeaderTess for MultiLeader {
|
|||||||
for root in &ml.context.leader_roots {
|
for root in &ml.context.leader_roots {
|
||||||
let cp = &root.connection_point;
|
let cp = &root.connection_point;
|
||||||
let cp_f = p3(cp);
|
let cp_f = p3(cp);
|
||||||
snap_pts.push((Vec3::from(cp_f), SnapHint::Node));
|
snap_pts.push((Vec3::from(cp_f).as_dvec3(), SnapHint::Node));
|
||||||
|
|
||||||
for line in &root.lines {
|
for line in &root.lines {
|
||||||
if line.points.is_empty() {
|
if line.points.is_empty() {
|
||||||
@@ -1216,7 +1217,7 @@ impl MultiLeaderTess for MultiLeader {
|
|||||||
}
|
}
|
||||||
for &c in &ctrl {
|
for &c in &ctrl {
|
||||||
key_verts.push(c);
|
key_verts.push(c);
|
||||||
snap_pts.push((Vec3::from(c), SnapHint::Node));
|
snap_pts.push((Vec3::from(c).as_dvec3(), SnapHint::Node));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ml.path_type == MultiLeaderPathType::Spline && ctrl.len() >= 2 {
|
if ml.path_type == MultiLeaderPathType::Spline && ctrl.len() >= 2 {
|
||||||
@@ -1550,7 +1551,7 @@ impl MultiLeaderTess for MultiLeader {
|
|||||||
pattern_length: 0.0,
|
pattern_length: 0.0,
|
||||||
pattern: [0.0; 8],
|
pattern: [0.0; 8],
|
||||||
line_weight_px,
|
line_weight_px,
|
||||||
snap_pts: vec![(Vec3::new(local_ins_x, local_ins_y, z), SnapHint::Node)],
|
snap_pts: vec![(glam::DVec3::new(local_ins_x as f64, local_ins_y as f64, z as f64), SnapHint::Node)],
|
||||||
tangent_geoms: vec![],
|
tangent_geoms: vec![],
|
||||||
key_vertices: vec![],
|
key_vertices: vec![],
|
||||||
aabb: WireModel::UNBOUNDED_AABB,
|
aabb: WireModel::UNBOUNDED_AABB,
|
||||||
@@ -1592,7 +1593,7 @@ impl MultiLeaderTess for MultiLeader {
|
|||||||
pattern_length: 0.0,
|
pattern_length: 0.0,
|
||||||
pattern: [0.0; 8],
|
pattern: [0.0; 8],
|
||||||
line_weight_px: 1.0,
|
line_weight_px: 1.0,
|
||||||
snap_pts: vec![(Vec3::new(local_ins_x, local_ins_y, z), SnapHint::Node)],
|
snap_pts: vec![(glam::DVec3::new(local_ins_x as f64, local_ins_y as f64, z as f64), SnapHint::Node)],
|
||||||
tangent_geoms: vec![],
|
tangent_geoms: vec![],
|
||||||
key_vertices: vec![],
|
key_vertices: vec![],
|
||||||
aabb: WireModel::UNBOUNDED_AABB,
|
aabb: WireModel::UNBOUNDED_AABB,
|
||||||
@@ -1632,7 +1633,7 @@ impl MultiLeaderTess for MultiLeader {
|
|||||||
pattern_length: 0.0,
|
pattern_length: 0.0,
|
||||||
pattern: [0.0; 8],
|
pattern: [0.0; 8],
|
||||||
line_weight_px,
|
line_weight_px,
|
||||||
snap_pts: vec![(Vec3::new(local_ins_x, local_ins_y, z), SnapHint::Node)],
|
snap_pts: vec![(glam::DVec3::new(local_ins_x as f64, local_ins_y as f64, z as f64), SnapHint::Node)],
|
||||||
tangent_geoms: vec![],
|
tangent_geoms: vec![],
|
||||||
key_vertices: vec![],
|
key_vertices: vec![],
|
||||||
aabb: WireModel::UNBOUNDED_AABB,
|
aabb: WireModel::UNBOUNDED_AABB,
|
||||||
|
|||||||
Vendored
+3
-7
@@ -39,7 +39,7 @@ pub struct LocalWire {
|
|||||||
/// sub-f32 precision once the renderer translates them to world space.
|
/// sub-f32 precision once the renderer translates them to world space.
|
||||||
pub points_low: Vec<[f32; 3]>,
|
pub points_low: Vec<[f32; 3]>,
|
||||||
pub key_vertices: Vec<[f32; 3]>,
|
pub key_vertices: Vec<[f32; 3]>,
|
||||||
pub snap_pts: Vec<(glam::Vec3, SnapHint)>,
|
pub snap_pts: Vec<(glam::DVec3, SnapHint)>,
|
||||||
pub tangent_geoms: Vec<TangentGeom>,
|
pub tangent_geoms: Vec<TangentGeom>,
|
||||||
pub fill_tris: Vec<[f32; 3]>,
|
pub fill_tris: Vec<[f32; 3]>,
|
||||||
pub color: [f32; 4],
|
pub color: [f32; 4],
|
||||||
@@ -1041,7 +1041,7 @@ struct BatchEntry {
|
|||||||
plinegen: bool,
|
plinegen: bool,
|
||||||
points: Vec<[f32; 3]>,
|
points: Vec<[f32; 3]>,
|
||||||
points_low: Vec<[f32; 3]>,
|
points_low: Vec<[f32; 3]>,
|
||||||
snap_pts: Vec<(glam::Vec3, SnapHint)>,
|
snap_pts: Vec<(glam::DVec3, SnapHint)>,
|
||||||
key_vertices: Vec<[f32; 3]>,
|
key_vertices: Vec<[f32; 3]>,
|
||||||
tangent_geoms: Vec<TangentGeom>,
|
tangent_geoms: Vec<TangentGeom>,
|
||||||
fill_tris: Vec<[f32; 3]>,
|
fill_tris: Vec<[f32; 3]>,
|
||||||
@@ -1465,11 +1465,7 @@ fn emit_wire(
|
|||||||
p.z as f64 + lo_z,
|
p.z as f64 + lo_z,
|
||||||
));
|
));
|
||||||
entry.snap_pts.push((
|
entry.snap_pts.push((
|
||||||
glam::Vec3::new(
|
glam::DVec3::new(v.x - ox, v.y - oy, v.z - oz),
|
||||||
(v.x - ox) as f32,
|
|
||||||
(v.y - oy) as f32,
|
|
||||||
(v.z - oz) as f32,
|
|
||||||
),
|
|
||||||
*hint,
|
*hint,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -477,7 +477,7 @@ pub fn tessellate(
|
|||||||
// Add insertion snap at point_of_reference.
|
// Add insertion snap at point_of_reference.
|
||||||
let [ox, oy, oz] = world_offset;
|
let [ox, oy, oz] = world_offset;
|
||||||
if let Some(p) = crate::entities::solid3d::point_of_reference(entity) {
|
if let Some(p) = crate::entities::solid3d::point_of_reference(entity) {
|
||||||
let sp = Vec3::new((p.x - ox) as f32, (p.y - oy) as f32, (p.z - oz) as f32);
|
let sp = glam::DVec3::new(p.x - ox, p.y - oy, p.z - oz);
|
||||||
wm.snap_pts.push((sp, SnapHint::Insertion));
|
wm.snap_pts.push((sp, SnapHint::Insertion));
|
||||||
}
|
}
|
||||||
return vec![wm];
|
return vec![wm];
|
||||||
@@ -487,6 +487,10 @@ pub fn tessellate(
|
|||||||
|
|
||||||
// ── Fallback for Viewport / Insert / Hatch / Ole2Frame ────────────────
|
// ── Fallback for Viewport / Insert / Hatch / Ole2Frame ────────────────
|
||||||
let (points, snap_pts, tangent_geoms, key_vertices) = fallback_geometry(entity, world_offset);
|
let (points, snap_pts, tangent_geoms, key_vertices) = fallback_geometry(entity, world_offset);
|
||||||
|
// fallback_geometry still emits offset-relative f32 snap points; widen to
|
||||||
|
// f64 for the WireModel's double-single-era snap buffer.
|
||||||
|
let snap_pts: Vec<(glam::DVec3, SnapHint)> =
|
||||||
|
snap_pts.into_iter().map(|(p, h)| (p.as_dvec3(), h)).collect();
|
||||||
vec![WireModel {
|
vec![WireModel {
|
||||||
name,
|
name,
|
||||||
points,
|
points,
|
||||||
@@ -858,12 +862,15 @@ pub(crate) fn add_polyline(points: &mut Vec<[f32; 3]>, polyline: &[Vec3]) {
|
|||||||
points.extend(polyline.iter().map(|p| [p.x, p.y, p.z]));
|
points.extend(polyline.iter().map(|p| [p.x, p.y, p.z]));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn offset_snap_pts(pts: Vec<(Vec3, SnapHint)>, off: [f64; 3]) -> Vec<(Vec3, SnapHint)> {
|
pub(crate) fn offset_snap_pts(
|
||||||
|
pts: Vec<(Vec3, SnapHint)>,
|
||||||
|
off: [f64; 3],
|
||||||
|
) -> Vec<(glam::DVec3, SnapHint)> {
|
||||||
let [ox, oy, oz] = off;
|
let [ox, oy, oz] = off;
|
||||||
pts.into_iter()
|
pts.into_iter()
|
||||||
.map(|(p, h)| {
|
.map(|(p, h)| {
|
||||||
(
|
(
|
||||||
Vec3::new(p.x - ox as f32, p.y - oy as f32, p.z - oz as f32),
|
glam::DVec3::new(p.x as f64 - ox, p.y as f64 - oy, p.z as f64 - oz),
|
||||||
h,
|
h,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
+1
-1
@@ -8229,7 +8229,7 @@ fn tessellate_entity(
|
|||||||
pattern_length: 0.0,
|
pattern_length: 0.0,
|
||||||
pattern: [0.0; 8],
|
pattern: [0.0; 8],
|
||||||
line_weight_px: 1.0,
|
line_weight_px: 1.0,
|
||||||
snap_pts: vec![(ip, model::wire_model::SnapHint::Insertion)],
|
snap_pts: vec![(ip.as_dvec3(), model::wire_model::SnapHint::Insertion)],
|
||||||
tangent_geoms: vec![],
|
tangent_geoms: vec![],
|
||||||
key_vertices: vec![],
|
key_vertices: vec![],
|
||||||
aabb: WireModel::UNBOUNDED_AABB,
|
aabb: WireModel::UNBOUNDED_AABB,
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ pub struct WireModel {
|
|||||||
/// ACI color index (1-255). 0 means true-color or unknown (no CTB lookup).
|
/// ACI color index (1-255). 0 means true-color or unknown (no CTB lookup).
|
||||||
pub aci: u8,
|
pub aci: u8,
|
||||||
/// Pre-baked snap candidates (Center, Node, Quadrant, Insertion).
|
/// Pre-baked snap candidates (Center, Node, Quadrant, Insertion).
|
||||||
pub snap_pts: Vec<(glam::Vec3, SnapHint)>,
|
pub snap_pts: Vec<(glam::DVec3, SnapHint)>,
|
||||||
/// Per-segment tangent geometry for Tangent snap.
|
/// Per-segment tangent geometry for Tangent snap.
|
||||||
/// Line/Arc entities: 1 entry. LwPolyline: 1 entry per segment.
|
/// Line/Arc entities: 1 entry. LwPolyline: 1 entry per segment.
|
||||||
pub tangent_geoms: Vec<TangentGeom>,
|
pub tangent_geoms: Vec<TangentGeom>,
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ pub fn clip_wires(wires: &mut Vec<WireModel>, poly: &[[f32; 2]]) {
|
|||||||
}
|
}
|
||||||
w.key_vertices
|
w.key_vertices
|
||||||
.retain(|v| point_in_poly(v[0], v[1], poly));
|
.retain(|v| point_in_poly(v[0], v[1], poly));
|
||||||
w.snap_pts.retain(|(p, _)| point_in_poly(p.x, p.y, poly));
|
w.snap_pts.retain(|(p, _)| point_in_poly(p.x as f32, p.y as f32, poly));
|
||||||
w.aabb = recompute_aabb(&w.points, &w.fill_tris);
|
w.aabb = recompute_aabb(&w.points, &w.fill_tris);
|
||||||
}
|
}
|
||||||
wires.retain(|w| !w.points.is_empty() || !w.fill_tris.is_empty());
|
wires.retain(|w| !w.points.is_empty() || !w.fill_tris.is_empty());
|
||||||
|
|||||||
+1
-1
@@ -528,7 +528,7 @@ impl Snapper {
|
|||||||
SnapHint::Midpoint => SnapType::Midpoint,
|
SnapHint::Midpoint => SnapType::Midpoint,
|
||||||
};
|
};
|
||||||
if self.is_on(snap_type) {
|
if self.is_on(snap_type) {
|
||||||
try_pt(world, snap_type);
|
try_pt(world.as_vec3(), snap_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user