geometric-pack
Version:
Geometric pack with lots of available calculations for 2D and 3D geometry
67 lines • 2.71 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.Sphere = void 0;
var normalize_result_1 = require("../../utils/normalize-result");
var Sphere = /** @class */ (function () {
function Sphere() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
this.validateInput(args);
this.radius = args[0];
}
Sphere.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("Sphere constructor takes 1 argument");
}
if (this.hasNegative(args[0])) {
throw new Error("Radius must be positive number");
}
};
Sphere.prototype.hasNegative = function (radius) {
return radius <= 0;
};
Sphere.prototype.getDefinition = function () {
return {
radius: this.radius,
diameter: this.getDiameter(),
volume: this.getVolume(),
circumference: this.getCircumference(),
area: this.getArea(),
};
};
Sphere.prototype.getVolume = function () {
return (4 / 3) * Math.PI * Math.pow(this.radius, 3);
};
Sphere.prototype.getCircumference = function () {
return 2 * Math.PI * this.radius;
};
Sphere.prototype.getArea = function () {
return 4 * Math.PI * Math.pow(this.radius, 2);
};
Sphere.prototype.getDiameter = function () {
return 2 * this.radius;
};
Sphere = __decorate([
normalize_result_1.NormalizeResults(),
__metadata("design:paramtypes", [Number])
], Sphere);
return Sphere;
}());
exports.Sphere = Sphere;
//# sourceMappingURL=sphere.js.map