Forceflow / libmorton

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

Encode and decode mismatch #19

Closed expedit85 closed 8 years ago

expedit85 commented 8 years ago

Hi.

This library is nice, however I've found an issue.

Consider:

template<typename T,typename U>
ostream & operator << (ostream & os, const pair<T,U> &p)
{
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

int main()
{
    uint_fast32_t i = 16, j = 16, x, y;
    morton2D_64_decode(morton2D_64_encode(i, j), x, y);
    cout << make_pair(i,j) << endl << make_pair(x,y)<<endl;
    return 0;
}

Compiling with G++ for C++11, I've got the following:

g++ --std=c++11 morton.cpp

(16,16)
(4,4)

Which is a mismatch between encode and decode.

Thanks.

Forceflow commented 8 years ago

Hot diggity, well spotted. Still have to test the 2D functions better. Will fix!

Forceflow commented 8 years ago

2D LUT table decoding has a bug, so in 23c1721b0703dbcebde8f59648d2691aa9a5afc8 I temporarily reverted default 2D decoding back to the magicbits method. Still working on finding the bug in LUT table decoding though!

Forceflow commented 8 years ago

Should be fixed in 3581f651c5aa8ba042da761a145493d43aab45fc now.