From: Richard Huang Date: Thu, 28 May 2020 12:55:50 +0000 (+0100) Subject: Add assignment operator for Rect to take Vector4 X-Git-Tag: dali_1.9.14~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F81%2F234781%2F3;p=platform%2Fcore%2Fuifw%2Fdali-core.git Add assignment operator for Rect to take Vector4 Change-Id: I4a91f7fbbfc4b12c9cc10c42ce00b70ce85ccca0 --- diff --git a/automated-tests/src/dali/utc-Dali-Rect.cpp b/automated-tests/src/dali/utc-Dali-Rect.cpp index 24ce9d8..b5f50a6 100644 --- a/automated-tests/src/dali/utc-Dali-Rect.cpp +++ b/automated-tests/src/dali/utc-Dali-Rect.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. @@ -65,7 +65,7 @@ int UtcDaliRectCons03(void) Rect rect(10.0f, 20.0f, 400.0f, 200.0f); - Rect r2 = rect; + Rect 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 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 rect(10.0f, 20.0f, 400.0f, 200.0f); - Rect r2(rect); + Rect 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 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; diff --git a/dali/public-api/math/rect.h b/dali/public-api/math/rect.h index 649949e..b8b64cf 100644 --- a/dali/public-api/math/rect.h +++ b/dali/public-api/math/rect.h @@ -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& 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