diff --git a/spec/nubtest.ts b/spec/nubtest.ts index 62f0e9c6f330781fa57c48fa02becb9601891f9c..ef4affddfd3b37eb7b9e7c7c95e65b9f856a3b20 100644 --- a/spec/nubtest.ts +++ b/spec/nubtest.ts @@ -68,10 +68,26 @@ export let precDigits = 3; */ export let precDist: number = Math.pow(10, -precDigits); +/** + * Compare deux valeurs réelles à un epsilon près + * @param val1 Première valeur à comparer + * @param val2 Deuxième valeur à comparer + * @param epsilon Erreur de comparaison acceptable + * @return Vrai si les valeurs sont égales, faux sinon + */ export function equalEpsilon(val1: number, val2: number, epsilon: number = precDist) { return Math.abs(val1 - val2) < epsilon; } +/** + * Test jasmine de deux valeurs réelles à un epsilon près + * @param val1 Première valeur à comparer + * @param val2 Deuxième valeur à comparer + */ +export function check(val1: Result, val2: number) { + expect(equalEpsilon(val1.vCalc, val2)).toBe(true); +} + /** * compare 2 objets * @param s message diff --git a/spec/pab/pab_dimension.spec.ts b/spec/pab/pab_dimension.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..33808a7aa1a7a38575865152a2a01e3630f6b731 --- /dev/null +++ b/spec/pab/pab_dimension.spec.ts @@ -0,0 +1,38 @@ +// tslint:disable-next-line:no-reference +/// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> + +import { Result } from "../../src/util/result"; +import { PabDimension, PabDimensionParams } from "../../src/pab/pab_dimension"; +import { check } from "../nubtest"; + +function pabDimensionTest(varTest: string) { + describe("Calc(): ", () => { + it("V should be 1", () => { + const prms = new PabDimensionParams( + 4, // Longueur L + 1, // Largeur W + 0.5, // Tirant d'eau Y + 2 // Volume V + ); + + let res: number = prms[varTest].v; + + const nub = new PabDimension(prms); + prms[varTest].v = undefined; + + check(nub.Calc(varTest), res); + }); + }); +} + +describe("Class PabDimension: ", () => { + // beforeEach(() => { + // }); + // beforeAll(() => { + // }); + pabDimensionTest("L"); + pabDimensionTest("W"); + pabDimensionTest("Y"); + pabDimensionTest("V"); + +}); diff --git a/src/index.ts b/src/index.ts index 1a8ae085171358b6957d36e5a579a1cf2752d638..79ad03eab0603508e1f5c8b78e3f223f669fa7ed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,3 +18,4 @@ export * from './util/message'; export * from './util/log'; export * from './util/result'; export * from './util/interval'; +export * from './pab/pab_dimension'; diff --git a/src/pab/pab_dimension.ts b/src/pab/pab_dimension.ts new file mode 100644 index 0000000000000000000000000000000000000000..d95c0e45e08bdea1f01db1b4bdd1a143827202bd --- /dev/null +++ b/src/pab/pab_dimension.ts @@ -0,0 +1,98 @@ +import { Result } from "../util/result"; +import { ComputeNodeType, ParamDefinition, ParamDomain, ParamDomainValue, ParamCalculability, ParamsEquation } from "../param"; +import { NumericalString } from "../index"; +import { Nub } from "../nub"; + +export class PabDimensionParams extends ParamsEquation { + [key: string]: any; // pour pouvoir faire this['methode](); + + /** Longueur L */ + private _L: ParamDefinition; + + /** Largeur W */ + private _W: ParamDefinition; + + /** Tirant d'eau Y */ + private _Y: ParamDefinition; + + /** Volume V */ + private _V: ParamDefinition; + + constructor(rL: number, rW: number, rY: number, rV: number = undefined) { + super(); + this._L = new ParamDefinition(ComputeNodeType.PabDimensions, 'L', ParamDomainValue.POS, rL); + this._W = new ParamDefinition(ComputeNodeType.PabDimensions, 'W', ParamDomainValue.POS, rW); + this._Y = new ParamDefinition(ComputeNodeType.PabDimensions, 'Y', ParamDomainValue.POS, rY); + this._V = new ParamDefinition(ComputeNodeType.PabDimensions, 'V', ParamDomainValue.POS, rV); + + this.addParamDefinition(this._L); + this.addParamDefinition(this._W); + this.addParamDefinition(this._Y); + this.addParamDefinition(this._V); + } + + get L() { + return this._L; + } + + get W() { + return this._W; + } + + get Y() { + return this._Y; + } + + get V() { + return this._V; + } +} +export class PabDimension extends Nub { + constructor(prms: PabDimensionParams, dbg: boolean = false) { + super(prms, dbg); + } + + /** + * paramètres castés au bon type + */ + get prms(): PabDimensionParams { + return <PabDimensionParams>this._prms; + } + + /** + * paramétrage de la calculabilité des paramètres + */ + protected setParametersCalculability() { + this.prms.L.calculability = ParamCalculability.EQUATION; + this.prms.W.calculability = ParamCalculability.EQUATION; + this.prms.Y.calculability = ParamCalculability.EQUATION; + this.prms.V.calculability = ParamCalculability.EQUATION; + } + + Equation(sVarCalc: string): Result { + let v: number; + + switch (sVarCalc) { + case "V": + v = this.prms.L.v * this.prms.W.v * this.prms.Y.v; + break; + + case "L": + v = this.prms.V.v / this.prms.W.v / this.prms.Y.v; + break + + case "W": + v = this.prms.V.v / this.prms.L.v / this.prms.Y.v; + break; + + case "Y": + v = this.prms.V.v / this.prms.L.v / this.prms.W.v; + break; + + default: + throw "PabDimension.Equation() : invalid variable name " + sVarCalc; + } + + return new Result(v); + } +} diff --git a/src/param.ts b/src/param.ts index 57fb26dec57920d62a88dc823318ed42f28a7f65..534c2cf0ded248695a34962b6124f9bf0883d0fc 100644 --- a/src/param.ts +++ b/src/param.ts @@ -421,6 +421,7 @@ export enum ComputeNodeType { RegimeUniformeTrapeze, RegimeUniformeRectangle, RegimeUniformeCercle, RegimeUniformePuissance, CourbeRemous, // paramètres communs à toutes les courbes de remous CourbeRemousTrapeze, CourbeRemousRectangle, CourbeRemousCercle, CourbeRemousPuissance, + PabDimensions, // passe à bassin rectangulaire Test } diff --git a/src/parameters.ts b/src/parameters.ts index 6ac00df8d2d92e77a4bba31d5ff2c13bf7ad0499..3133f27bd22fd939cd277bc517ff8aec54929803 100644 --- a/src/parameters.ts +++ b/src/parameters.ts @@ -8,6 +8,7 @@ import { ParamsSectionCirc, cSnCirc } from "./section/section_circulaire"; import { ParamsSectionPuiss, cSnPuiss } from "./section/section_puissance"; import { RegimeUniforme } from "./regime_uniforme"; import { CourbeRemous, CourbeRemousParams } from "./remous"; +import { PabDimensionParams, PabDimension } from "./pab/pab_dimension"; export class ComputeNodeParameters { private static _instance: ComputeNodeParameters; @@ -158,6 +159,13 @@ export class ComputeNodeParameters { return crp; } + case ComputeNodeType.PabDimensions: + { + let cn = new PabDimensionParams(undefined, undefined, undefined); + let n = new PabDimension(cn); // pour initialiser la calculabilité des paramètres + return cn; + } + default: throw "ComputeNodeParameters.getComputeNodeParameters() : noeud de calcul '" + ComputeNodeType[type] + "' non pris en charge"; }