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
Vendored
+3
-7
@@ -39,7 +39,7 @@ pub struct LocalWire {
|
||||
/// sub-f32 precision once the renderer translates them to world space.
|
||||
pub points_low: 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 fill_tris: Vec<[f32; 3]>,
|
||||
pub color: [f32; 4],
|
||||
@@ -1041,7 +1041,7 @@ struct BatchEntry {
|
||||
plinegen: bool,
|
||||
points: 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]>,
|
||||
tangent_geoms: Vec<TangentGeom>,
|
||||
fill_tris: Vec<[f32; 3]>,
|
||||
@@ -1465,11 +1465,7 @@ fn emit_wire(
|
||||
p.z as f64 + lo_z,
|
||||
));
|
||||
entry.snap_pts.push((
|
||||
glam::Vec3::new(
|
||||
(v.x - ox) as f32,
|
||||
(v.y - oy) as f32,
|
||||
(v.z - oz) as f32,
|
||||
),
|
||||
glam::DVec3::new(v.x - ox, v.y - oy, v.z - oz),
|
||||
*hint,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ pub fn tessellate(
|
||||
// Add insertion snap at point_of_reference.
|
||||
let [ox, oy, oz] = world_offset;
|
||||
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));
|
||||
}
|
||||
return vec![wm];
|
||||
@@ -487,6 +487,10 @@ pub fn tessellate(
|
||||
|
||||
// ── Fallback for Viewport / Insert / Hatch / Ole2Frame ────────────────
|
||||
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 {
|
||||
name,
|
||||
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]));
|
||||
}
|
||||
|
||||
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;
|
||||
pts.into_iter()
|
||||
.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,
|
||||
)
|
||||
})
|
||||
|
||||
+1
-1
@@ -8229,7 +8229,7 @@ fn tessellate_entity(
|
||||
pattern_length: 0.0,
|
||||
pattern: [0.0; 8],
|
||||
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![],
|
||||
key_vertices: vec![],
|
||||
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).
|
||||
pub aci: u8,
|
||||
/// 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.
|
||||
/// Line/Arc entities: 1 entry. LwPolyline: 1 entry per segment.
|
||||
pub tangent_geoms: Vec<TangentGeom>,
|
||||
|
||||
@@ -104,7 +104,7 @@ pub fn clip_wires(wires: &mut Vec<WireModel>, poly: &[[f32; 2]]) {
|
||||
}
|
||||
w.key_vertices
|
||||
.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);
|
||||
}
|
||||
wires.retain(|w| !w.points.is_empty() || !w.fill_tris.is_empty());
|
||||
|
||||
Reference in new issue
Block a user