Files
galaxy/static/scripts/tools/rgenetics/helper_functions.js
T

2 lines
6.9 KiB
JavaScript
Executable File

function toPolarDir(a,b){var c=Math.atan2(b,a);return c}function toPolarDist(a,b){var c=Math.sqrt(a*a+b*b);return c}function toRectX(a,b){var c=b*Math.cos(a);return c}function toRectY(a,b){return y=b*Math.sin(a),y}function DegToRad(a){return a/180*Math.PI}function RadToDeg(a){return a/Math.PI*180}function dd2dms(a){var b=60*(Math.abs(a)-Math.floor(Math.abs(a))),c=60*(b-Math.floor(b)),b=Math.floor(b);if(a>=0)var d=Math.floor(a);else var d=Math.ceil(a);return{deg:d,min:b,sec:c}}function dms2dd(a,b,c){return 0>a?a-b/60-c/3600:a+b/60+c/3600}function log(a,b){return null==b&&(b=Math.E),Math.log(a)/Math.log(b)}function intBilinear(a,b,c,d,e,f,g,h,i){var j=(e-g)/i,k=(f-h)/i,l=(1-j)*(1-k),m=j*(1-k),n=j*k,o=k*(1-j),p=l*c+m*d+n*a+o*b;return p}function leftOfTest(a,b,c,d,e,f){var g=(d-b)*(e-c)-(c-a)*(f-d);if(0>g)var h=1;else var h=0;return h}function distFromLine(a,b,c,d,e,f){var g=e-c,h=f-d,i=(h*(a-c)-g*(b-d))/Math.sqrt(Math.pow(g,2)+Math.pow(h,2));return i}function angleBetwTwoLines(a,b,c,d){var e=Math.acos((a*c+b*d)/(Math.sqrt(Math.pow(a,2)+Math.pow(b,2))*Math.sqrt(Math.pow(c,2)+Math.pow(d,2))));return e}function calcBisectorVector(a,b,c,d){var e=Math.sqrt(Math.pow(a,2)+Math.pow(b,2)),f=Math.sqrt(Math.pow(c,2)+Math.pow(d,2)),g=new Array;return g[0]=a/e+c/f,g[1]=b/e+d/f,g}function calcBisectorAngle(a,b,c,d){var e=Math.sqrt(Math.pow(a,2)+Math.pow(b,2)),f=Math.sqrt(Math.pow(c,2)+Math.pow(d,2)),g=a/e+c/f,h=b/e+d/f,i=toPolarDir(g,h);return i}function intersect2lines(a,b,c,d,e,f,g,h){var i=new Object,j=(h-f)*(c-a)-(g-e)*(d-b);if(0==j)alert("lines are parallel");else var k=((g-e)*(b-f)-(h-f)*(a-e))/j;return i.x=a+k*(c-a),i.y=b+k*(d-b),i}function formatNumberString(a,b){if("Number"==typeof a)var c=a.toString();else var c=a;var d="",e=c.split("."),f=e[0].length;if(f>3)for(;f>0;)d=f>3?b+e[0].substr(f-3,3)+d:e[0].substr(0,f)+d,f-=3;else d=e[0];return e[1]&&(d=d+"."+e[1]),d}function statusChange(a){document.getElementById("statusText").firstChild.nodeValue="Statusbar: "+a}function scaleObject(a,b){var c=a.currentTarget,d=c.getAttributeNS(null,"x"),e=c.getAttributeNS(null,"y"),f="scale("+b+") translate("+(1*d/b-d)+" "+(1*e/b-e)+")";c.setAttributeNS(null,"transform",f)}function getTransformToRootElement(a){try{var b=a.getTransformToElement(document.documentElement)}catch(c){for(var b=a.getCTM();(a=a.parentNode)!=document;)b=a.getCTM().multiply(b)}return b}function getTransformToElement(a,b){try{var c=a.getTransformToElement(b)}catch(d){for(var c=a.getCTM();(a=a.parentNode)!=b;)c=a.getCTM().multiply(c)}return c}function hsv2rgb(a,b,c){var d=new Object;if(0==b)d.red=Math.round(255*c),d.green=Math.round(255*c),d.blue=Math.round(255*c);else{var e=a/60,f=Math.floor(e),g=e-f;f%2==0&&(g=1-g);var h=c*(1-b),i=c*(1-b*g);switch(f){case 0:d.red=c,d.green=i,d.blue=h;break;case 1:d.red=i,d.green=c,d.blue=h;break;case 2:d.red=h,d.green=c,d.blue=i;break;case 3:d.red=h,d.green=i,d.blue=c;break;case 4:d.red=i,d.green=h,d.blue=c;break;case 5:d.red=c,d.green=h,d.blue=i;break;case 6:d.red=c,d.green=i,d.blue=h}d.red=Math.round(255*d.red),d.green=Math.round(255*d.green),d.blue=Math.round(255*d.blue)}return d}function rgb2hsv(a,b,c){var d=new Object;return a/=255,b/=255,c/=255,myMax=Math.max(a,Math.max(b,c)),myMin=Math.min(a,Math.min(b,c)),v=myMax,s=myMax>0?(myMax-myMin)/myMax:0,s>0?(myDiff=myMax-myMin,rc=(myMax-a)/myDiff,gc=(myMax-b)/myDiff,bc=(myMax-c)/myDiff,a==myMax&&(h=(bc-gc)/6),b==myMax&&(h=(2+rc-bc)/6),c==myMax&&(h=(4+gc-rc)/6)):h=0,h<0&&(h+=1),d.hue=Math.round(360*h),d.sat=s,d.val=v,d}function arrayPopulate(a,b){var c=new Array;if(a.length!=b.length)alert("error: arrays do not have the same length!");else for(i=0;i<a.length;i++)c[a[i]]=b[i];return c}function getData(a,b,c,d,e,f){this.url=a,this.callBackFunction=b,this.returnFormat=c,this.method=d,this.additionalParams=f,"get"!=d&&"post"!=d&&alert("Error in network request: parameter 'method' must be 'get' or 'post'"),this.postText=e,this.xmlRequest=null}function serializeNode(a){if("undefined"!=typeof XMLSerializer)return(new XMLSerializer).serializeToString(a);if("undefined"!=typeof a.xml)return a.xml;if("undefined"!=typeof printNode)return printNode(a);if("undefined"==typeof Packages)return alert("Sorry, your SVG viewer does not support the printNode/serialize function."),"";try{var b=new java.io.StringWriter;return Packages.org.apache.batik.dom.util.DOMUtilities.writeNode(a,b),b.toString()}catch(c){return alert("Sorry, your SVG viewer does not support the printNode/serialize function."),""}}function startAnimation(a){document.getElementById(a).beginElement()}var svgNS="http://www.w3.org/2000/svg",xlinkNS="http://www.w3.org/1999/xlink",cartoNS="http://www.carto.net/attrib",attribNS="http://www.carto.net/attrib",batikNS="http://xml.apache.org/batik/ext";getData.prototype.getData=function(){if(window.getURL)"get"==this.method&&getURL(this.url,this),"post"==this.method&&postURL(this.url,this.postText,this);else if(window.XMLHttpRequest){var a=this;if(this.xmlRequest=new XMLHttpRequest,"get"==this.method&&("xml"==this.returnFormat&&this.xmlRequest.overrideMimeType("text/xml"),this.xmlRequest.open("GET",this.url,!0)),"post"==this.method&&this.xmlRequest.open("POST",this.url,!0),this.xmlRequest.onreadystatechange=function(){a.handleEvent()},"get"==this.method&&this.xmlRequest.send(null),"post"==this.method){var b=!0;this.postText||(b=!1,alert("Error in network post request: missing parameter 'postText'!")),"string"!=typeof this.postText&&(b=!1,alert("Error in network post request: parameter 'postText' has to be of type 'string')")),b&&this.xmlRequest.send(this.postText)}}else alert("your browser/svg viewer neither supports window.getURL nor window.XMLHttpRequest!")},getData.prototype.operationComplete=function(a){if(a.success){if("xml"==this.returnFormat){var b=parseXML(a.content,document);"function"==typeof this.callBackFunction&&this.callBackFunction(b.firstChild,this.additionalParams),"object"==typeof this.callBackFunction&&this.callBackFunction.receiveData(b.firstChild,this.additionalParams)}"json"==this.returnFormat&&("function"==typeof this.callBackFunction&&this.callBackFunction(a.content,this.additionalParams),"object"==typeof this.callBackFunction&&this.callBackFunction.receiveData(a.content,this.additionalParams))}else alert("something went wrong with dynamic loading of geometry!")},getData.prototype.handleEvent=function(){if(4==this.xmlRequest.readyState){if("xml"==this.returnFormat){var a=document.importNode(this.xmlRequest.responseXML.documentElement,!0);"function"==typeof this.callBackFunction&&this.callBackFunction(a,this.additionalParams),"object"==typeof this.callBackFunction&&this.callBackFunction.receiveData(a,this.additionalParams)}"json"==this.returnFormat&&("function"==typeof this.callBackFunction&&this.callBackFunction(this.xmlRequest.responseText,this.additionalParams),"object"==typeof this.callBackFunction&&this.callBackFunction.receiveData(this.xmlRequest.responseText,this.additionalParams))}};
//# sourceMappingURL=../../../maps/tools/rgenetics/helper_functions.js.map