… | |
… | |
252 | #else |
252 | #else |
253 | return dx_ + dy_ - min (dx_, dy_) * 5 / 8; |
253 | return dx_ + dy_ - min (dx_, dy_) * 5 / 8; |
254 | #endif |
254 | #endif |
255 | } |
255 | } |
256 | |
256 | |
|
|
257 | // can be substantially faster than floor, if your value range allows for it |
|
|
258 | template<typename T> |
|
|
259 | inline T |
|
|
260 | fastfloor (T x) |
|
|
261 | { |
|
|
262 | return std::floor (x); |
|
|
263 | } |
|
|
264 | |
|
|
265 | inline float |
|
|
266 | fastfloor (float x) |
|
|
267 | { |
|
|
268 | return sint32(x) - (x < 0); |
|
|
269 | } |
|
|
270 | |
|
|
271 | inline double |
|
|
272 | fastfloor (double x) |
|
|
273 | { |
|
|
274 | return sint64(x) - (x < 0); |
|
|
275 | } |
|
|
276 | |
257 | /* |
277 | /* |
258 | * absdir(int): Returns a number between 1 and 8, which represent |
278 | * absdir(int): Returns a number between 1 and 8, which represent |
259 | * the "absolute" direction of a number (it actually takes care of |
279 | * the "absolute" direction of a number (it actually takes care of |
260 | * "overflow" in previous calculations of a direction). |
280 | * "overflow" in previous calculations of a direction). |
261 | */ |
281 | */ |