New build scripts

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5282 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2007-03-04 19:05:34 +00:00
parent 04f9a2e7bc
commit 838e7d5381
845 changed files with 121780 additions and 183 deletions

View File

@@ -0,0 +1,18 @@
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.kwCompoundRequire({
common: [
["dojo.math", false, false],
["dojo.math.curves", false, false],
["dojo.math.points", false, false]
]
});
dojo.provide("dojo.math.*");

View File

@@ -0,0 +1,242 @@
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.provide("dojo.math.curves");
dojo.require("dojo.math");
/* Curves from Dan's 13th lib stuff.
* See: http://pupius.co.uk/js/Toolkit.Drawing.js
* http://pupius.co.uk/dump/dojo/Dojo.Math.js
*/
dojo.math.curves = {
Line: function(/* array */start, /* array */end) {
// summary
// Creates a straight line object
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]);
}
//simple function to find point on an n-dimensional, straight line
this.getValue = function(/* float */n){
// summary
// Returns the point at point N (in terms of percentage) on this line.
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; // array
}
return this; // dojo.math.curves.Line
},
Bezier: function(/* array */pnts) {
// summary
// Creates a bezier curve
// Takes an array of points, the first is the start point, the last is end point and the ones in
// between are the Bezier control points.
this.getValue = function(/* float */step) {
// summary
// Returns the point at point N (in terms of percentage) on this curve.
if(step >= 1) return this.p[this.p.length-1]; // if step>=1 we must be at the end of the curve
if(step <= 0) return this.p[0]; // if step<=0 we must be at the start of the curve
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]
* dojo.math.bernstein(step,this.p.length,i);
}
for(var l=0;l<this.p.length;l++) {
D += this.p[this.p.length-1][0] * dojo.math.bernstein(step,this.p.length,l);
}
retVal[j] = C/D;
}
return retVal; // array
}
this.p = pnts;
return this; // dojo.math.curves.Bezier
},
CatmullRom : function(/* array */pnts, /* float */c) {
// summary
// Creates a catmull-rom spline curve with c tension.
this.getValue = function(/* float */step) {
// summary
// Returns the point at point N (in terms of percentage) on this curve.
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; // array
}
if(!c) this.c = 0.7;
else this.c = c;
this.p = pnts;
return this; // dojo.math.curves.CatmullRom
},
// FIXME: This is the bad way to do a partial-arc with 2 points. We need to have the user
// supply the radius, otherwise we always get a half-circle between the two points.
Arc : function(/* array */start, /* array */end, /* boolean? */ccw) {
// summary
// Creates an arc with a counter clockwise switch
var center = dojo.math.points.midpoint(start, end);
var sides = dojo.math.points.translate(dojo.math.points.invert(center), start);
var rad = Math.sqrt(Math.pow(sides[0], 2) + Math.pow(sides[1], 2));
var theta = dojo.math.radToDeg(Math.atan(sides[1]/sides[0]));
if( sides[0] < 0 ) {
theta -= 90;
} else {
theta += 90;
}
dojo.math.curves.CenteredArc.call(this, center, rad, theta, theta+(ccw?-180:180));
},
CenteredArc : function(/* array */center, /* float */radius, /* array */start, /* array */end) {
// summary
// Creates an arc object, with center and radius (Top of arc = 0 degrees, increments clockwise)
// center => 2D point for center of arc
// radius => scalar quantity for radius of arc
// start => to define an arc specify start angle (default: 0)
// end => to define an arc specify start angle
this.center = center;
this.radius = radius;
this.start = start || 0;
this.end = end;
this.getValue = function(/* float */n) {
// summary
// Returns the point at point N (in terms of percentage) on this curve.
var retVal = new Array(2);
var theta = dojo.math.degToRad(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; // array
}
return this; // dojo.math.curves.CenteredArc
},
Circle : function(/* array */center, /* float */radius) {
// summary
// Special case of Arc (start = 0, end = 360)
dojo.math.curves.CenteredArc.call(this, center, radius, 0, 360);
return this; // dojo.math.curves.Circle
},
Path : function() {
// summary
// Generic path shape, created from curve segments
var curves = [];
var weights = [];
var ranges = [];
var totalWeight = 0;
this.add = function(/* dojo.math.curves.* */curve, /* float */weight) {
// summary
// Add a curve segment to this path
if( weight < 0 ) { dojo.raise("dojo.math.curves.Path.add: weight cannot be less than 0"); }
curves.push(curve);
weights.push(weight);
totalWeight += weight;
computeRanges();
}
this.remove = function(/* dojo.math.curves.* */curve) {
// summary
// Remove a curve segment from this path
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() {
// summary
// Remove all curve segments
curves = [];
weights = [];
totalWeight = 0;
}
this.getValue = function(/* float */n) {
// summary
// Returns the point at point N (in terms of percentage) on this curve.
var found = false, value = 0;
for(var i = 0; i < ranges.length; i++) {
var r = ranges[i];
//w(r.join(" ... "));
if( n >= r[0] && n < r[1] ) {
var subN = (n - r[0]) / r[2];
value = curves[i].getValue(subN);
found = true;
break;
}
}
// FIXME: Do we want to assume we're at the end?
if( !found ) {
value = curves[curves.length-1].getValue(1);
}
for(var j = 0; j < i; j++) {
value = dojo.math.points.translate(value, curves[j].getValue(1));
}
return value; // array
}
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; // dojo.math.curves.Path
}
};

View File

@@ -0,0 +1,377 @@
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.provide("dojo.math.matrix");
// some of this code is based on
// http://www.mkaz.com/math/MatrixCalculator.java
// (published under a BSD Open Source License)
//
// the rest is from my vague memory of matricies in school [cal]
//
// the copying of arguments is a little excessive, and could be trimmed back in
// the case where a function doesn't modify them at all (but some do!)
//
// 2006-06-25: Some enhancements submitted by Erel Segal:
// * addition: a tolerance constant for determinant calculations.
// * performance fix: removed unnecessary argument copying.
// * addition: function "product" for multiplying more than 2 matrices
// * addition: function "sum" for adding any number of matrices
// * bug fix: inversion of a 1x1 matrix without using the adjoint
// * performance fixes: upperTriangle
// * addition: argument "value" to function create, to initialize the matrix with a custom val
// * addition: functions "ones" and "zeros" - like Matlab[TM] functions with the same name.
// * addition: function "identity" for creating an identity matrix of a given size.
// * addition: argument "decimal_points" to function format
// * bug fix: adjoint of a 0-size matrix
// * performance fixes: adjoint
//
dojo.math.matrix.iDF = 0;
// Erel: values lower than this value are considered zero (in detereminant calculations).
// It is analogous to Maltab[TM]'s "eps".
dojo.math.matrix.ALMOST_ZERO = 1e-10;
dojo.math.matrix.multiply = function(a, b){
var ay = a.length;
var ax = a[0].length;
var by = b.length;
var bx = b[0].length;
if (ax != by){
dojo.debug("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;
}
// Erel: added a "product" function to calculate product of more than 2 matrices:
dojo.math.matrix.product = function() {
if (arguments.length==0) {
dojo.debug ("can't multiply 0 matrices!");
return 1;
}
var result = arguments[0];
for (var i=1; i<arguments.length; i++){
result = dojo.math.matrix.multiply(result,arguments[i]);
}
return result;
}
// Erel: added a "sum" function to calculate sum of more than 2 matrices:
dojo.math.matrix.sum = function() {
if (arguments.length==0) {
dojo.debug ("can't sum 0 matrices!");
return 0;
}
var result = dojo.math.matrix.copy(arguments[0]);
var rows = result.length;
if (rows==0) {
dojo.debug ("can't deal with matrices of 0 rows!");
return 0;
}
var cols = result[0].length;
if (cols==0) {
dojo.debug ("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) {
dojo.debug ("can't add matrices of different dimensions: first dimensions were " + rows + "x" + cols + ", current dimensions are "+arg.length + "x" + arg[0].length);
return 0;
}
// The actual addition:
for (var r=0; r<rows; r++){
for (var c=0; c<cols; c++){
result[r][c] += arg[r][c];
}
}
}
return result;
}
dojo.math.matrix.inverse = function(a){
// Erel: added special case: inverse of a 1x1 matrix can't be calculated by adjoint
if (a.length==1 && a[0].length==1){
return [[ 1 / a[0][0] ]];
}
// Formula used to Calculate Inverse:
// inv(A) = 1/det(A) * adj(A)
var tms = a.length;
var m = dojo.math.matrix.create(tms, tms);
var mm = dojo.math.matrix.adjoint(a);
var det = dojo.math.matrix.determinant(a);
var dd = 0;
if(det == 0){
dojo.debug("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;
}
dojo.math.matrix.determinant = function(a){
if (a.length != a[0].length){
dojo.debug("Can't calculate the determiant of a non-squre matrix!");
return 0;
}
var tms = a.length;
var det = 1;
var b = dojo.math.matrix.upperTriangle(a);
for (var i=0; i < tms; i++){
var bii = b[i][i];
if (Math.abs(bii) < dojo.math.matrix.ALMOST_ZERO){
return 0;
}
det *= bii;
}
det = det * dojo.math.matrix.iDF;
return det;
}
dojo.math.matrix.upperTriangle = function(m){
m = dojo.math.matrix.copy(m); // Copy m, because m is changed!
var f1 = 0;
var temp = 0;
var tms = m.length;
var v = 1;
//Erel: why use a global variable and not a local variable?
dojo.math.matrix.iDF = 1;
for (var col = 0; col < tms - 1; col++) {
if (typeof m[col][col] != 'number'){
dojo.debug("non-numeric entry found in a numeric matrix: m["+col+"]["+col+"]="+m[col][col]);
}
v = 1;
var stop_loop = 0;
// check if there is a 0 in diagonal
while ((m[col][col] == 0) && !stop_loop) {
// if so, switch rows until there is no 0 in diagonal:
if (col + v >= tms){
// check if switched all rows
dojo.math.matrix.iDF = 0;
stop_loop = 1;
}else{
for (var r = 0; r < tms; r++) {
temp = m[col][r];
m[col][r] = m[col + v][r]; // switch rows
m[col + v][r] = temp;
}
v++; // count row switchs
dojo.math.matrix.iDF *= -1; // each switch changes determinant factor
}
}
// loop over lower-right triangle (where row>col):
// for each row, make m[row][col] = 0 by linear operations that don't change the determinant:
for (var row = col + 1; row < tms; row++) {
if (typeof m[row][col] != 'number'){
dojo.debug("non-numeric entry found in a numeric matrix: m["+row+"]["+col+"]="+m[row][col]);
}
if (typeof m[col][row] != 'number'){
dojo.debug("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];
// this should make m[row][col] zero:
// m[row] += f1 * m[col];
for (var i = col; i < tms; i++) {
m[row][i] = f1 * m[col][i] + m[row][i];
}
}
}
}
return m;
}
// Erel: added parameter "value" - a custom default value to fill the matrix with.
dojo.math.matrix.create = function(a, b, value){
if(!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;
}
// Erel implement Matlab[TM] functions "ones" and "zeros"
dojo.math.matrix.ones = function(a,b) {
return dojo.math.matrix.create(a,b,1);
}
dojo.math.matrix.zeros = function(a,b) {
return dojo.math.matrix.create(a,b,0);
}
// Erel: added function that returns identity matrix.
// size = number of rows and cols in the matrix.
// scale = an optional value to multiply the matrix by (default is 1).
dojo.math.matrix.identity = function(size, scale){
if (!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;
}
dojo.math.matrix.adjoint = function(a){
var tms = a.length;
// Erel: added "<=" to catch zero-size matrix
if (tms <= 1){
dojo.debug("Can't find the adjoint of a matrix with a dimension less than 2");
return [[0]];
}
if (a.length != a[0].length){
dojo.debug("Can't find the adjoint of a non-square matrix");
return [[0]];
}
var m = dojo.math.matrix.create(tms, tms);
var ii = 0;
var jj = 0;
var ia = 0;
var ja = 0;
var det = 0;
var ap = dojo.math.matrix.create(tms-1, tms-1);
for (var i = 0; i < tms; i++){
for (var j = 0; j < tms; j++){
ia = 0;
for (ii = 0; ii < tms; ii++) { // create a temporary matrix for determinant calc
if (ii==i){
continue; // skip current row
}
ja = 0;
for (jj = 0; jj < tms; jj++) {
if (jj==j){
continue; // skip current col
}
ap[ia][ja] = a[ii][jj];
ja++;
}
ia++;
}
det = dojo.math.matrix.determinant(ap);
m[i][j] = Math.pow(-1 , (i + j)) * det;
}
}
m = dojo.math.matrix.transpose(m);
return m;
}
dojo.math.matrix.transpose = function(a){
var m = dojo.math.matrix.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;
}
// Erel: added decimal_points argument
dojo.math.matrix.format = function(a, decimal_points){
if (arguments.length<=1){
decimal_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;}
var has_dp = 0;
for(var i=1; i<b.length; i++){
if (b.charAt(i) == '.'){ has_dp = 1; }
}
if (!has_dp){ 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], decimal_points) + ' ';
}
buffer += '|\n';
}
return buffer;
}
dojo.math.matrix.copy = function(a){
var ya = a.length;
var xa = a[0].length;
var m = dojo.math.matrix.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;
}
dojo.math.matrix.scale = function(k, a){
a = dojo.math.matrix.copy(a); // Copy a because a is changed!
var ya = a.length;
var xa = a[0].length;
for (var y=0; y<ya; y++){
for (var x=0; x<xa; x++){
a[y][x] *= k;
}
}
return a;
}

View File

@@ -0,0 +1,54 @@
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.provide("dojo.math.points");
dojo.require("dojo.math");
dojo.math.points = {
translate: function(/* array */a, /* array */b) {
// summary
// translate a by b, and return the result.
if( a.length != b.length ) {
dojo.raise("dojo.math.translate: points not same size (a:[" + a + "], b:[" + b + "])");
}
var c = new Array(a.length);
for(var i = 0; i < a.length; i++) {
c[i] = a[i] + b[i];
}
return c; // array
},
midpoint: function(/* array */a, /* array */b) {
// summary
// Find the point midway between a and b
if( a.length != b.length ) {
dojo.raise("dojo.math.midpoint: points not same size (a:[" + a + "], b:[" + b + "])");
}
var c = new Array(a.length);
for(var i = 0; i < a.length; i++) {
c[i] = (a[i] + b[i]) / 2;
}
return c; // array
},
invert: function(/* array */a) {
// summary
// invert the values in a and return it.
var b = new Array(a.length);
for(var i = 0; i < a.length; i++) { b[i] = -a[i]; }
return b; // 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)); // float
}
};