geometric-pack
Version:
Geometric pack with lots of available calculations for 2D and 3D geometry
87 lines • 3.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.ConicalFrustum = void 0;
var normalize_result_1 = require("../../utils/normalize-result");
var ConicalFrustum = /** @class */ (function () {
function ConicalFrustum() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
this.validateInput(args);
this.radius1 = args[0];
this.radius2 = args[1];
this.height = args[2];
}
ConicalFrustum.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("ConicalFrustum constructor takes 3 arguments");
}
if (this.hasNegative(args)) {
throw new Error("Radiuses and height must be positive numbers");
}
};
ConicalFrustum.prototype.hasNegative = function (_a) {
var radius1 = _a[0], radius2 = _a[1], height = _a[2];
return radius1 <= 0 || radius2 <= 0 || height <= 0;
};
ConicalFrustum.prototype.getDefinition = function () {
return {
radius1: this.radius1,
radius2: this.radius2,
height: this.height,
slantHeight: this.getSlantHeight(),
volume: this.getVolume(),
lateralSurfaceArea: this.getLateralSurfaceArea(),
topSurfaceArea: this.getTopSurfaceArea(),
baseSurfaceArea: this.getBaseSurfaceArea(),
totalSurfaceArea: this.getTotalSurfaceArea(),
};
};
ConicalFrustum.prototype.getSlantHeight = function () {
return Math.sqrt(Math.pow(this.radius1 - this.radius2, 2) + Math.pow(this.height, 2));
};
ConicalFrustum.prototype.getVolume = function () {
return ((1 / 3) *
Math.PI *
this.height *
(Math.pow(this.radius1, 2) +
Math.pow(this.radius2, 2) +
this.radius1 * this.radius2));
};
ConicalFrustum.prototype.getLateralSurfaceArea = function () {
return Math.PI * (this.radius1 + this.radius2) * this.getSlantHeight();
};
ConicalFrustum.prototype.getTopSurfaceArea = function () {
return Math.PI * Math.pow(this.radius1, 2);
};
ConicalFrustum.prototype.getBaseSurfaceArea = function () {
return Math.PI * Math.pow(this.radius2, 2);
};
ConicalFrustum.prototype.getTotalSurfaceArea = function () {
return (this.getLateralSurfaceArea() +
this.getTopSurfaceArea() +
this.getBaseSurfaceArea());
};
ConicalFrustum = __decorate([
normalize_result_1.NormalizeResults(),
__metadata("design:paramtypes", [Number])
], ConicalFrustum);
return ConicalFrustum;
}());
exports.ConicalFrustum = ConicalFrustum;
//# sourceMappingURL=conical-frustum.js.map