UNPKG

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