mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2024-12-04 19:23:28 +01:00
add small helper to scalar range
This commit is contained in:
parent
7bce78167b
commit
e9c62f9201
@ -7,7 +7,7 @@ namespace MM::Random {
|
|||||||
|
|
||||||
// Seeded (Pseudo-) Random Number Generator
|
// Seeded (Pseudo-) Random Number Generator
|
||||||
struct SRNG {
|
struct SRNG {
|
||||||
// make shuffle compat
|
// make shuffle compat
|
||||||
// TODO: add more type info
|
// TODO: add more type info
|
||||||
using result_type = uint32_t;
|
using result_type = uint32_t;
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ struct SRNG {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool roll(float prob) {
|
bool roll(float prob) {
|
||||||
return zeroToOne() <= prob;
|
return zeroToOne() <= prob; // TODO: just < ?
|
||||||
}
|
}
|
||||||
|
|
||||||
// more advanced
|
// more advanced
|
||||||
|
@ -60,6 +60,16 @@ struct ScalarRange2 {
|
|||||||
[[nodiscard]] constexpr bool inRange(T&& value) const {
|
[[nodiscard]] constexpr bool inRange(T&& value) const {
|
||||||
return value >= min() && value <= max();
|
return value >= min() && value <= max();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lerp between min and max
|
||||||
|
[[nodiscard]] constexpr T map(const float a) const {
|
||||||
|
return min() * (1.f-a) + max() * a;
|
||||||
|
}
|
||||||
|
|
||||||
|
// reverse map
|
||||||
|
[[nodiscard]] constexpr float unmap(const T& v) const {
|
||||||
|
return (v - min()) / static_cast<float>(max() - min());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // MM
|
} // MM
|
||||||
|
Loading…
Reference in New Issue
Block a user