Add operator for Matirx3 * Vector3 19/278819/5
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 26 Jul 2022 10:21:40 +0000 (19:21 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Mon, 1 Aug 2022 03:01:34 +0000 (12:01 +0900)
We might need to multiply for some non-transition matrix.

Change-Id: I5a8aa02ce8c1e68b623aea07d9e7540f7074368f
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali/utc-Dali-Matrix3.cpp
dali/public-api/math/matrix3.cpp
dali/public-api/math/matrix3.h

index fe2ee41..1f84030 100644 (file)
@@ -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.
@@ -313,6 +313,26 @@ int UtcDaliMatrix3Multiply(void)
   END_TEST;
 }
 
+int UtcDaliMatrix3OperatorMultiply01P(void)
+{
+  Vector3 v1(2.0f, 5.0f, 4.0f);
+
+  Vector3 v2 = m1 * v1;
+  Vector3 r1(-37.2f, 118.8f, 13.2f);
+  DALI_TEST_EQUALS(v2, r1, 0.01f, TEST_LOCATION);
+  END_TEST;
+}
+
+int UtcDaliMatrix3OperatorMultiply02P(void)
+{
+  Vector3 v1(2.0f, 5.0f, 4.0f);
+
+  Vector3 v2 = m6 * v1;
+  Vector3 r1(88.668f, 35.2f, -340.65f);
+  DALI_TEST_EQUALS(v2, r1, 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);
index 5fc44e7..118cc90 100644 (file)
@@ -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.
@@ -276,6 +276,13 @@ void Matrix3::Multiply(Matrix3& result, const Matrix3& lhs, const Matrix3& rhs)
   }
 }
 
+Vector3 Matrix3::operator*(const Vector3& rhs) const
+{
+  return Vector3(rhs.x * mElements[S00] + rhs.y * mElements[S10] + rhs.z * mElements[S20],
+                 rhs.x * mElements[S01] + rhs.y * mElements[S11] + rhs.z * mElements[S21],
+                 rhs.x * mElements[S02] + rhs.y * mElements[S12] + rhs.z * mElements[S22]);
+}
+
 bool Matrix3::operator==(const Matrix3& rhs) const
 {
   return (
index 8876bc1..47d51fb 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_MATRIX3_H
 
 /*
- * 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.
@@ -260,6 +260,17 @@ public:
    */
   static void Multiply(Matrix3& result, const Matrix3& lhs, const Matrix3& rhs);
 
+  /**
+   * @brief The multiplication operator.
+   *
+   * Returned Vector = This Matrix * rhs
+   *
+   * @SINCE_2_1.34
+   * @param[in] rhs The Vector3 to multiply this by
+   * @return A Vector3 containing the result
+   */
+  Vector3 operator*(const Vector3& rhs) const;
+
 private:
   float mElements[9]; ///< The elements of the matrix
 };