refactor: drop residual zero-subtraction from world_offset removal

In the files where ox/oy/oz came solely from the now-zero offset
destructure (tessellate, block_cache, dimension, leader, text_support),
remove the `let [ox,oy,oz] = [0,0,0]` binding and the `- ox` arithmetic so
the coordinate math reads as the plain absolute value it now is.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-06-24 18:38:23 +03:00
commit 29415cac20
5 changed files with 46 additions and 66 deletions

View file

@ -1449,10 +1449,9 @@ fn text_fill_rect(
let (sr, cr) = rot.sin_cos(); let (sr, cr) = rot.sin_cos();
let hx = approx_w * 0.5; let hx = approx_w * 0.5;
let hy = approx_h * 0.5; let hy = approx_h * 0.5;
let [ox, oy, oz] = [0.0_f64; 3]; let cx = (pos.x) as f32;
let cx = (pos.x - ox) as f32; let cy = (pos.y) as f32;
let cy = (pos.y - oy) as f32; let cz = (pos.z) as f32;
let cz = (pos.z - oz) as f32;
let corner = |dx: f64, dy: f64| -> [f32; 3] { let corner = |dx: f64, dy: f64| -> [f32; 3] {
let lx = dx * cr - dy * sr; let lx = dx * cr - dy * sr;
let ly = dx * sr + dy * cr; let ly = dx * sr + dy * cr;

View file

@ -589,9 +589,8 @@ impl LeaderTess for Leader {
entity_color entity_color
}; };
let name = handle.value().to_string(); let name = handle.value().to_string();
let [ox, oy, oz] = [0.0_f64; 3];
let p3 = |v: &acadrust::types::Vector3| -> [f32; 3] { let p3 = |v: &acadrust::types::Vector3| -> [f32; 3] {
[(v.x - ox) as f32, (v.y - oy) as f32, (v.z - oz) as f32] [(v.x) as f32, (v.y) as f32, (v.z) as f32]
}; };
let nan = [f32::NAN; 3]; let nan = [f32::NAN; 3];

View file

@ -1722,9 +1722,8 @@ pub(crate) fn text_baseline_points(
return vec![]; return vec![];
} }
let n_lines = n_lines.max(1); let n_lines = n_lines.max(1);
let [ox, oy, oz] = [0.0_f64; 3];
let cast = |p: [f64; 3]| -> [f32; 3] { let cast = |p: [f64; 3]| -> [f32; 3] {
[(p[0] - ox) as f32, (p[1] - oy) as f32, (p[2] - oz) as f32] [(p[0]) as f32, (p[1]) as f32, (p[2]) as f32]
}; };
let bl = cast(corners[0]); let bl = cast(corners[0]);
let br = cast(corners[1]); let br = cast(corners[1]);
@ -1782,9 +1781,8 @@ pub(crate) fn text_greek_obb_tris(
return vec![]; return vec![];
} }
let n_lines = n_lines.max(1); let n_lines = n_lines.max(1);
let [ox, oy, oz] = [0.0_f64; 3];
let cast = |p: [f64; 3]| -> [f32; 3] { let cast = |p: [f64; 3]| -> [f32; 3] {
[(p[0] - ox) as f32, (p[1] - oy) as f32, (p[2] - oz) as f32] [(p[0]) as f32, (p[1]) as f32, (p[2]) as f32]
}; };
let bl = cast(corners[0]); let bl = cast(corners[0]);
let br = cast(corners[1]); let br = cast(corners[1]);

View file

