geometric-pack
Version:
Geometric pack with lots of available calculations for 2D and 3D geometry
72 lines • 2.94 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.Square = void 0;
var normalize_result_1 = require("../../utils/normalize-result");
var Square = /** @class */ (function () {
function Square() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
this.validateInput(args);
this.sideLength = args[0];
}
Square.prototype.validateInput = function (args) {
args.forEach(function (arg) {
if (typeof arg !== "number") {
throw new Error("Argument must be a number");
}
});
if (args.length !== 1) {
throw new Error("Square constructor takes 1 argument");
}
if (this.hasNegative(args)) {
throw new Error("Side length must be positive number");
}
};
Square.prototype.hasNegative = function (_a) {
var sideLength = _a[0];
return sideLength <= 0;
};
Square.prototype.getDefinition = function () {
return {
sideLength: this.sideLength,
circumference: this.getCircumference(),
area: this.getArea(),
diagonal: this.getDiagonal(),
outerCircleRadius: this.getOuterCircleRadius(),
innerCircleRadius: this.getInnerCircleRadius(),
};
};
Square.prototype.getCircumference = function () {
return this.sideLength * 4;
};
Square.prototype.getArea = function () {
return Math.pow(this.sideLength, 2);
};
Square.prototype.getDiagonal = function () {
return Math.sqrt(this.getArea() * 2);
};
Square.prototype.getOuterCircleRadius = function () {
return this.getDiagonal() / 2;
};
Square.prototype.getInnerCircleRadius = function () {
return this.sideLength / 2;
};
Square = __decorate([
normalize_result_1.NormalizeResults(),
__metadata("design:paramtypes", [Number])
], Square);
return Square;
}());
exports.Square = Square;
//# sourceMappingURL=square.js.map