raisim::noiseUtils
class · #include <raisim/Terrain.hpp>
Internal: numeric helpers of the terrain noise generator.
Static member functions
fastFloor static
static std::int64_t fastFloor(double f) noexceptFloor as a SIGNED integer. Returning an unsigned type would wrap every negative result to ~1.8e19, which breaks x -= fastFloor(x) in PerlinNoise::sample below. Truncation toward zero already equals floor for f >= 0 and for exact negative integers; only a negative value with a fractional part needs the extra -1.
Parameters
| Parameter | Description |
|---|---|
f (in) | value inside the int64 range |
Returns floor(f)
fastRound static
static std::int64_t fastRound(double f) noexceptParameters
| Parameter | Description |
|---|---|
f (in) | value |
Returns f rounded to the nearest integer, halves away from zero
map static
static double map(
double value,
double lower0,
double upper0,
double lower1,
double upper1)Linearly maps value from [lower0, upper0] to [lower1, upper1] (no clamping).
Parameters
| Parameter | Description |
|---|---|
value (in) | input value |
lower0 (in) | input range start |
upper0 (in) | input range end |
lower1 (in) | output range start |
upper1 (in) | output range end |
Returns the mapped value
uniformBelow static
static std::uint64_t uniformBelow(std::mt19937 &engine, std::uint64_t bound)A uniform integer below a bound, drawn from the engine as std::uniform_int_distribution of libstdc++ draws it (see kMultiplyShiftReduction), with any standard library.
Parameters
| Parameter | Description |
|---|---|
engine (in, out) | the generator |
bound (in) | exclusive upper bound, in [1, 2^32) |
Returns the draw, in [0, bound)
shuffle static
template <typename T>
static void shuffle(T *values, std::uint64_t count, std::mt19937 &engine)Permute values[0, count) as std::shuffle(values, values + count, engine) does in libstdc++. The standard leaves that permutation to the library, so libc++ and the Microsoft library permuted the same values differently from the same seed. Each draw of the engine gives the swap partners of two consecutive elements.
Parameters
| Parameter | Description |
|---|---|
values (in, out) | the values |
count (in) | number of values, in [1, 65535] |
engine (in, out) | the generator |
Public attributes
kMultiplyShiftReduction
static constexpr bool kMultiplyShiftReductionHow uniformBelow() reduces a 32-bit draw to a bound. false: libstdc++ 10 (the toolchain of the released Linux binaries) rejects draws past the largest multiple of the bound and divides. true: libstdc++ 11 and newer take the high half of the draw times the bound and reject the low halves below 2^32 mod bound (Lemire, "Fast Random Integer Generation in an Interval", 2019).