Skip to content

fix: scope basis unit conversion to touched atom(s) (spec §5.2) - #208

Closed
timurbazhirov wants to merge 1 commit into
feat/editor-oneditcommit-callbackfrom
fix/scope-basis-unit-conversion-to-touched-atoms
Closed

fix: scope basis unit conversion to touched atom(s) (spec §5.2)#208
timurbazhirov wants to merge 1 commit into
feat/editor-oneditcommit-callbackfrom
fix/scope-basis-unit-conversion-to-touched-atoms

Conversation

@timurbazhirov

Copy link
Copy Markdown
Member

Summary

  • commitMovedAtoms_/addAtom/cloneSelectedAtoms placed a touched atom's coordinate by flipping the whole basis to Cartesian and back (basis.toCartesian()/toCrystal()) around the mutation. Basis.toCartesian/toCrystal round-trip every atom's coordinate via mapArrayInPlace, not just the touched one — so spec §5.2's "untouched atoms preserved bit-for-bit because they are never re-derived" claim didn't fully hold in the implementation, even though it was invisible in practice (Basis rounds every coordinate to Cell.roundPrecision, 9 decimals, on serialize, which absorbs a single round-trip's float noise for any reasonably-conditioned cell — verified directly against @mat3ra/made, including deliberately ill-conditioned lattices).
  • Converts only the touched point(s) directly via basis.cell.convertPointToCrystal/convertPointToCartesian instead, at all three call sites. Untouched atoms' coordinate entries are now genuinely never read or rewritten, and each edit does O(touched) matrix work instead of O(n).
  • Third PR in the post-review chained-PR stack (stacked on #207); see plan/interactive-editor-spec-plan.md's "Chained PR stack" section for the full writeup.

Test plan

  • New describe block "Basis unit-conversion scoped to touched atoms (spec §5.2)" in tests/__tests__/mixins/interactive_structure_editor.js: 3 tests spy on the ephemeral basis instance applyBasisDelta_ builds per commit (scoped to that instance, not the shared Basis prototype, since the wave legitimately calls toCartesian/toCrystal elsewhere for unrelated reasons) proving no whole-basis round-trip happens; 3 more assert untouched atoms' coordinates stay exactly unchanged and a moved atom's committed crystal coordinate round-trips to its exact dragged Cartesian position.
  • All 3 "does not round-trip" tests confirmed failing against the pre-fix code and passing after (verified via a temporary git stash of just the source change).
  • Full Jest suite green (181 passed, 2 skipped, up from 175).
  • tsc --noEmit clean.
  • npm run lint clean (0 errors; only pre-existing no-explicit-any warnings matching this file's established convention).
  • npm run build clean.

🤖 Generated with Claude Code

commitMovedAtoms_/addAtom/cloneSelectedAtoms placed a touched atom's
coordinate by flipping the whole basis to Cartesian and back around
the mutation - Basis.toCartesian()/toCrystal() round-trip every
atom's coordinate via mapArrayInPlace, not just the touched one, so
spec §5.2's "untouched atoms preserved bit-for-bit because they are
never re-derived" claim didn't fully hold in the implementation.
Convert only the touched point(s) directly via
basis.cell.convertPointToCrystal/convertPointToCartesian instead, so
untouched atoms' coordinate entries are genuinely never read or
rewritten and each edit does O(touched) matrix work instead of O(n).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Copy link
Copy Markdown
Member Author

Closing — consolidated into #216 (then #214 on top).

Verified contained: this PR's head baa03bba is a direct ancestor of claude/uiux-p2-figure-export. Spec §5.2's scoped unit conversion is also the reason U-6's units toggle changes the display only rather than converting the material — the two decisions sit next to each other now.

The branch fix/scope-basis-unit-conversion-to-touched-atoms stays on the remote.


Generated by Claude Code

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