summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/models/rect.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/rectangles/models/rect.js')
-rw-r--r--public/assets/javascripts/rectangles/models/rect.js40
1 files changed, 39 insertions, 1 deletions
diff --git a/public/assets/javascripts/rectangles/models/rect.js b/public/assets/javascripts/rectangles/models/rect.js
index 315adef..f91e759 100644
--- a/public/assets/javascripts/rectangles/models/rect.js
+++ b/public/assets/javascripts/rectangles/models/rect.js
@@ -1,5 +1,25 @@
(function(){
+ var vec2
+ if ('window' in this) {
+ vec2 = window.vec2
+ }
+ else {
+ vec2 = require('./vec2')
+ FRONT = 0x1, BACK = 0x2, LEFT = 0x4, RIGHT = 0x8, FLOOR = 0x10, CEILING = 0x20
+ TOP = CEILING, BOTTOM = FLOOR
+ function sidesToString(sides){
+ var s = ""
+ if (sides & FRONT) s += "front "
+ if (sides & BACK) s += "back "
+ if (sides & LEFT) s += "left "
+ if (sides & RIGHT) s += "right "
+ if (sides & TOP) s += "top "
+ if (sides & BOTTOM) s += "bottom "
+ return s
+ }
+ }
+
var Rect = function (x0,y0,x1,y1){
if (x0 instanceof vec2) {
this.x = x0
@@ -77,6 +97,12 @@
Rect.prototype.intersects = function(r){
return this.x.intersects(r.x) && this.y.intersects(r.y)
}
+ Rect.prototype.adjacent = function(r){
+ return this.x.adjacent(r.x) && this.y.adjacent(r.y)
+ }
+ Rect.prototype.eq = function(r){
+ return this.x.eq(r.x) && this.y.eq(r.y)
+ }
Rect.prototype.nearEdge = function (x, y, r) {
var edges = 0
if (x < this.x.a+r) {
@@ -173,6 +199,18 @@
if (r.intersects(rn)) {
rn.sides = 0
}
+ // if (r.x.b == rn.x.a) {
+// rn.sides &= ~LEFT
+// }
+// if (rn.x.b == r.x.a) {
+// rn.sides &= ~RIGHT
+// }
+// if (r.y.b == rn.y.a) {
+// rn.sides &= ~FRONT
+// }
+// if (rn.y.b == r.y.a) {
+// rn.sides &= ~BACK
+// }
rn.focused = rz.focused
splits.push(rn)
})
@@ -183,7 +221,7 @@
if ('window' in this) {
window.Rect = Rect
}
- else if ('module' in this) {
+ else {
module.exports = Rect
}