Calculate VisualRenderer coefficient only if updated.
[platform/core/uifw/dali-core.git] / dali / internal / update / common / property-condition-variable-step-functions.cpp
index 60fca7b..e194329 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
  */
 
+#include <dali/internal/update/common/property-condition-variable-step-functions.h>
 #include <dali/public-api/common/dali-common.h>
 #include <dali/public-api/math/vector2.h>
 #include <dali/public-api/math/vector3.h>
 #include <dali/public-api/math/vector4.h>
 #include <dali/public-api/object/property-input.h>
-#include <dali/internal/update/common/property-condition-variable-step-functions.h>
 
 namespace Dali
 {
-
 namespace Internal
 {
-
 namespace SceneGraph
 {
-
 namespace
 {
+const int32_t ARGINDEX_STEP_INDEX = 0;
+const int32_t ARGINDEX_LIST_SIZE  = 1;
+const int32_t ARGINDEX_LIST_START = 2;
 
-const int ARGINDEX_STEP_INDEX = 0;
-const int ARGINDEX_LIST_SIZE = 1;
-const int ARGINDEX_LIST_START = 2;
-
-}
+} // namespace
 
-ConditionFunction VariableStep::GetFunction( Property::Type valueType )
+ConditionFunction VariableStep::GetFunction(Property::Type valueType)
 {
-  ConditionFunction function = NULL;
+  ConditionFunction function = nullptr;
 
-  switch( valueType )
+  switch(valueType)
   {
     case Property::INTEGER:
     {
@@ -81,23 +77,23 @@ ConditionFunction VariableStep::GetFunction( Property::Type valueType )
   return function;
 }
 
-bool VariableStep::Evaluate( const float propertyValue, PropertyNotification::RawArgumentContainer& arg )
+bool VariableStep::Evaluate(const float propertyValue, PropertyNotification::RawArgumentContainer& arg)
 {
-  const int currentIndex = arg[ARGINDEX_STEP_INDEX];
-  const int numSteps = arg[ARGINDEX_LIST_SIZE];
-  const float first = arg[ARGINDEX_LIST_START];
-  const float last = arg[ARGINDEX_LIST_START + (numSteps - 1)];
-  const bool ascending = (last > first) ? true : false;
-  int newIndex = currentIndex;
+  const int32_t currentIndex = static_cast<int32_t>(arg[ARGINDEX_STEP_INDEX]); // truncated
+  const int32_t numSteps     = static_cast<int32_t>(arg[ARGINDEX_LIST_SIZE]);  // truncated
+  const float   first        = arg[ARGINDEX_LIST_START];
+  const float   last         = arg[ARGINDEX_LIST_START + (numSteps - 1)];
+  const bool    ascending    = (last > first) ? true : false;
+  int32_t       newIndex     = currentIndex;
 
   // avoid loop if property currently not within any of the range values
-  if( ascending )
+  if(ascending)
   {
-    if( propertyValue < first )
+    if(propertyValue < first)
     {
       newIndex = -1;
     }
-    else if( propertyValue >= last )
+    else if(propertyValue >= last)
     {
       newIndex = numSteps - 1;
     }
@@ -105,24 +101,23 @@ bool VariableStep::Evaluate( const float propertyValue, PropertyNotification::Ra
   else
   {
     // increments are in negative direction
-    if( propertyValue > first )
+    if(propertyValue > first)
     {
       newIndex = -1;
     }
-    else if( propertyValue <= last )
+    else if(propertyValue <= last)
     {
       newIndex = numSteps - 1;
     }
   }
-  int i = 0;
-  for( i = 0 ; i < numSteps - 1 ; ++i )
+  int32_t i = 0;
+  for(i = 0; i < numSteps - 1; ++i)
   {
     const float arg1 = arg[ARGINDEX_LIST_START + i];
     const float arg2 = arg[ARGINDEX_LIST_START + (i + 1)];
-    if( ascending )
+    if(ascending)
     {
-      if( ( propertyValue >= arg1 )
-          && ( propertyValue < arg2 ) )
+      if((propertyValue >= arg1) && (propertyValue < arg2))
       {
         newIndex = i;
         break;
@@ -131,15 +126,14 @@ bool VariableStep::Evaluate( const float propertyValue, PropertyNotification::Ra
     else
     {
       // increments are in negative direction
-      if( ( propertyValue > arg2 )
-          && ( propertyValue <= arg1 ) )
+      if((propertyValue > arg2) && (propertyValue <= arg1))
       {
         newIndex = i;
         break;
       }
     }
   }
-  if( newIndex != currentIndex )
+  if(newIndex != currentIndex)
   {
     // have changed to new step
     arg[ARGINDEX_STEP_INDEX] = static_cast<float>(newIndex);
@@ -148,37 +142,37 @@ bool VariableStep::Evaluate( const float propertyValue, PropertyNotification::Ra
   return false;
 }
 
-bool VariableStep::EvalInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
+bool VariableStep::EvalInteger(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
 {
-  const float propertyValue = static_cast<float>( value.GetInteger() );
-  return Evaluate( propertyValue, arg );
+  const float propertyValue = static_cast<float>(value.GetInteger());
+  return Evaluate(propertyValue, arg);
 }
 
-bool VariableStep::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
+bool VariableStep::EvalFloat(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
 {
   const float propertyValue = value.GetFloat();
-  return Evaluate( propertyValue, arg );
+  return Evaluate(propertyValue, arg);
 }
 
-bool VariableStep::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
+bool VariableStep::EvalVector2(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
 {
   const float propertyValue = value.GetVector2().LengthSquared();
-  return Evaluate( propertyValue, arg );
+  return Evaluate(propertyValue, arg);
 }
 
-bool VariableStep::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
+bool VariableStep::EvalVector3(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
 {
   float propertyValue = value.GetVector3().LengthSquared();
-  return Evaluate( propertyValue, arg );
+  return Evaluate(propertyValue, arg);
 }
 
-bool VariableStep::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
+bool VariableStep::EvalVector4(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
 {
   const float propertyValue = value.GetVector4().LengthSquared();
-  return Evaluate( propertyValue, arg );
+  return Evaluate(propertyValue, arg);
 }
 
-bool VariableStep::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
+bool VariableStep::EvalDefault(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
 {
   return false;
 }