cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=694149c773af18b5d5a3abb883cf7d521bb4cf56

commit 694149c773af18b5d5a3abb883cf7d521bb4cf56
Author: Cedric BAIL <ced...@osg.samsung.com>
Date:   Wed Jun 24 17:23:23 2015 +0200

    eina: add eina_matrix4_normalized.
---
 src/lib/eina/eina_matrix.c | 29 +++++++++++++++++++++++++++++
 src/lib/eina/eina_matrix.h | 15 +++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/src/lib/eina/eina_matrix.c b/src/lib/eina/eina_matrix.c
index 2e994df..a43c5b2 100644
--- a/src/lib/eina/eina_matrix.c
+++ b/src/lib/eina/eina_matrix.c
@@ -23,6 +23,7 @@
 #include "eina_private.h"
 
 #include <math.h>
+#include <float.h>
 
 #include "eina_fp.h"
 #include "eina_rectangle.h"
@@ -723,3 +724,31 @@ eina_matrix4_determinant(const Eina_Matrix4 *m)
      - MATRIX_XY(m) * MATRIX_YX(m) * MATRIX_ZZ(m) * MATRIX_WW(m)
      + MATRIX_XX(m) * MATRIX_YY(m) * MATRIX_ZZ(m) * MATRIX_WW(m);
 }
+
+EAPI Eina_Bool
+eina_matrix4_normalized(Eina_Matrix4 *out, const Eina_Matrix4 *in)
+{
+   double det;
+
+   det = eina_matrix4_determinant(in);
+   if (fabs(det) < DBL_EPSILON) return EINA_FALSE;
+
+   MATRIX_XX(out) = MATRIX_XX(in) / det;
+   MATRIX_XY(out) = MATRIX_XY(in) / det;
+   MATRIX_XZ(out) = MATRIX_XZ(in) / det;
+   MATRIX_XW(out) = MATRIX_XW(in) / det;
+   MATRIX_YX(out) = MATRIX_YX(in) / det;
+   MATRIX_YY(out) = MATRIX_YY(in) / det;
+   MATRIX_YZ(out) = MATRIX_YZ(in) / det;
+   MATRIX_YW(out) = MATRIX_YW(in) / det;
+   MATRIX_ZX(out) = MATRIX_ZX(in) / det;
+   MATRIX_ZY(out) = MATRIX_ZY(in) / det;
+   MATRIX_ZZ(out) = MATRIX_ZZ(in) / det;
+   MATRIX_ZW(out) = MATRIX_ZW(in) / det;
+   MATRIX_WX(out) = MATRIX_WX(in) / det;
+   MATRIX_WY(out) = MATRIX_WY(in) / det;
+   MATRIX_WZ(out) = MATRIX_WZ(in) / det;
+   MATRIX_WW(out) = MATRIX_WW(in) / det;
+
+   return EINA_TRUE;
+}
diff --git a/src/lib/eina/eina_matrix.h b/src/lib/eina/eina_matrix.h
index 8dc7014..bf02f17 100644
--- a/src/lib/eina/eina_matrix.h
+++ b/src/lib/eina/eina_matrix.h
@@ -525,6 +525,21 @@ EAPI void eina_matrix4_values_get(const Eina_Matrix4 *m,
 EAPI double eina_matrix4_determinant(const Eina_Matrix4 *m);
 
 /**
+ * @brief Return the determinant of the given matrix.
+ *
+ * @param m The matrix.
+ * @return The determinant.
+ *
+ * This function returns the determinant of the matrix @p m. No check
+ * is done on @p m.
+ *
+ * @since 1.15
+ */
+EAPI Eina_Bool eina_matrix4_normalized(Eina_Matrix4 *out,
+                                       const Eina_Matrix4 *in);
+
+
+/**
  * @brief Convert an Eina_Matrix4 into an Eina_Matrix3.
  *
  * @param m3 The destination Eina_Matrix3.

-- 


Reply via email to