Math module

Math functions and types.

Modules

module abs()
Constexpr-friendly alternatives to std::abs.
module acos()
Constexpr-friendly alternatives to std::acos.
module approx_equal()
Checks if floating-point values are approximately equal.
module approx_zero()
Checks if floating-point values are approximately equal to zero.
module asin()
Constexpr-friendly alternatives to std::asin.
module atan()
Constexpr-friendly alternatives to std::atan.
module atan2()
Constexpr-friendly alternatives to std::atan2.
module ceil()
Constexpr-friendly alternatives to std::ceil.
module consteval_sqrt()
std::sqrt alternatives that are always available at compile time.
module cos()
Constexpr-friendly alternatives to std::cos.
module degenerate()
Retuurns true if a math class type is in a degenerate state.
module floor()
Constexpr-friendly alternatives to std::floor.
module infinity_or_nan()
Checks for infinities and not-a-numbers (NaN).
module lerp()
Linear interpolations al a C++20's std::lerp.
module normalize_angle()
Normalizes angles, wrapping their values to the range [0.0, 2 * pi).
module normalize_angle_signed()
Normalizes angles, wrapping their values to the range [-pi, pi).
module sin()
Constexpr-friendly alternatives to std::sin.
module sqrt()
Constexpr-friendly alternatives to std::sqrt.
module tan()
Constexpr-friendly alternatives to std::tan.

Classes

template <typename ValueType, typename Impl = impl::default_accumulator<ValueType>::type>
class muu::accumulator
Determines min, max and sum of an interderminate number of values.
template <typename Scalar>
struct muu::axis_angle
An axis-angle rotation.
template <typename Scalar>
struct muu::bounding_box
An axis-aligned bounding box.
template <typename Scalar>
struct muu::bounding_sphere
A bounding sphere.
template <typename Scalar>
struct muu::euler_angles
A set of euler angles used for rotation.
template <typename Scalar>
struct muu::line_segment
A line segment.
template <typename Scalar, size_t Rows, size_t Columns>
struct muu::matrix
A matrix.
template <typename Scalar>
struct muu::oriented_bounding_box
An oriented bounding box.
template <typename Scalar>
struct muu::plane
A plane.
template <typename Scalar>
struct muu::quaternion
A quaternion.
template <typename Scalar>
struct muu::ray
A ray.
template <typename Scalar, size_t Dimensions>
struct muu::sat_tester
A helper utility for performing Separating-Axis Theorem tests.
template <typename Scalar>
struct muu::triangle
A triangle.
template <typename Scalar, size_t Dimensions>
struct muu::vector
An N-dimensional vector.

Enums

enum class box_corner: uint8_t { min = 0, x = 1, y = 2, xy = x | y, z = 4, xz = x | z, yz = y | z, xyz = x | y | z, max = xyz }
Corner masks/indices for three-dimensional bounding-boxes.
enum class math_apis { directx = 0, opengl = 1, right_handed = 0, left_handed = 2 }
Flags relating to math APIs w.r.t some graphics + rendering environments (e.g. DirectX).

Functions

template <typename T, typename U>
auto contains(const T& outer, const U& inner) -> bool constexpr noexcept
Checks if an object contains another object.
template <typename T>
auto evenly_distribute(T total, T bucket_count, T bucket_index) -> T constexpr noexcept
Evenly divides an integer into buckets.
template <typename T, typename U, typename... V>
auto gcd(T val1, U val2, V... vals) -> std::common_type_t<T, U, V...> constexpr noexcept
Returns the lowest common multiple of two or more integers.
template <typename T, typename U>
auto intersects(const T& obj1, const U& obj2) -> bool constexpr noexcept
Checks if two objects intersect.
template <typename T, typename U, typename... V>
auto lcm(T val1, U val2, V... vals) -> std::common_type_t<T, U, V...> constexpr noexcept
Returns the lowest common multiple of two or more integers.

Enum documentation

enum class box_corner: uint8_t

Corner masks/indices for three-dimensional bounding-boxes.

Enumerators
min

The 'min' corner (negative offset on all axes).

x

The corner with a positive offset on the X axis, negative on Y and Z.

y

The corner with a positive offset on the Y axis, negative on X and Z.

xy

The corner with a positive offset on the X and Y axes, negative on Z.

z

The corner with a positive offset on the Z axis, negative on X and Y.

xz

The corner with a positive offset on the X and Z axes, negative on Y.

yz

The corner with a positive offset on the Y and Z axes, negative on X.

xyz

The 'max' corner (positive offset on all axes).

max

The 'max' corner (positive offset on all axes).

enum class math_apis

Flags relating to math APIs w.r.t some graphics + rendering environments (e.g. DirectX).

Enumerators
directx

DirectX (default)

opengl

OpenGL.

right_handed

Right-handed coordinate system (default)

left_handed

Left-handed coordinate system.

Function documentation

#include <muu/math.h>
template <typename T, typename U>
bool contains(const T& outer, const U& inner) constexpr noexcept

Checks if an object contains another object.

Template parameters
T The type of the outer object.
U The type of the inner object.
Parameters
outer The outer object.
inner The inner object.
Returns Returns true if the outer object compltely contained the inner object.

#include <muu/math.h>
template <typename T>
T evenly_distribute(T total, T bucket_count, T bucket_index) constexpr noexcept

Evenly divides an integer into buckets.

#include <muu/math.h>
template <typename T, typename U, typename... V>
std::common_type_t<T, U, V...> gcd(T val1, U val2, V... vals) constexpr noexcept

Returns the lowest common multiple of two or more integers.

#include <muu/math.h>
template <typename T, typename U>
bool intersects(const T& obj1, const U& obj2) constexpr noexcept

Checks if two objects intersect.

Template parameters
T The type of object 1.
U The type of object 2.
Parameters
obj1 Object 1.
obj2 Object 2.
Returns Returns true if the two objects intersect.

#include <muu/math.h>
template <typename T, typename U, typename... V>
std::common_type_t<T, U, V...> lcm(T val1, U val2, V... vals) constexpr noexcept

Returns the lowest common multiple of two or more integers.