Migrate Cesium to ES6 Modules
See https://github.com/AnalyticalGraphicsInc/cesium/pull/8224 for details.
eslint
There are a handful of new .eslintrc.json files, mostly to identify the files that are still AMD modules (Sandcastle/Workers). These are needed because you can't change the parser type with a comment directive (since the parser is the thing reading the file). We can finally detect unusued modules! So those have all been cleaned up as well.
requirejs -> rollup & clean-css
requirejs, almond, and karma-requirejs have all been removed. We now use rollup for building and minifying (via uglify) JS code and clean-css for css. These changes are fairly straight-forward and just involve calling rollup instead of requirejs in the build process.
Overall build time is significantly faster. CI is ~11 minutes compared to ~17 in master. Running makeZipFile on my machine takes 69 seconds compared to 112 seconds in master. There's probably plenty of room for additional optimization here too.
We wrote an published a small npm module, rollup-plugin-strip-pragma, for stripping the requirejs pragmas we use out of the release builds. This is maintained in the Tools/rollup-plugin-strip-pragma directory.
As for what we produce. The built version of Cesium is now a UMD module. So it should work anywhere that hasn't made the jump to ES6 yet. For users that were already using the "legacy" combined/minified approach, nothing changes.
One awesome thing about roll-up is that it compiles all of the workers at once and automatically detects shared codes and generates separate bundles under the hood. This means the size of our worker modules shrink dramatically and Cesium itself will load them much faster. The total minified/gzipped size of all workers in master is 2.6 MB compared to 225 KB in this branch! This should be most noticeable on demos like Geometry & Appearances which load lots of workers for the various geometry typs.
roll-up is also used to build Cesium Viewer, which is now an ES6 app.
We use clean-css via gulp and it is also a straightforward change from requirejs that requires no special mention.
Workers
While the spec allows for ES6 Web Workers, no browser actually supports them yet. That means we needed a way to get our workers into non-ES6 form. Thankfully, roll-up can generate AMD modules, which means we now have a build step to compile our Worker source code back into AMD and use the existing TaskProcessor to load and execute them. This build step is part of the standard build task and is called createWorkers. During development, these "built" workers are un-optimized so you can still debug them and read the code.
Since there is a build step, that means if you are changing code that affects a worker, you need to re-run build, or you can use the build-watch task to do it automatically.
The ES6 versions of Worker code has moved into Source/WorkersES6 and we build the workers into their "old home" of Source/Workers. cesiumWorkerBootstrapper and transferTypedArrayTest which were already non-AMD ES5 scripts remain living in the Workers directory.
Surprisingly little was changed about TaskProcessor or the worker system in general, especially considering that I thought this would be one of the major hurdles.
ThirdParty
A lot of our ThirdParty either already had a hand-written wrapper for AMD (which I updated to ES6) or had UMD which created problems when importing the same code in both Node and the browser. I basically had to update the wrapper of every third-party library to fix these problems. In some cases I updated the library version itself (Autolinker, topojson). Nothing to be too concerned about, but future clean-up would be using npm versions of these libraries and auto-generating the wrappers as needed so we don't hand-edit things.
Sandcastle
Sandcastle is eternal and manages to live another day in it's ancient requirejs/dojo 1.x form. Sandcastle now automatically uses the ES6 version of Cesium if it is available and fallsback to the ES5 unminified version if it is now. The built version of Sandcastle always uses CesiumUnminified, just like master. This means Sandcastle still works in IE11 if you run the combine step first (or use the relase zip)
Removed Cesium usage from Sandcastle proper, since it wasn't really needed
Generate a VERSION propertyin the gallery index since Cesium is no longer being included.
Remove requirejs from Sandcastle bucket
Update bucket to use the built version of Cesium if it is available by fallbackto the ES6 version during development.
Standalone.html was also updated
There's a bit of room for further clean-up here, but I think this gets us into master. I did not rename bucket-requirejs.html because I'm pretty sure it would break previously shared demos. We can put in some backwards compatible code later on if we want. (But I'd rather just see a full Sandcastle rewrite).
Specs
Specs are now all ES6, except for TestWorkers, which remain standard JS worker modules. This means you can no longer run the unbuilt unit tests in IE11. No changes for Chrome and Firefox.
Since the specs use ES6 modules and built Cesium is an ES5 UMD, I added a build-specs build step which generates a combined ES5 version of the specs which rely on Cesium as a global variable. We then inject these files into jasmine instead of the standard specs and everything works exactly as it did before. SpecRunner.html has been updated to inject the correct version of the script depending on the build/release query parameters.
The Specs must always use Cesium by importing Source/Cesium.js, this is so we can replace it with the built Cesium as describe above.
There's a bunch of room for clean-up here, such as unifying our two copies of jasmine into a single helper file, but I didn't want to start doing that clean-up as part of this already overly big PR. The important thing is that we can still test the built version and still test on IE/Edge as needed.
I also found and fixed two bugs that were causing failing unit tests, one in BingMapsImageryProviderSpec.js (which was overwriting createImage andnot setting it back) and ShadowVolumeAppearance.js (which had a module level caching bug). I think these may have been the cause of random CI failures in master as well, but only time will tell.
For coverage, we had to switch to karma-coverage-istanbul-instrumenter for native ES6 support, but that's it.
Finally, I updated appveryor to build Cesium and run the built tests under IE. We still don't fail the build for IE, but we should probably fix that if we want to keep it going.
NodeJS
When NODE_ENV is production, we now require in the minified CesiumJS directly, which works great because it's now a UMD module. Otherwise, we use the excellant esmpackage to load individual modules, it was a fairly straightforward swap from our old requirejs usage. We could probably drop esm too if we don't care about debugging or if we provie source maps at some point.
2019-10-03 23:51:23 +08:00
|
|
|
import Check from "./Check.js";
|
|
|
|
|
import defined from "./defined.js";
|
|
|
|
|
import DeveloperError from "./DeveloperError.js";
|
|
|
|
|
import CesiumMath from "./Math.js";
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
|
|
|
|
* A 4D Cartesian point.
|
2012-06-27 02:20:12 +08:00
|
|
|
* @alias Cartesian4
|
2012-04-17 07:38:31 +08:00
|
|
|
* @constructor
|
2012-04-19 01:28:29 +08:00
|
|
|
*
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number} [x=0.0] The X component.
|
|
|
|
|
* @param {number} [y=0.0] The Y component.
|
|
|
|
|
* @param {number} [z=0.0] The Z component.
|
|
|
|
|
* @param {number} [w=0.0] The W component.
|
2012-04-19 01:28:29 +08:00
|
|
|
*
|
2012-04-17 07:38:31 +08:00
|
|
|
* @see Cartesian2
|
2012-07-16 22:26:35 +08:00
|
|
|
* @see Cartesian3
|
2013-08-20 03:59:46 +08:00
|
|
|
* @see Packable
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2015-12-12 09:31:44 +08:00
|
|
|
function Cartesian4(x, y, z, w) {
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* The X component.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @type {number}
|
2013-06-28 04:36:25 +08:00
|
|
|
* @default 0.0
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2025-03-04 03:03:53 +08:00
|
|
|
this.x = x ?? 0.0;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* The Y component.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @type {number}
|
2013-06-28 04:36:25 +08:00
|
|
|
* @default 0.0
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2025-03-04 03:03:53 +08:00
|
|
|
this.y = y ?? 0.0;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* The Z component.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @type {number}
|
2013-06-28 04:36:25 +08:00
|
|
|
* @default 0.0
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2025-03-04 03:03:53 +08:00
|
|
|
this.z = z ?? 0.0;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* The W component.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @type {number}
|
2013-06-28 04:36:25 +08:00
|
|
|
* @default 0.0
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2025-03-04 03:03:53 +08:00
|
|
|
this.w = w ?? 0.0;
|
2015-12-12 09:31:44 +08:00
|
|
|
}
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-05-08 21:37:29 +08:00
|
|
|
/**
|
2013-05-17 21:41:36 +08:00
|
|
|
* Creates a Cartesian4 instance from x, y, z and w coordinates.
|
|
|
|
|
*
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number} x The x coordinate.
|
|
|
|
|
* @param {number} y The y coordinate.
|
|
|
|
|
* @param {number} z The z coordinate.
|
|
|
|
|
* @param {number} w The w coordinate.
|
2014-06-11 23:57:21 +08:00
|
|
|
* @param {Cartesian4} [result] The object onto which to store the result.
|
2013-09-01 10:47:46 +08:00
|
|
|
* @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
|
2013-05-08 21:37:29 +08:00
|
|
|
*/
|
|
|
|
|
Cartesian4.fromElements = function (x, y, z, w, result) {
|
2013-08-12 11:05:36 +08:00
|
|
|
if (!defined(result)) {
|
2014-06-11 23:57:21 +08:00
|
|
|
return new Cartesian4(x, y, z, w);
|
2013-05-08 21:37:29 +08:00
|
|
|
}
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-05-08 21:37:29 +08:00
|
|
|
result.x = x;
|
|
|
|
|
result.y = y;
|
|
|
|
|
result.z = z;
|
|
|
|
|
result.w = w;
|
|
|
|
|
return result;
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-04-12 23:37:31 +08:00
|
|
|
/**
|
2014-04-16 01:00:05 +08:00
|
|
|
* Creates a Cartesian4 instance from a {@link Color}. <code>red</code>, <code>green</code>, <code>blue</code>,
|
|
|
|
|
* and <code>alpha</code> map to <code>x</code>, <code>y</code>, <code>z</code>, and <code>w</code>, respectively.
|
|
|
|
|
*
|
|
|
|
|
* @param {Color} color The source color.
|
|
|
|
|
* @param {Cartesian4} [result] The object onto which to store the result.
|
|
|
|
|
* @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
|
2014-04-12 23:37:31 +08:00
|
|
|
*/
|
|
|
|
|
Cartesian4.fromColor = function (color, result) {
|
|
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("color", color);
|
2014-04-12 23:37:31 +08:00
|
|
|
//>>includeEnd('debug');
|
|
|
|
|
if (!defined(result)) {
|
2014-06-11 23:57:21 +08:00
|
|
|
return new Cartesian4(color.red, color.green, color.blue, color.alpha);
|
2014-04-12 23:37:31 +08:00
|
|
|
}
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-04-12 23:37:31 +08:00
|
|
|
result.x = color.red;
|
|
|
|
|
result.y = color.green;
|
|
|
|
|
result.z = color.blue;
|
|
|
|
|
result.w = color.alpha;
|
|
|
|
|
return result;
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-19 01:28:29 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Duplicates a Cartesian4 instance.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} cartesian The Cartesian to duplicate.
|
|
|
|
|
* @param {Cartesian4} [result] The object onto which to store the result.
|
2013-09-01 10:47:46 +08:00
|
|
|
* @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided. (Returns undefined if cartesian is undefined)
|
2012-04-19 01:28:29 +08:00
|
|
|
*/
|
2012-07-14 04:53:46 +08:00
|
|
|
Cartesian4.clone = function (cartesian, result) {
|
2013-08-12 11:05:36 +08:00
|
|
|
if (!defined(cartesian)) {
|
2013-06-21 23:12:09 +08:00
|
|
|
return undefined;
|
2012-07-14 04:53:46 +08:00
|
|
|
}
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-08-12 11:05:36 +08:00
|
|
|
if (!defined(result)) {
|
2014-06-12 01:55:50 +08:00
|
|
|
return new Cartesian4(cartesian.x, cartesian.y, cartesian.z, cartesian.w);
|
2012-07-14 04:53:46 +08:00
|
|
|
}
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
result.x = cartesian.x;
|
|
|
|
|
result.y = cartesian.y;
|
|
|
|
|
result.z = cartesian.z;
|
|
|
|
|
result.w = cartesian.w;
|
|
|
|
|
return result;
|
2012-04-19 01:28:29 +08:00
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-08-20 03:59:46 +08:00
|
|
|
/**
|
|
|
|
|
* The number of elements used to pack the object into an array.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @type {number}
|
2013-08-20 03:59:46 +08:00
|
|
|
*/
|
|
|
|
|
Cartesian4.packedLength = 4;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-08-20 03:59:46 +08:00
|
|
|
/**
|
|
|
|
|
* Stores the provided instance into the provided array.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} value The value to pack.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number[]} array The array to pack into.
|
|
|
|
|
* @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
|
2016-08-01 20:57:41 +08:00
|
|
|
*
|
2023-02-10 16:35:41 +08:00
|
|
|
* @returns {number[]} The array that was packed into
|
2013-08-20 03:59:46 +08:00
|
|
|
*/
|
|
|
|
|
Cartesian4.pack = function (value, array, startingIndex) {
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("value", value);
|
|
|
|
|
Check.defined("array", array);
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2025-03-04 03:03:53 +08:00
|
|
|
startingIndex = startingIndex ?? 0;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-08-20 03:59:46 +08:00
|
|
|
array[startingIndex++] = value.x;
|
|
|
|
|
array[startingIndex++] = value.y;
|
|
|
|
|
array[startingIndex++] = value.z;
|
|
|
|
|
array[startingIndex] = value.w;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2016-07-29 02:57:56 +08:00
|
|
|
return array;
|
2013-08-20 03:59:46 +08:00
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-08-20 03:59:46 +08:00
|
|
|
/**
|
|
|
|
|
* Retrieves an instance from a packed array.
|
|
|
|
|
*
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number[]} array The packed array.
|
|
|
|
|
* @param {number} [startingIndex=0] The starting index of the element to be unpacked.
|
2013-08-20 03:59:46 +08:00
|
|
|
* @param {Cartesian4} [result] The object into which to store the result.
|
2014-06-11 23:57:21 +08:00
|
|
|
* @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
|
2013-08-20 03:59:46 +08:00
|
|
|
*/
|
|
|
|
|
Cartesian4.unpack = function (array, startingIndex, result) {
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.defined("array", array);
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2025-03-04 03:03:53 +08:00
|
|
|
startingIndex = startingIndex ?? 0;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-08-20 03:59:46 +08:00
|
|
|
if (!defined(result)) {
|
|
|
|
|
result = new Cartesian4();
|
|
|
|
|
}
|
|
|
|
|
result.x = array[startingIndex++];
|
|
|
|
|
result.y = array[startingIndex++];
|
|
|
|
|
result.z = array[startingIndex++];
|
|
|
|
|
result.w = array[startingIndex];
|
|
|
|
|
return result;
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2016-06-04 04:42:43 +08:00
|
|
|
/**
|
2022-02-19 00:47:04 +08:00
|
|
|
* Flattens an array of Cartesian4s into an array of components.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4[]} array The array of cartesians to pack.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 4 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 4) elements.
|
|
|
|
|
* @returns {number[]} The packed array.
|
2022-02-19 00:47:04 +08:00
|
|
|
*/
|
2016-06-04 04:42:43 +08:00
|
|
|
Cartesian4.packArray = function (array, result) {
|
|
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.defined("array", array);
|
2016-06-04 04:42:43 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2016-06-04 04:42:43 +08:00
|
|
|
const length = array.length;
|
2020-01-28 03:32:20 +08:00
|
|
|
const resultLength = length * 4;
|
2016-06-04 04:42:43 +08:00
|
|
|
if (!defined(result)) {
|
2020-01-28 03:32:20 +08:00
|
|
|
result = new Array(resultLength);
|
|
|
|
|
} else if (!Array.isArray(result) && result.length !== resultLength) {
|
2022-02-19 02:16:29 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2020-01-28 03:32:20 +08:00
|
|
|
throw new DeveloperError(
|
|
|
|
|
"If result is a typed array, it must have exactly array.length * 4 elements",
|
|
|
|
|
);
|
2022-02-19 02:16:29 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-01-28 03:32:20 +08:00
|
|
|
} else if (result.length !== resultLength) {
|
|
|
|
|
result.length = resultLength;
|
2016-06-04 04:42:43 +08:00
|
|
|
}
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2016-06-04 04:42:43 +08:00
|
|
|
for (let i = 0; i < length; ++i) {
|
|
|
|
|
Cartesian4.pack(array[i], result, i * 4);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2016-06-04 04:42:43 +08:00
|
|
|
/**
|
2022-02-19 00:47:04 +08:00
|
|
|
* Unpacks an array of cartesian components into an array of Cartesian4s.
|
2016-06-04 04:42:43 +08:00
|
|
|
*
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number[]} array The array of components to unpack.
|
2019-07-18 05:51:47 +08:00
|
|
|
* @param {Cartesian4[]} [result] The array onto which to store the result.
|
2016-06-04 04:42:43 +08:00
|
|
|
* @returns {Cartesian4[]} The unpacked array.
|
|
|
|
|
*/
|
|
|
|
|
Cartesian4.unpackArray = function (array, result) {
|
|
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.defined("array", array);
|
2020-01-28 03:32:20 +08:00
|
|
|
Check.typeOf.number.greaterThanOrEquals("array.length", array.length, 4);
|
|
|
|
|
if (array.length % 4 !== 0) {
|
|
|
|
|
throw new DeveloperError("array length must be a multiple of 4.");
|
|
|
|
|
}
|
2016-06-04 04:42:43 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2016-06-04 04:42:43 +08:00
|
|
|
const length = array.length;
|
|
|
|
|
if (!defined(result)) {
|
|
|
|
|
result = new Array(length / 4);
|
|
|
|
|
} else {
|
|
|
|
|
result.length = length / 4;
|
|
|
|
|
}
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2016-06-04 04:42:43 +08:00
|
|
|
for (let i = 0; i < length; i += 4) {
|
|
|
|
|
const index = i / 4;
|
|
|
|
|
result[index] = Cartesian4.unpack(array, i, result[index]);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-09-12 05:33:50 +08:00
|
|
|
/**
|
|
|
|
|
* Creates a Cartesian4 from four consecutive elements in an array.
|
2014-06-03 22:18:21 +08:00
|
|
|
* @function
|
2013-09-12 05:33:50 +08:00
|
|
|
*
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number[]} array The array whose four consecutive elements correspond to the x, y, z, and w components, respectively.
|
|
|
|
|
* @param {number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.
|
2013-09-12 05:33:50 +08:00
|
|
|
* @param {Cartesian4} [result] The object onto which to store the result.
|
2014-06-11 23:57:21 +08:00
|
|
|
* @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
|
2013-09-12 05:33:50 +08:00
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* // Create a Cartesian4 with (1.0, 2.0, 3.0, 4.0)
|
2022-01-29 00:32:07 +08:00
|
|
|
* const v = [1.0, 2.0, 3.0, 4.0];
|
|
|
|
|
* const p = Cesium.Cartesian4.fromArray(v);
|
2013-09-12 05:33:50 +08:00
|
|
|
*
|
|
|
|
|
* // Create a Cartesian4 with (1.0, 2.0, 3.0, 4.0) using an offset into an array
|
2022-01-29 00:32:07 +08:00
|
|
|
* const v2 = [0.0, 0.0, 1.0, 2.0, 3.0, 4.0];
|
|
|
|
|
* const p2 = Cesium.Cartesian4.fromArray(v2, 2);
|
2013-09-12 05:33:50 +08:00
|
|
|
*/
|
|
|
|
|
Cartesian4.fromArray = Cartesian4.unpack;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Computes the value of the maximum component for the supplied Cartesian.
|
|
|
|
|
*
|
2014-06-11 23:57:21 +08:00
|
|
|
* @param {Cartesian4} cartesian The cartesian to use.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @returns {number} The value of the maximum component.
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2014-07-09 22:51:03 +08:00
|
|
|
Cartesian4.maximumComponent = function (cartesian) {
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("cartesian", cartesian);
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
return Math.max(cartesian.x, cartesian.y, cartesian.z, cartesian.w);
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Computes the value of the minimum component for the supplied Cartesian.
|
|
|
|
|
*
|
2014-06-11 23:57:21 +08:00
|
|
|
* @param {Cartesian4} cartesian The cartesian to use.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @returns {number} The value of the minimum component.
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2014-07-09 22:51:03 +08:00
|
|
|
Cartesian4.minimumComponent = function (cartesian) {
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("cartesian", cartesian);
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
return Math.min(cartesian.x, cartesian.y, cartesian.z, cartesian.w);
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-11-22 10:57:57 +08:00
|
|
|
/**
|
|
|
|
|
* Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} first A cartesian to compare.
|
|
|
|
|
* @param {Cartesian4} second A cartesian to compare.
|
2014-05-30 00:06:56 +08:00
|
|
|
* @param {Cartesian4} result The object into which to store the result.
|
2013-11-22 10:57:57 +08:00
|
|
|
* @returns {Cartesian4} A cartesian with the minimum components.
|
|
|
|
|
*/
|
2014-07-09 22:51:03 +08:00
|
|
|
Cartesian4.minimumByComponent = function (first, second, result) {
|
2013-11-23 05:07:00 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("first", first);
|
|
|
|
|
Check.typeOf.object("second", second);
|
|
|
|
|
Check.typeOf.object("result", result);
|
2014-05-30 00:06:56 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-11-22 10:57:57 +08:00
|
|
|
result.x = Math.min(first.x, second.x);
|
|
|
|
|
result.y = Math.min(first.y, second.y);
|
|
|
|
|
result.z = Math.min(first.z, second.z);
|
|
|
|
|
result.w = Math.min(first.w, second.w);
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-11-22 10:57:57 +08:00
|
|
|
return result;
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-11-22 10:57:57 +08:00
|
|
|
/**
|
|
|
|
|
* Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} first A cartesian to compare.
|
|
|
|
|
* @param {Cartesian4} second A cartesian to compare.
|
2014-05-30 00:06:56 +08:00
|
|
|
* @param {Cartesian4} result The object into which to store the result.
|
2013-11-22 10:57:57 +08:00
|
|
|
* @returns {Cartesian4} A cartesian with the maximum components.
|
|
|
|
|
*/
|
2014-07-09 22:51:03 +08:00
|
|
|
Cartesian4.maximumByComponent = function (first, second, result) {
|
2013-11-23 05:07:00 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("first", first);
|
|
|
|
|
Check.typeOf.object("second", second);
|
|
|
|
|
Check.typeOf.object("result", result);
|
2014-05-30 00:06:56 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-11-22 10:57:57 +08:00
|
|
|
result.x = Math.max(first.x, second.x);
|
|
|
|
|
result.y = Math.max(first.y, second.y);
|
|
|
|
|
result.z = Math.max(first.z, second.z);
|
|
|
|
|
result.w = Math.max(first.w, second.w);
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-11-22 10:57:57 +08:00
|
|
|
return result;
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2022-03-15 23:49:07 +08:00
|
|
|
/**
|
|
|
|
|
* Constrain a value to lie between two values.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} value The value to clamp.
|
|
|
|
|
* @param {Cartesian4} min The minimum bound.
|
|
|
|
|
* @param {Cartesian4} max The maximum bound.
|
|
|
|
|
* @param {Cartesian4} result The object into which to store the result.
|
|
|
|
|
* @returns {Cartesian4} The clamped value such that min <= result <= max.
|
|
|
|
|
*/
|
|
|
|
|
Cartesian4.clamp = function (value, min, max, result) {
|
|
|
|
|
//>>includeStart('debug', pragmas.debug);
|
|
|
|
|
Check.typeOf.object("value", value);
|
|
|
|
|
Check.typeOf.object("min", min);
|
|
|
|
|
Check.typeOf.object("max", max);
|
|
|
|
|
Check.typeOf.object("result", result);
|
|
|
|
|
//>>includeEnd('debug');
|
|
|
|
|
|
|
|
|
|
const x = CesiumMath.clamp(value.x, min.x, max.x);
|
|
|
|
|
const y = CesiumMath.clamp(value.y, min.y, max.y);
|
|
|
|
|
const z = CesiumMath.clamp(value.z, min.z, max.z);
|
|
|
|
|
const w = CesiumMath.clamp(value.w, min.w, max.w);
|
|
|
|
|
|
|
|
|
|
result.x = x;
|
|
|
|
|
result.y = y;
|
|
|
|
|
result.z = z;
|
|
|
|
|
result.w = w;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Computes the provided Cartesian's squared magnitude.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} cartesian The Cartesian instance whose squared magnitude is to be computed.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @returns {number} The squared magnitude.
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2012-07-14 04:53:46 +08:00
|
|
|
Cartesian4.magnitudeSquared = function (cartesian) {
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("cartesian", cartesian);
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-08-31 04:31:12 +08:00
|
|
|
return (
|
|
|
|
|
cartesian.x * cartesian.x +
|
|
|
|
|
cartesian.y * cartesian.y +
|
|
|
|
|
cartesian.z * cartesian.z +
|
|
|
|
|
cartesian.w * cartesian.w
|
|
|
|
|
);
|
2012-07-14 04:53:46 +08:00
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Computes the Cartesian's magnitude (length).
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} cartesian The Cartesian instance whose magnitude is to be computed.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @returns {number} The magnitude.
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2012-07-14 04:53:46 +08:00
|
|
|
Cartesian4.magnitude = function (cartesian) {
|
|
|
|
|
return Math.sqrt(Cartesian4.magnitudeSquared(cartesian));
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-03-07 22:28:40 +08:00
|
|
|
const distanceScratch = new Cartesian4();
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-03-07 22:28:40 +08:00
|
|
|
/**
|
2014-11-22 22:33:19 +08:00
|
|
|
* Computes the 4-space distance between two points.
|
2013-03-07 22:28:40 +08:00
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} left The first point to compute the distance from.
|
|
|
|
|
* @param {Cartesian4} right The second point to compute the distance to.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @returns {number} The distance between two points.
|
2013-03-07 22:28:40 +08:00
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* // Returns 1.0
|
2022-01-29 00:32:07 +08:00
|
|
|
* const d = Cesium.Cartesian4.distance(
|
2014-11-22 22:33:19 +08:00
|
|
|
* new Cesium.Cartesian4(1.0, 0.0, 0.0, 0.0),
|
|
|
|
|
* new Cesium.Cartesian4(2.0, 0.0, 0.0, 0.0));
|
2013-03-07 22:28:40 +08:00
|
|
|
*/
|
|
|
|
|
Cartesian4.distance = function (left, right) {
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("left", left);
|
|
|
|
|
Check.typeOf.object("right", right);
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-03-07 22:28:40 +08:00
|
|
|
Cartesian4.subtract(left, right, distanceScratch);
|
|
|
|
|
return Cartesian4.magnitude(distanceScratch);
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-11-22 22:30:57 +08:00
|
|
|
/**
|
|
|
|
|
* Computes the squared distance between two points. Comparing squared distances
|
|
|
|
|
* using this function is more efficient than comparing distances using {@link Cartesian4#distance}.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} left The first point to compute the distance from.
|
|
|
|
|
* @param {Cartesian4} right The second point to compute the distance to.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @returns {number} The distance between two points.
|
2014-11-22 22:30:57 +08:00
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* // Returns 4.0, not 2.0
|
2022-01-29 00:32:07 +08:00
|
|
|
* const d = Cesium.Cartesian4.distance(
|
2014-11-22 22:34:43 +08:00
|
|
|
* new Cesium.Cartesian4(1.0, 0.0, 0.0, 0.0),
|
|
|
|
|
* new Cesium.Cartesian4(3.0, 0.0, 0.0, 0.0));
|
2014-11-22 22:30:57 +08:00
|
|
|
*/
|
|
|
|
|
Cartesian4.distanceSquared = function (left, right) {
|
|
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("left", left);
|
|
|
|
|
Check.typeOf.object("right", right);
|
2014-11-22 22:30:57 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-11-22 22:30:57 +08:00
|
|
|
Cartesian4.subtract(left, right, distanceScratch);
|
|
|
|
|
return Cartesian4.magnitudeSquared(distanceScratch);
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Computes the normalized form of the supplied Cartesian.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} cartesian The Cartesian to be normalized.
|
2014-05-30 00:06:56 +08:00
|
|
|
* @param {Cartesian4} result The object onto which to store the result.
|
2014-06-11 23:57:21 +08:00
|
|
|
* @returns {Cartesian4} The modified result parameter.
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2012-07-14 04:53:46 +08:00
|
|
|
Cartesian4.normalize = function (cartesian, result) {
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("cartesian", cartesian);
|
|
|
|
|
Check.typeOf.object("result", result);
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
const magnitude = Cartesian4.magnitude(cartesian);
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
result.x = cartesian.x / magnitude;
|
|
|
|
|
result.y = cartesian.y / magnitude;
|
|
|
|
|
result.z = cartesian.z / magnitude;
|
|
|
|
|
result.w = cartesian.w / magnitude;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2016-02-19 06:43:07 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
|
|
|
|
if (
|
|
|
|
|
isNaN(result.x) ||
|
|
|
|
|
isNaN(result.y) ||
|
|
|
|
|
isNaN(result.z) ||
|
|
|
|
|
isNaN(result.w)
|
|
|
|
|
) {
|
|
|
|
|
throw new DeveloperError("normalized result is not a number");
|
|
|
|
|
}
|
|
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
return result;
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Computes the dot (scalar) product of two Cartesians.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} left The first Cartesian.
|
|
|
|
|
* @param {Cartesian4} right The second Cartesian.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @returns {number} The dot product.
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2012-07-14 04:53:46 +08:00
|
|
|
Cartesian4.dot = function (left, right) {
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("left", left);
|
|
|
|
|
Check.typeOf.object("right", right);
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
return (
|
|
|
|
|
left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w
|
|
|
|
|
);
|
2012-04-17 07:38:31 +08:00
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Computes the componentwise product of two Cartesians.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} left The first Cartesian.
|
|
|
|
|
* @param {Cartesian4} right The second Cartesian.
|
2014-05-30 00:06:56 +08:00
|
|
|
* @param {Cartesian4} result The object onto which to store the result.
|
2014-06-11 23:57:21 +08:00
|
|
|
* @returns {Cartesian4} The modified result parameter.
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2012-07-14 04:53:46 +08:00
|
|
|
Cartesian4.multiplyComponents = function (left, right, result) {
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("left", left);
|
|
|
|
|
Check.typeOf.object("right", right);
|
|
|
|
|
Check.typeOf.object("result", result);
|
2014-05-30 00:06:56 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
result.x = left.x * right.x;
|
|
|
|
|
result.y = left.y * right.y;
|
|
|
|
|
result.z = left.z * right.z;
|
|
|
|
|
result.w = left.w * right.w;
|
|
|
|
|
return result;
|
2012-04-17 07:38:31 +08:00
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2016-12-14 05:09:56 +08:00
|
|
|
/**
|
|
|
|
|
* Computes the componentwise quotient of two Cartesians.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} left The first Cartesian.
|
|
|
|
|
* @param {Cartesian4} right The second Cartesian.
|
|
|
|
|
* @param {Cartesian4} result The object onto which to store the result.
|
|
|
|
|
* @returns {Cartesian4} The modified result parameter.
|
|
|
|
|
*/
|
|
|
|
|
Cartesian4.divideComponents = function (left, right, result) {
|
|
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("left", left);
|
|
|
|
|
Check.typeOf.object("right", right);
|
|
|
|
|
Check.typeOf.object("result", result);
|
2016-12-14 05:09:56 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2016-12-14 05:09:56 +08:00
|
|
|
result.x = left.x / right.x;
|
|
|
|
|
result.y = left.y / right.y;
|
|
|
|
|
result.z = left.z / right.z;
|
|
|
|
|
result.w = left.w / right.w;
|
|
|
|
|
return result;
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Computes the componentwise sum of two Cartesians.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} left The first Cartesian.
|
|
|
|
|
* @param {Cartesian4} right The second Cartesian.
|
2014-05-30 00:06:56 +08:00
|
|
|
* @param {Cartesian4} result The object onto which to store the result.
|
2014-06-11 23:57:21 +08:00
|
|
|
* @returns {Cartesian4} The modified result parameter.
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2012-07-14 04:53:46 +08:00
|
|
|
Cartesian4.add = function (left, right, result) {
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("left", left);
|
|
|
|
|
Check.typeOf.object("right", right);
|
|
|
|
|
Check.typeOf.object("result", result);
|
2014-05-30 00:06:56 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
result.x = left.x + right.x;
|
|
|
|
|
result.y = left.y + right.y;
|
|
|
|
|
result.z = left.z + right.z;
|
|
|
|
|
result.w = left.w + right.w;
|
|
|
|
|
return result;
|
2012-04-17 07:38:31 +08:00
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Computes the componentwise difference of two Cartesians.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} left The first Cartesian.
|
|
|
|
|
* @param {Cartesian4} right The second Cartesian.
|
2014-05-30 00:06:56 +08:00
|
|
|
* @param {Cartesian4} result The object onto which to store the result.
|
2014-06-11 23:57:21 +08:00
|
|
|
* @returns {Cartesian4} The modified result parameter.
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2012-07-14 04:53:46 +08:00
|
|
|
Cartesian4.subtract = function (left, right, result) {
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("left", left);
|
|
|
|
|
Check.typeOf.object("right", right);
|
|
|
|
|
Check.typeOf.object("result", result);
|
|
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
result.x = left.x - right.x;
|
|
|
|
|
result.y = left.y - right.y;
|
2017-01-24 19:26:27 +08:00
|
|
|
result.z = left.z - right.z;
|
|
|
|
|
result.w = left.w - right.w;
|
2012-07-14 04:53:46 +08:00
|
|
|
return result;
|
2020-04-17 08:31:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2020-01-28 03:32:20 +08:00
|
|
|
* Multiplies the provided Cartesian componentwise by the provided scalar.
|
2020-04-17 08:31:36 +08:00
|
|
|
*
|
2012-11-17 04:56:36 +08:00
|
|
|
* @param {Cartesian4} cartesian The Cartesian to be scaled.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number} scalar The scalar to multiply with.
|
2020-01-28 03:32:20 +08:00
|
|
|
* @param {Cartesian4} result The object onto which to store the result.
|
2013-09-01 10:47:46 +08:00
|
|
|
* @returns {Cartesian4} The modified result parameter.
|
2020-04-17 08:31:36 +08:00
|
|
|
*/
|
2012-07-18 22:24:02 +08:00
|
|
|
Cartesian4.multiplyByScalar = function (cartesian, scalar, result) {
|
2017-01-24 19:26:27 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
|
|
|
|
Check.typeOf.object("cartesian", cartesian);
|
|
|
|
|
Check.typeOf.number("scalar", scalar);
|
|
|
|
|
Check.typeOf.object("result", result);
|
2014-05-30 00:06:56 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
result.x = cartesian.x * scalar;
|
|
|
|
|
result.y = cartesian.y * scalar;
|
|
|
|
|
result.z = cartesian.z * scalar;
|
|
|
|
|
result.w = cartesian.w * scalar;
|
|
|
|
|
return result;
|
2012-04-17 07:38:31 +08:00
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Divides the provided Cartesian componentwise by the provided scalar.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} cartesian The Cartesian to be divided.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number} scalar The scalar to divide by.
|
2014-05-30 00:06:56 +08:00
|
|
|
* @param {Cartesian4} result The object onto which to store the result.
|
2014-06-11 23:57:21 +08:00
|
|
|
* @returns {Cartesian4} The modified result parameter.
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2012-07-18 22:24:02 +08:00
|
|
|
Cartesian4.divideByScalar = function (cartesian, scalar, result) {
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("cartesian", cartesian);
|
|
|
|
|
Check.typeOf.number("scalar", scalar);
|
|
|
|
|
Check.typeOf.object("result", result);
|
2014-05-30 00:06:56 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
result.x = cartesian.x / scalar;
|
|
|
|
|
result.y = cartesian.y / scalar;
|
|
|
|
|
result.z = cartesian.z / scalar;
|
|
|
|
|
result.w = cartesian.w / scalar;
|
|
|
|
|
return result;
|
2012-04-17 07:38:31 +08:00
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Negates the provided Cartesian.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} cartesian The Cartesian to be negated.
|
2014-05-30 00:06:56 +08:00
|
|
|
* @param {Cartesian4} result The object onto which to store the result.
|
2014-06-11 23:57:21 +08:00
|
|
|
* @returns {Cartesian4} The modified result parameter.
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2012-07-14 04:53:46 +08:00
|
|
|
Cartesian4.negate = function (cartesian, result) {
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("cartesian", cartesian);
|
|
|
|
|
Check.typeOf.object("result", result);
|
2014-05-30 00:06:56 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
result.x = -cartesian.x;
|
|
|
|
|
result.y = -cartesian.y;
|
|
|
|
|
result.z = -cartesian.z;
|
|
|
|
|
result.w = -cartesian.w;
|
|
|
|
|
return result;
|
2012-04-17 07:38:31 +08:00
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Computes the absolute value of the provided Cartesian.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} cartesian The Cartesian whose absolute value is to be computed.
|
2014-05-30 00:06:56 +08:00
|
|
|
* @param {Cartesian4} result The object onto which to store the result.
|
2014-06-11 23:57:21 +08:00
|
|
|
* @returns {Cartesian4} The modified result parameter.
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2012-07-14 04:53:46 +08:00
|
|
|
Cartesian4.abs = function (cartesian, result) {
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("cartesian", cartesian);
|
|
|
|
|
Check.typeOf.object("result", result);
|
2014-05-30 00:06:56 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
result.x = Math.abs(cartesian.x);
|
|
|
|
|
result.y = Math.abs(cartesian.y);
|
|
|
|
|
result.z = Math.abs(cartesian.z);
|
|
|
|
|
result.w = Math.abs(cartesian.w);
|
|
|
|
|
return result;
|
2012-04-17 07:38:31 +08:00
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-18 22:24:02 +08:00
|
|
|
const lerpScratch = new Cartesian4();
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Computes the linear interpolation or extrapolation at t using the provided cartesians.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} start The value corresponding to t at 0.0.
|
|
|
|
|
* @param {Cartesian4}end The value corresponding to t at 1.0.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number} t The point along t at which to interpolate.
|
2014-05-30 00:06:56 +08:00
|
|
|
* @param {Cartesian4} result The object onto which to store the result.
|
2014-06-11 23:57:21 +08:00
|
|
|
* @returns {Cartesian4} The modified result parameter.
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2012-07-14 04:53:46 +08:00
|
|
|
Cartesian4.lerp = function (start, end, t, result) {
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("start", start);
|
|
|
|
|
Check.typeOf.object("end", end);
|
|
|
|
|
Check.typeOf.number("t", t);
|
|
|
|
|
Check.typeOf.object("result", result);
|
2014-05-30 00:06:56 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
Cartesian4.multiplyByScalar(end, t, lerpScratch);
|
|
|
|
|
result = Cartesian4.multiplyByScalar(start, 1.0 - t, result);
|
|
|
|
|
return Cartesian4.add(lerpScratch, result, result);
|
2012-04-17 07:38:31 +08:00
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
const mostOrthogonalAxisScratch = new Cartesian4();
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Returns the axis that is most orthogonal to the provided Cartesian.
|
|
|
|
|
*
|
2014-06-11 23:57:21 +08:00
|
|
|
* @param {Cartesian4} cartesian The Cartesian on which to find the most orthogonal axis.
|
2014-06-12 01:50:32 +08:00
|
|
|
* @param {Cartesian4} result The object onto which to store the result.
|
2014-06-11 23:57:21 +08:00
|
|
|
* @returns {Cartesian4} The most orthogonal axis.
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
2012-07-14 04:53:46 +08:00
|
|
|
Cartesian4.mostOrthogonalAxis = function (cartesian, result) {
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2017-01-24 19:26:27 +08:00
|
|
|
Check.typeOf.object("cartesian", cartesian);
|
|
|
|
|
Check.typeOf.object("result", result);
|
2013-11-15 06:24:42 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-11-17 04:56:36 +08:00
|
|
|
const f = Cartesian4.normalize(cartesian, mostOrthogonalAxisScratch);
|
|
|
|
|
Cartesian4.abs(f, f);
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-11-17 04:56:36 +08:00
|
|
|
if (f.x <= f.y) {
|
|
|
|
|
if (f.x <= f.z) {
|
|
|
|
|
if (f.x <= f.w) {
|
2014-05-30 00:06:56 +08:00
|
|
|
result = Cartesian4.clone(Cartesian4.UNIT_X, result);
|
|
|
|
|
} else {
|
2012-11-17 04:56:36 +08:00
|
|
|
result = Cartesian4.clone(Cartesian4.UNIT_W, result);
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
2012-11-17 04:56:36 +08:00
|
|
|
} else if (f.z <= f.w) {
|
2017-01-24 19:26:27 +08:00
|
|
|
result = Cartesian4.clone(Cartesian4.UNIT_Z, result);
|
2020-04-17 08:31:36 +08:00
|
|
|
} else {
|
2012-11-17 04:56:36 +08:00
|
|
|
result = Cartesian4.clone(Cartesian4.UNIT_W, result);
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
2012-11-17 04:56:36 +08:00
|
|
|
} else if (f.y <= f.z) {
|
|
|
|
|
if (f.y <= f.w) {
|
|
|
|
|
result = Cartesian4.clone(Cartesian4.UNIT_Y, result);
|
|
|
|
|
} else {
|
|
|
|
|
result = Cartesian4.clone(Cartesian4.UNIT_W, result);
|
|
|
|
|
}
|
|
|
|
|
} else if (f.z <= f.w) {
|
|
|
|
|
result = Cartesian4.clone(Cartesian4.UNIT_Z, result);
|
|
|
|
|
} else {
|
|
|
|
|
result = Cartesian4.clone(Cartesian4.UNIT_W, result);
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
return result;
|
2012-11-17 04:56:36 +08:00
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
|
|
|
|
/**
|
2014-11-19 05:38:56 +08:00
|
|
|
* Compares the provided Cartesians componentwise and returns
|
2012-11-17 04:56:36 +08:00
|
|
|
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
2020-04-17 08:31:36 +08:00
|
|
|
*
|
2012-11-17 04:56:36 +08:00
|
|
|
* @param {Cartesian4} [left] The first Cartesian.
|
|
|
|
|
* @param {Cartesian4} [right] The second Cartesian.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
|
2020-04-17 08:31:36 +08:00
|
|
|
*/
|
2012-11-17 04:56:36 +08:00
|
|
|
Cartesian4.equals = function (left, right) {
|
|
|
|
|
return (
|
|
|
|
|
left === right ||
|
2013-08-12 11:05:36 +08:00
|
|
|
(defined(left) &&
|
2012-11-17 04:56:36 +08:00
|
|
|
defined(right) &&
|
2012-07-14 04:53:46 +08:00
|
|
|
left.x === right.x &&
|
|
|
|
|
left.y === right.y &&
|
2012-11-17 04:56:36 +08:00
|
|
|
left.z === right.z &&
|
|
|
|
|
left.w === right.w)
|
|
|
|
|
);
|
2020-04-17 08:31:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2015-02-07 04:30:58 +08:00
|
|
|
* @private
|
2020-04-17 08:31:36 +08:00
|
|
|
*/
|
2012-11-17 04:56:36 +08:00
|
|
|
Cartesian4.equalsArray = function (cartesian, array, offset) {
|
|
|
|
|
return (
|
|
|
|
|
cartesian.x === array[offset] &&
|
2015-02-07 04:30:58 +08:00
|
|
|
cartesian.y === array[offset + 1] &&
|
|
|
|
|
cartesian.z === array[offset + 2] &&
|
|
|
|
|
cartesian.w === array[offset + 3]
|
2012-11-17 04:56:36 +08:00
|
|
|
);
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Compares the provided Cartesians componentwise and returns
|
2012-07-19 02:34:50 +08:00
|
|
|
* <code>true</code> if they pass an absolute or relative tolerance test,
|
|
|
|
|
* <code>false</code> otherwise.
|
2012-04-17 07:38:31 +08:00
|
|
|
*
|
2012-07-14 04:53:46 +08:00
|
|
|
* @param {Cartesian4} [left] The first Cartesian.
|
|
|
|
|
* @param {Cartesian4} [right] The second Cartesian.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
|
|
|
|
|
* @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
|
|
|
|
|
* @returns {boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
|
2015-02-07 04:30:58 +08:00
|
|
|
*/
|
|
|
|
|
Cartesian4.equalsEpsilon = function (
|
|
|
|
|
left,
|
|
|
|
|
right,
|
2014-11-19 05:38:56 +08:00
|
|
|
relativeEpsilon,
|
|
|
|
|
absoluteEpsilon,
|
|
|
|
|
) {
|
2020-04-17 08:31:36 +08:00
|
|
|
return (
|
2014-11-19 05:38:56 +08:00
|
|
|
left === right ||
|
|
|
|
|
(defined(left) &&
|
|
|
|
|
defined(right) &&
|
|
|
|
|
CesiumMath.equalsEpsilon(
|
|
|
|
|
left.x,
|
2014-12-12 03:52:23 +08:00
|
|
|
right.x,
|
|
|
|
|
relativeEpsilon,
|
|
|
|
|
absoluteEpsilon,
|
2014-11-21 00:33:18 +08:00
|
|
|
) &&
|
2014-12-16 03:18:46 +08:00
|
|
|
CesiumMath.equalsEpsilon(
|
|
|
|
|
left.y,
|
|
|
|
|
right.y,
|
|
|
|
|
relativeEpsilon,
|
|
|
|
|
absoluteEpsilon,
|
|
|
|
|
) &&
|
|
|
|
|
CesiumMath.equalsEpsilon(
|
2020-04-17 08:31:36 +08:00
|
|
|
left.z,
|
|
|
|
|
right.z,
|
2014-12-16 03:18:46 +08:00
|
|
|
relativeEpsilon,
|
|
|
|
|
absoluteEpsilon,
|
|
|
|
|
) &&
|
|
|
|
|
CesiumMath.equalsEpsilon(
|
|
|
|
|
left.w,
|
|
|
|
|
right.w,
|
|
|
|
|
relativeEpsilon,
|
|
|
|
|
absoluteEpsilon,
|
|
|
|
|
))
|
|
|
|
|
);
|
2014-11-19 05:38:56 +08:00
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
/**
|
|
|
|
|
* An immutable Cartesian4 instance initialized to (0.0, 0.0, 0.0, 0.0).
|
2014-06-03 22:18:21 +08:00
|
|
|
*
|
|
|
|
|
* @type {Cartesian4}
|
|
|
|
|
* @constant
|
2012-07-14 04:53:46 +08:00
|
|
|
*/
|
2020-02-27 17:02:21 +08:00
|
|
|
Cartesian4.ZERO = Object.freeze(new Cartesian4(0.0, 0.0, 0.0, 0.0));
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2021-08-19 05:15:22 +08:00
|
|
|
/**
|
|
|
|
|
* An immutable Cartesian4 instance initialized to (1.0, 1.0, 1.0, 1.0).
|
|
|
|
|
*
|
|
|
|
|
* @type {Cartesian4}
|
|
|
|
|
* @constant
|
|
|
|
|
*/
|
|
|
|
|
Cartesian4.ONE = Object.freeze(new Cartesian4(1.0, 1.0, 1.0, 1.0));
|
|
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
/**
|
|
|
|
|
* An immutable Cartesian4 instance initialized to (1.0, 0.0, 0.0, 0.0).
|
2014-06-03 22:18:21 +08:00
|
|
|
*
|
|
|
|
|
* @type {Cartesian4}
|
|
|
|
|
* @constant
|
2012-07-14 04:53:46 +08:00
|
|
|
*/
|
2020-02-27 17:02:21 +08:00
|
|
|
Cartesian4.UNIT_X = Object.freeze(new Cartesian4(1.0, 0.0, 0.0, 0.0));
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
/**
|
|
|
|
|
* An immutable Cartesian4 instance initialized to (0.0, 1.0, 0.0, 0.0).
|
2014-06-03 22:18:21 +08:00
|
|
|
*
|
|
|
|
|
* @type {Cartesian4}
|
|
|
|
|
* @constant
|
2012-07-14 04:53:46 +08:00
|
|
|
*/
|
2020-02-27 17:02:21 +08:00
|
|
|
Cartesian4.UNIT_Y = Object.freeze(new Cartesian4(0.0, 1.0, 0.0, 0.0));
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
/**
|
|
|
|
|
* An immutable Cartesian4 instance initialized to (0.0, 0.0, 1.0, 0.0).
|
2014-06-03 22:18:21 +08:00
|
|
|
*
|
|
|
|
|
* @type {Cartesian4}
|
|
|
|
|
* @constant
|
2012-07-14 04:53:46 +08:00
|
|
|
*/
|
2020-02-27 17:02:21 +08:00
|
|
|
Cartesian4.UNIT_Z = Object.freeze(new Cartesian4(0.0, 0.0, 1.0, 0.0));
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
/**
|
|
|
|
|
* An immutable Cartesian4 instance initialized to (0.0, 0.0, 0.0, 1.0).
|
2014-06-03 22:18:21 +08:00
|
|
|
*
|
|
|
|
|
* @type {Cartesian4}
|
|
|
|
|
* @constant
|
2012-07-14 04:53:46 +08:00
|
|
|
*/
|
2020-02-27 17:02:21 +08:00
|
|
|
Cartesian4.UNIT_W = Object.freeze(new Cartesian4(0.0, 0.0, 0.0, 1.0));
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-04-17 07:38:31 +08:00
|
|
|
/**
|
2012-07-14 04:53:46 +08:00
|
|
|
* Duplicates this Cartesian4 instance.
|
2012-04-17 07:38:31 +08:00
|
|
|
*
|
2012-07-14 04:53:46 +08:00
|
|
|
* @param {Cartesian4} [result] The object onto which to store the result.
|
2013-09-01 10:47:46 +08:00
|
|
|
* @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
|
2012-07-14 04:53:46 +08:00
|
|
|
*/
|
|
|
|
|
Cartesian4.prototype.clone = function (result) {
|
|
|
|
|
return Cartesian4.clone(this, result);
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-10-09 00:06:46 +08:00
|
|
|
/**
|
|
|
|
|
* Compares this Cartesian against the provided Cartesian componentwise and returns
|
|
|
|
|
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} [right] The right hand side Cartesian.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @returns {boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
|
2013-10-09 00:06:46 +08:00
|
|
|
*/
|
|
|
|
|
Cartesian4.prototype.equals = function (right) {
|
|
|
|
|
return Cartesian4.equals(this, right);
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-10-09 00:06:46 +08:00
|
|
|
/**
|
|
|
|
|
* Compares this Cartesian against the provided Cartesian componentwise and returns
|
2015-03-03 22:36:04 +08:00
|
|
|
* <code>true</code> if they pass an absolute or relative tolerance test,
|
2013-10-09 00:06:46 +08:00
|
|
|
* <code>false</code> otherwise.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} [right] The right hand side Cartesian.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
|
|
|
|
|
* @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
|
|
|
|
|
* @returns {boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
|
2013-10-09 00:06:46 +08:00
|
|
|
*/
|
2015-03-03 22:36:04 +08:00
|
|
|
Cartesian4.prototype.equalsEpsilon = function (
|
|
|
|
|
right,
|
|
|
|
|
relativeEpsilon,
|
|
|
|
|
absoluteEpsilon,
|
2020-04-17 08:31:36 +08:00
|
|
|
) {
|
2015-03-03 22:36:04 +08:00
|
|
|
return Cartesian4.equalsEpsilon(
|
|
|
|
|
this,
|
|
|
|
|
right,
|
|
|
|
|
relativeEpsilon,
|
2014-11-19 05:38:56 +08:00
|
|
|
absoluteEpsilon,
|
2015-03-03 22:36:04 +08:00
|
|
|
);
|
2013-10-09 00:06:46 +08:00
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2012-07-14 04:53:46 +08:00
|
|
|
/**
|
2019-09-20 04:03:24 +08:00
|
|
|
* Creates a string representing this Cartesian in the format '(x, y, z, w)'.
|
2012-07-14 04:53:46 +08:00
|
|
|
*
|
2023-02-10 16:35:41 +08:00
|
|
|
* @returns {string} A string representing the provided Cartesian in the format '(x, y, z, w)'.
|
2012-04-17 07:38:31 +08:00
|
|
|
*/
|
|
|
|
|
Cartesian4.prototype.toString = function () {
|
2022-02-03 04:40:21 +08:00
|
|
|
return `(${this.x}, ${this.y}, ${this.z}, ${this.w})`;
|
2012-04-17 07:38:31 +08:00
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2020-12-19 02:39:22 +08:00
|
|
|
// scratchU8Array and scratchF32Array are views into the same buffer
|
|
|
|
|
const scratchF32Array = new Float32Array(1);
|
|
|
|
|
const scratchU8Array = new Uint8Array(scratchF32Array.buffer);
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2020-12-19 02:39:22 +08:00
|
|
|
const testU32 = new Uint32Array([0x11223344]);
|
|
|
|
|
const testU8 = new Uint8Array(testU32.buffer);
|
|
|
|
|
const littleEndian = testU8[0] === 0x44;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2018-03-01 22:57:28 +08:00
|
|
|
/**
|
|
|
|
|
* Packs an arbitrary floating point value to 4 values representable using uint8.
|
|
|
|
|
*
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number} value A floating point number.
|
2018-03-01 22:57:28 +08:00
|
|
|
* @param {Cartesian4} [result] The Cartesian4 that will contain the packed float.
|
|
|
|
|
* @returns {Cartesian4} A Cartesian4 representing the float packed to values in x, y, z, and w.
|
|
|
|
|
*/
|
|
|
|
|
Cartesian4.packFloat = function (value, result) {
|
|
|
|
|
//>>includeStart('debug', pragmas.debug);
|
|
|
|
|
Check.typeOf.number("value", value);
|
|
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2018-03-01 22:57:28 +08:00
|
|
|
if (!defined(result)) {
|
|
|
|
|
result = new Cartesian4();
|
|
|
|
|
}
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2020-12-19 02:39:22 +08:00
|
|
|
// scratchU8Array and scratchF32Array are views into the same buffer
|
|
|
|
|
scratchF32Array[0] = value;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2020-12-19 02:39:22 +08:00
|
|
|
if (littleEndian) {
|
|
|
|
|
result.x = scratchU8Array[0];
|
|
|
|
|
result.y = scratchU8Array[1];
|
|
|
|
|
result.z = scratchU8Array[2];
|
|
|
|
|
result.w = scratchU8Array[3];
|
2018-03-01 22:57:28 +08:00
|
|
|
} else {
|
2020-12-19 02:39:22 +08:00
|
|
|
// convert from big-endian to little-endian
|
|
|
|
|
result.x = scratchU8Array[3];
|
|
|
|
|
result.y = scratchU8Array[2];
|
|
|
|
|
result.z = scratchU8Array[1];
|
|
|
|
|
result.w = scratchU8Array[0];
|
2018-03-01 22:57:28 +08:00
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2018-03-01 22:57:28 +08:00
|
|
|
/**
|
|
|
|
|
* Unpacks a float packed using Cartesian4.packFloat.
|
|
|
|
|
*
|
|
|
|
|
* @param {Cartesian4} packedFloat A Cartesian4 containing a float packed to 4 values representable using uint8.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @returns {number} The unpacked float.
|
2018-03-13 03:54:16 +08:00
|
|
|
* @private
|
2018-03-01 22:57:28 +08:00
|
|
|
*/
|
|
|
|
|
Cartesian4.unpackFloat = function (packedFloat) {
|
|
|
|
|
//>>includeStart('debug', pragmas.debug);
|
|
|
|
|
Check.typeOf.object("packedFloat", packedFloat);
|
|
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2020-12-19 02:39:22 +08:00
|
|
|
// scratchU8Array and scratchF32Array are views into the same buffer
|
|
|
|
|
if (littleEndian) {
|
|
|
|
|
scratchU8Array[0] = packedFloat.x;
|
|
|
|
|
scratchU8Array[1] = packedFloat.y;
|
|
|
|
|
scratchU8Array[2] = packedFloat.z;
|
|
|
|
|
scratchU8Array[3] = packedFloat.w;
|
|
|
|
|
} else {
|
|
|
|
|
// convert from little-endian to big-endian
|
|
|
|
|
scratchU8Array[0] = packedFloat.w;
|
|
|
|
|
scratchU8Array[1] = packedFloat.z;
|
|
|
|
|
scratchU8Array[2] = packedFloat.y;
|
|
|
|
|
scratchU8Array[3] = packedFloat.x;
|
2018-03-01 22:57:28 +08:00
|
|
|
}
|
2020-12-19 02:39:22 +08:00
|
|
|
return scratchF32Array[0];
|
2018-03-01 22:57:28 +08:00
|
|
|
};
|
Migrate Cesium to ES6 Modules
See https://github.com/AnalyticalGraphicsInc/cesium/pull/8224 for details.
eslint
There are a handful of new .eslintrc.json files, mostly to identify the files that are still AMD modules (Sandcastle/Workers). These are needed because you can't change the parser type with a comment directive (since the parser is the thing reading the file). We can finally detect unusued modules! So those have all been cleaned up as well.
requirejs -> rollup & clean-css
requirejs, almond, and karma-requirejs have all been removed. We now use rollup for building and minifying (via uglify) JS code and clean-css for css. These changes are fairly straight-forward and just involve calling rollup instead of requirejs in the build process.
Overall build time is significantly faster. CI is ~11 minutes compared to ~17 in master. Running makeZipFile on my machine takes 69 seconds compared to 112 seconds in master. There's probably plenty of room for additional optimization here too.
We wrote an published a small npm module, rollup-plugin-strip-pragma, for stripping the requirejs pragmas we use out of the release builds. This is maintained in the Tools/rollup-plugin-strip-pragma directory.
As for what we produce. The built version of Cesium is now a UMD module. So it should work anywhere that hasn't made the jump to ES6 yet. For users that were already using the "legacy" combined/minified approach, nothing changes.
One awesome thing about roll-up is that it compiles all of the workers at once and automatically detects shared codes and generates separate bundles under the hood. This means the size of our worker modules shrink dramatically and Cesium itself will load them much faster. The total minified/gzipped size of all workers in master is 2.6 MB compared to 225 KB in this branch! This should be most noticeable on demos like Geometry & Appearances which load lots of workers for the various geometry typs.
roll-up is also used to build Cesium Viewer, which is now an ES6 app.
We use clean-css via gulp and it is also a straightforward change from requirejs that requires no special mention.
Workers
While the spec allows for ES6 Web Workers, no browser actually supports them yet. That means we needed a way to get our workers into non-ES6 form. Thankfully, roll-up can generate AMD modules, which means we now have a build step to compile our Worker source code back into AMD and use the existing TaskProcessor to load and execute them. This build step is part of the standard build task and is called createWorkers. During development, these "built" workers are un-optimized so you can still debug them and read the code.
Since there is a build step, that means if you are changing code that affects a worker, you need to re-run build, or you can use the build-watch task to do it automatically.
The ES6 versions of Worker code has moved into Source/WorkersES6 and we build the workers into their "old home" of Source/Workers. cesiumWorkerBootstrapper and transferTypedArrayTest which were already non-AMD ES5 scripts remain living in the Workers directory.
Surprisingly little was changed about TaskProcessor or the worker system in general, especially considering that I thought this would be one of the major hurdles.
ThirdParty
A lot of our ThirdParty either already had a hand-written wrapper for AMD (which I updated to ES6) or had UMD which created problems when importing the same code in both Node and the browser. I basically had to update the wrapper of every third-party library to fix these problems. In some cases I updated the library version itself (Autolinker, topojson). Nothing to be too concerned about, but future clean-up would be using npm versions of these libraries and auto-generating the wrappers as needed so we don't hand-edit things.
Sandcastle
Sandcastle is eternal and manages to live another day in it's ancient requirejs/dojo 1.x form. Sandcastle now automatically uses the ES6 version of Cesium if it is available and fallsback to the ES5 unminified version if it is now. The built version of Sandcastle always uses CesiumUnminified, just like master. This means Sandcastle still works in IE11 if you run the combine step first (or use the relase zip)
Removed Cesium usage from Sandcastle proper, since it wasn't really needed
Generate a VERSION propertyin the gallery index since Cesium is no longer being included.
Remove requirejs from Sandcastle bucket
Update bucket to use the built version of Cesium if it is available by fallbackto the ES6 version during development.
Standalone.html was also updated
There's a bit of room for further clean-up here, but I think this gets us into master. I did not rename bucket-requirejs.html because I'm pretty sure it would break previously shared demos. We can put in some backwards compatible code later on if we want. (But I'd rather just see a full Sandcastle rewrite).
Specs
Specs are now all ES6, except for TestWorkers, which remain standard JS worker modules. This means you can no longer run the unbuilt unit tests in IE11. No changes for Chrome and Firefox.
Since the specs use ES6 modules and built Cesium is an ES5 UMD, I added a build-specs build step which generates a combined ES5 version of the specs which rely on Cesium as a global variable. We then inject these files into jasmine instead of the standard specs and everything works exactly as it did before. SpecRunner.html has been updated to inject the correct version of the script depending on the build/release query parameters.
The Specs must always use Cesium by importing Source/Cesium.js, this is so we can replace it with the built Cesium as describe above.
There's a bunch of room for clean-up here, such as unifying our two copies of jasmine into a single helper file, but I didn't want to start doing that clean-up as part of this already overly big PR. The important thing is that we can still test the built version and still test on IE/Edge as needed.
I also found and fixed two bugs that were causing failing unit tests, one in BingMapsImageryProviderSpec.js (which was overwriting createImage andnot setting it back) and ShadowVolumeAppearance.js (which had a module level caching bug). I think these may have been the cause of random CI failures in master as well, but only time will tell.
For coverage, we had to switch to karma-coverage-istanbul-instrumenter for native ES6 support, but that's it.
Finally, I updated appveryor to build Cesium and run the built tests under IE. We still don't fail the build for IE, but we should probably fix that if we want to keep it going.
NodeJS
When NODE_ENV is production, we now require in the minified CesiumJS directly, which works great because it's now a UMD module. Otherwise, we use the excellant esmpackage to load individual modules, it was a fairly straightforward swap from our old requirejs usage. We could probably drop esm too if we don't care about debugging or if we provie source maps at some point.
2019-10-03 23:51:23 +08:00
|
|
|
export default Cartesian4;
|