cesium-native  0.41.0
CesiumUtility::Math Class Referencefinal

Mathematical constants and functions. More...

#include <CesiumUtility/Math.h>

Static Public Member Functions

template<glm::length_t L, typename T , glm::qualifier Q>
static constexpr glm::vec< L, T, Q > relativeEpsilonToAbsolute (const glm::vec< L, T, Q > &a, const glm::vec< L, T, Q > &b, double relativeEpsilon) noexcept
 Converts a relative to an absolute epsilon, for the epsilon-equality check between two values. More...
 
static constexpr double relativeEpsilonToAbsolute (double a, double b, double relativeEpsilon) noexcept
 Converts a relative to an absolute epsilon, for the epsilon-equality check between two values. More...
 
template<glm::length_t L, typename T , glm::qualifier Q>
static constexpr bool equalsEpsilon (const glm::vec< L, T, Q > &left, const glm::vec< L, T, Q > &right, double relativeEpsilon) noexcept
 Checks whether two values are equal up to a given relative epsilon. More...
 
static constexpr bool equalsEpsilon (double left, double right, double relativeEpsilon) noexcept
 Checks whether two values are equal up to a given relative epsilon. More...
 
static constexpr bool equalsEpsilon (double left, double right, double relativeEpsilon, double absoluteEpsilon) noexcept
 Determines if two values are equal using an absolute or relative tolerance test. More...
 
template<glm::length_t L, typename T , glm::qualifier Q>
static constexpr bool equalsEpsilon (const glm::vec< L, T, Q > &left, const glm::vec< L, T, Q > &right, double relativeEpsilon, double absoluteEpsilon) noexcept
 Determines if two values are equal using an absolute or relative tolerance test. More...
 
static constexpr double sign (double value) noexcept
 Returns the sign of the value. More...
 
static constexpr double signNotZero (double value) noexcept
 Returns 1.0 if the given value is positive or zero, and -1.0 if it is negative. More...
 
static double negativePiToPi (double angle) noexcept
 Produces an angle in the range -Pi <= angle <= Pi which is equivalent to the provided angle. More...
 
static double zeroToTwoPi (double angle) noexcept
 Produces an angle in the range 0 <= angle <= 2Pi which is equivalent to the provided angle. More...
 
static double mod (double m, double n) noexcept
 The modulo operation that also works for negative dividends. More...
 
static constexpr double degreesToRadians (double angleDegrees) noexcept
 Converts degrees to radians. More...
 
static constexpr double radiansToDegrees (double angleRadians) noexcept
 Converts radians to degrees. More...
 
static double lerp (double p, double q, double time) noexcept
 Computes the linear interpolation of two values. More...
 
static constexpr double clamp (double value, double min, double max) noexcept
 Constrain a value to lie between two values. More...
 
static double toSNorm (double value, double rangeMaximum=255.0) noexcept
 Converts a scalar value in the range [-1.0, 1.0] to a SNORM in the range [0, rangeMaximum]. More...
 
static constexpr double fromSNorm (double value, double rangeMaximum=255.0) noexcept
 Converts a SNORM value in the range [0, rangeMaximum] to a scalar in the range [-1.0, 1.0]. More...
 
static double convertLongitudeRange (double angle) noexcept
 
static double roundUp (double value, double tolerance) noexcept
 Rounds a value up to the nearest integer, like ceil, except that if the value is very close to the lower integer it is rounded down (like floor) instead. More...
 
static double roundDown (double value, double tolerance) noexcept
 Rounds a value down to the nearest integer, like floor, except that if the value is very close to the higher integer it is rounded up (like ceil) instead. More...
 
template<typename T , glm::qualifier Q>
static glm::vec< 3, T, Q > perpVec (const glm::vec< 3, T, Q > &v)
 Construct a vector perpendicular to the argument. More...
 
template<typename T , glm::qualifier Q>
static glm::qua< T, Q > rotation (const glm::vec< 3, T, Q > &vec1, const glm::vec< 3, T, Q > &vec2)
 Compute the rotation between two unit vectors. More...
 

Static Public Attributes

static constexpr double Epsilon1 = 1e-1
 0.1
 
static constexpr double Epsilon2 = 1e-2
 0.01
 
static constexpr double Epsilon3 = 1e-3
 0.001
 
static constexpr double Epsilon4 = 1e-4
 0.0001
 
static constexpr double Epsilon5 = 1e-5
 0.00001
 
static constexpr double Epsilon6 = 1e-6
 0.000001
 
