فهرست منبع

fix division by zero edge case

Michael 2 سال پیش
والد
کامیت
4137a66f2a
1فایلهای تغییر یافته به همراه6 افزوده شده و 3 حذف شده
  1. 6 3
      client/mapView/MapView.cpp

+ 6 - 3
client/mapView/MapView.cpp

@@ -148,8 +148,11 @@ void MapView::postSwipe(uint32_t msPassed) {
 
 			uint32_t timediff = swipeHistory.rbegin()->first - firstAccepted.first;
 
-			postSwipeAngle = diff.angle();
-			postSwipeSpeed = static_cast<double>(diff.length()) / static_cast<double>(timediff); // unit: pixel/millisecond			
+			if(diff.length() > 0 && timediff > 0)
+			{
+				postSwipeAngle = diff.angle();
+				postSwipeSpeed = static_cast<double>(diff.length()) / static_cast<double>(timediff); // unit: pixel/millisecond
+			}	
 		}
 		swipeHistory.clear();
 	} else
@@ -205,4 +208,4 @@ PuzzleMapView::PuzzleMapView(const Point & offset, const Point & dimensions, con
 	controller->activatePuzzleMapContext(tileToCenter);
 	controller->setViewCenter(tileToCenter);
 
-}
+}