Math.hpp File Reference

Go to the source code of this file.

Namespaces

 playrho
 
 playrho::d2
 

Functions

template<typename T >
PLAYRHO_CONSTEXPR auto & playrho::GetX (T &value)
 Gets the "X" element of the given value - i.e. the first element. More...
 
template<typename T >
PLAYRHO_CONSTEXPR auto & playrho::GetY (T &value)
 Gets the "Y" element of the given value - i.e. the second element. More...
 
template<typename T >
PLAYRHO_CONSTEXPR auto & playrho::GetZ (T &value)
 Gets the "Z" element of the given value - i.e. the third element. More...
 
template<typename T >
PLAYRHO_CONSTEXPR auto playrho::GetX (const T &value)
 Gets the "X" element of the given value - i.e. the first element. More...
 
template<typename T >
PLAYRHO_CONSTEXPR auto playrho::GetY (const T &value)
 Gets the "Y" element of the given value - i.e. the second element. More...
 
template<typename T >
PLAYRHO_CONSTEXPR auto playrho::GetZ (const T &value)
 Gets the "Z" element of the given value - i.e. the third element. More...
 
template<typename T >
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_signed< T >::value, std::make_unsigned_t< T > > playrho::MakeUnsigned (const T &arg) noexcept
 Makes the given value into an unsigned value. More...
 
template<typename T , LoValueCheck lo, HiValueCheck hi>
PLAYRHO_CONSTEXPR auto playrho::StripUnit (const BoundedValue< T, lo, hi > &v)
 Strips the unit from the given value. More...
 
template<typename T , typename U >
PLAYRHO_CONSTEXPRplayrho::Secant (T target, U a1, T s1, U a2, T s2) noexcept
 Secant method. More...
 
template<typename T >
PLAYRHO_CONSTEXPRplayrho::Bisect (T a1, T a2) noexcept
 Bisection method. More...
 
template<typename T >
PLAYRHO_CONSTEXPR bool playrho::IsOdd (T val) noexcept
 Is-odd. More...
 
template<class TYPE >
PLAYRHO_CONSTEXPR auto playrho::Square (TYPE t) noexcept
 Squares the given value. More...
 
template<typename T >
auto playrho::Atan2 (T y, T x)
 Computes the arc-tangent of the given y and x values. More...
 
template<typename T , typename = std::enable_if_t< IsIterable<T>::value && IsAddable<decltype(*begin(std::declval<T>()))>::value>
auto playrho::Average (const T &span)
 Computes the average of the given values. More...
 
template<typename T >
std::enable_if_t< IsArithmetic< T >::value, T > playrho::RoundOff (T value, unsigned precision=100000)
 Computes the rounded value of the given value. More...
 
Vec2 playrho::RoundOff (Vec2 value, std::uint32_t precision=100000)
 Computes the rounded value of the given value. More...
 
template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR Vector< T, N > playrho::abs (const Vector< T, N > &v) noexcept
 Absolute value function for vectors. More...
 
d2::UnitVec playrho::abs (const d2::UnitVec &v) noexcept
 Gets the absolute value of the given value. More...
 
template<typename T >
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_arithmetic< T >::value, bool > playrho::AlmostZero (T value)
 Gets whether a given value is almost zero. More...
 
template<typename T >
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_floating_point< T >::value, bool > playrho::AlmostEqual (T x, T y, int ulp=2)
 Determines whether the given two values are "almost equal". More...
 
template<typename T >
auto playrho::ModuloViaFmod (T dividend, T divisor) noexcept
 Modulo operation using std::fmod. More...
 
template<typename T >
auto playrho::ModuloViaTrunc (T dividend, T divisor) noexcept
 Modulo operation using std::trunc. More...
 
Angle playrho::GetNormalized (Angle value) noexcept
 Gets the "normalized" value of the given angle. More...
 
template<class T >
Angle playrho::GetAngle (const Vector2< T > value)
 Gets the angle. More...
 
template<typename T >
PLAYRHO_CONSTEXPR auto playrho::GetMagnitudeSquared (T value) noexcept
 Gets the square of the magnitude of the given iterable value. More...
 
template<typename T >
auto playrho::GetMagnitude (T value)
 Gets the magnitude of the given value. More...
 
template<typename T1 , typename T2 >
PLAYRHO_CONSTEXPR auto playrho::Dot (const T1 a, const T2 b) noexcept
 Performs the dot product on two vectors (A and B). More...
 
template<class T1 , class T2 , std::enable_if_t< std::tuple_size< T1 >::value==2 &&std::tuple_size< T2 >::value==2, int > = 0>
PLAYRHO_CONSTEXPR auto playrho::Cross (T1 a, T2 b) noexcept
 Performs the 2-element analog of the cross product of two vectors. More...
 
template<typename T , typename U >
PLAYRHO_CONSTEXPR auto playrho::Solve (const Matrix22< U > mat, const Vector2< T > b) noexcept
 Solves A * x = b, where b is a column vector. More...
 
template<class IN_TYPE >
PLAYRHO_CONSTEXPR auto playrho::Invert (const Matrix22< IN_TYPE > value) noexcept
 Inverts the given value. More...
 
PLAYRHO_CONSTEXPR Vec3 playrho::Solve33 (const Mat33 &mat, const Vec3 b) noexcept
 Solves A * x = b, where b is a column vector. More...
 
template<typename T >
PLAYRHO_CONSTEXPRplayrho::Solve22 (const Mat33 &mat, const T b) noexcept
 Solves A * x = b, where b is a column vector. More...
 
PLAYRHO_CONSTEXPR Mat33 playrho::GetInverse22 (const Mat33 &value) noexcept
 Gets the inverse of the given matrix as a 2-by-2. More...
 
PLAYRHO_CONSTEXPR Mat33 playrho::GetSymInverse33 (const Mat33 &value) noexcept
 Gets the symmetric inverse of this matrix as a 3-by-3. More...
 
template<class T >
PLAYRHO_CONSTEXPR auto playrho::GetRevPerpendicular (const T vector) noexcept
 Gets a vector counter-clockwise (reverse-clockwise) perpendicular to the given vector. More...
 
template<class T >
PLAYRHO_CONSTEXPR auto playrho::GetFwdPerpendicular (const T vector) noexcept
 Gets a vector clockwise (forward-clockwise) perpendicular to the given vector. More...
 
template<std::size_t M, typename T1 , std::size_t N, typename T2 >
PLAYRHO_CONSTEXPR auto playrho::Transform (const Vector< T1, M > v, const Matrix< T2, M, N > &m) noexcept
 Multiplies an M-element vector by an M-by-N matrix. More...
 
PLAYRHO_CONSTEXPR Vec2 playrho::Transform (const Vec2 v, const Mat33 &A) noexcept
 Multiplies a vector by a matrix. More...
 
PLAYRHO_CONSTEXPR Vec2 playrho::InverseTransform (const Vec2 v, const Mat22 &A) noexcept
 
PLAYRHO_CONSTEXPR Mat22 playrho::MulT (const Mat22 &A, const Mat22 &B) noexcept
 Computes A^T * B. More...
 
Mat22 playrho::abs (const Mat22 &A)
 Gets the absolute value of the given value. More...
 
std::uint64_t playrho::NextPowerOfTwo (std::uint64_t x)
 Gets the next largest power of 2. More...
 
Real playrho::Normalize (Vec2 &vector)
 Converts the given vector into a unit vector and returns its original length. More...
 
Length2 playrho::ComputeCentroid (const Span< const Length2 > &vertices)
 Computes the centroid of a counter-clockwise array of 3 or more vertices. More...
 
template<typename T >
PLAYRHO_CONSTEXPRplayrho::GetModuloNext (T value, T count) noexcept
 Gets the modulo next value. More...
 
template<typename T >
PLAYRHO_CONSTEXPRplayrho::GetModuloPrev (T value, T count) noexcept
 Gets the modulo previous value. More...
 
Angle playrho::GetDelta (Angle a1, Angle a2) noexcept
 Gets the shortest angular distance to go from angle 1 to angle 2. More...
 
PLAYRHO_CONSTEXPR Angle playrho::GetRevRotationalAngle (Angle a1, Angle a2) noexcept
 
std::vector< Length2 > playrho::GetCircleVertices (Length radius, unsigned slices, Angle start=0_deg, Real turns=Real{1})
 Gets the vertices for a circle described by the given parameters. More...
 
NonNegative< Area > playrho::GetAreaOfCircle (Length radius)
 Gets the area of a circle. More...
 
NonNegative< Area > playrho::GetAreaOfPolygon (Span< const Length2 > vertices)
 Gets the area of a polygon. More...
 
SecondMomentOfArea playrho::GetPolarMoment (Span< const Length2 > vertices)
 Gets the polar moment of the area enclosed by the given vertices. More...
 
PLAYRHO_CONSTEXPR Vec2 playrho::d2::GetVec2 (const UnitVec value)
 Gets a Vec2 representation of the given value. More...
 
Angle playrho::d2::GetAngle (const UnitVec value)
 Gets the angle of the given unit vector. More...
 
template<class T , LoValueCheck lo, HiValueCheck hi>
PLAYRHO_CONSTEXPR Vector2< T > playrho::d2::operator* (BoundedValue< T, lo, hi > s, UnitVec u) noexcept
 Multiplication operator. More...
 
template<class T >
PLAYRHO_CONSTEXPR Vector2< T > playrho::d2::operator* (const T s, const UnitVec u) noexcept
 Multiplication operator. More...
 
template<class T , LoValueCheck lo, HiValueCheck hi>
PLAYRHO_CONSTEXPR Vector2< T > playrho::d2::operator* (UnitVec u, BoundedValue< T, lo, hi > s) noexcept
 Multiplication operator. More...
 
template<class T >
PLAYRHO_CONSTEXPR Vector2< T > playrho::d2::operator* (const UnitVec u, const T s) noexcept
 Multiplication operator. More...
 
PLAYRHO_CONSTEXPR Vec2 playrho::d2::operator/ (const UnitVec u, const UnitVec::value_type s) noexcept
 Division operator. More...
 
template<class T >
PLAYRHO_CONSTEXPR auto playrho::d2::Rotate (const Vector2< T > vector, const UnitVec &angle) noexcept
 Rotates a vector by a given angle. More...
 
template<class T >
PLAYRHO_CONSTEXPR auto playrho::d2::InverseRotate (const Vector2< T > vector, const UnitVec &angle) noexcept
 Inverse rotates a vector. More...
 
template<class T >
UnitVec playrho::d2::GetUnitVector (Vector2< T > value, UnitVec fallback=UnitVec::GetDefaultFallback())
 
Position playrho::d2::GetNormalized (const Position &val) noexcept
 Gets the "normalized" position. More...
 
Sweep playrho::d2::GetNormalized (Sweep sweep) noexcept
 Gets a sweep with the given sweep's angles normalized. More...
 
PLAYRHO_CONSTEXPR Length2 playrho::d2::Transform (const Length2 v, const Transformation xfm) noexcept
 Transforms the given 2-D vector with the given transformation. More...
 
PLAYRHO_CONSTEXPR Length2 playrho::d2::InverseTransform (const Length2 v, const Transformation T) noexcept
 Inverse transforms the given 2-D vector with the given transformation. More...
 
PLAYRHO_CONSTEXPR Transformation playrho::d2::Mul (const Transformation &A, const Transformation &B) noexcept
 Multiplies a given transformation by another given transformation. More...
 
PLAYRHO_CONSTEXPR Transformation playrho::d2::MulT (const Transformation &A, const Transformation &B) noexcept
 Inverse multiplies a given transformation by another given transformation. More...
 
PLAYRHO_CONSTEXPR Transformation playrho::d2::GetTransformation (const Length2 ctr, const UnitVec rot, const Length2 localCtr) noexcept
 Gets the transformation for the given values. More...
 
Transformation playrho::d2::GetTransformation (const Position pos, const Length2 local_ctr) noexcept
 Gets the transformation for the given values. More...
 
Transformation playrho::d2::GetTransformation (const Sweep &sweep, const Real beta) noexcept
 Gets the interpolated transform at a specific time. More...
 
Transformation playrho::d2::GetTransform0 (const Sweep &sweep) noexcept
 Gets the transform at "time" zero. More...
 
Transformation playrho::d2::GetTransform1 (const Sweep &sweep) noexcept
 Gets the transform at "time" one. More...
 
LinearVelocity2 playrho::d2::GetContactRelVelocity (const Velocity velA, const Length2 relA, const Velocity velB, const Length2 relB) noexcept
 Gets the contact relative velocity. More...
 
bool playrho::d2::IsUnderActive (Velocity velocity, LinearVelocity linSleepTol, AngularVelocity angSleepTol) noexcept
 Gets whether the given velocity is "under active" based on the given tolerances. More...
 
PLAYRHO_CONSTEXPR auto playrho::d2::GetReflectionMatrix (UnitVec axis)
 Gets the reflection matrix for the given unit vector that defines the normal of the line through the origin that points should be reflected against. More...