Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
MathUtils.h File Reference
#include <array>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <limits>
#include <type_traits>
#include <utility>
#include "donner/base/Utils.h"
Include dependency graph for MathUtils.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  donner::MathConstants< T >
 Contains a set of math constants for the specified type (float or double). More...
 
struct  donner::MathConstants< float >
 Math constants for float. More...
 
struct  donner::MathConstants< double >
 Math constants for double. More...
 
struct  donner::QuadraticSolution< T >
 Holds the solution of a quadratic equation, as returned by SolveQuadratic. More...
 

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.
 

Functions

float donner::NarrowToFloat (double from)
 Semantically represent a narrowing conversion, such as converting a double to a float, to make the conversion more visible.
 
template<typename T >
const T & donner::Min (const T &a, const T &b)
 Returns minimum of the provided values.
 
template<typename T , typename... Args>
const T & donner::Min (const T &a, const T &b, Args &&... args)
 Returns minimum of the provided values.
 
template<typename T >
const T & donner::Max (const T &a, const T &b)
 Returns maximum of the provided values.
 
template<typename T , typename... Args>
const T & donner::Max (const T &a, const T &b, Args &&... args)
 Returns maximum of the provided values.
 
float donner::Abs (float a)
 Returns the absolute value of the number.
 
double donner::Abs (double a)
 Returns the absolute value of the number.
 
template<typename T , typename = std::enable_if<std::is_integral<T>::value && std::is_signed<T>::value>>
donner::Abs (T a)
 Returns the absolute value of the number.
 
template<typename T , typename = std::enable_if<std::is_floating_point<T>::value>>
donner::Round (T orig)
 Round a floating point value to an integer.
 
template<typename T >
donner::Lerp (T a, T b, const float t)
 Returns linear interpolation of a and b with ratio t.
 
template<typename T >
const T donner::Clamp (T value, T low, T high)
 Clamps a value between low and high.
 
template<typename T >
bool donner::NearEquals (T a, T b, T tolerance=std::numeric_limits< T >::epsilon())
 Returns if a equals b, taking possible rounding errors into account.
 
template<typename T >
bool donner::NearZero (T a, T tolerance=std::numeric_limits< T >::epsilon())
 Returns if a equals zero, taking rounding errors into account.
 
template<typename T , typename = std::enable_if<std::is_integral<T>::value>>
bool donner::InRange (T var, T start, T end)
 Test if a variable is in a specific range, using an optimized technique that requires only one branch.
 
template<typename T >
QuadraticSolution< T > donner::SolveQuadratic (T a, T b, T c)
 Solve a quadratic equation.
 

Class Documentation

◆ donner::MathConstants

struct donner::MathConstants
template<typename T>
struct donner::MathConstants< T >

Contains a set of math constants for the specified type (float or double).

Template Parameters
T

◆ donner::QuadraticSolution

struct donner::QuadraticSolution
template<typename T>
struct donner::QuadraticSolution< T >

Holds the solution of a quadratic equation, as returned by SolveQuadratic.

Template Parameters
T
Collaboration diagram for donner::QuadraticSolution< T >:
[legend]
Class Members
bool hasSolution = false True if the equation has solutions.
array< T, 2 > solution Solutions to the equation, valid if hasSolution is true.