Math helpers: constants, interpolation, random numbers, 2D and 3D vectors and matrices.
More...
|
| template<typename T > |
| using | Matrix4 = Matrix< T, 4, 4 > |
| |
| template<typename T > |
| using | Matrix3 = Matrix< T, 3, 3 > |
| |
| using | Matrix4f = Matrix< float, 4, 4 > |
| |
| using | Matrix3f = Matrix< float, 3, 3 > |
| |
| using | Matrix4d = Matrix< double, 4, 4 > |
| |
| using | Matrix3d = Matrix< double, 3, 3 > |
| |
| using | Vector4f = Matrix< float, 4, 1 > |
| | Column vector, to multiply with a Matrix4f.
|
| |
| using | Vector3f = Matrix< float, 3, 1 > |
| | Column vector, to multiply with a Matrix3f.
|
| |
| using | Vec2f = Vector2D< float > |
| |
| using | Vec2d = Vector2D< double > |
| |
| using | Vec2i = Vector2D< int > |
| |
| using | Vec2u = Vector2D< unsigned int > |
| |
| using | Vec3f = Vector3D< float > |
| |
| using | Vec3d = Vector3D< double > |
| |
| using | Vec3i = Vector3D< int > |
| |
| using | Vec3u = Vector3D< unsigned int > |
| |
|
| template<typename T , size_t Rows, size_t Cols> |
| std::ostream & | operator<< (std::ostream &os, const Matrix< T, Rows, Cols > &mat) |
| |
|
| std::mt19937 & | randomEngine () |
| | Per-thread engine behind random() and randomChoice(); call seed() on it for reproducible results.
|
| |
| template<typename T > |
| T | random (const T &min, const T &max) |
| | Uniform random number in [min, max] for integers, or [min, max) for floating-point types.
|
| |
| template<typename T > |
| T | randomChoice (const std::vector< T > &list) |
| | Random element of list, or T{} if it is empty.
|
| |
|
| template<std::floating_point T> |
| constexpr T | toRad (T degrees) noexcept |
| |
| template<std::floating_point T> |
| constexpr T | toDeg (T radians) noexcept |
| |
| template<typename T > |
| constexpr T | abs (T value) noexcept |
| |
| template<typename T > |
| constexpr T | clamp (T value, T min, T max) noexcept |
| |
| template<typename T > |
| constexpr int | sign (T value) noexcept |
| | Returns -1, 0 or 1 depending on the sign of value.
|
| |
| template<typename T , typename U > |
| constexpr T | lerp (T start, T end, U t) noexcept |
| | Linear interpolation from start to end, with t clamped to [0, 1].
|
| |
| template<std::floating_point T> |
| constexpr T | inverseLerp (T start, T end, T value) noexcept |
| | Inverse of lerp(): where value lies between start and end, or 0 if they are equal.
|
| |
| template<typename T > |
| constexpr T | remap (T value, T inMin, T inMax, T outMin, T outMax) noexcept |
| | Maps value from [inMin, inMax] to [outMin, outMax], without clamping.
|
| |
| template<std::floating_point T> |
| constexpr T | smoothstep (T edge0, T edge1, T x) noexcept |
| | Smooth Hermite interpolation from 0 at edge0 to 1 at edge1.
|
| |
template<typename T >
requires std::is_signed_v<T> |
| T | wrap (T value, T min, T max) noexcept |
| | Wraps value into [min, max), such as an angle into [0, 360).
|
| |
| template<typename T > |
| constexpr bool | isNearlyEqual (T a, T b, T epsilon=std::numeric_limits< T >::epsilon()) noexcept |
| | True if a and b differ by at most epsilon, scaled by their magnitude when it exceeds 1.
|
| |
|
| template<typename T > |
| constexpr Vector2D< T > | operator+ (Vector2D< T > lhs, const Vector2D< T > &rhs) noexcept |
| |
| template<typename T > |
| constexpr Vector2D< T > | operator- (Vector2D< T > lhs, const Vector2D< T > &rhs) noexcept |
| |
| template<typename T > |
| constexpr Vector2D< T > | operator* (Vector2D< T > lhs, const Vector2D< T > &rhs) noexcept |
| |
| template<typename T > |
| constexpr Vector2D< T > | operator/ (Vector2D< T > lhs, const Vector2D< T > &rhs) noexcept |
| |
| template<typename T > |
| constexpr Vector2D< T > | operator* (Vector2D< T > v, std::type_identity_t< T > s) noexcept |
| |
| template<typename T > |
| constexpr Vector2D< T > | operator* (std::type_identity_t< T > s, Vector2D< T > v) noexcept |
| |
| template<typename T > |
| constexpr Vector2D< T > | operator/ (Vector2D< T > v, std::type_identity_t< T > s) noexcept |
| |
| template<typename T > |
| constexpr Vector2D< T > | operator+ (Vector2D< T > v, std::type_identity_t< T > s) noexcept |
| |
| template<typename T > |
| constexpr Vector2D< T > | operator- (Vector2D< T > v, std::type_identity_t< T > s) noexcept |
| |
| template<typename T > |
| std::ostream & | operator<< (std::ostream &os, const Vector2D< T > &vec) |
| |
|
| template<typename T > |
| constexpr Vector3D< T > | operator+ (Vector3D< T > lhs, const Vector3D< T > &rhs) noexcept |
| |
| template<typename T > |
| constexpr Vector3D< T > | operator- (Vector3D< T > lhs, const Vector3D< T > &rhs) noexcept |
| |
| template<typename T > |
| constexpr Vector3D< T > | operator* (Vector3D< T > lhs, const Vector3D< T > &rhs) noexcept |
| |
| template<typename T > |
| constexpr Vector3D< T > | operator/ (Vector3D< T > lhs, const Vector3D< T > &rhs) noexcept |
| |
| template<typename T > |
| constexpr Vector3D< T > | operator* (Vector3D< T > v, std::type_identity_t< T > s) noexcept |
| |
| template<typename T > |
| constexpr Vector3D< T > | operator* (std::type_identity_t< T > s, Vector3D< T > v) noexcept |
| |
| template<typename T > |
| constexpr Vector3D< T > | operator/ (Vector3D< T > v, std::type_identity_t< T > s) noexcept |
| |
| template<typename T > |
| constexpr Vector3D< T > | operator+ (Vector3D< T > v, std::type_identity_t< T > s) noexcept |
| |
| template<typename T > |
| constexpr Vector3D< T > | operator- (Vector3D< T > v, std::type_identity_t< T > s) noexcept |
| |
| template<typename T > |
| std::ostream & | operator<< (std::ostream &os, const Vector3D< T > &vec) |
| |
Math helpers: constants, interpolation, random numbers, 2D and 3D vectors and matrices.