Skip to content

Illustrative: how the 658 code-grade loop improved meshfit/fit.rs#185

Open
bddap-bot wants to merge 1 commit into
illustrate-658-basefrom
illustrate-658
Open

Illustrative: how the 658 code-grade loop improved meshfit/fit.rs#185
bddap-bot wants to merge 1 commit into
illustrate-658-basefrom
illustrate-658

Conversation

@bddap-bot

@bddap-bot bddap-bot commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

The job-658 code-grade loop on crab-world/src/bot/meshfit/fit.rs, round by round. base←head diff = exactly the fit.rs change that landed in main (81af11a), net −5 lines. Every fix is a deletion, not an addition.

The fan-out

24 calibrated criteria → 8 fresh grading subs (ceil(24/3)), each handed 3 random non-overlapping criteria. One came back Work.

grading fan-out

Round 1 — grade → single-source the dups

Work: dry-not-overboard. A partial_cmp().unwrap_or(Equal) comparator inlined at 4 sort sites; centroid + covariance_eigenframe recomputed in both fit_capsule and score_capsule.
Deletion: callers stop computing/passing the centroid — covariance_eigenframe computes the one it needs, in the one place that needs it.

Reviewer round 1 — delete the bespoke comparator

correctness · security · API · Niko-taste pass: the hand-rolled NaN-safe comparator reinvents stdlib.
Deletion: sort_by(f32::total_cmp) at every site — the closure is gone, not abstracted into a helper.

Reviewer round 2 (the round past "done") — drop the unused return

covariance_eigenframe returned an eigenvalue-magnitude tuple no caller read; the eigenvalues only order the axes.
Deletion: signature shrinks ([Vec3;3], Vec3)(Vec3, [Vec3;3]).

round-by-round remediation

Result

18 Perfect / 4 Good / 0 Work / 2 NA (grade db @81af11a). cargo test (both meshfit::fit tests) + clippy clean. Net −5 lines, behaviour-preserving.

final grade distribution

Three small dedups, all deletion-first:
- four sort sites inlined the same NaN-safe float comparator; they now call the
  stdlib total order (f32/f64::total_cmp) directly, so there's no bespoke
  comparator to keep.
- covariance_eigenframe computes the centroid it needs for the covariance instead
  of every caller computing and passing one in.
- it no longer returns the eigenvalue magnitudes: they only order the axes, and no
  caller read them.

Resolves the file's one code-grade Work (dry-not-overboard) and lifts simplicity
and taste; behaviour-preserving (the two meshfit::fit tests pass, clippy clean).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant