UNPKG

1.83 kBJavaScriptView Raw
1/**
2 * Rectangle helper class.
3 *
4 * @public
5 * {@docCategory Rectangle}
6 */
7var Rectangle = /** @class */ (function () {
8 function Rectangle(left, right, top, bottom) {
9 if (left === void 0) { left = 0; }
10 if (right === void 0) { right = 0; }
11 if (top === void 0) { top = 0; }
12 if (bottom === void 0) { bottom = 0; }
13 this.top = top;
14 this.bottom = bottom;
15 this.left = left;
16 this.right = right;
17 }
18 Object.defineProperty(Rectangle.prototype, "width", {
19 /**
20 * Calculated automatically by subtracting the right from left
21 */
22 get: function () {
23 return this.right - this.left;
24 },
25 enumerable: true,
26 configurable: true
27 });
28 Object.defineProperty(Rectangle.prototype, "height", {
29 /**
30 * Calculated automatically by subtracting the bottom from top.
31 */
32 get: function () {
33 return this.bottom - this.top;
34 },
35 enumerable: true,
36 configurable: true
37 });
38 /**
39 * Tests if another rect is approximately equal to this rect (within 4 decimal places.)
40 */
41 Rectangle.prototype.equals = function (rect) {
42 // Fixing to 4 decimal places because it allows enough precision and will handle cases when something
43 // should be rounded, like .999999 should round to 1.
44 return (parseFloat(this.top.toFixed(4)) === parseFloat(rect.top.toFixed(4)) &&
45 parseFloat(this.bottom.toFixed(4)) === parseFloat(rect.bottom.toFixed(4)) &&
46 parseFloat(this.left.toFixed(4)) === parseFloat(rect.left.toFixed(4)) &&
47 parseFloat(this.right.toFixed(4)) === parseFloat(rect.right.toFixed(4)));
48 };
49 return Rectangle;
50}());
51export { Rectangle };
52//# sourceMappingURL=Rectangle.js.map
\No newline at end of file