24#include "AstUtil/MathDegree.hpp"
25#include "AstUtil/Constants.hpp"
51A_ALWAYS_INLINE
void sincos (
double x,
double *psin,
double *pcos)
64 double sin()
const {
return sin_; }
66 double& sin() {
return sin_; }
68 double cos()
const {
return cos_; }
70 double& cos() {
return cos_; }
83 sincos(x, &sc.sin_, &sc.cos_);
90template<
typename Scalar>
91Scalar
aMax(Scalar a, Scalar b)
97template<
typename Scalar>
98Scalar
aMin(Scalar a, Scalar b)
100 return a < b ? a : b;
109 if (step <= 0.0 || span < 0.0)
111 return static_cast<size_t>(std::ceil(span / step)) + 1;
123A_CONSTEXPR_CXX14
const T&
clamp(
const T& val,
const T& low,
const T& high)
126 assert(low <= high &&
"low must be less than or equal to high");
135 return (val < low) ? low : ((val > high) ? high : val);
145 return std::asin(
clamp(x, -1.0, 1.0));
153 return std::acos(
clamp(x, -1.0, 1.0));
161 return std::sqrt((std::max)(x, 0.0));
166template<
typename Scalar>
179 return angle - floor((angle - start) /
kTwoPI) *
kTwoPI;
219namespace propagate_nan
222 A_ALWAYS_INLINE double (min)(
double a,
double b)
228 return std::numeric_limits<double>::quiet_NaN();
232 A_ALWAYS_INLINE double (max)(
double a,
double b)
238 return std::numeric_limits<double>::quiet_NaN();
244 template <
typename T>
248 template <
typename T>
251 template <
typename U>
252 static auto test(
int) ->
decltype(std::declval<U>() - std::declval<U>(), std::true_type());
253 template <
typename U>
254 static std::false_type test(...);
256 static constexpr bool value =
decltype(test<T>(0))::value;
260 template <
typename T>
267 typename std::enable_if<!use_efficient_minus<T>::value,
const T&>::type
268 (min)(
const T& a,
const T& b)
279 template <
typename T>
280 typename std::enable_if<use_efficient_minus<T>::value,
const T&>::type
281 (min)(
const T& a,
const T& b) {
284 if (diff <= 0)
return a;
285 if (diff >= 0)
return b;
292 typename std::enable_if<!use_efficient_minus<T>::value,
const T&>::type
293 (max)(
const T& a,
const T& b)
304 template <
typename T>
305 typename std::enable_if<use_efficient_minus<T>::value,
const T&>::type
306 (max)(
const T& a,
const T& b)
310 if (diff >= 0)
return a;
311 if (diff <= 0)
return b;
包含 sin(x) 和 cos(x) 值的结构体
定义 Math.hpp:61
constexpr double kTwoPI
2*PI
定义 Constants.hpp:55
A_ALWAYS_INLINE size_t aDiscretizedCount(double span, double step)
计算闭区间 [0, span] 按 step 步长采样(含两端点)的采样点数
定义 Math.hpp:107
A_ALWAYS_INLINE double sqrtSafe(double x)
安全平方根,参数自动箝位到 [0, +∞]
定义 Math.hpp:159
A_ALWAYS_INLINE double aNormalizeAngle0To2Pi(double angle)
将角度量规范化到 0 到 2π 范围
定义 Math.hpp:196
A_ALWAYS_INLINE double asinSafe(double x)
安全反正弦,参数自动箝位到 [-1, 1]
定义 Math.hpp:143
A_ALWAYS_INLINE double aNormalizeAngleNegPiToPi(double angle)
将角度量规范化到 -π 到 π 范围
定义 Math.hpp:204
A_CONSTEXPR_CXX14 const T & clamp(const T &val, const T &low, const T &high)
对值进行范围限制
定义 Math.hpp:123
Scalar aMax(Scalar a, Scalar b)
计算两个数中的较大值
定义 Math.hpp:91
constexpr double kPI
PI
定义 Constants.hpp:54
A_ALWAYS_INLINE double aNormalizeAngleNeg2PiTo0(double angle)
将角度量规范化到 -2π 到 0 范围
定义 Math.hpp:212
Scalar aMin(Scalar a, Scalar b)
计算两个数中的较小值
定义 Math.hpp:98
A_ALWAYS_INLINE double aNormalizeAngleStart(double angle, double start)
将角度量规范化到指定起始范围
定义 Math.hpp:177
A_ALWAYS_INLINE double aNormalizeAngle(double angle, double center)
将角度量规范化到指定中心范围
定义 Math.hpp:187
Scalar square(Scalar x)
计算平方
定义 Math.hpp:167
A_ALWAYS_INLINE double acosSafe(double x)
安全反余弦,参数自动箝位到 [-1, 1]
定义 Math.hpp:151
A_ALWAYS_INLINE void sincos(double x, double *psin, double *pcos)
计算 sin(x) 和 cos(x) 值
定义 Math.hpp:51