static constexpr double Epsilon7 = 1e-7
 0.0000001
 
static constexpr double Epsilon8 = 1e-8
 0.00000001
 
static constexpr double Epsilon9 = 1e-9
 0.000000001
 
static constexpr double Epsilon10 = 1e-10
 0.0000000001
 
static constexpr double Epsilon11 = 1e-11
 0.00000000001
 
static constexpr double Epsilon12 = 1e-12
 0.000000000001
 
static constexpr double Epsilon13 = 1e-13
 0.0000000000001
 
static constexpr double Epsilon14 = 1e-14
 0.00000000000001
 
static constexpr double Epsilon15 = 1e-15
 0.000000000000001
 
static constexpr double Epsilon16 = 1e-16
 0.0000000000000001
 
static constexpr double Epsilon17 = 1e-17
 0.00000000000000001
 
static constexpr double Epsilon18 = 1e-18
 0.000000000000000001
 
static constexpr double Epsilon19 = 1e-19
 0.0000000000000000001
 
static constexpr double Epsilon20 = 1e-20
 0.00000000000000000001
 
static constexpr double Epsilon21 = 1e-21
 0.000000000000000000001
 
static constexpr double OnePi = 3.14159265358979323846
 pi
 
static constexpr double TwoPi = OnePi * 2.0
 two times pi
 
static constexpr double PiOverTwo = OnePi / 2.0
 pi divded by two
 

Detailed Description

Mathematical constants and functions.

Definition at line 12 of file Math.h.

Member Function Documentation

◆ clamp()

static constexpr double CesiumUtility::Math::clamp ( double  value,
double  min,
double  max 
)
inlinestaticconstexprnoexcept

Constrain a value to lie between two values.

Parameters
valueThe value to constrain.
minThe minimum value.
maxThe maximum value.
Returns
The value clamped so that min <= value <= max.

Definition at line 356 of file Math.h.

◆ convertLongitudeRange()

static double CesiumUtility::Math::convertLongitudeRange ( double  angle)
inlinestaticnoexcept

Converts a longitude value, in radians, to the range [-Math::OnePi, Math::OnePi).

Parameters
angleThe longitude value, in radians, to convert to the range [-Math::OnePi, Math::OnePi).
Returns
The equivalent longitude value in the range [-Math::OnePi, Math::OnePi).
// Convert 270 degrees to -90 degrees longitude
static constexpr double degreesToRadians(double angleDegrees) noexcept
Converts degrees to radians.
Definition: Math.h:320
static double convertLongitudeRange(double angle) noexcept
Definition: Math.h:400

Definition at line 400 of file Math.h.

◆ degreesToRadians()

static constexpr double CesiumUtility::Math::degreesToRadians ( double  angleDegrees)
inlinestaticconstexprnoexcept

Converts degrees to radians.

Parameters
angleDegreesThe angle to convert in degrees.
Returns
The corresponding angle in radians.

Definition at line 320 of file Math.h.

◆ equalsEpsilon() [1/4]

template<glm::length_t L, typename T , glm::qualifier Q>
static constexpr bool CesiumUtility::Math::equalsEpsilon ( const glm::vec< L, T, Q > &  left,
const glm::vec< L, T, Q > &  right,
double  relativeEpsilon 
)
inlinestaticconstexprnoexcept

Checks whether two values are equal up to a given relative epsilon.

Template Parameters
LThe length type.
Tvalue value type.
QThe GLM qualifier type.
Parameters
leftThe first value.
rightThe second value.
relativeEpsilonThe relative epsilon.
Returns
Whether the values are epsilon-equal

Definition at line 142 of file Math.h.

◆ equalsEpsilon() [2/4]

template<glm::length_t L, typename T , glm::qualifier Q>
static constexpr bool CesiumUtility::Math::equalsEpsilon ( const glm::vec< L, T, Q > &  left,
const glm::vec< L, T, Q > &  right,
double  relativeEpsilon,
double  absoluteEpsilon 
)
inlinestaticconstexprnoexcept

Determines if two values are equal using an absolute or relative tolerance test.

This is useful to avoid problems due to roundoff error when comparing floating-point values directly. The values are first compared using an absolute tolerance test. If that fails, a relative tolerance test is performed. Use this test if you are unsure of the magnitudes of left and right.

Template Parameters
LThe length type.
Tvalue value type.
QThe GLM qualifier type.
Parameters
leftThe first value to compare.
rightThe other value to compare.
relativeEpsilonThe maximum inclusive delta between left and right for the relative tolerance test.
absoluteEpsilonThe maximum inclusive delta between left and right for the absolute tolerance test.
Returns
true if the values are equal within the epsilon; otherwise, false.