@ -673,17 +673,16 @@ pub fn expand_insert(
let name = ins_handle.value().to_string(); let name = ins_handle.value().to_string();
let mut batches = Batches::default(); let mut batches = Batches::default();
let mut visited: Vec<String> = Vec::with_capacity(8); let mut visited: Vec<String> = Vec::with_capacity(8);
let [ox, oy, _] = [0.0_f64; 3];
// `defn.aabb_local` is in the defn's offset frame — re-add // `defn.aabb_local` is in the defn's offset frame — re-add
// `defn.local_offset` (f64) before transforming so the world AABB is // `defn.local_offset` (f64) before transforming so the world AABB is
// accurate for distant content. // accurate for distant content.
let insert_world = transform_offset_aabb_xy(defn.aabb_local, defn.local_offset, &xform); let insert_world = transform_offset_aabb_xy(defn.aabb_local, defn.local_offset, &xform);
let insert_local = [ let insert_local = [
insert_world[0] - ox as f32, insert_world[0] as f32,
insert_world[1] - oy as f32, insert_world[1] as f32,
insert_world[2] - ox as f32, insert_world[2] as f32,
insert_world[3] - oy as f32, insert_world[3] as f32,
]; ];
// Whole-Insert frustum cull. // Whole-Insert frustum cull.
@ -742,7 +741,6 @@ fn emit_greeked_text(
ctx: &ExpandCtx, ctx: &ExpandCtx,
out: &mut Batches, out: &mut Batches,
) { ) {
let [ox, oy, oz] = [0.0_f64; 3];
let [lo_x, lo_y, lo_z] = defn_lo; let [lo_x, lo_y, lo_z] = defn_lo;
// Re-add the defn's `local_offset` in f64 before composing with // Re-add the defn's `local_offset` in f64 before composing with
// `accum_xform` so the rect corners share the batch's f32 space // `accum_xform` so the rect corners share the batch's f32 space
@ -753,7 +751,7 @@ fn emit_greeked_text(
p[1] as f64 + lo_y, p[1] as f64 + lo_y,
p[2] as f64 + lo_z, p[2] as f64 + lo_z,
)); ));
[(w.x - ox) as f32, (w.y - oy) as f32, (w.z - oz) as f32] [(w.x) as f32, (w.y) as f32, (w.z) as f32]
}; };
// Per-line rects: split the OBB by `h_local` so each visible wrap // Per-line rects: split the OBB by `h_local` so each visible wrap
@ -877,7 +875,6 @@ fn emit_text_baseline(
if h_local <= 0.0 { if h_local <= 0.0 {
return; return;
} }
let [ox, oy, oz] = [0.0_f64; 3];
let [lo_x, lo_y, lo_z] = defn_lo; let [lo_x, lo_y, lo_z] = defn_lo;
let xf = |p: [f32; 3]| -> [f32; 3] { let xf = |p: [f32; 3]| -> [f32; 3] {
let w = accum_xform.apply(Vector3::new( let w = accum_xform.apply(Vector3::new(
@ -885,7 +882,7 @@ fn emit_text_baseline(
p[1] as f64 + lo_y, p[1] as f64 + lo_y,
p[2] as f64 + lo_z, p[2] as f64 + lo_z,
)); ));
[(w.x - ox) as f32, (w.y - oy) as f32, (w.z - oz) as f32] [(w.x) as f32, (w.y) as f32, (w.z) as f32]
}; };
// Single line: just obb[0] → obb[1]. Skip when the projected length // Single line: just obb[0] → obb[1]. Skip when the projected length
@ -1216,12 +1213,11 @@ fn expand_defn(
// `defn_lo` (in f64) before composing with `accum_xform` // `defn_lo` (in f64) before composing with `accum_xform`
// so culling uses correct world-space corners. // so culling uses correct world-space corners.
let world = transform_offset_aabb_xy(lw.aabb_local, defn_lo, accum_xform); let world = transform_offset_aabb_xy(lw.aabb_local, defn_lo, accum_xform);
let [ox, oy, _] = [0.0_f64; 3];
let local = [ let local = [
world[0] - ox as f32, world[0] as f32,
world[1] - oy as f32, world[1] as f32,
world[2] - ox as f32, world[2] as f32,
world[3] - oy as f32, world[3] as f32,
]; ];
if let Some(view) = ctx.view_aabb { if let Some(view) = ctx.view_aabb {
if aabb_disjoint_xy(local, view) { if aabb_disjoint_xy(local, view) {
@ -1279,12 +1275,11 @@ fn expand_defn(
nested_defn.local_offset, nested_defn.local_offset,
&composed, &composed,
); );
let [ox, oy, _] = [0.0_f64; 3];
let local = [ let local = [
world[0] - ox as f32, world[0] as f32,
world[1] - oy as f32, world[1] as f32,
world[2] - ox as f32, world[2] as f32,
world[3] - oy as f32, world[3] as f32,
]; ];
if let Some(view) = ctx.view_aabb { if let Some(view) = ctx.view_aabb {
if aabb_disjoint_xy(local, view) { if aabb_disjoint_xy(local, view) {
@ -1383,7 +1378,6 @@ fn emit_wire(
if lw.points.is_empty() && lw.fill_tris.is_empty() { if lw.points.is_empty() && lw.fill_tris.is_empty() {
return; return;
} }
let [ox, oy, oz] = [0.0_f64; 3];
let [lo_x, lo_y, lo_z] = defn_lo; let [lo_x, lo_y, lo_z] = defn_lo;
// Resolve final style for this LocalWire against the outer Insert ctx // Resolve final style for this LocalWire against the outer Insert ctx
@ -1471,12 +1465,12 @@ fn emit_wire(
p[1] as f64 + pl[1] as f64 + lo_y, p[1] as f64 + pl[1] as f64 + lo_y,
p[2] as f64 + pl[2] as f64 + lo_z, p[2] as f64 + pl[2] as f64 + lo_z,
)); ));
let qx = (v.x - ox) as f32; let qx = (v.x) as f32;
let qy = (v.y - oy) as f32; let qy = (v.y) as f32;
let qz = (v.z - oz) as f32; let qz = (v.z) as f32;
let qx_l = ((v.x - ox) - qx as f64) as f32; let qx_l = ((v.x) - qx as f64) as f32;
let qy_l = ((v.y - oy) - qy as f64) as f32; let qy_l = ((v.y) - qy as f64) as f32;
let qz_l = ((v.z - oz) - qz as f64) as f32; let qz_l = ((v.z) - qz as f64) as f32;
let q = [qx, qy, qz]; let q = [qx, qy, qz];
if qx < entry.min_x { if qx < entry.min_x {
entry.min_x = qx; entry.min_x = qx;
@ -1501,7 +1495,7 @@ fn emit_wire(
p[1] as f64 + lo_y, p[1] as f64 + lo_y,
p[2] as f64 + lo_z, p[2] as f64 + lo_z,
)); ));
entry.key_vertices.push([v.x - ox, v.y - oy, v.z - oz]); entry.key_vertices.push([v.x, v.y, v.z]);
} }
for (p, hint) in &lw.snap_pts { for (p, hint) in &lw.snap_pts {
let v = accum_xform.apply(Vector3::new( let v = accum_xform.apply(Vector3::new(
@ -1510,7 +1504,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::DVec3::new(v.x - ox, v.y - oy, v.z - oz), glam::DVec3::new(v.x, v.y, v.z),
*hint, *hint,
)); ));
} }
@ -1527,7 +1521,7 @@ fn emit_wire(
)); ));
entry entry
.fill_tris .fill_tris
.push([(v.x - ox) as f32, (v.y - oy) as f32, (v.z - oz) as f32]); .push([(v.x) as f32, (v.y) as f32, (v.z) as f32]);
} }
} }
@ -1537,7 +1531,6 @@ fn transform_tangent(
t: &Transform, t: &Transform,
defn_lo: [f64; 3], defn_lo: [f64; 3],
) -> TangentGeom { ) -> TangentGeom {
let [ox, oy, oz] = [0.0_f64; 3];
let [lo_x, lo_y, lo_z] = defn_lo; let [lo_x, lo_y, lo_z] = defn_lo;
match tg { match tg {
TangentGeom::Line { p1, p2 } => { TangentGeom::Line { p1, p2 } => {
@ -1552,8 +1545,8 @@ fn transform_tangent(
p2[2] as f64 + lo_z, p2[2] as f64 + lo_z,
)); ));
TangentGeom::Line { TangentGeom::Line {
p1: [(q1.x - ox) as f32, (q1.y - oy) as f32, (q1.z - oz) as f32], p1: [(q1.x) as f32, (q1.y) as f32, (q1.z) as f32],
p2: [(q2.x - ox) as f32, (q2.y - oy) as f32, (q2.z - oz) as f32], p2: [(q2.x) as f32, (q2.y) as f32, (q2.z) as f32],
} }
} }
TangentGeom::Circle { center, radius } => { TangentGeom::Circle { center, radius } => {
@ -1567,7 +1560,7 @@ fn transform_tangent(
let sy = ((m[1][0] * m[1][0] + m[1][1] * m[1][1] + m[1][2] * m[1][2]) as f64).sqrt(); let sy = ((m[1][0] * m[1][0] + m[1][1] * m[1][1] + m[1][2] * m[1][2]) as f64).sqrt();
let s = ((sx + sy) * 0.5) as f32; let s = ((sx + sy) * 0.5) as f32;
TangentGeom::Circle { TangentGeom::Circle {
center: [(c.x - ox) as f32, (c.y - oy) as f32, (c.z - oz) as f32], center: [(c.x) as f32, (c.y) as f32, (c.z) as f32],
radius: radius * s, radius: radius * s,
} }
} }

View file

@ -145,9 +145,8 @@ pub fn tessellate(
// single MTEXT can hand back N colour-distinct wires when the // single MTEXT can hand back N colour-distinct wires when the
// value mixes inline colours. // value mixes inline colours.
TruckObject::Text(stroke_groups) => { TruckObject::Text(stroke_groups) => {
let [ox, oy, oz] = [0.0_f64; 3];
let entity_zf = entity_z(entity) as f64; let entity_zf = entity_z(entity) as f64;
let elev_v = entity_zf - oz; let elev_v = entity_zf;
// anno_scale anchors at the first group's origin so multi-line // anno_scale anchors at the first group's origin so multi-line
// MText lines spread apart correctly as they grow. // MText lines spread apart correctly as they grow.
@ -155,8 +154,8 @@ pub fn tessellate(
.first() .first()
.map(|g| g.origin) .map(|g| g.origin)
.unwrap_or([0.0, 0.0]); .unwrap_or([0.0, 0.0]);
let ref_lx_v = ref_origin[0] - ox; let ref_lx_v = ref_origin[0];
let ref_ly_v = ref_origin[1] - oy; let ref_ly_v = ref_origin[1];
// Selection forces a single uniform colour — never split. // Selection forces a single uniform colour — never split.
let split_by_color = !selected; let split_by_color = !selected;
@ -179,8 +178,8 @@ pub fn tessellate(
let anno = anno_scale as f64; let anno = anno_scale as f64;
for group in &stroke_groups { for group in &stroke_groups {
let lx_v = group.origin[0] - ox; let lx_v = group.origin[0];
let ly_v = group.origin[1] - oy; let ly_v = group.origin[1];
let slx_v = (lx_v - ref_lx_v) * anno + ref_lx_v; let slx_v = (lx_v - ref_lx_v) * anno + ref_lx_v;
let sly_v = (ly_v - ref_ly_v) * anno + ref_ly_v; let sly_v = (ly_v - ref_ly_v) * anno + ref_ly_v;
let bin_key = if split_by_color { group.color } else { None }; let bin_key = if split_by_color { group.color } else { None };
@ -213,7 +212,7 @@ pub fn tessellate(
let key_vertices: Vec<[f64; 3]> = te let key_vertices: Vec<[f64; 3]> = te
.key_vertices .key_vertices
.into_iter() .into_iter()
.map(|[x, y, z]| [x - ox, y - oy, z - oz]) .map(|[x, y, z]| [x, y, z])
.collect(); .collect();
// Empty input (no glyphs) → emit a single empty wire so the // Empty input (no glyphs) → emit a single empty wire so the
@ -289,11 +288,10 @@ pub fn tessellate(
TruckTessResult::Point([x, y, z], [xl, yl, zl]) => { TruckTessResult::Point([x, y, z], [xl, yl, zl]) => {
let s = 0.1_f32; let s = 0.1_f32;
let snap_pts = te.snap_pts; let snap_pts = te.snap_pts;
let [ox, oy, oz] = [0.0_f64; 3];
let key_vertices: Vec<[f64; 3]> = te let key_vertices: Vec<[f64; 3]> = te
.key_vertices .key_vertices
.into_iter() .into_iter()
.map(|[kx, ky, kz]| [kx - ox, ky - oy, kz - oz]) .map(|[kx, ky, kz]| [kx, ky, kz])
.collect(); .collect();
return vec![WireModel { return vec![WireModel {
name, name,
@ -332,12 +330,11 @@ pub fn tessellate(
if let TruckTessResult::Lines(points, points_low) = if let TruckTessResult::Lines(points, points_low) =
tessellate_edge(&e) tessellate_edge(&e)
{ {
let [ox, oy, oz] = [0.0_f64; 3];
let snap_pts = te.snap_pts; let snap_pts = te.snap_pts;
let key_vertices: Vec<[f64; 3]> = te let key_vertices: Vec<[f64; 3]> = te
.key_vertices .key_vertices
.into_iter() .into_iter()
.map(|[x, y, z]| [x - ox, y - oy, z - oz]) .map(|[x, y, z]| [x, y, z])
.collect(); .collect();
return vec![WireModel { return vec![WireModel {
name, name,
@ -365,12 +362,11 @@ pub fn tessellate(
if let TruckTessResult::Lines(points, points_low) = if let TruckTessResult::Lines(points, points_low) =
tessellate_wire(&w) tessellate_wire(&w)
{ {
let [ox, oy, oz] = [0.0_f64; 3];
let snap_pts = te.snap_pts; let snap_pts = te.snap_pts;
let key_vertices: Vec<[f64; 3]> = te let key_vertices: Vec<[f64; 3]> = te
.key_vertices .key_vertices
.into_iter() .into_iter()
.map(|[x, y, z]| [x - ox, y - oy, z - oz]) .map(|[x, y, z]| [x, y, z])
.collect(); .collect();
return vec![WireModel { return vec![WireModel {
name, name,
@ -401,13 +397,12 @@ pub fn tessellate(
// GPU shader pairs them so drawings at large UTM-style // GPU shader pairs them so drawings at large UTM-style
// coordinates keep sub-unit precision in the wire model and // coordinates keep sub-unit precision in the wire model and
// don't jitter on camera movement. // don't jitter on camera movement.
let [ox, oy, oz] = [0.0_f64; 3];
let (local_pts, local_pts_low) = points_to_ds(points); let (local_pts, local_pts_low) = points_to_ds(points);
let snap_pts = te.snap_pts; let snap_pts = te.snap_pts;
let key_vertices: Vec<[f64; 3]> = te let key_vertices: Vec<[f64; 3]> = te
.key_vertices .key_vertices
.into_iter() .into_iter()
.map(|[x, y, z]| [x - ox, y - oy, z - oz]) .map(|[x, y, z]| [x, y, z])
.collect(); .collect();
let (fill_tris, fill_tris_low) = points_to_ds(te.fill_tris); let (fill_tris, fill_tris_low) = points_to_ds(te.fill_tris);
return vec![WireModel { return vec![WireModel {
@ -432,13 +427,12 @@ pub fn tessellate(
} }
TruckObject::SegmentedLines(points) => { TruckObject::SegmentedLines(points) => {
let [ox, oy, oz] = [0.0_f64; 3];
let (local_pts, local_pts_low) = points_to_ds(points); let (local_pts, local_pts_low) = points_to_ds(points);
let snap_pts = te.snap_pts; let snap_pts = te.snap_pts;
let key_vertices: Vec<[f64; 3]> = te let key_vertices: Vec<[f64; 3]> = te
.key_vertices .key_vertices
.into_iter() .into_iter()
.map(|[x, y, z]| [x - ox, y - oy, z - oz]) .map(|[x, y, z]| [x, y, z])
.collect(); .collect();
return vec![WireModel { return vec![WireModel {
name, name,
@ -470,9 +464,8 @@ pub fn tessellate(
let wire_pts = solid_wire_fallback(entity); let wire_pts = solid_wire_fallback(entity);
let mut wm = WireModel::solid_f64(name, wire_pts, color, selected); let mut wm = WireModel::solid_f64(name, wire_pts, color, selected);
// Add insertion snap at point_of_reference. // Add insertion snap at point_of_reference.
let [ox, oy, oz] = [0.0_f64; 3];
if let Some(p) = crate::entities::solid3d::point_of_reference(entity) { if let Some(p) = crate::entities::solid3d::point_of_reference(entity) {
let sp = glam::DVec3::new(p.x - ox, p.y - oy, p.z - oz); let sp = glam::DVec3::new(p.x, p.y, p.z);
wm.snap_pts.push((sp, SnapHint::Insertion)); wm.snap_pts.push((sp, SnapHint::Insertion));
} }
return vec![wm]; return vec![wm];
@ -706,9 +699,8 @@ fn fallback_geometry(entity: &EntityType) -> Geometry {
let pts = solid_wire_fallback(entity); let pts = solid_wire_fallback(entity);
let mut snap = vec![]; let mut snap = vec![];
if let Some(p) = crate::entities::solid3d::point_of_reference(entity) { if let Some(p) = crate::entities::solid3d::point_of_reference(entity) {
let [ox, oy, oz] = [0.0_f64; 3];
snap.push(( snap.push((
Vec3::new((p.x - ox) as f32, (p.y - oy) as f32, (p.z - oz) as f32), Vec3::new((p.x) as f32, (p.y) as f32, (p.z) as f32),
SnapHint::Insertion, SnapHint::Insertion,
)); ));
} }
@ -727,7 +719,6 @@ fn fallback_geometry(entity: &EntityType) -> Geometry {
/// ACIS data. We use this as a visible fallback when the SAT tessellator /// ACIS data. We use this as a visible fallback when the SAT tessellator
/// produces no mesh (e.g. binary SAB data or unsupported geometry). /// produces no mesh (e.g. binary SAB data or unsupported geometry).
fn solid_wire_fallback(entity: &EntityType) -> Vec<[f64; 3]> { fn solid_wire_fallback(entity: &EntityType) -> Vec<[f64; 3]> {
let [ox, oy, oz] = [0.0_f64; 3];
let Some(wires) = crate::entities::solid3d::fallback_wires(entity) else { let Some(wires) = crate::entities::solid3d::fallback_wires(entity) else {
return vec![]; return vec![];
}; };
@ -741,7 +732,7 @@ fn solid_wire_fallback(entity: &EntityType) -> Vec<[f64; 3]> {
continue; continue;
} }
for v in &wire.points { for v in &wire.points {
pts.push([v.x - ox, v.y - oy, v.z - oz]); pts.push([v.x, v.y, v.z]);
} }
// NaN sentinel separates distinct wire segments. // NaN sentinel separates distinct wire segments.
pts.push([f64::NAN, f64::NAN, f64::NAN]); pts.push([f64::NAN, f64::NAN, f64::NAN]);