From d7fe7609000cab22d8ba0552fcc736d7b227c537 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Tue, 17 Sep 2024 01:01:46 +0200 Subject: [PATCH] Slightly improving phases sum cleanness. Didn't have quite as many bugs, but isn't quite as clean as the magnitude one as of now --- .../LogarithmPlotter/js/objs/phasebode.mjs | 14 +++++++-- .../js/objs/sommephasesbode.mjs | 31 ++++++++++--------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/phasebode.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/phasebode.mjs index bee6ee6..97fdae2 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/phasebode.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/phasebode.mjs @@ -114,11 +114,21 @@ export default class PhaseBode extends ExecutableObject { } update() { - if(Objects.currentObjects['Somme phases Bode'] !== undefined && Objects.currentObjects['Somme phases Bode'].length > 0) { - Objects.currentObjects['Somme phases Bode'][0].recalculateCache() + super.update() + let sumObjs = Objects.currentObjects['Somme phases Bode'] + if(sumObjs !== undefined && sumObjs.length > 0) { + sumObjs[0].recalculateCache() } else { Objects.createNewRegisteredObject('Somme phases Bode') } } + + delete() { + super.update() + let sumObjs = Objects.currentObjects['Somme phases Bode'] + if(sumObjs !== undefined && sumObjs.length > 0) { + sumObjs[0].recalculateCache() + } + } } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/sommephasesbode.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/sommephasesbode.mjs index 1483788..3bb6a3c 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/sommephasesbode.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/sommephasesbode.mjs @@ -74,25 +74,28 @@ export default class SommePhasesBode extends ExecutableObject { recalculateCache() { // Minimum to draw (can be expended if needed, just not infinite or it'll cause issues. - let drawMin = 0.001 - let drawMax = 100000 + let drawMin = 1e-20 + let drawMax = 1e20 this.om0xList = [drawMin, drawMax] this.phasesList = [0] this.phasesExprList = ['0'] - let phasesDict = {} - let phasesExprDict = {} - phasesDict[drawMax] = 0 + let phasesDict = new Map() + let phasesExprDict = new Map() + phasesDict.set(drawMax, 0) - if(Objects.currentObjects['Phase Bode'] !== undefined) { + let phaseObjects = Objects.currentObjects['Phase Bode'] + if(phaseObjects === undefined || phaseObjects.length < 1) { + Objects.deleteObject(this.name) + } else { console.log('Recalculating cache phase') - for(/** @type {PhaseBode} */ let obj of Objects.currentObjects['Phase Bode']) { + for(/** @type {PhaseBode} */ let obj of phaseObjects) { this.om0xList.push(obj.om_0.x.execute()) - if(phasesDict[obj.om_0.x.execute()] === undefined) { - phasesDict[obj.om_0.x.execute()] = obj.phase.execute() - phasesExprDict[obj.om_0.x.execute()] = obj.phase.toEditableString() + if(!phasesDict.has(obj.om_0.x.execute())) { + phasesDict.set(obj.om_0.x.execute(), obj.phase.execute()) + phasesExprDict.set(obj.om_0.x.execute(), obj.phase.toEditableString()) } else { - phasesDict[obj.om_0.x.execute()] += obj.phase.execute() - phasesExprDict[obj.om_0.x.execute()] += '+' + obj.phase.toEditableString() + phasesDict.set(obj.om_0.x.execute(), obj.phase.execute() + phasesDict.get(obj.om_0.x.execute())) + phasesExprDict.set(obj.om_0.x.execute(), obj.phase.toEditableString() + '+' + phasesExprDict.get(obj.om_0.x.execute())) } this.phasesList[0] += obj.om_0.y.execute() this.phasesExprList[0] += '+' + obj.om_0.y.toEditableString() @@ -100,8 +103,8 @@ export default class SommePhasesBode extends ExecutableObject { this.om0xList.sort((a,b) => a - b) let totalAdded = this.phasesList[0] for(let i = 1; i < this.om0xList.length; i++) { - this.phasesList[i] = this.phasesList[i-1] + phasesDict[this.om0xList[i]] - this.phasesExprList[i] = this.phasesExprList[i-1] + '+' + phasesDict[this.om0xList[i]] + this.phasesList[i] = this.phasesList[i-1] + phasesDict.get(this.om0xList[i]) + this.phasesExprList[i] = this.phasesExprList[i-1] + '+' + phasesDict.get(this.om0xList[i]) } } }