Definition at line 217 of file Math.h.

◆ equalsEpsilon() [3/4]

static constexpr bool CesiumUtility::Math::equalsEpsilon ( double  left,
double  right,
double  relativeEpsilon 
)
inlinestaticconstexprnoexcept

Checks whether two values are equal up to a given relative epsilon.

Parameters
leftThe first value.
rightThe second value.
relativeEpsilonThe relative epsilon.
Returns
Whether the values are epsilon-equal

Definition at line 158 of file Math.h.

◆ equalsEpsilon() [4/4]

static constexpr bool CesiumUtility::Math::equalsEpsilon ( double  left,
double  right,
double  relativeEpsilon,
double  absoluteEpsilon 
)
inlinestaticconstexprnoexcept

Determines if two values are equal using an absolute or relative tolerance test.

This is useful to avoid problems due to roundoff error when comparing floating-point values directly. The values are first compared using an absolute tolerance test. If that fails, a relative tolerance test is performed. Use this test if you are unsure of the magnitudes of left and right.

Parameters
leftThe first value to compare.
rightThe other value to compare.
relativeEpsilonThe maximum inclusive delta between left and right for the relative tolerance test.
absoluteEpsilonThe maximum inclusive delta between left and right for the absolute tolerance test.
Returns
true if the values are equal within the epsilon; otherwise, false.
0.0,
0.01,
0.0,
0.1,
3699175.1634344,
3699175.2,
3699175.1634344,
3699175.2,
static constexpr double Epsilon9
0.000000001
Definition: Math.h:39
static constexpr double Epsilon2
0.01
Definition: Math.h:18
static constexpr bool equalsEpsilon(const glm::vec< L, T, Q > &left, const glm::vec< L, T, Q > &right, double relativeEpsilon) noexcept
Checks whether two values are equal up to a given relative epsilon.
Definition: Math.h:142
static constexpr double Epsilon7
0.0000001
Definition: Math.h:33

Definition at line 183 of file Math.h.

◆ fromSNorm()

static constexpr double CesiumUtility::Math::fromSNorm ( double  value,
double  rangeMaximum = 255.0 
)
inlinestaticconstexprnoexcept

Converts a SNORM value in the range [0, rangeMaximum] to a scalar in the range [-1.0, 1.0].

Parameters
valueSNORM value in the range [0, rangeMaximum].
rangeMaximumThe maximum value in the SNORM range, 255 by default.
Returns
Scalar in the range [-1.0, 1.0].
See also
Math::toSNorm

Definition at line 385 of file Math.h.

◆ lerp()

static double CesiumUtility::Math::lerp ( double  p,
double  q,
double  time 
)
inlinestaticnoexcept

Computes the linear interpolation of two values.

Parameters
pThe start value to interpolate.
qThe end value to interpolate.
timeThe time of interpolation generally in the range [0.0, 1.0].
Returns
The linearly interpolated value.
double n = CesiumUtility::Math::lerp(0.0, 2.0, 0.5); // returns 1.0
static double lerp(double p, double q, double time) noexcept
Computes the linear interpolation of two values.
Definition: Math.h:344

Definition at line 344 of file Math.h.

◆ mod()

static double CesiumUtility::Math::mod ( double  m,
double  n 
)
inlinestaticnoexcept

The modulo operation that also works for negative dividends.

Parameters
mThe dividend.
nThe divisor.
Returns
The remainder.

Definition at line 305 of file Math.h.

◆ negativePiToPi()

static double CesiumUtility::Math::negativePiToPi ( double  angle)
inlinestaticnoexcept

Produces an angle in the range -Pi <= angle <= Pi which is equivalent to the provided angle.

Parameters
angleThe angle in radians.
Returns
The angle in the range [-Math::OnePi, Math::OnePi].

Definition at line 269 of file Math.h.

◆ perpVec()

template<typename T , glm::qualifier Q>
static glm::vec<3, T, Q> CesiumUtility::Math::perpVec ( const glm::vec< 3, T, Q > &  v)
inlinestatic

Construct a vector perpendicular to the argument.

Parameters
vThe input vector
Returns
A vector perpendicular to the input vector

Definition at line 461 of file Math.h.

◆ radiansToDegrees()

static constexpr double CesiumUtility::Math::radiansToDegrees ( double  angleRadians)
inlinestaticconstexprnoexcept

Converts radians to degrees.

