Merge branch 'master' into hsh

This commit is contained in:
Luke Street 2020-09-28 18:33:49 -04:00
commit 542e3e4279
8 changed files with 53 additions and 33 deletions

View File

@ -309,8 +309,8 @@ public:
return max[idx - 3]; return max[idx - 3];
} }
}; };
constexpr CAABox skInvertedBox; constexpr inline CAABox skInvertedBox;
constexpr CAABox skNullBox(CVector3f{}, CVector3f{}); constexpr inline CAABox skNullBox(CVector3f{}, CVector3f{});
[[nodiscard]] inline bool operator==(const CAABox& left, const CAABox& right) { [[nodiscard]] inline bool operator==(const CAABox& left, const CAABox& right) {
return (left.min == right.min && left.max == right.max); return (left.min == right.min && left.max == right.max);

View File

@ -319,18 +319,18 @@ constexpr CVector4f& CVector4f::operator=(const CColor& other) {
return *this; return *this;
} }
constexpr CColor skRed(1.f, 0.f, 0.f, 1.f); constexpr inline CColor skRed(1.f, 0.f, 0.f, 1.f);
constexpr CColor skBlack(0.f, 0.f, 0.f, 1.f); constexpr inline CColor skBlack(0.f, 0.f, 0.f, 1.f);
constexpr CColor skBlue(0.f, 0.f, 1.f, 1.f); constexpr inline CColor skBlue(0.f, 0.f, 1.f, 1.f);
constexpr CColor skCyan(0.f, 1.f, 1.f, 1.f); constexpr inline CColor skCyan(0.f, 1.f, 1.f, 1.f);
constexpr CColor skGreen(0.f, 1.f, 0.f, 1.f); constexpr inline CColor skGreen(0.f, 1.f, 0.f, 1.f);
constexpr CColor skGrey(0.5f, 0.5f, 0.5f, 1.f); constexpr inline CColor skGrey(0.5f, 0.5f, 0.5f, 1.f);
constexpr CColor skMagenta(1.f, 0.f, 1.f, 1.f); constexpr inline CColor skMagenta(1.f, 0.f, 1.f, 1.f);
constexpr CColor skOrange(1.f, 0.43f, 0.f, 1.f); constexpr inline CColor skOrange(1.f, 0.43f, 0.f, 1.f);
constexpr CColor skPurple(0.63f, 0.f, 1.f, 1.f); constexpr inline CColor skPurple(0.63f, 0.f, 1.f, 1.f);
constexpr CColor skYellow(1.f, 1.f, 0.f, 1.f); constexpr inline CColor skYellow(1.f, 1.f, 0.f, 1.f);
constexpr CColor skWhite(1.f, 1.f, 1.f, 1.f); constexpr inline CColor skWhite(1.f, 1.f, 1.f, 1.f);
constexpr CColor skClear(0.f, 0.f, 0.f, 0.f); constexpr inline CColor skClear(0.f, 0.f, 0.f, 0.f);
[[nodiscard]] inline CColor operator+(float lhs, const CColor& rhs) { [[nodiscard]] inline CColor operator+(float lhs, const CColor& rhs) {
return CColor(simd<float>(lhs) + rhs.mSimd).Clamp(); return CColor(simd<float>(lhs) + rhs.mSimd).Clamp();

View File

@ -195,7 +195,7 @@ public:
return std::fabs(x()) >= FLT_EPSILON || std::fabs(y()) >= FLT_EPSILON; return std::fabs(x()) >= FLT_EPSILON || std::fabs(y()) >= FLT_EPSILON;
} }
[[nodiscard]] bool isZero() const { return magSquared() <= FLT_EPSILON; } [[nodiscard]] bool isZero() const { return mSimd[0] == 0.f && mSimd[1] == 0.f; }
[[nodiscard]] bool isEqu(const CVector2f& other, float epsilon = FLT_EPSILON) const { [[nodiscard]] bool isEqu(const CVector2f& other, float epsilon = FLT_EPSILON) const {
const CVector2f diffVec = other - *this; const CVector2f diffVec = other - *this;
@ -218,9 +218,9 @@ public:
[[nodiscard]] simd<float>::reference x() { return mSimd[0]; } [[nodiscard]] simd<float>::reference x() { return mSimd[0]; }
[[nodiscard]] simd<float>::reference y() { return mSimd[1]; } [[nodiscard]] simd<float>::reference y() { return mSimd[1]; }
}; };
constexpr CVector2f skOne2f(1.f); constexpr inline CVector2f skOne2f(1.f);
constexpr CVector2f skNegOne2f(-1.f); constexpr inline CVector2f skNegOne2f(-1.f);
constexpr CVector2f skZero2f(0.f); constexpr inline CVector2f skZero2f(0.f);
[[nodiscard]] inline CVector2f operator+(float lhs, const CVector2f& rhs) { return zeus::simd<float>(lhs) + rhs.mSimd; } [[nodiscard]] inline CVector2f operator+(float lhs, const CVector2f& rhs) { return zeus::simd<float>(lhs) + rhs.mSimd; }

View File

@ -79,7 +79,7 @@ public:
}; };
inline CVector3f::CVector3f(const CVector3d& vec) : mSimd(vec.mSimd) {} inline CVector3f::CVector3f(const CVector3d& vec) : mSimd(vec.mSimd) {}
constexpr CVector3d skZero3d(0.0); constexpr inline CVector3d skZero3d(0.0);
[[nodiscard]] inline CVector3d operator+(double lhs, const CVector3d& rhs) { [[nodiscard]] inline CVector3d operator+(double lhs, const CVector3d& rhs) {
return zeus::simd<double>(lhs) + rhs.mSimd; return zeus::simd<double>(lhs) + rhs.mSimd;

View File

@ -173,7 +173,7 @@ public:
return !(std::fabs(x()) < FLT_EPSILON && std::fabs(y()) < FLT_EPSILON && std::fabs(z()) < FLT_EPSILON); return !(std::fabs(x()) < FLT_EPSILON && std::fabs(y()) < FLT_EPSILON && std::fabs(z()) < FLT_EPSILON);
} }
[[nodiscard]] bool isZero() const { return magSquared() <= FLT_EPSILON; } [[nodiscard]] bool isZero() const { return mSimd[0] == 0.f && mSimd[1] == 0.f && mSimd[2] == 0.f; }
void scaleToLength(float newLength) { void scaleToLength(float newLength) {
float length = magSquared(); float length = magSquared();
@ -220,17 +220,17 @@ public:
[[nodiscard]] static inline CVector3f degToRad(const CVector3f& deg); [[nodiscard]] static inline CVector3f degToRad(const CVector3f& deg);
}; };
constexpr CVector3f skOne3f(1.f); constexpr inline CVector3f skOne3f(1.f);
constexpr CVector3f skNegOne3f(-1.f); constexpr inline CVector3f skNegOne3f(-1.f);
constexpr CVector3f skZero3f(0.f); constexpr inline CVector3f skZero3f(0.f);
constexpr CVector3f skForward(0.f, 1.f, 0.f); constexpr inline CVector3f skForward(0.f, 1.f, 0.f);
constexpr CVector3f skBack(0.f, -1.f, 0.f); constexpr inline CVector3f skBack(0.f, -1.f, 0.f);
constexpr CVector3f skLeft(-1.f, 0.f, 0.f); constexpr inline CVector3f skLeft(-1.f, 0.f, 0.f);
constexpr CVector3f skRight(1.f, 0.f, 0.f); constexpr inline CVector3f skRight(1.f, 0.f, 0.f);
constexpr CVector3f skUp(0.f, 0.f, 1.f); constexpr inline CVector3f skUp(0.f, 0.f, 1.f);
constexpr CVector3f skDown(0.f, 0.f, -1.f); constexpr inline CVector3f skDown(0.f, 0.f, -1.f);
constexpr CVector3f skRadToDegVec(180.f / M_PIF); constexpr inline CVector3f skRadToDegVec(180.f / M_PIF);
constexpr CVector3f skDegToRadVec(M_PIF / 180.f); constexpr inline CVector3f skDegToRadVec(M_PIF / 180.f);
[[nodiscard]] inline CVector3f operator+(float lhs, const CVector3f& rhs) { return zeus::simd<float>(lhs) + rhs.mSimd; } [[nodiscard]] inline CVector3f operator+(float lhs, const CVector3f& rhs) { return zeus::simd<float>(lhs) + rhs.mSimd; }

