1 #ifndef DALI_TEST_COMPARE_TYPES_H
2 #define DALI_TEST_COMPARE_TYPES_H
5 * Copyright (c) 2023 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 matching floats
31 * @param[in] value1 the first object
32 * @param[in] value2 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 matching doubles
44 * @param[in] value1 the first object
45 * @param[in] value2 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<double>(double value1, double value2, float epsilon)
52 return fabs(value1 - value2) < double(epsilon);
56 * A helper for fuzzy-comparing Vector2 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<Vector2>(Vector2 vector1, Vector2 vector2, float epsilon)
65 return fabsf(vector1.x - vector2.x) < epsilon && fabsf(vector1.y - vector2.y) < epsilon;
69 * A helper for fuzzy-comparing Vector3 objects
70 * @param[in] vector1 the first object
71 * @param[in] vector2 the second object
72 * @param[in] epsilon difference threshold
73 * @returns true if difference is smaller than epsilon threshold, false otherwise
76 inline bool CompareType<Vector3>(Vector3 vector1, Vector3 vector2, float epsilon)
78 return fabsf(vector1.x - vector2.x) < epsilon &&
79 fabsf(vector1.y - vector2.y) < epsilon &&
80 fabsf(vector1.z - vector2.z) < epsilon;
84 * A helper for fuzzy-comparing Vector4 objects
85 * @param[in] vector1 the first object
86 * @param[in] vector2 the second object
87 * @param[in] epsilon difference threshold
88 * @returns true if difference is smaller than epsilon threshold, false otherwise
91 inline bool CompareType<Vector4>(Vector4 vector1, Vector4 vector2, float epsilon)
93 return fabsf(vector1.x - vector2.x) < epsilon &&
94 fabsf(vector1.y - vector2.y) < epsilon &&
95 fabsf(vector1.z - vector2.z) < epsilon &&
96 fabsf(vector1.w - vector2.w) < epsilon;
100 inline bool CompareType<Quaternion>(Quaternion q1, Quaternion q2, float epsilon)
102 Quaternion q2N = -q2; // These quaternions represent the same rotation
103 return CompareType<Vector4>(q1.mVector, q2.mVector, epsilon) || CompareType<Vector4>(q1.mVector, q2N.mVector, epsilon);
107 inline bool CompareType<Radian>(Radian q1, Radian q2, float epsilon)
109 return CompareType<float>(q1.radian, q2.radian, epsilon);
113 inline bool CompareType<Degree>(Degree q1, Degree q2, float epsilon)
115 return CompareType<float>(q1.degree, q2.degree, epsilon);
119 inline bool CompareType<Extents>(Extents extents1, Extents extents2, float epsilon)
121 return (extents1.start == extents2.start) &&
122 (extents1.end == extents2.end) &&
123 (extents1.top == extents2.top) &&
124 (extents1.bottom == extents2.bottom);