Parameters
angleRadiansThe angle to convert in radians.
Returns
The corresponding angle in degrees.

Definition at line 330 of file Math.h.

◆ relativeEpsilonToAbsolute() [1/2]

template<glm::length_t L, typename T , glm::qualifier Q>
static constexpr glm::vec<L, T, Q> CesiumUtility::Math::relativeEpsilonToAbsolute ( const glm::vec< L, T, Q > &  a,
const glm::vec< L, T, Q > &  b,
double  relativeEpsilon 
)
inlinestaticconstexprnoexcept

Converts a relative to an absolute epsilon, for the epsilon-equality check between two values.

Template Parameters
LThe length type.
Tvalue value type.
QThe GLM qualifier type.
Parameters
aThe first value.
bThe second value.
relativeEpsilonThe relative epsilon.
Returns
The absolute epsilon.

Definition at line 106 of file Math.h.

◆ relativeEpsilonToAbsolute() [2/2]

static constexpr double CesiumUtility::Math::relativeEpsilonToAbsolute ( double  a,
double  b,
double  relativeEpsilon 
)
inlinestaticconstexprnoexcept

Converts a relative to an absolute epsilon, for the epsilon-equality check between two values.

Parameters
aThe first value.
bThe second value.
relativeEpsilonThe relative epsilon.
Returns
The absolute epsilon.

Definition at line 122 of file Math.h.

◆ rotation()

template<typename T , glm::qualifier Q>
static glm::qua<T, Q> CesiumUtility::Math::rotation ( const glm::vec< 3, T, Q > &  vec1,
const glm::vec< 3, T, Q > &  vec2 
)
inlinestatic

Compute the rotation between two unit vectors.

Parameters
vec1The first vector.
vec2The second vector.
Returns
A quaternion representing the rotation of vec1 to vec2.

Definition at line 477 of file Math.h.

◆ roundDown()

static double CesiumUtility::Math::roundDown ( double  value,
double  tolerance 
)
inlinestaticnoexcept

Rounds a value down to the nearest integer, like floor, except that if the value is very close to the higher integer it is rounded up (like ceil) instead.

Parameters
valueThe value to round.
toleranceThe tolerance. If the value is closer than this to the higher integer, it is rounded up instead.
Returns
The rounded value.

Definition at line 445 of file Math.h.

◆ roundUp()

static double CesiumUtility::Math::roundUp ( double  value,
double  tolerance 
)
inlinestaticnoexcept

Rounds a value up to the nearest integer, like ceil, except that if the value is very close to the lower integer it is rounded down (like floor) instead.

Parameters
valueThe value to round.
toleranceThe tolerance. If the value is closer than this to the lower integer, it is rounded down instead.
Returns
The rounded value.

Definition at line 425 of file Math.h.

◆ sign()

static constexpr double CesiumUtility::Math::sign ( double  value)
inlinestaticconstexprnoexcept

Returns the sign of the value.

This is 1 if the value is positive, -1 if the value is negative, or 0 if the value is 0.

Parameters
valueThe value to return the sign of.
Returns
The sign of value.

Definition at line 240 of file Math.h.

◆ signNotZero()

static constexpr double CesiumUtility::Math::signNotZero ( double  value)
inlinestaticconstexprnoexcept

Returns 1.0 if the given value is positive or zero, and -1.0 if it is negative.

This is similar to Math::sign except that returns 1.0 instead of 0.0 when the input value is 0.0.

Parameters
valueThe value to return the sign of.
Returns
The sign of value.

Definition at line 258 of file Math.h.

◆ toSNorm()

static double CesiumUtility::Math::toSNorm ( double  value,
double  rangeMaximum = 255.0 
)
inlinestaticnoexcept

Converts a scalar value in the range [-1.0, 1.0] to a SNORM in the range [0, rangeMaximum].

Parameters
valueThe scalar value in the range [-1.0, 1.0].
rangeMaximumThe maximum value in the mapped range, 255 by default.
Returns
A SNORM value, where 0 maps to -1.0 and rangeMaximum maps to 1.0.
See also
Math::fromSNorm

Definition at line 370 of file Math.h.

◆ zeroToTwoPi()

static double CesiumUtility::Math::zeroToTwoPi ( double  angle)
inlinestaticnoexcept

Produces an angle in the range 0 <= angle <= 2Pi which is equivalent to the provided angle.

Parameters
angleThe angle in radians.
Returns
The angle in the range [0, Math::TwoPi].

Definition at line 285 of file Math.h.


The documentation for this class was generated from the following file: