fusuma 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3978122d47e2294dd5d8391e76a0507c1e21b8de
4
- data.tar.gz: aa5df2c6707a715577a43e43e4a5ea7e9482a084
3
+ metadata.gz: 85a522e75bfcc182572f9c38a4d073c67f963319
4
+ data.tar.gz: 6679c88a779acbf8c7183d42609326eb988f9cdb
5
5
  SHA512:
6
- metadata.gz: 124a58da4e05ae6f4cf9881a0678942eb639728e326651106a4bc6938b1397a7db36bb50efa7fbca8d99e92fe513449291ba03ee5fa906b4e0b87df06e6134ad
7
- data.tar.gz: 44cec21490f90665063ebbd3c7567dd595ade069efc583076ffb8842b42bcd9304b55c544f072c4a3be75a1ab6398179eb6bae247574e867d215d02743d2160c
6
+ metadata.gz: 412eec95e91666f2839d9157d0d4a5dd1073b34b4b514e35c71ac0c69301bef3e52185d3020721543d46f701a5e4c0d71241cae0efc73dd56f66290707c2d83d
7
+ data.tar.gz: 018d4103d87ffd686e586fdb8c806cdc96ddfd93046df3663c35f3eb5e4043c06053e83b299732c753e4a3582e1a5e617625bc9706b2b6f91119e9cc85b15b2c
@@ -14,8 +14,6 @@ module Fusuma
14
14
  @last_triggered_time = last.time
15
15
  finger = detect_finger
16
16
  clear
17
- MultiLogger.debug(finger: finger, direction: direction,
18
- action_type: action_type)
19
17
  GestureInfo.new(finger, direction, action_type)
20
18
  end
21
19
 
@@ -30,7 +28,7 @@ module Fusuma
30
28
  GestureInfo = Struct.new(:finger, :direction, :action_type)
31
29
 
32
30
  def elapsed_time
33
- return 0 if length == 0
31
+ return 0 if length.zero?
34
32
  last.time - first.time
35
33
  end
36
34
 
@@ -44,39 +42,32 @@ module Fusuma
44
42
  end
45
43
 
46
44
  def detect_move
47
- moves = sum_moves
48
- return nil if moves[:x].zero? && moves[:y].zero?
49
- # MultiLogger.debug(moves: moves)
50
- return nil if (moves[:x].abs < 200) && (moves[:y].abs < 200)
51
- if moves[:x].abs > moves[:y].abs
52
- return moves[:x] > 0 ? 'right' : 'left'
53
- else
54
- moves[:y] > 0 ? 'down' : 'up'
55
- end
45
+ move = avg_moves
46
+ MultiLogger.debug(move: move)
47
+ return unless enough_distance?(move)
48
+ return move[:x] > 0 ? 'right' : 'left' if move[:x].abs > move[:y].abs
49
+ move[:y] > 0 ? 'down' : 'up'
56
50
  end
57
51
 
58
52
  def detect_zoom
59
- diameter = mul_diameter
53
+ diameter = avg_attrs(:zoom)
54
+ MultiLogger.debug(diameter: diameter)
60
55
  # TODO: change threshold from config files
61
- if diameter > 10
62
- 'in'
63
- elsif diameter < 0.1
64
- 'out'
65
- end
56
+ return unless enough_diameter?(diameter)
57
+ return 'in' if diameter > 1
58
+ 'out'
66
59
  end
67
60
 
68
61
  def detect_finger
69
62
  last.finger
70
63
  end
71
64
 
72
- def sum_moves
73
- move_x = sum_attrs(:move_x)
74
- move_y = sum_attrs(:move_y)
75
- { x: move_x, y: move_y }
76
- end
65
+ Distance = Struct.new(:x, :y)
77
66
 
78
- def mul_diameter
79
- mul_attrs(:zoom)
67
+ def avg_moves
68
+ move_x = sum_attrs(:move_x) / length
69
+ move_y = sum_attrs(:move_y) / length
70
+ Distance.new(move_x, move_y)
80
71
  end
81
72
 
82
73
  def sum_attrs(attr)
@@ -85,12 +76,8 @@ module Fusuma
85
76
  end.compact.inject(:+)
86
77
  end
87
78
 
88
- def mul_attrs(attr)
89
- send('map') do |gesture_action|
90
- num = gesture_action.send(attr.to_sym.to_s)
91
- # NOTE: ignore 0.0, treat as 1(immutable)
92
- num.zero? ? 1 : num
93
- end.compact.inject(:*)
79
+ def avg_attrs(attr)
80
+ sum_attrs(attr) / length
94
81
  end
95
82
 
96
83
  def action_end?
@@ -102,6 +89,19 @@ module Fusuma
102
89
  last.action
103
90
  end
104
91
 
92
+ def enough_distance?(move)
93
+ (move[:x].abs > 20) || (move[:y].abs > 20)
94
+ end
95
+
96
+ def enough_diameter?(avg_diameter)
97
+ delta_diameter = if avg_diameter > 1
98
+ avg_diameter - first.zoom
99
+ else
100
+ first.zoom - avg_diameter
101
+ end
102
+ delta_diameter > 0.3
103
+ end
104
+
105
105
  def enough_actions?
106
106
  (length > 1) && (elapsed_time > 0.1)
107
107
  end
@@ -41,7 +41,7 @@ module Fusuma
41
41
 
42
42
  def parse_finger_directions(finger_directions_line)
43
43
  finger_num, move_x, move_y, _, _, _, zoom =
44
- finger_directions_line.tr('/', ' ').split
44
+ finger_directions_line.tr('/|(|)', ' ').split
45
45
  [finger_num, move_x, move_y, zoom]
46
46
  end
47
47
  end
@@ -1,3 +1,3 @@
1
1
  module Fusuma
2
- VERSION = '0.1.9'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fusuma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - iberianpig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-17 00:00:00.000000000 Z
11
+ date: 2016-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler