diff --git a/spec/iterator/paramvalues_iterator.spec.ts b/spec/iterator/paramvalues_iterator.spec.ts index 238b64b503e76072787e6bb8e807fa1fb52fefe3..9bfa898de4e237b2d914a87b7effa3d8ab2d56c3 100644 --- a/spec/iterator/paramvalues_iterator.spec.ts +++ b/spec/iterator/paramvalues_iterator.spec.ts @@ -1,4 +1,6 @@ -import { ParamValues, ParamValueMode, ParamValueIterator } from "../../src/param/param-values" +import { ParamValues } from "../../src/param/param-values" +import { ParamValueIterator } from "../../src/param/param-value-iterator"; +import { ParamValueMode } from "../../src/param/param-value-mode"; function checkNumberList(it: ParamValueIterator, exp: number[]) { let n = 0; diff --git a/spec/param/param-values.spec.ts b/spec/param/param-values.spec.ts index 9eae6de7ab359ac7789dfd607cad42cf3433cd4d..f7575fe1cacb3724bcb7668f0985b98af6fc06b0 100644 --- a/spec/param/param-values.spec.ts +++ b/spec/param/param-values.spec.ts @@ -1,6 +1,7 @@ /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { ParamValues, ParamValueMode } from "../../src/param/param-values" +import { ParamValues } from "../../src/param/param-values" +import { ParamValueMode } from "../../src/param/param-value-mode"; describe('paramvalues : ', () => { it("check single (1)", () => { diff --git a/spec/value_ref/value_ref.spec.ts b/spec/value_ref/value_ref.spec.ts index b48a4d32f9433f94bc0bb6766d7460b30e42ad49..c9ba1ddda21ee4ad1f2dc57556e3905f6a3cd454 100644 --- a/spec/value_ref/value_ref.spec.ts +++ b/spec/value_ref/value_ref.spec.ts @@ -8,7 +8,8 @@ import { describe, expect, it, xdescribe, xit } from "../mock_jasmine"; import { NubTest, NubTestParams } from "../nubtest"; import { precDigits } from "../test_config"; -import { ParamValueMode, Result } from "../../src"; +import { ParamValueMode } from "../../src/param/param-value-mode"; +import { Result } from "../../src"; let nub1: NubTest; let nub2: NubTest; diff --git a/src/compute-node.ts b/src/compute-node.ts index 88ff3470faae9b9fbb1d386699967982268c1966..e7efe419b52f24d324a8db8ca78420c29fece627 100644 --- a/src/compute-node.ts +++ b/src/compute-node.ts @@ -1,7 +1,6 @@ import { Debug, IDebug } from "./base"; import { ParamsEquation, IParamDefinitionIterator } from "./param/params-equation"; import { ParamDefinition } from "./param/param-definition"; -import { ParamValueMode } from "./param/param-values"; import { JalhydObject } from "./jalhyd_object"; /** diff --git a/src/nub.ts b/src/nub.ts index a5160d4a6e0ee5aec7c1ed1b5fa9dd10d0044d49..79696d1da912e9f01721d4c34e2d6a3554d31e69 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -2,7 +2,8 @@ import { Debug } from "./base"; import { Dichotomie } from "./dichotomie"; import { ComputeNode } from "./compute-node"; import { Result } from "./util/result"; -import { ParamValues, ParamValueMode } from "./param/param-values"; +import { ParamValues } from "./param/param-values"; +import { ParamValueMode } from "./param/param-value-mode"; import { ParamDefinition } from "."; import { IReferencedObject } from "./value_ref/object_ref"; diff --git a/src/param/param-base.ts b/src/param/param-base.ts index fc8de5e275404d6e4f1b5665dda417a4a3daeb2d..7e21c6314a7e3641416519e3a6df4eb37ceef49b 100644 --- a/src/param/param-base.ts +++ b/src/param/param-base.ts @@ -4,7 +4,8 @@ import { Message, MessageCode } from "../util/message"; import { JalhydObject } from "../jalhyd_object" import { ParamDomain, ParamDomainValue } from "./param-domain"; -import { ParamValues, ParamValueMode } from "./param-values"; +import { ParamValues } from "./param-values"; +import { ParamValueMode } from "./param-value-mode"; import { IReferencedObject, IObjectReference } from "../value_ref/object_ref"; import { Result } from ".."; diff --git a/src/param/param-definition.ts b/src/param/param-definition.ts index afd80ace0140cc28416dbce39e7bbdd53c57fd23..070880604eb042f354d4e9eec4ba7284b5e2278e 100644 --- a/src/param/param-definition.ts +++ b/src/param/param-definition.ts @@ -2,7 +2,7 @@ import { Message, MessageCode } from "../util/message"; import { BaseParam } from "./param-base"; import { ParamDomain, ParamDomainValue } from "./param-domain"; -import { ParamValueMode, ParamValueIterator } from "./param-values"; +import { ParamValueMode } from "./param-value-mode"; /** * calculabilité du paramètre diff --git a/src/param/param-value-iterator.ts b/src/param/param-value-iterator.ts new file mode 100644 index 0000000000000000000000000000000000000000..0d123d96de9c20d67adc04ccba16a4d78b65b056 --- /dev/null +++ b/src/param/param-value-iterator.ts @@ -0,0 +1,149 @@ +import { ParamValues } from "./param-values"; +import { ParamValueMode } from "./param-value-mode"; + +/** + * itérateur sur les (ou la) valeurs prises par le paramètre + */ +export class ParamValueIterator implements IterableIterator<number> { + /** + * paramètre à itérer + */ + private _param: ParamValues; + + /** + * true si les valeurs sont fournies de max à min (ParamValueMode.MINMAX) + */ + private _reverse: boolean; + + private _index: number; + + /** + * cas de figure : + * 0 : valeur fixée + * 1 : min/max/pas + * 2 : liste de valeurs + */ + private _config: number; + + constructor(prm: ParamValues, reverse: boolean = false) { + prm.check(); + this._param = prm; + this.reset(reverse) + } + + public reset(reverse: boolean) { + this._reverse = reverse; + + switch (this._param.valueMode) { + case ParamValueMode.SINGLE: + this._config = 0; + this._index = 0; + break; + + case ParamValueMode.MINMAX: + this._config = 1; + if (reverse) + this._index = this._param.max; + else + this._index = this._param.min; + break; + + case ParamValueMode.LISTE: + this._config = 2; + this._index = 0; + break; + + default: + throw new Error(`ParamValueIterator : mode de génération de valeurs ${ParamValueMode[this._param.valueMode]} incorrect`); + } + } + + public get hasNext(): boolean { + switch (this._config) { + // valeur fixée + case 0: + return this._index == 0; + + // min/max + case 1: + const end = this._reverse ? this._index < this._param.min : this._index > this._param.max; + return !end; + + // liste + case 2: + return this._index < this._param.valueList.length; + + default: + throw new Error(`ParamValueIterator.hasNext() : erreur interne`); + } + } + + public next(): IteratorResult<number> { + switch (this._config) { + // valeur fixée + case 0: + if (this.hasNext) { + this._index++; + return { + done: false, + value: this._param.singleValue + }; + } + else + return { + done: true, + value: undefined + }; + + // min/max + case 1: + const res = this._index; + if (this.hasNext) { + if (this._reverse) + this._index -= this._param.step; + else + this._index += this._param.step; + return { + done: false, + value: res + }; + } else { + return { + done: true, + value: undefined + }; + } + + // liste + case 2: + const i = this._index; + if (this.hasNext) { + const res = this._param.valueList[this._index++]; + return { + done: false, + value: res + }; + } else { + return { + done: true, + value: undefined + }; + } + + default: + throw new Error(`ParamValueIterator.next() : erreur interne`); + } + } + + // public get current(): number { + // if (this._config == 1) + // return this._index; + // throw new Error(`appel ParamValueIterator.current() invalide`) + // } + + // interface IterableIterator + + public [Symbol.iterator](): IterableIterator<number> { + return this; + } +} diff --git a/src/param/param-value-mode.ts b/src/param/param-value-mode.ts new file mode 100644 index 0000000000000000000000000000000000000000..826ca43fb4f3b457e5487b2306ee667c7e6db29d --- /dev/null +++ b/src/param/param-value-mode.ts @@ -0,0 +1,30 @@ + +/** + * mode de génération des valeurs d'un paramètre + */ +export enum ParamValueMode { + /** + * valeur unique + */ + SINGLE, + + /** + * min, max, pas + */ + MINMAX, + + /** + * liste de valeurs discrètes + */ + LISTE, + + /** + * la valeur du paramètre est non définie et à calculer + */ + CALCUL, + + /** + * la valeur du paramètre est liée à celle d'un paramètre, d'un résultat, ... + */ + LINK +} diff --git a/src/param/param-values.ts b/src/param/param-values.ts index 57b5457b97cfa1378a0af15b1fcf5c2997e394ca..8486a6d42d9d9ec4aa1dedc730ddf00ad9351a16 100644 --- a/src/param/param-values.ts +++ b/src/param/param-values.ts @@ -2,183 +2,8 @@ import { Pair } from "../util/pair" import { DefinedNumber } from "../util/definedvalue"; import { IReferencedObject, IObjectReference, ObjectReference } from "../value_ref/object_ref"; import { Result } from ".."; - -/** - * mode de génération des valeurs - */ -export enum ParamValueMode { - /** - * valeur unique - */ - SINGLE, - - /** - * min, max, pas - */ - MINMAX, - - /** - * liste de valeurs discrètes - */ - LISTE, - - /** - * la valeur du paramètre est non définie et à calculer - */ - CALCUL, - - /** - * la valeur du paramètre est liée à celle d'un paramètre, d'un résultat, ... - */ - LINK -} - -/** - * itérateur sur les (ou la) valeurs prises par le paramètre - */ -export class ParamValueIterator implements IterableIterator<number> { - /** - * paramètre à itérer - */ - private _param: ParamValues; - - /** - * true si les valeurs sont fournies de max à min (ParamValueMode.MINMAX) - */ - private _reverse: boolean; - - private _index: number; - - /** - * cas de figure : - * 0 : valeur fixée - * 1 : min/max/pas - * 2 : liste de valeurs - */ - private _config: number; - - constructor(prm: ParamValues, reverse: boolean = false) { - prm.check(); - this._param = prm; - this.reset(reverse) - } - - public reset(reverse: boolean) { - this._reverse = reverse; - - switch (this._param.valueMode) { - case ParamValueMode.SINGLE: - this._config = 0; - this._index = 0; - break; - - case ParamValueMode.MINMAX: - this._config = 1; - if (reverse) - this._index = this._param.max; - else - this._index = this._param.min; - break; - - case ParamValueMode.LISTE: - this._config = 2; - this._index = 0; - break; - - default: - throw new Error(`ParamValueIterator : mode de génération de valeurs ${ParamValueMode[this._param.valueMode]} incorrect`); - } - } - - public get hasNext(): boolean { - switch (this._config) { - // valeur fixée - case 0: - return this._index == 0; - - // min/max - case 1: - const end = this._reverse ? this._index < this._param.min : this._index > this._param.max; - return !end; - - // liste - case 2: - return this._index < this._param.valueList.length; - - default: - throw new Error(`ParamValueIterator.hasNext() : erreur interne`); - } - } - - public next(): IteratorResult<number> { - switch (this._config) { - // valeur fixée - case 0: - if (this.hasNext) { - this._index++; - return { - done: false, - value: this._param.singleValue - }; - } - else - return { - done: true, - value: undefined - }; - - // min/max - case 1: - const res = this._index; - if (this.hasNext) { - if (this._reverse) - this._index -= this._param.step; - else - this._index += this._param.step; - return { - done: false, - value: res - }; - } else { - return { - done: true, - value: undefined - }; - } - - // liste - case 2: - const i = this._index; - if (this.hasNext) { - const res = this._param.valueList[this._index++]; - return { - done: false, - value: res - }; - } else { - return { - done: true, - value: undefined - }; - } - - default: - throw new Error(`ParamValueIterator.next() : erreur interne`); - } - } - - // public get current(): number { - // if (this._config == 1) - // return this._index; - // throw new Error(`appel ParamValueIterator.current() invalide`) - // } - - // interface IterableIterator - - public [Symbol.iterator](): IterableIterator<number> { - return this; - } -} +import { ParamValueMode } from "./param-value-mode"; +import { ParamValueIterator } from "./param-value-iterator"; export class ParamValues implements IObjectReference { /** diff --git a/src/remous.ts b/src/remous.ts index 6c3ff39a118f985843978792639fb19ce0bcff79..1b0075fa9f789e59427ab0fda37bff8563db7f07 100644 --- a/src/remous.ts +++ b/src/remous.ts @@ -9,7 +9,7 @@ import { cLog } from "./util/log"; import { Message, MessageCode } from "./util/message"; import { Result } from "./util/result"; import { ResultElement } from "./util/resultelement"; -import { ParamValueIterator, ParamValues, BaseParam } from "."; +import { ParamValues, BaseParam } from "."; export enum MethodeResolution { Trapezes, EulerExplicite, RungeKutta4 diff --git a/src/section/section_nub.ts b/src/section/section_nub.ts index ad9068b19cc2d69e6dfe96a1886ebbfcd788aaf6..56445b7da42da2ec90684799fbbba707ed64b49c 100644 --- a/src/section/section_nub.ts +++ b/src/section/section_nub.ts @@ -3,7 +3,7 @@ import { acSection } from "./section_type"; import { Result } from "../util/result"; import { ParamDefinition, ParamCalculability } from "../param/param-definition"; import { ParamDomain, ParamDomainValue } from "../param/param-domain"; -import { ParamValueMode } from "../param/param-values"; +import { ParamValueMode } from "../param/param-value-mode"; import { ResultElement } from "../util/resultelement"; /** diff --git a/src/value_ref/object_ref.ts b/src/value_ref/object_ref.ts index 200cc3bb24ba038050270af2f8c474c3d136842d..1591dff85810cefc4437b93d97fb7af0db474fba 100644 --- a/src/value_ref/object_ref.ts +++ b/src/value_ref/object_ref.ts @@ -1,4 +1,4 @@ -import { ParamValueMode, ParamValueIterator, ParamValues } from "../param/param-values"; +import { ParamValues } from "../param/param-values"; import { Result } from ".."; /**