Class: Rabbit::Gesture::Processor
- Inherits:
-
Object
- Object
- Rabbit::Gesture::Processor
- Defined in:
- lib/rabbit/gesture/processor.rb
Constant Summary collapse
- DEFAULT_THRESHOLD =
48
- DEFAULT_SKEW_THRESHOLD_ANGLE =
90 / 4
- MOTIONS =
%w(L R U D UL UR LL LR)
Instance Attribute Summary collapse
-
#motions ⇒ Object
readonly
Returns the value of attribute motions.
-
#skew_threshold_angle ⇒ Object
Returns the value of attribute skew_threshold_angle.
-
#threshold ⇒ Object
Returns the value of attribute threshold.
Instance Method Summary collapse
- #available_motion?(motion) ⇒ Boolean
-
#initialize(threshold = nil, skew_threshold_angle = nil) ⇒ Processor
constructor
A new instance of Processor.
- #position ⇒ Object
- #reset ⇒ Object
- #start(x, y) ⇒ Object
- #started? ⇒ Boolean
- #to_a ⇒ Object
- #update_position(x, y) ⇒ Object
Constructor Details
#initialize(threshold = nil, skew_threshold_angle = nil) ⇒ Processor
Returns a new instance of Processor.
10 11 12 13 14 15 |
# File 'lib/rabbit/gesture/processor.rb', line 10 def initialize(threshold=nil, skew_threshold_angle=nil) @threshold = threshold || DEFAULT_THRESHOLD @skew_threshold_angle = skew_threshold_angle @skew_threshold_angle ||= DEFAULT_SKEW_THRESHOLD_ANGLE reset end |
Instance Attribute Details
#motions ⇒ Object (readonly)
Returns the value of attribute motions.
8 9 10 |
# File 'lib/rabbit/gesture/processor.rb', line 8 def motions @motions end |
#skew_threshold_angle ⇒ Object
Returns the value of attribute skew_threshold_angle.
7 8 9 |
# File 'lib/rabbit/gesture/processor.rb', line 7 def skew_threshold_angle @skew_threshold_angle end |
#threshold ⇒ Object
Returns the value of attribute threshold.
7 8 9 |
# File 'lib/rabbit/gesture/processor.rb', line 7 def threshold @threshold end |
Instance Method Details
#available_motion?(motion) ⇒ Boolean
23 24 25 |
# File 'lib/rabbit/gesture/processor.rb', line 23 def available_motion?(motion) MOTIONS.include?(motion) end |
#position ⇒ Object
63 64 65 |
# File 'lib/rabbit/gesture/processor.rb', line 63 def position [@x, @y] end |
#reset ⇒ Object
53 54 55 56 57 |
# File 'lib/rabbit/gesture/processor.rb', line 53 def reset @started = false @x = @y = -1 @motions = [] end |
#start(x, y) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/rabbit/gesture/processor.rb', line 27 def start(x, y) @prev_x = @x = x @prev_y = @y = y @started = true @motions = [] end |
#started? ⇒ Boolean
17 18 19 |
# File 'lib/rabbit/gesture/processor.rb', line 17 def started? @started end |
#to_a ⇒ Object
59 60 61 |
# File 'lib/rabbit/gesture/processor.rb', line 59 def to_a @motions end |
#update_position(x, y) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rabbit/gesture/processor.rb', line 34 def update_position(x, y) mx = x - @prev_x my = y - @prev_y motion = judge_motion(mx, my) if motion @prev_x = @x = x @prev_y = @y = y if @motions.last == motion false else @motions << motion true end else false end end |