UNPKG

cesium

Version:

CesiumJS is a JavaScript library for creating 3D globes and 2D maps in a web browser without a plugin.

1,555 lines (1,369 loc) 10 MB
/** * Cesium - https://github.com/AnalyticalGraphicsInc/cesium * * Copyright 2011-2017 Cesium Contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Columbus View (Pat. Pend.) * * Portions licensed separately. * See https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md for full licensing details. */ (function () { /** * @license almond 0.3.3 Copyright jQuery Foundation and other contributors. * Released under MIT license, http://github.com/requirejs/almond/LICENSE */ //Going sloppy to avoid 'use strict' string cost, but strict practices should //be followed. /*global setTimeout: false */ var requirejs, require, define; (function (undef) { var main, req, makeMap, handlers, defined = {}, waiting = {}, config = {}, defining = {}, hasOwn = Object.prototype.hasOwnProperty, aps = [].slice, jsSuffixRegExp = /\.js$/; function hasProp(obj, prop) { return hasOwn.call(obj, prop); } /** * Given a relative module name, like ./something, normalize it to * a real name that can be mapped to a path. * @param {String} name the relative name * @param {String} baseName a real name that the name arg is relative * to. * @returns {String} normalized name */ function normalize(name, baseName) { var nameParts, nameSegment, mapValue, foundMap, lastIndex, foundI, foundStarMap, starI, i, j, part, normalizedBaseParts, baseParts = baseName && baseName.split("/"), map = config.map, starMap = (map && map['*']) || {}; //Adjust any relative paths. if (name) { name = name.split('/'); lastIndex = name.length - 1; // If wanting node ID compatibility, strip .js from end // of IDs. Have to do this here, and not in nameToUrl // because node allows either .js or non .js to map // to same file. if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) { name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, ''); } // Starts with a '.' so need the baseName if (name[0].charAt(0) === '.' && baseParts) { //Convert baseName to array, and lop off the last part, //so that . matches that 'directory' and not name of the baseName's //module. For instance, baseName of 'one/two/three', maps to //'one/two/three.js', but we want the directory, 'one/two' for //this normalization. normalizedBaseParts = baseParts.slice(0, baseParts.length - 1); name = normalizedBaseParts.concat(name); } //start trimDots for (i = 0; i < name.length; i++) { part = name[i]; if (part === '.') { name.splice(i, 1); i -= 1; } else if (part === '..') { // If at the start, or previous value is still .., // keep them so that when converted to a path it may // still work when converted to a path, even though // as an ID it is less than ideal. In larger point // releases, may be better to just kick out an error. if (i === 0 || (i === 1 && name[2] === '..') || name[i - 1] === '..') { continue; } else if (i > 0) { name.splice(i - 1, 2); i -= 2; } } } //end trimDots name = name.join('/'); } //Apply map config if available. if ((baseParts || starMap) && map) { nameParts = name.split('/'); for (i = nameParts.length; i > 0; i -= 1) { nameSegment = nameParts.slice(0, i).join("/"); if (baseParts) { //Find the longest baseName segment match in the config. //So, do joins on the biggest to smallest lengths of baseParts. for (j = baseParts.length; j > 0; j -= 1) { mapValue = map[baseParts.slice(0, j).join('/')]; //baseName segment has config, find if it has one for //this name. if (mapValue) { mapValue = mapValue[nameSegment]; if (mapValue) { //Match, update name to the new value. foundMap = mapValue; foundI = i; break; } } } } if (foundMap) { break; } //Check for a star map match, but just hold on to it, //if there is a shorter segment match later in a matching //config, then favor over this star map. if (!foundStarMap && starMap && starMap[nameSegment]) { foundStarMap = starMap[nameSegment]; starI = i; } } if (!foundMap && foundStarMap) { foundMap = foundStarMap; foundI = starI; } if (foundMap) { nameParts.splice(0, foundI, foundMap); name = nameParts.join('/'); } } return name; } function makeRequire(relName, forceSync) { return function () { //A version of a require function that passes a moduleName //value for items that may need to //look up paths relative to the moduleName var args = aps.call(arguments, 0); //If first arg is not require('string'), and there is only //one arg, it is the array form without a callback. Insert //a null so that the following concat is correct. if (typeof args[0] !== 'string' && args.length === 1) { args.push(null); } return req.apply(undef, args.concat([relName, forceSync])); }; } function makeNormalize(relName) { return function (name) { return normalize(name, relName); }; } function makeLoad(depName) { return function (value) { defined[depName] = value; }; } function callDep(name) { if (hasProp(waiting, name)) { var args = waiting[name]; delete waiting[name]; defining[name] = true; main.apply(undef, args); } if (!hasProp(defined, name) && !hasProp(defining, name)) { throw new Error('No ' + name); } return defined[name]; } //Turns a plugin!resource to [plugin, resource] //with the plugin being undefined if the name //did not have a plugin prefix. function splitPrefix(name) { var prefix, index = name ? name.indexOf('!') : -1; if (index > -1) { prefix = name.substring(0, index); name = name.substring(index + 1, name.length); } return [prefix, name]; } //Creates a parts array for a relName where first part is plugin ID, //second part is resource ID. Assumes relName has already been normalized. function makeRelParts(relName) { return relName ? splitPrefix(relName) : []; } /** * Makes a name map, normalizing the name, and using a plugin * for normalization if necessary. Grabs a ref to plugin * too, as an optimization. */ makeMap = function (name, relParts) { var plugin, parts = splitPrefix(name), prefix = parts[0], relResourceName = relParts[1]; name = parts[1]; if (prefix) { prefix = normalize(prefix, relResourceName); plugin = callDep(prefix); } //Normalize according if (prefix) { if (plugin && plugin.normalize) { name = plugin.normalize(name, makeNormalize(relResourceName)); } else { name = normalize(name, relResourceName); } } else { name = normalize(name, relResourceName); parts = splitPrefix(name); prefix = parts[0]; name = parts[1]; if (prefix) { plugin = callDep(prefix); } } //Using ridiculous property names for space reasons return { f: prefix ? prefix + '!' + name : name, //fullName n: name, pr: prefix, p: plugin }; }; function makeConfig(name) { return function () { return (config && config.config && config.config[name]) || {}; }; } handlers = { require: function (name) { return makeRequire(name); }, exports: function (name) { var e = defined[name]; if (typeof e !== 'undefined') { return e; } else { return (defined[name] = {}); } }, module: function (name) { return { id: name, uri: '', exports: defined[name], config: makeConfig(name) }; } }; main = function (name, deps, callback, relName) { var cjsModule, depName, ret, map, i, relParts, args = [], callbackType = typeof callback, usingExports; //Use name if no relName relName = relName || name; relParts = makeRelParts(relName); //Call the callback to define the module, if necessary. if (callbackType === 'undefined' || callbackType === 'function') { //Pull out the defined dependencies and pass the ordered //values to the callback. //Default to [require, exports, module] if no deps deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps; for (i = 0; i < deps.length; i += 1) { map = makeMap(deps[i], relParts); depName = map.f; //Fast path CommonJS standard dependencies. if (depName === "require") { args[i] = handlers.require(name); } else if (depName === "exports") { //CommonJS module spec 1.1 args[i] = handlers.exports(name); usingExports = true; } else if (depName === "module") { //CommonJS module spec 1.1 cjsModule = args[i] = handlers.module(name); } else if (hasProp(defined, depName) || hasProp(waiting, depName) || hasProp(defining, depName)) { args[i] = callDep(depName); } else if (map.p) { map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {}); args[i] = defined[depName]; } else { throw new Error(name + ' missing ' + depName); } } ret = callback ? callback.apply(defined[name], args) : undefined; if (name) { //If setting exports via "module" is in play, //favor that over return value and exports. After that, //favor a non-undefined return value over exports use. if (cjsModule && cjsModule.exports !== undef && cjsModule.exports !== defined[name]) { defined[name] = cjsModule.exports; } else if (ret !== undef || !usingExports) { //Use the return value from the function. defined[name] = ret; } } } else if (name) { //May just be an object definition for the module. Only //worry about defining if have a module name. defined[name] = callback; } }; requirejs = require = req = function (deps, callback, relName, forceSync, alt) { if (typeof deps === "string") { if (handlers[deps]) { //callback in this case is really relName return handlers[deps](callback); } //Just return the module wanted. In this scenario, the //deps arg is the module name, and second arg (if passed) //is just the relName. //Normalize module name, if it contains . or .. return callDep(makeMap(deps, makeRelParts(callback)).f); } else if (!deps.splice) { //deps is a config object, not an array. config = deps; if (config.deps) { req(config.deps, config.callback); } if (!callback) { return; } if (callback.splice) { //callback is an array, which means it is a dependency list. //Adjust args if there are dependencies deps = callback; callback = relName; relName = null; } else { deps = undef; } } //Support require(['a']) callback = callback || function () {}; //If relName is a function, it is an errback handler, //so remove it. if (typeof relName === 'function') { relName = forceSync; forceSync = alt; } //Simulate async callback; if (forceSync) { main(undef, deps, callback, relName); } else { //Using a non-zero value because of concern for what old browsers //do, and latest browsers "upgrade" to 4 if lower value is used: //http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout: //If want a value immediately, use require('id') instead -- something //that works in almond on the global level, but not guaranteed and //unlikely to work in other AMD implementations. setTimeout(function () { main(undef, deps, callback, relName); }, 4); } return req; }; /** * Just drops the config on the floor, but returns req in case * the config return value is used. */ req.config = function (cfg) { return req(cfg); }; /** * Expose module registry for debugging and tooling */ requirejs._defined = defined; define = function (name, deps, callback) { if (typeof name !== 'string') { throw new Error('See almond README: incorrect module build, no module name'); } //This module may not have dependencies if (!deps.splice) { //deps is not an array, so probably means //an object literal or factory function for //the value. Adjust args. callback = deps; deps = []; } if (!hasProp(defined, name) && !hasProp(waiting, name)) { waiting[name] = [name, deps, callback]; } }; define.amd = { jQuery: true }; }()); define('Core/appendForwardSlash',[],function() { 'use strict'; /** * @private */ function appendForwardSlash(url) { if (url.length === 0 || url[url.length - 1] !== '/') { url = url + '/'; } return url; } return appendForwardSlash; }); define('Core/defined',[],function() { 'use strict'; /** * @exports defined * * @param {Object} value The object. * @returns {Boolean} Returns true if the object is defined, returns false otherwise. * * @example * if (Cesium.defined(positions)) { * doSomething(); * } else { * doSomethingElse(); * } */ function defined(value) { return value !== undefined && value !== null; } return defined; }); define('Core/DeveloperError',[ './defined' ], function( defined) { 'use strict'; /** * Constructs an exception object that is thrown due to a developer error, e.g., invalid argument, * argument out of range, etc. This exception should only be thrown during development; * it usually indicates a bug in the calling code. This exception should never be * caught; instead the calling code should strive not to generate it. * <br /><br /> * On the other hand, a {@link RuntimeError} indicates an exception that may * be thrown at runtime, e.g., out of memory, that the calling code should be prepared * to catch. * * @alias DeveloperError * @constructor * @extends Error * * @param {String} [message] The error message for this exception. * * @see RuntimeError */ function DeveloperError(message) { /** * 'DeveloperError' indicating that this exception was thrown due to a developer error. * @type {String} * @readonly */ this.name = 'DeveloperError'; /** * The explanation for why this exception was thrown. * @type {String} * @readonly */ this.message = message; //Browsers such as IE don't have a stack property until you actually throw the error. var stack; try { throw new Error(); } catch (e) { stack = e.stack; } /** * The stack trace of this exception, if available. * @type {String} * @readonly */ this.stack = stack; } if (defined(Object.create)) { DeveloperError.prototype = Object.create(Error.prototype); DeveloperError.prototype.constructor = DeveloperError; } DeveloperError.prototype.toString = function() { var str = this.name + ': ' + this.message; if (defined(this.stack)) { str += '\n' + this.stack.toString(); } return str; }; /** * @private */ DeveloperError.throwInstantiationError = function() { throw new DeveloperError('This function defines an interface and should not be called directly.'); }; return DeveloperError; }); define('Core/Check',[ './defined', './DeveloperError' ], function( defined, DeveloperError) { 'use strict'; /** * Contains functions for checking that supplied arguments are of a specified type * or meet specified conditions * @private */ var Check = {}; /** * Contains type checking functions, all using the typeof operator */ Check.typeOf = {}; function getUndefinedErrorMessage(name) { return name + ' is required, actual value was undefined'; } function getFailedTypeErrorMessage(actual, expected, name) { return 'Expected ' + name + ' to be typeof ' + expected + ', actual typeof was ' + actual; } /** * Throws if test is not defined * * @param {String} name The name of the variable being tested * @param {*} test The value that is to be checked * @exception {DeveloperError} test must be defined */ Check.defined = function (name, test) { if (!defined(test)) { throw new DeveloperError(getUndefinedErrorMessage(name)); } }; /** * Throws if test is not typeof 'function' * * @param {String} name The name of the variable being tested * @param {*} test The value to test * @exception {DeveloperError} test must be typeof 'function' */ Check.typeOf.func = function (name, test) { if (typeof test !== 'function') { throw new DeveloperError(getFailedTypeErrorMessage(typeof test, 'function', name)); } }; /** * Throws if test is not typeof 'string' * * @param {String} name The name of the variable being tested * @param {*} test The value to test * @exception {DeveloperError} test must be typeof 'string' */ Check.typeOf.string = function (name, test) { if (typeof test !== 'string') { throw new DeveloperError(getFailedTypeErrorMessage(typeof test, 'string', name)); } }; /** * Throws if test is not typeof 'number' * * @param {String} name The name of the variable being tested * @param {*} test The value to test * @exception {DeveloperError} test must be typeof 'number' */ Check.typeOf.number = function (name, test) { if (typeof test !== 'number') { throw new DeveloperError(getFailedTypeErrorMessage(typeof test, 'number', name)); } }; /** * Throws if test is not typeof 'number' and less than limit * * @param {String} name The name of the variable being tested * @param {*} test The value to test * @param {Number} limit The limit value to compare against * @exception {DeveloperError} test must be typeof 'number' and less than limit */ Check.typeOf.number.lessThan = function (name, test, limit) { Check.typeOf.number(name, test); if (test >= limit) { throw new DeveloperError('Expected ' + name + ' to be less than ' + limit + ', actual value was ' + test); } }; /** * Throws if test is not typeof 'number' and less than or equal to limit * * @param {String} name The name of the variable being tested * @param {*} test The value to test * @param {Number} limit The limit value to compare against * @exception {DeveloperError} test must be typeof 'number' and less than or equal to limit */ Check.typeOf.number.lessThanOrEquals = function (name, test, limit) { Check.typeOf.number(name, test); if (test > limit) { throw new DeveloperError('Expected ' + name + ' to be less than or equal to ' + limit + ', actual value was ' + test); } }; /** * Throws if test is not typeof 'number' and greater than limit * * @param {String} name The name of the variable being tested * @param {*} test The value to test * @param {Number} limit The limit value to compare against * @exception {DeveloperError} test must be typeof 'number' and greater than limit */ Check.typeOf.number.greaterThan = function (name, test, limit) { Check.typeOf.number(name, test); if (test <= limit) { throw new DeveloperError('Expected ' + name + ' to be greater than ' + limit + ', actual value was ' + test); } }; /** * Throws if test is not typeof 'number' and greater than or equal to limit * * @param {String} name The name of the variable being tested * @param {*} test The value to test * @param {Number} limit The limit value to compare against * @exception {DeveloperError} test must be typeof 'number' and greater than or equal to limit */ Check.typeOf.number.greaterThanOrEquals = function (name, test, limit) { Check.typeOf.number(name, test); if (test < limit) { throw new DeveloperError('Expected ' + name + ' to be greater than or equal to' + limit + ', actual value was ' + test); } }; /** * Throws if test is not typeof 'object' * * @param {String} name The name of the variable being tested * @param {*} test The value to test * @exception {DeveloperError} test must be typeof 'object' */ Check.typeOf.object = function (name, test) { if (typeof test !== 'object') { throw new DeveloperError(getFailedTypeErrorMessage(typeof test, 'object', name)); } }; /** * Throws if test is not typeof 'boolean' * * @param {String} name The name of the variable being tested * @param {*} test The value to test * @exception {DeveloperError} test must be typeof 'boolean' */ Check.typeOf.bool = function (name, test) { if (typeof test !== 'boolean') { throw new DeveloperError(getFailedTypeErrorMessage(typeof test, 'boolean', name)); } }; /** * Throws if test1 and test2 is not typeof 'number' and not equal in value * * @param {String} name1 The name of the first variable being tested * @param {String} name2 The name of the second variable being tested against * @param {*} test1 The value to test * @param {*} test2 The value to test against * @exception {DeveloperError} test1 and test2 should be type of 'number' and be equal in value */ Check.typeOf.number.equals = function (name1, name2, test1, test2) { Check.typeOf.number(name1, test1); Check.typeOf.number(name2, test2); if (test1 !== test2) { throw new DeveloperError(name1 + ' must be equal to ' + name2 + ', the actual values are ' + test1 + ' and ' + test2); } }; return Check; }); define('Core/freezeObject',[ './defined' ], function( defined) { 'use strict'; /** * Freezes an object, using Object.freeze if available, otherwise returns * the object unchanged. This function should be used in setup code to prevent * errors from completely halting JavaScript execution in legacy browsers. * * @private * * @exports freezeObject */ var freezeObject = Object.freeze; if (!defined(freezeObject)) { freezeObject = function(o) { return o; }; } return freezeObject; }); define('Core/defaultValue',[ './freezeObject' ], function( freezeObject) { 'use strict'; /** * Returns the first parameter if not undefined, otherwise the second parameter. * Useful for setting a default value for a parameter. * * @exports defaultValue * * @param {*} a * @param {*} b * @returns {*} Returns the first parameter if not undefined, otherwise the second parameter. * * @example * param = Cesium.defaultValue(param, 'default'); */ function defaultValue(a, b) { if (a !== undefined && a !== null) { return a; } return b; } /** * A frozen empty object that can be used as the default value for options passed as * an object literal. */ defaultValue.EMPTY_OBJECT = freezeObject({}); return defaultValue; }); define('Core/arrayFill',[ './Check', './defaultValue', './defined' ], function( Check, defaultValue, defined) { 'use strict'; /** * Fill an array or a portion of an array with a given value. * * @param {Array} array The array to fill. * @param {*} value The value to fill the array with. * @param {Number} [start=0] The index to start filling at. * @param {Number} [end=array.length] The index to end stop at. * * @returns {Array} The resulting array. * @private */ function arrayFill(array, value, start, end) { Check.defined('array', array); Check.defined('value', value); if (defined(start)) { Check.typeOf.number('start', start); } if (defined(end)) { Check.typeOf.number('end', end); } if (typeof array.fill === 'function') { return array.fill(value, start, end); } var length = array.length >>> 0; var relativeStart = defaultValue(start, 0); // If negative, find wrap around position var k = (relativeStart < 0) ? Math.max(length + relativeStart, 0) : Math.min(relativeStart, length); var relativeEnd = defaultValue(end, length); // If negative, find wrap around position var last = (relativeEnd < 0) ? Math.max(length + relativeEnd, 0) : Math.min(relativeEnd, length); // Fill array accordingly while (k < last) { array[k] = value; k++; } return array; } return arrayFill; }); /* I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace so it's better encapsulated. Now you can have multiple random number generators and they won't stomp all over eachother's state. If you want to use this as a substitute for Math.random(), use the random() method like so: var m = new MersenneTwister(); var randomNumber = m.random(); You can also call the other genrand_{foo}() methods on the instance. If you want to use a specific seed in order to get a repeatable random sequence, pass an integer into the constructor: var m = new MersenneTwister(123); and that will always produce the same random sequence. Sean McCullough (banksean@gmail.com) */ /* A C-program for MT19937, with initialization improved 2002/1/26. Coded by Takuji Nishimura and Makoto Matsumoto. Before using, initialize the state by using init_genrand(seed) or init_by_array(init_key, key_length). */ /** @license mersenne-twister.js - https://gist.github.com/banksean/300494 Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Any feedback is very welcome. http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) */ define('ThirdParty/mersenne-twister',[],function() { var MersenneTwister = function(seed) { if (seed == undefined) { seed = new Date().getTime(); } /* Period parameters */ this.N = 624; this.M = 397; this.MATRIX_A = 0x9908b0df; /* constant vector a */ this.UPPER_MASK = 0x80000000; /* most significant w-r bits */ this.LOWER_MASK = 0x7fffffff; /* least significant r bits */ this.mt = new Array(this.N); /* the array for the state vector */ this.mti=this.N+1; /* mti==N+1 means mt[N] is not initialized */ this.init_genrand(seed); } /* initializes mt[N] with a 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; /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ /* In the previous versions, MSBs of the seed affect */ /* only MSBs of the array mt[]. */ /* 2002/01/09 modified by Makoto Matsumoto */ this.mt[this.mti] >>>= 0; /* for >32 bit machines */ } } /* initialize by an array with array-length */ /* init_key is the array for initializing keys */ /* key_length is its length */ /* slight change for C++, 2004/2/26 */ //MersenneTwister.prototype.init_by_array = function(init_key, key_length) { // var i, j, k; // this.init_genrand(19650218); // i=1; j=0; // k = (this.N>key_length ? this.N : key_length); // for (; k; k--) { // var s = this.mt[i-1] ^ (this.mt[i-1] >>> 30) // this.mt[i] = (this.mt[i] ^ (((((s & 0xffff0000) >>> 16) * 1664525) << 16) + ((s & 0x0000ffff) * 1664525))) // + init_key[j] + j; /* non linear */ // this.mt[i] >>>= 0; /* for WORDSIZE > 32 machines */ // i++; j++; // if (i>=this.N) { this.mt[0] = this.mt[this.N-1]; i=1; } // if (j>=key_length) j=0; // } // for (k=this.N-1; k; k--) { // var s = this.mt[i-1] ^ (this.mt[i-1] >>> 30); // this.mt[i] = (this.mt[i] ^ (((((s & 0xffff0000) >>> 16) * 1566083941) << 16) + (s & 0x0000ffff) * 1566083941)) // - i; /* non linear */ // this.mt[i] >>>= 0; /* for WORDSIZE > 32 machines */ // i++; // if (i>=this.N) { this.mt[0] = this.mt[this.N-1]; i=1; } // } // // this.mt[0] = 0x80000000; /* MSB is 1; assuring non-zero initial array */ //} /* generates a random number on [0,0xffffffff]-interval */ MersenneTwister.prototype.genrand_int32 = function() { var y; var mag01 = new Array(0x0, this.MATRIX_A); /* mag01[x] = x * MATRIX_A for x=0,1 */ if (this.mti >= this.N) { /* generate N words at one time */ var kk; if (this.mti == this.N+1) /* if init_genrand() has not been called, */ this.init_genrand(5489); /* a default initial seed is used */ 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++]; /* Tempering */ y ^= (y >>> 11); y ^= (y << 7) & 0x9d2c5680; y ^= (y << 15) & 0xefc60000; y ^= (y >>> 18); return y >>> 0; } /* generates a random number on [0,0x7fffffff]-interval */ //MersenneTwister.prototype.genrand_int31 = function() { // return (this.genrand_int32()>>>1); //} /* generates a random number on [0,1]-real-interval */ //MersenneTwister.prototype.genrand_real1 = function() { // return this.genrand_int32()*(1.0/4294967295.0); // /* divided by 2^32-1 */ //} /* generates a random number on [0,1)-real-interval */ MersenneTwister.prototype.random = function() { return this.genrand_int32()*(1.0/4294967296.0); /* divided by 2^32 */ } /* generates a random number on (0,1)-real-interval */ //MersenneTwister.prototype.genrand_real3 = function() { // return (this.genrand_int32() + 0.5)*(1.0/4294967296.0); // /* divided by 2^32 */ //} /* generates a random number on [0,1) with 53-bit resolution*/ //MersenneTwister.prototype.genrand_res53 = function() { // var a=this.genrand_int32()>>>5, b=this.genrand_int32()>>>6; // return(a*67108864.0+b)*(1.0/9007199254740992.0); //} /* These real versions are due to Isaku Wada, 2002/01/09 added */ return MersenneTwister; }); define('Core/Math',[ '../ThirdParty/mersenne-twister', './defaultValue', './defined', './DeveloperError' ], function( MersenneTwister, defaultValue, defined, DeveloperError) { 'use strict'; /** * Math functions. * * @exports CesiumMath * @alias Math */ var CesiumMath = {}; /** * 0.1 * @type {Number} * @constant */ CesiumMath.EPSILON1 = 0.1; /** * 0.01 * @type {Number} * @constant */ CesiumMath.EPSILON2 = 0.01; /** * 0.001 * @type {Number} * @constant */ CesiumMath.EPSILON3 = 0.001; /** * 0.0001 * @type {Number} * @constant */ CesiumMath.EPSILON4 = 0.0001; /** * 0.00001 * @type {Number} * @constant */ CesiumMath.EPSILON5 = 0.00001; /** * 0.000001 * @type {Number} * @constant */ CesiumMath.EPSILON6 = 0.000001; /** * 0.0000001 * @type {Number} * @constant */ CesiumMath.EPSILON7 = 0.0000001; /** * 0.00000001 * @type {Number} * @constant */ CesiumMath.EPSILON8 = 0.00000001; /** * 0.000000001 * @type {Number} * @constant */ CesiumMath.EPSILON9 = 0.000000001; /** * 0.0000000001 * @type {Number} * @constant */ CesiumMath.EPSILON10 = 0.0000000001; /** * 0.00000000001 * @type {Number} * @constant */ CesiumMath.EPSILON11 = 0.00000000001; /** * 0.000000000001 * @type {Number} * @constant */ CesiumMath.EPSILON12 = 0.000000000001; /** * 0.0000000000001 * @type {Number} * @constant */ CesiumMath.EPSILON13 = 0.0000000000001; /** * 0.00000000000001 * @type {Number} * @constant */ CesiumMath.EPSILON14 = 0.00000000000001; /** * 0.000000000000001 * @type {Number} * @constant */ CesiumMath.EPSILON15 = 0.000000000000001; /** * 0.0000000000000001 * @type {Number} * @constant */ CesiumMath.EPSILON16 = 0.0000000000000001; /** * 0.00000000000000001 * @type {Number} * @constant */ CesiumMath.EPSILON17 = 0.00000000000000001; /** * 0.000000000000000001 * @type {Number} * @constant */ CesiumMath.EPSILON18 = 0.000000000000000001; /** * 0.0000000000000000001 * @type {Number} * @constant */ CesiumMath.EPSILON19 = 0.0000000000000000001; /** * 0.00000000000000000001 * @type {Number} * @constant */ CesiumMath.EPSILON20 = 0.00000000000000000001; /** * 3.986004418e14 * @type {Number} * @constant */ CesiumMath.GRAVITATIONALPARAMETER = 3.986004418e14; /** * Radius of the sun in meters: 6.955e8 * @type {Number} * @constant */ CesiumMath.SOLAR_RADIUS = 6.955e8; /** * The mean radius of the moon, according to the "Report of the IAU/IAG Working Group on * Cartographic Coordinates and Rotational Elements of the Planets and satellites: 2000", * Celestial Mechanics 82: 83-110, 2002. * @type {Number} * @constant */ CesiumMath.LUNAR_RADIUS = 1737400.0; /** * 64 * 1024 * @type {Number} * @constant */ CesiumMath.SIXTY_FOUR_KILOBYTES = 64 * 1024; /** * Returns the sign of the value; 1 if the value is positive, -1 if the value is * negative, or 0 if the value is 0. * * @param {Number} value The value to return the sign of. * @returns {Number} The sign of value. */ CesiumMath.sign = defaultValue(Math.sign, function sign(value) { value = +value; // coerce to number if (value === 0 || value !== value) { // zero or NaN return value; } return value > 0 ? 1 : -1; }); /** * Returns 1.0 if the given value is positive or zero, and -1.0 if it is negative. * This is similar to {@link CesiumMath#sign} except that returns 1.0 instead of * 0.0 when the input value is 0.0. * @param {Number} value The value to return the sign of. * @returns {Number} The sign of value. */ CesiumMath.signNotZero = function(value) { return value < 0.0 ? -1.0 : 1.0; }; /** * Converts a scalar value in the range [-1.0, 1.0] to a SNORM in the range [0, rangeMax] * @param {Number} value The scalar value in the range [-1.0, 1.0] * @param {Number} [rangeMax=255] The maximum value in the mapped range, 255 by default. * @returns {Number} A SNORM value, where 0 maps to -1.0 and rangeMax maps to 1.0. * * @see CesiumMath.fromSNorm */ CesiumMath.toSNorm = function(value, rangeMax) { rangeMax = defaultValue(rangeMax, 255); return Math.round((CesiumMath.clamp(value, -1.0, 1.0) * 0.5 + 0.5) * rangeMax); }; /** * Converts a SNORM value in the range [0, rangeMax] to a scalar in the range [-1.0, 1.0]. * @param {Number} value SNORM value in the range [0, 255] * @param {Number} [rangeMax=255] The maximum value in the SNORM range, 255 by default. * @returns {Number} Scalar in the range [-1.0, 1.0]. * * @see CesiumMath.toSNorm */ CesiumMath.fromSNorm = function(value, rangeMax) { rangeMax = defaultValue(rangeMax, 255); return CesiumMath.clamp(value, 0.0, rangeMax) / rangeMax * 2.0 - 1.0; }; /** * Returns the hyperbolic sine of a number. * The hyperbolic sine of <em>value</em> is defined to be * (<em>e<sup>x</sup>&nbsp;-&nbsp;e<sup>-x</sup></em>)/2.0 * where <i>e</i> is Euler's number, approximately 2.71828183. * * <p>Special cases: * <ul> * <li>If the argument is NaN, then the result is NaN.</li> * * <li>If the argument is infinite, then the result is an infinity * with the same sign as the argument.</li> * * <li>If the argument is zero, then the result is a zero with the * same sign as the argument.</li> * </ul> *</p> * * @param {Number} value The number whose hyperbolic sine is to be returned. * @returns {Number} The hyperbolic sine of <code>value</code>. */ CesiumMath.sinh = defaultValue(Math.sinh, function sinh(value) { return (Math.exp(value) - Math.exp(-value)) / 2.0; }); /** * Returns the hyperbolic cosine of a number. * The hyperbolic cosine of <strong>value</strong> is defined to be * (<em>e<sup>x</sup>&nbsp;+&nbsp;e<sup>-x</sup></em>)/2.0 * where <i>e</i> is Euler's number, approximately 2.71828183. * * <p>Special cases: * <ul> * <li>If the argument is NaN, then the result is NaN.</li> * * <li>If the argument is infinite, then the result is positive infinity.</li> * * <li>If the argument is zero, then the result is 1.0.</li> * </ul> *</p> * * @param {Number} value The number whose hyperbolic cosine is to be returned. * @returns {Number} The hyperbolic cosine of <code>value</code>. */ CesiumMath.cosh = defaultValue(Math.cosh, function cosh(value) { return (Math.exp(value) + Math.exp(-value)) / 2.0; }); /** * Computes the linear interpolation of two values. * * @param {Number} p The start value to interpolate. * @param {Number} q The end value to interpolate. * @param {Number} time The time of interpolation generally in the range <code>[0.0, 1.0]</code>. * @returns {Number} The linearly interpolated value. * * @example * var n = Cesium.Math.lerp(0.0, 2.0, 0.5); // returns 1.0 */ CesiumMath.lerp = function(p, q, time) { return ((1.0 - time) * p) + (time * q); }; /** * pi * * @type {Number} * @constant */ CesiumMath.PI = Math.PI; /** * 1/pi * * @type {Number} * @constant */ CesiumMath.ONE_OVER_PI = 1.0 / Math.PI; /** * pi/2 * * @type {Number} * @constant */ CesiumMath.PI_OVER_TWO = Math.PI / 2.0; /** * pi/3 * * @type {Number} * @constant */ CesiumMath.PI_OVER_THREE = Math.PI / 3.0; /** * pi/4 * * @type {Number} * @constant */ CesiumMath.PI_OVER_FOUR = Math.PI / 4.0; /** * pi/6 * * @type {Number} * @constant */ CesiumMath.PI_OVER_SIX = Math.PI / 6.0; /** * 3pi/2 * * @type {Number} * @constant */ CesiumMath.THREE_PI_OVER_TWO = 3.0 * Math.PI / 2.0; /** * 2pi * * @type {Number} * @constant */ CesiumMath.TWO_PI = 2.0 * Math.PI; /** * 1/2pi * * @type {Number} * @constant */ CesiumMath.ONE_OVER_TWO_PI = 1.0 / (2.0 * Math.PI); /** * The number of radians in a degree. * * @type {Number} * @constant * @default Math.PI / 180.0 */ CesiumMath.RADIANS_PER_DEGREE = Math.PI / 180.0; /** * The number of degrees in a radian. * * @type {Number} * @constant * @default 180.0 / Math.PI */ CesiumMath.DEGREES_PER_RADIAN = 180.0 / Math.PI; /** * The number of radians in an arc second. * * @type {Number} * @constant * @default {@link CesiumMath.RADIANS_PER_DEGREE} / 3600.0 */ CesiumMath.RADIANS_PER_ARCSECOND = CesiumMath.RADIANS_PER_DEGREE / 3600.0; /** * Converts degrees to radians. * @param {Number} degrees The angle to convert in degrees. * @returns {Number} The corresponding angle in radians. */ CesiumMath.toRadians = function(degrees) { if (!defined(degrees)) { throw new DeveloperError('degrees is required.'); } return degrees * CesiumMath.RADIANS_PER_DEGREE; }; /** * Converts radians to degrees. * @param {Number} radians The angle to convert in radians. * @returns {Number} The corresponding angle in degrees. */ CesiumMath.toDegrees = function(radians) { if (!defined(radians)) { throw new DeveloperError('radians is required.'); } return radians * CesiumMath.DEGREES_PER_RADIAN; }; /** * Converts a longitude value, in radians, to the range [<code>-Math.PI</code>, <code>Math.PI</code>). * * @param {Number} angle The longitude value, in radians, to convert to the range [<code>-Math.PI</code>, <code>Math.PI</code>). * @returns {Number} The equivalent longitude value in the range [<code>-Math.PI</code>, <code>Math.PI</code>). * * @example * // Convert 270 degrees to -90 degrees longitude * var longitude = Cesium.Math.convertLongitudeRange(Cesium.Math.toRadians(270.0)); */ CesiumMath.convertLongitudeRange = function(angle) { if (!defined(angle)) { throw new 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; }; /** * Convenience function that clamps a latitude value, in radians, to the range [<code>-Math.PI/2</code>, <code>Math.PI/2</code>). * Useful for sanitizing data before use in objects requiring correct range. * * @param {Number} angle The latitude value, in radians, to clamp to the range [<code>-Math.PI/2</code>, <code>Math.PI/2</code>). * @returns {Number} The latitude value clamped to the range [<code>-Math.PI/2</code>, <code>Math.PI/2</code>). * * @example * // Clamp 108 degrees latitude to 90 degrees latitude * var latitude = Cesium.Math.clampToLatitudeRange(Cesium.Math.toRadians(108.0)); */ CesiumMath.clampToLatitudeRange = function(angle) { if (!defined(angle)) { throw new DeveloperError('angle is required.'); }