(Partial Update) Change damaged rect calcutation
[platform/core/uifw/dali-core.git] / dali / internal / update / common / property-condition-functions.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali/internal/update/common/property-condition-functions.h>
19 #include <dali/public-api/common/dali-common.h>
20 #include <dali/public-api/math/vector2.h>
21 #include <dali/public-api/math/vector3.h>
22 #include <dali/public-api/math/vector4.h>
23 #include <dali/public-api/object/property-input.h>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace SceneGraph
30 {
31 // LessThan ///////////////////////////////////////////////////////////////////
32
33 ConditionFunction LessThan::GetFunction(Property::Type valueType)
34 {
35   ConditionFunction function = nullptr;
36
37   switch(valueType)
38   {
39     case Property::BOOLEAN:
40     {
41       function = LessThan::EvalBoolean;
42       break;
43     }
44     case Property::INTEGER:
45     {
46       function = LessThan::EvalInteger;
47       break;
48     }
49     case Property::FLOAT:
50     {
51       function = LessThan::EvalFloat;
52       break;
53     }
54     case Property::VECTOR2:
55     {
56       function = LessThan::EvalVector2;
57       break;
58     }
59     case Property::VECTOR3:
60     {
61       function = LessThan::EvalVector3;
62       break;
63     }
64     case Property::VECTOR4:
65     {
66       function = LessThan::EvalVector4;
67       break;
68     }
69     default:
70     {
71       function = LessThan::EvalDefault;
72       break;
73     }
74   } // end switch
75
76   return function;
77 }
78
79 bool LessThan::EvalBoolean(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
80 {
81   const float arg0 = arg[0];
82   return (value.GetBoolean() < arg0);
83 }
84
85 bool LessThan::EvalInteger(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
86 {
87   const int32_t arg0 = static_cast<int32_t>(arg[0]);
88   return (value.GetInteger() < arg0);
89 }
90
91 bool LessThan::EvalFloat(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
92 {
93   const float arg0 = arg[0];
94   return (value.GetFloat() < arg0);
95 }
96
97 bool LessThan::EvalVector2(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
98 {
99   const float arg0 = arg[0];
100   return (value.GetVector2().LengthSquared() < arg0 * arg0);
101 }
102
103 bool LessThan::EvalVector3(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
104 {
105   const float arg0 = arg[0];
106   return (value.GetVector3().LengthSquared() < arg0 * arg0);
107 }
108
109 bool LessThan::EvalVector4(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
110 {
111   const float arg0 = arg[0];
112   return (value.GetVector4().LengthSquared() < arg0 * arg0);
113 }
114
115 bool LessThan::EvalDefault(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
116 {
117   return false;
118 }
119
120 // GreaterThan ///////////////////////////////////////////////////////////////////
121
122 ConditionFunction GreaterThan::GetFunction(Property::Type valueType)
123 {
124   ConditionFunction function = nullptr;
125
126   switch(valueType)
127   {
128     case Property::BOOLEAN:
129     {
130       function = GreaterThan::EvalBoolean;
131       break;
132     }
133     case Property::INTEGER:
134     {
135       function = GreaterThan::EvalInteger;
136       break;
137     }
138     case Property::FLOAT:
139     {
140       function = GreaterThan::EvalFloat;
141       break;
142     }
143     case Property::VECTOR2:
144     {
145       function = GreaterThan::EvalVector2;
146       break;
147     }
148     case Property::VECTOR3:
149     {
150       function = GreaterThan::EvalVector3;
151       break;
152     }
153     case Property::VECTOR4:
154     {
155       function = GreaterThan::EvalVector4;
156       break;
157     }
158     default:
159     {
160       function = GreaterThan::EvalDefault;
161       break;
162     }
163   } // end switch
164
165   return function;
166 }
167
168 bool GreaterThan::EvalBoolean(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
169 {
170   const float arg0 = arg[0];
171   return (value.GetBoolean() > arg0);
172 }
173
174 bool GreaterThan::EvalInteger(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
175 {
176   const int32_t arg0 = static_cast<int32_t>(arg[0]);
177   return (value.GetInteger() > arg0);
178 }
179
180 bool GreaterThan::EvalFloat(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
181 {
182   const float arg0 = arg[0];
183   return (value.GetFloat() > arg0);
184 }
185
186 bool GreaterThan::EvalVector2(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
187 {
188   const float arg0 = arg[0];
189   return (value.GetVector2().LengthSquared() > arg0 * arg0);
190 }
191
192 bool GreaterThan::EvalVector3(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
193 {
194   const float arg0 = arg[0];
195   return (value.GetVector3().LengthSquared() > arg0 * arg0);
196 }
197
198 bool GreaterThan::EvalVector4(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
199 {
200   const float arg0 = arg[0];
201   return (value.GetVector4().LengthSquared() > arg0 * arg0);
202 }
203
204 bool GreaterThan::EvalDefault(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
205 {
206   return false;
207 }
208
209 // Inside /////////////////////////////////////////////////////////////////////
210
211 ConditionFunction Inside::GetFunction(Property::Type valueType)
212 {
213   ConditionFunction function = nullptr;
214
215   switch(valueType)
216   {
217     case Property::BOOLEAN:
218     {
219       function = Inside::EvalBoolean;
220       break;
221     }
222     case Property::INTEGER:
223     {
224       function = Inside::EvalInteger;
225       break;
226     }
227     case Property::FLOAT:
228     {
229       function = Inside::EvalFloat;
230       break;
231     }
232     case Property::VECTOR2:
233     {
234       function = Inside::EvalVector2;
235       break;
236     }
237     case Property::VECTOR3:
238     {
239       function = Inside::EvalVector3;
240       break;
241     }
242     case Property::VECTOR4:
243     {
244       function = Inside::EvalVector4;
245       break;
246     }
247     default:
248     {
249       function = Inside::EvalDefault;
250       break;
251     }
252   } // end switch
253
254   return function;
255 }
256
257 bool Inside::EvalBoolean(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
258 {
259   const bool valueBoolean = value.GetBoolean();
260   return ((valueBoolean > arg[0]) && (valueBoolean < arg[1]));
261 }
262
263 bool Inside::EvalInteger(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
264 {
265   const int32_t valueInteger = value.GetInteger();
266   return ((valueInteger > static_cast<int32_t>(arg[0])) && (valueInteger < static_cast<int32_t>(arg[1])));
267 }
268
269 bool Inside::EvalFloat(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
270 {
271   const float valueFloat = value.GetFloat();
272   return ((valueFloat > arg[0]) && (valueFloat < arg[1]));
273 }
274
275 bool Inside::EvalVector2(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
276 {
277   const float length2 = value.GetVector2().LengthSquared();
278   return ((length2 > arg[0] * arg[0]) && (length2 < arg[1] * arg[1]));
279 }
280
281 bool Inside::EvalVector3(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
282 {
283   const float length2 = value.GetVector3().LengthSquared();
284   return ((length2 > arg[0] * arg[0]) && (length2 < arg[1] * arg[1]));
285 }
286
287 bool Inside::EvalVector4(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
288 {
289   const float length2 = value.GetVector4().LengthSquared();
290   return ((length2 > arg[0] * arg[0]) && (length2 < arg[1] * arg[1]));
291 }
292
293 bool Inside::EvalDefault(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
294 {
295   return false;
296 }
297
298 // Outside ////////////////////////////////////////////////////////////////////
299
300 ConditionFunction Outside::GetFunction(Property::Type valueType)
301 {
302   ConditionFunction function = nullptr;
303
304   switch(valueType)
305   {
306     case Property::BOOLEAN:
307     {
308       function = Outside::EvalBoolean;
309       break;
310     }
311     case Property::INTEGER:
312     {
313       function = Outside::EvalInteger;
314       break;
315     }
316     case Property::FLOAT:
317     {
318       function = Outside::EvalFloat;
319       break;
320     }
321     case Property::VECTOR2:
322     {
323       function = Outside::EvalVector2;
324       break;
325     }
326     case Property::VECTOR3:
327     {
328       function = Outside::EvalVector3;
329       break;
330     }
331     case Property::VECTOR4:
332     {
333       function = Outside::EvalVector4;
334       break;
335     }
336     default:
337     {
338       function = Outside::EvalDefault;
339       break;
340     }
341   } // end switch
342
343   return function;
344 }
345
346 bool Outside::EvalBoolean(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
347 {
348   const bool valueBoolean = value.GetBoolean();
349   return ((valueBoolean < arg[0]) || (valueBoolean > arg[1]));
350 }
351
352 bool Outside::EvalInteger(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
353 {
354   const int32_t valueInteger = value.GetInteger();
355   return ((valueInteger < static_cast<int32_t>(arg[0])) || (valueInteger > static_cast<int32_t>(arg[0])));
356 }
357
358 bool Outside::EvalFloat(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
359 {
360   const float valueFloat = value.GetFloat();
361   return ((valueFloat < arg[0]) || (valueFloat > arg[1]));
362 }
363
364 bool Outside::EvalVector2(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
365 {
366   const float length2 = value.GetVector2().LengthSquared();
367   return ((length2 < arg[0] * arg[0]) || (length2 > arg[1] * arg[1]));
368 }
369
370 bool Outside::EvalVector3(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
371 {
372   const float length2 = value.GetVector3().LengthSquared();
373   return ((length2 < arg[0] * arg[0]) || (length2 > arg[1] * arg[1]));
374 }
375
376 bool Outside::EvalVector4(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
377 {
378   const float length2 = value.GetVector4().LengthSquared();
379   return ((length2 < arg[0] * arg[0]) || (length2 > arg[1] * arg[1]));
380 }
381
382 bool Outside::EvalDefault(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
383 {
384   return false;
385 }
386
387 } // namespace SceneGraph
388
389 } // namespace Internal
390
391 } // namespace Dali