瀏覽代碼

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);
 
-}
+}