summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2015-05-28 14:35:55 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-05-29 17:20:28 +0200
commit9a83100a4ac1b040bde8aa63c868be3ad806758a (patch)
treeadb0ca777db9ac4e5bb6a68f21b76d9f806e4946 /src
parent5cdf202ee4c81afcd5a18749a09eab9724a76402 (diff)
eina: add the beginning of an Eina_Matrix4 API.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile_Eina.am5
-rw-r--r--src/lib/eina/eina_matrix.c103
-rw-r--r--src/lib/eina/eina_matrix.h135
-rw-r--r--src/tests/eina/eina_suite.c5
-rw-r--r--src/tests/eina/eina_suite.h1
-rw-r--r--src/tests/eina/eina_test_matrix.c100
6 files changed, 344 insertions, 5 deletions
diff --git a/src/Makefile_Eina.am b/src/Makefile_Eina.am
index 532c051a95..6cf5ae5a04 100644
--- a/src/Makefile_Eina.am
+++ b/src/Makefile_Eina.am
@@ -310,9 +310,8 @@ tests/eina/eina_test_trash.c \
310tests/eina/eina_test_lock.c \ 310tests/eina/eina_test_lock.c \
311tests/eina/eina_test_xattr.c \ 311tests/eina/eina_test_xattr.c \
312tests/eina/eina_test_crc.c \ 312tests/eina/eina_test_crc.c \
313tests/eina/eina_test_quad.c 313tests/eina/eina_test_quad.c \
314# tests/eina/eina_test_model.c 314tests/eina/eina_test_matrix.c
315
316 315
317tests_eina_eina_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ 316tests_eina_eina_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
318-DTESTS_WD=\"`pwd`\" \ 317-DTESTS_WD=\"`pwd`\" \
diff --git a/src/lib/eina/eina_matrix.c b/src/lib/eina/eina_matrix.c
index 468acf58fd..8e2d0beb98 100644
--- a/src/lib/eina/eina_matrix.c
+++ b/src/lib/eina/eina_matrix.c
@@ -32,12 +32,19 @@
32#define MATRIX_XX(m) (m)->xx 32#define MATRIX_XX(m) (m)->xx
33#define MATRIX_XY(m) (m)->xy 33#define MATRIX_XY(m) (m)->xy
34#define MATRIX_XZ(m) (m)->xz 34#define MATRIX_XZ(m) (m)->xz
35#define MATRIX_XW(m) (m)->xw
35#define MATRIX_YX(m) (m)->yx 36#define MATRIX_YX(m) (m)->yx
36#define MATRIX_YY(m) (m)->yy 37#define MATRIX_YY(m) (m)->yy
37#define MATRIX_YZ(m) (m)->yz 38#define MATRIX_YZ(m) (m)->yz
39#define MATRIX_YW(m) (m)->yw
38#define MATRIX_ZX(m) (m)->zx 40#define MATRIX_ZX(m) (m)->zx
39#define MATRIX_ZY(m) (m)->zy 41#define MATRIX_ZY(m) (m)->zy
40#define MATRIX_ZZ(m) (m)->zz 42#define MATRIX_ZZ(m) (m)->zz
43#define MATRIX_ZW(m) (m)->zw
44#define MATRIX_WX(m) (m)->wx
45#define MATRIX_WY(m) (m)->wy
46#define MATRIX_WZ(m) (m)->wz
47#define MATRIX_WW(m) (m)->ww
41#define MATRIX_SIZE 9 48#define MATRIX_SIZE 9
42 49
43#define QUAD_X0(q) q->x0 50#define QUAD_X0(q) q->x0
@@ -109,6 +116,17 @@ eina_matrix3_type_get(const Eina_Matrix3 *m)
109} 116}
110 117
111EAPI Eina_Matrix_Type 118EAPI Eina_Matrix_Type
119eina_matrix4_type_get(const Eina_Matrix4 *m)
120{
121 if ((MATRIX_XX(m) == 1) && (MATRIX_XY(m) == 0) && (MATRIX_XZ(m) == 0) && (MATRIX_XW(m) == 0) &&
122 (MATRIX_YX(m) == 0) && (MATRIX_YY(m) == 1) && (MATRIX_YZ(m) == 0) && (MATRIX_YW(m) == 0) &&
123 (MATRIX_ZX(m) == 0) && (MATRIX_ZY(m) == 0) && (MATRIX_ZZ(m) == 1) && (MATRIX_ZW(m) == 0) &&
124 (MATRIX_WX(m) == 0) && (MATRIX_WY(m) == 0) && (MATRIX_WZ(m) == 0) && (MATRIX_WW(m) == 1))
125 return EINA_MATRIX_TYPE_IDENTITY;
126 return EINA_MATRIX_TYPE_AFFINE;
127}
128
129EAPI Eina_Matrix_Type
112eina_matrix3_f16p16_type_get(const Eina_Matrix3_F16p16 *m) 130eina_matrix3_f16p16_type_get(const Eina_Matrix3_F16p16 *m)
113{ 131{
114 if ((MATRIX_ZX(m) != 0) || (MATRIX_ZY(m) != 0) || (MATRIX_ZZ(m) != 65536)) 132 if ((MATRIX_ZX(m) != 0) || (MATRIX_ZY(m) != 0) || (MATRIX_ZZ(m) != 65536))
@@ -158,6 +176,56 @@ eina_matrix3_values_get(const Eina_Matrix3 *m,
158} 176}
159 177
160EAPI void 178EAPI void
179eina_matrix4_values_set(Eina_Matrix4 *m,
180 double xx, double xy, double xz, double xw,
181 double yx, double yy, double yz, double yw,
182 double zx, double zy, double zz, double zw,
183 double wx, double wy, double wz, double ww)
184{
185 MATRIX_XX(m) = xx;
186 MATRIX_XY(m) = xy;
187 MATRIX_XZ(m) = xz;
188 MATRIX_XW(m) = xw;
189 MATRIX_YX(m) = yx;
190 MATRIX_YY(m) = yy;
191 MATRIX_YZ(m) = yz;
192 MATRIX_YW(m) = yw;
193 MATRIX_ZX(m) = zx;
194 MATRIX_ZY(m) = zy;
195 MATRIX_ZZ(m) = zz;
196 MATRIX_ZW(m) = zw;
197 MATRIX_WX(m) = wx;
198 MATRIX_WY(m) = wy;
199 MATRIX_WZ(m) = wz;
200 MATRIX_WW(m) = ww;
201}
202
203EAPI void
204eina_matrix4_values_get(const Eina_Matrix4 *m,
205 double *xx, double *xy, double *xz, double *xw,
206 double *yx, double *yy, double *yz, double *yw,
207 double *zx, double *zy, double *zz, double *zw,
208 double *wx, double *wy, double *wz, double *ww)
209{
210 if (xx) *xx = MATRIX_XX(m);
211 if (xy) *xy = MATRIX_XY(m);
212 if (xz) *xz = MATRIX_XZ(m);
213 if (xw) *xw = MATRIX_XW(m);
214 if (yx) *yx = MATRIX_YX(m);
215 if (yy) *yy = MATRIX_YY(m);
216 if (yz) *yz = MATRIX_YZ(m);
217 if (yw) *yw = MATRIX_YW(m);
218 if (zx) *zx = MATRIX_ZX(m);
219 if (zy) *zy = MATRIX_ZY(m);
220 if (zz) *zz = MATRIX_ZZ(m);
221 if (zw) *zw = MATRIX_ZW(m);
222 if (wx) *wx = MATRIX_WX(m);
223 if (wy) *wy = MATRIX_WY(m);
224 if (wz) *wz = MATRIX_WZ(m);
225 if (ww) *ww = MATRIX_WW(m);
226}
227
228EAPI void
161eina_matrix3_fixed_values_get(const Eina_Matrix3 *m, 229eina_matrix3_fixed_values_get(const Eina_Matrix3 *m,
162 Eina_F16p16 *xx, Eina_F16p16 *xy, Eina_F16p16 *xz, 230 Eina_F16p16 *xx, Eina_F16p16 *xy, Eina_F16p16 *xz,
163 Eina_F16p16 *yx, Eina_F16p16 *yy, Eina_F16p16 *yz, 231 Eina_F16p16 *yx, Eina_F16p16 *yy, Eina_F16p16 *yz,
@@ -590,3 +658,38 @@ eina_matrix3_quad_quad_map(Eina_Matrix3 *m,
590 658
591 return EINA_TRUE; 659 return EINA_TRUE;
592} 660}
661
662EAPI void
663eina_matrix4_matrix3_to(Eina_Matrix3 *m3, const Eina_Matrix4 *m4)
664{
665 MATRIX_XX(m3) = MATRIX_XX(m4);
666 MATRIX_XY(m3) = MATRIX_XY(m4);
667 MATRIX_XZ(m3) = MATRIX_XZ(m4);
668 MATRIX_YX(m3) = MATRIX_YX(m4);
669 MATRIX_YY(m3) = MATRIX_YY(m4);
670 MATRIX_YZ(m3) = MATRIX_YZ(m4);
671 MATRIX_ZX(m3) = MATRIX_ZX(m4);
672 MATRIX_ZY(m3) = MATRIX_ZY(m4);
673 MATRIX_ZZ(m3) = MATRIX_ZZ(m4);
674}
675
676EAPI void
677eina_matrix3_matrix4_to(Eina_Matrix4 *m4, const Eina_Matrix3 *m3)
678{
679 MATRIX_XX(m4) = MATRIX_XX(m3);
680 MATRIX_XY(m4) = MATRIX_XY(m3);
681 MATRIX_XZ(m4) = MATRIX_XZ(m3);
682 MATRIX_XW(m4) = 0;
683 MATRIX_YX(m4) = MATRIX_YX(m3);
684 MATRIX_YY(m4) = MATRIX_YY(m3);
685 MATRIX_YZ(m4) = MATRIX_YZ(m3);
686 MATRIX_YW(m4) = 0;
687 MATRIX_ZX(m4) = MATRIX_ZX(m3);
688 MATRIX_ZY(m4) = MATRIX_ZY(m3);
689 MATRIX_ZZ(m4) = MATRIX_ZZ(m3);
690 MATRIX_ZW(m4) = 0;
691 MATRIX_WX(m4) = 0;
692 MATRIX_WY(m4) = 0;
693 MATRIX_WZ(m4) = 0;
694 MATRIX_WW(m4) = 1;
695}
diff --git a/src/lib/eina/eina_matrix.h b/src/lib/eina/eina_matrix.h
index 4f6c23e729..83fff16540 100644
--- a/src/lib/eina/eina_matrix.h
+++ b/src/lib/eina/eina_matrix.h
@@ -398,5 +398,140 @@ EAPI Eina_Bool eina_matrix3_quad_square_map(Eina_Matrix3 *m,
398 398
399/** 399/**
400 * @} 400 * @}
401 * @defgroup Eina_Matrix4 Matrices in floating point
402 * @ingroup Eina_Basic
403 * @brief Matrix definition and operations
404 * @{
405 */
406
407typedef struct _Eina_Matrix4 Eina_Matrix4;
408struct _Eina_Matrix4
409{
410 double xx; /**< xx in x' = (x * xx) + (y * xy) + (z * xz) + xw */
411 double xy; /**< xy in x' = (x * xx) + (y * xy) + (z * xz) + xw */
412 double xz; /**< xz in x' = (x * xx) + (y * xy) + (z * xz) + xw */
413 double xw; /**< xw in x' = (x * xx) + (y * xy) + (z * xz) + xw */
414
415 double yx; /**< yx in y' = (x * yx) + (y * yy) + (z * yz) + yw */
416 double yy; /**< yy in y' = (x * yx) + (y * yy) + (z * yz) + yw */
417 double yz; /**< yz in y' = (x * yx) + (y * yy) + (z * yz) + yw */
418 double yw; /**< yw in y' = (x * yx) + (y * yy) + (z * yz) + yw */
419
420 double zx; /**< zx in z' = (x * zx) + (y * zy) + (z * zz) + zw */
421 double zy; /**< zy in z' = (x * zx) + (y * zy) + (z * zz) + zw */
422 double zz; /**< zz in z' = (x * zx) + (y * zy) + (z * zz) + zw */
423 double zw; /**< zw in z' = (x * zx) + (y * zy) + (z * zz) + zw */
424
425 double wx; /**< wx in w' = (x * wx) + (y * wy) + (z * wz) + ww */
426 double wy; /**< wy in w' = (x * wx) + (y * wy) + (z * wz) + ww */
427 double wz; /**< wz in w' = (x * wx) + (y * wy) + (z * wz) + ww */
428 double ww; /**< ww in w' = (x * wx) + (y * wy) + (z * wz) + ww */
429};
430
431/**
432 * @brief Return the type of the given floating point matrix.
433 *
434 * @param m The floating point matrix.
435 * @return The type of the matrix.
436 *
437 * This function returns the type of the matrix @p m. No check is done
438 * on @p m.
439 *
440 * @since 1.15
441 */
442EAPI Eina_Matrix_Type eina_matrix4_type_get(const Eina_Matrix4 *m);
443
444/**
445 * @brief Set the values of the coefficients of the given floating
446 * point matrix.
447 *
448 * @param m The floating point matrix.
449 * @param xx The first coefficient value.
450 * @param xy The second coefficient value.
451 * @param xz The third coefficient value.
452 * @param xw The fourth coefficient value.
453 * @param yx The fifth coefficient value.
454 * @param yy The sixth coefficient value.
455 * @param yz The seventh coefficient value.
456 * @param yw The heighth coefficient value.
457 * @param zx The nineth coefficient value.
458 * @param zy The tenth coefficient value.
459 * @param zz The eleventh coefficient value.
460 * @param zw The twelfth coefficient value.
461 * @param wx The thirteenth coefficient value.
462 * @param wy The fourteenth coefficient value.
463 * @param wz The fifteenth coefficient value.
464 * @param ww The sizteenth coefficient value.
465 *
466 * This function sets the values of the coefficients of the matrix
467 * @p m. No check is done on @p m.
468 *
469 * @see eina_matrix4_values_get()
470 *
471 * @since 1.15
472 */
473EAPI void eina_matrix4_values_set(Eina_Matrix4 *m,
474 double xx, double xy, double xz, double xw,
475 double yx, double yy, double yz, double yw,
476 double zx, double zy, double zz, double zw,
477 double wx, double wy, double wz, double ww);
478
479/**
480 * @brief Get the values of the coefficients of the given floating
481 * point matrix.
482 *
483 * @param m The floating point matrix.
484 * @param xx The first coefficient value.
485 * @param xy The second coefficient value.
486 * @param xz The third coefficient value.
487 * @param xw The fourth coefficient value.
488 * @param yx The fifth coefficient value.
489 * @param yy The sixth coefficient value.
490 * @param yz The seventh coefficient value.
491 * @param yw The heighth coefficient value.
492 * @param zx The nineth coefficient value.
493 * @param zy The tenth coefficient value.
494 * @param zz The eleventh coefficient value.
495 * @param zw The twelfth coefficient value.
496 * @param wx The thirteenth coefficient value.
497 * @param wy The fourteenth coefficient value.
498 * @param wz The fifteenth coefficient value.
499 * @param ww The sizteenth coefficient value.
500 *
501 * This function gets the values of the coefficients of the matrix
502 * @p m. No check is done on @p m.
503 *
504 * @see eina_matrix4_values_set()
505 *
506 * @since 1.15
507 */
508EAPI void eina_matrix4_values_get(const Eina_Matrix4 *m,
509 double *xx, double *xy, double *xz, double *xw,
510 double *yx, double *yy, double *yz, double *yw,
511 double *zx, double *zy, double *zz, double *zw,
512 double *wx, double *wy, double *wz, double *ww);
513
514/**
515 * @brief Convert an Eina_Matrix4 into an Eina_Matrix3.
516 *
517 * @param m3 The destination Eina_Matrix3.
518 * @param m4 The source Eina_Matrix4.
519 *
520 * @since 1.15
521 */
522EAPI void eina_matrix4_matrix3_to(Eina_Matrix3 *m3, const Eina_Matrix4 *m4);
523
524/**
525 * @brief Convert an Eina_Matrix3 into an Eina_Matrix4.
526 *
527 * @param m3 The destination Eina_Matrix3.
528 * @param m4 The source Eina_Matrix4.
529 *
530 * @since 1.15
531 */
532EAPI void eina_matrix3_matrix4_to(Eina_Matrix4 *m4, const Eina_Matrix3 *m3);
533
534/**
535 * @}
401 */ 536 */
402#endif /*EINA_MATRIX3_H_*/ 537#endif /*EINA_MATRIX3_H_*/
diff --git a/src/tests/eina/eina_suite.c b/src/tests/eina/eina_suite.c
index 17706cf483..5383bb6b59 100644
--- a/src/tests/eina/eina_suite.c
+++ b/src/tests/eina/eina_suite.c
@@ -79,8 +79,9 @@ static const Eina_Test_Case etc[] = {
79#ifdef XATTR_TEST_DIR 79#ifdef XATTR_TEST_DIR
80 { "Xattr", eina_test_xattr }, 80 { "Xattr", eina_test_xattr },
81#endif 81#endif
82 {"Crc", eina_test_crc }, 82 { "Crc", eina_test_crc },
83 {"Quad", eina_test_quad }, 83 { "Quad", eina_test_quad },
84 { "Matrix", eina_test_matrix },
84 { NULL, NULL } 85 { NULL, NULL }
85}; 86};
86 87
diff --git a/src/tests/eina/eina_suite.h b/src/tests/eina/eina_suite.h
index 9f3df3a81a..d39254d636 100644
--- a/src/tests/eina/eina_suite.h
+++ b/src/tests/eina/eina_suite.h
@@ -66,5 +66,6 @@ void eina_test_trash(TCase *tc);
66void eina_test_xattr(TCase *tc); 66void eina_test_xattr(TCase *tc);
67void eina_test_crc(TCase *tc); 67void eina_test_crc(TCase *tc);
68void eina_test_quad(TCase *tc); 68void eina_test_quad(TCase *tc);
69void eina_test_matrix(TCase *tc);
69 70
70#endif /* EINA_SUITE_H_ */ 71#endif /* EINA_SUITE_H_ */
diff --git a/src/tests/eina/eina_test_matrix.c b/src/tests/eina/eina_test_matrix.c
new file mode 100644
index 0000000000..046876d2c4
--- /dev/null
+++ b/src/tests/eina/eina_test_matrix.c
@@ -0,0 +1,100 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2015 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#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <math.h>
24#include <stdio.h>
25
26#include "eina_suite.h"
27#include "Eina.h"
28
29START_TEST(eina_matrix4)
30{
31 Eina_Matrix4 m;
32 double xx, xy, xz, xw,
33 yx, yy, yz, yw,
34 zx, zy, zz, zw,
35 wx, wy, wz, ww;
36
37 eina_init();
38
39 eina_matrix4_values_set(&m,
40 1, 0, 0, 0,
41 0, 1, 0, 0,
42 0, 0, 1, 0,
43 0, 0, 0, 1);
44 fail_if(eina_matrix4_type_get(&m) != EINA_MATRIX_TYPE_IDENTITY);
45
46 eina_matrix4_values_get(&m,
47 &xx, &xy, &xz, &xw,
48 &yx, &yy, &yz, &yw,
49 &zx, &zy, &zz, &zw,
50 &wx, &wy, &wz, &ww);
51
52 fail_if(xx != yy ||
53 yy != zz ||
54 zz != ww ||
55 ww != 1);
56 fail_if(xy != xz ||
57 xz != xw ||
58 xw != yx ||
59 yx != yz ||
60 yz != yw ||
61 yw != zx ||
62 zx != zy ||
63 zy != zw ||
64 zw != wx ||
65 wx != wy ||
66 wy != wz ||
67 wz != 0);
68
69 eina_shutdown();
70}
71END_TEST
72
73START_TEST(eina_matrix4_2_3)
74{
75 Eina_Matrix4 m4, m4b;
76 Eina_Matrix3 m3;
77
78 eina_init();
79
80 eina_matrix4_values_set(&m4,
81 1, 3, 2, 0,
82 3, 1, 4, 0,
83 2, 4, 1, 0,
84 0, 0, 0, 1);
85
86 eina_matrix4_matrix3_to(&m3, &m4);
87 eina_matrix3_matrix4_to(&m4b, &m3);
88
89 fail_if(memcmp(&m4, &m4b, sizeof (Eina_Matrix4)) != 0);
90
91 eina_shutdown();
92}
93END_TEST
94
95void
96eina_test_matrix(TCase *tc)
97{
98 tcase_add_test(tc, eina_matrix4);
99 tcase_add_test(tc, eina_matrix4_2_3);
100}