1 importScripts("algebra.js"); 2 "use strict"; 3 var classify ={}; 4 classify[Term.serializeName] = Term.fromWebWorker; 5 classify[Polynomial.serializeName] = Polynomial.fromWebWorker; 6 classify[PiecewiseFunction.serializeName] = PiecewiseFunction.fromWebWorker; 7 8 var currentfunction; 9 onmessage = function(event) { 10 switch(event.data.cmd) { 11 case 'calc': 12 var fn = event.data.fn; 13 classify[fn.serializeName](fn); 14 var plist = []; 15 var range = event.data.range; 16 var ingraph = false; 17 var oldery; 18 for(var i=0; i < range; i+=range/512) 19 { 20 var x = event.data.startx+i; 21 var newy = fn.resolve(x); 22 if(newy != undefined) { 23 if(newy >= event.data.ylow && newy <= event.data.yhigh) { 24 if(ingraph == false && oldery != undefined) { 25 plist.push(oldery); 26 } 27 plist.push(new Point(x,newy)); 28 ingraph = true; 29 }else if(ingraph == true) { 30 plist.push(new Point(x,newy)); 31 ingraph = false; 32 } 33 oldery = new Point(x,newy); 34 } 35 } 36 postMessage(plist); 37 break; 38 } 39 } 40 41 onerror = function(event) { 42 postMessage(event); 43 } 44 //postMessage("("+event.data.value+" ,"+currentfunction.resolve(parseFloat(event.data.value))+")"); 45