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