diff --git a/spec/macrorugo/macrorugo_compound.spec.ts b/spec/macrorugo/macrorugo_compound.spec.ts index 90883d3638c0dd108e601a6937167a2c0a012c2d..e302e0f2f238c1655308094adabce5373395d187 100644 --- a/spec/macrorugo/macrorugo_compound.spec.ts +++ b/spec/macrorugo/macrorugo_compound.spec.ts @@ -4,7 +4,7 @@ import { MacrorugoCompound } from "../../src/macrorugo/macrorugo_compound"; import { Props } from "../../src/props"; import { Session } from "../../src/session"; -let B: number; +let BR: number; describe("MacroRugoCompound", () => { describe("Default 1 apron", () => { @@ -20,22 +20,32 @@ describe("MacroRugoCompound", () => { }); describe("Default inclined but flat apron", () => { beforeAll(() => { - B = 2; + BR = 0; }); beforeEach(() => { - B++; + BR += 1; }); - for (let i = 2; i < 6; i++) { + for (let i = 1; i < 10; i += 1) { it(`B = ${i} should return same result as Macrorugo`, () => { const mrc = Session.getInstance().createNub( new Props({ calcType: CalculatorType.MacroRugoCompound }) ) as MacrorugoCompound; mrc.properties.setPropValue("InclinedApron", true); - mrc.prms.B.singleValue = 4; + mrc.prms.BR.singleValue = BR; const mr = Session.getInstance() .createNub(new Props({ calcType: CalculatorType.MacroRugo })) as MacroRugo; mr.prms.Q.setCalculated(); - expect(mrc.CalcSerie().vCalc).toBeCloseTo(mr.CalcSerie().vCalc * mrc.prms.B.currentValue, 3); + expect(mrc.CalcSerie().vCalc) + .toBeCloseTo(mr.CalcSerie().vCalc * mrc.prms.BR.currentValue / mr.prms.B.currentValue, 3); + const ax = mrc.prms.PBD.v / Math.sqrt(mrc.prms.C.v); + let B: number = 0; + for (const child of mrc.children) { + expect(child.result.values.xCenter) + .toBeCloseTo(B + child.prms.B.v / 2); + B += child.prms.B.v; + expect(child.prms.B.v).toBeGreaterThanOrEqual(ax / 4); + } + expect(B).toBeCloseTo(mrc.prms.BR.currentValue, 6); }); } }); diff --git a/src/macrorugo/macrorugo_compound.ts b/src/macrorugo/macrorugo_compound.ts index 718e9ecbd055777bad531ae19a125e753606c909..c246303b91c0b84a5a378a96b90e467a742298f9 100644 --- a/src/macrorugo/macrorugo_compound.ts +++ b/src/macrorugo/macrorugo_compound.ts @@ -39,9 +39,12 @@ export class MacrorugoCompound extends MacroRugo { public Equation(sVarCalc: string): Result { let QT: number = 0; + let B: number = 0; for (const child of this.children) { child.Calc(sVarCalc); QT += child.result.vCalc; + child.result.values.xCenter = B + child.prms.B.v / 2; + B += child.prms.B.v; } return new Result(QT); } @@ -104,7 +107,7 @@ export class MacrorugoCompound extends MacroRugo { // Taille d'une cellule de calcul const ax: number = this.prms.PBD.v / Math.sqrt(this.prms.C.v); // Nombre entier de cellules et reste - const nCells: number = Math.floor(this.prms.BR.v / ax); + let nCells: number = Math.floor(this.prms.BR.v / ax); const xRest: number = this.prms.BR.v % ax; const xCenters: number[] = []; let lastBorder: number = 0; @@ -112,22 +115,28 @@ export class MacrorugoCompound extends MacroRugo { if (xRest > ax / 2) { // Ajout d'une cellule à gauche xCenters.push(xRest / 4); + nCells++; } else { - xCenters.push((ax + xRest / 2) / 2); - } - lastBorder = xCenters[0] * 2; - // Ajout des cellules centrales décalées de ax - for (let i = 0; i < nCells; i++) { - xCenters.push(lastBorder + ax / 2); - lastBorder += ax; + if (nCells < 2) { + xCenters.push(this.prms.BR.v / 2); + } else { + xCenters.push((ax + xRest / 2) / 2); + } } - if (xRest > ax / 2) { - // Ajout de la cellule supplémentaire à droite - xCenters.push(this.prms.B.v - xRest / 4); - } else { - xCenters[xCenters.length - 1] = this.prms.BR.v - (ax + xRest / 2) / 2; + if (nCells > 1 || xRest > ax / 2) { + lastBorder = xCenters[0] * 2; + // Ajout des cellules centrales décalées de ax + for (let i = 1; i < nCells; i++) { + xCenters.push(lastBorder + ax / 2); + lastBorder += ax; + } + if (xRest > ax / 2) { + // Ajout de la cellule supplémentaire à droite + xCenters.push(this.prms.BR.v - xRest / 4); + } else { + xCenters[xCenters.length - 1] = this.prms.BR.v - (ax + xRest / 2) / 2; + } } - // Génération des radiers // Suppression des radiers existants while (this.children.length > 0) {