From f63976b7c5fd512c00442efd5cb9afb0b3707388 Mon Sep 17 00:00:00 2001 From: Robert Griebl Date: Fri, 1 Aug 2008 00:37:56 +0200 Subject: The QT_NO_SHAREDMEMORY define was checked a bit too late Reviewed-By: Harald Fernengel --- src/corelib/kernel/qsharedmemory_unix.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/corelib/kernel/qsharedmemory_unix.cpp b/src/corelib/kernel/qsharedmemory_unix.cpp index 487c653..cd248dc 100644 --- a/src/corelib/kernel/qsharedmemory_unix.cpp +++ b/src/corelib/kernel/qsharedmemory_unix.cpp @@ -47,12 +47,9 @@ #include #include -#include - -QT_BEGIN_NAMESPACE - #ifndef QT_NO_SHAREDMEMORY +#include #include #include #include @@ -61,6 +58,8 @@ QT_BEGIN_NAMESPACE #include #include +QT_BEGIN_NAMESPACE + QSharedMemoryPrivate::QSharedMemoryPrivate() : QObjectPrivate(), memory(0), size(0), error(QSharedMemory::NoError), #ifndef QT_NO_SYSTEMSEMAPHORE -- cgit v0.12 From a83faaf1bedfd321c4fc759156369d2f86fbbbed Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Tue, 7 Apr 2009 16:16:22 +1000 Subject: Remove fixed-point support from math3d The main use case for fixed-point support is to build large arrays of vertices. This can be handled using qvertextype or something similar at higher levels. So it isn't worth risking numerical instability in the core classes. Reviewed-by: trustme --- src/gui/math3d/math3d.pri | 5 - src/gui/math3d/qfixedpt.cpp | 711 --------------------- src/gui/math3d/qfixedpt.h | 551 ---------------- src/gui/math3d/qgenericmatrix.h | 22 +- src/gui/math3d/qmath3dglobal.h | 102 --- src/gui/math3d/qmath3dutil.cpp | 194 ------ src/gui/math3d/qmath3dutil_p.h | 96 --- src/gui/math3d/qmatrix4x4.cpp | 374 ++++++----- src/gui/math3d/qmatrix4x4.h | 177 +++-- src/gui/math3d/qquaternion.cpp | 33 +- src/gui/math3d/qquaternion.h | 49 +- src/gui/math3d/qvector2d.cpp | 9 +- src/gui/math3d/qvector2d.h | 34 +- src/gui/math3d/qvector3d.cpp | 8 +- src/gui/math3d/qvector3d.h | 41 +- src/gui/math3d/qvector4d.cpp | 12 +- src/gui/math3d/qvector4d.h | 46 +- tests/auto/math3d/math3d.pro | 3 +- tests/auto/math3d/qfixedpt/qfixedpt.pro | 2 - tests/auto/math3d/qfixedpt/tst_qfixedpt.cpp | 643 ------------------- tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp | 83 +-- .../math3d/qmatrixnxn_fixed/qmatrixnxn_fixed.pro | 8 - tests/auto/math3d/qquaternion/tst_qquaternion.cpp | 18 - .../math3d/qquaternion_fixed/qquaternion_fixed.pro | 8 - tests/auto/math3d/qvectornd/tst_qvectornd.cpp | 18 - .../math3d/qvectornd_fixed/qvectornd_fixed.pro | 8 - tests/auto/math3d/shared/math3dincludes.cpp | 54 -- tests/auto/math3d/shared/math3dincludes.h | 35 - 28 files changed, 391 insertions(+), 2953 deletions(-) delete mode 100644 src/gui/math3d/qfixedpt.cpp delete mode 100644 src/gui/math3d/qfixedpt.h delete mode 100644 src/gui/math3d/qmath3dglobal.h delete mode 100644 src/gui/math3d/qmath3dutil.cpp delete mode 100644 src/gui/math3d/qmath3dutil_p.h delete mode 100644 tests/auto/math3d/qfixedpt/qfixedpt.pro delete mode 100644 tests/auto/math3d/qfixedpt/tst_qfixedpt.cpp delete mode 100644 tests/auto/math3d/qmatrixnxn_fixed/qmatrixnxn_fixed.pro delete mode 100644 tests/auto/math3d/qquaternion_fixed/qquaternion_fixed.pro delete mode 100644 tests/auto/math3d/qvectornd_fixed/qvectornd_fixed.pro delete mode 100644 tests/auto/math3d/shared/math3dincludes.cpp diff --git a/src/gui/math3d/math3d.pri b/src/gui/math3d/math3d.pri index 581adbd..e4dd53a 100644 --- a/src/gui/math3d/math3d.pri +++ b/src/gui/math3d/math3d.pri @@ -1,8 +1,5 @@ HEADERS += \ - math3d/qfixedpt.h \ math3d/qgenericmatrix.h \ - math3d/qmath3dglobal.h \ - math3d/qmath3dutil_p.h \ math3d/qmatrix4x4.h \ math3d/qquaternion.h \ math3d/qvector2d.h \ @@ -10,9 +7,7 @@ HEADERS += \ math3d/qvector4d.h SOURCES += \ - math3d/qfixedpt.cpp \ math3d/qgenericmatrix.cpp \ - math3d/qmath3dutil.cpp \ math3d/qmatrix4x4.cpp \ math3d/qquaternion.cpp \ math3d/qvector2d.cpp \ diff --git a/src/gui/math3d/qfixedpt.cpp b/src/gui/math3d/qfixedpt.cpp deleted file mode 100644 index 93f2150..0000000 --- a/src/gui/math3d/qfixedpt.cpp +++ /dev/null @@ -1,711 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qfixedpt.h" - -QT_BEGIN_NAMESPACE - -/*! - \internal - Returns the fixed-point square root of \a value. -*/ -qint64 qt_math3d_fixed_sqrt(qint64 value) -{ - qint64 result = 0; - qint64 bit = ((qint64)1) << 62; - while (bit > value) - bit >>= 2; - while (bit != 0) { - if (value >= (result + bit)) { - value -= result + bit; - result += (bit << 1); - } - result >>= 1; - bit >>= 2; - } - return result; -} - -/*! - \class QFixedPt - \brief The QFixedPt class represents fixed-point numbers within a 32-bit integer with a configurable precision. - - The template parameter is the number of bits of precision after - the decimal point. For example, QFixedPt<5> indicates that there - are 27 bits before the decimal point, and 5 bits of precision after - the decimal point. -*/ - -/*! - \fn QFixedPt::QFixedPt() - - Constructs a default fixed-point number. The initial value - is undefined. -*/ - -/*! - \fn QFixedPt::QFixedPt(int value) - - Constructs a fixed-point number from the integer \a value. -*/ - -/*! - \fn QFixedPt::QFixedPt(qreal value) - - Constructs a fixed-point number from the floating-point \a value. -*/ - -/*! - \fn QFixedPt& QFixedPt::operator=(int value) - - Assigns the integer \a value to this fixed-point variable. -*/ - -/*! - \fn QFixedPt& QFixedPt::operator=(qreal value) - - Assigns the floating-point \a value to this fixed-point variable. -*/ - -/*! - \fn int QFixedPt::bits() const - - Returns the raw bits that represent the fixed-point value of this object. - - \sa setBits() -*/ - -/*! - \fn void QFixedPt::setBits(int value) - - Sets the raw bits that represent the fixed-point value of - this object to \a value. - - \sa bits() -*/ - -#if !defined(QT_NO_MEMBER_TEMPLATES) || defined(Q_QDOC) - -/*! - \fn QFixedPt QFixedPt::toPrecision() const - - Returns this fixed-point number, converted to the new fixed-point - precision Prec. - - \sa qFixedPtToPrecision() -*/ - -#endif - -/*! - \fn QFixedPt qFixedPtToPrecision(const QFixedPt& value) - - Returns the fixed-point number \a value, converted to the new fixed-point - precision Prec. - - \sa QFixedPt::toPrecision() -*/ - -/*! - \fn QFixedPt& QFixedPt::operator+=(const QFixedPt& value) - - Adds \a value to this fixed-point number. -*/ - -/*! - \fn QFixedPt& QFixedPt::operator+=(int value) - - Adds an integer \a value to this fixed-point number. -*/ - -/*! - \fn QFixedPt& QFixedPt::operator+=(qreal value) - - Adds a floating-point \a value to this fixed-point number. -*/ - -/*! - \fn QFixedPt& QFixedPt::operator-=(const QFixedPt& value) - - Subtracts \a value from this fixed-point number. -*/ - -/*! - \fn QFixedPt& QFixedPt::operator-=(int value) - - Subtracts an integer \a value from this fixed-point number. -*/ - -/*! - \fn QFixedPt& QFixedPt::operator-=(qreal value) - - Subtracts a floating-point \a value from this fixed-point number. -*/ - -/*! - \fn QFixedPt& QFixedPt::operator*=(const QFixedPt& value) - - Multiplies this fixed-point number by \a value. -*/ - -/*! - \fn QFixedPt& QFixedPt::operator*=(int value) - - Multiplies this fixed-point number by an integer \a value. -*/ - -/*! - \fn QFixedPt& QFixedPt::operator*=(qreal value) - - Multiplies this fixed-point number by a floating-point \a value. -*/ - -/*! - \fn QFixedPt& QFixedPt::operator/=(const QFixedPt& value) - - Divides this fixed-point number by \a value. Division by zero - will result in zero. -*/ - -/*! - \fn QFixedPt& QFixedPt::operator/=(int value) - - Divides this fixed-point number by an integer \a value. Division - by zero will result in zero. -*/ - -/*! - \fn QFixedPt& QFixedPt::operator/=(qreal value) - - Divides this fixed-point number by a floating-point \a value. Division - by zero will result in zero. -*/ - -/*! - \fn QFixedPt& QFixedPt::operator<<=(int value) - - Shifts this fixed-point number left by \a value bits. -*/ - -/*! - \fn QFixedPt& QFixedPt::operator>>=(int value) - - Shifts this fixed-point number right by \a value bits. -*/ - -/*! - \fn QFixedPt QFixedPt::operator<<(int value) const - - Returns the result of shifting this fixed-point number - left by \a value bits. -*/ - -/*! - \fn QFixedPt QFixedPt::operator>>(int value) const - - Returns the result of shifting this fixed-point number - right by \a value bits. -*/ - -/*! - \fn bool QFixedPt::operator==(const QFixedPt& value) const - - Returns true if this fixed-point number is equal to \a value; - false otherwise. -*/ - -/*! - \fn bool operator==(const QFixedPt& v1, int v2) - \relates QFixedPt - - Returns true if \a v1 is equal to \a v2; false otherwise. -*/ - -/*! - \fn bool operator==(int v1, const QFixedPt& v2) - \relates QFixedPt - - Returns true if \a v1 is equal to \a v2; false otherwise. -*/ - -/*! - \fn bool operator==(const QFixedPt& v1, qreal v2) - \relates QFixedPt - - Returns true if \a v1 is equal to \a v2; false otherwise. -*/ - -/*! - \fn bool operator==(qreal v1, const QFixedPt& v2) - \relates QFixedPt - - Returns true if \a v1 is equal to \a v2; false otherwise. -*/ - -/*! - \fn bool QFixedPt::operator!=(const QFixedPt& value) const - - Returns true if this fixed-point number is not equal to \a value; - false otherwise. -*/ - -/*! - \fn bool operator!=(const QFixedPt& v1, int v2) - \relates QFixedPt - - Returns true if \a v1 is not equal to \a v2; false otherwise. -*/ - -/*! - \fn bool operator!=(int v1, const QFixedPt& v2) - \relates QFixedPt - - Returns true if \a v1 is not equal to \a v2; false otherwise. -*/ - -/*! - \fn bool operator!=(const QFixedPt& v1, qreal v2) - \relates QFixedPt - - Returns true if \a v1 is not equal to \a v2; false otherwise. -*/ - -/*! - \fn bool operator!=(qreal v1, const QFixedPt& v2) - \relates QFixedPt - - Returns true if \a v1 is not equal to \a v2; false otherwise. -*/ - -/*! - \fn bool QFixedPt::operator<=(const QFixedPt& value) const - - Returns true if this fixed-point number is less than or equal to - \a value; false otherwise. -*/ - -/*! - \fn bool operator<=(const QFixedPt& v1, int v2) - \relates QFixedPt - - Returns true if \a v1 is less than or equal to \a v2; false otherwise. -*/ - -/*! - \fn bool operator<=(int v1, const QFixedPt& v2) - \relates QFixedPt - - Returns true if \a v1 is less than or equal to \a v2; false otherwise. -*/ - -/*! - \fn bool operator<=(const QFixedPt& v1, qreal v2) - \relates QFixedPt - - Returns true if \a v1 is less than or equal to \a v2; false otherwise. -*/ - -/*! - \fn bool operator<=(qreal v1, const QFixedPt& v2) - \relates QFixedPt - - Returns true if \a v1 is less than or equal to \a v2; false otherwise. -*/ - -/*! - \fn bool QFixedPt::operator<(const QFixedPt& value) const - - Returns true if this fixed-point number is less than \a value; - false otherwise. -*/ - -/*! - \fn bool operator<(const QFixedPt& v1, int v2) - \relates QFixedPt - - Returns true if \a v1 is less than \a v2; false otherwise. -*/ - -/*! - \fn bool operator<(int v1, const QFixedPt& v2) - \relates QFixedPt - - Returns true if \a v1 is less than \a v2; false otherwise. -*/ - -/*! - \fn bool operator<(const QFixedPt& v1, qreal v2) - \relates QFixedPt - - Returns true if \a v1 is less than \a v2; false otherwise. -*/ - -/*! - \fn bool operator<(qreal v1, const QFixedPt& v2) - \relates QFixedPt - - Returns true if \a v1 is less than \a v2; false otherwise. -*/ - -/*! - \fn bool QFixedPt::operator>=(const QFixedPt& value) const - - Returns true if this fixed-point number is greater than or equal to - \a value; false otherwise. -*/ - -/*! - \fn bool operator>=(const QFixedPt& v1, int v2) - \relates QFixedPt - - Returns true if \a v1 is greater than or equal to \a v2; false otherwise. -*/ - -/*! - \fn bool operator>=(int v1, const QFixedPt& v2) - \relates QFixedPt - - Returns true if \a v1 is greater than or equal to \a v2; false otherwise. -*/ - -/*! - \fn bool operator>=(const QFixedPt& v1, qreal v2) - \relates QFixedPt - - Returns true if \a v1 is greater than or equal to \a v2; false otherwise. -*/ - -/*! - \fn bool operator>=(qreal v1, const QFixedPt& v2) - \relates QFixedPt - - Returns true if \a v1 is greater than or equal to \a v2; false otherwise. -*/ - -/*! - \fn bool QFixedPt::operator>(const QFixedPt& value) const - - Returns true if this fixed-point number is greater than \a value; - false otherwise. -*/ - -/*! - \fn bool operator>(const QFixedPt& v1, int v2) - \relates QFixedPt - - Returns true if \a v1 is greater than \a v2; false otherwise. -*/ - -/*! - \fn bool operator>(int v1, const QFixedPt& v2) - \relates QFixedPt - - Returns true if \a v1 is greater than \a v2; false otherwise. -*/ - -/*! - \fn bool operator>(const QFixedPt& v1, qreal v2) - \relates QFixedPt - - Returns true if \a v1 is greater than \a v2; false otherwise. -*/ - -/*! - \fn bool operator>(qreal v1, const QFixedPt& v2) - \relates QFixedPt - - Returns true if \a v1 is greater than \a v2; false otherwise. -*/ - -/*! - \fn QFixedPt QFixedPt::operator+(const QFixedPt& value) const - - Returns the result of adding this fixed-point number and \a value. -*/ - -/*! - \fn QFixedPt QFixedPt::operator+(int value) const - - Returns the result of adding this fixed-point number and \a value. -*/ - -/*! - \fn QFixedPt QFixedPt::operator+(qreal value) const - - Returns the result of adding this fixed-point number and \a value. -*/ - -/*! - \fn QFixedPt operator+(int v1, const QFixedPt& v2) - \relates QFixedPt - - Returns the result of adding \a v1 and \a v2. -*/ - -/*! - \fn QFixedPt operator+(qreal v1, const QFixedPt& v2) - \relates QFixedPt - - Returns the result of adding \a v1 and \a v2. -*/ - -/*! - \fn QFixedPt QFixedPt::operator-(const QFixedPt& value) const - - Returns the result of subtracting \a value from this fixed-point number. -*/ - -/*! - \fn QFixedPt QFixedPt::operator-(int value) const - - Returns the result of subtracting \a value from this fixed-point number. -*/ - -/*! - \fn QFixedPt QFixedPt::operator-(qreal value) const - - Returns the result of subtracting \a value from this fixed-point number. -*/ - -/*! - \fn QFixedPt operator-(int v1, const QFixedPt& v2) - \relates QFixedPt - - Returns the result of subtracting \a v2 from \a v1. -*/ - -/*! - \fn QFixedPt operator-(qreal v1, const QFixedPt& v2) - \relates QFixedPt - - Returns the result of subtracting \a v2 from \a v1. -*/ - -/*! - \fn QFixedPt QFixedPt::operator*(const QFixedPt& value) const - - Returns the result of multiplying this fixed-point number by \a value. -*/ - -/*! - \fn QFixedPt QFixedPt::operator*(int value) const - - Returns the result of multiplying this fixed-point number by \a value. -*/ - -/*! - \fn QFixedPt QFixedPt::operator*(qreal value) const - - Returns the result of multiplying this fixed-point number by \a value. -*/ - -/*! - \fn QFixedPt operator*(int v1, const QFixedPt& v2) - \relates QFixedPt - - Returns the result of multiplying \a v1 by \a v2. -*/ - -/*! - \fn QFixedPt operator*(qreal v1, const QFixedPt& v2) - \relates QFixedPt - - Returns the result of multiplying \a v1 by \a v2. -*/ - -/*! - \fn QFixedPt QFixedPt::operator/(const QFixedPt& value) const - - Returns the result of dividing this fixed-point number by \a value. - Division by zero will result in zero. -*/ - -/*! - \fn QFixedPt QFixedPt::operator/(int value) const - - Returns the result of dividing this fixed-point number by \a value. - Division by zero will result in zero. -*/ - -/*! - \fn QFixedPt QFixedPt::operator/(qreal value) const - - Returns the result of dividing this fixed-point number by \a value. - Division by zero will result in zero. -*/ - -/*! - \fn QFixedPt operator/(int v1, const QFixedPt& v2) - \relates QFixedPt - - Returns the result of dividing \a v1 by \a v2. Division by zero will - result in zero. -*/ - -/*! - \fn QFixedPt operator/(qreal v1, const QFixedPt& v2) - \relates QFixedPt - - Returns the result of dividing \a v1 by \a v2. Division by zero will - result in zero. -*/ - -/*! - \fn QFixedPt QFixedPt::operator-() const - - Returns the negation of this fixed-point number. -*/ - -/*! - \fn QFixedPt QFixedPt::sqrt() const - - Returns the square root of this fixed-point number. - - \sa sqrtF() -*/ - -/*! - \fn qreal QFixedPt::sqrtF() const - - Return the square root of this fixed-point number as a - floating-point value. - - \sa sqrt() -*/ - -/*! - \fn QFixedPt QFixedPt::round() const - - Returns this fixed-point number, rounded to the nearest integer. - - \sa floor(), ceil(), truncate() -*/ - -/*! - \fn QFixedPt QFixedPt::floor() const; - - Returns the largest integer that is less than or equal to - this fixed-point number. - - \sa round(), ceil(), truncate() -*/ - -/*! - \fn QFixedPt QFixedPt::ceil() const - - Returns the smallest integer that is greater than or equal to - this fixed-point number. - - \sa round(), floor(), truncate() -*/ - -/*! - \fn int QFixedPt::truncate() const - - Returns this fixed-point number with the bits after the - decimal point truncated. - - \sa round(), floor(), ceil() -*/ - -/*! - \fn int QFixedPt::toInt() const - - Returns this fixed-point number, rounded to the nearest integer. - - \sa toReal() -*/ - -/*! - \fn qreal QFixedPt::toReal() const - - Returns this fixed-point number as a floating-point value. - - \sa toInt() -*/ - -/*! - \fn int qCeil(const QFixedPt& value) - \relates QFixedPt - - Returns the smallest integer that is greater than or equal to - \a value. - - \sa qFloor(), qRound(), QFixedPt::ceil() -*/ - -/*! - \fn int qFloor(const QFixedPt& value) - \relates QFixedPt - - Returns the largest integer that is less than or equal to - \a value. - - \sa qCeil(), qRound(), QFixedPt::floor() -*/ - -/*! - \fn int qRound(const QFixedPt& value) - \relates QFixedPt - - Returns \a value, rounded to the nearest integer. - - \sa qCeil(), qFloor(), QFixedPt::round() -*/ - -/*! - \fn bool qFuzzyCompare(const QFixedPt& v1, const QFixedPt& v2, int compareBits) - \relates QFixedPt - - Returns true if \a v1 is almost equal to \a v2; false otherwise. - The \a compareBits parameter specifies the number of bits of precision - that should be considered relevant when performing the comparison. - By default, \a compareBits is PrecBits / 4. -*/ - -/*! - \fn bool qIsNull(const QFixedPt& v) - \relates QFixedPt - - Returns true if \a v is zero; false otherwise. -*/ - -QT_END_NAMESPACE diff --git a/src/gui/math3d/qfixedpt.h b/src/gui/math3d/qfixedpt.h deleted file mode 100644 index 142f62f..0000000 --- a/src/gui/math3d/qfixedpt.h +++ /dev/null @@ -1,551 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFIXEDPT_H -#define QFIXEDPT_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -Q_GUI_EXPORT qint64 qt_math3d_fixed_sqrt(qint64 value); - -// Should be called QFixed or QFixedPoint, but both of those -// are already in use in src/gui/painting/qfixed_p.h. -template -class QFixedPt -{ -public: - inline QFixedPt() {} // Deliberately not initialized - don't change this. - inline QFixedPt(int value) : val(value << PrecBits) {} - inline QFixedPt(qreal value) : val(int(value * (1 << PrecBits))) {} - - inline QFixedPt& operator=(int value) - { val = value << PrecBits; return *this; } - inline QFixedPt& operator=(qreal value) - { val = int(value * (1 << PrecBits)); return *this; } - - inline int bits() const { return val; } - inline void setBits(int value) { val = value; } - -#if !defined(QT_NO_MEMBER_TEMPLATES) || defined(Q_QDOC) - template - inline QFixedPt toPrecision() const - { - QFixedPt result; - if (Prec < PrecBits) - result.setBits(shiftRight(val, (PrecBits - Prec))); - else - result.setBits(shiftLeft(val, (Prec - PrecBits))); - return result; - } -#endif - - inline QFixedPt& operator+=(const QFixedPt& value) - { val += value.val; return *this; } - inline QFixedPt& operator+=(int value) - { val += (value << PrecBits); return *this; } - inline QFixedPt& operator+=(qreal value) - { val += int(value * (1 << PrecBits)); return *this; } - - inline QFixedPt& operator-=(const QFixedPt& value) - { val -= value.val; return *this; } - inline QFixedPt& operator-=(int value) - { val -= (value << PrecBits); return *this; } - inline QFixedPt& operator-=(qreal value) - { val -= int(value * (1 << PrecBits)); return *this; } - - inline QFixedPt& operator*=(const QFixedPt& value) - { val = mul(val, value.val); return *this; } - inline QFixedPt& operator*=(int value) - { val = mul(val, (value << PrecBits)); return *this; } - inline QFixedPt& operator*=(qreal value) - { val = mul(val, int(value * (1 << PrecBits))); return *this; } - - inline QFixedPt& operator/=(const QFixedPt& value) - { val = div(val, value.val); return *this; } - inline QFixedPt& operator/=(int value) - { val = div(val, (value << PrecBits)); return *this; } - inline QFixedPt& operator/=(qreal value) - { val = div(val, int(value * (1 << PrecBits))); return *this; } - - inline QFixedPt& operator<<=(int value) - { val <<= value; return *this; } - inline QFixedPt& operator>>=(int value) - { val >>= value; return *this; } - - inline QFixedPt operator<<(int value) const - { QFixedPt result; result.val = val << value; return result; } - inline QFixedPt operator>>(int value) const - { QFixedPt result; result.val = val >> value; return result; } - - inline bool operator==(const QFixedPt& value) const - { return val == value.val; } - inline bool operator!=(const QFixedPt& value) const - { return val != value.val; } - inline bool operator<=(const QFixedPt& value) const - { return val <= value.val; } - inline bool operator<(const QFixedPt& value) const - { return val < value.val; } - inline bool operator>=(const QFixedPt& value) const - { return val >= value.val; } - inline bool operator>(const QFixedPt& value) const - { return val > value.val; } - - inline QFixedPt operator+(const QFixedPt& value) const - { QFixedPt result; - result.val = val + value.val; return result; } - inline QFixedPt operator+(int value) const - { QFixedPt result; - result.val = val + (value << PrecBits); return result; } - inline QFixedPt operator+(qreal value) const - { QFixedPt result; - result.val = val + int(value * (1 << PrecBits)); return result; } - - inline QFixedPt operator-(const QFixedPt& value) const - { QFixedPt result; - result.val = val - value.val; return result; } - inline QFixedPt operator-(int value) const - { QFixedPt result; - result.val = val - (value << PrecBits); return result; } - inline QFixedPt operator-(qreal value) const - { QFixedPt result; - result.val = val - int(value * (1 << PrecBits)); return result; } - - inline QFixedPt operator*(const QFixedPt& value) const - { QFixedPt result; - result.val = mul(val, value.val); return result; } - inline QFixedPt operator*(int value) const - { QFixedPt result; - result.val = mul(val, (value << PrecBits)); return result; } - inline QFixedPt operator*(qreal value) const - { QFixedPt result; - result.val = mul(val, int(value * (1 << PrecBits))); return result; } - - inline QFixedPt operator/(const QFixedPt& value) const - { QFixedPt result; - result.val = div(val, value.val); return result; } - inline QFixedPt operator/(int value) const - { QFixedPt result; - result.val = div(val, (value << PrecBits)); return result; } - inline QFixedPt operator/(qreal value) const - { QFixedPt result; - result.val = div(val, int(value * (1 << PrecBits))); return result; } - - inline QFixedPt operator-() const - { QFixedPt result; result.val = -val; return result; } - - inline QFixedPt sqrt() const; - inline qreal sqrtF() const; - inline QFixedPt round() const; - inline QFixedPt floor() const; - inline QFixedPt ceil() const; - inline int truncate() const { return val >> PrecBits; } - - inline int toInt() const { return (val + (1 << (PrecBits - 1))) >> PrecBits; } - inline qreal toReal() const { return qreal(val) / qreal(1 << PrecBits); } - -#if !defined(Q_NO_TEMPLATE_FRIENDS) - template - friend QFixedPt operator/(int v1, const QFixedPt& v2); - template - friend QFixedPt operator/(qreal v1, const QFixedPt& v2); - -private: -#endif - int val; - - inline static int mul(int v1, int v2) - { - return int((qint64(v1) * qint64(v2)) >> PrecBits); - } - - inline static int div(int v1, int v2) - { - if (v2) - return int((qint64(v1) << PrecBits) / qint64(v2)); - else - return 0; - } - - // These are used by toPrecision() to avoid a silly gcc compiler warning - // related to negative shift values that will never actually be used. - inline static int shiftRight(int val, int shift) - { - return val >> shift; - } - inline static int shiftLeft(int val, int shift) - { - return val << shift; - } - -#if !defined(Q_NO_TEMPLATE_FRIENDS) - template - friend QFixedPt qFixedPtToPrecision(const QFixedPt& value); -#endif -}; - -template -inline bool operator==(const QFixedPt& v1, int v2) -{ - return v1.bits() == (v2 << PrecBits); -} - -template -inline bool operator==(int v1, const QFixedPt& v2) -{ - return (v1 << PrecBits) == v2.bits(); -} - -template -inline bool operator==(const QFixedPt& v1, qreal v2) -{ - return v1.bits() == int(v2 * (1 << PrecBits)); -} - -template -inline bool operator==(qreal v1, const QFixedPt& v2) -{ - return int(v1 * (1 << PrecBits)) == v2.bits(); -} - -template -inline bool operator!=(const QFixedPt& v1, int v2) -{ - return v1.bits() != (v2 << PrecBits); -} - -template -inline bool operator!=(int v1, const QFixedPt& v2) -{ - return (v1 << PrecBits) != v2.bits(); -} - -template -inline bool operator!=(const QFixedPt& v1, qreal v2) -{ - return v1.bits() != int(v2 * (1 << PrecBits)); -} - -template -inline bool operator!=(qreal v1, const QFixedPt& v2) -{ - return int(v1 * (1 << PrecBits)) != v2.bits(); -} - -template -inline bool operator<=(const QFixedPt& v1, int v2) -{ - return v1.bits() <= (v2 << PrecBits); -} - -template -inline bool operator<=(int v1, const QFixedPt& v2) -{ - return (v1 << PrecBits) <= v2.bits(); -} - -template -inline bool operator<=(const QFixedPt& v1, qreal v2) -{ - return v1.bits() <= int(v2 * (1 << PrecBits)); -} - -template -inline bool operator<=(qreal v1, const QFixedPt& v2) -{ - return int(v1 * (1 << PrecBits)) <= v2.bits(); -} - -template -inline bool operator<(const QFixedPt& v1, int v2) -{ - return v1.bits() < (v2 << PrecBits); -} - -template -inline bool operator<(int v1, const QFixedPt& v2) -{ - return (v1 << PrecBits) < v2.bits(); -} - -template -inline bool operator<(const QFixedPt& v1, qreal v2) -{ - return v1.bits() < int(v2 * (1 << PrecBits)); -} - -template -inline bool operator<(qreal v1, const QFixedPt& v2) -{ - return int(v1 * (1 << PrecBits)) < v2.bits(); -} - -template -inline bool operator>=(const QFixedPt& v1, int v2) -{ - return v1.bits() >= (v2 << PrecBits); -} - -template -inline bool operator>=(int v1, const QFixedPt& v2) -{ - return (v1 << PrecBits) >= v2.bits(); -} - -template -inline bool operator>=(const QFixedPt& v1, qreal v2) -{ - return v1.bits() >= int(v2 * (1 << PrecBits)); -} - -template -inline bool operator>=(qreal v1, const QFixedPt& v2) -{ - return int(v1 * (1 << PrecBits)) >= v2.bits(); -} - -template -inline bool operator>(const QFixedPt& v1, int v2) -{ - return v1.bits() > (v2 << PrecBits); -} - -template -inline bool operator>(int v1, const QFixedPt& v2) -{ - return (v1 << PrecBits) > v2.bits(); -} - -template -inline bool operator>(const QFixedPt& v1, qreal v2) -{ - return v1.bits() > int(v2 * (1 << PrecBits)); -} - -template -inline bool operator>(qreal v1, const QFixedPt& v2) -{ - return int(v1 * (1 << PrecBits)) > v2.bits(); -} - -template -inline QFixedPt operator+(int v1, const QFixedPt& v2) -{ - return v2 + v1; -} - -template -inline QFixedPt operator+(qreal v1, const QFixedPt& v2) -{ - return v2 + v1; -} - -template -inline QFixedPt operator-(int v1, const QFixedPt& v2) -{ - return -(v2 - v1); -} - -template -inline QFixedPt operator-(qreal v1, const QFixedPt& v2) -{ - return -(v2 - v1); -} - -template -inline QFixedPt operator*(int v1, const QFixedPt& v2) -{ - return v2 * v1; -} - -template -inline QFixedPt operator*(qreal v1, const QFixedPt& v2) -{ - return v2 * v1; -} - -template -inline QFixedPt operator/(int v1, const QFixedPt& v2) -{ - QFixedPt result; - result.val = QFixedPt::div(v1 << PrecBits, v2.val); - return result; -} - -template -inline QFixedPt operator/(qreal v1, const QFixedPt& v2) -{ - QFixedPt result; - result.val = QFixedPt::div(int(v1 * (1 << PrecBits)), v2.val); - return result; -} - -template -inline QFixedPt QFixedPt::sqrt() const -{ - QFixedPt result; - result.val = int(qt_math3d_fixed_sqrt - (qint64(val) << (PrecBits * 2)) >> (PrecBits / 2)); - return result; -} - -template -inline qreal QFixedPt::sqrtF() const -{ - return qt_math3d_fixed_sqrt - (qint64(val) << (PrecBits * 2)) / (qreal)(1 << (PrecBits + (PrecBits / 2))); -} - -template -inline QFixedPt QFixedPt::round() const -{ - QFixedPt result; - result.val = (val + (1 << (PrecBits - 1))) & ~((1 << PrecBits) - 1); - return result; -} - -template -inline QFixedPt QFixedPt::floor() const -{ - QFixedPt result; - result.val = val & ~((1 << PrecBits) - 1); - return result; -} - -template -inline QFixedPt QFixedPt::ceil() const -{ - QFixedPt result; - result.val = (val + (1 << PrecBits) - 1) & ~((1 << PrecBits) - 1); - return result; -} - -template -inline int qCeil(const QFixedPt& value) -{ - return value.ceil().bits() >> PrecBits; -} - -template -inline int qFloor(const QFixedPt& value) -{ - return value.floor().bits() >> PrecBits; -} - -template -inline int qRound(const QFixedPt& value) -{ - return value.round().bits() >> PrecBits; -} - -template -inline bool qFuzzyCompare(const QFixedPt& v1, const QFixedPt& v2, int compareBits = (PrecBits / 4)) -{ - return ((v1.bits() ^ v2.bits()) & ~((1 << compareBits) - 1)) == 0; -} - -template -inline bool qIsNull(const QFixedPt& v) -{ - return v.bits() == 0; -} - -template -QFixedPt qFixedPtToPrecision(const QFixedPt& value) -{ - QFixedPt result; - if (Prec < PrecBits) - result.setBits(QFixedPt::shiftRight(value.bits(), (PrecBits - Prec))); - else - result.setBits(QFixedPt::shiftLeft(value.bits(), (Prec - PrecBits))); - return result; -} - -template -inline QDebug &operator<<(QDebug &dbg, const QFixedPt &f) -{ - return dbg << f.toReal(); -} - -Q_DECLARE_TYPEINFO(QFixedPt<0>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<1>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<2>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<3>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<4>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<5>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<6>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<7>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<8>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<9>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<10>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<11>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<12>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<13>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<14>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<15>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<16>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<17>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<18>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<19>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<20>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<21>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<22>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<23>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<24>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<25>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<26>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<27>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<28>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<29>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<30>, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(QFixedPt<31>, Q_PRIMITIVE_TYPE); - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/gui/math3d/qgenericmatrix.h b/src/gui/math3d/qgenericmatrix.h index dbeaaf3..d0b22de 100644 --- a/src/gui/math3d/qgenericmatrix.h +++ b/src/gui/math3d/qgenericmatrix.h @@ -42,8 +42,8 @@ #ifndef QGENERICMATRIX_H #define QGENERICMATRIX_H -#include #include +#include QT_BEGIN_HEADER @@ -134,7 +134,7 @@ template Q_INLINE_TEMPLATE T QGenericMatrix::operator()(int row, int column) const { Q_ASSERT(row >= 0 && row < M && column >= 0 && column < N); - return qt_math3d_convert(m[column][row]); + return T(m[column][row]); } template @@ -323,18 +323,18 @@ Q_OUTOFLINE_TEMPLATE void QGenericMatrix::toValueArray(T *value { for (int col = 0; col < N; ++col) for (int row = 0; row < M; ++row) - values[row * N + col] = qt_math3d_convert(m[col][row]); + values[row * N + col] = T(m[col][row]); } // Define aliases for the useful variants of QGenericMatrix. -typedef QGenericMatrix<2, 2, qreal, qrealinner> QMatrix2x2; -typedef QGenericMatrix<2, 3, qreal, qrealinner> QMatrix2x3; -typedef QGenericMatrix<2, 4, qreal, qrealinner> QMatrix2x4; -typedef QGenericMatrix<3, 2, qreal, qrealinner> QMatrix3x2; -typedef QGenericMatrix<3, 3, qreal, qrealinner> QMatrix3x3; -typedef QGenericMatrix<3, 4, qreal, qrealinner> QMatrix3x4; -typedef QGenericMatrix<4, 2, qreal, qrealinner> QMatrix4x2; -typedef QGenericMatrix<4, 3, qreal, qrealinner> QMatrix4x3; +typedef QGenericMatrix<2, 2, qreal, float> QMatrix2x2; +typedef QGenericMatrix<2, 3, qreal, float> QMatrix2x3; +typedef QGenericMatrix<2, 4, qreal, float> QMatrix2x4; +typedef QGenericMatrix<3, 2, qreal, float> QMatrix3x2; +typedef QGenericMatrix<3, 3, qreal, float> QMatrix3x3; +typedef QGenericMatrix<3, 4, qreal, float> QMatrix3x4; +typedef QGenericMatrix<4, 2, qreal, float> QMatrix4x2; +typedef QGenericMatrix<4, 3, qreal, float> QMatrix4x3; #ifndef QT_NO_DEBUG_STREAM diff --git a/src/gui/math3d/qmath3dglobal.h b/src/gui/math3d/qmath3dglobal.h deleted file mode 100644 index c2f7184..0000000 --- a/src/gui/math3d/qmath3dglobal.h +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMATH3DGLOBAL_H -#define QMATH3DGLOBAL_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -// Detect the presence of a fixed-point OpenGL implementation. -#if defined(QT_OPENGL_ES_1_CL) || defined(QT_NO_GL_FLOAT) -#ifndef QT_GL_FIXED_PREFERRED -#define QT_GL_FIXED_PREFERRED 1 -#endif -#endif - -// QT_GL_FIXED_PREFERRED indicates that fixed-point should be -// preferred over floating-point for operations requiring high performance. -// -// qreal is the floating-point type that should be used in -// user-visible functions. qrealinner is used internally where -// values may be stored as either floating-point or fixed-point. -// qrealinner will typically be the same size as GLfloat or GLfixed. -#if defined(QT_GL_FIXED_PREFERRED) -typedef QFixedPt<16> qrealinner; -#else -typedef float qrealinner; -#endif - -// Explicit conversion operator, primarily for converting from -// fixed point back to floating-point. This is safer than -// declaring conversion operators in the QFixedPt class. -template -T1 qt_math3d_convert(T2 v) -{ - return T1(v); -} -template <> -inline float qt_math3d_convert< float, QFixedPt<16> >(QFixedPt<16> v) -{ - return float(v.toReal()); -} -template <> -inline double qt_math3d_convert< double, QFixedPt<16> >(QFixedPt<16> v) -{ - return double(v.toReal()); -} -template <> -inline int qt_math3d_convert< int, QFixedPt<16> >(QFixedPt<16> v) -{ - return v.toInt(); -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/gui/math3d/qmath3dutil.cpp b/src/gui/math3d/qmath3dutil.cpp deleted file mode 100644 index ad84162..0000000 --- a/src/gui/math3d/qmath3dutil.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmath3dutil_p.h" - -QT_BEGIN_NAMESPACE - -#ifdef QT_GL_FIXED_PREFERRED - -// The table that follows was automatically generated by the following code: -// -//#include -//#include -// -//int main() -//{ -// double angle; -// int count = 0; -// for (angle = 0.0; angle < 360.0; angle += 1.0) { -// if ((count % 4) == 0) -// printf(" "); -// printf(" qf2vt(%f)", sin(angle * M_PI / 180.0)); -// ++count; -// if (count != 360) -// printf(","); -// if ((count % 4) == 0) -// printf("\n"); -// } -// return 0; -//} - -#define qf2vt(x) (int((x) * 65536.0)) - -static int const sinTable[360] = { - qf2vt(0.000000), qf2vt(0.017452), qf2vt(0.034899), qf2vt(0.052336), - qf2vt(0.069756), qf2vt(0.087156), qf2vt(0.104528), qf2vt(0.121869), - qf2vt(0.139173), qf2vt(0.156434), qf2vt(0.173648), qf2vt(0.190809), - qf2vt(0.207912), qf2vt(0.224951), qf2vt(0.241922), qf2vt(0.258819), - qf2vt(0.275637), qf2vt(0.292372), qf2vt(0.309017), qf2vt(0.325568), - qf2vt(0.342020), qf2vt(0.358368), qf2vt(0.374607), qf2vt(0.390731), - qf2vt(0.406737), qf2vt(0.422618), qf2vt(0.438371), qf2vt(0.453990), - qf2vt(0.469472), qf2vt(0.484810), qf2vt(0.500000), qf2vt(0.515038), - qf2vt(0.529919), qf2vt(0.544639), qf2vt(0.559193), qf2vt(0.573576), - qf2vt(0.587785), qf2vt(0.601815), qf2vt(0.615661), qf2vt(0.629320), - qf2vt(0.642788), qf2vt(0.656059), qf2vt(0.669131), qf2vt(0.681998), - qf2vt(0.694658), qf2vt(0.707107), qf2vt(0.719340), qf2vt(0.731354), - qf2vt(0.743145), qf2vt(0.754710), qf2vt(0.766044), qf2vt(0.777146), - qf2vt(0.788011), qf2vt(0.798636), qf2vt(0.809017), qf2vt(0.819152), - qf2vt(0.829038), qf2vt(0.838671), qf2vt(0.848048), qf2vt(0.857167), - qf2vt(0.866025), qf2vt(0.874620), qf2vt(0.882948), qf2vt(0.891007), - qf2vt(0.898794), qf2vt(0.906308), qf2vt(0.913545), qf2vt(0.920505), - qf2vt(0.927184), qf2vt(0.933580), qf2vt(0.939693), qf2vt(0.945519), - qf2vt(0.951057), qf2vt(0.956305), qf2vt(0.961262), qf2vt(0.965926), - qf2vt(0.970296), qf2vt(0.974370), qf2vt(0.978148), qf2vt(0.981627), - qf2vt(0.984808), qf2vt(0.987688), qf2vt(0.990268), qf2vt(0.992546), - qf2vt(0.994522), qf2vt(0.996195), qf2vt(0.997564), qf2vt(0.998630), - qf2vt(0.999391), qf2vt(0.999848), qf2vt(1.000000), qf2vt(0.999848), - qf2vt(0.999391), qf2vt(0.998630), qf2vt(0.997564), qf2vt(0.996195), - qf2vt(0.994522), qf2vt(0.992546), qf2vt(0.990268), qf2vt(0.987688), - qf2vt(0.984808), qf2vt(0.981627), qf2vt(0.978148), qf2vt(0.974370), - qf2vt(0.970296), qf2vt(0.965926), qf2vt(0.961262), qf2vt(0.956305), - qf2vt(0.951057), qf2vt(0.945519), qf2vt(0.939693), qf2vt(0.933580), - qf2vt(0.927184), qf2vt(0.920505), qf2vt(0.913545), qf2vt(0.906308), - qf2vt(0.898794), qf2vt(0.891007), qf2vt(0.882948), qf2vt(0.874620), - qf2vt(0.866025), qf2vt(0.857167), qf2vt(0.848048), qf2vt(0.838671), - qf2vt(0.829038), qf2vt(0.819152), qf2vt(0.809017), qf2vt(0.798636), - qf2vt(0.788011), qf2vt(0.777146), qf2vt(0.766044), qf2vt(0.754710), - qf2vt(0.743145), qf2vt(0.731354), qf2vt(0.719340), qf2vt(0.707107), - qf2vt(0.694658), qf2vt(0.681998), qf2vt(0.669131), qf2vt(0.656059), - qf2vt(0.642788), qf2vt(0.629320), qf2vt(0.615661), qf2vt(0.601815), - qf2vt(0.587785), qf2vt(0.573576), qf2vt(0.559193), qf2vt(0.544639), - qf2vt(0.529919), qf2vt(0.515038), qf2vt(0.500000), qf2vt(0.484810), - qf2vt(0.469472), qf2vt(0.453990), qf2vt(0.438371), qf2vt(0.422618), - qf2vt(0.406737), qf2vt(0.390731), qf2vt(0.374607), qf2vt(0.358368), - qf2vt(0.342020), qf2vt(0.325568), qf2vt(0.309017), qf2vt(0.292372), - qf2vt(0.275637), qf2vt(0.258819), qf2vt(0.241922), qf2vt(0.224951), - qf2vt(0.207912), qf2vt(0.190809), qf2vt(0.173648), qf2vt(0.156434), - qf2vt(0.139173), qf2vt(0.121869), qf2vt(0.104528), qf2vt(0.087156), - qf2vt(0.069756), qf2vt(0.052336), qf2vt(0.034899), qf2vt(0.017452), - qf2vt(0.000000), qf2vt(-0.017452), qf2vt(-0.034899), qf2vt(-0.052336), - qf2vt(-0.069756), qf2vt(-0.087156), qf2vt(-0.104528), qf2vt(-0.121869), - qf2vt(-0.139173), qf2vt(-0.156434), qf2vt(-0.173648), qf2vt(-0.190809), - qf2vt(-0.207912), qf2vt(-0.224951), qf2vt(-0.241922), qf2vt(-0.258819), - qf2vt(-0.275637), qf2vt(-0.292372), qf2vt(-0.309017), qf2vt(-0.325568), - qf2vt(-0.342020), qf2vt(-0.358368), qf2vt(-0.374607), qf2vt(-0.390731), - qf2vt(-0.406737), qf2vt(-0.422618), qf2vt(-0.438371), qf2vt(-0.453990), - qf2vt(-0.469472), qf2vt(-0.484810), qf2vt(-0.500000), qf2vt(-0.515038), - qf2vt(-0.529919), qf2vt(-0.544639), qf2vt(-0.559193), qf2vt(-0.573576), - qf2vt(-0.587785), qf2vt(-0.601815), qf2vt(-0.615661), qf2vt(-0.629320), - qf2vt(-0.642788), qf2vt(-0.656059), qf2vt(-0.669131), qf2vt(-0.681998), - qf2vt(-0.694658), qf2vt(-0.707107), qf2vt(-0.719340), qf2vt(-0.731354), - qf2vt(-0.743145), qf2vt(-0.754710), qf2vt(-0.766044), qf2vt(-0.777146), - qf2vt(-0.788011), qf2vt(-0.798636), qf2vt(-0.809017), qf2vt(-0.819152), - qf2vt(-0.829038), qf2vt(-0.838671), qf2vt(-0.848048), qf2vt(-0.857167), - qf2vt(-0.866025), qf2vt(-0.874620), qf2vt(-0.882948), qf2vt(-0.891007), - qf2vt(-0.898794), qf2vt(-0.906308), qf2vt(-0.913545), qf2vt(-0.920505), - qf2vt(-0.927184), qf2vt(-0.933580), qf2vt(-0.939693), qf2vt(-0.945519), - qf2vt(-0.951057), qf2vt(-0.956305), qf2vt(-0.961262), qf2vt(-0.965926), - qf2vt(-0.970296), qf2vt(-0.974370), qf2vt(-0.978148), qf2vt(-0.981627), - qf2vt(-0.984808), qf2vt(-0.987688), qf2vt(-0.990268), qf2vt(-0.992546), - qf2vt(-0.994522), qf2vt(-0.996195), qf2vt(-0.997564), qf2vt(-0.998630), - qf2vt(-0.999391), qf2vt(-0.999848), qf2vt(-1.000000), qf2vt(-0.999848), - qf2vt(-0.999391), qf2vt(-0.998630), qf2vt(-0.997564), qf2vt(-0.996195), - qf2vt(-0.994522), qf2vt(-0.992546), qf2vt(-0.990268), qf2vt(-0.987688), - qf2vt(-0.984808), qf2vt(-0.981627), qf2vt(-0.978148), qf2vt(-0.974370), - qf2vt(-0.970296), qf2vt(-0.965926), qf2vt(-0.961262), qf2vt(-0.956305), - qf2vt(-0.951057), qf2vt(-0.945519), qf2vt(-0.939693), qf2vt(-0.933580), - qf2vt(-0.927184), qf2vt(-0.920505), qf2vt(-0.913545), qf2vt(-0.906308), - qf2vt(-0.898794), qf2vt(-0.891007), qf2vt(-0.882948), qf2vt(-0.874620), - qf2vt(-0.866025), qf2vt(-0.857167), qf2vt(-0.848048), qf2vt(-0.838671), - qf2vt(-0.829038), qf2vt(-0.819152), qf2vt(-0.809017), qf2vt(-0.798636), - qf2vt(-0.788011), qf2vt(-0.777146), qf2vt(-0.766044), qf2vt(-0.754710), - qf2vt(-0.743145), qf2vt(-0.731354), qf2vt(-0.719340), qf2vt(-0.707107), - qf2vt(-0.694658), qf2vt(-0.681998), qf2vt(-0.669131), qf2vt(-0.656059), - qf2vt(-0.642788), qf2vt(-0.629320), qf2vt(-0.615661), qf2vt(-0.601815), - qf2vt(-0.587785), qf2vt(-0.573576), qf2vt(-0.559193), qf2vt(-0.544639), - qf2vt(-0.529919), qf2vt(-0.515038), qf2vt(-0.500000), qf2vt(-0.484810), - qf2vt(-0.469472), qf2vt(-0.453990), qf2vt(-0.438371), qf2vt(-0.422618), - qf2vt(-0.406737), qf2vt(-0.390731), qf2vt(-0.374607), qf2vt(-0.358368), - qf2vt(-0.342020), qf2vt(-0.325568), qf2vt(-0.309017), qf2vt(-0.292372), - qf2vt(-0.275637), qf2vt(-0.258819), qf2vt(-0.241922), qf2vt(-0.224951), - qf2vt(-0.207912), qf2vt(-0.190809), qf2vt(-0.173648), qf2vt(-0.156434), - qf2vt(-0.139173), qf2vt(-0.121869), qf2vt(-0.104528), qf2vt(-0.087156), - qf2vt(-0.069756), qf2vt(-0.052336), qf2vt(-0.034899), qf2vt(-0.017452) -}; - -void qt_math3d_sincos(qreal angle, qrealinner *s, qrealinner *c) -{ - if (angle == qFloor(angle)) { - // The angle is an integer number of degrees, so look up the results. - int a = (int)angle; - if (a >= 0) - a = (a % 360); - else - a = 360 - (-a % 360); - s->setBits(sinTable[a]); - c->setBits(sinTable[(a + 90) % 360]); - } else { - qreal a = angle * M_PI / 180.0f; - *s = qSin(a); - *c = qCos(a); - } -} - -#else - -void qt_math3d_sincos(qreal angle, qrealinner *s, qrealinner *c) -{ - qreal a = angle * M_PI / 180.0f; - *s = qSin(a); - *c = qCos(a); -} - -#endif - -QT_END_NAMESPACE diff --git a/src/gui/math3d/qmath3dutil_p.h b/src/gui/math3d/qmath3dutil_p.h deleted file mode 100644 index fa4c156..0000000 --- a/src/gui/math3d/qmath3dutil_p.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMATH3DUTIL_P_H -#define QMATH3DUTIL_P_H - -#include -#include - -QT_BEGIN_NAMESPACE - -#ifdef QT_GL_FIXED_PREFERRED -#define qvtsqrt(x) ((x).sqrtF()) -#else -#define qvtsqrt(x) qSqrt((x)) -#endif - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -void qt_math3d_sincos(qreal degrees, qrealinner *s, qrealinner *c); - -#ifdef QT_GL_FIXED_PREFERRED - -inline qrealinner qf2vt_round(qreal x) -{ - QFixedPt<16> result; - if (x >= 0.0f) - result.setBits(int(x * 65536.0f + 0.5f)); - else - result.setBits(int(x * 65536.0f - 0.5f)); - return result; -} - -// Helper macros for computing dot products without losing precision. -// In fixed-point mode, a 64-bit intermediate result is used. -#define qvtmul64(x,y) ((qint64((x).bits())) * (qint64((y).bits()))) -#define qvtsqrt64(x) \ - (qt_math3d_fixed_sqrt((x) << 16) / (qreal)(1 << 24)) -#define qvtdot64(x) ((x) / (qreal)(((qint64)1) << 32)) - -#else - -inline qrealinner qf2vt_round(qreal x) -{ - return x; -} - -#define qvtmul64(x,y) ((x) * (y)) -#define qvtsqrt64(x) (qvtsqrt((x))) -#define qvtdot64(x) ((x)) - -#endif - -QT_END_NAMESPACE - -#endif diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index bcb3066..c2873e0 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -40,7 +40,6 @@ ****************************************************************************/ #include "qmatrix4x4.h" -#include "qmath3dutil_p.h" #include #include #include @@ -106,7 +105,7 @@ QMatrix4x4::QMatrix4x4(const qreal *values) #if !defined(QT_NO_MEMBER_TEMPLATES) || defined(Q_QDOC) /*! - \fn QMatrix4x4::QMatrix4x4(const QGenericMatrix& matrix) + \fn QMatrix4x4::QMatrix4x4(const QGenericMatrix& matrix) Constructs a 4x4 matrix from the left-most 4 columns and top-most 4 rows of \a matrix. If \a matrix has less than 4 columns or rows, @@ -117,7 +116,7 @@ QMatrix4x4::QMatrix4x4(const qreal *values) */ /*! - \fn QGenericMatrix QMatrix4x4::toGenericMatrix() const + \fn QGenericMatrix QMatrix4x4::toGenericMatrix() const Constructs a NxM generic matrix from the left-most N columns and top-most M rows of this 4x4 matrix. If N or M is greater than 4, @@ -130,7 +129,7 @@ QMatrix4x4::QMatrix4x4(const qreal *values) #endif /*! - \fn QMatrix4x4 qGenericMatrixToMatrix4x4(const QGenericMatrix& matrix) + \fn QMatrix4x4 qGenericMatrixToMatrix4x4(const QGenericMatrix& matrix) \relates QMatrix4x4 Returns a 4x4 matrix constructed from the left-most 4 columns and @@ -142,7 +141,7 @@ QMatrix4x4::QMatrix4x4(const qreal *values) */ /*! - \fn QGenericMatrix qGenericMatrixFromMatrix4x4(const QMatrix4x4& matrix) + \fn QGenericMatrix qGenericMatrixFromMatrix4x4(const QMatrix4x4& matrix) \relates QMatrix4x4 Returns a NxM generic matrix constructed from the left-most N columns @@ -156,7 +155,7 @@ QMatrix4x4::QMatrix4x4(const qreal *values) /*! \internal */ -QMatrix4x4::QMatrix4x4(const qrealinner *values, int cols, int rows) +QMatrix4x4::QMatrix4x4(const float *values, int cols, int rows) { for (int col = 0; col < 4; ++col) { for (int row = 0; row < 4; ++row) { @@ -244,7 +243,7 @@ QMatrix4x4::QMatrix4x4(const QTransform& transform) */ /*! - \fn qrealinner& QMatrix4x4::operator()(int row, int column) + \fn float& QMatrix4x4::operator()(int row, int column) Returns a reference to the element at position (\a row, \a column) in this matrix so that the element can be assigned to. @@ -316,8 +315,8 @@ QMatrix4x4::QMatrix4x4(const QTransform& transform) // | A B C | // M = | D E F | det(M) = A * (EI - HF) - B * (DI - GF) + C * (DH - GE) // | G H I | -static inline qrealinner matrixDet3 - (const qrealinner m[4][4], int col0, int col1, int col2, +static inline float matrixDet3 + (const float m[4][4], int col0, int col1, int col2, int row0, int row1, int row2) { return m[col0][row0] * @@ -332,9 +331,9 @@ static inline qrealinner matrixDet3 } // Calculate the determinant of a 4x4 matrix. -static inline qrealinner matrixDet4(const qrealinner m[4][4]) +static inline float matrixDet4(const float m[4][4]) { - qrealinner det; + float det; det = m[0][0] * matrixDet3(m, 1, 2, 3, 1, 2, 3); det -= m[1][0] * matrixDet3(m, 0, 2, 3, 1, 2, 3); det += m[2][0] * matrixDet3(m, 0, 1, 3, 1, 2, 3); @@ -347,7 +346,7 @@ static inline qrealinner matrixDet4(const qrealinner m[4][4]) */ qreal QMatrix4x4::determinant() const { - return qt_math3d_convert(matrixDet4(m)); + return qreal(matrixDet4(m)); } /*! @@ -386,13 +385,13 @@ QMatrix4x4 QMatrix4x4::inverted(bool *invertible) const QMatrix4x4 inv(1); // The "1" says to not load the identity. - qrealinner det = matrixDet4(m); + float det = matrixDet4(m); if (det == 0.0f) { if (invertible) *invertible = false; return QMatrix4x4(); } - det = qrealinner(1.0f) / det; + det = 1.0f / det; inv.m[0][0] = matrixDet3(m, 1, 2, 3, 1, 2, 3) * det; inv.m[0][1] = -matrixDet3(m, 0, 2, 3, 1, 2, 3) * det; @@ -434,18 +433,18 @@ QMatrix3x3 QMatrix4x4::normalMatrix() const } else if (flagBits == Scale || flagBits == (Translation | Scale)) { if (m[0][0] == 0.0f || m[1][1] == 0.0f || m[2][2] == 0.0f) return inv; - inv.data()[0] = qrealinner(1.0f) / m[0][0]; - inv.data()[4] = qrealinner(1.0f) / m[1][1]; - inv.data()[8] = qrealinner(1.0f) / m[2][2]; + inv.data()[0] = 1.0f / m[0][0]; + inv.data()[4] = 1.0f / m[1][1]; + inv.data()[8] = 1.0f / m[2][2]; return inv; } - qrealinner det = matrixDet3(m, 0, 1, 2, 0, 1, 2); + float det = matrixDet3(m, 0, 1, 2, 0, 1, 2); if (det == 0.0f) return inv; - det = qrealinner(1.0f) / det; + det = 1.0f / det; - qrealinner *invm = inv.data(); + float *invm = inv.data(); // Invert and transpose in a single step. invm[0 + 0 * 3] = (m[1][1] * m[2][2] - m[2][1] * m[1][2]) * det; @@ -507,23 +506,22 @@ QMatrix4x4 QMatrix4x4::transposed() const */ QMatrix4x4& QMatrix4x4::operator/=(qreal divisor) { - qrealinner d(divisor); - m[0][0] /= d; - m[0][1] /= d; - m[0][2] /= d; - m[0][3] /= d; - m[1][0] /= d; - m[1][1] /= d; - m[1][2] /= d; - m[1][3] /= d; - m[2][0] /= d; - m[2][1] /= d; - m[2][2] /= d; - m[2][3] /= d; - m[3][0] /= d; - m[3][1] /= d; - m[3][2] /= d; - m[3][3] /= d; + m[0][0] /= divisor; + m[0][1] /= divisor; + m[0][2] /= divisor; + m[0][3] /= divisor; + m[1][0] /= divisor; + m[1][1] /= divisor; + m[1][2] /= divisor; + m[1][3] /= divisor; + m[2][0] /= divisor; + m[2][1] /= divisor; + m[2][2] /= divisor; + m[2][3] /= divisor; + m[3][0] /= divisor; + m[3][1] /= divisor; + m[3][2] /= divisor; + m[3][3] /= divisor; flagBits = General; return *this; } @@ -665,23 +663,22 @@ QMatrix4x4& QMatrix4x4::operator/=(qreal divisor) QMatrix4x4 operator/(const QMatrix4x4& matrix, qreal divisor) { QMatrix4x4 m(1); // The "1" says to not load the identity. - qrealinner d(divisor); - m.m[0][0] = matrix.m[0][0] / d; - m.m[0][1] = matrix.m[0][1] / d; - m.m[0][2] = matrix.m[0][2] / d; - m.m[0][3] = matrix.m[0][3] / d; - m.m[1][0] = matrix.m[1][0] / d; - m.m[1][1] = matrix.m[1][1] / d; - m.m[1][2] = matrix.m[1][2] / d; - m.m[1][3] = matrix.m[1][3] / d; - m.m[2][0] = matrix.m[2][0] / d; - m.m[2][1] = matrix.m[2][1] / d; - m.m[2][2] = matrix.m[2][2] / d; - m.m[2][3] = matrix.m[2][3] / d; - m.m[3][0] = matrix.m[3][0] / d; - m.m[3][1] = matrix.m[3][1] / d; - m.m[3][2] = matrix.m[3][2] / d; - m.m[3][3] = matrix.m[3][3] / d; + m.m[0][0] = matrix.m[0][0] / divisor; + m.m[0][1] = matrix.m[0][1] / divisor; + m.m[0][2] = matrix.m[0][2] / divisor; + m.m[0][3] = matrix.m[0][3] / divisor; + m.m[1][0] = matrix.m[1][0] / divisor; + m.m[1][1] = matrix.m[1][1] / divisor; + m.m[1][2] = matrix.m[1][2] / divisor; + m.m[1][3] = matrix.m[1][3] / divisor; + m.m[2][0] = matrix.m[2][0] / divisor; + m.m[2][1] = matrix.m[2][1] / divisor; + m.m[2][2] = matrix.m[2][2] / divisor; + m.m[2][3] = matrix.m[2][3] / divisor; + m.m[3][0] = matrix.m[3][0] / divisor; + m.m[3][1] = matrix.m[3][1] / divisor; + m.m[3][2] = matrix.m[3][2] / divisor; + m.m[3][3] = matrix.m[3][3] / divisor; return m; } @@ -703,9 +700,9 @@ QMatrix4x4 operator/(const QMatrix4x4& matrix, qreal divisor) */ QMatrix4x4& QMatrix4x4::scale(const QVector3D& vector) { - qrealinner vx = vector.xp; - qrealinner vy = vector.yp; - qrealinner vz = vector.zp; + float vx = vector.xp; + float vy = vector.yp; + float vz = vector.zp; if (flagBits == Identity) { m[0][0] = vx; m[1][1] = vy; @@ -749,9 +746,9 @@ QMatrix4x4& QMatrix4x4::scale(const QVector3D& vector) */ QMatrix4x4& QMatrix4x4::scale(qreal x, qreal y, qreal z) { - qrealinner vx(x); - qrealinner vy(y); - qrealinner vz(z); + float vx(x); + float vy(y); + float vz(z); if (flagBits == Identity) { m[0][0] = vx; m[1][1] = vy; @@ -794,34 +791,33 @@ QMatrix4x4& QMatrix4x4::scale(qreal x, qreal y, qreal z) */ QMatrix4x4& QMatrix4x4::scale(qreal factor) { - qrealinner f(factor); if (flagBits == Identity) { - m[0][0] = f; - m[1][1] = f; - m[2][2] = f; + m[0][0] = factor; + m[1][1] = factor; + m[2][2] = factor; flagBits = Scale; } else if (flagBits == Scale || flagBits == (Scale | Translation)) { - m[0][0] *= f; - m[1][1] *= f; - m[2][2] *= f; + m[0][0] *= factor; + m[1][1] *= factor; + m[2][2] *= factor; } else if (flagBits == Translation) { - m[0][0] = f; - m[1][1] = f; - m[2][2] = f; + m[0][0] = factor; + m[1][1] = factor; + m[2][2] = factor; flagBits |= Scale; } else { - m[0][0] *= f; - m[0][1] *= f; - m[0][2] *= f; - m[0][3] *= f; - m[1][0] *= f; - m[1][1] *= f; - m[1][2] *= f; - m[1][3] *= f; - m[2][0] *= f; - m[2][1] *= f; - m[2][2] *= f; - m[2][3] *= f; + m[0][0] *= factor; + m[0][1] *= factor; + m[0][2] *= factor; + m[0][3] *= factor; + m[1][0] *= factor; + m[1][1] *= factor; + m[1][2] *= factor; + m[1][3] *= factor; + m[2][0] *= factor; + m[2][1] *= factor; + m[2][2] *= factor; + m[2][3] *= factor; flagBits = General; } return *this; @@ -836,9 +832,9 @@ QMatrix4x4& QMatrix4x4::scale(qreal factor) */ QMatrix4x4& QMatrix4x4::translate(const QVector3D& vector) { - qrealinner vx = vector.xp; - qrealinner vy = vector.yp; - qrealinner vz = vector.zp; + float vx = vector.xp; + float vy = vector.yp; + float vz = vector.zp; if (flagBits == Identity) { m[3][0] = vx; m[3][1] = vy; @@ -882,9 +878,9 @@ QMatrix4x4& QMatrix4x4::translate(const QVector3D& vector) */ QMatrix4x4& QMatrix4x4::translate(qreal x, qreal y, qreal z) { - qrealinner vx(x); - qrealinner vy(y); - qrealinner vz(z); + float vx(x); + float vy(y); + float vz(z); if (flagBits == Identity) { m[3][0] = vx; m[3][1] = vy; @@ -931,6 +927,10 @@ QMatrix4x4& QMatrix4x4::rotate(qreal angle, const QVector3D& vector) #endif +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + /*! \overload @@ -942,8 +942,10 @@ QMatrix4x4& QMatrix4x4::rotate(qreal angle, const QVector3D& vector) QMatrix4x4& QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) { QMatrix4x4 m(1); // The "1" says to not load the identity. - qrealinner c, s, ic; - qt_math3d_sincos(angle, &s, &c); + qreal a = angle * M_PI / 180.0f; + qreal c = qCos(a); + qreal s = qSin(a); + qreal ic; bool quick = false; if (x == 0.0f) { if (y == 0.0f) { @@ -993,27 +995,24 @@ QMatrix4x4& QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) quick = true; } if (!quick) { - qrealinner vx(x); - qrealinner vy(y); - qrealinner vz(z); - qrealinner len(qvtsqrt(vx * vx + vy * vy + vz * vz)); + qreal len = qSqrt(x * x + y * y + z * z); if (len != 0) { - vx /= len; - vy /= len; - vz /= len; + x /= len; + y /= len; + z /= len; } ic = 1.0f - c; - m.m[0][0] = vx * vx * ic + c; - m.m[1][0] = vx * vy * ic - vz * s; - m.m[2][0] = vx * vz * ic + vy * s; + m.m[0][0] = x * x * ic + c; + m.m[1][0] = x * y * ic - z * s; + m.m[2][0] = x * z * ic + y * s; m.m[3][0] = 0.0f; - m.m[0][1] = vy * vx * ic + vz * s; - m.m[1][1] = vy * vy * ic + c; - m.m[2][1] = vy * vz * ic - vx * s; + m.m[0][1] = y * x * ic + z * s; + m.m[1][1] = y * y * ic + c; + m.m[2][1] = y * z * ic - x * s; m.m[3][1] = 0.0f; - m.m[0][2] = vx * vz * ic - vy * s; - m.m[1][2] = vy * vz * ic + vx * s; - m.m[2][2] = vz * vz * ic + c; + m.m[0][2] = x * z * ic - y * s; + m.m[1][2] = y * z * ic + x * s; + m.m[2][2] = z * z * ic + c; m.m[3][2] = 0.0f; m.m[0][3] = 0.0f; m.m[1][3] = 0.0f; @@ -1043,15 +1042,15 @@ QMatrix4x4& QMatrix4x4::rotate(const QQuaternion& quaternion) // Algorithm from: // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q54 QMatrix4x4 m(1); - qrealinner xx = quaternion.xp * quaternion.xp; - qrealinner xy = quaternion.xp * quaternion.yp; - qrealinner xz = quaternion.xp * quaternion.zp; - qrealinner xw = quaternion.xp * quaternion.wp; - qrealinner yy = quaternion.yp * quaternion.yp; - qrealinner yz = quaternion.yp * quaternion.zp; - qrealinner yw = quaternion.yp * quaternion.wp; - qrealinner zz = quaternion.zp * quaternion.zp; - qrealinner zw = quaternion.zp * quaternion.wp; + float xx = quaternion.xp * quaternion.xp; + float xy = quaternion.xp * quaternion.yp; + float xz = quaternion.xp * quaternion.zp; + float xw = quaternion.xp * quaternion.wp; + float yy = quaternion.yp * quaternion.yp; + float yz = quaternion.yp * quaternion.zp; + float yw = quaternion.yp * quaternion.wp; + float zz = quaternion.zp * quaternion.zp; + float zw = quaternion.zp * quaternion.wp; m.m[0][0] = 1.0f - 2 * (yy + zz); m.m[1][0] = 2 * (xy - zw); m.m[2][0] = 2 * (xz + yw); @@ -1137,33 +1136,33 @@ QMatrix4x4& QMatrix4x4::ortho(qreal left, qreal right, qreal bottom, qreal top, // which will be more efficient to modify with further // transformations than producing a "General" matrix. translate(QVector3D - (qf2vt_round(-(left + right) / width), - qf2vt_round(-(top + bottom) / invheight), + (-(left + right) / width, + -(top + bottom) / invheight, 0.0f, 1)); scale(QVector3D - (qf2vt_round(2.0f / width), - qf2vt_round(2.0f / invheight), + (2.0f / width, + 2.0f / invheight, -1.0f, 1)); return *this; } #endif QMatrix4x4 m(1); - m.m[0][0] = qf2vt_round(2.0f / width); - m.m[1][0] = qf2vt_round(0.0f); - m.m[2][0] = qf2vt_round(0.0f); - m.m[3][0] = qf2vt_round(-(left + right) / width); - m.m[0][1] = qf2vt_round(0.0f); - m.m[1][1] = qf2vt_round(2.0f / invheight); - m.m[2][1] = qf2vt_round(0.0f); - m.m[3][1] = qf2vt_round(-(top + bottom) / invheight); - m.m[0][2] = qf2vt_round(0.0f); - m.m[1][2] = qf2vt_round(0.0f); - m.m[2][2] = qf2vt_round(-2.0f / clip); - m.m[3][2] = qf2vt_round(-(nearPlane + farPlane) / clip); - m.m[0][3] = qf2vt_round(0.0f); - m.m[1][3] = qf2vt_round(0.0f); - m.m[2][3] = qf2vt_round(0.0f); - m.m[3][3] = qf2vt_round(1.0f); + m.m[0][0] = 2.0f / width; + m.m[1][0] = 0.0f; + m.m[2][0] = 0.0f; + m.m[3][0] = -(left + right) / width; + m.m[0][1] = 0.0f; + m.m[1][1] = 2.0f / invheight; + m.m[2][1] = 0.0f; + m.m[3][1] = -(top + bottom) / invheight; + m.m[0][2] = 0.0f; + m.m[1][2] = 0.0f; + m.m[2][2] = -2.0f / clip; + m.m[3][2] = -(nearPlane + farPlane) / clip; + m.m[0][3] = 0.0f; + m.m[1][3] = 0.0f; + m.m[2][3] = 0.0f; + m.m[3][3] = 1.0f; // Apply the projection. *this *= m; @@ -1189,22 +1188,22 @@ QMatrix4x4& QMatrix4x4::frustum(qreal left, qreal right, qreal bottom, qreal top qreal width = right - left; qreal invheight = top - bottom; qreal clip = farPlane - nearPlane; - m.m[0][0] = qf2vt_round(2.0f * nearPlane / width); - m.m[1][0] = qf2vt_round(0.0f); - m.m[2][0] = qf2vt_round((left + right) / width); - m.m[3][0] = qf2vt_round(0.0f); - m.m[0][1] = qf2vt_round(0.0f); - m.m[1][1] = qf2vt_round(2.0f * nearPlane / invheight); - m.m[2][1] = qf2vt_round((top + bottom) / invheight); - m.m[3][1] = qf2vt_round(0.0f); - m.m[0][2] = qf2vt_round(0.0f); - m.m[1][2] = qf2vt_round(0.0f); - m.m[2][2] = qf2vt_round(-(nearPlane + farPlane) / clip); - m.m[3][2] = qf2vt_round(-(2.0f * nearPlane * farPlane) / clip); - m.m[0][3] = qf2vt_round(0.0f); - m.m[1][3] = qf2vt_round(0.0f); - m.m[2][3] = qf2vt_round(-1.0f); - m.m[3][3] = qf2vt_round(0.0f); + m.m[0][0] = 2.0f * nearPlane / width; + m.m[1][0] = 0.0f; + m.m[2][0] = (left + right) / width; + m.m[3][0] = 0.0f; + m.m[0][1] = 0.0f; + m.m[1][1] = 2.0f * nearPlane / invheight; + m.m[2][1] = (top + bottom) / invheight; + m.m[3][1] = 0.0f; + m.m[0][2] = 0.0f; + m.m[1][2] = 0.0f; + m.m[2][2] = -(nearPlane + farPlane) / clip; + m.m[3][2] = -2.0f * nearPlane * farPlane / clip; + m.m[0][3] = 0.0f; + m.m[1][3] = 0.0f; + m.m[2][3] = -1.0f; + m.m[3][3] = 0.0f; // Apply the projection. *this *= m; @@ -1234,22 +1233,22 @@ QMatrix4x4& QMatrix4x4::perspective(qreal angle, qreal aspect, qreal nearPlane, return *this; qreal cotan = qCos(radians) / sine; qreal clip = farPlane - nearPlane; - m.m[0][0] = qf2vt_round(cotan / aspect); - m.m[1][0] = qf2vt_round(0.0f); - m.m[2][0] = qf2vt_round(0.0f); - m.m[3][0] = qf2vt_round(0.0f); - m.m[0][1] = qf2vt_round(0.0f); - m.m[1][1] = qf2vt_round(cotan); - m.m[2][1] = qf2vt_round(0.0f); - m.m[3][1] = qf2vt_round(0.0f); - m.m[0][2] = qf2vt_round(0.0f); - m.m[1][2] = qf2vt_round(0.0f); - m.m[2][2] = qf2vt_round(-(nearPlane + farPlane) / clip); - m.m[3][2] = qf2vt_round(-(2.0f * nearPlane * farPlane) / clip); - m.m[0][3] = qf2vt_round(0.0f); - m.m[1][3] = qf2vt_round(0.0f); - m.m[2][3] = qf2vt_round(-1.0f); - m.m[3][3] = qf2vt_round(0.0f); + m.m[0][0] = cotan / aspect; + m.m[1][0] = 0.0f; + m.m[2][0] = 0.0f; + m.m[3][0] = 0.0f; + m.m[0][1] = 0.0f; + m.m[1][1] = cotan; + m.m[2][1] = 0.0f; + m.m[3][1] = 0.0f; + m.m[0][2] = 0.0f; + m.m[1][2] = 0.0f; + m.m[2][2] = -(nearPlane + farPlane) / clip; + m.m[3][2] = -(2.0f * nearPlane * farPlane) / clip; + m.m[0][3] = 0.0f; + m.m[1][3] = 0.0f; + m.m[2][3] = -1.0f; + m.m[3][3] = 0.0f; // Apply the projection. *this *= m; @@ -1339,7 +1338,7 @@ void QMatrix4x4::toValueArray(qreal *values) const { for (int row = 0; row < 4; ++row) for (int col = 0; col < 4; ++col) - values[row * 4 + col] = qt_math3d_convert(m[col][row]); + values[row * 4 + col] = qreal(m[col][row]); } /*! @@ -1351,12 +1350,9 @@ void QMatrix4x4::toValueArray(qreal *values) const */ QMatrix QMatrix4x4::toAffine() const { - return QMatrix(qt_math3d_convert(m[0][0]), - qt_math3d_convert(m[0][1]), - qt_math3d_convert(m[1][0]), - qt_math3d_convert(m[1][1]), - qt_math3d_convert(m[3][0]), - qt_math3d_convert(m[3][1])); + return QMatrix(qreal(m[0][0]), qreal(m[0][1]), + qreal(m[1][0]), qreal(m[1][1]), + qreal(m[3][0]), qreal(m[3][1])); } /*! @@ -1368,15 +1364,9 @@ QMatrix QMatrix4x4::toAffine() const */ QTransform QMatrix4x4::toTransform() const { - return QTransform(qt_math3d_convert(m[0][0]), - qt_math3d_convert(m[0][1]), - qt_math3d_convert(m[0][3]), - qt_math3d_convert(m[1][0]), - qt_math3d_convert(m[1][1]), - qt_math3d_convert(m[1][3]), - qt_math3d_convert(m[3][0]), - qt_math3d_convert(m[3][1]), - qt_math3d_convert(m[3][3])); + return QTransform(qreal(m[0][0]), qreal(m[0][1]), qreal(m[0][3]), + qreal(m[1][0]), qreal(m[1][1]), qreal(m[1][3]), + qreal(m[3][0]), qreal(m[3][1]), qreal(m[3][3])); } /*! @@ -1442,7 +1432,7 @@ QTransform QMatrix4x4::toTransform() const */ /*! - \fn qrealinner *QMatrix4x4::data() + \fn float *QMatrix4x4::data() Returns a pointer to the raw data of this matrix. This is indended for use with raw GL functions. @@ -1451,7 +1441,7 @@ QTransform QMatrix4x4::toTransform() const */ /*! - \fn const qrealinner *QMatrix4x4::data() const + \fn const float *QMatrix4x4::data() const Returns a constant pointer to the raw data of this matrix. This is indended for use with raw GL functions. @@ -1460,7 +1450,7 @@ QTransform QMatrix4x4::toTransform() const */ /*! - \fn const qrealinner *QMatrix4x4::constData() const + \fn const float *QMatrix4x4::constData() const Returns a constant pointer to the raw data of this matrix. This is indended for use with raw GL functions. @@ -1519,8 +1509,8 @@ void QMatrix4x4::extractAxisRotation(qreal &angle, QVector3D &axis) const { // Orientation is dependent on the upper 3x3 matrix; subtract the // homogeneous scaling element from the trace of the 4x4 matrix - qrealinner tr = m[0][0] + m[1][1] + m[2][2]; - qreal cosa = qt_math3d_convert(0.5f * (tr - 1.0f)); + float tr = m[0][0] + m[1][1] + m[2][2]; + qreal cosa = qreal(0.5f * (tr - 1.0f)); angle = acos(cosa) * 180.0f / M_PI; // Any axis will work if r is zero (means no rotation) @@ -1540,11 +1530,11 @@ void QMatrix4x4::extractAxisRotation(qreal &angle, QVector3D &axis) const } // rads == PI - qrealinner tmp; + float tmp; // r00 is maximum if ((m[0][0] >= m[2][2]) && (m[0][0] >= m[1][1])) { - axis.xp = 0.5f * qvtsqrt(m[0][0] - m[1][1] - m[2][2] + 1.0f); + axis.xp = 0.5f * qSqrt(m[0][0] - m[1][1] - m[2][2] + 1.0f); tmp = 0.5f / axis.x(); axis.yp = m[1][0] * tmp; axis.zp = m[2][0] * tmp; @@ -1552,7 +1542,7 @@ void QMatrix4x4::extractAxisRotation(qreal &angle, QVector3D &axis) const // r11 is maximum if ((m[1][1] >= m[2][2]) && (m[1][1] >= m[0][0])) { - axis.yp = 0.5f * qvtsqrt(m[1][1] - m[0][0] - m[2][2] + 1.0f); + axis.yp = 0.5f * qSqrt(m[1][1] - m[0][0] - m[2][2] + 1.0f); tmp = 0.5f / axis.y(); axis.xp = tmp * m[1][0]; axis.zp = tmp * m[2][1]; @@ -1560,7 +1550,7 @@ void QMatrix4x4::extractAxisRotation(qreal &angle, QVector3D &axis) const // r22 is maximum if ((m[2][2] >= m[1][1]) && (m[2][2] >= m[0][0])) { - axis.zp = 0.5f * qvtsqrt(m[2][2] - m[0][0] - m[1][1] + 1.0f); + axis.zp = 0.5f * qSqrt(m[2][2] - m[0][0] - m[1][1] + 1.0f); tmp = 0.5f / axis.z(); axis.xp = m[2][0]*tmp; axis.yp = m[2][1]*tmp; diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h index 6428b20..2b485c1 100644 --- a/src/gui/math3d/qmatrix4x4.h +++ b/src/gui/math3d/qmatrix4x4.h @@ -70,14 +70,14 @@ public: qreal m41, qreal m42, qreal m43, qreal m44); #if !defined(QT_NO_MEMBER_TEMPLATES) || defined(Q_QDOC) template - explicit QMatrix4x4(const QGenericMatrix& matrix); + explicit QMatrix4x4(const QGenericMatrix& matrix); #endif - QMatrix4x4(const qrealinner *values, int cols, int rows); + QMatrix4x4(const float *values, int cols, int rows); QMatrix4x4(const QTransform& transform); QMatrix4x4(const QMatrix& matrix); inline qreal operator()(int row, int column) const; - inline qrealinner& operator()(int row, int column); + inline float& operator()(int row, int column); inline QVector4D column(int index) const; inline void setColumn(int index, const QVector4D& value); @@ -171,12 +171,12 @@ public: #if !defined(QT_NO_MEMBER_TEMPLATES) || defined(Q_QDOC) template - QGenericMatrix toGenericMatrix() const; + QGenericMatrix toGenericMatrix() const; #endif - inline qrealinner *data(); - inline const qrealinner *data() const { return m[0]; } - inline const qrealinner *constData() const { return m[0]; } + inline float *data(); + inline const float *data() const { return m[0]; } + inline const float *constData() const { return m[0]; } void inferSpecialType(); @@ -185,7 +185,7 @@ public: #endif private: - qrealinner m[4][4]; // Column-major order to match OpenGL. + float m[4][4]; // Column-major order to match OpenGL. int flagBits; // Flag bits from the enum below. enum { @@ -219,9 +219,9 @@ inline QMatrix4x4::QMatrix4x4 template Q_INLINE_TEMPLATE QMatrix4x4::QMatrix4x4 - (const QGenericMatrix& matrix) + (const QGenericMatrix& matrix) { - const qrealinner *values = matrix.constData(); + const float *values = matrix.constData(); for (int col = 0; col < 4; ++col) { for (int row = 0; row < 4; ++row) { if (col < N && row < M) @@ -236,10 +236,10 @@ Q_INLINE_TEMPLATE QMatrix4x4::QMatrix4x4 } template -QGenericMatrix QMatrix4x4::toGenericMatrix() const +QGenericMatrix QMatrix4x4::toGenericMatrix() const { - QGenericMatrix result; - qrealinner *values = result.data(); + QGenericMatrix result; + float *values = result.data(); for (int col = 0; col < N; ++col) { for (int row = 0; row < M; ++row) { if (col < 4 && row < 4) @@ -258,10 +258,10 @@ QGenericMatrix QMatrix4x4::toGenericMatrix() const inline qreal QMatrix4x4::operator()(int row, int column) const { Q_ASSERT(row >= 0 && row < 4 && column >= 0 && column < 4); - return qt_math3d_convert(m[column][row]); + return qreal(m[column][row]); } -inline qrealinner& QMatrix4x4::operator()(int row, int column) +inline float& QMatrix4x4::operator()(int row, int column) { Q_ASSERT(row >= 0 && row < 4 && column >= 0 && column < 4); flagBits = General; @@ -420,23 +420,22 @@ inline QMatrix4x4& QMatrix4x4::operator*=(const QMatrix4x4& other) inline QMatrix4x4& QMatrix4x4::operator*=(qreal factor) { - qrealinner f(factor); - m[0][0] *= f; - m[0][1] *= f; - m[0][2] *= f; - m[0][3] *= f; - m[1][0] *= f; - m[1][1] *= f; - m[1][2] *= f; - m[1][3] *= f; - m[2][0] *= f; - m[2][1] *= f; - m[2][2] *= f; - m[2][3] *= f; - m[3][0] *= f; - m[3][1] *= f; - m[3][2] *= f; - m[3][3] *= f; + m[0][0] *= factor; + m[0][1] *= factor; + m[0][2] *= factor; + m[0][3] *= factor; + m[1][0] *= factor; + m[1][1] *= factor; + m[1][2] *= factor; + m[1][3] *= factor; + m[2][0] *= factor; + m[2][1] *= factor; + m[2][2] *= factor; + m[2][3] *= factor; + m[3][0] *= factor; + m[3][1] *= factor; + m[3][2] *= factor; + m[3][3] *= factor; flagBits = General; return *this; } @@ -604,7 +603,7 @@ inline QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2) inline QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix) { - qrealinner x, y, z, w; + float x, y, z, w; x = vector.xp * matrix.m[0][0] + vector.yp * matrix.m[0][1] + vector.zp * matrix.m[0][2] + @@ -629,7 +628,7 @@ inline QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix) inline QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector) { - qrealinner x, y, z, w; + float x, y, z, w; x = vector.xp * matrix.m[0][0] + vector.yp * matrix.m[1][0] + vector.zp * matrix.m[2][0] + @@ -658,7 +657,7 @@ inline QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector) inline QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix) { - qrealinner x, y, z, w; + float x, y, z, w; x = vector.xp * matrix.m[0][0] + vector.yp * matrix.m[0][1] + vector.zp * matrix.m[0][2] + @@ -680,7 +679,7 @@ inline QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix) inline QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector) { - qrealinner x, y, z, w; + float x, y, z, w; x = vector.xp * matrix.m[0][0] + vector.yp * matrix.m[1][0] + vector.zp * matrix.m[2][0] + @@ -704,8 +703,8 @@ inline QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector) inline QPoint operator*(const QPoint& point, const QMatrix4x4& matrix) { - qrealinner xin, yin; - qrealinner x, y, w; + float xin, yin; + float x, y, w; xin = point.x(); yin = point.y(); x = xin * matrix.m[0][0] + @@ -725,8 +724,8 @@ inline QPoint operator*(const QPoint& point, const QMatrix4x4& matrix) inline QPointF operator*(const QPointF& point, const QMatrix4x4& matrix) { - qrealinner xin, yin; - qrealinner x, y, w; + float xin, yin; + float x, y, w; xin = point.x(); yin = point.y(); x = xin * matrix.m[0][0] + @@ -739,18 +738,16 @@ inline QPointF operator*(const QPointF& point, const QMatrix4x4& matrix) yin * matrix.m[3][1] + matrix.m[3][3]; if (w == 1.0f) { - return QPointF(qt_math3d_convert(x), - qt_math3d_convert(y)); + return QPointF(qreal(x), qreal(y)); } else { - return QPointF(qt_math3d_convert(x / w), - qt_math3d_convert(y / w)); + return QPointF(qreal(x / w), qreal(y / w)); } } inline QPoint operator*(const QMatrix4x4& matrix, const QPoint& point) { - qrealinner xin, yin; - qrealinner x, y, w; + float xin, yin; + float x, y, w; xin = point.x(); yin = point.y(); x = xin * matrix.m[0][0] + @@ -770,8 +767,8 @@ inline QPoint operator*(const QMatrix4x4& matrix, const QPoint& point) inline QPointF operator*(const QMatrix4x4& matrix, const QPointF& point) { - qrealinner xin, yin; - qrealinner x, y, w; + float xin, yin; + float x, y, w; xin = point.x(); yin = point.y(); x = xin * matrix.m[0][0] + @@ -784,11 +781,9 @@ inline QPointF operator*(const QMatrix4x4& matrix, const QPointF& point) yin * matrix.m[1][3] + matrix.m[3][3]; if (w == 1.0f) { - return QPointF(qt_math3d_convert(x), - qt_math3d_convert(y)); + return QPointF(qreal(x), qreal(y)); } else { - return QPointF(qt_math3d_convert(x / w), - qt_math3d_convert(y / w)); + return QPointF(qreal(x / w), qreal(y / w)); } } @@ -817,46 +812,44 @@ inline QMatrix4x4 operator-(const QMatrix4x4& matrix) inline QMatrix4x4 operator*(qreal factor, const QMatrix4x4& matrix) { QMatrix4x4 m(1); - qrealinner f(factor); - m.m[0][0] = matrix.m[0][0] * f; - m.m[0][1] = matrix.m[0][1] * f; - m.m[0][2] = matrix.m[0][2] * f; - m.m[0][3] = matrix.m[0][3] * f; - m.m[1][0] = matrix.m[1][0] * f; - m.m[1][1] = matrix.m[1][1] * f; - m.m[1][2] = matrix.m[1][2] * f; - m.m[1][3] = matrix.m[1][3] * f; - m.m[2][0] = matrix.m[2][0] * f; - m.m[2][1] = matrix.m[2][1] * f; - m.m[2][2] = matrix.m[2][2] * f; - m.m[2][3] = matrix.m[2][3] * f; - m.m[3][0] = matrix.m[3][0] * f; - m.m[3][1] = matrix.m[3][1] * f; - m.m[3][2] = matrix.m[3][2] * f; - m.m[3][3] = matrix.m[3][3] * f; + m.m[0][0] = matrix.m[0][0] * factor; + m.m[0][1] = matrix.m[0][1] * factor; + m.m[0][2] = matrix.m[0][2] * factor; + m.m[0][3] = matrix.m[0][3] * factor; + m.m[1][0] = matrix.m[1][0] * factor; + m.m[1][1] = matrix.m[1][1] * factor; + m.m[1][2] = matrix.m[1][2] * factor; + m.m[1][3] = matrix.m[1][3] * factor; + m.m[2][0] = matrix.m[2][0] * factor; + m.m[2][1] = matrix.m[2][1] * factor; + m.m[2][2] = matrix.m[2][2] * factor; + m.m[2][3] = matrix.m[2][3] * factor; + m.m[3][0] = matrix.m[3][0] * factor; + m.m[3][1] = matrix.m[3][1] * factor; + m.m[3][2] = matrix.m[3][2] * factor; + m.m[3][3] = matrix.m[3][3] * factor; return m; } inline QMatrix4x4 operator*(const QMatrix4x4& matrix, qreal factor) { QMatrix4x4 m(1); - qrealinner f(factor); - m.m[0][0] = matrix.m[0][0] * f; - m.m[0][1] = matrix.m[0][1] * f; - m.m[0][2] = matrix.m[0][2] * f; - m.m[0][3] = matrix.m[0][3] * f; - m.m[1][0] = matrix.m[1][0] * f; - m.m[1][1] = matrix.m[1][1] * f; - m.m[1][2] = matrix.m[1][2] * f; - m.m[1][3] = matrix.m[1][3] * f; - m.m[2][0] = matrix.m[2][0] * f; - m.m[2][1] = matrix.m[2][1] * f; - m.m[2][2] = matrix.m[2][2] * f; - m.m[2][3] = matrix.m[2][3] * f; - m.m[3][0] = matrix.m[3][0] * f; - m.m[3][1] = matrix.m[3][1] * f; - m.m[3][2] = matrix.m[3][2] * f; - m.m[3][3] = matrix.m[3][3] * f; + m.m[0][0] = matrix.m[0][0] * factor; + m.m[0][1] = matrix.m[0][1] * factor; + m.m[0][2] = matrix.m[0][2] * factor; + m.m[0][3] = matrix.m[0][3] * factor; + m.m[1][0] = matrix.m[1][0] * factor; + m.m[1][1] = matrix.m[1][1] * factor; + m.m[1][2] = matrix.m[1][2] * factor; + m.m[1][3] = matrix.m[1][3] * factor; + m.m[2][0] = matrix.m[2][0] * factor; + m.m[2][1] = matrix.m[2][1] * factor; + m.m[2][2] = matrix.m[2][2] * factor; + m.m[2][3] = matrix.m[2][3] * factor; + m.m[3][0] = matrix.m[3][0] * factor; + m.m[3][1] = matrix.m[3][1] * factor; + m.m[3][2] = matrix.m[3][2] * factor; + m.m[3][3] = matrix.m[3][3] * factor; return m; } @@ -934,7 +927,7 @@ inline QRectF QMatrix4x4::mapRect(const QRectF& rect) const return QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax)); } -inline qrealinner *QMatrix4x4::data() +inline float *QMatrix4x4::data() { // We have to assume that the caller will modify the matrix elements, // so we flip it over to "General" mode. @@ -947,17 +940,17 @@ Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QMatrix4x4 &m); #endif template -QMatrix4x4 qGenericMatrixToMatrix4x4(const QGenericMatrix& matrix) +QMatrix4x4 qGenericMatrixToMatrix4x4(const QGenericMatrix& matrix) { return QMatrix4x4(matrix.constData(), N, M); } template -QGenericMatrix qGenericMatrixFromMatrix4x4(const QMatrix4x4& matrix) +QGenericMatrix qGenericMatrixFromMatrix4x4(const QMatrix4x4& matrix) { - QGenericMatrix result; - const qrealinner *m = matrix.constData(); - qrealinner *values = result.data(); + QGenericMatrix result; + const float *m = matrix.constData(); + float *values = result.data(); for (int col = 0; col < N; ++col) { for (int row = 0; row < M; ++row) { if (col < 4 && row < 4) diff --git a/src/gui/math3d/qquaternion.cpp b/src/gui/math3d/qquaternion.cpp index 121ff51..efde362 100644 --- a/src/gui/math3d/qquaternion.cpp +++ b/src/gui/math3d/qquaternion.cpp @@ -40,8 +40,8 @@ ****************************************************************************/ #include "qquaternion.h" -#include "qmath3dutil_p.h" #include +#include QT_BEGIN_NAMESPACE @@ -223,8 +223,7 @@ QT_BEGIN_NAMESPACE */ qreal QQuaternion::length() const { - return qvtsqrt64(qvtmul64(xp, xp) + qvtmul64(yp, yp) + - qvtmul64(zp, zp) + qvtmul64(wp, wp)); + return qSqrt(xp * xp + yp * yp + zp * zp + wp * wp); } /*! @@ -234,8 +233,7 @@ qreal QQuaternion::length() const */ qreal QQuaternion::lengthSquared() const { - return qvtdot64(qvtmul64(xp, xp) + qvtmul64(yp, yp) + - qvtmul64(zp, zp) + qvtmul64(wp, wp)); + return xp * xp + yp * yp + zp * zp + wp * wp; } /*! @@ -342,6 +340,10 @@ QVector3D QQuaternion::rotateVector(const QVector3D& vector) const \sa operator*=() */ +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + #ifndef QT_NO_VECTOR3D /*! @@ -354,9 +356,10 @@ QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D& axis, qreal angle) // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q56 // We normalize the result just in case the values are close // to zero, as suggested in the above FAQ. - qrealinner s, c; + qreal a = (angle / 2.0f) * M_PI / 180.0f; + qreal s = qSin(a); + qreal c = qCos(a); QVector3D ax = axis.normalized(); - qt_math3d_sincos(angle / 2.0f, &s, &c); return QQuaternion(c, ax.xp * s, ax.yp * s, ax.zp * s, 1).normalized(); } @@ -369,17 +372,18 @@ QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D& axis, qreal angle) QQuaternion QQuaternion::fromAxisAndAngle (qreal x, qreal y, qreal z, qreal angle) { - qrealinner xp = x; - qrealinner yp = y; - qrealinner zp = z; - qrealinner s, c; - qreal length = qvtsqrt(xp * xp + yp * yp + zp * zp); + float xp = x; + float yp = y; + float zp = z; + qreal length = qSqrt(xp * xp + yp * yp + zp * zp); if (!qIsNull(length)) { xp /= length; yp /= length; zp /= length; } - qt_math3d_sincos(angle / 2.0f, &s, &c); + qreal a = (angle / 2.0f) * M_PI / 180.0f; + qreal s = qSin(a); + qreal c = qCos(a); return QQuaternion(c, xp * s, yp * s, zp * s, 1).normalized(); } @@ -500,8 +504,7 @@ QQuaternion QQuaternion::interpolate // Determine the angle between the two quaternions. QQuaternion q2b; qreal dot; - dot = qvtdot64(qvtmul64(q1.xp, q2.xp) + qvtmul64(q1.yp, q2.yp) + - qvtmul64(q1.zp, q2.zp) + qvtmul64(q1.wp, q2.wp)); + dot = q1.xp * q2.xp + q1.yp * q2.yp + q1.zp * q2.zp + q1.wp * q2.wp; if (dot >= 0.0f) { q2b = q2; } else { diff --git a/src/gui/math3d/qquaternion.h b/src/gui/math3d/qquaternion.h index 6ba63ec..f0cb308 100644 --- a/src/gui/math3d/qquaternion.h +++ b/src/gui/math3d/qquaternion.h @@ -129,11 +129,11 @@ public: (const QQuaternion& q1, const QQuaternion& q2, qreal t); private: - qrealinner wp, xp, yp, zp; + float wp, xp, yp, zp; friend class QMatrix4x4; - QQuaternion(qrealinner scalar, qrealinner xpos, qrealinner ypos, qrealinner zpos, int dummy); + QQuaternion(float scalar, float xpos, float ypos, float zpos, int dummy); }; inline QQuaternion::QQuaternion() : wp(1.0f), xp(0.0f), yp(0.0f), zp(0.0f) {} @@ -141,7 +141,7 @@ inline QQuaternion::QQuaternion() : wp(1.0f), xp(0.0f), yp(0.0f), zp(0.0f) {} inline QQuaternion::QQuaternion(qreal scalar, qreal xpos, qreal ypos, qreal zpos) : wp(scalar), xp(xpos), yp(ypos), zp(zpos) {} -inline QQuaternion::QQuaternion(qrealinner scalar, qrealinner xpos, qrealinner ypos, qrealinner zpos, int) : wp(scalar), xp(xpos), yp(ypos), zp(zpos) {} +inline QQuaternion::QQuaternion(float scalar, float xpos, float ypos, float zpos, int) : wp(scalar), xp(xpos), yp(ypos), zp(zpos) {} inline QQuaternion::QQuaternion(int scalar, int xpos, int ypos, int zpos) : wp(scalar), xp(xpos), yp(ypos), zp(zpos) {} @@ -155,10 +155,10 @@ inline bool QQuaternion::isIdentity() const return qIsNull(xp) && qIsNull(yp) && qIsNull(zp) && wp == 1.0f; } -inline qreal QQuaternion::x() const { return qt_math3d_convert(xp); } -inline qreal QQuaternion::y() const { return qt_math3d_convert(yp); } -inline qreal QQuaternion::z() const { return qt_math3d_convert(zp); } -inline qreal QQuaternion::scalar() const { return qt_math3d_convert(wp); } +inline qreal QQuaternion::x() const { return qreal(xp); } +inline qreal QQuaternion::y() const { return qreal(yp); } +inline qreal QQuaternion::z() const { return qreal(zp); } +inline qreal QQuaternion::scalar() const { return qreal(wp); } inline void QQuaternion::setX(qreal x) { xp = x; } inline void QQuaternion::setY(qreal y) { yp = y; } @@ -190,11 +190,10 @@ inline QQuaternion &QQuaternion::operator-=(const QQuaternion &quaternion) inline QQuaternion &QQuaternion::operator*=(qreal factor) { - qrealinner f(factor); - xp *= f; - yp *= f; - zp *= f; - wp *= f; + xp *= factor; + yp *= factor; + zp *= factor; + wp *= factor; return *this; } @@ -202,19 +201,19 @@ inline const QQuaternion operator*(const QQuaternion &q1, const QQuaternion& q2) { // Algorithm from: // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q53 - qrealinner x = q1.wp * q2.xp + + float x = q1.wp * q2.xp + q1.xp * q2.wp + q1.yp * q2.zp - q1.zp * q2.yp; - qrealinner y = q1.wp * q2.yp + + float y = q1.wp * q2.yp + q1.yp * q2.wp + q1.zp * q2.xp - q1.xp * q2.zp; - qrealinner z = q1.wp * q2.zp + + float z = q1.wp * q2.zp + q1.zp * q2.wp + q1.xp * q2.yp - q1.yp * q2.xp; - qrealinner w = q1.wp * q2.wp - + float w = q1.wp * q2.wp - q1.xp * q2.xp - q1.yp * q2.yp - q1.zp * q2.zp; @@ -229,11 +228,10 @@ inline QQuaternion &QQuaternion::operator*=(const QQuaternion &quaternion) inline QQuaternion &QQuaternion::operator/=(qreal divisor) { - qrealinner d(divisor); - xp /= d; - yp /= d; - zp /= d; - wp /= d; + xp /= divisor; + yp /= divisor; + zp /= divisor; + wp /= divisor; return *this; } @@ -259,14 +257,12 @@ inline const QQuaternion operator-(const QQuaternion &q1, const QQuaternion &q2) inline const QQuaternion operator*(qreal factor, const QQuaternion &quaternion) { - qrealinner f(factor); - return QQuaternion(quaternion.wp * f, quaternion.xp * f, quaternion.yp * f, quaternion.zp * f, 1); + return QQuaternion(quaternion.wp * factor, quaternion.xp * factor, quaternion.yp * factor, quaternion.zp * factor, 1); } inline const QQuaternion operator*(const QQuaternion &quaternion, qreal factor) { - qrealinner f(factor); - return QQuaternion(quaternion.wp * f, quaternion.xp * f, quaternion.yp * f, quaternion.zp * f, 1); + return QQuaternion(quaternion.wp * factor, quaternion.xp * factor, quaternion.yp * factor, quaternion.zp * factor, 1); } inline const QQuaternion operator-(const QQuaternion &quaternion) @@ -276,8 +272,7 @@ inline const QQuaternion operator-(const QQuaternion &quaternion) inline const QQuaternion operator/(const QQuaternion &quaternion, qreal divisor) { - qrealinner d(divisor); - return QQuaternion(quaternion.wp / d, quaternion.xp / d, quaternion.yp / d, quaternion.zp / d, 1); + return QQuaternion(quaternion.wp / divisor, quaternion.xp / divisor, quaternion.yp / divisor, quaternion.zp / divisor, 1); } inline bool qFuzzyCompare(const QQuaternion& q1, const QQuaternion& q2) diff --git a/src/gui/math3d/qvector2d.cpp b/src/gui/math3d/qvector2d.cpp index 0426fc5..31e5be6 100644 --- a/src/gui/math3d/qvector2d.cpp +++ b/src/gui/math3d/qvector2d.cpp @@ -42,7 +42,8 @@ #include "qvector2d.h" #include "qvector3d.h" #include "qvector4d.h" -#include "qmath3dutil_p.h" +#include +#include QT_BEGIN_NAMESPACE @@ -169,7 +170,7 @@ QVector2D::QVector2D(const QVector4D& vector) */ qreal QVector2D::length() const { - return qvtsqrt64(qvtmul64(xp, xp) + qvtmul64(yp, yp)); + return qSqrt(xp * xp + yp * yp); } /*! @@ -180,7 +181,7 @@ qreal QVector2D::length() const */ qreal QVector2D::lengthSquared() const { - return qvtdot64(qvtmul64(xp, xp) + qvtmul64(yp, yp)); + return xp * xp + yp * yp; } /*! @@ -263,7 +264,7 @@ void QVector2D::normalize() */ qreal QVector2D::dotProduct(const QVector2D& v1, const QVector2D& v2) { - return qvtdot64(qvtmul64(v1.xp, v2.xp) + qvtmul64(v1.yp, v2.yp)); + return v1.xp * v2.xp + v1.yp * v2.yp; } /*! diff --git a/src/gui/math3d/qvector2d.h b/src/gui/math3d/qvector2d.h index a72ecc5..5e15de6 100644 --- a/src/gui/math3d/qvector2d.h +++ b/src/gui/math3d/qvector2d.h @@ -42,7 +42,6 @@ #ifndef QVECTOR2D_H #define QVECTOR2D_H -#include #include #include @@ -117,18 +116,17 @@ public: QPointF toPointF() const; private: - qrealinner xp, yp; + float xp, yp; - QVector2D(qrealinner xpos, qrealinner ypos, int dummy); + QVector2D(float xpos, float ypos, int dummy); friend class QVector3D; friend class QVector4D; - friend class QVertexArray; }; inline QVector2D::QVector2D() : xp(0.0f), yp(0.0f) {} -inline QVector2D::QVector2D(qrealinner xpos, qrealinner ypos, int) : xp(xpos), yp(ypos) {} +inline QVector2D::QVector2D(float xpos, float ypos, int) : xp(xpos), yp(ypos) {} inline QVector2D::QVector2D(qreal xpos, qreal ypos) : xp(xpos), yp(ypos) {} @@ -143,8 +141,8 @@ inline bool QVector2D::isNull() const return qIsNull(xp) && qIsNull(yp); } -inline qreal QVector2D::x() const { return qt_math3d_convert(xp); } -inline qreal QVector2D::y() const { return qt_math3d_convert(yp); } +inline qreal QVector2D::x() const { return qreal(xp); } +inline qreal QVector2D::y() const { return qreal(yp); } inline void QVector2D::setX(qreal x) { xp = x; } inline void QVector2D::setY(qreal y) { yp = y; } @@ -165,9 +163,8 @@ inline QVector2D &QVector2D::operator-=(const QVector2D &vector) inline QVector2D &QVector2D::operator*=(qreal factor) { - qrealinner f(factor); - xp *= f; - yp *= f; + xp *= factor; + yp *= factor; return *this; } @@ -180,9 +177,8 @@ inline QVector2D &QVector2D::operator*=(const QVector2D &vector) inline QVector2D &QVector2D::operator/=(qreal divisor) { - qrealinner d(divisor); - xp /= d; - yp /= d; + xp /= divisor; + yp /= divisor; return *this; } @@ -208,14 +204,12 @@ inline const QVector2D operator-(const QVector2D &v1, const QVector2D &v2) inline const QVector2D operator*(qreal factor, const QVector2D &vector) { - qrealinner f(factor); - return QVector2D(vector.xp * f, vector.yp * f, 1); + return QVector2D(vector.xp * factor, vector.yp * factor, 1); } inline const QVector2D operator*(const QVector2D &vector, qreal factor) { - qrealinner f(factor); - return QVector2D(vector.xp * f, vector.yp * f, 1); + return QVector2D(vector.xp * factor, vector.yp * factor, 1); } inline const QVector2D operator*(const QVector2D &v1, const QVector2D &v2) @@ -230,8 +224,7 @@ inline const QVector2D operator-(const QVector2D &vector) inline const QVector2D operator/(const QVector2D &vector, qreal divisor) { - qrealinner d(divisor); - return QVector2D(vector.xp / d, vector.yp / d, 1); + return QVector2D(vector.xp / divisor, vector.yp / divisor, 1); } inline bool qFuzzyCompare(const QVector2D& v1, const QVector2D& v2) @@ -246,8 +239,7 @@ inline QPoint QVector2D::toPoint() const inline QPointF QVector2D::toPointF() const { - return QPointF(qt_math3d_convert(xp), - qt_math3d_convert(yp)); + return QPointF(qreal(xp), qreal(yp)); } #ifndef QT_NO_DEBUG_STREAM diff --git a/src/gui/math3d/qvector3d.cpp b/src/gui/math3d/qvector3d.cpp index 32068ee..814753d 100644 --- a/src/gui/math3d/qvector3d.cpp +++ b/src/gui/math3d/qvector3d.cpp @@ -42,8 +42,8 @@ #include "qvector3d.h" #include "qvector2d.h" #include "qvector4d.h" -#include "qmath3dutil_p.h" #include +#include QT_BEGIN_NAMESPACE @@ -287,7 +287,7 @@ void QVector3D::normalize() */ qreal QVector3D::dotProduct(const QVector3D& v1, const QVector3D& v2) { - return qvtdot64(qvtmul64(v1.xp, v2.xp) + qvtmul64(v1.yp, v2.yp) + qvtmul64(v1.zp, v2.zp)); + return v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp; } /*! @@ -535,7 +535,7 @@ QVector4D QVector3D::toVector4D() const */ qreal QVector3D::length() const { - return qvtsqrt64(qvtmul64(xp, xp) + qvtmul64(yp, yp) + qvtmul64(zp, zp)); + return qSqrt(xp * xp + yp * yp + zp * zp); } /*! @@ -546,7 +546,7 @@ qreal QVector3D::length() const */ qreal QVector3D::lengthSquared() const { - return qvtdot64(qvtmul64(xp, xp) + qvtmul64(yp, yp) + qvtmul64(zp, zp)); + return xp * xp + yp * yp + zp * zp; } #ifndef QT_NO_DEBUG_STREAM diff --git a/src/gui/math3d/qvector3d.h b/src/gui/math3d/qvector3d.h index 8f8f3b4..4771d5a 100644 --- a/src/gui/math3d/qvector3d.h +++ b/src/gui/math3d/qvector3d.h @@ -42,7 +42,6 @@ #ifndef QVECTOR3D_H #define QVECTOR3D_H -#include #include #include @@ -130,16 +129,14 @@ public: QPointF toPointF() const; private: - qrealinner xp, yp, zp; + float xp, yp, zp; - QVector3D(qrealinner xpos, qrealinner ypos, qrealinner zpos, int dummy); + QVector3D(float xpos, float ypos, float zpos, int dummy); friend class QVector2D; friend class QVector4D; friend class QQuaternion; friend class QMatrix4x4; - friend class QVertexArray; - friend class QGLPainter; #ifndef QT_NO_MATRIX4X4 friend QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix); friend QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector); @@ -150,7 +147,7 @@ inline QVector3D::QVector3D() : xp(0.0f), yp(0.0f), zp(0.0f) {} inline QVector3D::QVector3D(qreal xpos, qreal ypos, qreal zpos) : xp(xpos), yp(ypos), zp(zpos) {} -inline QVector3D::QVector3D(qrealinner xpos, qrealinner ypos, qrealinner zpos, int) : xp(xpos), yp(ypos), zp(zpos) {} +inline QVector3D::QVector3D(float xpos, float ypos, float zpos, int) : xp(xpos), yp(ypos), zp(zpos) {} inline QVector3D::QVector3D(int xpos, int ypos, int zpos) : xp(xpos), yp(ypos), zp(zpos) {} @@ -163,9 +160,9 @@ inline bool QVector3D::isNull() const return qIsNull(xp) && qIsNull(yp) && qIsNull(zp); } -inline qreal QVector3D::x() const { return qt_math3d_convert(xp); } -inline qreal QVector3D::y() const { return qt_math3d_convert(yp); } -inline qreal QVector3D::z() const { return qt_math3d_convert(zp); } +inline qreal QVector3D::x() const { return qreal(xp); } +inline qreal QVector3D::y() const { return qreal(yp); } +inline qreal QVector3D::z() const { return qreal(zp); } inline void QVector3D::setX(qreal x) { xp = x; } inline void QVector3D::setY(qreal y) { yp = y; } @@ -189,10 +186,9 @@ inline QVector3D &QVector3D::operator-=(const QVector3D &vector) inline QVector3D &QVector3D::operator*=(qreal factor) { - qrealinner f(factor); - xp *= f; - yp *= f; - zp *= f; + xp *= factor; + yp *= factor; + zp *= factor; return *this; } @@ -206,10 +202,9 @@ inline QVector3D &QVector3D::operator*=(const QVector3D& vector) inline QVector3D &QVector3D::operator/=(qreal divisor) { - qrealinner d(divisor); - xp /= d; - yp /= d; - zp /= d; + xp /= divisor; + yp /= divisor; + zp /= divisor; return *this; } @@ -235,14 +230,12 @@ inline const QVector3D operator-(const QVector3D &v1, const QVector3D &v2) inline const QVector3D operator*(qreal factor, const QVector3D &vector) { - qrealinner f(factor); - return QVector3D(vector.xp * f, vector.yp * f, vector.zp * f, 1); + return QVector3D(vector.xp * factor, vector.yp * factor, vector.zp * factor, 1); } inline const QVector3D operator*(const QVector3D &vector, qreal factor) { - qrealinner f(factor); - return QVector3D(vector.xp * f, vector.yp * f, vector.zp * f, 1); + return QVector3D(vector.xp * factor, vector.yp * factor, vector.zp * factor, 1); } inline const QVector3D operator*(const QVector3D &v1, const QVector3D& v2) @@ -257,8 +250,7 @@ inline const QVector3D operator-(const QVector3D &vector) inline const QVector3D operator/(const QVector3D &vector, qreal divisor) { - qrealinner d(divisor); - return QVector3D(vector.xp / d, vector.yp / d, vector.zp / d, 1); + return QVector3D(vector.xp / divisor, vector.yp / divisor, vector.zp / divisor, 1); } inline bool qFuzzyCompare(const QVector3D& v1, const QVector3D& v2) @@ -275,8 +267,7 @@ inline QPoint QVector3D::toPoint() const inline QPointF QVector3D::toPointF() const { - return QPointF(qt_math3d_convert(xp), - qt_math3d_convert(yp)); + return QPointF(qreal(xp), qreal(yp)); } #ifndef QT_NO_DEBUG_STREAM diff --git a/src/gui/math3d/qvector4d.cpp b/src/gui/math3d/qvector4d.cpp index 4287806..d19665a 100644 --- a/src/gui/math3d/qvector4d.cpp +++ b/src/gui/math3d/qvector4d.cpp @@ -42,7 +42,8 @@ #include "qvector4d.h" #include "qvector3d.h" #include "qvector2d.h" -#include "qmath3dutil_p.h" +#include +#include QT_BEGIN_NAMESPACE @@ -237,8 +238,7 @@ QVector4D::QVector4D(const QVector3D& vector, qreal wpos) */ qreal QVector4D::length() const { - return qvtsqrt64(qvtmul64(xp, xp) + qvtmul64(yp, yp) + - qvtmul64(zp, zp) + qvtmul64(wp, wp)); + return qSqrt(xp * xp + yp * yp + zp * zp + wp * wp); } /*! @@ -249,8 +249,7 @@ qreal QVector4D::length() const */ qreal QVector4D::lengthSquared() const { - return qvtdot64(qvtmul64(xp, xp) + qvtmul64(yp, yp) + - qvtmul64(zp, zp) + qvtmul64(wp, wp)); + return xp * xp + yp * yp + zp * zp + wp * wp; } /*! @@ -336,8 +335,7 @@ void QVector4D::normalize() */ qreal QVector4D::dotProduct(const QVector4D& v1, const QVector4D& v2) { - return qvtdot64(qvtmul64(v1.xp, v2.xp) + qvtmul64(v1.yp, v2.yp) + - qvtmul64(v1.zp, v2.zp) + qvtmul64(v1.wp, v2.wp)); + return v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp + v1.wp * v2.wp; } /*! diff --git a/src/gui/math3d/qvector4d.h b/src/gui/math3d/qvector4d.h index 4ac6ae8..12efc95 100644 --- a/src/gui/math3d/qvector4d.h +++ b/src/gui/math3d/qvector4d.h @@ -42,7 +42,6 @@ #ifndef QVECTOR4D_H #define QVECTOR4D_H -#include #include #include @@ -127,15 +126,14 @@ public: QPointF toPointF() const; private: - qrealinner xp, yp, zp, wp; + float xp, yp, zp, wp; - QVector4D(qrealinner xpos, qrealinner ypos, qrealinner zpos, qrealinner wpos, int dummy); + QVector4D(float xpos, float ypos, float zpos, float wpos, int dummy); friend class QVector2D; friend class QVector3D; friend class QQuaternion; friend class QMatrix4x4; - friend class QVertexArray; #ifndef QT_NO_MATRIX4X4 friend QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix); friend QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector); @@ -146,7 +144,7 @@ inline QVector4D::QVector4D() : xp(0.0f), yp(0.0f), zp(0.0f), wp(0.0f) {} inline QVector4D::QVector4D(qreal xpos, qreal ypos, qreal zpos, qreal wpos) : xp(xpos), yp(ypos), zp(zpos), wp(wpos) {} -inline QVector4D::QVector4D(qrealinner xpos, qrealinner ypos, qrealinner zpos, qrealinner wpos, int) : xp(xpos), yp(ypos), zp(zpos), wp(wpos) {} +inline QVector4D::QVector4D(float xpos, float ypos, float zpos, float wpos, int) : xp(xpos), yp(ypos), zp(zpos), wp(wpos) {} inline QVector4D::QVector4D(int xpos, int ypos, int zpos, int wpos) : xp(xpos), yp(ypos), zp(zpos), wp(wpos) {} @@ -159,10 +157,10 @@ inline bool QVector4D::isNull() const return qIsNull(xp) && qIsNull(yp) && qIsNull(zp) && qIsNull(wp); } -inline qreal QVector4D::x() const { return qt_math3d_convert(xp); } -inline qreal QVector4D::y() const { return qt_math3d_convert(yp); } -inline qreal QVector4D::z() const { return qt_math3d_convert(zp); } -inline qreal QVector4D::w() const { return qt_math3d_convert(wp); } +inline qreal QVector4D::x() const { return qreal(xp); } +inline qreal QVector4D::y() const { return qreal(yp); } +inline qreal QVector4D::z() const { return qreal(zp); } +inline qreal QVector4D::w() const { return qreal(wp); } inline void QVector4D::setX(qreal x) { xp = x; } inline void QVector4D::setY(qreal y) { yp = y; } @@ -189,11 +187,10 @@ inline QVector4D &QVector4D::operator-=(const QVector4D &vector) inline QVector4D &QVector4D::operator*=(qreal factor) { - qrealinner f(factor); - xp *= f; - yp *= f; - zp *= f; - wp *= f; + xp *= factor; + yp *= factor; + zp *= factor; + wp *= factor; return *this; } @@ -208,11 +205,10 @@ inline QVector4D &QVector4D::operator*=(const QVector4D &vector) inline QVector4D &QVector4D::operator/=(qreal divisor) { - qrealinner d(divisor); - xp /= d; - yp /= d; - zp /= d; - wp /= d; + xp /= divisor; + yp /= divisor; + zp /= divisor; + wp /= divisor; return *this; } @@ -238,14 +234,12 @@ inline const QVector4D operator-(const QVector4D &v1, const QVector4D &v2) inline const QVector4D operator*(qreal factor, const QVector4D &vector) { - qrealinner f(factor); - return QVector4D(vector.xp * f, vector.yp * f, vector.zp * f, vector.wp * f, 1); + return QVector4D(vector.xp * factor, vector.yp * factor, vector.zp * factor, vector.wp * factor, 1); } inline const QVector4D operator*(const QVector4D &vector, qreal factor) { - qrealinner f(factor); - return QVector4D(vector.xp * f, vector.yp * f, vector.zp * f, vector.wp * f, 1); + return QVector4D(vector.xp * factor, vector.yp * factor, vector.zp * factor, vector.wp * factor, 1); } inline const QVector4D operator*(const QVector4D &v1, const QVector4D& v2) @@ -260,8 +254,7 @@ inline const QVector4D operator-(const QVector4D &vector) inline const QVector4D operator/(const QVector4D &vector, qreal divisor) { - qrealinner d(divisor); - return QVector4D(vector.xp / d, vector.yp / d, vector.zp / d, vector.wp / d, 1); + return QVector4D(vector.xp / divisor, vector.yp / divisor, vector.zp / divisor, vector.wp / divisor, 1); } inline bool qFuzzyCompare(const QVector4D& v1, const QVector4D& v2) @@ -279,8 +272,7 @@ inline QPoint QVector4D::toPoint() const inline QPointF QVector4D::toPointF() const { - return QPointF(qt_math3d_convert(xp), - qt_math3d_convert(yp)); + return QPointF(qreal(xp), qreal(yp)); } #ifndef QT_NO_DEBUG_STREAM diff --git a/tests/auto/math3d/math3d.pro b/tests/auto/math3d/math3d.pro index 3977e92..d6189ef 100644 --- a/tests/auto/math3d/math3d.pro +++ b/tests/auto/math3d/math3d.pro @@ -1,3 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = qfixedpt qmatrixnxn qquaternion qvectornd -SUBDIRS += qmatrixnxn_fixed qquaternion_fixed qvectornd_fixed +SUBDIRS = qmatrixnxn qquaternion qvectornd diff --git a/tests/auto/math3d/qfixedpt/qfixedpt.pro b/tests/auto/math3d/qfixedpt/qfixedpt.pro deleted file mode 100644 index 94598b5..0000000 --- a/tests/auto/math3d/qfixedpt/qfixedpt.pro +++ /dev/null @@ -1,2 +0,0 @@ -load(qttest_p4) -SOURCES += tst_qfixedpt.cpp diff --git a/tests/auto/math3d/qfixedpt/tst_qfixedpt.cpp b/tests/auto/math3d/qfixedpt/tst_qfixedpt.cpp deleted file mode 100644 index ef333a6..0000000 --- a/tests/auto/math3d/qfixedpt/tst_qfixedpt.cpp +++ /dev/null @@ -1,643 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include - -class tst_QFixedPt : public QObject -{ - Q_OBJECT -public: - tst_QFixedPt() {} - ~tst_QFixedPt() {} - -private slots: - void create_data(); - void create(); - void add_data(); - void add(); - void sub_data(); - void sub(); - void mul_data(); - void mul(); - void div_data(); - void div(); - void neg_data(); - void neg(); - void shift_data(); - void shift(); - void sqrt_data(); - void sqrt(); - void round_data(); - void round(); - void compare_data(); - void compare(); -}; - -// qFuzzyCompare isn't quite "fuzzy" enough to handle conversion -// to fixed-point and back again. So create a "fuzzier" compare. -static bool fuzzyCompare(double x, double y) -{ - double diff = x - y; - if (diff < 0.0f) - diff = -diff; - return (diff < 0.0001); -} - -// Test the creation of QFixedPt values in various ways. -void tst_QFixedPt::create_data() -{ - QTest::addColumn("value"); - QTest::addColumn("intValue"); - QTest::addColumn("realValue"); - - QTest::newRow("zero") << 0x00000000 << 0 << 0.0f; - QTest::newRow("one") << 0x00010000 << 1 << 1.0f; - QTest::newRow("1.5") << 0x00018000 << 2 << 1.5f; // int rounds up - QTest::newRow("-1.5") << (int)0xFFFE8000 << -1 << -1.5f; // int rounds up - QTest::newRow("-7") << (int)0xFFF90000 << -7 << -7.0f; -} -void tst_QFixedPt::create() -{ - QFETCH(int, value); - QFETCH(int, intValue); - QFETCH(float, realValue); - - if (qFloor(realValue) == realValue) { - QFixedPt<16> ivalue(intValue); - QCOMPARE(ivalue.bits(), value); - QCOMPARE(ivalue.toInt(), intValue); - QCOMPARE(ivalue.toReal(), (qreal)realValue); - } - - QFixedPt<16> fvalue(realValue); - QCOMPARE(fvalue.bits(), value); - QCOMPARE(fvalue.toInt(), intValue); - QCOMPARE(fvalue.toReal(), (qreal)realValue); - - QFixedPt<16> fpvalue; - fpvalue.setBits(value); - QCOMPARE(fpvalue.bits(), value); - QCOMPARE(fpvalue.toInt(), intValue); - QCOMPARE(fpvalue.toReal(), (qreal)realValue); - - QFixedPt<16> fpvalue2(fpvalue); - QCOMPARE(fpvalue2.bits(), value); - QCOMPARE(fpvalue2.toInt(), intValue); - QCOMPARE(fpvalue2.toReal(), (qreal)realValue); - - if (qFloor(realValue) == realValue) { - QFixedPt<16> ivalue2(63); // Initialize the something else. - ivalue2 = intValue; // Then change the value. - QCOMPARE(ivalue2.bits(), value); - QCOMPARE(ivalue2.toInt(), intValue); - QCOMPARE(ivalue2.toReal(), (qreal)realValue); - } - - QFixedPt<16> fvalue2(36); - fvalue2 = realValue; - QCOMPARE(fvalue2.bits(), value); - QCOMPARE(fvalue2.toInt(), intValue); - QCOMPARE(fvalue2.toReal(), (qreal)realValue); - - QFixedPt<16> fpvalue3; - fpvalue3 = fpvalue; - QCOMPARE(fpvalue3.bits(), value); - QCOMPARE(fpvalue3.toInt(), intValue); - QCOMPARE(fpvalue3.toReal(), (qreal)realValue); - - // Now do some of the tests again with a different precision value. - - if (qFloor(realValue) == realValue) { - QFixedPt<4> ivalue3(intValue); - QCOMPARE(ivalue3.bits(), value >> 12); - QCOMPARE(ivalue3.toInt(), intValue); - QCOMPARE(ivalue3.toReal(), (qreal)realValue); - } - - QFixedPt<4> fvalue3(realValue); - QCOMPARE(fvalue3.bits(), value >> 12); - QCOMPARE(fvalue3.toInt(), intValue); - QCOMPARE(fvalue3.toReal(), (qreal)realValue); - - QFixedPt<4> fpvalue4; - fpvalue4.setBits(value >> 12); - QCOMPARE(fpvalue4.bits(), value >> 12); - QCOMPARE(fpvalue4.toInt(), intValue); - QCOMPARE(fpvalue4.toReal(), (qreal)realValue); - - // Test conversion between the precision values. - -#if !defined(QT_NO_MEMBER_TEMPLATES) - if (qFloor(realValue) == realValue) { - QFixedPt<16> ivalue(intValue); - QFixedPt<4> ivalue3(intValue); - QVERIFY(ivalue.toPrecision<4>() == ivalue3); - QVERIFY(ivalue3.toPrecision<16>() == ivalue); - } - QVERIFY(fvalue.toPrecision<4>() == fvalue3); - QVERIFY(fvalue3.toPrecision<16>() == fvalue); -#endif - - if (qFloor(realValue) == realValue) { - QFixedPt<16> ivalue(intValue); - QFixedPt<4> ivalue3(intValue); - QVERIFY(qFixedPtToPrecision<4>(ivalue) == ivalue3); - QVERIFY(qFixedPtToPrecision<16>(ivalue3) == ivalue); - } - QVERIFY(qFixedPtToPrecision<4>(fvalue) == fvalue3); - QVERIFY(qFixedPtToPrecision<16>(fvalue3) == fvalue); -} - -// Test fixed point addition. -void tst_QFixedPt::add_data() -{ - QTest::addColumn("a"); - QTest::addColumn("b"); - - QTest::newRow("zero") << 0.0f << 0.0f; - QTest::newRow("test1") << 1.0f << 0.0f; - QTest::newRow("test2") << 0.0f << 1.0f; - QTest::newRow("test3") << 10.0f << -3.0f; - QTest::newRow("test4") << 10.5f << 3.25f; -} -void tst_QFixedPt::add() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - QFixedPt<16> cvalue = avalue + bvalue; - QFixedPt<16> dvalue = a + bvalue; - QFixedPt<16> evalue = avalue + b; - - QCOMPARE(cvalue.toReal(), (qreal)(a + b)); - QCOMPARE(dvalue.toReal(), (qreal)(a + b)); - QCOMPARE(evalue.toReal(), (qreal)(a + b)); - - QFixedPt<16> fvalue(avalue); - fvalue += bvalue; - QCOMPARE(fvalue.toReal(), (qreal)(a + b)); - - QFixedPt<16> gvalue(avalue); - gvalue += b; - QCOMPARE(gvalue.toReal(), (qreal)(a + b)); - - if (qFloor(a) == a && qFloor(b) == b) { - QFixedPt<16> hvalue = int(a) + bvalue; - QFixedPt<16> ivalue = avalue + int(b); - - QCOMPARE(hvalue.toInt(), int(a) + int(b)); - QCOMPARE(ivalue.toInt(), int(a) + int(b)); - QCOMPARE(hvalue.toReal(), (qreal)(a + b)); - QCOMPARE(ivalue.toReal(), (qreal)(a + b)); - - QFixedPt<16> jvalue(avalue); - jvalue += int(b); - QCOMPARE(jvalue.toReal(), (qreal)(a + b)); - } -} - -// Test fixed point subtraction. -void tst_QFixedPt::sub_data() -{ - // Use the same test data as the add() test. - add_data(); -} -void tst_QFixedPt::sub() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - QFixedPt<16> cvalue = avalue - bvalue; - QFixedPt<16> dvalue = a - bvalue; - QFixedPt<16> evalue = avalue - b; - - QCOMPARE(cvalue.toReal(), (qreal)(a - b)); - QCOMPARE(dvalue.toReal(), (qreal)(a - b)); - QCOMPARE(evalue.toReal(), (qreal)(a - b)); - - QFixedPt<16> fvalue(avalue); - fvalue -= bvalue; - QCOMPARE(fvalue.toReal(), (qreal)(a - b)); - - QFixedPt<16> gvalue(avalue); - gvalue -= b; - QCOMPARE(gvalue.toReal(), (qreal)(a - b)); - - if (qFloor(a) == a && qFloor(b) == b) { - QFixedPt<16> hvalue = int(a) - bvalue; - QFixedPt<16> ivalue = avalue - int(b); - - QCOMPARE(hvalue.toInt(), int(a) - int(b)); - QCOMPARE(ivalue.toInt(), int(a) - int(b)); - QCOMPARE(hvalue.toReal(), (qreal)(a - b)); - QCOMPARE(ivalue.toReal(), (qreal)(a - b)); - - QFixedPt<16> jvalue(avalue); - jvalue -= int(b); - QCOMPARE(jvalue.toReal(), (qreal)(a - b)); - } -} - -// Test fixed point multiplication. -void tst_QFixedPt::mul_data() -{ - // Use the same test data as the add() test. - add_data(); -} -void tst_QFixedPt::mul() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - QFixedPt<16> cvalue = avalue * bvalue; - QFixedPt<16> dvalue = a * bvalue; - QFixedPt<16> evalue = avalue * b; - - QCOMPARE(cvalue.toReal(), (qreal)(a * b)); - QCOMPARE(dvalue.toReal(), (qreal)(a * b)); - QCOMPARE(evalue.toReal(), (qreal)(a * b)); - - QFixedPt<16> fvalue(avalue); - fvalue *= bvalue; - QCOMPARE(fvalue.toReal(), (qreal)(a * b)); - - QFixedPt<16> gvalue(avalue); - gvalue *= b; - QCOMPARE(gvalue.toReal(), (qreal)(a * b)); - - if (qFloor(a) == a && qFloor(b) == b) { - QFixedPt<16> hvalue = int(a) * bvalue; - QFixedPt<16> ivalue = avalue * int(b); - - QCOMPARE(hvalue.toInt(), int(a) * int(b)); - QCOMPARE(ivalue.toInt(), int(a) * int(b)); - QCOMPARE(hvalue.toReal(), (qreal)(a * b)); - QCOMPARE(ivalue.toReal(), (qreal)(a * b)); - - QFixedPt<16> jvalue(avalue); - jvalue *= int(b); - QCOMPARE(jvalue.toReal(), (qreal)(a * b)); - } -} - -// Test fixed point division. -void tst_QFixedPt::div_data() -{ - // Use the same test data as the add() test. - add_data(); -} -void tst_QFixedPt::div() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - qreal result; - if (b == 0.0f) - result = 0.0f; // Divide by zero results in zero. - else - result = a / b; - - QFixedPt<16> cvalue = avalue / bvalue; - QFixedPt<16> dvalue = a / bvalue; - QFixedPt<16> evalue = avalue / b; - - QVERIFY(fuzzyCompare(cvalue.toReal(), result)); - QVERIFY(fuzzyCompare(dvalue.toReal(), result)); - QVERIFY(fuzzyCompare(evalue.toReal(), result)); - - QFixedPt<16> fvalue(avalue); - fvalue /= bvalue; - QVERIFY(fuzzyCompare(fvalue.toReal(), result)); - - QFixedPt<16> gvalue(avalue); - gvalue /= b; - QVERIFY(fuzzyCompare(gvalue.toReal(), result)); - - if (qFloor(a) == a && qFloor(b) == b) { - QFixedPt<16> hvalue = int(a) / bvalue; - QFixedPt<16> ivalue = avalue / int(b); - - QCOMPARE(hvalue.toInt(), int(result)); - QCOMPARE(ivalue.toInt(), int(result)); - QVERIFY(fuzzyCompare(hvalue.toReal(), result)); - QVERIFY(fuzzyCompare(ivalue.toReal(), result)); - - QFixedPt<16> jvalue(avalue); - jvalue /= int(b); - QVERIFY(fuzzyCompare(jvalue.toReal(), result)); - } -} - -// Test fixed point negation. -void tst_QFixedPt::neg_data() -{ - // Use the same test data as the add() test. - add_data(); -} -void tst_QFixedPt::neg() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - QFixedPt<16> cvalue = -avalue; - QCOMPARE(cvalue.bits(), -avalue.bits()); - QCOMPARE(cvalue.toInt(), int(-a)); - QCOMPARE(cvalue.toReal(), (qreal)-a); - - QFixedPt<16> dvalue = -bvalue; - QCOMPARE(dvalue.bits(), -bvalue.bits()); - QCOMPARE(dvalue.toInt(), int(-b)); - QCOMPARE(dvalue.toReal(), (qreal)-b); -} - -// Test left and right shift operators on fixed point values. -void tst_QFixedPt::shift_data() -{ - QTest::addColumn("a"); - QTest::addColumn("amount"); - - QTest::newRow("zero") << 0.0f << 5; - QTest::newRow("one") << 1.0f << 4; - QTest::newRow("-1.75") << -1.75f << 4; -} -void tst_QFixedPt::shift() -{ - QFETCH(float, a); - QFETCH(int, amount); - - int lresult = int((a * 65536.0) * (1 << amount)); - int rresult = int((a * 65536.0) / (1 << amount)); - - QFixedPt<16> avalue(a); - avalue <<= amount; - QCOMPARE(avalue.bits(), lresult); - - QFixedPt<16> bvalue(a); - bvalue >>= amount; - QCOMPARE(bvalue.bits(), rresult); - - QFixedPt<16> cvalue(a); - - QFixedPt<16> dvalue; - dvalue = cvalue << amount; - QCOMPARE(dvalue.bits(), lresult); - - QFixedPt<16> evalue; - evalue = cvalue >> amount; - QCOMPARE(evalue.bits(), rresult); -} - -// Test fixed point square root. -void tst_QFixedPt::sqrt_data() -{ - QTest::addColumn("a"); - - QTest::newRow("zero") << 0.0f; - QTest::newRow("one") << 1.0f; - QTest::newRow("two") << 2.0f; - QTest::newRow("sixteen") << 16.0f; - QTest::newRow("1.5") << 1.5f; -} -void tst_QFixedPt::sqrt() -{ - QFETCH(float, a); - - QFixedPt<16> avalue(a); - QVERIFY(fuzzyCompare(avalue.sqrt().toReal(), qSqrt(a))); - QVERIFY(fuzzyCompare(avalue.sqrtF(), qSqrt(a))); -} - -// Test fixed point rounding. -void tst_QFixedPt::round_data() -{ - QTest::addColumn("a"); - QTest::addColumn("rounded"); - QTest::addColumn("ceiling"); - QTest::addColumn("flooring"); - QTest::addColumn("truncated"); - - QTest::newRow("zero") << 0.0f << 0 << 0 << 0 << 0; - QTest::newRow("test1") << 1.0f << 1 << 1 << 1 << 1; - QTest::newRow("test2") << 2.5f << 3 << 3 << 2 << 2; - QTest::newRow("test3") << 2.3f << 2 << 3 << 2 << 2; - QTest::newRow("test4") << -2.5f << -2 << -2 << -3 << -3; - QTest::newRow("test5") << -2.3f << -2 << -2 << -3 << -3; - QTest::newRow("test6") << -2.7f << -3 << -2 << -3 << -3; -} -void tst_QFixedPt::round() -{ - QFETCH(float, a); - QFETCH(int, rounded); - QFETCH(int, ceiling); - QFETCH(int, flooring); - QFETCH(int, truncated); - - QFixedPt<16> avalue(a); - QVERIFY(avalue.round() == rounded); - QVERIFY(avalue.ceil() == ceiling); - QVERIFY(avalue.floor() == flooring); - QVERIFY(avalue.truncate() == truncated); - - QCOMPARE(qRound(avalue), rounded); - QCOMPARE(qCeil(avalue), ceiling); - QCOMPARE(qFloor(avalue), flooring); -} - -// Test comparison operators. -void tst_QFixedPt::compare_data() -{ - QTest::addColumn("a"); - QTest::addColumn("b"); - - QTest::newRow("test1") << 0.0f << 0.0f; - QTest::newRow("test2") << 1.0f << 0.0f; - QTest::newRow("test3") << 2.5f << 2.5f; - QTest::newRow("test4") << 2.5f << -2.5f; - QTest::newRow("test5") << -2.5f << 2.5f; -} -void tst_QFixedPt::compare() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - if (a == b) { - QVERIFY(avalue == bvalue); - QVERIFY(avalue == b); - QVERIFY(a == bvalue); - QVERIFY(!(avalue != bvalue)); - QVERIFY(!(avalue != b)); - QVERIFY(!(a != bvalue)); - QVERIFY(!(avalue < bvalue)); - QVERIFY(!(avalue < b)); - QVERIFY(!(a < bvalue)); - QVERIFY(!(avalue > bvalue)); - QVERIFY(!(avalue > b)); - QVERIFY(!(a > bvalue)); - QVERIFY(avalue <= bvalue); - QVERIFY(avalue <= b); - QVERIFY(a <= bvalue); - QVERIFY(avalue >= bvalue); - QVERIFY(avalue >= b); - QVERIFY(a >= bvalue); - if (qFloor(a) == a) { - QVERIFY(int(a) == bvalue); - QVERIFY(!(int(a) != bvalue)); - QVERIFY(!(int(a) < bvalue)); - QVERIFY(!(int(a) > bvalue)); - QVERIFY(int(a) <= bvalue); - QVERIFY(int(a) >= bvalue); - } - if (qFloor(b) == b) { - QVERIFY(avalue == int(b)); - QVERIFY(!(avalue != int(b))); - QVERIFY(!(avalue < int(b))); - QVERIFY(!(avalue > int(b))); - QVERIFY(avalue <= int(b)); - QVERIFY(avalue >= int(b)); - } - } - - if (a != b) { - QVERIFY(avalue != bvalue); - QVERIFY(avalue != b); - QVERIFY(a != bvalue); - QVERIFY(!(avalue == bvalue)); - QVERIFY(!(avalue == b)); - QVERIFY(!(a == bvalue)); - if (qFloor(a) == a) { - QVERIFY(int(a) != bvalue); - QVERIFY(!(int(a) == bvalue)); - } - if (qFloor(b) == b) { - QVERIFY(avalue != int(b)); - QVERIFY(!(avalue == int(b))); - } - } - - if (a < b) { - QVERIFY(avalue < bvalue); - QVERIFY(avalue < b); - QVERIFY(a < bvalue); - QVERIFY(!(avalue >= bvalue)); - QVERIFY(!(avalue >= b)); - QVERIFY(!(a >= bvalue)); - QVERIFY(!(avalue > bvalue)); - QVERIFY(!(avalue > b)); - QVERIFY(!(a > bvalue)); - QVERIFY(avalue <= bvalue); - QVERIFY(avalue <= b); - QVERIFY(a <= bvalue); - QVERIFY(!(avalue >= bvalue)); - QVERIFY(!(avalue >= b)); - QVERIFY(!(a >= bvalue)); - if (qFloor(a) == a) { - QVERIFY(int(a) < bvalue); - QVERIFY(!(int(a) >= bvalue)); - QVERIFY(!(int(a) > bvalue)); - QVERIFY(int(a) <= bvalue); - } - if (qFloor(b) == b) { - QVERIFY(avalue < int(b)); - QVERIFY(!(avalue >= int(b))); - QVERIFY(!(avalue > int(b))); - QVERIFY(avalue <= int(b)); - } - } - - if (a > b) { - QVERIFY(avalue > bvalue); - QVERIFY(avalue > b); - QVERIFY(a > bvalue); - QVERIFY(!(avalue <= bvalue)); - QVERIFY(!(avalue <= b)); - QVERIFY(!(a <= bvalue)); - QVERIFY(!(avalue < bvalue)); - QVERIFY(!(avalue < b)); - QVERIFY(!(a < bvalue)); - QVERIFY(avalue >= bvalue); - QVERIFY(avalue >= b); - QVERIFY(a >= bvalue); - QVERIFY(!(avalue <= bvalue)); - QVERIFY(!(avalue <= b)); - QVERIFY(!(a <= bvalue)); - if (qFloor(a) == a) { - QVERIFY(int(a) > bvalue); - QVERIFY(!(int(a) <= bvalue)); - QVERIFY(!(int(a) < bvalue)); - QVERIFY(int(a) >= bvalue); - } - if (qFloor(b) == b) { - QVERIFY(avalue > int(b)); - QVERIFY(!(avalue <= int(b))); - QVERIFY(!(avalue < int(b))); - QVERIFY(avalue >= int(b)); - } - } - - if (qFuzzyCompare(a, b)) - QVERIFY(qFuzzyCompare(avalue, bvalue)); - else - QVERIFY(!qFuzzyCompare(avalue, bvalue)); -} - -QTEST_APPLESS_MAIN(tst_QFixedPt) - -#include "tst_qfixedpt.moc" diff --git a/tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp b/tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp index 8a7dd49..bb510fc 100644 --- a/tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp +++ b/tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp @@ -321,7 +321,7 @@ void tst_QMatrix::setMatrix(QMatrix4x3& m, const qreal *values) // to be in row-major order. This sets the values using fixed-point. void tst_QMatrix::setMatrixFixed(QMatrix2x2& m, const qreal *values) { - qrealinner *data = m.data(); + float *data = m.data(); for (int row = 0; row < 2; ++row) { for (int col = 0; col < 2; ++col) { data[row + col * 2] = values[row * 2 + col]; @@ -330,7 +330,7 @@ void tst_QMatrix::setMatrixFixed(QMatrix2x2& m, const qreal *values) } void tst_QMatrix::setMatrixFixed(QMatrix3x3& m, const qreal *values) { - qrealinner *data = m.data(); + float *data = m.data(); for (int row = 0; row < 3; ++row) { for (int col = 0; col < 3; ++col) { data[row + col * 3] = values[row * 3 + col]; @@ -339,7 +339,7 @@ void tst_QMatrix::setMatrixFixed(QMatrix3x3& m, const qreal *values) } void tst_QMatrix::setMatrixFixed(QMatrix4x4& m, const qreal *values) { - qrealinner *data = m.data(); + float *data = m.data(); for (int row = 0; row < 4; ++row) { for (int col = 0; col < 4; ++col) { data[row + col * 4] = values[row * 4 + col]; @@ -348,7 +348,7 @@ void tst_QMatrix::setMatrixFixed(QMatrix4x4& m, const qreal *values) } void tst_QMatrix::setMatrixFixed(QMatrix4x3& m, const qreal *values) { - qrealinner *data = m.data(); + float *data = m.data(); for (int row = 0; row < 3; ++row) { for (int col = 0; col < 4; ++col) { data[row + col * 3] = values[row * 4 + col]; @@ -365,15 +365,6 @@ static bool fuzzyCompare(float x, float y, qreal epsilon = 0.001) diff = -diff; return (diff < epsilon); } -#ifdef QT_GL_FIXED_PREFERRED -static bool fuzzyCompareFixed(qrealinner x, int y) -{ - int diff = x.bits() - y; - if (diff < 0) - diff = -diff; - return (diff < 50); -} -#endif static bool fuzzyCompare(const QVector3D &v1, const QVector3D &v2, qreal epsilon = 0.001) { @@ -402,7 +393,7 @@ static bool matrixFuzzyCompare(const QMatrix4x4 &m1, const QMatrix4x4 &m2) // The values are assumed to be specified in row-major order. bool tst_QMatrix::isSame(const QMatrix2x2& m, const qreal *values) { - const qrealinner *mv = m.constData(); + const float *mv = m.constData(); for (int row = 0; row < 2; ++row) { for (int col = 0; col < 2; ++col) { // Check the values using the operator() function. @@ -413,24 +404,17 @@ bool tst_QMatrix::isSame(const QMatrix2x2& m, const qreal *values) // Check the values using direct access, which verifies that the values // are stored internally in column-major order. -#ifdef QT_GL_FIXED_PREFERRED - if (!fuzzyCompareFixed(mv[col * 2 + row], (int)(values[row * 2 + col] * 65536.0))) { - qDebug() << "column fixed-point failure at" << row << col << "actual =" << mv[col * 2 + row] << "expected =" << (int)(values[row * 2 + col] * 65536.0); - return false; - } -#else if (!fuzzyCompare((float)(mv[col * 2 + row]), (float)(values[row * 2 + col]))) { qDebug() << "column floating-point failure at" << row << col << "actual =" << mv[col * 2 + row] << "expected =" << values[row * 2 + col]; return false; } -#endif } } return true; } bool tst_QMatrix::isSame(const QMatrix3x3& m, const qreal *values) { - const qrealinner *mv = m.constData(); + const float *mv = m.constData(); for (int row = 0; row < 3; ++row) { for (int col = 0; col < 3; ++col) { // Check the values using the operator() access function. @@ -441,24 +425,17 @@ bool tst_QMatrix::isSame(const QMatrix3x3& m, const qreal *values) // Check the values using direct access, which verifies that the values // are stored internally in column-major order. -#ifdef QT_GL_FIXED_PREFERRED - if (!fuzzyCompareFixed(mv[col * 3 + row], (int)(values[row * 3 + col] * 65536.0))) { - qDebug() << "column fixed-point failure at" << row << col << "actual =" << mv[col * 3 + row] << "expected =" << (int)(values[row * 3 + col] * 65536.0); - return false; - } -#else if (!fuzzyCompare((float)(mv[col * 3 + row]), (float)(values[row * 3 + col]))) { qDebug() << "column floating-point failure at" << row << col << "actual =" << mv[col * 3 + row] << "expected =" << values[row * 3 + col]; return false; } -#endif } } return true; } bool tst_QMatrix::isSame(const QMatrix4x4& m, const qreal *values) { - const qrealinner *mv = m.constData(); + const float *mv = m.constData(); for (int row = 0; row < 4; ++row) { for (int col = 0; col < 4; ++col) { // Check the values using the operator() access function. @@ -469,24 +446,17 @@ bool tst_QMatrix::isSame(const QMatrix4x4& m, const qreal *values) // Check the values using direct access, which verifies that the values // are stored internally in column-major order. -#ifdef QT_GL_FIXED_PREFERRED - if (!fuzzyCompareFixed(mv[col * 4 + row], (int)(values[row * 4 + col] * 65536.0))) { - qDebug() << "column fixed-point failure at" << row << col << "actual =" << mv[col * 4 + row] << "expected =" << (int)(values[row * 4 + col] * 65536.0); - return false; - } -#else if (!fuzzyCompare((float)(mv[col * 4 + row]), (float)(values[row * 4 + col]))) { qDebug() << "column floating-point failure at" << row << col << "actual =" << mv[col * 4 + row] << "expected =" << values[row * 4 + col]; return false; } -#endif } } return true; } bool tst_QMatrix::isSame(const QMatrix4x3& m, const qreal *values) { - const qrealinner *mv = m.constData(); + const float *mv = m.constData(); for (int row = 0; row < 3; ++row) { for (int col = 0; col < 4; ++col) { // Check the values using the operator() access function. @@ -497,17 +467,10 @@ bool tst_QMatrix::isSame(const QMatrix4x3& m, const qreal *values) // Check the values using direct access, which verifies that the values // are stored internally in column-major order. -#ifdef QT_GL_FIXED_PREFERRED - if (!fuzzyCompareFixed(mv[col * 3 + row], (int)(values[row * 4 + col] * 65536.0))) { - qDebug() << "column fixed-point failure at" << row << col << "actual =" << mv[col * 3 + row] << "expected =" << (int)(values[row * 4 + col] * 65536.0); - return false; - } -#else if (!fuzzyCompare((float)(mv[col * 3 + row]), (float)(values[row * 4 + col]))) { qDebug() << "column floating-point failure at" << row << col << "actual =" << mv[col * 3 + row] << "expected =" << values[row * 4 + col]; return false; } -#endif } } return true; @@ -1333,7 +1296,7 @@ void tst_QMatrix::multiply4x3() QMatrix4x3 m1((const qreal *)m1Values); QMatrix3x4 m2((const qreal *)m2Values); - QGenericMatrix<3, 3, qreal, qrealinner> m4; + QGenericMatrix<3, 3, qreal, float> m4; m4 = m1 * m2; qreal values[9]; m4.toValueArray(values); @@ -2901,11 +2864,7 @@ void tst_QMatrix::extractAxisRotation() m.extractAxisRotation(extractedAngle, extractedAxis); -#ifdef QT_GL_FIXED_PREFERRED - qreal epsilon = 0.003; -#else qreal epsilon = 0.001; -#endif if (angle > 180) { QVERIFY(fuzzyCompare(360.0f - angle, extractedAngle, epsilon)); @@ -2953,11 +2912,7 @@ void tst_QMatrix::extractTranslation() QVector3D vec = rotation.extractTranslation(); -#ifdef QT_GL_FIXED_PREFERRED - qreal epsilon = 0.01; -#else qreal epsilon = 0.001; -#endif QVERIFY(fuzzyCompare(vec.x(), x, epsilon)); QVERIFY(fuzzyCompare(vec.y(), y, epsilon)); @@ -2992,7 +2947,7 @@ enum { // Structure that allows direct access to "flagBits" for testing. struct Matrix4x4 { - qrealinner m[4][4]; + float m[4][4]; int flagBits; }; @@ -3225,24 +3180,6 @@ void tst_QMatrix::fill() QVERIFY(isSame(m2, fillValues4x3)); } -// Force the fixed-point version of the test case to put a -// different test name on the front of failure reports. -class tst_QMatrixFixed : public tst_QMatrix -{ - Q_OBJECT -public: - tst_QMatrixFixed() {} - ~tst_QMatrixFixed() {} -}; - -#ifdef QT_GL_FIXED_PREFERRED - -QTEST_APPLESS_MAIN(tst_QMatrixFixed) - -#else - QTEST_APPLESS_MAIN(tst_QMatrix) -#endif - #include "tst_qmatrixnxn.moc" diff --git a/tests/auto/math3d/qmatrixnxn_fixed/qmatrixnxn_fixed.pro b/tests/auto/math3d/qmatrixnxn_fixed/qmatrixnxn_fixed.pro deleted file mode 100644 index cd1c8fa..0000000 --- a/tests/auto/math3d/qmatrixnxn_fixed/qmatrixnxn_fixed.pro +++ /dev/null @@ -1,8 +0,0 @@ -load(qttest_p4) -VPATH += ../shared -VPATH += ../qmatrixnxn -INCLUDEPATH += ../shared -INCLUDEPATH += ../../../../src/gui/math3d -DEFINES += FIXED_POINT_TESTS -HEADERS += math3dincludes.h -SOURCES += tst_qmatrixnxn.cpp math3dincludes.cpp diff --git a/tests/auto/math3d/qquaternion/tst_qquaternion.cpp b/tests/auto/math3d/qquaternion/tst_qquaternion.cpp index 325cb40..fd7c7f8 100644 --- a/tests/auto/math3d/qquaternion/tst_qquaternion.cpp +++ b/tests/auto/math3d/qquaternion/tst_qquaternion.cpp @@ -768,24 +768,6 @@ void tst_QQuaternion::interpolate() QVERIFY(fuzzyCompare(result.scalar(), q3.scalar())); } -// Force the fixed-point version of the test case to put a -// different test name on the front of failure reports. -class tst_QQuaternionFixed : public tst_QQuaternion -{ - Q_OBJECT -public: - tst_QQuaternionFixed() {} - ~tst_QQuaternionFixed() {} -}; - -#ifdef QT_GL_FIXED_PREFERRED - -QTEST_APPLESS_MAIN(tst_QQuaternionFixed) - -#else - QTEST_APPLESS_MAIN(tst_QQuaternion) -#endif - #include "tst_qquaternion.moc" diff --git a/tests/auto/math3d/qquaternion_fixed/qquaternion_fixed.pro b/tests/auto/math3d/qquaternion_fixed/qquaternion_fixed.pro deleted file mode 100644 index a0d5401..0000000 --- a/tests/auto/math3d/qquaternion_fixed/qquaternion_fixed.pro +++ /dev/null @@ -1,8 +0,0 @@ -load(qttest_p4) -VPATH += ../shared -VPATH += ../qquaternion -INCLUDEPATH += ../shared -INCLUDEPATH += ../../../../src/gui/math3d -DEFINES += FIXED_POINT_TESTS -HEADERS += math3dincludes.h -SOURCES += tst_qquaternion.cpp math3dincludes.cpp diff --git a/tests/auto/math3d/qvectornd/tst_qvectornd.cpp b/tests/auto/math3d/qvectornd/tst_qvectornd.cpp index 83bacdf..a092fb0 100644 --- a/tests/auto/math3d/qvectornd/tst_qvectornd.cpp +++ b/tests/auto/math3d/qvectornd/tst_qvectornd.cpp @@ -2040,24 +2040,6 @@ void tst_QVector::dotProduct4() QCOMPARE(QVector4D::dotProduct(v1, v2), d); } -// Force the fixed-point version of the test case to put a -// different test name on the front of failure reports. -class tst_QVectorFixed : public tst_QVector -{ - Q_OBJECT -public: - tst_QVectorFixed() {} - ~tst_QVectorFixed() {} -}; - -#ifdef QT_GL_FIXED_PREFERRED - -QTEST_APPLESS_MAIN(tst_QVectorFixed) - -#else - QTEST_APPLESS_MAIN(tst_QVector) -#endif - #include "tst_qvectornd.moc" diff --git a/tests/auto/math3d/qvectornd_fixed/qvectornd_fixed.pro b/tests/auto/math3d/qvectornd_fixed/qvectornd_fixed.pro deleted file mode 100644 index a667fcc..0000000 --- a/tests/auto/math3d/qvectornd_fixed/qvectornd_fixed.pro +++ /dev/null @@ -1,8 +0,0 @@ -load(qttest_p4) -VPATH += ../shared -VPATH += ../qvectornd -INCLUDEPATH += ../shared -INCLUDEPATH += ../../../../src/gui/math3d -DEFINES += FIXED_POINT_TESTS -HEADERS += math3dincludes.h -SOURCES += tst_qvectornd.cpp math3dincludes.cpp diff --git a/tests/auto/math3d/shared/math3dincludes.cpp b/tests/auto/math3d/shared/math3dincludes.cpp deleted file mode 100644 index 725079d..0000000 --- a/tests/auto/math3d/shared/math3dincludes.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "math3dincludes.h" - -#if defined(FIXED_POINT_TESTS) - -#include "qmatrix4x4.cpp" -#include "qgenericmatrix.cpp" -#include "qvector2d.cpp" -#include "qvector3d.cpp" -#include "qvector4d.cpp" -#include "qquaternion.cpp" -#include "qmath3dutil.cpp" - -#endif diff --git a/tests/auto/math3d/shared/math3dincludes.h b/tests/auto/math3d/shared/math3dincludes.h index 23b0f16..1ac0c08 100644 --- a/tests/auto/math3d/shared/math3dincludes.h +++ b/tests/auto/math3d/shared/math3dincludes.h @@ -42,41 +42,6 @@ #ifndef MATH3DINCLUDES_H #define MATH3DINCLUDES_H -#if defined(FIXED_POINT_TESTS) - -// Rename the classes we want to test in fixed-point mode so that -// they don't conflict with the ones that are built into Qt. -#define QT_NO_GL_FLOAT 1 -#define QVector2D tst_QVector2D -#define QVector3D tst_QVector3D -#define QVector4D tst_QVector4D -#define QQuaternion tst_QQuaternionX -#define QMatrix2x2 tst_QMatrix2x2 -#define QMatrix3x3 tst_QMatrix3x3 -#define QMatrix4x4 tst_QMatrix4x4 -#define QMatrix2x3 tst_QMatrix2x3 -#define QMatrix2x4 tst_QMatrix2x4 -#define QMatrix3x2 tst_QMatrix3x2 -#define QMatrix3x4 tst_QMatrix3x4 -#define QMatrix4x2 tst_QMatrix4x2 -#define QMatrix4x3 tst_QMatrix4x3 -#define QGenericMatrix tst_QGenericMatrix -#define qt_math3d_sincos tst_qt_math3d_sincos -#define qt_math3d_convert tst_qt_math3d_convert -#define qrealinner tst_qrealinner - -// We need to re-include the headers with the changed class names. -#undef QGENERICMATRIX_H -#undef QMATH3DGLOBAL_H -#undef QMATH3DUTIL_P_H -#undef QMATRIX4X4_H -#undef QQUATERNION_H -#undef QVECTOR2D_H -#undef QVECTOR3D_H -#undef QVECTOR4D_H - -#endif - #include #include #include -- cgit v0.12 From 72f84ad17d0905f91e9d3988bb0f6482df6c6c78 Mon Sep 17 00:00:00 2001 From: Bjoern Erik Nilsen Date: Tue, 7 Apr 2009 16:50:23 +0200 Subject: Use qIsFuzzyNull rather than the more expensive qFuzzyCompare See also fde7f3d03782c801901f511131458d6fcb1021a5 Reviewed-by: Olivier Reviewed-by: Samuel --- src/corelib/tools/qsize.h | 8 +++---- src/gui/graphicsview/qgraphicsitem.cpp | 2 +- src/gui/kernel/qwidget.cpp | 2 +- src/gui/math3d/qmatrix4x4.cpp | 2 +- src/gui/painting/qbezier.cpp | 24 ++++++++++----------- src/gui/painting/qcolor.cpp | 4 ++-- src/gui/painting/qmatrix.h | 2 +- src/gui/painting/qpaintengine_d3d.cpp | 6 +++--- src/gui/painting/qpaintengine_raster.cpp | 24 ++++++++++----------- src/gui/painting/qpainter.cpp | 24 ++++++++++----------- src/gui/painting/qpainterpath.cpp | 8 +++---- src/gui/painting/qpathclipper.cpp | 36 ++++++++++++++++---------------- src/gui/painting/qstroker.cpp | 12 +++++------ src/gui/painting/qtessellator.cpp | 2 +- src/opengl/qpaintengine_opengl.cpp | 9 ++++---- src/svg/qgraphicssvgitem.cpp | 2 +- src/svg/qsvggenerator.cpp | 2 +- src/svg/qsvggraphics.cpp | 16 +++++++------- 18 files changed, 92 insertions(+), 93 deletions(-) diff --git a/src/corelib/tools/qsize.h b/src/corelib/tools/qsize.h index 57c55ca..df2c183 100644 --- a/src/corelib/tools/qsize.h +++ b/src/corelib/tools/qsize.h @@ -171,14 +171,14 @@ inline const QSize operator*(qreal c, const QSize &s) inline QSize &QSize::operator/=(qreal c) { - Q_ASSERT(!qFuzzyCompare(c + 1, 1)); + Q_ASSERT(!qIsFuzzyNull(c)); wd = qRound(wd/c); ht = qRound(ht/c); return *this; } inline const QSize operator/(const QSize &s, qreal c) { - Q_ASSERT(!qFuzzyCompare(c + 1, 1)); + Q_ASSERT(!qIsFuzzyNull(c)); return QSize(qRound(s.wd/c), qRound(s.ht/c)); } @@ -327,14 +327,14 @@ inline const QSizeF operator*(qreal c, const QSizeF &s) inline QSizeF &QSizeF::operator/=(qreal c) { - Q_ASSERT(!qFuzzyCompare(c + 1, 1)); + Q_ASSERT(!qIsFuzzyNull(c)); wd = wd/c; ht = ht/c; return *this; } inline const QSizeF operator/(const QSizeF &s, qreal c) { - Q_ASSERT(!qFuzzyCompare(c + 1, 1)); + Q_ASSERT(!qIsFuzzyNull(c)); return QSizeF(s.wd/c, s.ht/c); } diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index b8ff5b4..0d846d9 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -4091,7 +4091,7 @@ void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect) return; if (d->cacheMode != NoCache) { QGraphicsItemCache *c; - bool scrollCache = qFuzzyCompare(dx - int(dx), qreal(0.0)) && qFuzzyCompare(dy - int(dy), qreal(0.0)) + bool scrollCache = qIsFuzzyNull(dx - int(dx)) && qIsFuzzyNull(dy - int(dy)) && (c = (QGraphicsItemCache *)qVariantValue(d_ptr->extra(QGraphicsItemPrivate::ExtraCacheData))) && (d->cacheMode == ItemCoordinateCache && !c->fixedSize.isValid()); if (scrollCache) { diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 20b79ce..623ba59 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -4780,7 +4780,7 @@ void QWidget::render(QPainter *painter, const QPoint &targetOffset, } const qreal opacity = painter->opacity(); - if (qFuzzyCompare(opacity + 1, qreal(1.0))) + if (qIsFuzzyNull(opacity)) return; // Fully transparent. Q_D(QWidget); diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index c2873e0..1457400 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -1514,7 +1514,7 @@ void QMatrix4x4::extractAxisRotation(qreal &angle, QVector3D &axis) const angle = acos(cosa) * 180.0f / M_PI; // Any axis will work if r is zero (means no rotation) - if (qFuzzyCompare(angle, (qreal)0.0f)) { + if (qIsFuzzyNull(angle)) { axis.setX(1.0f); axis.setY(0.0f); axis.setZ(0.0f); diff --git a/src/gui/painting/qbezier.cpp b/src/gui/painting/qbezier.cpp index 8317dd8..1168b5a 100644 --- a/src/gui/painting/qbezier.cpp +++ b/src/gui/painting/qbezier.cpp @@ -127,13 +127,13 @@ static inline void flattenBezierWithoutInflections(QBezier &bez, qreal dy = bez.y2 - bez.y1; qreal normalized = qSqrt(dx * dx + dy * dy); - if (qFuzzyCompare(normalized + 1, 1)) + if (qIsFuzzyNull(normalized)) break; qreal d = qAbs(dx * (bez.y3 - bez.y2) - dy * (bez.x3 - bez.x2)); qreal t = qSqrt(4. / 3. * normalized * flatness / d); - if (t > 1 || qFuzzyCompare(t, (qreal)1.)) + if (t > 1 || qIsFuzzyNull(t - (qreal)1.)) break; bez.parameterSplitLeft(t, &left); p->append(bez.pt1()); @@ -144,19 +144,19 @@ static inline void flattenBezierWithoutInflections(QBezier &bez, static inline int quadraticRoots(qreal a, qreal b, qreal c, qreal *x1, qreal *x2) { - if (qFuzzyCompare(a + 1, 1)) { - if (qFuzzyCompare(b + 1, 1)) + if (qIsFuzzyNull(a)) { + if (qIsFuzzyNull(b)) return 0; *x1 = *x2 = (-c / b); return 1; } else { const qreal det = b * b - 4 * a * c; - if (qFuzzyCompare(det + 1, 1)) { + if (qIsFuzzyNull(det)) { *x1 = *x2 = -b / (2 * a); return 1; } if (det > 0) { - if (qFuzzyCompare(b + 1, 1)) { + if (qIsFuzzyNull(b)) { *x2 = qSqrt(-c / a); *x1 = -(*x2); return 2; @@ -187,7 +187,7 @@ static inline bool findInflections(qreal a, qreal b, qreal c, *t1 = r2; *t2 = r1; } - if (!qFuzzyCompare(a + 1, 1)) + if (!qIsFuzzyNull(a)) *tCups = 0.5 * (-b / a); else *tCups = 2; @@ -243,7 +243,7 @@ void QBezier::addToPolygonMixed(QPolygonF *polygon) const qreal b = 6 * (ay * cx - ax * cy); qreal c = 2 * (by * cx - bx * cy); - if ((qFuzzyCompare(a + 1, 1) && qFuzzyCompare(b + 1, 1)) || + if ((qIsFuzzyNull(a) && qIsFuzzyNull(b)) || (b * b - 4 * a *c) < 0) { QBezier bez(*this); flattenBezierWithoutInflections(bez, polygon); @@ -447,7 +447,7 @@ static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qr qreal r = 1.0 + prev_normal.x() * next_normal.x() + prev_normal.y() * next_normal.y(); - if (qFuzzyCompare(r + 1, 1)) { + if (qIsFuzzyNull(r)) { points_shifted[i] = points[i] + offset * prev_normal; } else { qreal k = offset / r; @@ -477,12 +477,12 @@ static bool addCircle(const QBezier *b, qreal offset, QBezier *o) normals[0] = QPointF(b->y2 - b->y1, b->x1 - b->x2); qreal dist = qSqrt(normals[0].x()*normals[0].x() + normals[0].y()*normals[0].y()); - if (qFuzzyCompare(dist + 1, 1)) + if (qIsFuzzyNull(dist)) return false; normals[0] /= dist; normals[2] = QPointF(b->y4 - b->y3, b->x3 - b->x4); dist = qSqrt(normals[2].x()*normals[2].x() + normals[2].y()*normals[2].y()); - if (qFuzzyCompare(dist + 1, 1)) + if (qIsFuzzyNull(dist)) return false; normals[2] /= dist; @@ -1022,7 +1022,7 @@ int QBezier::stationaryYPoints(qreal &t0, qreal &t1) const QList result; - if (qFuzzyCompare(reciprocal + 1, 1)) { + if (qIsFuzzyNull(reciprocal)) { t0 = -b / (2 * a); return 1; } else if (reciprocal > 0) { diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp index 5d7d4ab..6eecea0 100644 --- a/src/gui/painting/qcolor.cpp +++ b/src/gui/painting/qcolor.cpp @@ -1387,7 +1387,7 @@ QColor QColor::toHsv() const const qreal min = Q_MIN_3(r, g, b); const qreal delta = max - min; color.ct.ahsv.value = qRound(max * USHRT_MAX); - if (qFuzzyCompare(delta + 1, 1)) { + if (qIsFuzzyNull(delta)) { // achromatic case, hue is undefined color.ct.ahsv.hue = USHRT_MAX; color.ct.ahsv.saturation = 0; @@ -1441,7 +1441,7 @@ QColor QColor::toCmyk() const // cmy -> cmyk const qreal k = qMin(c, qMin(m, y)); - if (!qFuzzyCompare(k,1)) { + if (!qIsFuzzyNull(k - 1)) { c = (c - k) / (1.0 - k); m = (m - k) / (1.0 - k); y = (y - k) / (1.0 - k); diff --git a/src/gui/painting/qmatrix.h b/src/gui/painting/qmatrix.h index 1b6bd6d..71c1e34 100644 --- a/src/gui/painting/qmatrix.h +++ b/src/gui/painting/qmatrix.h @@ -99,7 +99,7 @@ public: QMatrix &shear(qreal sh, qreal sv); QMatrix &rotate(qreal a); - bool isInvertible() const { return !qFuzzyCompare(_m11*_m22 - _m12*_m21 + 1, 1); } + bool isInvertible() const { return !qIsFuzzyNull(_m11*_m22 - _m12*_m21); } qreal det() const { return _m11*_m22 - _m12*_m21; } QMatrix inverted(bool *invertible = 0) const; diff --git a/src/gui/painting/qpaintengine_d3d.cpp b/src/gui/painting/qpaintengine_d3d.cpp index bb81623..4b494d1 100644 --- a/src/gui/painting/qpaintengine_d3d.cpp +++ b/src/gui/painting/qpaintengine_d3d.cpp @@ -2506,8 +2506,8 @@ void QD3DDrawHelper::addTrap(const Trapezoid &trap) qreal _rightA = (qreal)_w/_h; qreal _rightB = topRightX - _rightA * topRightY; - qreal invLeftA = qFuzzyCompare(_leftA + 1, 1) ? 0.0 : 1.0 / _leftA; - qreal invRightA = qFuzzyCompare(_rightA + 1, 1) ? 0.0 : 1.0 / _rightA; + qreal invLeftA = qIsFuzzyNull(_leftA) ? 0.0 : 1.0 / _leftA; + qreal invRightA = qIsFuzzyNull(_rightA) ? 0.0 : 1.0 / _rightA; vertex v1 = { {1.f, top - 1.f, 0.5f}, 0.f, top, bottom, invLeftA, -invRightA, @@ -2970,7 +2970,7 @@ qreal calculateAngle(qreal dx, qreal dy) { qreal angle; - if (qFuzzyCompare(dx + 1, 1)) { + if (qIsFuzzyNull(dx)) { angle = (dy < 0) ? -M_PI/2 : M_PI/2; } else { angle = atanf(dy/dx); diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index addd63d..7aab25c 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -618,22 +618,22 @@ void QRasterPaintEngine::updateMatrix(const QTransform &matrix) d->isPlain45DegreeRotation = false; if (txop >= QTransform::TxRotate) { d->isPlain45DegreeRotation = - (qFuzzyCompare(matrix.m11() + 1, qreal(1)) - && qFuzzyCompare(matrix.m12(), qreal(1)) - && qFuzzyCompare(matrix.m21(), qreal(-1)) - && qFuzzyCompare(matrix.m22() + 1, qreal(1)) + (qIsFuzzyNull(matrix.m11()) + && qIsFuzzyNull(matrix.m12() - qreal(1)) + && qIsFuzzyNull(matrix.m21() + qreal(1)) + && qIsFuzzyNull(matrix.m22()) ) || - (qFuzzyCompare(matrix.m11(), qreal(-1)) - && qFuzzyCompare(matrix.m12() + 1, qreal(1)) - && qFuzzyCompare(matrix.m21() + 1, qreal(1)) - && qFuzzyCompare(matrix.m22(), qreal(-1)) + (qIsFuzzyNull(matrix.m11() + qreal(1)) + && qIsFuzzyNull(matrix.m12()) + && qIsFuzzyNull(matrix.m21()) + && qIsFuzzyNull(matrix.m22() + qreal(1)) ) || - (qFuzzyCompare(matrix.m11() + 1, qreal(1)) - && qFuzzyCompare(matrix.m12(), qreal(-1)) - && qFuzzyCompare(matrix.m21(), qreal(1)) - && qFuzzyCompare(matrix.m22() + 1, qreal(1)) + (qIsFuzzyNull(matrix.m11()) + && qIsFuzzyNull(matrix.m12() + qreal(1)) + && qIsFuzzyNull(matrix.m21() - qreal(1)) + && qIsFuzzyNull(matrix.m22()) ) ; } diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 2beb8c2..d4271ae 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -6055,22 +6055,22 @@ void QPainter::drawTextItem(const QPointF &p, const QTextItem &_ti) const QTransform &m = d->state->matrix; if (d->state->matrix.type() < QTransform::TxShear) { bool isPlain90DegreeRotation = - (qFuzzyCompare(m.m11() + 1, qreal(1)) - && qFuzzyCompare(m.m12(), qreal(1)) - && qFuzzyCompare(m.m21(), qreal(-1)) - && qFuzzyCompare(m.m22() + 1, qreal(1)) + (qIsFuzzyNull(m.m11()) + && qIsFuzzyNull(m.m12() - qreal(1)) + && qIsFuzzyNull(m.m21() + qreal(1)) + && qIsFuzzyNull(m.m22()) ) || - (qFuzzyCompare(m.m11(), qreal(-1)) - && qFuzzyCompare(m.m12() + 1, qreal(1)) - && qFuzzyCompare(m.m21() + 1, qreal(1)) - && qFuzzyCompare(m.m22(), qreal(-1)) + (qIsFuzzyNull(m.m11() + qreal(1)) + && qIsFuzzyNull(m.m12()) + && qIsFuzzyNull(m.m21()) + && qIsFuzzyNull(m.m22() + qreal(1)) ) || - (qFuzzyCompare(m.m11() + 1, qreal(1)) - && qFuzzyCompare(m.m12(), qreal(-1)) - && qFuzzyCompare(m.m21(), qreal(1)) - && qFuzzyCompare(m.m22() + 1, qreal(1)) + (qIsFuzzyNull(m.m11()) + && qIsFuzzyNull(m.m12() + qreal(1)) + && qIsFuzzyNull(m.m21() - qreal(1)) + && qIsFuzzyNull(m.m22()) ) ; aa = !isPlain90DegreeRotation; diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index 6ae908c..de8969c 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -1299,10 +1299,10 @@ static QRectF qt_painterpath_bezier_extrema(const QBezier &b) qreal bx = QT_BEZIER_B(b, x); qreal cx = QT_BEZIER_C(b, x); // specialcase quadratic curves to avoid div by zero - if (qFuzzyCompare(ax + 1, 1)) { + if (qIsFuzzyNull(ax)) { // linear curves are covered by initialization. - if (!qFuzzyCompare(bx + 1, 1)) { + if (!qIsFuzzyNull(bx)) { qreal t = -cx / bx; QT_BEZIER_CHECK_T(b, t); } @@ -1329,10 +1329,10 @@ static QRectF qt_painterpath_bezier_extrema(const QBezier &b) qreal cy = QT_BEZIER_C(b, y); // specialcase quadratic curves to avoid div by zero - if (qFuzzyCompare(ay + 1, 1)) { + if (qIsFuzzyNull(ay)) { // linear curves are covered by initialization. - if (!qFuzzyCompare(by + 1, 1)) { + if (!qIsFuzzyNull(by)) { qreal t = -cy / by; QT_BEZIER_CHECK_T(b, t); } diff --git a/src/gui/painting/qpathclipper.cpp b/src/gui/painting/qpathclipper.cpp index 297cdd3..33609ad 100644 --- a/src/gui/painting/qpathclipper.cpp +++ b/src/gui/painting/qpathclipper.cpp @@ -138,11 +138,11 @@ bool QIntersectionFinder::linesIntersect(const QLineF &a, const QLineF &b) const const qreal par = pDelta.x() * qDelta.y() - pDelta.y() * qDelta.x(); - if (qFuzzyCompare(par + 1, 1)) { + if (qIsFuzzyNull(par)) { const QPointF normal(-pDelta.y(), pDelta.x()); // coinciding? - if (qFuzzyCompare(dot(normal, q1 - p1) + 1, 1)) { + if (qIsFuzzyNull(dot(normal, q1 - p1))) { const qreal dp = dot(pDelta, pDelta); const qreal tq1 = dot(pDelta, q1 - p1); @@ -202,13 +202,13 @@ void QIntersectionFinder::intersectBeziers(const QBezier &one, const QBezier &tw qreal alpha_q = t.at(i).second; QPointF pt; - if (qFuzzyCompare(alpha_p + 1, 1)) { + if (qIsFuzzyNull(alpha_p)) { pt = one.pt1(); - } else if (qFuzzyCompare(alpha_p, 1)) { + } else if (qIsFuzzyNull(alpha_p - 1)) { pt = one.pt4(); - } else if (qFuzzyCompare(alpha_q + 1, 1)) { + } else if (qIsFuzzyNull(alpha_q)) { pt = two.pt1(); - } else if (qFuzzyCompare(alpha_q, 1)) { + } else if (qIsFuzzyNull(alpha_q - 1)) { pt = two.pt4(); } else { pt = one.pointAt(alpha_p); @@ -250,11 +250,11 @@ void QIntersectionFinder::intersectLines(const QLineF &a, const QLineF &b, QData const qreal par = pDelta.x() * qDelta.y() - pDelta.y() * qDelta.x(); - if (qFuzzyCompare(par + 1, 1)) { + if (qIsFuzzyNull(par)) { const QPointF normal(-pDelta.y(), pDelta.x()); // coinciding? - if (qFuzzyCompare(dot(normal, q1 - p1) + 1, 1)) { + if (qIsFuzzyNull(dot(normal, q1 - p1))) { const qreal invDp = 1 / dot(pDelta, pDelta); const qreal tq1 = dot(pDelta, q1 - p1) * invDp; @@ -315,11 +315,11 @@ void QIntersectionFinder::intersectLines(const QLineF &a, const QLineF &b, QData if (tp<0 || tp>1 || tq<0 || tq>1) return; - const bool p_zero = qFuzzyCompare(tp + 1, 1); - const bool p_one = qFuzzyCompare(tp, 1); + const bool p_zero = qIsFuzzyNull(tp); + const bool p_one = qIsFuzzyNull(tp - 1); - const bool q_zero = qFuzzyCompare(tq + 1, 1); - const bool q_one = qFuzzyCompare(tq, 1); + const bool q_zero = qIsFuzzyNull(tq); + const bool q_one = qIsFuzzyNull(tq - 1); if ((q_zero || q_one) && (p_zero || p_one)) return; @@ -922,7 +922,7 @@ qreal QWingedEdge::delta(int vertex, int a, int b) const qreal result = b_angle - a_angle; - if (qFuzzyCompare(result + 1, 1) || qFuzzyCompare(result, 128)) + if (qIsFuzzyNull(result) || qFuzzyCompare(result, 128)) return 0; if (result < 0) @@ -951,7 +951,7 @@ static inline QPointF tangentAt(const QWingedEdge &list, int vi, int ei) if (ep->bezier) { normal = ep->bezier->derivedAt(t); - if (qFuzzyCompare(normal.x() + 1, 1) && qFuzzyCompare(normal.y() + 1, 1)) + if (qIsFuzzyNull(normal.x()) && qIsFuzzyNull(normal.y())) normal = ep->bezier->secondDerivedAt(t); } else { const QPointF a = *list.vertex(ep->first); @@ -1080,7 +1080,7 @@ QWingedEdge::TraversalStatus QWingedEdge::findInsertStatus(int vi, int ei) const qDebug() << "Delta to edge" << status.edge << d2 << ", angles: " << op->angle << op->invAngle; #endif - if (!(qFuzzyCompare(d2 + 1, 1) && isLeftOf(*this, vi, status.edge, ei)) + if (!(qIsFuzzyNull(d2) && isLeftOf(*this, vi, status.edge, ei)) && (d2 < d || (qFuzzyCompare(d2, d) && isLeftOf(*this, vi, status.edge, position)))) { position = status.edge; d = d2; @@ -1232,10 +1232,10 @@ int QWingedEdge::addEdge(int fi, int si, const QBezier *bezier, qreal t0, qreal QPointF aTangent = bezier->derivedAt(t0); QPointF bTangent = -bezier->derivedAt(t1); - if (qFuzzyCompare(aTangent.x() + 1, 1) && qFuzzyCompare(aTangent.y() + 1, 1)) + if (qIsFuzzyNull(aTangent.x()) && qIsFuzzyNull(aTangent.y())) aTangent = bezier->secondDerivedAt(t0); - if (qFuzzyCompare(bTangent.x() + 1, 1) && qFuzzyCompare(bTangent.y() + 1, 1)) + if (qIsFuzzyNull(bTangent.x()) && qIsFuzzyNull(bTangent.y())) bTangent = bezier->secondDerivedAt(t1); ep->angle = computeAngle(aTangent); @@ -1400,7 +1400,7 @@ static void addLineTo(QPainterPath &path, const QPointF &point) const QPointF p(-d1.y(), d1.x()); - if (qFuzzyCompare(dot(p, d2) + 1, 1)) { + if (qIsFuzzyNull(dot(p, d2))) { path.setElementPositionAt(elementCount - 1, point.x(), point.y()); return; } diff --git a/src/gui/painting/qstroker.cpp b/src/gui/painting/qstroker.cpp index b894c62..3a856d3 100644 --- a/src/gui/painting/qstroker.cpp +++ b/src/gui/painting/qstroker.cpp @@ -763,7 +763,7 @@ template bool qt_stroke_side(Iterator *it, qreal qt_t_for_arc_angle(qreal angle) { - if (qFuzzyCompare(angle + 1, qreal(1))) + if (qIsFuzzyNull(angle)) return 0; if (qFuzzyCompare(angle, qreal(90))) @@ -904,13 +904,13 @@ QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLengt } // avoid empty start segment - if (qFuzzyCompare(startT, qreal(1))) { + if (qIsFuzzyNull(startT - qreal(1))) { startT = 0; startSegment += delta; } // avoid empty end segment - if (qFuzzyCompare(endT + 1, qreal(1))) { + if (qIsFuzzyNull(endT)) { endT = 1; endSegment -= delta; } @@ -918,8 +918,8 @@ QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLengt startT = qt_t_for_arc_angle(startT * 90); endT = qt_t_for_arc_angle(endT * 90); - const bool splitAtStart = !qFuzzyCompare(startT + 1, qreal(1)); - const bool splitAtEnd = !qFuzzyCompare(endT, qreal(1)); + const bool splitAtStart = !qIsFuzzyNull(startT); + const bool splitAtEnd = !qIsFuzzyNull(endT - qreal(1)); const int end = endSegment + delta; @@ -1018,7 +1018,7 @@ void QDashStroker::processCurrentSubpath() sumLength += dashes[i]; } - if (qFuzzyCompare(sumLength + 1, qreal(1))) + if (qIsFuzzyNull(sumLength)) return; Q_ASSERT(dashCount > 0); diff --git a/src/gui/painting/qtessellator.cpp b/src/gui/painting/qtessellator.cpp index e02f02d..ae07565 100644 --- a/src/gui/painting/qtessellator.cpp +++ b/src/gui/painting/qtessellator.cpp @@ -1436,7 +1436,7 @@ void QTessellator::tessellateRect(const QPointF &a_, const QPointF &b_, qreal wi QPointF perp(pb.y() - pa.y(), pa.x() - pb.x()); qreal length = qSqrt(perp.x() * perp.x() + perp.y() * perp.y()); - if (qFuzzyCompare(length + 1, static_cast(1))) + if (qIsFuzzyNull(length)) return; // need the half of the width diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp index 88fd379..11df590 100644 --- a/src/opengl/qpaintengine_opengl.cpp +++ b/src/opengl/qpaintengine_opengl.cpp @@ -1924,15 +1924,15 @@ static void drawTrapezoid(const QGLTrapezoid &trap, const qreal offscreenHeight, qreal leftB = trap.bottomLeftX + (trap.topLeftX - trap.bottomLeftX) * reciprocal; qreal rightB = trap.bottomRightX + (trap.topRightX - trap.bottomRightX) * reciprocal; - const bool topZero = qFuzzyCompare(topDist + 1, 1); + const bool topZero = qIsFuzzyNull(topDist); reciprocal = topZero ? 1.0 / bottomDist : 1.0 / topDist; qreal leftA = topZero ? (trap.bottomLeftX - leftB) * reciprocal : (trap.topLeftX - leftB) * reciprocal; qreal rightA = topZero ? (trap.bottomRightX - rightB) * reciprocal : (trap.topRightX - rightB) * reciprocal; - qreal invLeftA = qFuzzyCompare(leftA + 1, 1) ? 0.0 : 1.0 / leftA; - qreal invRightA = qFuzzyCompare(rightA + 1, 1) ? 0.0 : 1.0 / rightA; + qreal invLeftA = qIsFuzzyNull(leftA) ? 0.0 : 1.0 / leftA; + qreal invRightA = qIsFuzzyNull(rightA) ? 0.0 : 1.0 / rightA; // fragment program needs the negative of invRightA as it mirrors the line glTexCoord4f(topDist, bottomDist, invLeftA, -invRightA); @@ -3445,8 +3445,7 @@ QVector QGLRectMaskGenerator::generateTrapezoids() // manhattan distance (no rotation) qreal width = qAbs(delta.x()) + qAbs(delta.y()); - Q_ASSERT(qFuzzyCompare(delta.x() + 1, static_cast(1)) - || qFuzzyCompare(delta.y() + 1, static_cast(1))); + Q_ASSERT(qIsFuzzyNull(delta.x()) || qIsFuzzyNull(delta.y())); tessellator.tessellateRect(first, last, width); } else { diff --git a/src/svg/qgraphicssvgitem.cpp b/src/svg/qgraphicssvgitem.cpp index e17df03..5c8a3c0 100644 --- a/src/svg/qgraphicssvgitem.cpp +++ b/src/svg/qgraphicssvgitem.cpp @@ -186,7 +186,7 @@ static void qt_graphicsItem_highlightSelected( QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option) { const QRectF murect = painter->transform().mapRect(QRectF(0, 0, 1, 1)); - if (qFuzzyCompare(qMax(murect.width(), murect.height()) + 1, 1)) + if (qIsFuzzyNull(qMax(murect.width(), murect.height()))) return; const QRectF mbrect = painter->transform().mapRect(item->boundingRect()); diff --git a/src/svg/qsvggenerator.cpp b/src/svg/qsvggenerator.cpp index e822da5..7c8926d 100644 --- a/src/svg/qsvggenerator.cpp +++ b/src/svg/qsvggenerator.cpp @@ -971,7 +971,7 @@ void QSvgPaintEngine::updateState(const QPaintEngineState &state) } if (flags & QPaintEngine::DirtyOpacity) { - if (!qFuzzyCompare(state.opacity(), 1)) + if (!qIsFuzzyNull(state.opacity() - 1)) stream() << "opacity=\""< Date: Wed, 8 Apr 2009 10:07:10 +0200 Subject: Rename qIsFuzzyNull to qFuzzyIsNull The function was added in fde7f3d03782c801901f511131458d6fcb1021a5 and we believe qFuzzyIsNull is a better naming and more in line with qFuzzyCompare. Reviewed-by: Lars Knoll Reviewed-by: nrc Reviewed-by: Samuel --- src/corelib/global/qglobal.h | 4 ++-- src/corelib/tools/qsize.h | 8 +++---- src/gui/graphicsview/qgraphicsitem.cpp | 10 ++++----- src/gui/graphicsview/qgraphicsitem_p.h | 2 +- src/gui/graphicsview/qgraphicsscene.cpp | 4 ++-- src/gui/kernel/qwidget.cpp | 2 +- src/gui/math3d/qmatrix4x4.cpp | 2 +- src/gui/painting/qbezier.cpp | 24 ++++++++++----------- src/gui/painting/qcolor.cpp | 4 ++-- src/gui/painting/qmatrix.h | 6 +++--- src/gui/painting/qpaintengine_d3d.cpp | 6 +++--- src/gui/painting/qpaintengine_raster.cpp | 24 ++++++++++----------- src/gui/painting/qpainter.cpp | 24 ++++++++++----------- src/gui/painting/qpainterpath.cpp | 8 +++---- src/gui/painting/qpathclipper.cpp | 36 ++++++++++++++++---------------- src/gui/painting/qstroker.cpp | 12 +++++------ src/gui/painting/qtessellator.cpp | 2 +- src/gui/painting/qtransform.cpp | 16 +++++++------- src/gui/painting/qtransform.h | 2 +- src/opengl/qpaintengine_opengl.cpp | 8 +++---- src/svg/qgraphicssvgitem.cpp | 2 +- src/svg/qsvggenerator.cpp | 2 +- src/svg/qsvggraphics.cpp | 16 +++++++------- 23 files changed, 112 insertions(+), 112 deletions(-) diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 28b9d08..5fd05c0 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1709,7 +1709,7 @@ static inline bool qFuzzyCompare(float p1, float p2) /*! \internal */ -static inline bool qIsFuzzyNull(double d) +static inline bool qFuzzyIsNull(double d) { return qAbs(d) <= 0.000000000001; } @@ -1717,7 +1717,7 @@ static inline bool qIsFuzzyNull(double d) /*! \internal */ -static inline bool qIsFuzzyNull(float f) +static inline bool qFuzzyIsNull(float f) { return qAbs(f) <= 0.00001f; } diff --git a/src/corelib/tools/qsize.h b/src/corelib/tools/qsize.h index df2c183..34a6c99 100644 --- a/src/corelib/tools/qsize.h +++ b/src/corelib/tools/qsize.h @@ -171,14 +171,14 @@ inline const QSize operator*(qreal c, const QSize &s) inline QSize &QSize::operator/=(qreal c) { - Q_ASSERT(!qIsFuzzyNull(c)); + Q_ASSERT(!qFuzzyIsNull(c)); wd = qRound(wd/c); ht = qRound(ht/c); return *this; } inline const QSize operator/(const QSize &s, qreal c) { - Q_ASSERT(!qIsFuzzyNull(c)); + Q_ASSERT(!qFuzzyIsNull(c)); return QSize(qRound(s.wd/c), qRound(s.ht/c)); } @@ -327,14 +327,14 @@ inline const QSizeF operator*(qreal c, const QSizeF &s) inline QSizeF &QSizeF::operator/=(qreal c) { - Q_ASSERT(!qIsFuzzyNull(c)); + Q_ASSERT(!qFuzzyIsNull(c)); wd = wd/c; ht = ht/c; return *this; } inline const QSizeF operator/(const QSizeF &s, qreal c) { - Q_ASSERT(!qIsFuzzyNull(c)); + Q_ASSERT(!qFuzzyIsNull(c)); return QSizeF(s.wd/c, s.ht/c); } diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 0d846d9..e7f9bd3 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -1906,11 +1906,11 @@ void QGraphicsItem::setOpacity(qreal opacity) newOpacity = qBound(0.0, newOpacity, 1.0); // No change? Done. - if (qIsFuzzyNull(newOpacity - this->opacity())) + if (qFuzzyIsNull(newOpacity - this->opacity())) return; // Assign local opacity. - if (qIsFuzzyNull(newOpacity - 1)) { + if (qFuzzyIsNull(newOpacity - 1)) { // Opaque, unset opacity. d_ptr->hasOpacity = 0; d_ptr->unsetExtra(QGraphicsItemPrivate::ExtraOpacity); @@ -3771,7 +3771,7 @@ void QGraphicsItemPrivate::resolveEffectiveOpacity(qreal parentEffectiveOpacity) } // Set this item's resolved opacity. - if (qIsFuzzyNull(myEffectiveOpacity - 1)) { + if (qFuzzyIsNull(myEffectiveOpacity - 1)) { // Opaque, unset effective opacity. hasEffectiveOpacity = 0; unsetExtra(ExtraEffectiveOpacity); @@ -4091,7 +4091,7 @@ void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect) return; if (d->cacheMode != NoCache) { QGraphicsItemCache *c; - bool scrollCache = qIsFuzzyNull(dx - int(dx)) && qIsFuzzyNull(dy - int(dy)) + bool scrollCache = qFuzzyIsNull(dx - int(dx)) && qFuzzyIsNull(dy - int(dy)) && (c = (QGraphicsItemCache *)qVariantValue(d_ptr->extra(QGraphicsItemPrivate::ExtraCacheData))) && (d->cacheMode == ItemCoordinateCache && !c->fixedSize.isValid()); if (scrollCache) { @@ -5854,7 +5854,7 @@ static void qt_graphicsItem_highlightSelected( QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option) { const QRectF murect = painter->transform().mapRect(QRectF(0, 0, 1, 1)); - if (qIsFuzzyNull(qMax(murect.width(), murect.height()))) + if (qFuzzyIsNull(qMax(murect.width(), murect.height()))) return; const QRectF mbrect = painter->transform().mapRect(item->boundingRect()); diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index 77db691..078c543 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -269,7 +269,7 @@ public: void updateCachedClipPathFromSetPosHelper(const QPointF &newPos); inline bool isFullyTransparent() const - { return hasEffectiveOpacity && qIsFuzzyNull(q_func()->effectiveOpacity()); } + { return hasEffectiveOpacity && qFuzzyIsNull(q_func()->effectiveOpacity()); } inline bool childrenCombineOpacity() const { return allChildrenCombineOpacity || children.isEmpty(); } diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index e885238..bd66c3d 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -4642,7 +4642,7 @@ static void _q_paintItem(QGraphicsItem *item, QPainter *painter, ? proxy->widget()->windowOpacity() : 1.0; const qreal oldPainterOpacity = painter->opacity(); - if (qIsFuzzyNull(windowOpacity)) + if (qFuzzyIsNull(windowOpacity)) return; // Set new painter opacity. if (windowOpacity < 1.0) @@ -5282,7 +5282,7 @@ void QGraphicsScene::itemUpdated(QGraphicsItem *item, const QRectF &rect) // Deliver the actual update. if (!d->updateAll) { if (d->views.isEmpty() || ((d->connectedSignals & d->changedSignalMask) && !item->d_ptr->itemIsUntransformable() - && qIsFuzzyNull(item->boundingRegionGranularity()))) { + && qFuzzyIsNull(item->boundingRegionGranularity()))) { // This block of code is kept for compatibility. Since 4.5, by default // QGraphicsView does not connect the signal and we use the below // method of delivering updates. diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 623ba59..3e25ffc 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -4780,7 +4780,7 @@ void QWidget::render(QPainter *painter, const QPoint &targetOffset, } const qreal opacity = painter->opacity(); - if (qIsFuzzyNull(opacity)) + if (qFuzzyIsNull(opacity)) return; // Fully transparent. Q_D(QWidget); diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index 1457400..e00d772 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -1514,7 +1514,7 @@ void QMatrix4x4::extractAxisRotation(qreal &angle, QVector3D &axis) const angle = acos(cosa) * 180.0f / M_PI; // Any axis will work if r is zero (means no rotation) - if (qIsFuzzyNull(angle)) { + if (qFuzzyIsNull(angle)) { axis.setX(1.0f); axis.setY(0.0f); axis.setZ(0.0f); diff --git a/src/gui/painting/qbezier.cpp b/src/gui/painting/qbezier.cpp index 1168b5a..7ed521e 100644 --- a/src/gui/painting/qbezier.cpp +++ b/src/gui/painting/qbezier.cpp @@ -127,13 +127,13 @@ static inline void flattenBezierWithoutInflections(QBezier &bez, qreal dy = bez.y2 - bez.y1; qreal normalized = qSqrt(dx * dx + dy * dy); - if (qIsFuzzyNull(normalized)) + if (qFuzzyIsNull(normalized)) break; qreal d = qAbs(dx * (bez.y3 - bez.y2) - dy * (bez.x3 - bez.x2)); qreal t = qSqrt(4. / 3. * normalized * flatness / d); - if (t > 1 || qIsFuzzyNull(t - (qreal)1.)) + if (t > 1 || qFuzzyIsNull(t - (qreal)1.)) break; bez.parameterSplitLeft(t, &left); p->append(bez.pt1()); @@ -144,19 +144,19 @@ static inline void flattenBezierWithoutInflections(QBezier &bez, static inline int quadraticRoots(qreal a, qreal b, qreal c, qreal *x1, qreal *x2) { - if (qIsFuzzyNull(a)) { - if (qIsFuzzyNull(b)) + if (qFuzzyIsNull(a)) { + if (qFuzzyIsNull(b)) return 0; *x1 = *x2 = (-c / b); return 1; } else { const qreal det = b * b - 4 * a * c; - if (qIsFuzzyNull(det)) { + if (qFuzzyIsNull(det)) { *x1 = *x2 = -b / (2 * a); return 1; } if (det > 0) { - if (qIsFuzzyNull(b)) { + if (qFuzzyIsNull(b)) { *x2 = qSqrt(-c / a); *x1 = -(*x2); return 2; @@ -187,7 +187,7 @@ static inline bool findInflections(qreal a, qreal b, qreal c, *t1 = r2; *t2 = r1; } - if (!qIsFuzzyNull(a)) + if (!qFuzzyIsNull(a)) *tCups = 0.5 * (-b / a); else *tCups = 2; @@ -243,7 +243,7 @@ void QBezier::addToPolygonMixed(QPolygonF *polygon) const qreal b = 6 * (ay * cx - ax * cy); qreal c = 2 * (by * cx - bx * cy); - if ((qIsFuzzyNull(a) && qIsFuzzyNull(b)) || + if ((qFuzzyIsNull(a) && qFuzzyIsNull(b)) || (b * b - 4 * a *c) < 0) { QBezier bez(*this); flattenBezierWithoutInflections(bez, polygon); @@ -447,7 +447,7 @@ static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qr qreal r = 1.0 + prev_normal.x() * next_normal.x() + prev_normal.y() * next_normal.y(); - if (qIsFuzzyNull(r)) { + if (qFuzzyIsNull(r)) { points_shifted[i] = points[i] + offset * prev_normal; } else { qreal k = offset / r; @@ -477,12 +477,12 @@ static bool addCircle(const QBezier *b, qreal offset, QBezier *o) normals[0] = QPointF(b->y2 - b->y1, b->x1 - b->x2); qreal dist = qSqrt(normals[0].x()*normals[0].x() + normals[0].y()*normals[0].y()); - if (qIsFuzzyNull(dist)) + if (qFuzzyIsNull(dist)) return false; normals[0] /= dist; normals[2] = QPointF(b->y4 - b->y3, b->x3 - b->x4); dist = qSqrt(normals[2].x()*normals[2].x() + normals[2].y()*normals[2].y()); - if (qIsFuzzyNull(dist)) + if (qFuzzyIsNull(dist)) return false; normals[2] /= dist; @@ -1022,7 +1022,7 @@ int QBezier::stationaryYPoints(qreal &t0, qreal &t1) const QList result; - if (qIsFuzzyNull(reciprocal)) { + if (qFuzzyIsNull(reciprocal)) { t0 = -b / (2 * a); return 1; } else if (reciprocal > 0) { diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp index 6eecea0..24d167e 100644 --- a/src/gui/painting/qcolor.cpp +++ b/src/gui/painting/qcolor.cpp @@ -1387,7 +1387,7 @@ QColor QColor::toHsv() const const qreal min = Q_MIN_3(r, g, b); const qreal delta = max - min; color.ct.ahsv.value = qRound(max * USHRT_MAX); - if (qIsFuzzyNull(delta)) { + if (qFuzzyIsNull(delta)) { // achromatic case, hue is undefined color.ct.ahsv.hue = USHRT_MAX; color.ct.ahsv.saturation = 0; @@ -1441,7 +1441,7 @@ QColor QColor::toCmyk() const // cmy -> cmyk const qreal k = qMin(c, qMin(m, y)); - if (!qIsFuzzyNull(k - 1)) { + if (!qFuzzyIsNull(k - 1)) { c = (c - k) / (1.0 - k); m = (m - k) / (1.0 - k); y = (y - k) / (1.0 - k); diff --git a/src/gui/painting/qmatrix.h b/src/gui/painting/qmatrix.h index 71c1e34..1e5fbb4 100644 --- a/src/gui/painting/qmatrix.h +++ b/src/gui/painting/qmatrix.h @@ -99,7 +99,7 @@ public: QMatrix &shear(qreal sh, qreal sv); QMatrix &rotate(qreal a); - bool isInvertible() const { return !qIsFuzzyNull(_m11*_m22 - _m12*_m21); } + bool isInvertible() const { return !qFuzzyIsNull(_m11*_m22 - _m12*_m21); } qreal det() const { return _m11*_m22 - _m12*_m21; } QMatrix inverted(bool *invertible = 0) const; @@ -161,8 +161,8 @@ Q_GUI_EXPORT QPainterPath operator *(const QPainterPath &p, const QMatrix &m); inline bool QMatrix::isIdentity() const { - return qIsFuzzyNull(_m11 - 1) && qIsFuzzyNull(_m22 - 1) && qIsFuzzyNull(_m12) - && qIsFuzzyNull(_m21) && qIsFuzzyNull(_dx) && qIsFuzzyNull(_dy); + return qFuzzyIsNull(_m11 - 1) && qFuzzyIsNull(_m22 - 1) && qFuzzyIsNull(_m12) + && qFuzzyIsNull(_m21) && qFuzzyIsNull(_dx) && qFuzzyIsNull(_dy); } /***************************************************************************** diff --git a/src/gui/painting/qpaintengine_d3d.cpp b/src/gui/painting/qpaintengine_d3d.cpp index 4b494d1..9a7638b 100644 --- a/src/gui/painting/qpaintengine_d3d.cpp +++ b/src/gui/painting/qpaintengine_d3d.cpp @@ -2506,8 +2506,8 @@ void QD3DDrawHelper::addTrap(const Trapezoid &trap) qreal _rightA = (qreal)_w/_h; qreal _rightB = topRightX - _rightA * topRightY; - qreal invLeftA = qIsFuzzyNull(_leftA) ? 0.0 : 1.0 / _leftA; - qreal invRightA = qIsFuzzyNull(_rightA) ? 0.0 : 1.0 / _rightA; + qreal invLeftA = qFuzzyIsNull(_leftA) ? 0.0 : 1.0 / _leftA; + qreal invRightA = qFuzzyIsNull(_rightA) ? 0.0 : 1.0 / _rightA; vertex v1 = { {1.f, top - 1.f, 0.5f}, 0.f, top, bottom, invLeftA, -invRightA, @@ -2970,7 +2970,7 @@ qreal calculateAngle(qreal dx, qreal dy) { qreal angle; - if (qIsFuzzyNull(dx)) { + if (qFuzzyIsNull(dx)) { angle = (dy < 0) ? -M_PI/2 : M_PI/2; } else { angle = atanf(dy/dx); diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 7aab25c..92160f9 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -618,22 +618,22 @@ void QRasterPaintEngine::updateMatrix(const QTransform &matrix) d->isPlain45DegreeRotation = false; if (txop >= QTransform::TxRotate) { d->isPlain45DegreeRotation = - (qIsFuzzyNull(matrix.m11()) - && qIsFuzzyNull(matrix.m12() - qreal(1)) - && qIsFuzzyNull(matrix.m21() + qreal(1)) - && qIsFuzzyNull(matrix.m22()) + (qFuzzyIsNull(matrix.m11()) + && qFuzzyIsNull(matrix.m12() - qreal(1)) + && qFuzzyIsNull(matrix.m21() + qreal(1)) + && qFuzzyIsNull(matrix.m22()) ) || - (qIsFuzzyNull(matrix.m11() + qreal(1)) - && qIsFuzzyNull(matrix.m12()) - && qIsFuzzyNull(matrix.m21()) - && qIsFuzzyNull(matrix.m22() + qreal(1)) + (qFuzzyIsNull(matrix.m11() + qreal(1)) + && qFuzzyIsNull(matrix.m12()) + && qFuzzyIsNull(matrix.m21()) + && qFuzzyIsNull(matrix.m22() + qreal(1)) ) || - (qIsFuzzyNull(matrix.m11()) - && qIsFuzzyNull(matrix.m12() + qreal(1)) - && qIsFuzzyNull(matrix.m21() - qreal(1)) - && qIsFuzzyNull(matrix.m22()) + (qFuzzyIsNull(matrix.m11()) + && qFuzzyIsNull(matrix.m12() + qreal(1)) + && qFuzzyIsNull(matrix.m21() - qreal(1)) + && qFuzzyIsNull(matrix.m22()) ) ; } diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index d4271ae..133520e 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -6055,22 +6055,22 @@ void QPainter::drawTextItem(const QPointF &p, const QTextItem &_ti) const QTransform &m = d->state->matrix; if (d->state->matrix.type() < QTransform::TxShear) { bool isPlain90DegreeRotation = - (qIsFuzzyNull(m.m11()) - && qIsFuzzyNull(m.m12() - qreal(1)) - && qIsFuzzyNull(m.m21() + qreal(1)) - && qIsFuzzyNull(m.m22()) + (qFuzzyIsNull(m.m11()) + && qFuzzyIsNull(m.m12() - qreal(1)) + && qFuzzyIsNull(m.m21() + qreal(1)) + && qFuzzyIsNull(m.m22()) ) || - (qIsFuzzyNull(m.m11() + qreal(1)) - && qIsFuzzyNull(m.m12()) - && qIsFuzzyNull(m.m21()) - && qIsFuzzyNull(m.m22() + qreal(1)) + (qFuzzyIsNull(m.m11() + qreal(1)) + && qFuzzyIsNull(m.m12()) + && qFuzzyIsNull(m.m21()) + && qFuzzyIsNull(m.m22() + qreal(1)) ) || - (qIsFuzzyNull(m.m11()) - && qIsFuzzyNull(m.m12() + qreal(1)) - && qIsFuzzyNull(m.m21() - qreal(1)) - && qIsFuzzyNull(m.m22()) + (qFuzzyIsNull(m.m11()) + && qFuzzyIsNull(m.m12() + qreal(1)) + && qFuzzyIsNull(m.m21() - qreal(1)) + && qFuzzyIsNull(m.m22()) ) ; aa = !isPlain90DegreeRotation; diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index de8969c..d471aaa 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -1299,10 +1299,10 @@ static QRectF qt_painterpath_bezier_extrema(const QBezier &b) qreal bx = QT_BEZIER_B(b, x); qreal cx = QT_BEZIER_C(b, x); // specialcase quadratic curves to avoid div by zero - if (qIsFuzzyNull(ax)) { + if (qFuzzyIsNull(ax)) { // linear curves are covered by initialization. - if (!qIsFuzzyNull(bx)) { + if (!qFuzzyIsNull(bx)) { qreal t = -cx / bx; QT_BEZIER_CHECK_T(b, t); } @@ -1329,10 +1329,10 @@ static QRectF qt_painterpath_bezier_extrema(const QBezier &b) qreal cy = QT_BEZIER_C(b, y); // specialcase quadratic curves to avoid div by zero - if (qIsFuzzyNull(ay)) { + if (qFuzzyIsNull(ay)) { // linear curves are covered by initialization. - if (!qIsFuzzyNull(by)) { + if (!qFuzzyIsNull(by)) { qreal t = -cy / by; QT_BEZIER_CHECK_T(b, t); } diff --git a/src/gui/painting/qpathclipper.cpp b/src/gui/painting/qpathclipper.cpp index 33609ad..9ef3eb7 100644 --- a/src/gui/painting/qpathclipper.cpp +++ b/src/gui/painting/qpathclipper.cpp @@ -138,11 +138,11 @@ bool QIntersectionFinder::linesIntersect(const QLineF &a, const QLineF &b) const const qreal par = pDelta.x() * qDelta.y() - pDelta.y() * qDelta.x(); - if (qIsFuzzyNull(par)) { + if (qFuzzyIsNull(par)) { const QPointF normal(-pDelta.y(), pDelta.x()); // coinciding? - if (qIsFuzzyNull(dot(normal, q1 - p1))) { + if (qFuzzyIsNull(dot(normal, q1 - p1))) { const qreal dp = dot(pDelta, pDelta); const qreal tq1 = dot(pDelta, q1 - p1); @@ -202,13 +202,13 @@ void QIntersectionFinder::intersectBeziers(const QBezier &one, const QBezier &tw qreal alpha_q = t.at(i).second; QPointF pt; - if (qIsFuzzyNull(alpha_p)) { + if (qFuzzyIsNull(alpha_p)) { pt = one.pt1(); - } else if (qIsFuzzyNull(alpha_p - 1)) { + } else if (qFuzzyIsNull(alpha_p - 1)) { pt = one.pt4(); - } else if (qIsFuzzyNull(alpha_q)) { + } else if (qFuzzyIsNull(alpha_q)) { pt = two.pt1(); - } else if (qIsFuzzyNull(alpha_q - 1)) { + } else if (qFuzzyIsNull(alpha_q - 1)) { pt = two.pt4(); } else { pt = one.pointAt(alpha_p); @@ -250,11 +250,11 @@ void QIntersectionFinder::intersectLines(const QLineF &a, const QLineF &b, QData const qreal par = pDelta.x() * qDelta.y() - pDelta.y() * qDelta.x(); - if (qIsFuzzyNull(par)) { + if (qFuzzyIsNull(par)) { const QPointF normal(-pDelta.y(), pDelta.x()); // coinciding? - if (qIsFuzzyNull(dot(normal, q1 - p1))) { + if (qFuzzyIsNull(dot(normal, q1 - p1))) { const qreal invDp = 1 / dot(pDelta, pDelta); const qreal tq1 = dot(pDelta, q1 - p1) * invDp; @@ -315,11 +315,11 @@ void QIntersectionFinder::intersectLines(const QLineF &a, const QLineF &b, QData if (tp<0 || tp>1 || tq<0 || tq>1) return; - const bool p_zero = qIsFuzzyNull(tp); - const bool p_one = qIsFuzzyNull(tp - 1); + const bool p_zero = qFuzzyIsNull(tp); + const bool p_one = qFuzzyIsNull(tp - 1); - const bool q_zero = qIsFuzzyNull(tq); - const bool q_one = qIsFuzzyNull(tq - 1); + const bool q_zero = qFuzzyIsNull(tq); + const bool q_one = qFuzzyIsNull(tq - 1); if ((q_zero || q_one) && (p_zero || p_one)) return; @@ -922,7 +922,7 @@ qreal QWingedEdge::delta(int vertex, int a, int b) const qreal result = b_angle - a_angle; - if (qIsFuzzyNull(result) || qFuzzyCompare(result, 128)) + if (qFuzzyIsNull(result) || qFuzzyCompare(result, 128)) return 0; if (result < 0) @@ -951,7 +951,7 @@ static inline QPointF tangentAt(const QWingedEdge &list, int vi, int ei) if (ep->bezier) { normal = ep->bezier->derivedAt(t); - if (qIsFuzzyNull(normal.x()) && qIsFuzzyNull(normal.y())) + if (qFuzzyIsNull(normal.x()) && qFuzzyIsNull(normal.y())) normal = ep->bezier->secondDerivedAt(t); } else { const QPointF a = *list.vertex(ep->first); @@ -1080,7 +1080,7 @@ QWingedEdge::TraversalStatus QWingedEdge::findInsertStatus(int vi, int ei) const qDebug() << "Delta to edge" << status.edge << d2 << ", angles: " << op->angle << op->invAngle; #endif - if (!(qIsFuzzyNull(d2) && isLeftOf(*this, vi, status.edge, ei)) + if (!(qFuzzyIsNull(d2) && isLeftOf(*this, vi, status.edge, ei)) && (d2 < d || (qFuzzyCompare(d2, d) && isLeftOf(*this, vi, status.edge, position)))) { position = status.edge; d = d2; @@ -1232,10 +1232,10 @@ int QWingedEdge::addEdge(int fi, int si, const QBezier *bezier, qreal t0, qreal QPointF aTangent = bezier->derivedAt(t0); QPointF bTangent = -bezier->derivedAt(t1); - if (qIsFuzzyNull(aTangent.x()) && qIsFuzzyNull(aTangent.y())) + if (qFuzzyIsNull(aTangent.x()) && qFuzzyIsNull(aTangent.y())) aTangent = bezier->secondDerivedAt(t0); - if (qIsFuzzyNull(bTangent.x()) && qIsFuzzyNull(bTangent.y())) + if (qFuzzyIsNull(bTangent.x()) && qFuzzyIsNull(bTangent.y())) bTangent = bezier->secondDerivedAt(t1); ep->angle = computeAngle(aTangent); @@ -1400,7 +1400,7 @@ static void addLineTo(QPainterPath &path, const QPointF &point) const QPointF p(-d1.y(), d1.x()); - if (qIsFuzzyNull(dot(p, d2))) { + if (qFuzzyIsNull(dot(p, d2))) { path.setElementPositionAt(elementCount - 1, point.x(), point.y()); return; } diff --git a/src/gui/painting/qstroker.cpp b/src/gui/painting/qstroker.cpp index 3a856d3..5fffc72 100644 --- a/src/gui/painting/qstroker.cpp +++ b/src/gui/painting/qstroker.cpp @@ -763,7 +763,7 @@ template bool qt_stroke_side(Iterator *it, qreal qt_t_for_arc_angle(qreal angle) { - if (qIsFuzzyNull(angle)) + if (qFuzzyIsNull(angle)) return 0; if (qFuzzyCompare(angle, qreal(90))) @@ -904,13 +904,13 @@ QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLengt } // avoid empty start segment - if (qIsFuzzyNull(startT - qreal(1))) { + if (qFuzzyIsNull(startT - qreal(1))) { startT = 0; startSegment += delta; } // avoid empty end segment - if (qIsFuzzyNull(endT)) { + if (qFuzzyIsNull(endT)) { endT = 1; endSegment -= delta; } @@ -918,8 +918,8 @@ QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLengt startT = qt_t_for_arc_angle(startT * 90); endT = qt_t_for_arc_angle(endT * 90); - const bool splitAtStart = !qIsFuzzyNull(startT); - const bool splitAtEnd = !qIsFuzzyNull(endT - qreal(1)); + const bool splitAtStart = !qFuzzyIsNull(startT); + const bool splitAtEnd = !qFuzzyIsNull(endT - qreal(1)); const int end = endSegment + delta; @@ -1018,7 +1018,7 @@ void QDashStroker::processCurrentSubpath() sumLength += dashes[i]; } - if (qIsFuzzyNull(sumLength)) + if (qFuzzyIsNull(sumLength)) return; Q_ASSERT(dashCount > 0); diff --git a/src/gui/painting/qtessellator.cpp b/src/gui/painting/qtessellator.cpp index ae07565..ce5ab74 100644 --- a/src/gui/painting/qtessellator.cpp +++ b/src/gui/painting/qtessellator.cpp @@ -1436,7 +1436,7 @@ void QTessellator::tessellateRect(const QPointF &a_, const QPointF &b_, qreal wi QPointF perp(pb.y() - pa.y(), pa.x() - pb.x()); qreal length = qSqrt(perp.x() * perp.x() + perp.y() * perp.y()); - if (qIsFuzzyNull(length)) + if (qFuzzyIsNull(length)) return; // need the half of the width diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index 6c37ab6..dfcca63 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -353,8 +353,8 @@ QTransform QTransform::inverted(bool *invertible) const invert.affine._dy = -affine._dy; break; case TxScale: - inv = !qIsFuzzyNull(affine._m11); - inv &= !qIsFuzzyNull(affine._m22); + inv = !qFuzzyIsNull(affine._m11); + inv &= !qFuzzyIsNull(affine._m22); if (inv) { invert.affine._m11 = 1. / affine._m11; invert.affine._m22 = 1. / affine._m22; @@ -369,7 +369,7 @@ QTransform QTransform::inverted(bool *invertible) const default: // general case qreal det = determinant(); - inv = !qIsFuzzyNull(det); + inv = !qFuzzyIsNull(det); if (inv) invert = adjoint() / det; break; @@ -1958,27 +1958,27 @@ QTransform::TransformationType QTransform::type() const switch (static_cast(m_dirty)) { case TxProject: - if (!qIsFuzzyNull(m_13) || !qIsFuzzyNull(m_23) || !qIsFuzzyNull(m_33 - 1)) { + if (!qFuzzyIsNull(m_13) || !qFuzzyIsNull(m_23) || !qFuzzyIsNull(m_33 - 1)) { m_type = TxProject; break; } case TxShear: case TxRotate: - if (!qIsFuzzyNull(affine._m12) || !qIsFuzzyNull(affine._m21)) { + if (!qFuzzyIsNull(affine._m12) || !qFuzzyIsNull(affine._m21)) { const qreal dot = affine._m11 * affine._m12 + affine._m21 * affine._m22; - if (qIsFuzzyNull(dot)) + if (qFuzzyIsNull(dot)) m_type = TxRotate; else m_type = TxShear; break; } case TxScale: - if (!qIsFuzzyNull(affine._m11 - 1) || !qIsFuzzyNull(affine._m22 - 1)) { + if (!qFuzzyIsNull(affine._m11 - 1) || !qFuzzyIsNull(affine._m22 - 1)) { m_type = TxScale; break; } case TxTranslate: - if (!qIsFuzzyNull(affine._dx) || !qIsFuzzyNull(affine._dy)) { + if (!qFuzzyIsNull(affine._dx) || !qFuzzyIsNull(affine._dy)) { m_type = TxTranslate; break; } diff --git a/src/gui/painting/qtransform.h b/src/gui/painting/qtransform.h index 2d6c889..aac7c31 100644 --- a/src/gui/painting/qtransform.h +++ b/src/gui/painting/qtransform.h @@ -204,7 +204,7 @@ inline bool QTransform::isIdentity() const inline bool QTransform::isInvertible() const { - return !qIsFuzzyNull(determinant()); + return !qFuzzyIsNull(determinant()); } inline bool QTransform::isScaling() const diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp index 11df590..4afc621 100644 --- a/src/opengl/qpaintengine_opengl.cpp +++ b/src/opengl/qpaintengine_opengl.cpp @@ -1924,15 +1924,15 @@ static void drawTrapezoid(const QGLTrapezoid &trap, const qreal offscreenHeight, qreal leftB = trap.bottomLeftX + (trap.topLeftX - trap.bottomLeftX) * reciprocal; qreal rightB = trap.bottomRightX + (trap.topRightX - trap.bottomRightX) * reciprocal; - const bool topZero = qIsFuzzyNull(topDist); + const bool topZero = qFuzzyIsNull(topDist); reciprocal = topZero ? 1.0 / bottomDist : 1.0 / topDist; qreal leftA = topZero ? (trap.bottomLeftX - leftB) * reciprocal : (trap.topLeftX - leftB) * reciprocal; qreal rightA = topZero ? (trap.bottomRightX - rightB) * reciprocal : (trap.topRightX - rightB) * reciprocal; - qreal invLeftA = qIsFuzzyNull(leftA) ? 0.0 : 1.0 / leftA; - qreal invRightA = qIsFuzzyNull(rightA) ? 0.0 : 1.0 / rightA; + qreal invLeftA = qFuzzyIsNull(leftA) ? 0.0 : 1.0 / leftA; + qreal invRightA = qFuzzyIsNull(rightA) ? 0.0 : 1.0 / rightA; // fragment program needs the negative of invRightA as it mirrors the line glTexCoord4f(topDist, bottomDist, invLeftA, -invRightA); @@ -3445,7 +3445,7 @@ QVector QGLRectMaskGenerator::generateTrapezoids() // manhattan distance (no rotation) qreal width = qAbs(delta.x()) + qAbs(delta.y()); - Q_ASSERT(qIsFuzzyNull(delta.x()) || qIsFuzzyNull(delta.y())); + Q_ASSERT(qFuzzyIsNull(delta.x()) || qFuzzyIsNull(delta.y())); tessellator.tessellateRect(first, last, width); } else { diff --git a/src/svg/qgraphicssvgitem.cpp b/src/svg/qgraphicssvgitem.cpp index 5c8a3c0..a14636e 100644 --- a/src/svg/qgraphicssvgitem.cpp +++ b/src/svg/qgraphicssvgitem.cpp @@ -186,7 +186,7 @@ static void qt_graphicsItem_highlightSelected( QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option) { const QRectF murect = painter->transform().mapRect(QRectF(0, 0, 1, 1)); - if (qIsFuzzyNull(qMax(murect.width(), murect.height()))) + if (qFuzzyIsNull(qMax(murect.width(), murect.height()))) return; const QRectF mbrect = painter->transform().mapRect(item->boundingRect()); diff --git a/src/svg/qsvggenerator.cpp b/src/svg/qsvggenerator.cpp index 7c8926d..2b5fbd5 100644 --- a/src/svg/qsvggenerator.cpp +++ b/src/svg/qsvggenerator.cpp @@ -971,7 +971,7 @@ void QSvgPaintEngine::updateState(const QPaintEngineState &state) } if (flags & QPaintEngine::DirtyOpacity) { - if (!qIsFuzzyNull(state.opacity() - 1)) + if (!qFuzzyIsNull(state.opacity() - 1)) stream() << "opacity=\""< Date: Wed, 8 Apr 2009 13:02:19 +0200 Subject: Refactor the palette and opacity change into a separate function. We can save on some creation and only show the container when we really need to. It does mean that we need to ensure that everything is correct on construction as well. It's now factored into another file. Reviewed-by: Jens Bache-Wiig --- src/gui/widgets/qcombobox.cpp | 37 +++++++++++++++++++++++-------------- src/gui/widgets/qcombobox_p.h | 1 + 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index 09a51fe..f30ece4 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -949,6 +949,7 @@ QComboBoxPrivateContainer* QComboBoxPrivate::viewContainer() container->itemView()->setTextElideMode(Qt::ElideMiddle); updateDelegate(); updateLayoutDirection(); + updateViewContainerPaletteAndOpacity(); QObject::connect(container, SIGNAL(itemSelected(QModelIndex)), q, SLOT(_q_itemSelected(QModelIndex))); QObject::connect(container->itemView()->selectionModel(), @@ -1051,6 +1052,27 @@ void QComboBoxPrivate::_q_rowsRemoved(const QModelIndex &parent, int /*start*/, } +void QComboBoxPrivate::updateViewContainerPaletteAndOpacity() +{ + if (!container) + return; + Q_Q(QComboBox); + QStyleOptionComboBox opt; + q->initStyleOption(&opt); +#ifndef QT_NO_MENU + if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) { + QMenu menu; + menu.ensurePolished(); + container->setPalette(menu.palette()); + container->setWindowOpacity(menu.windowOpacity()); + } else +#endif + { + container->setPalette(q->palette()); + container->setWindowOpacity(1.0); + } +} + /*! Initialize \a option with the values from this QComboBox. This method is useful for subclasses when they need a QStyleOptionComboBox, but don't want @@ -2572,20 +2594,7 @@ void QComboBox::changeEvent(QEvent *e) hidePopup(); break; case QEvent::PaletteChange: { - QStyleOptionComboBox opt; - initStyleOption(&opt); -#ifndef QT_NO_MENU - if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) { - QMenu menu; - menu.ensurePolished(); - d->viewContainer()->setPalette(menu.palette()); - d->viewContainer()->setWindowOpacity(menu.windowOpacity()); - } else -#endif - { - d->viewContainer()->setPalette(palette()); - d->viewContainer()->setWindowOpacity(1.0); - } + d->updateViewContainerPaletteAndOpacity(); break; } case QEvent::FontChange: diff --git a/src/gui/widgets/qcombobox_p.h b/src/gui/widgets/qcombobox_p.h index c39a231..a0b76cf 100644 --- a/src/gui/widgets/qcombobox_p.h +++ b/src/gui/widgets/qcombobox_p.h @@ -370,6 +370,7 @@ public: void updateDelegate(); void keyboardSearchString(const QString &text); void modelChanged(); + void updateViewContainerPaletteAndOpacity(); QAbstractItemModel *model; QLineEdit *lineEdit; -- cgit v0.12 From 8da880e77db04cc4509e0f48e0b5b1d6265da223 Mon Sep 17 00:00:00 2001 From: Prasanth Ullattil Date: Wed, 8 Apr 2009 13:43:39 +0200 Subject: =?UTF-8?q?QTextEdit=20character=20are=20lost=20after=20special=20?= =?UTF-8?q?characters=20like=20^=20=C2=B4=20`=20This=20happens=20only=20on?= =?UTF-8?q?=20keyboard=20layouts=20like=20French.=20The=20is=20mainly=20du?= =?UTF-8?q?e=20to=20the=20key=20event=20processing=20done=20by=20the=20Inp?= =?UTF-8?q?ut=20manager.=20In=20carbon,=20the=20key=20down=20event=20has?= =?UTF-8?q?=20to=20be=20replayed=20after=20the=20input=20manager=20finishe?= =?UTF-8?q?s=20his=20processing.=20In=20Cocoa,=20while=20unmarking=20we=20?= =?UTF-8?q?have=20to=20accept=20the=20current=20text.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: 123740 Reviewed-by: nrc --- src/gui/inputmethod/qmacinputcontext_mac.cpp | 20 +++++++++++++++++++- src/gui/inputmethod/qmacinputcontext_p.h | 5 +++++ src/gui/kernel/qcocoaview_mac.mm | 14 +++++++++++++- src/gui/kernel/qcocoaview_mac_p.h | 1 + src/gui/kernel/qkeymapper_mac.cpp | 15 ++++++++++++--- 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/gui/inputmethod/qmacinputcontext_mac.cpp b/src/gui/inputmethod/qmacinputcontext_mac.cpp index f0e7ea9..86385fa 100644 --- a/src/gui/inputmethod/qmacinputcontext_mac.cpp +++ b/src/gui/inputmethod/qmacinputcontext_mac.cpp @@ -45,6 +45,7 @@ #include "qtextformat.h" #include #include +#include QT_BEGIN_NAMESPACE @@ -63,7 +64,8 @@ static QTextFormat qt_mac_compose_format() } QMacInputContext::QMacInputContext(QObject *parent) - : QInputContext(parent), composing(false), recursionGuard(false), textDocument(0) + : QInputContext(parent), composing(false), recursionGuard(false), textDocument(0), + keydownEvent(0) { // createTextDocument(); } @@ -183,6 +185,16 @@ QMacInputContext::cleanup() #endif } +void QMacInputContext::setLastKeydownEvent(EventRef event) +{ + EventRef tmpEvent = keydownEvent; + keydownEvent = event; + if (keydownEvent) + RetainEvent(keydownEvent); + if (tmpEvent) + ReleaseEvent(tmpEvent); +} + OSStatus QMacInputContext::globalEventProcessor(EventHandlerCallRef, EventRef event, void *) { @@ -335,6 +347,12 @@ QMacInputContext::globalEventProcessor(EventHandlerCallRef, EventRef event, void GetEventParameter(key_ev, kEventParamKeyMacCharCodes, typeChar, 0, sizeof(chr), 0, &chr); if(!chr || chr >= 128 || (text.length() > 0 && (text.length() > 1 || text.at(0) != QLatin1Char(chr)))) handled_event = !widget->testAttribute(Qt::WA_InputMethodEnabled); + QMacInputContext *context = qobject_cast(qApp->inputContext()); + if (context && context->lastKeydownEvent()) { + qt_keymapper_private()->translateKeyEvent(widget, 0, context->lastKeydownEvent(), + 0, false); + context->setLastKeydownEvent(0); + } } break; } default: diff --git a/src/gui/inputmethod/qmacinputcontext_p.h b/src/gui/inputmethod/qmacinputcontext_p.h index f708040..c3f245a 100644 --- a/src/gui/inputmethod/qmacinputcontext_p.h +++ b/src/gui/inputmethod/qmacinputcontext_p.h @@ -78,6 +78,10 @@ public: static OSStatus globalEventProcessor(EventHandlerCallRef, EventRef, void *); static void initialize(); static void cleanup(); + + EventRef lastKeydownEvent() { return keydownEvent; } + void setLastKeydownEvent(EventRef); + protected: void mouseHandler(int pos, QMouseEvent *); private: @@ -85,6 +89,7 @@ private: bool recursionGuard; TSMDocumentID textDocument; QString currentText; + EventRef keydownEvent; }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index 19367d1..2d6f5ad 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -195,6 +195,7 @@ extern "C" { if (self) { [self finishInitWithQWidget:widget widgetPrivate:widgetprivate]; } + composingText = new QString(); composing = false; sendKeyEvents = true; [self setHidden:YES]; @@ -364,6 +365,7 @@ extern "C" { - (void)dealloc { + delete composingText; [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; } @@ -917,7 +919,7 @@ extern "C" { - (void) insertText:(id)aString { - if (composing) { + if ([aString length]) { // Send the commit string to the widget. QString commitText; if ([aString isKindOfClass:[NSAttributedString class]]) { @@ -931,6 +933,7 @@ extern "C" { e.setCommitString(commitText); qt_sendSpontaneousEvent(qwidget, &e); } + composingText->clear(); } - (void) setMarkedText:(id)aString selectedRange:(NSRange)selRange @@ -984,12 +987,21 @@ extern "C" { attrs<clear(); composing = false; } diff --git a/src/gui/kernel/qcocoaview_mac_p.h b/src/gui/kernel/qcocoaview_mac_p.h index 9de94d5..ec1281e 100644 --- a/src/gui/kernel/qcocoaview_mac_p.h +++ b/src/gui/kernel/qcocoaview_mac_p.h @@ -83,6 +83,7 @@ Q_GUI_EXPORT bool composing; int composingLength; bool sendKeyEvents; + QString *composingText; } - (id)initWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate; - (void) finishInitWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate; diff --git a/src/gui/kernel/qkeymapper_mac.cpp b/src/gui/kernel/qkeymapper_mac.cpp index 1a0fb08..39abc5e 100644 --- a/src/gui/kernel/qkeymapper_mac.cpp +++ b/src/gui/kernel/qkeymapper_mac.cpp @@ -48,6 +48,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -480,7 +481,8 @@ static bool translateKeyEventInternal(EventHandlerCallRef er, EventRef keyEvent, #ifdef QT_MAC_USE_COCOA if (outHandled) { qt_mac_eat_unicode_key = false; - CallNextEventHandler(er, keyEvent); + if (er) + CallNextEventHandler(er, keyEvent); *outHandled = qt_mac_eat_unicode_key; } #endif @@ -692,8 +694,14 @@ bool QKeyMapperPrivate::translateKeyEvent(QWidget *widget, EventHandlerCallRef e return true; } - if (qApp->inputContext() && qApp->inputContext()->isComposing()) + if (qApp->inputContext() && qApp->inputContext()->isComposing()) { + if (ekind == kEventRawKeyDown) { + QMacInputContext *context = qobject_cast(qApp->inputContext()); + if (context) + context->setLastKeydownEvent(event); + } return false; + } //get modifiers Qt::KeyboardModifiers modifiers; int qtKey; @@ -721,7 +729,8 @@ bool QKeyMapperPrivate::translateKeyEvent(QWidget *widget, EventHandlerCallRef e //is it of use to text services? If so we won't bother //with a QKeyEvent. qt_mac_eat_unicode_key = false; - CallNextEventHandler(er, event); + if (er) + CallNextEventHandler(er, event); extern bool qt_mac_menubar_is_open(); if (qt_mac_eat_unicode_key || qt_mac_menubar_is_open()) { return true; -- cgit v0.12