summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/models/rect.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-10-08 13:26:08 -0400
committerJules Laplace <jules@okfoc.us>2014-10-08 13:26:08 -0400
commit6f4cd32fa13efe3b0e8b26183589f66889dd3738 (patch)
treedf5ceeb82a40c247ec0dc508b5672289b483a5b4 /public/assets/javascripts/rectangles/models/rect.js
parent1f66850f5ec5a2e664ee8eaafbe25c46dad34102 (diff)
render thumbnails as masks
Diffstat (limited to 'public/assets/javascripts/rectangles/models/rect.js')
-rw-r--r--public/assets/javascripts/rectangles/models/rect.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/public/assets/javascripts/rectangles/models/rect.js b/public/assets/javascripts/rectangles/models/rect.js
index a08176a..00f2c55 100644
--- a/public/assets/javascripts/rectangles/models/rect.js
+++ b/public/assets/javascripts/rectangles/models/rect.js
@@ -141,6 +141,29 @@
Rect.prototype.width = function(){ return this.x.length() }
Rect.prototype.height = function(){ return this.y.length() }
Rect.prototype.delta = function(){ return new vec2( this.x.magnitude(), this.y.magnitude() ) }
+ Rect.prototype.expand = function(rect){
+ this.x.a = Math.min( this.x.a, rect.x.a )
+ this.x.b = Math.max( this.x.b, rect.x.b )
+ this.y.a = Math.min( this.y.a, rect.y.a )
+ this.y.b = Math.max( this.y.b, rect.y.b )
+ return this
+ }
+ Rect.prototype.square = function(){
+ var width = this.x.length()
+ var height = this.y.length()
+ var diff
+ if (width < height) {
+ diff = (height - width) / 2
+ this.x.a -= diff
+ this.x.b += diff
+ }
+ else {
+ diff = (width - height) / 2
+ this.y.a -= diff
+ this.y.b += diff
+ }
+ return this
+ }
Rect.prototype.toString = function(){
var sides = sidesToString(this.sides)
var s = "[" + this.x.toString() + " " + this.y.toString() + "] " + sides