// // SPDX-License-Identifier: BSD-3-Clause // Copyright Contributors to the OpenEXR Project. // // clang-format off #ifndef _PyImathFunOperators_h_ #define _PyImathFunOperators_h_ #include #include #include #include #include namespace PyImath { template struct rotationXYZWithUpDir_op { static IMATH_NAMESPACE::Vec3 apply(const IMATH_NAMESPACE::Vec3 &from, const IMATH_NAMESPACE::Vec3 &to, const IMATH_NAMESPACE::Vec3 &up) { IMATH_NAMESPACE::Vec3 retval; IMATH_NAMESPACE::extractEulerXYZ(IMATH_NAMESPACE::rotationMatrixWithUpDir(from,to,up),retval); return retval; } }; template struct abs_op { static T apply(T value) { return IMATH_NAMESPACE::abs(value); } }; template struct sign_op { static T apply(T value) { return IMATH_NAMESPACE::sign(value); } }; template struct log_op { static T apply(T value) { return ::log(value); } }; template struct log10_op { static T apply(T value) { return ::log10(value); } }; template struct lerp_op { static T apply(T a, T b, T t) { return IMATH_NAMESPACE::lerp(a,b,t); } }; template struct ulerp_op { static T apply(T a, T b, T t) { return IMATH_NAMESPACE::ulerp(a,b,t); } }; template struct lerpfactor_op { static T apply(T a, T b, T t) { return IMATH_NAMESPACE::lerpfactor(a,b,t); } }; template struct clamp_op { static T apply(T value, T low, T high) { return IMATH_NAMESPACE::clamp(value,low,high); } }; template struct cmp_op { static T apply(T value) { return IMATH_NAMESPACE::cmp(value); } }; template struct cmpt_op { static T apply(T value) { return IMATH_NAMESPACE::cmpt(value); } }; template struct iszero_op { static T apply(T value) { return IMATH_NAMESPACE::iszero(value); } }; template struct equal_op { static T apply(T value) { return IMATH_NAMESPACE::equal(value); } }; template struct floor_op { static int apply(T value) { return IMATH_NAMESPACE::floor(value); } }; template struct ceil_op { static int apply(T value) { return IMATH_NAMESPACE::ceil(value); } }; template struct trunc_op { static int apply(T value) { return IMATH_NAMESPACE::trunc(value); } }; struct divs_op { static int apply(int x, int y) { return IMATH_NAMESPACE::divs(x,y); } }; struct mods_op { static int apply(int x, int y) { return IMATH_NAMESPACE::mods(x,y); } }; struct divp_op { static int apply(int x, int y) { return IMATH_NAMESPACE::divp(x,y); } }; struct modp_op { static int apply(int x, int y) { return IMATH_NAMESPACE::modp(x,y); } }; struct bias_op { static inline float apply(float x, float b) { if (b != 0.5f) { static const float inverse_log_half = 1.0f / std::log(0.5f); const float biasPow = std::log(b)*inverse_log_half; return std::pow(x, biasPow); } return x; } }; struct gain_op { static inline float apply(float x, float g) { if (x < 0.5f) return 0.5f*bias_op::apply(2.0f*x, 1.0f - g); else return 1.0f - 0.5f*bias_op::apply(2.0f - 2.0f*x, 1.0f - g); } }; template struct rgb2hsv_op { static inline IMATH_NAMESPACE::Vec3 apply(const IMATH_NAMESPACE::Vec3 &rgb) { return IMATH_NAMESPACE::rgb2hsv(rgb); } }; template struct hsv2rgb_op { static inline IMATH_NAMESPACE::Vec3 apply(const IMATH_NAMESPACE::Vec3 &rgb) { return IMATH_NAMESPACE::hsv2rgb(rgb); } }; template struct min_op { static inline T apply(T x, T y) { return std::min(x,y); } }; template struct max_op { static inline T apply(T x, T y) { return std::max(x,y); } }; template struct sin_op { static inline T apply(T theta) { return std::sin(theta); } }; template struct cos_op { static inline T apply(T theta) { return std::cos(theta); } }; template struct tan_op { static inline T apply(T theta) { return std::tan(theta); } }; template struct asin_op { static inline T apply(T x) { return std::asin(x); } }; template struct acos_op { static inline T apply(T x) { return std::acos(x); } }; template struct atan_op { static inline float apply(T x) { return std::atan(x); } }; template struct atan2_op { static inline T apply(T y, T x) { return std::atan2(y,x); } }; template struct sqrt_op { static inline T apply(T x) { return std::sqrt(x); } }; template struct pow_op { static inline T apply(T x, T y) { return std::pow(x,y); } }; template struct exp_op { static inline T apply(T x) { return std::exp(x); } }; template struct sinh_op { static inline T apply(T x) { return std::sinh(x); } }; template struct cosh_op { static inline T apply(T x) { return std::cosh(x); } }; } // namespace PyImath #endif // _PyImathFunOperators_h_