Making DALi public API typesafe using guaranteed types; uint8_t, uint32_t
[platform/core/uifw/dali-core.git] / dali / public-api / math / matrix.cpp
index 7ffb393..81630cd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,9 +19,9 @@
 #include <dali/public-api/math/matrix.h>
 
 // EXTERNAL INCLUDES
-#include <math.h>
-#include <string.h>
-#include <iostream>
+#include <cmath>
+#include <cstring> // for memcpy
+#include <ostream>
 
 // INTERNAL INCLUDES
 #include <dali/public-api/common/dali-common.h>
@@ -192,9 +192,9 @@ static bool InvertMatrix(const float* m, float* out)
     return false;
   }
 
-  det = 1.0 / det;
+  det = 1.0f / det;
 
-  for (int i = 0; i < 16; i++)
+  for( int32_t i = 0; i < 16; i++)
   {
     out[i] = inv[i] * det;
   }
@@ -274,13 +274,13 @@ void Matrix::Multiply( Matrix& result, const Matrix& lhs, const Matrix& rhs )
 
 #ifndef  __ARM_NEON__
 
-  for( int i=0; i < 4; i++ )
+  for( int32_t i=0; i < 4; i++ )
   {
     // i<<2 gives the first vector / column
-    int loc = i<<2;
-    int loc1 = loc + 1;
-    int loc2 = loc + 2;
-    int loc3 = loc + 3;
+    int32_t loc = i<<2;
+    int32_t loc1 = loc + 1;
+    int32_t loc2 = loc + 2;
+    int32_t loc3 = loc + 3;
     float value0 = lhsPtr[loc];
     float value1 = lhsPtr[loc1];
     float value2 = lhsPtr[loc2];
@@ -360,13 +360,13 @@ void Matrix::Multiply( Matrix& result, const Matrix& lhs, const Quaternion& rhs
 
 #ifndef  __ARM_NEON__
 
-  for( int i=0; i < 4; i++ )
+  for( int32_t i=0; i < 4; i++ )
   {
     // i<<2 gives the first vector / column
-    int loc = i<<2;
-    int loc1 = loc + 1;
-    int loc2 = loc + 2;
-    int loc3 = loc + 3;
+    int32_t loc = i<<2;
+    int32_t loc1 = loc + 1;
+    int32_t loc2 = loc + 2;
+    int32_t loc3 = loc + 3;
     float value0 = lhsPtr[loc];
     float value1 = lhsPtr[loc1];
     float value2 = lhsPtr[loc2];
@@ -778,10 +778,10 @@ void Matrix::GetTransformComponents(Vector3&     position,
 
 std::ostream& operator<< (std::ostream& o, const Matrix& matrix)
 {
-  return o << "[ [" << matrix.mMatrix[0] << ", " << matrix.mMatrix[1] << ", " << matrix.mMatrix[2]  << ", " << matrix.mMatrix[3] << "], "
-             << "[" << matrix.mMatrix[4] << ", " << matrix.mMatrix[5] << ", " << matrix.mMatrix[6]  << ", " << matrix.mMatrix[7] << "], "
-             << "[" << matrix.mMatrix[8] << ", " << matrix.mMatrix[9] << ", " << matrix.mMatrix[10] << ", " << matrix.mMatrix[11] << "], "
-             << "[" << matrix.mMatrix[12] << ", " << matrix.mMatrix[13] << ", " << matrix.mMatrix[14] << ", " << matrix.mMatrix[15] << "] ]";
+  return o << "[ " << matrix.mMatrix[0]  << ", " << matrix.mMatrix[1]  << ", " << matrix.mMatrix[2]  << ", " << matrix.mMatrix[3]  << ", "
+                   << matrix.mMatrix[4]  << ", " << matrix.mMatrix[5]  << ", " << matrix.mMatrix[6]  << ", " << matrix.mMatrix[7]  << ", "
+                   << matrix.mMatrix[8]  << ", " << matrix.mMatrix[9]  << ", " << matrix.mMatrix[10] << ", " << matrix.mMatrix[11] << ", "
+                   << matrix.mMatrix[12] << ", " << matrix.mMatrix[13] << ", " << matrix.mMatrix[14] << ", " << matrix.mMatrix[15] << " ]";
 }
 
 } // namespace Dali