lib/fusuma/plugin/detectors/rotate_detector.rb in fusuma-2.4.1 vs lib/fusuma/plugin/detectors/rotate_detector.rb in fusuma-2.5.0
- old
+ new
@@ -1,77 +1,77 @@
# frozen_string_literal: true
-require_relative './detector'
+require_relative "./detector"
module Fusuma
module Plugin
module Detectors
class RotateDetector < Detector
- SOURCES = ['gesture'].freeze
- BUFFER_TYPE = 'gesture'
- GESTURE_RECORD_TYPE = 'pinch'
+ SOURCES = ["gesture"].freeze
+ BUFFER_TYPE = "gesture"
+ GESTURE_RECORD_TYPE = "pinch"
FINGERS = [2, 3, 4].freeze
BASE_THERESHOLD = 0.5
# @param buffers [Array<Buffer>]
# @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_from_last_begin
+ .select_by_events { |e| e.record.gesture == 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
+ 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?
finger = gesture_buffer.finger
status = case gesture_buffer.events.last.record.status
- when 'end'
- 'end'
- when 'update'
- if updating_events.length == 1
- 'begin'
- else
- 'update'
- end
- else
- gesture_buffer.events.last.record.status
- end
+ when "end"
+ "end"
+ when "update"
+ if updating_events.length == 1
+ "begin"
+ else
+ "update"
+ end
+ else
+ gesture_buffer.events.last.record.status
+ end
- delta = if status == 'end'
- gesture_buffer.events[-2].record.delta
- else
- gesture_buffer.events.last.record.delta
- end
+ delta = if status == "end"
+ gesture_buffer.events[-2].record.delta
+ else
+ gesture_buffer.events.last.record.delta
+ end
repeat_direction = Direction.new(angle: delta.rotate).to_s
repeat_quantity = Quantity.new(angle: delta.rotate).to_f
repeat_index = create_repeat_index(gesture: type, finger: finger,
- direction: repeat_direction,
- status: status)
+ direction: repeat_direction,
+ status: status)
- if status == 'update'
+ if status == "update"
return unless moved?(repeat_quantity)
oneshot_direction = Direction.new(angle: oneshot_angle).to_s
oneshot_quantity = Quantity.new(angle: oneshot_angle).to_f
oneshot_index = create_oneshot_index(gesture: type, finger: finger,
- direction: oneshot_direction)
+ direction: oneshot_direction)
if enough_oneshot_threshold?(index: oneshot_index, quantity: oneshot_quantity)
return [
create_event(record: Events::Records::IndexRecord.new(
index: oneshot_index, trigger: :oneshot, args: delta.to_h
)),
@@ -127,21 +127,21 @@
end
def threshold(index:)
@threshold ||= {}
@threshold[index.cache_key] ||= begin
- keys_specific = Config::Index.new [*index.keys, 'threshold']
- keys_global = Config::Index.new ['threshold', type]
- config_value = Config.search(keys_specific) ||
- Config.search(keys_global) || 1
+ keys_specific = Config::Index.new [*index.keys, "threshold"]
+ keys_global = Config::Index.new ["threshold", type]
+ config_value = Config.search(keys_specific) ||
+ Config.search(keys_global) || 1
BASE_THERESHOLD * config_value
end
end
# direction of gesture
class Direction
- CLOCKWISE = 'clockwise'
- COUNTERCLOCKWISE = 'counterclockwise'
+ CLOCKWISE = "clockwise"
+ COUNTERCLOCKWISE = "counterclockwise"
def initialize(angle:)
@angle = angle.to_f
end