forked from 1b-agent/opencadstudio-upstream
refactor(snap): widen key_vertices to f64 (world_offset removal P4)
WireModel/LocalWire/BatchEntry key_vertices are now Vec<[f64; 3]>; tessellation keeps them in f64 (no f32 cast at offset subtraction), producers (dimension, leader, multileader) build them from the acadrust f64 source, the block-cache transform keeps f64, and the face3d Face3D quad path splits them into the double-single (high, low) pair. Consumers (snap endpoint/midpoint, xclip) read via f32 at the leaf. Still offset-relative (inert); endpoint/midpoint snap is no longer f32-capped. Co-Authored-By: Claude Opus 4.7 <[email protected]>
This commit is contained in:
1 parent
cd1d3bb619
commit
cca1086696
10 files changed
+54
-40
No files matched your search
Vendored
+3
-5
@@ -38,7 +38,7 @@ pub struct LocalWire {
|
||||
/// Low-bit residual paired with `points` so block-instance wires keep
|
||||
/// sub-f32 precision once the renderer translates them to world space.
|
||||
pub points_low: Vec<[f32; 3]>,
|
||||
pub key_vertices: Vec<[f32; 3]>,
|
||||
pub key_vertices: Vec<[f64; 3]>,
|
||||
pub snap_pts: Vec<(glam::DVec3, SnapHint)>,
|
||||
pub tangent_geoms: Vec<TangentGeom>,
|
||||
pub fill_tris: Vec<[f32; 3]>,
|
||||
@@ -1042,7 +1042,7 @@ struct BatchEntry {
|
||||
points: Vec<[f32; 3]>,
|
||||
points_low: Vec<[f32; 3]>,
|
||||
snap_pts: Vec<(glam::DVec3, SnapHint)>,
|
||||
key_vertices: Vec<[f32; 3]>,
|
||||
key_vertices: Vec<[f64; 3]>,
|
||||
tangent_geoms: Vec<TangentGeom>,
|
||||
fill_tris: Vec<[f32; 3]>,
|
||||
min_x: f32,
|
||||
@@ -1454,9 +1454,7 @@ fn emit_wire(
|
||||
p[1] as f64 + lo_y,
|
||||
p[2] as f64 + lo_z,
|
||||
));
|
||||
entry
|
||||
.key_vertices
|
||||
.push([(v.x - ox) as f32, (v.y - oy) as f32, (v.z - oz) as f32]);
|
||||
entry.key_vertices.push([v.x - ox, v.y - oy, v.z - oz]);
|
||||
}
|
||||
for (p, hint) in &lw.snap_pts {
|
||||
let v = accum_xform.apply(Vector3::new(
|
||||
|
||||
@@ -213,10 +213,10 @@ pub fn tessellate(
|
||||
}
|
||||
|
||||
let snap_pts = offset_snap_pts(te.snap_pts, world_offset);
|
||||
let key_vertices: Vec<[f32; 3]> = te
|
||||
let key_vertices: Vec<[f64; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| [(x - ox) as f32, (y - oy) as f32, (z - oz) as f32])
|
||||
.map(|[x, y, z]| [x - ox, y - oy, z - oz])
|
||||
.collect();
|
||||
|
||||
// Empty input (no glyphs) → emit a single empty wire so the
|
||||
@@ -293,12 +293,10 @@ pub fn tessellate(
|
||||
let s = 0.1_f32;
|
||||
let snap_pts = offset_snap_pts(te.snap_pts, world_offset);
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let key_vertices: Vec<[f32; 3]> = te
|
||||
let key_vertices: Vec<[f64; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
.map(|[kx, ky, kz]| {
|
||||
[(kx - ox) as f32, (ky - oy) as f32, (kz - oz) as f32]
|
||||
})
|
||||
.map(|[kx, ky, kz]| [kx - ox, ky - oy, kz - oz])
|
||||
.collect();
|
||||
return vec![WireModel {
|
||||
name,
|
||||
@@ -339,10 +337,10 @@ pub fn tessellate(
|
||||
{
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let snap_pts = offset_snap_pts(te.snap_pts, world_offset);
|
||||
let key_vertices: Vec<[f32; 3]> = te
|
||||
let key_vertices: Vec<[f64; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| [(x - ox) as f32, (y - oy) as f32, (z - oz) as f32])
|
||||
.map(|[x, y, z]| [x - ox, y - oy, z - oz])
|
||||
.collect();
|
||||
return vec![WireModel {
|
||||
name,
|
||||
@@ -372,10 +370,10 @@ pub fn tessellate(
|
||||
{
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let snap_pts = offset_snap_pts(te.snap_pts, world_offset);
|
||||
let key_vertices: Vec<[f32; 3]> = te
|
||||
let key_vertices: Vec<[f64; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| [(x - ox) as f32, (y - oy) as f32, (z - oz) as f32])
|
||||
.map(|[x, y, z]| [x - ox, y - oy, z - oz])
|
||||
.collect();
|
||||
return vec![WireModel {
|
||||
name,
|
||||
@@ -409,10 +407,10 @@ pub fn tessellate(
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let (local_pts, local_pts_low) = offset_to_ds(points, world_offset);
|
||||
let snap_pts = offset_snap_pts(te.snap_pts, world_offset);
|
||||
let key_vertices: Vec<[f32; 3]> = te
|
||||
let key_vertices: Vec<[f64; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| [(x - ox) as f32, (y - oy) as f32, (z - oz) as f32])
|
||||
.map(|[x, y, z]| [x - ox, y - oy, z - oz])
|
||||
.collect();
|
||||
let (fill_tris, fill_tris_low) = offset_to_ds(te.fill_tris, world_offset);
|
||||
return vec![WireModel {
|
||||
@@ -440,10 +438,10 @@ pub fn tessellate(
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let (local_pts, local_pts_low) = offset_to_ds(points, world_offset);
|
||||
let snap_pts = offset_snap_pts(te.snap_pts, world_offset);
|
||||
let key_vertices: Vec<[f32; 3]> = te
|
||||
let key_vertices: Vec<[f64; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| [(x - ox) as f32, (y - oy) as f32, (z - oz) as f32])
|
||||
.map(|[x, y, z]| [x - ox, y - oy, z - oz])
|
||||
.collect();
|
||||
return vec![WireModel {
|
||||
name,
|
||||
@@ -491,6 +489,10 @@ pub fn tessellate(
|
||||
// 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();
|
||||
let key_vertices: Vec<[f64; 3]> = key_vertices
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| [x as f64, y as f64, z as f64])
|
||||
.collect();
|
||||
vec![WireModel {
|
||||
name,
|
||||
points,
|
||||
|
||||
+7
-7
@@ -3270,14 +3270,14 @@ impl Scene {
|
||||
for &[x, y, z] in &wire.key_vertices {
|
||||
if x.is_finite() && y.is_finite() && z.is_finite() {
|
||||
min = min.min(glam::Vec3::new(
|
||||
x + ox as f32,
|
||||
y + oy as f32,
|
||||
z + oz,
|
||||
(x + ox) as f32,
|
||||
(y + oy) as f32,
|
||||
(z + oz as f64) as f32,
|
||||
));
|
||||
max = max.max(glam::Vec3::new(
|
||||
x + ox as f32,
|
||||
y + oy as f32,
|
||||
z + oz,
|
||||
(x + ox) as f32,
|
||||
(y + oy) as f32,
|
||||
(z + oz as f64) as f32,
|
||||
));
|
||||
any = true;
|
||||
}
|
||||
@@ -8593,7 +8593,7 @@ fn lod_stub_wire(
|
||||
line_weight_px: 1.0,
|
||||
snap_pts: vec![],
|
||||
tangent_geoms: vec![],
|
||||
key_vertices: vec![[cx, cy, cz]],
|
||||
key_vertices: vec![[cx as f64, cy as f64, cz as f64]],
|
||||
aabb,
|
||||
plinegen: true,
|
||||
vp_scissor: None,
|
||||
|
||||
@@ -64,7 +64,7 @@ pub struct WireModel {
|
||||
/// True polyline vertices used for Endpoint/Midpoint snap.
|
||||
/// Non-empty only for entities with distinct vertex positions (Line, LwPolyline).
|
||||
/// Empty for tessellated curves (Circle, Arc, Ellipse) which use snap_pts instead.
|
||||
pub key_vertices: Vec<[f32; 3]>,
|
||||
pub key_vertices: Vec<[f64; 3]>,
|
||||
/// World-space 2-D bounding box [min_x, min_y, max_x, max_y].
|
||||
/// Set from acadrust `bounding_box()` in `tessellate_entity()`.
|
||||
/// Preview / interim wires use `UNBOUNDED_AABB` so they are never pre-rejected
|
||||
|
||||
@@ -103,7 +103,7 @@ pub fn clip_wires(wires: &mut Vec<WireModel>, poly: &[[f32; 2]]) {
|
||||
w.fill_tris = clip_triangles(&w.fill_tris, poly);
|
||||
}
|
||||
w.key_vertices
|
||||
.retain(|v| point_in_poly(v[0], v[1], poly));
|
||||
.retain(|v| point_in_poly(v[0] as f32, v[1] as f32, 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);
|
||||
}
|
||||
|
||||
@@ -126,11 +126,21 @@ impl Face3DGpu {
|
||||
let fill_color = [r * 0.45, g * 0.45, b * 0.45, a];
|
||||
let depth = depth_of(wire);
|
||||
let p = &wire.key_vertices;
|
||||
let v = |i: usize| Face3DVertex {
|
||||
position: p[i],
|
||||
color: fill_color,
|
||||
draw_depth: depth,
|
||||
position_low: [0.0; 3],
|
||||
// key_vertices are f64 (offset-relative); split into the
|
||||
// double-single (high, low) pair the face3d shader expects.
|
||||
let v = |i: usize| {
|
||||
let [x, y, z] = p[i];
|
||||
let h = [x as f32, y as f32, z as f32];
|
||||
Face3DVertex {
|
||||
position: h,
|
||||
color: fill_color,
|
||||
draw_depth: depth,
|
||||
position_low: [
|
||||
(x - h[0] as f64) as f32,
|
||||
(y - h[1] as f64) as f32,
|
||||
(z - h[2] as f64) as f32,
|
||||
],
|
||||
}
|
||||
};
|
||||
verts_3d.push(v(0));
|
||||
verts_3d.push(v(1));
|
||||
|
||||
Reference in new issue
Block a user