Merge "Add method to get ObjectRegistry from Core" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Matrix.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #include <sstream>
20
21 #include <stdlib.h>
22 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
24
25 using namespace Dali;
26
27
28 void utc_dali_matrix_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void utc_dali_matrix_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38
39 int UtcDaliMatrixConstructor01P(void)
40 {
41   // State of memory cannot be guaranteed, so use
42   // a buffer in a known state to check for changes
43   char buffer[sizeof(Matrix)];
44
45   memset(buffer, 1, sizeof(Matrix));
46
47   Matrix* m2 = new(&buffer) Matrix(false);
48   bool initialisation_occured = false;
49   {
50     float* els = m2->AsFloat();
51     for(size_t idx=0; idx<16; ++idx, ++els)
52     {
53       if(*els == 0.0f)
54         initialisation_occured = true;
55     }
56   }
57
58   DALI_TEST_EQUALS(initialisation_occured, false, TEST_LOCATION);
59
60   END_TEST;
61 }
62
63 int UtcDaliMatrixConstructor02P(void)
64 {
65   float r[] = { 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f};
66   Matrix m(r);
67
68   float* els = m.AsFloat();
69   float* init = r;
70   bool initialised = true;
71   for(size_t idx=0; idx<16; ++idx, ++els, ++init)
72   {
73     if(*els != *init)
74       initialised = false;
75   }
76   DALI_TEST_EQUALS(initialised, true, TEST_LOCATION);
77
78   END_TEST;
79 }
80
81 int UtcDaliMatrixConstructor03P(void)
82 {
83   float r[] = { 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f};
84
85   Matrix ma(r);
86   Matrix mb(ma);
87
88   float* els = ma.AsFloat();
89   float* init = mb.AsFloat();
90   bool initialised = true;
91   for(size_t idx=0; idx<16; ++idx, ++els, ++init)
92   {
93     if(*els != *init)
94       initialised = false;
95   }
96   DALI_TEST_EQUALS(initialised, true, TEST_LOCATION);
97
98   END_TEST;
99 }
100
101 int UtcDaliMatrixConstructor04P(void)
102 {
103   Quaternion q(Quaternion::IDENTITY);
104   Matrix m(q);
105   DALI_TEST_EQUALS(Matrix(Matrix::IDENTITY), m, 0.001, TEST_LOCATION);
106   END_TEST;
107 }
108
109 int UtcDaliMatrixCopyConstructor(void)
110 {
111   Matrix m0( Matrix::IDENTITY );
112   Matrix m1( m0 );
113   DALI_TEST_EQUALS(m1, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
114
115   END_TEST;
116 }
117
118 int UtcDaliMatrixMoveConstructor(void)
119 {
120   Matrix m0( Matrix::IDENTITY );
121   Matrix m1 = std::move( m0 );
122   DALI_TEST_EQUALS(m1, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
123
124   END_TEST;
125 }
126
127 int UtcDaliMatrixCopyAssignment(void)
128 {
129   Matrix m0( Matrix::IDENTITY );
130   Matrix m1;
131   m1 = m0;
132   DALI_TEST_EQUALS(m1, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
133
134   END_TEST;
135 }
136
137 int UtcDaliMatrixMoveAssignment(void)
138 {
139   Matrix m0( Matrix::IDENTITY );
140   Matrix m1;
141   m1 = std::move( m0 );
142   DALI_TEST_EQUALS(m1, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
143
144   END_TEST;
145 }
146
147 int UtcDaliMatrixAssignP(void)
148 {
149   Matrix a(Matrix::IDENTITY);
150   Matrix b = a;
151   DALI_TEST_EQUALS(a, b, 0.001, TEST_LOCATION);
152   END_TEST;
153 }
154
155 int UtcDaliMatrixAssign02P(void)
156 {
157   Matrix a(Matrix::IDENTITY);
158   a = a; // self assign does the do nothing branch
159   DALI_TEST_EQUALS(Matrix(Matrix::IDENTITY), a, 0.001, TEST_LOCATION);
160   END_TEST;
161 }
162
163 int UtcDaliMatrixSetIdentityP(void)
164 {
165   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
166                   4.0f,  5.0f,  6.0f,  7.0f,
167                   8.0f,  9.0f, 10.0f, 11.0f,
168                   12.0f, 13.0f, 14.0f, 15.0f };
169   Matrix m(els);
170   m.SetIdentity();
171
172   DALI_TEST_EQUALS(m, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
173   END_TEST;
174 }
175
176 int UtcDaliMatrixSetIdentityAndScaleP(void)
177 {
178   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
179                   4.0f,  5.0f,  6.0f,  7.0f,
180                   8.0f,  9.0f, 10.0f, 11.0f,
181                   12.0f, 13.0f, 14.0f, 15.0f };
182   Matrix m(els);
183   m.SetIdentityAndScale(Vector3(4.0f, 4.0f, 4.0f));
184
185   float els2[] = { 4.0f, 0.0f, 0.0f, 0.0f,
186                    0.0f, 4.0f, 0.0f, 0.0f,
187                    0.0f, 0.0f, 4.0f, 0.0f,
188                    0.0f, 0.0f, 0.0f, 1.0f };
189   Matrix r(els2);
190
191   DALI_TEST_EQUALS(m, r, 0.001f, TEST_LOCATION);
192   END_TEST;
193 }
194
195 int UtcDaliMatrixInvertTransformP(void)
196 {
197   for (int i=0;i<1000;++i)
198   {
199     float f = i;
200     Vector3 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f));
201     axis.Normalize();
202     Vector3 center(f, cosf(f) * 100.0f, cosf(f*0.5f) * 50.0f);
203
204     Matrix m0;
205     m0.SetIdentity();
206     m0.SetTransformComponents( Vector3::ONE, Quaternion(Radian(1.0f), axis), center );
207
208     Matrix m1;
209     m0.InvertTransform(m1);
210
211     Matrix m2( false );
212     Matrix::Multiply( m2, m0, m1 );
213
214     DALI_TEST_EQUALS(m2, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
215   }
216   END_TEST;
217 }
218
219 int UtcDaliMatrixInvertTransformN(void)
220 {
221   std::string exceptionString( "EqualsZero( mMatrix[3] ) && EqualsZero( mMatrix[7] ) && EqualsZero( mMatrix[11] ) && Equals( mMatrix[15], 1.0f" );
222   try
223   {
224     float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
225                     4.0f,  5.0f,  6.0f,  7.0f,
226                     8.0f,  9.0f, 10.0f, 11.0f,
227                     12.0f, 13.0f, 14.0f, 15.0f };
228     Matrix m(els);
229
230     Matrix it;
231     m.InvertTransform(it);
232     tet_result(TET_FAIL);
233   }
234   catch (Dali::DaliException& e)
235   {
236     DALI_TEST_PRINT_ASSERT( e );
237     DALI_TEST_ASSERT( e, exceptionString, TEST_LOCATION );
238   }
239
240   try
241   {
242     float els[] = { 0.0f,  1.0f,  2.0f,  0.0f,
243                     4.0f,  5.0f,  6.0f,  7.0f,
244                     8.0f,  9.0f, 10.0f, 11.0f,
245                     12.0f, 13.0f, 14.0f, 15.0f };
246     Matrix m(els);
247
248     Matrix it;
249     m.InvertTransform(it);
250     tet_result(TET_FAIL);
251   }
252   catch (Dali::DaliException& e)
253   {
254     DALI_TEST_PRINT_ASSERT( e );
255     DALI_TEST_ASSERT( e, exceptionString, TEST_LOCATION );
256   }
257
258   try
259   {
260     float els[] = { 0.0f,  1.0f,  2.0f,  0.0f,
261                     4.0f,  5.0f,  6.0f,  0.0f,
262                     8.0f,  9.0f, 10.0f, 11.0f,
263                     12.0f, 13.0f, 14.0f, 15.0f };
264     Matrix m(els);
265
266     Matrix it;
267     m.InvertTransform(it);
268     tet_result(TET_FAIL);
269   }
270   catch (Dali::DaliException& e)
271   {
272     DALI_TEST_PRINT_ASSERT( e );
273     DALI_TEST_ASSERT( e, exceptionString, TEST_LOCATION );
274   }
275
276   try
277   {
278     float els[] = { 0.0f,  1.0f,  2.0f,  0.0f,
279                     4.0f,  5.0f,  6.0f,  0.0f,
280                     8.0f,  9.0f, 10.0f,  0.0f,
281                     12.0f, 13.0f, 14.0f, 15.0f };
282     Matrix m(els);
283
284     Matrix it;
285     m.InvertTransform(it);
286     tet_result(TET_FAIL);
287   }
288   catch (Dali::DaliException& e)
289   {
290     DALI_TEST_PRINT_ASSERT( e );
291     DALI_TEST_ASSERT( e, exceptionString, TEST_LOCATION );
292   }
293   END_TEST;
294 }
295
296 int UtcDaliMatrixInvert01P(void)
297 {
298   // We're going to invert a whole load of different matrices to make sure we don't
299   // fail on particular orientations.
300   for (int i=0;i<1000;++i)
301   {
302     float f = i;
303     Vector3 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f));
304     axis.Normalize();
305     Vector3 center(f, cosf(f) * 100.0f, cosf(f*0.5f) * 50.0f);
306
307     Matrix m0;
308     m0.SetIdentity();
309     m0.SetTransformComponents( Vector3::ONE, Quaternion(Radian(1.0f), axis), center );
310
311     Matrix m1(m0);
312     m1.Invert();
313
314     Matrix m2( false );
315     Matrix::Multiply( m2, m0, m1 );
316
317     DALI_TEST_EQUALS(m2, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
318
319     m1.Invert();    // doube invert - should be back to m0
320
321     DALI_TEST_EQUALS(m0, m1, 0.001f, TEST_LOCATION);
322   }
323   END_TEST;
324 }
325
326 int UtcDaliMatrixInvert02P(void)
327 {
328   Matrix m1 = Matrix::IDENTITY;
329   m1.SetXAxis(Vector3(0.0f, 0.0f, 0.0f));
330   DALI_TEST_EQUALS(m1.Invert(), false, TEST_LOCATION);
331   END_TEST;
332 }
333
334 int UtcDaliMatrixTransposeP(void)
335 {
336   float floats[] =
337   {   0.0f,  1.0f,  2.0f,  3.0f,
338       4.0f,  5.0f,  6.0f,  7.0f,
339       8.0f,  9.0f, 10.0f,  11.0f,
340      12.0f, 13.0f, 14.0f,  15.0f
341   };
342
343   Matrix m(floats);
344   m.Transpose();
345
346   bool success = true;
347
348   for (int x=0;x<4;++x)
349   {
350     for (int y=0;y<4;++y)
351     {
352       success &= (m.AsFloat()[x+y*4] == floats[x*4+y]);
353     }
354   }
355
356   DALI_TEST_CHECK(success);
357   END_TEST;
358 }
359
360 int UtcDaliMatrixGetXAxisP(void)
361 {
362   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
363                   4.0f,  5.0f,  6.0f,  7.0f,
364                   8.0f,  9.0f, 10.0f, 11.0f,
365                   12.0f, 13.0f, 14.0f, 15.0f };
366   Matrix m(els);
367
368   DALI_TEST_CHECK(m.GetXAxis() == Vector3(0.0f,  1.0f,  2.0f));
369   END_TEST;
370 }
371
372 int UtcDaliMatrixGetYAxisP(void)
373 {
374   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
375                   4.0f,  5.0f,  6.0f,  7.0f,
376                   8.0f,  9.0f, 10.0f, 11.0f,
377                   12.0f, 13.0f, 14.0f, 15.0f };
378   Matrix m(els);
379
380   DALI_TEST_CHECK(m.GetYAxis() == Vector3(4.0f,  5.0f,  6.0f));
381   END_TEST;
382 }
383
384 int UtcDaliMatrixGetZAxisP(void)
385 {
386   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
387                   4.0f,  5.0f,  6.0f,  7.0f,
388                   8.0f,  9.0f, 10.0f, 11.0f,
389                   12.0f, 13.0f, 14.0f, 15.0f };
390   Matrix m(els);
391
392   DALI_TEST_CHECK(m.GetZAxis() == Vector3(8.0f,  9.0f, 10.0f));
393   END_TEST;
394 }
395
396 int UtcDaliMatrixSetXAxisP(void)
397 {
398   Matrix m;
399   Vector3 v(2.0f, 3.0f, 4.0f);
400   m.SetXAxis(v);
401
402   DALI_TEST_CHECK(m.GetXAxis() == v);
403   END_TEST;
404 }
405
406 int UtcDaliMatrixSetYAxisP(void)
407 {
408   Matrix m;
409   Vector3 v(2.0f, 3.0f, 4.0f);
410   m.SetYAxis(v);
411
412   DALI_TEST_CHECK(m.GetYAxis() == v);
413   END_TEST;
414 }
415
416 int UtcDaliMatrixSetZAxisP(void)
417 {
418   Matrix m;
419   Vector3 v(2.0f, 3.0f, 4.0f);
420   m.SetZAxis(v);
421
422   DALI_TEST_CHECK(m.GetZAxis() == v);
423   END_TEST;
424 }
425
426 int UtcDaliMatrixGetTranslationP(void)
427 {
428   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
429                   4.0f,  5.0f,  6.0f,  7.0f,
430                   8.0f,  9.0f, 10.0f, 11.0f,
431                   12.0f, 13.0f, 14.0f, 15.0f };
432   Matrix m(els);
433
434   DALI_TEST_EQUALS(m.GetTranslation(), Vector4(12.0f, 13.0f, 14.0f, 15.0f), TEST_LOCATION);
435   END_TEST;
436 }
437
438 int UtcDaliMatrixGetTranslation3P(void)
439 {
440   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
441                   4.0f,  5.0f,  6.0f,  7.0f,
442                   8.0f,  9.0f, 10.0f, 11.0f,
443                   12.0f, 13.0f, 14.0f, 15.0f };
444   Matrix m(els);
445
446   DALI_TEST_EQUALS(m.GetTranslation3(), Vector3(12.0f, 13.0f, 14.0f), TEST_LOCATION);
447   END_TEST;
448 }
449
450 int UtcDaliMatrixSetTranslationP(void)
451 {
452   Matrix m;
453   Vector4 v(2.0f, 3.0f, 4.0f, 5.0f);
454   m.SetTranslation(v);
455
456   DALI_TEST_CHECK(m.GetTranslation() == v);
457   END_TEST;
458 }
459
460 int UtcDaliMatrixSetTranslation3P(void)
461 {
462   Matrix m;
463   Vector3 v(2.0f, 3.0f, 4.0f);
464   m.SetTranslation(v);
465
466   DALI_TEST_CHECK(m.GetTranslation3() == v);
467   END_TEST;
468 }
469
470 int UtcDaliMatrixOrthoNormalize0P(void)
471 {
472   // OrthoNormalise fixes floating point errors from matrix rotations
473   Matrix m;
474   m.SetIdentity();
475
476   for (int i=0;i<1000;++i)
477   {
478     float f = i;
479     Vector3 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f));
480     axis.Normalize();
481
482     m.SetTransformComponents( Vector3::ONE, Quaternion(Radian(1.0f), axis), Vector3::ZERO );
483     m.OrthoNormalize();
484   }
485
486   bool success = true;
487   success &= fabsf(m.GetXAxis().Dot(m.GetYAxis())) < 0.001f;
488   success &= fabsf(m.GetYAxis().Dot(m.GetXAxis())) < 0.001f;
489   success &= fabsf(m.GetZAxis().Dot(m.GetYAxis())) < 0.001f;
490
491   success &= fabsf(m.GetXAxis().Length() - 1.0f) < 0.001f;
492   success &= fabsf(m.GetYAxis().Length() - 1.0f) < 0.001f;
493   success &= fabsf(m.GetZAxis().Length() - 1.0f) < 0.001f;
494
495   DALI_TEST_CHECK(success);
496   END_TEST;
497 }
498
499 int UtcDaliMatrixOrthoNormalize1P(void)
500 {
501   // OrthoNormalize is not flipping the axes and is maintaining the translation
502   for (int i=0;i<1000;++i)
503   {
504     float f = i;
505     Vector3 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f));
506     axis.Normalize();
507     Vector3 center(10.0f, 15.0f, 5.0f);
508
509     Matrix m0;
510     m0.SetIdentity();
511     m0.SetTransformComponents( Vector3::ONE, Quaternion(Radian(1.0f), axis), center );
512
513     Matrix m1(m0);
514     m1.OrthoNormalize();
515
516     DALI_TEST_EQUALS(m0.GetXAxis(), m1.GetXAxis(), 0.001f, TEST_LOCATION);
517     DALI_TEST_EQUALS(m0.GetYAxis(), m1.GetYAxis(), 0.001f, TEST_LOCATION);
518     DALI_TEST_EQUALS(m0.GetZAxis(), m1.GetZAxis(), 0.001f, TEST_LOCATION);
519     DALI_TEST_EQUALS(m0.GetTranslation(), m1.GetTranslation(), 0.001f, TEST_LOCATION);
520   }
521   END_TEST;
522 }
523
524 int UtcDaliMatrixConstAsFloatP(void)
525 {
526   float r[] = { 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f};
527   const Matrix m(r);
528
529   const float* els = m.AsFloat();
530   const float* init = r;
531   bool initialised = true;
532   for(size_t idx=0; idx<16; ++idx, ++els, ++init)
533   {
534     if(*els != *init)
535       initialised = false;
536   }
537   DALI_TEST_EQUALS(initialised, true, TEST_LOCATION);
538
539
540   END_TEST;
541 }
542
543 int UtcDaliMatrixAsFloatP(void)
544 {
545   float r[] = { 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f};
546   Matrix m(r);
547
548   float* els = m.AsFloat();
549   float* init = r;
550   bool initialised = true;
551   for(size_t idx=0; idx<16; ++idx, ++els, ++init)
552   {
553     if(*els != *init)
554       initialised = false;
555   }
556   DALI_TEST_EQUALS(initialised, true, TEST_LOCATION);
557
558
559   END_TEST;
560 }
561
562 int UtcDaliMatrixMultiplyP(void)
563 {
564   Matrix m1 = Matrix::IDENTITY;
565
566   float els[] = { 1.0f, 0.0f,    0.0f,   0.0f,
567                   0.0f, 0.707f, 0.707f, 0.0f,
568                   0.0f, -0.707f,  0.707f, 0.0f,
569                   0.0f, 0.0f,    0.0f,   1.0f };
570   Matrix result(els);
571
572   Quaternion q(Radian(Degree(45.0f)), Vector3::XAXIS);
573   Matrix m2(false);
574   Matrix::Multiply(m2, m1, q);
575
576   DALI_TEST_EQUALS(m2, result, 0.01f, TEST_LOCATION);
577   END_TEST;
578 }
579
580 int UtcDaliMatrixOperatorMultiply01P(void)
581 {
582   Vector4 v1(2.0f, 5.0f, 4.0f, 0.0f);
583
584   float els[] = {2.0f, 0.0f, 0.0f, 0.0f,
585                  0.0f, 3.0f, 0.0f, 0.0f,
586                  0.0f, 0.0f, 4.0f, 0.0f,
587                  0.0f, 0.0f, 0.0f, 1.0f };
588   Matrix m1(els);
589
590   Vector4 v2 = m1 * v1;
591   Vector4 r1(4.0f, 15.0f, 16.0f, 0.0f);
592   DALI_TEST_EQUALS(v2, r1, 0.01f, TEST_LOCATION);
593   END_TEST;
594 }
595
596 int UtcDaliMatrixOperatorMultiply02P(void)
597 {
598   TestApplication application;
599
600   Vector3 position ( 30.f, 40.f, 50.f);
601
602   Matrix m1(false);
603   m1.SetIdentity();
604   m1.SetTranslation(-position);
605
606   Vector4 positionV4(position);
607   positionV4.w=1.0f;
608   Vector4 output = m1 * positionV4;
609
610   output.w = 0.0f;
611   DALI_TEST_EQUALS(output, Vector4::ZERO, 0.01f, TEST_LOCATION);
612   END_TEST;
613 }
614
615 int UtcDaliMatrixOperatorEqualsP(void)
616 {
617   Matrix m1 = Matrix::IDENTITY;
618
619   float els[] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
620   Matrix r2(els);
621   DALI_TEST_EQUALS(m1 == r2, true, TEST_LOCATION);
622
623   float *f = m1.AsFloat();
624   for(size_t i=0; i<16; i++)
625   {
626     f[15-i] = 1.2f;
627     DALI_TEST_EQUALS(m1 == r2, false, TEST_LOCATION);
628   }
629   END_TEST;
630 }
631
632 int UtcDaliMatrixOperatorNotEqualsP(void)
633 {
634   Matrix m1 = Matrix::IDENTITY;
635   float els[] = {2.0f, 0.0f, 0.0f, 0.0f,
636                  0.0f, 3.0f, 0.0f, 0.0f,
637                  0.0f, 0.0f, 4.0f, 0.0f,
638                  0.0f, 0.0f, 0.0f, 1.0f };
639   Matrix r1(els);
640
641   DALI_TEST_CHECK(m1 != r1);
642   DALI_TEST_CHECK(!(m1 != m1));
643   END_TEST;
644 }
645
646 int UtcDaliMatrixSetTransformComponents01P(void)
647 {
648   // Create an arbitrary vector
649   for( float x=-1.0f; x<=1.0f; x+=0.1f )
650   {
651     for( float y=-1.0f; y<1.0f; y+=0.1f )
652     {
653       for( float z=-1.0f; z<1.0f; z+=0.1f )
654       {
655         Vector3 vForward(x, y, z);
656         vForward.Normalize();
657
658         for( float angle = 5.0f; angle <= 360.0f; angle += 15.0f)
659         {
660           Quaternion rotation1(Radian(Degree(angle)), vForward);
661
662           Matrix m1(rotation1);
663           Matrix result1(false);
664           Vector3 vForward3(vForward.x, vForward.y, vForward.z);
665           result1.SetTransformComponents( Vector3::ONE, Quaternion(Radian(Degree(angle)), vForward3), Vector3::ZERO );
666
667           DALI_TEST_EQUALS(m1, result1, 0.001, TEST_LOCATION);
668
669           Matrix m2(false);
670           m2.SetTransformComponents(vForward, Quaternion::IDENTITY, Vector3::ZERO);
671
672           Matrix result2a(Matrix::IDENTITY);
673           result2a.SetXAxis(result2a.GetXAxis() * vForward[0]);
674           result2a.SetYAxis(result2a.GetYAxis() * vForward[1]);
675           result2a.SetZAxis(result2a.GetZAxis() * vForward[2]);
676
677           DALI_TEST_EQUALS(m2, result2a, 0.001, TEST_LOCATION);
678
679           Matrix m3(false);
680           m3.SetTransformComponents(vForward, rotation1, Vector3::ZERO);
681
682           Matrix result3(Matrix::IDENTITY);
683           result3.SetXAxis(result3.GetXAxis() * vForward[0]);
684           result3.SetYAxis(result3.GetYAxis() * vForward[1]);
685           result3.SetZAxis(result3.GetZAxis() * vForward[2]);
686
687           Matrix::Multiply(result3, result3, m1);
688           DALI_TEST_EQUALS(m3, result3, 0.001, TEST_LOCATION);
689         }
690       }
691     }
692   }
693   END_TEST;
694 }
695
696 int UtcDaliMatrixSetInverseTransformComponent01P(void)
697 {
698   // Create an arbitrary vector
699   for( float x=-1.0f; x<=1.0f; x+=0.1f )
700   {
701     for( float y=-1.0f; y<1.0f; y+=0.1f )
702     {
703       for( float z=-1.0f; z<1.0f; z+=0.1f )
704       {
705         Vector3 vForward(x, y, z);
706         vForward.Normalize();
707
708         {
709           Quaternion rotation1(Quaternion::IDENTITY); // test no rotation branch
710           Vector3 scale1(2.0f, 3.0f, 4.0f);
711           Vector3 position1(1.0f, 2.0f, 3.0f);
712
713           Matrix m1(false);
714           m1.SetTransformComponents(scale1, rotation1, position1);
715
716           Matrix m2(false);
717           m2.SetInverseTransformComponents(scale1, rotation1, position1);
718
719           Matrix result;
720           Matrix::Multiply(result, m1, m2);
721
722           DALI_TEST_EQUALS(result, Matrix::IDENTITY, 0.001, TEST_LOCATION);
723         }
724       }
725     }
726   }
727   END_TEST;
728 }
729
730 int UtcDaliMatrixSetInverseTransformComponent02P(void)
731 {
732   // Create an arbitrary vector
733   for( float x=-1.0f; x<=1.0f; x+=0.1f )
734   {
735     for( float y=-1.0f; y<1.0f; y+=0.1f )
736     {
737       for( float z=-1.0f; z<1.0f; z+=0.1f )
738       {
739         Vector3 vForward(x, y, z);
740         vForward.Normalize();
741
742         for( float angle = 5.0f; angle <= 360.0f; angle += 15.0f)
743         {
744           Quaternion rotation1(Radian(Degree(angle)), vForward);
745           Matrix rotationMatrix(rotation1);   // TEST RELIES ON THIS METHOD WORKING!!!
746
747           Vector3 position1(5.0f, -6.0f, 7.0f);
748
749           Matrix m1(false);
750           m1.SetTransformComponents( Vector3::ONE, rotation1, position1 );
751
752           Matrix m2(false);
753           m2.SetInverseTransformComponents( rotationMatrix.GetXAxis(),
754                                             rotationMatrix.GetYAxis(),
755                                             rotationMatrix.GetZAxis(),
756                                             position1 );
757
758           Matrix result;
759           Matrix::Multiply(result, m1, m2);
760
761           DALI_TEST_EQUALS(result, Matrix::IDENTITY, 0.001, TEST_LOCATION);
762         }
763       }
764     }
765   }
766   END_TEST;
767 }
768
769 int UtcDaliMatrixGetTransformComponents01P(void)
770 {
771   Matrix m2(Matrix::IDENTITY.AsFloat());
772   Vector3 pos2;
773   Vector3 scale2;
774   Quaternion q2;
775   m2.GetTransformComponents(pos2, q2, scale2);
776   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), pos2, 0.001, TEST_LOCATION);
777   DALI_TEST_EQUALS(Vector3(1.0f, 1.0f, 1.0f), scale2, 0.001, TEST_LOCATION);
778   DALI_TEST_EQUALS(Quaternion(), q2, 0.001, TEST_LOCATION);
779   END_TEST;
780 }
781
782
783 int UtcDaliMatrixGetTransformComponents02P(void)
784 {
785   // Create an arbitrary vector
786   for( float x=-1.0f; x<=1.0f; x+=0.1f )
787   {
788     for( float y=-1.0f; y<1.0f; y+=0.1f )
789     {
790       for( float z=-1.0f; z<1.0f; z+=0.1f )
791       {
792         Vector3 vForward(x, y, z);
793         vForward.Normalize();
794
795         for( float angle = 5.0f; angle <= 360.0f; angle += 15.0f)
796         {
797           Quaternion rotation1(Radian(Degree(angle)), vForward);
798           Vector3 scale1(2.0f, 3.0f, 4.0f);
799           Vector3 position1(1.0f, 2.0f, 3.0f);
800
801           Matrix m1(false);
802           m1.SetTransformComponents(scale1, rotation1, position1);
803
804           Vector3 position2;
805           Quaternion rotation2;
806           Vector3 scale2;
807           m1.GetTransformComponents(position2, rotation2, scale2);
808
809           DALI_TEST_EQUALS(position1, position2, 0.001, TEST_LOCATION);
810           DALI_TEST_EQUALS(scale1, scale2, 0.001, TEST_LOCATION);
811           DALI_TEST_EQUALS(rotation1, rotation2, 0.001, TEST_LOCATION);
812         }
813       }
814     }
815   }
816   END_TEST;
817 }
818
819 int UtcDaliMatrixGetTransformComponents03P(void)
820 {
821   Matrix m2; // zero branch
822   Vector3 pos2;
823   Vector3 scale2;
824   Quaternion q2;
825   m2.GetTransformComponents(pos2, q2, scale2);
826   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), pos2, 0.001, TEST_LOCATION);
827   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), scale2, 0.001, TEST_LOCATION);
828   // DALI_TEST_EQUALS(Quaternion(), q2, 0.001, TEST_LOCATION);
829   END_TEST;
830 }
831
832 int UtcDaliMatrixOStreamOperator(void)
833 {
834   std::ostringstream oss;
835
836   Matrix matrix;
837   matrix.SetIdentity();
838
839   oss << matrix;
840
841   std::string expectedOutput = "[ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]";
842
843   DALI_TEST_EQUALS( oss.str(), expectedOutput, TEST_LOCATION);
844   END_TEST;
845 }