UNPKG

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