123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257 |
- define(['exports', './when-e6985d2a', './Check-24cae389'], function (exports, when, Check) { 'use strict';
-
-
-
-
- function MersenneTwister(seed) {
- if (seed == undefined) {
- seed = new Date().getTime();
- }
-
- this.N = 624;
- this.M = 397;
- this.MATRIX_A = 0x9908b0df;
- this.UPPER_MASK = 0x80000000;
- this.LOWER_MASK = 0x7fffffff;
- this.mt = new Array(this.N);
- this.mti=this.N+1;
- this.init_genrand(seed);
- }
-
- MersenneTwister.prototype.init_genrand = function(s) {
- this.mt[0] = s >>> 0;
- for (this.mti=1; this.mti<this.N; this.mti++) {
- var s = this.mt[this.mti-1] ^ (this.mt[this.mti-1] >>> 30);
- this.mt[this.mti] = (((((s & 0xffff0000) >>> 16) * 1812433253) << 16) + (s & 0x0000ffff) * 1812433253)
- + this.mti;
-
-
-
-
- this.mt[this.mti] >>>= 0;
-
- }
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- MersenneTwister.prototype.genrand_int32 = function() {
- var y;
- var mag01 = new Array(0x0, this.MATRIX_A);
-
- if (this.mti >= this.N) {
- var kk;
- if (this.mti == this.N+1)
- this.init_genrand(5489);
- for (kk=0;kk<this.N-this.M;kk++) {
- y = (this.mt[kk]&this.UPPER_MASK)|(this.mt[kk+1]&this.LOWER_MASK);
- this.mt[kk] = this.mt[kk+this.M] ^ (y >>> 1) ^ mag01[y & 0x1];
- }
- for (;kk<this.N-1;kk++) {
- y = (this.mt[kk]&this.UPPER_MASK)|(this.mt[kk+1]&this.LOWER_MASK);
- this.mt[kk] = this.mt[kk+(this.M-this.N)] ^ (y >>> 1) ^ mag01[y & 0x1];
- }
- y = (this.mt[this.N-1]&this.UPPER_MASK)|(this.mt[0]&this.LOWER_MASK);
- this.mt[this.N-1] = this.mt[this.M-1] ^ (y >>> 1) ^ mag01[y & 0x1];
- this.mti = 0;
- }
- y = this.mt[this.mti++];
-
- y ^= (y >>> 11);
- y ^= (y << 7) & 0x9d2c5680;
- y ^= (y << 15) & 0xefc60000;
- y ^= (y >>> 18);
- return y >>> 0;
- };
-
-
-
-
-
-
-
-
-
-
- MersenneTwister.prototype.random = function() {
- return this.genrand_int32()*(1.0/4294967296.0);
-
- };
-
- var CesiumMath = {};
-
- CesiumMath.EPSILON1 = 0.1;
-
- CesiumMath.EPSILON2 = 0.01;
-
- CesiumMath.EPSILON3 = 0.001;
-
- CesiumMath.EPSILON4 = 0.0001;
-
- CesiumMath.EPSILON5 = 0.00001;
-
- CesiumMath.EPSILON6 = 0.000001;
-
- CesiumMath.EPSILON7 = 0.0000001;
-
- CesiumMath.EPSILON8 = 0.00000001;
-
- CesiumMath.EPSILON9 = 0.000000001;
-
- CesiumMath.EPSILON10 = 0.0000000001;
-
- CesiumMath.EPSILON11 = 0.00000000001;
-
- CesiumMath.EPSILON12 = 0.000000000001;
-
- CesiumMath.EPSILON13 = 0.0000000000001;
-
- CesiumMath.EPSILON14 = 0.00000000000001;
-
- CesiumMath.EPSILON15 = 0.000000000000001;
-
- CesiumMath.EPSILON16 = 0.0000000000000001;
-
- CesiumMath.EPSILON17 = 0.00000000000000001;
-
- CesiumMath.EPSILON18 = 0.000000000000000001;
-
- CesiumMath.EPSILON19 = 0.0000000000000000001;
-
- CesiumMath.EPSILON20 = 0.00000000000000000001;
-
- CesiumMath.EPSILON21 = 0.000000000000000000001;
-
- CesiumMath.GRAVITATIONALPARAMETER = 3.986004418e14;
-
- CesiumMath.SOLAR_RADIUS = 6.955e8;
-
- CesiumMath.LUNAR_RADIUS = 1737400.0;
-
- CesiumMath.SIXTY_FOUR_KILOBYTES = 64 * 1024;
-
- CesiumMath.FOUR_GIGABYTES = 4 * 1024 * 1024 * 1024;
-
- CesiumMath.sign = when.defaultValue(Math.sign, function sign(value) {
- value = +value;
- if (value === 0 || value !== value) {
-
- return value;
- }
- return value > 0 ? 1 : -1;
- });
-
- CesiumMath.signNotZero = function (value) {
- return value < 0.0 ? -1.0 : 1.0;
- };
-
- CesiumMath.toSNorm = function (value, rangeMaximum) {
- rangeMaximum = when.defaultValue(rangeMaximum, 255);
- return Math.round(
- (CesiumMath.clamp(value, -1.0, 1.0) * 0.5 + 0.5) * rangeMaximum
- );
- };
-
- CesiumMath.fromSNorm = function (value, rangeMaximum) {
- rangeMaximum = when.defaultValue(rangeMaximum, 255);
- return (
- (CesiumMath.clamp(value, 0.0, rangeMaximum) / rangeMaximum) * 2.0 - 1.0
- );
- };
-
- CesiumMath.normalize = function (value, rangeMinimum, rangeMaximum) {
- rangeMaximum = Math.max(rangeMaximum - rangeMinimum, 0.0);
- return rangeMaximum === 0.0
- ? 0.0
- : CesiumMath.clamp((value - rangeMinimum) / rangeMaximum, 0.0, 1.0);
- };
-
- CesiumMath.sinh = when.defaultValue(Math.sinh, function sinh(value) {
- return (Math.exp(value) - Math.exp(-value)) / 2.0;
- });
-
- CesiumMath.cosh = when.defaultValue(Math.cosh, function cosh(value) {
- return (Math.exp(value) + Math.exp(-value)) / 2.0;
- });
-
- CesiumMath.lerp = function (p, q, time) {
- return (1.0 - time) * p + time * q;
- };
-
- CesiumMath.PI = Math.PI;
-
- CesiumMath.ONE_OVER_PI = 1.0 / Math.PI;
-
- CesiumMath.PI_OVER_TWO = Math.PI / 2.0;
-
- CesiumMath.PI_OVER_THREE = Math.PI / 3.0;
-
- CesiumMath.PI_OVER_FOUR = Math.PI / 4.0;
-
- CesiumMath.PI_OVER_SIX = Math.PI / 6.0;
-
- CesiumMath.THREE_PI_OVER_TWO = (3.0 * Math.PI) / 2.0;
-
- CesiumMath.TWO_PI = 2.0 * Math.PI;
-
- CesiumMath.ONE_OVER_TWO_PI = 1.0 / (2.0 * Math.PI);
-
- CesiumMath.RADIANS_PER_DEGREE = Math.PI / 180.0;
-
- CesiumMath.DEGREES_PER_RADIAN = 180.0 / Math.PI;
-
- CesiumMath.RADIANS_PER_ARCSECOND = CesiumMath.RADIANS_PER_DEGREE / 3600.0;
-
- CesiumMath.toRadians = function (degrees) {
-
- if (!when.defined(degrees)) {
- throw new Check.DeveloperError("degrees is required.");
- }
-
- return degrees * CesiumMath.RADIANS_PER_DEGREE;
- };
-
- CesiumMath.toDegrees = function (radians) {
-
- if (!when.defined(radians)) {
- throw new Check.DeveloperError("radians is required.");
- }
-
- return radians * CesiumMath.DEGREES_PER_RADIAN;
- };
-
- CesiumMath.convertLongitudeRange = function (angle) {
-
- if (!when.defined(angle)) {
- throw new Check.DeveloperError("angle is required.");
- }
-
- var twoPi = CesiumMath.TWO_PI;
- var simplified = angle - Math.floor(angle / twoPi) * twoPi;
- if (simplified < -Math.PI) {
- return simplified + twoPi;
- }
- if (simplified >= Math.PI) {
- return simplified - twoPi;
- }
- return simplified;
- };
-
- CesiumMath.clampToLatitudeRange = function (angle) {
-
- if (!when.defined(angle)) {
- throw new Check.DeveloperError("angle is required.");
- }
-
- return CesiumMath.clamp(
- angle,
- -1 * CesiumMath.PI_OVER_TWO,
- CesiumMath.PI_OVER_TWO
- );
- };
-
- CesiumMath.negativePiToPi = function (angle) {
-
- if (!when.defined(angle)) {
- throw new Check.DeveloperError("angle is required.");
- }
-
- return CesiumMath.zeroToTwoPi(angle + CesiumMath.PI) - CesiumMath.PI;
- };
-
- CesiumMath.zeroToTwoPi = function (angle) {
-
- if (!when.defined(angle)) {
- throw new Check.DeveloperError("angle is required.");
- }
-
- var mod = CesiumMath.mod(angle, CesiumMath.TWO_PI);
- if (
- Math.abs(mod) < CesiumMath.EPSILON14 &&
- Math.abs(angle) > CesiumMath.EPSILON14
- ) {
- return CesiumMath.TWO_PI;
- }
- return mod;
- };
-
- CesiumMath.mod = function (m, n) {
-
- if (!when.defined(m)) {
- throw new Check.DeveloperError("m is required.");
- }
- if (!when.defined(n)) {
- throw new Check.DeveloperError("n is required.");
- }
-
- return ((m % n) + n) % n;
- };
-
- CesiumMath.equalsEpsilon = function (
- left,
- right,
- relativeEpsilon,
- absoluteEpsilon
- ) {
-
- if (!when.defined(left)) {
- throw new Check.DeveloperError("left is required.");
- }
- if (!when.defined(right)) {
- throw new Check.DeveloperError("right is required.");
- }
-
- relativeEpsilon = when.defaultValue(relativeEpsilon, 0.0);
- absoluteEpsilon = when.defaultValue(absoluteEpsilon, relativeEpsilon);
- var absDiff = Math.abs(left - right);
- return (
- absDiff <= absoluteEpsilon ||
- absDiff <= relativeEpsilon * Math.max(Math.abs(left), Math.abs(right))
- );
- };
-
- CesiumMath.lessThan = function (left, right, absoluteEpsilon) {
-
- if (!when.defined(left)) {
- throw new Check.DeveloperError("first is required.");
- }
- if (!when.defined(right)) {
- throw new Check.DeveloperError("second is required.");
- }
- if (!when.defined(absoluteEpsilon)) {
- throw new Check.DeveloperError("relativeEpsilon is required.");
- }
-
- return left - right < -absoluteEpsilon;
- };
-
- CesiumMath.lessThanOrEquals = function (left, right, absoluteEpsilon) {
-
- if (!when.defined(left)) {
- throw new Check.DeveloperError("first is required.");
- }
- if (!when.defined(right)) {
- throw new Check.DeveloperError("second is required.");
- }
- if (!when.defined(absoluteEpsilon)) {
- throw new Check.DeveloperError("relativeEpsilon is required.");
- }
-
- return left - right < absoluteEpsilon;
- };
-
- CesiumMath.greaterThan = function (left, right, absoluteEpsilon) {
-
- if (!when.defined(left)) {
- throw new Check.DeveloperError("first is required.");
- }
- if (!when.defined(right)) {
- throw new Check.DeveloperError("second is required.");
- }
- if (!when.defined(absoluteEpsilon)) {
- throw new Check.DeveloperError("relativeEpsilon is required.");
- }
-
- return left - right > absoluteEpsilon;
- };
-
- CesiumMath.greaterThanOrEquals = function (left, right, absoluteEpsilon) {
-
- if (!when.defined(left)) {
- throw new Check.DeveloperError("first is required.");
- }
- if (!when.defined(right)) {
- throw new Check.DeveloperError("second is required.");
- }
- if (!when.defined(absoluteEpsilon)) {
- throw new Check.DeveloperError("relativeEpsilon is required.");
- }
-
- return left - right > -absoluteEpsilon;
- };
- var factorials = [1];
-
- CesiumMath.factorial = function (n) {
-
- if (typeof n !== "number" || n < 0) {
- throw new Check.DeveloperError(
- "A number greater than or equal to 0 is required."
- );
- }
-
- var length = factorials.length;
- if (n >= length) {
- var sum = factorials[length - 1];
- for (var i = length; i <= n; i++) {
- var next = sum * i;
- factorials.push(next);
- sum = next;
- }
- }
- return factorials[n];
- };
-
- CesiumMath.incrementWrap = function (n, maximumValue, minimumValue) {
- minimumValue = when.defaultValue(minimumValue, 0.0);
-
- if (!when.defined(n)) {
- throw new Check.DeveloperError("n is required.");
- }
- if (maximumValue <= minimumValue) {
- throw new Check.DeveloperError("maximumValue must be greater than minimumValue.");
- }
-
- ++n;
- if (n > maximumValue) {
- n = minimumValue;
- }
- return n;
- };
-
- CesiumMath.isPowerOfTwo = function (n) {
-
- if (typeof n !== "number" || n < 0) {
- throw new Check.DeveloperError(
- "A number greater than or equal to 0 is required."
- );
- }
-
- return n !== 0 && (n & (n - 1)) === 0;
- };
-
- CesiumMath.nextPowerOfTwo = function (n) {
-
- if (typeof n !== "number" || n < 0) {
- throw new Check.DeveloperError(
- "A number greater than or equal to 0 is required."
- );
- }
-
-
- --n;
- n |= n >> 1;
- n |= n >> 2;
- n |= n >> 4;
- n |= n >> 8;
- n |= n >> 16;
- ++n;
- return n;
- };
-
- CesiumMath.clamp = function (value, min, max) {
-
- if (!when.defined(value)) {
- throw new Check.DeveloperError("value is required");
- }
- if (!when.defined(min)) {
- throw new Check.DeveloperError("min is required.");
- }
- if (!when.defined(max)) {
- throw new Check.DeveloperError("max is required.");
- }
-
- return value < min ? min : value > max ? max : value;
- };
- var randomNumberGenerator = new MersenneTwister();
-
- CesiumMath.setRandomNumberSeed = function (seed) {
-
- if (!when.defined(seed)) {
- throw new Check.DeveloperError("seed is required.");
- }
-
- randomNumberGenerator = new MersenneTwister(seed);
- };
-
- CesiumMath.nextRandomNumber = function () {
- return randomNumberGenerator.random();
- };
-
- CesiumMath.randomBetween = function (min, max) {
- return CesiumMath.nextRandomNumber() * (max - min) + min;
- };
-
- CesiumMath.acosClamped = function (value) {
-
- if (!when.defined(value)) {
- throw new Check.DeveloperError("value is required.");
- }
-
- return Math.acos(CesiumMath.clamp(value, -1.0, 1.0));
- };
-
- CesiumMath.asinClamped = function (value) {
-
- if (!when.defined(value)) {
- throw new Check.DeveloperError("value is required.");
- }
-
- return Math.asin(CesiumMath.clamp(value, -1.0, 1.0));
- };
-
- CesiumMath.chordLength = function (angle, radius) {
-
- if (!when.defined(angle)) {
- throw new Check.DeveloperError("angle is required.");
- }
- if (!when.defined(radius)) {
- throw new Check.DeveloperError("radius is required.");
- }
-
- return 2.0 * radius * Math.sin(angle * 0.5);
- };
-
- CesiumMath.logBase = function (number, base) {
-
- if (!when.defined(number)) {
- throw new Check.DeveloperError("number is required.");
- }
- if (!when.defined(base)) {
- throw new Check.DeveloperError("base is required.");
- }
-
- return Math.log(number) / Math.log(base);
- };
-
- CesiumMath.cbrt = when.defaultValue(Math.cbrt, function cbrt(number) {
- var result = Math.pow(Math.abs(number), 1.0 / 3.0);
- return number < 0.0 ? -result : result;
- });
-
- CesiumMath.log2 = when.defaultValue(Math.log2, function log2(number) {
- return Math.log(number) * Math.LOG2E;
- });
-
- CesiumMath.fog = function (distanceToCamera, density) {
- var scalar = distanceToCamera * density;
- return 1.0 - Math.exp(-(scalar * scalar));
- };
-
- CesiumMath.fastApproximateAtan = function (x) {
-
- Check.Check.typeOf.number("x", x);
-
- return x * (-0.1784 * Math.abs(x) - 0.0663 * x * x + 1.0301);
- };
-
- CesiumMath.fastApproximateAtan2 = function (x, y) {
-
- Check.Check.typeOf.number("x", x);
- Check.Check.typeOf.number("y", y);
-
-
-
- var opposite;
- var adjacent;
- var t = Math.abs(x);
- opposite = Math.abs(y);
- adjacent = Math.max(t, opposite);
- opposite = Math.min(t, opposite);
- var oppositeOverAdjacent = opposite / adjacent;
-
- if (isNaN(oppositeOverAdjacent)) {
- throw new Check.DeveloperError("either x or y must be nonzero");
- }
-
- t = CesiumMath.fastApproximateAtan(oppositeOverAdjacent);
-
- t = Math.abs(y) > Math.abs(x) ? CesiumMath.PI_OVER_TWO - t : t;
- t = x < 0.0 ? CesiumMath.PI - t : t;
- t = y < 0.0 ? -t : t;
- return t;
- };
- exports.CesiumMath = CesiumMath;
- });
|