diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2013-08-16 17:57:38 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-27 17:50:40 +0200 |
commit | a70c0ad1d15e1346f7784f4e720bbe460af85c17 (patch) | |
tree | a5c2e1c59a2d2c1977d1cd922f15ccdfcb46696a /src/gui/math3d/qvector3d.h | |
parent | e0f2603f49b17eb4e562ec81e92796e3b2435490 (diff) |
Add operator[] to QVectorND classes
Change-Id: Ia786d4fab64da974bb60f24c05325925d42a1e70
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/gui/math3d/qvector3d.h')
-rw-r--r-- | src/gui/math3d/qvector3d.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/gui/math3d/qvector3d.h b/src/gui/math3d/qvector3d.h index 49d9ca6bf8..c880930935 100644 --- a/src/gui/math3d/qvector3d.h +++ b/src/gui/math3d/qvector3d.h @@ -79,6 +79,9 @@ public: void setY(float y); void setZ(float z); + float &operator[](int i); + float operator[](int i) const; + float length() const; float lengthSquared() const; @@ -160,6 +163,18 @@ inline void QVector3D::setX(float aX) { xp = aX; } inline void QVector3D::setY(float aY) { yp = aY; } inline void QVector3D::setZ(float aZ) { zp = aZ; } +inline float &QVector3D::operator[](int i) +{ + Q_ASSERT(uint(i) < 3u); + return *(&xp + i); +} + +inline float QVector3D::operator[](int i) const +{ + Q_ASSERT(uint(i) < 3u); + return *(&xp + i); +} + inline QVector3D &QVector3D::operator+=(const QVector3D &vector) { xp += vector.xp; |