-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathdiff-area.js
More file actions
40 lines (31 loc) · 912 Bytes
/
diff-area.js
File metadata and controls
40 lines (31 loc) · 912 Bytes
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
'use strict';
module.exports = class DiffArea {
static create() {
return new DiffArea();
}
constructor() {
this._diffArea = {left: Infinity, top: Infinity, right: -Infinity, bottom: -Infinity};
this._updated = false;
}
update(x, y) {
const {left, top, right, bottom} = this._diffArea;
this._diffArea = {
left: Math.min(left, x),
top: Math.min(top, y),
right: Math.max(right, x),
bottom: Math.max(bottom, y)
};
this._updated = true;
return this;
}
isPointInArea(x, y, radius) {
const {left, top, right, bottom} = this._diffArea;
return x >= (left - radius) && x <= (right + radius) && y >= (top - radius) && y <= (bottom + radius);
}
isEmpty() {
return !this._updated;
}
get area() {
return this._diffArea;
}
};