Module: AutoBrowse::MouseMover::MathUtils
- Included in:
- BrowserMouseMover, Vector
- Defined in:
- lib/auto_browse/mouse.rb
Instance Method Summary collapse
-
#clamp(target, min, max) ⇒ Object
returns target if min < target < max otherwise, returns min.
- #confine(target, min, max) ⇒ Object
-
#coordinate_floor0(coord) ⇒ Object
coord is a pair: [x, y] returns [identity_floor0(x), identity_floor0(y)].
-
#fitts(distance, width) ⇒ Object
Calculate the amount of time needed to move from (x1, y1) to (x2, y2) given the width of the element being clicked on en.wikipedia.org/wiki/Fitts%27s_law.
-
#identity_floor0(x) ⇒ Object
returns 0 if the supplied value is less than 0; otherwise returns the given value.
- #random_number_range(min, max) ⇒ Object
Instance Method Details
#clamp(target, min, max) ⇒ Object
returns target if min < target < max otherwise, returns min
13 14 15 |
# File 'lib/auto_browse/mouse.rb', line 13 def clamp(target, min, max) [max, [min, target].max].min end |
#confine(target, min, max) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/auto_browse/mouse.rb', line 17 def confine(target, min, max) case when target < min min when target > max max else target end end |
#coordinate_floor0(coord) ⇒ Object
coord is a pair: [x, y] returns [identity_floor0(x), identity_floor0(y)]
45 46 47 |
# File 'lib/auto_browse/mouse.rb', line 45 def coordinate_floor0(coord) coord.map {|val| identity_floor0(val) } end |
#fitts(distance, width) ⇒ Object
Calculate the amount of time needed to move from (x1, y1) to (x2, y2) given the width of the element being clicked on en.wikipedia.org/wiki/Fitts%27s_law
31 32 33 34 35 36 |
# File 'lib/auto_browse/mouse.rb', line 31 def fitts(distance, width) a = 0 b = 2 id = Math.log2(distance / width + 1) a + b * id end |
#identity_floor0(x) ⇒ Object
returns 0 if the supplied value is less than 0; otherwise returns the given value
39 40 41 |
# File 'lib/auto_browse/mouse.rb', line 39 def identity_floor0(x) x < 0 ? 0 : x end |
#random_number_range(min, max) ⇒ Object
7 8 9 |
# File 'lib/auto_browse/mouse.rb', line 7 def random_number_range(min, max) rand * (max - min) + min end |