X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Futil%2Fnumeric.h;h=b96c94faa70cad3a14cc89134ab09d7181c03623;hb=4e1f50035e860a00636ca5d804c267119df99601;hp=450a98e40b0335368a0900e95be60e2058b0d61c;hpb=6d0ea26c2d62c3774ff384cf1bfc2a3372b49a3b;p=dragonfireclient.git diff --git a/src/util/numeric.h b/src/util/numeric.h index 450a98e40..b96c94faa 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -24,10 +24,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "../irr_v2d.h" #include "../irr_v3d.h" #include "../irr_aabb3d.h" -#include +#include // Calculate the borders of a "d-radius" cube -void getFacePositions(core::list &list, u16 d); +void getFacePositions(std::list &list, u16 d); class IndentationRaiser { @@ -139,6 +139,22 @@ inline v3s16 arealim(v3s16 p, s16 d) return p; } +// The naive swap performs better than the xor version +#define SWAP(t, x, y) do { \ + t temp = x; \ + x = y; \ + y = temp; \ +} while (0) + +inline void sortBoxVerticies(v3s16 &p1, v3s16 &p2) { + if (p1.X > p2.X) + SWAP(s16, p1.X, p2.X); + if (p1.Y > p2.Y) + SWAP(s16, p1.Y, p2.Y); + if (p1.Z > p2.Z) + SWAP(s16, p1.Z, p2.Z); +} + /* See test.cpp for example cases. @@ -332,5 +348,12 @@ inline void paging(u32 length, u32 page, u32 pagecount, u32 &minindex, u32 &maxi } } +inline float cycle_shift(float value, float by = 0, float max = 1) +{ + if (value + by < 0) return max + by + value; + if (value + by > max) return value + by - max; + return value + by; +} + #endif