summaryrefslogtreecommitdiff
path: root/public/js/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js/util.js')
-rw-r--r--public/js/util.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/public/js/util.js b/public/js/util.js
index e51b844..dbb37a7 100644
--- a/public/js/util.js
+++ b/public/js/util.js
@@ -11,3 +11,23 @@ function scrollToBottom (el) {
try { $(el).scrollTop( $(el)[0].scrollHeight ) }
catch (err) { }
}
+var Trig = {
+ distanceBetween2Points: function ( point1, point2 ) {
+ var dx = point2.x - point1.x;
+ var dy = point2.y - point1.y;
+ return Math.sqrt( Math.pow( dx, 2 ) + Math.pow( dy, 2 ) );
+ },
+ angleBetween2Points: function ( point1, point2 ) {
+ var dx = point2.x - point1.x;
+ var dy = point2.y - point1.y;
+ return Math.atan2( dx, dy );
+ },
+ magnitude: function (point) {
+ return Math.sqrt( Math.pow( point.x, 2 ) + Math.pow( point.y, 2 ) );
+ }
+}
+
+function fib (f) { for (var i = 1, n = 1; n < 200; i++, n += i) f(n); }
+function rand(x) { return Math.random() * x; }
+function randInt(x) { return Math.floor(Math.random() * x); }
+function clamp(x,a,b) { return Math.min(Math.max(x,a),b); }