Add operator[] asserts

This commit is contained in:
Jack Andersen 2017-11-23 22:21:18 -10:00
parent c5f9137df8
commit bad3038132
8 changed files with 18 additions and 16 deletions

View File

@ -417,6 +417,7 @@ public:
inline float operator[](size_t idx) const
{
assert(idx < 6);
if (idx < 3)
return min[idx];
else

View File

@ -9,6 +9,7 @@
#include <athena/FileWriter.hpp>
#endif
#include <iostream>
#include <assert.h>
#undef min
#undef max
@ -275,8 +276,8 @@ public:
inline float magnitude() const { return std::sqrt(magSquared()); }
static inline CColor lerp(const CColor& a, const CColor& b, float t) { return (a + (b - a) * t); }
static inline CColor nlerp(const CColor& a, const CColor& b, float t) { return lerp(a, b, t).normalized(); }
inline float& operator[](const size_t& idx) { return (&r)[idx]; }
inline const float& operator[](const size_t& idx) const { return (&r)[idx]; }
inline float& operator[](const size_t& idx) { assert(idx < 4); return (&r)[idx]; }
inline const float& operator[](const size_t& idx) const { assert(idx < 4); return (&r)[idx]; }
inline void splat(float rgb, float a)
{
#if __SSE__

View File

@ -57,8 +57,8 @@ public:
const CVector3f& normal() const { return vec; }
inline float& operator[](size_t idx) { return p[idx]; }
inline const float& operator[](size_t idx) const { return p[idx]; }
inline float& operator[](size_t idx) { assert(idx < 4); return p[idx]; }
inline const float& operator[](size_t idx) const { assert(idx < 4); return p[idx]; }
union {
struct

View File

@ -283,8 +283,8 @@ public:
CRelAngle angleFrom(const zeus::CQuaternion& other);
inline float& operator[](size_t idx) { return (&w)[idx]; }
inline const float& operator[](size_t idx) const { return (&w)[idx]; }
inline float& operator[](size_t idx) { assert(idx < 4); return (&w)[idx]; }
inline const float& operator[](size_t idx) const { assert(idx < 4); return (&w)[idx]; }
union
{
@ -336,8 +336,8 @@ public:
CNUQuaternion operator*(float f) const;
const CNUQuaternion& operator+=(const CNUQuaternion& q);
inline float& operator[](size_t idx) { return (&w)[idx]; }
inline const float& operator[](size_t idx) const { return (&w)[idx]; }
inline float& operator[](size_t idx) { assert(idx < 4); return (&w)[idx]; }
inline const float& operator[](size_t idx) const { assert(idx < 4); return (&w)[idx]; }
union
{

View File

@ -347,8 +347,8 @@ public:
return (diffVec.x <= epsilon && diffVec.y <= epsilon);
}
inline float& operator[](size_t idx) { return (&x)[idx]; }
inline const float& operator[](size_t idx) const { return (&x)[idx]; }
inline float& operator[](size_t idx) { assert(idx < 2); return (&x)[idx]; }
inline const float& operator[](size_t idx) const { assert(idx < 2); return (&x)[idx]; }
static const CVector2f skOne;
static const CVector2f skNegOne;

View File

@ -185,8 +185,8 @@ public:
#endif
}
inline double& operator[](size_t idx) { return v[idx]; }
inline const double& operator[](size_t idx) const { return v[idx]; }
inline double& operator[](size_t idx) { assert(idx < 3); return v[idx]; }
inline const double& operator[](size_t idx) const { assert(idx < 3); return v[idx]; }
union {
struct

View File

@ -375,8 +375,8 @@ public:
return (diffVec.x <= epsilon && diffVec.y <= epsilon && diffVec.z <= epsilon);
}
inline float& operator[](size_t idx) { return (&x)[idx]; }
inline const float& operator[](size_t idx) const { return (&x)[idx]; }
inline float& operator[](size_t idx) { assert(idx < 3); return (&x)[idx]; }
inline const float& operator[](size_t idx) const { assert(idx < 3); return (&x)[idx]; }
static const CVector3f skOne;
static const CVector3f skNegOne;

View File

@ -376,8 +376,8 @@ public:
return (diffVec.x <= epsilon && diffVec.y <= epsilon && diffVec.z <= epsilon && diffVec.w <= epsilon);
}
inline float& operator[](size_t idx) { return (&x)[idx]; }
inline const float& operator[](size_t idx) const { return (&x)[idx]; }
inline float& operator[](size_t idx) { assert(idx < 4); return (&x)[idx]; }
inline const float& operator[](size_t idx) const { assert(idx < 4); return (&x)[idx]; }
static const CVector4f skOne;
static const CVector4f skNegOne;