Compare commits
3 commits
d6a83b0f4b
...
7408520819
Author | SHA1 | Date | |
---|---|---|---|
7408520819 | |||
9f2b08b938 | |||
3039aade29 |
4 changed files with 44 additions and 18 deletions
|
@ -26,7 +26,8 @@ var ADDITIONAL_VARCHARS = [
|
||||||
"ₕ","ₖ","ₗ","ₘ","ₙ","ₚ","ₛ",
|
"ₕ","ₖ","ₗ","ₘ","ₙ","ₚ","ₛ",
|
||||||
"ₜ","¹","²","³","⁴","⁵","⁶",
|
"ₜ","¹","²","³","⁴","⁵","⁶",
|
||||||
"⁷","⁸","⁹","⁰","₁","₂","₃",
|
"⁷","⁸","⁹","⁰","₁","₂","₃",
|
||||||
"₄","₅","₆","₇","₈","₉","₀"
|
"₄","₅","₆","₇","₈","₉","₀",
|
||||||
|
"∞"
|
||||||
]
|
]
|
||||||
|
|
||||||
function Instruction(type, value) {
|
function Instruction(type, value) {
|
||||||
|
@ -691,7 +692,7 @@ TokenStream.prototype.isConst = function () {
|
||||||
var i = startPos;
|
var i = startPos;
|
||||||
for (; i < this.expression.length; i++) {
|
for (; i < this.expression.length; i++) {
|
||||||
var c = this.expression.charAt(i);
|
var c = this.expression.charAt(i);
|
||||||
if (c.toUpperCase() === c.toLowerCase()) {
|
if (c.toUpperCase() === c.toLowerCase() && !ADDITIONAL_VARCHARS.includes(c)) {
|
||||||
if (i === this.pos || (c !== '_' && c !== '.' && (c < '0' || c > '9'))) {
|
if (i === this.pos || (c !== '_' && c !== '.' && (c < '0' || c > '9'))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -437,8 +437,8 @@ class UnionDomain extends Domain {
|
||||||
static import(frm) {
|
static import(frm) {
|
||||||
var domains = frm.trim().split("∪")
|
var domains = frm.trim().split("∪")
|
||||||
if(domains.length == 1) domains = frm.trim().split("U") // Fallback
|
if(domains.length == 1) domains = frm.trim().split("U") // Fallback
|
||||||
var dom1 = parseDomain(domains.pop())
|
var dom2 = parseDomain(domains.pop())
|
||||||
var dom2 = parseDomain(domains.join('∪'))
|
var dom1 = parseDomain(domains.join('∪'))
|
||||||
return dom1.union(dom2)
|
return dom1.union(dom2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ function variable(vari, wrapIn$ = false) {
|
||||||
"ₜ","¹","²","³","⁴","⁵","⁶",
|
"ₜ","¹","²","³","⁴","⁵","⁶",
|
||||||
"⁷","⁸","⁹","⁰","₁","₂","₃",
|
"⁷","⁸","⁹","⁰","₁","₂","₃",
|
||||||
"₄","₅","₆","₇","₈","₉","₀",
|
"₄","₅","₆","₇","₈","₉","₀",
|
||||||
"pi"]
|
"pi", "∞"]
|
||||||
let equivalchars = ["\\alpha","\\beta","\\gamma","\\delta","\\epsilon","\\zeta","\\eta",
|
let equivalchars = ["\\alpha","\\beta","\\gamma","\\delta","\\epsilon","\\zeta","\\eta",
|
||||||
"\\pi","\\theta","\\kappa","\\lambda","\\mu","\\xi","\\rho",
|
"\\pi","\\theta","\\kappa","\\lambda","\\mu","\\xi","\\rho",
|
||||||
"\\sigma","\\sigma","\\tau","\\phi","\\chi","\\psi","\\omega",
|
"\\sigma","\\sigma","\\tau","\\phi","\\chi","\\psi","\\omega",
|
||||||
|
@ -124,7 +124,7 @@ function variable(vari, wrapIn$ = false) {
|
||||||
"{}_{t}","{}^{1}","{}^{2}","{}^{3}","{}^{4}","{}^{5}","{}^{6}",
|
"{}_{t}","{}^{1}","{}^{2}","{}^{3}","{}^{4}","{}^{5}","{}^{6}",
|
||||||
"{}^{7}","{}^{8}","{}^{9}","{}^{0}","{}_{1}","{}_{2}","{}_{3}",
|
"{}^{7}","{}^{8}","{}^{9}","{}^{0}","{}_{1}","{}_{2}","{}_{3}",
|
||||||
"{}_{4}","{}_{5}","{}_{6}","{}_{7}","{}_{8}","{}_{9}","{}_{0}",
|
"{}_{4}","{}_{5}","{}_{6}","{}_{7}","{}_{8}","{}_{9}","{}_{0}",
|
||||||
"\\pi"]
|
"\\pi", "\\infty"]
|
||||||
if(wrapIn$)
|
if(wrapIn$)
|
||||||
for(let i = 0; i < unicodechars.length; i++) {
|
for(let i = 0; i < unicodechars.length; i++) {
|
||||||
if(vari.includes(unicodechars[i]))
|
if(vari.includes(unicodechars[i]))
|
||||||
|
|
|
@ -115,9 +115,9 @@ class Function extends Common.ExecutableObject {
|
||||||
static drawFunction(canvas, ctx, expr, definitionDomain, destinationDomain, drawPoints = true, drawDash = true) {
|
static drawFunction(canvas, ctx, expr, definitionDomain, destinationDomain, drawPoints = true, drawDash = true) {
|
||||||
// Reusable in other objects.
|
// Reusable in other objects.
|
||||||
// Drawing small traits every 0.2px
|
// Drawing small traits every 0.2px
|
||||||
var pxprecision = 1
|
var pxprecision = 10
|
||||||
var previousX = canvas.px2x(0)
|
var previousX = canvas.px2x(0)
|
||||||
var previousY;
|
var previousY = null;
|
||||||
if(definitionDomain instanceof MathLib.SpecialDomain && definitionDomain.moveSupported) {
|
if(definitionDomain instanceof MathLib.SpecialDomain && definitionDomain.moveSupported) {
|
||||||
// Point based functions.
|
// Point based functions.
|
||||||
previousX = definitionDomain.next(previousX)
|
previousX = definitionDomain.next(previousX)
|
||||||
|
@ -147,17 +147,42 @@ class Function extends Common.ExecutableObject {
|
||||||
ctx.fillRect(canvas.x2px(previousX)-1, canvas.y2px(previousY)-5, 2, 10)
|
ctx.fillRect(canvas.x2px(previousX)-1, canvas.y2px(previousY)-5, 2, 10)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if(definitionDomain.includes(previousX))
|
||||||
|
// PreviousY at the start of the canvas
|
||||||
previousY = expr.execute(previousX)
|
previousY = expr.execute(previousX)
|
||||||
for(var px = pxprecision; px < canvas.canvasSize.width; px += pxprecision) {
|
for(let px = pxprecision; px < canvas.canvasSize.width; px += pxprecision) {
|
||||||
var currentX = canvas.px2x(px)
|
let currentX = canvas.px2x(px)
|
||||||
var currentY = expr.execute(currentX)
|
if(!definitionDomain.includes(previousX) && definitionDomain.includes(currentX)) {
|
||||||
if((definitionDomain.includes(currentX) || definitionDomain.includes(previousX)) &&
|
// Should draw up to currentX, but NOT at previousX.
|
||||||
(destinationDomain.includes(currentY) || destinationDomain.includes(previousY)) &&
|
// Need to find the starting point.
|
||||||
Math.abs(previousY-currentY)<100) {
|
let tmpPx = px-pxprecision
|
||||||
|
do {
|
||||||
|
tmpPx++;
|
||||||
|
previousX = canvas.px2x(tmpPx)
|
||||||
|
} while(!definitionDomain.includes(previousX))
|
||||||
|
// Recaclulate previousY
|
||||||
|
previousY = expr.execute(previousX)
|
||||||
|
} else if(!definitionDomain.includes(currentX)) {
|
||||||
|
// Next x is NOT in the definition domain.
|
||||||
|
// Augmenting the pixel precision until this condition is fulfilled.
|
||||||
|
let tmpPx = px
|
||||||
|
do {
|
||||||
|
tmpPx--;
|
||||||
|
currentX = canvas.px2x(tmpPx)
|
||||||
|
} while(!definitionDomain.includes(currentX) && currentX != previousX)
|
||||||
|
}
|
||||||
|
if(definitionDomain.includes(previousX) && definitionDomain.includes(currentX)) {
|
||||||
|
let currentY = expr.execute(currentX)
|
||||||
|
if(destinationDomain.includes(currentY)) {
|
||||||
|
if(previousY != null && destinationDomain.includes(previousY)) {
|
||||||
canvas.drawLine(ctx, canvas.x2px(previousX), canvas.y2px(previousY), canvas.x2px(currentX), canvas.y2px(currentY))
|
canvas.drawLine(ctx, canvas.x2px(previousX), canvas.y2px(previousY), canvas.x2px(currentX), canvas.y2px(currentY))
|
||||||
}
|
}
|
||||||
previousX = currentX
|
}
|
||||||
previousY = currentY
|
previousY = currentY
|
||||||
|
} else {
|
||||||
|
previousY = null // Last y was invalid, so let's not draw anything from it.
|
||||||
|
}
|
||||||
|
previousX = canvas.px2x(px)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue