1 #ifndef DALI_TEST_COMPARE_TYPES_H
2 #define DALI_TEST_COMPARE_TYPES_H
5 * Copyright (c) 2020 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>
23 template<typename Type>
24 inline bool CompareType(Type value1, Type value2, float epsilon)
26 return value1 == value2;
30 * A helper for fuzzy-comparing Vector2 objects
31 * @param[in] vector1 the first object
32 * @param[in] vector2 the second object
33 * @param[in] epsilon difference threshold
34 * @returns true if difference is smaller than epsilon threshold, false otherwise
37 inline bool CompareType<float>(float value1, float value2, float epsilon)
39 return fabsf(value1 - value2) < epsilon;
43 * A helper for fuzzy-comparing Vector2 objects
44 * @param[in] vector1 the first object
45 * @param[in] vector2 the second object
46 * @param[in] epsilon difference threshold
47 * @returns true if difference is smaller than epsilon threshold, false otherwise
50 inline bool CompareType<Vector2>(Vector2 vector1, Vector2 vector2, float epsilon)
52 return fabsf(vector1.x - vector2.x) < epsilon && fabsf(vector1.y - vector2.y) < epsilon;
56 * A helper for fuzzy-comparing Vector3 objects
57 * @param[in] vector1 the first object
58 * @param[in] vector2 the second object
59 * @param[in] epsilon difference threshold
60 * @returns true if difference is smaller than epsilon threshold, false otherwise
63 inline bool CompareType<Vector3>(Vector3 vector1, Vector3 vector2, float epsilon)
65 return fabsf(vector1.x - vector2.x) < epsilon &&
66 fabsf(vector1.y - vector2.y) < epsilon &&
67 fabsf(vector1.z - vector2.z) < epsilon;
71 * A helper for fuzzy-comparing Vector4 objects
72 * @param[in] vector1 the first object
73 * @param[in] vector2 the second object
74 * @param[in] epsilon difference threshold
75 * @returns true if difference is smaller than epsilon threshold, false otherwise
78 inline bool CompareType<Vector4>(Vector4 vector1, Vector4 vector2, float epsilon)
80 return fabsf(vector1.x - vector2.x) < epsilon &&
81 fabsf(vector1.y - vector2.y) < epsilon &&
82 fabsf(vector1.z - vector2.z) < epsilon &&
83 fabsf(vector1.w - vector2.w) < epsilon;
87 inline bool CompareType<Quaternion>(Quaternion q1, Quaternion q2, float epsilon)
89 Quaternion q2N = -q2; // These quaternions represent the same rotation
90 return CompareType<Vector4>(q1.mVector, q2.mVector, epsilon) || CompareType<Vector4>(q1.mVector, q2N.mVector, epsilon);
94 inline bool CompareType<Radian>(Radian q1, Radian q2, float epsilon)
96 return CompareType<float>(q1.radian, q2.radian, epsilon);
100 inline bool CompareType<Degree>(Degree q1, Degree q2, float epsilon)
102 return CompareType<float>(q1.degree, q2.degree, epsilon);
106 inline bool CompareType<Extents>(Extents extents1, Extents extents2, float epsilon)
108 return (extents1.start == extents2.start) &&
109 (extents1.end == extents2.end) &&
110 (extents1.top == extents2.top) &&
111 (extents1.bottom == extents2.bottom);
115 inline bool CompareType<Property::Value>(Property::Value q1, Property::Value q2, float epsilon)
117 Property::Type type = q1.GetType();
118 if(type != q2.GetType())
126 case Property::BOOLEAN:
134 case Property::INTEGER:
142 case Property::FLOAT:
147 result = CompareType<float>(a, b, epsilon);
150 case Property::VECTOR2:
155 result = CompareType<Vector2>(a, b, epsilon);
158 case Property::VECTOR3:
163 result = CompareType<Vector3>(a, b, epsilon);
166 case Property::RECTANGLE:
167 case Property::VECTOR4:
172 result = CompareType<Vector4>(a, b, epsilon);
175 case Property::ROTATION:
180 result = CompareType<Quaternion>(a, b, epsilon);
183 case Property::STRING:
188 result = (a.compare(b) == 0);
191 case Property::MATRIX:
192 case Property::MATRIX3:
193 case Property::ARRAY:
196 //TODO: Implement this?
197 DALI_ASSERT_ALWAYS(0 && "Not implemented");
201 case Property::EXTENTS:
206 result = CompareType<Extents>(a, b, epsilon);