-
Notifications
You must be signed in to change notification settings - Fork 0
/
rect.js
50 lines (48 loc) · 1.27 KB
/
rect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class rect {
constructor(scale, position){
this.scale = scale;
this.position = position;
}
//#region Getters&Setters
get position() {
return this.position;
}
get scale() {
return this.scale;
}
get height() {
return this.scale[1];
}
get width() {
return this.scale[0];
}
set position(position) {
this.position = position;
}
set scale(scale) {
this.scale = scale;
}
set width(width) {
this.scale[0] = width;
}
set height(height) {
this.scale[1] = height;
}
//#endregion
intersectPoint(pos) {
if(pos[0] > this.position[0] +this.scale[0] / 2)
return false;
if(pos[1] > this.position[1] + this.scale[1] / 2)
return false;
if(pos[0] < this.position[0] - this.scale[0] / 2)
return false;
if(pos[1] < this.position[1] - this.scale[1] / 2)
return false;
return true;
}
intersectRect(rect) {
let yDir = rect.position[1] > this.position[1] ? 1 : -1;
let xDir = rect.position[0] > this.position[0] ? 1 : -1;
return this.intersectPoint([rect.position[0] + (rect.scale[0] * xDir / 2), rect.position[1] + (rect.scale[1] * yDir / 2)]);
}
}