(PanGesture) Ensure we do not send invalid velocities 95/24095/1
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Mon, 30 Jun 2014 08:05:39 +0000 (17:05 +0900)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Tue, 8 Jul 2014 13:19:39 +0000 (14:19 +0100)
[problem]     Sometimes, the velocity is an infinite number.
[cause]       In these cases, no time has passed between the current and the last velocity so time
              difference is zero.
[solution]    Ensure we do not divide by 0, just send a ZERO vector2 if this is the case.

Change-Id: I80c03000576a324febe0e19e257a4f095079547b
Signed-off-by: Adeel Kazmi <adeel.kazmi@samsung.com>
automated-tests/src/dali/tct-dali-core.h
automated-tests/src/dali/utc-Dali-PanGestureDetector.cpp
dali/internal/event/events/pan-gesture-processor.cpp

index 07833ed..be42d95 100644 (file)
@@ -430,6 +430,7 @@ extern int UtcDaliAnimationAnimateBetweenActorColorFunctionTimePeriod(void);
 extern int UtcDaliAnimationAnimateVector3Func(void);
 extern int UtcDaliAnimationCreateDestroy(void);
 extern int UtcDaliAnimationUpdateManager(void);
+extern int UtcDaliAnimationSignalOrder(void);
 extern int UtcDaliAnyConstructors(void);
 extern int UtcDaliAnyAssignmentOperators(void);
 extern int UtcDaliAnyNegativeAssignmentOperators(void);
@@ -887,6 +888,7 @@ extern int UtcDaliPanGestureSetProperties(void);
 extern int UtcDaliPanGestureSetPropertiesAlreadyPanning(void);
 extern int UtcDaliPanGesturePropertyIndices(void);
 extern int UtcDaliPanGestureLayerConsumesTouch(void);
+extern int UtcDaliPanGestureNoTimeDiff(void);
 extern int UtcDaliPinchGestureConstructor(void);
 extern int UtcDaliPinchGestureAssignment(void);
 extern int UtcDaliPinchGestureDetectorConstructor(void);
@@ -939,6 +941,7 @@ extern int UtcDaliPropertyConditionGetArguments(void);
 extern int UtcDaliPropertyConditionGetArgumentsConst(void);
 extern int UtcDaliPropertyNotificationStep(void);
 extern int UtcDaliPropertyNotificationVariableStep(void);
+extern int UtcDaliPropertyNotificationOrder(void);
 extern int UtcDaliQuaternionCtor01(void);
 extern int UtcDaliQuaternionCtor02(void);
 extern int UtcDaliQuaternionCtor03(void);
