lib/fusuma/plugin/detectors/swipe_detector.rb in fusuma-2.0.5 vs lib/fusuma/plugin/detectors/swipe_detector.rb in fusuma-2.1.0
- old
+ new
@@ -22,12 +22,20 @@
.select_by_events { |e| e.record.gesture == GESTURE_RECORD_TYPE }
updating_events = gesture_buffer.updating_events
return if updating_events.empty?
- updating_time = 100 * (updating_events.last.time - updating_events.first.time)
- oneshot_move_x = gesture_buffer.sum_attrs(:move_x) / updating_time
- oneshot_move_y = gesture_buffer.sum_attrs(:move_y) / updating_time
+ oneshot_move_x, oneshot_move_y = if updating_events.size >= 10
+ updating_time = 100 * (updating_events[-1].time - updating_events[-10].time)
+ last_10 = gesture_buffer.class.new(updating_events[-10..-1])
+ [last_10.sum_attrs(:move_x) / updating_time,
+ last_10.sum_attrs(:move_y) / updating_time]
+ else
+ updating_time = 100 * (updating_events.last.time - updating_events.first.time)
+ [gesture_buffer.sum_attrs(:move_x) / updating_time,
+ gesture_buffer.sum_attrs(:move_y) / updating_time]
+ end
+ gesture_buffer.sum_attrs(:move_x) / updating_time
finger = gesture_buffer.finger
status = case gesture_buffer.events.last.record.status
when 'end'
'end'