geometric-pack
Version:
Geometric pack with lots of available calculations for 2D and 3D geometry
95 lines • 3.53 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.LinearFunction = void 0;
var normalize_result_1 = require("../../utils/normalize-result");
var LinearFunction = /** @class */ (function () {
function LinearFunction() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
this.validateInput(args);
this.a = args[0];
this.b = args[1];
}
LinearFunction.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("LinearFunction constructor takes 2 arguments");
}
};
LinearFunction.prototype.getDefinition = function () {
return {
a: this.a,
b: this.b,
solution: this.getSolution(),
monotonicity: this.getMonotonicity(),
positiveRange: this.getPositiveRange(),
negativeRange: this.getNegativeRange(),
};
};
LinearFunction.prototype.getSolution = function () {
if (this.a === 0) {
if (this.b === 0) {
return Infinity;
}
return null;
}
return -(this.b / this.a);
};
LinearFunction.prototype.getMonotonicity = function () {
if (this.a > 0) {
return "increasing";
}
if (this.a < 0) {
return "decreasing";
}
return "constant";
};
LinearFunction.prototype.getPositiveRange = function () {
var solution = this.getSolution();
if (solution !== null) {
if (this.a > 0) {
return [solution, Infinity];
}
return [-Infinity, solution];
}
if (this.b > 0) {
return [-Infinity, Infinity];
}
return [];
};
LinearFunction.prototype.getNegativeRange = function () {
var solution = this.getSolution();
if (solution !== null) {
if (this.a > 0) {
return [-Infinity, solution];
}
return [solution, Infinity];
}
if (this.b < 0) {
return [-Infinity, Infinity];
}
return [];
};
LinearFunction = __decorate([
normalize_result_1.NormalizeResults(),
__metadata("design:paramtypes", [Number])
], LinearFunction);
return LinearFunction;
}());
exports.LinearFunction = LinearFunction;
//# sourceMappingURL=linear-function.js.map