24#include "AstUtil/MathDegree.hpp"
25#include "AstUtil/Constants.h"
50A_ALWAYS_INLINE
void sincos (
double x,
double *psin,
double *pcos)
63 double sin()
const {
return sin_; }
65 double& sin() {
return sin_; }
67 double cos()
const {
return cos_; }
69 double& cos() {
return cos_; }
82 sincos(x, &sc.sin_, &sc.cos_);
89template<
typename Scalar>
90Scalar
aMax(Scalar a, Scalar b)
96template<
typename Scalar>
97Scalar
aMin(Scalar a, Scalar b)
111A_CONSTEXPR_CXX14
const T&
clamp(
const T& val,
const T& low,
const T& high)
114 assert(low <= high &&
"low must be less than or equal to high");
123 return (val < low) ? low : ((val > high) ? high : val);
133 return std::asin(
clamp(x, -1.0, 1.0));
141 return std::acos(
clamp(x, -1.0, 1.0));
149 return std::sqrt((std::max)(x, 0.0));
154template<
typename Scalar>
167 return angle - floor((angle - start) /
kTwoPI) *
kTwoPI;
207namespace propagate_nan
210 A_ALWAYS_INLINE double (min)(
double a,
double b)
216 return std::numeric_limits<double>::quiet_NaN();
220 A_ALWAYS_INLINE double (max)(
double a,
double b)
226 return std::numeric_limits<double>::quiet_NaN();
232 template <
typename T>
236 template <
typename T>
239 template <
typename U>
240 static auto test(
int) ->
decltype(std::declval<U>() - std::declval<U>(), std::true_type());
241 template <
typename U>
242 static std::false_type test(...);
244 static constexpr bool value =
decltype(test<T>(0))::value;
248 template <
typename T>
255 typename std::enable_if<!use_efficient_minus<T>::value,
const T&>::type
256 (min)(
const T& a,
const T& b)
267 template <
typename T>
268 typename std::enable_if<use_efficient_minus<T>::value,
const T&>::type
269 (min)(
const T& a,
const T& b) {
272 if (diff <= 0)
return a;
273 if (diff >= 0)
return b;
280 typename std::enable_if<!use_efficient_minus<T>::value,
const T&>::type
281 (max)(
const T& a,
const T& b)
292 template <
typename T>
293 typename std::enable_if<use_efficient_minus<T>::value,
const T&>::type
294 (max)(
const T& a,
const T& b)
298 if (diff >= 0)
return a;
299 if (diff <= 0)
return b;
包含 sin(x) 和 cos(x) 值的结构体
定义 Math.hpp:60
constexpr double kTwoPI
2*PI
定义 Constants.h:54
A_ALWAYS_INLINE double sqrtSafe(double x)
安全平方根,参数自动箝位到 [0, +∞]
定义 Math.hpp:147
A_ALWAYS_INLINE double aNormalizeAngle0To2Pi(double angle)
将角度量规范化到 0 到 2π 范围
定义 Math.hpp:184
A_ALWAYS_INLINE double asinSafe(double x)
安全反正弦,参数自动箝位到 [-1, 1]
定义 Math.hpp:131
A_ALWAYS_INLINE double aNormalizeAngleNegPiToPi(double angle)
将角度量规范化到 -π 到 π 范围
定义 Math.hpp:192
A_CONSTEXPR_CXX14 const T & clamp(const T &val, const T &low, const T &high)
对值进行范围限制
定义 Math.hpp:111
Scalar aMax(Scalar a, Scalar b)
计算两个数中的较大值
定义 Math.hpp:90
constexpr double kPI
PI
定义 Constants.h:53
A_ALWAYS_INLINE double aNormalizeAngleNeg2PiTo0(double angle)
将角度量规范化到 -2π 到 0 范围
定义 Math.hpp:200
Scalar aMin(Scalar a, Scalar b)
计算两个数中的较小值
定义 Math.hpp:97
A_ALWAYS_INLINE double aNormalizeAngleStart(double angle, double start)
将角度量规范化到指定起始范围
定义 Math.hpp:165
A_ALWAYS_INLINE double aNormalizeAngle(double angle, double center)
将角度量规范化到指定中心范围
定义 Math.hpp:175
Scalar square(Scalar x)
计算平方
定义 Math.hpp:155
A_ALWAYS_INLINE double acosSafe(double x)
安全反余弦,参数自动箝位到 [-1, 1]
定义 Math.hpp:139
A_ALWAYS_INLINE void sincos(double x, double *psin, double *pcos)
计算 sin(x) 和 cos(x) 值
定义 Math.hpp:50