{"version":3,"file":"Transforms-8b90e17c.js","sources":["../../../../Source/Core/GeographicProjection.js","../../../../Source/Core/Intersect.js","../../../../Source/Core/Interval.js","../../../../Source/Core/BoundingSphere.js","../../../../Source/Core/Fullscreen.js","../../../../Source/Core/FeatureDetection.js","../../../../Source/Core/Quaternion.js","../../../../Source/Core/binarySearch.js","../../../../Source/Core/EarthOrientationParametersSample.js","../../../../Source/Core/GregorianDate.js","../../../../Source/Core/isLeapYear.js","../../../../Source/Core/LeapSecond.js","../../../../Source/Core/TimeConstants.js","../../../../Source/Core/TimeStandard.js","../../../../Source/Core/JulianDate.js","../../../../Source/ThirdParty/Uri.js","../../../../Source/Core/appendForwardSlash.js","../../../../Source/Core/clone.js","../../../../Source/Core/getAbsoluteUri.js","../../../../Source/Core/getBaseUri.js","../../../../Source/Core/getExtensionFromUri.js","../../../../Source/Core/getImagePixels.js","../../../../Source/Core/isBlobUri.js","../../../../Source/Core/isCrossOriginUrl.js","../../../../Source/Core/isDataUri.js","../../../../Source/Core/loadAndExecuteScript.js","../../../../Source/Core/objectToQuery.js","../../../../Source/Core/queryToObject.js","../../../../Source/Core/RequestState.js","../../../../Source/Core/RequestType.js","../../../../Source/Core/Request.js","../../../../Source/Core/parseResponseHeaders.js","../../../../Source/Core/RequestErrorEvent.js","../../../../Source/Core/Event.js","../../../../Source/Core/Heap.js","../../../../Source/Core/RequestScheduler.js","../../../../Source/Core/TrustedServers.js","../../../../Source/Core/Resource.js","../../../../Source/Core/EarthOrientationParameters.js","../../../../Source/Core/HeadingPitchRoll.js","../../../../Source/Core/buildModuleUrl.js","../../../../Source/Core/Iau2006XysSample.js","../../../../Source/Core/Iau2006XysData.js","../../../../Source/Core/Transforms.js"],"sourcesContent":["import Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\n\n/**\n * A simple map projection where longitude and latitude are linearly mapped to X and Y by multiplying\n * them by the {@link Ellipsoid#maximumRadius}. This projection\n * is commonly known as geographic, equirectangular, equidistant cylindrical, or plate carrée. It\n * is also known as EPSG:4326.\n *\n * @alias GeographicProjection\n * @constructor\n *\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid.\n *\n * @see WebMercatorProjection\n */\nfunction GeographicProjection(ellipsoid) {\n this._ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n this._semimajorAxis = this._ellipsoid.maximumRadius;\n this._oneOverSemimajorAxis = 1.0 / this._semimajorAxis;\n}\n\nObject.defineProperties(GeographicProjection.prototype, {\n /**\n * Gets the {@link Ellipsoid}.\n *\n * @memberof GeographicProjection.prototype\n *\n * @type {Ellipsoid}\n * @readonly\n */\n ellipsoid: {\n get: function () {\n return this._ellipsoid;\n },\n },\n});\n\n/**\n * Projects a set of {@link Cartographic} coordinates, in radians, to map coordinates, in meters.\n * X and Y are the longitude and latitude, respectively, multiplied by the maximum radius of the\n * ellipsoid. Z is the unmodified height.\n *\n * @param {Cartographic} cartographic The coordinates to project.\n * @param {Cartesian3} [result] An instance into which to copy the result. If this parameter is\n * undefined, a new instance is created and returned.\n * @returns {Cartesian3} The projected coordinates. If the result parameter is not undefined, the\n * coordinates are copied there and that instance is returned. Otherwise, a new instance is\n * created and returned.\n */\nGeographicProjection.prototype.project = function (cartographic, result) {\n // Actually this is the special case of equidistant cylindrical called the plate carree\n const semimajorAxis = this._semimajorAxis;\n const x = cartographic.longitude * semimajorAxis;\n const y = cartographic.latitude * semimajorAxis;\n const z = cartographic.height;\n\n if (!defined(result)) {\n return new Cartesian3(x, y, z);\n }\n\n result.x = x;\n result.y = y;\n result.z = z;\n return result;\n};\n\n/**\n * Unprojects a set of projected {@link Cartesian3} coordinates, in meters, to {@link Cartographic}\n * coordinates, in radians. Longitude and Latitude are the X and Y coordinates, respectively,\n * divided by the maximum radius of the ellipsoid. Height is the unmodified Z coordinate.\n *\n * @param {Cartesian3} cartesian The Cartesian position to unproject with height (z) in meters.\n * @param {Cartographic} [result] An instance into which to copy the result. If this parameter is\n * undefined, a new instance is created and returned.\n * @returns {Cartographic} The unprojected coordinates. If the result parameter is not undefined, the\n * coordinates are copied there and that instance is returned. Otherwise, a new instance is\n * created and returned.\n */\nGeographicProjection.prototype.unproject = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(cartesian)) {\n throw new DeveloperError(\"cartesian is required\");\n }\n //>>includeEnd('debug');\n\n const oneOverEarthSemimajorAxis = this._oneOverSemimajorAxis;\n const longitude = cartesian.x * oneOverEarthSemimajorAxis;\n const latitude = cartesian.y * oneOverEarthSemimajorAxis;\n const height = cartesian.z;\n\n if (!defined(result)) {\n return new Cartographic(longitude, latitude, height);\n }\n\n result.longitude = longitude;\n result.latitude = latitude;\n result.height = height;\n return result;\n};\nexport default GeographicProjection;\n","/**\n * This enumerated type is used in determining where, relative to the frustum, an\n * object is located. The object can either be fully contained within the frustum (INSIDE),\n * partially inside the frustum and partially outside (INTERSECTING), or somewhere entirely\n * outside of the frustum's 6 planes (OUTSIDE).\n *\n * @enum {Number}\n */\nconst Intersect = {\n /**\n * Represents that an object is not contained within the frustum.\n *\n * @type {Number}\n * @constant\n */\n OUTSIDE: -1,\n\n /**\n * Represents that an object intersects one of the frustum's planes.\n *\n * @type {Number}\n * @constant\n */\n INTERSECTING: 0,\n\n /**\n * Represents that an object is fully within the frustum.\n *\n * @type {Number}\n * @constant\n */\n INSIDE: 1,\n};\nexport default Object.freeze(Intersect);\n","import defaultValue from \"./defaultValue.js\";\n\n/**\n * Represents the closed interval [start, stop].\n * @alias Interval\n * @constructor\n *\n * @param {Number} [start=0.0] The beginning of the interval.\n * @param {Number} [stop=0.0] The end of the interval.\n */\nfunction Interval(start, stop) {\n /**\n * The beginning of the interval.\n * @type {Number}\n * @default 0.0\n */\n this.start = defaultValue(start, 0.0);\n /**\n * The end of the interval.\n * @type {Number}\n * @default 0.0\n */\n this.stop = defaultValue(stop, 0.0);\n}\nexport default Interval;\n","import Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport GeographicProjection from \"./GeographicProjection.js\";\nimport Intersect from \"./Intersect.js\";\nimport Interval from \"./Interval.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport Matrix4 from \"./Matrix4.js\";\nimport Rectangle from \"./Rectangle.js\";\n\n/**\n * A bounding sphere with a center and a radius.\n * @alias BoundingSphere\n * @constructor\n *\n * @param {Cartesian3} [center=Cartesian3.ZERO] The center of the bounding sphere.\n * @param {Number} [radius=0.0] The radius of the bounding sphere.\n *\n * @see AxisAlignedBoundingBox\n * @see BoundingRectangle\n * @see Packable\n */\nfunction BoundingSphere(center, radius) {\n /**\n * The center point of the sphere.\n * @type {Cartesian3}\n * @default {@link Cartesian3.ZERO}\n */\n this.center = Cartesian3.clone(defaultValue(center, Cartesian3.ZERO));\n\n /**\n * The radius of the sphere.\n * @type {Number}\n * @default 0.0\n */\n this.radius = defaultValue(radius, 0.0);\n}\n\nconst fromPointsXMin = new Cartesian3();\nconst fromPointsYMin = new Cartesian3();\nconst fromPointsZMin = new Cartesian3();\nconst fromPointsXMax = new Cartesian3();\nconst fromPointsYMax = new Cartesian3();\nconst fromPointsZMax = new Cartesian3();\nconst fromPointsCurrentPos = new Cartesian3();\nconst fromPointsScratch = new Cartesian3();\nconst fromPointsRitterCenter = new Cartesian3();\nconst fromPointsMinBoxPt = new Cartesian3();\nconst fromPointsMaxBoxPt = new Cartesian3();\nconst fromPointsNaiveCenterScratch = new Cartesian3();\nconst volumeConstant = (4.0 / 3.0) * CesiumMath.PI;\n\n/**\n * Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.\n * The bounding sphere is computed by running two algorithms, a naive algorithm and\n * Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.\n *\n * @param {Cartesian3[]} [positions] An array of points that the bounding sphere will enclose. Each point must have x
, y
, and z
properties.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.\n *\n * @see {@link http://help.agi.com/AGIComponents/html/BlogBoundingSphere.htm|Bounding Sphere computation article}\n */\nBoundingSphere.fromPoints = function (positions, result) {\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n if (!defined(positions) || positions.length === 0) {\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\n result.radius = 0.0;\n return result;\n }\n\n const currentPos = Cartesian3.clone(positions[0], fromPointsCurrentPos);\n\n const xMin = Cartesian3.clone(currentPos, fromPointsXMin);\n const yMin = Cartesian3.clone(currentPos, fromPointsYMin);\n const zMin = Cartesian3.clone(currentPos, fromPointsZMin);\n\n const xMax = Cartesian3.clone(currentPos, fromPointsXMax);\n const yMax = Cartesian3.clone(currentPos, fromPointsYMax);\n const zMax = Cartesian3.clone(currentPos, fromPointsZMax);\n\n const numPositions = positions.length;\n let i;\n for (i = 1; i < numPositions; i++) {\n Cartesian3.clone(positions[i], currentPos);\n\n const x = currentPos.x;\n const y = currentPos.y;\n const z = currentPos.z;\n\n // Store points containing the the smallest and largest components\n if (x < xMin.x) {\n Cartesian3.clone(currentPos, xMin);\n }\n\n if (x > xMax.x) {\n Cartesian3.clone(currentPos, xMax);\n }\n\n if (y < yMin.y) {\n Cartesian3.clone(currentPos, yMin);\n }\n\n if (y > yMax.y) {\n Cartesian3.clone(currentPos, yMax);\n }\n\n if (z < zMin.z) {\n Cartesian3.clone(currentPos, zMin);\n }\n\n if (z > zMax.z) {\n Cartesian3.clone(currentPos, zMax);\n }\n }\n\n // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).\n const xSpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(xMax, xMin, fromPointsScratch)\n );\n const ySpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(yMax, yMin, fromPointsScratch)\n );\n const zSpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(zMax, zMin, fromPointsScratch)\n );\n\n // Set the diameter endpoints to the largest span.\n let diameter1 = xMin;\n let diameter2 = xMax;\n let maxSpan = xSpan;\n if (ySpan > maxSpan) {\n maxSpan = ySpan;\n diameter1 = yMin;\n diameter2 = yMax;\n }\n if (zSpan > maxSpan) {\n maxSpan = zSpan;\n diameter1 = zMin;\n diameter2 = zMax;\n }\n\n // Calculate the center of the initial sphere found by Ritter's algorithm\n const ritterCenter = fromPointsRitterCenter;\n ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;\n ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;\n ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;\n\n // Calculate the radius of the initial sphere found by Ritter's algorithm\n let radiusSquared = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(diameter2, ritterCenter, fromPointsScratch)\n );\n let ritterRadius = Math.sqrt(radiusSquared);\n\n // Find the center of the sphere found using the Naive method.\n const minBoxPt = fromPointsMinBoxPt;\n minBoxPt.x = xMin.x;\n minBoxPt.y = yMin.y;\n minBoxPt.z = zMin.z;\n\n const maxBoxPt = fromPointsMaxBoxPt;\n maxBoxPt.x = xMax.x;\n maxBoxPt.y = yMax.y;\n maxBoxPt.z = zMax.z;\n\n const naiveCenter = Cartesian3.midpoint(\n minBoxPt,\n maxBoxPt,\n fromPointsNaiveCenterScratch\n );\n\n // Begin 2nd pass to find naive radius and modify the ritter sphere.\n let naiveRadius = 0;\n for (i = 0; i < numPositions; i++) {\n Cartesian3.clone(positions[i], currentPos);\n\n // Find the furthest point from the naive center to calculate the naive radius.\n const r = Cartesian3.magnitude(\n Cartesian3.subtract(currentPos, naiveCenter, fromPointsScratch)\n );\n if (r > naiveRadius) {\n naiveRadius = r;\n }\n\n // Make adjustments to the Ritter Sphere to include all points.\n const oldCenterToPointSquared = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(currentPos, ritterCenter, fromPointsScratch)\n );\n if (oldCenterToPointSquared > radiusSquared) {\n const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);\n // Calculate new radius to include the point that lies outside\n ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;\n radiusSquared = ritterRadius * ritterRadius;\n // Calculate center of new Ritter sphere\n const oldToNew = oldCenterToPoint - ritterRadius;\n ritterCenter.x =\n (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) /\n oldCenterToPoint;\n ritterCenter.y =\n (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) /\n oldCenterToPoint;\n ritterCenter.z =\n (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) /\n oldCenterToPoint;\n }\n }\n\n if (ritterRadius < naiveRadius) {\n Cartesian3.clone(ritterCenter, result.center);\n result.radius = ritterRadius;\n } else {\n Cartesian3.clone(naiveCenter, result.center);\n result.radius = naiveRadius;\n }\n\n return result;\n};\n\nconst defaultProjection = new GeographicProjection();\nconst fromRectangle2DLowerLeft = new Cartesian3();\nconst fromRectangle2DUpperRight = new Cartesian3();\nconst fromRectangle2DSouthwest = new Cartographic();\nconst fromRectangle2DNortheast = new Cartographic();\n\n/**\n * Computes a bounding sphere from a rectangle projected in 2D.\n *\n * @param {Rectangle} [rectangle] The rectangle around which to create a bounding sphere.\n * @param {Object} [projection=GeographicProjection] The projection used to project the rectangle into 2D.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.fromRectangle2D = function (rectangle, projection, result) {\n return BoundingSphere.fromRectangleWithHeights2D(\n rectangle,\n projection,\n 0.0,\n 0.0,\n result\n );\n};\n\n/**\n * Computes a bounding sphere from a rectangle projected in 2D. The bounding sphere accounts for the\n * object's minimum and maximum heights over the rectangle.\n *\n * @param {Rectangle} [rectangle] The rectangle around which to create a bounding sphere.\n * @param {Object} [projection=GeographicProjection] The projection used to project the rectangle into 2D.\n * @param {Number} [minimumHeight=0.0] The minimum height over the rectangle.\n * @param {Number} [maximumHeight=0.0] The maximum height over the rectangle.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.fromRectangleWithHeights2D = function (\n rectangle,\n projection,\n minimumHeight,\n maximumHeight,\n result\n) {\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n if (!defined(rectangle)) {\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\n result.radius = 0.0;\n return result;\n }\n\n projection = defaultValue(projection, defaultProjection);\n\n Rectangle.southwest(rectangle, fromRectangle2DSouthwest);\n fromRectangle2DSouthwest.height = minimumHeight;\n Rectangle.northeast(rectangle, fromRectangle2DNortheast);\n fromRectangle2DNortheast.height = maximumHeight;\n\n const lowerLeft = projection.project(\n fromRectangle2DSouthwest,\n fromRectangle2DLowerLeft\n );\n const upperRight = projection.project(\n fromRectangle2DNortheast,\n fromRectangle2DUpperRight\n );\n\n const width = upperRight.x - lowerLeft.x;\n const height = upperRight.y - lowerLeft.y;\n const elevation = upperRight.z - lowerLeft.z;\n\n result.radius =\n Math.sqrt(width * width + height * height + elevation * elevation) * 0.5;\n const center = result.center;\n center.x = lowerLeft.x + width * 0.5;\n center.y = lowerLeft.y + height * 0.5;\n center.z = lowerLeft.z + elevation * 0.5;\n return result;\n};\n\nconst fromRectangle3DScratch = [];\n\n/**\n * Computes a bounding sphere from a rectangle in 3D. The bounding sphere is created using a subsample of points\n * on the ellipsoid and contained in the rectangle. It may not be accurate for all rectangles on all types of ellipsoids.\n *\n * @param {Rectangle} [rectangle] The valid rectangle used to create a bounding sphere.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid used to determine positions of the rectangle.\n * @param {Number} [surfaceHeight=0.0] The height above the surface of the ellipsoid.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.fromRectangle3D = function (\n rectangle,\n ellipsoid,\n surfaceHeight,\n result\n) {\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n surfaceHeight = defaultValue(surfaceHeight, 0.0);\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n if (!defined(rectangle)) {\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\n result.radius = 0.0;\n return result;\n }\n\n const positions = Rectangle.subsample(\n rectangle,\n ellipsoid,\n surfaceHeight,\n fromRectangle3DScratch\n );\n return BoundingSphere.fromPoints(positions, result);\n};\n\n/**\n * Computes a tight-fitting bounding sphere enclosing a list of 3D points, where the points are\n * stored in a flat array in X, Y, Z, order. The bounding sphere is computed by running two\n * algorithms, a naive algorithm and Ritter's algorithm. The smaller of the two spheres is used to\n * ensure a tight fit.\n *\n * @param {Number[]} [positions] An array of points that the bounding sphere will enclose. Each point\n * is formed from three elements in the array in the order X, Y, Z.\n * @param {Cartesian3} [center=Cartesian3.ZERO] The position to which the positions are relative, which need not be the\n * origin of the coordinate system. This is useful when the positions are to be used for\n * relative-to-center (RTC) rendering.\n * @param {Number} [stride=3] The number of array elements per vertex. It must be at least 3, but it may\n * be higher. Regardless of the value of this parameter, the X coordinate of the first position\n * is at array index 0, the Y coordinate is at array index 1, and the Z coordinate is at array index\n * 2. When stride is 3, the X coordinate of the next position then begins at array index 3. If\n * the stride is 5, however, two array elements are skipped and the next position begins at array\n * index 5.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.\n *\n * @example\n * // Compute the bounding sphere from 3 positions, each specified relative to a center.\n * // In addition to the X, Y, and Z coordinates, the points array contains two additional\n * // elements per point which are ignored for the purpose of computing the bounding sphere.\n * const center = new Cesium.Cartesian3(1.0, 2.0, 3.0);\n * const points = [1.0, 2.0, 3.0, 0.1, 0.2,\n * 4.0, 5.0, 6.0, 0.1, 0.2,\n * 7.0, 8.0, 9.0, 0.1, 0.2];\n * const sphere = Cesium.BoundingSphere.fromVertices(points, center, 5);\n *\n * @see {@link http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding/|Bounding Sphere computation article}\n */\nBoundingSphere.fromVertices = function (positions, center, stride, result) {\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n if (!defined(positions) || positions.length === 0) {\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\n result.radius = 0.0;\n return result;\n }\n\n center = defaultValue(center, Cartesian3.ZERO);\n\n stride = defaultValue(stride, 3);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"stride\", stride, 3);\n //>>includeEnd('debug');\n\n const currentPos = fromPointsCurrentPos;\n currentPos.x = positions[0] + center.x;\n currentPos.y = positions[1] + center.y;\n currentPos.z = positions[2] + center.z;\n\n const xMin = Cartesian3.clone(currentPos, fromPointsXMin);\n const yMin = Cartesian3.clone(currentPos, fromPointsYMin);\n const zMin = Cartesian3.clone(currentPos, fromPointsZMin);\n\n const xMax = Cartesian3.clone(currentPos, fromPointsXMax);\n const yMax = Cartesian3.clone(currentPos, fromPointsYMax);\n const zMax = Cartesian3.clone(currentPos, fromPointsZMax);\n\n const numElements = positions.length;\n let i;\n for (i = 0; i < numElements; i += stride) {\n const x = positions[i] + center.x;\n const y = positions[i + 1] + center.y;\n const z = positions[i + 2] + center.z;\n\n currentPos.x = x;\n currentPos.y = y;\n currentPos.z = z;\n\n // Store points containing the the smallest and largest components\n if (x < xMin.x) {\n Cartesian3.clone(currentPos, xMin);\n }\n\n if (x > xMax.x) {\n Cartesian3.clone(currentPos, xMax);\n }\n\n if (y < yMin.y) {\n Cartesian3.clone(currentPos, yMin);\n }\n\n if (y > yMax.y) {\n Cartesian3.clone(currentPos, yMax);\n }\n\n if (z < zMin.z) {\n Cartesian3.clone(currentPos, zMin);\n }\n\n if (z > zMax.z) {\n Cartesian3.clone(currentPos, zMax);\n }\n }\n\n // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).\n const xSpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(xMax, xMin, fromPointsScratch)\n );\n const ySpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(yMax, yMin, fromPointsScratch)\n );\n const zSpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(zMax, zMin, fromPointsScratch)\n );\n\n // Set the diameter endpoints to the largest span.\n let diameter1 = xMin;\n let diameter2 = xMax;\n let maxSpan = xSpan;\n if (ySpan > maxSpan) {\n maxSpan = ySpan;\n diameter1 = yMin;\n diameter2 = yMax;\n }\n if (zSpan > maxSpan) {\n maxSpan = zSpan;\n diameter1 = zMin;\n diameter2 = zMax;\n }\n\n // Calculate the center of the initial sphere found by Ritter's algorithm\n const ritterCenter = fromPointsRitterCenter;\n ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;\n ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;\n ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;\n\n // Calculate the radius of the initial sphere found by Ritter's algorithm\n let radiusSquared = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(diameter2, ritterCenter, fromPointsScratch)\n );\n let ritterRadius = Math.sqrt(radiusSquared);\n\n // Find the center of the sphere found using the Naive method.\n const minBoxPt = fromPointsMinBoxPt;\n minBoxPt.x = xMin.x;\n minBoxPt.y = yMin.y;\n minBoxPt.z = zMin.z;\n\n const maxBoxPt = fromPointsMaxBoxPt;\n maxBoxPt.x = xMax.x;\n maxBoxPt.y = yMax.y;\n maxBoxPt.z = zMax.z;\n\n const naiveCenter = Cartesian3.midpoint(\n minBoxPt,\n maxBoxPt,\n fromPointsNaiveCenterScratch\n );\n\n // Begin 2nd pass to find naive radius and modify the ritter sphere.\n let naiveRadius = 0;\n for (i = 0; i < numElements; i += stride) {\n currentPos.x = positions[i] + center.x;\n currentPos.y = positions[i + 1] + center.y;\n currentPos.z = positions[i + 2] + center.z;\n\n // Find the furthest point from the naive center to calculate the naive radius.\n const r = Cartesian3.magnitude(\n Cartesian3.subtract(currentPos, naiveCenter, fromPointsScratch)\n );\n if (r > naiveRadius) {\n naiveRadius = r;\n }\n\n // Make adjustments to the Ritter Sphere to include all points.\n const oldCenterToPointSquared = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(currentPos, ritterCenter, fromPointsScratch)\n );\n if (oldCenterToPointSquared > radiusSquared) {\n const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);\n // Calculate new radius to include the point that lies outside\n ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;\n radiusSquared = ritterRadius * ritterRadius;\n // Calculate center of new Ritter sphere\n const oldToNew = oldCenterToPoint - ritterRadius;\n ritterCenter.x =\n (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) /\n oldCenterToPoint;\n ritterCenter.y =\n (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) /\n oldCenterToPoint;\n ritterCenter.z =\n (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) /\n oldCenterToPoint;\n }\n }\n\n if (ritterRadius < naiveRadius) {\n Cartesian3.clone(ritterCenter, result.center);\n result.radius = ritterRadius;\n } else {\n Cartesian3.clone(naiveCenter, result.center);\n result.radius = naiveRadius;\n }\n\n return result;\n};\n\n/**\n * Computes a tight-fitting bounding sphere enclosing a list of EncodedCartesian3s, where the points are\n * stored in parallel flat arrays in X, Y, Z, order. The bounding sphere is computed by running two\n * algorithms, a naive algorithm and Ritter's algorithm. The smaller of the two spheres is used to\n * ensure a tight fit.\n *\n * @param {Number[]} [positionsHigh] An array of high bits of the encoded cartesians that the bounding sphere will enclose. Each point\n * is formed from three elements in the array in the order X, Y, Z.\n * @param {Number[]} [positionsLow] An array of low bits of the encoded cartesians that the bounding sphere will enclose. Each point\n * is formed from three elements in the array in the order X, Y, Z.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.\n *\n * @see {@link http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding/|Bounding Sphere computation article}\n */\nBoundingSphere.fromEncodedCartesianVertices = function (\n positionsHigh,\n positionsLow,\n result\n) {\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n if (\n !defined(positionsHigh) ||\n !defined(positionsLow) ||\n positionsHigh.length !== positionsLow.length ||\n positionsHigh.length === 0\n ) {\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\n result.radius = 0.0;\n return result;\n }\n\n const currentPos = fromPointsCurrentPos;\n currentPos.x = positionsHigh[0] + positionsLow[0];\n currentPos.y = positionsHigh[1] + positionsLow[1];\n currentPos.z = positionsHigh[2] + positionsLow[2];\n\n const xMin = Cartesian3.clone(currentPos, fromPointsXMin);\n const yMin = Cartesian3.clone(currentPos, fromPointsYMin);\n const zMin = Cartesian3.clone(currentPos, fromPointsZMin);\n\n const xMax = Cartesian3.clone(currentPos, fromPointsXMax);\n const yMax = Cartesian3.clone(currentPos, fromPointsYMax);\n const zMax = Cartesian3.clone(currentPos, fromPointsZMax);\n\n const numElements = positionsHigh.length;\n let i;\n for (i = 0; i < numElements; i += 3) {\n const x = positionsHigh[i] + positionsLow[i];\n const y = positionsHigh[i + 1] + positionsLow[i + 1];\n const z = positionsHigh[i + 2] + positionsLow[i + 2];\n\n currentPos.x = x;\n currentPos.y = y;\n currentPos.z = z;\n\n // Store points containing the the smallest and largest components\n if (x < xMin.x) {\n Cartesian3.clone(currentPos, xMin);\n }\n\n if (x > xMax.x) {\n Cartesian3.clone(currentPos, xMax);\n }\n\n if (y < yMin.y) {\n Cartesian3.clone(currentPos, yMin);\n }\n\n if (y > yMax.y) {\n Cartesian3.clone(currentPos, yMax);\n }\n\n if (z < zMin.z) {\n Cartesian3.clone(currentPos, zMin);\n }\n\n if (z > zMax.z) {\n Cartesian3.clone(currentPos, zMax);\n }\n }\n\n // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).\n const xSpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(xMax, xMin, fromPointsScratch)\n );\n const ySpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(yMax, yMin, fromPointsScratch)\n );\n const zSpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(zMax, zMin, fromPointsScratch)\n );\n\n // Set the diameter endpoints to the largest span.\n let diameter1 = xMin;\n let diameter2 = xMax;\n let maxSpan = xSpan;\n if (ySpan > maxSpan) {\n maxSpan = ySpan;\n diameter1 = yMin;\n diameter2 = yMax;\n }\n if (zSpan > maxSpan) {\n maxSpan = zSpan;\n diameter1 = zMin;\n diameter2 = zMax;\n }\n\n // Calculate the center of the initial sphere found by Ritter's algorithm\n const ritterCenter = fromPointsRitterCenter;\n ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;\n ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;\n ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;\n\n // Calculate the radius of the initial sphere found by Ritter's algorithm\n let radiusSquared = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(diameter2, ritterCenter, fromPointsScratch)\n );\n let ritterRadius = Math.sqrt(radiusSquared);\n\n // Find the center of the sphere found using the Naive method.\n const minBoxPt = fromPointsMinBoxPt;\n minBoxPt.x = xMin.x;\n minBoxPt.y = yMin.y;\n minBoxPt.z = zMin.z;\n\n const maxBoxPt = fromPointsMaxBoxPt;\n maxBoxPt.x = xMax.x;\n maxBoxPt.y = yMax.y;\n maxBoxPt.z = zMax.z;\n\n const naiveCenter = Cartesian3.midpoint(\n minBoxPt,\n maxBoxPt,\n fromPointsNaiveCenterScratch\n );\n\n // Begin 2nd pass to find naive radius and modify the ritter sphere.\n let naiveRadius = 0;\n for (i = 0; i < numElements; i += 3) {\n currentPos.x = positionsHigh[i] + positionsLow[i];\n currentPos.y = positionsHigh[i + 1] + positionsLow[i + 1];\n currentPos.z = positionsHigh[i + 2] + positionsLow[i + 2];\n\n // Find the furthest point from the naive center to calculate the naive radius.\n const r = Cartesian3.magnitude(\n Cartesian3.subtract(currentPos, naiveCenter, fromPointsScratch)\n );\n if (r > naiveRadius) {\n naiveRadius = r;\n }\n\n // Make adjustments to the Ritter Sphere to include all points.\n const oldCenterToPointSquared = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(currentPos, ritterCenter, fromPointsScratch)\n );\n if (oldCenterToPointSquared > radiusSquared) {\n const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);\n // Calculate new radius to include the point that lies outside\n ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;\n radiusSquared = ritterRadius * ritterRadius;\n // Calculate center of new Ritter sphere\n const oldToNew = oldCenterToPoint - ritterRadius;\n ritterCenter.x =\n (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) /\n oldCenterToPoint;\n ritterCenter.y =\n (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) /\n oldCenterToPoint;\n ritterCenter.z =\n (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) /\n oldCenterToPoint;\n }\n }\n\n if (ritterRadius < naiveRadius) {\n Cartesian3.clone(ritterCenter, result.center);\n result.radius = ritterRadius;\n } else {\n Cartesian3.clone(naiveCenter, result.center);\n result.radius = naiveRadius;\n }\n\n return result;\n};\n\n/**\n * Computes a bounding sphere from the corner points of an axis-aligned bounding box. The sphere\n * tighly and fully encompases the box.\n *\n * @param {Cartesian3} [corner] The minimum height over the rectangle.\n * @param {Cartesian3} [oppositeCorner] The maximum height over the rectangle.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n *\n * @example\n * // Create a bounding sphere around the unit cube\n * const sphere = Cesium.BoundingSphere.fromCornerPoints(new Cesium.Cartesian3(-0.5, -0.5, -0.5), new Cesium.Cartesian3(0.5, 0.5, 0.5));\n */\nBoundingSphere.fromCornerPoints = function (corner, oppositeCorner, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"corner\", corner);\n Check.typeOf.object(\"oppositeCorner\", oppositeCorner);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n const center = Cartesian3.midpoint(corner, oppositeCorner, result.center);\n result.radius = Cartesian3.distance(center, oppositeCorner);\n return result;\n};\n\n/**\n * Creates a bounding sphere encompassing an ellipsoid.\n *\n * @param {Ellipsoid} ellipsoid The ellipsoid around which to create a bounding sphere.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n *\n * @example\n * const boundingSphere = Cesium.BoundingSphere.fromEllipsoid(ellipsoid);\n */\nBoundingSphere.fromEllipsoid = function (ellipsoid, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"ellipsoid\", ellipsoid);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n Cartesian3.clone(Cartesian3.ZERO, result.center);\n result.radius = ellipsoid.maximumRadius;\n return result;\n};\n\nconst fromBoundingSpheresScratch = new Cartesian3();\n\n/**\n * Computes a tight-fitting bounding sphere enclosing the provided array of bounding spheres.\n *\n * @param {BoundingSphere[]} [boundingSpheres] The array of bounding spheres.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.fromBoundingSpheres = function (boundingSpheres, result) {\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n if (!defined(boundingSpheres) || boundingSpheres.length === 0) {\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\n result.radius = 0.0;\n return result;\n }\n\n const length = boundingSpheres.length;\n if (length === 1) {\n return BoundingSphere.clone(boundingSpheres[0], result);\n }\n\n if (length === 2) {\n return BoundingSphere.union(boundingSpheres[0], boundingSpheres[1], result);\n }\n\n const positions = [];\n let i;\n for (i = 0; i < length; i++) {\n positions.push(boundingSpheres[i].center);\n }\n\n result = BoundingSphere.fromPoints(positions, result);\n\n const center = result.center;\n let radius = result.radius;\n for (i = 0; i < length; i++) {\n const tmp = boundingSpheres[i];\n radius = Math.max(\n radius,\n Cartesian3.distance(center, tmp.center, fromBoundingSpheresScratch) +\n tmp.radius\n );\n }\n result.radius = radius;\n\n return result;\n};\n\nconst fromOrientedBoundingBoxScratchU = new Cartesian3();\nconst fromOrientedBoundingBoxScratchV = new Cartesian3();\nconst fromOrientedBoundingBoxScratchW = new Cartesian3();\n\n/**\n * Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box.\n *\n * @param {OrientedBoundingBox} orientedBoundingBox The oriented bounding box.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.fromOrientedBoundingBox = function (\n orientedBoundingBox,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"orientedBoundingBox\", orientedBoundingBox);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n const halfAxes = orientedBoundingBox.halfAxes;\n const u = Matrix3.getColumn(halfAxes, 0, fromOrientedBoundingBoxScratchU);\n const v = Matrix3.getColumn(halfAxes, 1, fromOrientedBoundingBoxScratchV);\n const w = Matrix3.getColumn(halfAxes, 2, fromOrientedBoundingBoxScratchW);\n\n Cartesian3.add(u, v, u);\n Cartesian3.add(u, w, u);\n\n result.center = Cartesian3.clone(orientedBoundingBox.center, result.center);\n result.radius = Cartesian3.magnitude(u);\n\n return result;\n};\n\nconst scratchFromTransformationCenter = new Cartesian3();\nconst scratchFromTransformationScale = new Cartesian3();\n\n/**\n * Computes a tight-fitting bounding sphere enclosing the provided affine transformation.\n *\n * @param {Matrix4} transformation The affine transformation.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.fromTransformation = function (transformation, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"transformation\", transformation);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n const center = Matrix4.getTranslation(\n transformation,\n scratchFromTransformationCenter\n );\n const scale = Matrix4.getScale(\n transformation,\n scratchFromTransformationScale\n );\n const radius = 0.5 * Cartesian3.magnitude(scale);\n result.center = Cartesian3.clone(center, result.center);\n result.radius = radius;\n\n return result;\n};\n\n/**\n * Duplicates a BoundingSphere instance.\n *\n * @param {BoundingSphere} sphere The bounding sphere to duplicate.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided. (Returns undefined if sphere is undefined)\n */\nBoundingSphere.clone = function (sphere, result) {\n if (!defined(sphere)) {\n return undefined;\n }\n\n if (!defined(result)) {\n return new BoundingSphere(sphere.center, sphere.radius);\n }\n\n result.center = Cartesian3.clone(sphere.center, result.center);\n result.radius = sphere.radius;\n return result;\n};\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {Number}\n */\nBoundingSphere.packedLength = 4;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {BoundingSphere} value The value to pack.\n * @param {Number[]} array The array to pack into.\n * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {Number[]} The array that was packed into\n */\nBoundingSphere.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const center = value.center;\n array[startingIndex++] = center.x;\n array[startingIndex++] = center.y;\n array[startingIndex++] = center.z;\n array[startingIndex] = value.radius;\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {Number[]} array The packed array.\n * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {BoundingSphere} [result] The object into which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.\n */\nBoundingSphere.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n const center = result.center;\n center.x = array[startingIndex++];\n center.y = array[startingIndex++];\n center.z = array[startingIndex++];\n result.radius = array[startingIndex];\n return result;\n};\n\nconst unionScratch = new Cartesian3();\nconst unionScratchCenter = new Cartesian3();\n/**\n * Computes a bounding sphere that contains both the left and right bounding spheres.\n *\n * @param {BoundingSphere} left A sphere to enclose in a bounding sphere.\n * @param {BoundingSphere} right A sphere to enclose in a bounding sphere.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.union = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n const leftCenter = left.center;\n const leftRadius = left.radius;\n const rightCenter = right.center;\n const rightRadius = right.radius;\n\n const toRightCenter = Cartesian3.subtract(\n rightCenter,\n leftCenter,\n unionScratch\n );\n const centerSeparation = Cartesian3.magnitude(toRightCenter);\n\n if (leftRadius >= centerSeparation + rightRadius) {\n // Left sphere wins.\n left.clone(result);\n return result;\n }\n\n if (rightRadius >= centerSeparation + leftRadius) {\n // Right sphere wins.\n right.clone(result);\n return result;\n }\n\n // There are two tangent points, one on far side of each sphere.\n const halfDistanceBetweenTangentPoints =\n (leftRadius + centerSeparation + rightRadius) * 0.5;\n\n // Compute the center point halfway between the two tangent points.\n const center = Cartesian3.multiplyByScalar(\n toRightCenter,\n (-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation,\n unionScratchCenter\n );\n Cartesian3.add(center, leftCenter, center);\n Cartesian3.clone(center, result.center);\n result.radius = halfDistanceBetweenTangentPoints;\n\n return result;\n};\n\nconst expandScratch = new Cartesian3();\n/**\n * Computes a bounding sphere by enlarging the provided sphere to contain the provided point.\n *\n * @param {BoundingSphere} sphere A sphere to expand.\n * @param {Cartesian3} point A point to enclose in a bounding sphere.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.expand = function (sphere, point, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"sphere\", sphere);\n Check.typeOf.object(\"point\", point);\n //>>includeEnd('debug');\n\n result = BoundingSphere.clone(sphere, result);\n\n const radius = Cartesian3.magnitude(\n Cartesian3.subtract(point, result.center, expandScratch)\n );\n if (radius > result.radius) {\n result.radius = radius;\n }\n\n return result;\n};\n\n/**\n * Determines which side of a plane a sphere is located.\n *\n * @param {BoundingSphere} sphere The bounding sphere to test.\n * @param {Plane} plane The plane to test against.\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire sphere is on the side of the plane\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire sphere is\n * on the opposite side, and {@link Intersect.INTERSECTING} if the sphere\n * intersects the plane.\n */\nBoundingSphere.intersectPlane = function (sphere, plane) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"sphere\", sphere);\n Check.typeOf.object(\"plane\", plane);\n //>>includeEnd('debug');\n\n const center = sphere.center;\n const radius = sphere.radius;\n const normal = plane.normal;\n const distanceToPlane = Cartesian3.dot(normal, center) + plane.distance;\n\n if (distanceToPlane < -radius) {\n // The center point is negative side of the plane normal\n return Intersect.OUTSIDE;\n } else if (distanceToPlane < radius) {\n // The center point is positive side of the plane, but radius extends beyond it; partial overlap\n return Intersect.INTERSECTING;\n }\n return Intersect.INSIDE;\n};\n\n/**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n *\n * @param {BoundingSphere} sphere The bounding sphere to apply the transformation to.\n * @param {Matrix4} transform The transformation matrix to apply to the bounding sphere.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.transform = function (sphere, transform, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"sphere\", sphere);\n Check.typeOf.object(\"transform\", transform);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n result.center = Matrix4.multiplyByPoint(\n transform,\n sphere.center,\n result.center\n );\n result.radius = Matrix4.getMaximumScale(transform) * sphere.radius;\n\n return result;\n};\n\nconst distanceSquaredToScratch = new Cartesian3();\n\n/**\n * Computes the estimated distance squared from the closest point on a bounding sphere to a point.\n *\n * @param {BoundingSphere} sphere The sphere.\n * @param {Cartesian3} cartesian The point\n * @returns {Number} The distance squared from the bounding sphere to the point. Returns 0 if the point is inside the sphere.\n *\n * @example\n * // Sort bounding spheres from back to front\n * spheres.sort(function(a, b) {\n * return Cesium.BoundingSphere.distanceSquaredTo(b, camera.positionWC) - Cesium.BoundingSphere.distanceSquaredTo(a, camera.positionWC);\n * });\n */\nBoundingSphere.distanceSquaredTo = function (sphere, cartesian) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"sphere\", sphere);\n Check.typeOf.object(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n const diff = Cartesian3.subtract(\n sphere.center,\n cartesian,\n distanceSquaredToScratch\n );\n\n const distance = Cartesian3.magnitude(diff) - sphere.radius;\n if (distance <= 0.0) {\n return 0.0;\n }\n\n return distance * distance;\n};\n\n/**\n * Applies a 4x4 affine transformation matrix to a bounding sphere where there is no scale\n * The transformation matrix is not verified to have a uniform scale of 1.\n * This method is faster than computing the general bounding sphere transform using {@link BoundingSphere.transform}.\n *\n * @param {BoundingSphere} sphere The bounding sphere to apply the transformation to.\n * @param {Matrix4} transform The transformation matrix to apply to the bounding sphere.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n *\n * @example\n * const modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(positionOnEllipsoid);\n * const boundingSphere = new Cesium.BoundingSphere();\n * const newBoundingSphere = Cesium.BoundingSphere.transformWithoutScale(boundingSphere, modelMatrix);\n */\nBoundingSphere.transformWithoutScale = function (sphere, transform, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"sphere\", sphere);\n Check.typeOf.object(\"transform\", transform);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n result.center = Matrix4.multiplyByPoint(\n transform,\n sphere.center,\n result.center\n );\n result.radius = sphere.radius;\n\n return result;\n};\n\nconst scratchCartesian3 = new Cartesian3();\n/**\n * The distances calculated by the vector from the center of the bounding sphere to position projected onto direction\n * plus/minus the radius of the bounding sphere.\n *
\n * If you imagine the infinite number of planes with normal direction, this computes the smallest distance to the\n * closest and farthest planes from position that intersect the bounding sphere.\n *\n * @param {BoundingSphere} sphere The bounding sphere to calculate the distance to.\n * @param {Cartesian3} position The position to calculate the distance from.\n * @param {Cartesian3} direction The direction from position.\n * @param {Interval} [result] A Interval to store the nearest and farthest distances.\n * @returns {Interval} The nearest and farthest distances on the bounding sphere from position in direction.\n */\nBoundingSphere.computePlaneDistances = function (\n sphere,\n position,\n direction,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"sphere\", sphere);\n Check.typeOf.object(\"position\", position);\n Check.typeOf.object(\"direction\", direction);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Interval();\n }\n\n const toCenter = Cartesian3.subtract(\n sphere.center,\n position,\n scratchCartesian3\n );\n const mag = Cartesian3.dot(direction, toCenter);\n\n result.start = mag - sphere.radius;\n result.stop = mag + sphere.radius;\n return result;\n};\n\nconst projectTo2DNormalScratch = new Cartesian3();\nconst projectTo2DEastScratch = new Cartesian3();\nconst projectTo2DNorthScratch = new Cartesian3();\nconst projectTo2DWestScratch = new Cartesian3();\nconst projectTo2DSouthScratch = new Cartesian3();\nconst projectTo2DCartographicScratch = new Cartographic();\nconst projectTo2DPositionsScratch = new Array(8);\nfor (let n = 0; n < 8; ++n) {\n projectTo2DPositionsScratch[n] = new Cartesian3();\n}\n\nconst projectTo2DProjection = new GeographicProjection();\n/**\n * Creates a bounding sphere in 2D from a bounding sphere in 3D world coordinates.\n *\n * @param {BoundingSphere} sphere The bounding sphere to transform to 2D.\n * @param {Object} [projection=GeographicProjection] The projection to 2D.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.projectTo2D = function (sphere, projection, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"sphere\", sphere);\n //>>includeEnd('debug');\n\n projection = defaultValue(projection, projectTo2DProjection);\n\n const ellipsoid = projection.ellipsoid;\n let center = sphere.center;\n const radius = sphere.radius;\n\n let normal;\n if (Cartesian3.equals(center, Cartesian3.ZERO)) {\n // Bounding sphere is at the center. The geodetic surface normal is not\n // defined here so pick the x-axis as a fallback.\n normal = Cartesian3.clone(Cartesian3.UNIT_X, projectTo2DNormalScratch);\n } else {\n normal = ellipsoid.geodeticSurfaceNormal(center, projectTo2DNormalScratch);\n }\n const east = Cartesian3.cross(\n Cartesian3.UNIT_Z,\n normal,\n projectTo2DEastScratch\n );\n Cartesian3.normalize(east, east);\n const north = Cartesian3.cross(normal, east, projectTo2DNorthScratch);\n Cartesian3.normalize(north, north);\n\n Cartesian3.multiplyByScalar(normal, radius, normal);\n Cartesian3.multiplyByScalar(north, radius, north);\n Cartesian3.multiplyByScalar(east, radius, east);\n\n const south = Cartesian3.negate(north, projectTo2DSouthScratch);\n const west = Cartesian3.negate(east, projectTo2DWestScratch);\n\n const positions = projectTo2DPositionsScratch;\n\n // top NE corner\n let corner = positions[0];\n Cartesian3.add(normal, north, corner);\n Cartesian3.add(corner, east, corner);\n\n // top NW corner\n corner = positions[1];\n Cartesian3.add(normal, north, corner);\n Cartesian3.add(corner, west, corner);\n\n // top SW corner\n corner = positions[2];\n Cartesian3.add(normal, south, corner);\n Cartesian3.add(corner, west, corner);\n\n // top SE corner\n corner = positions[3];\n Cartesian3.add(normal, south, corner);\n Cartesian3.add(corner, east, corner);\n\n Cartesian3.negate(normal, normal);\n\n // bottom NE corner\n corner = positions[4];\n Cartesian3.add(normal, north, corner);\n Cartesian3.add(corner, east, corner);\n\n // bottom NW corner\n corner = positions[5];\n Cartesian3.add(normal, north, corner);\n Cartesian3.add(corner, west, corner);\n\n // bottom SW corner\n corner = positions[6];\n Cartesian3.add(normal, south, corner);\n Cartesian3.add(corner, west, corner);\n\n // bottom SE corner\n corner = positions[7];\n Cartesian3.add(normal, south, corner);\n Cartesian3.add(corner, east, corner);\n\n const length = positions.length;\n for (let i = 0; i < length; ++i) {\n const position = positions[i];\n Cartesian3.add(center, position, position);\n const cartographic = ellipsoid.cartesianToCartographic(\n position,\n projectTo2DCartographicScratch\n );\n projection.project(cartographic, position);\n }\n\n result = BoundingSphere.fromPoints(positions, result);\n\n // swizzle center components\n center = result.center;\n const x = center.x;\n const y = center.y;\n const z = center.z;\n center.x = z;\n center.y = x;\n center.z = y;\n\n return result;\n};\n\n/**\n * Determines whether or not a sphere is hidden from view by the occluder.\n *\n * @param {BoundingSphere} sphere The bounding sphere surrounding the occludee object.\n * @param {Occluder} occluder The occluder.\n * @returns {Boolean} true
if the sphere is not visible; otherwise false
.\n */\nBoundingSphere.isOccluded = function (sphere, occluder) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"sphere\", sphere);\n Check.typeOf.object(\"occluder\", occluder);\n //>>includeEnd('debug');\n return !occluder.isBoundingSphereVisible(sphere);\n};\n\n/**\n * Compares the provided BoundingSphere componentwise and returns\n * true
if they are equal, false
otherwise.\n *\n * @param {BoundingSphere} [left] The first BoundingSphere.\n * @param {BoundingSphere} [right] The second BoundingSphere.\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\n */\nBoundingSphere.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n Cartesian3.equals(left.center, right.center) &&\n left.radius === right.radius)\n );\n};\n\n/**\n * Determines which side of a plane the sphere is located.\n *\n * @param {Plane} plane The plane to test against.\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire sphere is on the side of the plane\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire sphere is\n * on the opposite side, and {@link Intersect.INTERSECTING} if the sphere\n * intersects the plane.\n */\nBoundingSphere.prototype.intersectPlane = function (plane) {\n return BoundingSphere.intersectPlane(this, plane);\n};\n\n/**\n * Computes the estimated distance squared from the closest point on a bounding sphere to a point.\n *\n * @param {Cartesian3} cartesian The point\n * @returns {Number} The estimated distance squared from the bounding sphere to the point.\n *\n * @example\n * // Sort bounding spheres from back to front\n * spheres.sort(function(a, b) {\n * return b.distanceSquaredTo(camera.positionWC) - a.distanceSquaredTo(camera.positionWC);\n * });\n */\nBoundingSphere.prototype.distanceSquaredTo = function (cartesian) {\n return BoundingSphere.distanceSquaredTo(this, cartesian);\n};\n\n/**\n * The distances calculated by the vector from the center of the bounding sphere to position projected onto direction\n * plus/minus the radius of the bounding sphere.\n *
\n * If you imagine the infinite number of planes with normal direction, this computes the smallest distance to the\n * closest and farthest planes from position that intersect the bounding sphere.\n *\n * @param {Cartesian3} position The position to calculate the distance from.\n * @param {Cartesian3} direction The direction from position.\n * @param {Interval} [result] A Interval to store the nearest and farthest distances.\n * @returns {Interval} The nearest and farthest distances on the bounding sphere from position in direction.\n */\nBoundingSphere.prototype.computePlaneDistances = function (\n position,\n direction,\n result\n) {\n return BoundingSphere.computePlaneDistances(\n this,\n position,\n direction,\n result\n );\n};\n\n/**\n * Determines whether or not a sphere is hidden from view by the occluder.\n *\n * @param {Occluder} occluder The occluder.\n * @returns {Boolean} true
if the sphere is not visible; otherwise false
.\n */\nBoundingSphere.prototype.isOccluded = function (occluder) {\n return BoundingSphere.isOccluded(this, occluder);\n};\n\n/**\n * Compares this BoundingSphere against the provided BoundingSphere componentwise and returns\n * true
if they are equal, false
otherwise.\n *\n * @param {BoundingSphere} [right] The right hand side BoundingSphere.\n * @returns {Boolean} true
if they are equal, false
otherwise.\n */\nBoundingSphere.prototype.equals = function (right) {\n return BoundingSphere.equals(this, right);\n};\n\n/**\n * Duplicates this BoundingSphere instance.\n *\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.prototype.clone = function (result) {\n return BoundingSphere.clone(this, result);\n};\n\n/**\n * Computes the radius of the BoundingSphere.\n * @returns {Number} The radius of the BoundingSphere.\n */\nBoundingSphere.prototype.volume = function () {\n const radius = this.radius;\n return volumeConstant * radius * radius * radius;\n};\nexport default BoundingSphere;\n","import defined from \"./defined.js\";\n\nlet _supportsFullscreen;\nconst _names = {\n requestFullscreen: undefined,\n exitFullscreen: undefined,\n fullscreenEnabled: undefined,\n fullscreenElement: undefined,\n fullscreenchange: undefined,\n fullscreenerror: undefined,\n};\n\n/**\n * Browser-independent functions for working with the standard fullscreen API.\n *\n * @namespace Fullscreen\n *\n * @see {@link http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html|W3C Fullscreen Living Specification}\n */\nconst Fullscreen = {};\n\nObject.defineProperties(Fullscreen, {\n /**\n * The element that is currently fullscreen, if any. To simply check if the\n * browser is in fullscreen mode or not, use {@link Fullscreen#fullscreen}.\n * @memberof Fullscreen\n * @type {Object}\n * @readonly\n */\n element: {\n get: function () {\n if (!Fullscreen.supportsFullscreen()) {\n return undefined;\n }\n\n return document[_names.fullscreenElement];\n },\n },\n\n /**\n * The name of the event on the document that is fired when fullscreen is\n * entered or exited. This event name is intended for use with addEventListener.\n * In your event handler, to determine if the browser is in fullscreen mode or not,\n * use {@link Fullscreen#fullscreen}.\n * @memberof Fullscreen\n * @type {String}\n * @readonly\n */\n changeEventName: {\n get: function () {\n if (!Fullscreen.supportsFullscreen()) {\n return undefined;\n }\n\n return _names.fullscreenchange;\n },\n },\n\n /**\n * The name of the event that is fired when a fullscreen error\n * occurs. This event name is intended for use with addEventListener.\n * @memberof Fullscreen\n * @type {String}\n * @readonly\n */\n errorEventName: {\n get: function () {\n if (!Fullscreen.supportsFullscreen()) {\n return undefined;\n }\n\n return _names.fullscreenerror;\n },\n },\n\n /**\n * Determine whether the browser will allow an element to be made fullscreen, or not.\n * For example, by default, iframes cannot go fullscreen unless the containing page\n * adds an \"allowfullscreen\" attribute (or prefixed equivalent).\n * @memberof Fullscreen\n * @type {Boolean}\n * @readonly\n */\n enabled: {\n get: function () {\n if (!Fullscreen.supportsFullscreen()) {\n return undefined;\n }\n\n return document[_names.fullscreenEnabled];\n },\n },\n\n /**\n * Determines if the browser is currently in fullscreen mode.\n * @memberof Fullscreen\n * @type {Boolean}\n * @readonly\n */\n fullscreen: {\n get: function () {\n if (!Fullscreen.supportsFullscreen()) {\n return undefined;\n }\n\n return Fullscreen.element !== null;\n },\n },\n});\n\n/**\n * Detects whether the browser supports the standard fullscreen API.\n *\n * @returns {Boolean} true
if the browser supports the standard fullscreen API,\n * false
otherwise.\n */\nFullscreen.supportsFullscreen = function () {\n if (defined(_supportsFullscreen)) {\n return _supportsFullscreen;\n }\n\n _supportsFullscreen = false;\n\n const body = document.body;\n if (typeof body.requestFullscreen === \"function\") {\n // go with the unprefixed, standard set of names\n _names.requestFullscreen = \"requestFullscreen\";\n _names.exitFullscreen = \"exitFullscreen\";\n _names.fullscreenEnabled = \"fullscreenEnabled\";\n _names.fullscreenElement = \"fullscreenElement\";\n _names.fullscreenchange = \"fullscreenchange\";\n _names.fullscreenerror = \"fullscreenerror\";\n _supportsFullscreen = true;\n return _supportsFullscreen;\n }\n\n //check for the correct combination of prefix plus the various names that browsers use\n const prefixes = [\"webkit\", \"moz\", \"o\", \"ms\", \"khtml\"];\n let name;\n for (let i = 0, len = prefixes.length; i < len; ++i) {\n const prefix = prefixes[i];\n\n // casing of Fullscreen differs across browsers\n name = `${prefix}RequestFullscreen`;\n if (typeof body[name] === \"function\") {\n _names.requestFullscreen = name;\n _supportsFullscreen = true;\n } else {\n name = `${prefix}RequestFullScreen`;\n if (typeof body[name] === \"function\") {\n _names.requestFullscreen = name;\n _supportsFullscreen = true;\n }\n }\n\n // disagreement about whether it's \"exit\" as per spec, or \"cancel\"\n name = `${prefix}ExitFullscreen`;\n if (typeof document[name] === \"function\") {\n _names.exitFullscreen = name;\n } else {\n name = `${prefix}CancelFullScreen`;\n if (typeof document[name] === \"function\") {\n _names.exitFullscreen = name;\n }\n }\n\n // casing of Fullscreen differs across browsers\n name = `${prefix}FullscreenEnabled`;\n if (document[name] !== undefined) {\n _names.fullscreenEnabled = name;\n } else {\n name = `${prefix}FullScreenEnabled`;\n if (document[name] !== undefined) {\n _names.fullscreenEnabled = name;\n }\n }\n\n // casing of Fullscreen differs across browsers\n name = `${prefix}FullscreenElement`;\n if (document[name] !== undefined) {\n _names.fullscreenElement = name;\n } else {\n name = `${prefix}FullScreenElement`;\n if (document[name] !== undefined) {\n _names.fullscreenElement = name;\n }\n }\n\n // thankfully, event names are all lowercase per spec\n name = `${prefix}fullscreenchange`;\n // event names do not have 'on' in the front, but the property on the document does\n if (document[`on${name}`] !== undefined) {\n //except on IE\n if (prefix === \"ms\") {\n name = \"MSFullscreenChange\";\n }\n _names.fullscreenchange = name;\n }\n\n name = `${prefix}fullscreenerror`;\n if (document[`on${name}`] !== undefined) {\n //except on IE\n if (prefix === \"ms\") {\n name = \"MSFullscreenError\";\n }\n _names.fullscreenerror = name;\n }\n }\n\n return _supportsFullscreen;\n};\n\n/**\n * Asynchronously requests the browser to enter fullscreen mode on the given element.\n * If fullscreen mode is not supported by the browser, does nothing.\n *\n * @param {Object} element The HTML element which will be placed into fullscreen mode.\n * @param {Object} [vrDevice] The HMDVRDevice device.\n *\n * @example\n * // Put the entire page into fullscreen.\n * Cesium.Fullscreen.requestFullscreen(document.body)\n *\n * // Place only the Cesium canvas into fullscreen.\n * Cesium.Fullscreen.requestFullscreen(scene.canvas)\n */\nFullscreen.requestFullscreen = function (element, vrDevice) {\n if (!Fullscreen.supportsFullscreen()) {\n return;\n }\n\n element[_names.requestFullscreen]({ vrDisplay: vrDevice });\n};\n\n/**\n * Asynchronously exits fullscreen mode. If the browser is not currently\n * in fullscreen, or if fullscreen mode is not supported by the browser, does nothing.\n */\nFullscreen.exitFullscreen = function () {\n if (!Fullscreen.supportsFullscreen()) {\n return;\n }\n\n document[_names.exitFullscreen]();\n};\n\n//For unit tests\nFullscreen._names = _names;\nexport default Fullscreen;\n","import when from \"../ThirdParty/when.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Fullscreen from \"./Fullscreen.js\";\n\nlet theNavigator;\nif (typeof navigator !== \"undefined\") {\n theNavigator = navigator;\n} else {\n theNavigator = {};\n}\n\nfunction extractVersion(versionString) {\n const parts = versionString.split(\".\");\n for (let i = 0, len = parts.length; i < len; ++i) {\n parts[i] = parseInt(parts[i], 10);\n }\n return parts;\n}\n\nlet isChromeResult;\nlet chromeVersionResult;\nfunction isChrome() {\n if (!defined(isChromeResult)) {\n isChromeResult = false;\n // Edge contains Chrome in the user agent too\n if (!isEdge()) {\n const fields = / Chrome\\/([\\.0-9]+)/.exec(theNavigator.userAgent);\n if (fields !== null) {\n isChromeResult = true;\n chromeVersionResult = extractVersion(fields[1]);\n }\n }\n }\n\n return isChromeResult;\n}\n\nfunction chromeVersion() {\n return isChrome() && chromeVersionResult;\n}\n\nlet isSafariResult;\nlet safariVersionResult;\nfunction isSafari() {\n if (!defined(isSafariResult)) {\n isSafariResult = false;\n\n // Chrome and Edge contain Safari in the user agent too\n if (\n !isChrome() &&\n !isEdge() &&\n / Safari\\/[\\.0-9]+/.test(theNavigator.userAgent)\n ) {\n const fields = / Version\\/([\\.0-9]+)/.exec(theNavigator.userAgent);\n if (fields !== null) {\n isSafariResult = true;\n safariVersionResult = extractVersion(fields[1]);\n }\n }\n }\n\n return isSafariResult;\n}\n\nfunction safariVersion() {\n return isSafari() && safariVersionResult;\n}\n\nlet isWebkitResult;\nlet webkitVersionResult;\nfunction isWebkit() {\n if (!defined(isWebkitResult)) {\n isWebkitResult = false;\n\n const fields = / AppleWebKit\\/([\\.0-9]+)(\\+?)/.exec(theNavigator.userAgent);\n if (fields !== null) {\n isWebkitResult = true;\n webkitVersionResult = extractVersion(fields[1]);\n webkitVersionResult.isNightly = !!fields[2];\n }\n }\n\n return isWebkitResult;\n}\n\nfunction webkitVersion() {\n return isWebkit() && webkitVersionResult;\n}\n\nlet isInternetExplorerResult;\nlet internetExplorerVersionResult;\nfunction isInternetExplorer() {\n if (!defined(isInternetExplorerResult)) {\n isInternetExplorerResult = false;\n\n let fields;\n if (theNavigator.appName === \"Microsoft Internet Explorer\") {\n fields = /MSIE ([0-9]{1,}[\\.0-9]{0,})/.exec(theNavigator.userAgent);\n if (fields !== null) {\n isInternetExplorerResult = true;\n internetExplorerVersionResult = extractVersion(fields[1]);\n }\n } else if (theNavigator.appName === \"Netscape\") {\n fields = /Trident\\/.*rv:([0-9]{1,}[\\.0-9]{0,})/.exec(\n theNavigator.userAgent\n );\n if (fields !== null) {\n isInternetExplorerResult = true;\n internetExplorerVersionResult = extractVersion(fields[1]);\n }\n }\n }\n return isInternetExplorerResult;\n}\n\nfunction internetExplorerVersion() {\n return isInternetExplorer() && internetExplorerVersionResult;\n}\n\nlet isEdgeResult;\nlet edgeVersionResult;\nfunction isEdge() {\n if (!defined(isEdgeResult)) {\n isEdgeResult = false;\n const fields = / Edge\\/([\\.0-9]+)/.exec(theNavigator.userAgent);\n if (fields !== null) {\n isEdgeResult = true;\n edgeVersionResult = extractVersion(fields[1]);\n }\n }\n return isEdgeResult;\n}\n\nfunction edgeVersion() {\n return isEdge() && edgeVersionResult;\n}\n\nlet isFirefoxResult;\nlet firefoxVersionResult;\nfunction isFirefox() {\n if (!defined(isFirefoxResult)) {\n isFirefoxResult = false;\n\n const fields = /Firefox\\/([\\.0-9]+)/.exec(theNavigator.userAgent);\n if (fields !== null) {\n isFirefoxResult = true;\n firefoxVersionResult = extractVersion(fields[1]);\n }\n }\n return isFirefoxResult;\n}\n\nlet isWindowsResult;\nfunction isWindows() {\n if (!defined(isWindowsResult)) {\n isWindowsResult = /Windows/i.test(theNavigator.appVersion);\n }\n return isWindowsResult;\n}\n\nfunction firefoxVersion() {\n return isFirefox() && firefoxVersionResult;\n}\n\nlet hasPointerEvents;\nfunction supportsPointerEvents() {\n if (!defined(hasPointerEvents)) {\n //While navigator.pointerEnabled is deprecated in the W3C specification\n //we still need to use it if it exists in order to support browsers\n //that rely on it, such as the Windows WebBrowser control which defines\n //PointerEvent but sets navigator.pointerEnabled to false.\n\n //Firefox disabled because of https://github.com/CesiumGS/cesium/issues/6372\n hasPointerEvents =\n !isFirefox() &&\n typeof PointerEvent !== \"undefined\" &&\n (!defined(theNavigator.pointerEnabled) || theNavigator.pointerEnabled);\n }\n return hasPointerEvents;\n}\n\nlet imageRenderingValueResult;\nlet supportsImageRenderingPixelatedResult;\nfunction supportsImageRenderingPixelated() {\n if (!defined(supportsImageRenderingPixelatedResult)) {\n const canvas = document.createElement(\"canvas\");\n canvas.setAttribute(\n \"style\",\n \"image-rendering: -moz-crisp-edges;\" + \"image-rendering: pixelated;\"\n );\n //canvas.style.imageRendering will be undefined, null or an empty string on unsupported browsers.\n const tmp = canvas.style.imageRendering;\n supportsImageRenderingPixelatedResult = defined(tmp) && tmp !== \"\";\n if (supportsImageRenderingPixelatedResult) {\n imageRenderingValueResult = tmp;\n }\n }\n return supportsImageRenderingPixelatedResult;\n}\n\nfunction imageRenderingValue() {\n return supportsImageRenderingPixelated()\n ? imageRenderingValueResult\n : undefined;\n}\n\nfunction supportsWebP() {\n //>>includeStart('debug', pragmas.debug);\n if (!supportsWebP.initialized) {\n throw new DeveloperError(\n \"You must call FeatureDetection.supportsWebP.initialize and wait for the promise to resolve before calling FeatureDetection.supportsWebP\"\n );\n }\n //>>includeEnd('debug');\n return supportsWebP._result;\n}\nsupportsWebP._promise = undefined;\nsupportsWebP._result = undefined;\nsupportsWebP.initialize = function () {\n // From https://developers.google.com/speed/webp/faq#how_can_i_detect_browser_support_for_webp\n if (defined(supportsWebP._promise)) {\n return supportsWebP._promise;\n }\n\n const supportsWebPDeferred = when.defer();\n supportsWebP._promise = supportsWebPDeferred.promise;\n if (isEdge()) {\n // Edge's WebP support with WebGL is incomplete.\n // See bug report: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/19221241/\n supportsWebP._result = false;\n supportsWebPDeferred.resolve(supportsWebP._result);\n return supportsWebPDeferred.promise;\n }\n\n const image = new Image();\n image.onload = function () {\n supportsWebP._result = image.width > 0 && image.height > 0;\n supportsWebPDeferred.resolve(supportsWebP._result);\n };\n\n image.onerror = function () {\n supportsWebP._result = false;\n supportsWebPDeferred.resolve(supportsWebP._result);\n };\n\n image.src =\n \"data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA\";\n\n return supportsWebPDeferred.promise;\n};\nObject.defineProperties(supportsWebP, {\n initialized: {\n get: function () {\n return defined(supportsWebP._result);\n },\n },\n});\n\nconst typedArrayTypes = [];\nif (typeof ArrayBuffer !== \"undefined\") {\n typedArrayTypes.push(\n Int8Array,\n Uint8Array,\n Int16Array,\n Uint16Array,\n Int32Array,\n Uint32Array,\n Float32Array,\n Float64Array\n );\n\n if (typeof Uint8ClampedArray !== \"undefined\") {\n typedArrayTypes.push(Uint8ClampedArray);\n }\n\n if (typeof Uint8ClampedArray !== \"undefined\") {\n typedArrayTypes.push(Uint8ClampedArray);\n }\n\n if (typeof BigInt64Array !== \"undefined\") {\n // eslint-disable-next-line no-undef\n typedArrayTypes.push(BigInt64Array);\n }\n\n if (typeof BigUint64Array !== \"undefined\") {\n // eslint-disable-next-line no-undef\n typedArrayTypes.push(BigUint64Array);\n }\n}\n\n/**\n * A set of functions to detect whether the current browser supports\n * various features.\n *\n * @namespace FeatureDetection\n */\nconst FeatureDetection = {\n isChrome: isChrome,\n chromeVersion: chromeVersion,\n isSafari: isSafari,\n safariVersion: safariVersion,\n isWebkit: isWebkit,\n webkitVersion: webkitVersion,\n isInternetExplorer: isInternetExplorer,\n internetExplorerVersion: internetExplorerVersion,\n isEdge: isEdge,\n edgeVersion: edgeVersion,\n isFirefox: isFirefox,\n firefoxVersion: firefoxVersion,\n isWindows: isWindows,\n hardwareConcurrency: defaultValue(theNavigator.hardwareConcurrency, 3),\n supportsPointerEvents: supportsPointerEvents,\n supportsImageRenderingPixelated: supportsImageRenderingPixelated,\n supportsWebP: supportsWebP,\n imageRenderingValue: imageRenderingValue,\n typedArrayTypes: typedArrayTypes,\n};\n\n/**\n * Detects whether the current browser supports Basis Universal textures and the web assembly modules needed to transcode them.\n *\n * @param {Scene} scene\n * @returns {Boolean} true if the browser supports web assembly modules and the scene supports Basis Universal textures, false if not.\n */\nFeatureDetection.supportsBasis = function (scene) {\n return FeatureDetection.supportsWebAssembly() && scene.context.supportsBasis;\n};\n\n/**\n * Detects whether the current browser supports the full screen standard.\n *\n * @returns {Boolean} true if the browser supports the full screen standard, false if not.\n *\n * @see Fullscreen\n * @see {@link http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html|W3C Fullscreen Living Specification}\n */\nFeatureDetection.supportsFullscreen = function () {\n return Fullscreen.supportsFullscreen();\n};\n\n/**\n * Detects whether the current browser supports typed arrays.\n *\n * @returns {Boolean} true if the browser supports typed arrays, false if not.\n *\n * @see {@link https://tc39.es/ecma262/#sec-typedarray-objects|Typed Array Specification}\n */\nFeatureDetection.supportsTypedArrays = function () {\n return typeof ArrayBuffer !== \"undefined\";\n};\n\n/**\n * Detects whether the current browser supports BigInt64Array typed arrays.\n *\n * @returns {Boolean} true if the browser supports BigInt64Array typed arrays, false if not.\n *\n * @see {@link https://tc39.es/ecma262/#sec-typedarray-objects|Typed Array Specification}\n */\nFeatureDetection.supportsBigInt64Array = function () {\n return typeof BigInt64Array !== \"undefined\";\n};\n\n/**\n * Detects whether the current browser supports BigUint64Array typed arrays.\n *\n * @returns {Boolean} true if the browser supports BigUint64Array typed arrays, false if not.\n *\n * @see {@link https://tc39.es/ecma262/#sec-typedarray-objects|Typed Array Specification}\n */\nFeatureDetection.supportsBigUint64Array = function () {\n return typeof BigUint64Array !== \"undefined\";\n};\n\n/**\n * Detects whether the current browser supports BigInt.\n *\n * @returns {Boolean} true if the browser supports BigInt, false if not.\n *\n * @see {@link https://tc39.es/ecma262/#sec-bigint-objects|BigInt Specification}\n */\nFeatureDetection.supportsBigInt = function () {\n return typeof BigInt !== \"undefined\";\n};\n\n/**\n * Detects whether the current browser supports Web Workers.\n *\n * @returns {Boolean} true if the browsers supports Web Workers, false if not.\n *\n * @see {@link http://www.w3.org/TR/workers/}\n */\nFeatureDetection.supportsWebWorkers = function () {\n return typeof Worker !== \"undefined\";\n};\n\n/**\n * Detects whether the current browser supports Web Assembly.\n *\n * @returns {Boolean} true if the browsers supports Web Assembly, false if not.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/WebAssembly}\n */\nFeatureDetection.supportsWebAssembly = function () {\n return typeof WebAssembly !== \"undefined\" && !FeatureDetection.isEdge();\n};\nexport default FeatureDetection;\n","import Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport FeatureDetection from \"./FeatureDetection.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\n\n/**\n * A set of 4-dimensional coordinates used to represent rotation in 3-dimensional space.\n * @alias Quaternion\n * @constructor\n *\n * @param {Number} [x=0.0] The X component.\n * @param {Number} [y=0.0] The Y component.\n * @param {Number} [z=0.0] The Z component.\n * @param {Number} [w=0.0] The W component.\n *\n * @see PackableForInterpolation\n */\nfunction Quaternion(x, y, z, w) {\n /**\n * The X component.\n * @type {Number}\n * @default 0.0\n */\n this.x = defaultValue(x, 0.0);\n\n /**\n * The Y component.\n * @type {Number}\n * @default 0.0\n */\n this.y = defaultValue(y, 0.0);\n\n /**\n * The Z component.\n * @type {Number}\n * @default 0.0\n */\n this.z = defaultValue(z, 0.0);\n\n /**\n * The W component.\n * @type {Number}\n * @default 0.0\n */\n this.w = defaultValue(w, 0.0);\n}\n\nlet fromAxisAngleScratch = new Cartesian3();\n\n/**\n * Computes a quaternion representing a rotation around an axis.\n *\n * @param {Cartesian3} axis The axis of rotation.\n * @param {Number} angle The angle in radians to rotate around the axis.\n * @param {Quaternion} [result] The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.\n */\nQuaternion.fromAxisAngle = function (axis, angle, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"axis\", axis);\n Check.typeOf.number(\"angle\", angle);\n //>>includeEnd('debug');\n\n const halfAngle = angle / 2.0;\n const s = Math.sin(halfAngle);\n fromAxisAngleScratch = Cartesian3.normalize(axis, fromAxisAngleScratch);\n\n const x = fromAxisAngleScratch.x * s;\n const y = fromAxisAngleScratch.y * s;\n const z = fromAxisAngleScratch.z * s;\n const w = Math.cos(halfAngle);\n if (!defined(result)) {\n return new Quaternion(x, y, z, w);\n }\n result.x = x;\n result.y = y;\n result.z = z;\n result.w = w;\n return result;\n};\n\nconst fromRotationMatrixNext = [1, 2, 0];\nconst fromRotationMatrixQuat = new Array(3);\n/**\n * Computes a Quaternion from the provided Matrix3 instance.\n *\n * @param {Matrix3} matrix The rotation matrix.\n * @param {Quaternion} [result] The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.\n *\n * @see Matrix3.fromQuaternion\n */\nQuaternion.fromRotationMatrix = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n //>>includeEnd('debug');\n\n let root;\n let x;\n let y;\n let z;\n let w;\n\n const m00 = matrix[Matrix3.COLUMN0ROW0];\n const m11 = matrix[Matrix3.COLUMN1ROW1];\n const m22 = matrix[Matrix3.COLUMN2ROW2];\n const trace = m00 + m11 + m22;\n\n if (trace > 0.0) {\n // |w| > 1/2, may as well choose w > 1/2\n root = Math.sqrt(trace + 1.0); // 2w\n w = 0.5 * root;\n root = 0.5 / root; // 1/(4w)\n\n x = (matrix[Matrix3.COLUMN1ROW2] - matrix[Matrix3.COLUMN2ROW1]) * root;\n y = (matrix[Matrix3.COLUMN2ROW0] - matrix[Matrix3.COLUMN0ROW2]) * root;\n z = (matrix[Matrix3.COLUMN0ROW1] - matrix[Matrix3.COLUMN1ROW0]) * root;\n } else {\n // |w| <= 1/2\n const next = fromRotationMatrixNext;\n\n let i = 0;\n if (m11 > m00) {\n i = 1;\n }\n if (m22 > m00 && m22 > m11) {\n i = 2;\n }\n const j = next[i];\n const k = next[j];\n\n root = Math.sqrt(\n matrix[Matrix3.getElementIndex(i, i)] -\n matrix[Matrix3.getElementIndex(j, j)] -\n matrix[Matrix3.getElementIndex(k, k)] +\n 1.0\n );\n\n const quat = fromRotationMatrixQuat;\n quat[i] = 0.5 * root;\n root = 0.5 / root;\n w =\n (matrix[Matrix3.getElementIndex(k, j)] -\n matrix[Matrix3.getElementIndex(j, k)]) *\n root;\n quat[j] =\n (matrix[Matrix3.getElementIndex(j, i)] +\n matrix[Matrix3.getElementIndex(i, j)]) *\n root;\n quat[k] =\n (matrix[Matrix3.getElementIndex(k, i)] +\n matrix[Matrix3.getElementIndex(i, k)]) *\n root;\n\n x = -quat[0];\n y = -quat[1];\n z = -quat[2];\n }\n\n if (!defined(result)) {\n return new Quaternion(x, y, z, w);\n }\n result.x = x;\n result.y = y;\n result.z = z;\n result.w = w;\n return result;\n};\n\nconst scratchHPRQuaternion = new Quaternion();\nlet scratchHeadingQuaternion = new Quaternion();\nlet scratchPitchQuaternion = new Quaternion();\nlet scratchRollQuaternion = new Quaternion();\n\n/**\n * Computes a rotation from the given heading, pitch and roll angles. Heading is the rotation about the\n * negative z axis. Pitch is the rotation about the negative y axis. Roll is the rotation about\n * the positive x axis.\n *\n * @param {HeadingPitchRoll} headingPitchRoll The rotation expressed as a heading, pitch and roll.\n * @param {Quaternion} [result] The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if none was provided.\n */\nQuaternion.fromHeadingPitchRoll = function (headingPitchRoll, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"headingPitchRoll\", headingPitchRoll);\n //>>includeEnd('debug');\n\n scratchRollQuaternion = Quaternion.fromAxisAngle(\n Cartesian3.UNIT_X,\n headingPitchRoll.roll,\n scratchHPRQuaternion\n );\n scratchPitchQuaternion = Quaternion.fromAxisAngle(\n Cartesian3.UNIT_Y,\n -headingPitchRoll.pitch,\n result\n );\n result = Quaternion.multiply(\n scratchPitchQuaternion,\n scratchRollQuaternion,\n scratchPitchQuaternion\n );\n scratchHeadingQuaternion = Quaternion.fromAxisAngle(\n Cartesian3.UNIT_Z,\n -headingPitchRoll.heading,\n scratchHPRQuaternion\n );\n return Quaternion.multiply(scratchHeadingQuaternion, result, result);\n};\n\nconst sampledQuaternionAxis = new Cartesian3();\nconst sampledQuaternionRotation = new Cartesian3();\nconst sampledQuaternionTempQuaternion = new Quaternion();\nconst sampledQuaternionQuaternion0 = new Quaternion();\nconst sampledQuaternionQuaternion0Conjugate = new Quaternion();\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {Number}\n */\nQuaternion.packedLength = 4;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {Quaternion} value The value to pack.\n * @param {Number[]} array The array to pack into.\n * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {Number[]} The array that was packed into\n */\nQuaternion.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n array[startingIndex++] = value.x;\n array[startingIndex++] = value.y;\n array[startingIndex++] = value.z;\n array[startingIndex] = value.w;\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {Number[]} array The packed array.\n * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {Quaternion} [result] The object into which to store the result.\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.\n */\nQuaternion.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new Quaternion();\n }\n result.x = array[startingIndex];\n result.y = array[startingIndex + 1];\n result.z = array[startingIndex + 2];\n result.w = array[startingIndex + 3];\n return result;\n};\n\n/**\n * The number of elements used to store the object into an array in its interpolatable form.\n * @type {Number}\n */\nQuaternion.packedInterpolationLength = 3;\n\n/**\n * Converts a packed array into a form suitable for interpolation.\n *\n * @param {Number[]} packedArray The packed array.\n * @param {Number} [startingIndex=0] The index of the first element to be converted.\n * @param {Number} [lastIndex=packedArray.length] The index of the last element to be converted.\n * @param {Number[]} [result] The object into which to store the result.\n */\nQuaternion.convertPackedArrayForInterpolation = function (\n packedArray,\n startingIndex,\n lastIndex,\n result\n) {\n Quaternion.unpack(\n packedArray,\n lastIndex * 4,\n sampledQuaternionQuaternion0Conjugate\n );\n Quaternion.conjugate(\n sampledQuaternionQuaternion0Conjugate,\n sampledQuaternionQuaternion0Conjugate\n );\n\n for (let i = 0, len = lastIndex - startingIndex + 1; i < len; i++) {\n const offset = i * 3;\n Quaternion.unpack(\n packedArray,\n (startingIndex + i) * 4,\n sampledQuaternionTempQuaternion\n );\n\n Quaternion.multiply(\n sampledQuaternionTempQuaternion,\n sampledQuaternionQuaternion0Conjugate,\n sampledQuaternionTempQuaternion\n );\n\n if (sampledQuaternionTempQuaternion.w < 0) {\n Quaternion.negate(\n sampledQuaternionTempQuaternion,\n sampledQuaternionTempQuaternion\n );\n }\n\n Quaternion.computeAxis(\n sampledQuaternionTempQuaternion,\n sampledQuaternionAxis\n );\n const angle = Quaternion.computeAngle(sampledQuaternionTempQuaternion);\n if (!defined(result)) {\n result = [];\n }\n result[offset] = sampledQuaternionAxis.x * angle;\n result[offset + 1] = sampledQuaternionAxis.y * angle;\n result[offset + 2] = sampledQuaternionAxis.z * angle;\n }\n};\n\n/**\n * Retrieves an instance from a packed array converted with {@link convertPackedArrayForInterpolation}.\n *\n * @param {Number[]} array The array previously packed for interpolation.\n * @param {Number[]} sourceArray The original packed array.\n * @param {Number} [firstIndex=0] The firstIndex used to convert the array.\n * @param {Number} [lastIndex=packedArray.length] The lastIndex used to convert the array.\n * @param {Quaternion} [result] The object into which to store the result.\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.\n */\nQuaternion.unpackInterpolationResult = function (\n array,\n sourceArray,\n firstIndex,\n lastIndex,\n result\n) {\n if (!defined(result)) {\n result = new Quaternion();\n }\n Cartesian3.fromArray(array, 0, sampledQuaternionRotation);\n const magnitude = Cartesian3.magnitude(sampledQuaternionRotation);\n\n Quaternion.unpack(sourceArray, lastIndex * 4, sampledQuaternionQuaternion0);\n\n if (magnitude === 0) {\n Quaternion.clone(Quaternion.IDENTITY, sampledQuaternionTempQuaternion);\n } else {\n Quaternion.fromAxisAngle(\n sampledQuaternionRotation,\n magnitude,\n sampledQuaternionTempQuaternion\n );\n }\n\n return Quaternion.multiply(\n sampledQuaternionTempQuaternion,\n sampledQuaternionQuaternion0,\n result\n );\n};\n\n/**\n * Duplicates a Quaternion instance.\n *\n * @param {Quaternion} quaternion The quaternion to duplicate.\n * @param {Quaternion} [result] The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided. (Returns undefined if quaternion is undefined)\n */\nQuaternion.clone = function (quaternion, result) {\n if (!defined(quaternion)) {\n return undefined;\n }\n\n if (!defined(result)) {\n return new Quaternion(\n quaternion.x,\n quaternion.y,\n quaternion.z,\n quaternion.w\n );\n }\n\n result.x = quaternion.x;\n result.y = quaternion.y;\n result.z = quaternion.z;\n result.w = quaternion.w;\n return result;\n};\n\n/**\n * Computes the conjugate of the provided quaternion.\n *\n * @param {Quaternion} quaternion The quaternion to conjugate.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.conjugate = function (quaternion, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = -quaternion.x;\n result.y = -quaternion.y;\n result.z = -quaternion.z;\n result.w = quaternion.w;\n return result;\n};\n\n/**\n * Computes magnitude squared for the provided quaternion.\n *\n * @param {Quaternion} quaternion The quaternion to conjugate.\n * @returns {Number} The magnitude squared.\n */\nQuaternion.magnitudeSquared = function (quaternion) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n //>>includeEnd('debug');\n\n return (\n quaternion.x * quaternion.x +\n quaternion.y * quaternion.y +\n quaternion.z * quaternion.z +\n quaternion.w * quaternion.w\n );\n};\n\n/**\n * Computes magnitude for the provided quaternion.\n *\n * @param {Quaternion} quaternion The quaternion to conjugate.\n * @returns {Number} The magnitude.\n */\nQuaternion.magnitude = function (quaternion) {\n return Math.sqrt(Quaternion.magnitudeSquared(quaternion));\n};\n\n/**\n * Computes the normalized form of the provided quaternion.\n *\n * @param {Quaternion} quaternion The quaternion to normalize.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.normalize = function (quaternion, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const inverseMagnitude = 1.0 / Quaternion.magnitude(quaternion);\n const x = quaternion.x * inverseMagnitude;\n const y = quaternion.y * inverseMagnitude;\n const z = quaternion.z * inverseMagnitude;\n const w = quaternion.w * inverseMagnitude;\n\n result.x = x;\n result.y = y;\n result.z = z;\n result.w = w;\n return result;\n};\n\n/**\n * Computes the inverse of the provided quaternion.\n *\n * @param {Quaternion} quaternion The quaternion to normalize.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.inverse = function (quaternion, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const magnitudeSquared = Quaternion.magnitudeSquared(quaternion);\n result = Quaternion.conjugate(quaternion, result);\n return Quaternion.multiplyByScalar(result, 1.0 / magnitudeSquared, result);\n};\n\n/**\n * Computes the componentwise sum of two quaternions.\n *\n * @param {Quaternion} left The first quaternion.\n * @param {Quaternion} right The second quaternion.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.add = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = left.x + right.x;\n result.y = left.y + right.y;\n result.z = left.z + right.z;\n result.w = left.w + right.w;\n return result;\n};\n\n/**\n * Computes the componentwise difference of two quaternions.\n *\n * @param {Quaternion} left The first quaternion.\n * @param {Quaternion} right The second quaternion.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.subtract = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = left.x - right.x;\n result.y = left.y - right.y;\n result.z = left.z - right.z;\n result.w = left.w - right.w;\n return result;\n};\n\n/**\n * Negates the provided quaternion.\n *\n * @param {Quaternion} quaternion The quaternion to be negated.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.negate = function (quaternion, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = -quaternion.x;\n result.y = -quaternion.y;\n result.z = -quaternion.z;\n result.w = -quaternion.w;\n return result;\n};\n\n/**\n * Computes the dot (scalar) product of two quaternions.\n *\n * @param {Quaternion} left The first quaternion.\n * @param {Quaternion} right The second quaternion.\n * @returns {Number} The dot product.\n */\nQuaternion.dot = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n return (\n left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w\n );\n};\n\n/**\n * Computes the product of two quaternions.\n *\n * @param {Quaternion} left The first quaternion.\n * @param {Quaternion} right The second quaternion.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.multiply = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const leftX = left.x;\n const leftY = left.y;\n const leftZ = left.z;\n const leftW = left.w;\n\n const rightX = right.x;\n const rightY = right.y;\n const rightZ = right.z;\n const rightW = right.w;\n\n const x = leftW * rightX + leftX * rightW + leftY * rightZ - leftZ * rightY;\n const y = leftW * rightY - leftX * rightZ + leftY * rightW + leftZ * rightX;\n const z = leftW * rightZ + leftX * rightY - leftY * rightX + leftZ * rightW;\n const w = leftW * rightW - leftX * rightX - leftY * rightY - leftZ * rightZ;\n\n result.x = x;\n result.y = y;\n result.z = z;\n result.w = w;\n return result;\n};\n\n/**\n * Multiplies the provided quaternion componentwise by the provided scalar.\n *\n * @param {Quaternion} quaternion The quaternion to be scaled.\n * @param {Number} scalar The scalar to multiply with.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.multiplyByScalar = function (quaternion, scalar, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n Check.typeOf.number(\"scalar\", scalar);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = quaternion.x * scalar;\n result.y = quaternion.y * scalar;\n result.z = quaternion.z * scalar;\n result.w = quaternion.w * scalar;\n return result;\n};\n\n/**\n * Divides the provided quaternion componentwise by the provided scalar.\n *\n * @param {Quaternion} quaternion The quaternion to be divided.\n * @param {Number} scalar The scalar to divide by.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.divideByScalar = function (quaternion, scalar, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n Check.typeOf.number(\"scalar\", scalar);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = quaternion.x / scalar;\n result.y = quaternion.y / scalar;\n result.z = quaternion.z / scalar;\n result.w = quaternion.w / scalar;\n return result;\n};\n\n/**\n * Computes the axis of rotation of the provided quaternion.\n *\n * @param {Quaternion} quaternion The quaternion to use.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n */\nQuaternion.computeAxis = function (quaternion, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const w = quaternion.w;\n if (Math.abs(w - 1.0) < CesiumMath.EPSILON6) {\n result.x = result.y = result.z = 0;\n return result;\n }\n\n const scalar = 1.0 / Math.sqrt(1.0 - w * w);\n\n result.x = quaternion.x * scalar;\n result.y = quaternion.y * scalar;\n result.z = quaternion.z * scalar;\n return result;\n};\n\n/**\n * Computes the angle of rotation of the provided quaternion.\n *\n * @param {Quaternion} quaternion The quaternion to use.\n * @returns {Number} The angle of rotation.\n */\nQuaternion.computeAngle = function (quaternion) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n //>>includeEnd('debug');\n\n if (Math.abs(quaternion.w - 1.0) < CesiumMath.EPSILON6) {\n return 0.0;\n }\n return 2.0 * Math.acos(quaternion.w);\n};\n\nlet lerpScratch = new Quaternion();\n/**\n * Computes the linear interpolation or extrapolation at t using the provided quaternions.\n *\n * @param {Quaternion} start The value corresponding to t at 0.0.\n * @param {Quaternion} end The value corresponding to t at 1.0.\n * @param {Number} t The point along t at which to interpolate.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.lerp = function (start, end, t, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"start\", start);\n Check.typeOf.object(\"end\", end);\n Check.typeOf.number(\"t\", t);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n lerpScratch = Quaternion.multiplyByScalar(end, t, lerpScratch);\n result = Quaternion.multiplyByScalar(start, 1.0 - t, result);\n return Quaternion.add(lerpScratch, result, result);\n};\n\nlet slerpEndNegated = new Quaternion();\nlet slerpScaledP = new Quaternion();\nlet slerpScaledR = new Quaternion();\n/**\n * Computes the spherical linear interpolation or extrapolation at t using the provided quaternions.\n *\n * @param {Quaternion} start The value corresponding to t at 0.0.\n * @param {Quaternion} end The value corresponding to t at 1.0.\n * @param {Number} t The point along t at which to interpolate.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n *\n * @see Quaternion#fastSlerp\n */\nQuaternion.slerp = function (start, end, t, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"start\", start);\n Check.typeOf.object(\"end\", end);\n Check.typeOf.number(\"t\", t);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n let dot = Quaternion.dot(start, end);\n\n // The angle between start must be acute. Since q and -q represent\n // the same rotation, negate q to get the acute angle.\n let r = end;\n if (dot < 0.0) {\n dot = -dot;\n r = slerpEndNegated = Quaternion.negate(end, slerpEndNegated);\n }\n\n // dot > 0, as the dot product approaches 1, the angle between the\n // quaternions vanishes. use linear interpolation.\n if (1.0 - dot < CesiumMath.EPSILON6) {\n return Quaternion.lerp(start, r, t, result);\n }\n\n const theta = Math.acos(dot);\n slerpScaledP = Quaternion.multiplyByScalar(\n start,\n Math.sin((1 - t) * theta),\n slerpScaledP\n );\n slerpScaledR = Quaternion.multiplyByScalar(\n r,\n Math.sin(t * theta),\n slerpScaledR\n );\n result = Quaternion.add(slerpScaledP, slerpScaledR, result);\n return Quaternion.multiplyByScalar(result, 1.0 / Math.sin(theta), result);\n};\n\n/**\n * The logarithmic quaternion function.\n *\n * @param {Quaternion} quaternion The unit quaternion.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n */\nQuaternion.log = function (quaternion, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const theta = CesiumMath.acosClamped(quaternion.w);\n let thetaOverSinTheta = 0.0;\n\n if (theta !== 0.0) {\n thetaOverSinTheta = theta / Math.sin(theta);\n }\n\n return Cartesian3.multiplyByScalar(quaternion, thetaOverSinTheta, result);\n};\n\n/**\n * The exponential quaternion function.\n *\n * @param {Cartesian3} cartesian The cartesian.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.exp = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const theta = Cartesian3.magnitude(cartesian);\n let sinThetaOverTheta = 0.0;\n\n if (theta !== 0.0) {\n sinThetaOverTheta = Math.sin(theta) / theta;\n }\n\n result.x = cartesian.x * sinThetaOverTheta;\n result.y = cartesian.y * sinThetaOverTheta;\n result.z = cartesian.z * sinThetaOverTheta;\n result.w = Math.cos(theta);\n\n return result;\n};\n\nconst squadScratchCartesian0 = new Cartesian3();\nconst squadScratchCartesian1 = new Cartesian3();\nconst squadScratchQuaternion0 = new Quaternion();\nconst squadScratchQuaternion1 = new Quaternion();\n\n/**\n * Computes an inner quadrangle point.\n *
This will compute quaternions that ensure a squad curve is C1.
\n *\n * @param {Quaternion} q0 The first quaternion.\n * @param {Quaternion} q1 The second quaternion.\n * @param {Quaternion} q2 The third quaternion.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n *\n * @see Quaternion#squad\n */\nQuaternion.computeInnerQuadrangle = function (q0, q1, q2, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"q0\", q0);\n Check.typeOf.object(\"q1\", q1);\n Check.typeOf.object(\"q2\", q2);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const qInv = Quaternion.conjugate(q1, squadScratchQuaternion0);\n Quaternion.multiply(qInv, q2, squadScratchQuaternion1);\n const cart0 = Quaternion.log(squadScratchQuaternion1, squadScratchCartesian0);\n\n Quaternion.multiply(qInv, q0, squadScratchQuaternion1);\n const cart1 = Quaternion.log(squadScratchQuaternion1, squadScratchCartesian1);\n\n Cartesian3.add(cart0, cart1, cart0);\n Cartesian3.multiplyByScalar(cart0, 0.25, cart0);\n Cartesian3.negate(cart0, cart0);\n Quaternion.exp(cart0, squadScratchQuaternion0);\n\n return Quaternion.multiply(q1, squadScratchQuaternion0, result);\n};\n\n/**\n * Computes the spherical quadrangle interpolation between quaternions.\n *\n * @param {Quaternion} q0 The first quaternion.\n * @param {Quaternion} q1 The second quaternion.\n * @param {Quaternion} s0 The first inner quadrangle.\n * @param {Quaternion} s1 The second inner quadrangle.\n * @param {Number} t The time in [0,1] used to interpolate.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n *\n *\n * @example\n * // 1. compute the squad interpolation between two quaternions on a curve\n * const s0 = Cesium.Quaternion.computeInnerQuadrangle(quaternions[i - 1], quaternions[i], quaternions[i + 1], new Cesium.Quaternion());\n * const s1 = Cesium.Quaternion.computeInnerQuadrangle(quaternions[i], quaternions[i + 1], quaternions[i + 2], new Cesium.Quaternion());\n * const q = Cesium.Quaternion.squad(quaternions[i], quaternions[i + 1], s0, s1, t, new Cesium.Quaternion());\n *\n * // 2. compute the squad interpolation as above but where the first quaternion is a end point.\n * const s1 = Cesium.Quaternion.computeInnerQuadrangle(quaternions[0], quaternions[1], quaternions[2], new Cesium.Quaternion());\n * const q = Cesium.Quaternion.squad(quaternions[0], quaternions[1], quaternions[0], s1, t, new Cesium.Quaternion());\n *\n * @see Quaternion#computeInnerQuadrangle\n */\nQuaternion.squad = function (q0, q1, s0, s1, t, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"q0\", q0);\n Check.typeOf.object(\"q1\", q1);\n Check.typeOf.object(\"s0\", s0);\n Check.typeOf.object(\"s1\", s1);\n Check.typeOf.number(\"t\", t);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const slerp0 = Quaternion.slerp(q0, q1, t, squadScratchQuaternion0);\n const slerp1 = Quaternion.slerp(s0, s1, t, squadScratchQuaternion1);\n return Quaternion.slerp(slerp0, slerp1, 2.0 * t * (1.0 - t), result);\n};\n\nconst fastSlerpScratchQuaternion = new Quaternion();\nconst opmu = 1.90110745351730037;\nconst u = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];\nconst v = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];\nconst bT = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];\nconst bD = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];\n\nfor (let i = 0; i < 7; ++i) {\n const s = i + 1.0;\n const t = 2.0 * s + 1.0;\n u[i] = 1.0 / (s * t);\n v[i] = s / t;\n}\n\nu[7] = opmu / (8.0 * 17.0);\nv[7] = (opmu * 8.0) / 17.0;\n\n/**\n * Computes the spherical linear interpolation or extrapolation at t using the provided quaternions.\n * This implementation is faster than {@link Quaternion#slerp}, but is only accurate up to 10-6.\n *\n * @param {Quaternion} start The value corresponding to t at 0.0.\n * @param {Quaternion} end The value corresponding to t at 1.0.\n * @param {Number} t The point along t at which to interpolate.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n *\n * @see Quaternion#slerp\n */\nQuaternion.fastSlerp = function (start, end, t, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"start\", start);\n Check.typeOf.object(\"end\", end);\n Check.typeOf.number(\"t\", t);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n let x = Quaternion.dot(start, end);\n\n let sign;\n if (x >= 0) {\n sign = 1.0;\n } else {\n sign = -1.0;\n x = -x;\n }\n\n const xm1 = x - 1.0;\n const d = 1.0 - t;\n const sqrT = t * t;\n const sqrD = d * d;\n\n for (let i = 7; i >= 0; --i) {\n bT[i] = (u[i] * sqrT - v[i]) * xm1;\n bD[i] = (u[i] * sqrD - v[i]) * xm1;\n }\n\n const cT =\n sign *\n t *\n (1.0 +\n bT[0] *\n (1.0 +\n bT[1] *\n (1.0 +\n bT[2] *\n (1.0 +\n bT[3] *\n (1.0 +\n bT[4] *\n (1.0 + bT[5] * (1.0 + bT[6] * (1.0 + bT[7]))))))));\n const cD =\n d *\n (1.0 +\n bD[0] *\n (1.0 +\n bD[1] *\n (1.0 +\n bD[2] *\n (1.0 +\n bD[3] *\n (1.0 +\n bD[4] *\n (1.0 + bD[5] * (1.0 + bD[6] * (1.0 + bD[7]))))))));\n\n const temp = Quaternion.multiplyByScalar(\n start,\n cD,\n fastSlerpScratchQuaternion\n );\n Quaternion.multiplyByScalar(end, cT, result);\n return Quaternion.add(temp, result, result);\n};\n\n/**\n * Computes the spherical quadrangle interpolation between quaternions.\n * An implementation that is faster than {@link Quaternion#squad}, but less accurate.\n *\n * @param {Quaternion} q0 The first quaternion.\n * @param {Quaternion} q1 The second quaternion.\n * @param {Quaternion} s0 The first inner quadrangle.\n * @param {Quaternion} s1 The second inner quadrangle.\n * @param {Number} t The time in [0,1] used to interpolate.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter or a new instance if none was provided.\n *\n * @see Quaternion#squad\n */\nQuaternion.fastSquad = function (q0, q1, s0, s1, t, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"q0\", q0);\n Check.typeOf.object(\"q1\", q1);\n Check.typeOf.object(\"s0\", s0);\n Check.typeOf.object(\"s1\", s1);\n Check.typeOf.number(\"t\", t);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const slerp0 = Quaternion.fastSlerp(q0, q1, t, squadScratchQuaternion0);\n const slerp1 = Quaternion.fastSlerp(s0, s1, t, squadScratchQuaternion1);\n return Quaternion.fastSlerp(slerp0, slerp1, 2.0 * t * (1.0 - t), result);\n};\n\n/**\n * Compares the provided quaternions componentwise and returns\n *true
if they are equal, false
otherwise.\n *\n * @param {Quaternion} [left] The first quaternion.\n * @param {Quaternion} [right] The second quaternion.\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\n */\nQuaternion.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left.x === right.x &&\n left.y === right.y &&\n left.z === right.z &&\n left.w === right.w)\n );\n};\n\n/**\n * Compares the provided quaternions componentwise and returns\n * true
if they are within the provided epsilon,\n * false
otherwise.\n *\n * @param {Quaternion} [left] The first quaternion.\n * @param {Quaternion} [right] The second quaternion.\n * @param {Number} [epsilon=0] The epsilon to use for equality testing.\n * @returns {Boolean} true
if left and right are within the provided epsilon, false
otherwise.\n */\nQuaternion.equalsEpsilon = function (left, right, epsilon) {\n epsilon = defaultValue(epsilon, 0);\n\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n Math.abs(left.x - right.x) <= epsilon &&\n Math.abs(left.y - right.y) <= epsilon &&\n Math.abs(left.z - right.z) <= epsilon &&\n Math.abs(left.w - right.w) <= epsilon)\n );\n};\n\n/**\n * An immutable Quaternion instance initialized to (0.0, 0.0, 0.0, 0.0).\n *\n * @type {Quaternion}\n * @constant\n */\nQuaternion.ZERO = Object.freeze(new Quaternion(0.0, 0.0, 0.0, 0.0));\n\n/**\n * An immutable Quaternion instance initialized to (0.0, 0.0, 0.0, 1.0).\n *\n * @type {Quaternion}\n * @constant\n */\nQuaternion.IDENTITY = Object.freeze(new Quaternion(0.0, 0.0, 0.0, 1.0));\n\n/**\n * Duplicates this Quaternion instance.\n *\n * @param {Quaternion} [result] The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.\n */\nQuaternion.prototype.clone = function (result) {\n return Quaternion.clone(this, result);\n};\n\n/**\n * Compares this and the provided quaternion componentwise and returns\n * true
if they are equal, false
otherwise.\n *\n * @param {Quaternion} [right] The right hand side quaternion.\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\n */\nQuaternion.prototype.equals = function (right) {\n return Quaternion.equals(this, right);\n};\n\n/**\n * Compares this and the provided quaternion componentwise and returns\n * true
if they are within the provided epsilon,\n * false
otherwise.\n *\n * @param {Quaternion} [right] The right hand side quaternion.\n * @param {Number} [epsilon=0] The epsilon to use for equality testing.\n * @returns {Boolean} true
if left and right are within the provided epsilon, false
otherwise.\n */\nQuaternion.prototype.equalsEpsilon = function (right, epsilon) {\n return Quaternion.equalsEpsilon(this, right, epsilon);\n};\n\n/**\n * Returns a string representing this quaternion in the format (x, y, z, w).\n *\n * @returns {String} A string representing this Quaternion.\n */\nQuaternion.prototype.toString = function () {\n return `(${this.x}, ${this.y}, ${this.z}, ${this.w})`;\n};\nexport default Quaternion;\n","import Check from \"./Check.js\";\n\n/**\n * Finds an item in a sorted array.\n *\n * @function\n * @param {Array} array The sorted array to search.\n * @param {*} itemToFind The item to find in the array.\n * @param {binarySearchComparator} comparator The function to use to compare the item to\n * elements in the array.\n * @returns {Number} The index of itemToFind
in the array, if it exists. If itemToFind
\n * does not exist, the return value is a negative number which is the bitwise complement (~)\n * of the index before which the itemToFind should be inserted in order to maintain the\n * sorted order of the array.\n *\n * @example\n * // Create a comparator function to search through an array of numbers.\n * function comparator(a, b) {\n * return a - b;\n * };\n * const numbers = [0, 2, 4, 6, 8];\n * const index = Cesium.binarySearch(numbers, 6, comparator); // 3\n */\nfunction binarySearch(array, itemToFind, comparator) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n Check.defined(\"itemToFind\", itemToFind);\n Check.defined(\"comparator\", comparator);\n //>>includeEnd('debug');\n\n let low = 0;\n let high = array.length - 1;\n let i;\n let comparison;\n\n while (low <= high) {\n i = ~~((low + high) / 2);\n comparison = comparator(array[i], itemToFind);\n if (comparison < 0) {\n low = i + 1;\n continue;\n }\n if (comparison > 0) {\n high = i - 1;\n continue;\n }\n return i;\n }\n return ~(high + 1);\n}\n\n/**\n * A function used to compare two items while performing a binary search.\n * @callback binarySearchComparator\n *\n * @param {*} a An item in the array.\n * @param {*} b The item being searched for.\n * @returns {Number} Returns a negative value if a
is less than b
,\n * a positive value if a
is greater than b
, or\n * 0 if a
is equal to b
.\n *\n * @example\n * function compareNumbers(a, b) {\n * return a - b;\n * }\n */\nexport default binarySearch;\n","/**\n * A set of Earth Orientation Parameters (EOP) sampled at a time.\n *\n * @alias EarthOrientationParametersSample\n * @constructor\n *\n * @param {Number} xPoleWander The pole wander about the X axis, in radians.\n * @param {Number} yPoleWander The pole wander about the Y axis, in radians.\n * @param {Number} xPoleOffset The offset to the Celestial Intermediate Pole (CIP) about the X axis, in radians.\n * @param {Number} yPoleOffset The offset to the Celestial Intermediate Pole (CIP) about the Y axis, in radians.\n * @param {Number} ut1MinusUtc The difference in time standards, UT1 - UTC, in seconds.\n *\n * @private\n */\nfunction EarthOrientationParametersSample(\n xPoleWander,\n yPoleWander,\n xPoleOffset,\n yPoleOffset,\n ut1MinusUtc\n) {\n /**\n * The pole wander about the X axis, in radians.\n * @type {Number}\n */\n this.xPoleWander = xPoleWander;\n\n /**\n * The pole wander about the Y axis, in radians.\n * @type {Number}\n */\n this.yPoleWander = yPoleWander;\n\n /**\n * The offset to the Celestial Intermediate Pole (CIP) about the X axis, in radians.\n * @type {Number}\n */\n this.xPoleOffset = xPoleOffset;\n\n /**\n * The offset to the Celestial Intermediate Pole (CIP) about the Y axis, in radians.\n * @type {Number}\n */\n this.yPoleOffset = yPoleOffset;\n\n /**\n * The difference in time standards, UT1 - UTC, in seconds.\n * @type {Number}\n */\n this.ut1MinusUtc = ut1MinusUtc;\n}\nexport default EarthOrientationParametersSample;\n","/**\n * Represents a Gregorian date in a more precise format than the JavaScript Date object.\n * In addition to submillisecond precision, this object can also represent leap seconds.\n * @alias GregorianDate\n * @constructor\n *\n * @param {Number} [year] The year as a whole number.\n * @param {Number} [month] The month as a whole number with range [1, 12].\n * @param {Number} [day] The day of the month as a whole number starting at 1.\n * @param {Number} [hour] The hour as a whole number with range [0, 23].\n * @param {Number} [minute] The minute of the hour as a whole number with range [0, 59].\n * @param {Number} [second] The second of the minute as a whole number with range [0, 60], with 60 representing a leap second.\n * @param {Number} [millisecond] The millisecond of the second as a floating point number with range [0.0, 1000.0).\n * @param {Boolean} [isLeapSecond] Whether this time is during a leap second.\n *\n * @see JulianDate#toGregorianDate\n */\nfunction GregorianDate(\n year,\n month,\n day,\n hour,\n minute,\n second,\n millisecond,\n isLeapSecond\n) {\n /**\n * Gets or sets the year as a whole number.\n * @type {Number}\n */\n this.year = year;\n /**\n * Gets or sets the month as a whole number with range [1, 12].\n * @type {Number}\n */\n this.month = month;\n /**\n * Gets or sets the day of the month as a whole number starting at 1.\n * @type {Number}\n */\n this.day = day;\n /**\n * Gets or sets the hour as a whole number with range [0, 23].\n * @type {Number}\n */\n this.hour = hour;\n /**\n * Gets or sets the minute of the hour as a whole number with range [0, 59].\n * @type {Number}\n */\n this.minute = minute;\n /**\n * Gets or sets the second of the minute as a whole number with range [0, 60], with 60 representing a leap second.\n * @type {Number}\n */\n this.second = second;\n /**\n * Gets or sets the millisecond of the second as a floating point number with range [0.0, 1000.0).\n * @type {Number}\n */\n this.millisecond = millisecond;\n /**\n * Gets or sets whether this time is during a leap second.\n * @type {Boolean}\n */\n this.isLeapSecond = isLeapSecond;\n}\nexport default GregorianDate;\n","import DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Determines if a given date is a leap year.\n *\n * @function isLeapYear\n *\n * @param {Number} year The year to be tested.\n * @returns {Boolean} True if year
is a leap year.\n *\n * @example\n * const leapYear = Cesium.isLeapYear(2000); // true\n */\nfunction isLeapYear(year) {\n //>>includeStart('debug', pragmas.debug);\n if (year === null || isNaN(year)) {\n throw new DeveloperError(\"year is required and must be a number.\");\n }\n //>>includeEnd('debug');\n\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n}\nexport default isLeapYear;\n","/**\n * Describes a single leap second, which is constructed from a {@link JulianDate} and a\n * numerical offset representing the number of seconds TAI is ahead of the UTC time standard.\n * @alias LeapSecond\n * @constructor\n *\n * @param {JulianDate} [date] A Julian date representing the time of the leap second.\n * @param {Number} [offset] The cumulative number of seconds that TAI is ahead of UTC at the provided date.\n */\nfunction LeapSecond(date, offset) {\n /**\n * Gets or sets the date at which this leap second occurs.\n * @type {JulianDate}\n */\n this.julianDate = date;\n\n /**\n * Gets or sets the cumulative number of seconds between the UTC and TAI time standards at the time\n * of this leap second.\n * @type {Number}\n */\n this.offset = offset;\n}\nexport default LeapSecond;\n","/**\n * Constants for time conversions like those done by {@link JulianDate}.\n *\n * @namespace TimeConstants\n *\n * @see JulianDate\n *\n * @private\n */\nconst TimeConstants = {\n /**\n * The number of seconds in one millisecond: 0.001
\n * @type {Number}\n * @constant\n */\n SECONDS_PER_MILLISECOND: 0.001,\n\n /**\n * The number of seconds in one minute: 60
.\n * @type {Number}\n * @constant\n */\n SECONDS_PER_MINUTE: 60.0,\n\n /**\n * The number of minutes in one hour: 60
.\n * @type {Number}\n * @constant\n */\n MINUTES_PER_HOUR: 60.0,\n\n /**\n * The number of hours in one day: 24
.\n * @type {Number}\n * @constant\n */\n HOURS_PER_DAY: 24.0,\n\n /**\n * The number of seconds in one hour: 3600
.\n * @type {Number}\n * @constant\n */\n SECONDS_PER_HOUR: 3600.0,\n\n /**\n * The number of minutes in one day: 1440
.\n * @type {Number}\n * @constant\n */\n MINUTES_PER_DAY: 1440.0,\n\n /**\n * The number of seconds in one day, ignoring leap seconds: 86400
.\n * @type {Number}\n * @constant\n */\n SECONDS_PER_DAY: 86400.0,\n\n /**\n * The number of days in one Julian century: 36525
.\n * @type {Number}\n * @constant\n */\n DAYS_PER_JULIAN_CENTURY: 36525.0,\n\n /**\n * One trillionth of a second.\n * @type {Number}\n * @constant\n */\n PICOSECOND: 0.000000001,\n\n /**\n * The number of days to subtract from a Julian date to determine the\n * modified Julian date, which gives the number of days since midnight\n * on November 17, 1858.\n * @type {Number}\n * @constant\n */\n MODIFIED_JULIAN_DATE_DIFFERENCE: 2400000.5,\n};\nexport default Object.freeze(TimeConstants);\n","/**\n * Provides the type of time standards which JulianDate can take as input.\n *\n * @enum {Number}\n *\n * @see JulianDate\n */\nconst TimeStandard = {\n /**\n * Represents the coordinated Universal Time (UTC) time standard.\n *\n * UTC is related to TAI according to the relationship\n * UTC = TAI - deltaT
where deltaT
is the number of leap\n * seconds which have been introduced as of the time in TAI.\n *\n * @type {Number}\n * @constant\n */\n UTC: 0,\n\n /**\n * Represents the International Atomic Time (TAI) time standard.\n * TAI is the principal time standard to which the other time standards are related.\n *\n * @type {Number}\n * @constant\n */\n TAI: 1,\n};\nexport default Object.freeze(TimeStandard);\n","import binarySearch from \"./binarySearch.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport GregorianDate from \"./GregorianDate.js\";\nimport isLeapYear from \"./isLeapYear.js\";\nimport LeapSecond from \"./LeapSecond.js\";\nimport TimeConstants from \"./TimeConstants.js\";\nimport TimeStandard from \"./TimeStandard.js\";\n\nconst gregorianDateScratch = new GregorianDate();\nconst daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\nconst daysInLeapFeburary = 29;\n\nfunction compareLeapSecondDates(leapSecond, dateToFind) {\n return JulianDate.compare(leapSecond.julianDate, dateToFind.julianDate);\n}\n\n// we don't really need a leap second instance, anything with a julianDate property will do\nconst binarySearchScratchLeapSecond = new LeapSecond();\n\nfunction convertUtcToTai(julianDate) {\n //Even though julianDate is in UTC, we'll treat it as TAI and\n //search the leap second table for it.\n binarySearchScratchLeapSecond.julianDate = julianDate;\n const leapSeconds = JulianDate.leapSeconds;\n let index = binarySearch(\n leapSeconds,\n binarySearchScratchLeapSecond,\n compareLeapSecondDates\n );\n\n if (index < 0) {\n index = ~index;\n }\n\n if (index >= leapSeconds.length) {\n index = leapSeconds.length - 1;\n }\n\n let offset = leapSeconds[index].offset;\n if (index > 0) {\n //Now we have the index of the closest leap second that comes on or after our UTC time.\n //However, if the difference between the UTC date being converted and the TAI\n //defined leap second is greater than the offset, we are off by one and need to use\n //the previous leap second.\n const difference = JulianDate.secondsDifference(\n leapSeconds[index].julianDate,\n julianDate\n );\n if (difference > offset) {\n index--;\n offset = leapSeconds[index].offset;\n }\n }\n\n JulianDate.addSeconds(julianDate, offset, julianDate);\n}\n\nfunction convertTaiToUtc(julianDate, result) {\n binarySearchScratchLeapSecond.julianDate = julianDate;\n const leapSeconds = JulianDate.leapSeconds;\n let index = binarySearch(\n leapSeconds,\n binarySearchScratchLeapSecond,\n compareLeapSecondDates\n );\n if (index < 0) {\n index = ~index;\n }\n\n //All times before our first leap second get the first offset.\n if (index === 0) {\n return JulianDate.addSeconds(julianDate, -leapSeconds[0].offset, result);\n }\n\n //All times after our leap second get the last offset.\n if (index >= leapSeconds.length) {\n return JulianDate.addSeconds(\n julianDate,\n -leapSeconds[index - 1].offset,\n result\n );\n }\n\n //Compute the difference between the found leap second and the time we are converting.\n const difference = JulianDate.secondsDifference(\n leapSeconds[index].julianDate,\n julianDate\n );\n\n if (difference === 0) {\n //The date is in our leap second table.\n return JulianDate.addSeconds(\n julianDate,\n -leapSeconds[index].offset,\n result\n );\n }\n\n if (difference <= 1.0) {\n //The requested date is during the moment of a leap second, then we cannot convert to UTC\n return undefined;\n }\n\n //The time is in between two leap seconds, index is the leap second after the date\n //we're converting, so we subtract one to get the correct LeapSecond instance.\n return JulianDate.addSeconds(\n julianDate,\n -leapSeconds[--index].offset,\n result\n );\n}\n\nfunction setComponents(wholeDays, secondsOfDay, julianDate) {\n const extraDays = (secondsOfDay / TimeConstants.SECONDS_PER_DAY) | 0;\n wholeDays += extraDays;\n secondsOfDay -= TimeConstants.SECONDS_PER_DAY * extraDays;\n\n if (secondsOfDay < 0) {\n wholeDays--;\n secondsOfDay += TimeConstants.SECONDS_PER_DAY;\n }\n\n julianDate.dayNumber = wholeDays;\n julianDate.secondsOfDay = secondsOfDay;\n return julianDate;\n}\n\nfunction computeJulianDateComponents(\n year,\n month,\n day,\n hour,\n minute,\n second,\n millisecond\n) {\n // Algorithm from page 604 of the Explanatory Supplement to the\n // Astronomical Almanac (Seidelmann 1992).\n\n const a = ((month - 14) / 12) | 0;\n const b = year + 4800 + a;\n let dayNumber =\n (((1461 * b) / 4) | 0) +\n (((367 * (month - 2 - 12 * a)) / 12) | 0) -\n (((3 * (((b + 100) / 100) | 0)) / 4) | 0) +\n day -\n 32075;\n\n // JulianDates are noon-based\n hour = hour - 12;\n if (hour < 0) {\n hour += 24;\n }\n\n const secondsOfDay =\n second +\n (hour * TimeConstants.SECONDS_PER_HOUR +\n minute * TimeConstants.SECONDS_PER_MINUTE +\n millisecond * TimeConstants.SECONDS_PER_MILLISECOND);\n\n if (secondsOfDay >= 43200.0) {\n dayNumber -= 1;\n }\n\n return [dayNumber, secondsOfDay];\n}\n\n//Regular expressions used for ISO8601 date parsing.\n//YYYY\nconst matchCalendarYear = /^(\\d{4})$/;\n//YYYY-MM (YYYYMM is invalid)\nconst matchCalendarMonth = /^(\\d{4})-(\\d{2})$/;\n//YYYY-DDD or YYYYDDD\nconst matchOrdinalDate = /^(\\d{4})-?(\\d{3})$/;\n//YYYY-Www or YYYYWww or YYYY-Www-D or YYYYWwwD\nconst matchWeekDate = /^(\\d{4})-?W(\\d{2})-?(\\d{1})?$/;\n//YYYY-MM-DD or YYYYMMDD\nconst matchCalendarDate = /^(\\d{4})-?(\\d{2})-?(\\d{2})$/;\n// Match utc offset\nconst utcOffset = /([Z+\\-])?(\\d{2})?:?(\\d{2})?$/;\n// Match hours HH or HH.xxxxx\nconst matchHours = /^(\\d{2})(\\.\\d+)?/.source + utcOffset.source;\n// Match hours/minutes HH:MM HHMM.xxxxx\nconst matchHoursMinutes = /^(\\d{2}):?(\\d{2})(\\.\\d+)?/.source + utcOffset.source;\n// Match hours/minutes HH:MM:SS HHMMSS.xxxxx\nconst matchHoursMinutesSeconds =\n /^(\\d{2}):?(\\d{2}):?(\\d{2})(\\.\\d+)?/.source + utcOffset.source;\n\nconst iso8601ErrorMessage = \"Invalid ISO 8601 date.\";\n\n/**\n * Represents an astronomical Julian date, which is the number of days since noon on January 1, -4712 (4713 BC).\n * For increased precision, this class stores the whole number part of the date and the seconds\n * part of the date in separate components. In order to be safe for arithmetic and represent\n * leap seconds, the date is always stored in the International Atomic Time standard\n * {@link TimeStandard.TAI}.\n * @alias JulianDate\n * @constructor\n *\n * @param {Number} [julianDayNumber=0.0] The Julian Day Number representing the number of whole days. Fractional days will also be handled correctly.\n * @param {Number} [secondsOfDay=0.0] The number of seconds into the current Julian Day Number. Fractional seconds, negative seconds and seconds greater than a day will be handled correctly.\n * @param {TimeStandard} [timeStandard=TimeStandard.UTC] The time standard in which the first two parameters are defined.\n */\nfunction JulianDate(julianDayNumber, secondsOfDay, timeStandard) {\n /**\n * Gets or sets the number of whole days.\n * @type {Number}\n */\n this.dayNumber = undefined;\n\n /**\n * Gets or sets the number of seconds into the current day.\n * @type {Number}\n */\n this.secondsOfDay = undefined;\n\n julianDayNumber = defaultValue(julianDayNumber, 0.0);\n secondsOfDay = defaultValue(secondsOfDay, 0.0);\n timeStandard = defaultValue(timeStandard, TimeStandard.UTC);\n\n //If julianDayNumber is fractional, make it an integer and add the number of seconds the fraction represented.\n const wholeDays = julianDayNumber | 0;\n secondsOfDay =\n secondsOfDay +\n (julianDayNumber - wholeDays) * TimeConstants.SECONDS_PER_DAY;\n\n setComponents(wholeDays, secondsOfDay, this);\n\n if (timeStandard === TimeStandard.UTC) {\n convertUtcToTai(this);\n }\n}\n\n/**\n * Creates a new instance from a GregorianDate.\n *\n * @param {GregorianDate} date A GregorianDate.\n * @param {JulianDate} [result] An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided.\n *\n * @exception {DeveloperError} date must be a valid GregorianDate.\n */\nJulianDate.fromGregorianDate = function (date, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!(date instanceof GregorianDate)) {\n throw new DeveloperError(\"date must be a valid GregorianDate.\");\n }\n //>>includeEnd('debug');\n\n const components = computeJulianDateComponents(\n date.year,\n date.month,\n date.day,\n date.hour,\n date.minute,\n date.second,\n date.millisecond\n );\n if (!defined(result)) {\n return new JulianDate(components[0], components[1], TimeStandard.UTC);\n }\n setComponents(components[0], components[1], result);\n convertUtcToTai(result);\n return result;\n};\n\n/**\n * Creates a new instance from a JavaScript Date.\n *\n * @param {Date} date A JavaScript Date.\n * @param {JulianDate} [result] An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided.\n *\n * @exception {DeveloperError} date must be a valid JavaScript Date.\n */\nJulianDate.fromDate = function (date, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!(date instanceof Date) || isNaN(date.getTime())) {\n throw new DeveloperError(\"date must be a valid JavaScript Date.\");\n }\n //>>includeEnd('debug');\n\n const components = computeJulianDateComponents(\n date.getUTCFullYear(),\n date.getUTCMonth() + 1,\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n date.getUTCSeconds(),\n date.getUTCMilliseconds()\n );\n if (!defined(result)) {\n return new JulianDate(components[0], components[1], TimeStandard.UTC);\n }\n setComponents(components[0], components[1], result);\n convertUtcToTai(result);\n return result;\n};\n\n/**\n * Creates a new instance from a from an {@link http://en.wikipedia.org/wiki/ISO_8601|ISO 8601} date.\n * This method is superior to Date.parse
because it will handle all valid formats defined by the ISO 8601\n * specification, including leap seconds and sub-millisecond times, which discarded by most JavaScript implementations.\n *\n * @param {String} iso8601String An ISO 8601 date.\n * @param {JulianDate} [result] An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided.\n *\n * @exception {DeveloperError} Invalid ISO 8601 date.\n */\nJulianDate.fromIso8601 = function (iso8601String, result) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof iso8601String !== \"string\") {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n //>>includeEnd('debug');\n\n //Comma and decimal point both indicate a fractional number according to ISO 8601,\n //start out by blanket replacing , with . which is the only valid such symbol in JS.\n iso8601String = iso8601String.replace(\",\", \".\");\n\n //Split the string into its date and time components, denoted by a mandatory T\n let tokens = iso8601String.split(\"T\");\n let year;\n let month = 1;\n let day = 1;\n let hour = 0;\n let minute = 0;\n let second = 0;\n let millisecond = 0;\n\n //Lacking a time is okay, but a missing date is illegal.\n const date = tokens[0];\n const time = tokens[1];\n let tmp;\n let inLeapYear;\n //>>includeStart('debug', pragmas.debug);\n if (!defined(date)) {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n\n let dashCount;\n //>>includeEnd('debug');\n\n //First match the date against possible regular expressions.\n tokens = date.match(matchCalendarDate);\n if (tokens !== null) {\n //>>includeStart('debug', pragmas.debug);\n dashCount = date.split(\"-\").length - 1;\n if (dashCount > 0 && dashCount !== 2) {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n //>>includeEnd('debug');\n year = +tokens[1];\n month = +tokens[2];\n day = +tokens[3];\n } else {\n tokens = date.match(matchCalendarMonth);\n if (tokens !== null) {\n year = +tokens[1];\n month = +tokens[2];\n } else {\n tokens = date.match(matchCalendarYear);\n if (tokens !== null) {\n year = +tokens[1];\n } else {\n //Not a year/month/day so it must be an ordinal date.\n let dayOfYear;\n tokens = date.match(matchOrdinalDate);\n if (tokens !== null) {\n year = +tokens[1];\n dayOfYear = +tokens[2];\n inLeapYear = isLeapYear(year);\n\n //This validation is only applicable for this format.\n //>>includeStart('debug', pragmas.debug);\n if (\n dayOfYear < 1 ||\n (inLeapYear && dayOfYear > 366) ||\n (!inLeapYear && dayOfYear > 365)\n ) {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n //>>includeEnd('debug')\n } else {\n tokens = date.match(matchWeekDate);\n if (tokens !== null) {\n //ISO week date to ordinal date from\n //http://en.wikipedia.org/w/index.php?title=ISO_week_date&oldid=474176775\n year = +tokens[1];\n const weekNumber = +tokens[2];\n const dayOfWeek = +tokens[3] || 0;\n\n //>>includeStart('debug', pragmas.debug);\n dashCount = date.split(\"-\").length - 1;\n if (\n dashCount > 0 &&\n ((!defined(tokens[3]) && dashCount !== 1) ||\n (defined(tokens[3]) && dashCount !== 2))\n ) {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n //>>includeEnd('debug')\n\n const january4 = new Date(Date.UTC(year, 0, 4));\n dayOfYear = weekNumber * 7 + dayOfWeek - january4.getUTCDay() - 3;\n } else {\n //None of our regular expressions succeeded in parsing the date properly.\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(iso8601ErrorMessage);\n //>>includeEnd('debug')\n }\n }\n //Split an ordinal date into month/day.\n tmp = new Date(Date.UTC(year, 0, 1));\n tmp.setUTCDate(dayOfYear);\n month = tmp.getUTCMonth() + 1;\n day = tmp.getUTCDate();\n }\n }\n }\n\n //Now that we have all of the date components, validate them to make sure nothing is out of range.\n inLeapYear = isLeapYear(year);\n //>>includeStart('debug', pragmas.debug);\n if (\n month < 1 ||\n month > 12 ||\n day < 1 ||\n ((month !== 2 || !inLeapYear) && day > daysInMonth[month - 1]) ||\n (inLeapYear && month === 2 && day > daysInLeapFeburary)\n ) {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n //>>includeEnd('debug')\n\n //Now move onto the time string, which is much simpler.\n //If no time is specified, it is considered the beginning of the day, UTC to match Javascript's implementation.\n let offsetIndex;\n if (defined(time)) {\n tokens = time.match(matchHoursMinutesSeconds);\n if (tokens !== null) {\n //>>includeStart('debug', pragmas.debug);\n dashCount = time.split(\":\").length - 1;\n if (dashCount > 0 && dashCount !== 2 && dashCount !== 3) {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n //>>includeEnd('debug')\n\n hour = +tokens[1];\n minute = +tokens[2];\n second = +tokens[3];\n millisecond = +(tokens[4] || 0) * 1000.0;\n offsetIndex = 5;\n } else {\n tokens = time.match(matchHoursMinutes);\n if (tokens !== null) {\n //>>includeStart('debug', pragmas.debug);\n dashCount = time.split(\":\").length - 1;\n if (dashCount > 2) {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n //>>includeEnd('debug')\n\n hour = +tokens[1];\n minute = +tokens[2];\n second = +(tokens[3] || 0) * 60.0;\n offsetIndex = 4;\n } else {\n tokens = time.match(matchHours);\n if (tokens !== null) {\n hour = +tokens[1];\n minute = +(tokens[2] || 0) * 60.0;\n offsetIndex = 3;\n } else {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(iso8601ErrorMessage);\n //>>includeEnd('debug')\n }\n }\n }\n\n //Validate that all values are in proper range. Minutes and hours have special cases at 60 and 24.\n //>>includeStart('debug', pragmas.debug);\n if (\n minute >= 60 ||\n second >= 61 ||\n hour > 24 ||\n (hour === 24 && (minute > 0 || second > 0 || millisecond > 0))\n ) {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n //>>includeEnd('debug');\n\n //Check the UTC offset value, if no value exists, use local time\n //a Z indicates UTC, + or - are offsets.\n const offset = tokens[offsetIndex];\n const offsetHours = +tokens[offsetIndex + 1];\n const offsetMinutes = +(tokens[offsetIndex + 2] || 0);\n switch (offset) {\n case \"+\":\n hour = hour - offsetHours;\n minute = minute - offsetMinutes;\n break;\n case \"-\":\n hour = hour + offsetHours;\n minute = minute + offsetMinutes;\n break;\n case \"Z\":\n break;\n default:\n minute =\n minute +\n new Date(\n Date.UTC(year, month - 1, day, hour, minute)\n ).getTimezoneOffset();\n break;\n }\n }\n\n //ISO8601 denotes a leap second by any time having a seconds component of 60 seconds.\n //If that's the case, we need to temporarily subtract a second in order to build a UTC date.\n //Then we add it back in after converting to TAI.\n const isLeapSecond = second === 60;\n if (isLeapSecond) {\n second--;\n }\n\n //Even if we successfully parsed the string into its components, after applying UTC offset or\n //special cases like 24:00:00 denoting midnight, we need to normalize the data appropriately.\n\n //milliseconds can never be greater than 1000, and seconds can't be above 60, so we start with minutes\n while (minute >= 60) {\n minute -= 60;\n hour++;\n }\n\n while (hour >= 24) {\n hour -= 24;\n day++;\n }\n\n tmp = inLeapYear && month === 2 ? daysInLeapFeburary : daysInMonth[month - 1];\n while (day > tmp) {\n day -= tmp;\n month++;\n\n if (month > 12) {\n month -= 12;\n year++;\n }\n\n tmp =\n inLeapYear && month === 2 ? daysInLeapFeburary : daysInMonth[month - 1];\n }\n\n //If UTC offset is at the beginning/end of the day, minutes can be negative.\n while (minute < 0) {\n minute += 60;\n hour--;\n }\n\n while (hour < 0) {\n hour += 24;\n day--;\n }\n\n while (day < 1) {\n month--;\n if (month < 1) {\n month += 12;\n year--;\n }\n\n tmp =\n inLeapYear && month === 2 ? daysInLeapFeburary : daysInMonth[month - 1];\n day += tmp;\n }\n\n //Now create the JulianDate components from the Gregorian date and actually create our instance.\n const components = computeJulianDateComponents(\n year,\n month,\n day,\n hour,\n minute,\n second,\n millisecond\n );\n\n if (!defined(result)) {\n result = new JulianDate(components[0], components[1], TimeStandard.UTC);\n } else {\n setComponents(components[0], components[1], result);\n convertUtcToTai(result);\n }\n\n //If we were on a leap second, add it back.\n if (isLeapSecond) {\n JulianDate.addSeconds(result, 1, result);\n }\n\n return result;\n};\n\n/**\n * Creates a new instance that represents the current system time.\n * This is equivalent to calling JulianDate.fromDate(new Date());
.\n *\n * @param {JulianDate} [result] An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided.\n */\nJulianDate.now = function (result) {\n return JulianDate.fromDate(new Date(), result);\n};\n\nconst toGregorianDateScratch = new JulianDate(0, 0, TimeStandard.TAI);\n\n/**\n * Creates a {@link GregorianDate} from the provided instance.\n *\n * @param {JulianDate} julianDate The date to be converted.\n * @param {GregorianDate} [result] An existing instance to use for the result.\n * @returns {GregorianDate} The modified result parameter or a new instance if none was provided.\n */\nJulianDate.toGregorianDate = function (julianDate, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(julianDate)) {\n throw new DeveloperError(\"julianDate is required.\");\n }\n //>>includeEnd('debug');\n\n let isLeapSecond = false;\n let thisUtc = convertTaiToUtc(julianDate, toGregorianDateScratch);\n if (!defined(thisUtc)) {\n //Conversion to UTC will fail if we are during a leap second.\n //If that's the case, subtract a second and convert again.\n //JavaScript doesn't support leap seconds, so this results in second 59 being repeated twice.\n JulianDate.addSeconds(julianDate, -1, toGregorianDateScratch);\n thisUtc = convertTaiToUtc(toGregorianDateScratch, toGregorianDateScratch);\n isLeapSecond = true;\n }\n\n let julianDayNumber = thisUtc.dayNumber;\n const secondsOfDay = thisUtc.secondsOfDay;\n\n if (secondsOfDay >= 43200.0) {\n julianDayNumber += 1;\n }\n\n // Algorithm from page 604 of the Explanatory Supplement to the\n // Astronomical Almanac (Seidelmann 1992).\n let L = (julianDayNumber + 68569) | 0;\n const N = ((4 * L) / 146097) | 0;\n L = (L - (((146097 * N + 3) / 4) | 0)) | 0;\n const I = ((4000 * (L + 1)) / 1461001) | 0;\n L = (L - (((1461 * I) / 4) | 0) + 31) | 0;\n const J = ((80 * L) / 2447) | 0;\n const day = (L - (((2447 * J) / 80) | 0)) | 0;\n L = (J / 11) | 0;\n const month = (J + 2 - 12 * L) | 0;\n const year = (100 * (N - 49) + I + L) | 0;\n\n let hour = (secondsOfDay / TimeConstants.SECONDS_PER_HOUR) | 0;\n let remainingSeconds = secondsOfDay - hour * TimeConstants.SECONDS_PER_HOUR;\n const minute = (remainingSeconds / TimeConstants.SECONDS_PER_MINUTE) | 0;\n remainingSeconds =\n remainingSeconds - minute * TimeConstants.SECONDS_PER_MINUTE;\n let second = remainingSeconds | 0;\n const millisecond =\n (remainingSeconds - second) / TimeConstants.SECONDS_PER_MILLISECOND;\n\n // JulianDates are noon-based\n hour += 12;\n if (hour > 23) {\n hour -= 24;\n }\n\n //If we were on a leap second, add it back.\n if (isLeapSecond) {\n second += 1;\n }\n\n if (!defined(result)) {\n return new GregorianDate(\n year,\n month,\n day,\n hour,\n minute,\n second,\n millisecond,\n isLeapSecond\n );\n }\n\n result.year = year;\n result.month = month;\n result.day = day;\n result.hour = hour;\n result.minute = minute;\n result.second = second;\n result.millisecond = millisecond;\n result.isLeapSecond = isLeapSecond;\n return result;\n};\n\n/**\n * Creates a JavaScript Date from the provided instance.\n * Since JavaScript dates are only accurate to the nearest millisecond and\n * cannot represent a leap second, consider using {@link JulianDate.toGregorianDate} instead.\n * If the provided JulianDate is during a leap second, the previous second is used.\n *\n * @param {JulianDate} julianDate The date to be converted.\n * @returns {Date} A new instance representing the provided date.\n */\nJulianDate.toDate = function (julianDate) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(julianDate)) {\n throw new DeveloperError(\"julianDate is required.\");\n }\n //>>includeEnd('debug');\n\n const gDate = JulianDate.toGregorianDate(julianDate, gregorianDateScratch);\n let second = gDate.second;\n if (gDate.isLeapSecond) {\n second -= 1;\n }\n return new Date(\n Date.UTC(\n gDate.year,\n gDate.month - 1,\n gDate.day,\n gDate.hour,\n gDate.minute,\n second,\n gDate.millisecond\n )\n );\n};\n\n/**\n * Creates an ISO8601 representation of the provided date.\n *\n * @param {JulianDate} julianDate The date to be converted.\n * @param {Number} [precision] The number of fractional digits used to represent the seconds component. By default, the most precise representation is used.\n * @returns {String} The ISO8601 representation of the provided date.\n */\nJulianDate.toIso8601 = function (julianDate, precision) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(julianDate)) {\n throw new DeveloperError(\"julianDate is required.\");\n }\n //>>includeEnd('debug');\n\n const gDate = JulianDate.toGregorianDate(julianDate, gregorianDateScratch);\n let year = gDate.year;\n let month = gDate.month;\n let day = gDate.day;\n let hour = gDate.hour;\n const minute = gDate.minute;\n const second = gDate.second;\n const millisecond = gDate.millisecond;\n\n // special case - Iso8601.MAXIMUM_VALUE produces a string which we can't parse unless we adjust.\n // 10000-01-01T00:00:00 is the same instant as 9999-12-31T24:00:00\n if (\n year === 10000 &&\n month === 1 &&\n day === 1 &&\n hour === 0 &&\n minute === 0 &&\n second === 0 &&\n millisecond === 0\n ) {\n year = 9999;\n month = 12;\n day = 31;\n hour = 24;\n }\n\n let millisecondStr;\n\n if (!defined(precision) && millisecond !== 0) {\n //Forces milliseconds into a number with at least 3 digits to whatever the default toString() precision is.\n millisecondStr = (millisecond * 0.01).toString().replace(\".\", \"\");\n return `${year.toString().padStart(4, \"0\")}-${month\n .toString()\n .padStart(2, \"0\")}-${day\n .toString()\n .padStart(2, \"0\")}T${hour\n .toString()\n .padStart(2, \"0\")}:${minute\n .toString()\n .padStart(2, \"0\")}:${second\n .toString()\n .padStart(2, \"0\")}.${millisecondStr}Z`;\n }\n\n //Precision is either 0 or milliseconds is 0 with undefined precision, in either case, leave off milliseconds entirely\n if (!defined(precision) || precision === 0) {\n return `${year.toString().padStart(4, \"0\")}-${month\n .toString()\n .padStart(2, \"0\")}-${day\n .toString()\n .padStart(2, \"0\")}T${hour\n .toString()\n .padStart(2, \"0\")}:${minute\n .toString()\n .padStart(2, \"0\")}:${second.toString().padStart(2, \"0\")}Z`;\n }\n\n //Forces milliseconds into a number with at least 3 digits to whatever the specified precision is.\n millisecondStr = (millisecond * 0.01)\n .toFixed(precision)\n .replace(\".\", \"\")\n .slice(0, precision);\n return `${year.toString().padStart(4, \"0\")}-${month\n .toString()\n .padStart(2, \"0\")}-${day\n .toString()\n .padStart(2, \"0\")}T${hour\n .toString()\n .padStart(2, \"0\")}:${minute\n .toString()\n .padStart(2, \"0\")}:${second\n .toString()\n .padStart(2, \"0\")}.${millisecondStr}Z`;\n};\n\n/**\n * Duplicates a JulianDate instance.\n *\n * @param {JulianDate} julianDate The date to duplicate.\n * @param {JulianDate} [result] An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided. Returns undefined if julianDate is undefined.\n */\nJulianDate.clone = function (julianDate, result) {\n if (!defined(julianDate)) {\n return undefined;\n }\n if (!defined(result)) {\n return new JulianDate(\n julianDate.dayNumber,\n julianDate.secondsOfDay,\n TimeStandard.TAI\n );\n }\n result.dayNumber = julianDate.dayNumber;\n result.secondsOfDay = julianDate.secondsOfDay;\n return result;\n};\n\n/**\n * Compares two instances.\n *\n * @param {JulianDate} left The first instance.\n * @param {JulianDate} right The second instance.\n * @returns {Number} A negative value if left is less than right, a positive value if left is greater than right, or zero if left and right are equal.\n */\nJulianDate.compare = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(left)) {\n throw new DeveloperError(\"left is required.\");\n }\n if (!defined(right)) {\n throw new DeveloperError(\"right is required.\");\n }\n //>>includeEnd('debug');\n\n const julianDayNumberDifference = left.dayNumber - right.dayNumber;\n if (julianDayNumberDifference !== 0) {\n return julianDayNumberDifference;\n }\n return left.secondsOfDay - right.secondsOfDay;\n};\n\n/**\n * Compares two instances and returns true
if they are equal, false
otherwise.\n *\n * @param {JulianDate} [left] The first instance.\n * @param {JulianDate} [right] The second instance.\n * @returns {Boolean} true
if the dates are equal; otherwise, false
.\n */\nJulianDate.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left.dayNumber === right.dayNumber &&\n left.secondsOfDay === right.secondsOfDay)\n );\n};\n\n/**\n * Compares two instances and returns true
if they are within epsilon
seconds of\n * each other. That is, in order for the dates to be considered equal (and for\n * this function to return true
), the absolute value of the difference between them, in\n * seconds, must be less than epsilon
.\n *\n * @param {JulianDate} [left] The first instance.\n * @param {JulianDate} [right] The second instance.\n * @param {Number} [epsilon=0] The maximum number of seconds that should separate the two instances.\n * @returns {Boolean} true
if the two dates are within epsilon
seconds of each other; otherwise false
.\n */\nJulianDate.equalsEpsilon = function (left, right, epsilon) {\n epsilon = defaultValue(epsilon, 0);\n\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n Math.abs(JulianDate.secondsDifference(left, right)) <= epsilon)\n );\n};\n\n/**\n * Computes the total number of whole and fractional days represented by the provided instance.\n *\n * @param {JulianDate} julianDate The date.\n * @returns {Number} The Julian date as single floating point number.\n */\nJulianDate.totalDays = function (julianDate) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(julianDate)) {\n throw new DeveloperError(\"julianDate is required.\");\n }\n //>>includeEnd('debug');\n return (\n julianDate.dayNumber +\n julianDate.secondsOfDay / TimeConstants.SECONDS_PER_DAY\n );\n};\n\n/**\n * Computes the difference in seconds between the provided instance.\n *\n * @param {JulianDate} left The first instance.\n * @param {JulianDate} right The second instance.\n * @returns {Number} The difference, in seconds, when subtracting right
from left
.\n */\nJulianDate.secondsDifference = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(left)) {\n throw new DeveloperError(\"left is required.\");\n }\n if (!defined(right)) {\n throw new DeveloperError(\"right is required.\");\n }\n //>>includeEnd('debug');\n\n const dayDifference =\n (left.dayNumber - right.dayNumber) * TimeConstants.SECONDS_PER_DAY;\n return dayDifference + (left.secondsOfDay - right.secondsOfDay);\n};\n\n/**\n * Computes the difference in days between the provided instance.\n *\n * @param {JulianDate} left The first instance.\n * @param {JulianDate} right The second instance.\n * @returns {Number} The difference, in days, when subtracting right
from left
.\n */\nJulianDate.daysDifference = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(left)) {\n throw new DeveloperError(\"left is required.\");\n }\n if (!defined(right)) {\n throw new DeveloperError(\"right is required.\");\n }\n //>>includeEnd('debug');\n\n const dayDifference = left.dayNumber - right.dayNumber;\n const secondDifference =\n (left.secondsOfDay - right.secondsOfDay) / TimeConstants.SECONDS_PER_DAY;\n return dayDifference + secondDifference;\n};\n\n/**\n * Computes the number of seconds the provided instance is ahead of UTC.\n *\n * @param {JulianDate} julianDate The date.\n * @returns {Number} The number of seconds the provided instance is ahead of UTC\n */\nJulianDate.computeTaiMinusUtc = function (julianDate) {\n binarySearchScratchLeapSecond.julianDate = julianDate;\n const leapSeconds = JulianDate.leapSeconds;\n let index = binarySearch(\n leapSeconds,\n binarySearchScratchLeapSecond,\n compareLeapSecondDates\n );\n if (index < 0) {\n index = ~index;\n --index;\n if (index < 0) {\n index = 0;\n }\n }\n return leapSeconds[index].offset;\n};\n\n/**\n * Adds the provided number of seconds to the provided date instance.\n *\n * @param {JulianDate} julianDate The date.\n * @param {Number} seconds The number of seconds to add or subtract.\n * @param {JulianDate} result An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter.\n */\nJulianDate.addSeconds = function (julianDate, seconds, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(julianDate)) {\n throw new DeveloperError(\"julianDate is required.\");\n }\n if (!defined(seconds)) {\n throw new DeveloperError(\"seconds is required.\");\n }\n if (!defined(result)) {\n throw new DeveloperError(\"result is required.\");\n }\n //>>includeEnd('debug');\n\n return setComponents(\n julianDate.dayNumber,\n julianDate.secondsOfDay + seconds,\n result\n );\n};\n\n/**\n * Adds the provided number of minutes to the provided date instance.\n *\n * @param {JulianDate} julianDate The date.\n * @param {Number} minutes The number of minutes to add or subtract.\n * @param {JulianDate} result An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter.\n */\nJulianDate.addMinutes = function (julianDate, minutes, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(julianDate)) {\n throw new DeveloperError(\"julianDate is required.\");\n }\n if (!defined(minutes)) {\n throw new DeveloperError(\"minutes is required.\");\n }\n if (!defined(result)) {\n throw new DeveloperError(\"result is required.\");\n }\n //>>includeEnd('debug');\n\n const newSecondsOfDay =\n julianDate.secondsOfDay + minutes * TimeConstants.SECONDS_PER_MINUTE;\n return setComponents(julianDate.dayNumber, newSecondsOfDay, result);\n};\n\n/**\n * Adds the provided number of hours to the provided date instance.\n *\n * @param {JulianDate} julianDate The date.\n * @param {Number} hours The number of hours to add or subtract.\n * @param {JulianDate} result An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter.\n */\nJulianDate.addHours = function (julianDate, hours, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(julianDate)) {\n throw new DeveloperError(\"julianDate is required.\");\n }\n if (!defined(hours)) {\n throw new DeveloperError(\"hours is required.\");\n }\n if (!defined(result)) {\n throw new DeveloperError(\"result is required.\");\n }\n //>>includeEnd('debug');\n\n const newSecondsOfDay =\n julianDate.secondsOfDay + hours * TimeConstants.SECONDS_PER_HOUR;\n return setComponents(julianDate.dayNumber, newSecondsOfDay, result);\n};\n\n/**\n * Adds the provided number of days to the provided date instance.\n *\n * @param {JulianDate} julianDate The date.\n * @param {Number} days The number of days to add or subtract.\n * @param {JulianDate} result An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter.\n */\nJulianDate.addDays = function (julianDate, days, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(julianDate)) {\n throw new DeveloperError(\"julianDate is required.\");\n }\n if (!defined(days)) {\n throw new DeveloperError(\"days is required.\");\n }\n if (!defined(result)) {\n throw new DeveloperError(\"result is required.\");\n }\n //>>includeEnd('debug');\n\n const newJulianDayNumber = julianDate.dayNumber + days;\n return setComponents(newJulianDayNumber, julianDate.secondsOfDay, result);\n};\n\n/**\n * Compares the provided instances and returns true
if left
is earlier than right
, false
otherwise.\n *\n * @param {JulianDate} left The first instance.\n * @param {JulianDate} right The second instance.\n * @returns {Boolean} true
if left
is earlier than right
, false
otherwise.\n */\nJulianDate.lessThan = function (left, right) {\n return JulianDate.compare(left, right) < 0;\n};\n\n/**\n * Compares the provided instances and returns true
if left
is earlier than or equal to right
, false
otherwise.\n *\n * @param {JulianDate} left The first instance.\n * @param {JulianDate} right The second instance.\n * @returns {Boolean} true
if left
is earlier than or equal to right
, false
otherwise.\n */\nJulianDate.lessThanOrEquals = function (left, right) {\n return JulianDate.compare(left, right) <= 0;\n};\n\n/**\n * Compares the provided instances and returns true
if left
is later than right
, false
otherwise.\n *\n * @param {JulianDate} left The first instance.\n * @param {JulianDate} right The second instance.\n * @returns {Boolean} true
if left
is later than right
, false
otherwise.\n */\nJulianDate.greaterThan = function (left, right) {\n return JulianDate.compare(left, right) > 0;\n};\n\n/**\n * Compares the provided instances and returns true
if left
is later than or equal to right
, false
otherwise.\n *\n * @param {JulianDate} left The first instance.\n * @param {JulianDate} right The second instance.\n * @returns {Boolean} true
if left
is later than or equal to right
, false
otherwise.\n */\nJulianDate.greaterThanOrEquals = function (left, right) {\n return JulianDate.compare(left, right) >= 0;\n};\n\n/**\n * Duplicates this instance.\n *\n * @param {JulianDate} [result] An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided.\n */\nJulianDate.prototype.clone = function (result) {\n return JulianDate.clone(this, result);\n};\n\n/**\n * Compares this and the provided instance and returns true
if they are equal, false
otherwise.\n *\n * @param {JulianDate} [right] The second instance.\n * @returns {Boolean} true
if the dates are equal; otherwise, false
.\n */\nJulianDate.prototype.equals = function (right) {\n return JulianDate.equals(this, right);\n};\n\n/**\n * Compares this and the provided instance and returns true
if they are within epsilon
seconds of\n * each other. That is, in order for the dates to be considered equal (and for\n * this function to return true
), the absolute value of the difference between them, in\n * seconds, must be less than epsilon
.\n *\n * @param {JulianDate} [right] The second instance.\n * @param {Number} [epsilon=0] The maximum number of seconds that should separate the two instances.\n * @returns {Boolean} true
if the two dates are within epsilon
seconds of each other; otherwise false
.\n */\nJulianDate.prototype.equalsEpsilon = function (right, epsilon) {\n return JulianDate.equalsEpsilon(this, right, epsilon);\n};\n\n/**\n * Creates a string representing this date in ISO8601 format.\n *\n * @returns {String} A string representing this date in ISO8601 format.\n */\nJulianDate.prototype.toString = function () {\n return JulianDate.toIso8601(this);\n};\n\n/**\n * Gets or sets the list of leap seconds used throughout Cesium.\n * @memberof JulianDate\n * @type {LeapSecond[]}\n */\nJulianDate.leapSeconds = [\n new LeapSecond(new JulianDate(2441317, 43210.0, TimeStandard.TAI), 10), // January 1, 1972 00:00:00 UTC\n new LeapSecond(new JulianDate(2441499, 43211.0, TimeStandard.TAI), 11), // July 1, 1972 00:00:00 UTC\n new LeapSecond(new JulianDate(2441683, 43212.0, TimeStandard.TAI), 12), // January 1, 1973 00:00:00 UTC\n new LeapSecond(new JulianDate(2442048, 43213.0, TimeStandard.TAI), 13), // January 1, 1974 00:00:00 UTC\n new LeapSecond(new JulianDate(2442413, 43214.0, TimeStandard.TAI), 14), // January 1, 1975 00:00:00 UTC\n new LeapSecond(new JulianDate(2442778, 43215.0, TimeStandard.TAI), 15), // January 1, 1976 00:00:00 UTC\n new LeapSecond(new JulianDate(2443144, 43216.0, TimeStandard.TAI), 16), // January 1, 1977 00:00:00 UTC\n new LeapSecond(new JulianDate(2443509, 43217.0, TimeStandard.TAI), 17), // January 1, 1978 00:00:00 UTC\n new LeapSecond(new JulianDate(2443874, 43218.0, TimeStandard.TAI), 18), // January 1, 1979 00:00:00 UTC\n new LeapSecond(new JulianDate(2444239, 43219.0, TimeStandard.TAI), 19), // January 1, 1980 00:00:00 UTC\n new LeapSecond(new JulianDate(2444786, 43220.0, TimeStandard.TAI), 20), // July 1, 1981 00:00:00 UTC\n new LeapSecond(new JulianDate(2445151, 43221.0, TimeStandard.TAI), 21), // July 1, 1982 00:00:00 UTC\n new LeapSecond(new JulianDate(2445516, 43222.0, TimeStandard.TAI), 22), // July 1, 1983 00:00:00 UTC\n new LeapSecond(new JulianDate(2446247, 43223.0, TimeStandard.TAI), 23), // July 1, 1985 00:00:00 UTC\n new LeapSecond(new JulianDate(2447161, 43224.0, TimeStandard.TAI), 24), // January 1, 1988 00:00:00 UTC\n new LeapSecond(new JulianDate(2447892, 43225.0, TimeStandard.TAI), 25), // January 1, 1990 00:00:00 UTC\n new LeapSecond(new JulianDate(2448257, 43226.0, TimeStandard.TAI), 26), // January 1, 1991 00:00:00 UTC\n new LeapSecond(new JulianDate(2448804, 43227.0, TimeStandard.TAI), 27), // July 1, 1992 00:00:00 UTC\n new LeapSecond(new JulianDate(2449169, 43228.0, TimeStandard.TAI), 28), // July 1, 1993 00:00:00 UTC\n new LeapSecond(new JulianDate(2449534, 43229.0, TimeStandard.TAI), 29), // July 1, 1994 00:00:00 UTC\n new LeapSecond(new JulianDate(2450083, 43230.0, TimeStandard.TAI), 30), // January 1, 1996 00:00:00 UTC\n new LeapSecond(new JulianDate(2450630, 43231.0, TimeStandard.TAI), 31), // July 1, 1997 00:00:00 UTC\n new LeapSecond(new JulianDate(2451179, 43232.0, TimeStandard.TAI), 32), // January 1, 1999 00:00:00 UTC\n new LeapSecond(new JulianDate(2453736, 43233.0, TimeStandard.TAI), 33), // January 1, 2006 00:00:00 UTC\n new LeapSecond(new JulianDate(2454832, 43234.0, TimeStandard.TAI), 34), // January 1, 2009 00:00:00 UTC\n new LeapSecond(new JulianDate(2456109, 43235.0, TimeStandard.TAI), 35), // July 1, 2012 00:00:00 UTC\n new LeapSecond(new JulianDate(2457204, 43236.0, TimeStandard.TAI), 36), // July 1, 2015 00:00:00 UTC\n new LeapSecond(new JulianDate(2457754, 43237.0, TimeStandard.TAI), 37), // January 1, 2017 00:00:00 UTC\n];\nexport default JulianDate;\n","/* This file is automatically rebuilt by the Cesium build process. */\nimport { c as createCommonjsModule, a as commonjsGlobal } from './_commonjsHelpers-3aae1032.js';\n\nvar punycode = createCommonjsModule(function (module, exports) {\n(function(root) {\n\n\t/** Detect free variables */\n\tvar freeExports = exports &&\n\t\t!exports.nodeType && exports;\n\tvar freeModule = module &&\n\t\t!module.nodeType && module;\n\tvar freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;\n\tif (\n\t\tfreeGlobal.global === freeGlobal ||\n\t\tfreeGlobal.window === freeGlobal ||\n\t\tfreeGlobal.self === freeGlobal\n\t) {\n\t\troot = freeGlobal;\n\t}\n\n\t/**\n\t * The `punycode` object.\n\t * @name punycode\n\t * @type Object\n\t */\n\tvar punycode,\n\n\t/** Highest positive signed 32-bit float value */\n\tmaxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1\n\n\t/** Bootstring parameters */\n\tbase = 36,\n\ttMin = 1,\n\ttMax = 26,\n\tskew = 38,\n\tdamp = 700,\n\tinitialBias = 72,\n\tinitialN = 128, // 0x80\n\tdelimiter = '-', // '\\x2D'\n\n\t/** Regular expressions */\n\tregexPunycode = /^xn--/,\n\tregexNonASCII = /[^\\x20-\\x7E]/, // unprintable ASCII chars + non-ASCII chars\n\tregexSeparators = /[\\x2E\\u3002\\uFF0E\\uFF61]/g, // RFC 3490 separators\n\n\t/** Error messages */\n\terrors = {\n\t\t'overflow': 'Overflow: input needs wider integers to process',\n\t\t'not-basic': 'Illegal input >= 0x80 (not a basic code point)',\n\t\t'invalid-input': 'Invalid input'\n\t},\n\n\t/** Convenience shortcuts */\n\tbaseMinusTMin = base - tMin,\n\tfloor = Math.floor,\n\tstringFromCharCode = String.fromCharCode,\n\n\t/** Temporary variable */\n\tkey;\n\n\t/*--------------------------------------------------------------------------*/\n\n\t/**\n\t * A generic error utility function.\n\t * @private\n\t * @param {String} type The error type.\n\t * @returns {Error} Throws a `RangeError` with the applicable error message.\n\t */\n\tfunction error(type) {\n\t\tthrow new RangeError(errors[type]);\n\t}\n\n\t/**\n\t * A generic `Array#map` utility function.\n\t * @private\n\t * @param {Array} array The array to iterate over.\n\t * @param {Function} callback The function that gets called for every array\n\t * item.\n\t * @returns {Array} A new array of values returned by the callback function.\n\t */\n\tfunction map(array, fn) {\n\t\tvar length = array.length;\n\t\tvar result = [];\n\t\twhile (length--) {\n\t\t\tresult[length] = fn(array[length]);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * A simple `Array#map`-like wrapper to work with domain name strings or email\n\t * addresses.\n\t * @private\n\t * @param {String} domain The domain name or email address.\n\t * @param {Function} callback The function that gets called for every\n\t * character.\n\t * @returns {Array} A new string of characters returned by the callback\n\t * function.\n\t */\n\tfunction mapDomain(string, fn) {\n\t\tvar parts = string.split('@');\n\t\tvar result = '';\n\t\tif (parts.length > 1) {\n\t\t\t// In email addresses, only the domain name should be punycoded. Leave\n\t\t\t// the local part (i.e. everything up to `@`) intact.\n\t\t\tresult = parts[0] + '@';\n\t\t\tstring = parts[1];\n\t\t}\n\t\t// Avoid `split(regex)` for IE8 compatibility. See #17.\n\t\tstring = string.replace(regexSeparators, '\\x2E');\n\t\tvar labels = string.split('.');\n\t\tvar encoded = map(labels, fn).join('.');\n\t\treturn result + encoded;\n\t}\n\n\t/**\n\t * Creates an array containing the numeric code points of each Unicode\n\t * character in the string. While JavaScript uses UCS-2 internally,\n\t * this function will convert a pair of surrogate halves (each of which\n\t * UCS-2 exposes as separate characters) into a single code point,\n\t * matching UTF-16.\n\t * @see `punycode.ucs2.encode`\n\t * @see true
is preferable for requests going through HTTP/1 servers.\n *\n * @type {Boolean}\n * @readonly\n *\n * @default false\n */\n this.throttleByServer = throttleByServer;\n\n /**\n * Type of request.\n *\n * @type {RequestType}\n * @readonly\n *\n * @default RequestType.OTHER\n */\n this.type = defaultValue(options.type, RequestType.OTHER);\n\n /**\n * A key used to identify the server that a request is going to. It is derived from the url's authority and scheme.\n *\n * @type {String}\n *\n * @private\n */\n this.serverKey = undefined;\n\n /**\n * The current state of the request.\n *\n * @type {RequestState}\n * @readonly\n */\n this.state = RequestState.UNISSUED;\n\n /**\n * The requests's deferred promise.\n *\n * @type {Object}\n *\n * @private\n */\n this.deferred = undefined;\n\n /**\n * Whether the request was explicitly cancelled.\n *\n * @type {Boolean}\n *\n * @private\n */\n this.cancelled = false;\n}\n\n/**\n * Mark the request as cancelled.\n *\n * @private\n */\nRequest.prototype.cancel = function () {\n this.cancelled = true;\n};\n\n/**\n * Duplicates a Request instance.\n *\n * @param {Request} [result] The object onto which to store the result.\n *\n * @returns {Request} The modified result parameter or a new Resource instance if one was not provided.\n */\nRequest.prototype.clone = function (result) {\n if (!defined(result)) {\n return new Request(this);\n }\n\n result.url = this.url;\n result.requestFunction = this.requestFunction;\n result.cancelFunction = this.cancelFunction;\n result.priorityFunction = this.priorityFunction;\n result.priority = this.priority;\n result.throttle = this.throttle;\n result.throttleByServer = this.throttleByServer;\n result.type = this.type;\n result.serverKey = this.serverKey;\n\n // These get defaulted because the cloned request hasn't been issued\n result.state = this.RequestState.UNISSUED;\n result.deferred = undefined;\n result.cancelled = false;\n\n return result;\n};\n\n/**\n * The function that makes the actual data request.\n * @callback Request.RequestCallback\n * @returns {Promisethis
pointer\n * in which the function will execute.\n *\n * @param {Function} listener The function to be executed when the event is raised.\n * @param {Object} [scope] An optional object scope to serve as the this
\n * pointer in which the listener function will execute.\n * @returns {Event.RemoveCallback} A function that will remove this event listener when invoked.\n *\n * @see Event#raiseEvent\n * @see Event#removeEventListener\n */\nEvent.prototype.addEventListener = function (listener, scope) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.func(\"listener\", listener);\n //>>includeEnd('debug');\n\n this._listeners.push(listener);\n this._scopes.push(scope);\n\n const event = this;\n return function () {\n event.removeEventListener(listener, scope);\n };\n};\n\n/**\n * Unregisters a previously registered callback.\n *\n * @param {Function} listener The function to be unregistered.\n * @param {Object} [scope] The scope that was originally passed to addEventListener.\n * @returns {Boolean} true
if the listener was removed; false
if the listener and scope are not registered with the event.\n *\n * @see Event#addEventListener\n * @see Event#raiseEvent\n */\nEvent.prototype.removeEventListener = function (listener, scope) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.func(\"listener\", listener);\n //>>includeEnd('debug');\n\n const listeners = this._listeners;\n const scopes = this._scopes;\n\n let index = -1;\n for (let i = 0; i < listeners.length; i++) {\n if (listeners[i] === listener && scopes[i] === scope) {\n index = i;\n break;\n }\n }\n\n if (index !== -1) {\n if (this._insideRaiseEvent) {\n //In order to allow removing an event subscription from within\n //a callback, we don't actually remove the items here. Instead\n //remember the index they are at and undefined their value.\n this._toRemove.push(index);\n listeners[index] = undefined;\n scopes[index] = undefined;\n } else {\n listeners.splice(index, 1);\n scopes.splice(index, 1);\n }\n return true;\n }\n\n return false;\n};\n\nfunction compareNumber(a, b) {\n return b - a;\n}\n\n/**\n * Raises the event by calling each registered listener with all supplied arguments.\n *\n * @param {...Object} arguments This method takes any number of parameters and passes them through to the listener functions.\n *\n * @see Event#addEventListener\n * @see Event#removeEventListener\n */\nEvent.prototype.raiseEvent = function () {\n this._insideRaiseEvent = true;\n\n let i;\n const listeners = this._listeners;\n const scopes = this._scopes;\n let length = listeners.length;\n\n for (i = 0; i < length; i++) {\n const listener = listeners[i];\n if (defined(listener)) {\n listeners[i].apply(scopes[i], arguments);\n }\n }\n\n //Actually remove items removed in removeEventListener.\n const toRemove = this._toRemove;\n length = toRemove.length;\n if (length > 0) {\n toRemove.sort(compareNumber);\n for (i = 0; i < length; i++) {\n const index = toRemove[i];\n listeners.splice(index, 1);\n scopes.splice(index, 1);\n }\n toRemove.length = 0;\n }\n\n this._insideRaiseEvent = false;\n};\n\n/**\n * A function that removes a listener.\n * @callback Event.RemoveCallback\n */\nexport default Event;\n","import Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\n\n/**\n * Array implementation of a heap.\n *\n * @alias Heap\n * @constructor\n * @private\n *\n * @param {Object} options Object with the following properties:\n * @param {Heap.ComparatorCallback} options.comparator The comparator to use for the heap. If comparator(a, b) is less than 0, sort a to a lower index than b, otherwise sort to a higher index.\n */\nfunction Heap(options) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options\", options);\n Check.defined(\"options.comparator\", options.comparator);\n //>>includeEnd('debug');\n\n this._comparator = options.comparator;\n this._array = [];\n this._length = 0;\n this._maximumLength = undefined;\n}\n\nObject.defineProperties(Heap.prototype, {\n /**\n * Gets the length of the heap.\n *\n * @memberof Heap.prototype\n *\n * @type {Number}\n * @readonly\n */\n length: {\n get: function () {\n return this._length;\n },\n },\n\n /**\n * Gets the internal array.\n *\n * @memberof Heap.prototype\n *\n * @type {Array}\n * @readonly\n */\n internalArray: {\n get: function () {\n return this._array;\n },\n },\n\n /**\n * Gets and sets the maximum length of the heap.\n *\n * @memberof Heap.prototype\n *\n * @type {Number}\n */\n maximumLength: {\n get: function () {\n return this._maximumLength;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"maximumLength\", value, 0);\n //>>includeEnd('debug');\n const originalLength = this._length;\n if (value < originalLength) {\n const array = this._array;\n // Remove trailing references\n for (let i = value; i < originalLength; ++i) {\n array[i] = undefined;\n }\n this._length = value;\n array.length = value;\n }\n this._maximumLength = value;\n },\n },\n\n /**\n * The comparator to use for the heap. If comparator(a, b) is less than 0, sort a to a lower index than b, otherwise sort to a higher index.\n *\n * @memberof Heap.prototype\n *\n * @type {Heap.ComparatorCallback}\n */\n comparator: {\n get: function () {\n return this._comparator;\n },\n },\n});\n\nfunction swap(array, a, b) {\n const temp = array[a];\n array[a] = array[b];\n array[b] = temp;\n}\n\n/**\n * Resizes the internal array of the heap.\n *\n * @param {Number} [length] The length to resize internal array to. Defaults to the current length of the heap.\n */\nHeap.prototype.reserve = function (length) {\n length = defaultValue(length, this._length);\n this._array.length = length;\n};\n\n/**\n * Update the heap so that index and all descendants satisfy the heap property.\n *\n * @param {Number} [index=0] The starting index to heapify from.\n */\nHeap.prototype.heapify = function (index) {\n index = defaultValue(index, 0);\n const length = this._length;\n const comparator = this._comparator;\n const array = this._array;\n let candidate = -1;\n let inserting = true;\n\n while (inserting) {\n const right = 2 * (index + 1);\n const left = right - 1;\n\n if (left < length && comparator(array[left], array[index]) < 0) {\n candidate = left;\n } else {\n candidate = index;\n }\n\n if (right < length && comparator(array[right], array[candidate]) < 0) {\n candidate = right;\n }\n if (candidate !== index) {\n swap(array, candidate, index);\n index = candidate;\n } else {\n inserting = false;\n }\n }\n};\n\n/**\n * Resort the heap.\n */\nHeap.prototype.resort = function () {\n const length = this._length;\n for (let i = Math.ceil(length / 2); i >= 0; --i) {\n this.heapify(i);\n }\n};\n\n/**\n * Insert an element into the heap. If the length would grow greater than maximumLength\n * of the heap, extra elements are removed.\n *\n * @param {*} element The element to insert\n *\n * @return {*} The element that was removed from the heap if the heap is at full capacity.\n */\nHeap.prototype.insert = function (element) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"element\", element);\n //>>includeEnd('debug');\n\n const array = this._array;\n const comparator = this._comparator;\n const maximumLength = this._maximumLength;\n\n let index = this._length++;\n if (index < array.length) {\n array[index] = element;\n } else {\n array.push(element);\n }\n\n while (index !== 0) {\n const parent = Math.floor((index - 1) / 2);\n if (comparator(array[index], array[parent]) < 0) {\n swap(array, index, parent);\n index = parent;\n } else {\n break;\n }\n }\n\n let removedElement;\n\n if (defined(maximumLength) && this._length > maximumLength) {\n removedElement = array[maximumLength];\n this._length = maximumLength;\n }\n\n return removedElement;\n};\n\n/**\n * Remove the element specified by index from the heap and return it.\n *\n * @param {Number} [index=0] The index to remove.\n * @returns {*} The specified element of the heap.\n */\nHeap.prototype.pop = function (index) {\n index = defaultValue(index, 0);\n if (this._length === 0) {\n return undefined;\n }\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.lessThan(\"index\", index, this._length);\n //>>includeEnd('debug');\n\n const array = this._array;\n const root = array[index];\n swap(array, index, --this._length);\n this.heapify(index);\n array[this._length] = undefined; // Remove trailing reference\n return root;\n};\n\n/**\n * The comparator to use for the heap.\n * @callback Heap.ComparatorCallback\n * @param {*} a An element in the heap.\n * @param {*} b An element in the heap.\n * @returns {Number} If the result of the comparison is less than 0, sort a to a lower index than b, otherwise sort to a higher index.\n */\nexport default Heap;\n","import Uri from \"../ThirdParty/Uri.js\";\nimport when from \"../ThirdParty/when.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Event from \"./Event.js\";\nimport Heap from \"./Heap.js\";\nimport isBlobUri from \"./isBlobUri.js\";\nimport isDataUri from \"./isDataUri.js\";\nimport RequestState from \"./RequestState.js\";\n\nfunction sortRequests(a, b) {\n return a.priority - b.priority;\n}\n\nconst statistics = {\n numberOfAttemptedRequests: 0,\n numberOfActiveRequests: 0,\n numberOfCancelledRequests: 0,\n numberOfCancelledActiveRequests: 0,\n numberOfFailedRequests: 0,\n numberOfActiveRequestsEver: 0,\n lastNumberOfActiveRequests: 0,\n};\n\nlet priorityHeapLength = 20;\nconst requestHeap = new Heap({\n comparator: sortRequests,\n});\nrequestHeap.maximumLength = priorityHeapLength;\nrequestHeap.reserve(priorityHeapLength);\n\nconst activeRequests = [];\nlet numberOfActiveRequestsByServer = {};\n\nconst pageUri =\n typeof document !== \"undefined\" ? new Uri(document.location.href) : new Uri();\n\nconst requestCompletedEvent = new Event();\n\n/**\n * The request scheduler is used to track and constrain the number of active requests in order to prioritize incoming requests. The ability\n * to retain control over the number of requests in CesiumJS is important because due to events such as changes in the camera position,\n * a lot of new requests may be generated and a lot of in-flight requests may become redundant. The request scheduler manually constrains the\n * number of requests so that newer requests wait in a shorter queue and don't have to compete for bandwidth with requests that have expired.\n *\n * @namespace RequestScheduler\n *\n */\nfunction RequestScheduler() {}\n\n/**\n * The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit.\n * @type {Number}\n * @default 50\n */\nRequestScheduler.maximumRequests = 50;\n\n/**\n * The maximum number of simultaneous active requests per server. Un-throttled requests or servers specifically\n * listed in {@link requestsByServer} do not observe this limit.\n * @type {Number}\n * @default 6\n */\nRequestScheduler.maximumRequestsPerServer = 6;\n\n/**\n * A per server key list of overrides to use for throttling instead of maximumRequestsPerServer
\n * @type {Object}\n *\n * @example\n * RequestScheduler.requestsByServer = {\n * 'api.cesium.com:443': 18,\n * 'assets.cesium.com:443': 18\n * };\n */\nRequestScheduler.requestsByServer = {\n \"api.cesium.com:443\": 18,\n \"assets.cesium.com:443\": 18,\n};\n\n/**\n * Specifies if the request scheduler should throttle incoming requests, or let the browser queue requests under its control.\n * @type {Boolean}\n * @default true\n */\nRequestScheduler.throttleRequests = true;\n\n/**\n * When true, log statistics to the console every frame\n * @type {Boolean}\n * @default false\n * @private\n */\nRequestScheduler.debugShowStatistics = false;\n\n/**\n * An event that's raised when a request is completed. Event handlers are passed\n * the error object if the request fails.\n *\n * @type {Event}\n * @default Event()\n * @private\n */\nRequestScheduler.requestCompletedEvent = requestCompletedEvent;\n\nObject.defineProperties(RequestScheduler, {\n /**\n * Returns the statistics used by the request scheduler.\n *\n * @memberof RequestScheduler\n *\n * @type Object\n * @readonly\n * @private\n */\n statistics: {\n get: function () {\n return statistics;\n },\n },\n\n /**\n * The maximum size of the priority heap. This limits the number of requests that are sorted by priority. Only applies to requests that are not yet active.\n *\n * @memberof RequestScheduler\n *\n * @type {Number}\n * @default 20\n * @private\n */\n priorityHeapLength: {\n get: function () {\n return priorityHeapLength;\n },\n set: function (value) {\n // If the new length shrinks the heap, need to cancel some of the requests.\n // Since this value is not intended to be tweaked regularly it is fine to just cancel the high priority requests.\n if (value < priorityHeapLength) {\n while (requestHeap.length > value) {\n const request = requestHeap.pop();\n cancelRequest(request);\n }\n }\n priorityHeapLength = value;\n requestHeap.maximumLength = value;\n requestHeap.reserve(value);\n },\n },\n});\n\nfunction updatePriority(request) {\n if (defined(request.priorityFunction)) {\n request.priority = request.priorityFunction();\n }\n}\n\n/**\n * Check if there are open slots for a particular server key. If desiredRequests is greater than 1, this checks if the queue has room for scheduling multiple requests.\n * @param {String} serverKey The server key returned by {@link RequestScheduler.getServerKey}.\n * @param {Number} [desiredRequests=1] How many requests the caller plans to request\n * @return {Boolean} True if there are enough open slots for desiredRequests
more requests.\n * @private\n */\nRequestScheduler.serverHasOpenSlots = function (serverKey, desiredRequests) {\n desiredRequests = defaultValue(desiredRequests, 1);\n\n const maxRequests = defaultValue(\n RequestScheduler.requestsByServer[serverKey],\n RequestScheduler.maximumRequestsPerServer\n );\n const hasOpenSlotsServer =\n numberOfActiveRequestsByServer[serverKey] + desiredRequests <= maxRequests;\n\n return hasOpenSlotsServer;\n};\n\n/**\n * Check if the priority heap has open slots, regardless of which server they\n * are from. This is used in {@link Multiple3DTileContent} for determining when\n * all requests can be scheduled\n * @param {Number} desiredRequests The number of requests the caller intends to make\n * @return {Boolean} true
if the heap has enough available slots to meet the desiredRequests. false
otherwise.\n *\n * @private\n */\nRequestScheduler.heapHasOpenSlots = function (desiredRequests) {\n const hasOpenSlotsHeap =\n requestHeap.length + desiredRequests <= priorityHeapLength;\n return hasOpenSlotsHeap;\n};\n\nfunction issueRequest(request) {\n if (request.state === RequestState.UNISSUED) {\n request.state = RequestState.ISSUED;\n request.deferred = when.defer();\n }\n return request.deferred.promise;\n}\n\nfunction getRequestReceivedFunction(request) {\n return function (results) {\n if (request.state === RequestState.CANCELLED) {\n // If the data request comes back but the request is cancelled, ignore it.\n return;\n }\n // explicitly set to undefined to ensure GC of request response data. See #8843\n const deferred = request.deferred;\n\n --statistics.numberOfActiveRequests;\n --numberOfActiveRequestsByServer[request.serverKey];\n requestCompletedEvent.raiseEvent();\n request.state = RequestState.RECEIVED;\n request.deferred = undefined;\n\n deferred.resolve(results);\n };\n}\n\nfunction getRequestFailedFunction(request) {\n return function (error) {\n if (request.state === RequestState.CANCELLED) {\n // If the data request comes back but the request is cancelled, ignore it.\n return;\n }\n ++statistics.numberOfFailedRequests;\n --statistics.numberOfActiveRequests;\n --numberOfActiveRequestsByServer[request.serverKey];\n requestCompletedEvent.raiseEvent(error);\n request.state = RequestState.FAILED;\n request.deferred.reject(error);\n };\n}\n\nfunction startRequest(request) {\n const promise = issueRequest(request);\n request.state = RequestState.ACTIVE;\n activeRequests.push(request);\n ++statistics.numberOfActiveRequests;\n ++statistics.numberOfActiveRequestsEver;\n ++numberOfActiveRequestsByServer[request.serverKey];\n request\n .requestFunction()\n .then(getRequestReceivedFunction(request))\n .otherwise(getRequestFailedFunction(request));\n return promise;\n}\n\nfunction cancelRequest(request) {\n const active = request.state === RequestState.ACTIVE;\n request.state = RequestState.CANCELLED;\n ++statistics.numberOfCancelledRequests;\n // check that deferred has not been cleared since cancelRequest can be called\n // on a finished request, e.g. by clearForSpecs during tests\n if (defined(request.deferred)) {\n const deferred = request.deferred;\n request.deferred = undefined;\n deferred.reject();\n }\n\n if (active) {\n --statistics.numberOfActiveRequests;\n --numberOfActiveRequestsByServer[request.serverKey];\n ++statistics.numberOfCancelledActiveRequests;\n }\n\n if (defined(request.cancelFunction)) {\n request.cancelFunction();\n }\n}\n\n/**\n * Sort requests by priority and start requests.\n * @private\n */\nRequestScheduler.update = function () {\n let i;\n let request;\n\n // Loop over all active requests. Cancelled, failed, or received requests are removed from the array to make room for new requests.\n let removeCount = 0;\n const activeLength = activeRequests.length;\n for (i = 0; i < activeLength; ++i) {\n request = activeRequests[i];\n if (request.cancelled) {\n // Request was explicitly cancelled\n cancelRequest(request);\n }\n if (request.state !== RequestState.ACTIVE) {\n // Request is no longer active, remove from array\n ++removeCount;\n continue;\n }\n if (removeCount > 0) {\n // Shift back to fill in vacated slots from completed requests\n activeRequests[i - removeCount] = request;\n }\n }\n activeRequests.length -= removeCount;\n\n // Update priority of issued requests and resort the heap\n const issuedRequests = requestHeap.internalArray;\n const issuedLength = requestHeap.length;\n for (i = 0; i < issuedLength; ++i) {\n updatePriority(issuedRequests[i]);\n }\n requestHeap.resort();\n\n // Get the number of open slots and fill with the highest priority requests.\n // Un-throttled requests are automatically added to activeRequests, so activeRequests.length may exceed maximumRequests\n const openSlots = Math.max(\n RequestScheduler.maximumRequests - activeRequests.length,\n 0\n );\n let filledSlots = 0;\n while (filledSlots < openSlots && requestHeap.length > 0) {\n // Loop until all open slots are filled or the heap becomes empty\n request = requestHeap.pop();\n if (request.cancelled) {\n // Request was explicitly cancelled\n cancelRequest(request);\n continue;\n }\n\n if (\n request.throttleByServer &&\n !RequestScheduler.serverHasOpenSlots(request.serverKey)\n ) {\n // Open slots are available, but the request is throttled by its server. Cancel and try again later.\n cancelRequest(request);\n continue;\n }\n\n startRequest(request);\n ++filledSlots;\n }\n\n updateStatistics();\n};\n\n/**\n * Get the server key from a given url.\n *\n * @param {String} url The url.\n * @returns {String} The server key.\n * @private\n */\nRequestScheduler.getServerKey = function (url) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"url\", url);\n //>>includeEnd('debug');\n\n let uri = new Uri(url);\n if (uri.scheme() === \"\") {\n uri = new Uri(url).absoluteTo(pageUri);\n uri.normalize();\n }\n\n let serverKey = uri.authority();\n if (!/:/.test(serverKey)) {\n // If the authority does not contain a port number, add port 443 for https or port 80 for http\n serverKey = `${serverKey}:${uri.scheme() === \"https\" ? \"443\" : \"80\"}`;\n }\n\n const length = numberOfActiveRequestsByServer[serverKey];\n if (!defined(length)) {\n numberOfActiveRequestsByServer[serverKey] = 0;\n }\n\n return serverKey;\n};\n\n/**\n * Issue a request. If request.throttle is false, the request is sent immediately. Otherwise the request will be\n * queued and sorted by priority before being sent.\n *\n * @param {Request} request The request object.\n *\n * @returns {Promise|undefined} A Promise for the requested data, or undefined if this request does not have high enough priority to be issued.\n *\n * @private\n */\nRequestScheduler.request = function (request) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"request\", request);\n Check.typeOf.string(\"request.url\", request.url);\n Check.typeOf.func(\"request.requestFunction\", request.requestFunction);\n //>>includeEnd('debug');\n\n if (isDataUri(request.url) || isBlobUri(request.url)) {\n requestCompletedEvent.raiseEvent();\n request.state = RequestState.RECEIVED;\n return request.requestFunction();\n }\n\n ++statistics.numberOfAttemptedRequests;\n\n if (!defined(request.serverKey)) {\n request.serverKey = RequestScheduler.getServerKey(request.url);\n }\n\n if (\n RequestScheduler.throttleRequests &&\n request.throttleByServer &&\n !RequestScheduler.serverHasOpenSlots(request.serverKey)\n ) {\n // Server is saturated. Try again later.\n return undefined;\n }\n\n if (!RequestScheduler.throttleRequests || !request.throttle) {\n return startRequest(request);\n }\n\n if (activeRequests.length >= RequestScheduler.maximumRequests) {\n // Active requests are saturated. Try again later.\n return undefined;\n }\n\n // Insert into the priority heap and see if a request was bumped off. If this request is the lowest\n // priority it will be returned.\n updatePriority(request);\n const removedRequest = requestHeap.insert(request);\n\n if (defined(removedRequest)) {\n if (removedRequest === request) {\n // Request does not have high enough priority to be issued\n return undefined;\n }\n // A previously issued request has been bumped off the priority heap, so cancel it\n cancelRequest(removedRequest);\n }\n\n return issueRequest(request);\n};\n\nfunction updateStatistics() {\n if (!RequestScheduler.debugShowStatistics) {\n return;\n }\n\n if (\n statistics.numberOfActiveRequests === 0 &&\n statistics.lastNumberOfActiveRequests > 0\n ) {\n if (statistics.numberOfAttemptedRequests > 0) {\n console.log(\n `Number of attempted requests: ${statistics.numberOfAttemptedRequests}`\n );\n statistics.numberOfAttemptedRequests = 0;\n }\n\n if (statistics.numberOfCancelledRequests > 0) {\n console.log(\n `Number of cancelled requests: ${statistics.numberOfCancelledRequests}`\n );\n statistics.numberOfCancelledRequests = 0;\n }\n\n if (statistics.numberOfCancelledActiveRequests > 0) {\n console.log(\n `Number of cancelled active requests: ${statistics.numberOfCancelledActiveRequests}`\n );\n statistics.numberOfCancelledActiveRequests = 0;\n }\n\n if (statistics.numberOfFailedRequests > 0) {\n console.log(\n `Number of failed requests: ${statistics.numberOfFailedRequests}`\n );\n statistics.numberOfFailedRequests = 0;\n }\n }\n\n statistics.lastNumberOfActiveRequests = statistics.numberOfActiveRequests;\n}\n\n/**\n * For testing only. Clears any requests that may not have completed from previous tests.\n *\n * @private\n */\nRequestScheduler.clearForSpecs = function () {\n while (requestHeap.length > 0) {\n const request = requestHeap.pop();\n cancelRequest(request);\n }\n const length = activeRequests.length;\n for (let i = 0; i < length; ++i) {\n cancelRequest(activeRequests[i]);\n }\n activeRequests.length = 0;\n numberOfActiveRequestsByServer = {};\n\n // Clear stats\n statistics.numberOfAttemptedRequests = 0;\n statistics.numberOfActiveRequests = 0;\n statistics.numberOfCancelledRequests = 0;\n statistics.numberOfCancelledActiveRequests = 0;\n statistics.numberOfFailedRequests = 0;\n statistics.numberOfActiveRequestsEver = 0;\n statistics.lastNumberOfActiveRequests = 0;\n};\n\n/**\n * For testing only.\n *\n * @private\n */\nRequestScheduler.numberOfActiveRequestsByServer = function (serverKey) {\n return numberOfActiveRequestsByServer[serverKey];\n};\n\n/**\n * For testing only.\n *\n * @private\n */\nRequestScheduler.requestHeap = requestHeap;\nexport default RequestScheduler;\n","import Uri from \"../ThirdParty/Uri.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * A singleton that contains all of the servers that are trusted. Credentials will be sent with\n * any requests to these servers.\n *\n * @namespace TrustedServers\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n */\nconst TrustedServers = {};\nlet _servers = {};\n\n/**\n * Adds a trusted server to the registry\n *\n * @param {String} host The host to be added.\n * @param {Number} port The port used to access the host.\n *\n * @example\n * // Add a trusted server\n * TrustedServers.add('my.server.com', 80);\n */\nTrustedServers.add = function (host, port) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(host)) {\n throw new DeveloperError(\"host is required.\");\n }\n if (!defined(port) || port <= 0) {\n throw new DeveloperError(\"port is required to be greater than 0.\");\n }\n //>>includeEnd('debug');\n\n const authority = `${host.toLowerCase()}:${port}`;\n if (!defined(_servers[authority])) {\n _servers[authority] = true;\n }\n};\n\n/**\n * Removes a trusted server from the registry\n *\n * @param {String} host The host to be removed.\n * @param {Number} port The port used to access the host.\n *\n * @example\n * // Remove a trusted server\n * TrustedServers.remove('my.server.com', 80);\n */\nTrustedServers.remove = function (host, port) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(host)) {\n throw new DeveloperError(\"host is required.\");\n }\n if (!defined(port) || port <= 0) {\n throw new DeveloperError(\"port is required to be greater than 0.\");\n }\n //>>includeEnd('debug');\n\n const authority = `${host.toLowerCase()}:${port}`;\n if (defined(_servers[authority])) {\n delete _servers[authority];\n }\n};\n\nfunction getAuthority(url) {\n const uri = new Uri(url);\n uri.normalize();\n\n // Removes username:password@ so we just have host[:port]\n let authority = uri.authority();\n if (authority.length === 0) {\n return undefined; // Relative URL\n }\n uri.authority(authority);\n\n if (authority.indexOf(\"@\") !== -1) {\n const parts = authority.split(\"@\");\n authority = parts[1];\n }\n\n // If the port is missing add one based on the scheme\n if (authority.indexOf(\":\") === -1) {\n let scheme = uri.scheme();\n if (scheme.length === 0) {\n scheme = window.location.protocol;\n scheme = scheme.substring(0, scheme.length - 1);\n }\n if (scheme === \"http\") {\n authority += \":80\";\n } else if (scheme === \"https\") {\n authority += \":443\";\n } else {\n return undefined;\n }\n }\n\n return authority;\n}\n\n/**\n * Tests whether a server is trusted or not. The server must have been added with the port if it is included in the url.\n *\n * @param {String} url The url to be tested against the trusted list\n *\n * @returns {boolean} Returns true if url is trusted, false otherwise.\n *\n * @example\n * // Add server\n * TrustedServers.add('my.server.com', 81);\n *\n * // Check if server is trusted\n * if (TrustedServers.contains('https://my.server.com:81/path/to/file.png')) {\n * // my.server.com:81 is trusted\n * }\n * if (TrustedServers.contains('https://my.server.com/path/to/file.png')) {\n * // my.server.com isn't trusted\n * }\n */\nTrustedServers.contains = function (url) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(url)) {\n throw new DeveloperError(\"url is required.\");\n }\n //>>includeEnd('debug');\n const authority = getAuthority(url);\n if (defined(authority) && defined(_servers[authority])) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Clears the registry\n *\n * @example\n * // Remove a trusted server\n * TrustedServers.clear();\n */\nTrustedServers.clear = function () {\n _servers = {};\n};\nexport default TrustedServers;\n","import Uri from \"../ThirdParty/Uri.js\";\nimport when from \"../ThirdParty/when.js\";\nimport appendForwardSlash from \"./appendForwardSlash.js\";\nimport Check from \"./Check.js\";\nimport clone from \"./clone.js\";\nimport combine from \"./combine.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport getAbsoluteUri from \"./getAbsoluteUri.js\";\nimport getBaseUri from \"./getBaseUri.js\";\nimport getExtensionFromUri from \"./getExtensionFromUri.js\";\nimport getImagePixels from \"./getImagePixels.js\";\nimport isBlobUri from \"./isBlobUri.js\";\nimport isCrossOriginUrl from \"./isCrossOriginUrl.js\";\nimport isDataUri from \"./isDataUri.js\";\nimport loadAndExecuteScript from \"./loadAndExecuteScript.js\";\nimport CesiumMath from \"./Math.js\";\nimport objectToQuery from \"./objectToQuery.js\";\nimport queryToObject from \"./queryToObject.js\";\nimport Request from \"./Request.js\";\nimport RequestErrorEvent from \"./RequestErrorEvent.js\";\nimport RequestScheduler from \"./RequestScheduler.js\";\nimport RequestState from \"./RequestState.js\";\nimport RuntimeError from \"./RuntimeError.js\";\nimport TrustedServers from \"./TrustedServers.js\";\n\nconst xhrBlobSupported = (function () {\n try {\n const xhr = new XMLHttpRequest();\n xhr.open(\"GET\", \"#\", true);\n xhr.responseType = \"blob\";\n return xhr.responseType === \"blob\";\n } catch (e) {\n return false;\n }\n})();\n\n/**\n * Parses a query string and returns the object equivalent.\n *\n * @param {Uri} uri The Uri with a query object.\n * @param {Resource} resource The Resource that will be assigned queryParameters.\n * @param {Boolean} merge If true, we'll merge with the resource's existing queryParameters. Otherwise they will be replaced.\n * @param {Boolean} preserveQueryParameters If true duplicate parameters will be concatenated into an array. If false, keys in uri will take precedence.\n *\n * @private\n */\nfunction parseQuery(uri, resource, merge, preserveQueryParameters) {\n const queryString = uri.query();\n if (queryString.length === 0) {\n return {};\n }\n\n let query;\n // Special case we run into where the querystring is just a string, not key/value pairs\n if (queryString.indexOf(\"=\") === -1) {\n const result = {};\n result[queryString] = undefined;\n query = result;\n } else {\n query = queryToObject(queryString);\n }\n\n if (merge) {\n resource._queryParameters = combineQueryParameters(\n query,\n resource._queryParameters,\n preserveQueryParameters\n );\n } else {\n resource._queryParameters = query;\n }\n uri.search(\"\");\n}\n\n/**\n * Converts a query object into a string.\n *\n * @param {Uri} uri The Uri object that will have the query object set.\n * @param {Resource} resource The resource that has queryParameters\n *\n * @private\n */\nfunction stringifyQuery(uri, resource) {\n const queryObject = resource._queryParameters;\n\n const keys = Object.keys(queryObject);\n\n // We have 1 key with an undefined value, so this is just a string, not key/value pairs\n if (keys.length === 1 && !defined(queryObject[keys[0]])) {\n uri.search(keys[0]);\n } else {\n uri.search(objectToQuery(queryObject));\n }\n}\n\n/**\n * Clones a value if it is defined, otherwise returns the default value\n *\n * @param {*} [val] The value to clone.\n * @param {*} [defaultVal] The default value.\n *\n * @returns {*} A clone of val or the defaultVal.\n *\n * @private\n */\nfunction defaultClone(val, defaultVal) {\n if (!defined(val)) {\n return defaultVal;\n }\n\n return defined(val.clone) ? val.clone() : clone(val);\n}\n\n/**\n * Checks to make sure the Resource isn't already being requested.\n *\n * @param {Request} request The request to check.\n *\n * @private\n */\nfunction checkAndResetRequest(request) {\n if (\n request.state === RequestState.ISSUED ||\n request.state === RequestState.ACTIVE\n ) {\n throw new RuntimeError(\"The Resource is already being fetched.\");\n }\n\n request.state = RequestState.UNISSUED;\n request.deferred = undefined;\n}\n\n/**\n * This combines a map of query parameters.\n *\n * @param {Object} q1 The first map of query parameters. Values in this map will take precedence if preserveQueryParameters is false.\n * @param {Object} q2 The second map of query parameters.\n * @param {Boolean} preserveQueryParameters If true duplicate parameters will be concatenated into an array. If false, keys in q1 will take precedence.\n *\n * @returns {Object} The combined map of query parameters.\n *\n * @example\n * const q1 = {\n * a: 1,\n * b: 2\n * };\n * const q2 = {\n * a: 3,\n * c: 4\n * };\n * const q3 = {\n * b: [5, 6],\n * d: 7\n * }\n *\n * // Returns\n * // {\n * // a: [1, 3],\n * // b: 2,\n * // c: 4\n * // };\n * combineQueryParameters(q1, q2, true);\n *\n * // Returns\n * // {\n * // a: 1,\n * // b: 2,\n * // c: 4\n * // };\n * combineQueryParameters(q1, q2, false);\n *\n * // Returns\n * // {\n * // a: 1,\n * // b: [2, 5, 6],\n * // d: 7\n * // };\n * combineQueryParameters(q1, q3, true);\n *\n * // Returns\n * // {\n * // a: 1,\n * // b: 2,\n * // d: 7\n * // };\n * combineQueryParameters(q1, q3, false);\n *\n * @private\n */\nfunction combineQueryParameters(q1, q2, preserveQueryParameters) {\n if (!preserveQueryParameters) {\n return combine(q1, q2);\n }\n\n const result = clone(q1, true);\n for (const param in q2) {\n if (q2.hasOwnProperty(param)) {\n let value = result[param];\n const q2Value = q2[param];\n if (defined(value)) {\n if (!Array.isArray(value)) {\n value = result[param] = [value];\n }\n\n result[param] = value.concat(q2Value);\n } else {\n result[param] = Array.isArray(q2Value) ? q2Value.slice() : q2Value;\n }\n }\n }\n\n return result;\n}\n\n/**\n * A resource that includes the location and any other parameters we need to retrieve it or create derived resources. It also provides the ability to retry requests.\n *\n * @alias Resource\n * @constructor\n *\n * @param {String|Object} options A url or an object with the following properties\n * @param {String} options.url The url of the resource.\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n *\n * @example\n * function refreshTokenRetryCallback(resource, error) {\n * if (error.statusCode === 403) {\n * // 403 status code means a new token should be generated\n * return getNewAccessToken()\n * .then(function(token) {\n * resource.queryParameters.access_token = token;\n * return true;\n * })\n * .otherwise(function() {\n * return false;\n * });\n * }\n *\n * return false;\n * }\n *\n * const resource = new Resource({\n * url: 'http://server.com/path/to/resource.json',\n * proxy: new DefaultProxy('/proxy/'),\n * headers: {\n * 'X-My-Header': 'valueOfHeader'\n * },\n * queryParameters: {\n * 'access_token': '123-435-456-000'\n * },\n * retryCallback: refreshTokenRetryCallback,\n * retryAttempts: 1\n * });\n */\nfunction Resource(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n if (typeof options === \"string\") {\n options = {\n url: options,\n };\n }\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"options.url\", options.url);\n //>>includeEnd('debug');\n\n this._url = undefined;\n this._templateValues = defaultClone(options.templateValues, {});\n this._queryParameters = defaultClone(options.queryParameters, {});\n\n /**\n * Additional HTTP headers that will be sent with the request.\n *\n * @type {Object}\n */\n this.headers = defaultClone(options.headers, {});\n\n /**\n * A Request object that will be used. Intended for internal use only.\n *\n * @type {Request}\n */\n this.request = defaultValue(options.request, new Request());\n\n /**\n * A proxy to be used when loading the resource.\n *\n * @type {Proxy}\n */\n this.proxy = options.proxy;\n\n /**\n * Function to call when a request for this resource fails. If it returns true or a Promise that resolves to true, the request will be retried.\n *\n * @type {Function}\n */\n this.retryCallback = options.retryCallback;\n\n /**\n * The number of times the retryCallback should be called before giving up.\n *\n * @type {Number}\n */\n this.retryAttempts = defaultValue(options.retryAttempts, 0);\n this._retryCount = 0;\n\n const uri = new Uri(options.url);\n parseQuery(uri, this, true, true);\n\n // Remove the fragment as it's not sent with a request\n uri.fragment(\"\");\n\n this._url = uri.toString();\n}\n\n/**\n * A helper function to create a resource depending on whether we have a String or a Resource\n *\n * @param {Resource|String} resource A Resource or a String to use when creating a new Resource.\n *\n * @returns {Resource} If resource is a String, a Resource constructed with the url and options. Otherwise the resource parameter is returned.\n *\n * @private\n */\nResource.createIfNeeded = function (resource) {\n if (resource instanceof Resource) {\n // Keep existing request object. This function is used internally to duplicate a Resource, so that it can't\n // be modified outside of a class that holds it (eg. an imagery or terrain provider). Since the Request objects\n // are managed outside of the providers, by the tile loading code, we want to keep the request property the same so if it is changed\n // in the underlying tiling code the requests for this resource will use it.\n return resource.getDerivedResource({\n request: resource.request,\n });\n }\n\n if (typeof resource !== \"string\") {\n return resource;\n }\n\n return new Resource({\n url: resource,\n });\n};\n\nlet supportsImageBitmapOptionsPromise;\n/**\n * A helper function to check whether createImageBitmap supports passing ImageBitmapOptions.\n *\n * @returns {Promiserequest.throttle
is true and the request does not have high enough priority.\n *\n * @example\n * // load a single URL asynchronously\n * resource.fetchArrayBuffer().then(function(arrayBuffer) {\n * // use the data\n * }).otherwise(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.fetchArrayBuffer = function () {\n return this.fetch({\n responseType: \"arraybuffer\",\n });\n};\n\n/**\n * Creates a Resource and calls fetchArrayBuffer() on it.\n *\n * @param {String|Object} options A url or an object with the following properties\n * @param {String} options.url The url of the resource.\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @returns {Promise.request.throttle
is true and the request does not have high enough priority.\n */\nResource.fetchArrayBuffer = function (options) {\n const resource = new Resource(options);\n return resource.fetchArrayBuffer();\n};\n\n/**\n * Asynchronously loads the given resource as a blob. Returns a promise that will resolve to\n * a Blob once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @returns {Promise.request.throttle
is true and the request does not have high enough priority.\n *\n * @example\n * // load a single URL asynchronously\n * resource.fetchBlob().then(function(blob) {\n * // use the data\n * }).otherwise(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.fetchBlob = function () {\n return this.fetch({\n responseType: \"blob\",\n });\n};\n\n/**\n * Creates a Resource and calls fetchBlob() on it.\n *\n * @param {String|Object} options A url or an object with the following properties\n * @param {String} options.url The url of the resource.\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @returns {Promise.request.throttle
is true and the request does not have high enough priority.\n */\nResource.fetchBlob = function (options) {\n const resource = new Resource(options);\n return resource.fetchBlob();\n};\n\n/**\n * Asynchronously loads the given image resource. Returns a promise that will resolve to\n * an {@link https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap|ImageBitmap} if preferImageBitmap
is true and the browser supports createImageBitmap
or otherwise an\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement|Image} once loaded, or reject if the image failed to load.\n *\n * @param {Object} [options] An object with the following properties.\n * @param {Boolean} [options.preferBlob=false] If true, we will load the image via a blob.\n * @param {Boolean} [options.preferImageBitmap=false] If true, image will be decoded during fetch and an ImageBitmap
is returned.\n * @param {Boolean} [options.flipY=false] If true, image will be vertically flipped during decode. Only applies if the browser supports createImageBitmap
.\n * @param {Boolean} [options.skipColorSpaceConversion=false] If true, any custom gamma or color profiles in the image will be ignored. Only applies if the browser supports createImageBitmap
.\n * @returns {Promise.request.throttle
is true and the request does not have high enough priority.\n *\n *\n * @example\n * // load a single image asynchronously\n * resource.fetchImage().then(function(image) {\n * // use the loaded image\n * }).otherwise(function(error) {\n * // an error occurred\n * });\n *\n * // load several images in parallel\n * when.all([resource1.fetchImage(), resource2.fetchImage()]).then(function(images) {\n * // images is an array containing all the loaded images\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.fetchImage = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const preferImageBitmap = defaultValue(options.preferImageBitmap, false);\n const preferBlob = defaultValue(options.preferBlob, false);\n const flipY = defaultValue(options.flipY, false);\n const skipColorSpaceConversion = defaultValue(\n options.skipColorSpaceConversion,\n false\n );\n\n checkAndResetRequest(this.request);\n // We try to load the image normally if\n // 1. Blobs aren't supported\n // 2. It's a data URI\n // 3. It's a blob URI\n // 4. It doesn't have request headers and we preferBlob is false\n if (\n !xhrBlobSupported ||\n this.isDataUri ||\n this.isBlobUri ||\n (!this.hasHeaders && !preferBlob)\n ) {\n return fetchImage({\n resource: this,\n flipY: flipY,\n skipColorSpaceConversion: skipColorSpaceConversion,\n preferImageBitmap: preferImageBitmap,\n });\n }\n\n const blobPromise = this.fetchBlob();\n if (!defined(blobPromise)) {\n return;\n }\n\n let supportsImageBitmap;\n let useImageBitmap;\n let generatedBlobResource;\n let generatedBlob;\n return Resource.supportsImageBitmapOptions()\n .then(function (result) {\n supportsImageBitmap = result;\n useImageBitmap = supportsImageBitmap && preferImageBitmap;\n return blobPromise;\n })\n .then(function (blob) {\n if (!defined(blob)) {\n return;\n }\n generatedBlob = blob;\n if (useImageBitmap) {\n return Resource.createImageBitmapFromBlob(blob, {\n flipY: flipY,\n premultiplyAlpha: false,\n skipColorSpaceConversion: skipColorSpaceConversion,\n });\n }\n const blobUrl = window.URL.createObjectURL(blob);\n generatedBlobResource = new Resource({\n url: blobUrl,\n });\n\n return fetchImage({\n resource: generatedBlobResource,\n flipY: flipY,\n skipColorSpaceConversion: skipColorSpaceConversion,\n preferImageBitmap: false,\n });\n })\n .then(function (image) {\n if (!defined(image)) {\n return;\n }\n\n // The blob object may be needed for use by a TileDiscardPolicy,\n // so attach it to the image.\n image.blob = generatedBlob;\n\n if (useImageBitmap) {\n return image;\n }\n\n window.URL.revokeObjectURL(generatedBlobResource.url);\n return image;\n })\n .otherwise(function (error) {\n if (defined(generatedBlobResource)) {\n window.URL.revokeObjectURL(generatedBlobResource.url);\n }\n\n // If the blob load succeeded but the image decode failed, attach the blob\n // to the error object for use by a TileDiscardPolicy.\n // In particular, BingMapsImageryProvider uses this to detect the\n // zero-length response that is returned when a tile is not available.\n error.blob = generatedBlob;\n\n return when.reject(error);\n });\n};\n\n/**\n * Fetches an image and returns a promise to it.\n *\n * @param {Object} [options] An object with the following properties.\n * @param {Resource} [options.resource] Resource object that points to an image to fetch.\n * @param {Boolean} [options.preferImageBitmap] If true, image will be decoded during fetch and an ImageBitmap
is returned.\n * @param {Boolean} [options.flipY] If true, image will be vertically flipped during decode. Only applies if the browser supports createImageBitmap
.\n * @param {Boolean} [options.skipColorSpaceConversion=false] If true, any custom gamma or color profiles in the image will be ignored. Only applies if the browser supports createImageBitmap
.\n * @private\n */\nfunction fetchImage(options) {\n const resource = options.resource;\n const flipY = options.flipY;\n const skipColorSpaceConversion = options.skipColorSpaceConversion;\n const preferImageBitmap = options.preferImageBitmap;\n\n const request = resource.request;\n request.url = resource.url;\n request.requestFunction = function () {\n let crossOrigin = false;\n\n // data URIs can't have crossorigin set.\n if (!resource.isDataUri && !resource.isBlobUri) {\n crossOrigin = resource.isCrossOriginUrl;\n }\n\n const deferred = when.defer();\n Resource._Implementations.createImage(\n request,\n crossOrigin,\n deferred,\n flipY,\n skipColorSpaceConversion,\n preferImageBitmap\n );\n\n return deferred.promise;\n };\n\n const promise = RequestScheduler.request(request);\n if (!defined(promise)) {\n return;\n }\n\n return promise.otherwise(function (e) {\n // Don't retry cancelled or otherwise aborted requests\n if (request.state !== RequestState.FAILED) {\n return when.reject(e);\n }\n return resource.retryOnError(e).then(function (retry) {\n if (retry) {\n // Reset request so it can try again\n request.state = RequestState.UNISSUED;\n request.deferred = undefined;\n\n return fetchImage({\n resource: resource,\n flipY: flipY,\n skipColorSpaceConversion: skipColorSpaceConversion,\n preferImageBitmap: preferImageBitmap,\n });\n }\n return when.reject(e);\n });\n });\n}\n\n/**\n * Creates a Resource and calls fetchImage() on it.\n *\n * @param {String|Object} options A url or an object with the following properties\n * @param {String} options.url The url of the resource.\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Boolean} [options.flipY=false] Whether to vertically flip the image during fetch and decode. Only applies when requesting an image and the browser supports createImageBitmap
.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {Boolean} [options.preferBlob=false] If true, we will load the image via a blob.\n * @param {Boolean} [options.preferImageBitmap=false] If true, image will be decoded during fetch and an ImageBitmap
is returned.\n * @param {Boolean} [options.skipColorSpaceConversion=false] If true, any custom gamma or color profiles in the image will be ignored. Only applies when requesting an image and the browser supports createImageBitmap
.\n * @returns {Promise.request.throttle
is true and the request does not have high enough priority.\n */\nResource.fetchImage = function (options) {\n const resource = new Resource(options);\n return resource.fetchImage({\n flipY: options.flipY,\n skipColorSpaceConversion: options.skipColorSpaceConversion,\n preferBlob: options.preferBlob,\n preferImageBitmap: options.preferImageBitmap,\n });\n};\n\n/**\n * Asynchronously loads the given resource as text. Returns a promise that will resolve to\n * a String once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @returns {Promise.request.throttle
is true and the request does not have high enough priority.\n *\n * @example\n * // load text from a URL, setting a custom header\n * const resource = new Resource({\n * url: 'http://someUrl.com/someJson.txt',\n * headers: {\n * 'X-Custom-Header' : 'some value'\n * }\n * });\n * resource.fetchText().then(function(text) {\n * // Do something with the text\n * }).otherwise(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest|XMLHttpRequest}\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.fetchText = function () {\n return this.fetch({\n responseType: \"text\",\n });\n};\n\n/**\n * Creates a Resource and calls fetchText() on it.\n *\n * @param {String|Object} options A url or an object with the following properties\n * @param {String} options.url The url of the resource.\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @returns {Promise.request.throttle
is true and the request does not have high enough priority.\n */\nResource.fetchText = function (options) {\n const resource = new Resource(options);\n return resource.fetchText();\n};\n\n// note: */* below is */* but that ends the comment block early\n/**\n * Asynchronously loads the given resource as JSON. Returns a promise that will resolve to\n * a JSON object once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled. This function\n * adds 'Accept: application/json,*/*;q=0.01' to the request headers, if not\n * already specified.\n *\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n *\n *\n * @example\n * resource.fetchJson().then(function(jsonData) {\n * // Do something with the JSON object\n * }).otherwise(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.fetchJson = function () {\n const promise = this.fetch({\n responseType: \"text\",\n headers: {\n Accept: \"application/json,*/*;q=0.01\",\n },\n });\n\n if (!defined(promise)) {\n return undefined;\n }\n\n return promise.then(function (value) {\n if (!defined(value)) {\n return;\n }\n return JSON.parse(value);\n });\n};\n\n/**\n * Creates a Resource and calls fetchJson() on it.\n *\n * @param {String|Object} options A url or an object with the following properties\n * @param {String} options.url The url of the resource.\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n */\nResource.fetchJson = function (options) {\n const resource = new Resource(options);\n return resource.fetchJson();\n};\n\n/**\n * Asynchronously loads the given resource as XML. Returns a promise that will resolve to\n * an XML Document once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @returns {Promise.request.throttle
is true and the request does not have high enough priority.\n *\n *\n * @example\n * // load XML from a URL, setting a custom header\n * Cesium.loadXML('http://someUrl.com/someXML.xml', {\n * 'X-Custom-Header' : 'some value'\n * }).then(function(document) {\n * // Do something with the document\n * }).otherwise(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest|XMLHttpRequest}\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.fetchXML = function () {\n return this.fetch({\n responseType: \"document\",\n overrideMimeType: \"text/xml\",\n });\n};\n\n/**\n * Creates a Resource and calls fetchXML() on it.\n *\n * @param {String|Object} options A url or an object with the following properties\n * @param {String} options.url The url of the resource.\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @returns {Promise.request.throttle
is true and the request does not have high enough priority.\n */\nResource.fetchXML = function (options) {\n const resource = new Resource(options);\n return resource.fetchXML();\n};\n\n/**\n * Requests a resource using JSONP.\n *\n * @param {String} [callbackParameterName='callback'] The callback parameter name that the server expects.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n *\n *\n * @example\n * // load a data asynchronously\n * resource.fetchJsonp().then(function(data) {\n * // use the loaded data\n * }).otherwise(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.fetchJsonp = function (callbackParameterName) {\n callbackParameterName = defaultValue(callbackParameterName, \"callback\");\n\n checkAndResetRequest(this.request);\n\n //generate a unique function name\n let functionName;\n do {\n functionName = `loadJsonp${CesiumMath.nextRandomNumber()\n .toString()\n .substring(2, 8)}`;\n } while (defined(window[functionName]));\n\n return fetchJsonp(this, callbackParameterName, functionName);\n};\n\nfunction fetchJsonp(resource, callbackParameterName, functionName) {\n const callbackQuery = {};\n callbackQuery[callbackParameterName] = functionName;\n resource.setQueryParameters(callbackQuery);\n\n const request = resource.request;\n request.url = resource.url;\n request.requestFunction = function () {\n const deferred = when.defer();\n\n //assign a function with that name in the global scope\n window[functionName] = function (data) {\n deferred.resolve(data);\n\n try {\n delete window[functionName];\n } catch (e) {\n window[functionName] = undefined;\n }\n };\n\n Resource._Implementations.loadAndExecuteScript(\n resource.url,\n functionName,\n deferred\n );\n return deferred.promise;\n };\n\n const promise = RequestScheduler.request(request);\n if (!defined(promise)) {\n return;\n }\n\n return promise.otherwise(function (e) {\n if (request.state !== RequestState.FAILED) {\n return when.reject(e);\n }\n\n return resource.retryOnError(e).then(function (retry) {\n if (retry) {\n // Reset request so it can try again\n request.state = RequestState.UNISSUED;\n request.deferred = undefined;\n\n return fetchJsonp(resource, callbackParameterName, functionName);\n }\n\n return when.reject(e);\n });\n });\n}\n\n/**\n * Creates a Resource from a URL and calls fetchJsonp() on it.\n *\n * @param {String|Object} options A url or an object with the following properties\n * @param {String} options.url The url of the resource.\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {String} [options.callbackParameterName='callback'] The callback parameter name that the server expects.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n */\nResource.fetchJsonp = function (options) {\n const resource = new Resource(options);\n return resource.fetchJsonp(options.callbackParameterName);\n};\n\n/**\n * @private\n */\nResource.prototype._makeRequest = function (options) {\n const resource = this;\n checkAndResetRequest(resource.request);\n\n const request = resource.request;\n request.url = resource.url;\n\n request.requestFunction = function () {\n const responseType = options.responseType;\n const headers = combine(options.headers, resource.headers);\n const overrideMimeType = options.overrideMimeType;\n const method = options.method;\n const data = options.data;\n const deferred = when.defer();\n const xhr = Resource._Implementations.loadWithXhr(\n resource.url,\n responseType,\n method,\n data,\n headers,\n deferred,\n overrideMimeType\n );\n if (defined(xhr) && defined(xhr.abort)) {\n request.cancelFunction = function () {\n xhr.abort();\n };\n }\n return deferred.promise;\n };\n\n const promise = RequestScheduler.request(request);\n if (!defined(promise)) {\n return;\n }\n\n return promise\n .then(function (data) {\n // explicitly set to undefined to ensure GC of request response data. See #8843\n request.cancelFunction = undefined;\n return data;\n })\n .otherwise(function (e) {\n request.cancelFunction = undefined;\n if (request.state !== RequestState.FAILED) {\n return when.reject(e);\n }\n\n return resource.retryOnError(e).then(function (retry) {\n if (retry) {\n // Reset request so it can try again\n request.state = RequestState.UNISSUED;\n request.deferred = undefined;\n\n return resource.fetch(options);\n }\n\n return when.reject(e);\n });\n });\n};\n\nconst dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;\n\nfunction decodeDataUriText(isBase64, data) {\n const result = decodeURIComponent(data);\n if (isBase64) {\n return atob(result);\n }\n return result;\n}\n\nfunction decodeDataUriArrayBuffer(isBase64, data) {\n const byteString = decodeDataUriText(isBase64, data);\n const buffer = new ArrayBuffer(byteString.length);\n const view = new Uint8Array(buffer);\n for (let i = 0; i < byteString.length; i++) {\n view[i] = byteString.charCodeAt(i);\n }\n return buffer;\n}\n\nfunction decodeDataUri(dataUriRegexResult, responseType) {\n responseType = defaultValue(responseType, \"\");\n const mimeType = dataUriRegexResult[1];\n const isBase64 = !!dataUriRegexResult[2];\n const data = dataUriRegexResult[3];\n let buffer;\n let parser;\n\n switch (responseType) {\n case \"\":\n case \"text\":\n return decodeDataUriText(isBase64, data);\n case \"arraybuffer\":\n return decodeDataUriArrayBuffer(isBase64, data);\n case \"blob\":\n buffer = decodeDataUriArrayBuffer(isBase64, data);\n return new Blob([buffer], {\n type: mimeType,\n });\n case \"document\":\n parser = new DOMParser();\n return parser.parseFromString(\n decodeDataUriText(isBase64, data),\n mimeType\n );\n case \"json\":\n return JSON.parse(decodeDataUriText(isBase64, data));\n default:\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(`Unhandled responseType: ${responseType}`);\n //>>includeEnd('debug');\n }\n}\n\n/**\n * Asynchronously loads the given resource. Returns a promise that will resolve to\n * the result once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled. It's recommended that you use\n * the more specific functions eg. fetchJson, fetchBlob, etc.\n *\n * @param {Object} [options] Object with the following properties:\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\n * @param {Object} [options.headers] Additional HTTP headers to send with the request, if any.\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n *\n *\n * @example\n * resource.fetch()\n * .then(function(body) {\n * // use the data\n * }).otherwise(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.fetch = function (options) {\n options = defaultClone(options, {});\n options.method = \"GET\";\n\n return this._makeRequest(options);\n};\n\n/**\n * Creates a Resource from a URL and calls fetch() on it.\n *\n * @param {String|Object} options A url or an object with the following properties\n * @param {String} options.url The url of the resource.\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n */\nResource.fetch = function (options) {\n const resource = new Resource(options);\n return resource.fetch({\n // Make copy of just the needed fields because headers can be passed to both the constructor and to fetch\n responseType: options.responseType,\n overrideMimeType: options.overrideMimeType,\n });\n};\n\n/**\n * Asynchronously deletes the given resource. Returns a promise that will resolve to\n * the result once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @param {Object} [options] Object with the following properties:\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\n * @param {Object} [options.headers] Additional HTTP headers to send with the request, if any.\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n *\n *\n * @example\n * resource.delete()\n * .then(function(body) {\n * // use the data\n * }).otherwise(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.delete = function (options) {\n options = defaultClone(options, {});\n options.method = \"DELETE\";\n\n return this._makeRequest(options);\n};\n\n/**\n * Creates a Resource from a URL and calls delete() on it.\n *\n * @param {String|Object} options A url or an object with the following properties\n * @param {String} options.url The url of the resource.\n * @param {Object} [options.data] Data that is posted with the resource.\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n */\nResource.delete = function (options) {\n const resource = new Resource(options);\n return resource.delete({\n // Make copy of just the needed fields because headers can be passed to both the constructor and to fetch\n responseType: options.responseType,\n overrideMimeType: options.overrideMimeType,\n data: options.data,\n });\n};\n\n/**\n * Asynchronously gets headers the given resource. Returns a promise that will resolve to\n * the result once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @param {Object} [options] Object with the following properties:\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\n * @param {Object} [options.headers] Additional HTTP headers to send with the request, if any.\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n *\n *\n * @example\n * resource.head()\n * .then(function(headers) {\n * // use the data\n * }).otherwise(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.head = function (options) {\n options = defaultClone(options, {});\n options.method = \"HEAD\";\n\n return this._makeRequest(options);\n};\n\n/**\n * Creates a Resource from a URL and calls head() on it.\n *\n * @param {String|Object} options A url or an object with the following properties\n * @param {String} options.url The url of the resource.\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n */\nResource.head = function (options) {\n const resource = new Resource(options);\n return resource.head({\n // Make copy of just the needed fields because headers can be passed to both the constructor and to fetch\n responseType: options.responseType,\n overrideMimeType: options.overrideMimeType,\n });\n};\n\n/**\n * Asynchronously gets options the given resource. Returns a promise that will resolve to\n * the result once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @param {Object} [options] Object with the following properties:\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\n * @param {Object} [options.headers] Additional HTTP headers to send with the request, if any.\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n *\n *\n * @example\n * resource.options()\n * .then(function(headers) {\n * // use the data\n * }).otherwise(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.options = function (options) {\n options = defaultClone(options, {});\n options.method = \"OPTIONS\";\n\n return this._makeRequest(options);\n};\n\n/**\n * Creates a Resource from a URL and calls options() on it.\n *\n * @param {String|Object} options A url or an object with the following properties\n * @param {String} options.url The url of the resource.\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n */\nResource.options = function (options) {\n const resource = new Resource(options);\n return resource.options({\n // Make copy of just the needed fields because headers can be passed to both the constructor and to fetch\n responseType: options.responseType,\n overrideMimeType: options.overrideMimeType,\n });\n};\n\n/**\n * Asynchronously posts data to the given resource. Returns a promise that will resolve to\n * the result once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @param {Object} data Data that is posted with the resource.\n * @param {Object} [options] Object with the following properties:\n * @param {Object} [options.data] Data that is posted with the resource.\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\n * @param {Object} [options.headers] Additional HTTP headers to send with the request, if any.\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n *\n *\n * @example\n * resource.post(data)\n * .then(function(result) {\n * // use the result\n * }).otherwise(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.post = function (data, options) {\n Check.defined(\"data\", data);\n\n options = defaultClone(options, {});\n options.method = \"POST\";\n options.data = data;\n\n return this._makeRequest(options);\n};\n\n/**\n * Creates a Resource from a URL and calls post() on it.\n *\n * @param {Object} options A url or an object with the following properties\n * @param {String} options.url The url of the resource.\n * @param {Object} options.data Data that is posted with the resource.\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n */\nResource.post = function (options) {\n const resource = new Resource(options);\n return resource.post(options.data, {\n // Make copy of just the needed fields because headers can be passed to both the constructor and to post\n responseType: options.responseType,\n overrideMimeType: options.overrideMimeType,\n });\n};\n\n/**\n * Asynchronously puts data to the given resource. Returns a promise that will resolve to\n * the result once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @param {Object} data Data that is posted with the resource.\n * @param {Object} [options] Object with the following properties:\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\n * @param {Object} [options.headers] Additional HTTP headers to send with the request, if any.\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n *\n *\n * @example\n * resource.put(data)\n * .then(function(result) {\n * // use the result\n * }).otherwise(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.put = function (data, options) {\n Check.defined(\"data\", data);\n\n options = defaultClone(options, {});\n options.method = \"PUT\";\n options.data = data;\n\n return this._makeRequest(options);\n};\n\n/**\n * Creates a Resource from a URL and calls put() on it.\n *\n * @param {Object} options A url or an object with the following properties\n * @param {String} options.url The url of the resource.\n * @param {Object} options.data Data that is posted with the resource.\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n */\nResource.put = function (options) {\n const resource = new Resource(options);\n return resource.put(options.data, {\n // Make copy of just the needed fields because headers can be passed to both the constructor and to post\n responseType: options.responseType,\n overrideMimeType: options.overrideMimeType,\n });\n};\n\n/**\n * Asynchronously patches data to the given resource. Returns a promise that will resolve to\n * the result once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @param {Object} data Data that is posted with the resource.\n * @param {Object} [options] Object with the following properties:\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\n * @param {Object} [options.headers] Additional HTTP headers to send with the request, if any.\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n *\n *\n * @example\n * resource.patch(data)\n * .then(function(result) {\n * // use the result\n * }).otherwise(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.patch = function (data, options) {\n Check.defined(\"data\", data);\n\n options = defaultClone(options, {});\n options.method = \"PATCH\";\n options.data = data;\n\n return this._makeRequest(options);\n};\n\n/**\n * Creates a Resource from a URL and calls patch() on it.\n *\n * @param {Object} options A url or an object with the following properties\n * @param {String} options.url The url of the resource.\n * @param {Object} options.data Data that is posted with the resource.\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise.<*>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle
is true and the request does not have high enough priority.\n */\nResource.patch = function (options) {\n const resource = new Resource(options);\n return resource.patch(options.data, {\n // Make copy of just the needed fields because headers can be passed to both the constructor and to post\n responseType: options.responseType,\n overrideMimeType: options.overrideMimeType,\n });\n};\n\n/**\n * Contains implementations of functions that can be replaced for testing\n *\n * @private\n */\nResource._Implementations = {};\n\nfunction loadImageElement(url, crossOrigin, deferred) {\n const image = new Image();\n\n image.onload = function () {\n deferred.resolve(image);\n };\n\n image.onerror = function (e) {\n deferred.reject(e);\n };\n\n if (crossOrigin) {\n if (TrustedServers.contains(url)) {\n image.crossOrigin = \"use-credentials\";\n } else {\n image.crossOrigin = \"\";\n }\n }\n\n image.src = url;\n}\n\nResource._Implementations.createImage = function (\n request,\n crossOrigin,\n deferred,\n flipY,\n skipColorSpaceConversion,\n preferImageBitmap\n) {\n const url = request.url;\n // Passing an Image to createImageBitmap will force it to run on the main thread\n // since DOM elements don't exist on workers. We convert it to a blob so it's non-blocking.\n // See:\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1044102#c38\n // https://bugs.chromium.org/p/chromium/issues/detail?id=580202#c10\n Resource.supportsImageBitmapOptions()\n .then(function (supportsImageBitmap) {\n // We can only use ImageBitmap if we can flip on decode.\n // See: https://github.com/CesiumGS/cesium/pull/7579#issuecomment-466146898\n if (!(supportsImageBitmap && preferImageBitmap)) {\n loadImageElement(url, crossOrigin, deferred);\n return;\n }\n const responseType = \"blob\";\n const method = \"GET\";\n const xhrDeferred = when.defer();\n const xhr = Resource._Implementations.loadWithXhr(\n url,\n responseType,\n method,\n undefined,\n undefined,\n xhrDeferred,\n undefined,\n undefined,\n undefined\n );\n\n if (defined(xhr) && defined(xhr.abort)) {\n request.cancelFunction = function () {\n xhr.abort();\n };\n }\n return xhrDeferred.promise\n .then(function (blob) {\n if (!defined(blob)) {\n deferred.reject(\n new RuntimeError(\n `Successfully retrieved ${url} but it contained no content.`\n )\n );\n return;\n }\n\n return Resource.createImageBitmapFromBlob(blob, {\n flipY: flipY,\n premultiplyAlpha: false,\n skipColorSpaceConversion: skipColorSpaceConversion,\n });\n })\n .then(deferred.resolve);\n })\n .otherwise(deferred.reject);\n};\n\n/**\n * Wrapper for createImageBitmap\n *\n * @private\n */\nResource.createImageBitmapFromBlob = function (blob, options) {\n Check.defined(\"options\", options);\n Check.typeOf.bool(\"options.flipY\", options.flipY);\n Check.typeOf.bool(\"options.premultiplyAlpha\", options.premultiplyAlpha);\n Check.typeOf.bool(\n \"options.skipColorSpaceConversion\",\n options.skipColorSpaceConversion\n );\n\n return createImageBitmap(blob, {\n imageOrientation: options.flipY ? \"flipY\" : \"none\",\n premultiplyAlpha: options.premultiplyAlpha ? \"premultiply\" : \"none\",\n colorSpaceConversion: options.skipColorSpaceConversion ? \"none\" : \"default\",\n });\n};\n\nfunction decodeResponse(loadWithHttpResponse, responseType) {\n switch (responseType) {\n case \"text\":\n return loadWithHttpResponse.toString(\"utf8\");\n case \"json\":\n return JSON.parse(loadWithHttpResponse.toString(\"utf8\"));\n default:\n return new Uint8Array(loadWithHttpResponse).buffer;\n }\n}\n\nfunction loadWithHttpRequest(\n url,\n responseType,\n method,\n data,\n headers,\n deferred,\n overrideMimeType\n) {\n // Note: only the 'json' and 'text' responseTypes transforms the loaded buffer\n /* eslint-disable no-undef */\n const URL = require(\"url\").parse(url);\n const http = URL.protocol === \"https:\" ? require(\"https\") : require(\"http\");\n const zlib = require(\"zlib\");\n /* eslint-enable no-undef */\n\n const options = {\n protocol: URL.protocol,\n hostname: URL.hostname,\n port: URL.port,\n path: URL.path,\n query: URL.query,\n method: method,\n headers: headers,\n };\n\n http\n .request(options)\n .on(\"response\", function (res) {\n if (res.statusCode < 200 || res.statusCode >= 300) {\n deferred.reject(\n new RequestErrorEvent(res.statusCode, res, res.headers)\n );\n return;\n }\n\n const chunkArray = [];\n res.on(\"data\", function (chunk) {\n chunkArray.push(chunk);\n });\n\n res.on(\"end\", function () {\n // eslint-disable-next-line no-undef\n const result = Buffer.concat(chunkArray);\n if (res.headers[\"content-encoding\"] === \"gzip\") {\n zlib.gunzip(result, function (error, resultUnzipped) {\n if (error) {\n deferred.reject(\n new RuntimeError(\"Error decompressing response.\")\n );\n } else {\n deferred.resolve(decodeResponse(resultUnzipped, responseType));\n }\n });\n } else {\n deferred.resolve(decodeResponse(result, responseType));\n }\n });\n })\n .on(\"error\", function (e) {\n deferred.reject(new RequestErrorEvent());\n })\n .end();\n}\n\nconst noXMLHttpRequest = typeof XMLHttpRequest === \"undefined\";\nResource._Implementations.loadWithXhr = function (\n url,\n responseType,\n method,\n data,\n headers,\n deferred,\n overrideMimeType\n) {\n const dataUriRegexResult = dataUriRegex.exec(url);\n if (dataUriRegexResult !== null) {\n deferred.resolve(decodeDataUri(dataUriRegexResult, responseType));\n return;\n }\n\n if (noXMLHttpRequest) {\n loadWithHttpRequest(\n url,\n responseType,\n method,\n data,\n headers,\n deferred,\n overrideMimeType\n );\n return;\n }\n\n const xhr = new XMLHttpRequest();\n\n if (TrustedServers.contains(url)) {\n xhr.withCredentials = true;\n }\n\n xhr.open(method, url, true);\n\n if (defined(overrideMimeType) && defined(xhr.overrideMimeType)) {\n xhr.overrideMimeType(overrideMimeType);\n }\n\n if (defined(headers)) {\n for (const key in headers) {\n if (headers.hasOwnProperty(key)) {\n xhr.setRequestHeader(key, headers[key]);\n }\n }\n }\n\n if (defined(responseType)) {\n xhr.responseType = responseType;\n }\n\n // While non-standard, file protocol always returns a status of 0 on success\n let localFile = false;\n if (typeof url === \"string\") {\n localFile =\n url.indexOf(\"file://\") === 0 ||\n (typeof window !== \"undefined\" && window.location.origin === \"file://\");\n }\n\n xhr.onload = function () {\n if (\n (xhr.status < 200 || xhr.status >= 300) &&\n !(localFile && xhr.status === 0)\n ) {\n deferred.reject(\n new RequestErrorEvent(\n xhr.status,\n xhr.response,\n xhr.getAllResponseHeaders()\n )\n );\n return;\n }\n\n const response = xhr.response;\n const browserResponseType = xhr.responseType;\n\n if (method === \"HEAD\" || method === \"OPTIONS\") {\n const responseHeaderString = xhr.getAllResponseHeaders();\n const splitHeaders = responseHeaderString.trim().split(/[\\r\\n]+/);\n\n const responseHeaders = {};\n splitHeaders.forEach(function (line) {\n const parts = line.split(\": \");\n const header = parts.shift();\n responseHeaders[header] = parts.join(\": \");\n });\n\n deferred.resolve(responseHeaders);\n return;\n }\n\n //All modern browsers will go into either the first or second if block or last else block.\n //Other code paths support older browsers that either do not support the supplied responseType\n //or do not support the xhr.response property.\n if (xhr.status === 204) {\n // accept no content\n deferred.resolve();\n } else if (\n defined(response) &&\n (!defined(responseType) || browserResponseType === responseType)\n ) {\n deferred.resolve(response);\n } else if (responseType === \"json\" && typeof response === \"string\") {\n try {\n deferred.resolve(JSON.parse(response));\n } catch (e) {\n deferred.reject(e);\n }\n } else if (\n (browserResponseType === \"\" || browserResponseType === \"document\") &&\n defined(xhr.responseXML) &&\n xhr.responseXML.hasChildNodes()\n ) {\n deferred.resolve(xhr.responseXML);\n } else if (\n (browserResponseType === \"\" || browserResponseType === \"text\") &&\n defined(xhr.responseText)\n ) {\n deferred.resolve(xhr.responseText);\n } else {\n deferred.reject(\n new RuntimeError(\"Invalid XMLHttpRequest response type.\")\n );\n }\n };\n\n xhr.onerror = function (e) {\n deferred.reject(new RequestErrorEvent());\n };\n\n xhr.send(data);\n\n return xhr;\n};\n\nResource._Implementations.loadAndExecuteScript = function (\n url,\n functionName,\n deferred\n) {\n return loadAndExecuteScript(url, functionName).otherwise(deferred.reject);\n};\n\n/**\n * The default implementations\n *\n * @private\n */\nResource._DefaultImplementations = {};\nResource._DefaultImplementations.createImage =\n Resource._Implementations.createImage;\nResource._DefaultImplementations.loadWithXhr =\n Resource._Implementations.loadWithXhr;\nResource._DefaultImplementations.loadAndExecuteScript =\n Resource._Implementations.loadAndExecuteScript;\n\n/**\n * A resource instance initialized to the current browser location\n *\n * @type {Resource}\n * @constant\n */\nResource.DEFAULT = Object.freeze(\n new Resource({\n url:\n typeof document === \"undefined\"\n ? \"\"\n : document.location.href.split(\"?\")[0],\n })\n);\n\n/**\n * A function that returns the value of the property.\n * @callback Resource.RetryCallback\n *\n * @param {Resource} [resource] The resource that failed to load.\n * @param {Error} [error] The error that occurred during the loading of the resource.\n * @returns {Boolean|Promisetrue
if they are equal, false
otherwise.\n *\n * @param {HeadingPitchRoll} [left] The first HeadingPitchRoll.\n * @param {HeadingPitchRoll} [right] The second HeadingPitchRoll.\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\n */\nHeadingPitchRoll.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left.heading === right.heading &&\n left.pitch === right.pitch &&\n left.roll === right.roll)\n );\n};\n\n/**\n * Compares the provided HeadingPitchRolls componentwise and returns\n * true
if they pass an absolute or relative tolerance test,\n * false
otherwise.\n *\n * @param {HeadingPitchRoll} [left] The first HeadingPitchRoll.\n * @param {HeadingPitchRoll} [right] The second HeadingPitchRoll.\n * @param {Number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\n * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\n * @returns {Boolean} true
if left and right are within the provided epsilon, false
otherwise.\n */\nHeadingPitchRoll.equalsEpsilon = function (\n left,\n right,\n relativeEpsilon,\n absoluteEpsilon\n) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n CesiumMath.equalsEpsilon(\n left.heading,\n right.heading,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n CesiumMath.equalsEpsilon(\n left.pitch,\n right.pitch,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n CesiumMath.equalsEpsilon(\n left.roll,\n right.roll,\n relativeEpsilon,\n absoluteEpsilon\n ))\n );\n};\n\n/**\n * Duplicates this HeadingPitchRoll instance.\n *\n * @param {HeadingPitchRoll} [result] The object onto which to store the result.\n * @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if one was not provided.\n */\nHeadingPitchRoll.prototype.clone = function (result) {\n return HeadingPitchRoll.clone(this, result);\n};\n\n/**\n * Compares this HeadingPitchRoll against the provided HeadingPitchRoll componentwise and returns\n * true
if they are equal, false
otherwise.\n *\n * @param {HeadingPitchRoll} [right] The right hand side HeadingPitchRoll.\n * @returns {Boolean} true
if they are equal, false
otherwise.\n */\nHeadingPitchRoll.prototype.equals = function (right) {\n return HeadingPitchRoll.equals(this, right);\n};\n\n/**\n * Compares this HeadingPitchRoll against the provided HeadingPitchRoll componentwise and returns\n * true
if they pass an absolute or relative tolerance test,\n * false
otherwise.\n *\n * @param {HeadingPitchRoll} [right] The right hand side HeadingPitchRoll.\n * @param {Number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\n * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\n * @returns {Boolean} true
if they are within the provided epsilon, false
otherwise.\n */\nHeadingPitchRoll.prototype.equalsEpsilon = function (\n right,\n relativeEpsilon,\n absoluteEpsilon\n) {\n return HeadingPitchRoll.equalsEpsilon(\n this,\n right,\n relativeEpsilon,\n absoluteEpsilon\n );\n};\n\n/**\n * Creates a string representing this HeadingPitchRoll in the format '(heading, pitch, roll)' in radians.\n *\n * @returns {String} A string representing the provided HeadingPitchRoll in the format '(heading, pitch, roll)'.\n */\nHeadingPitchRoll.prototype.toString = function () {\n return `(${this.heading}, ${this.pitch}, ${this.roll})`;\n};\nexport default HeadingPitchRoll;\n","import defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport getAbsoluteUri from \"./getAbsoluteUri.js\";\nimport Resource from \"./Resource.js\";\n\n/*global CESIUM_BASE_URL,define,require*/\n\nconst cesiumScriptRegex = /((?:.*\\/)|^)Cesium\\.js(?:\\?|\\#|$)/;\nfunction getBaseUrlFromCesiumScript() {\n const scripts = document.getElementsByTagName(\"script\");\n for (let i = 0, len = scripts.length; i < len; ++i) {\n const src = scripts[i].getAttribute(\"src\");\n const result = cesiumScriptRegex.exec(src);\n if (result !== null) {\n return result[1];\n }\n }\n return undefined;\n}\n\nlet a;\nfunction tryMakeAbsolute(url) {\n if (typeof document === \"undefined\") {\n //Node.js and Web Workers. In both cases, the URL will already be absolute.\n return url;\n }\n\n if (!defined(a)) {\n a = document.createElement(\"a\");\n }\n a.href = url;\n\n // IE only absolutizes href on get, not set\n // eslint-disable-next-line no-self-assign\n a.href = a.href;\n return a.href;\n}\n\nlet baseResource;\nfunction getCesiumBaseUrl() {\n if (defined(baseResource)) {\n return baseResource;\n }\n\n let baseUrlString;\n if (typeof CESIUM_BASE_URL !== \"undefined\") {\n baseUrlString = CESIUM_BASE_URL;\n } else if (\n typeof define === \"object\" &&\n defined(define.amd) &&\n !define.amd.toUrlUndefined &&\n defined(require.toUrl)\n ) {\n baseUrlString = getAbsoluteUri(\n \"..\",\n buildModuleUrl(\"Core/buildModuleUrl.js\")\n );\n } else {\n baseUrlString = getBaseUrlFromCesiumScript();\n }\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(baseUrlString)) {\n throw new DeveloperError(\n \"Unable to determine Cesium base URL automatically, try defining a global variable called CESIUM_BASE_URL.\"\n );\n }\n //>>includeEnd('debug');\n\n baseResource = new Resource({\n url: tryMakeAbsolute(baseUrlString),\n });\n baseResource.appendForwardSlash();\n\n return baseResource;\n}\n\nfunction buildModuleUrlFromRequireToUrl(moduleID) {\n //moduleID will be non-relative, so require it relative to this module, in Core.\n return tryMakeAbsolute(require.toUrl(`../${moduleID}`));\n}\n\nfunction buildModuleUrlFromBaseUrl(moduleID) {\n const resource = getCesiumBaseUrl().getDerivedResource({\n url: moduleID,\n });\n return resource.url;\n}\n\nlet implementation;\n\n/**\n * Given a relative URL under the Cesium base URL, returns an absolute URL.\n * @function\n *\n * @param {String} relativeUrl The relative path.\n * @returns {String} The absolutely URL representation of the provided path.\n *\n * @example\n * const viewer = new Cesium.Viewer(\"cesiumContainer\", {\n * imageryProvider: new Cesium.TileMapServiceImageryProvider({\n * url: Cesium.buildModuleUrl(\"Assets/Textures/NaturalEarthII\"),\n * }),\n * baseLayerPicker: false,\n * });\n */\nfunction buildModuleUrl(relativeUrl) {\n if (!defined(implementation)) {\n //select implementation\n if (\n typeof define === \"object\" &&\n defined(define.amd) &&\n !define.amd.toUrlUndefined &&\n defined(require.toUrl)\n ) {\n implementation = buildModuleUrlFromRequireToUrl;\n } else {\n implementation = buildModuleUrlFromBaseUrl;\n }\n }\n\n const url = implementation(relativeUrl);\n return url;\n}\n\n// exposed for testing\nbuildModuleUrl._cesiumScriptRegex = cesiumScriptRegex;\nbuildModuleUrl._buildModuleUrlFromBaseUrl = buildModuleUrlFromBaseUrl;\nbuildModuleUrl._clearBaseResource = function () {\n baseResource = undefined;\n};\n\n/**\n * Sets the base URL for resolving modules.\n * @param {String} value The new base URL.\n */\nbuildModuleUrl.setBaseUrl = function (value) {\n baseResource = Resource.DEFAULT.getDerivedResource({\n url: value,\n });\n};\n\n/**\n * Gets the base URL for resolving modules.\n */\nbuildModuleUrl.getCesiumBaseUrl = getCesiumBaseUrl;\n\nexport default buildModuleUrl;\n","/**\n * An IAU 2006 XYS value sampled at a particular time.\n *\n * @alias Iau2006XysSample\n * @constructor\n *\n * @param {Number} x The X value.\n * @param {Number} y The Y value.\n * @param {Number} s The S value.\n *\n * @private\n */\nfunction Iau2006XysSample(x, y, s) {\n /**\n * The X value.\n * @type {Number}\n */\n this.x = x;\n\n /**\n * The Y value.\n * @type {Number}\n */\n this.y = y;\n\n /**\n * The S value.\n * @type {Number}\n */\n this.s = s;\n}\nexport default Iau2006XysSample;\n","import when from \"../ThirdParty/when.js\";\nimport buildModuleUrl from \"./buildModuleUrl.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Iau2006XysSample from \"./Iau2006XysSample.js\";\nimport JulianDate from \"./JulianDate.js\";\nimport Resource from \"./Resource.js\";\nimport TimeStandard from \"./TimeStandard.js\";\n\n/**\n * A set of IAU2006 XYS data that is used to evaluate the transformation between the International\n * Celestial Reference Frame (ICRF) and the International Terrestrial Reference Frame (ITRF).\n *\n * @alias Iau2006XysData\n * @constructor\n *\n * @param {Object} [options] Object with the following properties:\n * @param {Resource|String} [options.xysFileUrlTemplate='Assets/IAU2006_XYS/IAU2006_XYS_{0}.json'] A template URL for obtaining the XYS data. In the template,\n * `{0}` will be replaced with the file index.\n * @param {Number} [options.interpolationOrder=9] The order of interpolation to perform on the XYS data.\n * @param {Number} [options.sampleZeroJulianEphemerisDate=2442396.5] The Julian ephemeris date (JED) of the\n * first XYS sample.\n * @param {Number} [options.stepSizeDays=1.0] The step size, in days, between successive XYS samples.\n * @param {Number} [options.samplesPerXysFile=1000] The number of samples in each XYS file.\n * @param {Number} [options.totalSamples=27426] The total number of samples in all XYS files.\n *\n * @private\n */\nfunction Iau2006XysData(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._xysFileUrlTemplate = Resource.createIfNeeded(\n options.xysFileUrlTemplate\n );\n this._interpolationOrder = defaultValue(options.interpolationOrder, 9);\n this._sampleZeroJulianEphemerisDate = defaultValue(\n options.sampleZeroJulianEphemerisDate,\n 2442396.5\n );\n this._sampleZeroDateTT = new JulianDate(\n this._sampleZeroJulianEphemerisDate,\n 0.0,\n TimeStandard.TAI\n );\n this._stepSizeDays = defaultValue(options.stepSizeDays, 1.0);\n this._samplesPerXysFile = defaultValue(options.samplesPerXysFile, 1000);\n this._totalSamples = defaultValue(options.totalSamples, 27426);\n this._samples = new Array(this._totalSamples * 3);\n this._chunkDownloadsInProgress = [];\n\n const order = this._interpolationOrder;\n\n // Compute denominators and X values for interpolation.\n const denom = (this._denominators = new Array(order + 1));\n const xTable = (this._xTable = new Array(order + 1));\n\n const stepN = Math.pow(this._stepSizeDays, order);\n\n for (let i = 0; i <= order; ++i) {\n denom[i] = stepN;\n xTable[i] = i * this._stepSizeDays;\n\n for (let j = 0; j <= order; ++j) {\n if (j !== i) {\n denom[i] *= i - j;\n }\n }\n\n denom[i] = 1.0 / denom[i];\n }\n\n // Allocate scratch arrays for interpolation.\n this._work = new Array(order + 1);\n this._coef = new Array(order + 1);\n}\n\nconst julianDateScratch = new JulianDate(0, 0.0, TimeStandard.TAI);\n\nfunction getDaysSinceEpoch(xys, dayTT, secondTT) {\n const dateTT = julianDateScratch;\n dateTT.dayNumber = dayTT;\n dateTT.secondsOfDay = secondTT;\n return JulianDate.daysDifference(dateTT, xys._sampleZeroDateTT);\n}\n\n/**\n * Preloads XYS data for a specified date range.\n *\n * @param {Number} startDayTT The Julian day number of the beginning of the interval to preload, expressed in\n * the Terrestrial Time (TT) time standard.\n * @param {Number} startSecondTT The seconds past noon of the beginning of the interval to preload, expressed in\n * the Terrestrial Time (TT) time standard.\n * @param {Number} stopDayTT The Julian day number of the end of the interval to preload, expressed in\n * the Terrestrial Time (TT) time standard.\n * @param {Number} stopSecondTT The seconds past noon of the end of the interval to preload, expressed in\n * the Terrestrial Time (TT) time standard.\n * @returns {Promisex
axis points in the local east direction.y
axis points in the local north direction.z
axis points in the direction of the ellipsoid surface normal which passes through the position.x
axis points in the local north direction.y
axis points in the local east direction.z
axis points in the opposite direction of the ellipsoid surface normal which passes through the position.x
axis points in the local north direction.y
axis points in the direction of the ellipsoid surface normal which passes through the position.z
axis points in the local east direction.x
axis points in the local north direction.y
axis points in the local west direction.z
axis points in the direction of the ellipsoid surface normal which passes through the position.