Updated ImageVisual to handle CPU Image Masking
[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) 2017 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
24 template <typename Type>
25 inline bool CompareType(Type value1, Type value2, float epsilon)
26 {
27   return value1 == value2;
28 }
29
30 /**
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
36  */
37 template <>
38 inline bool CompareType<float>(float value1, float value2, float epsilon)
39 {
40   return fabsf(value1 - value2) < epsilon;
41 }
42
43 /**
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
49  */
50 template <>
51 inline bool CompareType<Vector2>(Vector2 vector1, Vector2 vector2, float epsilon)
52 {
53   return fabsf(vector1.x - vector2.x)<epsilon && fabsf(vector1.y - vector2.y)<epsilon;
54 }
55
56 /**
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
62  */
63 template <>
64 inline bool CompareType<Vector3>(Vector3 vector1, Vector3 vector2, float epsilon)
65 {
66   return fabsf(vector1.x - vector2.x)<epsilon &&
67          fabsf(vector1.y - vector2.y)<epsilon &&
68          fabsf(vector1.z - vector2.z)<epsilon;
69 }
70
71
72 /**
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
78  */
79 template <>
80 inline bool CompareType<Vector4>(Vector4 vector1, Vector4 vector2, float epsilon)
81 {
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;
86 }
87
88 template <>
89 inline bool CompareType<Quaternion>(Quaternion q1, Quaternion q2, float epsilon)
90 {
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);
93 }
94
95 template <>
96 inline bool CompareType<Radian>(Radian q1, Radian q2, float epsilon)
97 {
98   return CompareType<float>(q1.radian, q2.radian, epsilon);
99 }
100
101 template <>
102 inline bool CompareType<Degree>(Degree q1, Degree q2, float epsilon)
103 {
104   return CompareType<float>(q1.degree, q2.degree, epsilon);
105 }
106
107 template <>
108 inline bool CompareType<Property::Value>(Property::Value q1, Property::Value q2, float epsilon)
109 {
110   Property::Type type = q1.GetType();
111   if( type != q2.GetType() )
112   {
113     return false;
114   }
115
116   bool result = false;
117   switch(type)
118   {
119     case Property::BOOLEAN:
120     {
121       bool a, b;
122       q1.Get(a);
123       q2.Get(b);
124       result =  a == b;
125       break;
126     }
127     case Property::INTEGER:
128     {
129       int a, b;
130       q1.Get(a);
131       q2.Get(b);
132       result =  a == b;
133       break;
134     }
135     case Property::FLOAT:
136     {
137       float a, b;
138       q1.Get(a);
139       q2.Get(b);
140       result =  CompareType<float>(a, b, epsilon);
141       break;
142     }
143     case Property::VECTOR2:
144     {
145       Vector2 a, b;
146       q1.Get(a);
147       q2.Get(b);
148       result = CompareType<Vector2>(a, b, epsilon);
149       break;
150     }
151     case Property::VECTOR3:
152     {
153       Vector3 a, b;
154       q1.Get(a);
155       q2.Get(b);
156       result = CompareType<Vector3>(a, b, epsilon);
157       break;
158     }
159     case Property::RECTANGLE:
160     case Property::VECTOR4:
161     {
162       Vector4 a, b;
163       q1.Get(a);
164       q2.Get(b);
165       result = CompareType<Vector4>(a, b, epsilon);
166       break;
167     }
168     case Property::ROTATION:
169     {
170       Quaternion a, b;
171       q1.Get(a);
172       q2.Get(b);
173       result = CompareType<Quaternion>(a, b, epsilon);
174       break;
175     }
176     case Property::STRING:
177     {
178       std::string a, b;
179       q1.Get(a);
180       q2.Get(b);
181       result = (a.compare(b) == 0);
182       break;
183     }
184     case Property::MATRIX:
185     case Property::MATRIX3:
186     case Property::ARRAY:
187     case Property::MAP:
188     {
189       //TODO: Implement this?
190       DALI_ASSERT_ALWAYS( 0 && "Not implemented");
191       result = false;
192       break;
193     }
194     case Property::NONE:
195     {
196       result = false;
197       break;
198     }
199   }
200
201   return result;
202 }
203
204
205
206 #endif