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"
22PXR_NAMESPACE_OPEN_SCOPE
28inline bool GfIsClose(
double a,
double b,
double epsilon) {
29 return fabs(a-b) < epsilon;
35 return radians * (180.0 / M_PI);
41 return degrees * (M_PI / 180.0);
53 double slope0 = 0.0,
double slope1 = 0.0);
166double GfSmoothRamp(
double tmin,
double tmax,
double t,
double w0,
double w1);
185 return (v < 0) ? -1 : ((v > 0) ? 1 : 0);
190inline double GfSqrt(
double f) {
return std::sqrt(f); }
193inline float GfSqrt(
float f) {
return std::sqrt(f); }
197inline double GfExp(
double f) {
return std::exp(f); }
200inline float GfExp(
float f) {
return std::exp(f); }
204inline double GfLog(
double f) {
return std::log(f); }
207inline float GfLog(
float f) {
return std::log(f); }
211inline double GfFloor(
double f) {
return std::floor(f); }
214inline float GfFloor(
float f) {
return std::floor(f); }
218inline double GfCeil(
double f) {
return std::ceil(f); }
221inline float GfCeil(
float f) {
return std::ceil(f); }
225inline double GfAbs(
double f) {
return std::fabs(f); }
228inline float GfAbs(
float f) {
return std::fabs(f); }
232inline double GfRound(
double f) {
return std::rint(f); }
235inline float GfRound(
float f) {
return std::rint(f); }
239inline double GfPow(
double f,
double p) {
return std::pow(f, p); }
242inline float GfPow(
float f,
float p) {
return std::pow(f, p); }
246inline double GfSin(
double v) {
return std::sin(v); }
249inline float GfSin(
float v) {
return std::sin(v); }
252inline double GfCos(
double v) {
return std::cos(v); }
255inline float GfCos(
float v) {
return std::cos(v); }
266inline double GfClamp(
double value,
double min,
double max) {
267 if (value < min)
return min;
268 if (value > max)
return max;
274inline float GfClamp(
float value,
float min,
float max) {
275 if (value < min)
return min;
276 if (value > max)
return max;
303inline T
GfLerp(
double alpha,
const T& a,
const T& b) {
304 return (1-alpha)* a + alpha * b;
311 return (a1 < a2 ? a1 : a2);
314inline T
GfMin(T a1, T a2, T a3) {
318inline T
GfMin(T a1, T a2, T a3, T a4) {
322inline T
GfMin(T a1, T a2, T a3, T a4, T a5) {
330 return (a1 < a2 ? a2 : a1);
333inline T
GfMax(T a1, T a2, T a3) {
337inline T
GfMax(T a1, T a2, T a3, T a4) {
341inline T
GfMax(T a1, T a2, T a3, T a4, T a5) {
348template <
typename Left,
typename Right,
349 std::enable_if_t<GfIsArithmetic<Left>::value &&
351inline decltype(std::declval<Left>() * std::declval<Right>())
359template <
typename Left,
typename Right,
360 std::enable_if_t<GfIsArithmetic<Left>::value &&
362inline decltype(std::declval<Left>() * std::declval<Right>())
370template <
typename Left,
typename Right,
371 std::enable_if_t<GfIsArithmetic<Left>::value &&
373inline decltype(std::declval<Left>() / std::declval<Right>())
378PXR_NAMESPACE_CLOSE_SCOPE
Architecture-specific math function calls.
TfType represents a dynamic runtime type.
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.
GF_API double GfSmoothStep(double min, double max, double val, double slope0=0.0, double slope1=0.0)
Smooth step function using a cubic hermite blend.
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).
GF_API double GfSmoothRamp(double tmin, double tmax, double t, double w0, double w1)
Smooth Step with independently controllable shoulders.
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...