UNPKG

jalhyd

Version:

JaLHyd, a Javascript Library for Hydraulics

155 lines 6.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Trigo = exports.TrigoUnit = exports.TrigoOperation = void 0; const internal_modules_1 = require("../internal_modules"); const internal_modules_2 = require("../internal_modules"); const internal_modules_3 = require("../internal_modules"); const internal_modules_4 = require("../internal_modules"); const internal_modules_5 = require("../internal_modules"); var TrigoOperation; (function (TrigoOperation) { TrigoOperation[TrigoOperation["COS"] = 0] = "COS"; TrigoOperation[TrigoOperation["SIN"] = 1] = "SIN"; TrigoOperation[TrigoOperation["TAN"] = 2] = "TAN"; TrigoOperation[TrigoOperation["COSH"] = 3] = "COSH"; TrigoOperation[TrigoOperation["SINH"] = 4] = "SINH"; TrigoOperation[TrigoOperation["TANH"] = 5] = "TANH"; })(TrigoOperation = exports.TrigoOperation || (exports.TrigoOperation = {})); var TrigoUnit; (function (TrigoUnit) { TrigoUnit[TrigoUnit["DEG"] = 0] = "DEG"; TrigoUnit[TrigoUnit["RAD"] = 1] = "RAD"; // Radians })(TrigoUnit = exports.TrigoUnit || (exports.TrigoUnit = {})); /** * cos, sin, tan, cosh, sinh, tanh */ class Trigo extends internal_modules_2.Nub { constructor(prms, dbg = false) { super(prms, dbg); this.setCalculatorType(internal_modules_1.CalculatorType.Trigo); this._defaultCalculatedParam = prms.Y; this.resetDefaultCalculatedParam(); this._props.addObserver(this); this.operation = TrigoOperation.COS; this.unit = TrigoUnit.DEG; } /** paramètres castés au bon type */ get prms() { return this._prms; } get operation() { return this.getPropValue("trigoOperation"); } set operation(o) { this.setPropValue("trigoOperation", o); } get unit() { return this.getPropValue("trigoUnit"); } set unit(u) { this.setPropValue("trigoUnit", u); } Equation(sVarCalc) { let v; switch (sVarCalc) { case "Y": let xv = this.prms.X.v; if (this.unit === TrigoUnit.DEG) { xv = xv * Math.PI / 180; } switch (this.operation) { case TrigoOperation.COS: v = Math.cos(xv); break; case TrigoOperation.SIN: v = Math.sin(xv); break; case TrigoOperation.TAN: v = Math.tan(xv); break; case TrigoOperation.COSH: v = Math.cosh(xv); break; case TrigoOperation.SINH: v = Math.sinh(xv); break; case TrigoOperation.TANH: v = Math.tanh(xv); break; default: throw new Error("Trigo.Equation() : invalid operation " + this.operation); } break; case "X": const yv = this.prms.Y.v; switch (this.operation) { case TrigoOperation.COS: v = Math.acos(yv); break; case TrigoOperation.SIN: v = Math.asin(yv); break; case TrigoOperation.TAN: v = Math.atan(yv); break; case TrigoOperation.COSH: v = Math.acosh(yv); break; case TrigoOperation.SINH: v = Math.asinh(yv); break; case TrigoOperation.TANH: v = Math.atanh(yv); break; default: throw new Error("Trigo.Equation() : invalid operation " + this.operation); } if (this.unit === TrigoUnit.DEG) { v = v / Math.PI * 180; } break; default: throw new Error("Trigo.Equation() : invalid variable name " + sVarCalc); } return new internal_modules_5.Result(v, this); } // interface Observer update(sender, data) { if (data.action === "propertyChange") { switch (data.name) { case "trigoOperation": // adjust definition domains const un = this.unit; switch (this.operation) { case TrigoOperation.COS: case TrigoOperation.SIN: // [-1,1] this.prms.Y.setDomain(new internal_modules_4.ParamDomain(internal_modules_4.ParamDomainValue.INTERVAL, -1, 1)); break; case TrigoOperation.TANH: // ]-1,1[ // @TODO manage boundaries exclusion in Interval this.prms.Y.setDomain(new internal_modules_4.ParamDomain(internal_modules_4.ParamDomainValue.INTERVAL, -0.99999999, 0.99999999)); break; case TrigoOperation.TAN: case TrigoOperation.SINH: // R this.prms.Y.setDomain(internal_modules_4.ParamDomainValue.ANY); break; case TrigoOperation.COSH: // [1,+∞[ this.prms.Y.setDomain(new internal_modules_4.ParamDomain(internal_modules_4.ParamDomainValue.INTERVAL, 1, Infinity)); break; } break; } } } /** paramétrage de la calculabilité des paramètres */ setParametersCalculability() { this.prms.Y.calculability = internal_modules_3.ParamCalculability.EQUATION; this.prms.X.calculability = internal_modules_3.ParamCalculability.EQUATION; } } exports.Trigo = Trigo; //# sourceMappingURL=trigo.js.map