diff options
Diffstat (limited to 'includes/js/dojox/math')
-rw-r--r-- | includes/js/dojox/math/README | 38 | ||||
-rw-r--r-- | includes/js/dojox/math/_base.js | 122 | ||||
-rw-r--r-- | includes/js/dojox/math/curves.js | 193 | ||||
-rw-r--r-- | includes/js/dojox/math/matrix.js | 294 |
4 files changed, 0 insertions, 647 deletions
diff --git a/includes/js/dojox/math/README b/includes/js/dojox/math/README deleted file mode 100644 index f9f50ad..0000000 --- a/includes/js/dojox/math/README +++ /dev/null @@ -1,38 +0,0 @@ --------------------------------------------------------------------------------
-DojoX Math
--------------------------------------------------------------------------------
-Version 0.9
-Release date: 10/20/2007
--------------------------------------------------------------------------------
-Project state:
-experimental
--------------------------------------------------------------------------------
-Credits
- Cal Henderson
- Dan Pupius
- Tom Trenka (ttrenka AT gmail.com)
--------------------------------------------------------------------------------
-Project description
-
-A port of the main functionality of dojo.math 0.4. Includes advanced math
-functions, abstract curve definitions, and some point calculations.
--------------------------------------------------------------------------------
-Dependencies:
-
-Depends on the Dojo Core, v1.0
--------------------------------------------------------------------------------
-Documentation
-
-See the API documentation.
--------------------------------------------------------------------------------
-Installation instructions
-
-Grab the following from the Dojo SVN Repository:
-http://svn.dojotoolkit.org/var/src/dojo/dojox/trunk/math.js
-http://svn.dojotoolkit.org/var/src/dojo/dojox/trunk/math/*
-
-Install into the following directory structure:
-/dojox/math/
-
-...which should be at the same level as your Dojo checkout.
--------------------------------------------------------------------------------
diff --git a/includes/js/dojox/math/_base.js b/includes/js/dojox/math/_base.js deleted file mode 100644 index ef2243c..0000000 --- a/includes/js/dojox/math/_base.js +++ /dev/null @@ -1,122 +0,0 @@ -if(!dojo._hasResource["dojox.math._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. -dojo._hasResource["dojox.math._base"] = true; -dojo.provide("dojox.math._base"); - -dojo.mixin(dojox.math, { - degreesToRadians: function(/* Number */n){ - // summary - // Convert the passed number to radians. - return (n*Math.PI)/180; // Number - }, - radiansToDegrees: function(/* Number */n){ - // summary - // Convert the passed number to degrees. - return (n*180)/Math.PI; // Number - }, - - factoral: function(/* Number */n){ - // summary - // Return the factoral of n. - if(n<1){ - return 0; // Number - } - var ret=1; - for(var i=1; i<=n; i++){ - ret*=i; - } - return ret; // Number - }, - permutations: function(/* Number */n, /* Number */k){ - // summary - // TODO - if(n==0 || k==0){ - return 1; // Number - } - return (this.factoral(n)/this.factoral(n-k)); - }, - combinations: function(/* Number */n, /* Number */r){ - // summary - // TODO - if(n==0 || r==0){ - return 1; // Number - } - return (this.factoral(n)/(this.factoral(n-r)*this.factoral(r))); // Number - }, - bernstein: function(/* Number */t, /* Number */n, /* Number */ i){ - // summary - // TODO - return (this.combinations(n, i)*Math.pow(t, i)*Math.pow(1-t, n-i)); // Number - }, - gaussian: function(){ - // summary - // Return a random number based on the Gaussian algo. - var k=2; - do{ - var i=2*Math.random()-1; - var j=2*Math.random()-1; - k = i*i+j*j; - }while(k>=1); - return (i * Math.sqrt((-2*Math.log(k))/k)); // Number - }, - - // basic statistics - sd: function(/* Array */a){ - // summary - // Returns the standard deviation of the passed arguments. - return Math.sqrt(this.variance(a)); // Number - }, - variance: function(/* Array */a){ - // summary - // Find the variance in the passed array of numbers. - var mean=0, squares=0; - dojo.forEach(a, function(item){ - mean+=item; - squares+=Math.pow(item,2); - }); - return (squares/a.length)-Math.pow(mean/a.length, 2); // Number - }, - - // create a range of numbers - range: function(/* Number */a, /* Number? */b, /* Number? */step){ - // summary - // Create a range of numbers based on the parameters. - if(arguments.length<2){ - b=a,a=0; - } - var s=step||1; - var range=[]; - if(s>0){ - for(var i=a; i<b; i+=s){ - range.push(i); - } - }else{ - if(s<0){ - for(var i=a; i>b; i+=s){ - range.push(i); - } - }else{ - throw new Error("dojox.math.range: step must not be zero."); - } - } - return range; // Array - }, - distance: function(/* Array */a, /* Array */b){ - // summary - // Calculate the distance between point A and point B - return Math.sqrt(Math.pow(b[0]-a[0],2)+Math.pow(b[1]-a[1],2)); // Number - }, - midpoint: function(/* Array */a, /* Array */b){ - // summary - // Calculate the midpoint between points A and B. A and B may be multidimensional. - if(a.length!=b.length){ - console.error("dojox.math.midpoint: Points A and B are not the same dimensionally.", a, b); - } - var m=[]; - for(var i=0; i<a.length; i++){ - m[i]=(a[i]+b[i])/2; - } - return m; // Array - } -}); - -} diff --git a/includes/js/dojox/math/curves.js b/includes/js/dojox/math/curves.js deleted file mode 100644 index 7045c41..0000000 --- a/includes/js/dojox/math/curves.js +++ /dev/null @@ -1,193 +0,0 @@ -if(!dojo._hasResource["dojox.math.curves"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. -dojo._hasResource["dojox.math.curves"] = true; -dojo.provide("dojox.math.curves"); - -dojo.mixin(dojox.math.curves, { - Line:function (start, end) { - this.start = start; - this.end = end; - this.dimensions = start.length; - for (var i = 0; i < start.length; i++) { - start[i] = Number(start[i]); - } - for (var i = 0; i < end.length; i++) { - end[i] = Number(end[i]); - } - this.getValue = function (n) { - var retVal = new Array(this.dimensions); - for (var i = 0; i < this.dimensions; i++) { - retVal[i] = ((this.end[i] - this.start[i]) * n) + this.start[i]; - } - return retVal; - }; - return this; - }, - Bezier:function(pnts) { - this.getValue = function (step) { - if (step >= 1) { - return this.p[this.p.length - 1]; - } - if (step <= 0) { - return this.p[0]; - } - var retVal = new Array(this.p[0].length); - for (var k = 0; j < this.p[0].length; k++) { - retVal[k] = 0; - } - for (var j = 0; j < this.p[0].length; j++) { - var C = 0; - var D = 0; - for (var i = 0; i < this.p.length; i++) { - C += this.p[i][j] * this.p[this.p.length - 1][0] * dojox.math.bernstein(step, this.p.length, i); - } - for (var l = 0; l < this.p.length; l++) { - D += this.p[this.p.length - 1][0] * dojox.math.bernstein(step, this.p.length, l); - } - retVal[j] = C / D; - } - return retVal; - }; - this.p = pnts; - return this; - }, - CatmullRom:function (pnts, c) { - this.getValue = function (step) { - var percent = step * (this.p.length - 1); - var node = Math.floor(percent); - var progress = percent - node; - var i0 = node - 1; - if (i0 < 0) { - i0 = 0; - } - var i = node; - var i1 = node + 1; - if (i1 >= this.p.length) { - i1 = this.p.length - 1; - } - var i2 = node + 2; - if (i2 >= this.p.length) { - i2 = this.p.length - 1; - } - var u = progress; - var u2 = progress * progress; - var u3 = progress * progress * progress; - var retVal = new Array(this.p[0].length); - for (var k = 0; k < this.p[0].length; k++) { - var x1 = (-this.c * this.p[i0][k]) + ((2 - this.c) * this.p[i][k]) + ((this.c - 2) * this.p[i1][k]) + (this.c * this.p[i2][k]); - var x2 = (2 * this.c * this.p[i0][k]) + ((this.c - 3) * this.p[i][k]) + ((3 - 2 * this.c) * this.p[i1][k]) + (-this.c * this.p[i2][k]); - var x3 = (-this.c * this.p[i0][k]) + (this.c * this.p[i1][k]); - var x4 = this.p[i][k]; - retVal[k] = x1 * u3 + x2 * u2 + x3 * u + x4; - } - return retVal; - }; - if (!c) { - this.c = 0.7; - } else { - this.c = c; - } - this.p = pnts; - return this; - }, - Arc:function (start, end, ccw){ - function translate(a,b){ - var c=new Array(a.length); - for(var i=0; i<a.length; i++){ c[i]=a[i]+b[i]; } - return c; - } - function invert(a){ - var b = new Array(a.length); - for(var i=0; i<a.length; i++){ b[i]=-a[i]; } - return b; - } - var center = dojox.math.midpoint(start, end); - var sides = translate(invert(center), start); - var rad = Math.sqrt(Math.pow(sides[0], 2) + Math.pow(sides[1], 2)); - var theta = dojox.math.radiansToDegrees(Math.atan(sides[1] / sides[0])); - if (sides[0] < 0){ - theta -= 90; - } else { - theta += 90; - } - dojox.math.curves.CenteredArc.call(this, center, rad, theta, theta + (ccw ? -180 : 180)); - }, - CenteredArc:function (center, radius, start, end) { - this.center = center; - this.radius = radius; - this.start = start || 0; - this.end = end; - this.getValue = function (n) { - var retVal = new Array(2); - var theta = dojox.math.degreesToRadians(this.start + ((this.end - this.start) * n)); - retVal[0] = this.center[0] + this.radius * Math.sin(theta); - retVal[1] = this.center[1] - this.radius * Math.cos(theta); - return retVal; - }; - return this; - }, - Circle:function(center, radius){ - dojox.math.curves.CenteredArc.call(this, center, radius, 0, 360); - return this; - }, - Path:function () { - var curves = []; - var weights = []; - var ranges = []; - var totalWeight = 0; - this.add = function (curve, weight) { - if (weight < 0) { - console.error("dojox.math.curves.Path.add: weight cannot be less than 0"); - } - curves.push(curve); - weights.push(weight); - totalWeight += weight; - computeRanges(); - }; - this.remove = function (curve) { - for (var i = 0; i < curves.length; i++) { - if (curves[i] == curve) { - curves.splice(i, 1); - totalWeight -= weights.splice(i, 1)[0]; - break; - } - } - computeRanges(); - }; - this.removeAll = function () { - curves = []; - weights = []; - totalWeight = 0; - }; - this.getValue = function (n) { - var found = false, value = 0; - for (var i = 0; i < ranges.length; i++) { - var r = ranges[i]; - if (n >= r[0] && n < r[1]) { - var subN = (n - r[0]) / r[2]; - value = curves[i].getValue(subN); - found = true; - break; - } - } - if (!found) { - value = curves[curves.length - 1].getValue(1); - } - for (var j = 0; j < i; j++) { - value = dojox.math.points.translate(value, curves[j].getValue(1)); - } - return value; - }; - function computeRanges() { - var start = 0; - for (var i = 0; i < weights.length; i++) { - var end = start + weights[i] / totalWeight; - var len = end - start; - ranges[i] = [start, end, len]; - start = end; - } - } - return this; - } -}); - -} diff --git a/includes/js/dojox/math/matrix.js b/includes/js/dojox/math/matrix.js deleted file mode 100644 index 386bad3..0000000 --- a/includes/js/dojox/math/matrix.js +++ /dev/null @@ -1,294 +0,0 @@ -if(!dojo._hasResource["dojox.math.matrix"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. -dojo._hasResource["dojox.math.matrix"] = true; -dojo.provide("dojox.math.matrix"); - -dojo.mixin(dojox.math.matrix, { - iDF:0, - ALMOST_ZERO: 1e-10, - multiply: function(/* Array */a, /* Array */b){ - // summary - // Multiply matrix a by matrix b. - var ay=a.length, ax=a[0].length, by=b.length, bx=b[0].length; - if(ax!=by){ - console.warn("Can't multiply matricies of sizes " + ax + "," + ay + " and " + bx + "," + by); - return [[0]]; - } - var c=[]; - for (var k=0; k<ay; k++) { - c[k]=[]; - for(var i=0; i<bx; i++){ - c[k][i]=0; - for(var m=0; m<ax; m++){ - c[k][i]+=a[k][m]*b[m][i]; - } - } - } - return c; // Array - }, - product: function(/* Array... */){ - // summary - // Return the product of N matrices - if (arguments.length==0){ - console.warn("can't multiply 0 matrices!"); - return 1; - } - var m=arguments[0]; - for(var i=1; i<arguments.length; i++){ - m=this.multiply(m, arguments[i]); - } - return m; // Array - }, - sum: function(/* Array... */){ - // summary - // Return the sum of N matrices - if(arguments.length==0){ - console.warn("can't sum 0 matrices!"); - return 0; // Number - } - var m=this.copy(arguments[0]); - var rows=m.length; - if(rows==0){ - console.warn("can't deal with matrices of 0 rows!"); - return 0; - } - var cols=m[0].length; - if(cols==0){ - console.warn("can't deal with matrices of 0 cols!"); - return 0; - } - for(var i=1; i<arguments.length; ++i){ - var arg=arguments[i]; - if(arg.length!=rows || arg[0].length!=cols){ - console.warn("can't add matrices of different dimensions: first dimensions were " + rows + "x" + cols + ", current dimensions are " + arg.length + "x" + arg[0].length); - return 0; - } - for(var r=0; r<rows; r++) { - for(var c=0; c<cols; c++) { - m[r][c]+=arg[r][c]; - } - } - } - return m; // Array - }, - inverse: function(/* Array */a){ - // summary - // Return the inversion of the passed matrix - if(a.length==1 && a[0].length==1){ - return [[1/a[0][0]]]; // Array - } - var tms=a.length, m=this.create(tms, tms), mm=this.adjoint(a), det=this.determinant(a), dd=0; - if(det==0){ - console.warn("Determinant Equals 0, Not Invertible."); - return [[0]]; - }else{ - dd=1/det; - } - for(var i=0; i<tms; i++) { - for (var j=0; j<tms; j++) { - m[i][j]=dd*mm[i][j]; - } - } - return m; // Array - }, - determinant: function(/* Array */a){ - // summary - // Calculate the determinant of the passed square matrix. - if(a.length!=a[0].length){ - console.warn("Can't calculate the determinant of a non-squre matrix!"); - return 0; - } - var tms=a.length, det=1, b=this.upperTriangle(a); - for (var i=0; i<tms; i++){ - var bii=b[i][i]; - if (Math.abs(bii)<this.ALMOST_ZERO) { - return 0; // Number - } - det*=bii; - } - det*=this.iDF; - return det; // Number - }, - upperTriangle: function(/* Array */m){ - // Summary - // Find the upper triangle of the passed matrix and return it. - m=this.copy(m); - var f1=0, temp=0, tms=m.length, v=1; - this.iDF=1; - for(var col=0; col<tms-1; col++){ - if(typeof m[col][col]!="number") { - console.warn("non-numeric entry found in a numeric matrix: m[" + col + "][" + col + "]=" + m[col][col]); - } - v=1; - var stop_loop=0; - while((m[col][col] == 0) && !stop_loop){ - if (col+v>=tms){ - this.iDF=0; - stop_loop=1; - }else{ - for(var r=0; r<tms; r++){ - temp=m[col][r]; - m[col][r]=m[col+v][r]; - m[col+v][r]=temp; - } - v++; - this.iDF*=-1; - } - } - for(var row=col+1; row<tms; row++){ - if(typeof m[row][col]!="number"){ - console.warn("non-numeric entry found in a numeric matrix: m[" + row + "][" + col + "]=" + m[row][col]); - } - if(typeof m[col][row]!="number"){ - console.warn("non-numeric entry found in a numeric matrix: m[" + col + "][" + row + "]=" + m[col][row]); - } - if(m[col][col]!=0){ - var f1=(-1)* m[row][col]/m[col][col]; - for (var i=col; i<tms; i++){ - m[row][i]=f1*m[col][i]+m[row][i]; - } - } - } - } - return m; // Array - }, - create: function(/* Number */a, /* Number */b, /* Number? */value){ - // summary - // Create a new matrix with rows a and cols b, and pre-populate with value. - value=value||0; - var m=[]; - for (var i=0; i<b; i++){ - m[i]=[]; - for(var j=0; j<a; j++) { - m[i][j]=value; - } - } - return m; // Array - }, - ones: function(/* Number */a, /* Number */b){ - // summary - // Create a matrix pre-populated with ones - return this.create(a, b, 1); // Array - }, - zeros: function(/* Number */a, /* Number */b){ - // summary - // Create a matrix pre-populated with zeros - return this.create(a, b); // Array - }, - identity: function(/* Number */size, /* Number? */scale){ - // summary - // Create an identity matrix based on the size and scale. - scale=scale||1; - var m=[]; - for(var i=0; i<size; i++){ - m[i]=[]; - for(var j=0; j<size; j++){ - m[i][j]=(i==j?scale:0); - } - } - return m; // Array - }, - adjoint: function(/* Array */a){ - // summary - // Find the adjoint of the passed matrix - var tms=a.length; - if(tms<=1){ - console.warn("Can't find the adjoint of a matrix with a dimension less than 2"); - return [[0]]; - } - if(a.length!=a[0].length){ - console.warn("Can't find the adjoint of a non-square matrix"); - return [[0]]; - } - var m=this.create(tms, tms), ap=this.create(tms-1, tms-1); - var ii=0, jj=0, ia=0, ja=0, det=0; - for(var i=0; i<tms; i++){ - for (var j=0; j<tms; j++){ - ia=0; - for(ii=0; ii<tms; ii++){ - if(ii==i){ - continue; - } - ja = 0; - for(jj=0; jj<tms; jj++){ - if(jj==j){ - continue; - } - ap[ia][ja] = a[ii][jj]; - ja++; - } - ia++; - } - det=this.determinant(ap); - m[i][j]=Math.pow(-1, (i+j))*det; - } - } - return this.transpose(m); // Array - }, - transpose: function(/* Array */a){ - // summary - // Transpose the passed matrix (i.e. rows to columns) - var m=this.create(a.length, a[0].length); - for(var i=0; i<a.length; i++){ - for(var j=0; j<a[i].length; j++){ - m[j][i]=a[i][j]; - } - } - return m; // Array - }, - format: function(/* Array */a, /* Number? */points){ - // summary - // Return a string representation of the matrix, rounded to points (if needed) - points=points||5; - function format_int(x, dp){ - var fac=Math.pow(10, dp); - var a=Math.round(x*fac)/fac; - var b=a.toString(); - if(b.charAt(0)!="-"){ - b=" "+b; - } - if(b.indexOf(".")>-1){ - b+="."; - } - while(b.length<dp+3){ - b+="0"; - } - return b; - } - var ya=a.length; - var xa=ya>0?a[0].length:0; - var buffer=""; - for(var y=0; y<ya; y++){ - buffer+="| "; - for(var x=0; x<xa; x++){ - buffer+=format_int(a[y][x], points)+" "; - } - buffer+="|\n"; - } - return buffer; // string - }, - copy: function(/* Array */a){ - // summary - // Create a copy of the passed matrix - var ya=a.length, xa=a[0].length, m=this.create(xa, ya); - for(var y=0; y<ya; y++){ - for(var x=0; x<xa; x++){ - m[y][x]=a[y][x]; - } - } - return m; // Array - }, - scale: function(/* Array */a, /* Number */factor){ - // summary - // Create a copy of passed matrix and scale each member by factor. - a=this.copy(a); - var ya=a.length, xa=a[0].length; - for(var y=0; y<ya; y++){ - for(var x=0; x<xa; x++){ - a[y][x]*=factor; - } - } - return a; - } -}); - -} |