fcadd6fa5f65156795822b7e9612ec44ccd19e74
[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) 2022 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 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
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 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
48  */
49 template<>
50 inline bool CompareType<Vector2>(Vector2 vector1, Vector2 vector2, float epsilon)
51 {
52   return fabsf(vector1.x - vector2.x) < epsilon && fabsf(vector1.y - vector2.y) < epsilon;
53 }
54
55 /**
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
61  */
62 template<>
63 inline bool CompareType<Vector3>(Vector3 vector1, Vector3 vector2, float epsilon)
64 {
65   return fabsf(vector1.x - vector2.x) < epsilon &&
66          fabsf(vector1.y - vector2.y) < epsilon &&
67          fabsf(vector1.z - vector2.z) < epsilon;
68 }
69
70 /**
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
76  */
77 template<>
78 inline bool CompareType<Vector4>(Vector4 vector1, Vector4 vector2, float epsilon)
79 {
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;
84 }
85
86 template<>
87 inline bool CompareType<Quaternion>(Quaternion q1, Quaternion q2, float epsilon)
88 {
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);
91 }
92
93 template<>
94 inline bool CompareType<Radian>(Radian q1, Radian q2, float epsilon)
95 {
96   return CompareType<float>(q1.radian, q2.radian, epsilon);
97 }
98
99 template<>
100 inline bool CompareType<Degree>(Degree q1, Degree q2, float epsilon)
101 {
102   return CompareType<float>(q1.degree, q2.degree, epsilon);
103 }
104
105 template<>
106 inline bool CompareType<Extents>(Extents extents1, Extents extents2, float epsilon)
107 {
108   return (extents1.start == extents2.start) &&
109          (extents1.end == extents2.end) &&
110          (extents1.top == extents2.top) &&
111          (extents1.bottom == extents2.bottom);
112 }
113
114 #endif