import createVector from 'vector';

export default function createRect({
	x,
	y,
	width,
	height
}) {
	return {
		get x() {
			return x;
		},
		get y() {
			return y;
		},
		get width() {
			return width;
		},
		get height() {
			return height;
		},
		get topLeft() {
			return createVector({x:x, y:y});
		},
		get topRight() {
			return createVector({x:x + width, y:y});
		},
		get bottomLeft() {
			return createVector({x:x, y:y + height});
		},
		get bottomRight() {
			return createVector({x:x + width, y:y + height});
		},
		get center(){
			return createVector({x: x + width/2, y: y + height/2});
		},
		contains({x,y}){
			return x >= this.bottomLeft.x
				&& y <= this.bottomLeft.y
				&& x >= this.topLeft.x
				&& y > this.topLeft.y
				&& x < this.topRight.x
				&& y > this.topRight.y
				&& x < this.bottomRight.x
				&& y < this.bottomRight.y;
		},
		intersect(rect) {
			return this.contains(rect.topRight)
					|| this.contains(rect.bottomRight)
					|| this.contains(rect.bottomLeft)
					|| this.contains(rect.topLeft);
		}
	};
}

@@ -69,33 +69,29 @@
 ct(%7B
-%0A%09x,%0A%09y,%0A%09
+x, y%7D, %7B
 width,
-%0A%09
+ 
 height
-%0A
 %7D) %7B
@@ -235,24 +235,84 @@
 eight;%0A%09%09%7D,%0A
+%09%09get size() %7B%0A%09%09%09return %7B%0A%09%09%09%09width,%0A%09%09%09%09height%0A%09%09%09%7D;%0A%09%09%7D,%0A
 %09%09get topLef
@@ -341,24 +341,39 @@
 Vector(%7B
+%0A%09%09%09%09
 x:
+ 
 x,
- y:y
+%0A%09%09%09%09y: y%0A%09%09%09
 %7D);%0A%09%09%7D,
@@ -408,34 +408,40 @@
 n createVector(%7B
+%0A%09%09%09%09
 x:
+ 
 x + width, y:y%7D)
@@ -434,20 +434,29 @@
 + width,
- y:y
+%0A%09%09%09%09y: y%0A%09%09%09
 %7D);%0A%09%09%7D,
@@ -505,15 +505,26 @@
 or(%7B
+%0A%09%09%09%09
 x:
+ 
 x,
- 
+%0A%09%09%09%09
 y:
+ 
 y + 
@@ -521,32 +521,36 @@
 %09%09%09y: y + height
+%0A%09%09%09
 %7D);%0A%09%09%7D,%0A%09%09get b
@@ -588,18 +588,24 @@
 Vector(%7B
+%0A%09%09%09%09
 x:
+ 
 x + widt
@@ -606,19 +606,24 @@
 + width,
- 
+%0A%09%09%09%09
 y:
+ 
 y + heig
@@ -624,16 +624,20 @@
 + height
+%0A%09%09%09
 %7D);%0A%09%09%7D,
@@ -651,16 +651,17 @@
 center()
+ 
 %7B%0A%09%09%09ret
@@ -678,16 +678,21 @@
 Vector(%7B
+%0A%09%09%09%09
 x: x + w
@@ -698,17 +698,21 @@
 width/2,
- 
+%0A%09%09%09%09
 y: y + h
@@ -718,16 +718,20 @@
 height/2
+%0A%09%09%09
 %7D);%0A%09%09%7D,
@@ -749,11 +749,13 @@
 (%7Bx,
+ 
 y%7D)
+ 
 %7B%0A%09%09
@@ -780,29 +780,26 @@
 bottomLeft.x
-%0A%09%09%09%09
+  
 && y %3C= this
@@ -838,26 +838,27 @@
 opLeft.x
-%0A%09%09%09%09
+     
 && y 
+ 
 %3E this.t
@@ -871,24 +871,25 @@
 .y%0A%09%09%09%09&& x 
+ 
 %3C this.topRi
@@ -893,26 +893,26 @@
 pRight.x
-%0A%09%09%09%09
+    
 && y 
+ 
 %3E this.t
@@ -930,16 +930,17 @@
 %09%09%09&& x 
+ 
 %3C this.b
@@ -955,18 +955,15 @@
 ht.x
-%0A%09%09%09%09
+ 
 && y 
+ 
 %3C th
@@ -1040,33 +1040,32 @@
 t.topRight)%0A%09%09%09%09
-%09
 %7C%7C this.contains
@@ -1083,25 +1083,24 @@
 mRight)%0A%09%09%09%09
-%09
 %7C%7C this.cont
@@ -1121,17 +1121,16 @@
 omLeft)%0A
-%09
 %09%09%09%09%7C%7C t
@@ -1157,16 +1157,108 @@
 pLeft);%0A
+%09%09%7D,%0A%09%09translate(%7Bx, y%7D) %7B%0A%09%09%09return createRect(this.topLeft.add(%7Bx, y%7D), %7Bwidth, height%7D);%0A
 %09%09%7D%0A%09%7D;%0A

change interface