X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali%2Futc-Dali-Matrix.cpp;h=d40d9b3513c303a23d389e2ebc8f3f2e78244dc7;hb=53962366b6f3138455ddb929b1c25a25d2e15252;hp=573e63e5623db6d812365d34c85e19b13871f601;hpb=df59eea2434495c32414fcf9ffafe4cb7dff5324;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/automated-tests/src/dali/utc-Dali-Matrix.cpp b/automated-tests/src/dali/utc-Dali-Matrix.cpp index 573e63e..d40d9b3 100644 --- a/automated-tests/src/dali/utc-Dali-Matrix.cpp +++ b/automated-tests/src/dali/utc-Dali-Matrix.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,16 +15,15 @@ * */ +#include +#include +#include + #include #include -#include -#include -#include - using namespace Dali; - void utc_dali_matrix_startup(void) { test_return_value = TET_UNDEF; @@ -35,358 +34,332 @@ void utc_dali_matrix_cleanup(void) test_return_value = TET_PASS; } - -int UtcDaliMatrixCtor(void) +int UtcDaliMatrixConstructor01P(void) { - // Test initialized startup - Matrix m1; - - float r1[] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; - float r2[] = {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}; - Matrix mr1(r1); - Matrix mr2(r2); + // State of memory cannot be guaranteed, so use + // a buffer in a known state to check for changes + char buffer[sizeof(Matrix)]; - DALI_TEST_EQUALS(m1, mr1, 0.001f, TEST_LOCATION); + memset(buffer, 1, sizeof(Matrix)); - // Test uninitialized startup - // Stack construct a matrix to non zero, then stack construct another matrix over the top of it. - float r3[] = { 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}; + Matrix* m2 = new(&buffer) Matrix(false); + bool initialisation_occured = false; { - Matrix m3(r3); - } - { - Matrix m2(false); - - bool initialised = true; + float* els = m2->AsFloat(); + for(size_t idx = 0; idx < 16; ++idx, ++els) { - float* els = m2.AsFloat(); - for(size_t idx=0; idx<16; ++idx, ++els) - { - if(*els != 0.0f) - initialised = false; - } + if(*els == 0.0f) + initialisation_occured = true; } - - DALI_TEST_EQUALS(initialised, false, TEST_LOCATION); } - Matrix m4(true); - DALI_TEST_EQUALS(m4, mr1, 0.001f, TEST_LOCATION); - - m4 = m4; - DALI_TEST_EQUALS(m4, mr1, 0.001f, TEST_LOCATION); + DALI_TEST_EQUALS(initialisation_occured, false, TEST_LOCATION); - Matrix m5(false); - m5.SetIdentity(); - Matrix m6 = m5; - DALI_TEST_EQUALS(m6, mr2, 0.001f, TEST_LOCATION); END_TEST; } -// OrthoNormalise fixes floating point errors from matrix rotations -int UtcDaliMatrixOrthoNormalize0(void) +int UtcDaliMatrixConstructor02P(void) { - Matrix m; - m.SetIdentity(); + 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}; + Matrix m(r); - for (int i=0;i<1000;++i) + float* els = m.AsFloat(); + float* init = r; + bool initialised = true; + for(size_t idx = 0; idx < 16; ++idx, ++els, ++init) { - float f = i; - Vector4 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f), 0.0f); - axis.Normalize(); - - m.SetTransformComponents( Vector3::ONE, Quaternion(1.0f, axis), Vector3::ZERO ); - m.OrthoNormalize(); + if(*els != *init) + initialised = false; } + DALI_TEST_EQUALS(initialised, true, TEST_LOCATION); - bool success = true; - success &= fabsf(m.GetXAxis().Dot(m.GetYAxis())) < 0.001f; - success &= fabsf(m.GetYAxis().Dot(m.GetXAxis())) < 0.001f; - success &= fabsf(m.GetZAxis().Dot(m.GetYAxis())) < 0.001f; - - success &= fabsf(m.GetXAxis().Length() - 1.0f) < 0.001f; - success &= fabsf(m.GetYAxis().Length() - 1.0f) < 0.001f; - success &= fabsf(m.GetZAxis().Length() - 1.0f) < 0.001f; - - DALI_TEST_CHECK(success); END_TEST; } -// OrthoNormalize is not flipping the axes and is maintaining the translation -int UtcDaliMatrixOrthoNormalize1(void) +int UtcDaliMatrixConstructor03P(void) { - for (int i=0;i<1000;++i) + 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}; + + Matrix ma(r); + Matrix mb(ma); + + float* els = ma.AsFloat(); + float* init = mb.AsFloat(); + bool initialised = true; + for(size_t idx = 0; idx < 16; ++idx, ++els, ++init) { - float f = i; - Vector4 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f), 0.0f); - axis.Normalize(); - Vector3 center(10.0f, 15.0f, 5.0f); + if(*els != *init) + initialised = false; + } + DALI_TEST_EQUALS(initialised, true, TEST_LOCATION); - Matrix m0; - m0.SetIdentity(); - m0.SetTransformComponents( Vector3::ONE, Quaternion(1.0f, axis), center ); + END_TEST; +} - Matrix m1(m0); - m1.OrthoNormalize(); +int UtcDaliMatrixConstructor04P(void) +{ + Quaternion q(Quaternion::IDENTITY); + Matrix m(q); + DALI_TEST_EQUALS(Matrix(Matrix::IDENTITY), m, 0.001, TEST_LOCATION); + END_TEST; +} + +int UtcDaliMatrixCopyConstructor(void) +{ + Matrix m0(Matrix::IDENTITY); + Matrix m1(m0); + DALI_TEST_EQUALS(m1, Matrix::IDENTITY, 0.001f, TEST_LOCATION); - DALI_TEST_EQUALS(m0.GetXAxis(), m1.GetXAxis(), 0.001f, TEST_LOCATION); - DALI_TEST_EQUALS(m0.GetYAxis(), m1.GetYAxis(), 0.001f, TEST_LOCATION); - DALI_TEST_EQUALS(m0.GetZAxis(), m1.GetZAxis(), 0.001f, TEST_LOCATION); - DALI_TEST_EQUALS(m0.GetTranslation(), m1.GetTranslation(), 0.001f, TEST_LOCATION); - } END_TEST; } -// Invert works -int UtcDaliMatrixInvert01(void) +int UtcDaliMatrixMoveConstructor(void) { - // We're going to invert a whole load of different matrices to make sure we don't - // fail on particular orientations. - for (int i=0;i<1000;++i) - { - float f = i; - Vector4 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f), 0.0f); - axis.Normalize(); - Vector3 center(f, cosf(f) * 100.0f, cosf(f*0.5f) * 50.0f); + Matrix m0(Matrix::IDENTITY); + Matrix m1 = std::move(m0); + DALI_TEST_EQUALS(m1, Matrix::IDENTITY, 0.001f, TEST_LOCATION); - Matrix m0; - m0.SetIdentity(); - m0.SetTransformComponents( Vector3::ONE, Quaternion(1.0f, axis), center ); + END_TEST; +} - Matrix m1(m0); - m1.Invert(); +int UtcDaliMatrixCopyAssignment(void) +{ + Matrix m0(Matrix::IDENTITY); + Matrix m1; + m1 = m0; + DALI_TEST_EQUALS(m1, Matrix::IDENTITY, 0.001f, TEST_LOCATION); - Matrix m2( false ); - Matrix::Multiply( m2, m0, m1 ); + END_TEST; +} - DALI_TEST_EQUALS(m2, Matrix::IDENTITY, 0.001f, TEST_LOCATION); +int UtcDaliMatrixMoveAssignment(void) +{ + Matrix m0(Matrix::IDENTITY); + Matrix m1; + m1 = std::move(m0); + DALI_TEST_EQUALS(m1, Matrix::IDENTITY, 0.001f, TEST_LOCATION); - m1.Invert(); // doube invert - should be back to m0 + END_TEST; +} - DALI_TEST_EQUALS(m0, m1, 0.001f, TEST_LOCATION); - } +int UtcDaliMatrixAssignP(void) +{ + Matrix a(Matrix::IDENTITY); + Matrix b = a; + DALI_TEST_EQUALS(a, b, 0.001, TEST_LOCATION); END_TEST; } +int UtcDaliMatrixAssign02P(void) +{ + Matrix a(Matrix::IDENTITY); + a = a; // self assign does the do nothing branch + DALI_TEST_EQUALS(Matrix(Matrix::IDENTITY), a, 0.001, TEST_LOCATION); + END_TEST; +} -int UtcDaliMatrixInvert02(void) +int UtcDaliMatrixSetIdentityP(void) { - Matrix m1 = Matrix::IDENTITY; - m1.SetXAxis(Vector3(0.0f, 0.0f, 0.0f)); - DALI_TEST_EQUALS(m1.Invert(), false, TEST_LOCATION); + float els[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f}; + Matrix m(els); + m.SetIdentity(); + + DALI_TEST_EQUALS(m, Matrix::IDENTITY, 0.001f, TEST_LOCATION); END_TEST; } +int UtcDaliMatrixSetIdentityAndScaleP(void) +{ + float els[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f}; + Matrix m(els); + m.SetIdentityAndScale(Vector3(4.0f, 4.0f, 4.0f)); + + float els2[] = {4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; + Matrix r(els2); + + DALI_TEST_EQUALS(m, r, 0.001f, TEST_LOCATION); + END_TEST; +} -// Invert transform works -int UtcDaliMatrixInvertTransform01(void) +int UtcDaliMatrixInvertTransformP(void) { - for (int i=0;i<1000;++i) + for(int i = 0; i < 1000; ++i) { - float f = i; - Vector4 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f), 0.0f); + float f = i; + Vector3 axis(cosf(f * 0.001f), cosf(f * 0.02f), cosf(f * 0.03f)); axis.Normalize(); - Vector3 center(f, cosf(f) * 100.0f, cosf(f*0.5f) * 50.0f); + Vector3 center(f, cosf(f) * 100.0f, cosf(f * 0.5f) * 50.0f); Matrix m0; m0.SetIdentity(); - m0.SetTransformComponents( Vector3::ONE, Quaternion(1.0f, axis), center ); + m0.SetTransformComponents(Vector3::ONE, Quaternion(Radian(1.0f), axis), center); Matrix m1; m0.InvertTransform(m1); - Matrix m2( false ); - Matrix::Multiply( m2, m0, m1 ); + Matrix m2(false); + Matrix::Multiply(m2, m0, m1); DALI_TEST_EQUALS(m2, Matrix::IDENTITY, 0.001f, TEST_LOCATION); } END_TEST; } - -// Invert transform works -int UtcDaliMatrixInvertTransform02(void) +int UtcDaliMatrixInvertTransformN(void) { - std::string exceptionString( "EqualsZero( mMatrix[3] ) && EqualsZero( mMatrix[7] ) && EqualsZero( mMatrix[11] ) && Equals( mMatrix[15], 1.0f" ); + std::string exceptionString("EqualsZero(mMatrix[3]) && EqualsZero(mMatrix[7]) && EqualsZero(mMatrix[11]) && Equals(mMatrix[15], 1.0f"); try { - float els[] = { 0.0f, 1.0f, 2.0f, 3.0f, - 4.0f, 5.0f, 6.0f, 7.0f, - 8.0f, 9.0f, 10.0f, 11.0f, - 12.0f, 13.0f, 14.0f, 15.0f }; + float els[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f}; Matrix m(els); Matrix it; m.InvertTransform(it); tet_result(TET_FAIL); } - catch (Dali::DaliException& e) + catch(Dali::DaliException& e) { - tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str()); - DALI_TEST_ASSERT( e, exceptionString, TEST_LOCATION ); + DALI_TEST_PRINT_ASSERT(e); + DALI_TEST_ASSERT(e, exceptionString, TEST_LOCATION); } try { - float els[] = { 0.0f, 1.0f, 2.0f, 3.0f, - 4.0f, 5.0f, 6.0f, 7.0f, - 8.0f, 9.0f, 10.0f, 11.0f, - 12.0f, 13.0f, 14.0f, 15.0f }; + float els[] = {0.0f, 1.0f, 2.0f, 0.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f}; Matrix m(els); Matrix it; m.InvertTransform(it); tet_result(TET_FAIL); } - catch (Dali::DaliException& e) + catch(Dali::DaliException& e) { - tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str()); - DALI_TEST_ASSERT( e, exceptionString, TEST_LOCATION ); + DALI_TEST_PRINT_ASSERT(e); + DALI_TEST_ASSERT(e, exceptionString, TEST_LOCATION); } try { - float els[] = { 0.0f, 1.0f, 2.0f, 3.0f, - 4.0f, 5.0f, 6.0f, 7.0f, - 8.0f, 9.0f, 10.0f, 11.0f, - 12.0f, 13.0f, 14.0f, 15.0f }; + float els[] = {0.0f, 1.0f, 2.0f, 0.0f, 4.0f, 5.0f, 6.0f, 0.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f}; Matrix m(els); Matrix it; m.InvertTransform(it); tet_result(TET_FAIL); } - catch (Dali::DaliException& e) + catch(Dali::DaliException& e) { - tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str()); - DALI_TEST_ASSERT( e, exceptionString, TEST_LOCATION ); + DALI_TEST_PRINT_ASSERT(e); + DALI_TEST_ASSERT(e, exceptionString, TEST_LOCATION); } try { - float els[] = { 0.0f, 1.0f, 2.0f, 3.0f, - 4.0f, 5.0f, 6.0f, 7.0f, - 8.0f, 9.0f, 10.0f, 11.0f, - 12.0f, 13.0f, 14.0f, 15.0f }; + float els[] = {0.0f, 1.0f, 2.0f, 0.0f, 4.0f, 5.0f, 6.0f, 0.0f, 8.0f, 9.0f, 10.0f, 0.0f, 12.0f, 13.0f, 14.0f, 15.0f}; Matrix m(els); Matrix it; m.InvertTransform(it); tet_result(TET_FAIL); } - catch (Dali::DaliException& e) + catch(Dali::DaliException& e) { - tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str()); - DALI_TEST_ASSERT( e, exceptionString, TEST_LOCATION ); + DALI_TEST_PRINT_ASSERT(e); + DALI_TEST_ASSERT(e, exceptionString, TEST_LOCATION); } END_TEST; } - -// GetXAxis -int UtcDaliMatrixGetXAxis(void) +int UtcDaliMatrixInvert01P(void) { - float els[] = { 0.0f, 1.0f, 2.0f, 3.0f, - 4.0f, 5.0f, 6.0f, 7.0f, - 8.0f, 9.0f, 10.0f, 11.0f, - 12.0f, 13.0f, 14.0f, 15.0f }; - Matrix m(els); + // We're going to invert a whole load of different matrices to make sure we don't + // fail on particular orientations. + for(int i = 0; i < 1000; ++i) + { + float f = i; + Vector3 axis(cosf(f * 0.001f), cosf(f * 0.02f), cosf(f * 0.03f)); + axis.Normalize(); + Vector3 center(f, cosf(f) * 100.0f, cosf(f * 0.5f) * 50.0f); - DALI_TEST_CHECK(m.GetXAxis() == Vector3(0.0f, 1.0f, 2.0f)); - END_TEST; -} + Matrix m0; + m0.SetIdentity(); + m0.SetTransformComponents(Vector3::ONE, Quaternion(Radian(1.0f), axis), center); -// GetYAxis -int UtcDaliMatrixGetYAxis(void) -{ - float els[] = { 0.0f, 1.0f, 2.0f, 3.0f, - 4.0f, 5.0f, 6.0f, 7.0f, - 8.0f, 9.0f, 10.0f, 11.0f, - 12.0f, 13.0f, 14.0f, 15.0f }; - Matrix m(els); + Matrix m1(m0); + m1.Invert(); + + Matrix m2(false); + Matrix::Multiply(m2, m0, m1); + + DALI_TEST_EQUALS(m2, Matrix::IDENTITY, 0.001f, TEST_LOCATION); + + m1.Invert(); // doube invert - should be back to m0 - DALI_TEST_CHECK(m.GetYAxis() == Vector3(4.0f, 5.0f, 6.0f)); + DALI_TEST_EQUALS(m0, m1, 0.001f, TEST_LOCATION); + } END_TEST; } -// GetZAxis -int UtcDaliMatrixGetZAxis(void) +int UtcDaliMatrixInvert02P(void) { - float els[] = { 0.0f, 1.0f, 2.0f, 3.0f, - 4.0f, 5.0f, 6.0f, 7.0f, - 8.0f, 9.0f, 10.0f, 11.0f, - 12.0f, 13.0f, 14.0f, 15.0f }; - Matrix m(els); - - DALI_TEST_CHECK(m.GetZAxis() == Vector3(8.0f, 9.0f, 10.0f)); + Matrix m1 = Matrix::IDENTITY; + m1.SetXAxis(Vector3(0.0f, 0.0f, 0.0f)); + DALI_TEST_EQUALS(m1.Invert(), false, TEST_LOCATION); END_TEST; } -// GetTranslation -int UtcDaliMatrixGetTranslation(void) +int UtcDaliMatrixTransposeP(void) { - float els[] = { 0.0f, 1.0f, 2.0f, 3.0f, - 4.0f, 5.0f, 6.0f, 7.0f, - 8.0f, 9.0f, 10.0f, 11.0f, - 12.0f, 13.0f, 14.0f, 15.0f }; - Matrix m(els); + float floats[] = + {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f}; - DALI_TEST_EQUALS(m.GetTranslation(), Vector4(12.0f, 13.0f, 14.0f, 15.0f), TEST_LOCATION); + Matrix m(floats); + m.Transpose(); + + bool success = true; + + for(int x = 0; x < 4; ++x) + { + for(int y = 0; y < 4; ++y) + { + success &= (m.AsFloat()[x + y * 4] == floats[x * 4 + y]); + } + } + + DALI_TEST_CHECK(success); END_TEST; } -// GetTranslation -int UtcDaliMatrixGetTranslation3(void) +int UtcDaliMatrixGetXAxisP(void) { - float els[] = { 0.0f, 1.0f, 2.0f, 3.0f, - 4.0f, 5.0f, 6.0f, 7.0f, - 8.0f, 9.0f, 10.0f, 11.0f, - 12.0f, 13.0f, 14.0f, 15.0f }; + float els[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f}; Matrix m(els); - DALI_TEST_EQUALS(m.GetTranslation3(), Vector3(12.0f, 13.0f, 14.0f), TEST_LOCATION); + DALI_TEST_CHECK(m.GetXAxis() == Vector3(0.0f, 1.0f, 2.0f)); END_TEST; } -// SetIdentity -int UtcDaliMatrixSetIdentity(void) +int UtcDaliMatrixGetYAxisP(void) { - float els[] = { 0.0f, 1.0f, 2.0f, 3.0f, - 4.0f, 5.0f, 6.0f, 7.0f, - 8.0f, 9.0f, 10.0f, 11.0f, - 12.0f, 13.0f, 14.0f, 15.0f }; + float els[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f}; Matrix m(els); - m.SetIdentity(); - DALI_TEST_EQUALS(m, Matrix::IDENTITY, 0.001f, TEST_LOCATION); + DALI_TEST_CHECK(m.GetYAxis() == Vector3(4.0f, 5.0f, 6.0f)); END_TEST; } - -int UtcDaliMatrixSetIdentityAndScale(void) +int UtcDaliMatrixGetZAxisP(void) { - float els[] = { 0.0f, 1.0f, 2.0f, 3.0f, - 4.0f, 5.0f, 6.0f, 7.0f, - 8.0f, 9.0f, 10.0f, 11.0f, - 12.0f, 13.0f, 14.0f, 15.0f }; + float els[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f}; Matrix m(els); - m.SetIdentityAndScale(Vector3(4.0f, 4.0f, 4.0f)); - - float els2[] = { 4.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 4.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 4.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f }; - Matrix r(els2); - DALI_TEST_EQUALS(m, r, 0.001f, TEST_LOCATION); + DALI_TEST_CHECK(m.GetZAxis() == Vector3(8.0f, 9.0f, 10.0f)); END_TEST; } - -// SetXAxis -int UtcDaliMatrixSetXAxis(void) +int UtcDaliMatrixSetXAxisP(void) { - Matrix m; + Matrix m; Vector3 v(2.0f, 3.0f, 4.0f); m.SetXAxis(v); @@ -394,10 +367,9 @@ int UtcDaliMatrixSetXAxis(void) END_TEST; } -// SetYAxis -int UtcDaliMatrixSetYAxis(void) +int UtcDaliMatrixSetYAxisP(void) { - Matrix m; + Matrix m; Vector3 v(2.0f, 3.0f, 4.0f); m.SetYAxis(v); @@ -405,10 +377,9 @@ int UtcDaliMatrixSetYAxis(void) END_TEST; } -// SetZAxis -int UtcDaliMatrixSetZAxis(void) +int UtcDaliMatrixSetZAxisP(void) { - Matrix m; + Matrix m; Vector3 v(2.0f, 3.0f, 4.0f); m.SetZAxis(v); @@ -416,10 +387,27 @@ int UtcDaliMatrixSetZAxis(void) END_TEST; } -// SetTranslation -int UtcDaliMatrixSetTranslation(void) +int UtcDaliMatrixGetTranslationP(void) { - Matrix m; + float els[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f}; + Matrix m(els); + + DALI_TEST_EQUALS(m.GetTranslation(), Vector4(12.0f, 13.0f, 14.0f, 15.0f), TEST_LOCATION); + END_TEST; +} + +int UtcDaliMatrixGetTranslation3P(void) +{ + float els[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f}; + Matrix m(els); + + DALI_TEST_EQUALS(m.GetTranslation3(), Vector3(12.0f, 13.0f, 14.0f), TEST_LOCATION); + END_TEST; +} + +int UtcDaliMatrixSetTranslationP(void) +{ + Matrix m; Vector4 v(2.0f, 3.0f, 4.0f, 5.0f); m.SetTranslation(v); @@ -427,10 +415,9 @@ int UtcDaliMatrixSetTranslation(void) END_TEST; } -// SetTranslation -int UtcDaliMatrixSetTranslation3(void) +int UtcDaliMatrixSetTranslation3P(void) { - Matrix m; + Matrix m; Vector3 v(2.0f, 3.0f, 4.0f); m.SetTranslation(v); @@ -438,76 +425,116 @@ int UtcDaliMatrixSetTranslation3(void) END_TEST; } - - -// Transpose -int UtcDaliMatrixTranspose(void) +int UtcDaliMatrixOrthoNormalize0P(void) { - float floats[] = - { 0.0f, 1.0f, 2.0f, 3.0f, - 4.0f, 5.0f, 6.0f, 7.0f, - 8.0f, 9.0f, 10.0f, 11.0f, - 12.0f, 13.0f, 14.0f, 15.0f - }; + // OrthoNormalise fixes floating point errors from matrix rotations + Matrix m; + m.SetIdentity(); - Matrix m(floats); - m.Transpose(); + for(int i = 0; i < 1000; ++i) + { + float f = i; + Vector3 axis(cosf(f * 0.001f), cosf(f * 0.02f), cosf(f * 0.03f)); + axis.Normalize(); + + m.SetTransformComponents(Vector3::ONE, Quaternion(Radian(1.0f), axis), Vector3::ZERO); + m.OrthoNormalize(); + } bool success = true; + success &= fabsf(m.GetXAxis().Dot(m.GetYAxis())) < 0.001f; + success &= fabsf(m.GetYAxis().Dot(m.GetXAxis())) < 0.001f; + success &= fabsf(m.GetZAxis().Dot(m.GetYAxis())) < 0.001f; - for (int x=0;x<4;++x) - { - for (int y=0;y<4;++y) - { - success &= (m.AsFloat()[x+y*4] == floats[x*4+y]); - } - } + success &= fabsf(m.GetXAxis().Length() - 1.0f) < 0.001f; + success &= fabsf(m.GetYAxis().Length() - 1.0f) < 0.001f; + success &= fabsf(m.GetZAxis().Length() - 1.0f) < 0.001f; DALI_TEST_CHECK(success); END_TEST; } -int UtcDaliMatrixOStreamOperator(void) +int UtcDaliMatrixOrthoNormalize1P(void) { - std::ostringstream oss; + // OrthoNormalize is not flipping the axes and is maintaining the translation + for(int i = 0; i < 1000; ++i) + { + float f = i; + Vector3 axis(cosf(f * 0.001f), cosf(f * 0.02f), cosf(f * 0.03f)); + axis.Normalize(); + Vector3 center(10.0f, 15.0f, 5.0f); - Matrix matrix; - matrix.SetIdentity(); + Matrix m0; + m0.SetIdentity(); + m0.SetTransformComponents(Vector3::ONE, Quaternion(Radian(1.0f), axis), center); - oss << matrix; + Matrix m1(m0); + m1.OrthoNormalize(); + + DALI_TEST_EQUALS(m0.GetXAxis(), m1.GetXAxis(), 0.001f, TEST_LOCATION); + DALI_TEST_EQUALS(m0.GetYAxis(), m1.GetYAxis(), 0.001f, TEST_LOCATION); + DALI_TEST_EQUALS(m0.GetZAxis(), m1.GetZAxis(), 0.001f, TEST_LOCATION); + DALI_TEST_EQUALS(m0.GetTranslation(), m1.GetTranslation(), 0.001f, TEST_LOCATION); + } + END_TEST; +} + +int UtcDaliMatrixConstAsFloatP(void) +{ + 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}; + const Matrix m(r); - std::string expectedOutput = "[ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ]"; + const float* els = m.AsFloat(); + const float* init = r; + bool initialised = true; + for(size_t idx = 0; idx < 16; ++idx, ++els, ++init) + { + if(*els != *init) + initialised = false; + } + DALI_TEST_EQUALS(initialised, true, TEST_LOCATION); - DALI_TEST_EQUALS( oss.str(), expectedOutput, TEST_LOCATION); END_TEST; } -int UtcDaliMatrixMultiply(void) +int UtcDaliMatrixAsFloatP(void) +{ + 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}; + Matrix m(r); + + float* els = m.AsFloat(); + float* init = r; + bool initialised = true; + for(size_t idx = 0; idx < 16; ++idx, ++els, ++init) + { + if(*els != *init) + initialised = false; + } + DALI_TEST_EQUALS(initialised, true, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliMatrixMultiplyP(void) { Matrix m1 = Matrix::IDENTITY; - float els[] = { 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.707f, 0.707f, 0.0f, - 0.0f, -0.707f, 0.707f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f }; + float els[] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.707f, 0.707f, 0.0f, 0.0f, -0.707f, 0.707f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; Matrix result(els); Quaternion q(Radian(Degree(45.0f)), Vector3::XAXIS); - Matrix m2(false); + Matrix m2(false); Matrix::Multiply(m2, m1, q); DALI_TEST_EQUALS(m2, result, 0.01f, TEST_LOCATION); END_TEST; } -int UtcDaliMatrixOperatorMultiply01(void) +int UtcDaliMatrixOperatorMultiply01P(void) { Vector4 v1(2.0f, 5.0f, 4.0f, 0.0f); - float els[] = {2.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 3.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 4.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f }; + float els[] = {2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; Matrix m1(els); Vector4 v2 = m1 * v1; @@ -516,18 +543,18 @@ int UtcDaliMatrixOperatorMultiply01(void) END_TEST; } -int UtcDaliMatrixOperatorMultiply02(void) +int UtcDaliMatrixOperatorMultiply02P(void) { TestApplication application; - Vector3 position ( 30.f, 40.f, 50.f); + Vector3 position(30.f, 40.f, 50.f); Matrix m1(false); m1.SetIdentity(); m1.SetTranslation(-position); Vector4 positionV4(position); - positionV4.w=1.0f; + positionV4.w = 1.0f; Vector4 output = m1 * positionV4; output.w = 0.0f; @@ -535,31 +562,27 @@ int UtcDaliMatrixOperatorMultiply02(void) END_TEST; } -int UtcDaliMatrixOperatorEquals(void) +int UtcDaliMatrixOperatorEqualsP(void) { Matrix m1 = Matrix::IDENTITY; - 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}; + 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}; Matrix r2(els); DALI_TEST_EQUALS(m1 == r2, true, TEST_LOCATION); - float *f = m1.AsFloat(); - for(size_t i=0; i<16; i++) + float* f = m1.AsFloat(); + for(size_t i = 0; i < 16; i++) { - f[15-i] = 1.2f; + f[15 - i] = 1.2f; DALI_TEST_EQUALS(m1 == r2, false, TEST_LOCATION); } END_TEST; } - -int UtcDaliMatrixOperatorNotEquals(void) +int UtcDaliMatrixOperatorNotEqualsP(void) { - Matrix m1 = Matrix::IDENTITY; - float els[] = {2.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 3.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 4.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f }; + Matrix m1 = Matrix::IDENTITY; + float els[] = {2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; Matrix r1(els); DALI_TEST_CHECK(m1 != r1); @@ -567,76 +590,26 @@ int UtcDaliMatrixOperatorNotEquals(void) END_TEST; } -int UtcDaliMatrixGetTransformComponents01(void) -{ - Matrix m2(Matrix::IDENTITY.AsFloat()); - Vector3 pos2; - Vector3 scale2; - Quaternion q2; - m2.GetTransformComponents(pos2, q2, scale2); - DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), pos2, 0.001, TEST_LOCATION); - DALI_TEST_EQUALS(Vector3(1.0f, 1.0f, 1.0f), scale2, 0.001, TEST_LOCATION); - DALI_TEST_EQUALS(Quaternion(), q2, 0.001, TEST_LOCATION); - END_TEST; -} - - -int UtcDaliMatrixGetTransformComponents02(void) -{ - // Create an arbitrary vector - for( float x=-1.0f; x<=1.0f; x+=0.1f ) - { - for( float y=-1.0f; y<1.0f; y+=0.1f ) - { - for( float z=-1.0f; z<1.0f; z+=0.1f ) - { - Vector3 vForward(x, y, z); - vForward.Normalize(); - - for( float angle = 5.0f; angle <= 360.0f; angle += 15.0f) - { - Quaternion rotation1(Radian(Degree(angle)), vForward); - Vector3 scale1(2.0f, 3.0f, 4.0f); - Vector3 position1(1.0f, 2.0f, 3.0f); - - Matrix m1(false); - m1.SetTransformComponents(scale1, rotation1, position1); - - Vector3 position2; - Quaternion rotation2; - Vector3 scale2; - m1.GetTransformComponents(position2, rotation2, scale2); - - DALI_TEST_EQUALS(position1, position2, 0.001, TEST_LOCATION); - DALI_TEST_EQUALS(scale1, scale2, 0.001, TEST_LOCATION); - DALI_TEST_EQUALS(rotation1, rotation2, 0.001, TEST_LOCATION); - } - } - } - } - END_TEST; -} - -int UtcDaliMatrixSetTransformComponents01(void) +int UtcDaliMatrixSetTransformComponents01P(void) { // Create an arbitrary vector - for( float x=-1.0f; x<=1.0f; x+=0.1f ) + for(float x = -1.0f; x <= 1.0f; x += 0.1f) { - for( float y=-1.0f; y<1.0f; y+=0.1f ) + for(float y = -1.0f; y < 1.0f; y += 0.1f) { - for( float z=-1.0f; z<1.0f; z+=0.1f ) + for(float z = -1.0f; z < 1.0f; z += 0.1f) { Vector3 vForward(x, y, z); vForward.Normalize(); - for( float angle = 5.0f; angle <= 360.0f; angle += 15.0f) + for(float angle = 5.0f; angle <= 360.0f; angle += 15.0f) { Quaternion rotation1(Radian(Degree(angle)), vForward); - Matrix m1(rotation1); - Matrix result1(false); - Vector4 vForward4(vForward.x, vForward.y, vForward.z, 0.0f); - result1.SetTransformComponents( Vector3::ONE, Quaternion(Radian(Degree(angle)), vForward4), Vector3::ZERO ); + Matrix m1(rotation1); + Matrix result1(false); + Vector3 vForward3(vForward.x, vForward.y, vForward.z); + result1.SetTransformComponents(Vector3::ONE, Quaternion(Radian(Degree(angle)), vForward3), Vector3::ZERO); DALI_TEST_EQUALS(m1, result1, 0.001, TEST_LOCATION); @@ -667,24 +640,22 @@ int UtcDaliMatrixSetTransformComponents01(void) END_TEST; } - -int UtcDaliMatrixSetInverseTransformComponent01(void) +int UtcDaliMatrixSetInverseTransformComponent01P(void) { // Create an arbitrary vector - for( float x=-1.0f; x<=1.0f; x+=0.1f ) + for(float x = -1.0f; x <= 1.0f; x += 0.1f) { - for( float y=-1.0f; y<1.0f; y+=0.1f ) + for(float y = -1.0f; y < 1.0f; y += 0.1f) { - for( float z=-1.0f; z<1.0f; z+=0.1f ) + for(float z = -1.0f; z < 1.0f; z += 0.1f) { Vector3 vForward(x, y, z); vForward.Normalize(); - for( float angle = 5.0f; angle <= 360.0f; angle += 15.0f) { - Quaternion rotation1(Radian(Degree(angle)), vForward); - Vector3 scale1(2.0f, 3.0f, 4.0f); - Vector3 position1(1.0f, 2.0f, 3.0f); + Quaternion rotation1(Quaternion::IDENTITY); // test no rotation branch + Vector3 scale1(2.0f, 3.0f, 4.0f); + Vector3 position1(1.0f, 2.0f, 3.0f); Matrix m1(false); m1.SetTransformComponents(scale1, rotation1, position1); @@ -703,33 +674,33 @@ int UtcDaliMatrixSetInverseTransformComponent01(void) END_TEST; } -int UtcDaliMatrixSetInverseTransformComponent02(void) +int UtcDaliMatrixSetInverseTransformComponent02P(void) { // Create an arbitrary vector - for( float x=-1.0f; x<=1.0f; x+=0.1f ) + for(float x = -1.0f; x <= 1.0f; x += 0.1f) { - for( float y=-1.0f; y<1.0f; y+=0.1f ) + for(float y = -1.0f; y < 1.0f; y += 0.1f) { - for( float z=-1.0f; z<1.0f; z+=0.1f ) + for(float z = -1.0f; z < 1.0f; z += 0.1f) { Vector3 vForward(x, y, z); vForward.Normalize(); - for( float angle = 5.0f; angle <= 360.0f; angle += 15.0f) + for(float angle = 5.0f; angle <= 360.0f; angle += 15.0f) { Quaternion rotation1(Radian(Degree(angle)), vForward); - Matrix rotationMatrix(rotation1); // TEST RELIES ON THIS METHOD WORKING!!! + Matrix rotationMatrix(rotation1); // TEST RELIES ON THIS METHOD WORKING!!! Vector3 position1(5.0f, -6.0f, 7.0f); Matrix m1(false); - m1.SetTransformComponents( Vector3::ONE, rotation1, position1 ); + m1.SetTransformComponents(Vector3::ONE, rotation1, position1); Matrix m2(false); - m2.SetInverseTransformComponents( rotationMatrix.GetXAxis(), - rotationMatrix.GetYAxis(), - rotationMatrix.GetZAxis(), - position1 ); + m2.SetInverseTransformComponents(rotationMatrix.GetXAxis(), + rotationMatrix.GetYAxis(), + rotationMatrix.GetZAxis(), + position1); Matrix result; Matrix::Multiply(result, m1, m2); @@ -741,3 +712,80 @@ int UtcDaliMatrixSetInverseTransformComponent02(void) } END_TEST; } + +int UtcDaliMatrixGetTransformComponents01P(void) +{ + Matrix m2(Matrix::IDENTITY.AsFloat()); + Vector3 pos2; + Vector3 scale2; + Quaternion q2; + m2.GetTransformComponents(pos2, q2, scale2); + DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), pos2, 0.001, TEST_LOCATION); + DALI_TEST_EQUALS(Vector3(1.0f, 1.0f, 1.0f), scale2, 0.001, TEST_LOCATION); + DALI_TEST_EQUALS(Quaternion(), q2, 0.001, TEST_LOCATION); + END_TEST; +} + +int UtcDaliMatrixGetTransformComponents02P(void) +{ + // Create an arbitrary vector + for(float x = -1.0f; x <= 1.0f; x += 0.1f) + { + for(float y = -1.0f; y < 1.0f; y += 0.1f) + { + for(float z = -1.0f; z < 1.0f; z += 0.1f) + { + Vector3 vForward(x, y, z); + vForward.Normalize(); + + for(float angle = 5.0f; angle <= 360.0f; angle += 15.0f) + { + Quaternion rotation1(Radian(Degree(angle)), vForward); + Vector3 scale1(2.0f, 3.0f, 4.0f); + Vector3 position1(1.0f, 2.0f, 3.0f); + + Matrix m1(false); + m1.SetTransformComponents(scale1, rotation1, position1); + + Vector3 position2; + Quaternion rotation2; + Vector3 scale2; + m1.GetTransformComponents(position2, rotation2, scale2); + + DALI_TEST_EQUALS(position1, position2, 0.001, TEST_LOCATION); + DALI_TEST_EQUALS(scale1, scale2, 0.001, TEST_LOCATION); + DALI_TEST_EQUALS(rotation1, rotation2, 0.001, TEST_LOCATION); + } + } + } + } + END_TEST; +} + +int UtcDaliMatrixGetTransformComponents03P(void) +{ + Matrix m2; // zero branch + Vector3 pos2; + Vector3 scale2; + Quaternion q2; + m2.GetTransformComponents(pos2, q2, scale2); + DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), pos2, 0.001, TEST_LOCATION); + DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), scale2, 0.001, TEST_LOCATION); + // DALI_TEST_EQUALS(Quaternion(), q2, 0.001, TEST_LOCATION); + END_TEST; +} + +int UtcDaliMatrixOStreamOperator(void) +{ + std::ostringstream oss; + + Matrix matrix; + matrix.SetIdentity(); + + oss << matrix; + + std::string expectedOutput = "[ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]"; + + DALI_TEST_EQUALS(oss.str(), expectedOutput, TEST_LOCATION); + END_TEST; +}