UNPKG

geometric-pack

Version:

Geometric pack with lots of available calculations for 2D and 3D geometry

73 lines 2.98 kB
"use strict"; 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.Cuboid = void 0; var normalize_result_1 = require("../../utils/normalize-result"); var Cuboid = /** @class */ (function () { function Cuboid() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } this.validateInput(args); this.length = args[0]; this.width = args[1]; this.height = args[2]; } Cuboid.prototype.validateInput = function (args) { args.forEach(function (arg) { if (typeof arg !== "number") { throw new Error("Argument must be a number"); } }); if (args.length !== 3) { throw new Error("Cuboid constructor takes 3 arguments"); } if (this.hasNegative(args)) { throw new Error("Length, width and height must be positive numbers"); } }; Cuboid.prototype.hasNegative = function (_a) { var length = _a[0], width = _a[1], height = _a[2]; return length <= 0 || width <= 0 || height <= 0; }; Cuboid.prototype.getDefinition = function () { return { length: this.length, width: this.width, height: this.height, diagonal: this.getDiagonal(), volume: this.getVolume(), area: this.getArea(), }; }; Cuboid.prototype.getVolume = function () { return this.length * this.width * this.height; }; Cuboid.prototype.getArea = function () { return (2 * (this.length * this.width + this.length * this.height + this.width * this.height)); }; Cuboid.prototype.getDiagonal = function () { return Math.sqrt(Math.pow(this.length, 2) + Math.pow(this.width, 2) + Math.pow(this.height, 2)); }; Cuboid = __decorate([ normalize_result_1.NormalizeResults(), __metadata("design:paramtypes", [Number]) ], Cuboid); return Cuboid; }()); exports.Cuboid = Cuboid; //# sourceMappingURL=cuboid.js.map