30 return x + ((y - x) & mask);
39 return x + ((y - x) & mask);
44 KY_INLINE
KyInt32 Isign(
KyInt32 x) {
return (x >> 31) - ((-x) >> 31); };
49 template <
typename T> KY_INLINE T Min(
const T& a,
const T& b) {
return (a < b) ? a : b; }
50 template <
typename T> KY_INLINE T Max(
const T& a,
const T& b) {
return (a < b) ? b : a; }
52 template <
typename T> KY_INLINE T Min(
const T& a,
const T& b,
const T& c) {
return Min(Min(a, b), c); }
53 template <
typename T> KY_INLINE T Max(
const T& a,
const T& b,
const T& c) {
return Max(Max(a, b), c); }
55 template <
typename T> KY_INLINE T Min(
const T& a,
const T& b,
const T& c,
const T& d) {
return Min(Min(a, b), Min(c, d)); }
56 template <
typename T> KY_INLINE T Max(
const T& a,
const T& b,
const T& c,
const T& d) {
return Max(Max(a, b), Max(c, d)); }
58 template <
typename T> KY_INLINE T Min(
const T& a,
const T& b,
const T& c,
const T& d,
const T& e) {
return Min(Min(a, b, c, d), e); }
59 template <
typename T> KY_INLINE T Max(
const T& a,
const T& b,
const T& c,
const T& d,
const T& e) {
return Max(Max(a, b, c, d), e); }
61 template <
typename T> KY_INLINE T Clamp(
const T& x,
const T& min_,
const T& max_)
63 if (x > max_)
return max_;
64 if (x < min_)
return min_;
68 template <
typename T>
inline bool Less(
const T& a,
const T& b,
const T& c) {
return a < b && b < c; }
69 template <
typename T>
inline bool LessEq(
const T& a,
const T& b,
const T& c) {
return a <= b && b <= c; }
73 #if defined(KY_CPU_PPC) || defined(KY_CPU_PPC64)
83 KY_INLINE
KyUInt32 FastDivisionBy3(
KyUInt32 i) {
return (i * 0x0000AAAB) >> 17; }
84 KY_INLINE
KyUInt32 FastModuloBy3(
KyUInt32 i) {
return i - 3 * FastDivisionBy3(i); }
106 template <
typename T1,
typename T2 = T1>
110 KY_INLINE
bool operator()(
const T1& lhs,
const T2& rhs)
const {
return lhs < rhs; }
160 static const KyFloat32 KY_MIN_NORMALIZED_FLOAT = FLT_MIN;
161 static const KyFloat32 KY_EPSILON = FLT_EPSILON;
163 KY_INLINE
bool IsFloatDenormalized(
KyFloat32 x) {
return x < KY_MIN_NORMALIZED_FLOAT && x > -KY_MIN_NORMALIZED_FLOAT; }
164 KY_INLINE
bool IsFloatNormalized(
KyFloat32 x) {
return x >= KY_MIN_NORMALIZED_FLOAT || x <= -KY_MIN_NORMALIZED_FLOAT; }
165 KY_INLINE
bool CanDivideBy(
KyFloat32 x) {
return x >= KY_MIN_NORMALIZED_FLOAT || x <= -KY_MIN_NORMALIZED_FLOAT; }
167 KY_INLINE
bool IsEpsilonPositive(
KyFloat32 x) {
return x > KY_EPSILON; }
168 KY_INLINE
bool IsEpsilonNegative(
KyFloat32 x) {
return x < -KY_EPSILON; }
169 KY_INLINE
bool IsEpsilonZero(
KyFloat32 x) {
return x <= KY_EPSILON && x >= -KY_EPSILON; }
170 KY_INLINE
bool IsEpsilonEqual(
KyFloat32 a,
KyFloat32 b) {
return IsEpsilonZero(a - b); };
172 KY_INLINE
bool IsNearZero(
KyFloat32 x,
KyFloat32 dist) {
return x <= dist && x >= -dist; }
178 namespace Winding {
enum Enum { CCW = 0, CW = 1}; }
181 KY_INLINE T Square(
const T& x) {
return x * x; }
183 #define KY_SQRT1_2 ((KyFloat32)0.70710678118654752440f) // 1/sqrt(2)
197 KyInt64 c = (m2 == 0 && sab == 0) ? 0 : 2 * sab + 1;
205 KyInt64 sb = 2 * (b >> 63) + 1;
206 KyInt64 c = (1 + sab) * (b - sb) + sab * b;
207 return (a + c / 2) / b;
218 KyInt64 sb = 2 * (b >> 63) + 1;
static const KyFloat32 KY_PI
Stores the value of pi.
Definition: fastmath.h:142
static const KyFloat32 KY_180_DIVIDED_BY_PI
Stores the value of 180 divided by KY_PI.
Definition: fastmath.h:145
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
KyInt64 Lsign(KyInt64 x)
return -1 if x<0, 0="" if="" x="=0," 1="" if="" x="">0 0,>
Definition: fastmath.h:43
KyFloat32 DegFromRad(KyFloat32 radians)
Converts radians into degrees.
Definition: fastmath.h:147
KyInt32 Isel(KyInt32 a, KyInt32 x, KyInt32 y)
If a is greater than 0, returns x.
Definition: fastmath.h:26
KyFloat32 RadFromDeg(KyFloat32 degrees)
Converts degrees into radians.
Definition: fastmath.h:146
std::int64_t KyInt64
int64_t
Definition: types.h:25
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
std::int32_t KyInt32
int32_t
Definition: types.h:24
static const KyFloat32 KY_PI_DIVIDED_BY_180
Stores the value of KY_PI divided by 180.
Definition: fastmath.h:144
static const KyFloat32 KY_2_PI
Stores the value of 2*pi.
Definition: fastmath.h:143
KyFloat32 Fsel(KyFloat32 a, KyFloat32 x, KyFloat32 y)
x if a>=0.0f, y if a<0.0f>0.0f>
Definition: fastmath.h:19
float KyFloat32
float
Definition: types.h:32
KyInt64 Lsel(KyInt64 a, KyInt64 x, KyInt64 y)
If a is greater than 0, returns x.
Definition: fastmath.h:35