void tst_QVectorArray::create3DArray() { QVector3DArray array; QVERIFY(array.isEmpty()); array.append(1.0f, 2.0f, 3.0f); array.append(3.0f, 4.0f, 5.0f); array.append(QVector3D(5.0f, 6.0f, 7.0f)); QCOMPARE(array.size(), 3); QVERIFY(array[0] == QVector3D(1.0f, 2.0f, 3.0f)); QVERIFY(array[1] == QVector3D(3.0f, 4.0f, 5.0f)); QVERIFY(array[2] == QVector3D(5.0f, 6.0f, 7.0f)); array.append(QVector3D(7.0f, 8.0f, 9.0f), QVector3D(9.0f, 10.0f, 11.0f)); array.append(QVector3D(11.0f, 12.0f, 13.0f), QVector3D(13.0f, 14.0f, 15.0f), QVector3D(15.0f, 16.0f, 17.0f)); array.append(QVector3D(17.0f, 18.0f, 19.0f), QVector3D(19.0f, 20.0f, 21.0f), QVector3D(21.0f, 22.0f, 23.0f)); for (int index = 0; index < array.size(); ++index) { QVERIFY(array[index] == QVector3D(index * 2 + 1, index * 2 + 2, index * 2 + 3)); } QVector3DArray array2(34); QCOMPARE(array2.size(), 34); for (int index = 0; index < array2.size(); ++index) QCOMPARE(array2[index], QVector3D(0.0f, 0.0f, 0.0f)); QVector3DArray array3(15, QVector3D(1.0f, 2.0f, 3.0f)); QCOMPARE(array3.size(), 15); for (int index = 0; index < array3.size(); ++index) QCOMPARE(array3[index], QVector3D(1.0f, 2.0f, 3.0f)); }
void tst_QVectorArray::vector3DArray() { QVector3DArray array; QVERIFY(array.isEmpty()); array.append(1.0f, 2.0f, 3.0f); array.append(3.0f, 4.0f, 5.0f); array.append(QVector3D(5.0f, 6.0f, 7.0f)); QCOMPARE(array.size(), 3); QVERIFY(array[0] == QVector3D(1.0f, 2.0f, 3.0f)); QVERIFY(array[1] == QVector3D(3.0f, 4.0f, 5.0f)); QVERIFY(array[2] == QVector3D(5.0f, 6.0f, 7.0f)); array.append(QVector3D(7.0f, 8.0f, 9.0f), QVector3D(9.0f, 10.0f, 11.0f)); array.append(QVector3D(11.0f, 12.0f, 13.0f), QVector3D(13.0f, 14.0f, 15.0f), QVector3D(15.0f, 16.0f, 17.0f)); array.append(QVector3D(17.0f, 18.0f, 19.0f), QVector3D(19.0f, 20.0f, 21.0f), QVector3D(21.0f, 22.0f, 23.0f)); for (int index = 0; index < array.size(); ++index) { QVERIFY(array[index] == QVector3D(index * 2 + 1, index * 2 + 2, index * 2 + 3)); } int size = array.size(); QVector3DArray result = array.scaled(1.0); // check did not change the original QCOMPARE(array.size(), size); QCOMPARE(array[0], QVector3D(1.0f, 2.0f, 3.0)); QCOMPARE(array[4], QVector3D(9.0f, 10.0f, 11.0f)); // result should be copy - mult by 1.0 costs nothing QVERIFY(!result.isDetached()); QCOMPARE(result.size(), size); QCOMPARE(result[0], QVector3D(1.0f, 2.0f, 3.0f)); QCOMPARE(result[4], QVector3D(9.0f, 10.0f, 11.0f)); QCOMPARE(result[10], QVector3D(21.0f, 22.0f, 23.0f)); // now actually do a scale result = array.scaled(2.0); QCOMPARE(result.size(), size); QCOMPARE(array.size(), size); QCOMPARE(result[0], QVector3D(2.0f, 4.0f, 6.0f)); QCOMPARE(result[4], QVector3D(18.0f, 20.0f, 22.0f)); QCOMPARE(result[10], QVector3D(42.0f, 44.0f, 46.0f)); array.scale(1.0); QCOMPARE(array.size(), size); // should all be the same QCOMPARE(array[0], QVector3D(1.0f, 2.0f, 3.0f)); QCOMPARE(array[4], QVector3D(9.0f, 10.0f, 11.0f)); QCOMPARE(array[10], QVector3D(21.0f, 22.0f, 23.0f)); array.scale(2.0); QCOMPARE(array.size(), size); // size should be the same QCOMPARE(array[0], QVector3D(2.0f, 4.0f, 6.0f)); QCOMPARE(array[4], QVector3D(18.0f, 20.0f, 22.0f)); QCOMPARE(array[10], QVector3D(42.0f, 44.0f, 46.0f)); }