summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles/models/vec2.js
diff options
context:
space:
mode:
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