View File

@ -159,6 +159,26 @@ template <typename E>
return PopCount(static_cast<typename std::underlying_type<E>::type>(e)); return PopCount(static_cast<typename std::underlying_type<E>::type>(e));
} }
template <typename U>
[[nodiscard]] typename std::enable_if<!std::is_enum<U>::value && std::is_integral<U>::value, int>::type
countLeadingZeros(U x) {
#if __GNUC__ >= 4
return __builtin_clz(x);
#else
x = x | (x >> 1);
x = x | (x >> 2);
x = x | (x >> 4);
x = x | (x >> 8);
x = x | (x >> 16);
return PopCount(~x);
#endif
}
template <typename E>
[[nodiscard]] typename std::enable_if<std::is_enum<E>::value, int>::type countLeadingZeros(E e) {
return countLeadingZeros(static_cast<typename std::underlying_type<E>::type>(e));
}
[[nodiscard]] bool close_enough(const CVector3f& a, const CVector3f& b, float epsilon = FLT_EPSILON); [[nodiscard]] bool close_enough(const CVector3f& a, const CVector3f& b, float epsilon = FLT_EPSILON);
[[nodiscard]] bool close_enough(const CVector2f& a, const CVector2f& b, float epsilon = FLT_EPSILON); [[nodiscard]] bool close_enough(const CVector2f& a, const CVector2f& b, float epsilon = FLT_EPSILON);

View File

@ -14,7 +14,7 @@ float CVector2f::getAngleDiff(const CVector2f& a, const CVector2f& b) {
return 0.f; return 0.f;
float dot = a.dot(b); float dot = a.dot(b);
return std::acos(std::clamp(-1.f, dot / (mag1 * mag2), 1.f)); return std::acos(zeus::clamp(-1.f, dot / (mag1 * mag2), 1.f));
} }
CVector2f CVector2f::slerp(const CVector2f& a, const CVector2f& b, float t) { CVector2f CVector2f::slerp(const CVector2f& a, const CVector2f& b, float t) {

View File

@ -16,7 +16,7 @@ float CVector3f::getAngleDiff(const CVector3f& a, const CVector3f& b) {
return 0.f; return 0.f;
float dot = a.dot(b); float dot = a.dot(b);
return std::acos(std::clamp(-1.f, dot / (mag1 * mag2), 1.f)); return std::acos(zeus::clamp(-1.f, dot / (mag1 * mag2), 1.f));
} }
CVector3f CVector3f::slerp(const CVector3f& a, const CVector3f& b, CRelAngle clampAngle) { CVector3f CVector3f::slerp(const CVector3f& a, const CVector3f& b, CRelAngle clampAngle) {