57 lines
2.2 KiB
JavaScript
57 lines
2.2 KiB
JavaScript
define(["require", "exports"], function (require, exports) {
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.Rectangle = void 0;
|
|
/**
|
|
* Rectangle helper class.
|
|
*
|
|
* @public
|
|
* {@docCategory Rectangle}
|
|
*/
|
|
var Rectangle = /** @class */ (function () {
|
|
function Rectangle(left, right, top, bottom) {
|
|
if (left === void 0) { left = 0; }
|
|
if (right === void 0) { right = 0; }
|
|
if (top === void 0) { top = 0; }
|
|
if (bottom === void 0) { bottom = 0; }
|
|
this.top = top;
|
|
this.bottom = bottom;
|
|
this.left = left;
|
|
this.right = right;
|
|
}
|
|
Object.defineProperty(Rectangle.prototype, "width", {
|
|
/**
|
|
* Calculated automatically by subtracting the right from left
|
|
*/
|
|
get: function () {
|
|
return this.right - this.left;
|
|
},
|
|
enumerable: false,
|
|
configurable: true
|
|
});
|
|
Object.defineProperty(Rectangle.prototype, "height", {
|
|
/**
|
|
* Calculated automatically by subtracting the bottom from top.
|
|
*/
|
|
get: function () {
|
|
return this.bottom - this.top;
|
|
},
|
|
enumerable: false,
|
|
configurable: true
|
|
});
|
|
/**
|
|
* Tests if another rect is approximately equal to this rect (within 4 decimal places.)
|
|
*/
|
|
Rectangle.prototype.equals = function (rect) {
|
|
// Fixing to 4 decimal places because it allows enough precision and will handle cases when something
|
|
// should be rounded, like .999999 should round to 1.
|
|
return (parseFloat(this.top.toFixed(4)) === parseFloat(rect.top.toFixed(4)) &&
|
|
parseFloat(this.bottom.toFixed(4)) === parseFloat(rect.bottom.toFixed(4)) &&
|
|
parseFloat(this.left.toFixed(4)) === parseFloat(rect.left.toFixed(4)) &&
|
|
parseFloat(this.right.toFixed(4)) === parseFloat(rect.right.toFixed(4)));
|
|
};
|
|
return Rectangle;
|
|
}());
|
|
exports.Rectangle = Rectangle;
|
|
});
|
|
//# sourceMappingURL=Rectangle.js.map
|