From f6854d8e826ad53ea4deefb142a6bd69fafb2509 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 1 Sep 2019 21:53:55 -0400 Subject: [PATCH] General: Mark member functions as const where applicable These don't modify internal member state, so they can be const. --- include/zeus/COBBox.hpp | 2 +- include/zeus/CQuaternion.hpp | 2 +- include/zeus/CTransform.hpp | 4 ++-- include/zeus/CVector2f.hpp | 2 +- include/zeus/CVector3d.hpp | 4 ++-- include/zeus/CVector3f.hpp | 2 +- include/zeus/CVector4f.hpp | 2 +- src/CQuaternion.cpp | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/zeus/COBBox.hpp b/include/zeus/COBBox.hpp index fca6f5e..1e05901 100644 --- a/include/zeus/COBBox.hpp +++ b/include/zeus/COBBox.hpp @@ -46,6 +46,6 @@ public: bool OBBIntersectsBox(const COBBox& other) const; - bool AABoxIntersectsBox(const CAABox& other) { return OBBIntersectsBox(FromAABox(other, CTransform())); } + bool AABoxIntersectsBox(const CAABox& other) const { return OBBIntersectsBox(FromAABox(other, CTransform())); } }; } // namespace zeus diff --git a/include/zeus/CQuaternion.hpp b/include/zeus/CQuaternion.hpp index 1ff7425..c3d0f76 100644 --- a/include/zeus/CQuaternion.hpp +++ b/include/zeus/CQuaternion.hpp @@ -199,7 +199,7 @@ public: z() = i.z(); } - CRelAngle angleFrom(const zeus::CQuaternion& other); + CRelAngle angleFrom(const zeus::CQuaternion& other) const; simd::reference operator[](size_t idx) { assert(idx < 4); diff --git a/include/zeus/CTransform.hpp b/include/zeus/CTransform.hpp index c897cae..79adb98 100644 --- a/include/zeus/CTransform.hpp +++ b/include/zeus/CTransform.hpp @@ -52,14 +52,14 @@ public: static CTransform Translate(float x, float y, float z) { return Translate({x, y, z}); } - CTransform operator+(const CVector3f& other) { return CTransform(basis, origin + other); } + CTransform operator+(const CVector3f& other) const { return CTransform(basis, origin + other); } CTransform& operator+=(const CVector3f& other) { origin += other; return *this; } - CTransform operator-(const CVector3f& other) { return CTransform(basis, origin - other); } + CTransform operator-(const CVector3f& other) const { return CTransform(basis, origin - other); } CTransform& operator-=(const CVector3f& other) { origin -= other; diff --git a/include/zeus/CVector2f.hpp b/include/zeus/CVector2f.hpp index 48ba6c2..37e2f27 100644 --- a/include/zeus/CVector2f.hpp +++ b/include/zeus/CVector2f.hpp @@ -172,7 +172,7 @@ public: bool isZero() const { return magSquared() <= FLT_EPSILON; } - bool isEqu(const CVector2f& other, float epsilon = FLT_EPSILON) { + bool isEqu(const CVector2f& other, float epsilon = FLT_EPSILON) const { const CVector2f diffVec = other - *this; return (diffVec.x() <= epsilon && diffVec.y() <= epsilon); } diff --git a/include/zeus/CVector3d.hpp b/include/zeus/CVector3d.hpp index b57a234..55ee99b 100644 --- a/include/zeus/CVector3d.hpp +++ b/include/zeus/CVector3d.hpp @@ -29,7 +29,7 @@ public: constexpr CVector3d(double x, double y, double z) : mSimd(x, y, z) {} - CVector3f asCVector3f() { return mSimd; } + CVector3f asCVector3f() const { return mSimd; } double magSquared() const { return mSimd.dot3(mSimd); } @@ -41,7 +41,7 @@ public: double dot(const CVector3d& rhs) const { return mSimd.dot3(rhs.mSimd); } - CVector3d asNormalized() { + CVector3d asNormalized() const { double mag = magnitude(); mag = 1.0 / mag; return mSimd * zeus::simd(mag); diff --git a/include/zeus/CVector3f.hpp b/include/zeus/CVector3f.hpp index 5827f73..2a0413d 100644 --- a/include/zeus/CVector3f.hpp +++ b/include/zeus/CVector3f.hpp @@ -180,7 +180,7 @@ public: return v; } - bool isEqu(const CVector3f& other, float epsilon = FLT_EPSILON) { + bool isEqu(const CVector3f& other, float epsilon = FLT_EPSILON) const { const CVector3f diffVec = other - *this; return (diffVec.x() <= epsilon && diffVec.y() <= epsilon && diffVec.z() <= epsilon); } diff --git a/include/zeus/CVector4f.hpp b/include/zeus/CVector4f.hpp index c7ab42e..b88769b 100644 --- a/include/zeus/CVector4f.hpp +++ b/include/zeus/CVector4f.hpp @@ -166,7 +166,7 @@ public: std::fabs(w()) >= FLT_EPSILON; } - bool isEqu(const CVector4f& other, float epsilon = FLT_EPSILON) { + bool isEqu(const CVector4f& other, float epsilon = FLT_EPSILON) const { const CVector4f diffVec = other - *this; return (diffVec.x() <= epsilon && diffVec.y() <= epsilon && diffVec.z() <= epsilon && diffVec.w() <= epsilon); } diff --git a/src/CQuaternion.cpp b/src/CQuaternion.cpp index 75f0194..85c0cda 100644 --- a/src/CQuaternion.cpp +++ b/src/CQuaternion.cpp @@ -226,7 +226,7 @@ CQuaternion CQuaternion::buildEquivalent() const { return CQuaternion::fromAxisAngle(CUnitVector3f(mSimd.shuffle<1, 2, 3, 3>()), tmp + 2.0 * M_PI); } -CRelAngle CQuaternion::angleFrom(const zeus::CQuaternion& other) { +CRelAngle CQuaternion::angleFrom(const zeus::CQuaternion& other) const { return std::acos(zeus::clamp(-1.f, dot(other), 1.f)); }