pbpt
Loading...
Searching...
No Matches
pbpt::math Namespace Reference

The namespace for math library implementation. More...

Namespaces

namespace  detail
 Contains internal implementation details for the math library.

Classes

class  BoundingBox
class  Homogeneous
 A template class for an N-dimensional homogeneous coordinate. More...
class  Matrix
 A template class for RxC dimensional mathematical matrices. More...
class  MatrixView
 A non-owning, mutable view/proxy into a sub-region of another Matrix. More...
class  Normal
class  Point
 A template class for an N-dimensional point in space. More...
class  Ray
 A template class for an N-dimensional geometric ray. More...
class  RayDifferential
class  Transform
 A namespace for 3D transformation factory functions. More...
class  Vector
 A template class for N-dimensional mathematical vectors. More...
class  VectorView
 A non-owning, mutable view/proxy of vector-like data. More...

Typedefs

using Bound3 = BoundingBox<Float, 3>
 3D bounding box
using Bound2 = BoundingBox<Float, 2>
 2D bounding box
using Float = float
 The primary floating-point type used throughout the math library.
using Homo3 = Homogeneous<Float, 3>
 A 3-dimensional homogeneous coordinate using the library's default Float type.
using Homo2 = Homogeneous<Float, 2>
using Mat2 = Matrix<Float, 2, 2>
 A 2x2 matrix of type Float.
using Mat3 = Matrix<Float, 3, 3>
 A 3x3 matrix of type Float.
using Mat4 = Matrix<Float, 4, 4>
 A 4x4 matrix of type Float.
using Mat3x4 = Matrix<Float, 3, 4>
 A 3x4 matrix of type Float.
using Mat4x3 = Matrix<Float, 4, 3>
 A 4x3 matrix of type Float.
using Pt2 = Point<Float, 2>
 A 2-dimensional point of type Float.
using Pt3 = Point<Float, 3>
 A 3-dimensional point of type Float.
using Pt4 = Point<Float, 4>
 A 4-dimensional point of type Float.
using Ray3 = Ray<Float, 3>
 A 3-dimensional ray of type Float, commonly used in 3D graphics.
using Ray2 = Ray<Float, 2>
 A 2-dimensional ray of type Float.
using RayDiff3 = RayDifferential<Float, 3>
using Vec2 = Vector<Float, 2>
 A 2-dimensional vector of type Float.
using Vec3 = Vector<Float, 3>
 A 3-dimensional vector of type Float.
using Vec4 = Vector<Float, 4>
 A 4-dimensional vector of type Float.
using Normal2 = Normal<Float, 2>
 A 2-dimensional vector of type Float.
using Normal3 = Normal<Float, 3>
 A 3-dimensional vector of type Float.
using Normal4 = Normal<Float, 4>
 A 4-dimensional vector of type Float.

Functions

template<typename T>
constexpr T abs (T x)
 A constexpr implementation of the absolute value function.
template<typename T>
requires std::is_floating_point_v<T>
constexpr T rad2deg (T rad)
 Converts an angle from radians to degrees.
template<typename T>
requires std::is_floating_point_v<T>
constexpr T deg2rad (T deg)
 Converts an angle from degrees to radians.
template<typename T>
constexpr T sqrt (T x)
 Calculates the square root of a number with constexpr support.
template<typename T>
requires std::is_floating_point_v<T>
constexpr T sin (T x)
 Calculates the sine of an angle with constexpr support.
template<typename T>
requires std::is_floating_point_v<T>
constexpr T cos (T x)
 Calculates the cosine of an angle with constexpr support.
template<typename T>
requires std::is_floating_point_v<T>
constexpr T tan (T x)
 Calculates the tangent of an angle with constexpr support.
template<typename T>
requires std::is_floating_point_v<T>
constexpr bool is_equal (T a, T b)
 Compares two floating-point values for equality.
template<typename T>
requires std::is_floating_point_v<T>
constexpr bool is_greater (T a, T b)
 Compares if a is greater than b.
