Improving stability of Function drawing.
This commit is contained in:
parent
8da10497d2
commit
f52ee65c56
1 changed files with 6 additions and 4 deletions
|
@ -122,7 +122,9 @@ export default class Function extends ExecutableObject {
|
||||||
*/
|
*/
|
||||||
static drawFunction(canvas, expr, definitionDomain, destinationDomain, drawPoints = true, drawDash = true) {
|
static drawFunction(canvas, expr, definitionDomain, destinationDomain, drawPoints = true, drawDash = true) {
|
||||||
let pxprecision = 10
|
let pxprecision = 10
|
||||||
let previousX = canvas.px2x(0)
|
const startDrawFrom = canvas.x2px(1)%pxprecision-pxprecision
|
||||||
|
let previousX = canvas.px2x(startDrawFrom)
|
||||||
|
// console.log("Starting draw from", previousX, startDrawFrom, canvas.x2px(1))
|
||||||
let previousY = null
|
let previousY = null
|
||||||
if(definitionDomain instanceof SpecialDomain && definitionDomain.moveSupported) {
|
if(definitionDomain instanceof SpecialDomain && definitionDomain.moveSupported) {
|
||||||
// Point based functions.
|
// Point based functions.
|
||||||
|
@ -160,7 +162,7 @@ export default class Function extends ExecutableObject {
|
||||||
// Calculate the previousY at the start of the canvas
|
// Calculate the previousY at the start of the canvas
|
||||||
if(definitionDomain.includes(previousX))
|
if(definitionDomain.includes(previousX))
|
||||||
previousY = expr.execute(previousX)
|
previousY = expr.execute(previousX)
|
||||||
for(let px = pxprecision; px < canvas.width; px += pxprecision) {
|
for(let px = pxprecision; px-pxprecision < canvas.width; px += pxprecision) {
|
||||||
let currentX = canvas.px2x(px)
|
let currentX = canvas.px2x(px)
|
||||||
if(!definitionDomain.includes(previousX) && definitionDomain.includes(currentX)) {
|
if(!definitionDomain.includes(previousX) && definitionDomain.includes(currentX)) {
|
||||||
// Should draw up to currentX, but NOT at previousX.
|
// Should draw up to currentX, but NOT at previousX.
|
||||||
|
@ -169,7 +171,7 @@ export default class Function extends ExecutableObject {
|
||||||
do {
|
do {
|
||||||
tmpPx++
|
tmpPx++
|
||||||
previousX = canvas.px2x(tmpPx)
|
previousX = canvas.px2x(tmpPx)
|
||||||
} while(!definitionDomain.includes(previousX))
|
} while(!definitionDomain.includes(previousX) && currentX > previousX)
|
||||||
// Recaclulate previousY
|
// Recaclulate previousY
|
||||||
previousY = expr.execute(previousX)
|
previousY = expr.execute(previousX)
|
||||||
} else if(!definitionDomain.includes(currentX)) {
|
} else if(!definitionDomain.includes(currentX)) {
|
||||||
|
@ -179,7 +181,7 @@ export default class Function extends ExecutableObject {
|
||||||
do {
|
do {
|
||||||
tmpPx--
|
tmpPx--
|
||||||
currentX = canvas.px2x(tmpPx)
|
currentX = canvas.px2x(tmpPx)
|
||||||
} while(!definitionDomain.includes(currentX) && currentX !== previousX)
|
} while(!definitionDomain.includes(currentX) && currentX > previousX)
|
||||||
}
|
}
|
||||||
// This max variation is needed for functions with asymptotical vertical lines (e.g. 1/x, tan x...)
|
// This max variation is needed for functions with asymptotical vertical lines (e.g. 1/x, tan x...)
|
||||||
let maxvariation = (canvas.px2y(0) - canvas.px2y(canvas.height))
|
let maxvariation = (canvas.px2y(0) - canvas.px2y(canvas.height))
|
||||||
|
|
Loading…
Reference in a new issue