From 4ef916e7b406a80102aa02a20ee0da2d807ddf26 Mon Sep 17 00:00:00 2001 From: Kimmo Hoikka Date: Thu, 12 May 2016 14:49:01 +0100 Subject: [PATCH] Allow reading Vector2/3/4 values from Property::Value with type Vector2/3/4, matching Dali::Vector default behaviour Change-Id: I27fcafa2d80dcc5b1d991ff14bfec75558d63b7c --- .../src/dali/utc-Dali-PropertyValue.cpp | 62 +++++++++++++++++++++- automated-tests/src/dali/utc-Dali-Vector4.cpp | 9 +++- dali/public-api/math/vector4.cpp | 7 +-- dali/public-api/object/property-value.cpp | 46 ++++++++++++---- dali/public-api/object/property-value.h | 26 ++++----- 5 files changed, 122 insertions(+), 28 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-PropertyValue.cpp b/automated-tests/src/dali/utc-Dali-PropertyValue.cpp index 5444adb..ea4ec5d 100644 --- a/automated-tests/src/dali/utc-Dali-PropertyValue.cpp +++ b/automated-tests/src/dali/utc-Dali-PropertyValue.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -876,6 +876,26 @@ int UtcDaliPropertyValueGetVector2P(void) END_TEST; } +int UtcDaliPropertyValueGetVector2fromVector3P(void) +{ + Property::Value value( Vector3(1.f,2.f,3.f) ); + Vector2 result; + DALI_TEST_EQUALS( Vector2(1.0f,2.0f), value.Get< Vector2 >(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Vector2(1.0f,2.0f), result, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliPropertyValueGetVector2fromVector4P(void) +{ + Property::Value value( Vector4(1.f,2.f,3.f,4.f) ); + Vector2 result; + DALI_TEST_EQUALS( Vector2(1.0f,2.0f), value.Get< Vector2 >(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Vector2(1.0f,2.0f), result, TEST_LOCATION ); + END_TEST; +} + int UtcDaliPropertyValueGetVector2N(void) { Property::Value value; @@ -899,6 +919,26 @@ int UtcDaliPropertyValueGetVector3P(void) END_TEST; } +int UtcDaliPropertyValueGetVector3FromVector2P(void) +{ + Property::Value value( Vector2(1.0f,2.0f) ); + Vector3 result(99.f,88.f,77.f); + DALI_TEST_EQUALS( Vector3(1.0f,2.0f,0.f), value.Get< Vector3 >(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Vector3(1.0f,2.0f,0.f), result, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliPropertyValueGetVector3FromVector4P(void) +{ + Property::Value value( Vector4(4.f,3.f,2.f,1.f) ); + Vector3 result; + DALI_TEST_EQUALS( Vector3(4.f,3.f,2.f), value.Get< Vector3 >(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Vector3(4.f,3.f,2.f), result, TEST_LOCATION ); + END_TEST; +} + int UtcDaliPropertyValueGetVector3N(void) { Property::Value value; @@ -922,6 +962,26 @@ int UtcDaliPropertyValueGetVector4P(void) END_TEST; } +int UtcDaliPropertyValueGetVector4FromVector2P(void) +{ + Property::Value value( Vector2(-1.f,-3.f) ); + Vector4 result(99.f,88.f,77.f,66.f); + DALI_TEST_EQUALS( Vector4(-1.f,-3.f,0.f,0.f), value.Get< Vector4 >(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Vector4(-1.f,-3.f,0.f,0.f), result, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliPropertyValueGetVector4FromVector3P(void) +{ + Property::Value value( Vector3(1.f,2.f,-1.f) ); + Vector4 result(99.f,88.f,77.f,66.f); + DALI_TEST_EQUALS( Vector4(1.f,2.f,-1.f,0.f), value.Get< Vector4 >(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Vector4(1.f,2.f,-1.f,0.f), result, TEST_LOCATION ); + END_TEST; +} + int UtcDaliPropertyValueGetVector4N(void) { Property::Value value; diff --git a/automated-tests/src/dali/utc-Dali-Vector4.cpp b/automated-tests/src/dali/utc-Dali-Vector4.cpp index b1a6a63..ba51c56 100644 --- a/automated-tests/src/dali/utc-Dali-Vector4.cpp +++ b/automated-tests/src/dali/utc-Dali-Vector4.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -109,6 +109,13 @@ int UtcDaliVector4Assign02P(void) DALI_TEST_EQUALS(v0.y, 2.0f, 0.001f, TEST_LOCATION); DALI_TEST_EQUALS(v0.z, 0.0f, 0.001f, TEST_LOCATION); DALI_TEST_EQUALS(v0.z, 0.0f, 0.001f, TEST_LOCATION); + v0.w = v0.z = 99.f; + v0 = vec2; + DALI_TEST_EQUALS(v0.x, 1.0f, 0.001f, TEST_LOCATION); + DALI_TEST_EQUALS(v0.y, 2.0f, 0.001f, TEST_LOCATION); + DALI_TEST_EQUALS(v0.z, 0.0f, 0.001f, TEST_LOCATION); + DALI_TEST_EQUALS(v0.z, 0.0f, 0.001f, TEST_LOCATION); + END_TEST; } diff --git a/dali/public-api/math/vector4.cpp b/dali/public-api/math/vector4.cpp index 3924f6c..15815d4 100644 --- a/dali/public-api/math/vector4.cpp +++ b/dali/public-api/math/vector4.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -58,18 +58,19 @@ Vector4::Vector4( const Vector3& vec3 ) Vector4& Vector4::operator=(const Vector2& vec2 ) { - // only set x and y x = vec2.x; y = vec2.y; + z = 0.0f; + w = 0.0f; return *this; } Vector4& Vector4::operator=(const Vector3& vec3 ) { - // only set x, y and z x = vec3.x; y = vec3.y; z = vec3.z; + w = 0.0f; return *this; } diff --git a/dali/public-api/object/property-value.cpp b/dali/public-api/object/property-value.cpp index 864c07e..ffd0f70 100644 --- a/dali/public-api/object/property-value.cpp +++ b/dali/public-api/object/property-value.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -634,10 +634,14 @@ bool Property::Value::Get( int& integerValue ) const bool Property::Value::Get( Vector2& vectorValue ) const { bool converted = false; - if( mImpl && (mImpl->type == VECTOR2) ) // type cannot change in mImpl so vector is allocated + if( mImpl ) { - vectorValue = *(mImpl->vector2Value); - converted = true; + // type cannot change in mImpl so vector is allocated + if( mImpl->type == VECTOR2 || mImpl->type == VECTOR3 || mImpl->type == VECTOR4 ) + { + vectorValue = *(mImpl->vector2Value); // if Vector3 or 4 only x and y are assigned + converted = true; + } } return converted; } @@ -645,10 +649,19 @@ bool Property::Value::Get( Vector2& vectorValue ) const bool Property::Value::Get( Vector3& vectorValue ) const { bool converted = false; - if( mImpl && (mImpl->type == VECTOR3) ) // type cannot change in mImpl so vector is allocated + if( mImpl ) { - vectorValue = *(mImpl->vector3Value); - converted = true; + // type cannot change in mImpl so vector is allocated + if ( mImpl->type == VECTOR3 || mImpl->type == VECTOR4 ) + { + vectorValue = *(mImpl->vector3Value); // if Vector4 only x,y,z are assigned + converted = true; + } + else if( mImpl->type == VECTOR2 ) + { + vectorValue = *(mImpl->vector2Value); + converted = true; + } } return converted; } @@ -656,10 +669,23 @@ bool Property::Value::Get( Vector3& vectorValue ) const bool Property::Value::Get( Vector4& vectorValue ) const { bool converted = false; - if( mImpl && (mImpl->type == VECTOR4) ) // type cannot change in mImpl so vector is allocated + if( mImpl ) { - vectorValue = *(mImpl->vector4Value); - converted = true; + if( mImpl->type == VECTOR4 ) // type cannot change in mImpl so vector is allocated + { + vectorValue = *(mImpl->vector4Value); + converted = true; + } + else if( mImpl->type == VECTOR2 ) + { + vectorValue = *(mImpl->vector2Value); + converted = true; + } + else if( mImpl->type == VECTOR3 ) + { + vectorValue = *(mImpl->vector3Value); + converted = true; + } } return converted; } diff --git a/dali/public-api/object/property-value.h b/dali/public-api/object/property-value.h index a388aa5..8ebab5a 100644 --- a/dali/public-api/object/property-value.h +++ b/dali/public-api/object/property-value.h @@ -2,7 +2,7 @@ #define __DALI_PROPERTY_VALUE_H__ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -239,7 +239,7 @@ public: * @SINCE_1_0.0 * @param [out] boolValue On return, a boolean value. * @return true if the value is successfully retrieved, false if the type is not convertible - * @pre GetType() returns Property::BOOLEAN. + * @pre GetType() is a type convertible to bool. */ bool Get( bool& boolValue ) const; @@ -249,7 +249,7 @@ public: * @SINCE_1_0.0 * @param [out] floatValue On return, a floating-point value. * @return true if the value is successfully retrieved, false if the type is not convertible - * @pre GetType() returns Property::FLOAT. + * @pre GetType() is a type convertible to float. */ bool Get( float& floatValue ) const; @@ -259,7 +259,7 @@ public: * @SINCE_1_0.0 * @param [out] integerValue On return, an integer value. * @return true if the value is successfully retrieved, false if the type is not convertible - * @pre GetType() returns Property::INTEGER. + * @pre GetType() is a type convertible to int. */ bool Get( int& integerValue ) const; @@ -269,7 +269,7 @@ public: * @SINCE_1_0.0 * @param [out] rect On return, an integer rectangle. * @return true if the value is successfully retrieved, false if the type is not convertible - * @pre GetType() returns Property::RECTANGLE. + * @pre GetType() is a type convertible to Rect. */ bool Get( Rect& rect ) const; @@ -279,7 +279,7 @@ public: * @SINCE_1_0.0 * @param [out] vectorValue On return, a vector value. * @return true if the value is successfully retrieved, false if the type is not convertible - * @pre GetType() returns Property::VECTOR2. + * @pre GetType() is a type convertible to Vector2. */ bool Get( Vector2& vectorValue ) const; @@ -289,7 +289,7 @@ public: * @SINCE_1_0.0 * @param [out] vectorValue On return, a vector value. * @return true if the value is successfully retrieved, false if the type is not convertible - * @pre GetType() returns Property::VECTOR3. + * @pre GetType() is a type convertible to Vector3. */ bool Get( Vector3& vectorValue ) const; @@ -299,7 +299,7 @@ public: * @SINCE_1_0.0 * @param [out] vectorValue On return, a vector value. * @return true if the value is successfully retrieved, false if the type is not convertible - * @pre GetType() returns Property::VECTOR4. + * @pre GetType() is a type convertible to Vector4. */ bool Get( Vector4& vectorValue ) const; @@ -309,7 +309,7 @@ public: * @SINCE_1_0.0 * @param [out] matrixValue On return, a matrix3 value. * @return true if the value is successfully retrieved, false if the type is not convertible - * @pre GetType() returns Property::MATRIX3. + * @pre GetType() is a type convertible to Matrix3. */ bool Get( Matrix3& matrixValue ) const; @@ -319,7 +319,7 @@ public: * @SINCE_1_0.0 * @param [out] matrixValue On return, a matrix value. * @return true if the value is successfully retrieved, false if the type is not convertible - * @pre GetType() returns Property::MATRIX. + * @pre GetType() is a type convertible to Matrix. */ bool Get( Matrix& matrixValue ) const; @@ -329,7 +329,7 @@ public: * @SINCE_1_0.0 * @param [out] angleAxisValue On return, a angle-axis value. * @return true if the value is successfully retrieved, false if the type is not convertible - * @pre GetType() returns Property::ROTATION. + * @pre GetType() is a type convertible to AngleAxis. */ bool Get( AngleAxis& angleAxisValue ) const; @@ -339,7 +339,7 @@ public: * @SINCE_1_0.0 * @param [out] quaternionValue On return, a quaternion value. * @return true if the value is successfully retrieved, false if the type is not convertible - * @pre GetType() returns Property::ROTATION. + * @pre GetType() is a type convertible to Quaternion. */ bool Get( Quaternion& quaternionValue ) const; @@ -349,7 +349,7 @@ public: * @SINCE_1_0.0 * @param [out] stringValue A string. * @return true if the value is successfully retrieved, false if the type is not convertible - * @pre GetType() returns Property::STRING. + * @pre GetType() is a type convertible to string. */ bool Get( std::string& stringValue ) const; -- 2.7.4