Forceflow / libmorton

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

Supply same uint types overloads or templates #83

Open WildRackoon opened 11 months ago

WildRackoon commented 11 months ago

Somewhat related to https://github.com/Forceflow/libmorton/issues/41

Having to manage both uint_fast32_t / uint_fast16_t or uint_fast64_t / uint_fast32_t is not easy, especially with templated code:

The following overload: inline void morton2D_32_decode(const uint_fast32_t morton, uint_fast16_t& x, uint_fast16_t& y);

Should also offer the following overload by casting: inline void morton2D_32_decode(const uint_fast32_t morton, uint_fast32_t & x, uint_fast32_t & y);

This brings up the fact that it could use a templated implementation to allow that kind of overloads:

template<typename T, typename U>
inline void morton2D_32_decode(const T morton, U& x, U& y);

Implementation should static_assert that both T and U are unsigned and optionnaly that there are enough std::numeric_limits<>::digits between each other.