Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove unneeded sqrt() calculation

The #close_enough method does not need to find
the true distance between points since we want
to be within 1 unit of distance. The trick is to
realize that square roots will always approach 1 no
matter which side of the number line they are on.

Mouse animations will be closer in timings now than
previously.
  • Loading branch information...
commit 377d1830246e530e09f5eceaa0f00976ec6b57ab 1 parent 2e21f66
@ferrous26 ferrous26 authored
Showing with 1 addition and 2 deletions.
  1. +1 −2  lib/mouse.rb
View
3  lib/mouse.rb
@@ -199,8 +199,7 @@ def animate type, button, from, to, duration
def close_enough? current, target
x = current.x - target.x
y = current.y - target.y
- delta = Math.sqrt((x**2) + (y**2))
- delta <= 1.0
+ ((x**2)+(y**2)) <= 1
end
def new_event event, position, button

0 comments on commit 377d183

Please sign in to comment.
Something went wrong with that request. Please try again.