From e44a7e37b6c7b5961adaffc62b9042b8d442938e Mon Sep 17 00:00:00 2001 From: mensonge Date: Thu, 13 Nov 2008 09:49:11 +0000 Subject: New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f --- includes/js/dojox/math/README | 38 +++++ includes/js/dojox/math/_base.js | 122 ++++++++++++++++ includes/js/dojox/math/curves.js | 193 +++++++++++++++++++++++++ includes/js/dojox/math/matrix.js | 294 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 647 insertions(+) create mode 100644 includes/js/dojox/math/README create mode 100644 includes/js/dojox/math/_base.js create mode 100644 includes/js/dojox/math/curves.js create mode 100644 includes/js/dojox/math/matrix.js (limited to 'includes/js/dojox/math') diff --git a/includes/js/dojox/math/README b/includes/js/dojox/math/README new file mode 100644 index 0000000..f9f50ad --- /dev/null +++ b/includes/js/dojox/math/README @@ -0,0 +1,38 @@ +------------------------------------------------------------------------------- +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 new file mode 100644 index 0000000..ef2243c --- /dev/null +++ b/includes/js/dojox/math/_base.js @@ -0,0 +1,122 @@ +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; ib; 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= 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= 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 new file mode 100644 index 0000000..386bad3 --- /dev/null +++ b/includes/js/dojox/math/matrix.js @@ -0,0 +1,294 @@ +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-1){ + b+="."; + } + while(b.length0?a[0].length:0; + var buffer=""; + for(var y=0; y