geometric-pack
Version:
Geometric pack with lots of available calculations for 2D and 3D geometry
102 lines • 4.28 kB
JavaScript
"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.Parallelogram = void 0;
var transform_1 = require("../../utils/transform");
var normalize_result_1 = require("../../utils/normalize-result");
var Parallelogram = /** @class */ (function () {
function Parallelogram() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
this.validateInput(args);
this.sideLengthA = args[0];
this.sideLengthB = args[1];
this.height = args[2];
}
Parallelogram.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("Parallelogram constructor takes 3 arguments");
}
if (this.hasNegative(args)) {
throw new Error("Side lengths and height must be positive numbers");
}
};
Parallelogram.prototype.hasNegative = function (_a) {
var sideLengthA = _a[0], sideLengthB = _a[1], height = _a[2];
return sideLengthA <= 0 || sideLengthB <= 0 || height <= 0;
};
Parallelogram.prototype.getDefinition = function () {
return {
sideLengthA: this.sideLengthA,
sideLengthB: this.sideLengthB,
height: this.height,
circumference: this.getCircumference(),
area: this.getArea(),
cornerAngles: this.getAngles(),
diagonals: this.getDiagonals(),
};
};
Parallelogram.prototype.getCircumference = function () {
return this.sideLengthA * 2 + this.sideLengthB * 2;
};
Parallelogram.prototype.getArea = function () {
return this.sideLengthB * this.height;
};
Parallelogram.prototype.getAlpha = function () {
var radians = Math.asin(this.height / this.sideLengthA);
return transform_1.transformRadiansToDegrees(radians);
};
Parallelogram.prototype.getBeta = function () {
return 180 - this.getAlpha();
};
Parallelogram.prototype.getAngles = function () {
return {
alpha: this.getAlpha(),
beta: this.getBeta(),
};
};
Parallelogram.prototype.getLongerDiagonal = function () {
return Math.sqrt(Math.pow(this.sideLengthA, 2) +
Math.pow(this.sideLengthB, 2) +
2 *
this.sideLengthA *
this.sideLengthB *
Math.cos((this.getAlpha() * Math.PI) / 180));
};
Parallelogram.prototype.getShorterDiagonal = function () {
return Math.sqrt(Math.pow(this.sideLengthA, 2) +
Math.pow(this.sideLengthB, 2) -
2 *
this.sideLengthA *
this.sideLengthB *
Math.cos((this.getAlpha() * Math.PI) / 180));
};
Parallelogram.prototype.getDiagonals = function () {
return {
longerDiagonal: this.getLongerDiagonal(),
shorterDiagonal: this.getShorterDiagonal(),
};
};
Parallelogram = __decorate([
normalize_result_1.NormalizeResults(),
__metadata("design:paramtypes", [Number])
], Parallelogram);
return Parallelogram;
}());
exports.Parallelogram = Parallelogram;
//# sourceMappingURL=parallelogram.js.map