[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-compare-types.h
1 #ifndef DALI_TEST_COMPARE_TYPES_H
2 #define DALI_TEST_COMPARE_TYPES_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 #include <dali/public-api/dali-core.h>
21 using namespace Dali;
22
23 template<typename Type>
24 inline bool CompareType(Type value1, Type value2, float epsilon)
25 {
26   return value1 == value2;
27 }
28
29 /**
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
35  */
36 template<>
37 inline bool CompareType<float>(float value1, float value2, float epsilon)
38 {
39   return fabsf(value1 - value2) < epsilon;
40 }
41
42 /**
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
48  */
49 template<>
50 inline bool CompareType<double>(double value1, double value2, float epsilon)
51 {
52   return fabs(value1 - value2) < double(epsilon);
53 }
54
55 /**
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
61  */
62 template<>
63 inline bool CompareType<Vector2>(Vector2 vector1, Vector2 vector2, float epsilon)
64 {
65   return fabsf(vector1.x - vector2.x) < epsilon && fabsf(vector1.y - vector2.y) < epsilon;
66 }
67
68 /**
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
74  */
75 template<>
76 inline bool CompareType<Vector3>(Vector3 vector1, Vector3 vector2, float epsilon)
77 {
78   return fabsf(vector1.x - vector2.x) < epsilon &&
79          fabsf(vector1.y - vector2.y) < epsilon &&
80          fabsf(vector1.z - vector2.z) < epsilon;
81 }
82
83 /**
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
89  */
90 template<>
91 inline bool CompareType<Vector4>(Vector4 vector1, Vector4 vector2, float epsilon)
92 {
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;
97 }
98
99 template<>
100 inline bool CompareType<Quaternion>(Quaternion q1, Quaternion q2, float epsilon)
101 {
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);
104 }
105
106 template<>
107 inline bool CompareType<Radian>(Radian q1, Radian q2, float epsilon)
108 {
109   return CompareType<float>(q1.radian, q2.radian, epsilon);
110 }
111
112 template<>
113 inline bool CompareType<Degree>(Degree q1, Degree q2, float epsilon)
114 {
115   return CompareType<float>(q1.degree, q2.degree, epsilon);
116 }
117
118 template<>
119 inline bool CompareType<Extents>(Extents extents1, Extents extents2, float epsilon)
120 {
121   return (extents1.start == extents2.start) &&
122          (extents1.end == extents2.end) &&
123          (extents1.top == extents2.top) &&
124          (extents1.bottom == extents2.bottom);
125 }
126
127 #endif