Starting Sequences!

This commit is contained in:
Adsooi 2020-12-25 20:42:13 +01:00
parent 8aa6ac7e88
commit 05e51fdd73
7 changed files with 57 additions and 18 deletions

View file

@ -41,7 +41,7 @@ Item {
anchors.top: parent.top
verticalAlignment: TextInput.AlignVCenter
color: sysPalette.windowText
text: " "+ control.label +": "
text: control.label +": "
}
ComboBox {

View file

@ -140,7 +140,7 @@ ApplicationWindow {
function loadDiagram(filename) {
var data = JSON.parse(Helper.load(filename))
if(Object.keys(data).indexOf("type") != -1 && data["type"] == "logplotv1") {
if("type" in Object.keys(data) && data["type"] == "logplotv1") {
settings.xzoom = data["xzoom"]
settings.yzoom = data["yzoom"]
settings.xmin = data["xmin"]

View file

@ -263,13 +263,22 @@ ListView {
width: dlgProperties.width
property string label: Utils.camelCase2readable(modelData[0])
Text {
id: customPropComment
height: 30
width: parent.width
visible: modelData[0].startsWith('comment')
text: modelData[1]
color: sysPalette.windowText
}
TextSetting {
id: customPropText
height: 30
width: parent.width
label: parent.label
isDouble: modelData[1] == 'number'
visible: ['Expression', 'Domain', 'string', 'number'].indexOf(modelData[1]) >= 0
visible: modelData[1] in ['Expression', 'Domain', 'string', 'number']
defValue: visible ? {
'Expression': () => Utils.simplifyExpression(objEditor.obj[modelData[0]].toEditableString()),
'Domain': () => objEditor.obj[modelData[0]].toString(),
@ -286,9 +295,6 @@ ListView {
Objects.currentObjects[objEditor.objType][objEditor.objIndex].update()
objectListList.update()
}
Component.onCompleted: {
//console.log(modelData[0], objEditor.obj[modelData[0]],modelData[1], defValue)
}
}
CheckBox {
@ -310,7 +316,7 @@ ListView {
width: dlgProperties.width
label: parent.label
// True to select an object of type, false for enums.
property bool selectObjMode: (typeof modelData[1] == "string" && Object.keys(Objects.types).indexOf(modelData[1]) >= 0)
property bool selectObjMode: (typeof modelData[1] == "string" && modelData[1] in Object.keys(Objects.types))
model: visible ?
(selectObjMode ? Objects.getObjectsName(modelData[1]).concat(['+ Create new ' + modelData[1]]) : modelData[1])
: []

View file

@ -37,7 +37,7 @@ Item {
anchors.top: parent.top
verticalAlignment: TextInput.AlignVCenter
color: sysPalette.windowText
text: " "+ control.label +": "
text: control.label +": "
}

View file

@ -23,13 +23,17 @@
const parser = new ExprEval.Parser()
var u = {1: 1, 2: 2, 3: 3}
console.log(parser.parse('u[n]+u[n+1]+u[n+2]').simplify().evaluate({"u": u, 'n': 1}))
var evalVariables = { // Variables not provided by expr-eval.js, needs to be provided manualy
"pi": Math.PI,
"π": Math.PI,
"inf": Infinity,
"Infinity": Infinity,
"∞": Infinity,
"e": Math.E
"e": Math.E,
"E": Math.E
}
class Expression {
@ -64,10 +68,7 @@ class Expression {
}
toString(forceSign=false) {
var str = this.calc.toString()
if(str[0] == "(") str = str.substr(1)
if(str[str.length - 1] == ")") str = str.substr(0, str.length - 1)
str = Utils.makeExpressionReadable(str)
var str = Utils.makeExpressionReadable(this.calc.toString())
if(str[0] != '-' && forceSign) str = '+' + str
return str
}
@ -77,6 +78,34 @@ function executeExpression(expr){
return (new Expression(expr.toString())).execute()
}
class Sequence extends Expression {
constructor(name, baseValues = {}, expr) {
console.log('Expression', expr)
super(expr)
this.name = name
this.baseValues = baseValues
}
isConstant() {
return this.expr.indexOf("n") == -1
}
execute(n = 0) {
if(this.cached) return this.cachedValue
if(n in this.baseValues) return this.baseValues[n]
var vars = Object.assign({'n': n-1}, evalVariables)
vars[this.name] = this.baseValues
var un = this.calc.evaluate(vars)
this.baseValues[n] = un
return un
}
}
var test = new Sequence('u', {0: 0}, '3*u[n]+3')
console.log(test)
for(var i=0; i<20; i++)
console.log('u' + Utils.textsub(i) + ' = ' + test.execute(i))
// Domains
class Domain {
constructor() {}

View file

@ -203,6 +203,7 @@ class Function extends ExecutableObject {
'expression': 'Expression',
'inDomain': 'Domain',
'outDomain': 'Domain',
'comment1': 'Ex: R+* (ℝ⁺*), N* (*), Z-* (ℤ⁻*), ]0;1[, {3;4;5}',
'labelPosition': ['above', 'below'],
'displayMode': ['application', 'function'],
'labelX': 'number'
@ -280,8 +281,6 @@ class Function extends ExecutableObject {
var pxprecision = 2
var previousX = canvas.px2x(0)
var previousY;
var draw = function(currentX) {
}
if(inDomain instanceof MathLib.SpecialDomain && inDomain.moveSupported) {
previousX = inDomain.previous(previousX)
if(previousX === null) previousX = inDomain.next(canvas.px2x(0))
@ -924,6 +923,8 @@ class CursorX extends DrawableObject {
}
}
const types = {
'Point': Point,
'Function': Function,

View file

@ -207,8 +207,10 @@ function makeExpressionReadable(str) {
[/ \^ /g, '^'],
[/\^\(([^\^]+)\)/g, function(match, p1) { return textsup(p1) }],
[/\^([^ ]+)/g, function(match, p1) { return textsup(p1) }],
[/_\(([^_]+)\)/g, function(match, p1) { return textsub(p1) }],
[/_([^ ]+)/g, function(match, p1) { return textsub(p1) }],
[/(\d|\))×/g, '$1'],
[/×(\d|\()/g, '$1'],
//[/×(\d|\()/g, '$1'],
[/\(([^)(+.\/-]+)\)/g, "$1"],
]
@ -258,8 +260,10 @@ function parseName(str, removeUnallowed = true) {
[/([^a-z]|^)gps(i)?([^a-z]|$)/g, '$1Ψ$3'],
[/([^a-z]|^)gom(ega)?([^a-z]|$)/g, '$1Ω$3'],
// Underscores
[/_\(([^\^]+)\)/g, function(match, p1) { return textsub(p1) }],
[/_\(([^_]+)\)/g, function(match, p1) { return textsub(p1) }],
[/_([^ ]+)/g, function(match, p1) { return textsub(p1) }],
// Array elements
[/\[([^\]\[]+)\]/g, function(match, p1) { return textsub(p1) }],
// Removing
[/[xπ\\∪∩\]\[ ()^/÷*×+=\d-]/g , ''],
]
@ -271,7 +275,6 @@ function parseName(str, removeUnallowed = true) {
return str
}
String.prototype.toLatinUppercase = function() {
return this.replace(/[a-z]/g, function(match){return match.toUpperCase()})
}