Convert more QVector*D member functions to constexpr

constexpr requires inline functions. We convert more member functions
to inline functions while retaining a version of those functions
inside QtGui. This prevents any BC breakage.

Change-Id: I325b78da6b41611bda3994869f474c700b6fb306
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
Alex Blasche 2013-11-15 13:47:24 +01:00 committed by The Qt Project
parent ac6b9be9b3
commit cd91d8ad02
3 changed files with 31 additions and 3 deletions

View File

@ -80,7 +80,12 @@ public:
float operator[](int i) const; float operator[](int i) const;
float length() const; float length() const;
#ifdef QT_BUILD_GUI_LIB
float lengthSquared() const; float lengthSquared() const;
#else
Q_DECL_CONSTEXPR inline float lengthSquared() const
{ return xp * xp + yp * yp; }
#endif
QVector2D normalized() const; QVector2D normalized() const;
void normalize(); void normalize();
@ -94,7 +99,12 @@ public:
QVector2D &operator*=(const QVector2D &vector); QVector2D &operator*=(const QVector2D &vector);
QVector2D &operator/=(float divisor); QVector2D &operator/=(float divisor);
#ifdef QT_BUILD_GUI_LIB
static float dotProduct(const QVector2D& v1, const QVector2D& v2); static float dotProduct(const QVector2D& v1, const QVector2D& v2);
#else
Q_DECL_CONSTEXPR inline static float dotProduct(const QVector2D& v1, const QVector2D& v2)
{ return v1.xp * v2.xp + v1.yp * v2.yp; }
#endif
Q_DECL_CONSTEXPR friend inline bool operator==(const QVector2D &v1, const QVector2D &v2); Q_DECL_CONSTEXPR friend inline bool operator==(const QVector2D &v1, const QVector2D &v2);
Q_DECL_CONSTEXPR friend inline bool operator!=(const QVector2D &v1, const QVector2D &v2); Q_DECL_CONSTEXPR friend inline bool operator!=(const QVector2D &v1, const QVector2D &v2);

View File

@ -58,7 +58,8 @@ class Q_GUI_EXPORT QVector3D
{ {
public: public:
Q_DECL_CONSTEXPR QVector3D(); Q_DECL_CONSTEXPR QVector3D();
Q_DECL_CONSTEXPR QVector3D(float xpos, float ypos, float zpos); Q_DECL_CONSTEXPR QVector3D(float xpos, float ypos, float zpos) : xp(xpos), yp(ypos), zp(zpos) {}
Q_DECL_CONSTEXPR explicit QVector3D(const QPoint& point); Q_DECL_CONSTEXPR explicit QVector3D(const QPoint& point);
Q_DECL_CONSTEXPR explicit QVector3D(const QPointF& point); Q_DECL_CONSTEXPR explicit QVector3D(const QPointF& point);
#ifndef QT_NO_VECTOR2D #ifndef QT_NO_VECTOR2D
@ -94,8 +95,17 @@ public:
QVector3D &operator*=(const QVector3D& vector); QVector3D &operator*=(const QVector3D& vector);
QVector3D &operator/=(float divisor); QVector3D &operator/=(float divisor);
#ifdef QT_BUILD_GUI_LIB
static float dotProduct(const QVector3D& v1, const QVector3D& v2); static float dotProduct(const QVector3D& v1, const QVector3D& v2);
static QVector3D crossProduct(const QVector3D& v1, const QVector3D& v2); static QVector3D crossProduct(const QVector3D& v1, const QVector3D& v2);
#else
Q_DECL_CONSTEXPR inline static float dotProduct(const QVector3D& v1, const QVector3D& v2)
{ return v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp; }
Q_DECL_CONSTEXPR inline static QVector3D crossProduct(const QVector3D& v1, const QVector3D& v2)
{ return QVector3D(v1.yp * v2.zp - v1.zp * v2.yp,
v1.zp * v2.xp - v1.xp * v2.zp,
v1.xp * v2.yp - v1.yp * v2.xp); }
#endif
static QVector3D normal(const QVector3D& v1, const QVector3D& v2); static QVector3D normal(const QVector3D& v1, const QVector3D& v2);
static QVector3D normal static QVector3D normal
(const QVector3D& v1, const QVector3D& v2, const QVector3D& v3); (const QVector3D& v1, const QVector3D& v2, const QVector3D& v3);
@ -144,8 +154,6 @@ Q_DECLARE_TYPEINFO(QVector3D, Q_MOVABLE_TYPE);
Q_DECL_CONSTEXPR inline QVector3D::QVector3D() : xp(0.0f), yp(0.0f), zp(0.0f) {} Q_DECL_CONSTEXPR inline QVector3D::QVector3D() : xp(0.0f), yp(0.0f), zp(0.0f) {}
Q_DECL_CONSTEXPR inline QVector3D::QVector3D(float xpos, float ypos, float zpos) : xp(xpos), yp(ypos), zp(zpos) {}
Q_DECL_CONSTEXPR inline QVector3D::QVector3D(const QPoint& point) : xp(point.x()), yp(point.y()), zp(0.0f) {} Q_DECL_CONSTEXPR inline QVector3D::QVector3D(const QPoint& point) : xp(point.x()), yp(point.y()), zp(0.0f) {}
Q_DECL_CONSTEXPR inline QVector3D::QVector3D(const QPointF& point) : xp(point.x()), yp(point.y()), zp(0.0f) {} Q_DECL_CONSTEXPR inline QVector3D::QVector3D(const QPointF& point) : xp(point.x()), yp(point.y()), zp(0.0f) {}

View File

@ -86,7 +86,12 @@ public:
float operator[](int i) const; float operator[](int i) const;
float length() const; float length() const;
#ifdef QT_BUILD_GUI_LIB
float lengthSquared() const; float lengthSquared() const;
#else
Q_DECL_CONSTEXPR inline float lengthSquared() const
{ return xp * xp + yp * yp + zp * zp + wp * wp; }
#endif
QVector4D normalized() const; QVector4D normalized() const;
void normalize(); void normalize();
@ -97,7 +102,12 @@ public:
QVector4D &operator*=(const QVector4D &vector); QVector4D &operator*=(const QVector4D &vector);
QVector4D &operator/=(float divisor); QVector4D &operator/=(float divisor);
#ifdef QT_BUILD_GUI_LIB
static float dotProduct(const QVector4D& v1, const QVector4D& v2); static float dotProduct(const QVector4D& v1, const QVector4D& v2);
#else
static float dotProduct(const QVector4D& v1, const QVector4D& v2)
{ return v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp + v1.wp * v2.wp; }
#endif
Q_DECL_CONSTEXPR friend inline bool operator==(const QVector4D &v1, const QVector4D &v2); Q_DECL_CONSTEXPR friend inline bool operator==(const QVector4D &v1, const QVector4D &v2);
Q_DECL_CONSTEXPR friend inline bool operator!=(const QVector4D &v1, const QVector4D &v2); Q_DECL_CONSTEXPR friend inline bool operator!=(const QVector4D &v1, const QVector4D &v2);