template<typename T>
requires std::is_floating_point_v<T>
constexpr bool is_less_equal (T a, T b)
 Compares if a is less than or equal to b.
template<typename T>
requires std::is_floating_point_v<T>
constexpr bool is_less (T a, T b)
 Compares if a is less than b.
template<typename T>
requires std::is_floating_point_v<T>
constexpr bool is_greater_equal (T a, T b)
 Compares if a is greater than or equal to b.
template<typename T, int N>
constexpr std::vector< Vector< T, N > > get_orthogonal_bases (const Vector< T, N > &base)
 Returns orthogonal bases for a given vector.
template<typename T>
constexpr std::vector< Vector< T, 2 > > get_orthogonal_bases (const Vector< T, 2 > &base)
 Returns orthogonal bases for a given vector when N == 2.
template<typename T>
constexpr std::vector< Vector< T, 3 > > get_orthogonal_bases (const Vector< T, 3 > &base)
 Returns orthogonal bases for a given vector when N == 3.

Detailed Description

The namespace for math library implementation.

Typedef Documentation

◆ Float

using pbpt::math::Float = float

The primary floating-point type used throughout the math library.

This type alias controls the precision of geometric and mathematical calculations.

  • If the FLOAT_64BIT preprocessor macro is defined, Float will be a double (64-bit).
  • Otherwise, Float will default to a float (32-bit).
Note
To use double-precision floating-point numbers, define the FLOAT_64BIT macro in your project's build settings, for example, by passing the -DFLOAT_64BIT flag to your C++ compiler.

Function Documentation

◆ abs()

template<typename T>
T pbpt::math::abs ( T x)
constexpr

A constexpr implementation of the absolute value function.

Template Parameters
TThe arithmetic type of the number.
Parameters
xThe number to get the absolute value of.
Returns
The absolute value of x.

◆ cos()

template<typename T>
requires std::is_floating_point_v<T>
T pbpt::math::cos ( T x)
constexpr

Calculates the cosine of an angle with constexpr support.

At compile-time, uses a Taylor series. At runtime, calls std::cos. It can be implemented efficiently by shifting the angle and calling pbpt::math::sin.

Template Parameters
TFloating-point type of the angle.
Parameters
xThe angle in radians.
Returns
The cosine of x.

◆ deg2rad()

template<typename T>
requires std::is_floating_point_v<T>
T pbpt::math::deg2rad ( T deg)
constexpr

Converts an angle from degrees to radians.

Template Parameters
TThe floating-point type of the angle.
Parameters
degThe angle in degrees.
Returns
The angle in radians.

◆ get_orthogonal_bases() [1/3]

template<typename T>
std::vector< Vector< T, 2 > > pbpt::math::get_orthogonal_bases ( const Vector< T, 2 > & base)
inlineconstexpr

Returns orthogonal bases for a given vector when N == 2.

Template Parameters
ArgsThe types of the orthogonal vectors.
Parameters
uThe input vector.
Returns
A vector of orthogonal vectors.

◆ get_orthogonal_bases() [2/3]

template<typename T>
std::vector< Vector< T, 3 > > pbpt::math::get_orthogonal_bases ( const Vector< T, 3 > & base)
inlineconstexpr

Returns orthogonal bases for a given vector when N == 3.

Template Parameters
ArgsThe types of the orthogonal vectors.
Parameters
baseThe input vector.
Returns
A vector of orthogonal vectors.

◆ get_orthogonal_bases() [3/3]

template<typename T, int N>
std::vector< Vector< T, N > > pbpt::math::get_orthogonal_bases ( const Vector< T, N > & base)
inlineconstexpr

Returns orthogonal bases for a given vector.

Template Parameters
ArgsThe types of the orthogonal vectors.
Parameters
baseThe input vector.
Returns
A vector of orthogonal vectors.

◆ is_equal()

template<typename T>
requires std::is_floating_point_v<T>
bool pbpt::math::is_equal ( T a,
T b )
constexpr

Compares two floating-point values for equality.

