Compare commits
No commits in common. "a16f02fd5f18f902557a097451ea0fc301707599" and "ef14db8bbb16d7edf7481f715c3fb10f74650e20" have entirely different histories.
a16f02fd5f
...
ef14db8bbb
5 changed files with 54 additions and 68 deletions
|
@ -53,7 +53,6 @@ Item {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.rightMargin: 5
|
|
||||||
placeholderText: qsTr("Filter...")
|
placeholderText: qsTr("Filter...")
|
||||||
category: "all"
|
category: "all"
|
||||||
}
|
}
|
||||||
|
|
|
@ -282,9 +282,10 @@ Item {
|
||||||
x: picker.mouseX - width - 5
|
x: picker.mouseX - width - 5
|
||||||
y: picker.mouseY - height - 5
|
y: picker.mouseY - height - 5
|
||||||
color: 'black'
|
color: 'black'
|
||||||
|
property double axisX: Modules.Canvas.axesStep.x.value
|
||||||
|
property double axisY: Modules.Canvas.axesStep.y.value
|
||||||
property double mouseX: {
|
property double mouseX: {
|
||||||
const axisX = Modules.Canvas.axesSteps.x.value
|
let xpos = Modules.Canvas.px2x(picker.mouseX)
|
||||||
const xpos = Modules.Canvas.px2x(picker.mouseX)
|
|
||||||
if(snapToGridCheckbox.checked) {
|
if(snapToGridCheckbox.checked) {
|
||||||
if(canvas.logscalex) {
|
if(canvas.logscalex) {
|
||||||
// Calculate the logged power
|
// Calculate the logged power
|
||||||
|
@ -298,8 +299,7 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
property double mouseY: {
|
property double mouseY: {
|
||||||
const axisY = Modules.Canvas.axesSteps.y.value
|
let ypos = Modules.Canvas.px2y(picker.mouseY)
|
||||||
const ypos = Modules.Canvas.px2y(picker.mouseY)
|
|
||||||
if(snapToGridCheckbox.checked) {
|
if(snapToGridCheckbox.checked) {
|
||||||
return axisY*Math.round(ypos/axisY)
|
return axisY*Math.round(ypos/axisY)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -102,7 +102,7 @@ Item {
|
||||||
anchors.leftMargin: icon == "" ? 0 : 5
|
anchors.leftMargin: icon == "" ? 0 : 5
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
height: parent.height
|
height: parent.height
|
||||||
width: visible ? Math.max(85, implicitWidth) : 0
|
width: Math.max(85, implicitWidth)
|
||||||
verticalAlignment: TextInput.AlignVCenter
|
verticalAlignment: TextInput.AlignVCenter
|
||||||
//color: sysPalette.windowText
|
//color: sysPalette.windowText
|
||||||
text: visible ? qsTranslate("control", "%1: ").arg(control.label) : ""
|
text: visible ? qsTranslate("control", "%1: ").arg(control.label) : ""
|
||||||
|
|
|
@ -133,19 +133,10 @@ export default class GainBode extends ExecutableObject {
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
super.update()
|
super.update()
|
||||||
let sumObjs = Objects.currentObjects['Somme gains Bode']
|
if(Objects.currentObjects['Somme gains Bode'] !== undefined && Objects.currentObjects['Somme gains Bode'].length > 0) {
|
||||||
if(sumObjs !== undefined && sumObjs.length > 0) {
|
Objects.currentObjects['Somme gains Bode'][0].recalculateCache()
|
||||||
sumObjs[0].recalculateCache()
|
|
||||||
} else {
|
} else {
|
||||||
Objects.createNewRegisteredObject('Somme gains Bode')
|
Objects.createNewRegisteredObject('Somme gains Bode')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete() {
|
|
||||||
super.delete()
|
|
||||||
let sumObjs = Objects.currentObjects['Somme gains Bode']
|
|
||||||
if(sumObjs !== undefined && sumObjs.length > 0) {
|
|
||||||
sumObjs[0].recalculateCache()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* 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 * as P from "../parameters.mjs"
|
||||||
import Objects from "../objects.mjs"
|
import Objects from "../objects.mjs"
|
||||||
import Latex from "../math/latex.mjs"
|
import Latex from "../math/latex.mjs"
|
||||||
|
@ -53,9 +53,9 @@ export default class SommeGainsBode extends ExecutableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
execute(x = 0) {
|
execute(x = 0) {
|
||||||
for(let [limitedDrawFunction, inDrawDom] of this.cachedParts) {
|
for(let [dbfn, inDrawDom] of this.cachedParts) {
|
||||||
if(inDrawDom.includes(x)) {
|
if(inDrawDom.includes(x)) {
|
||||||
return limitedDrawFunction.execute(x)
|
return dbfn.execute(x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
|
@ -66,9 +66,9 @@ export default class SommeGainsBode extends ExecutableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
simplify(x = 1) {
|
simplify(x = 1) {
|
||||||
for(let [limitedDrawFunction, inDrawDom] of this.cachedParts) {
|
for(let [dbfn, inDrawDom] of this.cachedParts) {
|
||||||
if(inDrawDom.includes(x)) {
|
if(inDrawDom.includes(x)) {
|
||||||
return limitedDrawFunction.simplify(x)
|
return dbfn.simplify(x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ''
|
return ''
|
||||||
|
@ -77,65 +77,61 @@ export default class SommeGainsBode extends ExecutableObject {
|
||||||
recalculateCache() {
|
recalculateCache() {
|
||||||
this.cachedParts = []
|
this.cachedParts = []
|
||||||
// Calculating this is fairly resource expansive so it's cached.
|
// Calculating this is fairly resource expansive so it's cached.
|
||||||
let magnitudeObjects = Objects.currentObjects['Gain Bode']
|
if(Objects.currentObjects['Gain Bode'] !== undefined) {
|
||||||
if(magnitudeObjects === undefined || magnitudeObjects.length < 1) {
|
|
||||||
Objects.deleteObject(this.name)
|
|
||||||
} else {
|
|
||||||
console.log('Recalculating cache gain')
|
console.log('Recalculating cache gain')
|
||||||
// Minimum to draw (can be expended if needed, just not infinite or it'll cause issues.
|
// Minimum to draw (can be expended if needed, just not infinite or it'll cause issues.
|
||||||
const MIN_DRAW = 1e-20
|
let drawMin = 0.001
|
||||||
// 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 baseY = 0
|
let baseY = 0
|
||||||
for(/** @type {GainBode} */ let magnitudeObj of magnitudeObjects) { // Sorting by their om_0 position.
|
let om0xGains = {1000000000: 0} // To draw the last part
|
||||||
const om0x = magnitudeObj.om_0.x.execute()
|
let om0xPass = {1000000000: 'high'} // To draw the last part
|
||||||
magnitudes.push([om0x, magnitudeObj.gain.execute(), magnitudeObj.pass === 'high'])
|
for(/** @type {GainBode} */ let gainObj of Objects.currentObjects['Gain Bode']) { // Sorting by their om_0 position.
|
||||||
baseY += magnitudeObj.execute(MIN_DRAW)
|
let om0x = gainObj.om_0.x.execute()
|
||||||
}
|
if(om0xGains[om0x] === undefined) {
|
||||||
// Sorting the data by their x transitions value
|
om0xGains[om0x] = gainObj.gain.execute()
|
||||||
magnitudes.sort((a,b) => a[XVALUE] - b[XVALUE])
|
om0xPass[om0x] = gainObj.pass === 'high'
|
||||||
// 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
|
|
||||||
} else {
|
} else {
|
||||||
magnitudesBeforeTransition.push(0)
|
om0xGains[om0x+0.001] = gainObj.gain.execute()
|
||||||
magnitudesAfterTransition.push(magnitude)
|
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
|
// Calculating parts
|
||||||
let previousTransitionX = MIN_DRAW
|
let previousPallier = drawMin
|
||||||
let currentMagnitude = totalMagnitudeAtStart
|
for(let pallier = 0; pallier < om0xList.length; pallier++) {
|
||||||
for(let transitionID = 0; transitionID < magnitudes.length; transitionID++) {
|
let dbfn = new Expression(`${gainTotal}*(ln(x)-ln(${previousPallier}))/ln(10)+${baseY}`)
|
||||||
const transitionX = magnitudes[transitionID][XVALUE]
|
let inDrawDom = parseDomain(`]${previousPallier};${om0xList[pallier]}]`)
|
||||||
// Create draw function that will be used during drawing.
|
this.cachedParts.push([dbfn, inDrawDom])
|
||||||
const limitedDrawFunction = new Expression(`${currentMagnitude}*(ln(x)-ln(${previousTransitionX}))/ln(10)+${baseY}`)
|
previousPallier = om0xList[pallier]
|
||||||
const drawDomain = new Range(previousTransitionX, transitionX, true, false)
|
baseY = dbfn.execute(om0xList[pallier])
|
||||||
this.cachedParts.push([limitedDrawFunction, drawDomain])
|
gainTotal += gainsAfterP[pallier] - gainsBeforeP[pallier]
|
||||||
// Prepare default values for next function.
|
|
||||||
previousTransitionX = transitionX
|
|
||||||
baseY = limitedDrawFunction.execute(transitionX)
|
|
||||||
currentMagnitude += magnitudesAfterTransition[transitionID] - magnitudesBeforeTransition[transitionID]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
draw(canvas) {
|
draw(canvas) {
|
||||||
if(this.cachedParts.length > 0) {
|
if(this.cachedParts.length > 0) {
|
||||||
for(let [limitedDrawFunction, drawDomain] of this.cachedParts) {
|
for(let [dbfn, inDrawDom] of this.cachedParts) {
|
||||||
Function.drawFunction(canvas, limitedDrawFunction, drawDomain, Domain.R)
|
Function.drawFunction(canvas, dbfn, inDrawDom, Domain.R)
|
||||||
// Check if necessary to draw label
|
if(inDrawDom.includes(this.labelX)) {
|
||||||
if(drawDomain.includes(this.labelX)) {
|
// Label
|
||||||
this.drawLabel(canvas, this.labelPosition, canvas.x2px(this.labelX), canvas.y2px(this.execute(this.labelX)))
|
this.drawLabel(canvas, this.labelPosition, canvas.x2px(this.labelX), canvas.y2px(this.execute(this.labelX)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue