JPL Spatial
Sound spatialization and propagation library
Loading...
Searching...
No Matches
JPL::Math Namespace Reference

Namespaces

namespace  Detail
 Square Root.
 
namespace  InternalUtils
 

Classes

struct  Mat2
 Minimal 2x2 matrix interface. More...
 
struct  Mat3
 Minimal 3x3 matrix interface. More...
 
struct  VBSSample
 

Concepts

concept  CArithmetic
 
concept  COrderedWith
 
concept  CArithmeticAndOrderedWith
 

Functions

template<std::floating_point T>
JPL_INLINE constexpr T ToRadians (T degrees) noexcept
 Function to convert degrees to radians.
 
template<std::floating_point T>
JPL_INLINE constexpr T ToDegrees (T radians) noexcept
 Function to convert radians to degrees.
 
template<std::floating_point T>
JPL_INLINE constexpr bool IsNan (T x) noexcept
 
template<CArithmetic T>
JPL_INLINE constexpr auto Abs (const T &value) noexcept
 Standard abs is not constexpr in C++20.
 
template<std::floating_point T>
JPL_INLINE constexpr T Floor (T value) noexcept
 A constexpr implementation of floor.
 
template<CArithmetic T>
JPL_INLINE constexpr T Sign (T value) noexcept
 Sign returns -1 for negative values, 1 for positive, 0 for 0.
 
template<CArithmetic T>
JPL_INLINE constexpr T Sign2 (T value) noexcept
 Sign2 returns -1 for negative values, 1 otherwise.
 
template<CArithmetic T1, CArithmeticAndOrderedWith< T1 > T2>
JPL_INLINE constexpr bool IsPositiveAndBelow (T1 value, T2 below) noexcept
 
template<std::floating_point T>
JPL_INLINE constexpr bool IsNearlyZero (T value, T errorTolerance=JPL_FLOAT_EPS_V< T >) noexcept
 
template<std::floating_point T>
JPL_INLINE constexpr bool IsNearlyEqual (T a, T b, T tolerance=JPL_FLOAT_EPS_V< T >) noexcept
 
template<std::integral T>
JPL_INLINE constexpr bool IsEven (T number) noexcept
 
template<std::floating_point T>
JPL_INLINE std::pair< T, T > SinCos (T value) noexcept
 
template<std::floating_point T>
JPL_INLINE constexpr T Lerp (const T &v0, const T &v1, T t) noexcept
 Linearly interpolate v0 towards v1.
 
template<std::integral T, std::floating_point Tt>
JPL_INLINE constexpr T Lerp (const T &v0, const T &v1, Tt t) noexcept
 Linearly interpolate v0 towards v1.
 
template<std::floating_point T>
JPL_INLINE constexpr T FMA (T a, T b, T c) noexcept
 Inlined fuse multiply-add. Compiler in some circumstances is more eager to optimize this than std::fma.
 
template<std::floating_point T, int NR = 2>
JPL_INLINE constexpr T Sqrt (T x) noexcept
 
template<std::floating_point T, int NR = 2>
JPL_INLINE constexpr T InvSqrt (T x) noexcept
 
JPL_INLINE simd Sqrt (const simd &vec) noexcept
 Component-wise square root.
 
JPL_INLINE simd InvSqrt (const simd &vec) noexcept
 Component-wise inverse square root (1 / sqrt(x))
 
JPL_INLINE simd Sign2 (const simd &vec) noexcept
 Sign2 returns -1 for negative values, 1 otherwise.
 
JPL_INLINE simd_mask IsNearlyZero (const simd &vec, float tolerance=JPL_FLOAT_EPS) noexcept
 
JPL_INLINE simd FMA (const simd &mul1, const simd &mul2, const simd &addV) noexcept
 An overload to match our scalar version in Math.h.
 
JPL_INLINE simd Lerp (const simd &a, const simd &b, const simd &t) noexcept
 
template<int NR>
requires (NR > 0 && NR <= 2)
JPL_INLINE simd InvSqrtImpl (const simd &vec) noexcept
 
