diff --git a/src/dichotomie.ts b/src/dichotomie.ts index 115d1f6b0afb84c288dbbc5278f15e2bd98cc8d4..e748417c9db1e3c3087721f151f988710ecdbbeb 100644 --- a/src/dichotomie.ts +++ b/src/dichotomie.ts @@ -37,6 +37,11 @@ export class Dichotomie extends Debug { private _func: () => number; + /** + * si > 0, un calcul dichotomique est en cours + */ + private static _inDicho: number = 0; + /** * Construction de la classe. * @param nub Noeud de calcul contenant la méthode de calcul Equation @@ -68,6 +73,10 @@ export class Dichotomie extends Debug { this._startIntervalMaxSteps = n; } + public static get inDico(): boolean { + return Dichotomie._inDicho > 0; + } + public CalculX(x: number): number { this.vX = x; return this.Calcul(); @@ -80,6 +89,8 @@ export class Dichotomie extends Debug { * @param rInit valeur initiale approximative de x */ public Dichotomie(rTarget: number, rTol: number, rInit: number): Result { + Dichotomie._inDicho++; + this._target = rTarget; // console.log("-----"); // for (let x = 0; x <= 1; x += 0.1) @@ -109,20 +120,24 @@ export class Dichotomie extends Debug { this.debug( `${this.analyticalSymbol}(${this.sVarCalc}=${s.value}) = ${rTarget}` ); + Dichotomie._inDicho--; return new Result(s.value); } else { this.debug( "Non convergence" ); + Dichotomie._inDicho--; return new Result(new Message(MessageCode.ERROR_DICHO_CONVERGE, { lastApproximation: s.value }), this.nub); } } else { + Dichotomie._inDicho--; return new Result(r.res); } } catch (e) { // un appel à Calcul() a généré une erreur + Dichotomie._inDicho--; return this.nub.result; } }