38 auto it = m_history.begin();
39 for (; it != m_history.end(); ++it) {
40 if (event->timestamp() - it->timestamp < m_interval) {
44 if (it != m_history.begin()) {
45 m_history.erase(m_history.begin(), it);
48 m_history.emplace_back(HistoryItem{
49 .position =
event->localPos(),
50 .timestamp = event->timestamp(),
53 qreal left = m_history[0].position.x();
54 qreal top = m_history[0].position.y();
55 qreal right = m_history[0].position.x();
56 qreal bottom = m_history[0].position.y();
59 for (
size_t i = 1; i < m_history.size(); ++i) {
61 const qreal deltaX = m_history.at(i).position.x() - m_history.at(i - 1).position.x();
62 const qreal deltaY = m_history.at(i).position.y() - m_history.at(i - 1).position.y();
63 distance += std::sqrt(deltaX * deltaX + deltaY * deltaY);
66 left = std::min(left, m_history.at(i).position.x());
67 top = std::min(top, m_history.at(i).position.y());
68 right = std::max(right, m_history.at(i).position.x());
69 bottom = std::max(bottom, m_history.at(i).position.y());
72 const qreal boundsWidth = right - left;
73 const qreal boundsHeight = bottom - top;
74 const qreal diagonal = std::sqrt(boundsWidth * boundsWidth + boundsHeight * boundsHeight);
79 const qreal shakeFactor = distance / diagonal;
80 if (shakeFactor > m_sensitivity) {
81 return shakeFactor - m_sensitivity;