Starting Sequences!
This commit is contained in:
parent
8aa6ac7e88
commit
05e51fdd73
7 changed files with 57 additions and 18 deletions
|
@ -41,7 +41,7 @@ Item {
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
verticalAlignment: TextInput.AlignVCenter
|
verticalAlignment: TextInput.AlignVCenter
|
||||||
color: sysPalette.windowText
|
color: sysPalette.windowText
|
||||||
text: " "+ control.label +": "
|
text: control.label +": "
|
||||||
}
|
}
|
||||||
|
|
||||||
ComboBox {
|
ComboBox {
|
||||||
|
|
|
@ -140,7 +140,7 @@ ApplicationWindow {
|
||||||
|
|
||||||
function loadDiagram(filename) {
|
function loadDiagram(filename) {
|
||||||
var data = JSON.parse(Helper.load(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.xzoom = data["xzoom"]
|
||||||
settings.yzoom = data["yzoom"]
|
settings.yzoom = data["yzoom"]
|
||||||
settings.xmin = data["xmin"]
|
settings.xmin = data["xmin"]
|
||||||
|
|
|
@ -263,13 +263,22 @@ ListView {
|
||||||
width: dlgProperties.width
|
width: dlgProperties.width
|
||||||
property string label: Utils.camelCase2readable(modelData[0])
|
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 {
|
TextSetting {
|
||||||
id: customPropText
|
id: customPropText
|
||||||
height: 30
|
height: 30
|
||||||
width: parent.width
|
width: parent.width
|
||||||
label: parent.label
|
label: parent.label
|
||||||
isDouble: modelData[1] == 'number'
|
isDouble: modelData[1] == 'number'
|
||||||
visible: ['Expression', 'Domain', 'string', 'number'].indexOf(modelData[1]) >= 0
|
visible: modelData[1] in ['Expression', 'Domain', 'string', 'number']
|
||||||
defValue: visible ? {
|
defValue: visible ? {
|
||||||
'Expression': () => Utils.simplifyExpression(objEditor.obj[modelData[0]].toEditableString()),
|
'Expression': () => Utils.simplifyExpression(objEditor.obj[modelData[0]].toEditableString()),
|
||||||
'Domain': () => objEditor.obj[modelData[0]].toString(),
|
'Domain': () => objEditor.obj[modelData[0]].toString(),
|
||||||
|
@ -286,9 +295,6 @@ ListView {
|
||||||
Objects.currentObjects[objEditor.objType][objEditor.objIndex].update()
|
Objects.currentObjects[objEditor.objType][objEditor.objIndex].update()
|
||||||
objectListList.update()
|
objectListList.update()
|
||||||
}
|
}
|
||||||
Component.onCompleted: {
|
|
||||||
//console.log(modelData[0], objEditor.obj[modelData[0]],modelData[1], defValue)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckBox {
|
CheckBox {
|
||||||
|
@ -310,7 +316,7 @@ ListView {
|
||||||
width: dlgProperties.width
|
width: dlgProperties.width
|
||||||
label: parent.label
|
label: parent.label
|
||||||
// True to select an object of type, false for enums.
|
// 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 ?
|
model: visible ?
|
||||||
(selectObjMode ? Objects.getObjectsName(modelData[1]).concat(['+ Create new ' + modelData[1]]) : modelData[1])
|
(selectObjMode ? Objects.getObjectsName(modelData[1]).concat(['+ Create new ' + modelData[1]]) : modelData[1])
|
||||||
: []
|
: []
|
||||||
|
|
|
@ -37,7 +37,7 @@ Item {
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
verticalAlignment: TextInput.AlignVCenter
|
verticalAlignment: TextInput.AlignVCenter
|
||||||
color: sysPalette.windowText
|
color: sysPalette.windowText
|
||||||
text: " "+ control.label +": "
|
text: control.label +": "
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,13 +23,17 @@
|
||||||
|
|
||||||
const parser = new ExprEval.Parser()
|
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
|
var evalVariables = { // Variables not provided by expr-eval.js, needs to be provided manualy
|
||||||
"pi": Math.PI,
|
"pi": Math.PI,
|
||||||
"π": Math.PI,
|
"π": Math.PI,
|
||||||
"inf": Infinity,
|
"inf": Infinity,
|
||||||
"Infinity": Infinity,
|
"Infinity": Infinity,
|
||||||
"∞": Infinity,
|
"∞": Infinity,
|
||||||
"e": Math.E
|
"e": Math.E,
|
||||||
|
"E": Math.E
|
||||||
}
|
}
|
||||||
|
|
||||||
class Expression {
|
class Expression {
|
||||||
|
@ -64,10 +68,7 @@ class Expression {
|
||||||
}
|
}
|
||||||
|
|
||||||
toString(forceSign=false) {
|
toString(forceSign=false) {
|
||||||
var str = this.calc.toString()
|
var str = Utils.makeExpressionReadable(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)
|
|
||||||
if(str[0] != '-' && forceSign) str = '+' + str
|
if(str[0] != '-' && forceSign) str = '+' + str
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
@ -77,6 +78,34 @@ function executeExpression(expr){
|
||||||
return (new Expression(expr.toString())).execute()
|
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
|
// Domains
|
||||||
class Domain {
|
class Domain {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
|
@ -203,6 +203,7 @@ class Function extends ExecutableObject {
|
||||||
'expression': 'Expression',
|
'expression': 'Expression',
|
||||||
'inDomain': 'Domain',
|
'inDomain': 'Domain',
|
||||||
'outDomain': 'Domain',
|
'outDomain': 'Domain',
|
||||||
|
'comment1': 'Ex: R+* (ℝ⁺*), N* (ℕ*), Z-* (ℤ⁻*), ]0;1[, {3;4;5}',
|
||||||
'labelPosition': ['above', 'below'],
|
'labelPosition': ['above', 'below'],
|
||||||
'displayMode': ['application', 'function'],
|
'displayMode': ['application', 'function'],
|
||||||
'labelX': 'number'
|
'labelX': 'number'
|
||||||
|
@ -280,8 +281,6 @@ class Function extends ExecutableObject {
|
||||||
var pxprecision = 2
|
var pxprecision = 2
|
||||||
var previousX = canvas.px2x(0)
|
var previousX = canvas.px2x(0)
|
||||||
var previousY;
|
var previousY;
|
||||||
var draw = function(currentX) {
|
|
||||||
}
|
|
||||||
if(inDomain instanceof MathLib.SpecialDomain && inDomain.moveSupported) {
|
if(inDomain instanceof MathLib.SpecialDomain && inDomain.moveSupported) {
|
||||||
previousX = inDomain.previous(previousX)
|
previousX = inDomain.previous(previousX)
|
||||||
if(previousX === null) previousX = inDomain.next(canvas.px2x(0))
|
if(previousX === null) previousX = inDomain.next(canvas.px2x(0))
|
||||||
|
@ -924,6 +923,8 @@ class CursorX extends DrawableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const types = {
|
const types = {
|
||||||
'Point': Point,
|
'Point': Point,
|
||||||
'Function': Function,
|
'Function': Function,
|
||||||
|
|
|
@ -207,8 +207,10 @@ function makeExpressionReadable(str) {
|
||||||
[/ \^ /g, '^'],
|
[/ \^ /g, '^'],
|
||||||
[/\^\(([^\^]+)\)/g, function(match, p1) { return textsup(p1) }],
|
[/\^\(([^\^]+)\)/g, function(match, p1) { return textsup(p1) }],
|
||||||
[/\^([^ ]+)/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'],
|
//[/×(\d|\()/g, '$1'],
|
||||||
[/\(([^)(+.\/-]+)\)/g, "$1"],
|
[/\(([^)(+.\/-]+)\)/g, "$1"],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -258,8 +260,10 @@ function parseName(str, removeUnallowed = true) {
|
||||||
[/([^a-z]|^)gps(i)?([^a-z]|$)/g, '$1Ψ$3'],
|
[/([^a-z]|^)gps(i)?([^a-z]|$)/g, '$1Ψ$3'],
|
||||||
[/([^a-z]|^)gom(ega)?([^a-z]|$)/g, '$1Ω$3'],
|
[/([^a-z]|^)gom(ega)?([^a-z]|$)/g, '$1Ω$3'],
|
||||||
// Underscores
|
// Underscores
|
||||||
[/_\(([^\^]+)\)/g, function(match, p1) { return textsub(p1) }],
|
[/_\(([^_]+)\)/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
|
// Removing
|
||||||
[/[xπℝℕ\\∪∩\]\[ ()^/÷*×+=\d-]/g , ''],
|
[/[xπℝℕ\\∪∩\]\[ ()^/÷*×+=\d-]/g , ''],
|
||||||
]
|
]
|
||||||
|
@ -271,7 +275,6 @@ function parseName(str, removeUnallowed = true) {
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String.prototype.toLatinUppercase = function() {
|
String.prototype.toLatinUppercase = function() {
|
||||||
return this.replace(/[a-z]/g, function(match){return match.toUpperCase()})
|
return this.replace(/[a-z]/g, function(match){return match.toUpperCase()})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue