18template <
typename T,
typename T2,
typename T3>
20inline constexpr T
rangelim(
const T &d,
const T2 &min,
const T3 &max)
35 return (
p >= 0 ?
p :
p - d + 1) / d;
74 container = (
p >= 0 ?
p :
p - d + 1) / d;
94 p.X >= 0 &&
p.X < d &&
95 p.Y >= 0 &&
p.Y < d &&
103 p.X >= 0 &&
p.X < d &&
111 p.X >= 0 &&
p.X < d.X &&
112 p.Y >= 0 &&
p.Y < d.Y &&
113 p.Z >= 0 &&
p.Z < d.Z
121 std::swap(p1.X, p2.X);
123 std::swap(p1.Y, p2.Y);
125 std::swap(p1.Z, p2.Z);
130 const core::vector2d<T> &b)
132 return {std::min(a.X, b.X), std::min(a.Y, b.Y)};
137 const core::vector2d<T> &b)
139 return {std::max(a.X, b.X), std::max(a.Y, b.Y)};
144 const core::vector3d<T> &b)
146 return {std::min(a.X, b.X), std::min(a.Y, b.Y), std::min(a.Z, b.Z)};
151 const core::vector3d<T> &b)
153 return {std::max(a.X, b.X), std::max(a.Y, b.Y), std::max(a.Z, b.Z)};
212 return fmodf(f, 360.0f);
222 return value < 0 ? value + 360 : value;
237 value_v3f.X = value_v3f.X < 0 ? value_v3f.X + 360 : value_v3f.X;
238 value_v3f.Y = value_v3f.Y < 0 ? value_v3f.Y + 360 : value_v3f.Y;
239 value_v3f.Z = value_v3f.Z < 0 ? value_v3f.Z + 360 : value_v3f.Z;
258#define MYRAND_RANGE 0xffffffff
282 u32 mask = (1 << len) - 1;
283 return (
x >> pos) & mask;
288 u32 mask = (1 << len) - 1;
289 *
x &= ~(mask << pos);
290 *
x |= (val & mask) << pos;
299 return (0x6996 >> v) & 1;
320 f32 camera_fov, f32 range, f32 *distance_ptr=
nullptr);
331 return (s32)(f < 0.f ? (f - 0.5f) : (f + 0.5f));
336inline constexpr T
sqr(T f)
348 (
p.X + (
p.X > 0 ? d / 2 : -d / 2)) / d,
349 (
p.Y + (
p.Y > 0 ? d / 2 : -d / 2)) / d,
350 (
p.Z + (
p.Z > 0 ? d / 2 : -d / 2)) / d);
360 (
p.X + (
p.X > 0 ? d / 2 : -d / 2)) / d,
361 (
p.Y + (
p.Y > 0 ? d / 2 : -d / 2)) / d,
362 (
p.Z + (
p.Z > 0 ? d / 2 : -d / 2)) / d);
371 return v3f::from(
p) * d;
379 v3f::from(
p) * d - 0.5f * d,
380 v3f::from(
p) * d + 0.5f * d
396 bool step(
float dtime,
float wanted_interval)
412 return n != 0 && (n & (n - 1)) == 0;
435 unsigned s = b - a, l =
static_cast<unsigned>(maximum - b) + a + 1;
436 return std::min(s, l);
445 T delta = target - current;
449 if (delta > stepsize && maximum - delta > stepsize) {
450 current += (delta < maximum / 2) ? stepsize : -stepsize;
451 if (current >= maximum)
478 return video::SColor(color.getAlpha(),
479 core::clamp<u32>(color.getRed() * mod, 0, 255),
480 core::clamp<u32>(color.getGreen() * mod, 0, 255),
481 core::clamp<u32>(color.getBlue() * mod, 0, 255));
487 return v < 0 ? T(-v) : v;
493 return T(v < 0 ? -1 : (v == 0 ? 0 : 1));
497inline constexpr core::vector3d<T>
vecAbsolute(
const core::vector3d<T> &v)
507inline constexpr core::vector3d<T>
vecSign(
const core::vector3d<T> &v)
float m_accumulator
Definition numeric.h:406
IntervalLimiter()=default
bool step(float dtime, float wanted_interval)
Definition numeric.h:396
#define BS
Definition constants.h:61
#define MAP_BLOCKSIZE
Definition constants.h:64
core::aabbox3d< f32 > aabb3f
Definition irr_aabb3d.h:11
core::vector2d< s16 > v2s16
Definition irr_v2d.h:12
core::vector3d< double > v3d
Definition irr_v3d.h:12
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
core::vector3df v3f
Definition irr_v3d.h:11
constexpr core::vector3d< T > vecAbsolute(const core::vector3d< T > &v)
Definition numeric.h:497
s16 getContainerPos(s16 p, s16 d)
Definition numeric.h:33
constexpr core::vector2d< T > componentwise_min(const core::vector2d< T > &a, const core::vector2d< T > &b)
Definition numeric.h:129
v3f getPitchYawRollRad(const core::matrix4 &m)
Definition numeric.cpp:181
constexpr T sqr(T f)
Definition numeric.h:336
bool isInArea(v3s16 p, s16 d)
Definition numeric.h:91
void wrappedApproachShortest(T ¤t, const T target, const T stepsize, const T maximum)
Definition numeric.h:442
v3s16 floatToInt(v3f p, f32 d)
Definition numeric.h:345
void mysrand(u64 seed)
Definition numeric.cpp:22
float wrapDegrees_0_360(float f)
Returns f wrapped to the range [0, 360].
Definition numeric.h:219
u64 murmur_hash_64_ua(const void *key, size_t len, unsigned int seed)
Calculate MurmurHash64A hash for an arbitrary block of data.
Definition numeric.cpp:49
constexpr core::vector3d< T > vecSign(const core::vector3d< T > &v)
Definition numeric.h:507
constexpr T numericAbsolute(T v)
Definition numeric.h:485
void setPitchYawRoll(core::matrix4 &m, v3f rot)
Definition numeric.h:462
void sortBoxVerticies(core::vector3d< T > &p1, core::vector3d< T > &p2)
Definition numeric.h:118
v3f getPitchYawRoll(const core::matrix4 &m)
Definition numeric.h:470
constexpr T rangelim(const T &d, const T2 &min, const T3 &max)
Definition numeric.h:20
v3f wrapDegrees_0_360_v3f(v3f v)
Returns v3f wrapped to the range [0, 360].
Definition numeric.h:229
s16 adjustDist(s16 dist, float zoom_fov)
Definition numeric.cpp:155
void set_bits(u32 *x, u32 pos, u32 len, u32 val)
Definition numeric.h:286
void setPitchYawRollRad(core::matrix4 &m, v3f rot)
Definition numeric.cpp:160
constexpr core::vector2d< T > componentwise_max(const core::vector2d< T > &a, const core::vector2d< T > &b)
Definition numeric.h:136
u32 myrand()
Definition numeric.cpp:17
v3f intToFloat(v3s16 p, f32 d)
Definition numeric.h:369
u32 get_bits(u32 x, u32 pos, u32 len)
Definition numeric.h:280
static constexpr const f32 BLOCK_MAX_RADIUS
Definition numeric.h:31
unsigned wrappedDifference(T a, T b, const T maximum)
Definition numeric.h:430
float modulo360f(float f)
Returns f wrapped to the range [-360, 360].
Definition numeric.h:210
v3s16 doubleToInt(v3d p, double d)
Definition numeric.h:357
#define MYRAND_RANGE
Definition numeric.h:258
float wrapDegrees_180(float f)
Returns f wrapped to the range [-180, 180].
Definition numeric.h:247
aabb3f getNodeBox(v3s16 p, float d)
Definition numeric.h:376
void getContainerPosWithOffset(s16 p, s16 d, s16 &container, s16 &offset)
Definition numeric.h:72
video::SColor multiplyColorValue(const video::SColor &color, float mod)
Definition numeric.h:476
constexpr bool is_power_of_two(u32 n)
Definition numeric.h:410
float myrand_float()
Definition numeric.cpp:32
constexpr u32 npot2(u32 orig)
Definition numeric.h:417
s32 myround(f32 f)
Definition numeric.h:329
int myrand_range(int min, int max)
Definition numeric.cpp:38
constexpr T numericSign(T v)
Definition numeric.h:491
u32 calc_parity(u32 v)
Definition numeric.h:293
void myrand_bytes(void *out, size_t len)
Definition numeric.cpp:27
bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir, f32 camera_fov, f32 range, f32 *distance_ptr=nullptr)
Definition numeric.cpp:90
Describes a grid with given step, oirginating at (0,0,0)
Definition numeric.h:157
bool isMeshPos(v3s16 &p) const
Returns true if p is an origin of a cell in the grid.
Definition numeric.h:187
v3s16 getMeshPos(v3s16 p) const
Returns coordinates of the origin of the grid cell containing p.
Definition numeric.h:181
u16 cell_size
Definition numeric.h:158
s16 getCellPos(s16 p) const
returns coordinate of mesh cell given coordinate of a map block
Definition numeric.h:163
u32 getCellVolume() const
Definition numeric.h:160
v3s16 getCellPos(v3s16 block_pos) const
returns position of mesh cell in the grid given position of a map block
Definition numeric.h:169
s16 getMeshPos(s16 p) const
returns closest step of the grid smaller than p
Definition numeric.h:175
u16 getOffsetIndex(v3s16 offset) const
Returns index of the given offset in a grid cell All offset coordinates must be smaller than the size...
Definition numeric.h:196
static constexpr result_type max()
Definition numeric.h:270
u32 result_type
Definition numeric.h:268
static constexpr result_type min()
Definition numeric.h:269
result_type operator()()
Definition numeric.h:271
static std::string p(std::string path)
Definition test_filesys.cpp:64
constexpr v3f x
Definition test_irr_matrix4.cpp:18