lib/fusuma/plugin/detectors/rotate_detector.rb in fusuma-2.5.1 vs lib/fusuma/plugin/detectors/rotate_detector.rb in fusuma-3.0.0
- old
+ new
@@ -17,24 +17,17 @@
# @return [Events::Event] if event is detected
# @return [NilClass] if event is NOT detected
def detect(buffers)
gesture_buffer = buffers.find { |b| b.type == BUFFER_TYPE }
.select_from_last_begin
- .select_by_events { |e| e.record.gesture == GESTURE_RECORD_TYPE }
+ .select_by_type(GESTURE_RECORD_TYPE)
updating_events = gesture_buffer.updating_events
return if updating_events.empty?
- oneshot_angle = 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(:rotate) / updating_time
- else
- updating_time = 100 * (updating_events.last.time - updating_events.first.time)
- gesture_buffer.sum_attrs(:rotate) / updating_time
- end
-
- return if updating_events.empty?
+ updating_time = 100 * (updating_events[-1].time -
+ (updating_events[-10] || updating_events.first).time)
+ oneshot_angle = gesture_buffer.sum_last10_attrs(:rotate) / updating_time
finger = gesture_buffer.finger
status = case gesture_buffer.events.last.record.status
when "end"