Browse Source

added [] operator for vector; tests

develop
Robin Thoni 8 years ago
parent
commit
5925a79726
3 changed files with 20 additions and 2 deletions
  1. 3
    1
      UGameEngine/utils/vectorxd.h
  2. 6
    1
      UGameEngine/utils/vectorxd.hxx
  3. 11
    0
      tests/testvector3d.cpp

+ 3
- 1
UGameEngine/utils/vectorxd.h View File

13
     VectorXD(const VectorXD<X>& other);
13
     VectorXD(const VectorXD<X>& other);
14
 
14
 
15
     VectorXD<X>& setScalar(unsigned i, double value);
15
     VectorXD<X>& setScalar(unsigned i, double value);
16
-    double getScalar(unsigned i);
16
+    double getScalar(unsigned i) const;
17
 
17
 
18
     bool isNull() const;
18
     bool isNull() const;
19
 
19
 
66
     bool operator==(const VectorXD<X>& other) const;
66
     bool operator==(const VectorXD<X>& other) const;
67
     bool operator!=(const VectorXD<X>& other) const;
67
     bool operator!=(const VectorXD<X>& other) const;
68
 
68
 
69
+    double operator[](unsigned i) const;
70
+
69
     bool operator!() const;
71
     bool operator!() const;
70
     operator bool() const;
72
     operator bool() const;
71
 
73
 

+ 6
- 1
UGameEngine/utils/vectorxd.hxx View File

29
     return *this;
29
     return *this;
30
 }
30
 }
31
 
31
 
32
-tmpl double VectorXD<X>::getScalar(unsigned i)
32
+tmpl double VectorXD<X>::getScalar(unsigned i) const
33
 {
33
 {
34
     return _scalars[i];
34
     return _scalars[i];
35
 }
35
 }
265
     return !equal(other);
265
     return !equal(other);
266
 }
266
 }
267
 
267
 
268
+tmpl double VectorXD<X>::operator[](unsigned i) const
269
+{
270
+    return getScalar(i);
271
+}
272
+
268
 tmpl bool VectorXD<X>::operator!() const
273
 tmpl bool VectorXD<X>::operator!() const
269
 {
274
 {
270
     return isNull();
275
     return isNull();

+ 11
- 0
tests/testvector3d.cpp View File

51
 
51
 
52
     void norm1();
52
     void norm1();
53
     void norm2();
53
     void norm2();
54
+
55
+    void getScalarOp();
54
 };
56
 };
55
 
57
 
56
 void TestVector3D::gettersSetters1()
58
 void TestVector3D::gettersSetters1()
404
     QCOMPARE(v.norm(), 50.0);
406
     QCOMPARE(v.norm(), 50.0);
405
 }
407
 }
406
 
408
 
409
+void TestVector3D::getScalarOp()
410
+{
411
+    double x = 1.42, y = 2.0, z = 3.0;
412
+    Vector3D v(x, y, z);
413
+    QCOMPARE(v[0], x);
414
+    QCOMPARE(v[1], y);
415
+    QCOMPARE(v[2], z);
416
+}
417
+
407
 QTEST_MAIN(TestVector3D)
418
 QTEST_MAIN(TestVector3D)
408
 #include "testvector3d.moc"
419
 #include "testvector3d.moc"

Loading…
Cancel
Save