summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles/models/vec2.js
diff options
context:
space:
mode:
authorJulie Lala <jules@okfoc.us>2014-04-29 03:47:32 -0400
committerJulie Lala <jules@okfoc.us>2014-04-29 03:47:32 -0400
commitc89f1107041a4ac8a513e4e2e7c1c3da984b1c59 (patch)
treebbf94e2d7239193d8339e243d2489bb945cd2baf /assets/javascripts/rectangles/models/vec2.js
parentaca59762480289d1cded7ebb53004b415d8d68ca (diff)
dragging between walls
Diffstat (limited to 'assets/javascripts/rectangles/models/vec2.js')
-rw-r--r--assets/javascripts/rectangles/models/vec2.js14
1 files changed, 9 insertions, 5 deletions
diff --git a/assets/javascripts/rectangles/models/vec2.js b/assets/javascripts/rectangles/models/vec2.js
index 7307fca..9b0447c 100644
--- a/assets/javascripts/rectangles/models/vec2.js
+++ b/assets/javascripts/rectangles/models/vec2.js
@@ -13,12 +13,16 @@ vec2.prototype.clone = function(){
}
vec2.prototype.abs = function(){
if (this.b < this.a) {
- this.a = this.a ^ this.b
- this.b = this.a ^ this.b
- this.a = this.a ^ this.b
+ this.invert()
}
return this
}
+vec2.prototype.invert = function(){
+ this.a = this.a ^ this.b
+ this.b = this.a ^ this.b
+ this.a = this.a ^ this.b
+ return this
+}
vec2.prototype.midpoint = function(){
return lerp(0.5, this.a, this.b)
}
@@ -45,7 +49,7 @@ vec2.prototype.div = function(n){
this.b /= n
return this
}
-vec2.normalize = function(){
+vec2.prototype.normalize = function(){
var dim = max(this.a, this.b)
this.a = this.a/dim
this.b = this.b/dim
@@ -85,7 +89,7 @@ vec2.prototype.intersection = function(v){
}
}
vec2.prototype.toString = function(){
- return "[" + this.a + " " + this.b + "]"
+ return "[" + ~~this.a + " " + ~~this.b + "]"
}
vec2.prototype.quantize = function(n){
n = n || 10