cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=2127547cb95114bfc8bb7e999f55c98fc91179c7

commit 2127547cb95114bfc8bb7e999f55c98fc91179c7
Author: se.osadchy <se.osad...@samsung.com>
Date:   Mon Jan 4 15:05:58 2016 -0800

    evas: create Eina_Vector2 structure and add functions.
    
    Summary: Only copy code from evas_3d_utils, rename evas to eina and add 
documentation.
    
    Reviewers: Hermet, raster, jpeg, cedric
    
    Reviewed By: jpeg, cedric
    
    Subscribers: jpeg
    
    Differential Revision: https://phab.enlightenment.org/D3509
    
    Signed-off-by: Cedric BAIL <ced...@osg.samsung.com>
---
 src/Makefile_Eina.am                 |   2 +
 src/lib/eina/eina_vector.c           | 158 ++++++++++++++++++++++++
 src/lib/eina/eina_vector.h           | 224 +++++++++++++++++++++++++++++++++++
 src/lib/evas/include/evas_3d_utils.h |   1 -
 4 files changed, 384 insertions(+), 1 deletion(-)

diff --git a/src/Makefile_Eina.am b/src/Makefile_Eina.am
index abfff07..0f4518d 100644
--- a/src/Makefile_Eina.am
+++ b/src/Makefile_Eina.am
@@ -94,6 +94,7 @@ lib/eina/eina_inline_crc.x \
 lib/eina/eina_evlog.h \
 lib/eina/eina_util.h \
 lib/eina/eina_quaternion.h \
+lib/eina/eina_vector.h \
 lib/eina/eina_bezier.h
 
 lib_eina_libeina_la_SOURCES = \
@@ -164,6 +165,7 @@ lib/eina/eina_private.h \
 lib/eina/eina_share_common.h \
 lib/eina/eina_strbuf_common.h \
 lib/eina/eina_quaternion.c \
+lib/eina/eina_vector.c \
 lib/eina/eina_bezier.c
 
 if HAVE_WIN32
