1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

avoid some edge cases

This commit is contained in:
Michael 2023-08-26 23:25:46 +02:00 committed by GitHub
parent a354a7f696
commit 6b71820197
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -134,10 +134,17 @@ void MapView::postSwipe(uint32_t msPassed) {
if(swipeHistory.size() > 1)
{
Point diff = Point(0, 0);
for (auto & x : swipeHistory)
diff += x.second;
std::pair<uint32_t, Point> firstAccepted;
uint32_t now = GH.input().getTicks();
for (auto & x : swipeHistory) {
if(now - x.first < 150) { // only the last 150 ms are catched
if(firstAccepted.first == 0)
firstAccepted = x;
diff += x.second;
}
}
uint32_t timediff = swipeHistory.rbegin()->first - swipeHistory.begin()->first;
uint32_t timediff = swipeHistory.rbegin()->first - firstAccepted.first;
postSwipeAngle = diff.angle();
postSwipeSpeed = static_cast<double>(diff.length()) / static_cast<double>(timediff); // unit: pixel/millisecond