Add assignment operator for Rect to take Vector4 81/234781/3
authorRichard Huang <r.huang@samsung.com>
Thu, 28 May 2020 12:55:50 +0000 (13:55 +0100)
committerRichard Huang <r.huang@samsung.com>
Thu, 28 May 2020 15:38:47 +0000 (16:38 +0100)
Change-Id: I4a91f7fbbfc4b12c9cc10c42ce00b70ce85ccca0

automated-tests/src/dali/utc-Dali-Rect.cpp
dali/public-api/math/rect.h

index 24ce9d8..b5f50a6 100644 (file)
@@ -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.
@@ -65,7 +65,7 @@ int UtcDaliRectCons03(void)
 
   Rect<float> rect(10.0f, 20.0f, 400.0f, 200.0f);
 
-  Rect<float> r2 = rect;
+  Rect<float> r2(rect);
 
   DALI_TEST_EQUALS(r2.x, 10.0f, 0.001, TEST_LOCATION);
   DALI_TEST_EQUALS(r2.y, 20.0f, 0.001, TEST_LOCATION);
@@ -78,9 +78,25 @@ int UtcDaliRectCons04(void)
 {
   TestApplication application;
 
+  Vector4 vec4(10.0f, 20.0f, 400.0f, 200.0f);
+
+  Rect<float> rect(vec4);
+
+  DALI_TEST_EQUALS(rect.x, 10.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(rect.y, 20.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(rect.width, 400.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(rect.height, 200.0f, 0.001, TEST_LOCATION);
+  END_TEST;
+}
+
+int UtcDaliRectAssignmentOperatorRect(void)
+{
+  TestApplication application;
+
   Rect<float> rect(10.0f, 20.0f, 400.0f, 200.0f);
 
-  Rect<float> r2(rect);
+  Rect<float> r2;
+  r2 = rect;
 
   DALI_TEST_EQUALS(r2.x, 10.0f, 0.001, TEST_LOCATION);
   DALI_TEST_EQUALS(r2.y, 20.0f, 0.001, TEST_LOCATION);
@@ -89,6 +105,22 @@ int UtcDaliRectCons04(void)
   END_TEST;
 }
 
+int UtcDaliRectAssignmentOperatorVector4(void)
+{
+  TestApplication application;
+
+  Vector4 vec4(10.0f, 20.0f, 400.0f, 200.0f);
+
+  Rect<float> rect;
+  rect = vec4;
+
+  DALI_TEST_EQUALS(rect.x, 10.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(rect.y, 20.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(rect.width, 400.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(rect.height, 200.0f, 0.001, TEST_LOCATION);
+  END_TEST;
+}
+
 int UtcDaliRectSet(void)
 {
   TestApplication application;
index 649949e..b8b64cf 100644 (file)
@@ -78,11 +78,11 @@ struct Rect
    * @param[in] vec4 Vector4 to convert from
    */
   Rect( const Vector4& vec4 )
+  : x(vec4.x),
+    y(vec4.y),
+    width(vec4.z),
+    height(vec4.w)
   {
-    x = vec4.x;
-    y = vec4.y;
-    width = vec4.z;
-    height = vec4.w;
   }
 
   /**
@@ -120,6 +120,23 @@ struct Rect
   }
 
   /**
+   * @brief Assignment operator.
+   *
+   * @SINCE_1_9.14
+   * @param[in] vec4 The Vector4 to assign
+   * @return Reference to this
+   */
+  Rect<T>& operator= (const Vector4& vec4)
+  {
+    x = vec4.x;
+    y = vec4.y;
+    width = vec4.z;
+    height = vec4.w;
+
+    return *this;
+  }
+
+  /**
    * @brief Assignment from individual values.
    *
    * @SINCE_1_0.0