summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorse.osadchy <se.osadchy@samsung.com>2016-01-04 15:05:58 -0800
committerCedric BAIL <cedric@osg.samsung.com>2016-01-04 15:06:00 -0800
commit2127547cb95114bfc8bb7e999f55c98fc91179c7 (patch)
tree3ec1a3f08cea0e926c6ef91a5f930b0ba9bff059
parente6ccfcedd80d4ede8d3482947b8e81500b356e62 (diff)
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 <cedric@osg.samsung.com>
-rw-r--r--src/Makefile_Eina.am2
-rw-r--r--src/lib/eina/eina_vector.c158
-rw-r--r--src/lib/eina/eina_vector.h224
-rw-r--r--src/lib/evas/include/evas_3d_utils.h1
4 files changed, 384 insertions, 1 deletions
diff --git a/src/Makefile_Eina.am b/src/Makefile_Eina.am
index abfff07abf..0f4518d192 100644
--- a/src/Makefile_Eina.am
+++ b/src/Makefile_Eina.am
@@ -94,6 +94,7 @@ lib/eina/eina_inline_crc.x \
94lib/eina/eina_evlog.h \ 94lib/eina/eina_evlog.h \
95lib/eina/eina_util.h \ 95lib/eina/eina_util.h \
96lib/eina/eina_quaternion.h \ 96lib/eina/eina_quaternion.h \
97lib/eina/eina_vector.h \
97lib/eina/eina_bezier.h 98lib/eina/eina_bezier.h
98 99
99lib_eina_libeina_la_SOURCES = \ 100lib_eina_libeina_la_SOURCES = \
@@ -164,6 +165,7 @@ lib/eina/eina_private.h \
164lib/eina/eina_share_common.h \ 165lib/eina/eina_share_common.h \
165lib/eina/eina_strbuf_common.h \ 166lib/eina/eina_strbuf_common.h \
166lib/eina/eina_quaternion.c \ 167lib/eina/eina_quaternion.c \
168lib/eina/eina_vector.c \
167lib/eina/eina_bezier.c 169lib/eina/eina_bezier.c
168 170
169if HAVE_WIN32 171if HAVE_WIN32
diff --git a/src/lib/eina/eina_vector.c b/src/lib/eina/eina_vector.c
new file mode 100644
index 0000000000..d2338ceb71
--- /dev/null
+++ b/src/lib/eina/eina_vector.c
@@ -0,0 +1,158 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2008 Cedric Bail
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19
20#ifdef HAVE_CONFIG_H
21# include "config.h"
22#endif
23
24#include "eina_private.h"
25
26#include <math.h>
27#include <float.h>
28
29#include "eina_fp.h"
30#include "eina_matrix.h"
31#include "eina_vector.h"
32
33EAPI void
34eina_vector2_set(Eina_Vector2 *dst, double x, double y)
35{
36 dst->x = x;
37 dst->y = y;
38}
39
40EAPI void
41eina_vector2_array_set(Eina_Vector2 *dst, const double *v)
42{
43 dst->x = v[0];
44 dst->y = v[1];
45}
46
47EAPI void
48eina_vector2_copy(Eina_Vector2 *dst, const Eina_Vector2 *src)
49{
50 dst->x = src->x;
51 dst->y = src->y;
52}
53
54EAPI void
55eina_vector2_negate(Eina_Vector2 *out, const Eina_Vector2 *v)
56{
57 out->x = -v->x;
58 out->y = -v->y;
59}
60
61EAPI void
62eina_vector2_add(Eina_Vector2 *out, const Eina_Vector2 *a, const Eina_Vector2 *b)
63{
64 out->x = a->x + b->x;
65 out->y = a->y + b->y;
66}
67
68EAPI void
69eina_vector2_subtract(Eina_Vector2 *out, const Eina_Vector2 *a, const Eina_Vector2 *b)
70{
71 out->x = a->x - b->x;
72 out->y = a->y - b->y;
73}
74
75EAPI void
76eina_vector2_scale(Eina_Vector2 *out, const Eina_Vector2 *v, double scale)
77{
78 out->x = scale * v->x;
79 out->y = scale * v->y;
80}
81
82EAPI double
83eina_vector2_dot_product(const Eina_Vector2 *a, const Eina_Vector2 *b)
84{
85 return (a->x * b->x) + (a->y * b->y);
86}
87
88EAPI double
89eina_vector2_length_get(const Eina_Vector2 *v)
90{
91 return (double)sqrt((double)((v->x * v->x) + (v->y * v->y)));
92}
93
94EAPI double
95eina_vector2_length_square_get(const Eina_Vector2 *v)
96{
97 return (v->x * v->x) + (v->y * v->y);
98}
99
100EAPI double
101eina_vector2_distance_get(const Eina_Vector2 *a, const Eina_Vector2 *b)
102{
103 Eina_Vector2 v;
104
105 eina_vector2_subtract(&v, a, b);
106 return eina_vector2_length_get(&v);
107}
108
109EAPI double
110eina_vector2_distance_square_get(const Eina_Vector2 *a, const Eina_Vector2 *b)
111{
112 Eina_Vector2 v;
113
114 eina_vector2_subtract(&v, a, b);
115 return eina_vector2_length_square_get(&v);
116}
117
118EAPI void
119eina_vector2_normalize(Eina_Vector2 *out, const Eina_Vector2 *v)
120{
121 /* Assume "v" is not a zero vector */
122 eina_vector2_scale(out, v, 1.0 / eina_vector2_length_get(v));
123}
124
125EAPI void
126eina_vector2_transform(Eina_Vector2 *out, const Eina_Matrix2 *m, const Eina_Vector2 *v)
127{
128 Eina_Vector2 tmp;
129
130 tmp.x = (m->xx * v->x) + (m->yx * v->y);
131 tmp.y = (m->xy * v->x) + (m->yy * v->y);
132
133 eina_vector2_copy(out, &tmp);
134}
135
136EAPI void
137eina_vector2_homogeneous_position_transform(Eina_Vector2 *out, const Eina_Matrix3 *m,
138 const Eina_Vector2 *v)
139{
140 Eina_Vector2 tmp;
141
142 tmp.x = (m->xx * v->x) + (m->yx * v->y) + m->zx;
143 tmp.y = (m->xy * v->x) + (m->yy * v->y) + m->zy;
144
145 eina_vector2_scale(out, &tmp, 1.0 / ((m->xz * v->x) + (m->yz * v->y) + m->zz));
146}
147
148EAPI void
149eina_vector2_homogeneous_direction_transform(Eina_Vector2 *out, const Eina_Matrix3 *m,
150 const Eina_Vector2 *v)
151{
152 Eina_Vector2 tmp;
153
154 tmp.x = (m->xx * v->x) + (m->yx * v->y);
155 tmp.y = (m->xy * v->x) + (m->yy * v->y);
156
157 eina_vector2_copy(out, &tmp);
158}
diff --git a/src/lib/eina/eina_vector.h b/src/lib/eina/eina_vector.h
new file mode 100644
index 0000000000..aa32e32815
--- /dev/null
+++ b/src/lib/eina/eina_vector.h
@@ -0,0 +1,224 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2008 Cedric Bail
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef EINA_VECTOR_H_
20#define EINA_VECTOR_H_
21
22/**
23 * @file
24 * @ender_group{Eina_Vector_Type}
25 * @ender_group{Eina_Vector2}
26 */
27
28typedef struct _Eina_Vector2 Eina_Vector2;
29
30/**
31 * @}
32 * @defgroup Eina_Vector2 Vectors in floating point
33 * @ingroup Eina_Basic
34 * @brief Vector definition and operations
35 * @{
36 */
37
38struct _Eina_Vector2
39{
40 double x;
41 double y;
42};
43
44/**
45 * @brief Set parameters to vector.
46 *
47 * @param dst The resulting vector.
48 * @param x The x component.
49 * @param y The y component.
50 *
51 * @since 1.17
52 */
53EAPI void eina_vector2_set(Eina_Vector2 *dst, double x, double y);
54
55/**
56 * @brief Set array to vector.
57 *
58 * @param dst The resulting vector.
59 * @param v The the array[2] for set.
60 *
61 * Set to vector first 2 elements from array.
62 *
63 * @since 1.17
64 */
65EAPI void eina_vector2_array_set(Eina_Vector2 *dst, const double *v);
66
67/**
68 * @brief Copy vector.
69 *
70 * @param dst The vector copy.
71 * @param src The vector for copy.
72 *
73 * @since 1.17
74 */
75EAPI void eina_vector2_copy(Eina_Vector2 *dst, const Eina_Vector2 *src);
76
77/**
78 * @brief Make negative vector.
79 *
80 * @param out The resulting vector.
81 * @param v The current vector.
82 *
83 * @since 1.17
84 */
85EAPI void eina_vector2_negate(Eina_Vector2 *out, const Eina_Vector2 *v);
86
87/**
88 * @brief Add two vectors.
89 *
90 * @param out The resulting vector.
91 * @param a The first member of the add.
92 * @param b The second member of the add.
93 *
94 * @since 1.17
95 */
96EAPI void eina_vector2_add(Eina_Vector2 *out, const Eina_Vector2 *a,
97 const Eina_Vector2 *b);
98
99/**
100 * @brief Subtract two vectors
101 *
102 * @param out The resulting vector
103 * @param a The first member of the subtract
104 * @param b The second member of the subtract
105 *
106 * @since 1.17
107 */
108EAPI void eina_vector2_subtract(Eina_Vector2 *out, const Eina_Vector2 *a,
109 const Eina_Vector2 *b);
110
111/**
112 * @brief Scale vector.
113 *
114 * @param out The resulting vector.
115 * @param v The vector for scale.
116 * @param scale The scale value.
117 *
118 * @since 1.17
119 */
120EAPI void eina_vector2_scale(Eina_Vector2 *out, const Eina_Vector2 *v, double scale);
121
122/**
123 * @brief Return the dot product of the two vectors.
124 *
125 * @param a The first member.
126 * @param b The secondt member.
127 * @return The dot product.
128 *
129 * @since 1.17
130 */
131EAPI double eina_vector2_dot_product(const Eina_Vector2 *a, const Eina_Vector2 *b);
132
133/**
134 * @brief Return the length of the given vector.
135 *
136 * @param v The vector.
137 * @return The length.
138 *
139 * @since 1.17
140 */
141EAPI double eina_vector2_length_get(const Eina_Vector2 *v);
142
143/**
144 * @brief Return the length in square of the given vector.
145 *
146 * @param v The vector.
147 * @return The length in square.
148 *
149 * @since 1.17
150 */
151EAPI double eina_vector2_length_square_get(const Eina_Vector2 *v);
152
153/**
154 * @brief Return the distance between of two vectors.
155 *
156 * @param a The first vector.
157 * @param b The second vector.
158 * @return The distance.
159 *
160 * @since 1.17
161 */
162EAPI double eina_vector2_distance_get(const Eina_Vector2 *a, const Eina_Vector2 *b);
163
164/**
165 * @brief Return the distance in square between of two vectors.
166 *
167 * @param a The first vector.
168 * @param b The second vector.
169 * @return The distance in square.
170 *
171 * @since 1.17
172 */
173EAPI double eina_vector2_distance_square_get(const Eina_Vector2 *a,
174 const Eina_Vector2 *b);
175
176/**
177 * @brief normalize vector.
178 *
179 * @param out The resulting vector.
180 * @param v The vector for normalize.
181 *
182 * @since 1.17
183 */
184EAPI void eina_vector2_normalize(Eina_Vector2 *out, const Eina_Vector2 *v);
185
186/**
187 * @brief Transform vector.
188 *
189 * @param out The resulting vector.
190 * @param m The matrix for transform.
191 * @param v The ector for transform.
192 *
193 * @since 1.17
194 */
195EAPI void eina_vector2_transform(Eina_Vector2 *out, const Eina_Matrix2 *m,
196 const Eina_Vector2 *v);
197
198/**
199 * @brief Homogeneous position transform vector.
200 *
201 * @param out The resulting vector.
202 * @param m The matrix for transform.
203 * @param v The ector for transform.
204 *
205 * @since 1.17
206 */
207EAPI void eina_vector2_homogeneous_position_transform(Eina_Vector2 *out,
208 const Eina_Matrix3 *m,
209 const Eina_Vector2 *v);
210
211/**
212 * @brief Homogeneous direction ransform vector.
213 *
214 * @param out The resulting vector.
215 * @param m The matrix for transform.
216 * @param v The ector for transform.
217 *
218 * @since 1.17
219 */
220EAPI void eina_vector2_homogeneous_direction_transform(Eina_Vector2 *out,
221 const Eina_Matrix3 *m,
222 const Eina_Vector2 *v);
223
224#endif
diff --git a/src/lib/evas/include/evas_3d_utils.h b/src/lib/evas/include/evas_3d_utils.h
index 96b8c74af7..cc557c6889 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,
528 return EINA_FALSE; 528 return EINA_FALSE;
529} 529}
530 530
531
532static inline Eina_Bool 531static inline Eina_Bool
533evas_triangle3_if_equivalent(Evas_Triangle3 *a, Evas_Triangle3 *b) 532evas_triangle3_if_equivalent(Evas_Triangle3 *a, Evas_Triangle3 *b)
534{ 533{