geometric-pack
Version:
Geometric pack with lots of available calculations for 2D and 3D geometry
66 lines • 2.84 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Rectangle = void 0;
var normalize_result_1 = require("../../utils/normalize-result");
var Rectangle = /** @class */ (function () {
function Rectangle() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
this.validateInput(args);
this.sideLengthA = args[0];
this.sideLengthB = args[1];
}
Rectangle.prototype.validateInput = function (args) {
args.forEach(function (arg) {
if (typeof arg !== "number") {
throw new Error("Argument must be a number");
}
});
if (args.length !== 2) {
throw new Error("Rectangle takes 2 arguments");
}
if (this.hasNegative(args)) {
throw new Error("Sides lengths must be positive numbers");
}
};
Rectangle.prototype.hasNegative = function (_a) {
var sideLengthA = _a[0], sideLengthB = _a[1];
return sideLengthA <= 0 || sideLengthB <= 0;
};
Rectangle.prototype.getDefinition = function () {
return {
sideLengthA: this.sideLengthA,
sideLengthB: this.sideLengthB,
circumference: this.getCircumference(),
area: this.getArea(),
diagonal: this.getDiagonal(),
};
};
Rectangle.prototype.getCircumference = function () {
return this.sideLengthA * 2 + this.sideLengthB * 2;
};
Rectangle.prototype.getArea = function () {
return this.sideLengthA * this.sideLengthB;
};
Rectangle.prototype.getDiagonal = function () {
return Math.sqrt(Math.pow(this.sideLengthA, 2) + Math.pow(this.sideLengthB, 2));
};
Rectangle = __decorate([
normalize_result_1.NormalizeResults(),
__metadata("design:paramtypes", [Number])
], Rectangle);
return Rectangle;
}());
exports.Rectangle = Rectangle;
//# sourceMappingURL=rectangle.js.map