Class: Fusuma::Plugin::Detectors::RotateDetector
- Defined in:
- lib/fusuma/plugin/detectors/rotate_detector.rb
Defined Under Namespace
Constant Summary collapse
- BUFFER_TYPE =
'gesture'- GESTURE_RECORD_TYPE =
'pinch'- FINGERS =
[2, 3, 4].freeze
- BASE_THERESHOLD =
0.5
- BASE_INTERVAL =
0.1
Instance Method Summary collapse
Methods inherited from Detector
#create_event, #last_time, #tag, #type
Methods inherited from Base
#config_index, #config_param_types, #config_params, inherited, plugins
Instance Method Details
#create_index(gesture:, finger:, direction:) ⇒ Config::Index
44 45 46 47 48 49 50 51 52 |
# File 'lib/fusuma/plugin/detectors/rotate_detector.rb', line 44 def create_index(gesture:, finger:, direction:) Config::Index.new( [ Config::Index::Key.new(gesture), Config::Index::Key.new(finger.to_i, skippable: true), Config::Index::Key.new(direction) ] ) end |
#detect(buffers) ⇒ Event, NilClass
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fusuma/plugin/detectors/rotate_detector.rb', line 19 def detect(buffers) buffer = buffers.find { |b| b.type == BUFFER_TYPE } .select_by_events { |e| e.record.gesture == GESTURE_RECORD_TYPE } return if buffer.empty? angle = buffer.avg_attrs(:rotate) finger = buffer.finger direction = Direction.new(angle: angle).to_s quantity = Quantity.new(angle: angle).to_f index = create_index(gesture: type, finger: finger, direction: direction) return unless enough?(index: index, quantity: quantity) create_event(record: Events::Records::IndexRecord.new(index: index)) end |