12
12
#define EIGHTBITMASK (morton) 0x000000FF
13
13
#define NINEBITMASK (morton) 0x000001FF
14
14
15
-
16
15
namespace libmorton {
17
16
// AVAILABLE METHODS FOR ENCODING
18
17
template <typename morton, typename coord> inline morton m3D_e_sLUT (const coord x, const coord y, const coord z);
@@ -126,7 +125,7 @@ namespace libmorton {
126
125
template <typename morton, typename coord>
127
126
inline morton m3D_e_for (const coord x, const coord y, const coord z) {
128
127
morton answer = 0 ;
129
- unsigned int checkbits = static_cast < unsigned int >( floor (( sizeof (morton) * 8 . 0f / 3 . 0f ))) ;
128
+ unsigned int checkbits = ( sizeof (morton) * 8 ) / 3 ;
130
129
for (unsigned int i = 0 ; i < checkbits; ++i) {
131
130
morton mshifted = static_cast <morton>(1 ) << i; // Here we need to cast 0x1 to 64bits, otherwise there is a bug when morton code is larger than 32 bits
132
131
unsigned int shift = 2 * i; // because you have to shift back i and forth 3*i
@@ -143,7 +142,7 @@ namespace libmorton {
143
142
inline morton m3D_e_for_ET (const coord x, const coord y, const coord z) {
144
143
morton answer = 0 ;
145
144
unsigned long x_max = 0 , y_max = 0 , z_max = 0 ;
146
- unsigned int checkbits = static_cast < unsigned int >( floor (( sizeof (morton) * 8 . 0f / 3 . 0f ))) ;
145
+ unsigned int checkbits = ( sizeof (morton) * 8 ) / 3 ;
147
146
findFirstSetBit<morton>(x, &x_max);
148
147
findFirstSetBit<morton>(y, &y_max);
149
148
findFirstSetBit<morton>(z, &z_max);
@@ -158,13 +157,12 @@ namespace libmorton {
158
157
return answer;
159
158
}
160
159
161
-
162
160
// HELPER METHOD for LUT decoding
163
161
// todo: wouldn't this be better with 8-bit aligned decode LUT?
164
162
template <typename morton, typename coord>
165
163
inline coord morton3D_DecodeCoord_LUT256 (const morton m, const uint_fast8_t *LUT, const unsigned int startshift) {
166
164
morton a = 0 ;
167
- unsigned int loops = (sizeof (morton) <= 4 ) ? 4 : 7 ; // ceil for 32bit, floor for 64bit
165
+ unsigned int loops = (sizeof (morton) <= 4 ) ? 4 : 7 ;
168
166
for (unsigned int i = 0 ; i < loops; ++i) {
169
167
a |= (morton)(LUT[(m >> ((i * 9 ) + startshift)) & NINEBITMASK] << morton (3 * i));
170
168
}
@@ -254,7 +252,7 @@ namespace libmorton {
254
252
template <typename morton, typename coord>
255
253
inline void m3D_d_for (const morton m, coord& x, coord& y, coord& z) {
256
254
x = 0 ; y = 0 ; z = 0 ;
257
- unsigned int checkbits = static_cast < unsigned int >( floor (( sizeof (morton) * 8 . 0f / 3 . 0f ))) ;
255
+ unsigned int checkbits = ( sizeof (morton) * 8 ) / 3 ;
258
256
for (unsigned int i = 0 ; i <= checkbits; ++i) {
259
257
morton selector = 1 ;
260
258
unsigned int shift_selector = 3 * i;
@@ -271,8 +269,8 @@ namespace libmorton {
271
269
x = 0 ; y = 0 ; z = 0 ;
272
270
unsigned long firstbit_location = 0 ;
273
271
if (!findFirstSetBit<morton>(m, &firstbit_location)) return ;
274
- float defaultbits = floor (( sizeof (morton) * 8 . 0f / 3 . 0f )) ;
275
- unsigned int checkbits = static_cast <unsigned int >(std::min (defaultbits, firstbit_location / 3 .0f ));
272
+ unsigned int defaultbits = ( sizeof (morton) * 8 ) / 3 ;
273
+ unsigned int checkbits = static_cast <unsigned int >(std::min (( float ) defaultbits, firstbit_location / 3 .0f ));
276
274
for (unsigned int i = 0 ; i <= checkbits; ++i) {
277
275
morton selector = 1 ;
278
276
unsigned int shift_selector = 3 * i;
@@ -282,4 +280,4 @@ namespace libmorton {
282
280
z |= (m & (selector << (shift_selector + 2 ))) >> (shiftback + 2 );
283
281
}
284
282
}
285
- }
283
+ }
0 commit comments