-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregion.js
84 lines (69 loc) · 2.24 KB
/
region.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"use strict";
module.exports = Region;
function Region(position, size) {
this.position = position;
this.size = size;
}
Region.prototype.copyFrom = function (that) {
this.position.copyFrom(that.position);
this.size.copyFrom(that.size);
return this;
};
// TODO deprecated for copyFrom
Region.prototype.become = function (that) {
this.position.become(that.position);
this.size.become(that.size);
return this;
};
Region.prototype.scaleThis = function (n) {
this.position.scaleThis(n);
this.size.scaleThis(n);
return this;
};
Region.prototype.scale = function (n) {
return this.clone().scaleThis(n);
};
Region.prototype.roundThis = function () {
this.temp1.become(this.position).addThis(this.size).roundThis();
this.position.roundThis();
this.size.become(this.temp1).subThis(this.position);
return this;
};
Region.prototype.round = function (n) {
return this.clone().roundThis(n);
};
Region.prototype.roundInwardThis = function () {
this.temp1.become(this.position).addThis(this.size).floorThis();
this.position.ceilThis().minThis(this.temp1);
this.size.become(this.temp1).subThis(this.position);
return this;
};
Region.prototype.roundInward = function (n) {
return this.clone().roundInwardThis(n);
};
Region.prototype.roundOutwardThis = function () {
this.temp1.become(this.position).addThis(this.size).ceilThis();
this.position.floorThis();
this.size.become(this.temp1).subThis(this.position);
return this;
};
Region.prototype.roundOutward = function (n) {
return this.clone().roundOutwardThis(n);
};
Region.prototype.annex = function (that) {
return this.clone().annexThis(that);
};
Region.prototype.annexThis = function (that) {
this.temp1.become(this.position).addThis(this.size);
this.temp2.become(that.position).addThis(that.size);
this.position.minThis(that.position);
this.temp1.maxThis(this.temp2);
this.size.become(this.temp1).subThis(this.position);
return this;
};
Region.prototype.equals = function (that) {
return that && this.position.equals(that.position) && this.size.equals(that.size);
};
Region.prototype.toString = function () {
return "[position:" + this.position.toString() + " size:" + this.size.toString() + "]";
};