RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
Utils.hpp File Reference
#include <cmath>
#include <concepts>
#include <limits>
#include <numbers>
#include <type_traits>

Go to the source code of this file.

Namespaces

namespace  RST
 Root namespace of RSTools.
 
namespace  RST::Maths
 Math helpers: constants, interpolation, random numbers, 2D and 3D vectors and matrices.
 

Functions

Numeric helpers
template<std::floating_point T>
constexpr T RST::Maths::toRad (T degrees) noexcept
 
template<std::floating_point T>
constexpr T RST::Maths::toDeg (T radians) noexcept
 
template<typename T >
constexpr T RST::Maths::abs (T value) noexcept
 
template<typename T >
constexpr T RST::Maths::clamp (T value, T min, T max) noexcept
 
template<typename T >
constexpr int RST::Maths::sign (T value) noexcept
 Returns -1, 0 or 1 depending on the sign of value.
 
template<typename T , typename U >
constexpr T RST::Maths::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 RST::Maths::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 RST::Maths::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 RST::Maths::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 RST::Maths::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 RST::Maths::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.