Skip to content

Comments

Fix/grid3d coordinate leakage#36

Open
divye-joshi wants to merge 2 commits intoINCF:masterfrom
divye-joshi:fix/grid3d-coordinate-leakage
Open

Fix/grid3d coordinate leakage#36
divye-joshi wants to merge 2 commits intoINCF:masterfrom
divye-joshi:fix/grid3d-coordinate-leakage

Conversation

@divye-joshi
Copy link

@divye-joshi divye-joshi commented Jan 30, 2026

Description

This PR fixes a critical mathematical bug in csa/geometry.py where the grid3d function uses true division instead of floor division for spatial indexing.

Closes #37

The Fix

I have updated the grid3d lambda function to use the floor division operator (//) for the $y$ and $z$ coordinate calculations. This ensures that 1D indices are correctly mapped to discrete 3D grid points without floating-point "drift" or "leakage".

Safety and Necessity

  • Mathematical Correctness: This change restores the intended discrete grid behavior described in the function's documentation.
  • Parity: This fix brings grid3d into alignment with the existing (and correct) implementation of grid2d.
  • Zero Negative Impact: This change only affects the internal calculation of coordinates within grid3d to ensure they match the expected discrete bins. It does not change the function's signature or return types.

Verification

Verification was performed by calculating the Taxicab distance between the origin and high-index grid points (e.g., index 111 in a width-10 grid). Before the fix, coordinates leaked into floating-point decimals; after the fix, coordinates correctly aligned to the grid centers (0.1, 0.1, 0.1).

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.

Critical Issue: Coordinate Leakage in grid3d

1 participant