Forceflow / libmorton

C++ header-only library with methods to efficiently encode/decode Morton codes in/from 2D/3D coordinates
MIT License
593 stars 71 forks source link

Problem with round trip between m3D_e_for(...) and m3D_d_for(..) #81

Closed norlesh closed 1 year ago

norlesh commented 1 year ago

While studying your implementation using the simple for loop in the file morton3D.h I noticed that on line 129 of m3D_e_for the loop is implemented as for (unsigned int i = 0; i < checkbits; ++i) {

while the corresponding m#D_e_for on line 253 is implemented as for (unsigned int i = 0; i <= checkbits; ++i) {

while I haven't run your code I can confirm that when doing a port of the functions into a C# project I needed to change both loops to use i < checkbits before I could get my round trip tests to pass.

Forceflow commented 1 year ago

Changed this, all correctness tests still run. Intuitively, this tracks.