diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-04-25 16:08:48 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-04-25 16:08:48 -0400 |
| commit | 1b06bfa4b67747229c3283a9466047b1daece035 (patch) | |
| tree | cd889dd15463324be0c03aaa96bca6eeaf89052e /assets/javascripts/rectangles/models/rect.js | |
| parent | 0772bb5e55d0d00c925620a27b59a7f52aaa4199 (diff) | |
improve names
Diffstat (limited to 'assets/javascripts/rectangles/models/rect.js')
| -rw-r--r-- | assets/javascripts/rectangles/models/rect.js | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/assets/javascripts/rectangles/models/rect.js b/assets/javascripts/rectangles/models/rect.js index 0664693..2d48e13 100644 --- a/assets/javascripts/rectangles/models/rect.js +++ b/assets/javascripts/rectangles/models/rect.js @@ -10,8 +10,8 @@ function sidesToString(sides){ return s } -window.rect = (function(){ - var rect = function (x0,y0,x1,y1){ +window.Rect = (function(){ + var Rect = function (x0,y0,x1,y1){ if (x0 instanceof vec2) { this.x = x0 this.y = y0 @@ -27,56 +27,56 @@ window.rect = (function(){ this.translation = new vec2(0,0) this.sides = FRONT | BACK | LEFT | RIGHT } - rect.prototype.clone = function(){ - return new rect( this.x.clone(), this.y.clone() ) + Rect.prototype.clone = function(){ + return new Rect( this.x.clone(), this.y.clone() ) } - rect.prototype.center = function(){ + Rect.prototype.center = function(){ return new vec2(this.x.midpoint(), this.y.midpoint()) } - rect.prototype.area = function(){ + Rect.prototype.area = function(){ return this.x.length() * this.y.length() } - rect.prototype.mul = function(n){ + Rect.prototype.mul = function(n){ this.x.mul(n) this.y.mul(n) return this } - rect.prototype.div = function(n){ + Rect.prototype.div = function(n){ this.x.div(n) this.y.div(n) return this } - rect.prototype.translate = function(translation){ + Rect.prototype.translate = function(translation){ var translation = translation || this.translation this.x.abs().add(translation.a) this.y.abs().add(translation.b) this.translation.a = this.translation.b = 0 return this } - rect.prototype.contains = function(x,y){ + Rect.prototype.contains = function(x,y){ return this.x.contains(x) && this.y.contains(y) } - rect.prototype.containsDisc = function(x,y,r){ + Rect.prototype.containsDisc = function(x,y,r){ return this.x.containsDisc(x,r) && this.y.containsDisc(y,r) } - rect.prototype.intersects = function(r){ + Rect.prototype.intersects = function(r){ return this.x.intersects(r.x) && this.y.intersects(r.y) } - rect.prototype.width = function(){ return this.x.length() } - rect.prototype.height = function(){ return this.y.length() } - rect.prototype.toString = function(){ + Rect.prototype.width = function(){ return this.x.length() } + Rect.prototype.height = function(){ return this.y.length() } + Rect.prototype.toString = function(){ var sides = sidesToString(this.sides) var s = "[" + this.x.toString() + " " + this.y.toString() + "] " + sides return s } - rect.prototype.quantize = function(n){ + Rect.prototype.quantize = function(n){ this.x.quantize(n) this.y.quantize(n) return this } - rect.prototype.split = function(r){ + Rect.prototype.split = function(r){ var rz = this var splits = [] var split_contains = 0 @@ -135,7 +135,7 @@ window.rect = (function(){ x_intervals.forEach(function(x){ y_intervals.forEach(function(y){ - var rn = new rect(x[0], y[0]) + var rn = new Rect(x[0], y[0]) rn.id = rz.id rn.sides = ((x[1] | y[1]) & sides) if (r.intersects(rn)) { @@ -148,6 +148,6 @@ window.rect = (function(){ return splits } - return rect + return Rect })() |
