Jeff Hardy avatar Jeff Hardy committed 8b48fed

Minor changes to code layout.

Comments (0)

Files changed (3)

Matrix/Matrix/Matrix.h

     return result;
 }
 
+template<class T, int Rows, int Cols>
+Matrix<T, Rows, Cols> zero_matrix()
+{
+    Matrix<T, Rows, Cols> result = {};
+    return result;
+}
+
 #include "MatrixOps.h"
 
 template<class T, int Rows, int Cols>

Matrix/Matrix/MatrixOps.h

         return m * -1;
     }
 
-
     template<class T, int Rows, int Cols>
     Matrix<T, Rows, Cols> subtract(const Matrix<T, Rows, Cols> &l, const Matrix<T, Rows, Cols> &r)
     {
     template<class T>
     Matrix<T, 3, 1> cross_product(const Matrix<T, 3, 1> &l, const Matrix<T, 3, 1> &r)
     {
-        Matrix<T, 3, 1> result;
-
-        result(0) = l(1) * r(2) - l(2) * r(1);
-        result(1) = l(2) * r(0) - l(0) * r(2);
-        result(2) = l(0) * r(1) - l(1) * r(0);
-
+        Matrix<T, 3, 1> result = {
+            l(1) * r(2) - l(2) * r(1),
+            l(2) * r(0) - l(0) * r(2),
+            l(0) * r(1) - l(1) * r(0)
+        };
         return result;
     }
 
     template<class T>
     Matrix<T, 1, 3> cross_product(const Matrix<T, 1, 3> &l, const Matrix<T, 1, 3> &r)
     {
-        Matrix<T, 1, 3> result;
-
-        result(0) = l(1) * r(2) - l(2) * r(1);
-        result(1) = l(2) * r(0) - l(0) * r(2);
-        result(2) = l(0) * r(1) - l(1) * r(0);
-
+        Matrix<T, 1, 3> result = {
+            l(1) * r(2) - l(2) * r(1),
+            l(2) * r(0) - l(0) * r(2),
+            l(0) * r(1) - l(1) * r(0)
+        };
         return result;
     }
 

Matrix/MatrixTests/MatrixTests.cpp

 
 BOOST_AUTO_TEST_CASE( test_subtract )
 {
-    Matrix<int, 3, 3> zero = {};
+    Matrix<int, 3, 3> zero = zero_matrix<int, 3, 3>();
 
     Matrix<int, 3, 3> a = {0, 1, 2, 
                            3, 4, 5, 
 
 BOOST_AUTO_TEST_CASE( test_add )
 {
-    Matrix<int, 3, 3> zero = {};
+    Matrix<int, 3, 3> zero = zero_matrix<int, 3, 3>();
 
     Matrix<int, 3, 3> a = {0, 1, 2, 
                            3, 4, 5, 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.