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);
50 double slope0 = 0.0,
double slope1 = 0.0);
163double GfSmoothRamp(
double tmin,
double tmax,
double t,
double w0,
double w1);
182 return (v < 0) ? -1 : ((v > 0) ? 1 : 0);
187inline double GfSqrt(
double f) {
return std::sqrt(f); }
190inline float GfSqrt(
float f) {
return std::sqrt(f); }
194inline double GfExp(
double f) {
return std::exp(f); }
197inline float GfExp(
float f) {
return std::exp(f); }
201inline double GfLog(
double f) {
return std::log(f); }
204inline float GfLog(
float f) {
return std::log(f); }
208inline double GfFloor(
double f) {
return std::floor(f); }
211inline float GfFloor(
float f) {
return std::floor(f); }
215inline double GfCeil(
double f) {
return std::ceil(f); }
218inline float GfCeil(
float f) {
return std::ceil(f); }
222inline double GfAbs(
double f) {
return std::fabs(f); }
225inline float GfAbs(
float f) {
return std::fabs(f); }
229inline double GfRound(
double f) {
return std::rint(f); }
232inline float GfRound(
float f) {
return std::rint(f); }
236inline double GfPow(
double f,
double p) {
return std::pow(f, p); }
239inline float GfPow(
float f,
float p) {
return std::pow(f, p); }
243inline double GfSin(
double v) {
return std::sin(v); }
246inline float GfSin(
float v) {
return std::sin(v); }
249inline double GfCos(
double v) {
return std::cos(v); }
252inline float GfCos(
float v) {
return std::cos(v); }
263inline double GfClamp(
double value,
double min,
double max) {
264 if (value < min)
return min;
265 if (value > max)
return max;
271inline float GfClamp(
float value,
float min,
float max) {
272 if (value < min)
return min;
273 if (value > max)
return max;
300inline T
GfLerp(
double alpha,
const T& a,
const T& b) {
301 return (1-alpha)* a + alpha * b;
308 return (a1 < a2 ? a1 : a2);
311inline T
GfMin(T a1, T a2, T a3) {
315inline T
GfMin(T a1, T a2, T a3, T a4) {
319inline T
GfMin(T a1, T a2, T a3, T a4, T a5) {
327 return (a1 < a2 ? a2 : a1);
330inline T
GfMax(T a1, T a2, T a3) {
334inline T
GfMax(T a1, T a2, T a3, T a4) {
338inline T
GfMax(T a1, T a2, T a3, T a4, T a5) {
345template <
typename Left,
typename Right,
346 std::enable_if_t<GfIsArithmetic<Left>::value &&
348inline decltype(std::declval<Left>() * std::declval<Right>())
356template <
typename Left,
typename Right,
357 std::enable_if_t<GfIsArithmetic<Left>::value &&
359inline decltype(std::declval<Left>() * std::declval<Right>())
367template <
typename Left,
typename Right,
368 std::enable_if_t<GfIsArithmetic<Left>::value &&
370inline decltype(std::declval<Left>() / std::declval<Right>())
376PXR_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.
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...