JPL_INLINE simd InvSqrtFast (const simd &vec) noexcept
 
void SinCos (simd x, simd &outSin, simd &outCos) noexcept
 Sin and Cos for 4-wide 32-bit float vector.
 
template<CVec3 Vec3>
JPL_INLINE constexpr bool IsNearlyEqual (const Vec3 &a, const Vec3 &b, Internal::FloatOf< Vec3 > tolerance=JPL_FLOAT_EPS_V< Internal::FloatOf< Vec3 > >) noexcept
 
template<CVec3 Vec3>
JPL_INLINE constexpr bool IsNearlyZero (const Vec3 &a, Internal::FloatOf< Vec3 > tolerance=JPL_FLOAT_EPS_V< Internal::FloatOf< Vec3 > >) noexcept
 
template<CVec3 Vec3>
JPL_INLINE bool HasNans (const Vec3 &vec)
 
template<CVec3 Vec3>
Vec3 GetNormalizedPerpendicular (const Vec3 &vec) noexcept
 
template<CVec3 Vec3>
void CreateOrthonormalBasis (const Vec3 &normal, Vec3 &tangent, Vec3 &bitangent) noexcept
 
template<CVec3 Vec3>
JPL_INLINE Vec3 RotateVector (const Vec3 &vector, const Vec3 &rotationAxis, float angleRad) noexcept
 
template<CVec3 Vec3>
JPL_INLINE Vec3 Lerp (const Vec3 &v0, const Vec3 &v1, float t) noexcept
 
JPL_INLINE Vec3Pack Lerp (const Vec3Pack &v0, const Vec3Pack &v1, simd t) noexcept
 
template<CVec3 Vec3>
JPL_INLINE Vec3 Nlerp (const Vec3 &v0, const Vec3 &v1, float t) noexcept
 
JPL_INLINE Vec3Pack Nlerp (const Vec3Pack &v0, const Vec3Pack &v1, simd t) noexcept
 
template<CVec3 Vec3>
Vec3 Slerp (const Vec3 &v0, const Vec3 &v1, float t) noexcept
 Input vectors must be normalized.
 
void Slerp (Vec3Pack &inOutV0, const Vec3Pack &V1, const simd &t) noexcept
 Input vectors must be normalized.
 
template<class Vec3 >
JPL_INLINE float ComputePDF (const Vec3 &normal, const Vec3 &outDirection, float diffusion, bool bIsSpecular)
 

Function Documentation

◆ Abs()

template<CArithmetic T>
JPL_INLINE constexpr auto JPL::Math::Abs ( const T & value)
nodiscardconstexprnoexcept

Standard abs is not constexpr in C++20.

◆ ComputePDF()

template<class Vec3 >
JPL_INLINE float JPL::Math::ComputePDF ( const Vec3 & normal,
const Vec3 & outDirection,
float diffusion,
bool bIsSpecular )

◆ CreateOrthonormalBasis()

template<CVec3 Vec3>
void JPL::Math::CreateOrthonormalBasis ( const Vec3 & normal,
Vec3 & tangent,
Vec3 & bitangent )
inlinenoexcept

◆ Floor()

template<std::floating_point T>
JPL_INLINE constexpr T JPL::Math::Floor ( T value)
nodiscardconstexprnoexcept

A constexpr implementation of floor.

A constexpr implementation of floor. Note: NaN-s and inf-s are not handled.

◆ FMA() [1/2]

JPL_INLINE simd JPL::Math::FMA ( const simd & mul1,
const simd & mul2,
const simd & addV )
noexcept

An overload to match our scalar version in Math.h.

◆ FMA() [2/2]

template<std::floating_point T>
JPL_INLINE constexpr T JPL::Math::FMA ( T a,
T b,
T c )
nodiscardconstexprnoexcept

Inlined fuse multiply-add. Compiler in some circumstances is more eager to optimize this than std::fma.

◆ GetNormalizedPerpendicular()

template<CVec3 Vec3>
Vec3 JPL::Math::GetNormalizedPerpendicular ( const Vec3 & vec)
inlinenodiscardnoexcept

◆ HasNans()

template<CVec3 Vec3>
JPL_INLINE bool JPL::Math::HasNans ( const Vec3 & vec)
nodiscard

◆ InvSqrt() [1/2]

JPL_INLINE simd JPL::Math::InvSqrt ( const simd & vec)
nodiscardnoexcept

Component-wise inverse square root (1 / sqrt(x))

◆ InvSqrt() [2/2]

template<std::floating_point T, int NR = 2>
JPL_INLINE constexpr T JPL::Math::InvSqrt ( T x)
nodiscardconstexprnoexcept

Inverse square root: constexpr at compile time, 1 / std::sqrt at runtime Tempalte param 'NR' (used for consteval path): number of Newton–Raphson refinement steps on 1/sqrt(x). NR=2 is a decent default for float.

◆ InvSqrtFast()

JPL_INLINE simd JPL::Math::InvSqrtFast ( const simd & vec)
noexcept

◆ InvSqrtImpl()

template<int NR>
requires (NR > 0 && NR <= 2)
JPL_INLINE simd JPL::Math::InvSqrtImpl ( const simd & vec)
noexcept

◆ IsEven()

template<std::integral T>
JPL_INLINE constexpr bool JPL::Math::IsEven ( T number)
nodiscardconstexprnoexcept

◆ IsNan()

template<std::floating_point T>
JPL_INLINE constexpr bool JPL::Math::IsNan ( T x)
nodiscardconstexprnoexcept

◆ IsNearlyEqual() [1/2]

template<CVec3 Vec3>
JPL_INLINE constexpr bool JPL::Math::IsNearlyEqual ( const Vec3 & a,
const Vec3 & b,
Internal::FloatOf< Vec3 > tolerance = JPL_FLOAT_EPS_V<Internal::FloatOf<Vec3>> )
nodiscardconstexprnoexcept

◆ IsNearlyEqual() [2/2]

template<std::floating_point T>
JPL_INLINE constexpr bool JPL::Math::IsNearlyEqual ( T a,
T b,
T tolerance = JPL_FLOAT_EPS_V<T> )
nodiscardconstexprnoexcept

◆ IsNearlyZero() [1/3]

JPL_INLINE simd_mask JPL::Math::IsNearlyZero ( const simd & vec,
float tolerance = JPL_FLOAT_EPS )
nodiscardnoexcept

◆ IsNearlyZero() [2/3]

template<CVec3 Vec3>
JPL_INLINE constexpr bool JPL::Math::IsNearlyZero ( const Vec3 & a,
Internal::FloatOf< Vec3 > tolerance = JPL_FLOAT_EPS_V<Internal::FloatOf<Vec3>> )
nodiscardconstexprnoexcept

◆ IsNearlyZero() [3/3]

template<std::floating_point T>
JPL_INLINE constexpr bool JPL::Math::IsNearlyZero ( T value,
T errorTolerance = JPL_FLOAT_EPS_V<T> )
nodiscardconstexprnoexcept

◆ IsPositiveAndBelow()

template<CArithmetic T1, CArithmeticAndOrderedWith< T1 > T2>
JPL_INLINE constexpr bool JPL::Math::IsPositiveAndBelow ( T1 value,
T2 below )
nodiscardconstexprnoexcept

◆ Lerp() [1/5]

JPL_INLINE simd JPL::Math::Lerp ( const simd & a,
const simd & b,
const simd & t )
noexcept

◆ Lerp() [2/5]

template<std::floating_point T>
JPL_INLINE constexpr T JPL::Math::Lerp ( const T & v0,
const T & v1,
T t )
nodiscardconstexprnoexcept

Linearly interpolate v0 towards v1.

◆ Lerp() [3/5]

template<std::integral T, std::floating_point Tt>
JPL_INLINE constexpr T JPL::Math::Lerp ( const T & v0,
const T & v1,
Tt t )
nodiscardconstexprnoexcept

