(Partial Update) Change damaged rect calcutation
[platform/core/uifw/dali-core.git] / dali / internal / update / common / property-condition-step-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-step-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 namespace
32 {
33 const int32_t ARGINDEX_REF_VALUE    = 0;
34 const int32_t ARGINDEX_STEP_SIZE    = 1;
35 const int32_t ARGINDEX_CURRENT_STEP = 2;
36 const int32_t ARGINDEX_FIRST_VALUE  = 3;
37 const int32_t ARGINDEX_SECOND_VALUE = 4;
38 const int32_t ARGINDEX_THIRD_VALUE  = 5;
39
40 } // namespace
41
42 ConditionFunction Step::GetFunction(Property::Type valueType)
43 {
44   ConditionFunction function = nullptr;
45
46   switch(valueType)
47   {
48     case Property::INTEGER:
49     {
50       function = EvalInteger;
51       break;
52     }
53     case Property::FLOAT:
54     {
55       function = EvalFloat;
56       break;
57     }
58     case Property::VECTOR2:
59     {
60       function = EvalVector2;
61       break;
62     }
63     case Property::VECTOR3:
64     {
65       function = EvalVector3;
66       break;
67     }
68     case Property::VECTOR4:
69     {
70       function = EvalVector4;
71       break;
72     }
73     default:
74     {
75       function = EvalDefault;
76       break;
77     }
78   } // end switch
79
80   return function;
81 }
82
83 ConditionFunction Step::GetCompareFunction(Property::Type valueType)
84 {
85   ConditionFunction function = nullptr;
86   if(valueType == Property::VECTOR3)
87   {
88     function = EvalAndCompareVector3;
89   }
90   else
91   {
92     function = GetFunction(valueType);
93   }
94
95   return function;
96 }
97
98 bool Step::Evaluate(const float propertyValue, PropertyNotification::RawArgumentContainer& arg)
99 {
100   const float   refValue    = arg[ARGINDEX_REF_VALUE];
101   const float   step        = arg[ARGINDEX_STEP_SIZE];
102   const int32_t currentStep = static_cast<int32_t>(arg[ARGINDEX_CURRENT_STEP]);
103   const float   distance    = (propertyValue - refValue);
104   // step is actual 1.0f / step so can multiply instead of dividing
105   const int32_t newStep = static_cast<int32_t>(floorf(distance * step));
106
107   if(newStep != currentStep)
108   {
109     // in new section
110     arg[ARGINDEX_CURRENT_STEP] = static_cast<float>(newStep);
111     return true;
112   }
113   return false;
114 }
115
116 bool Step::EvalInteger(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
117 {
118   const float propertyValue = static_cast<float>(value.GetInteger());
119   return Evaluate(propertyValue, arg);
120 }
121
122 bool Step::EvalFloat(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
123 {
124   const float propertyValue = value.GetFloat();
125   return Evaluate(propertyValue, arg);
126 }
127
128 bool Step::EvalVector2(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
129 {
130   const float propertyValue = value.GetVector2().Length();
131   return Evaluate(propertyValue, arg);
132 }
133
134 bool Step::EvalVector3(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
135 {
136   float propertyValue = value.GetVector3().Length();
137   return Evaluate(propertyValue, arg);
138 }
139
140 bool Step::EvalAndCompareVector3(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
141 {
142   float propertyValue = value.GetVector3().Length();
143   bool  result        = Evaluate(propertyValue, arg);
144   if(result == false)
145   {
146     const float step = 1.0f / arg[ARGINDEX_STEP_SIZE];
147     if((fabsf(arg[ARGINDEX_FIRST_VALUE] - value.GetVector3().x) > step) || (fabsf(arg[ARGINDEX_SECOND_VALUE] - value.GetVector3().y) > step) || (fabsf(arg[ARGINDEX_THIRD_VALUE] - value.GetVector3().z) > step))
148     {
149       result = true;
150     }
151   }
152   arg[ARGINDEX_FIRST_VALUE]  = value.GetVector3().x;
153   arg[ARGINDEX_SECOND_VALUE] = value.GetVector3().y;
154   arg[ARGINDEX_THIRD_VALUE]  = value.GetVector3().z;
155   return result;
156 }
157
158 bool Step::EvalVector4(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
159 {
160   const float propertyValue = value.GetVector4().Length();
161   return Evaluate(propertyValue, arg);
162 }
163
164 bool Step::EvalDefault(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
165 {
166   return false;
167 }
168
169 } // namespace SceneGraph
170
171 } // namespace Internal
172
173 } // namespace Dali