7#ifndef PXR_BASE_GF_MATH_H
8#define PXR_BASE_GF_MATH_H
16#include "pxr/base/gf/api.h"
17#include "pxr/base/gf/traits.h"
21PXR_NAMESPACE_OPEN_SCOPE
25inline bool GfIsClose(
double a,
double b,
double epsilon) {
26 return fabs(a-b) < epsilon;
32 return radians * (180.0 / M_PI);
38 return degrees * (M_PI / 180.0);
45inline double GfSqr(
const T& x) {
58 return (v < 0) ? -1 : ((v > 0) ? 1 : 0);
63inline double GfSqrt(
double f) {
return std::sqrt(f); }
66inline float GfSqrt(
float f) {
return std::sqrt(f); }
70inline double GfExp(
double f) {
return std::exp(f); }
73inline float GfExp(
float f) {
return std::exp(f); }
77inline double GfLog(
double f) {
return std::log(f); }
80inline float GfLog(
float f) {
return std::log(f); }
84inline double GfFloor(
double f) {
return std::floor(f); }
87inline float GfFloor(
float f) {
return std::floor(f); }
91inline double GfCeil(
double f) {
return std::ceil(f); }
94inline float GfCeil(
float f) {
return std::ceil(f); }
98inline double GfAbs(
double f) {
return std::fabs(f); }
101inline float GfAbs(
float f) {
return std::fabs(f); }
105inline double GfRound(
double f) {
return std::rint(f); }
108inline float GfRound(
float f) {
return std::rint(f); }
112inline double GfPow(
double f,
double p) {
return std::pow(f, p); }
115inline float GfPow(
float f,
float p) {
return std::pow(f, p); }
119inline double GfSin(
double v) {
return std::sin(v); }
122inline float GfSin(
float v) {
return std::sin(v); }
125inline double GfCos(
double v) {
return std::cos(v); }
128inline float GfCos(
float v) {
return std::cos(v); }
139inline double GfClamp(
double value,
double min,
double max) {
140 if (value < min)
return min;
141 if (value > max)
return max;
147inline float GfClamp(
float value,
float min,
float max) {
148 if (value < min)
return min;
149 if (value > max)
return max;
176inline T
GfLerp(
double alpha,
const T& a,
const T& b) {
177 return (1-alpha)* a + alpha * b;
184 return (a1 < a2 ? a1 : a2);
187inline T
GfMin(T a1, T a2, T a3) {
191inline T
GfMin(T a1, T a2, T a3, T a4) {
195inline T
GfMin(T a1, T a2, T a3, T a4, T a5) {
203 return (a1 < a2 ? a2 : a1);
206inline T
GfMax(T a1, T a2, T a3) {
210inline T
GfMax(T a1, T a2, T a3, T a4) {
214inline T
GfMax(T a1, T a2, T a3, T a4, T a5) {
221template <
typename Left,
typename Right,
222 std::enable_if_t<GfIsArithmetic<Left>::value &&
224inline decltype(std::declval<Left>() * std::declval<Right>())
232template <
typename Left,
typename Right,
233 std::enable_if_t<GfIsArithmetic<Left>::value &&
235inline decltype(std::declval<Left>() * std::declval<Right>())
243template <
typename Left,
typename Right,
244 std::enable_if_t<GfIsArithmetic<Left>::value &&
246inline decltype(std::declval<Left>() / std::declval<Right>())
252PXR_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...