equal
deleted
inserted
replaced
1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the test suite of the Qt Toolkit. |
7 ** This file is part of the test suite of the Qt Toolkit. |
8 ** |
8 ** |
43 #include <QtCore/qmath.h> |
43 #include <QtCore/qmath.h> |
44 #include <QtGui/qvector2d.h> |
44 #include <QtGui/qvector2d.h> |
45 #include <QtGui/qvector3d.h> |
45 #include <QtGui/qvector3d.h> |
46 #include <QtGui/qvector4d.h> |
46 #include <QtGui/qvector4d.h> |
47 |
47 |
48 class tst_QVector : public QObject |
48 class tst_QVectorND : public QObject |
49 { |
49 { |
50 Q_OBJECT |
50 Q_OBJECT |
51 public: |
51 public: |
52 tst_QVector() {} |
52 tst_QVectorND() {} |
53 ~tst_QVector() {} |
53 ~tst_QVectorND() {} |
54 |
54 |
55 private slots: |
55 private slots: |
56 void create2(); |
56 void create2(); |
57 void create3(); |
57 void create3(); |
58 void create4(); |
58 void create4(); |
153 return qFuzzyIsNull((float)(x - y)); |
153 return qFuzzyIsNull((float)(x - y)); |
154 } |
154 } |
155 |
155 |
156 // Test the creation of QVector2D objects in various ways: |
156 // Test the creation of QVector2D objects in various ways: |
157 // construct, copy, and modify. |
157 // construct, copy, and modify. |
158 void tst_QVector::create2() |
158 void tst_QVectorND::create2() |
159 { |
159 { |
160 QVector2D null; |
160 QVector2D null; |
161 QCOMPARE(null.x(), (qreal)0.0f); |
161 QCOMPARE(null.x(), (qreal)0.0f); |
162 QCOMPARE(null.y(), (qreal)0.0f); |
162 QCOMPARE(null.y(), (qreal)0.0f); |
163 QVERIFY(null.isNull()); |
163 QVERIFY(null.isNull()); |
242 QCOMPARE(v10.w(), (qreal)0.0f); |
242 QCOMPARE(v10.w(), (qreal)0.0f); |
243 } |
243 } |
244 |
244 |
245 // Test the creation of QVector3D objects in various ways: |
245 // Test the creation of QVector3D objects in various ways: |
246 // construct, copy, and modify. |
246 // construct, copy, and modify. |
247 void tst_QVector::create3() |
247 void tst_QVectorND::create3() |
248 { |
248 { |
249 QVector3D null; |
249 QVector3D null; |
250 QCOMPARE(null.x(), (qreal)0.0f); |
250 QCOMPARE(null.x(), (qreal)0.0f); |
251 QCOMPARE(null.y(), (qreal)0.0f); |
251 QCOMPARE(null.y(), (qreal)0.0f); |
252 QCOMPARE(null.z(), (qreal)0.0f); |
252 QCOMPARE(null.z(), (qreal)0.0f); |
368 QCOMPARE(v11.w(), (qreal)0.0f); |
368 QCOMPARE(v11.w(), (qreal)0.0f); |
369 } |
369 } |
370 |
370 |
371 // Test the creation of QVector4D objects in various ways: |
371 // Test the creation of QVector4D objects in various ways: |
372 // construct, copy, and modify. |
372 // construct, copy, and modify. |
373 void tst_QVector::create4() |
373 void tst_QVectorND::create4() |
374 { |
374 { |
375 QVector4D null; |
375 QVector4D null; |
376 QCOMPARE(null.x(), (qreal)0.0f); |
376 QCOMPARE(null.x(), (qreal)0.0f); |
377 QCOMPARE(null.y(), (qreal)0.0f); |
377 QCOMPARE(null.y(), (qreal)0.0f); |
378 QCOMPARE(null.z(), (qreal)0.0f); |
378 QCOMPARE(null.z(), (qreal)0.0f); |
554 v14 = zerow.toVector3DAffine(); |
554 v14 = zerow.toVector3DAffine(); |
555 QVERIFY(v14.isNull()); |
555 QVERIFY(v14.isNull()); |
556 } |
556 } |
557 |
557 |
558 // Test vector length computation for 2D vectors. |
558 // Test vector length computation for 2D vectors. |
559 void tst_QVector::length2_data() |
559 void tst_QVectorND::length2_data() |
560 { |
560 { |
561 QTest::addColumn<qreal>("x"); |
561 QTest::addColumn<qreal>("x"); |
562 QTest::addColumn<qreal>("y"); |
562 QTest::addColumn<qreal>("y"); |
563 QTest::addColumn<qreal>("len"); |
563 QTest::addColumn<qreal>("len"); |
564 |
564 |
567 QTest::newRow("1y") << (qreal)0.0f << (qreal)1.0f << (qreal)1.0f; |
567 QTest::newRow("1y") << (qreal)0.0f << (qreal)1.0f << (qreal)1.0f; |
568 QTest::newRow("-1x") << (qreal)-1.0f << (qreal)0.0f << (qreal)1.0f; |
568 QTest::newRow("-1x") << (qreal)-1.0f << (qreal)0.0f << (qreal)1.0f; |
569 QTest::newRow("-1y") << (qreal)0.0f << (qreal)-1.0f << (qreal)1.0f; |
569 QTest::newRow("-1y") << (qreal)0.0f << (qreal)-1.0f << (qreal)1.0f; |
570 QTest::newRow("two") << (qreal)2.0f << (qreal)-2.0f << (qreal)qSqrt(8.0f); |
570 QTest::newRow("two") << (qreal)2.0f << (qreal)-2.0f << (qreal)qSqrt(8.0f); |
571 } |
571 } |
572 void tst_QVector::length2() |
572 void tst_QVectorND::length2() |
573 { |
573 { |
574 QFETCH(qreal, x); |
574 QFETCH(qreal, x); |
575 QFETCH(qreal, y); |
575 QFETCH(qreal, y); |
576 QFETCH(qreal, len); |
576 QFETCH(qreal, len); |
577 |
577 |
579 QCOMPARE(v.length(), len); |
579 QCOMPARE(v.length(), len); |
580 QCOMPARE(v.lengthSquared(), x * x + y * y); |
580 QCOMPARE(v.lengthSquared(), x * x + y * y); |
581 } |
581 } |
582 |
582 |
583 // Test vector length computation for 3D vectors. |
583 // Test vector length computation for 3D vectors. |
584 void tst_QVector::length3_data() |
584 void tst_QVectorND::length3_data() |
585 { |
585 { |
586 QTest::addColumn<qreal>("x"); |
586 QTest::addColumn<qreal>("x"); |
587 QTest::addColumn<qreal>("y"); |
587 QTest::addColumn<qreal>("y"); |
588 QTest::addColumn<qreal>("z"); |
588 QTest::addColumn<qreal>("z"); |
589 QTest::addColumn<qreal>("len"); |
589 QTest::addColumn<qreal>("len"); |
595 QTest::newRow("-1x") << (qreal)-1.0f << (qreal)0.0f << (qreal)0.0f << (qreal)1.0f; |
595 QTest::newRow("-1x") << (qreal)-1.0f << (qreal)0.0f << (qreal)0.0f << (qreal)1.0f; |
596 QTest::newRow("-1y") << (qreal)0.0f << (qreal)-1.0f << (qreal)0.0f << (qreal)1.0f; |
596 QTest::newRow("-1y") << (qreal)0.0f << (qreal)-1.0f << (qreal)0.0f << (qreal)1.0f; |
597 QTest::newRow("-1z") << (qreal)0.0f << (qreal)0.0f << (qreal)-1.0f << (qreal)1.0f; |
597 QTest::newRow("-1z") << (qreal)0.0f << (qreal)0.0f << (qreal)-1.0f << (qreal)1.0f; |
598 QTest::newRow("two") << (qreal)2.0f << (qreal)-2.0f << (qreal)2.0f << (qreal)qSqrt(12.0f); |
598 QTest::newRow("two") << (qreal)2.0f << (qreal)-2.0f << (qreal)2.0f << (qreal)qSqrt(12.0f); |
599 } |
599 } |
600 void tst_QVector::length3() |
600 void tst_QVectorND::length3() |
601 { |
601 { |
602 QFETCH(qreal, x); |
602 QFETCH(qreal, x); |
603 QFETCH(qreal, y); |
603 QFETCH(qreal, y); |
604 QFETCH(qreal, z); |
604 QFETCH(qreal, z); |
605 QFETCH(qreal, len); |
605 QFETCH(qreal, len); |
608 QCOMPARE(v.length(), len); |
608 QCOMPARE(v.length(), len); |
609 QCOMPARE(v.lengthSquared(), x * x + y * y + z * z); |
609 QCOMPARE(v.lengthSquared(), x * x + y * y + z * z); |
610 } |
610 } |
611 |
611 |
612 // Test vector length computation for 4D vectors. |
612 // Test vector length computation for 4D vectors. |
613 void tst_QVector::length4_data() |
613 void tst_QVectorND::length4_data() |
614 { |
614 { |
615 QTest::addColumn<qreal>("x"); |
615 QTest::addColumn<qreal>("x"); |
616 QTest::addColumn<qreal>("y"); |
616 QTest::addColumn<qreal>("y"); |
617 QTest::addColumn<qreal>("z"); |
617 QTest::addColumn<qreal>("z"); |
618 QTest::addColumn<qreal>("w"); |
618 QTest::addColumn<qreal>("w"); |
627 QTest::newRow("-1y") << (qreal)0.0f << (qreal)-1.0f << (qreal)0.0f << (qreal)0.0f << (qreal)1.0f; |
627 QTest::newRow("-1y") << (qreal)0.0f << (qreal)-1.0f << (qreal)0.0f << (qreal)0.0f << (qreal)1.0f; |
628 QTest::newRow("-1z") << (qreal)0.0f << (qreal)0.0f << (qreal)-1.0f << (qreal)0.0f << (qreal)1.0f; |
628 QTest::newRow("-1z") << (qreal)0.0f << (qreal)0.0f << (qreal)-1.0f << (qreal)0.0f << (qreal)1.0f; |
629 QTest::newRow("-1w") << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f << (qreal)-1.0f << (qreal)1.0f; |
629 QTest::newRow("-1w") << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f << (qreal)-1.0f << (qreal)1.0f; |
630 QTest::newRow("two") << (qreal)2.0f << (qreal)-2.0f << (qreal)2.0f << (qreal)2.0f << (qreal)qSqrt(16.0f); |
630 QTest::newRow("two") << (qreal)2.0f << (qreal)-2.0f << (qreal)2.0f << (qreal)2.0f << (qreal)qSqrt(16.0f); |
631 } |
631 } |
632 void tst_QVector::length4() |
632 void tst_QVectorND::length4() |
633 { |
633 { |
634 QFETCH(qreal, x); |
634 QFETCH(qreal, x); |
635 QFETCH(qreal, y); |
635 QFETCH(qreal, y); |
636 QFETCH(qreal, z); |
636 QFETCH(qreal, z); |
637 QFETCH(qreal, w); |
637 QFETCH(qreal, w); |
641 QCOMPARE(v.length(), len); |
641 QCOMPARE(v.length(), len); |
642 QCOMPARE(v.lengthSquared(), x * x + y * y + z * z + w * w); |
642 QCOMPARE(v.lengthSquared(), x * x + y * y + z * z + w * w); |
643 } |
643 } |
644 |
644 |
645 // Test the unit vector conversion for 2D vectors. |
645 // Test the unit vector conversion for 2D vectors. |
646 void tst_QVector::normalized2_data() |
646 void tst_QVectorND::normalized2_data() |
647 { |
647 { |
648 // Use the same test data as the length test. |
648 // Use the same test data as the length test. |
649 length2_data(); |
649 length2_data(); |
650 } |
650 } |
651 void tst_QVector::normalized2() |
651 void tst_QVectorND::normalized2() |
652 { |
652 { |
653 QFETCH(qreal, x); |
653 QFETCH(qreal, x); |
654 QFETCH(qreal, y); |
654 QFETCH(qreal, y); |
655 QFETCH(qreal, len); |
655 QFETCH(qreal, len); |
656 |
656 |
663 QVERIFY(fuzzyCompare(u.x() * len, v.x())); |
663 QVERIFY(fuzzyCompare(u.x() * len, v.x())); |
664 QVERIFY(fuzzyCompare(u.y() * len, v.y())); |
664 QVERIFY(fuzzyCompare(u.y() * len, v.y())); |
665 } |
665 } |
666 |
666 |
667 // Test the unit vector conversion for 3D vectors. |
667 // Test the unit vector conversion for 3D vectors. |
668 void tst_QVector::normalized3_data() |
668 void tst_QVectorND::normalized3_data() |
669 { |
669 { |
670 // Use the same test data as the length test. |
670 // Use the same test data as the length test. |
671 length3_data(); |
671 length3_data(); |
672 } |
672 } |
673 void tst_QVector::normalized3() |
673 void tst_QVectorND::normalized3() |
674 { |
674 { |
675 QFETCH(qreal, x); |
675 QFETCH(qreal, x); |
676 QFETCH(qreal, y); |
676 QFETCH(qreal, y); |
677 QFETCH(qreal, z); |
677 QFETCH(qreal, z); |
678 QFETCH(qreal, len); |
678 QFETCH(qreal, len); |
687 QVERIFY(fuzzyCompare(u.y() * len, v.y())); |
687 QVERIFY(fuzzyCompare(u.y() * len, v.y())); |
688 QVERIFY(fuzzyCompare(u.z() * len, v.z())); |
688 QVERIFY(fuzzyCompare(u.z() * len, v.z())); |
689 } |
689 } |
690 |
690 |
691 // Test the unit vector conversion for 4D vectors. |
691 // Test the unit vector conversion for 4D vectors. |
692 void tst_QVector::normalized4_data() |
692 void tst_QVectorND::normalized4_data() |
693 { |
693 { |
694 // Use the same test data as the length test. |
694 // Use the same test data as the length test. |
695 length4_data(); |
695 length4_data(); |
696 } |
696 } |
697 void tst_QVector::normalized4() |
697 void tst_QVectorND::normalized4() |
698 { |
698 { |
699 QFETCH(qreal, x); |
699 QFETCH(qreal, x); |
700 QFETCH(qreal, y); |
700 QFETCH(qreal, y); |
701 QFETCH(qreal, z); |
701 QFETCH(qreal, z); |
702 QFETCH(qreal, w); |
702 QFETCH(qreal, w); |
713 QVERIFY(fuzzyCompare(u.z() * len, v.z())); |
713 QVERIFY(fuzzyCompare(u.z() * len, v.z())); |
714 QVERIFY(fuzzyCompare(u.w() * len, v.w())); |
714 QVERIFY(fuzzyCompare(u.w() * len, v.w())); |
715 } |
715 } |
716 |
716 |
717 // Test the unit vector conversion for 2D vectors. |
717 // Test the unit vector conversion for 2D vectors. |
718 void tst_QVector::normalize2_data() |
718 void tst_QVectorND::normalize2_data() |
719 { |
719 { |
720 // Use the same test data as the length test. |
720 // Use the same test data as the length test. |
721 length2_data(); |
721 length2_data(); |
722 } |
722 } |
723 void tst_QVector::normalize2() |
723 void tst_QVectorND::normalize2() |
724 { |
724 { |
725 QFETCH(qreal, x); |
725 QFETCH(qreal, x); |
726 QFETCH(qreal, y); |
726 QFETCH(qreal, y); |
727 |
727 |
728 QVector2D v(x, y); |
728 QVector2D v(x, y); |
733 else |
733 else |
734 QVERIFY(fuzzyCompare(v.length(), qreal(1.0f))); |
734 QVERIFY(fuzzyCompare(v.length(), qreal(1.0f))); |
735 } |
735 } |
736 |
736 |
737 // Test the unit vector conversion for 3D vectors. |
737 // Test the unit vector conversion for 3D vectors. |
738 void tst_QVector::normalize3_data() |
738 void tst_QVectorND::normalize3_data() |
739 { |
739 { |
740 // Use the same test data as the length test. |
740 // Use the same test data as the length test. |
741 length3_data(); |
741 length3_data(); |
742 } |
742 } |
743 void tst_QVector::normalize3() |
743 void tst_QVectorND::normalize3() |
744 { |
744 { |
745 QFETCH(qreal, x); |
745 QFETCH(qreal, x); |
746 QFETCH(qreal, y); |
746 QFETCH(qreal, y); |
747 QFETCH(qreal, z); |
747 QFETCH(qreal, z); |
748 |
748 |
754 else |
754 else |
755 QVERIFY(fuzzyCompare(v.length(), qreal(1.0f))); |
755 QVERIFY(fuzzyCompare(v.length(), qreal(1.0f))); |
756 } |
756 } |
757 |
757 |
758 // Test the unit vector conversion for 4D vectors. |
758 // Test the unit vector conversion for 4D vectors. |
759 void tst_QVector::normalize4_data() |
759 void tst_QVectorND::normalize4_data() |
760 { |
760 { |
761 // Use the same test data as the length test. |
761 // Use the same test data as the length test. |
762 length4_data(); |
762 length4_data(); |
763 } |
763 } |
764 void tst_QVector::normalize4() |
764 void tst_QVectorND::normalize4() |
765 { |
765 { |
766 QFETCH(qreal, x); |
766 QFETCH(qreal, x); |
767 QFETCH(qreal, y); |
767 QFETCH(qreal, y); |
768 QFETCH(qreal, z); |
768 QFETCH(qreal, z); |
769 QFETCH(qreal, w); |
769 QFETCH(qreal, w); |
776 else |
776 else |
777 QVERIFY(fuzzyCompare(v.length(), qreal(1.0f))); |
777 QVERIFY(fuzzyCompare(v.length(), qreal(1.0f))); |
778 } |
778 } |
779 |
779 |
780 // Test the comparison operators for 2D vectors. |
780 // Test the comparison operators for 2D vectors. |
781 void tst_QVector::compare2() |
781 void tst_QVectorND::compare2() |
782 { |
782 { |
783 QVector2D v1(1, 2); |
783 QVector2D v1(1, 2); |
784 QVector2D v2(1, 2); |
784 QVector2D v2(1, 2); |
785 QVector2D v3(3, 2); |
785 QVector2D v3(3, 2); |
786 QVector2D v4(1, 3); |
786 QVector2D v4(1, 3); |
789 QVERIFY(v1 != v3); |
789 QVERIFY(v1 != v3); |
790 QVERIFY(v1 != v4); |
790 QVERIFY(v1 != v4); |
791 } |
791 } |
792 |
792 |
793 // Test the comparison operators for 3D vectors. |
793 // Test the comparison operators for 3D vectors. |
794 void tst_QVector::compare3() |
794 void tst_QVectorND::compare3() |
795 { |
795 { |
796 QVector3D v1(1, 2, 4); |
796 QVector3D v1(1, 2, 4); |
797 QVector3D v2(1, 2, 4); |
797 QVector3D v2(1, 2, 4); |
798 QVector3D v3(3, 2, 4); |
798 QVector3D v3(3, 2, 4); |
799 QVector3D v4(1, 3, 4); |
799 QVector3D v4(1, 3, 4); |
804 QVERIFY(v1 != v4); |
804 QVERIFY(v1 != v4); |
805 QVERIFY(v1 != v5); |
805 QVERIFY(v1 != v5); |
806 } |
806 } |
807 |
807 |
808 // Test the comparison operators for 4D vectors. |
808 // Test the comparison operators for 4D vectors. |
809 void tst_QVector::compare4() |
809 void tst_QVectorND::compare4() |
810 { |
810 { |
811 QVector4D v1(1, 2, 4, 8); |
811 QVector4D v1(1, 2, 4, 8); |
812 QVector4D v2(1, 2, 4, 8); |
812 QVector4D v2(1, 2, 4, 8); |
813 QVector4D v3(3, 2, 4, 8); |
813 QVector4D v3(3, 2, 4, 8); |
814 QVector4D v4(1, 3, 4, 8); |
814 QVector4D v4(1, 3, 4, 8); |
821 QVERIFY(v1 != v5); |
821 QVERIFY(v1 != v5); |
822 QVERIFY(v1 != v6); |
822 QVERIFY(v1 != v6); |
823 } |
823 } |
824 |
824 |
825 // Test vector addition for 2D vectors. |
825 // Test vector addition for 2D vectors. |
826 void tst_QVector::add2_data() |
826 void tst_QVectorND::add2_data() |
827 { |
827 { |
828 QTest::addColumn<qreal>("x1"); |
828 QTest::addColumn<qreal>("x1"); |
829 QTest::addColumn<qreal>("y1"); |
829 QTest::addColumn<qreal>("y1"); |
830 QTest::addColumn<qreal>("x2"); |
830 QTest::addColumn<qreal>("x2"); |
831 QTest::addColumn<qreal>("y2"); |
831 QTest::addColumn<qreal>("y2"); |
850 QTest::newRow("all") |
850 QTest::newRow("all") |
851 << (qreal)1.0f << (qreal)2.0f |
851 << (qreal)1.0f << (qreal)2.0f |
852 << (qreal)4.0f << (qreal)5.0f |
852 << (qreal)4.0f << (qreal)5.0f |
853 << (qreal)5.0f << (qreal)7.0f; |
853 << (qreal)5.0f << (qreal)7.0f; |
854 } |
854 } |
855 void tst_QVector::add2() |
855 void tst_QVectorND::add2() |
856 { |
856 { |
857 QFETCH(qreal, x1); |
857 QFETCH(qreal, x1); |
858 QFETCH(qreal, y1); |
858 QFETCH(qreal, y1); |
859 QFETCH(qreal, x2); |
859 QFETCH(qreal, x2); |
860 QFETCH(qreal, y2); |
860 QFETCH(qreal, y2); |
874 QCOMPARE(v4.x(), v1.x() + v2.x()); |
874 QCOMPARE(v4.x(), v1.x() + v2.x()); |
875 QCOMPARE(v4.y(), v1.y() + v2.y()); |
875 QCOMPARE(v4.y(), v1.y() + v2.y()); |
876 } |
876 } |
877 |
877 |
878 // Test vector addition for 3D vectors. |
878 // Test vector addition for 3D vectors. |
879 void tst_QVector::add3_data() |
879 void tst_QVectorND::add3_data() |
880 { |
880 { |
881 QTest::addColumn<qreal>("x1"); |
881 QTest::addColumn<qreal>("x1"); |
882 QTest::addColumn<qreal>("y1"); |
882 QTest::addColumn<qreal>("y1"); |
883 QTest::addColumn<qreal>("z1"); |
883 QTest::addColumn<qreal>("z1"); |
884 QTest::addColumn<qreal>("x2"); |
884 QTest::addColumn<qreal>("x2"); |
911 QTest::newRow("all") |
911 QTest::newRow("all") |
912 << (qreal)1.0f << (qreal)2.0f << (qreal)3.0f |
912 << (qreal)1.0f << (qreal)2.0f << (qreal)3.0f |
913 << (qreal)4.0f << (qreal)5.0f << (qreal)-6.0f |
913 << (qreal)4.0f << (qreal)5.0f << (qreal)-6.0f |
914 << (qreal)5.0f << (qreal)7.0f << (qreal)-3.0f; |
914 << (qreal)5.0f << (qreal)7.0f << (qreal)-3.0f; |
915 } |
915 } |
916 void tst_QVector::add3() |
916 void tst_QVectorND::add3() |
917 { |
917 { |
918 QFETCH(qreal, x1); |
918 QFETCH(qreal, x1); |
919 QFETCH(qreal, y1); |
919 QFETCH(qreal, y1); |
920 QFETCH(qreal, z1); |
920 QFETCH(qreal, z1); |
921 QFETCH(qreal, x2); |
921 QFETCH(qreal, x2); |
939 QCOMPARE(v4.y(), v1.y() + v2.y()); |
939 QCOMPARE(v4.y(), v1.y() + v2.y()); |
940 QCOMPARE(v4.z(), v1.z() + v2.z()); |
940 QCOMPARE(v4.z(), v1.z() + v2.z()); |
941 } |
941 } |
942 |
942 |
943 // Test vector addition for 4D vectors. |
943 // Test vector addition for 4D vectors. |
944 void tst_QVector::add4_data() |
944 void tst_QVectorND::add4_data() |
945 { |
945 { |
946 QTest::addColumn<qreal>("x1"); |
946 QTest::addColumn<qreal>("x1"); |
947 QTest::addColumn<qreal>("y1"); |
947 QTest::addColumn<qreal>("y1"); |
948 QTest::addColumn<qreal>("z1"); |
948 QTest::addColumn<qreal>("z1"); |
949 QTest::addColumn<qreal>("w1"); |
949 QTest::addColumn<qreal>("w1"); |
984 QTest::newRow("all") |
984 QTest::newRow("all") |
985 << (qreal)1.0f << (qreal)2.0f << (qreal)3.0f << (qreal)8.0f |
985 << (qreal)1.0f << (qreal)2.0f << (qreal)3.0f << (qreal)8.0f |
986 << (qreal)4.0f << (qreal)5.0f << (qreal)-6.0f << (qreal)9.0f |
986 << (qreal)4.0f << (qreal)5.0f << (qreal)-6.0f << (qreal)9.0f |
987 << (qreal)5.0f << (qreal)7.0f << (qreal)-3.0f << (qreal)17.0f; |
987 << (qreal)5.0f << (qreal)7.0f << (qreal)-3.0f << (qreal)17.0f; |
988 } |
988 } |
989 void tst_QVector::add4() |
989 void tst_QVectorND::add4() |
990 { |
990 { |
991 QFETCH(qreal, x1); |
991 QFETCH(qreal, x1); |
992 QFETCH(qreal, y1); |
992 QFETCH(qreal, y1); |
993 QFETCH(qreal, z1); |
993 QFETCH(qreal, z1); |
994 QFETCH(qreal, w1); |
994 QFETCH(qreal, w1); |
1016 QCOMPARE(v4.z(), v1.z() + v2.z()); |
1016 QCOMPARE(v4.z(), v1.z() + v2.z()); |
1017 QCOMPARE(v4.w(), v1.w() + v2.w()); |
1017 QCOMPARE(v4.w(), v1.w() + v2.w()); |
1018 } |
1018 } |
1019 |
1019 |
1020 // Test vector subtraction for 2D vectors. |
1020 // Test vector subtraction for 2D vectors. |
1021 void tst_QVector::subtract2_data() |
1021 void tst_QVectorND::subtract2_data() |
1022 { |
1022 { |
1023 // Use the same test data as the add test. |
1023 // Use the same test data as the add test. |
1024 add2_data(); |
1024 add2_data(); |
1025 } |
1025 } |
1026 void tst_QVector::subtract2() |
1026 void tst_QVectorND::subtract2() |
1027 { |
1027 { |
1028 QFETCH(qreal, x1); |
1028 QFETCH(qreal, x1); |
1029 QFETCH(qreal, y1); |
1029 QFETCH(qreal, y1); |
1030 QFETCH(qreal, x2); |
1030 QFETCH(qreal, x2); |
1031 QFETCH(qreal, y2); |
1031 QFETCH(qreal, y2); |
1053 QCOMPARE(v5.x(), v3.x() - v2.x()); |
1053 QCOMPARE(v5.x(), v3.x() - v2.x()); |
1054 QCOMPARE(v5.y(), v3.y() - v2.y()); |
1054 QCOMPARE(v5.y(), v3.y() - v2.y()); |
1055 } |
1055 } |
1056 |
1056 |
1057 // Test vector subtraction for 3D vectors. |
1057 // Test vector subtraction for 3D vectors. |
1058 void tst_QVector::subtract3_data() |
1058 void tst_QVectorND::subtract3_data() |
1059 { |
1059 { |
1060 // Use the same test data as the add test. |
1060 // Use the same test data as the add test. |
1061 add3_data(); |
1061 add3_data(); |
1062 } |
1062 } |
1063 void tst_QVector::subtract3() |
1063 void tst_QVectorND::subtract3() |
1064 { |
1064 { |
1065 QFETCH(qreal, x1); |
1065 QFETCH(qreal, x1); |
1066 QFETCH(qreal, y1); |
1066 QFETCH(qreal, y1); |
1067 QFETCH(qreal, z1); |
1067 QFETCH(qreal, z1); |
1068 QFETCH(qreal, x2); |
1068 QFETCH(qreal, x2); |
1095 QCOMPARE(v5.y(), v3.y() - v2.y()); |
1095 QCOMPARE(v5.y(), v3.y() - v2.y()); |
1096 QCOMPARE(v5.z(), v3.z() - v2.z()); |
1096 QCOMPARE(v5.z(), v3.z() - v2.z()); |
1097 } |
1097 } |
1098 |
1098 |
1099 // Test vector subtraction for 4D vectors. |
1099 // Test vector subtraction for 4D vectors. |
1100 void tst_QVector::subtract4_data() |
1100 void tst_QVectorND::subtract4_data() |
1101 { |
1101 { |
1102 // Use the same test data as the add test. |
1102 // Use the same test data as the add test. |
1103 add4_data(); |
1103 add4_data(); |
1104 } |
1104 } |
1105 void tst_QVector::subtract4() |
1105 void tst_QVectorND::subtract4() |
1106 { |
1106 { |
1107 QFETCH(qreal, x1); |
1107 QFETCH(qreal, x1); |
1108 QFETCH(qreal, y1); |
1108 QFETCH(qreal, y1); |
1109 QFETCH(qreal, z1); |
1109 QFETCH(qreal, z1); |
1110 QFETCH(qreal, w1); |
1110 QFETCH(qreal, w1); |
1142 QCOMPARE(v5.z(), v3.z() - v2.z()); |
1142 QCOMPARE(v5.z(), v3.z() - v2.z()); |
1143 QCOMPARE(v5.w(), v3.w() - v2.w()); |
1143 QCOMPARE(v5.w(), v3.w() - v2.w()); |
1144 } |
1144 } |
1145 |
1145 |
1146 // Test component-wise vector multiplication for 2D vectors. |
1146 // Test component-wise vector multiplication for 2D vectors. |
1147 void tst_QVector::multiply2_data() |
1147 void tst_QVectorND::multiply2_data() |
1148 { |
1148 { |
1149 QTest::addColumn<qreal>("x1"); |
1149 QTest::addColumn<qreal>("x1"); |
1150 QTest::addColumn<qreal>("y1"); |
1150 QTest::addColumn<qreal>("y1"); |
1151 QTest::addColumn<qreal>("x2"); |
1151 QTest::addColumn<qreal>("x2"); |
1152 QTest::addColumn<qreal>("y2"); |
1152 QTest::addColumn<qreal>("y2"); |
1171 QTest::newRow("all") |
1171 QTest::newRow("all") |
1172 << (qreal)1.0f << (qreal)2.0f |
1172 << (qreal)1.0f << (qreal)2.0f |
1173 << (qreal)4.0f << (qreal)5.0f |
1173 << (qreal)4.0f << (qreal)5.0f |
1174 << (qreal)4.0f << (qreal)10.0f; |
1174 << (qreal)4.0f << (qreal)10.0f; |
1175 } |
1175 } |
1176 void tst_QVector::multiply2() |
1176 void tst_QVectorND::multiply2() |
1177 { |
1177 { |
1178 QFETCH(qreal, x1); |
1178 QFETCH(qreal, x1); |
1179 QFETCH(qreal, y1); |
1179 QFETCH(qreal, y1); |
1180 QFETCH(qreal, x2); |
1180 QFETCH(qreal, x2); |
1181 QFETCH(qreal, y2); |
1181 QFETCH(qreal, y2); |
1195 QCOMPARE(v4.x(), v1.x() * v2.x()); |
1195 QCOMPARE(v4.x(), v1.x() * v2.x()); |
1196 QCOMPARE(v4.y(), v1.y() * v2.y()); |
1196 QCOMPARE(v4.y(), v1.y() * v2.y()); |
1197 } |
1197 } |
1198 |
1198 |
1199 // Test component-wise vector multiplication for 3D vectors. |
1199 // Test component-wise vector multiplication for 3D vectors. |
1200 void tst_QVector::multiply3_data() |
1200 void tst_QVectorND::multiply3_data() |
1201 { |
1201 { |
1202 QTest::addColumn<qreal>("x1"); |
1202 QTest::addColumn<qreal>("x1"); |
1203 QTest::addColumn<qreal>("y1"); |
1203 QTest::addColumn<qreal>("y1"); |
1204 QTest::addColumn<qreal>("z1"); |
1204 QTest::addColumn<qreal>("z1"); |
1205 QTest::addColumn<qreal>("x2"); |
1205 QTest::addColumn<qreal>("x2"); |
1232 QTest::newRow("all") |
1232 QTest::newRow("all") |
1233 << (qreal)1.0f << (qreal)2.0f << (qreal)3.0f |
1233 << (qreal)1.0f << (qreal)2.0f << (qreal)3.0f |
1234 << (qreal)4.0f << (qreal)5.0f << (qreal)-6.0f |
1234 << (qreal)4.0f << (qreal)5.0f << (qreal)-6.0f |
1235 << (qreal)4.0f << (qreal)10.0f << (qreal)-18.0f; |
1235 << (qreal)4.0f << (qreal)10.0f << (qreal)-18.0f; |
1236 } |
1236 } |
1237 void tst_QVector::multiply3() |
1237 void tst_QVectorND::multiply3() |
1238 { |
1238 { |
1239 QFETCH(qreal, x1); |
1239 QFETCH(qreal, x1); |
1240 QFETCH(qreal, y1); |
1240 QFETCH(qreal, y1); |
1241 QFETCH(qreal, z1); |
1241 QFETCH(qreal, z1); |
1242 QFETCH(qreal, x2); |
1242 QFETCH(qreal, x2); |
1260 QCOMPARE(v4.y(), v1.y() * v2.y()); |
1260 QCOMPARE(v4.y(), v1.y() * v2.y()); |
1261 QCOMPARE(v4.z(), v1.z() * v2.z()); |
1261 QCOMPARE(v4.z(), v1.z() * v2.z()); |
1262 } |
1262 } |
1263 |
1263 |
1264 // Test component-wise vector multiplication for 4D vectors. |
1264 // Test component-wise vector multiplication for 4D vectors. |
1265 void tst_QVector::multiply4_data() |
1265 void tst_QVectorND::multiply4_data() |
1266 { |
1266 { |
1267 QTest::addColumn<qreal>("x1"); |
1267 QTest::addColumn<qreal>("x1"); |
1268 QTest::addColumn<qreal>("y1"); |
1268 QTest::addColumn<qreal>("y1"); |
1269 QTest::addColumn<qreal>("z1"); |
1269 QTest::addColumn<qreal>("z1"); |
1270 QTest::addColumn<qreal>("w1"); |
1270 QTest::addColumn<qreal>("w1"); |
1305 QTest::newRow("all") |
1305 QTest::newRow("all") |
1306 << (qreal)1.0f << (qreal)2.0f << (qreal)3.0f << (qreal)8.0f |
1306 << (qreal)1.0f << (qreal)2.0f << (qreal)3.0f << (qreal)8.0f |
1307 << (qreal)4.0f << (qreal)5.0f << (qreal)-6.0f << (qreal)9.0f |
1307 << (qreal)4.0f << (qreal)5.0f << (qreal)-6.0f << (qreal)9.0f |
1308 << (qreal)4.0f << (qreal)10.0f << (qreal)-18.0f << (qreal)72.0f; |
1308 << (qreal)4.0f << (qreal)10.0f << (qreal)-18.0f << (qreal)72.0f; |
1309 } |
1309 } |
1310 void tst_QVector::multiply4() |
1310 void tst_QVectorND::multiply4() |
1311 { |
1311 { |
1312 QFETCH(qreal, x1); |
1312 QFETCH(qreal, x1); |
1313 QFETCH(qreal, y1); |
1313 QFETCH(qreal, y1); |
1314 QFETCH(qreal, z1); |
1314 QFETCH(qreal, z1); |
1315 QFETCH(qreal, w1); |
1315 QFETCH(qreal, w1); |
1337 QCOMPARE(v4.z(), v1.z() * v2.z()); |
1337 QCOMPARE(v4.z(), v1.z() * v2.z()); |
1338 QCOMPARE(v4.w(), v1.w() * v2.w()); |
1338 QCOMPARE(v4.w(), v1.w() * v2.w()); |
1339 } |
1339 } |
1340 |
1340 |
1341 // Test vector multiplication by a factor for 2D vectors. |
1341 // Test vector multiplication by a factor for 2D vectors. |
1342 void tst_QVector::multiplyFactor2_data() |
1342 void tst_QVectorND::multiplyFactor2_data() |
1343 { |
1343 { |
1344 QTest::addColumn<qreal>("x1"); |
1344 QTest::addColumn<qreal>("x1"); |
1345 QTest::addColumn<qreal>("y1"); |
1345 QTest::addColumn<qreal>("y1"); |
1346 QTest::addColumn<qreal>("factor"); |
1346 QTest::addColumn<qreal>("factor"); |
1347 QTest::addColumn<qreal>("x2"); |
1347 QTest::addColumn<qreal>("x2"); |
1370 QTest::newRow("allzero") |
1370 QTest::newRow("allzero") |
1371 << (qreal)1.0f << (qreal)2.0f |
1371 << (qreal)1.0f << (qreal)2.0f |
1372 << (qreal)0.0f |
1372 << (qreal)0.0f |
1373 << (qreal)0.0f << (qreal)0.0f; |
1373 << (qreal)0.0f << (qreal)0.0f; |
1374 } |
1374 } |
1375 void tst_QVector::multiplyFactor2() |
1375 void tst_QVectorND::multiplyFactor2() |
1376 { |
1376 { |
1377 QFETCH(qreal, x1); |
1377 QFETCH(qreal, x1); |
1378 QFETCH(qreal, y1); |
1378 QFETCH(qreal, y1); |
1379 QFETCH(qreal, factor); |
1379 QFETCH(qreal, factor); |
1380 QFETCH(qreal, x2); |
1380 QFETCH(qreal, x2); |
1393 QCOMPARE(v3.x(), v1.x() * factor); |
1393 QCOMPARE(v3.x(), v1.x() * factor); |
1394 QCOMPARE(v3.y(), v1.y() * factor); |
1394 QCOMPARE(v3.y(), v1.y() * factor); |
1395 } |
1395 } |
1396 |
1396 |
1397 // Test vector multiplication by a factor for 3D vectors. |
1397 // Test vector multiplication by a factor for 3D vectors. |
1398 void tst_QVector::multiplyFactor3_data() |
1398 void tst_QVectorND::multiplyFactor3_data() |
1399 { |
1399 { |
1400 QTest::addColumn<qreal>("x1"); |
1400 QTest::addColumn<qreal>("x1"); |
1401 QTest::addColumn<qreal>("y1"); |
1401 QTest::addColumn<qreal>("y1"); |
1402 QTest::addColumn<qreal>("z1"); |
1402 QTest::addColumn<qreal>("z1"); |
1403 QTest::addColumn<qreal>("factor"); |
1403 QTest::addColumn<qreal>("factor"); |
1433 QTest::newRow("allzero") |
1433 QTest::newRow("allzero") |
1434 << (qreal)1.0f << (qreal)2.0f << (qreal)-3.0f |
1434 << (qreal)1.0f << (qreal)2.0f << (qreal)-3.0f |
1435 << (qreal)0.0f |
1435 << (qreal)0.0f |
1436 << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f; |
1436 << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f; |
1437 } |
1437 } |
1438 void tst_QVector::multiplyFactor3() |
1438 void tst_QVectorND::multiplyFactor3() |
1439 { |
1439 { |
1440 QFETCH(qreal, x1); |
1440 QFETCH(qreal, x1); |
1441 QFETCH(qreal, y1); |
1441 QFETCH(qreal, y1); |
1442 QFETCH(qreal, z1); |
1442 QFETCH(qreal, z1); |
1443 QFETCH(qreal, factor); |
1443 QFETCH(qreal, factor); |
1459 QCOMPARE(v3.y(), v1.y() * factor); |
1459 QCOMPARE(v3.y(), v1.y() * factor); |
1460 QCOMPARE(v3.z(), v1.z() * factor); |
1460 QCOMPARE(v3.z(), v1.z() * factor); |
1461 } |
1461 } |
1462 |
1462 |
1463 // Test vector multiplication by a factor for 4D vectors. |
1463 // Test vector multiplication by a factor for 4D vectors. |
1464 void tst_QVector::multiplyFactor4_data() |
1464 void tst_QVectorND::multiplyFactor4_data() |
1465 { |
1465 { |
1466 QTest::addColumn<qreal>("x1"); |
1466 QTest::addColumn<qreal>("x1"); |
1467 QTest::addColumn<qreal>("y1"); |
1467 QTest::addColumn<qreal>("y1"); |
1468 QTest::addColumn<qreal>("z1"); |
1468 QTest::addColumn<qreal>("z1"); |
1469 QTest::addColumn<qreal>("w1"); |
1469 QTest::addColumn<qreal>("w1"); |
1506 QTest::newRow("allzero") |
1506 QTest::newRow("allzero") |
1507 << (qreal)1.0f << (qreal)2.0f << (qreal)-3.0f << (qreal)4.0f |
1507 << (qreal)1.0f << (qreal)2.0f << (qreal)-3.0f << (qreal)4.0f |
1508 << (qreal)0.0f |
1508 << (qreal)0.0f |
1509 << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f; |
1509 << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f; |
1510 } |
1510 } |
1511 void tst_QVector::multiplyFactor4() |
1511 void tst_QVectorND::multiplyFactor4() |
1512 { |
1512 { |
1513 QFETCH(qreal, x1); |
1513 QFETCH(qreal, x1); |
1514 QFETCH(qreal, y1); |
1514 QFETCH(qreal, y1); |
1515 QFETCH(qreal, z1); |
1515 QFETCH(qreal, z1); |
1516 QFETCH(qreal, w1); |
1516 QFETCH(qreal, w1); |
1535 QCOMPARE(v3.z(), v1.z() * factor); |
1535 QCOMPARE(v3.z(), v1.z() * factor); |
1536 QCOMPARE(v3.w(), v1.w() * factor); |
1536 QCOMPARE(v3.w(), v1.w() * factor); |
1537 } |
1537 } |
1538 |
1538 |
1539 // Test vector division by a factor for 2D vectors. |
1539 // Test vector division by a factor for 2D vectors. |
1540 void tst_QVector::divide2_data() |
1540 void tst_QVectorND::divide2_data() |
1541 { |
1541 { |
1542 // Use the same test data as the multiply test. |
1542 // Use the same test data as the multiply test. |
1543 multiplyFactor2_data(); |
1543 multiplyFactor2_data(); |
1544 } |
1544 } |
1545 void tst_QVector::divide2() |
1545 void tst_QVectorND::divide2() |
1546 { |
1546 { |
1547 QFETCH(qreal, x1); |
1547 QFETCH(qreal, x1); |
1548 QFETCH(qreal, y1); |
1548 QFETCH(qreal, y1); |
1549 QFETCH(qreal, factor); |
1549 QFETCH(qreal, factor); |
1550 QFETCH(qreal, x2); |
1550 QFETCH(qreal, x2); |
1565 QCOMPARE(v3.x(), v2.x() / factor); |
1565 QCOMPARE(v3.x(), v2.x() / factor); |
1566 QCOMPARE(v3.y(), v2.y() / factor); |
1566 QCOMPARE(v3.y(), v2.y() / factor); |
1567 } |
1567 } |
1568 |
1568 |
1569 // Test vector division by a factor for 3D vectors. |
1569 // Test vector division by a factor for 3D vectors. |
1570 void tst_QVector::divide3_data() |
1570 void tst_QVectorND::divide3_data() |
1571 { |
1571 { |
1572 // Use the same test data as the multiply test. |
1572 // Use the same test data as the multiply test. |
1573 multiplyFactor3_data(); |
1573 multiplyFactor3_data(); |
1574 } |
1574 } |
1575 void tst_QVector::divide3() |
1575 void tst_QVectorND::divide3() |
1576 { |
1576 { |
1577 QFETCH(qreal, x1); |
1577 QFETCH(qreal, x1); |
1578 QFETCH(qreal, y1); |
1578 QFETCH(qreal, y1); |
1579 QFETCH(qreal, z1); |
1579 QFETCH(qreal, z1); |
1580 QFETCH(qreal, factor); |
1580 QFETCH(qreal, factor); |
1598 QCOMPARE(v3.y(), v2.y() / factor); |
1598 QCOMPARE(v3.y(), v2.y() / factor); |
1599 QCOMPARE(v3.z(), v2.z() / factor); |
1599 QCOMPARE(v3.z(), v2.z() / factor); |
1600 } |
1600 } |
1601 |
1601 |
1602 // Test vector division by a factor for 4D vectors. |
1602 // Test vector division by a factor for 4D vectors. |
1603 void tst_QVector::divide4_data() |
1603 void tst_QVectorND::divide4_data() |
1604 { |
1604 { |
1605 // Use the same test data as the multiply test. |
1605 // Use the same test data as the multiply test. |
1606 multiplyFactor4_data(); |
1606 multiplyFactor4_data(); |
1607 } |
1607 } |
1608 void tst_QVector::divide4() |
1608 void tst_QVectorND::divide4() |
1609 { |
1609 { |
1610 QFETCH(qreal, x1); |
1610 QFETCH(qreal, x1); |
1611 QFETCH(qreal, y1); |
1611 QFETCH(qreal, y1); |
1612 QFETCH(qreal, z1); |
1612 QFETCH(qreal, z1); |
1613 QFETCH(qreal, w1); |
1613 QFETCH(qreal, w1); |
1634 QCOMPARE(v3.z(), v2.z() / factor); |
1634 QCOMPARE(v3.z(), v2.z() / factor); |
1635 QCOMPARE(v3.w(), v2.w() / factor); |
1635 QCOMPARE(v3.w(), v2.w() / factor); |
1636 } |
1636 } |
1637 |
1637 |
1638 // Test vector negation for 2D vectors. |
1638 // Test vector negation for 2D vectors. |
1639 void tst_QVector::negate2_data() |
1639 void tst_QVectorND::negate2_data() |
1640 { |
1640 { |
1641 // Use the same test data as the add test. |
1641 // Use the same test data as the add test. |
1642 add2_data(); |
1642 add2_data(); |
1643 } |
1643 } |
1644 void tst_QVector::negate2() |
1644 void tst_QVectorND::negate2() |
1645 { |
1645 { |
1646 QFETCH(qreal, x1); |
1646 QFETCH(qreal, x1); |
1647 QFETCH(qreal, y1); |
1647 QFETCH(qreal, y1); |
1648 |
1648 |
1649 QVector2D v1(x1, y1); |
1649 QVector2D v1(x1, y1); |
1651 |
1651 |
1652 QVERIFY(-v1 == v2); |
1652 QVERIFY(-v1 == v2); |
1653 } |
1653 } |
1654 |
1654 |
1655 // Test vector negation for 3D vectors. |
1655 // Test vector negation for 3D vectors. |
1656 void tst_QVector::negate3_data() |
1656 void tst_QVectorND::negate3_data() |
1657 { |
1657 { |
1658 // Use the same test data as the add test. |
1658 // Use the same test data as the add test. |
1659 add3_data(); |
1659 add3_data(); |
1660 } |
1660 } |
1661 void tst_QVector::negate3() |
1661 void tst_QVectorND::negate3() |
1662 { |
1662 { |
1663 QFETCH(qreal, x1); |
1663 QFETCH(qreal, x1); |
1664 QFETCH(qreal, y1); |
1664 QFETCH(qreal, y1); |
1665 QFETCH(qreal, z1); |
1665 QFETCH(qreal, z1); |
1666 |
1666 |
1669 |
1669 |
1670 QVERIFY(-v1 == v2); |
1670 QVERIFY(-v1 == v2); |
1671 } |
1671 } |
1672 |
1672 |
1673 // Test vector negation for 4D vectors. |
1673 // Test vector negation for 4D vectors. |
1674 void tst_QVector::negate4_data() |
1674 void tst_QVectorND::negate4_data() |
1675 { |
1675 { |
1676 // Use the same test data as the add test. |
1676 // Use the same test data as the add test. |
1677 add4_data(); |
1677 add4_data(); |
1678 } |
1678 } |
1679 void tst_QVector::negate4() |
1679 void tst_QVectorND::negate4() |
1680 { |
1680 { |
1681 QFETCH(qreal, x1); |
1681 QFETCH(qreal, x1); |
1682 QFETCH(qreal, y1); |
1682 QFETCH(qreal, y1); |
1683 QFETCH(qreal, z1); |
1683 QFETCH(qreal, z1); |
1684 QFETCH(qreal, w1); |
1684 QFETCH(qreal, w1); |
1688 |
1688 |
1689 QVERIFY(-v1 == v2); |
1689 QVERIFY(-v1 == v2); |
1690 } |
1690 } |
1691 |
1691 |
1692 // Test the computation of vector cross-products. |
1692 // Test the computation of vector cross-products. |
1693 void tst_QVector::crossProduct_data() |
1693 void tst_QVectorND::crossProduct_data() |
1694 { |
1694 { |
1695 QTest::addColumn<qreal>("x1"); |
1695 QTest::addColumn<qreal>("x1"); |
1696 QTest::addColumn<qreal>("y1"); |
1696 QTest::addColumn<qreal>("y1"); |
1697 QTest::addColumn<qreal>("z1"); |
1697 QTest::addColumn<qreal>("z1"); |
1698 QTest::addColumn<qreal>("x2"); |
1698 QTest::addColumn<qreal>("x2"); |
1719 << (qreal)1.0f << (qreal)2.0f << (qreal)3.0f |
1719 << (qreal)1.0f << (qreal)2.0f << (qreal)3.0f |
1720 << (qreal)4.0f << (qreal)5.0f << (qreal)6.0f |
1720 << (qreal)4.0f << (qreal)5.0f << (qreal)6.0f |
1721 << (qreal)-3.0f << (qreal)6.0f << (qreal)-3.0f |
1721 << (qreal)-3.0f << (qreal)6.0f << (qreal)-3.0f |
1722 << (qreal)32.0f; |
1722 << (qreal)32.0f; |
1723 } |
1723 } |
1724 void tst_QVector::crossProduct() |
1724 void tst_QVectorND::crossProduct() |
1725 { |
1725 { |
1726 QFETCH(qreal, x1); |
1726 QFETCH(qreal, x1); |
1727 QFETCH(qreal, y1); |
1727 QFETCH(qreal, y1); |
1728 QFETCH(qreal, z1); |
1728 QFETCH(qreal, z1); |
1729 QFETCH(qreal, x2); |
1729 QFETCH(qreal, x2); |
1749 QCOMPARE(v4.y(), yres); |
1749 QCOMPARE(v4.y(), yres); |
1750 QCOMPARE(v4.z(), zres); |
1750 QCOMPARE(v4.z(), zres); |
1751 } |
1751 } |
1752 |
1752 |
1753 // Test the computation of normals. |
1753 // Test the computation of normals. |
1754 void tst_QVector::normal_data() |
1754 void tst_QVectorND::normal_data() |
1755 { |
1755 { |
1756 // Use the same test data as the crossProduct test. |
1756 // Use the same test data as the crossProduct test. |
1757 crossProduct_data(); |
1757 crossProduct_data(); |
1758 } |
1758 } |
1759 void tst_QVector::normal() |
1759 void tst_QVectorND::normal() |
1760 { |
1760 { |
1761 QFETCH(qreal, x1); |
1761 QFETCH(qreal, x1); |
1762 QFETCH(qreal, y1); |
1762 QFETCH(qreal, y1); |
1763 QFETCH(qreal, z1); |
1763 QFETCH(qreal, z1); |
1764 QFETCH(qreal, x2); |
1764 QFETCH(qreal, x2); |
1778 QVector3D point(1.0f, 2.0f, 3.0f); |
1778 QVector3D point(1.0f, 2.0f, 3.0f); |
1779 QVERIFY(QVector3D::normal(point, v1 + point, v2 + point) == v3.normalized()); |
1779 QVERIFY(QVector3D::normal(point, v1 + point, v2 + point) == v3.normalized()); |
1780 } |
1780 } |
1781 |
1781 |
1782 // Test distance to plane calculations. |
1782 // Test distance to plane calculations. |
1783 void tst_QVector::distanceToPlane_data() |
1783 void tst_QVectorND::distanceToPlane_data() |
1784 { |
1784 { |
1785 QTest::addColumn<qreal>("x1"); // Point on plane |
1785 QTest::addColumn<qreal>("x1"); // Point on plane |
1786 QTest::addColumn<qreal>("y1"); |
1786 QTest::addColumn<qreal>("y1"); |
1787 QTest::addColumn<qreal>("z1"); |
1787 QTest::addColumn<qreal>("z1"); |
1788 QTest::addColumn<qreal>("x2"); // Normal to plane |
1788 QTest::addColumn<qreal>("x2"); // Normal to plane |
1821 << (qreal)-1.0f << (qreal)1.0f << (qreal)-2.0f |
1821 << (qreal)-1.0f << (qreal)1.0f << (qreal)-2.0f |
1822 << (qreal)1.0f << (qreal)0.0f << (qreal)0.0f |
1822 << (qreal)1.0f << (qreal)0.0f << (qreal)0.0f |
1823 << (qreal)0.0f << (qreal)2.0f << (qreal)0.0f |
1823 << (qreal)0.0f << (qreal)2.0f << (qreal)0.0f |
1824 << (qreal)-2.0f; |
1824 << (qreal)-2.0f; |
1825 } |
1825 } |
1826 void tst_QVector::distanceToPlane() |
1826 void tst_QVectorND::distanceToPlane() |
1827 { |
1827 { |
1828 QFETCH(qreal, x1); |
1828 QFETCH(qreal, x1); |
1829 QFETCH(qreal, y1); |
1829 QFETCH(qreal, y1); |
1830 QFETCH(qreal, z1); |
1830 QFETCH(qreal, z1); |
1831 QFETCH(qreal, x2); |
1831 QFETCH(qreal, x2); |
1851 QCOMPARE(v3.distanceToPlane(v1, v2), distance); |
1851 QCOMPARE(v3.distanceToPlane(v1, v2), distance); |
1852 QCOMPARE(v3.distanceToPlane(v1, v4, v5), distance); |
1852 QCOMPARE(v3.distanceToPlane(v1, v4, v5), distance); |
1853 } |
1853 } |
1854 |
1854 |
1855 // Test distance to line calculations. |
1855 // Test distance to line calculations. |
1856 void tst_QVector::distanceToLine_data() |
1856 void tst_QVectorND::distanceToLine_data() |
1857 { |
1857 { |
1858 QTest::addColumn<qreal>("x1"); // Point on line |
1858 QTest::addColumn<qreal>("x1"); // Point on line |
1859 QTest::addColumn<qreal>("y1"); |
1859 QTest::addColumn<qreal>("y1"); |
1860 QTest::addColumn<qreal>("z1"); |
1860 QTest::addColumn<qreal>("z1"); |
1861 QTest::addColumn<qreal>("x2"); // Direction of the line |
1861 QTest::addColumn<qreal>("x2"); // Direction of the line |
1894 << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f |
1894 << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f |
1895 << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f |
1895 << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f |
1896 << (qreal)0.0f << (qreal)5.0f << (qreal)0.0f |
1896 << (qreal)0.0f << (qreal)5.0f << (qreal)0.0f |
1897 << (qreal)5.0f; |
1897 << (qreal)5.0f; |
1898 } |
1898 } |
1899 void tst_QVector::distanceToLine() |
1899 void tst_QVectorND::distanceToLine() |
1900 { |
1900 { |
1901 QFETCH(qreal, x1); |
1901 QFETCH(qreal, x1); |
1902 QFETCH(qreal, y1); |
1902 QFETCH(qreal, y1); |
1903 QFETCH(qreal, z1); |
1903 QFETCH(qreal, z1); |
1904 QFETCH(qreal, x2); |
1904 QFETCH(qreal, x2); |
1915 |
1915 |
1916 QCOMPARE(v3.distanceToLine(v1, v2), distance); |
1916 QCOMPARE(v3.distanceToLine(v1, v2), distance); |
1917 } |
1917 } |
1918 |
1918 |
1919 // Test the computation of dot products for 2D vectors. |
1919 // Test the computation of dot products for 2D vectors. |
1920 void tst_QVector::dotProduct2_data() |
1920 void tst_QVectorND::dotProduct2_data() |
1921 { |
1921 { |
1922 QTest::addColumn<qreal>("x1"); |
1922 QTest::addColumn<qreal>("x1"); |
1923 QTest::addColumn<qreal>("y1"); |
1923 QTest::addColumn<qreal>("y1"); |
1924 QTest::addColumn<qreal>("x2"); |
1924 QTest::addColumn<qreal>("x2"); |
1925 QTest::addColumn<qreal>("y2"); |
1925 QTest::addColumn<qreal>("y2"); |
1938 QTest::newRow("complex") |
1938 QTest::newRow("complex") |
1939 << (qreal)1.0f << (qreal)2.0f |
1939 << (qreal)1.0f << (qreal)2.0f |
1940 << (qreal)4.0f << (qreal)5.0f |
1940 << (qreal)4.0f << (qreal)5.0f |
1941 << (qreal)14.0f; |
1941 << (qreal)14.0f; |
1942 } |
1942 } |
1943 void tst_QVector::dotProduct2() |
1943 void tst_QVectorND::dotProduct2() |
1944 { |
1944 { |
1945 QFETCH(qreal, x1); |
1945 QFETCH(qreal, x1); |
1946 QFETCH(qreal, y1); |
1946 QFETCH(qreal, y1); |
1947 QFETCH(qreal, x2); |
1947 QFETCH(qreal, x2); |
1948 QFETCH(qreal, y2); |
1948 QFETCH(qreal, y2); |
1958 |
1958 |
1959 QCOMPARE(QVector2D::dotProduct(v1, v2), d); |
1959 QCOMPARE(QVector2D::dotProduct(v1, v2), d); |
1960 } |
1960 } |
1961 |
1961 |
1962 // Test the computation of dot products for 3D vectors. |
1962 // Test the computation of dot products for 3D vectors. |
1963 void tst_QVector::dotProduct3_data() |
1963 void tst_QVectorND::dotProduct3_data() |
1964 { |
1964 { |
1965 // Use the same test data as the crossProduct test. |
1965 // Use the same test data as the crossProduct test. |
1966 crossProduct_data(); |
1966 crossProduct_data(); |
1967 } |
1967 } |
1968 void tst_QVector::dotProduct3() |
1968 void tst_QVectorND::dotProduct3() |
1969 { |
1969 { |
1970 QFETCH(qreal, x1); |
1970 QFETCH(qreal, x1); |
1971 QFETCH(qreal, y1); |
1971 QFETCH(qreal, y1); |
1972 QFETCH(qreal, z1); |
1972 QFETCH(qreal, z1); |
1973 QFETCH(qreal, x2); |
1973 QFETCH(qreal, x2); |
1992 |
1992 |
1993 QCOMPARE(QVector3D::dotProduct(v1, v2), d); |
1993 QCOMPARE(QVector3D::dotProduct(v1, v2), d); |
1994 } |
1994 } |
1995 |
1995 |
1996 // Test the computation of dot products for 4D vectors. |
1996 // Test the computation of dot products for 4D vectors. |
1997 void tst_QVector::dotProduct4_data() |
1997 void tst_QVectorND::dotProduct4_data() |
1998 { |
1998 { |
1999 QTest::addColumn<qreal>("x1"); |
1999 QTest::addColumn<qreal>("x1"); |
2000 QTest::addColumn<qreal>("y1"); |
2000 QTest::addColumn<qreal>("y1"); |
2001 QTest::addColumn<qreal>("z1"); |
2001 QTest::addColumn<qreal>("z1"); |
2002 QTest::addColumn<qreal>("w1"); |
2002 QTest::addColumn<qreal>("w1"); |
2019 QTest::newRow("complex") |
2019 QTest::newRow("complex") |
2020 << (qreal)1.0f << (qreal)2.0f << (qreal)3.0f << (qreal)4.0f |
2020 << (qreal)1.0f << (qreal)2.0f << (qreal)3.0f << (qreal)4.0f |
2021 << (qreal)4.0f << (qreal)5.0f << (qreal)6.0f << (qreal)7.0f |
2021 << (qreal)4.0f << (qreal)5.0f << (qreal)6.0f << (qreal)7.0f |
2022 << (qreal)60.0f; |
2022 << (qreal)60.0f; |
2023 } |
2023 } |
2024 void tst_QVector::dotProduct4() |
2024 void tst_QVectorND::dotProduct4() |
2025 { |
2025 { |
2026 QFETCH(qreal, x1); |
2026 QFETCH(qreal, x1); |
2027 QFETCH(qreal, y1); |
2027 QFETCH(qreal, y1); |
2028 QFETCH(qreal, z1); |
2028 QFETCH(qreal, z1); |
2029 QFETCH(qreal, w1); |
2029 QFETCH(qreal, w1); |
2042 qreal d = x1 * x2 + y1 * y2 + z1 * z2 + w1 * w2; |
2042 qreal d = x1 * x2 + y1 * y2 + z1 * z2 + w1 * w2; |
2043 |
2043 |
2044 QCOMPARE(QVector4D::dotProduct(v1, v2), d); |
2044 QCOMPARE(QVector4D::dotProduct(v1, v2), d); |
2045 } |
2045 } |
2046 |
2046 |
2047 class tst_QVectorProperties : public QObject |
2047 class tst_QVectorNDProperties : public QObject |
2048 { |
2048 { |
2049 Q_OBJECT |
2049 Q_OBJECT |
2050 Q_PROPERTY(QVector2D vector2D READ vector2D WRITE setVector2D) |
2050 Q_PROPERTY(QVector2D vector2D READ vector2D WRITE setVector2D) |
2051 Q_PROPERTY(QVector3D vector3D READ vector3D WRITE setVector3D) |
2051 Q_PROPERTY(QVector3D vector3D READ vector3D WRITE setVector3D) |
2052 Q_PROPERTY(QVector4D vector4D READ vector4D WRITE setVector4D) |
2052 Q_PROPERTY(QVector4D vector4D READ vector4D WRITE setVector4D) |
2053 public: |
2053 public: |
2054 tst_QVectorProperties(QObject *parent = 0) : QObject(parent) {} |
2054 tst_QVectorNDProperties(QObject *parent = 0) : QObject(parent) {} |
2055 |
2055 |
2056 QVector2D vector2D() const { return v2; } |
2056 QVector2D vector2D() const { return v2; } |
2057 void setVector2D(const QVector2D& value) { v2 = value; } |
2057 void setVector2D(const QVector2D& value) { v2 = value; } |
2058 |
2058 |
2059 QVector3D vector3D() const { return v3; } |
2059 QVector3D vector3D() const { return v3; } |
2067 QVector3D v3; |
2067 QVector3D v3; |
2068 QVector4D v4; |
2068 QVector4D v4; |
2069 }; |
2069 }; |
2070 |
2070 |
2071 // Test getting and setting vector properties via the metaobject system. |
2071 // Test getting and setting vector properties via the metaobject system. |
2072 void tst_QVector::properties() |
2072 void tst_QVectorND::properties() |
2073 { |
2073 { |
2074 tst_QVectorProperties obj; |
2074 tst_QVectorNDProperties obj; |
2075 |
2075 |
2076 obj.setVector2D(QVector2D(1.0f, 2.0f)); |
2076 obj.setVector2D(QVector2D(1.0f, 2.0f)); |
2077 obj.setVector3D(QVector3D(3.0f, 4.0f, 5.0f)); |
2077 obj.setVector3D(QVector3D(3.0f, 4.0f, 5.0f)); |
2078 obj.setVector4D(QVector4D(6.0f, 7.0f, 8.0f, 9.0f)); |
2078 obj.setVector4D(QVector4D(6.0f, 7.0f, 8.0f, 9.0f)); |
2079 |
2079 |
2113 QCOMPARE(v4.y(), (qreal)-7.0f); |
2113 QCOMPARE(v4.y(), (qreal)-7.0f); |
2114 QCOMPARE(v4.z(), (qreal)-8.0f); |
2114 QCOMPARE(v4.z(), (qreal)-8.0f); |
2115 QCOMPARE(v4.w(), (qreal)-9.0f); |
2115 QCOMPARE(v4.w(), (qreal)-9.0f); |
2116 } |
2116 } |
2117 |
2117 |
2118 void tst_QVector::metaTypes() |
2118 void tst_QVectorND::metaTypes() |
2119 { |
2119 { |
2120 QVERIFY(QMetaType::type("QVector2D") == QMetaType::QVector2D); |
2120 QVERIFY(QMetaType::type("QVector2D") == QMetaType::QVector2D); |
2121 QVERIFY(QMetaType::type("QVector3D") == QMetaType::QVector3D); |
2121 QVERIFY(QMetaType::type("QVector3D") == QMetaType::QVector3D); |
2122 QVERIFY(QMetaType::type("QVector4D") == QMetaType::QVector4D); |
2122 QVERIFY(QMetaType::type("QVector4D") == QMetaType::QVector4D); |
2123 |
2123 |
2135 QVERIFY(qMetaTypeId<QVector2D>() == QMetaType::QVector2D); |
2135 QVERIFY(qMetaTypeId<QVector2D>() == QMetaType::QVector2D); |
2136 QVERIFY(qMetaTypeId<QVector3D>() == QMetaType::QVector3D); |
2136 QVERIFY(qMetaTypeId<QVector3D>() == QMetaType::QVector3D); |
2137 QVERIFY(qMetaTypeId<QVector4D>() == QMetaType::QVector4D); |
2137 QVERIFY(qMetaTypeId<QVector4D>() == QMetaType::QVector4D); |
2138 } |
2138 } |
2139 |
2139 |
2140 QTEST_APPLESS_MAIN(tst_QVector) |
2140 QTEST_APPLESS_MAIN(tst_QVectorND) |
2141 |
2141 |
2142 #include "tst_qvectornd.moc" |
2142 #include "tst_qvectornd.moc" |