From af2a0cc5fb9d07dd8ddcb9b20e10facd05cd0206 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Fri, 7 Oct 2022 16:31:09 +0900 Subject: [PATCH] Matrix operator* Matrix::Multiply(result, lhs, rhs) do as result = rhs * lhs; It might makes some strange scense to future of Dali developer. Let we make operator* so nobody feel confuse about the order of multiply operation Change-Id: I5adf0c8a8f29fa1c0774aa1e23ff0c3050e66af4 Signed-off-by: Eunki, Hong --- automated-tests/src/dali/utc-Dali-Matrix.cpp | 23 ++++++++++++++++++++++- automated-tests/src/dali/utc-Dali-Matrix3.cpp | 21 +++++++++++++++++++++ dali/public-api/math/matrix.h | 19 +++++++++++++++++++ dali/public-api/math/matrix3.h | 19 +++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) diff --git a/automated-tests/src/dali/utc-Dali-Matrix.cpp b/automated-tests/src/dali/utc-Dali-Matrix.cpp index d40d9b3..d689185 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) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -562,6 +562,27 @@ int UtcDaliMatrixOperatorMultiply02P(void) END_TEST; } +int UtcDaliMatrixOperatorMultiply03P(void) +{ + const float ll[16] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; + const float rr[16] = {1.0f, 5.0f, 0.0f, 0.0f, 2.0f, 6.0f, 0.0f, 0.0f, 3.0f, 7.0f, 0.0f, 0.0f, 4.0f, 8.0f, 0.0f, 0.0f}; + Matrix left(ll); + Matrix right(rr); + + const float els[16] = {26.0f, 32.0f, 38.0f, 44.0f, 32.0f, 40.0f, 48.0f, 56.0f, 38.0f, 48.0f, 58.0f, 68.0f, 44.0f, 56.0f, 68.0f, 80.0f}; + Matrix result(els); + + // Get result by operator* + Matrix multResult = left * right; + DALI_TEST_EQUALS(multResult, result, 0.01f, TEST_LOCATION); + + // Get result by Multiply API + Matrix::Multiply(multResult, right, left); + DALI_TEST_EQUALS(multResult, result, 0.01f, TEST_LOCATION); + + END_TEST; +} + int UtcDaliMatrixOperatorEqualsP(void) { Matrix m1 = Matrix::IDENTITY; diff --git a/automated-tests/src/dali/utc-Dali-Matrix3.cpp b/automated-tests/src/dali/utc-Dali-Matrix3.cpp index 1f84030..9e59a29 100644 --- a/automated-tests/src/dali/utc-Dali-Matrix3.cpp +++ b/automated-tests/src/dali/utc-Dali-Matrix3.cpp @@ -333,6 +333,27 @@ int UtcDaliMatrix3OperatorMultiply02P(void) END_TEST; } +int UtcDaliMatrix3OperatorMultiply03P(void) +{ + Matrix3 left( + 1.0f, 2.0f, 3.0f, 5.0f, 6.0f, 7.0f, 0.0f, 0.0f, 0.0f); + Matrix3 right( + 1.0f, 5.0f, 0.0f, 2.0f, 6.0f, 0.0f, 3.0f, 7.0f, 0.0f); + + Matrix3 result( + 26.0f, 32.0f, 38.0f, 32.0f, 40.0f, 48.0f, 38.0f, 48.0f, 58.0f); + + // Get result by operator* + Matrix3 multResult = left * right; + DALI_TEST_EQUALS(multResult, result, 0.01f, TEST_LOCATION); + + // Get result by Multiply API + Matrix3::Multiply(multResult, right, left); + DALI_TEST_EQUALS(multResult, result, 0.01f, TEST_LOCATION); + + END_TEST; +} + int UtcDaliMatrix3EqualityOperator(void) { Matrix3 m1(0.0f, 3.0f, 6.0f, 12.0f, 15.0f, 18.0f, 24.0f, 27.0f, 30.0f); diff --git a/dali/public-api/math/matrix.h b/dali/public-api/math/matrix.h index 15b3181..6f19787 100644 --- a/dali/public-api/math/matrix.h +++ b/dali/public-api/math/matrix.h @@ -346,6 +346,25 @@ public: static void Multiply(Matrix& result, const Matrix& lhs, const Quaternion& rhs); /** + * @brief Multiplication operator. + * + * Returned Matrix = This Matrix * rhs + * + * @note It makes some memory allocate & copy internally. + * Use Matrix::Multiply API for time critical path. + * + * @SINCE_2_1.44 + * @param[in] rhs The Matrix to multiply this by + * @return A Matrix containing the result + */ + Matrix operator*(const Matrix& rhs) const + { + Matrix result(false); + Multiply(result, rhs, *this); + return result; + } + + /** * @brief The multiplication operator. * * Returned Vector = This Matrix * rhs diff --git a/dali/public-api/math/matrix3.h b/dali/public-api/math/matrix3.h index 47d51fb..4627536 100644 --- a/dali/public-api/math/matrix3.h +++ b/dali/public-api/math/matrix3.h @@ -261,6 +261,25 @@ public: static void Multiply(Matrix3& result, const Matrix3& lhs, const Matrix3& rhs); /** + * @brief Multiplication operator. + * + * Returned Matrix = This Matrix * rhs + * + * @note It makes some memory allocate & copy internally. + * Use Matrix3::Multiply API for time critical path. + * + * @SINCE_2_1.44 + * @param[in] rhs The Matrix to multiply this by + * @return A Matrix containing the result + */ + Matrix3 operator*(const Matrix3& rhs) const + { + Matrix3 result; + Multiply(result, rhs, *this); + return result; + } + + /** * @brief The multiplication operator. * * Returned Vector = This Matrix * rhs -- 2.7.4