Compare commits

..

No commits in common. "a16f02fd5f18f902557a097451ea0fc301707599" and "ef14db8bbb16d7edf7481f715c3fb10f74650e20" have entirely different histories.

5 changed files with 54 additions and 68 deletions

View file

@ -53,7 +53,6 @@ Item {
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.rightMargin: 5
placeholderText: qsTr("Filter...")
category: "all"
}

View file

@ -282,9 +282,10 @@ Item {
x: picker.mouseX - width - 5
y: picker.mouseY - height - 5
color: 'black'
property double axisX: Modules.Canvas.axesStep.x.value
property double axisY: Modules.Canvas.axesStep.y.value
property double mouseX: {
const axisX = Modules.Canvas.axesSteps.x.value
const xpos = Modules.Canvas.px2x(picker.mouseX)
let xpos = Modules.Canvas.px2x(picker.mouseX)
if(snapToGridCheckbox.checked) {
if(canvas.logscalex) {
// Calculate the logged power
@ -298,8 +299,7 @@ Item {
}
}
property double mouseY: {
const axisY = Modules.Canvas.axesSteps.y.value
const ypos = Modules.Canvas.px2y(picker.mouseY)
let ypos = Modules.Canvas.px2y(picker.mouseY)
if(snapToGridCheckbox.checked) {
return axisY*Math.round(ypos/axisY)
} else {

View file

@ -102,7 +102,7 @@ Item {
anchors.leftMargin: icon == "" ? 0 : 5
anchors.top: parent.top
height: parent.height
width: visible ? Math.max(85, implicitWidth) : 0
width: Math.max(85, implicitWidth)
verticalAlignment: TextInput.AlignVCenter
//color: sysPalette.windowText
text: visible ? qsTranslate("control", "%1: ").arg(control.label) : ""

View file

@ -133,19 +133,10 @@ export default class GainBode extends ExecutableObject {
update() {
super.update()
let sumObjs = Objects.currentObjects['Somme gains Bode']
if(sumObjs !== undefined && sumObjs.length > 0) {
sumObjs[0].recalculateCache()
if(Objects.currentObjects['Somme gains Bode'] !== undefined && Objects.currentObjects['Somme gains Bode'].length > 0) {
Objects.currentObjects['Somme gains Bode'][0].recalculateCache()
} else {
Objects.createNewRegisteredObject('Somme gains Bode')
}
}
delete() {
super.delete()
let sumObjs = Objects.currentObjects['Somme gains Bode']
if(sumObjs !== undefined && sumObjs.length > 0) {
sumObjs[0].recalculateCache()
}
}
}

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Range, Expression, Domain } from "../mathlib.mjs"
import { parseDomain, Expression, Domain } from "../mathlib.mjs"
import * as P from "../parameters.mjs"
import Objects from "../objects.mjs"
import Latex from "../math/latex.mjs"
@ -53,9 +53,9 @@ export default class SommeGainsBode extends ExecutableObject {
}
execute(x = 0) {
for(let [limitedDrawFunction, inDrawDom] of this.cachedParts) {
for(let [dbfn, inDrawDom] of this.cachedParts) {
if(inDrawDom.includes(x)) {
return limitedDrawFunction.execute(x)
return dbfn.execute(x)
}
}
return null
@ -66,9 +66,9 @@ export default class SommeGainsBode extends ExecutableObject {
}
simplify(x = 1) {
for(let [limitedDrawFunction, inDrawDom] of this.cachedParts) {
for(let [dbfn, inDrawDom] of this.cachedParts) {
if(inDrawDom.includes(x)) {
return limitedDrawFunction.simplify(x)
return dbfn.simplify(x)
}
}
return ''
@ -77,65 +77,61 @@ export default class SommeGainsBode extends ExecutableObject {
recalculateCache() {
this.cachedParts = []
// Calculating this is fairly resource expansive so it's cached.
let magnitudeObjects = Objects.currentObjects['Gain Bode']
if(magnitudeObjects === undefined || magnitudeObjects.length < 1) {
Objects.deleteObject(this.name)
} else {
if(Objects.currentObjects['Gain Bode'] !== undefined) {
console.log('Recalculating cache gain')
// Minimum to draw (can be expended if needed, just not infinite or it'll cause issues.
const MIN_DRAW = 1e-20
// Format: [[x value of where the filter transitions, magnitude, high-pass (bool)]]
const magnitudes = []
const XVALUE = 0
const MAGNITUDE = 1
const PASS = 2
magnitudes.push([Number.MAX_VALUE, 0, true]) // Draw the ending section
// Collect data from current magnitude (or gain in French) objects.
let drawMin = 0.001
let baseY = 0
for(/** @type {GainBode} */ let magnitudeObj of magnitudeObjects) { // Sorting by their om_0 position.
const om0x = magnitudeObj.om_0.x.execute()
magnitudes.push([om0x, magnitudeObj.gain.execute(), magnitudeObj.pass === 'high'])
baseY += magnitudeObj.execute(MIN_DRAW)
}
// Sorting the data by their x transitions value
magnitudes.sort((a,b) => a[XVALUE] - b[XVALUE])
// Adding the total gains.
let magnitudesBeforeTransition = []
let magnitudesAfterTransition = []
let totalMagnitudeAtStart = 0 // Magnitude at the lowest x value (sum of all high-pass magnitudes)
for(let [om0x, magnitude, highpass] of magnitudes){
if(highpass) {
magnitudesBeforeTransition.push(magnitude)
magnitudesAfterTransition.push(0)
totalMagnitudeAtStart += magnitude
let om0xGains = {1000000000: 0} // To draw the last part
let om0xPass = {1000000000: 'high'} // To draw the last part
for(/** @type {GainBode} */ let gainObj of Objects.currentObjects['Gain Bode']) { // Sorting by their om_0 position.
let om0x = gainObj.om_0.x.execute()
if(om0xGains[om0x] === undefined) {
om0xGains[om0x] = gainObj.gain.execute()
om0xPass[om0x] = gainObj.pass === 'high'
} else {
magnitudesBeforeTransition.push(0)
magnitudesAfterTransition.push(magnitude)
om0xGains[om0x+0.001] = gainObj.gain.execute()
om0xPass[om0x+0.001] = gainObj.pass === 'high'
}
baseY += gainObj.execute(drawMin)
}
// Sorting the om_0x
let om0xList = Object.keys(om0xGains).map(x => parseFloat(x)) // THEY WERE CONVERTED TO STRINGS...
om0xList.sort((a,b) => a - b)
// Adding the total gains.
let gainsBeforeP = []
let gainsAfterP = []
let gainTotal = 0
for(let om0x of om0xList){
if(om0xPass[om0x]) { // High-pass
gainsBeforeP.push(om0xGains[om0x])
gainsAfterP.push(0)
gainTotal += om0xGains[om0x] // Gain at first
} else {
gainsBeforeP.push(0)
gainsAfterP.push(om0xGains[om0x])
}
}
// Calculating parts
let previousTransitionX = MIN_DRAW
let currentMagnitude = totalMagnitudeAtStart
for(let transitionID = 0; transitionID < magnitudes.length; transitionID++) {
const transitionX = magnitudes[transitionID][XVALUE]
// Create draw function that will be used during drawing.
const limitedDrawFunction = new Expression(`${currentMagnitude}*(ln(x)-ln(${previousTransitionX}))/ln(10)+${baseY}`)
const drawDomain = new Range(previousTransitionX, transitionX, true, false)
this.cachedParts.push([limitedDrawFunction, drawDomain])
// Prepare default values for next function.
previousTransitionX = transitionX
baseY = limitedDrawFunction.execute(transitionX)
currentMagnitude += magnitudesAfterTransition[transitionID] - magnitudesBeforeTransition[transitionID]
let previousPallier = drawMin
for(let pallier = 0; pallier < om0xList.length; pallier++) {
let dbfn = new Expression(`${gainTotal}*(ln(x)-ln(${previousPallier}))/ln(10)+${baseY}`)
let inDrawDom = parseDomain(`]${previousPallier};${om0xList[pallier]}]`)
this.cachedParts.push([dbfn, inDrawDom])
previousPallier = om0xList[pallier]
baseY = dbfn.execute(om0xList[pallier])
gainTotal += gainsAfterP[pallier] - gainsBeforeP[pallier]
}
}
}
draw(canvas) {
if(this.cachedParts.length > 0) {
for(let [limitedDrawFunction, drawDomain] of this.cachedParts) {
Function.drawFunction(canvas, limitedDrawFunction, drawDomain, Domain.R)
// Check if necessary to draw label
if(drawDomain.includes(this.labelX)) {
for(let [dbfn, inDrawDom] of this.cachedParts) {
Function.drawFunction(canvas, dbfn, inDrawDom, Domain.R)
if(inDrawDom.includes(this.labelX)) {
// Label
this.drawLabel(canvas, this.labelPosition, canvas.x2px(this.labelX), canvas.y2px(this.execute(this.labelX)))
}
}