@@ -1660,6 +1663,7 @@ testcase tc_array[] = {
     {"UtcDaliAnimationAnimateVector3Func", UtcDaliAnimationAnimateVector3Func, utc_dali_animation_startup, utc_dali_animation_cleanup},
     {"UtcDaliAnimationCreateDestroy", UtcDaliAnimationCreateDestroy, utc_dali_animation_startup, utc_dali_animation_cleanup},
     {"UtcDaliAnimationUpdateManager", UtcDaliAnimationUpdateManager, utc_dali_animation_startup, utc_dali_animation_cleanup},
+    {"UtcDaliAnimationSignalOrder", UtcDaliAnimationSignalOrder, utc_dali_animation_startup, utc_dali_animation_cleanup},
     {"UtcDaliAnyConstructors", UtcDaliAnyConstructors, utc_dali_any_startup, utc_dali_any_cleanup},
     {"UtcDaliAnyAssignmentOperators", UtcDaliAnyAssignmentOperators, utc_dali_any_startup, utc_dali_any_cleanup},
     {"UtcDaliAnyNegativeAssignmentOperators", UtcDaliAnyNegativeAssignmentOperators, utc_dali_any_startup, utc_dali_any_cleanup},
@@ -2117,6 +2121,7 @@ testcase tc_array[] = {
     {"UtcDaliPanGestureSetPropertiesAlreadyPanning", UtcDaliPanGestureSetPropertiesAlreadyPanning, utc_dali_pan_gesture_detector_startup, utc_dali_pan_gesture_detector_cleanup},
     {"UtcDaliPanGesturePropertyIndices", UtcDaliPanGesturePropertyIndices, utc_dali_pan_gesture_detector_startup, utc_dali_pan_gesture_detector_cleanup},
     {"UtcDaliPanGestureLayerConsumesTouch", UtcDaliPanGestureLayerConsumesTouch, utc_dali_pan_gesture_detector_startup, utc_dali_pan_gesture_detector_cleanup},
+    {"UtcDaliPanGestureNoTimeDiff", UtcDaliPanGestureNoTimeDiff, utc_dali_pan_gesture_detector_startup, utc_dali_pan_gesture_detector_cleanup},
     {"UtcDaliPinchGestureConstructor", UtcDaliPinchGestureConstructor, utc_dali_pinch_gesture_startup, utc_dali_pinch_gesture_cleanup},
     {"UtcDaliPinchGestureAssignment", UtcDaliPinchGestureAssignment, utc_dali_pinch_gesture_startup, utc_dali_pinch_gesture_cleanup},
     {"UtcDaliPinchGestureDetectorConstructor", UtcDaliPinchGestureDetectorConstructor, utc_dali_pinch_gesture_detector_startup, utc_dali_pinch_gesture_detector_cleanup},
@@ -2169,6 +2174,7 @@ testcase tc_array[] = {
     {"UtcDaliPropertyConditionGetArgumentsConst", UtcDaliPropertyConditionGetArgumentsConst, utc_dali_property_notification_startup, utc_dali_property_notification_cleanup},
     {"UtcDaliPropertyNotificationStep", UtcDaliPropertyNotificationStep, utc_dali_property_notification_startup, utc_dali_property_notification_cleanup},
     {"UtcDaliPropertyNotificationVariableStep", UtcDaliPropertyNotificationVariableStep, utc_dali_property_notification_startup, utc_dali_property_notification_cleanup},
+    {"UtcDaliPropertyNotificationOrder", UtcDaliPropertyNotificationOrder, utc_dali_property_notification_startup, utc_dali_property_notification_cleanup},
     {"UtcDaliQuaternionCtor01", UtcDaliQuaternionCtor01, utc_dali_quaternion_startup, utc_dali_quaternion_cleanup},
     {"UtcDaliQuaternionCtor02", UtcDaliQuaternionCtor02, utc_dali_quaternion_startup, utc_dali_quaternion_cleanup},
     {"UtcDaliQuaternionCtor03", UtcDaliQuaternionCtor03, utc_dali_quaternion_startup, utc_dali_quaternion_cleanup},
index 63f1203..943c187 100644 (file)
@@ -18,6 +18,7 @@
 #include <iostream>
 
 #include <stdlib.h>
+#include <cmath>
 #include <dali/dali.h>
 #include <dali/integration-api/events/touch-event-integ.h>
 #include <dali/integration-api/events/pan-gesture-event.h>
@@ -2184,3 +2185,39 @@ int UtcDaliPanGestureLayerConsumesTouch(void)
 
   END_TEST;
 }
+
+int UtcDaliPanGestureNoTimeDiff(void)
+{
+  TestApplication application;
+
+  Actor actor = Actor::New();
+  actor.SetSize(100.0f, 100.0f);
+  actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
+  Stage::GetCurrent().Add(actor);
+
+  // Add a pan detector
+  PanGestureDetector detector = PanGestureDetector::New();
+  detector.Attach( actor );
+  SignalData data;
+  GestureReceivedFunctor functor( data );
+  detector.DetectedSignal().Connect( &application, functor );
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  // Emit signals, should receive
+  application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
+  application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
+  application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
+  DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
+  DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
+  DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );
+  data.Reset();
+
+  data.Reset();
+
+  END_TEST;
+}
index 134212a..3385553 100644 (file)
@@ -397,11 +397,15 @@ void PanGestureProcessor::EmitPanSignal( Actor* actor,
 
     pan.screenDisplacement = panEvent.currentPosition - previousPos;
 
-    pan.velocity.x = pan.displacement.x / panEvent.timeDelta;
-    pan.velocity.y = pan.displacement.y / panEvent.timeDelta;
+    // Avoid dividing by 0
+    if ( panEvent.timeDelta > 0 )
+    {
+      pan.velocity.x = pan.displacement.x / panEvent.timeDelta;
+      pan.velocity.y = pan.displacement.y / panEvent.timeDelta;
 
-    pan.screenVelocity.x = pan.screenDisplacement.x / panEvent.timeDelta;
-    pan.screenVelocity.y = pan.screenDisplacement.y / panEvent.timeDelta;
+      pan.screenVelocity.x = pan.screenDisplacement.x / panEvent.timeDelta;
+      pan.screenVelocity.y = pan.screenDisplacement.y / panEvent.timeDelta;
+    }
 
     // When the gesture ends, we may incorrectly get a ZERO velocity (as we have lifted our finger without any movement)
     // so we should use the last recorded velocity instead in this scenario.