1 #ifndef DALI_TEST_COMPARE_TYPES_H
2 #define DALI_TEST_COMPARE_TYPES_H
5 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 #include <dali/public-api/dali-core.h>
24 template <typename Type>
25 inline bool CompareType(Type value1, Type value2, float epsilon)
27 return value1 == value2;
31 * A helper for fuzzy-comparing Vector2 objects
32 * @param[in] vector1 the first object
33 * @param[in] vector2 the second object
34 * @param[in] epsilon difference threshold
35 * @returns true if difference is smaller than epsilon threshold, false otherwise
38 inline bool CompareType<float>(float value1, float value2, float epsilon)
40 return fabsf(value1 - value2) < epsilon;
44 * A helper for fuzzy-comparing Vector2 objects
45 * @param[in] vector1 the first object
46 * @param[in] vector2 the second object
47 * @param[in] epsilon difference threshold
48 * @returns true if difference is smaller than epsilon threshold, false otherwise
51 inline bool CompareType<Vector2>(Vector2 vector1, Vector2 vector2, float epsilon)
53 return fabsf(vector1.x - vector2.x)<epsilon && fabsf(vector1.y - vector2.y)<epsilon;
57 * A helper for fuzzy-comparing Vector3 objects
58 * @param[in] vector1 the first object
59 * @param[in] vector2 the second object
60 * @param[in] epsilon difference threshold
61 * @returns true if difference is smaller than epsilon threshold, false otherwise
64 inline bool CompareType<Vector3>(Vector3 vector1, Vector3 vector2, float epsilon)
66 return fabsf(vector1.x - vector2.x)<epsilon &&
67 fabsf(vector1.y - vector2.y)<epsilon &&
68 fabsf(vector1.z - vector2.z)<epsilon;
73 * A helper for fuzzy-comparing Vector4 objects
74 * @param[in] vector1 the first object
75 * @param[in] vector2 the second object
76 * @param[in] epsilon difference threshold
77 * @returns true if difference is smaller than epsilon threshold, false otherwise
80 inline bool CompareType<Vector4>(Vector4 vector1, Vector4 vector2, float epsilon)
82 return fabsf(vector1.x - vector2.x)<epsilon &&
83 fabsf(vector1.y - vector2.y)<epsilon &&
84 fabsf(vector1.z - vector2.z)<epsilon &&
85 fabsf(vector1.w - vector2.w)<epsilon;
89 inline bool CompareType<Quaternion>(Quaternion q1, Quaternion q2, float epsilon)
91 Quaternion q2N = -q2; // These quaternions represent the same rotation
92 return CompareType<Vector4>(q1.mVector, q2.mVector, epsilon) || CompareType<Vector4>(q1.mVector, q2N.mVector, epsilon);
96 inline bool CompareType<Radian>(Radian q1, Radian q2, float epsilon)
98 return CompareType<float>(q1.radian, q2.radian, epsilon);
102 inline bool CompareType<Degree>(Degree q1, Degree q2, float epsilon)
104 return CompareType<float>(q1.degree, q2.degree, epsilon);
108 inline bool CompareType<Extents>(Extents extents1, Extents extents2, float epsilon)
110 return (extents1.start == extents2.start) &&
111 (extents1.end == extents2.end) &&
112 (extents1.top == extents2.top) &&
113 (extents1.bottom == extents2.bottom);
117 inline bool CompareType<Property::Value>(Property::Value q1, Property::Value q2, float epsilon)
119 Property::Type type = q1.GetType();
120 if( type != q2.GetType() )
128 case Property::BOOLEAN:
136 case Property::INTEGER:
144 case Property::FLOAT:
149 result = CompareType<float>(a, b, epsilon);
152 case Property::VECTOR2:
157 result = CompareType<Vector2>(a, b, epsilon);
160 case Property::VECTOR3:
165 result = CompareType<Vector3>(a, b, epsilon);
168 case Property::RECTANGLE:
169 case Property::VECTOR4:
174 result = CompareType<Vector4>(a, b, epsilon);
177 case Property::ROTATION:
182 result = CompareType<Quaternion>(a, b, epsilon);
185 case Property::STRING:
190 result = (a.compare(b) == 0);
193 case Property::MATRIX:
194 case Property::MATRIX3:
195 case Property::ARRAY:
198 //TODO: Implement this?
199 DALI_ASSERT_ALWAYS( 0 && "Not implemented");
203 case Property::EXTENTS:
208 result = CompareType<Extents>( a, b, epsilon );