summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles/rect.js
diff options
context:
space:
mode:
authorJulie Lala <jules@okfoc.us>2014-04-17 02:32:53 -0400
committerJulie Lala <jules@okfoc.us>2014-04-17 02:32:53 -0400
commit1af8f41cc88e3c57bfabe6d4a5dcd83fc4a0e1bc (patch)
treee10fd06cd40c21a7375f626ac130b438613b8abe /assets/javascripts/rectangles/rect.js
parent3b7c327b6502ef6e510a0a0e77c6b6facf0be723 (diff)
further code bath, fix minimap orientation/translation
Diffstat (limited to 'assets/javascripts/rectangles/rect.js')
-rw-r--r--assets/javascripts/rectangles/rect.js130
1 files changed, 0 insertions, 130 deletions
diff --git a/assets/javascripts/rectangles/rect.js b/assets/javascripts/rectangles/rect.js
deleted file mode 100644
index 50debbc..0000000
--- a/assets/javascripts/rectangles/rect.js
+++ /dev/null
@@ -1,130 +0,0 @@
-var FRONT = 0x1, BACK = 0x2, LEFT = 0x4, RIGHT = 0x8
-
-window.rect = (function(){
- var rect = function (x0,y0,x1,y1){
- if (x0 instanceof vec2) {
- this.x = x0
- this.y = y0
- }
- else if (x1 === undefined) {
- this.x = new vec2(x0,x0)
- this.y = new vec2(y0,y0)
- }
- else {
- this.x = new vec2(x0,x1)
- this.y = new vec2(y0,y1)
- }
- 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.center = function(){
- return new vec2(this.x.midpoint(), this.y.midpoint())
- }
- rect.prototype.area = function(){
- return this.x.length() * this.y.length()
- }
- rect.prototype.translate = function(){
- this.x.abs().add(this.translation.a)
- this.y.abs().add(this.translation.b)
- this.translation.a = this.translation.b = 0
- return this
- }
- rect.prototype.contains = function(x,y){
- return this.x.contains(x) && this.y.contains(y)
- }
- 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(){
- var sides = ""
- if (this.sides & FRONT) sides += "front "
- if (this.sides & BACK) sides += "back "
- if (this.sides & LEFT) sides += "left "
- if (this.sides & RIGHT) sides += "right "
- var s = "[" + this.x.toString() + " " + this.y.toString() + "] " + sides
- return s
- }
- rect.prototype.quantize = function(n){
- this.x.quantize(n)
- this.y.quantize(n)
- }
- rect.prototype.split = function(r){
- var rz = this
- var splits = []
- var split_contains = 0
- var x_intervals = [], y_intervals = []
- var sides = this.sides
-
- // Split vertically
- if (this.x.contains(r.x.a) && r.x.contains(this.x.b)) {
- x_intervals.push([ new vec2( this.x.a, r.x.a ), LEFT ])
- x_intervals.push([ new vec2( r.x.a, this.x.b ), RIGHT ])
- split_contains |= RIGHT
- }
-
- else if (r.x.contains(this.x.a) && this.x.contains(r.x.b)) {
- x_intervals.push([ new vec2( this.x.a, r.x.b ), LEFT ])
- x_intervals.push([ new vec2( r.x.b, this.x.b ), RIGHT ])
- split_contains |= LEFT
- }
-
- else if (this.x.contains(r.x.a) && this.x.contains(r.x.b)) {
- x_intervals.push([ new vec2( this.x.a, r.x.a ), LEFT ])
- x_intervals.push([ new vec2( r.x.a, r.x.b ), 0 ])
- x_intervals.push([ new vec2( r.x.b, this.x.b ), RIGHT ])
- split_contains |= LEFT | RIGHT
- }
-
- else { // if (r.x.contains(this.x.a) && r.x.contains(r.x.b)) {
- x_intervals.push([ new vec2( this.x.a, this.x.b ), LEFT | RIGHT ])
- split_contains |= LEFT | RIGHT
- }
-
- // Split horizontally
- if (this.y.contains(r.y.a) && r.y.contains(this.y.b)) {
- y_intervals.push([ new vec2( this.y.a, r.y.a ), FRONT ])
- y_intervals.push([ new vec2( r.y.a, this.y.b ), BACK ])
- split_contains |= BACK
- }
-
- else if (r.y.contains(this.y.a) && this.y.contains(r.y.b)) {
- y_intervals.push([ new vec2( this.y.a, r.y.b ), FRONT ])
- y_intervals.push([ new vec2( r.y.b, this.y.b ), BACK ])
- split_contains |= FRONT
- }
-
- else if (this.y.contains(r.y.a) && this.y.contains(r.y.b)) {
- y_intervals.push([ new vec2( this.y.a, r.y.a ), FRONT ])
- y_intervals.push([ new vec2( r.y.a, r.y.b ), 0 ])
- y_intervals.push([ new vec2( r.y.b, this.y.b ), BACK ])
- split_contains |= FRONT | BACK
- }
-
- else { // if (r.y.contains(this.y.a) && this.y.contains(r.y.b)) {
- y_intervals.push([ new vec2( this.y.a, this.y.b ), FRONT | BACK ])
- split_contains |= FRONT | BACK
- }
-
- x_intervals.forEach(function(x){
- y_intervals.forEach(function(y){
- var rn = new rect(x[0], y[0])
- rn.id = rz.id
- rn.sides = ((x[1] | y[1]) & sides)
- if (r.intersects(rn)) {
- rn.sides = 0
- }
- rn.focused = rz.focused
- splits.push(rn)
- })
- })
- return splits
- }
-
- return rect
-
-})()