Browse Source

added static cross product; tests

develop
Robin Thoni 7 years ago
parent
commit
7862666b44
3 changed files with 18 additions and 0 deletions
  1. 2
    0
      UGameEngine/utils/vectorxd.h
  2. 5
    0
      UGameEngine/utils/vectorxd.hxx
  3. 11
    0
      tests/testvector3d.cpp

+ 2
- 0
UGameEngine/utils/vectorxd.h View File

@@ -33,7 +33,9 @@ public:
33 33
     VectorXD<X>& div(double k);
34 34
 
35 35
     double dotProduct(const VectorXD<X>& other) const;
36
+
36 37
     VectorXD<X>& crossProduct(const VectorXD<X>& other);
38
+    static VectorXD<X> crossProduct(const VectorXD<X> &v1, const VectorXD<X> &v2);
37 39
 
38 40
     double norm() const;
39 41
 

+ 5
- 0
UGameEngine/utils/vectorxd.hxx View File

@@ -137,6 +137,11 @@ tmpl VectorXD<X>& VectorXD<X>::crossProduct(const VectorXD<X>& other)
137 137
     return *this;
138 138
 }
139 139
 
140
+tmpl VectorXD<X> VectorXD<X>::crossProduct(const VectorXD<X> &v1, const VectorXD<X> &v2)
141
+{
142
+    return VectorXD<X>(v1).crossProduct(v2);
143
+}
144
+
140 145
 tmpl double VectorXD<X>::norm() const
141 146
 {
142 147
     double total = 0;

+ 11
- 0
tests/testvector3d.cpp View File

@@ -47,6 +47,7 @@ private slots:
47 47
 
48 48
     void crossProduct1();
49 49
     void crossProduct2();
50
+    void crossProduct3();
50 51
 
51 52
     void norm1();
52 53
     void norm2();
@@ -381,6 +382,16 @@ void TestVector3D::crossProduct2()
381 382
     QCOMPARE(v.getZ(), -310.0);
382 383
 }
383 384
 
385
+void TestVector3D::crossProduct3()
386
+{
387
+    Vector3D v1(10.0, 24.0, 8.0);
388
+    Vector3D v2(15.0, 5.0, 0.0);
389
+    Vector3D v = Vector3D::crossProduct(v1, v2);
390
+    QCOMPARE(v.getX(), -40.0);
391
+    QCOMPARE(v.getY(), 120.0);
392
+    QCOMPARE(v.getZ(), -310.0);
393
+}
394
+
384 395
 void TestVector3D::norm1()
385 396
 {
386 397
     Vector3D v(3.0, 4.0, 0.0);;

Loading…
Cancel
Save