24#ifndef PXR_BASE_GF_MATH_H
25#define PXR_BASE_GF_MATH_H
33#include "pxr/base/gf/api.h"
34#include "pxr/base/gf/traits.h"
38PXR_NAMESPACE_OPEN_SCOPE
42inline bool GfIsClose(
double a,
double b,
double epsilon) {
43 return fabs(a-b) < epsilon;
49 return radians * (180.0 / M_PI);
55 return degrees * (M_PI / 180.0);
62inline double GfSqr(
const T& x) {
75 return (v < 0) ? -1 : ((v > 0) ? 1 : 0);
80inline double GfSqrt(
double f) {
return std::sqrt(f); }
83inline float GfSqrt(
float f) {
return std::sqrt(f); }
87inline double GfExp(
double f) {
return std::exp(f); }
90inline float GfExp(
float f) {
return std::exp(f); }
94inline double GfLog(
double f) {
return std::log(f); }
97inline float GfLog(
float f) {
return std::log(f); }
101inline double GfFloor(
double f) {
return std::floor(f); }
104inline float GfFloor(
float f) {
return std::floor(f); }
108inline double GfCeil(
double f) {
return std::ceil(f); }
111inline float GfCeil(
float f) {
return std::ceil(f); }
115inline double GfAbs(
double f) {
return std::fabs(f); }
118inline float GfAbs(
float f) {
return std::fabs(f); }
122inline double GfRound(
double f) {
return std::rint(f); }
125inline float GfRound(
float f) {
return std::rint(f); }
129inline double GfPow(
double f,
double p) {
return std::pow(f, p); }
132inline float GfPow(
float f,
float p) {
return std::pow(f, p); }
136inline double GfSin(
double v) {
return std::sin(v); }
139inline float GfSin(
float v) {
return std::sin(v); }
142inline double GfCos(
double v) {
return std::cos(v); }
145inline float GfCos(
float v) {
return std::cos(v); }
156inline double GfClamp(
double value,
double min,
double max) {
157 if (value < min)
return min;
158 if (value > max)
return max;
164inline float GfClamp(
float value,
float min,
float max) {
165 if (value < min)
return min;
166 if (value > max)
return max;
193inline T
GfLerp(
double alpha,
const T& a,
const T& b) {
194 return (1-alpha)* a + alpha * b;
201 return (a1 < a2 ? a1 : a2);
204inline T
GfMin(T a1, T a2, T a3) {
208inline T
GfMin(T a1, T a2, T a3, T a4) {
212inline T
GfMin(T a1, T a2, T a3, T a4, T a5) {
220 return (a1 < a2 ? a2 : a1);
223inline T
GfMax(T a1, T a2, T a3) {
227inline T
GfMax(T a1, T a2, T a3, T a4) {
231inline T
GfMax(T a1, T a2, T a3, T a4, T a5) {
238template <
typename Left,
typename Right,
239 std::enable_if_t<GfIsArithmetic<Left>::value &&
241inline decltype(std::declval<Left>() * std::declval<Right>())
249template <
typename Left,
typename Right,
250 std::enable_if_t<GfIsArithmetic<Left>::value &&
252inline decltype(std::declval<Left>() * std::declval<Right>())
260template <
typename Left,
typename Right,
261 std::enable_if_t<GfIsArithmetic<Left>::value &&
263inline decltype(std::declval<Left>() / std::declval<Right>())
269PXR_NAMESPACE_CLOSE_SCOPE
Architecture-specific math function calls.
void ArchSinCos(double v, double *s, double *c)
Computes the sine and cosine of the specified value as a double.
void ArchSinCosf(float v, float *s, float *c)
Computes the sine and cosine of the specified value as a float.
decltype(std::declval< Left >()/std::declval< Right >()) GfCompDiv(Left left, Right right)
Returns component-wise quotient of vectors.
double GfDegreesToRadians(double degrees)
Converts an angle in degrees to radians.
double GfPow(double f, double p)
Return pow(f, p).
double GfSqr(const T &x)
Returns the inner product of x with itself: specifically, x*x.
GF_API double GfMod(double a, double b)
The mod function with "correct" behaviour for negative numbers.
double GfCos(double v)
Return cos(v).
double GfRadiansToDegrees(double radians)
Converts an angle in radians to degrees.
double GfRound(double f)
Return round(f).
double GfFloor(double f)
Return floor(f).
double GfClamp(double value, double min, double max)
Return the resulting of clamping value to lie between min and max.
bool GfIsClose(double a, double b, double epsilon)
Returns true if a and b are with epsilon of each other.
double GfCeil(double f)
Return ceil(f).
T GfMin(T a1, T a2)
Returns the smallest of the given values.
void GfSinCos(double v, double *s, double *c)
Return sin(v) in s and cos(v) in c.
double GfSqrt(double f)
Return sqrt(f).
double GfLog(double f)
Return log(f).
T GfMax(T a1, T a2)
Returns the largest of the given values.
decltype(std::declval< Left >() *std::declval< Right >()) GfDot(Left left, Right right)
Returns the dot (inner) product of two vectors.
T GfLerp(double alpha, const T &a, const T &b)
Linear interpolation function.
double GfAbs(double f)
Return abs(f).
T GfSgn(T v)
Return the signum of v (i.e.
double GfSin(double v)
Return sin(v).
double GfExp(double f)
Return exp(f).
decltype(std::declval< Left >() *std::declval< Right >()) GfCompMult(Left left, Right right)
Returns component-wise multiplication of vectors.
A metafunction which is equivalent to std::arithmetic but also includes any specializations from GfIs...