Linearly interpolate v0 towards v1.

◆ Lerp() [4/5]

template<CVec3 Vec3>
JPL_INLINE Vec3 JPL::Math::Lerp ( const Vec3 & v0,
const Vec3 & v1,
float t )
nodiscardnoexcept

◆ Lerp() [5/5]

JPL_INLINE Vec3Pack JPL::Math::Lerp ( const Vec3Pack & v0,
const Vec3Pack & v1,
simd t )
nodiscardnoexcept

◆ Nlerp() [1/2]

template<CVec3 Vec3>
JPL_INLINE Vec3 JPL::Math::Nlerp ( const Vec3 & v0,
const Vec3 & v1,
float t )
nodiscardnoexcept

Linearly interpolate v0 towards v1 and normalize. Input vectors must be normalized

◆ Nlerp() [2/2]

JPL_INLINE Vec3Pack JPL::Math::Nlerp ( const Vec3Pack & v0,
const Vec3Pack & v1,
simd t )
nodiscardnoexcept

◆ RotateVector()

template<CVec3 Vec3>
JPL_INLINE Vec3 JPL::Math::RotateVector ( const Vec3 & vector,
const Vec3 & rotationAxis,
float angleRad )
nodiscardnoexcept

Rotate a 3D vector using Rodrigues' formula

Parameters
vectorVector to rotate.
rotationAxisNormalized axis to rotate around.
angleRadRotation angle in radians.

◆ Sign()

template<CArithmetic T>
JPL_INLINE constexpr T JPL::Math::Sign ( T value)
nodiscardconstexprnoexcept

Sign returns -1 for negative values, 1 for positive, 0 for 0.

◆ Sign2() [1/2]

JPL_INLINE simd JPL::Math::Sign2 ( const simd & vec)
nodiscardnoexcept

Sign2 returns -1 for negative values, 1 otherwise.

◆ Sign2() [2/2]

template<CArithmetic T>
JPL_INLINE constexpr T JPL::Math::Sign2 ( T value)
nodiscardconstexprnoexcept

Sign2 returns -1 for negative values, 1 otherwise.

◆ SinCos() [1/2]

void JPL::Math::SinCos ( simd x,
simd & outSin,
simd & outCos )
inlinenoexcept

Sin and Cos for 4-wide 32-bit float vector.

◆ SinCos() [2/2]

template<std::floating_point T>
JPL_INLINE std::pair< T, T > JPL::Math::SinCos ( T value)
nodiscardnoexcept

◆ Slerp() [1/2]

template<CVec3 Vec3>
Vec3 JPL::Math::Slerp ( const Vec3 & v0,
const Vec3 & v1,
float t )
inlinenodiscardnoexcept

Input vectors must be normalized.

◆ Slerp() [2/2]

void JPL::Math::Slerp ( Vec3Pack & inOutV0,
const Vec3Pack & V1,
const simd & t )
inlinenoexcept

Input vectors must be normalized.

◆ Sqrt() [1/2]

JPL_INLINE simd JPL::Math::Sqrt ( const simd & vec)
nodiscardnoexcept

Component-wise square root.

◆ Sqrt() [2/2]

template<std::floating_point T, int NR = 2>
JPL_INLINE constexpr T JPL::Math::Sqrt ( T x)
nodiscardconstexprnoexcept

Square root: constexpr at compile time, std::sqrt at runtime Tempalte param 'NR' (used for consteval path): number of Newton–Raphson refinement steps on 1/sqrt(x). NR=2 is a decent default for float.

◆ ToDegrees()

template<std::floating_point T>
JPL_INLINE constexpr T JPL::Math::ToDegrees ( T radians)
nodiscardconstexprnoexcept

Function to convert radians to degrees.

◆ ToRadians()

template<std::floating_point T>
JPL_INLINE constexpr T JPL::Math::ToRadians ( T degrees)
nodiscardconstexprnoexcept

Function to convert degrees to radians.