geometric-pack
Version:
Geometric pack with lots of available calculations for 2D and 3D geometry
74 lines • 3.21 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.Annulus = void 0;
var normalize_result_1 = require("../../utils/normalize-result");
var Annulus = /** @class */ (function () {
function Annulus() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
this.validateInput(args);
this.outerRadius = args[0];
this.innerRadius = args[1];
}
Annulus.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("Annulus constructor takes 2 arguments");
}
if (this.hasNegative(args)) {
throw new Error("Radiuses must be positive numbers");
}
};
Annulus.prototype.hasNegative = function (_a) {
var outerRadius = _a[0], innerRadius = _a[1];
return outerRadius <= 0 || innerRadius <= 0;
};
Annulus.prototype.getDefinition = function () {
return {
outerRadius: this.outerRadius,
innerRadius: this.innerRadius,
outerCircumference: this.getOuterCircumference(),
innerCircumference: this.getInnerCircumference(),
outerCircleArea: this.getOuterCircleArea(),
innerCircleArea: this.getInnerCircleArea(),
annulusArea: this.getAnnulusArea(),
};
};
Annulus.prototype.getOuterCircumference = function () {
return 2 * Math.PI * this.outerRadius;
};
Annulus.prototype.getInnerCircumference = function () {
return 2 * Math.PI * this.innerRadius;
};
Annulus.prototype.getOuterCircleArea = function () {
return Math.PI * Math.pow(this.outerRadius, 2);
};
Annulus.prototype.getInnerCircleArea = function () {
return Math.PI * Math.pow(this.innerRadius, 2);
};
Annulus.prototype.getAnnulusArea = function () {
return this.getOuterCircleArea() - this.getInnerCircleArea();
};
Annulus = __decorate([
normalize_result_1.NormalizeResults(),
__metadata("design:paramtypes", [Number])
], Annulus);
return Annulus;
}());
exports.Annulus = Annulus;
//# sourceMappingURL=annulus.js.map