-
Notifications
You must be signed in to change notification settings - Fork 3
/
box.js
58 lines (48 loc) · 1.82 KB
/
box.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
// LifeViewer BoundingBox
// BoundingBox for pattern and selection extent.
/*
This file is part of LifeViewer
Copyright (C) 2015-2024 Chris Rowett
LifeViewer is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// BoundingBox object
/**
* @constructor
*/
function BoundingBox(/** @type {number} */ leftX, /** @type {number} */ bottomY, /** @type {number} */ rightX, /** @type {number} */ topY) {
/** @type {number} */ this.leftX = leftX;
/** @type {number} */ this.bottomY = bottomY;
/** @type {number} */ this.rightX = rightX;
/** @type {number} */ this.topY = topY;
}
// copy box from another
BoundingBox.prototype.set = function(/** @type {BoundingBox} */ source) {
/** @type {number} */ this.leftX = source.leftX;
/** @type {number} */ this.bottomY = source.bottomY;
/** @type {number} */ this.rightX = source.rightX;
/** @type {number} */ this.topY = source.topY;
};
// merge box from another
BoundingBox.prototype.merge = function(/** @type {BoundingBox} */ source) {
if (source.leftX < this.leftX) {
this.leftX = source.leftX;
}
if (source.rightX > this.rightX) {
this.rightX = source.rightX;
}
if (source.bottomY < this.bottomY) {
this.bottomY = source.bottomY;
}
if (source.topY > this.topY) {
this.topY = source.topY;
}
};