diff options
Diffstat (limited to 'src/gui/math3d')
-rw-r--r-- | src/gui/math3d/qvector2d.cpp | 19 | ||||
-rw-r--r-- | src/gui/math3d/qvector2d.h | 15 | ||||
-rw-r--r-- | src/gui/math3d/qvector3d.cpp | 19 | ||||
-rw-r--r-- | src/gui/math3d/qvector3d.h | 15 | ||||
-rw-r--r-- | src/gui/math3d/qvector4d.cpp | 19 | ||||
-rw-r--r-- | src/gui/math3d/qvector4d.h | 15 |
6 files changed, 102 insertions, 0 deletions
diff --git a/src/gui/math3d/qvector2d.cpp b/src/gui/math3d/qvector2d.cpp index 784297ca70..7446d27dab 100644 --- a/src/gui/math3d/qvector2d.cpp +++ b/src/gui/math3d/qvector2d.cpp @@ -160,6 +160,25 @@ QVector2D::QVector2D(const QVector4D& vector) \sa y(), setX() */ +/*! \fn float &QVector2D::operator[](int i) + \since 5.2 + + Returns the component of the vector at index position \a i + as a modifiable reference. + + \a i must be a valid index position in the vector (i.e., 0 <= \a i + < 2). +*/ + +/*! \fn float QVector2D::operator[](int i) const + \since 5.2 + + Returns the component of the vector at index position \a i. + + \a i must be a valid index position in the vector (i.e., 0 <= \a i + < 2). +*/ + /*! Returns the length of the vector from the origin. diff --git a/src/gui/math3d/qvector2d.h b/src/gui/math3d/qvector2d.h index b3c2272287..55e606ec35 100644 --- a/src/gui/math3d/qvector2d.h +++ b/src/gui/math3d/qvector2d.h @@ -76,6 +76,9 @@ public: void setX(float x); void setY(float y); + float &operator[](int i); + float operator[](int i) const; + float length() const; float lengthSquared() const; @@ -145,6 +148,18 @@ inline float QVector2D::y() const { return yp; } inline void QVector2D::setX(float aX) { xp = aX; } inline void QVector2D::setY(float aY) { yp = aY; } +inline float &QVector2D::operator[](int i) +{ + Q_ASSERT(uint(i) < 2u); + return *(&xp + i); +} + +inline float QVector2D::operator[](int i) const +{ + Q_ASSERT(uint(i) < 2u); + return *(&xp + i); +} + inline QVector2D &QVector2D::operator+=(const QVector2D &vector) { xp += vector.xp; diff --git a/src/gui/math3d/qvector3d.cpp b/src/gui/math3d/qvector3d.cpp index 5537562b61..226483c227 100644 --- a/src/gui/math3d/qvector3d.cpp +++ b/src/gui/math3d/qvector3d.cpp @@ -196,6 +196,25 @@ QVector3D::QVector3D(const QVector4D& vector) \sa z(), setX(), setY() */ +/*! \fn float &QVector3D::operator[](int i) + \since 5.2 + + Returns the component of the vector at index position \a i + as a modifiable reference. + + \a i must be a valid index position in the vector (i.e., 0 <= \a i + < 3). +*/ + +/*! \fn float QVector3D::operator[](int i) const + \since 5.2 + + Returns the component of the vector at index position \a i. + + \a i must be a valid index position in the vector (i.e., 0 <= \a i + < 3). +*/ + /*! Returns the normalized unit vector form of this vector. 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; diff --git a/src/gui/math3d/qvector4d.cpp b/src/gui/math3d/qvector4d.cpp index 7ced99dfeb..2247e95d5e 100644 --- a/src/gui/math3d/qvector4d.cpp +++ b/src/gui/math3d/qvector4d.cpp @@ -225,6 +225,25 @@ QVector4D::QVector4D(const QVector3D& vector, float wpos) \sa w(), setX(), setY(), setZ() */ +/*! \fn float &QVector4D::operator[](int i) + \since 5.2 + + Returns the component of the vector at index position \a i + as a modifiable reference. + + \a i must be a valid index position in the vector (i.e., 0 <= \a i + < 4). +*/ + +/*! \fn float QVector4D::operator[](int i) const + \since 5.2 + + Returns the component of the vector at index position \a i. + + \a i must be a valid index position in the vector (i.e., 0 <= \a i + < 4). +*/ + /*! Returns the length of the vector from the origin. diff --git a/src/gui/math3d/qvector4d.h b/src/gui/math3d/qvector4d.h index 4bd3822133..810380b805 100644 --- a/src/gui/math3d/qvector4d.h +++ b/src/gui/math3d/qvector4d.h @@ -82,6 +82,9 @@ public: void setZ(float z); void setW(float w); + float &operator[](int i); + float operator[](int i) const; + float length() const; float lengthSquared() const; @@ -158,6 +161,18 @@ inline void QVector4D::setY(float aY) { yp = aY; } inline void QVector4D::setZ(float aZ) { zp = aZ; } inline void QVector4D::setW(float aW) { wp = aW; } +inline float &QVector4D::operator[](int i) +{ + Q_ASSERT(uint(i) < 4u); + return *(&xp + i); +} + +inline float QVector4D::operator[](int i) const +{ + Q_ASSERT(uint(i) < 4u); + return *(&xp + i); +} + inline QVector4D &QVector4D::operator+=(const QVector4D &vector) { xp += vector.xp; |