fusuma 0.1.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fusuma/action_stack.rb +31 -31
- data/lib/fusuma/gesture_action.rb +1 -1
- data/lib/fusuma/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85a522e75bfcc182572f9c38a4d073c67f963319
|
4
|
+
data.tar.gz: 6679c88a779acbf8c7183d42609326eb988f9cdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 412eec95e91666f2839d9157d0d4a5dd1073b34b4b514e35c71ac0c69301bef3e52185d3020721543d46f701a5e4c0d71241cae0efc73dd56f66290707c2d83d
|
7
|
+
data.tar.gz: 018d4103d87ffd686e586fdb8c806cdc96ddfd93046df3663c35f3eb5e4043c06053e83b299732c753e4a3582e1a5e617625bc9706b2b6f91119e9cc85b15b2c
|
data/lib/fusuma/action_stack.rb
CHANGED
@@ -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
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
return
|
51
|
-
|
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 =
|
53
|
+
diameter = avg_attrs(:zoom)
|
54
|
+
MultiLogger.debug(diameter: diameter)
|
60
55
|
# TODO: change threshold from config files
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
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
|
79
|
-
|
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
|
89
|
-
|
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('
|
44
|
+
finger_directions_line.tr('/|(|)', ' ').split
|
45
45
|
[finger_num, move_x, move_y, zoom]
|
46
46
|
end
|
47
47
|
end
|
data/lib/fusuma/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2016-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|