refactor(units): vec3_homogeneous_ops! macro — single-source Vec3 boilerplate #40

Merged
patman merged 1 commit from patman/uom-vec-macro into main 2026-07-09 23:11:42 +00:00
Owner

What this does

Replaces the seven hand-copied add/sub/scale/magnitude bodies across the *Vec3 boundary types with a single vec3_homogeneous_ops! macro (common/src/types/units/vec_ops.rs). Pure, behavior-preserving refactor.

Why

The seven copies were a live unit-bug surface — each re-typed the SI accessor, so a single wrong accessor (e.g. as_millimeters for as_meters) would be a silent unit bug that compiles and passes a same-unit round-trip test. The macro makes the SI accessor a single source of truth. It also unblocks the line budget for the typed-vector seam (next PR) and only ever generates dimension-homogeneous boilerplate — never dimensional algebra.

Verification

buck2 build //common:common green; buck2 test //common:common-tests89 passed. The existing per-type proptests (vec3_add_then_sub_identity, vec3_magnitude_matches_pythagoras, vec3_scale_by_one_is_identity, angular equivalents) are the regression net and pass unchanged. Net −165 lines.

Stack position

PR 0 of the typed-vector/CAM series, on top of #39. Foundation for #41+ (SI-array seam, typed ops, integrator). Part of the night-session build — see docs/superpowers/cam-typed-layer-design.md.

## What this does Replaces the seven hand-copied `add`/`sub`/`scale`/`magnitude` bodies across the `*Vec3` boundary types with a single `vec3_homogeneous_ops!` macro (`common/src/types/units/vec_ops.rs`). Pure, behavior-preserving refactor. ## Why The seven copies were a live unit-bug surface — each re-typed the SI accessor, so a single wrong accessor (e.g. `as_millimeters` for `as_meters`) would be a silent unit bug that compiles and passes a same-unit round-trip test. The macro makes the SI accessor a **single source of truth**. It also unblocks the line budget for the typed-vector seam (next PR) and only ever generates dimension-homogeneous boilerplate — never dimensional algebra. ## Verification `buck2 build //common:common` green; `buck2 test //common:common-tests` → **89 passed**. The existing per-type proptests (`vec3_add_then_sub_identity`, `vec3_magnitude_matches_pythagoras`, `vec3_scale_by_one_is_identity`, angular equivalents) are the regression net and pass unchanged. Net −165 lines. ## Stack position PR 0 of the typed-vector/CAM series, on top of #39. Foundation for #41+ (SI-array seam, typed ops, integrator). Part of the night-session build — see `docs/superpowers/cam-typed-layer-design.md`.
Replace the 7x hand-copied add/sub/scale/magnitude bodies across the
*Vec3 boundary types with one declarative macro, making the SI accessor a
single source of truth (a wrong unit accessor can now only be wrong in one
place). Pure, behavior-preserving refactor; existing proptests are the net.

Co-authored-by: patman-assist <patrick-ai@kgroo.co>
patman changed target branch from patman/uom-trybuild to main 2026-07-09 23:11:26 +00:00
patman merged commit 72c1289cce into main 2026-07-09 23:11:42 +00:00
Sign in to join this conversation.
No description provided.