diff --git a/src/lib/eina/eina_vector.c b/src/lib/eina/eina_vector.c
new file mode 100644
index 0000000..d2338ce
--- /dev/null
+++ b/src/lib/eina/eina_vector.c
@@ -0,0 +1,158 @@
+/* EINA - EFL data type library
+ * Copyright (C) 2008 Cedric Bail
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library;
+ * if not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "eina_private.h"
+
+#include <math.h>
+#include <float.h>
+
+#include "eina_fp.h"
+#include "eina_matrix.h"
+#include "eina_vector.h"
+
+EAPI void
+eina_vector2_set(Eina_Vector2 *dst, double x, double y)
+{
+   dst->x = x;
+   dst->y = y;
+}
+
+EAPI void
+eina_vector2_array_set(Eina_Vector2 *dst, const double *v)
+{
+   dst->x = v[0];
+   dst->y = v[1];
+}
+
+EAPI void
+eina_vector2_copy(Eina_Vector2 *dst, const Eina_Vector2 *src)
+{
+   dst->x = src->x;
+   dst->y = src->y;
+}
+
+EAPI void
+eina_vector2_negate(Eina_Vector2 *out, const Eina_Vector2 *v)
+{
+   out->x = -v->x;
+   out->y = -v->y;
+}
+
+EAPI void
+eina_vector2_add(Eina_Vector2 *out, const Eina_Vector2 *a, const Eina_Vector2 
*b)
+{
+   out->x = a->x + b->x;
+   out->y = a->y + b->y;
+}
+
+EAPI void
+eina_vector2_subtract(Eina_Vector2 *out, const Eina_Vector2 *a, const 
Eina_Vector2 *b)
+{
+   out->x = a->x - b->x;
+   out->y = a->y - b->y;
+}
+
+EAPI void
+eina_vector2_scale(Eina_Vector2 *out, const Eina_Vector2 *v, double scale)
+{
+   out->x = scale * v->x;
+   out->y = scale * v->y;
+}
+
+EAPI double
+eina_vector2_dot_product(const Eina_Vector2 *a, const Eina_Vector2 *b)
+{
+   return (a->x * b->x) + (a->y * b->y);
+}
+
+EAPI double
+eina_vector2_length_get(const Eina_Vector2 *v)
+{
+   return (double)sqrt((double)((v->x * v->x) + (v->y * v->y)));
+}
+
+EAPI double
+eina_vector2_length_square_get(const Eina_Vector2 *v)
+{
+   return (v->x * v->x) + (v->y * v->y);
+}
+
+EAPI double
+eina_vector2_distance_get(const Eina_Vector2 *a, const Eina_Vector2 *b)
+{
+   Eina_Vector2 v;
+
+   eina_vector2_subtract(&v, a, b);
+   return eina_vector2_length_get(&v);
+}
+
+EAPI double
+eina_vector2_distance_square_get(const Eina_Vector2 *a, const Eina_Vector2 *b)
+{
+   Eina_Vector2 v;
+
+   eina_vector2_subtract(&v, a, b);
+   return eina_vector2_length_square_get(&v);
+}
+
+EAPI void
+eina_vector2_normalize(Eina_Vector2 *out, const Eina_Vector2 *v)
+{
+   /* Assume "v" is not a zero vector */
+   eina_vector2_scale(out, v, 1.0 / eina_vector2_length_get(v));
+}
+
+EAPI void
+eina_vector2_transform(Eina_Vector2 *out, const Eina_Matrix2 *m, const 
Eina_Vector2 *v)
+{
+   Eina_Vector2 tmp;
+
+   tmp.x = (m->xx * v->x) + (m->yx * v->y);
+   tmp.y = (m->xy * v->x) + (m->yy * v->y);
+
+   eina_vector2_copy(out, &tmp);
+}
+
+EAPI void
+eina_vector2_homogeneous_position_transform(Eina_Vector2 *out, const 
Eina_Matrix3 *m,
+                                            const Eina_Vector2 *v)
+{
+   Eina_Vector2 tmp;
+
+   tmp.x = (m->xx * v->x) + (m->yx * v->y) + m->zx;
+   tmp.y = (m->xy * v->x) + (m->yy * v->y) + m->zy;
+
+   eina_vector2_scale(out, &tmp, 1.0 / ((m->xz * v->x) + (m->yz * v->y) + 
m->zz));
+}
+
+EAPI void
+eina_vector2_homogeneous_direction_transform(Eina_Vector2 *out, const 
Eina_Matrix3 *m,
+                                             const Eina_Vector2 *v)
+{
+   Eina_Vector2 tmp;
+
+   tmp.x = (m->xx * v->x) + (m->yx * v->y);
+   tmp.y = (m->xy * v->x) + (m->yy * v->y);
+
+   eina_vector2_copy(out, &tmp);
+}
diff --git a/src/lib/eina/eina_vector.h b/src/lib/eina/eina_vector.h
new file mode 100644
index 0000000..aa32e32
--- /dev/null
+++ b/src/lib/eina/eina_vector.h
@@ -0,0 +1,224 @@
+/* EINA - EFL data type library
+ * Copyright (C) 2008 Cedric Bail
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library;
+ * if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef EINA_VECTOR_H_
+#define EINA_VECTOR_H_
+
+/**
+ * @file
+ * @ender_group{Eina_Vector_Type}
+ * @ender_group{Eina_Vector2}
+ */
+
+typedef struct _Eina_Vector2 Eina_Vector2;
+
+/**
+ * @}
+ * @defgroup Eina_Vector2 Vectors in floating point
+ * @ingroup Eina_Basic
+ * @brief Vector definition and operations
+ * @{
+ */
+
+struct _Eina_Vector2
+{
+   double x;
+   double y;
+};
+
+/**
+ * @brief Set parameters to vector.
+ *
+ * @param dst The resulting vector.
+ * @param x The x component.
+ * @param y The y component.
+ *
+ * @since 1.17
+ */
+EAPI void eina_vector2_set(Eina_Vector2 *dst, double x, double y);
+
+/**
+ * @brief Set array to vector.
+ *
+ * @param dst The resulting vector.
+ * @param v The the array[2] for set.
+ *
+ * Set to vector first 2 elements from array.
+ *
+ * @since 1.17
+ */
+EAPI void eina_vector2_array_set(Eina_Vector2 *dst, const double *v);
+
+/**
+ * @brief Copy vector.
+ *
+ * @param dst The vector copy.
+ * @param src The vector for copy.
+ *
+ * @since 1.17
+ */
+EAPI void eina_vector2_copy(Eina_Vector2 *dst, const Eina_Vector2 *src);
+
+/**
+ * @brief Make negative vector.
+ *
+ * @param out The resulting vector.
+ * @param v The current vector.
+ *
+ * @since 1.17
+ */
+EAPI void eina_vector2_negate(Eina_Vector2 *out, const Eina_Vector2 *v);
+
+/**
+ * @brief Add two vectors.
+ *
+ * @param out The resulting vector.
+ * @param a The first member of the add.
+ * @param b The second member of the add.
+ *
+ * @since 1.17
+ */
+EAPI void eina_vector2_add(Eina_Vector2 *out, const Eina_Vector2 *a,
+                           const Eina_Vector2 *b);
+
+/**
+ * @brief Subtract two vectors
+ *
+ * @param out The resulting vector
+ * @param a The first member of the subtract
+ * @param b The second member of the subtract
+ *
+ * @since 1.17
+ */
+EAPI void eina_vector2_subtract(Eina_Vector2 *out, const Eina_Vector2 *a,
+                                const Eina_Vector2 *b);
+
+/**
+ * @brief Scale vector.
+ *
+ * @param out The resulting vector.
+ * @param v The vector for scale.
+ * @param scale The scale value.
+ *
+ * @since 1.17
+ */
+EAPI void eina_vector2_scale(Eina_Vector2 *out, const Eina_Vector2 *v, double 
scale);
+
+/**
+ * @brief Return the dot product of the two vectors.
+ *
+ * @param a The first member.
+ * @param b The secondt member.
+ * @return The dot product.
+ *
+ * @since 1.17
+ */
+EAPI double eina_vector2_dot_product(const Eina_Vector2 *a, const Eina_Vector2 
*b);
+
+/**
+ * @brief Return the length of the given vector.
+ *
+ * @param v The vector.
+ * @return The length.
+ *
+ * @since 1.17
+ */
+EAPI double eina_vector2_length_get(const Eina_Vector2 *v);
+
+/**
+ * @brief Return the length in square of the given vector.
+ *
+ * @param v The vector.
+ * @return The length in square.
+ *
+ * @since 1.17
+ */
+EAPI double eina_vector2_length_square_get(const Eina_Vector2 *v);
+
+/**
+ * @brief Return the distance between of two vectors.
+ *
+ * @param a The first vector.
+ * @param b The second vector.
+ * @return The distance.
+ *
+ * @since 1.17
+ */
+EAPI double eina_vector2_distance_get(const Eina_Vector2 *a, const 
Eina_Vector2 *b);
+
+/**
+ * @brief Return the distance in square between of two vectors.
+ *
+ * @param a The first vector.
+ * @param b The second vector.
+ * @return The distance in square.
+ *
+ * @since 1.17
+ */
+EAPI double eina_vector2_distance_square_get(const Eina_Vector2 *a,
+                                             const Eina_Vector2 *b);
+
+/**
+ * @brief normalize vector.
+ *
+ * @param out The resulting vector.
+ * @param v The vector for normalize.
+ *
+ * @since 1.17
+ */
+EAPI void eina_vector2_normalize(Eina_Vector2 *out, const Eina_Vector2 *v);
+
+/**
+ * @brief Transform vector.
+ *
+ * @param out The resulting vector.
+ * @param m The matrix for transform.
+ * @param v The ector for transform.
+ *
+ * @since 1.17
+ */
+EAPI void eina_vector2_transform(Eina_Vector2 *out, const Eina_Matrix2 *m,
+                                 const Eina_Vector2 *v);
+
+/**
+ * @brief Homogeneous position transform vector.
+ *
+ * @param out The resulting vector.
+ * @param m The matrix for transform.
+ * @param v The ector for transform.
+ *
+ * @since 1.17
+ */
+EAPI void eina_vector2_homogeneous_position_transform(Eina_Vector2 *out,
+                                                      const Eina_Matrix3 *m,
+                                                      const Eina_Vector2 *v);
+
+/**
+ * @brief Homogeneous direction ransform vector.
+ *
+ * @param out The resulting vector.
+ * @param m The matrix for transform.
+ * @param v The ector for transform.
+ *
+ * @since 1.17
+ */
+EAPI void eina_vector2_homogeneous_direction_transform(Eina_Vector2 *out,
+                                                       const Eina_Matrix3 *m,
+                                                       const Eina_Vector2 *v);
+
+#endif
diff --git a/src/lib/evas/include/evas_3d_utils.h 
b/src/lib/evas/include/evas_3d_utils.h
index 96b8c74..cc557c6 100644
--- a/src/lib/evas/include/evas_3d_utils.h
+++ b/src/lib/evas/include/evas_3d_utils.h
@@ -528,7 +528,6 @@ evas_vec3_if_equivalent_as_triangle(Evas_Vec3 *v0, 
Evas_Vec3 *v1, Evas_Vec3 *v2,
    return EINA_FALSE;
 }
 
-
 static inline Eina_Bool
 evas_triangle3_if_equivalent(Evas_Triangle3 *a, Evas_Triangle3 *b)
 {

-- 


Reply via email to