From c89f1107041a4ac8a513e4e2e7c1c3da984b1c59 Mon Sep 17 00:00:00 2001 From: Julie Lala Date: Tue, 29 Apr 2014 03:47:32 -0400 Subject: dragging between walls --- assets/javascripts/rectangles/models/vec2.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'assets/javascripts/rectangles/models/vec2.js') 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 -- cgit v1.2.3-70-g09d2