| 1 |
|
| 2 |
|
| 3 |
on |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
function run(_command) { |
| 27 |
return iannix.execute(_command); |
| 28 |
} |
| 29 |
function ask(_category, _label, _variable, _defaultValue) { |
| 30 |
return iannix.ask(_category, _label, _variable, _defaultValue); |
| 31 |
} |
| 32 |
function title(_title) { |
| 33 |
return iannix.meta(_title); |
| 34 |
} |
| 35 |
function console(_log) { |
| 36 |
return iannix.execute("log " + JSON.stringify(_log, null, 4)); |
| 37 |
} |
| 38 |
function load(_filename) { |
| 39 |
return iannix.load(_filename); |
| 40 |
} |
| 41 |
function loadJSON(_filename) { |
| 42 |
return JSON.parse(load(_filename)); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
String.prototype.trim = function() |
| 47 |
{ return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, "")) } |
| 48 |
String.prototype.startsWith = function(str) |
| 49 |
{ return (this.match("^"+str)==str) } |
| 50 |
String.prototype.endsWith = function(str) |
| 51 |
{ return (this.match(str+"$")==str) } |
| 52 |
String.prototype.replaceAll = function(str, str2) |
| 53 |
{ return (this.replace(new RegExp(str, 'g'), str2)) } |
| 54 |
String.prototype.pad = function(length) { |
| 55 |
var str = '' + this; |
| 56 |
while (str.length < length) { |
| 57 |
str = '0' + str; |
| 58 |
} |
| 59 |
return str; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
var E = Math.E; |
| 65 |
var LN2 = Math.LN2; |
| 66 |
var LN10 = Math.LN10; |
| 67 |
var LOG2E = Math.LOG2E; |
| 68 |
var LOG10E = Math.LOG10E; |
| 69 |
var PI = Math.PI; |
| 70 |
var TWO_PI = 2 * Math.PI; |
| 71 |
var THIRD_PI = Math.PI / 3; |
| 72 |
var QUARTER_PI = Math.PI / 4; |
| 73 |
var HALF_PI = Math.PI / 2; |
| 74 |
var SQRT1_2 = Math.SQRT1_2; |
| 75 |
var SQRT2 = Math.SQRT2; |
| 76 |
|
| 77 |
|
| 78 |
function abs(x) { return Math.abs(x); } |
| 79 |
function acos(x) { return Math.acos(x); } |
| 80 |
function asin(x) { return Math.asin(x); } |
| 81 |
function atan(x) { return Math.atan(x); } |
| 82 |
function atan2(x,y) { return Math.atan2(x,y); } |
| 83 |
function ceil(x) { return Math.ceil(x); } |
| 84 |
function cos(x) { return Math.cos(x); } |
| 85 |
function exp(x) { return Math.exp(x); } |
| 86 |
function floor(x) { return Math.floor(x); } |
| 87 |
function log(x) { return Math.log(x); } |
| 88 |
function min(x,y) { return Math.min(x,y); } |
| 89 |
function max(x,y) { return Math.max(x,y); } |
| 90 |
function pow(x,y) { return Math.pow(x,y); } |
| 91 |
function sin(x) { return Math.sin(x); } |
| 92 |
function sqrt(x) { return Math.sqrt(x); } |
| 93 |
function sq(x) { return x*x; } |
| 94 |
function tan(x) { return Math.tan(x); } |
| 95 |
function degrees(value) { return value * 180. / pi; } |
| 96 |
function radians(value) { return value * pi / 180.; } |
| 97 |
function round(x, y) { |
| 98 |
if(y == undefined) return Math.round(x); |
| 99 |
else return Math.round(x*Math.pow(10, y)) / Math.pow(10, y); |
| 100 |
} |
| 101 |
function random(low, high) { |
| 102 |
if((low == undefined) || (high == undefined)) |
| 103 |
return Math.random(); |
| 104 |
else |
| 105 |
return range(Math.random(), low, high); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
function constrain(value, min, max) { |
| 110 |
return Math.min(max, Math.max(min, value)); |
| 111 |
} |
| 112 |
function dist(x1, y1, z1, x2, y2, z2) { |
| 113 |
var dx = x2 - x1, dy = y2 - y1, dz = z2 - z1; |
| 114 |
return Math.sqrt(sq(dx) + sq(dy) + sq(dz)); |
| 115 |
} |
| 116 |
function angle(x1, y1, x2, y2) { |
| 117 |
var dx = x2 - x1, dy = y2 - y1, angle = 0; |
| 118 |
if((dx > 0) && (dy >= 0)) |
| 119 |
angle = (Math.atan(dy / dx)) * 180.0 / PI; |
| 120 |
else if((dx <= 0) && (dy > 0)) |
| 121 |
angle = (-Math.atan(dx / dy) + HALF_PI) * 180.0 / PI; |
| 122 |
else if((dx < 0) && (dy <= 0)) |
| 123 |
angle = (Math.atan(dy / dx) + PI) * 180.0 / PI; |
| 124 |
else if((dx >= 0) && (dy < 0)) |
| 125 |
angle = (-Math.atan(dx / dy) + 3 * HALF_PI) * 180.0 / PI; |
| 126 |
return angle; |
| 127 |
} |
| 128 |
function norm(value, low, high, exp) { |
| 129 |
if((high - low) == 0) |
| 130 |
return 0; |
| 131 |
else |
| 132 |
return linexp((value - low) / (high - low), exp); |
| 133 |
} |
| 134 |
function range(value, low, high, exp) { |
| 135 |
value = linexp(value, exp); |
| 136 |
return value * (high - low) + low; |
| 137 |
} |
| 138 |
function rangeMid(value, low, mid, high, exp) { |
| 139 |
value = linexp(value, exp); |
| 140 |
if(value < 0.5) |
| 141 |
return (value * 2) * (mid - low) + low; |
| 142 |
else |
| 143 |
return (value - .5) * 2 * (high - mid) + mid; |
| 144 |
} |
| 145 |
function map(value, low1, high1, low2, high2, exp) { |
| 146 |
return range(norm(value, low1, high1, exp), low2, high2); |
| 147 |
} |
| 148 |
|
| 149 |
function linexp(value, factor) { |
| 150 |
if((factor == undefined) || (factor == 0)) |
| 151 |
return value; |
| 152 |
else |
| 153 |
return (exp(factor * value - factor) - exp(-factor)) / (1 - exp(-factor)); |
| 154 |
} |