This function checks if the absolute difference between a and b is less than a predefined epsilon (EPSILON). This is a conservative approach, but it's useful in constexpr contexts where exact comparisons are not always possible.

Template Parameters
TFloating-point type of the values.
Parameters
aThe first value.
bThe second value.
Returns
true if abs(a - b) < EPSILON, false otherwise.

◆ is_greater()

template<typename T>
requires std::is_floating_point_v<T>
bool pbpt::math::is_greater ( T a,
T b )
constexpr

Compares if a is greater than b.

This function checks if a - b is greater than a predefined epsilon (EPSILON).

Template Parameters
TFloating-point type of the values.
Parameters
aThe first value.
bThe second value.
Returns
true if a - b > EPSILON, false otherwise.

◆ is_greater_equal()

template<typename T>
requires std::is_floating_point_v<T>
bool pbpt::math::is_greater_equal ( T a,
T b )
constexpr

Compares if a is greater than or equal to b.

This function checks if a - b is greater than a predefined epsilon (EPSILON).

Template Parameters
TFloating-point type of the values.
Parameters
aThe first value.
bThe second value.
Returns
true if a - b > EPSILON, false otherwise.

◆ is_less()

template<typename T>
requires std::is_floating_point_v<T>
bool pbpt::math::is_less ( T a,
T b )
constexpr

Compares if a is less than b.

This function checks if b - a is greater than a predefined epsilon (EPSILON).

Template Parameters
TFloating-point type of the values.
Parameters
aThe first value.
bThe second value.
Returns
true if b - a > EPSILON, false otherwise.

◆ is_less_equal()

template<typename T>
requires std::is_floating_point_v<T>
bool pbpt::math::is_less_equal ( T a,
T b )
constexpr

Compares if a is less than or equal to b.

This function checks if b - a is greater than a predefined epsilon (EPSILON).

Template Parameters
TFloating-point type of the values.
Parameters
aThe first value.
bThe second value.
Returns
true if b - a > EPSILON, false otherwise.

◆ rad2deg()

template<typename T>
requires std::is_floating_point_v<T>
T pbpt::math::rad2deg ( T rad)
constexpr

Converts an angle from radians to degrees.

This function converts an angle from radians to degrees.

Template Parameters
TThe floating-point type of the angle.
Parameters
radThe angle in radians.
Returns
requires constexpr

◆ sin()

template<typename T>
requires std::is_floating_point_v<T>
T pbpt::math::sin ( T x)
constexpr

Calculates the sine of an angle with constexpr support.

At compile-time, uses a Taylor series. At runtime, calls std::sin. The compile-time version performs range reduction to maintain precision.

Template Parameters
TFloating-point type of the angle.
Parameters
xThe angle in radians.
Returns
The sine of x.

◆ sqrt()

template<typename T>
T pbpt::math::sqrt ( T x)
constexpr

Calculates the square root of a number with constexpr support.

This function intelligently switches its implementation based on the evaluation context.

  • At compile-time (inside a constexpr expression), it uses a constexpr-friendly Newton-Raphson implementation (detail::sqrt_newton_raphson).
  • At runtime, it calls the standard library's std::sqrt, which is typically faster and more accurate due to hardware-specific optimizations (e.g., FPU instructions).

This dual approach provides both compile-time evaluation capabilities and runtime performance.

Template Parameters
TThe arithmetic type of the number.
Parameters
xThe non-negative number to find the square root of.
Returns
The square root of x.
Exceptions
std::runtime_errorIf a negative x is passed at runtime.
Note
Providing a negative x at compile-time will result in a compilation error.

◆ tan()

template<typename T>
requires std::is_floating_point_v<T>
T pbpt::math::tan ( T x)
constexpr

Calculates the tangent of an angle with constexpr support.

This function is implemented as sin(x) / cos(x), automatically leveraging their context-aware constexpr behavior.

Template Parameters
TFloating-point type of the angle.
Parameters
xThe angle in radians.
Returns
The tangent of x.