summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles/models
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-04-17 12:27:51 -0400
committerJules Laplace <jules@okfoc.us>2014-04-17 12:27:51 -0400
commitf6424c4756de2045648de0980de14a32b0126df7 (patch)
tree844b690dbe722dad6d8eb2869015abacb563a11b /assets/javascripts/rectangles/models
parent309574dec1852238ae899d719f5486f21949a064 (diff)
scale map
Diffstat (limited to 'assets/javascripts/rectangles/models')
-rw-r--r--assets/javascripts/rectangles/models/rect.js10
-rw-r--r--assets/javascripts/rectangles/models/vec2.js5
2 files changed, 15 insertions, 0 deletions
diff --git a/assets/javascripts/rectangles/models/rect.js b/assets/javascripts/rectangles/models/rect.js
index 548e16a..5623dc8 100644
--- a/assets/javascripts/rectangles/models/rect.js
+++ b/assets/javascripts/rectangles/models/rect.js
@@ -26,6 +26,16 @@ window.rect = (function(){
rect.prototype.area = function(){
return this.x.length() * this.y.length()
}
+
+ rect.prototype.mul = function(n){
+ this.x.mul(n)
+ this.y.mul(n)
+ }
+ rect.prototype.div = function(n){
+ this.x.div(n)
+ this.y.div(n)
+ }
+
rect.prototype.translate = function(translation){
var translation = translation || this.translation
this.x.abs().add(translation.a)
diff --git a/assets/javascripts/rectangles/models/vec2.js b/assets/javascripts/rectangles/models/vec2.js
index 4e2ad36..3105fec 100644
--- a/assets/javascripts/rectangles/models/vec2.js
+++ b/assets/javascripts/rectangles/models/vec2.js
@@ -28,23 +28,28 @@ vec2.prototype.eq = function(v){
vec2.prototype.add = function(n){
this.a += n
this.b += n
+ return this
}
vec2.prototype.sub = function(n){
this.a -= n
this.b -= n
+ return this
}
vec2.prototype.mul = function(n){
this.a *= n
this.b *= n
+ return this
}
vec2.prototype.div = function(n){
this.a /= n
this.b /= n
+ return this
}
vec2.normalize = function(){
var dim = max(this.a, this.b)
this.a = this.a/dim
this.b = this.b/dim
+ return this
}
vec2.prototype.contains = function(n){
return this.a <= n && n <= this.b