{"version":3,"file":"Cesium.js","sources":["../../../Source/Core/appendForwardSlash.js","../../../Source/Core/defined.js","../../../Source/Core/DeveloperError.js","../../../Source/Core/Check.js","../../../Source/Core/defaultValue.js","../../../Source/ThirdParty/mersenne-twister.js","../../../Source/Core/Math.js","../../../Source/Core/Cartesian3.js","../../../Source/Core/scaleToGeodeticSurface.js","../../../Source/Core/Cartographic.js","../../../Source/Core/Ellipsoid.js","../../../Source/Core/GeographicProjection.js","../../../Source/Core/Intersect.js","../../../Source/Core/Interval.js","../../../Source/Core/Matrix3.js","../../../Source/Core/Cartesian4.js","../../../Source/Core/RuntimeError.js","../../../Source/Core/Matrix4.js","../../../Source/Core/Rectangle.js","../../../Source/Core/BoundingSphere.js","../../../Source/ThirdParty/Uri.js","../../../Source/Core/getAbsoluteUri.js","../../../Source/ThirdParty/when.js","../../../Source/Core/clone.js","../../../Source/Core/combine.js","../../../Source/Core/getBaseUri.js","../../../Source/Core/getExtensionFromUri.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/buildModuleUrl.js","../../../Source/Core/Cartesian2.js","../../../Source/Core/GeographicTilingScheme.js","../../../Source/Core/ApproximateTerrainHeights.js","../../../Source/ThirdParty/purify.js","../../../Source/Core/Credit.js","../../../Source/Core/HeightmapEncoding.js","../../../Source/Core/AxisAlignedBoundingBox.js","../../../Source/Core/EllipsoidalOccluder.js","../../../Source/Core/QuadraticRealPolynomial.js","../../../Source/Core/CubicRealPolynomial.js","../../../Source/Core/QuarticRealPolynomial.js","../../../Source/Core/Ray.js","../../../Source/Core/IntersectionTests.js","../../../Source/Core/Plane.js","../../../Source/Core/binarySearch.js","../../../Source/Core/EarthOrientationParametersSample.js","../../../Source/ThirdParty/sprintf.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/Core/EarthOrientationParameters.js","../../../Source/Core/HeadingPitchRoll.js","../../../Source/Core/Iau2006XysSample.js","../../../Source/Core/Iau2006XysData.js","../../../Source/Core/Fullscreen.js","../../../Source/Core/FeatureDetection.js","../../../Source/Core/Quaternion.js","../../../Source/Core/Transforms.js","../../../Source/Core/EllipsoidTangentPlane.js","../../../Source/Core/OrientedBoundingBox.js","../../../Source/Core/AttributeCompression.js","../../../Source/Core/WebGLConstants.js","../../../Source/Core/ComponentDatatype.js","../../../Source/Core/TerrainQuantization.js","../../../Source/Core/TerrainEncoding.js","../../../Source/Core/WebMercatorProjection.js","../../../Source/Core/HeightmapTessellator.js","../../../Source/Core/destroyObject.js","../../../Source/Core/TaskProcessor.js","../../../Source/Core/TerrainData.js","../../../Source/Core/TerrainMesh.js","../../../Source/Core/IndexDatatype.js","../../../Source/Core/TerrainProvider.js","../../../Source/Core/HeightmapTerrainData.js","../../../Source/Core/TileAvailability.js","../../../Source/Core/formatError.js","../../../Source/Core/TileProviderError.js","../../../Source/Core/WebMercatorTilingScheme.js","../../../Source/Core/ArcGISTiledElevationTerrainProvider.js","../../../Source/Core/ArcType.js","../../../Source/Core/arrayFill.js","../../../Source/Core/arrayRemoveDuplicates.js","../../../Source/Core/arraySlice.js","../../../Source/Core/AssociativeArray.js","../../../Source/Core/barycentricCoordinates.js","../../../Source/Core/BingMapsGeocoderService.js","../../../Source/Core/BoundingRectangle.js","../../../Source/Core/GeometryType.js","../../../Source/Core/Matrix2.js","../../../Source/Core/PrimitiveType.js","../../../Source/Core/Geometry.js","../../../Source/Core/GeometryAttribute.js","../../../Source/Core/GeometryAttributes.js","../../../Source/Core/GeometryOffsetAttribute.js","../../../Source/Core/VertexFormat.js","../../../Source/Core/BoxGeometry.js","../../../Source/Core/BoxOutlineGeometry.js","../../../Source/Core/cancelAnimationFrame.js","../../../Source/Core/CartographicGeocoderService.js","../../../Source/Core/Spline.js","../../../Source/Core/LinearSpline.js","../../../Source/Core/TridiagonalSystemSolver.js","../../../Source/Core/HermiteSpline.js","../../../Source/Core/CatmullRomSpline.js","../../../Source/Core/getStringFromTypedArray.js","../../../Source/Core/getJsonFromTypedArray.js","../../../Source/Core/Intersections2D.js","../../../Source/Core/QuantizedMeshTerrainData.js","../../../Source/Core/CesiumTerrainProvider.js","../../../Source/Core/EllipseGeometryLibrary.js","../../../Source/Core/GeometryInstance.js","../../../Source/Core/EncodedCartesian3.js","../../../Source/Core/Tipsify.js","../../../Source/Core/GeometryPipeline.js","../../../Source/Core/EllipseGeometry.js","../../../Source/Core/CircleGeometry.js","../../../Source/Core/EllipseOutlineGeometry.js","../../../Source/Core/CircleOutlineGeometry.js","../../../Source/Core/ClockRange.js","../../../Source/Core/ClockStep.js","../../../Source/Core/getTimestamp.js","../../../Source/Core/Clock.js","../../../Source/Core/Color.js","../../../Source/Core/ColorGeometryInstanceAttribute.js","../../../Source/Core/CompressedTextureBuffer.js","../../../Source/Core/CoplanarPolygonGeometryLibrary.js","../../../Source/Core/EllipsoidRhumbLine.js","../../../Source/ThirdParty/earcut-2.2.1.js","../../../Source/Core/WindingOrder.js","../../../Source/Core/PolygonPipeline.js","../../../Source/Core/Queue.js","../../../Source/Core/PolygonGeometryLibrary.js","../../../Source/Core/CoplanarPolygonGeometry.js","../../../Source/Core/CoplanarPolygonOutlineGeometry.js","../../../Source/Core/CornerType.js","../../../Source/Core/EllipsoidGeodesic.js","../../../Source/Core/PolylinePipeline.js","../../../Source/Core/PolylineVolumeGeometryLibrary.js","../../../Source/Core/CorridorGeometryLibrary.js","../../../Source/Core/CorridorGeometry.js","../../../Source/Core/CorridorOutlineGeometry.js","../../../Source/Core/createGuid.js","../../../Source/Core/Ion.js","../../../Source/Core/IonResource.js","../../../Source/Core/createWorldTerrain.js","../../../Source/Core/CullingVolume.js","../../../Source/Core/CylinderGeometryLibrary.js","../../../Source/Core/CylinderGeometry.js","../../../Source/Core/CylinderOutlineGeometry.js","../../../Source/Core/decodeGoogleEarthEnterpriseData.js","../../../Source/Core/decodeVectorPolylinePositions.js","../../../Source/Core/DefaultProxy.js","../../../Source/Core/oneTimeWarning.js","../../../Source/Core/deprecationWarning.js","../../../Source/Core/DistanceDisplayCondition.js","../../../Source/Core/DistanceDisplayConditionGeometryInstanceAttribute.js","../../../Source/Core/DoubleEndedPriorityQueue.js","../../../Source/Core/DoublyLinkedList.js","../../../Source/ThirdParty/Tween.js","../../../Source/Core/EasingFunction.js","../../../Source/Core/EllipsoidGeometry.js","../../../Source/Core/EllipsoidOutlineGeometry.js","../../../Source/Core/EllipsoidTerrainProvider.js","../../../Source/Core/EventHelper.js","../../../Source/Core/ExtrapolationType.js","../../../Source/Core/OrthographicOffCenterFrustum.js","../../../Source/Core/OrthographicFrustum.js","../../../Source/Core/PerspectiveOffCenterFrustum.js","../../../Source/Core/PerspectiveFrustum.js","../../../Source/Core/FrustumGeometry.js","../../../Source/Core/FrustumOutlineGeometry.js","../../../Source/Core/GeocoderService.js","../../../Source/Core/GeocodeType.js","../../../Source/Core/GeometryFactory.js","../../../Source/Core/GeometryInstanceAttribute.js","../../../Source/Core/getFilenameFromUri.js","../../../Source/Core/getImagePixels.js","../../../Source/Core/getMagic.js","../../../Source/ThirdParty/protobuf-minimal.js","../../../Source/Core/isBitSet.js","../../../Source/Core/GoogleEarthEnterpriseTileInformation.js","../../../Source/Core/GoogleEarthEnterpriseMetadata.js","../../../Source/Core/GoogleEarthEnterpriseTerrainData.js","../../../Source/Core/GoogleEarthEnterpriseTerrainProvider.js","../../../Source/Core/GroundPolylineGeometry.js","../../../Source/Core/HeadingPitchRange.js","../../../Source/Core/HermitePolynomialApproximation.js","../../../Source/Core/IauOrientationParameters.js","../../../Source/Core/Iau2000Orientation.js","../../../Source/Core/IauOrientationAxes.js","../../../Source/Core/InterpolationAlgorithm.js","../../../Source/Core/PeliasGeocoderService.js","../../../Source/Core/IonGeocoderService.js","../../../Source/Core/TimeInterval.js","../../../Source/Core/Iso8601.js","../../../Source/Core/KeyboardEventModifier.js","../../../Source/Core/LagrangePolynomialApproximation.js","../../../Source/Core/LinearApproximation.js","../../../Source/Core/loadCRN.js","../../../Source/Core/loadImageFromTypedArray.js","../../../Source/Renderer/PixelDatatype.js","../../../Source/Core/PixelFormat.js","../../../Source/Core/loadKTX.js","../../../Source/Core/ManagedArray.js","../../../Source/Core/MapProjection.js","../../../Source/Core/mergeSort.js","../../../Source/Core/NearFarScalar.js","../../../Source/Core/Visibility.js","../../../Source/Core/Occluder.js","../../../Source/Core/OffsetGeometryInstanceAttribute.js","../../../Source/Core/OpenCageGeocoderService.js","../../../Source/Core/Packable.js","../../../Source/Core/PackableForInterpolation.js","../../../Source/ThirdParty/measureText.js","../../../Source/Core/writeTextToCanvas.js","../../../Source/Core/PinBuilder.js","../../../Source/Core/PlaneGeometry.js","../../../Source/Core/PlaneOutlineGeometry.js","../../../Source/Core/pointInsideTriangle.js","../../../Source/Core/PolygonGeometry.js","../../../Source/Core/PolygonHierarchy.js","../../../Source/Core/PolygonOutlineGeometry.js","../../../Source/Core/PolylineGeometry.js","../../../Source/Core/PolylineVolumeGeometry.js","../../../Source/Core/PolylineVolumeOutlineGeometry.js","../../../Source/Core/Proxy.js","../../../Source/Core/QuaternionSpline.js","../../../Source/ThirdParty/rbush.js","../../../Source/Core/RectangleCollisionChecker.js","../../../Source/Core/RectangleGeometryLibrary.js","../../../Source/Core/RectangleGeometry.js","../../../Source/Core/RectangleOutlineGeometry.js","../../../Source/Core/ReferenceFrame.js","../../../Source/Core/requestAnimationFrame.js","../../../Source/Core/sampleTerrain.js","../../../Source/Core/sampleTerrainMostDetailed.js","../../../Source/Core/ScreenSpaceEventType.js","../../../Source/Core/ScreenSpaceEventHandler.js","../../../Source/Core/ShowGeometryInstanceAttribute.js","../../../Source/Core/Simon1994PlanetaryPositions.js","../../../Source/Core/SimplePolylineGeometry.js","../../../Source/Core/SphereGeometry.js","../../../Source/Core/SphereOutlineGeometry.js","../../../Source/Core/Spherical.js","../../../Source/Core/subdivideArray.js","../../../Source/Core/TileEdge.js","../../../Source/Core/TilingScheme.js","../../../Source/Core/TimeIntervalCollection.js","../../../Source/Core/TranslationRotationScale.js","../../../Source/Core/VideoSynchronizer.js","../../../Source/Core/VRTheWorldTerrainProvider.js","../../../Source/Core/WallGeometryLibrary.js","../../../Source/Core/WallGeometry.js","../../../Source/Core/WallOutlineGeometry.js","../../../Source/Core/webGLConstantToGlslType.js","../../../Source/Core/WeightSpline.js","../../../Source/Core/wrapFunction.js","../../../Source/DataSources/ConstantProperty.js","../../../Source/DataSources/createPropertyDescriptor.js","../../../Source/DataSources/BillboardGraphics.js","../../../Source/Scene/HeightReference.js","../../../Source/Scene/HorizontalOrigin.js","../../../Source/Scene/VerticalOrigin.js","../../../Source/DataSources/BoundingSphereState.js","../../../Source/DataSources/Property.js","../../../Source/DataSources/BillboardVisualizer.js","../../../Source/Shaders/Appearances/AllMaterialAppearanceFS.js","../../../Source/Shaders/Appearances/AllMaterialAppearanceVS.js","../../../Source/Shaders/Appearances/BasicMaterialAppearanceFS.js","../../../Source/Shaders/Appearances/BasicMaterialAppearanceVS.js","../../../Source/Shaders/Appearances/TexturedMaterialAppearanceFS.js","../../../Source/Shaders/Appearances/TexturedMaterialAppearanceVS.js","../../../Source/Scene/BlendEquation.js","../../../Source/Scene/BlendFunction.js","../../../Source/Scene/BlendingState.js","../../../Source/Scene/CullFace.js","../../../Source/Scene/Appearance.js","../../../Source/Renderer/ContextLimits.js","../../../Source/Renderer/CubeMapFace.js","../../../Source/Renderer/MipmapHint.js","../../../Source/Renderer/TextureMagnificationFilter.js","../../../Source/Renderer/TextureMinificationFilter.js","../../../Source/Renderer/TextureWrap.js","../../../Source/Renderer/Sampler.js","../../../Source/Renderer/CubeMap.js","../../../Source/Renderer/Texture.js","../../../Source/Shaders/Materials/AspectRampMaterial.js","../../../Source/Shaders/Materials/BumpMapMaterial.js","../../../Source/Shaders/Materials/CheckerboardMaterial.js","../../../Source/Shaders/Materials/DotMaterial.js","../../../Source/Shaders/Materials/ElevationBandMaterial.js","../../../Source/Shaders/Materials/ElevationContourMaterial.js","../../../Source/Shaders/Materials/ElevationRampMaterial.js","../../../Source/Shaders/Materials/FadeMaterial.js","../../../Source/Shaders/Materials/GridMaterial.js","../../../Source/Shaders/Materials/NormalMapMaterial.js","../../../Source/Shaders/Materials/PolylineArrowMaterial.js","../../../Source/Shaders/Materials/PolylineDashMaterial.js","../../../Source/Shaders/Materials/PolylineGlowMaterial.js","../../../Source/Shaders/Materials/PolylineOutlineMaterial.js","../../../Source/Shaders/Materials/RimLightingMaterial.js","../../../Source/Shaders/Materials/SlopeRampMaterial.js","../../../Source/Shaders/Materials/StripeMaterial.js","../../../Source/Shaders/Materials/Water.js","../../../Source/Scene/Material.js","../../../Source/Scene/MaterialAppearance.js","../../../Source/Shaders/Appearances/PerInstanceColorAppearanceFS.js","../../../Source/Shaders/Appearances/PerInstanceColorAppearanceVS.js","../../../Source/Shaders/Appearances/PerInstanceFlatColorAppearanceFS.js","../../../Source/Shaders/Appearances/PerInstanceFlatColorAppearanceVS.js","../../../Source/Scene/PerInstanceColorAppearance.js","../../../Source/DataSources/ColorMaterialProperty.js","../../../Source/Renderer/DrawCommand.js","../../../Source/Renderer/Pass.js","../../../Source/Renderer/freezeRenderState.js","../../../Source/Renderer/RenderState.js","../../../Source/Renderer/AutomaticUniforms.js","../../../Source/Renderer/createUniform.js","../../../Source/Renderer/createUniformArray.js","../../../Source/Renderer/ShaderProgram.js","../../../Source/Renderer/modernizeShader.js","../../../Source/Shaders/Builtin/Constants/degreesPerRadian.js","../../../Source/Shaders/Builtin/Constants/depthRange.js","../../../Source/Shaders/Builtin/Constants/epsilon1.js","../../../Source/Shaders/Builtin/Constants/epsilon2.js","../../../Source/Shaders/Builtin/Constants/epsilon3.js","../../../Source/Shaders/Builtin/Constants/epsilon4.js","../../../Source/Shaders/Builtin/Constants/epsilon5.js","../../../Source/Shaders/Builtin/Constants/epsilon6.js","../../../Source/Shaders/Builtin/Constants/epsilon7.js","../../../Source/Shaders/Builtin/Constants/infinity.js","../../../Source/Shaders/Builtin/Constants/oneOverPi.js","../../../Source/Shaders/Builtin/Constants/oneOverTwoPi.js","../../../Source/Shaders/Builtin/Constants/passCesium3DTile.js","../../../Source/Shaders/Builtin/Constants/passCesium3DTileClassification.js","../../../Source/Shaders/Builtin/Constants/passCesium3DTileClassificationIgnoreShow.js","../../../Source/Shaders/Builtin/Constants/passClassification.js","../../../Source/Shaders/Builtin/Constants/passCompute.js","../../../Source/Shaders/Builtin/Constants/passEnvironment.js","../../../Source/Shaders/Builtin/Constants/passGlobe.js","../../../Source/Shaders/Builtin/Constants/passOpaque.js","../../../Source/Shaders/Builtin/Constants/passOverlay.js","../../../Source/Shaders/Builtin/Constants/passTerrainClassification.js","../../../Source/Shaders/Builtin/Constants/passTranslucent.js","../../../Source/Shaders/Builtin/Constants/pi.js","../../../Source/Shaders/Builtin/Constants/piOverFour.js","../../../Source/Shaders/Builtin/Constants/piOverSix.js","../../../Source/Shaders/Builtin/Constants/piOverThree.js","../../../Source/Shaders/Builtin/Constants/piOverTwo.js","../../../Source/Shaders/Builtin/Constants/radiansPerDegree.js","../../../Source/Shaders/Builtin/Constants/sceneMode2D.js","../../../Source/Shaders/Builtin/Constants/sceneMode3D.js","../../../Source/Shaders/Builtin/Constants/sceneModeColumbusView.js","../../../Source/Shaders/Builtin/Constants/sceneModeMorphing.js","../../../Source/Shaders/Builtin/Constants/solarRadius.js","../../../Source/Shaders/Builtin/Constants/threePiOver2.js","../../../Source/Shaders/Builtin/Constants/twoPi.js","../../../Source/Shaders/Builtin/Constants/webMercatorMaxLatitude.js","../../../Source/Shaders/Builtin/Structs/depthRangeStruct.js","../../../Source/Shaders/Builtin/Structs/material.js","../../../Source/Shaders/Builtin/Structs/materialInput.js","../../../Source/Shaders/Builtin/Structs/ray.js","../../../Source/Shaders/Builtin/Structs/raySegment.js","../../../Source/Shaders/Builtin/Structs/shadowParameters.js","../../../Source/Shaders/Builtin/Functions/acesTonemapping.js","../../../Source/Shaders/Builtin/Functions/alphaWeight.js","../../../Source/Shaders/Builtin/Functions/antialias.js","../../../Source/Shaders/Builtin/Functions/approximateSphericalCoordinates.js","../../../Source/Shaders/Builtin/Functions/backFacing.js","../../../Source/Shaders/Builtin/Functions/branchFreeTernary.js","../../../Source/Shaders/Builtin/Functions/cascadeColor.js","../../../Source/Shaders/Builtin/Functions/cascadeDistance.js","../../../Source/Shaders/Builtin/Functions/cascadeMatrix.js","../../../Source/Shaders/Builtin/Functions/cascadeWeights.js","../../../Source/Shaders/Builtin/Functions/columbusViewMorph.js","../../../Source/Shaders/Builtin/Functions/computePosition.js","../../../Source/Shaders/Builtin/Functions/cosineAndSine.js","../../../Source/Shaders/Builtin/Functions/decompressTextureCoordinates.js","../../../Source/Shaders/Builtin/Functions/depthClamp.js","../../../Source/Shaders/Builtin/Functions/eastNorthUpToEyeCoordinates.js","../../../Source/Shaders/Builtin/Functions/ellipsoidContainsPoint.js","../../../Source/Shaders/Builtin/Functions/ellipsoidWgs84TextureCoordinates.js","../../../Source/Shaders/Builtin/Functions/equalsEpsilon.js","../../../Source/Shaders/Builtin/Functions/eyeOffset.js","../../../Source/Shaders/Builtin/Functions/eyeToWindowCoordinates.js","../../../Source/Shaders/Builtin/Functions/fastApproximateAtan.js","../../../Source/Shaders/Builtin/Functions/fog.js","../../../Source/Shaders/Builtin/Functions/gammaCorrect.js","../../../Source/Shaders/Builtin/Functions/geodeticSurfaceNormal.js","../../../Source/Shaders/Builtin/Functions/getDefaultMaterial.js","../../../Source/Shaders/Builtin/Functions/getLambertDiffuse.js","../../../Source/Shaders/Builtin/Functions/getSpecular.js","../../../Source/Shaders/Builtin/Functions/getWaterNoise.js","../../../Source/Shaders/Builtin/Functions/HSBToRGB.js","../../../Source/Shaders/Builtin/Functions/HSLToRGB.js","../../../Source/Shaders/Builtin/Functions/hue.js","../../../Source/Shaders/Builtin/Functions/inverseGamma.js","../../../Source/Shaders/Builtin/Functions/isEmpty.js","../../../Source/Shaders/Builtin/Functions/isFull.js","../../../Source/Shaders/Builtin/Functions/latitudeToWebMercatorFraction.js","../../../Source/Shaders/Builtin/Functions/lineDistance.js","../../../Source/Shaders/Builtin/Functions/luminance.js","../../../Source/Shaders/Builtin/Functions/metersPerPixel.js","../../../Source/Shaders/Builtin/Functions/modelToWindowCoordinates.js","../../../Source/Shaders/Builtin/Functions/multiplyWithColorBalance.js","../../../Source/Shaders/Builtin/Functions/nearFarScalar.js","../../../Source/Shaders/Builtin/Functions/octDecode.js","../../../Source/Shaders/Builtin/Functions/packDepth.js","../../../Source/Shaders/Builtin/Functions/phong.js","../../../Source/Shaders/Builtin/Functions/planeDistance.js","../../../Source/Shaders/Builtin/Functions/pointAlongRay.js","../../../Source/Shaders/Builtin/Functions/rayEllipsoidIntersectionInterval.js","../../../Source/Shaders/Builtin/Functions/readDepth.js","../../../Source/Shaders/Builtin/Functions/readNonPerspective.js","../../../Source/Shaders/Builtin/Functions/reverseLogDepth.js","../../../Source/Shaders/Builtin/Functions/RGBToHSB.js","../../../Source/Shaders/Builtin/Functions/RGBToHSL.js","../../../Source/Shaders/Builtin/Functions/RGBToXYZ.js","../../../Source/Shaders/Builtin/Functions/sampleOctahedralProjection.js","../../../Source/Shaders/Builtin/Functions/saturation.js","../../../Source/Shaders/Builtin/Functions/shadowDepthCompare.js","../../../Source/Shaders/Builtin/Functions/shadowVisibility.js","../../../Source/Shaders/Builtin/Functions/signNotZero.js","../../../Source/Shaders/Builtin/Functions/sphericalHarmonics.js","../../../Source/Shaders/Builtin/Functions/tangentToEyeSpaceMatrix.js","../../../Source/Shaders/Builtin/Functions/transformPlane.js","../../../Source/Shaders/Builtin/Functions/translateRelativeToEye.js","../../../Source/Shaders/Builtin/Functions/translucentPhong.js","../../../Source/Shaders/Builtin/Functions/transpose.js","../../../Source/Shaders/Builtin/Functions/unpackDepth.js","../../../Source/Shaders/Builtin/Functions/unpackFloat.js","../../../Source/Shaders/Builtin/Functions/vertexLogDepth.js","../../../Source/Shaders/Builtin/Functions/windowToEyeCoordinates.js","../../../Source/Shaders/Builtin/Functions/writeDepthClamp.js","../../../Source/Shaders/Builtin/Functions/writeLogDepth.js","../../../Source/Shaders/Builtin/Functions/writeNonPerspective.js","../../../Source/Shaders/Builtin/Functions/XYZToRGB.js","../../../Source/Shaders/Builtin/CzmBuiltins.js","../../../Source/Renderer/ShaderSource.js","../../../Source/Shaders/ShadowVolumeAppearanceVS.js","../../../Source/Shaders/ShadowVolumeFS.js","../../../Source/Scene/ClassificationType.js","../../../Source/Scene/DepthFunction.js","../../../Source/Renderer/BufferUsage.js","../../../Source/Renderer/Buffer.js","../../../Source/Renderer/VertexArray.js","../../../Source/Scene/BatchTable.js","../../../Source/Scene/PrimitivePipeline.js","../../../Source/Scene/PrimitiveState.js","../../../Source/Scene/SceneMode.js","../../../Source/Scene/ShadowMode.js","../../../Source/Scene/Primitive.js","../../../Source/Shaders/ShadowVolumeAppearanceFS.js","../../../Source/Scene/ShadowVolumeAppearance.js","../../../Source/Scene/StencilFunction.js","../../../Source/Scene/StencilOperation.js","../../../Source/Scene/StencilConstants.js","../../../Source/Scene/ClassificationPrimitive.js","../../../Source/Scene/GroundPrimitive.js","../../../Source/DataSources/MaterialProperty.js","../../../Source/DataSources/DynamicGeometryUpdater.js","../../../Source/Shaders/PolylineShadowVolumeFS.js","../../../Source/Shaders/PolylineShadowVolumeMorphFS.js","../../../Source/Shaders/PolylineShadowVolumeMorphVS.js","../../../Source/Shaders/PolylineShadowVolumeVS.js","../../../Source/Shaders/Appearances/PolylineColorAppearanceVS.js","../../../Source/Shaders/PolylineCommon.js","../../../Source/Scene/PolylineColorAppearance.js","../../../Source/Shaders/Appearances/PolylineMaterialAppearanceVS.js","../../../Source/Shaders/PolylineFS.js","../../../Source/Scene/PolylineMaterialAppearance.js","../../../Source/Scene/GroundPolylinePrimitive.js","../../../Source/DataSources/ImageMaterialProperty.js","../../../Source/DataSources/createMaterialPropertyDescriptor.js","../../../Source/DataSources/BoxGraphics.js","../../../Source/DataSources/PositionProperty.js","../../../Source/DataSources/ConstantPositionProperty.js","../../../Source/DataSources/CorridorGraphics.js","../../../Source/DataSources/createRawPropertyDescriptor.js","../../../Source/DataSources/CylinderGraphics.js","../../../Source/DataSources/EllipseGraphics.js","../../../Source/DataSources/EllipsoidGraphics.js","../../../Source/DataSources/LabelGraphics.js","../../../Source/DataSources/NodeTransformationProperty.js","../../../Source/DataSources/PropertyBag.js","../../../Source/DataSources/ModelGraphics.js","../../../Source/DataSources/Cesium3DTilesetGraphics.js","../../../Source/DataSources/PathGraphics.js","../../../Source/DataSources/PlaneGraphics.js","../../../Source/DataSources/PointGraphics.js","../../../Source/DataSources/PolygonGraphics.js","../../../Source/DataSources/PolylineGraphics.js","../../../Source/DataSources/PolylineVolumeGraphics.js","../../../Source/DataSources/RectangleGraphics.js","../../../Source/DataSources/WallGraphics.js","../../../Source/DataSources/Entity.js","../../../Source/DataSources/GeometryUpdater.js","../../../Source/DataSources/CallbackProperty.js","../../../Source/DataSources/TerrainOffsetProperty.js","../../../Source/DataSources/heightReferenceOnEntityPropertyChanged.js","../../../Source/DataSources/BoxGeometryUpdater.js","../../../Source/Renderer/ClearCommand.js","../../../Source/Scene/Axis.js","../../../Source/Scene/AttributeType.js","../../../Source/Scene/Cesium3DTileColorBlendMode.js","../../../Source/Scene/getBinaryAccessor.js","../../../Source/Scene/Cesium3DTileBatchTable.js","../../../Source/Scene/Cesium3DTileFeature.js","../../../Source/Scene/Cesium3DTileFeatureTable.js","../../../Source/ThirdParty/GltfPipeline/addToArray.js","../../../Source/ThirdParty/GltfPipeline/hasExtension.js","../../../Source/ThirdParty/GltfPipeline/ForEach.js","../../../Source/ThirdParty/GltfPipeline/numberOfComponentsForType.js","../../../Source/ThirdParty/GltfPipeline/getAccessorByteStride.js","../../../Source/ThirdParty/GltfPipeline/addDefaults.js","../../../Source/ThirdParty/GltfPipeline/addPipelineExtras.js","../../../Source/ThirdParty/GltfPipeline/removeExtensionsRequired.js","../../../Source/ThirdParty/GltfPipeline/removeExtensionsUsed.js","../../../Source/ThirdParty/GltfPipeline/parseGlb.js","../../../Source/ThirdParty/GltfPipeline/addExtensionsUsed.js","../../../Source/ThirdParty/GltfPipeline/getComponentReader.js","../../../Source/ThirdParty/GltfPipeline/findAccessorMinMax.js","../../../Source/ThirdParty/GltfPipeline/moveTechniqueRenderStates.js","../../../Source/ThirdParty/GltfPipeline/addExtensionsRequired.js","../../../Source/ThirdParty/GltfPipeline/moveTechniquesToExtension.js","../../../Source/ThirdParty/GltfPipeline/removeUnusedElements.js","../../../Source/ThirdParty/GltfPipeline/addBuffer.js","../../../Source/ThirdParty/GltfPipeline/readAccessorPacked.js","../../../Source/ThirdParty/GltfPipeline/updateAccessorComponentTypes.js","../../../Source/ThirdParty/GltfPipeline/updateVersion.js","../../../Source/Scene/ModelLoadResources.js","../../../Source/Scene/ModelUtility.js","../../../Source/Scene/processModelMaterialsCommon.js","../../../Source/Scene/processPbrMaterials.js","../../../Source/Scene/Vector3DTileBatch.js","../../../Source/Shaders/VectorTileVS.js","../../../Source/ThirdParty/jsep.js","../../../Source/Scene/ExpressionNodeType.js","../../../Source/Scene/Expression.js","../../../Source/Scene/Vector3DTilePrimitive.js","../../../Source/Scene/ClassificationModel.js","../../../Source/Scene/ClippingPlane.js","../../../Source/Scene/ClippingPlaneCollection.js","../../../Source/Scene/ColorBlendMode.js","../../../Source/Scene/DracoLoader.js","../../../Source/Scene/getClipAndStyleCode.js","../../../Source/Scene/getClippingFunction.js","../../../Source/Scene/JobType.js","../../../Source/Scene/ModelAnimationCache.js","../../../Source/Scene/ModelAnimationLoop.js","../../../Source/Scene/ModelAnimationState.js","../../../Source/Scene/ModelAnimation.js","../../../Source/Scene/ModelAnimationCollection.js","../../../Source/Scene/ModelMaterial.js","../../../Source/Scene/ModelMesh.js","../../../Source/Scene/ModelNode.js","../../../Source/Scene/ModelOutlineLoader.js","../../../Source/Renderer/ComputeCommand.js","../../../Source/Shaders/OctahedralProjectionAtlasFS.js","../../../Source/Shaders/OctahedralProjectionFS.js","../../../Source/Shaders/OctahedralProjectionVS.js","../../../Source/Scene/OctahedralProjectedCubeMap.js","../../../Source/Scene/Model.js","../../../Source/Scene/Batched3DModel3DTileContent.js","../../../Source/Scene/Composite3DTileContent.js","../../../Source/Scene/Vector3DTileGeometry.js","../../../Source/Scene/Geometry3DTileContent.js","../../../Source/Scene/ModelInstance.js","../../../Source/Scene/ModelInstanceCollection.js","../../../Source/Scene/Instanced3DModel3DTileContent.js","../../../Source/Scene/Cesium3DTileRefine.js","../../../Source/Scene/PointCloud.js","../../../Source/Renderer/Framebuffer.js","../../../Source/Shaders/PostProcessStages/PointCloudEyeDomeLighting.js","../../../Source/Scene/PointCloudEyeDomeLighting.js","../../../Source/Scene/PointCloudShading.js","../../../Source/Scene/PointCloud3DTileContent.js","../../../Source/Scene/Tileset3DTileContent.js","../../../Source/Renderer/VertexArrayFacade.js","../../../Source/Shaders/BillboardCollectionFS.js","../../../Source/Shaders/BillboardCollectionVS.js","../../../Source/Scene/SceneTransforms.js","../../../Source/Scene/Billboard.js","../../../Source/Scene/BlendOption.js","../../../Source/Scene/SDFSettings.js","../../../Source/Scene/TextureAtlas.js","../../../Source/Scene/BillboardCollection.js","../../../Source/Scene/createBillboardPointCallback.js","../../../Source/Scene/Cesium3DTilePointFeature.js","../../../Source/ThirdParty/bitmap-sdf.js","../../../Source/Scene/LabelStyle.js","../../../Source/Scene/Label.js","../../../Source/ThirdParty/graphemesplitter.js","../../../Source/Scene/LabelCollection.js","../../../Source/Shaders/PolylineVS.js","../../../Source/Scene/Polyline.js","../../../Source/Scene/PolylineCollection.js","../../../Source/Scene/Vector3DTilePoints.js","../../../Source/Scene/Vector3DTilePolygons.js","../../../Source/Shaders/Vector3DTilePolylinesVS.js","../../../Source/Scene/Vector3DTilePolylines.js","../../../Source/Shaders/Vector3DTileClampedPolylinesVS.js","../../../Source/Shaders/Vector3DTileClampedPolylinesFS.js","../../../Source/Scene/Vector3DTileClampedPolylines.js","../../../Source/Scene/Vector3DTileContent.js","../../../Source/Scene/Cesium3DTileContentFactory.js","../../../Source/Scene/Cesium3DTileContentState.js","../../../Source/Scene/Cesium3DTileOptimizationHint.js","../../../Source/Scene/Cesium3DTilesetMostDetailedTraversal.js","../../../Source/Scene/Cesium3DTilesetTraversal.js","../../../Source/Scene/Cesium3DTilePass.js","../../../Source/Scene/Empty3DTileContent.js","../../../Source/Scene/TileBoundingRegion.js","../../../Source/Scene/TileBoundingSphere.js","../../../Source/Scene/TileOrientedBoundingBox.js","../../../Source/Scene/Cesium3DTile.js","../../../Source/Scene/Cesium3DTileOptimizations.js","../../../Source/Scene/Cesium3DTilesetCache.js","../../../Source/Scene/Cesium3DTilesetHeatmap.js","../../../Source/Scene/Cesium3DTilesetStatistics.js","../../../Source/Scene/Cesium3DTileStyleEngine.js","../../../Source/Scene/Cesium3DTileset.js","../../../Source/DataSources/Cesium3DTilesetVisualizer.js","../../../Source/DataSources/CheckerboardMaterialProperty.js","../../../Source/DataSources/EntityCollection.js","../../../Source/DataSources/CompositeEntityCollection.js","../../../Source/DataSources/CompositeProperty.js","../../../Source/DataSources/CompositeMaterialProperty.js","../../../Source/DataSources/CompositePositionProperty.js","../../../Source/DataSources/GroundGeometryUpdater.js","../../../Source/DataSources/CorridorGeometryUpdater.js","../../../Source/DataSources/DataSource.js","../../../Source/Scene/PointPrimitive.js","../../../Source/Shaders/PointPrimitiveCollectionFS.js","../../../Source/Shaders/PointPrimitiveCollectionVS.js","../../../Source/Scene/PointPrimitiveCollection.js","../../../Source/ThirdParty/kdbush.js","../../../Source/DataSources/EntityCluster.js","../../../Source/DataSources/CustomDataSource.js","../../../Source/DataSources/CylinderGeometryUpdater.js","../../../Source/DataSources/DataSourceClock.js","../../../Source/DataSources/GridMaterialProperty.js","../../../Source/DataSources/PolylineArrowMaterialProperty.js","../../../Source/DataSources/PolylineDashMaterialProperty.js","../../../Source/DataSources/PolylineGlowMaterialProperty.js","../../../Source/DataSources/PolylineOutlineMaterialProperty.js","../../../Source/DataSources/PositionPropertyArray.js","../../../Source/DataSources/PropertyArray.js","../../../Source/DataSources/ReferenceProperty.js","../../../Source/DataSources/Rotation.js","../../../Source/DataSources/SampledProperty.js","../../../Source/DataSources/SampledPositionProperty.js","../../../Source/DataSources/StripeOrientation.js","../../../Source/DataSources/StripeMaterialProperty.js","../../../Source/DataSources/TimeIntervalCollectionPositionProperty.js","../../../Source/DataSources/TimeIntervalCollectionProperty.js","../../../Source/DataSources/VelocityVectorProperty.js","../../../Source/DataSources/VelocityOrientationProperty.js","../../../Source/DataSources/CzmlDataSource.js","../../../Source/DataSources/DataSourceCollection.js","../../../Source/Scene/PrimitiveCollection.js","../../../Source/Scene/OrderedGroundPrimitiveCollection.js","../../../Source/DataSources/DynamicGeometryBatch.js","../../../Source/DataSources/EllipseGeometryUpdater.js","../../../Source/DataSources/EllipsoidGeometryUpdater.js","../../../Source/DataSources/PlaneGeometryUpdater.js","../../../Source/DataSources/PolygonGeometryUpdater.js","../../../Source/DataSources/PolylineVolumeGeometryUpdater.js","../../../Source/DataSources/RectangleGeometryUpdater.js","../../../Source/DataSources/StaticGeometryColorBatch.js","../../../Source/DataSources/StaticGeometryPerMaterialBatch.js","../../../Source/DataSources/StaticGroundGeometryColorBatch.js","../../../Source/DataSources/StaticGroundGeometryPerMaterialBatch.js","../../../Source/DataSources/StaticOutlineGeometryBatch.js","../../../Source/DataSources/WallGeometryUpdater.js","../../../Source/DataSources/GeometryVisualizer.js","../../../Source/DataSources/LabelVisualizer.js","../../../Source/DataSources/ModelVisualizer.js","../../../Source/DataSources/ScaledPositionProperty.js","../../../Source/DataSources/PathVisualizer.js","../../../Source/DataSources/PointVisualizer.js","../../../Source/DataSources/PolylineGeometryUpdater.js","../../../Source/DataSources/StaticGroundPolylinePerMaterialBatch.js","../../../Source/DataSources/PolylineVisualizer.js","../../../Source/DataSources/DataSourceDisplay.js","../../../Source/DataSources/EntityView.js","../../../Source/ThirdParty/zip.js","../../../Source/DataSources/exportKml.js","../../../Source/ThirdParty/topojson.js","../../../Source/DataSources/GeoJsonDataSource.js","../../../Source/DataSources/KmlCamera.js","../../../Source/ThirdParty/Autolinker.js","../../../Source/DataSources/KmlLookAt.js","../../../Source/DataSources/KmlTour.js","../../../Source/DataSources/KmlTourFlyTo.js","../../../Source/DataSources/KmlTourWait.js","../../../Source/DataSources/KmlDataSource.js","../../../Source/DataSources/Visualizer.js","../../../Source/Shaders/ViewportQuadVS.js","../../../Source/Renderer/ComputeEngine.js","../../../Source/Renderer/PassState.js","../../../Source/Renderer/ShaderCache.js","../../../Source/Renderer/TextureCache.js","../../../Source/Scene/SunLight.js","../../../Source/Renderer/UniformState.js","../../../Source/Renderer/Context.js","../../../Source/Renderer/loadCubeMap.js","../../../Source/Renderer/RenderbufferFormat.js","../../../Source/Renderer/Renderbuffer.js","../../../Source/Scene/DiscardMissingTileImagePolicy.js","../../../Source/Scene/ImageryLayerFeatureInfo.js","../../../Source/Scene/ImageryProvider.js","../../../Source/Scene/ArcGisMapServerImageryProvider.js","../../../Source/Scene/AutoExposure.js","../../../Source/Scene/BingMapsStyle.js","../../../Source/Scene/DiscardEmptyTileImagePolicy.js","../../../Source/Scene/BingMapsImageryProvider.js","../../../Source/Scene/BoxEmitter.js","../../../Source/Shaders/BrdfLutGeneratorFS.js","../../../Source/Scene/BrdfLutGenerator.js","../../../Source/Scene/CameraFlightPath.js","../../../Source/Scene/MapMode2D.js","../../../Source/Scene/Camera.js","../../../Source/Scene/CameraEventType.js","../../../Source/Scene/CameraEventAggregator.js","../../../Source/Scene/Cesium3DTileContent.js","../../../Source/Scene/Cesium3DTilePassState.js","../../../Source/Scene/ConditionsExpression.js","../../../Source/Scene/Cesium3DTileStyle.js","../../../Source/Scene/CircleEmitter.js","../../../Source/Scene/computeFlyToLocationForRectangle.js","../../../Source/Scene/ConeEmitter.js","../../../Source/Scene/createElevationBandMaterial.js","../../../Source/Scene/createOsmBuildings.js","../../../Source/Scene/createTangentSpaceDebugPrimitive.js","../../../Source/Scene/UrlTemplateImageryProvider.js","../../../Source/Scene/TileMapServiceImageryProvider.js","../../../Source/Scene/GoogleEarthEnterpriseMapsProvider.js","../../../Source/Scene/MapboxImageryProvider.js","../../../Source/Scene/SingleTileImageryProvider.js","../../../Source/Scene/GetFeatureInfoFormat.js","../../../Source/Scene/TimeDynamicImagery.js","../../../Source/Scene/WebMapServiceImageryProvider.js","../../../Source/Scene/WebMapTileServiceImageryProvider.js","../../../Source/Scene/IonImageryProvider.js","../../../Source/Scene/IonWorldImageryStyle.js","../../../Source/Scene/createWorldImagery.js","../../../Source/Scene/CreditDisplay.js","../../../Source/Scene/DebugAppearance.js","../../../Source/Scene/DebugCameraPrimitive.js","../../../Source/Scene/DebugInspector.js","../../../Source/Scene/DebugModelMatrixPrimitive.js","../../../Source/Shaders/DepthPlaneFS.js","../../../Source/Shaders/DepthPlaneVS.js","../../../Source/Scene/DepthPlane.js","../../../Source/Scene/DerivedCommand.js","../../../Source/Scene/DeviceOrientationCameraController.js","../../../Source/Scene/DirectionalLight.js","../../../Source/Shaders/EllipsoidFS.js","../../../Source/Shaders/EllipsoidVS.js","../../../Source/Scene/EllipsoidPrimitive.js","../../../Source/Shaders/Appearances/EllipsoidSurfaceAppearanceFS.js","../../../Source/Shaders/Appearances/EllipsoidSurfaceAppearanceVS.js","../../../Source/Scene/EllipsoidSurfaceAppearance.js","../../../Source/Scene/Fog.js","../../../Source/Scene/FrameRateMonitor.js","../../../Source/Scene/FrameState.js","../../../Source/Scene/FrustumCommands.js","../../../Source/Shaders/GlobeFS.js","../../../Source/Shaders/GlobeVS.js","../../../Source/Shaders/GroundAtmosphere.js","../../../Source/Scene/GlobeSurfaceShaderSet.js","../../../Source/Scene/ImageryState.js","../../../Source/Scene/QuadtreeTileLoadState.js","../../../Source/Scene/TerrainState.js","../../../Source/Scene/GlobeSurfaceTile.js","../../../Source/Shaders/ReprojectWebMercatorFS.js","../../../Source/Shaders/ReprojectWebMercatorVS.js","../../../Source/Scene/Imagery.js","../../../Source/Scene/ImagerySplitDirection.js","../../../Source/Scene/TileImagery.js","../../../Source/Scene/ImageryLayer.js","../../../Source/Scene/TileSelectionResult.js","../../../Source/Scene/TerrainFillMesh.js","../../../Source/Scene/GlobeSurfaceTileProvider.js","../../../Source/Scene/GlobeTranslucency.js","../../../Source/Scene/ImageryLayerCollection.js","../../../Source/Scene/QuadtreeOccluders.js","../../../Source/Scene/QuadtreeTile.js","../../../Source/Scene/TileReplacementQueue.js","../../../Source/Scene/QuadtreePrimitive.js","../../../Source/Scene/Globe.js","../../../Source/Shaders/PostProcessStages/PassThrough.js","../../../Source/Shaders/PostProcessStages/PassThroughDepth.js","../../../Source/Scene/GlobeDepth.js","../../../Source/Scene/GlobeTranslucencyFramebuffer.js","../../../Source/Scene/GlobeTranslucencyState.js","../../../Source/Scene/GoogleEarthEnterpriseImageryProvider.js","../../../Source/Scene/GridImageryProvider.js","../../../Source/Scene/InvertClassification.js","../../../Source/Scene/JobScheduler.js","../../../Source/Scene/Light.js","../../../Source/Scene/MapboxStyleImageryProvider.js","../../../Source/Scene/Moon.js","../../../Source/Scene/NeverTileDiscardPolicy.js","../../../Source/Shaders/AdjustTranslucentFS.js","../../../Source/Shaders/CompositeOITFS.js","../../../Source/Scene/OIT.js","../../../Source/Scene/OpenStreetMapImageryProvider.js","../../../Source/Scene/Particle.js","../../../Source/Scene/ParticleBurst.js","../../../Source/Scene/ParticleEmitter.js","../../../Source/Scene/ParticleSystem.js","../../../Source/Widgets/getElement.js","../../../Source/Scene/PerformanceDisplay.js","../../../Source/Scene/PickDepth.js","../../../Source/Scene/PickDepthFramebuffer.js","../../../Source/Scene/PickFramebuffer.js","../../../Source/Scene/SceneFramebuffer.js","../../../Source/Scene/ShadowMapShader.js","../../../Source/Scene/ShadowMap.js","../../../Source/Shaders/CompareAndPackTranslucentDepth.js","../../../Source/Shaders/PostProcessStages/CompositeTranslucentClassification.js","../../../Source/Scene/TranslucentTileClassification.js","../../../Source/Scene/View.js","../../../Source/Scene/Picking.js","../../../Source/Scene/PostProcessStageSampleMode.js","../../../Source/Scene/PostProcessStage.js","../../../Source/Shaders/PostProcessStages/AcesTonemappingStage.js","../../../Source/Shaders/PostProcessStages/AmbientOcclusionGenerate.js","../../../Source/Shaders/PostProcessStages/AmbientOcclusionModulate.js","../../../Source/Shaders/PostProcessStages/BlackAndWhite.js","../../../Source/Shaders/PostProcessStages/BloomComposite.js","../../../Source/Shaders/PostProcessStages/Brightness.js","../../../Source/Shaders/PostProcessStages/ContrastBias.js","../../../Source/Shaders/PostProcessStages/DepthOfField.js","../../../Source/Shaders/PostProcessStages/DepthView.js","../../../Source/Shaders/PostProcessStages/EdgeDetection.js","../../../Source/Shaders/PostProcessStages/FilmicTonemapping.js","../../../Source/Shaders/PostProcessStages/FXAA.js","../../../Source/Shaders/PostProcessStages/GaussianBlur1D.js","../../../Source/Shaders/PostProcessStages/LensFlare.js","../../../Source/Shaders/PostProcessStages/ModifiedReinhardTonemapping.js","../../../Source/Shaders/PostProcessStages/NightVision.js","../../../Source/Shaders/PostProcessStages/ReinhardTonemapping.js","../../../Source/Shaders/PostProcessStages/Silhouette.js","../../../Source/ThirdParty/Shaders/FXAA3_11.js","../../../Source/Scene/PostProcessStageComposite.js","../../../Source/Scene/PostProcessStageLibrary.js","../../../Source/Scene/PostProcessStageTextureCache.js","../../../Source/Scene/Tonemapper.js","../../../Source/Scene/PostProcessStageCollection.js","../../../Source/Scene/QuadtreeTileProvider.js","../../../Source/Scene/SceneTransitioner.js","../../../Source/Scene/TweenCollection.js","../../../Source/Scene/ScreenSpaceCameraController.js","../../../Source/Shaders/PostProcessStages/AdditiveBlend.js","../../../Source/Shaders/PostProcessStages/BrightPass.js","../../../Source/Scene/SunPostProcess.js","../../../Source/Scene/Scene.js","../../../Source/Shaders/SkyAtmosphereCommon.js","../../../Source/Shaders/SkyAtmosphereFS.js","../../../Source/Shaders/SkyAtmosphereVS.js","../../../Source/Scene/SkyAtmosphere.js","../../../Source/Shaders/SkyBoxFS.js","../../../Source/Shaders/SkyBoxVS.js","../../../Source/Scene/SkyBox.js","../../../Source/Scene/SphereEmitter.js","../../../Source/Scene/StyleExpression.js","../../../Source/Shaders/SunFS.js","../../../Source/Shaders/SunTextureFS.js","../../../Source/Shaders/SunVS.js","../../../Source/Scene/Sun.js","../../../Source/Scene/TileBoundingVolume.js","../../../Source/Scene/TileCoordinatesImageryProvider.js","../../../Source/Scene/TileDiscardPolicy.js","../../../Source/Scene/TileState.js","../../../Source/Scene/TimeDynamicPointCloud.js","../../../Source/Shaders/ViewportQuadFS.js","../../../Source/Scene/ViewportQuad.js","../../../Source/ThirdParty/knockout-3.5.1.js","../../../Source/ThirdParty/knockout-es5.js","../../../Source/Widgets/SvgPathBindingHandler.js","../../../Source/ThirdParty/knockout.js","../../../Source/ThirdParty/LercDecode.js","../../../Source/ThirdParty/NoSleep.js","../../../Source/ThirdParty/quickselect.js","../../../Source/Widgets/ClockViewModel.js","../../../Source/Widgets/Command.js","../../../Source/Widgets/createCommand.js","../../../Source/Widgets/InspectorShared.js","../../../Source/Widgets/subscribeAndEvaluate.js","../../../Source/Widgets/ToggleButtonViewModel.js","../../../Source/Shaders/PostProcessStages/DepthViewPacked.js","../../../Source/ThirdParty/GltfPipeline/removePipelineExtras.js","../../../Source/Widgets/Animation/Animation.js","../../../Source/Widgets/Animation/AnimationViewModel.js","../../../Source/Widgets/BaseLayerPicker/BaseLayerPickerViewModel.js","../../../Source/Widgets/BaseLayerPicker/BaseLayerPicker.js","../../../Source/Widgets/BaseLayerPicker/ProviderViewModel.js","../../../Source/Widgets/BaseLayerPicker/createDefaultImageryProviderViewModels.js","../../../Source/Widgets/BaseLayerPicker/createDefaultTerrainProviderViewModels.js","../../../Source/Widgets/Cesium3DTilesInspector/Cesium3DTilesInspectorViewModel.js","../../../Source/Widgets/Cesium3DTilesInspector/Cesium3DTilesInspector.js","../../../Source/Widgets/CesiumInspector/CesiumInspectorViewModel.js","../../../Source/Widgets/CesiumInspector/CesiumInspector.js","../../../Source/Widgets/CesiumWidget/CesiumWidget.js","../../../Source/Widgets/FullscreenButton/FullscreenButtonViewModel.js","../../../Source/Widgets/FullscreenButton/FullscreenButton.js","../../../Source/Widgets/Geocoder/GeocoderViewModel.js","../../../Source/Widgets/Geocoder/Geocoder.js","../../../Source/Widgets/HomeButton/HomeButtonViewModel.js","../../../Source/Widgets/HomeButton/HomeButton.js","../../../Source/Widgets/InfoBox/InfoBoxViewModel.js","../../../Source/Widgets/InfoBox/InfoBox.js","../../../Source/Widgets/NavigationHelpButton/NavigationHelpButtonViewModel.js","../../../Source/Widgets/NavigationHelpButton/NavigationHelpButton.js","../../../Source/Widgets/PerformanceWatchdog/PerformanceWatchdogViewModel.js","../../../Source/Widgets/PerformanceWatchdog/PerformanceWatchdog.js","../../../Source/Widgets/ProjectionPicker/ProjectionPickerViewModel.js","../../../Source/Widgets/ProjectionPicker/ProjectionPicker.js","../../../Source/Widgets/SceneModePicker/SceneModePickerViewModel.js","../../../Source/Widgets/SceneModePicker/SceneModePicker.js","../../../Source/Widgets/SelectionIndicator/SelectionIndicatorViewModel.js","../../../Source/Widgets/SelectionIndicator/SelectionIndicator.js","../../../Source/Widgets/Timeline/TimelineHighlightRange.js","../../../Source/Widgets/Timeline/TimelineTrack.js","../../../Source/Widgets/Timeline/Timeline.js","../../../Source/Widgets/VRButton/VRButtonViewModel.js","../../../Source/Widgets/VRButton/VRButton.js","../../../Source/Widgets/Viewer/Viewer.js","../../../Source/Widgets/Viewer/viewerCesium3DTilesInspectorMixin.js","../../../Source/Widgets/Viewer/viewerCesiumInspectorMixin.js","../../../Source/Widgets/Viewer/viewerDragDropMixin.js","../../../Source/Widgets/Viewer/viewerPerformanceWatchdogMixin.js","../../../Source/WorkersES6/createTaskProcessorWorker.js","../../../Source/Cesium.js"],"sourcesContent":["/**\r\n * @private\r\n */\r\nfunction appendForwardSlash(url) {\r\n if (url.length === 0 || url[url.length - 1] !== \"/\") {\r\n url = url + \"/\";\r\n }\r\n return url;\r\n}\r\nexport default appendForwardSlash;\r\n","/**\r\n * @function\r\n *\r\n * @param {*} value The object.\r\n * @returns {Boolean} Returns true if the object is defined, returns false otherwise.\r\n *\r\n * @example\r\n * if (Cesium.defined(positions)) {\r\n * doSomething();\r\n * } else {\r\n * doSomethingElse();\r\n * }\r\n */\r\nfunction defined(value) {\r\n return value !== undefined && value !== null;\r\n}\r\nexport default defined;\r\n","import defined from \"./defined.js\";\r\n\r\n/**\r\n * Constructs an exception object that is thrown due to a developer error, e.g., invalid argument,\r\n * argument out of range, etc. This exception should only be thrown during development;\r\n * it usually indicates a bug in the calling code. This exception should never be\r\n * caught; instead the calling code should strive not to generate it.\r\n * Special cases:\r\n *
\r\n * On the other hand, a {@link RuntimeError} indicates an exception that may\r\n * be thrown at runtime, e.g., out of memory, that the calling code should be prepared\r\n * to catch.\r\n *\r\n * @alias DeveloperError\r\n * @constructor\r\n * @extends Error\r\n *\r\n * @param {String} [message] The error message for this exception.\r\n *\r\n * @see RuntimeError\r\n */\r\nfunction DeveloperError(message) {\r\n /**\r\n * 'DeveloperError' indicating that this exception was thrown due to a developer error.\r\n * @type {String}\r\n * @readonly\r\n */\r\n this.name = \"DeveloperError\";\r\n\r\n /**\r\n * The explanation for why this exception was thrown.\r\n * @type {String}\r\n * @readonly\r\n */\r\n this.message = message;\r\n\r\n //Browsers such as IE don't have a stack property until you actually throw the error.\r\n var stack;\r\n try {\r\n throw new Error();\r\n } catch (e) {\r\n stack = e.stack;\r\n }\r\n\r\n /**\r\n * The stack trace of this exception, if available.\r\n * @type {String}\r\n * @readonly\r\n */\r\n this.stack = stack;\r\n}\r\n\r\nif (defined(Object.create)) {\r\n DeveloperError.prototype = Object.create(Error.prototype);\r\n DeveloperError.prototype.constructor = DeveloperError;\r\n}\r\n\r\nDeveloperError.prototype.toString = function () {\r\n var str = this.name + \": \" + this.message;\r\n\r\n if (defined(this.stack)) {\r\n str += \"\\n\" + this.stack.toString();\r\n }\r\n\r\n return str;\r\n};\r\n\r\n/**\r\n * @private\r\n */\r\nDeveloperError.throwInstantiationError = function () {\r\n throw new DeveloperError(\r\n \"This function defines an interface and should not be called directly.\"\r\n );\r\n};\r\nexport default DeveloperError;\r\n","import defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\n\r\n/**\r\n * Contains functions for checking that supplied arguments are of a specified type\r\n * or meet specified conditions\r\n * @private\r\n */\r\nvar Check = {};\r\n\r\n/**\r\n * Contains type checking functions, all using the typeof operator\r\n */\r\nCheck.typeOf = {};\r\n\r\nfunction getUndefinedErrorMessage(name) {\r\n return name + \" is required, actual value was undefined\";\r\n}\r\n\r\nfunction getFailedTypeErrorMessage(actual, expected, name) {\r\n return (\r\n \"Expected \" +\r\n name +\r\n \" to be typeof \" +\r\n expected +\r\n \", actual typeof was \" +\r\n actual\r\n );\r\n}\r\n\r\n/**\r\n * Throws if test is not defined\r\n *\r\n * @param {String} name The name of the variable being tested\r\n * @param {*} test The value that is to be checked\r\n * @exception {DeveloperError} test must be defined\r\n */\r\nCheck.defined = function (name, test) {\r\n if (!defined(test)) {\r\n throw new DeveloperError(getUndefinedErrorMessage(name));\r\n }\r\n};\r\n\r\n/**\r\n * Throws if test is not typeof 'function'\r\n *\r\n * @param {String} name The name of the variable being tested\r\n * @param {*} test The value to test\r\n * @exception {DeveloperError} test must be typeof 'function'\r\n */\r\nCheck.typeOf.func = function (name, test) {\r\n if (typeof test !== \"function\") {\r\n throw new DeveloperError(\r\n getFailedTypeErrorMessage(typeof test, \"function\", name)\r\n );\r\n }\r\n};\r\n\r\n/**\r\n * Throws if test is not typeof 'string'\r\n *\r\n * @param {String} name The name of the variable being tested\r\n * @param {*} test The value to test\r\n * @exception {DeveloperError} test must be typeof 'string'\r\n */\r\nCheck.typeOf.string = function (name, test) {\r\n if (typeof test !== \"string\") {\r\n throw new DeveloperError(\r\n getFailedTypeErrorMessage(typeof test, \"string\", name)\r\n );\r\n }\r\n};\r\n\r\n/**\r\n * Throws if test is not typeof 'number'\r\n *\r\n * @param {String} name The name of the variable being tested\r\n * @param {*} test The value to test\r\n * @exception {DeveloperError} test must be typeof 'number'\r\n */\r\nCheck.typeOf.number = function (name, test) {\r\n if (typeof test !== \"number\") {\r\n throw new DeveloperError(\r\n getFailedTypeErrorMessage(typeof test, \"number\", name)\r\n );\r\n }\r\n};\r\n\r\n/**\r\n * Throws if test is not typeof 'number' and less than limit\r\n *\r\n * @param {String} name The name of the variable being tested\r\n * @param {*} test The value to test\r\n * @param {Number} limit The limit value to compare against\r\n * @exception {DeveloperError} test must be typeof 'number' and less than limit\r\n */\r\nCheck.typeOf.number.lessThan = function (name, test, limit) {\r\n Check.typeOf.number(name, test);\r\n if (test >= limit) {\r\n throw new DeveloperError(\r\n \"Expected \" +\r\n name +\r\n \" to be less than \" +\r\n limit +\r\n \", actual value was \" +\r\n test\r\n );\r\n }\r\n};\r\n\r\n/**\r\n * Throws if test is not typeof 'number' and less than or equal to limit\r\n *\r\n * @param {String} name The name of the variable being tested\r\n * @param {*} test The value to test\r\n * @param {Number} limit The limit value to compare against\r\n * @exception {DeveloperError} test must be typeof 'number' and less than or equal to limit\r\n */\r\nCheck.typeOf.number.lessThanOrEquals = function (name, test, limit) {\r\n Check.typeOf.number(name, test);\r\n if (test > limit) {\r\n throw new DeveloperError(\r\n \"Expected \" +\r\n name +\r\n \" to be less than or equal to \" +\r\n limit +\r\n \", actual value was \" +\r\n test\r\n );\r\n }\r\n};\r\n\r\n/**\r\n * Throws if test is not typeof 'number' and greater than limit\r\n *\r\n * @param {String} name The name of the variable being tested\r\n * @param {*} test The value to test\r\n * @param {Number} limit The limit value to compare against\r\n * @exception {DeveloperError} test must be typeof 'number' and greater than limit\r\n */\r\nCheck.typeOf.number.greaterThan = function (name, test, limit) {\r\n Check.typeOf.number(name, test);\r\n if (test <= limit) {\r\n throw new DeveloperError(\r\n \"Expected \" +\r\n name +\r\n \" to be greater than \" +\r\n limit +\r\n \", actual value was \" +\r\n test\r\n );\r\n }\r\n};\r\n\r\n/**\r\n * Throws if test is not typeof 'number' and greater than or equal to limit\r\n *\r\n * @param {String} name The name of the variable being tested\r\n * @param {*} test The value to test\r\n * @param {Number} limit The limit value to compare against\r\n * @exception {DeveloperError} test must be typeof 'number' and greater than or equal to limit\r\n */\r\nCheck.typeOf.number.greaterThanOrEquals = function (name, test, limit) {\r\n Check.typeOf.number(name, test);\r\n if (test < limit) {\r\n throw new DeveloperError(\r\n \"Expected \" +\r\n name +\r\n \" to be greater than or equal to\" +\r\n limit +\r\n \", actual value was \" +\r\n test\r\n );\r\n }\r\n};\r\n\r\n/**\r\n * Throws if test is not typeof 'object'\r\n *\r\n * @param {String} name The name of the variable being tested\r\n * @param {*} test The value to test\r\n * @exception {DeveloperError} test must be typeof 'object'\r\n */\r\nCheck.typeOf.object = function (name, test) {\r\n if (typeof test !== \"object\") {\r\n throw new DeveloperError(\r\n getFailedTypeErrorMessage(typeof test, \"object\", name)\r\n );\r\n }\r\n};\r\n\r\n/**\r\n * Throws if test is not typeof 'boolean'\r\n *\r\n * @param {String} name The name of the variable being tested\r\n * @param {*} test The value to test\r\n * @exception {DeveloperError} test must be typeof 'boolean'\r\n */\r\nCheck.typeOf.bool = function (name, test) {\r\n if (typeof test !== \"boolean\") {\r\n throw new DeveloperError(\r\n getFailedTypeErrorMessage(typeof test, \"boolean\", name)\r\n );\r\n }\r\n};\r\n\r\n/**\r\n * Throws if test1 and test2 is not typeof 'number' and not equal in value\r\n *\r\n * @param {String} name1 The name of the first variable being tested\r\n * @param {String} name2 The name of the second variable being tested against\r\n * @param {*} test1 The value to test\r\n * @param {*} test2 The value to test against\r\n * @exception {DeveloperError} test1 and test2 should be type of 'number' and be equal in value\r\n */\r\nCheck.typeOf.number.equals = function (name1, name2, test1, test2) {\r\n Check.typeOf.number(name1, test1);\r\n Check.typeOf.number(name2, test2);\r\n if (test1 !== test2) {\r\n throw new DeveloperError(\r\n name1 +\r\n \" must be equal to \" +\r\n name2 +\r\n \", the actual values are \" +\r\n test1 +\r\n \" and \" +\r\n test2\r\n );\r\n }\r\n};\r\nexport default Check;\r\n","/**\r\n * Returns the first parameter if not undefined, otherwise the second parameter.\r\n * Useful for setting a default value for a parameter.\r\n *\r\n * @function\r\n *\r\n * @param {*} a\r\n * @param {*} b\r\n * @returns {*} Returns the first parameter if not undefined, otherwise the second parameter.\r\n *\r\n * @example\r\n * param = Cesium.defaultValue(param, 'default');\r\n */\r\nfunction defaultValue(a, b) {\r\n if (a !== undefined && a !== null) {\r\n return a;\r\n }\r\n return b;\r\n}\r\n\r\n/**\r\n * A frozen empty object that can be used as the default value for options passed as\r\n * an object literal.\r\n * @type {Object}\r\n * @memberof defaultValue\r\n */\r\ndefaultValue.EMPTY_OBJECT = Object.freeze({});\r\n\r\nexport default defaultValue;\r\n","/*\r\n I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace\r\n so it's better encapsulated. Now you can have multiple random number generators\r\n and they won't stomp all over eachother's state.\r\n\r\n If you want to use this as a substitute for Math.random(), use the random()\r\n method like so:\r\n\r\n var m = new MersenneTwister();\r\n var randomNumber = m.random();\r\n\r\n You can also call the other genrand_{foo}() methods on the instance.\r\n\r\n If you want to use a specific seed in order to get a repeatable random\r\n sequence, pass an integer into the constructor:\r\n\r\n var m = new MersenneTwister(123);\r\n\r\n and that will always produce the same random sequence.\r\n\r\n Sean McCullough (banksean@gmail.com)\r\n*/\r\n\r\n/*\r\n A C-program for MT19937, with initialization improved 2002/1/26.\r\n Coded by Takuji Nishimura and Makoto Matsumoto.\r\n\r\n Before using, initialize the state by using init_genrand(seed)\r\n or init_by_array(init_key, key_length).\r\n*/\r\n/**\r\n@license\r\nmersenne-twister.js - https://gist.github.com/banksean/300494\r\n\r\n Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,\r\n All rights reserved.\r\n\r\n Redistribution and use in source and binary forms, with or without\r\n modification, are permitted provided that the following conditions\r\n are met:\r\n\r\n 1. Redistributions of source code must retain the above copyright\r\n notice, this list of conditions and the following disclaimer.\r\n\r\n 2. Redistributions in binary form must reproduce the above copyright\r\n notice, this list of conditions and the following disclaimer in the\r\n documentation and/or other materials provided with the distribution.\r\n\r\n 3. The names of its contributors may not be used to endorse or promote\r\n products derived from this software without specific prior written\r\n permission.\r\n\r\n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r\n \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r\n LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r\n A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r\n CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r\n EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r\n PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r\n PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r\n SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r\n*/\r\n/*\r\n Any feedback is very welcome.\r\n http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html\r\n email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)\r\n*/\r\n\r\nfunction MersenneTwister(seed) {\r\n if (seed == undefined) {\r\n seed = new Date().getTime();\r\n }\r\n /* Period parameters */\r\n this.N = 624;\r\n this.M = 397;\r\n this.MATRIX_A = 0x9908b0df; /* constant vector a */\r\n this.UPPER_MASK = 0x80000000; /* most significant w-r bits */\r\n this.LOWER_MASK = 0x7fffffff; /* least significant r bits */\r\n\r\n this.mt = new Array(this.N); /* the array for the state vector */\r\n this.mti=this.N+1; /* mti==N+1 means mt[N] is not initialized */\r\n\r\n this.init_genrand(seed);\r\n}\r\n\r\n/* initializes mt[N] with a seed */\r\nMersenneTwister.prototype.init_genrand = function(s) {\r\n this.mt[0] = s >>> 0;\r\n for (this.mti=1; this.mti\r\n *
\r\n *
value
.\r\n */\r\n// eslint-disable-next-line es/no-math-sinh\r\nCesiumMath.sinh = defaultValue(Math.sinh, function sinh(value) {\r\n return (Math.exp(value) - Math.exp(-value)) / 2.0;\r\n});\r\n\r\n/**\r\n * Returns the hyperbolic cosine of a number.\r\n * The hyperbolic cosine of value is defined to be\r\n * (ex + e-x)/2.0\r\n * where e is Euler's number, approximately 2.71828183.\r\n *\r\n * Special cases:\r\n *
value
.\r\n */\r\n// eslint-disable-next-line es/no-math-cosh\r\nCesiumMath.cosh = defaultValue(Math.cosh, function cosh(value) {\r\n return (Math.exp(value) + Math.exp(-value)) / 2.0;\r\n});\r\n\r\n/**\r\n * Computes the linear interpolation of two values.\r\n *\r\n * @param {Number} p The start value to interpolate.\r\n * @param {Number} q The end value to interpolate.\r\n * @param {Number} time The time of interpolation generally in the range [0.0, 1.0]
.\r\n * @returns {Number} The linearly interpolated value.\r\n *\r\n * @example\r\n * var n = Cesium.Math.lerp(0.0, 2.0, 0.5); // returns 1.0\r\n */\r\nCesiumMath.lerp = function (p, q, time) {\r\n return (1.0 - time) * p + time * q;\r\n};\r\n\r\n/**\r\n * pi\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nCesiumMath.PI = Math.PI;\r\n\r\n/**\r\n * 1/pi\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nCesiumMath.ONE_OVER_PI = 1.0 / Math.PI;\r\n\r\n/**\r\n * pi/2\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nCesiumMath.PI_OVER_TWO = Math.PI / 2.0;\r\n\r\n/**\r\n * pi/3\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nCesiumMath.PI_OVER_THREE = Math.PI / 3.0;\r\n\r\n/**\r\n * pi/4\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nCesiumMath.PI_OVER_FOUR = Math.PI / 4.0;\r\n\r\n/**\r\n * pi/6\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nCesiumMath.PI_OVER_SIX = Math.PI / 6.0;\r\n\r\n/**\r\n * 3pi/2\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nCesiumMath.THREE_PI_OVER_TWO = (3.0 * Math.PI) / 2.0;\r\n\r\n/**\r\n * 2pi\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nCesiumMath.TWO_PI = 2.0 * Math.PI;\r\n\r\n/**\r\n * 1/2pi\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nCesiumMath.ONE_OVER_TWO_PI = 1.0 / (2.0 * Math.PI);\r\n\r\n/**\r\n * The number of radians in a degree.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nCesiumMath.RADIANS_PER_DEGREE = Math.PI / 180.0;\r\n\r\n/**\r\n * The number of degrees in a radian.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nCesiumMath.DEGREES_PER_RADIAN = 180.0 / Math.PI;\r\n\r\n/**\r\n * The number of radians in an arc second.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nCesiumMath.RADIANS_PER_ARCSECOND = CesiumMath.RADIANS_PER_DEGREE / 3600.0;\r\n\r\n/**\r\n * Converts degrees to radians.\r\n * @param {Number} degrees The angle to convert in degrees.\r\n * @returns {Number} The corresponding angle in radians.\r\n */\r\nCesiumMath.toRadians = function (degrees) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(degrees)) {\r\n throw new DeveloperError(\"degrees is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n return degrees * CesiumMath.RADIANS_PER_DEGREE;\r\n};\r\n\r\n/**\r\n * Converts radians to degrees.\r\n * @param {Number} radians The angle to convert in radians.\r\n * @returns {Number} The corresponding angle in degrees.\r\n */\r\nCesiumMath.toDegrees = function (radians) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(radians)) {\r\n throw new DeveloperError(\"radians is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n return radians * CesiumMath.DEGREES_PER_RADIAN;\r\n};\r\n\r\n/**\r\n * Converts a longitude value, in radians, to the range [-Math.PI
, Math.PI
).\r\n *\r\n * @param {Number} angle The longitude value, in radians, to convert to the range [-Math.PI
, Math.PI
).\r\n * @returns {Number} The equivalent longitude value in the range [-Math.PI
, Math.PI
).\r\n *\r\n * @example\r\n * // Convert 270 degrees to -90 degrees longitude\r\n * var longitude = Cesium.Math.convertLongitudeRange(Cesium.Math.toRadians(270.0));\r\n */\r\nCesiumMath.convertLongitudeRange = function (angle) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(angle)) {\r\n throw new DeveloperError(\"angle is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n var twoPi = CesiumMath.TWO_PI;\r\n\r\n var simplified = angle - Math.floor(angle / twoPi) * twoPi;\r\n\r\n if (simplified < -Math.PI) {\r\n return simplified + twoPi;\r\n }\r\n if (simplified >= Math.PI) {\r\n return simplified - twoPi;\r\n }\r\n\r\n return simplified;\r\n};\r\n\r\n/**\r\n * Convenience function that clamps a latitude value, in radians, to the range [-Math.PI/2
, Math.PI/2
).\r\n * Useful for sanitizing data before use in objects requiring correct range.\r\n *\r\n * @param {Number} angle The latitude value, in radians, to clamp to the range [-Math.PI/2
, Math.PI/2
).\r\n * @returns {Number} The latitude value clamped to the range [-Math.PI/2
, Math.PI/2
).\r\n *\r\n * @example\r\n * // Clamp 108 degrees latitude to 90 degrees latitude\r\n * var latitude = Cesium.Math.clampToLatitudeRange(Cesium.Math.toRadians(108.0));\r\n */\r\nCesiumMath.clampToLatitudeRange = function (angle) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(angle)) {\r\n throw new DeveloperError(\"angle is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n return CesiumMath.clamp(\r\n angle,\r\n -1 * CesiumMath.PI_OVER_TWO,\r\n CesiumMath.PI_OVER_TWO\r\n );\r\n};\r\n\r\n/**\r\n * Produces an angle in the range -Pi <= angle <= Pi which is equivalent to the provided angle.\r\n *\r\n * @param {Number} angle in radians\r\n * @returns {Number} The angle in the range [-CesiumMath.PI
, CesiumMath.PI
].\r\n */\r\nCesiumMath.negativePiToPi = function (angle) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(angle)) {\r\n throw new DeveloperError(\"angle is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n if (angle >= -CesiumMath.PI && angle <= CesiumMath.PI) {\r\n // Early exit if the input is already inside the range. This avoids\r\n // unnecessary math which could introduce floating point error.\r\n return angle;\r\n }\r\n return CesiumMath.zeroToTwoPi(angle + CesiumMath.PI) - CesiumMath.PI;\r\n};\r\n\r\n/**\r\n * Produces an angle in the range 0 <= angle <= 2Pi which is equivalent to the provided angle.\r\n *\r\n * @param {Number} angle in radians\r\n * @returns {Number} The angle in the range [0, CesiumMath.TWO_PI
].\r\n */\r\nCesiumMath.zeroToTwoPi = function (angle) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(angle)) {\r\n throw new DeveloperError(\"angle is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n if (angle >= 0 && angle <= CesiumMath.TWO_PI) {\r\n // Early exit if the input is already inside the range. This avoids\r\n // unnecessary math which could introduce floating point error.\r\n return angle;\r\n }\r\n var mod = CesiumMath.mod(angle, CesiumMath.TWO_PI);\r\n if (\r\n Math.abs(mod) < CesiumMath.EPSILON14 &&\r\n Math.abs(angle) > CesiumMath.EPSILON14\r\n ) {\r\n return CesiumMath.TWO_PI;\r\n }\r\n return mod;\r\n};\r\n\r\n/**\r\n * The modulo operation that also works for negative dividends.\r\n *\r\n * @param {Number} m The dividend.\r\n * @param {Number} n The divisor.\r\n * @returns {Number} The remainder.\r\n */\r\nCesiumMath.mod = function (m, n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(m)) {\r\n throw new DeveloperError(\"m is required.\");\r\n }\r\n if (!defined(n)) {\r\n throw new DeveloperError(\"n is required.\");\r\n }\r\n if (n === 0.0) {\r\n throw new DeveloperError(\"divisor cannot be 0.\");\r\n }\r\n //>>includeEnd('debug');\r\n if (CesiumMath.sign(m) === CesiumMath.sign(n) && Math.abs(m) < Math.abs(n)) {\r\n // Early exit if the input does not need to be modded. This avoids\r\n // unnecessary math which could introduce floating point error.\r\n return m;\r\n }\r\n\r\n return ((m % n) + n) % n;\r\n};\r\n\r\n/**\r\n * Determines if two values are equal using an absolute or relative tolerance test. This is useful\r\n * to avoid problems due to roundoff error when comparing floating-point values directly. The values are\r\n * first compared using an absolute tolerance test. If that fails, a relative tolerance test is performed.\r\n * Use this test if you are unsure of the magnitudes of left and right.\r\n *\r\n * @param {Number} left The first value to compare.\r\n * @param {Number} right The other value to compare.\r\n * @param {Number} [relativeEpsilon=0] The maximum inclusive delta between left
and right
for the relative tolerance test.\r\n * @param {Number} [absoluteEpsilon=relativeEpsilon] The maximum inclusive delta between left
and right
for the absolute tolerance test.\r\n * @returns {Boolean} true
if the values are equal within the epsilon; otherwise, false
.\r\n *\r\n * @example\r\n * var a = Cesium.Math.equalsEpsilon(0.0, 0.01, Cesium.Math.EPSILON2); // true\r\n * var b = Cesium.Math.equalsEpsilon(0.0, 0.1, Cesium.Math.EPSILON2); // false\r\n * var c = Cesium.Math.equalsEpsilon(3699175.1634344, 3699175.2, Cesium.Math.EPSILON7); // true\r\n * var d = Cesium.Math.equalsEpsilon(3699175.1634344, 3699175.2, Cesium.Math.EPSILON9); // false\r\n */\r\nCesiumMath.equalsEpsilon = function (\r\n left,\r\n right,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(left)) {\r\n throw new DeveloperError(\"left is required.\");\r\n }\r\n if (!defined(right)) {\r\n throw new DeveloperError(\"right is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n relativeEpsilon = defaultValue(relativeEpsilon, 0.0);\r\n absoluteEpsilon = defaultValue(absoluteEpsilon, relativeEpsilon);\r\n var absDiff = Math.abs(left - right);\r\n return (\r\n absDiff <= absoluteEpsilon ||\r\n absDiff <= relativeEpsilon * Math.max(Math.abs(left), Math.abs(right))\r\n );\r\n};\r\n\r\n/**\r\n * Determines if the left value is less than the right value. If the two values are within\r\n * absoluteEpsilon
of each other, they are considered equal and this function returns false.\r\n *\r\n * @param {Number} left The first number to compare.\r\n * @param {Number} right The second number to compare.\r\n * @param {Number} absoluteEpsilon The absolute epsilon to use in comparison.\r\n * @returns {Boolean} true
if left
is less than right
by more than\r\n * absoluteEpsilon. false
if left
is greater or if the two\r\n * values are nearly equal.\r\n */\r\nCesiumMath.lessThan = function (left, right, absoluteEpsilon) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(left)) {\r\n throw new DeveloperError(\"first is required.\");\r\n }\r\n if (!defined(right)) {\r\n throw new DeveloperError(\"second is required.\");\r\n }\r\n if (!defined(absoluteEpsilon)) {\r\n throw new DeveloperError(\"absoluteEpsilon is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n return left - right < -absoluteEpsilon;\r\n};\r\n\r\n/**\r\n * Determines if the left value is less than or equal to the right value. If the two values are within\r\n * absoluteEpsilon
of each other, they are considered equal and this function returns true.\r\n *\r\n * @param {Number} left The first number to compare.\r\n * @param {Number} right The second number to compare.\r\n * @param {Number} absoluteEpsilon The absolute epsilon to use in comparison.\r\n * @returns {Boolean} true
if left
is less than right
or if the\r\n * the values are nearly equal.\r\n */\r\nCesiumMath.lessThanOrEquals = function (left, right, absoluteEpsilon) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(left)) {\r\n throw new DeveloperError(\"first is required.\");\r\n }\r\n if (!defined(right)) {\r\n throw new DeveloperError(\"second is required.\");\r\n }\r\n if (!defined(absoluteEpsilon)) {\r\n throw new DeveloperError(\"absoluteEpsilon is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n return left - right < absoluteEpsilon;\r\n};\r\n\r\n/**\r\n * Determines if the left value is greater the right value. If the two values are within\r\n * absoluteEpsilon
of each other, they are considered equal and this function returns false.\r\n *\r\n * @param {Number} left The first number to compare.\r\n * @param {Number} right The second number to compare.\r\n * @param {Number} absoluteEpsilon The absolute epsilon to use in comparison.\r\n * @returns {Boolean} true
if left
is greater than right
by more than\r\n * absoluteEpsilon. false
if left
is less or if the two\r\n * values are nearly equal.\r\n */\r\nCesiumMath.greaterThan = function (left, right, absoluteEpsilon) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(left)) {\r\n throw new DeveloperError(\"first is required.\");\r\n }\r\n if (!defined(right)) {\r\n throw new DeveloperError(\"second is required.\");\r\n }\r\n if (!defined(absoluteEpsilon)) {\r\n throw new DeveloperError(\"absoluteEpsilon is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n return left - right > absoluteEpsilon;\r\n};\r\n\r\n/**\r\n * Determines if the left value is greater than or equal to the right value. If the two values are within\r\n * absoluteEpsilon
of each other, they are considered equal and this function returns true.\r\n *\r\n * @param {Number} left The first number to compare.\r\n * @param {Number} right The second number to compare.\r\n * @param {Number} absoluteEpsilon The absolute epsilon to use in comparison.\r\n * @returns {Boolean} true
if left
is greater than right
or if the\r\n * the values are nearly equal.\r\n */\r\nCesiumMath.greaterThanOrEquals = function (left, right, absoluteEpsilon) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(left)) {\r\n throw new DeveloperError(\"first is required.\");\r\n }\r\n if (!defined(right)) {\r\n throw new DeveloperError(\"second is required.\");\r\n }\r\n if (!defined(absoluteEpsilon)) {\r\n throw new DeveloperError(\"absoluteEpsilon is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n return left - right > -absoluteEpsilon;\r\n};\r\n\r\nvar factorials = [1];\r\n\r\n/**\r\n * Computes the factorial of the provided number.\r\n *\r\n * @param {Number} n The number whose factorial is to be computed.\r\n * @returns {Number} The factorial of the provided number or undefined if the number is less than 0.\r\n *\r\n * @exception {DeveloperError} A number greater than or equal to 0 is required.\r\n *\r\n *\r\n * @example\r\n * //Compute 7!, which is equal to 5040\r\n * var computedFactorial = Cesium.Math.factorial(7);\r\n *\r\n * @see {@link http://en.wikipedia.org/wiki/Factorial|Factorial on Wikipedia}\r\n */\r\nCesiumMath.factorial = function (n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (typeof n !== \"number\" || n < 0) {\r\n throw new DeveloperError(\r\n \"A number greater than or equal to 0 is required.\"\r\n );\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var length = factorials.length;\r\n if (n >= length) {\r\n var sum = factorials[length - 1];\r\n for (var i = length; i <= n; i++) {\r\n var next = sum * i;\r\n factorials.push(next);\r\n sum = next;\r\n }\r\n }\r\n return factorials[n];\r\n};\r\n\r\n/**\r\n * Increments a number with a wrapping to a minimum value if the number exceeds the maximum value.\r\n *\r\n * @param {Number} [n] The number to be incremented.\r\n * @param {Number} [maximumValue] The maximum incremented value before rolling over to the minimum value.\r\n * @param {Number} [minimumValue=0.0] The number reset to after the maximum value has been exceeded.\r\n * @returns {Number} The incremented number.\r\n *\r\n * @exception {DeveloperError} Maximum value must be greater than minimum value.\r\n *\r\n * @example\r\n * var n = Cesium.Math.incrementWrap(5, 10, 0); // returns 6\r\n * var n = Cesium.Math.incrementWrap(10, 10, 0); // returns 0\r\n */\r\nCesiumMath.incrementWrap = function (n, maximumValue, minimumValue) {\r\n minimumValue = defaultValue(minimumValue, 0.0);\r\n\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(n)) {\r\n throw new DeveloperError(\"n is required.\");\r\n }\r\n if (maximumValue <= minimumValue) {\r\n throw new DeveloperError(\"maximumValue must be greater than minimumValue.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n ++n;\r\n if (n > maximumValue) {\r\n n = minimumValue;\r\n }\r\n return n;\r\n};\r\n\r\n/**\r\n * Determines if a non-negative integer is a power of two.\r\n * The maximum allowed input is (2^32)-1 due to 32-bit bitwise operator limitation in Javascript.\r\n *\r\n * @param {Number} n The integer to test in the range [0, (2^32)-1].\r\n * @returns {Boolean} true
if the number if a power of two; otherwise, false
.\r\n *\r\n * @exception {DeveloperError} A number between 0 and (2^32)-1 is required.\r\n *\r\n * @example\r\n * var t = Cesium.Math.isPowerOfTwo(16); // true\r\n * var f = Cesium.Math.isPowerOfTwo(20); // false\r\n */\r\nCesiumMath.isPowerOfTwo = function (n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (typeof n !== \"number\" || n < 0 || n > 4294967295) {\r\n throw new DeveloperError(\"A number between 0 and (2^32)-1 is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n return n !== 0 && (n & (n - 1)) === 0;\r\n};\r\n\r\n/**\r\n * Computes the next power-of-two integer greater than or equal to the provided non-negative integer.\r\n * The maximum allowed input is 2^31 due to 32-bit bitwise operator limitation in Javascript.\r\n *\r\n * @param {Number} n The integer to test in the range [0, 2^31].\r\n * @returns {Number} The next power-of-two integer.\r\n *\r\n * @exception {DeveloperError} A number between 0 and 2^31 is required.\r\n *\r\n * @example\r\n * var n = Cesium.Math.nextPowerOfTwo(29); // 32\r\n * var m = Cesium.Math.nextPowerOfTwo(32); // 32\r\n */\r\nCesiumMath.nextPowerOfTwo = function (n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (typeof n !== \"number\" || n < 0 || n > 2147483648) {\r\n throw new DeveloperError(\"A number between 0 and 2^31 is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n // From http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2\r\n --n;\r\n n |= n >> 1;\r\n n |= n >> 2;\r\n n |= n >> 4;\r\n n |= n >> 8;\r\n n |= n >> 16;\r\n ++n;\r\n\r\n return n;\r\n};\r\n\r\n/**\r\n * Computes the previous power-of-two integer less than or equal to the provided non-negative integer.\r\n * The maximum allowed input is (2^32)-1 due to 32-bit bitwise operator limitation in Javascript.\r\n *\r\n * @param {Number} n The integer to test in the range [0, (2^32)-1].\r\n * @returns {Number} The previous power-of-two integer.\r\n *\r\n * @exception {DeveloperError} A number between 0 and (2^32)-1 is required.\r\n *\r\n * @example\r\n * var n = Cesium.Math.previousPowerOfTwo(29); // 16\r\n * var m = Cesium.Math.previousPowerOfTwo(32); // 32\r\n */\r\nCesiumMath.previousPowerOfTwo = function (n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (typeof n !== \"number\" || n < 0 || n > 4294967295) {\r\n throw new DeveloperError(\"A number between 0 and (2^32)-1 is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n n |= n >> 1;\r\n n |= n >> 2;\r\n n |= n >> 4;\r\n n |= n >> 8;\r\n n |= n >> 16;\r\n n |= n >> 32;\r\n\r\n // The previous bitwise operations implicitly convert to signed 32-bit. Use `>>>` to convert to unsigned\r\n n = (n >>> 0) - (n >>> 1);\r\n\r\n return n;\r\n};\r\n\r\n/**\r\n * Constraint a value to lie between two values.\r\n *\r\n * @param {Number} value The value to constrain.\r\n * @param {Number} min The minimum value.\r\n * @param {Number} max The maximum value.\r\n * @returns {Number} The value clamped so that min <= value <= max.\r\n */\r\nCesiumMath.clamp = function (value, min, max) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(value)) {\r\n throw new DeveloperError(\"value is required\");\r\n }\r\n if (!defined(min)) {\r\n throw new DeveloperError(\"min is required.\");\r\n }\r\n if (!defined(max)) {\r\n throw new DeveloperError(\"max is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n return value < min ? min : value > max ? max : value;\r\n};\r\n\r\nvar randomNumberGenerator = new MersenneTwister();\r\n\r\n/**\r\n * Sets the seed used by the random number generator\r\n * in {@link CesiumMath#nextRandomNumber}.\r\n *\r\n * @param {Number} seed An integer used as the seed.\r\n */\r\nCesiumMath.setRandomNumberSeed = function (seed) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(seed)) {\r\n throw new DeveloperError(\"seed is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n randomNumberGenerator = new MersenneTwister(seed);\r\n};\r\n\r\n/**\r\n * Generates a random floating point number in the range of [0.0, 1.0)\r\n * using a Mersenne twister.\r\n *\r\n * @returns {Number} A random number in the range of [0.0, 1.0).\r\n *\r\n * @see CesiumMath.setRandomNumberSeed\r\n * @see {@link http://en.wikipedia.org/wiki/Mersenne_twister|Mersenne twister on Wikipedia}\r\n */\r\nCesiumMath.nextRandomNumber = function () {\r\n return randomNumberGenerator.random();\r\n};\r\n\r\n/**\r\n * Generates a random number between two numbers.\r\n *\r\n * @param {Number} min The minimum value.\r\n * @param {Number} max The maximum value.\r\n * @returns {Number} A random number between the min and max.\r\n */\r\nCesiumMath.randomBetween = function (min, max) {\r\n return CesiumMath.nextRandomNumber() * (max - min) + min;\r\n};\r\n\r\n/**\r\n * Computes Math.acos(value)
, but first clamps value
to the range [-1.0, 1.0]\r\n * so that the function will never return NaN.\r\n *\r\n * @param {Number} value The value for which to compute acos.\r\n * @returns {Number} The acos of the value if the value is in the range [-1.0, 1.0], or the acos of -1.0 or 1.0,\r\n * whichever is closer, if the value is outside the range.\r\n */\r\nCesiumMath.acosClamped = function (value) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(value)) {\r\n throw new DeveloperError(\"value is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n return Math.acos(CesiumMath.clamp(value, -1.0, 1.0));\r\n};\r\n\r\n/**\r\n * Computes Math.asin(value)
, but first clamps value
to the range [-1.0, 1.0]\r\n * so that the function will never return NaN.\r\n *\r\n * @param {Number} value The value for which to compute asin.\r\n * @returns {Number} The asin of the value if the value is in the range [-1.0, 1.0], or the asin of -1.0 or 1.0,\r\n * whichever is closer, if the value is outside the range.\r\n */\r\nCesiumMath.asinClamped = function (value) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(value)) {\r\n throw new DeveloperError(\"value is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n return Math.asin(CesiumMath.clamp(value, -1.0, 1.0));\r\n};\r\n\r\n/**\r\n * Finds the chord length between two points given the circle's radius and the angle between the points.\r\n *\r\n * @param {Number} angle The angle between the two points.\r\n * @param {Number} radius The radius of the circle.\r\n * @returns {Number} The chord length.\r\n */\r\nCesiumMath.chordLength = function (angle, radius) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(angle)) {\r\n throw new DeveloperError(\"angle is required.\");\r\n }\r\n if (!defined(radius)) {\r\n throw new DeveloperError(\"radius is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n return 2.0 * radius * Math.sin(angle * 0.5);\r\n};\r\n\r\n/**\r\n * Finds the logarithm of a number to a base.\r\n *\r\n * @param {Number} number The number.\r\n * @param {Number} base The base.\r\n * @returns {Number} The result.\r\n */\r\nCesiumMath.logBase = function (number, base) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(number)) {\r\n throw new DeveloperError(\"number is required.\");\r\n }\r\n if (!defined(base)) {\r\n throw new DeveloperError(\"base is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n return Math.log(number) / Math.log(base);\r\n};\r\n\r\n/**\r\n * Finds the cube root of a number.\r\n * Returns NaN if number
is not provided.\r\n *\r\n * @function\r\n * @param {Number} [number] The number.\r\n * @returns {Number} The result.\r\n */\r\n// eslint-disable-next-line es/no-math-cbrt\r\nCesiumMath.cbrt = defaultValue(Math.cbrt, function cbrt(number) {\r\n var result = Math.pow(Math.abs(number), 1.0 / 3.0);\r\n return number < 0.0 ? -result : result;\r\n});\r\n\r\n/**\r\n * Finds the base 2 logarithm of a number.\r\n *\r\n * @function\r\n * @param {Number} number The number.\r\n * @returns {Number} The result.\r\n */\r\n// eslint-disable-next-line es/no-math-log2\r\nCesiumMath.log2 = defaultValue(Math.log2, function log2(number) {\r\n return Math.log(number) * Math.LOG2E;\r\n});\r\n\r\n/**\r\n * @private\r\n */\r\nCesiumMath.fog = function (distanceToCamera, density) {\r\n var scalar = distanceToCamera * density;\r\n return 1.0 - Math.exp(-(scalar * scalar));\r\n};\r\n\r\n/**\r\n * Computes a fast approximation of Atan for input in the range [-1, 1].\r\n *\r\n * Based on Michal Drobot's approximation from ShaderFastLibs,\r\n * which in turn is based on \"Efficient approximations for the arctangent function,\"\r\n * Rajan, S. Sichun Wang Inkol, R. Joyal, A., May 2006.\r\n * Adapted from ShaderFastLibs under MIT License.\r\n *\r\n * @param {Number} x An input number in the range [-1, 1]\r\n * @returns {Number} An approximation of atan(x)\r\n */\r\nCesiumMath.fastApproximateAtan = function (x) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number(\"x\", x);\r\n //>>includeEnd('debug');\r\n\r\n return x * (-0.1784 * Math.abs(x) - 0.0663 * x * x + 1.0301);\r\n};\r\n\r\n/**\r\n * Computes a fast approximation of Atan2(x, y) for arbitrary input scalars.\r\n *\r\n * Range reduction math based on nvidia's cg reference implementation: http://developer.download.nvidia.com/cg/atan2.html\r\n *\r\n * @param {Number} x An input number that isn't zero if y is zero.\r\n * @param {Number} y An input number that isn't zero if x is zero.\r\n * @returns {Number} An approximation of atan2(x, y)\r\n */\r\nCesiumMath.fastApproximateAtan2 = function (x, y) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number(\"x\", x);\r\n Check.typeOf.number(\"y\", y);\r\n //>>includeEnd('debug');\r\n\r\n // atan approximations are usually only reliable over [-1, 1]\r\n // So reduce the range by flipping whether x or y is on top based on which is bigger.\r\n var opposite;\r\n var adjacent;\r\n var t = Math.abs(x); // t used as swap and atan result.\r\n opposite = Math.abs(y);\r\n adjacent = Math.max(t, opposite);\r\n opposite = Math.min(t, opposite);\r\n\r\n var oppositeOverAdjacent = opposite / adjacent;\r\n //>>includeStart('debug', pragmas.debug);\r\n if (isNaN(oppositeOverAdjacent)) {\r\n throw new DeveloperError(\"either x or y must be nonzero\");\r\n }\r\n //>>includeEnd('debug');\r\n t = CesiumMath.fastApproximateAtan(oppositeOverAdjacent);\r\n\r\n // Undo range reduction\r\n t = Math.abs(y) > Math.abs(x) ? CesiumMath.PI_OVER_TWO - t : t;\r\n t = x < 0.0 ? CesiumMath.PI - t : t;\r\n t = y < 0.0 ? -t : t;\r\n return t;\r\n};\r\nexport default CesiumMath;\r\n","import Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport CesiumMath from \"./Math.js\";\r\n\r\n/**\r\n * A 3D Cartesian point.\r\n * @alias Cartesian3\r\n * @constructor\r\n *\r\n * @param {Number} [x=0.0] The X component.\r\n * @param {Number} [y=0.0] The Y component.\r\n * @param {Number} [z=0.0] The Z component.\r\n *\r\n * @see Cartesian2\r\n * @see Cartesian4\r\n * @see Packable\r\n */\r\nfunction Cartesian3(x, y, z) {\r\n /**\r\n * The X component.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.x = defaultValue(x, 0.0);\r\n\r\n /**\r\n * The Y component.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.y = defaultValue(y, 0.0);\r\n\r\n /**\r\n * The Z component.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.z = defaultValue(z, 0.0);\r\n}\r\n\r\n/**\r\n * Converts the provided Spherical into Cartesian3 coordinates.\r\n *\r\n * @param {Spherical} spherical The Spherical to be converted to Cartesian3.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.\r\n */\r\nCartesian3.fromSpherical = function (spherical, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"spherical\", spherical);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n\r\n var clock = spherical.clock;\r\n var cone = spherical.cone;\r\n var magnitude = defaultValue(spherical.magnitude, 1.0);\r\n var radial = magnitude * Math.sin(cone);\r\n result.x = radial * Math.cos(clock);\r\n result.y = radial * Math.sin(clock);\r\n result.z = magnitude * Math.cos(cone);\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a Cartesian3 instance from x, y and z coordinates.\r\n *\r\n * @param {Number} x The x coordinate.\r\n * @param {Number} y The y coordinate.\r\n * @param {Number} z The z coordinate.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.\r\n */\r\nCartesian3.fromElements = function (x, y, z, result) {\r\n if (!defined(result)) {\r\n return new Cartesian3(x, y, z);\r\n }\r\n\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Duplicates a Cartesian3 instance.\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian to duplicate.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided. (Returns undefined if cartesian is undefined)\r\n */\r\nCartesian3.clone = function (cartesian, result) {\r\n if (!defined(cartesian)) {\r\n return undefined;\r\n }\r\n if (!defined(result)) {\r\n return new Cartesian3(cartesian.x, cartesian.y, cartesian.z);\r\n }\r\n\r\n result.x = cartesian.x;\r\n result.y = cartesian.y;\r\n result.z = cartesian.z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a Cartesian3 instance from an existing Cartesian4. This simply takes the\r\n * x, y, and z properties of the Cartesian4 and drops w.\r\n * @function\r\n *\r\n * @param {Cartesian4} cartesian The Cartesian4 instance to create a Cartesian3 instance from.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.\r\n */\r\nCartesian3.fromCartesian4 = Cartesian3.clone;\r\n\r\n/**\r\n * The number of elements used to pack the object into an array.\r\n * @type {Number}\r\n */\r\nCartesian3.packedLength = 3;\r\n\r\n/**\r\n * Stores the provided instance into the provided array.\r\n *\r\n * @param {Cartesian3} value The value to pack.\r\n * @param {Number[]} array The array to pack into.\r\n * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.\r\n *\r\n * @returns {Number[]} The array that was packed into\r\n */\r\nCartesian3.pack = function (value, array, startingIndex) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"value\", value);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n array[startingIndex++] = value.x;\r\n array[startingIndex++] = value.y;\r\n array[startingIndex] = value.z;\r\n\r\n return array;\r\n};\r\n\r\n/**\r\n * Retrieves an instance from a packed array.\r\n *\r\n * @param {Number[]} array The packed array.\r\n * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.\r\n * @param {Cartesian3} [result] The object into which to store the result.\r\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.\r\n */\r\nCartesian3.unpack = function (array, startingIndex, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n result.x = array[startingIndex++];\r\n result.y = array[startingIndex++];\r\n result.z = array[startingIndex];\r\n return result;\r\n};\r\n\r\n/**\r\n * Flattens an array of Cartesian3s into an array of components.\r\n *\r\n * @param {Cartesian3[]} array The array of cartesians to pack.\r\n * @param {Number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 3 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 3) elements.\r\n * @returns {Number[]} The packed array.\r\n */\r\nCartesian3.packArray = function (array, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n var length = array.length;\r\n var resultLength = length * 3;\r\n if (!defined(result)) {\r\n result = new Array(resultLength);\r\n } else if (!Array.isArray(result) && result.length !== resultLength) {\r\n throw new DeveloperError(\r\n \"If result is a typed array, it must have exactly array.length * 3 elements\"\r\n );\r\n } else if (result.length !== resultLength) {\r\n result.length = resultLength;\r\n }\r\n\r\n for (var i = 0; i < length; ++i) {\r\n Cartesian3.pack(array[i], result, i * 3);\r\n }\r\n return result;\r\n};\r\n\r\n/**\r\n * Unpacks an array of cartesian components into an array of Cartesian3s.\r\n *\r\n * @param {Number[]} array The array of components to unpack.\r\n * @param {Cartesian3[]} [result] The array onto which to store the result.\r\n * @returns {Cartesian3[]} The unpacked array.\r\n */\r\nCartesian3.unpackArray = function (array, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n Check.typeOf.number.greaterThanOrEquals(\"array.length\", array.length, 3);\r\n if (array.length % 3 !== 0) {\r\n throw new DeveloperError(\"array length must be a multiple of 3.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var length = array.length;\r\n if (!defined(result)) {\r\n result = new Array(length / 3);\r\n } else {\r\n result.length = length / 3;\r\n }\r\n\r\n for (var i = 0; i < length; i += 3) {\r\n var index = i / 3;\r\n result[index] = Cartesian3.unpack(array, i, result[index]);\r\n }\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a Cartesian3 from three consecutive elements in an array.\r\n * @function\r\n *\r\n * @param {Number[]} array The array whose three consecutive elements correspond to the x, y, and z components, respectively.\r\n * @param {Number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.\r\n *\r\n * @example\r\n * // Create a Cartesian3 with (1.0, 2.0, 3.0)\r\n * var v = [1.0, 2.0, 3.0];\r\n * var p = Cesium.Cartesian3.fromArray(v);\r\n *\r\n * // Create a Cartesian3 with (1.0, 2.0, 3.0) using an offset into an array\r\n * var v2 = [0.0, 0.0, 1.0, 2.0, 3.0];\r\n * var p2 = Cesium.Cartesian3.fromArray(v2, 2);\r\n */\r\nCartesian3.fromArray = Cartesian3.unpack;\r\n\r\n/**\r\n * Computes the value of the maximum component for the supplied Cartesian.\r\n *\r\n * @param {Cartesian3} cartesian The cartesian to use.\r\n * @returns {Number} The value of the maximum component.\r\n */\r\nCartesian3.maximumComponent = function (cartesian) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n //>>includeEnd('debug');\r\n\r\n return Math.max(cartesian.x, cartesian.y, cartesian.z);\r\n};\r\n\r\n/**\r\n * Computes the value of the minimum component for the supplied Cartesian.\r\n *\r\n * @param {Cartesian3} cartesian The cartesian to use.\r\n * @returns {Number} The value of the minimum component.\r\n */\r\nCartesian3.minimumComponent = function (cartesian) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n //>>includeEnd('debug');\r\n\r\n return Math.min(cartesian.x, cartesian.y, cartesian.z);\r\n};\r\n\r\n/**\r\n * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.\r\n *\r\n * @param {Cartesian3} first A cartesian to compare.\r\n * @param {Cartesian3} second A cartesian to compare.\r\n * @param {Cartesian3} result The object into which to store the result.\r\n * @returns {Cartesian3} A cartesian with the minimum components.\r\n */\r\nCartesian3.minimumByComponent = function (first, second, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"first\", first);\r\n Check.typeOf.object(\"second\", second);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = Math.min(first.x, second.x);\r\n result.y = Math.min(first.y, second.y);\r\n result.z = Math.min(first.z, second.z);\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.\r\n *\r\n * @param {Cartesian3} first A cartesian to compare.\r\n * @param {Cartesian3} second A cartesian to compare.\r\n * @param {Cartesian3} result The object into which to store the result.\r\n * @returns {Cartesian3} A cartesian with the maximum components.\r\n */\r\nCartesian3.maximumByComponent = function (first, second, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"first\", first);\r\n Check.typeOf.object(\"second\", second);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = Math.max(first.x, second.x);\r\n result.y = Math.max(first.y, second.y);\r\n result.z = Math.max(first.z, second.z);\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the provided Cartesian's squared magnitude.\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian instance whose squared magnitude is to be computed.\r\n * @returns {Number} The squared magnitude.\r\n */\r\nCartesian3.magnitudeSquared = function (cartesian) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n //>>includeEnd('debug');\r\n\r\n return (\r\n cartesian.x * cartesian.x +\r\n cartesian.y * cartesian.y +\r\n cartesian.z * cartesian.z\r\n );\r\n};\r\n\r\n/**\r\n * Computes the Cartesian's magnitude (length).\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian instance whose magnitude is to be computed.\r\n * @returns {Number} The magnitude.\r\n */\r\nCartesian3.magnitude = function (cartesian) {\r\n return Math.sqrt(Cartesian3.magnitudeSquared(cartesian));\r\n};\r\n\r\nvar distanceScratch = new Cartesian3();\r\n\r\n/**\r\n * Computes the distance between two points.\r\n *\r\n * @param {Cartesian3} left The first point to compute the distance from.\r\n * @param {Cartesian3} right The second point to compute the distance to.\r\n * @returns {Number} The distance between two points.\r\n *\r\n * @example\r\n * // Returns 1.0\r\n * var d = Cesium.Cartesian3.distance(new Cesium.Cartesian3(1.0, 0.0, 0.0), new Cesium.Cartesian3(2.0, 0.0, 0.0));\r\n */\r\nCartesian3.distance = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n //>>includeEnd('debug');\r\n\r\n Cartesian3.subtract(left, right, distanceScratch);\r\n return Cartesian3.magnitude(distanceScratch);\r\n};\r\n\r\n/**\r\n * Computes the squared distance between two points. Comparing squared distances\r\n * using this function is more efficient than comparing distances using {@link Cartesian3#distance}.\r\n *\r\n * @param {Cartesian3} left The first point to compute the distance from.\r\n * @param {Cartesian3} right The second point to compute the distance to.\r\n * @returns {Number} The distance between two points.\r\n *\r\n * @example\r\n * // Returns 4.0, not 2.0\r\n * var d = Cesium.Cartesian3.distanceSquared(new Cesium.Cartesian3(1.0, 0.0, 0.0), new Cesium.Cartesian3(3.0, 0.0, 0.0));\r\n */\r\nCartesian3.distanceSquared = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n //>>includeEnd('debug');\r\n\r\n Cartesian3.subtract(left, right, distanceScratch);\r\n return Cartesian3.magnitudeSquared(distanceScratch);\r\n};\r\n\r\n/**\r\n * Computes the normalized form of the supplied Cartesian.\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian to be normalized.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n */\r\nCartesian3.normalize = function (cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var magnitude = Cartesian3.magnitude(cartesian);\r\n\r\n result.x = cartesian.x / magnitude;\r\n result.y = cartesian.y / magnitude;\r\n result.z = cartesian.z / magnitude;\r\n\r\n //>>includeStart('debug', pragmas.debug);\r\n if (isNaN(result.x) || isNaN(result.y) || isNaN(result.z)) {\r\n throw new DeveloperError(\"normalized result is not a number\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the dot (scalar) product of two Cartesians.\r\n *\r\n * @param {Cartesian3} left The first Cartesian.\r\n * @param {Cartesian3} right The second Cartesian.\r\n * @returns {Number} The dot product.\r\n */\r\nCartesian3.dot = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n //>>includeEnd('debug');\r\n\r\n return left.x * right.x + left.y * right.y + left.z * right.z;\r\n};\r\n\r\n/**\r\n * Computes the componentwise product of two Cartesians.\r\n *\r\n * @param {Cartesian3} left The first Cartesian.\r\n * @param {Cartesian3} right The second Cartesian.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n */\r\nCartesian3.multiplyComponents = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = left.x * right.x;\r\n result.y = left.y * right.y;\r\n result.z = left.z * right.z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the componentwise quotient of two Cartesians.\r\n *\r\n * @param {Cartesian3} left The first Cartesian.\r\n * @param {Cartesian3} right The second Cartesian.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n */\r\nCartesian3.divideComponents = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = left.x / right.x;\r\n result.y = left.y / right.y;\r\n result.z = left.z / right.z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the componentwise sum of two Cartesians.\r\n *\r\n * @param {Cartesian3} left The first Cartesian.\r\n * @param {Cartesian3} right The second Cartesian.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n */\r\nCartesian3.add = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = left.x + right.x;\r\n result.y = left.y + right.y;\r\n result.z = left.z + right.z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the componentwise difference of two Cartesians.\r\n *\r\n * @param {Cartesian3} left The first Cartesian.\r\n * @param {Cartesian3} right The second Cartesian.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n */\r\nCartesian3.subtract = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = left.x - right.x;\r\n result.y = left.y - right.y;\r\n result.z = left.z - right.z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Multiplies the provided Cartesian componentwise by the provided scalar.\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian to be scaled.\r\n * @param {Number} scalar The scalar to multiply with.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n */\r\nCartesian3.multiplyByScalar = function (cartesian, scalar, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.number(\"scalar\", scalar);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = cartesian.x * scalar;\r\n result.y = cartesian.y * scalar;\r\n result.z = cartesian.z * scalar;\r\n return result;\r\n};\r\n\r\n/**\r\n * Divides the provided Cartesian componentwise by the provided scalar.\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian to be divided.\r\n * @param {Number} scalar The scalar to divide by.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n */\r\nCartesian3.divideByScalar = function (cartesian, scalar, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.number(\"scalar\", scalar);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = cartesian.x / scalar;\r\n result.y = cartesian.y / scalar;\r\n result.z = cartesian.z / scalar;\r\n return result;\r\n};\r\n\r\n/**\r\n * Negates the provided Cartesian.\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian to be negated.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n */\r\nCartesian3.negate = function (cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = -cartesian.x;\r\n result.y = -cartesian.y;\r\n result.z = -cartesian.z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the absolute value of the provided Cartesian.\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian whose absolute value is to be computed.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n */\r\nCartesian3.abs = function (cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = Math.abs(cartesian.x);\r\n result.y = Math.abs(cartesian.y);\r\n result.z = Math.abs(cartesian.z);\r\n return result;\r\n};\r\n\r\nvar lerpScratch = new Cartesian3();\r\n/**\r\n * Computes the linear interpolation or extrapolation at t using the provided cartesians.\r\n *\r\n * @param {Cartesian3} start The value corresponding to t at 0.0.\r\n * @param {Cartesian3} end The value corresponding to t at 1.0.\r\n * @param {Number} t The point along t at which to interpolate.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n */\r\nCartesian3.lerp = function (start, end, t, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"start\", start);\r\n Check.typeOf.object(\"end\", end);\r\n Check.typeOf.number(\"t\", t);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n Cartesian3.multiplyByScalar(end, t, lerpScratch);\r\n result = Cartesian3.multiplyByScalar(start, 1.0 - t, result);\r\n return Cartesian3.add(lerpScratch, result, result);\r\n};\r\n\r\nvar angleBetweenScratch = new Cartesian3();\r\nvar angleBetweenScratch2 = new Cartesian3();\r\n/**\r\n * Returns the angle, in radians, between the provided Cartesians.\r\n *\r\n * @param {Cartesian3} left The first Cartesian.\r\n * @param {Cartesian3} right The second Cartesian.\r\n * @returns {Number} The angle between the Cartesians.\r\n */\r\nCartesian3.angleBetween = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n //>>includeEnd('debug');\r\n\r\n Cartesian3.normalize(left, angleBetweenScratch);\r\n Cartesian3.normalize(right, angleBetweenScratch2);\r\n var cosine = Cartesian3.dot(angleBetweenScratch, angleBetweenScratch2);\r\n var sine = Cartesian3.magnitude(\r\n Cartesian3.cross(\r\n angleBetweenScratch,\r\n angleBetweenScratch2,\r\n angleBetweenScratch\r\n )\r\n );\r\n return Math.atan2(sine, cosine);\r\n};\r\n\r\nvar mostOrthogonalAxisScratch = new Cartesian3();\r\n/**\r\n * Returns the axis that is most orthogonal to the provided Cartesian.\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian on which to find the most orthogonal axis.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The most orthogonal axis.\r\n */\r\nCartesian3.mostOrthogonalAxis = function (cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var f = Cartesian3.normalize(cartesian, mostOrthogonalAxisScratch);\r\n Cartesian3.abs(f, f);\r\n\r\n if (f.x <= f.y) {\r\n if (f.x <= f.z) {\r\n result = Cartesian3.clone(Cartesian3.UNIT_X, result);\r\n } else {\r\n result = Cartesian3.clone(Cartesian3.UNIT_Z, result);\r\n }\r\n } else if (f.y <= f.z) {\r\n result = Cartesian3.clone(Cartesian3.UNIT_Y, result);\r\n } else {\r\n result = Cartesian3.clone(Cartesian3.UNIT_Z, result);\r\n }\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Projects vector a onto vector b\r\n * @param {Cartesian3} a The vector that needs projecting\r\n * @param {Cartesian3} b The vector to project onto\r\n * @param {Cartesian3} result The result cartesian\r\n * @returns {Cartesian3} The modified result parameter\r\n */\r\nCartesian3.projectVector = function (a, b, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"a\", a);\r\n Check.defined(\"b\", b);\r\n Check.defined(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var scalar = Cartesian3.dot(a, b) / Cartesian3.dot(b, b);\r\n return Cartesian3.multiplyByScalar(b, scalar, result);\r\n};\r\n\r\n/**\r\n * Compares the provided Cartesians componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Cartesian3} [left] The first Cartesian.\r\n * @param {Cartesian3} [right] The second Cartesian.\r\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\r\n */\r\nCartesian3.equals = function (left, right) {\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n left.x === right.x &&\r\n left.y === right.y &&\r\n left.z === right.z)\r\n );\r\n};\r\n\r\n/**\r\n * @private\r\n */\r\nCartesian3.equalsArray = function (cartesian, array, offset) {\r\n return (\r\n cartesian.x === array[offset] &&\r\n cartesian.y === array[offset + 1] &&\r\n cartesian.z === array[offset + 2]\r\n );\r\n};\r\n\r\n/**\r\n * Compares the provided Cartesians componentwise and returns\r\n * true
if they pass an absolute or relative tolerance test,\r\n * false
otherwise.\r\n *\r\n * @param {Cartesian3} [left] The first Cartesian.\r\n * @param {Cartesian3} [right] The second Cartesian.\r\n * @param {Number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\r\n * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\r\n * @returns {Boolean} true
if left and right are within the provided epsilon, false
otherwise.\r\n */\r\nCartesian3.equalsEpsilon = function (\r\n left,\r\n right,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n) {\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n CesiumMath.equalsEpsilon(\r\n left.x,\r\n right.x,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n ) &&\r\n CesiumMath.equalsEpsilon(\r\n left.y,\r\n right.y,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n ) &&\r\n CesiumMath.equalsEpsilon(\r\n left.z,\r\n right.z,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n ))\r\n );\r\n};\r\n\r\n/**\r\n * Computes the cross (outer) product of two Cartesians.\r\n *\r\n * @param {Cartesian3} left The first Cartesian.\r\n * @param {Cartesian3} right The second Cartesian.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The cross product.\r\n */\r\nCartesian3.cross = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var leftX = left.x;\r\n var leftY = left.y;\r\n var leftZ = left.z;\r\n var rightX = right.x;\r\n var rightY = right.y;\r\n var rightZ = right.z;\r\n\r\n var x = leftY * rightZ - leftZ * rightY;\r\n var y = leftZ * rightX - leftX * rightZ;\r\n var z = leftX * rightY - leftY * rightX;\r\n\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the midpoint between the right and left Cartesian.\r\n * @param {Cartesian3} left The first Cartesian.\r\n * @param {Cartesian3} right The second Cartesian.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The midpoint.\r\n */\r\nCartesian3.midpoint = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = (left.x + right.x) * 0.5;\r\n result.y = (left.y + right.y) * 0.5;\r\n result.z = (left.z + right.z) * 0.5;\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Returns a Cartesian3 position from longitude and latitude values given in degrees.\r\n *\r\n * @param {Number} longitude The longitude, in degrees\r\n * @param {Number} latitude The latitude, in degrees\r\n * @param {Number} [height=0.0] The height, in meters, above the ellipsoid.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The position\r\n *\r\n * @example\r\n * var position = Cesium.Cartesian3.fromDegrees(-115.0, 37.0);\r\n */\r\nCartesian3.fromDegrees = function (\r\n longitude,\r\n latitude,\r\n height,\r\n ellipsoid,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number(\"longitude\", longitude);\r\n Check.typeOf.number(\"latitude\", latitude);\r\n //>>includeEnd('debug');\r\n\r\n longitude = CesiumMath.toRadians(longitude);\r\n latitude = CesiumMath.toRadians(latitude);\r\n return Cartesian3.fromRadians(longitude, latitude, height, ellipsoid, result);\r\n};\r\n\r\nvar scratchN = new Cartesian3();\r\nvar scratchK = new Cartesian3();\r\nvar wgs84RadiiSquared = new Cartesian3(\r\n 6378137.0 * 6378137.0,\r\n 6378137.0 * 6378137.0,\r\n 6356752.3142451793 * 6356752.3142451793\r\n);\r\n\r\n/**\r\n * Returns a Cartesian3 position from longitude and latitude values given in radians.\r\n *\r\n * @param {Number} longitude The longitude, in radians\r\n * @param {Number} latitude The latitude, in radians\r\n * @param {Number} [height=0.0] The height, in meters, above the ellipsoid.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The position\r\n *\r\n * @example\r\n * var position = Cesium.Cartesian3.fromRadians(-2.007, 0.645);\r\n */\r\nCartesian3.fromRadians = function (\r\n longitude,\r\n latitude,\r\n height,\r\n ellipsoid,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number(\"longitude\", longitude);\r\n Check.typeOf.number(\"latitude\", latitude);\r\n //>>includeEnd('debug');\r\n\r\n height = defaultValue(height, 0.0);\r\n var radiiSquared = defined(ellipsoid)\r\n ? ellipsoid.radiiSquared\r\n : wgs84RadiiSquared;\r\n\r\n var cosLatitude = Math.cos(latitude);\r\n scratchN.x = cosLatitude * Math.cos(longitude);\r\n scratchN.y = cosLatitude * Math.sin(longitude);\r\n scratchN.z = Math.sin(latitude);\r\n scratchN = Cartesian3.normalize(scratchN, scratchN);\r\n\r\n Cartesian3.multiplyComponents(radiiSquared, scratchN, scratchK);\r\n var gamma = Math.sqrt(Cartesian3.dot(scratchN, scratchK));\r\n scratchK = Cartesian3.divideByScalar(scratchK, gamma, scratchK);\r\n scratchN = Cartesian3.multiplyByScalar(scratchN, height, scratchN);\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n return Cartesian3.add(scratchK, scratchN, result);\r\n};\r\n\r\n/**\r\n * Returns an array of Cartesian3 positions given an array of longitude and latitude values given in degrees.\r\n *\r\n * @param {Number[]} coordinates A list of longitude and latitude values. Values alternate [longitude, latitude, longitude, latitude...].\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the coordinates lie.\r\n * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.\r\n * @returns {Cartesian3[]} The array of positions.\r\n *\r\n * @example\r\n * var positions = Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0, -107.0, 33.0]);\r\n */\r\nCartesian3.fromDegreesArray = function (coordinates, ellipsoid, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"coordinates\", coordinates);\r\n if (coordinates.length < 2 || coordinates.length % 2 !== 0) {\r\n throw new DeveloperError(\r\n \"the number of coordinates must be a multiple of 2 and at least 2\"\r\n );\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var length = coordinates.length;\r\n if (!defined(result)) {\r\n result = new Array(length / 2);\r\n } else {\r\n result.length = length / 2;\r\n }\r\n\r\n for (var i = 0; i < length; i += 2) {\r\n var longitude = coordinates[i];\r\n var latitude = coordinates[i + 1];\r\n var index = i / 2;\r\n result[index] = Cartesian3.fromDegrees(\r\n longitude,\r\n latitude,\r\n 0,\r\n ellipsoid,\r\n result[index]\r\n );\r\n }\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Returns an array of Cartesian3 positions given an array of longitude and latitude values given in radians.\r\n *\r\n * @param {Number[]} coordinates A list of longitude and latitude values. Values alternate [longitude, latitude, longitude, latitude...].\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the coordinates lie.\r\n * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.\r\n * @returns {Cartesian3[]} The array of positions.\r\n *\r\n * @example\r\n * var positions = Cesium.Cartesian3.fromRadiansArray([-2.007, 0.645, -1.867, .575]);\r\n */\r\nCartesian3.fromRadiansArray = function (coordinates, ellipsoid, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"coordinates\", coordinates);\r\n if (coordinates.length < 2 || coordinates.length % 2 !== 0) {\r\n throw new DeveloperError(\r\n \"the number of coordinates must be a multiple of 2 and at least 2\"\r\n );\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var length = coordinates.length;\r\n if (!defined(result)) {\r\n result = new Array(length / 2);\r\n } else {\r\n result.length = length / 2;\r\n }\r\n\r\n for (var i = 0; i < length; i += 2) {\r\n var longitude = coordinates[i];\r\n var latitude = coordinates[i + 1];\r\n var index = i / 2;\r\n result[index] = Cartesian3.fromRadians(\r\n longitude,\r\n latitude,\r\n 0,\r\n ellipsoid,\r\n result[index]\r\n );\r\n }\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in degrees.\r\n *\r\n * @param {Number[]} coordinates A list of longitude, latitude and height values. Values alternate [longitude, latitude, height, longitude, latitude, height...].\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.\r\n * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.\r\n * @returns {Cartesian3[]} The array of positions.\r\n *\r\n * @example\r\n * var positions = Cesium.Cartesian3.fromDegreesArrayHeights([-115.0, 37.0, 100000.0, -107.0, 33.0, 150000.0]);\r\n */\r\nCartesian3.fromDegreesArrayHeights = function (coordinates, ellipsoid, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"coordinates\", coordinates);\r\n if (coordinates.length < 3 || coordinates.length % 3 !== 0) {\r\n throw new DeveloperError(\r\n \"the number of coordinates must be a multiple of 3 and at least 3\"\r\n );\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var length = coordinates.length;\r\n if (!defined(result)) {\r\n result = new Array(length / 3);\r\n } else {\r\n result.length = length / 3;\r\n }\r\n\r\n for (var i = 0; i < length; i += 3) {\r\n var longitude = coordinates[i];\r\n var latitude = coordinates[i + 1];\r\n var height = coordinates[i + 2];\r\n var index = i / 3;\r\n result[index] = Cartesian3.fromDegrees(\r\n longitude,\r\n latitude,\r\n height,\r\n ellipsoid,\r\n result[index]\r\n );\r\n }\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in radians.\r\n *\r\n * @param {Number[]} coordinates A list of longitude, latitude and height values. Values alternate [longitude, latitude, height, longitude, latitude, height...].\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.\r\n * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.\r\n * @returns {Cartesian3[]} The array of positions.\r\n *\r\n * @example\r\n * var positions = Cesium.Cartesian3.fromRadiansArrayHeights([-2.007, 0.645, 100000.0, -1.867, .575, 150000.0]);\r\n */\r\nCartesian3.fromRadiansArrayHeights = function (coordinates, ellipsoid, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"coordinates\", coordinates);\r\n if (coordinates.length < 3 || coordinates.length % 3 !== 0) {\r\n throw new DeveloperError(\r\n \"the number of coordinates must be a multiple of 3 and at least 3\"\r\n );\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var length = coordinates.length;\r\n if (!defined(result)) {\r\n result = new Array(length / 3);\r\n } else {\r\n result.length = length / 3;\r\n }\r\n\r\n for (var i = 0; i < length; i += 3) {\r\n var longitude = coordinates[i];\r\n var latitude = coordinates[i + 1];\r\n var height = coordinates[i + 2];\r\n var index = i / 3;\r\n result[index] = Cartesian3.fromRadians(\r\n longitude,\r\n latitude,\r\n height,\r\n ellipsoid,\r\n result[index]\r\n );\r\n }\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * An immutable Cartesian3 instance initialized to (0.0, 0.0, 0.0).\r\n *\r\n * @type {Cartesian3}\r\n * @constant\r\n */\r\nCartesian3.ZERO = Object.freeze(new Cartesian3(0.0, 0.0, 0.0));\r\n\r\n/**\r\n * An immutable Cartesian3 instance initialized to (1.0, 0.0, 0.0).\r\n *\r\n * @type {Cartesian3}\r\n * @constant\r\n */\r\nCartesian3.UNIT_X = Object.freeze(new Cartesian3(1.0, 0.0, 0.0));\r\n\r\n/**\r\n * An immutable Cartesian3 instance initialized to (0.0, 1.0, 0.0).\r\n *\r\n * @type {Cartesian3}\r\n * @constant\r\n */\r\nCartesian3.UNIT_Y = Object.freeze(new Cartesian3(0.0, 1.0, 0.0));\r\n\r\n/**\r\n * An immutable Cartesian3 instance initialized to (0.0, 0.0, 1.0).\r\n *\r\n * @type {Cartesian3}\r\n * @constant\r\n */\r\nCartesian3.UNIT_Z = Object.freeze(new Cartesian3(0.0, 0.0, 1.0));\r\n\r\n/**\r\n * Duplicates this Cartesian3 instance.\r\n *\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.\r\n */\r\nCartesian3.prototype.clone = function (result) {\r\n return Cartesian3.clone(this, result);\r\n};\r\n\r\n/**\r\n * Compares this Cartesian against the provided Cartesian componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Cartesian3} [right] The right hand side Cartesian.\r\n * @returns {Boolean} true
if they are equal, false
otherwise.\r\n */\r\nCartesian3.prototype.equals = function (right) {\r\n return Cartesian3.equals(this, right);\r\n};\r\n\r\n/**\r\n * Compares this Cartesian against the provided Cartesian componentwise and returns\r\n * true
if they pass an absolute or relative tolerance test,\r\n * false
otherwise.\r\n *\r\n * @param {Cartesian3} [right] The right hand side Cartesian.\r\n * @param {Number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\r\n * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\r\n * @returns {Boolean} true
if they are within the provided epsilon, false
otherwise.\r\n */\r\nCartesian3.prototype.equalsEpsilon = function (\r\n right,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n) {\r\n return Cartesian3.equalsEpsilon(\r\n this,\r\n right,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n );\r\n};\r\n\r\n/**\r\n * Creates a string representing this Cartesian in the format '(x, y, z)'.\r\n *\r\n * @returns {String} A string representing this Cartesian in the format '(x, y, z)'.\r\n */\r\nCartesian3.prototype.toString = function () {\r\n return \"(\" + this.x + \", \" + this.y + \", \" + this.z + \")\";\r\n};\r\nexport default Cartesian3;\r\n","import Cartesian3 from \"./Cartesian3.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport CesiumMath from \"./Math.js\";\r\n\r\nvar scaleToGeodeticSurfaceIntersection = new Cartesian3();\r\nvar scaleToGeodeticSurfaceGradient = new Cartesian3();\r\n\r\n/**\r\n * Scales the provided Cartesian position along the geodetic surface normal\r\n * so that it is on the surface of this ellipsoid. If the position is\r\n * at the center of the ellipsoid, this function returns undefined.\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian position to scale.\r\n * @param {Cartesian3} oneOverRadii One over radii of the ellipsoid.\r\n * @param {Cartesian3} oneOverRadiiSquared One over radii squared of the ellipsoid.\r\n * @param {Number} centerToleranceSquared Tolerance for closeness to the center.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter, a new Cartesian3 instance if none was provided, or undefined if the position is at the center.\r\n *\r\n * @function scaleToGeodeticSurface\r\n *\r\n * @private\r\n */\r\nfunction scaleToGeodeticSurface(\r\n cartesian,\r\n oneOverRadii,\r\n oneOverRadiiSquared,\r\n centerToleranceSquared,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(cartesian)) {\r\n throw new DeveloperError(\"cartesian is required.\");\r\n }\r\n if (!defined(oneOverRadii)) {\r\n throw new DeveloperError(\"oneOverRadii is required.\");\r\n }\r\n if (!defined(oneOverRadiiSquared)) {\r\n throw new DeveloperError(\"oneOverRadiiSquared is required.\");\r\n }\r\n if (!defined(centerToleranceSquared)) {\r\n throw new DeveloperError(\"centerToleranceSquared is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var positionX = cartesian.x;\r\n var positionY = cartesian.y;\r\n var positionZ = cartesian.z;\r\n\r\n var oneOverRadiiX = oneOverRadii.x;\r\n var oneOverRadiiY = oneOverRadii.y;\r\n var oneOverRadiiZ = oneOverRadii.z;\r\n\r\n var x2 = positionX * positionX * oneOverRadiiX * oneOverRadiiX;\r\n var y2 = positionY * positionY * oneOverRadiiY * oneOverRadiiY;\r\n var z2 = positionZ * positionZ * oneOverRadiiZ * oneOverRadiiZ;\r\n\r\n // Compute the squared ellipsoid norm.\r\n var squaredNorm = x2 + y2 + z2;\r\n var ratio = Math.sqrt(1.0 / squaredNorm);\r\n\r\n // As an initial approximation, assume that the radial intersection is the projection point.\r\n var intersection = Cartesian3.multiplyByScalar(\r\n cartesian,\r\n ratio,\r\n scaleToGeodeticSurfaceIntersection\r\n );\r\n\r\n // If the position is near the center, the iteration will not converge.\r\n if (squaredNorm < centerToleranceSquared) {\r\n return !isFinite(ratio)\r\n ? undefined\r\n : Cartesian3.clone(intersection, result);\r\n }\r\n\r\n var oneOverRadiiSquaredX = oneOverRadiiSquared.x;\r\n var oneOverRadiiSquaredY = oneOverRadiiSquared.y;\r\n var oneOverRadiiSquaredZ = oneOverRadiiSquared.z;\r\n\r\n // Use the gradient at the intersection point in place of the true unit normal.\r\n // The difference in magnitude will be absorbed in the multiplier.\r\n var gradient = scaleToGeodeticSurfaceGradient;\r\n gradient.x = intersection.x * oneOverRadiiSquaredX * 2.0;\r\n gradient.y = intersection.y * oneOverRadiiSquaredY * 2.0;\r\n gradient.z = intersection.z * oneOverRadiiSquaredZ * 2.0;\r\n\r\n // Compute the initial guess at the normal vector multiplier, lambda.\r\n var lambda =\r\n ((1.0 - ratio) * Cartesian3.magnitude(cartesian)) /\r\n (0.5 * Cartesian3.magnitude(gradient));\r\n var correction = 0.0;\r\n\r\n var func;\r\n var denominator;\r\n var xMultiplier;\r\n var yMultiplier;\r\n var zMultiplier;\r\n var xMultiplier2;\r\n var yMultiplier2;\r\n var zMultiplier2;\r\n var xMultiplier3;\r\n var yMultiplier3;\r\n var zMultiplier3;\r\n\r\n do {\r\n lambda -= correction;\r\n\r\n xMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredX);\r\n yMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredY);\r\n zMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredZ);\r\n\r\n xMultiplier2 = xMultiplier * xMultiplier;\r\n yMultiplier2 = yMultiplier * yMultiplier;\r\n zMultiplier2 = zMultiplier * zMultiplier;\r\n\r\n xMultiplier3 = xMultiplier2 * xMultiplier;\r\n yMultiplier3 = yMultiplier2 * yMultiplier;\r\n zMultiplier3 = zMultiplier2 * zMultiplier;\r\n\r\n func = x2 * xMultiplier2 + y2 * yMultiplier2 + z2 * zMultiplier2 - 1.0;\r\n\r\n // \"denominator\" here refers to the use of this expression in the velocity and acceleration\r\n // computations in the sections to follow.\r\n denominator =\r\n x2 * xMultiplier3 * oneOverRadiiSquaredX +\r\n y2 * yMultiplier3 * oneOverRadiiSquaredY +\r\n z2 * zMultiplier3 * oneOverRadiiSquaredZ;\r\n\r\n var derivative = -2.0 * denominator;\r\n\r\n correction = func / derivative;\r\n } while (Math.abs(func) > CesiumMath.EPSILON12);\r\n\r\n if (!defined(result)) {\r\n return new Cartesian3(\r\n positionX * xMultiplier,\r\n positionY * yMultiplier,\r\n positionZ * zMultiplier\r\n );\r\n }\r\n result.x = positionX * xMultiplier;\r\n result.y = positionY * yMultiplier;\r\n result.z = positionZ * zMultiplier;\r\n return result;\r\n}\r\nexport default scaleToGeodeticSurface;\r\n","import Cartesian3 from \"./Cartesian3.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport CesiumMath from \"./Math.js\";\r\nimport scaleToGeodeticSurface from \"./scaleToGeodeticSurface.js\";\r\n\r\n/**\r\n * A position defined by longitude, latitude, and height.\r\n * @alias Cartographic\r\n * @constructor\r\n *\r\n * @param {Number} [longitude=0.0] The longitude, in radians.\r\n * @param {Number} [latitude=0.0] The latitude, in radians.\r\n * @param {Number} [height=0.0] The height, in meters, above the ellipsoid.\r\n *\r\n * @see Ellipsoid\r\n */\r\nfunction Cartographic(longitude, latitude, height) {\r\n /**\r\n * The longitude, in radians.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.longitude = defaultValue(longitude, 0.0);\r\n\r\n /**\r\n * The latitude, in radians.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.latitude = defaultValue(latitude, 0.0);\r\n\r\n /**\r\n * The height, in meters, above the ellipsoid.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.height = defaultValue(height, 0.0);\r\n}\r\n\r\n/**\r\n * Creates a new Cartographic instance from longitude and latitude\r\n * specified in radians.\r\n *\r\n * @param {Number} longitude The longitude, in radians.\r\n * @param {Number} latitude The latitude, in radians.\r\n * @param {Number} [height=0.0] The height, in meters, above the ellipsoid.\r\n * @param {Cartographic} [result] The object onto which to store the result.\r\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.\r\n */\r\nCartographic.fromRadians = function (longitude, latitude, height, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number(\"longitude\", longitude);\r\n Check.typeOf.number(\"latitude\", latitude);\r\n //>>includeEnd('debug');\r\n\r\n height = defaultValue(height, 0.0);\r\n\r\n if (!defined(result)) {\r\n return new Cartographic(longitude, latitude, height);\r\n }\r\n\r\n result.longitude = longitude;\r\n result.latitude = latitude;\r\n result.height = height;\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a new Cartographic instance from longitude and latitude\r\n * specified in degrees. The values in the resulting object will\r\n * be in radians.\r\n *\r\n * @param {Number} longitude The longitude, in degrees.\r\n * @param {Number} latitude The latitude, in degrees.\r\n * @param {Number} [height=0.0] The height, in meters, above the ellipsoid.\r\n * @param {Cartographic} [result] The object onto which to store the result.\r\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.\r\n */\r\nCartographic.fromDegrees = function (longitude, latitude, height, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number(\"longitude\", longitude);\r\n Check.typeOf.number(\"latitude\", latitude);\r\n //>>includeEnd('debug');\r\n longitude = CesiumMath.toRadians(longitude);\r\n latitude = CesiumMath.toRadians(latitude);\r\n\r\n return Cartographic.fromRadians(longitude, latitude, height, result);\r\n};\r\n\r\nvar cartesianToCartographicN = new Cartesian3();\r\nvar cartesianToCartographicP = new Cartesian3();\r\nvar cartesianToCartographicH = new Cartesian3();\r\nvar wgs84OneOverRadii = new Cartesian3(\r\n 1.0 / 6378137.0,\r\n 1.0 / 6378137.0,\r\n 1.0 / 6356752.3142451793\r\n);\r\nvar wgs84OneOverRadiiSquared = new Cartesian3(\r\n 1.0 / (6378137.0 * 6378137.0),\r\n 1.0 / (6378137.0 * 6378137.0),\r\n 1.0 / (6356752.3142451793 * 6356752.3142451793)\r\n);\r\nvar wgs84CenterToleranceSquared = CesiumMath.EPSILON1;\r\n\r\n/**\r\n * Creates a new Cartographic instance from a Cartesian position. The values in the\r\n * resulting object will be in radians.\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian position to convert to cartographic representation.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.\r\n * @param {Cartographic} [result] The object onto which to store the result.\r\n * @returns {Cartographic} The modified result parameter, new Cartographic instance if none was provided, or undefined if the cartesian is at the center of the ellipsoid.\r\n */\r\nCartographic.fromCartesian = function (cartesian, ellipsoid, result) {\r\n var oneOverRadii = defined(ellipsoid)\r\n ? ellipsoid.oneOverRadii\r\n : wgs84OneOverRadii;\r\n var oneOverRadiiSquared = defined(ellipsoid)\r\n ? ellipsoid.oneOverRadiiSquared\r\n : wgs84OneOverRadiiSquared;\r\n var centerToleranceSquared = defined(ellipsoid)\r\n ? ellipsoid._centerToleranceSquared\r\n : wgs84CenterToleranceSquared;\r\n\r\n //`cartesian is required.` is thrown from scaleToGeodeticSurface\r\n var p = scaleToGeodeticSurface(\r\n cartesian,\r\n oneOverRadii,\r\n oneOverRadiiSquared,\r\n centerToleranceSquared,\r\n cartesianToCartographicP\r\n );\r\n\r\n if (!defined(p)) {\r\n return undefined;\r\n }\r\n\r\n var n = Cartesian3.multiplyComponents(\r\n p,\r\n oneOverRadiiSquared,\r\n cartesianToCartographicN\r\n );\r\n n = Cartesian3.normalize(n, n);\r\n\r\n var h = Cartesian3.subtract(cartesian, p, cartesianToCartographicH);\r\n\r\n var longitude = Math.atan2(n.y, n.x);\r\n var latitude = Math.asin(n.z);\r\n var height =\r\n CesiumMath.sign(Cartesian3.dot(h, cartesian)) * Cartesian3.magnitude(h);\r\n\r\n if (!defined(result)) {\r\n return new Cartographic(longitude, latitude, height);\r\n }\r\n result.longitude = longitude;\r\n result.latitude = latitude;\r\n result.height = height;\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a new Cartesian3 instance from a Cartographic input. The values in the inputted\r\n * object should be in radians.\r\n *\r\n * @param {Cartographic} cartographic Input to be converted into a Cartesian3 output.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The position\r\n */\r\nCartographic.toCartesian = function (cartographic, ellipsoid, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"cartographic\", cartographic);\r\n //>>includeEnd('debug');\r\n\r\n return Cartesian3.fromRadians(\r\n cartographic.longitude,\r\n cartographic.latitude,\r\n cartographic.height,\r\n ellipsoid,\r\n result\r\n );\r\n};\r\n\r\n/**\r\n * Duplicates a Cartographic instance.\r\n *\r\n * @param {Cartographic} cartographic The cartographic to duplicate.\r\n * @param {Cartographic} [result] The object onto which to store the result.\r\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided. (Returns undefined if cartographic is undefined)\r\n */\r\nCartographic.clone = function (cartographic, result) {\r\n if (!defined(cartographic)) {\r\n return undefined;\r\n }\r\n if (!defined(result)) {\r\n return new Cartographic(\r\n cartographic.longitude,\r\n cartographic.latitude,\r\n cartographic.height\r\n );\r\n }\r\n result.longitude = cartographic.longitude;\r\n result.latitude = cartographic.latitude;\r\n result.height = cartographic.height;\r\n return result;\r\n};\r\n\r\n/**\r\n * Compares the provided cartographics componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Cartographic} [left] The first cartographic.\r\n * @param {Cartographic} [right] The second cartographic.\r\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\r\n */\r\nCartographic.equals = function (left, right) {\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n left.longitude === right.longitude &&\r\n left.latitude === right.latitude &&\r\n left.height === right.height)\r\n );\r\n};\r\n\r\n/**\r\n * Compares the provided cartographics componentwise and returns\r\n * true
if they are within the provided epsilon,\r\n * false
otherwise.\r\n *\r\n * @param {Cartographic} [left] The first cartographic.\r\n * @param {Cartographic} [right] The second cartographic.\r\n * @param {Number} [epsilon=0] The epsilon to use for equality testing.\r\n * @returns {Boolean} true
if left and right are within the provided epsilon, false
otherwise.\r\n */\r\nCartographic.equalsEpsilon = function (left, right, epsilon) {\r\n epsilon = defaultValue(epsilon, 0);\r\n\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n Math.abs(left.longitude - right.longitude) <= epsilon &&\r\n Math.abs(left.latitude - right.latitude) <= epsilon &&\r\n Math.abs(left.height - right.height) <= epsilon)\r\n );\r\n};\r\n\r\n/**\r\n * An immutable Cartographic instance initialized to (0.0, 0.0, 0.0).\r\n *\r\n * @type {Cartographic}\r\n * @constant\r\n */\r\nCartographic.ZERO = Object.freeze(new Cartographic(0.0, 0.0, 0.0));\r\n\r\n/**\r\n * Duplicates this instance.\r\n *\r\n * @param {Cartographic} [result] The object onto which to store the result.\r\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.\r\n */\r\nCartographic.prototype.clone = function (result) {\r\n return Cartographic.clone(this, result);\r\n};\r\n\r\n/**\r\n * Compares the provided against this cartographic componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Cartographic} [right] The second cartographic.\r\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\r\n */\r\nCartographic.prototype.equals = function (right) {\r\n return Cartographic.equals(this, right);\r\n};\r\n\r\n/**\r\n * Compares the provided against this cartographic componentwise and returns\r\n * true
if they are within the provided epsilon,\r\n * false
otherwise.\r\n *\r\n * @param {Cartographic} [right] The second cartographic.\r\n * @param {Number} [epsilon=0] The epsilon to use for equality testing.\r\n * @returns {Boolean} true
if left and right are within the provided epsilon, false
otherwise.\r\n */\r\nCartographic.prototype.equalsEpsilon = function (right, epsilon) {\r\n return Cartographic.equalsEpsilon(this, right, epsilon);\r\n};\r\n\r\n/**\r\n * Creates a string representing this cartographic in the format '(longitude, latitude, height)'.\r\n *\r\n * @returns {String} A string representing the provided cartographic in the format '(longitude, latitude, height)'.\r\n */\r\nCartographic.prototype.toString = function () {\r\n return \"(\" + this.longitude + \", \" + this.latitude + \", \" + this.height + \")\";\r\n};\r\nexport default Cartographic;\r\n","import Cartesian3 from \"./Cartesian3.js\";\r\nimport Cartographic from \"./Cartographic.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport CesiumMath from \"./Math.js\";\r\nimport scaleToGeodeticSurface from \"./scaleToGeodeticSurface.js\";\r\n\r\nfunction initialize(ellipsoid, x, y, z) {\r\n x = defaultValue(x, 0.0);\r\n y = defaultValue(y, 0.0);\r\n z = defaultValue(z, 0.0);\r\n\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number.greaterThanOrEquals(\"x\", x, 0.0);\r\n Check.typeOf.number.greaterThanOrEquals(\"y\", y, 0.0);\r\n Check.typeOf.number.greaterThanOrEquals(\"z\", z, 0.0);\r\n //>>includeEnd('debug');\r\n\r\n ellipsoid._radii = new Cartesian3(x, y, z);\r\n\r\n ellipsoid._radiiSquared = new Cartesian3(x * x, y * y, z * z);\r\n\r\n ellipsoid._radiiToTheFourth = new Cartesian3(\r\n x * x * x * x,\r\n y * y * y * y,\r\n z * z * z * z\r\n );\r\n\r\n ellipsoid._oneOverRadii = new Cartesian3(\r\n x === 0.0 ? 0.0 : 1.0 / x,\r\n y === 0.0 ? 0.0 : 1.0 / y,\r\n z === 0.0 ? 0.0 : 1.0 / z\r\n );\r\n\r\n ellipsoid._oneOverRadiiSquared = new Cartesian3(\r\n x === 0.0 ? 0.0 : 1.0 / (x * x),\r\n y === 0.0 ? 0.0 : 1.0 / (y * y),\r\n z === 0.0 ? 0.0 : 1.0 / (z * z)\r\n );\r\n\r\n ellipsoid._minimumRadius = Math.min(x, y, z);\r\n\r\n ellipsoid._maximumRadius = Math.max(x, y, z);\r\n\r\n ellipsoid._centerToleranceSquared = CesiumMath.EPSILON1;\r\n\r\n if (ellipsoid._radiiSquared.z !== 0) {\r\n ellipsoid._squaredXOverSquaredZ =\r\n ellipsoid._radiiSquared.x / ellipsoid._radiiSquared.z;\r\n }\r\n}\r\n\r\n/**\r\n * A quadratic surface defined in Cartesian coordinates by the equation\r\n * (x / a)^2 + (y / b)^2 + (z / c)^2 = 1
. Primarily used\r\n * by Cesium to represent the shape of planetary bodies.\r\n *\r\n * Rather than constructing this object directly, one of the provided\r\n * constants is normally used.\r\n * @alias Ellipsoid\r\n * @constructor\r\n *\r\n * @param {Number} [x=0] The radius in the x direction.\r\n * @param {Number} [y=0] The radius in the y direction.\r\n * @param {Number} [z=0] The radius in the z direction.\r\n *\r\n * @exception {DeveloperError} All radii components must be greater than or equal to zero.\r\n *\r\n * @see Ellipsoid.fromCartesian3\r\n * @see Ellipsoid.WGS84\r\n * @see Ellipsoid.UNIT_SPHERE\r\n */\r\nfunction Ellipsoid(x, y, z) {\r\n this._radii = undefined;\r\n this._radiiSquared = undefined;\r\n this._radiiToTheFourth = undefined;\r\n this._oneOverRadii = undefined;\r\n this._oneOverRadiiSquared = undefined;\r\n this._minimumRadius = undefined;\r\n this._maximumRadius = undefined;\r\n this._centerToleranceSquared = undefined;\r\n this._squaredXOverSquaredZ = undefined;\r\n\r\n initialize(this, x, y, z);\r\n}\r\n\r\nObject.defineProperties(Ellipsoid.prototype, {\r\n /**\r\n * Gets the radii of the ellipsoid.\r\n * @memberof Ellipsoid.prototype\r\n * @type {Cartesian3}\r\n * @readonly\r\n */\r\n radii: {\r\n get: function () {\r\n return this._radii;\r\n },\r\n },\r\n /**\r\n * Gets the squared radii of the ellipsoid.\r\n * @memberof Ellipsoid.prototype\r\n * @type {Cartesian3}\r\n * @readonly\r\n */\r\n radiiSquared: {\r\n get: function () {\r\n return this._radiiSquared;\r\n },\r\n },\r\n /**\r\n * Gets the radii of the ellipsoid raise to the fourth power.\r\n * @memberof Ellipsoid.prototype\r\n * @type {Cartesian3}\r\n * @readonly\r\n */\r\n radiiToTheFourth: {\r\n get: function () {\r\n return this._radiiToTheFourth;\r\n },\r\n },\r\n /**\r\n * Gets one over the radii of the ellipsoid.\r\n * @memberof Ellipsoid.prototype\r\n * @type {Cartesian3}\r\n * @readonly\r\n */\r\n oneOverRadii: {\r\n get: function () {\r\n return this._oneOverRadii;\r\n },\r\n },\r\n /**\r\n * Gets one over the squared radii of the ellipsoid.\r\n * @memberof Ellipsoid.prototype\r\n * @type {Cartesian3}\r\n * @readonly\r\n */\r\n oneOverRadiiSquared: {\r\n get: function () {\r\n return this._oneOverRadiiSquared;\r\n },\r\n },\r\n /**\r\n * Gets the minimum radius of the ellipsoid.\r\n * @memberof Ellipsoid.prototype\r\n * @type {Number}\r\n * @readonly\r\n */\r\n minimumRadius: {\r\n get: function () {\r\n return this._minimumRadius;\r\n },\r\n },\r\n /**\r\n * Gets the maximum radius of the ellipsoid.\r\n * @memberof Ellipsoid.prototype\r\n * @type {Number}\r\n * @readonly\r\n */\r\n maximumRadius: {\r\n get: function () {\r\n return this._maximumRadius;\r\n },\r\n },\r\n});\r\n\r\n/**\r\n * Duplicates an Ellipsoid instance.\r\n *\r\n * @param {Ellipsoid} ellipsoid The ellipsoid to duplicate.\r\n * @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new\r\n * instance should be created.\r\n * @returns {Ellipsoid} The cloned Ellipsoid. (Returns undefined if ellipsoid is undefined)\r\n */\r\nEllipsoid.clone = function (ellipsoid, result) {\r\n if (!defined(ellipsoid)) {\r\n return undefined;\r\n }\r\n var radii = ellipsoid._radii;\r\n\r\n if (!defined(result)) {\r\n return new Ellipsoid(radii.x, radii.y, radii.z);\r\n }\r\n\r\n Cartesian3.clone(radii, result._radii);\r\n Cartesian3.clone(ellipsoid._radiiSquared, result._radiiSquared);\r\n Cartesian3.clone(ellipsoid._radiiToTheFourth, result._radiiToTheFourth);\r\n Cartesian3.clone(ellipsoid._oneOverRadii, result._oneOverRadii);\r\n Cartesian3.clone(ellipsoid._oneOverRadiiSquared, result._oneOverRadiiSquared);\r\n result._minimumRadius = ellipsoid._minimumRadius;\r\n result._maximumRadius = ellipsoid._maximumRadius;\r\n result._centerToleranceSquared = ellipsoid._centerToleranceSquared;\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions.\r\n *\r\n * @param {Cartesian3} [cartesian=Cartesian3.ZERO] The ellipsoid's radius in the x, y, and z directions.\r\n * @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new\r\n * instance should be created.\r\n * @returns {Ellipsoid} A new Ellipsoid instance.\r\n *\r\n * @exception {DeveloperError} All radii components must be greater than or equal to zero.\r\n *\r\n * @see Ellipsoid.WGS84\r\n * @see Ellipsoid.UNIT_SPHERE\r\n */\r\nEllipsoid.fromCartesian3 = function (cartesian, result) {\r\n if (!defined(result)) {\r\n result = new Ellipsoid();\r\n }\r\n\r\n if (!defined(cartesian)) {\r\n return result;\r\n }\r\n\r\n initialize(result, cartesian.x, cartesian.y, cartesian.z);\r\n return result;\r\n};\r\n\r\n/**\r\n * An Ellipsoid instance initialized to the WGS84 standard.\r\n *\r\n * @type {Ellipsoid}\r\n * @constant\r\n */\r\nEllipsoid.WGS84 = Object.freeze(\r\n new Ellipsoid(6378137.0, 6378137.0, 6356752.3142451793)\r\n);\r\n\r\n/**\r\n * An Ellipsoid instance initialized to radii of (1.0, 1.0, 1.0).\r\n *\r\n * @type {Ellipsoid}\r\n * @constant\r\n */\r\nEllipsoid.UNIT_SPHERE = Object.freeze(new Ellipsoid(1.0, 1.0, 1.0));\r\n\r\n/**\r\n * An Ellipsoid instance initialized to a sphere with the lunar radius.\r\n *\r\n * @type {Ellipsoid}\r\n * @constant\r\n */\r\nEllipsoid.MOON = Object.freeze(\r\n new Ellipsoid(\r\n CesiumMath.LUNAR_RADIUS,\r\n CesiumMath.LUNAR_RADIUS,\r\n CesiumMath.LUNAR_RADIUS\r\n )\r\n);\r\n\r\n/**\r\n * Duplicates an Ellipsoid instance.\r\n *\r\n * @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new\r\n * instance should be created.\r\n * @returns {Ellipsoid} The cloned Ellipsoid.\r\n */\r\nEllipsoid.prototype.clone = function (result) {\r\n return Ellipsoid.clone(this, result);\r\n};\r\n\r\n/**\r\n * The number of elements used to pack the object into an array.\r\n * @type {Number}\r\n */\r\nEllipsoid.packedLength = Cartesian3.packedLength;\r\n\r\n/**\r\n * Stores the provided instance into the provided array.\r\n *\r\n * @param {Ellipsoid} value The value to pack.\r\n * @param {Number[]} array The array to pack into.\r\n * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.\r\n *\r\n * @returns {Number[]} The array that was packed into\r\n */\r\nEllipsoid.pack = function (value, array, startingIndex) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"value\", value);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n Cartesian3.pack(value._radii, array, startingIndex);\r\n\r\n return array;\r\n};\r\n\r\n/**\r\n * Retrieves an instance from a packed array.\r\n *\r\n * @param {Number[]} array The packed array.\r\n * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.\r\n * @param {Ellipsoid} [result] The object into which to store the result.\r\n * @returns {Ellipsoid} The modified result parameter or a new Ellipsoid instance if one was not provided.\r\n */\r\nEllipsoid.unpack = function (array, startingIndex, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n var radii = Cartesian3.unpack(array, startingIndex);\r\n return Ellipsoid.fromCartesian3(radii, result);\r\n};\r\n\r\n/**\r\n * Computes the unit vector directed from the center of this ellipsoid toward the provided Cartesian position.\r\n * @function\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian for which to to determine the geocentric normal.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.\r\n */\r\nEllipsoid.prototype.geocentricSurfaceNormal = Cartesian3.normalize;\r\n\r\n/**\r\n * Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.\r\n *\r\n * @param {Cartographic} cartographic The cartographic position for which to to determine the geodetic normal.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.\r\n */\r\nEllipsoid.prototype.geodeticSurfaceNormalCartographic = function (\r\n cartographic,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartographic\", cartographic);\r\n //>>includeEnd('debug');\r\n\r\n var longitude = cartographic.longitude;\r\n var latitude = cartographic.latitude;\r\n var cosLatitude = Math.cos(latitude);\r\n\r\n var x = cosLatitude * Math.cos(longitude);\r\n var y = cosLatitude * Math.sin(longitude);\r\n var z = Math.sin(latitude);\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n return Cartesian3.normalize(result, result);\r\n};\r\n\r\n/**\r\n * Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian position for which to to determine the surface normal.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided, or undefined if a normal cannot be found.\r\n */\r\nEllipsoid.prototype.geodeticSurfaceNormal = function (cartesian, result) {\r\n if (\r\n Cartesian3.equalsEpsilon(cartesian, Cartesian3.ZERO, CesiumMath.EPSILON14)\r\n ) {\r\n return undefined;\r\n }\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n result = Cartesian3.multiplyComponents(\r\n cartesian,\r\n this._oneOverRadiiSquared,\r\n result\r\n );\r\n return Cartesian3.normalize(result, result);\r\n};\r\n\r\nvar cartographicToCartesianNormal = new Cartesian3();\r\nvar cartographicToCartesianK = new Cartesian3();\r\n\r\n/**\r\n * Converts the provided cartographic to Cartesian representation.\r\n *\r\n * @param {Cartographic} cartographic The cartographic position.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.\r\n *\r\n * @example\r\n * //Create a Cartographic and determine it's Cartesian representation on a WGS84 ellipsoid.\r\n * var position = new Cesium.Cartographic(Cesium.Math.toRadians(21), Cesium.Math.toRadians(78), 5000);\r\n * var cartesianPosition = Cesium.Ellipsoid.WGS84.cartographicToCartesian(position);\r\n */\r\nEllipsoid.prototype.cartographicToCartesian = function (cartographic, result) {\r\n //`cartographic is required` is thrown from geodeticSurfaceNormalCartographic.\r\n var n = cartographicToCartesianNormal;\r\n var k = cartographicToCartesianK;\r\n this.geodeticSurfaceNormalCartographic(cartographic, n);\r\n Cartesian3.multiplyComponents(this._radiiSquared, n, k);\r\n var gamma = Math.sqrt(Cartesian3.dot(n, k));\r\n Cartesian3.divideByScalar(k, gamma, k);\r\n Cartesian3.multiplyByScalar(n, cartographic.height, n);\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n return Cartesian3.add(k, n, result);\r\n};\r\n\r\n/**\r\n * Converts the provided array of cartographics to an array of Cartesians.\r\n *\r\n * @param {Cartographic[]} cartographics An array of cartographic positions.\r\n * @param {Cartesian3[]} [result] The object onto which to store the result.\r\n * @returns {Cartesian3[]} The modified result parameter or a new Array instance if none was provided.\r\n *\r\n * @example\r\n * //Convert an array of Cartographics and determine their Cartesian representation on a WGS84 ellipsoid.\r\n * var positions = [new Cesium.Cartographic(Cesium.Math.toRadians(21), Cesium.Math.toRadians(78), 0),\r\n * new Cesium.Cartographic(Cesium.Math.toRadians(21.321), Cesium.Math.toRadians(78.123), 100),\r\n * new Cesium.Cartographic(Cesium.Math.toRadians(21.645), Cesium.Math.toRadians(78.456), 250)];\r\n * var cartesianPositions = Cesium.Ellipsoid.WGS84.cartographicArrayToCartesianArray(positions);\r\n */\r\nEllipsoid.prototype.cartographicArrayToCartesianArray = function (\r\n cartographics,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"cartographics\", cartographics);\r\n //>>includeEnd('debug')\r\n\r\n var length = cartographics.length;\r\n if (!defined(result)) {\r\n result = new Array(length);\r\n } else {\r\n result.length = length;\r\n }\r\n for (var i = 0; i < length; i++) {\r\n result[i] = this.cartographicToCartesian(cartographics[i], result[i]);\r\n }\r\n return result;\r\n};\r\n\r\nvar cartesianToCartographicN = new Cartesian3();\r\nvar cartesianToCartographicP = new Cartesian3();\r\nvar cartesianToCartographicH = new Cartesian3();\r\n\r\n/**\r\n * Converts the provided cartesian to cartographic representation.\r\n * The cartesian is undefined at the center of the ellipsoid.\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian position to convert to cartographic representation.\r\n * @param {Cartographic} [result] The object onto which to store the result.\r\n * @returns {Cartographic} The modified result parameter, new Cartographic instance if none was provided, or undefined if the cartesian is at the center of the ellipsoid.\r\n *\r\n * @example\r\n * //Create a Cartesian and determine it's Cartographic representation on a WGS84 ellipsoid.\r\n * var position = new Cesium.Cartesian3(17832.12, 83234.52, 952313.73);\r\n * var cartographicPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);\r\n */\r\nEllipsoid.prototype.cartesianToCartographic = function (cartesian, result) {\r\n //`cartesian is required.` is thrown from scaleToGeodeticSurface\r\n var p = this.scaleToGeodeticSurface(cartesian, cartesianToCartographicP);\r\n\r\n if (!defined(p)) {\r\n return undefined;\r\n }\r\n\r\n var n = this.geodeticSurfaceNormal(p, cartesianToCartographicN);\r\n var h = Cartesian3.subtract(cartesian, p, cartesianToCartographicH);\r\n\r\n var longitude = Math.atan2(n.y, n.x);\r\n var latitude = Math.asin(n.z);\r\n var height =\r\n CesiumMath.sign(Cartesian3.dot(h, cartesian)) * Cartesian3.magnitude(h);\r\n\r\n if (!defined(result)) {\r\n return new Cartographic(longitude, latitude, height);\r\n }\r\n result.longitude = longitude;\r\n result.latitude = latitude;\r\n result.height = height;\r\n return result;\r\n};\r\n\r\n/**\r\n * Converts the provided array of cartesians to an array of cartographics.\r\n *\r\n * @param {Cartesian3[]} cartesians An array of Cartesian positions.\r\n * @param {Cartographic[]} [result] The object onto which to store the result.\r\n * @returns {Cartographic[]} The modified result parameter or a new Array instance if none was provided.\r\n *\r\n * @example\r\n * //Create an array of Cartesians and determine their Cartographic representation on a WGS84 ellipsoid.\r\n * var positions = [new Cesium.Cartesian3(17832.12, 83234.52, 952313.73),\r\n * new Cesium.Cartesian3(17832.13, 83234.53, 952313.73),\r\n * new Cesium.Cartesian3(17832.14, 83234.54, 952313.73)]\r\n * var cartographicPositions = Cesium.Ellipsoid.WGS84.cartesianArrayToCartographicArray(positions);\r\n */\r\nEllipsoid.prototype.cartesianArrayToCartographicArray = function (\r\n cartesians,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"cartesians\", cartesians);\r\n //>>includeEnd('debug');\r\n\r\n var length = cartesians.length;\r\n if (!defined(result)) {\r\n result = new Array(length);\r\n } else {\r\n result.length = length;\r\n }\r\n for (var i = 0; i < length; ++i) {\r\n result[i] = this.cartesianToCartographic(cartesians[i], result[i]);\r\n }\r\n return result;\r\n};\r\n\r\n/**\r\n * Scales the provided Cartesian position along the geodetic surface normal\r\n * so that it is on the surface of this ellipsoid. If the position is\r\n * at the center of the ellipsoid, this function returns undefined.\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian position to scale.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter, a new Cartesian3 instance if none was provided, or undefined if the position is at the center.\r\n */\r\nEllipsoid.prototype.scaleToGeodeticSurface = function (cartesian, result) {\r\n return scaleToGeodeticSurface(\r\n cartesian,\r\n this._oneOverRadii,\r\n this._oneOverRadiiSquared,\r\n this._centerToleranceSquared,\r\n result\r\n );\r\n};\r\n\r\n/**\r\n * Scales the provided Cartesian position along the geocentric surface normal\r\n * so that it is on the surface of this ellipsoid.\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian position to scale.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.\r\n */\r\nEllipsoid.prototype.scaleToGeocentricSurface = function (cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n\r\n var positionX = cartesian.x;\r\n var positionY = cartesian.y;\r\n var positionZ = cartesian.z;\r\n var oneOverRadiiSquared = this._oneOverRadiiSquared;\r\n\r\n var beta =\r\n 1.0 /\r\n Math.sqrt(\r\n positionX * positionX * oneOverRadiiSquared.x +\r\n positionY * positionY * oneOverRadiiSquared.y +\r\n positionZ * positionZ * oneOverRadiiSquared.z\r\n );\r\n\r\n return Cartesian3.multiplyByScalar(cartesian, beta, result);\r\n};\r\n\r\n/**\r\n * Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying\r\n * its components by the result of {@link Ellipsoid#oneOverRadii}.\r\n *\r\n * @param {Cartesian3} position The position to transform.\r\n * @param {Cartesian3} [result] The position to which to copy the result, or undefined to create and\r\n * return a new instance.\r\n * @returns {Cartesian3} The position expressed in the scaled space. The returned instance is the\r\n * one passed as the result parameter if it is not undefined, or a new instance of it is.\r\n */\r\nEllipsoid.prototype.transformPositionToScaledSpace = function (\r\n position,\r\n result\r\n) {\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n\r\n return Cartesian3.multiplyComponents(position, this._oneOverRadii, result);\r\n};\r\n\r\n/**\r\n * Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying\r\n * its components by the result of {@link Ellipsoid#radii}.\r\n *\r\n * @param {Cartesian3} position The position to transform.\r\n * @param {Cartesian3} [result] The position to which to copy the result, or undefined to create and\r\n * return a new instance.\r\n * @returns {Cartesian3} The position expressed in the unscaled space. The returned instance is the\r\n * one passed as the result parameter if it is not undefined, or a new instance of it is.\r\n */\r\nEllipsoid.prototype.transformPositionFromScaledSpace = function (\r\n position,\r\n result\r\n) {\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n\r\n return Cartesian3.multiplyComponents(position, this._radii, result);\r\n};\r\n\r\n/**\r\n * Compares this Ellipsoid against the provided Ellipsoid componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Ellipsoid} [right] The other Ellipsoid.\r\n * @returns {Boolean} true
if they are equal, false
otherwise.\r\n */\r\nEllipsoid.prototype.equals = function (right) {\r\n return (\r\n this === right ||\r\n (defined(right) && Cartesian3.equals(this._radii, right._radii))\r\n );\r\n};\r\n\r\n/**\r\n * Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'.\r\n *\r\n * @returns {String} A string representing this ellipsoid in the format '(radii.x, radii.y, radii.z)'.\r\n */\r\nEllipsoid.prototype.toString = function () {\r\n return this._radii.toString();\r\n};\r\n\r\n/**\r\n * Computes a point which is the intersection of the surface normal with the z-axis.\r\n *\r\n * @param {Cartesian3} position the position. must be on the surface of the ellipsoid.\r\n * @param {Number} [buffer = 0.0] A buffer to subtract from the ellipsoid size when checking if the point is inside the ellipsoid.\r\n * In earth case, with common earth datums, there is no need for this buffer since the intersection point is always (relatively) very close to the center.\r\n * In WGS84 datum, intersection point is at max z = +-42841.31151331382 (0.673% of z-axis).\r\n * Intersection point could be outside the ellipsoid if the ratio of MajorAxis / AxisOfRotation is bigger than the square root of 2\r\n * @param {Cartesian3} [result] The cartesian to which to copy the result, or undefined to create and\r\n * return a new instance.\r\n * @returns {Cartesian3 | undefined} the intersection point if it's inside the ellipsoid, undefined otherwise\r\n *\r\n * @exception {DeveloperError} position is required.\r\n * @exception {DeveloperError} Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y).\r\n * @exception {DeveloperError} Ellipsoid.radii.z must be greater than 0.\r\n */\r\nEllipsoid.prototype.getSurfaceNormalIntersectionWithZAxis = function (\r\n position,\r\n buffer,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"position\", position);\r\n\r\n if (\r\n !CesiumMath.equalsEpsilon(\r\n this._radii.x,\r\n this._radii.y,\r\n CesiumMath.EPSILON15\r\n )\r\n ) {\r\n throw new DeveloperError(\r\n \"Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)\"\r\n );\r\n }\r\n\r\n Check.typeOf.number.greaterThan(\"Ellipsoid.radii.z\", this._radii.z, 0);\r\n //>>includeEnd('debug');\r\n\r\n buffer = defaultValue(buffer, 0.0);\r\n\r\n var squaredXOverSquaredZ = this._squaredXOverSquaredZ;\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n\r\n result.x = 0.0;\r\n result.y = 0.0;\r\n result.z = position.z * (1 - squaredXOverSquaredZ);\r\n\r\n if (Math.abs(result.z) >= this._radii.z - buffer) {\r\n return undefined;\r\n }\r\n\r\n return result;\r\n};\r\n\r\nvar abscissas = [\r\n 0.14887433898163,\r\n 0.43339539412925,\r\n 0.67940956829902,\r\n 0.86506336668898,\r\n 0.97390652851717,\r\n 0.0,\r\n];\r\nvar weights = [\r\n 0.29552422471475,\r\n 0.26926671930999,\r\n 0.21908636251598,\r\n 0.14945134915058,\r\n 0.066671344308684,\r\n 0.0,\r\n];\r\n\r\n/**\r\n * Compute the 10th order Gauss-Legendre Quadrature of the given definite integral.\r\n *\r\n * @param {Number} a The lower bound for the integration.\r\n * @param {Number} b The upper bound for the integration.\r\n * @param {Ellipsoid~RealValuedScalarFunction} func The function to integrate.\r\n * @returns {Number} The value of the integral of the given function over the given domain.\r\n *\r\n * @private\r\n */\r\nfunction gaussLegendreQuadrature(a, b, func) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number(\"a\", a);\r\n Check.typeOf.number(\"b\", b);\r\n Check.typeOf.func(\"func\", func);\r\n //>>includeEnd('debug');\r\n\r\n // The range is half of the normal range since the five weights add to one (ten weights add to two).\r\n // The values of the abscissas are multiplied by two to account for this.\r\n var xMean = 0.5 * (b + a);\r\n var xRange = 0.5 * (b - a);\r\n\r\n var sum = 0.0;\r\n for (var i = 0; i < 5; i++) {\r\n var dx = xRange * abscissas[i];\r\n sum += weights[i] * (func(xMean + dx) + func(xMean - dx));\r\n }\r\n\r\n // Scale the sum to the range of x.\r\n sum *= xRange;\r\n return sum;\r\n}\r\n\r\n/**\r\n * A real valued scalar function.\r\n * @callback Ellipsoid~RealValuedScalarFunction\r\n *\r\n * @param {Number} x The value used to evaluate the function.\r\n * @returns {Number} The value of the function at x.\r\n *\r\n * @private\r\n */\r\n\r\n/**\r\n * Computes an approximation of the surface area of a rectangle on the surface of an ellipsoid using\r\n * Gauss-Legendre 10th order quadrature.\r\n *\r\n * @param {Rectangle} rectangle The rectangle used for computing the surface area.\r\n * @returns {Number} The approximate area of the rectangle on the surface of this ellipsoid.\r\n */\r\nEllipsoid.prototype.surfaceArea = function (rectangle) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rectangle\", rectangle);\r\n //>>includeEnd('debug');\r\n var minLongitude = rectangle.west;\r\n var maxLongitude = rectangle.east;\r\n var minLatitude = rectangle.south;\r\n var maxLatitude = rectangle.north;\r\n\r\n while (maxLongitude < minLongitude) {\r\n maxLongitude += CesiumMath.TWO_PI;\r\n }\r\n\r\n var radiiSquared = this._radiiSquared;\r\n var a2 = radiiSquared.x;\r\n var b2 = radiiSquared.y;\r\n var c2 = radiiSquared.z;\r\n var a2b2 = a2 * b2;\r\n return gaussLegendreQuadrature(minLatitude, maxLatitude, function (lat) {\r\n // phi represents the angle measured from the north pole\r\n // sin(phi) = sin(pi / 2 - lat) = cos(lat), cos(phi) is similar\r\n var sinPhi = Math.cos(lat);\r\n var cosPhi = Math.sin(lat);\r\n return (\r\n Math.cos(lat) *\r\n gaussLegendreQuadrature(minLongitude, maxLongitude, function (lon) {\r\n var cosTheta = Math.cos(lon);\r\n var sinTheta = Math.sin(lon);\r\n return Math.sqrt(\r\n a2b2 * cosPhi * cosPhi +\r\n c2 *\r\n (b2 * cosTheta * cosTheta + a2 * sinTheta * sinTheta) *\r\n sinPhi *\r\n sinPhi\r\n );\r\n })\r\n );\r\n });\r\n};\r\n\r\nexport default Ellipsoid;\r\n","import Cartesian3 from \"./Cartesian3.js\";\r\nimport Cartographic from \"./Cartographic.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport Ellipsoid from \"./Ellipsoid.js\";\r\n\r\n/**\r\n * A simple map projection where longitude and latitude are linearly mapped to X and Y by multiplying\r\n * them by the {@link Ellipsoid#maximumRadius}. This projection\r\n * is commonly known as geographic, equirectangular, equidistant cylindrical, or plate carrée. It\r\n * is also known as EPSG:4326.\r\n *\r\n * @alias GeographicProjection\r\n * @constructor\r\n *\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid.\r\n *\r\n * @see WebMercatorProjection\r\n */\r\nfunction GeographicProjection(ellipsoid) {\r\n this._ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\r\n this._semimajorAxis = this._ellipsoid.maximumRadius;\r\n this._oneOverSemimajorAxis = 1.0 / this._semimajorAxis;\r\n}\r\n\r\nObject.defineProperties(GeographicProjection.prototype, {\r\n /**\r\n * Gets the {@link Ellipsoid}.\r\n *\r\n * @memberof GeographicProjection.prototype\r\n *\r\n * @type {Ellipsoid}\r\n * @readonly\r\n */\r\n ellipsoid: {\r\n get: function () {\r\n return this._ellipsoid;\r\n },\r\n },\r\n});\r\n\r\n/**\r\n * Projects a set of {@link Cartographic} coordinates, in radians, to map coordinates, in meters.\r\n * X and Y are the longitude and latitude, respectively, multiplied by the maximum radius of the\r\n * ellipsoid. Z is the unmodified height.\r\n *\r\n * @param {Cartographic} cartographic The coordinates to project.\r\n * @param {Cartesian3} [result] An instance into which to copy the result. If this parameter is\r\n * undefined, a new instance is created and returned.\r\n * @returns {Cartesian3} The projected coordinates. If the result parameter is not undefined, the\r\n * coordinates are copied there and that instance is returned. Otherwise, a new instance is\r\n * created and returned.\r\n */\r\nGeographicProjection.prototype.project = function (cartographic, result) {\r\n // Actually this is the special case of equidistant cylindrical called the plate carree\r\n var semimajorAxis = this._semimajorAxis;\r\n var x = cartographic.longitude * semimajorAxis;\r\n var y = cartographic.latitude * semimajorAxis;\r\n var z = cartographic.height;\r\n\r\n if (!defined(result)) {\r\n return new Cartesian3(x, y, z);\r\n }\r\n\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Unprojects a set of projected {@link Cartesian3} coordinates, in meters, to {@link Cartographic}\r\n * coordinates, in radians. Longitude and Latitude are the X and Y coordinates, respectively,\r\n * divided by the maximum radius of the ellipsoid. Height is the unmodified Z coordinate.\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian position to unproject with height (z) in meters.\r\n * @param {Cartographic} [result] An instance into which to copy the result. If this parameter is\r\n * undefined, a new instance is created and returned.\r\n * @returns {Cartographic} The unprojected coordinates. If the result parameter is not undefined, the\r\n * coordinates are copied there and that instance is returned. Otherwise, a new instance is\r\n * created and returned.\r\n */\r\nGeographicProjection.prototype.unproject = function (cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(cartesian)) {\r\n throw new DeveloperError(\"cartesian is required\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var oneOverEarthSemimajorAxis = this._oneOverSemimajorAxis;\r\n var longitude = cartesian.x * oneOverEarthSemimajorAxis;\r\n var latitude = cartesian.y * oneOverEarthSemimajorAxis;\r\n var height = cartesian.z;\r\n\r\n if (!defined(result)) {\r\n return new Cartographic(longitude, latitude, height);\r\n }\r\n\r\n result.longitude = longitude;\r\n result.latitude = latitude;\r\n result.height = height;\r\n return result;\r\n};\r\nexport default GeographicProjection;\r\n","/**\r\n * This enumerated type is used in determining where, relative to the frustum, an\r\n * object is located. The object can either be fully contained within the frustum (INSIDE),\r\n * partially inside the frustum and partially outside (INTERSECTING), or somewhere entirely\r\n * outside of the frustum's 6 planes (OUTSIDE).\r\n *\r\n * @enum {Number}\r\n */\r\nvar Intersect = {\r\n /**\r\n * Represents that an object is not contained within the frustum.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\n OUTSIDE: -1,\r\n\r\n /**\r\n * Represents that an object intersects one of the frustum's planes.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\n INTERSECTING: 0,\r\n\r\n /**\r\n * Represents that an object is fully within the frustum.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\n INSIDE: 1,\r\n};\r\nexport default Object.freeze(Intersect);\r\n","import defaultValue from \"./defaultValue.js\";\r\n\r\n/**\r\n * Represents the closed interval [start, stop].\r\n * @alias Interval\r\n * @constructor\r\n *\r\n * @param {Number} [start=0.0] The beginning of the interval.\r\n * @param {Number} [stop=0.0] The end of the interval.\r\n */\r\nfunction Interval(start, stop) {\r\n /**\r\n * The beginning of the interval.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.start = defaultValue(start, 0.0);\r\n /**\r\n * The end of the interval.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.stop = defaultValue(stop, 0.0);\r\n}\r\nexport default Interval;\r\n","import Cartesian3 from \"./Cartesian3.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport CesiumMath from \"./Math.js\";\r\n\r\n/**\r\n * A 3x3 matrix, indexable as a column-major order array.\r\n * Constructor parameters are in row-major order for code readability.\r\n * @alias Matrix3\r\n * @constructor\r\n * @implements {ArrayLike}\r\n *\r\n * @param {Number} [column0Row0=0.0] The value for column 0, row 0.\r\n * @param {Number} [column1Row0=0.0] The value for column 1, row 0.\r\n * @param {Number} [column2Row0=0.0] The value for column 2, row 0.\r\n * @param {Number} [column0Row1=0.0] The value for column 0, row 1.\r\n * @param {Number} [column1Row1=0.0] The value for column 1, row 1.\r\n * @param {Number} [column2Row1=0.0] The value for column 2, row 1.\r\n * @param {Number} [column0Row2=0.0] The value for column 0, row 2.\r\n * @param {Number} [column1Row2=0.0] The value for column 1, row 2.\r\n * @param {Number} [column2Row2=0.0] The value for column 2, row 2.\r\n *\r\n * @see Matrix3.fromColumnMajorArray\r\n * @see Matrix3.fromRowMajorArray\r\n * @see Matrix3.fromQuaternion\r\n * @see Matrix3.fromScale\r\n * @see Matrix3.fromUniformScale\r\n * @see Matrix2\r\n * @see Matrix4\r\n */\r\nfunction Matrix3(\r\n column0Row0,\r\n column1Row0,\r\n column2Row0,\r\n column0Row1,\r\n column1Row1,\r\n column2Row1,\r\n column0Row2,\r\n column1Row2,\r\n column2Row2\r\n) {\r\n this[0] = defaultValue(column0Row0, 0.0);\r\n this[1] = defaultValue(column0Row1, 0.0);\r\n this[2] = defaultValue(column0Row2, 0.0);\r\n this[3] = defaultValue(column1Row0, 0.0);\r\n this[4] = defaultValue(column1Row1, 0.0);\r\n this[5] = defaultValue(column1Row2, 0.0);\r\n this[6] = defaultValue(column2Row0, 0.0);\r\n this[7] = defaultValue(column2Row1, 0.0);\r\n this[8] = defaultValue(column2Row2, 0.0);\r\n}\r\n\r\n/**\r\n * The number of elements used to pack the object into an array.\r\n * @type {Number}\r\n */\r\nMatrix3.packedLength = 9;\r\n\r\n/**\r\n * Stores the provided instance into the provided array.\r\n *\r\n * @param {Matrix3} value The value to pack.\r\n * @param {Number[]} array The array to pack into.\r\n * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.\r\n *\r\n * @returns {Number[]} The array that was packed into\r\n */\r\nMatrix3.pack = function (value, array, startingIndex) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"value\", value);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n array[startingIndex++] = value[0];\r\n array[startingIndex++] = value[1];\r\n array[startingIndex++] = value[2];\r\n array[startingIndex++] = value[3];\r\n array[startingIndex++] = value[4];\r\n array[startingIndex++] = value[5];\r\n array[startingIndex++] = value[6];\r\n array[startingIndex++] = value[7];\r\n array[startingIndex++] = value[8];\r\n\r\n return array;\r\n};\r\n\r\n/**\r\n * Retrieves an instance from a packed array.\r\n *\r\n * @param {Number[]} array The packed array.\r\n * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.\r\n * @param {Matrix3} [result] The object into which to store the result.\r\n * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.\r\n */\r\nMatrix3.unpack = function (array, startingIndex, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n if (!defined(result)) {\r\n result = new Matrix3();\r\n }\r\n\r\n result[0] = array[startingIndex++];\r\n result[1] = array[startingIndex++];\r\n result[2] = array[startingIndex++];\r\n result[3] = array[startingIndex++];\r\n result[4] = array[startingIndex++];\r\n result[5] = array[startingIndex++];\r\n result[6] = array[startingIndex++];\r\n result[7] = array[startingIndex++];\r\n result[8] = array[startingIndex++];\r\n return result;\r\n};\r\n\r\n/**\r\n * Duplicates a Matrix3 instance.\r\n *\r\n * @param {Matrix3} matrix The matrix to duplicate.\r\n * @param {Matrix3} [result] The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided. (Returns undefined if matrix is undefined)\r\n */\r\nMatrix3.clone = function (matrix, result) {\r\n if (!defined(matrix)) {\r\n return undefined;\r\n }\r\n if (!defined(result)) {\r\n return new Matrix3(\r\n matrix[0],\r\n matrix[3],\r\n matrix[6],\r\n matrix[1],\r\n matrix[4],\r\n matrix[7],\r\n matrix[2],\r\n matrix[5],\r\n matrix[8]\r\n );\r\n }\r\n result[0] = matrix[0];\r\n result[1] = matrix[1];\r\n result[2] = matrix[2];\r\n result[3] = matrix[3];\r\n result[4] = matrix[4];\r\n result[5] = matrix[5];\r\n result[6] = matrix[6];\r\n result[7] = matrix[7];\r\n result[8] = matrix[8];\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a Matrix3 from 9 consecutive elements in an array.\r\n *\r\n * @param {Number[]} array The array whose 9 consecutive elements correspond to the positions of the matrix. Assumes column-major order.\r\n * @param {Number} [startingIndex=0] The offset into the array of the first element, which corresponds to first column first row position in the matrix.\r\n * @param {Matrix3} [result] The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.\r\n *\r\n * @example\r\n * // Create the Matrix3:\r\n * // [1.0, 2.0, 3.0]\r\n * // [1.0, 2.0, 3.0]\r\n * // [1.0, 2.0, 3.0]\r\n *\r\n * var v = [1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0];\r\n * var m = Cesium.Matrix3.fromArray(v);\r\n *\r\n * // Create same Matrix3 with using an offset into an array\r\n * var v2 = [0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0];\r\n * var m2 = Cesium.Matrix3.fromArray(v2, 2);\r\n */\r\nMatrix3.fromArray = function (array, startingIndex, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n if (!defined(result)) {\r\n result = new Matrix3();\r\n }\r\n\r\n result[0] = array[startingIndex];\r\n result[1] = array[startingIndex + 1];\r\n result[2] = array[startingIndex + 2];\r\n result[3] = array[startingIndex + 3];\r\n result[4] = array[startingIndex + 4];\r\n result[5] = array[startingIndex + 5];\r\n result[6] = array[startingIndex + 6];\r\n result[7] = array[startingIndex + 7];\r\n result[8] = array[startingIndex + 8];\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a Matrix3 instance from a column-major order array.\r\n *\r\n * @param {Number[]} values The column-major order array.\r\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.\r\n */\r\nMatrix3.fromColumnMajorArray = function (values, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"values\", values);\r\n //>>includeEnd('debug');\r\n\r\n return Matrix3.clone(values, result);\r\n};\r\n\r\n/**\r\n * Creates a Matrix3 instance from a row-major order array.\r\n * The resulting matrix will be in column-major order.\r\n *\r\n * @param {Number[]} values The row-major order array.\r\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.\r\n */\r\nMatrix3.fromRowMajorArray = function (values, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"values\", values);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n return new Matrix3(\r\n values[0],\r\n values[1],\r\n values[2],\r\n values[3],\r\n values[4],\r\n values[5],\r\n values[6],\r\n values[7],\r\n values[8]\r\n );\r\n }\r\n result[0] = values[0];\r\n result[1] = values[3];\r\n result[2] = values[6];\r\n result[3] = values[1];\r\n result[4] = values[4];\r\n result[5] = values[7];\r\n result[6] = values[2];\r\n result[7] = values[5];\r\n result[8] = values[8];\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a 3x3 rotation matrix from the provided quaternion.\r\n *\r\n * @param {Quaternion} quaternion the quaternion to use.\r\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix3} The 3x3 rotation matrix from this quaternion.\r\n */\r\nMatrix3.fromQuaternion = function (quaternion, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"quaternion\", quaternion);\r\n //>>includeEnd('debug');\r\n\r\n var x2 = quaternion.x * quaternion.x;\r\n var xy = quaternion.x * quaternion.y;\r\n var xz = quaternion.x * quaternion.z;\r\n var xw = quaternion.x * quaternion.w;\r\n var y2 = quaternion.y * quaternion.y;\r\n var yz = quaternion.y * quaternion.z;\r\n var yw = quaternion.y * quaternion.w;\r\n var z2 = quaternion.z * quaternion.z;\r\n var zw = quaternion.z * quaternion.w;\r\n var w2 = quaternion.w * quaternion.w;\r\n\r\n var m00 = x2 - y2 - z2 + w2;\r\n var m01 = 2.0 * (xy - zw);\r\n var m02 = 2.0 * (xz + yw);\r\n\r\n var m10 = 2.0 * (xy + zw);\r\n var m11 = -x2 + y2 - z2 + w2;\r\n var m12 = 2.0 * (yz - xw);\r\n\r\n var m20 = 2.0 * (xz - yw);\r\n var m21 = 2.0 * (yz + xw);\r\n var m22 = -x2 - y2 + z2 + w2;\r\n\r\n if (!defined(result)) {\r\n return new Matrix3(m00, m01, m02, m10, m11, m12, m20, m21, m22);\r\n }\r\n result[0] = m00;\r\n result[1] = m10;\r\n result[2] = m20;\r\n result[3] = m01;\r\n result[4] = m11;\r\n result[5] = m21;\r\n result[6] = m02;\r\n result[7] = m12;\r\n result[8] = m22;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a 3x3 rotation matrix from the provided headingPitchRoll. (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles )\r\n *\r\n * @param {HeadingPitchRoll} headingPitchRoll the headingPitchRoll to use.\r\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix3} The 3x3 rotation matrix from this headingPitchRoll.\r\n */\r\nMatrix3.fromHeadingPitchRoll = function (headingPitchRoll, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"headingPitchRoll\", headingPitchRoll);\r\n //>>includeEnd('debug');\r\n\r\n var cosTheta = Math.cos(-headingPitchRoll.pitch);\r\n var cosPsi = Math.cos(-headingPitchRoll.heading);\r\n var cosPhi = Math.cos(headingPitchRoll.roll);\r\n var sinTheta = Math.sin(-headingPitchRoll.pitch);\r\n var sinPsi = Math.sin(-headingPitchRoll.heading);\r\n var sinPhi = Math.sin(headingPitchRoll.roll);\r\n\r\n var m00 = cosTheta * cosPsi;\r\n var m01 = -cosPhi * sinPsi + sinPhi * sinTheta * cosPsi;\r\n var m02 = sinPhi * sinPsi + cosPhi * sinTheta * cosPsi;\r\n\r\n var m10 = cosTheta * sinPsi;\r\n var m11 = cosPhi * cosPsi + sinPhi * sinTheta * sinPsi;\r\n var m12 = -sinPhi * cosPsi + cosPhi * sinTheta * sinPsi;\r\n\r\n var m20 = -sinTheta;\r\n var m21 = sinPhi * cosTheta;\r\n var m22 = cosPhi * cosTheta;\r\n\r\n if (!defined(result)) {\r\n return new Matrix3(m00, m01, m02, m10, m11, m12, m20, m21, m22);\r\n }\r\n result[0] = m00;\r\n result[1] = m10;\r\n result[2] = m20;\r\n result[3] = m01;\r\n result[4] = m11;\r\n result[5] = m21;\r\n result[6] = m02;\r\n result[7] = m12;\r\n result[8] = m22;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a Matrix3 instance representing a non-uniform scale.\r\n *\r\n * @param {Cartesian3} scale The x, y, and z scale factors.\r\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.\r\n *\r\n * @example\r\n * // Creates\r\n * // [7.0, 0.0, 0.0]\r\n * // [0.0, 8.0, 0.0]\r\n * // [0.0, 0.0, 9.0]\r\n * var m = Cesium.Matrix3.fromScale(new Cesium.Cartesian3(7.0, 8.0, 9.0));\r\n */\r\nMatrix3.fromScale = function (scale, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"scale\", scale);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n return new Matrix3(scale.x, 0.0, 0.0, 0.0, scale.y, 0.0, 0.0, 0.0, scale.z);\r\n }\r\n\r\n result[0] = scale.x;\r\n result[1] = 0.0;\r\n result[2] = 0.0;\r\n result[3] = 0.0;\r\n result[4] = scale.y;\r\n result[5] = 0.0;\r\n result[6] = 0.0;\r\n result[7] = 0.0;\r\n result[8] = scale.z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a Matrix3 instance representing a uniform scale.\r\n *\r\n * @param {Number} scale The uniform scale factor.\r\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.\r\n *\r\n * @example\r\n * // Creates\r\n * // [2.0, 0.0, 0.0]\r\n * // [0.0, 2.0, 0.0]\r\n * // [0.0, 0.0, 2.0]\r\n * var m = Cesium.Matrix3.fromUniformScale(2.0);\r\n */\r\nMatrix3.fromUniformScale = function (scale, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number(\"scale\", scale);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n return new Matrix3(scale, 0.0, 0.0, 0.0, scale, 0.0, 0.0, 0.0, scale);\r\n }\r\n\r\n result[0] = scale;\r\n result[1] = 0.0;\r\n result[2] = 0.0;\r\n result[3] = 0.0;\r\n result[4] = scale;\r\n result[5] = 0.0;\r\n result[6] = 0.0;\r\n result[7] = 0.0;\r\n result[8] = scale;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a Matrix3 instance representing the cross product equivalent matrix of a Cartesian3 vector.\r\n *\r\n * @param {Cartesian3} vector the vector on the left hand side of the cross product operation.\r\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.\r\n *\r\n * @example\r\n * // Creates\r\n * // [0.0, -9.0, 8.0]\r\n * // [9.0, 0.0, -7.0]\r\n * // [-8.0, 7.0, 0.0]\r\n * var m = Cesium.Matrix3.fromCrossProduct(new Cesium.Cartesian3(7.0, 8.0, 9.0));\r\n */\r\nMatrix3.fromCrossProduct = function (vector, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"vector\", vector);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n return new Matrix3(\r\n 0.0,\r\n -vector.z,\r\n vector.y,\r\n vector.z,\r\n 0.0,\r\n -vector.x,\r\n -vector.y,\r\n vector.x,\r\n 0.0\r\n );\r\n }\r\n\r\n result[0] = 0.0;\r\n result[1] = vector.z;\r\n result[2] = -vector.y;\r\n result[3] = -vector.z;\r\n result[4] = 0.0;\r\n result[5] = vector.x;\r\n result[6] = vector.y;\r\n result[7] = -vector.x;\r\n result[8] = 0.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a rotation matrix around the x-axis.\r\n *\r\n * @param {Number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.\r\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.\r\n *\r\n * @example\r\n * // Rotate a point 45 degrees counterclockwise around the x-axis.\r\n * var p = new Cesium.Cartesian3(5, 6, 7);\r\n * var m = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(45.0));\r\n * var rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());\r\n */\r\nMatrix3.fromRotationX = function (angle, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number(\"angle\", angle);\r\n //>>includeEnd('debug');\r\n\r\n var cosAngle = Math.cos(angle);\r\n var sinAngle = Math.sin(angle);\r\n\r\n if (!defined(result)) {\r\n return new Matrix3(\r\n 1.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n cosAngle,\r\n -sinAngle,\r\n 0.0,\r\n sinAngle,\r\n cosAngle\r\n );\r\n }\r\n\r\n result[0] = 1.0;\r\n result[1] = 0.0;\r\n result[2] = 0.0;\r\n result[3] = 0.0;\r\n result[4] = cosAngle;\r\n result[5] = sinAngle;\r\n result[6] = 0.0;\r\n result[7] = -sinAngle;\r\n result[8] = cosAngle;\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a rotation matrix around the y-axis.\r\n *\r\n * @param {Number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.\r\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.\r\n *\r\n * @example\r\n * // Rotate a point 45 degrees counterclockwise around the y-axis.\r\n * var p = new Cesium.Cartesian3(5, 6, 7);\r\n * var m = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(45.0));\r\n * var rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());\r\n */\r\nMatrix3.fromRotationY = function (angle, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number(\"angle\", angle);\r\n //>>includeEnd('debug');\r\n\r\n var cosAngle = Math.cos(angle);\r\n var sinAngle = Math.sin(angle);\r\n\r\n if (!defined(result)) {\r\n return new Matrix3(\r\n cosAngle,\r\n 0.0,\r\n sinAngle,\r\n 0.0,\r\n 1.0,\r\n 0.0,\r\n -sinAngle,\r\n 0.0,\r\n cosAngle\r\n );\r\n }\r\n\r\n result[0] = cosAngle;\r\n result[1] = 0.0;\r\n result[2] = -sinAngle;\r\n result[3] = 0.0;\r\n result[4] = 1.0;\r\n result[5] = 0.0;\r\n result[6] = sinAngle;\r\n result[7] = 0.0;\r\n result[8] = cosAngle;\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a rotation matrix around the z-axis.\r\n *\r\n * @param {Number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.\r\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.\r\n *\r\n * @example\r\n * // Rotate a point 45 degrees counterclockwise around the z-axis.\r\n * var p = new Cesium.Cartesian3(5, 6, 7);\r\n * var m = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(45.0));\r\n * var rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());\r\n */\r\nMatrix3.fromRotationZ = function (angle, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number(\"angle\", angle);\r\n //>>includeEnd('debug');\r\n\r\n var cosAngle = Math.cos(angle);\r\n var sinAngle = Math.sin(angle);\r\n\r\n if (!defined(result)) {\r\n return new Matrix3(\r\n cosAngle,\r\n -sinAngle,\r\n 0.0,\r\n sinAngle,\r\n cosAngle,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 1.0\r\n );\r\n }\r\n\r\n result[0] = cosAngle;\r\n result[1] = sinAngle;\r\n result[2] = 0.0;\r\n result[3] = -sinAngle;\r\n result[4] = cosAngle;\r\n result[5] = 0.0;\r\n result[6] = 0.0;\r\n result[7] = 0.0;\r\n result[8] = 1.0;\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates an Array from the provided Matrix3 instance.\r\n * The array will be in column-major order.\r\n *\r\n * @param {Matrix3} matrix The matrix to use..\r\n * @param {Number[]} [result] The Array onto which to store the result.\r\n * @returns {Number[]} The modified Array parameter or a new Array instance if one was not provided.\r\n */\r\nMatrix3.toArray = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n return [\r\n matrix[0],\r\n matrix[1],\r\n matrix[2],\r\n matrix[3],\r\n matrix[4],\r\n matrix[5],\r\n matrix[6],\r\n matrix[7],\r\n matrix[8],\r\n ];\r\n }\r\n result[0] = matrix[0];\r\n result[1] = matrix[1];\r\n result[2] = matrix[2];\r\n result[3] = matrix[3];\r\n result[4] = matrix[4];\r\n result[5] = matrix[5];\r\n result[6] = matrix[6];\r\n result[7] = matrix[7];\r\n result[8] = matrix[8];\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the array index of the element at the provided row and column.\r\n *\r\n * @param {Number} row The zero-based index of the row.\r\n * @param {Number} column The zero-based index of the column.\r\n * @returns {Number} The index of the element at the provided row and column.\r\n *\r\n * @exception {DeveloperError} row must be 0, 1, or 2.\r\n * @exception {DeveloperError} column must be 0, 1, or 2.\r\n *\r\n * @example\r\n * var myMatrix = new Cesium.Matrix3();\r\n * var column1Row0Index = Cesium.Matrix3.getElementIndex(1, 0);\r\n * var column1Row0 = myMatrix[column1Row0Index]\r\n * myMatrix[column1Row0Index] = 10.0;\r\n */\r\nMatrix3.getElementIndex = function (column, row) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number.greaterThanOrEquals(\"row\", row, 0);\r\n Check.typeOf.number.lessThanOrEquals(\"row\", row, 2);\r\n Check.typeOf.number.greaterThanOrEquals(\"column\", column, 0);\r\n Check.typeOf.number.lessThanOrEquals(\"column\", column, 2);\r\n //>>includeEnd('debug');\r\n\r\n return column * 3 + row;\r\n};\r\n\r\n/**\r\n * Retrieves a copy of the matrix column at the provided index as a Cartesian3 instance.\r\n *\r\n * @param {Matrix3} matrix The matrix to use.\r\n * @param {Number} index The zero-based index of the column to retrieve.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n *\r\n * @exception {DeveloperError} index must be 0, 1, or 2.\r\n */\r\nMatrix3.getColumn = function (matrix, index, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\r\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 2);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var startIndex = index * 3;\r\n var x = matrix[startIndex];\r\n var y = matrix[startIndex + 1];\r\n var z = matrix[startIndex + 2];\r\n\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a new matrix that replaces the specified column in the provided matrix with the provided Cartesian3 instance.\r\n *\r\n * @param {Matrix3} matrix The matrix to use.\r\n * @param {Number} index The zero-based index of the column to set.\r\n * @param {Cartesian3} cartesian The Cartesian whose values will be assigned to the specified column.\r\n * @param {Matrix3} result The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter.\r\n *\r\n * @exception {DeveloperError} index must be 0, 1, or 2.\r\n */\r\nMatrix3.setColumn = function (matrix, index, cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\r\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 2);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result = Matrix3.clone(matrix, result);\r\n var startIndex = index * 3;\r\n result[startIndex] = cartesian.x;\r\n result[startIndex + 1] = cartesian.y;\r\n result[startIndex + 2] = cartesian.z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Retrieves a copy of the matrix row at the provided index as a Cartesian3 instance.\r\n *\r\n * @param {Matrix3} matrix The matrix to use.\r\n * @param {Number} index The zero-based index of the row to retrieve.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n *\r\n * @exception {DeveloperError} index must be 0, 1, or 2.\r\n */\r\nMatrix3.getRow = function (matrix, index, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\r\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 2);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var x = matrix[index];\r\n var y = matrix[index + 3];\r\n var z = matrix[index + 6];\r\n\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a new matrix that replaces the specified row in the provided matrix with the provided Cartesian3 instance.\r\n *\r\n * @param {Matrix3} matrix The matrix to use.\r\n * @param {Number} index The zero-based index of the row to set.\r\n * @param {Cartesian3} cartesian The Cartesian whose values will be assigned to the specified row.\r\n * @param {Matrix3} result The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter.\r\n *\r\n * @exception {DeveloperError} index must be 0, 1, or 2.\r\n */\r\nMatrix3.setRow = function (matrix, index, cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\r\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 2);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result = Matrix3.clone(matrix, result);\r\n result[index] = cartesian.x;\r\n result[index + 3] = cartesian.y;\r\n result[index + 6] = cartesian.z;\r\n return result;\r\n};\r\n\r\nvar scratchColumn = new Cartesian3();\r\n\r\n/**\r\n * Extracts the non-uniform scale assuming the matrix is an affine transformation.\r\n *\r\n * @param {Matrix3} matrix The matrix.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n */\r\nMatrix3.getScale = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = Cartesian3.magnitude(\r\n Cartesian3.fromElements(matrix[0], matrix[1], matrix[2], scratchColumn)\r\n );\r\n result.y = Cartesian3.magnitude(\r\n Cartesian3.fromElements(matrix[3], matrix[4], matrix[5], scratchColumn)\r\n );\r\n result.z = Cartesian3.magnitude(\r\n Cartesian3.fromElements(matrix[6], matrix[7], matrix[8], scratchColumn)\r\n );\r\n return result;\r\n};\r\n\r\nvar scratchScale = new Cartesian3();\r\n\r\n/**\r\n * Computes the maximum scale assuming the matrix is an affine transformation.\r\n * The maximum scale is the maximum length of the column vectors.\r\n *\r\n * @param {Matrix3} matrix The matrix.\r\n * @returns {Number} The maximum scale.\r\n */\r\nMatrix3.getMaximumScale = function (matrix) {\r\n Matrix3.getScale(matrix, scratchScale);\r\n return Cartesian3.maximumComponent(scratchScale);\r\n};\r\n\r\n/**\r\n * Computes the product of two matrices.\r\n *\r\n * @param {Matrix3} left The first matrix.\r\n * @param {Matrix3} right The second matrix.\r\n * @param {Matrix3} result The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter.\r\n */\r\nMatrix3.multiply = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var column0Row0 =\r\n left[0] * right[0] + left[3] * right[1] + left[6] * right[2];\r\n var column0Row1 =\r\n left[1] * right[0] + left[4] * right[1] + left[7] * right[2];\r\n var column0Row2 =\r\n left[2] * right[0] + left[5] * right[1] + left[8] * right[2];\r\n\r\n var column1Row0 =\r\n left[0] * right[3] + left[3] * right[4] + left[6] * right[5];\r\n var column1Row1 =\r\n left[1] * right[3] + left[4] * right[4] + left[7] * right[5];\r\n var column1Row2 =\r\n left[2] * right[3] + left[5] * right[4] + left[8] * right[5];\r\n\r\n var column2Row0 =\r\n left[0] * right[6] + left[3] * right[7] + left[6] * right[8];\r\n var column2Row1 =\r\n left[1] * right[6] + left[4] * right[7] + left[7] * right[8];\r\n var column2Row2 =\r\n left[2] * right[6] + left[5] * right[7] + left[8] * right[8];\r\n\r\n result[0] = column0Row0;\r\n result[1] = column0Row1;\r\n result[2] = column0Row2;\r\n result[3] = column1Row0;\r\n result[4] = column1Row1;\r\n result[5] = column1Row2;\r\n result[6] = column2Row0;\r\n result[7] = column2Row1;\r\n result[8] = column2Row2;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the sum of two matrices.\r\n *\r\n * @param {Matrix3} left The first matrix.\r\n * @param {Matrix3} right The second matrix.\r\n * @param {Matrix3} result The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter.\r\n */\r\nMatrix3.add = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result[0] = left[0] + right[0];\r\n result[1] = left[1] + right[1];\r\n result[2] = left[2] + right[2];\r\n result[3] = left[3] + right[3];\r\n result[4] = left[4] + right[4];\r\n result[5] = left[5] + right[5];\r\n result[6] = left[6] + right[6];\r\n result[7] = left[7] + right[7];\r\n result[8] = left[8] + right[8];\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the difference of two matrices.\r\n *\r\n * @param {Matrix3} left The first matrix.\r\n * @param {Matrix3} right The second matrix.\r\n * @param {Matrix3} result The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter.\r\n */\r\nMatrix3.subtract = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result[0] = left[0] - right[0];\r\n result[1] = left[1] - right[1];\r\n result[2] = left[2] - right[2];\r\n result[3] = left[3] - right[3];\r\n result[4] = left[4] - right[4];\r\n result[5] = left[5] - right[5];\r\n result[6] = left[6] - right[6];\r\n result[7] = left[7] - right[7];\r\n result[8] = left[8] - right[8];\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the product of a matrix and a column vector.\r\n *\r\n * @param {Matrix3} matrix The matrix.\r\n * @param {Cartesian3} cartesian The column.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n */\r\nMatrix3.multiplyByVector = function (matrix, cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var vX = cartesian.x;\r\n var vY = cartesian.y;\r\n var vZ = cartesian.z;\r\n\r\n var x = matrix[0] * vX + matrix[3] * vY + matrix[6] * vZ;\r\n var y = matrix[1] * vX + matrix[4] * vY + matrix[7] * vZ;\r\n var z = matrix[2] * vX + matrix[5] * vY + matrix[8] * vZ;\r\n\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the product of a matrix and a scalar.\r\n *\r\n * @param {Matrix3} matrix The matrix.\r\n * @param {Number} scalar The number to multiply by.\r\n * @param {Matrix3} result The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter.\r\n */\r\nMatrix3.multiplyByScalar = function (matrix, scalar, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.number(\"scalar\", scalar);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result[0] = matrix[0] * scalar;\r\n result[1] = matrix[1] * scalar;\r\n result[2] = matrix[2] * scalar;\r\n result[3] = matrix[3] * scalar;\r\n result[4] = matrix[4] * scalar;\r\n result[5] = matrix[5] * scalar;\r\n result[6] = matrix[6] * scalar;\r\n result[7] = matrix[7] * scalar;\r\n result[8] = matrix[8] * scalar;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the product of a matrix times a (non-uniform) scale, as if the scale were a scale matrix.\r\n *\r\n * @param {Matrix3} matrix The matrix on the left-hand side.\r\n * @param {Cartesian3} scale The non-uniform scale on the right-hand side.\r\n * @param {Matrix3} result The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter.\r\n *\r\n *\r\n * @example\r\n * // Instead of Cesium.Matrix3.multiply(m, Cesium.Matrix3.fromScale(scale), m);\r\n * Cesium.Matrix3.multiplyByScale(m, scale, m);\r\n *\r\n * @see Matrix3.fromScale\r\n * @see Matrix3.multiplyByUniformScale\r\n */\r\nMatrix3.multiplyByScale = function (matrix, scale, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"scale\", scale);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result[0] = matrix[0] * scale.x;\r\n result[1] = matrix[1] * scale.x;\r\n result[2] = matrix[2] * scale.x;\r\n result[3] = matrix[3] * scale.y;\r\n result[4] = matrix[4] * scale.y;\r\n result[5] = matrix[5] * scale.y;\r\n result[6] = matrix[6] * scale.z;\r\n result[7] = matrix[7] * scale.z;\r\n result[8] = matrix[8] * scale.z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a negated copy of the provided matrix.\r\n *\r\n * @param {Matrix3} matrix The matrix to negate.\r\n * @param {Matrix3} result The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter.\r\n */\r\nMatrix3.negate = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result[0] = -matrix[0];\r\n result[1] = -matrix[1];\r\n result[2] = -matrix[2];\r\n result[3] = -matrix[3];\r\n result[4] = -matrix[4];\r\n result[5] = -matrix[5];\r\n result[6] = -matrix[6];\r\n result[7] = -matrix[7];\r\n result[8] = -matrix[8];\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the transpose of the provided matrix.\r\n *\r\n * @param {Matrix3} matrix The matrix to transpose.\r\n * @param {Matrix3} result The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter.\r\n */\r\nMatrix3.transpose = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var column0Row0 = matrix[0];\r\n var column0Row1 = matrix[3];\r\n var column0Row2 = matrix[6];\r\n var column1Row0 = matrix[1];\r\n var column1Row1 = matrix[4];\r\n var column1Row2 = matrix[7];\r\n var column2Row0 = matrix[2];\r\n var column2Row1 = matrix[5];\r\n var column2Row2 = matrix[8];\r\n\r\n result[0] = column0Row0;\r\n result[1] = column0Row1;\r\n result[2] = column0Row2;\r\n result[3] = column1Row0;\r\n result[4] = column1Row1;\r\n result[5] = column1Row2;\r\n result[6] = column2Row0;\r\n result[7] = column2Row1;\r\n result[8] = column2Row2;\r\n return result;\r\n};\r\n\r\nvar UNIT = new Cartesian3(1, 1, 1);\r\n\r\n/**\r\n * Extracts the rotation assuming the matrix is an affine transformation.\r\n *\r\n * @param {Matrix3} matrix The matrix.\r\n * @param {Matrix3} result The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter\r\n */\r\nMatrix3.getRotation = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var inverseScale = Cartesian3.divideComponents(\r\n UNIT,\r\n Matrix3.getScale(matrix, scratchScale),\r\n scratchScale\r\n );\r\n result = Matrix3.multiplyByScale(matrix, inverseScale, result);\r\n\r\n return result;\r\n};\r\n\r\nfunction computeFrobeniusNorm(matrix) {\r\n var norm = 0.0;\r\n for (var i = 0; i < 9; ++i) {\r\n var temp = matrix[i];\r\n norm += temp * temp;\r\n }\r\n\r\n return Math.sqrt(norm);\r\n}\r\n\r\nvar rowVal = [1, 0, 0];\r\nvar colVal = [2, 2, 1];\r\n\r\nfunction offDiagonalFrobeniusNorm(matrix) {\r\n // Computes the \"off-diagonal\" Frobenius norm.\r\n // Assumes matrix is symmetric.\r\n\r\n var norm = 0.0;\r\n for (var i = 0; i < 3; ++i) {\r\n var temp = matrix[Matrix3.getElementIndex(colVal[i], rowVal[i])];\r\n norm += 2.0 * temp * temp;\r\n }\r\n\r\n return Math.sqrt(norm);\r\n}\r\n\r\nfunction shurDecomposition(matrix, result) {\r\n // This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,\r\n // section 8.4.2 The 2by2 Symmetric Schur Decomposition.\r\n //\r\n // The routine takes a matrix, which is assumed to be symmetric, and\r\n // finds the largest off-diagonal term, and then creates\r\n // a matrix (result) which can be used to help reduce it\r\n\r\n var tolerance = CesiumMath.EPSILON15;\r\n\r\n var maxDiagonal = 0.0;\r\n var rotAxis = 1;\r\n\r\n // find pivot (rotAxis) based on max diagonal of matrix\r\n for (var i = 0; i < 3; ++i) {\r\n var temp = Math.abs(matrix[Matrix3.getElementIndex(colVal[i], rowVal[i])]);\r\n if (temp > maxDiagonal) {\r\n rotAxis = i;\r\n maxDiagonal = temp;\r\n }\r\n }\r\n\r\n var c = 1.0;\r\n var s = 0.0;\r\n\r\n var p = rowVal[rotAxis];\r\n var q = colVal[rotAxis];\r\n\r\n if (Math.abs(matrix[Matrix3.getElementIndex(q, p)]) > tolerance) {\r\n var qq = matrix[Matrix3.getElementIndex(q, q)];\r\n var pp = matrix[Matrix3.getElementIndex(p, p)];\r\n var qp = matrix[Matrix3.getElementIndex(q, p)];\r\n\r\n var tau = (qq - pp) / 2.0 / qp;\r\n var t;\r\n\r\n if (tau < 0.0) {\r\n t = -1.0 / (-tau + Math.sqrt(1.0 + tau * tau));\r\n } else {\r\n t = 1.0 / (tau + Math.sqrt(1.0 + tau * tau));\r\n }\r\n\r\n c = 1.0 / Math.sqrt(1.0 + t * t);\r\n s = t * c;\r\n }\r\n\r\n result = Matrix3.clone(Matrix3.IDENTITY, result);\r\n\r\n result[Matrix3.getElementIndex(p, p)] = result[\r\n Matrix3.getElementIndex(q, q)\r\n ] = c;\r\n result[Matrix3.getElementIndex(q, p)] = s;\r\n result[Matrix3.getElementIndex(p, q)] = -s;\r\n\r\n return result;\r\n}\r\n\r\nvar jMatrix = new Matrix3();\r\nvar jMatrixTranspose = new Matrix3();\r\n\r\n/**\r\n * Computes the eigenvectors and eigenvalues of a symmetric matrix.\r\n * \r\n * Returns a diagonal matrix and unitary matrix such that:\r\n * matrix = unitary matrix * diagonal matrix * transpose(unitary matrix)
\r\n *
\r\n * \r\n * The values along the diagonal of the diagonal matrix are the eigenvalues. The columns\r\n * of the unitary matrix are the corresponding eigenvectors.\r\n *
\r\n *\r\n * @param {Matrix3} matrix The matrix to decompose into diagonal and unitary matrix. Expected to be symmetric.\r\n * @param {Object} [result] An object with unitary and diagonal properties which are matrices onto which to store the result.\r\n * @returns {Object} An object with unitary and diagonal properties which are the unitary and diagonal matrices, respectively.\r\n *\r\n * @example\r\n * var a = //... symetric matrix\r\n * var result = {\r\n * unitary : new Cesium.Matrix3(),\r\n * diagonal : new Cesium.Matrix3()\r\n * };\r\n * Cesium.Matrix3.computeEigenDecomposition(a, result);\r\n *\r\n * var unitaryTranspose = Cesium.Matrix3.transpose(result.unitary, new Cesium.Matrix3());\r\n * var b = Cesium.Matrix3.multiply(result.unitary, result.diagonal, new Cesium.Matrix3());\r\n * Cesium.Matrix3.multiply(b, unitaryTranspose, b); // b is now equal to a\r\n *\r\n * var lambda = Cesium.Matrix3.getColumn(result.diagonal, 0, new Cesium.Cartesian3()).x; // first eigenvalue\r\n * var v = Cesium.Matrix3.getColumn(result.unitary, 0, new Cesium.Cartesian3()); // first eigenvector\r\n * var c = Cesium.Cartesian3.multiplyByScalar(v, lambda, new Cesium.Cartesian3()); // equal to Cesium.Matrix3.multiplyByVector(a, v)\r\n */\r\nMatrix3.computeEigenDecomposition = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n //>>includeEnd('debug');\r\n\r\n // This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,\r\n // section 8.4.3 The Classical Jacobi Algorithm\r\n\r\n var tolerance = CesiumMath.EPSILON20;\r\n var maxSweeps = 10;\r\n\r\n var count = 0;\r\n var sweep = 0;\r\n\r\n if (!defined(result)) {\r\n result = {};\r\n }\r\n\r\n var unitaryMatrix = (result.unitary = Matrix3.clone(\r\n Matrix3.IDENTITY,\r\n result.unitary\r\n ));\r\n var diagMatrix = (result.diagonal = Matrix3.clone(matrix, result.diagonal));\r\n\r\n var epsilon = tolerance * computeFrobeniusNorm(diagMatrix);\r\n\r\n while (sweep < maxSweeps && offDiagonalFrobeniusNorm(diagMatrix) > epsilon) {\r\n shurDecomposition(diagMatrix, jMatrix);\r\n Matrix3.transpose(jMatrix, jMatrixTranspose);\r\n Matrix3.multiply(diagMatrix, jMatrix, diagMatrix);\r\n Matrix3.multiply(jMatrixTranspose, diagMatrix, diagMatrix);\r\n Matrix3.multiply(unitaryMatrix, jMatrix, unitaryMatrix);\r\n\r\n if (++count > 2) {\r\n ++sweep;\r\n count = 0;\r\n }\r\n }\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a matrix, which contains the absolute (unsigned) values of the provided matrix's elements.\r\n *\r\n * @param {Matrix3} matrix The matrix with signed elements.\r\n * @param {Matrix3} result The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter.\r\n */\r\nMatrix3.abs = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result[0] = Math.abs(matrix[0]);\r\n result[1] = Math.abs(matrix[1]);\r\n result[2] = Math.abs(matrix[2]);\r\n result[3] = Math.abs(matrix[3]);\r\n result[4] = Math.abs(matrix[4]);\r\n result[5] = Math.abs(matrix[5]);\r\n result[6] = Math.abs(matrix[6]);\r\n result[7] = Math.abs(matrix[7]);\r\n result[8] = Math.abs(matrix[8]);\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the determinant of the provided matrix.\r\n *\r\n * @param {Matrix3} matrix The matrix to use.\r\n * @returns {Number} The value of the determinant of the matrix.\r\n */\r\nMatrix3.determinant = function (matrix) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n //>>includeEnd('debug');\r\n\r\n var m11 = matrix[0];\r\n var m21 = matrix[3];\r\n var m31 = matrix[6];\r\n var m12 = matrix[1];\r\n var m22 = matrix[4];\r\n var m32 = matrix[7];\r\n var m13 = matrix[2];\r\n var m23 = matrix[5];\r\n var m33 = matrix[8];\r\n\r\n return (\r\n m11 * (m22 * m33 - m23 * m32) +\r\n m12 * (m23 * m31 - m21 * m33) +\r\n m13 * (m21 * m32 - m22 * m31)\r\n );\r\n};\r\n\r\n/**\r\n * Computes the inverse of the provided matrix.\r\n *\r\n * @param {Matrix3} matrix The matrix to invert.\r\n * @param {Matrix3} result The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter.\r\n *\r\n * @exception {DeveloperError} matrix is not invertible.\r\n */\r\nMatrix3.inverse = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var m11 = matrix[0];\r\n var m21 = matrix[1];\r\n var m31 = matrix[2];\r\n var m12 = matrix[3];\r\n var m22 = matrix[4];\r\n var m32 = matrix[5];\r\n var m13 = matrix[6];\r\n var m23 = matrix[7];\r\n var m33 = matrix[8];\r\n\r\n var determinant = Matrix3.determinant(matrix);\r\n\r\n //>>includeStart('debug', pragmas.debug);\r\n if (Math.abs(determinant) <= CesiumMath.EPSILON15) {\r\n throw new DeveloperError(\"matrix is not invertible\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n result[0] = m22 * m33 - m23 * m32;\r\n result[1] = m23 * m31 - m21 * m33;\r\n result[2] = m21 * m32 - m22 * m31;\r\n result[3] = m13 * m32 - m12 * m33;\r\n result[4] = m11 * m33 - m13 * m31;\r\n result[5] = m12 * m31 - m11 * m32;\r\n result[6] = m12 * m23 - m13 * m22;\r\n result[7] = m13 * m21 - m11 * m23;\r\n result[8] = m11 * m22 - m12 * m21;\r\n\r\n var scale = 1.0 / determinant;\r\n return Matrix3.multiplyByScalar(result, scale, result);\r\n};\r\n\r\nvar scratchTransposeMatrix = new Matrix3();\r\n\r\n/**\r\n * Computes the inverse transpose of a matrix.\r\n *\r\n * @param {Matrix3} matrix The matrix to transpose and invert.\r\n * @param {Matrix3} result The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter.\r\n */\r\nMatrix3.inverseTranspose = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n return Matrix3.inverse(\r\n Matrix3.transpose(matrix, scratchTransposeMatrix),\r\n result\r\n );\r\n};\r\n\r\n/**\r\n * Compares the provided matrices componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Matrix3} [left] The first matrix.\r\n * @param {Matrix3} [right] The second matrix.\r\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\r\n */\r\nMatrix3.equals = function (left, right) {\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n left[0] === right[0] &&\r\n left[1] === right[1] &&\r\n left[2] === right[2] &&\r\n left[3] === right[3] &&\r\n left[4] === right[4] &&\r\n left[5] === right[5] &&\r\n left[6] === right[6] &&\r\n left[7] === right[7] &&\r\n left[8] === right[8])\r\n );\r\n};\r\n\r\n/**\r\n * Compares the provided matrices componentwise and returns\r\n * true
if they are within the provided epsilon,\r\n * false
otherwise.\r\n *\r\n * @param {Matrix3} [left] The first matrix.\r\n * @param {Matrix3} [right] The second matrix.\r\n * @param {Number} [epsilon=0] The epsilon to use for equality testing.\r\n * @returns {Boolean} true
if left and right are within the provided epsilon, false
otherwise.\r\n */\r\nMatrix3.equalsEpsilon = function (left, right, epsilon) {\r\n epsilon = defaultValue(epsilon, 0);\r\n\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n Math.abs(left[0] - right[0]) <= epsilon &&\r\n Math.abs(left[1] - right[1]) <= epsilon &&\r\n Math.abs(left[2] - right[2]) <= epsilon &&\r\n Math.abs(left[3] - right[3]) <= epsilon &&\r\n Math.abs(left[4] - right[4]) <= epsilon &&\r\n Math.abs(left[5] - right[5]) <= epsilon &&\r\n Math.abs(left[6] - right[6]) <= epsilon &&\r\n Math.abs(left[7] - right[7]) <= epsilon &&\r\n Math.abs(left[8] - right[8]) <= epsilon)\r\n );\r\n};\r\n\r\n/**\r\n * An immutable Matrix3 instance initialized to the identity matrix.\r\n *\r\n * @type {Matrix3}\r\n * @constant\r\n */\r\nMatrix3.IDENTITY = Object.freeze(\r\n new Matrix3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)\r\n);\r\n\r\n/**\r\n * An immutable Matrix3 instance initialized to the zero matrix.\r\n *\r\n * @type {Matrix3}\r\n * @constant\r\n */\r\nMatrix3.ZERO = Object.freeze(\r\n new Matrix3(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)\r\n);\r\n\r\n/**\r\n * The index into Matrix3 for column 0, row 0.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix3.COLUMN0ROW0 = 0;\r\n\r\n/**\r\n * The index into Matrix3 for column 0, row 1.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix3.COLUMN0ROW1 = 1;\r\n\r\n/**\r\n * The index into Matrix3 for column 0, row 2.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix3.COLUMN0ROW2 = 2;\r\n\r\n/**\r\n * The index into Matrix3 for column 1, row 0.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix3.COLUMN1ROW0 = 3;\r\n\r\n/**\r\n * The index into Matrix3 for column 1, row 1.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix3.COLUMN1ROW1 = 4;\r\n\r\n/**\r\n * The index into Matrix3 for column 1, row 2.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix3.COLUMN1ROW2 = 5;\r\n\r\n/**\r\n * The index into Matrix3 for column 2, row 0.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix3.COLUMN2ROW0 = 6;\r\n\r\n/**\r\n * The index into Matrix3 for column 2, row 1.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix3.COLUMN2ROW1 = 7;\r\n\r\n/**\r\n * The index into Matrix3 for column 2, row 2.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix3.COLUMN2ROW2 = 8;\r\n\r\nObject.defineProperties(Matrix3.prototype, {\r\n /**\r\n * Gets the number of items in the collection.\r\n * @memberof Matrix3.prototype\r\n *\r\n * @type {Number}\r\n */\r\n length: {\r\n get: function () {\r\n return Matrix3.packedLength;\r\n },\r\n },\r\n});\r\n\r\n/**\r\n * Duplicates the provided Matrix3 instance.\r\n *\r\n * @param {Matrix3} [result] The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.\r\n */\r\nMatrix3.prototype.clone = function (result) {\r\n return Matrix3.clone(this, result);\r\n};\r\n\r\n/**\r\n * Compares this matrix to the provided matrix componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Matrix3} [right] The right hand side matrix.\r\n * @returns {Boolean} true
if they are equal, false
otherwise.\r\n */\r\nMatrix3.prototype.equals = function (right) {\r\n return Matrix3.equals(this, right);\r\n};\r\n\r\n/**\r\n * @private\r\n */\r\nMatrix3.equalsArray = function (matrix, array, offset) {\r\n return (\r\n matrix[0] === array[offset] &&\r\n matrix[1] === array[offset + 1] &&\r\n matrix[2] === array[offset + 2] &&\r\n matrix[3] === array[offset + 3] &&\r\n matrix[4] === array[offset + 4] &&\r\n matrix[5] === array[offset + 5] &&\r\n matrix[6] === array[offset + 6] &&\r\n matrix[7] === array[offset + 7] &&\r\n matrix[8] === array[offset + 8]\r\n );\r\n};\r\n\r\n/**\r\n * Compares this matrix to the provided matrix componentwise and returns\r\n * true
if they are within the provided epsilon,\r\n * false
otherwise.\r\n *\r\n * @param {Matrix3} [right] The right hand side matrix.\r\n * @param {Number} [epsilon=0] The epsilon to use for equality testing.\r\n * @returns {Boolean} true
if they are within the provided epsilon, false
otherwise.\r\n */\r\nMatrix3.prototype.equalsEpsilon = function (right, epsilon) {\r\n return Matrix3.equalsEpsilon(this, right, epsilon);\r\n};\r\n\r\n/**\r\n * Creates a string representing this Matrix with each row being\r\n * on a separate line and in the format '(column0, column1, column2)'.\r\n *\r\n * @returns {String} A string representing the provided Matrix with each row being on a separate line and in the format '(column0, column1, column2)'.\r\n */\r\nMatrix3.prototype.toString = function () {\r\n return (\r\n \"(\" +\r\n this[0] +\r\n \", \" +\r\n this[3] +\r\n \", \" +\r\n this[6] +\r\n \")\\n\" +\r\n \"(\" +\r\n this[1] +\r\n \", \" +\r\n this[4] +\r\n \", \" +\r\n this[7] +\r\n \")\\n\" +\r\n \"(\" +\r\n this[2] +\r\n \", \" +\r\n this[5] +\r\n \", \" +\r\n this[8] +\r\n \")\"\r\n );\r\n};\r\nexport default Matrix3;\r\n","import Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport CesiumMath from \"./Math.js\";\r\n\r\n/**\r\n * A 4D Cartesian point.\r\n * @alias Cartesian4\r\n * @constructor\r\n *\r\n * @param {Number} [x=0.0] The X component.\r\n * @param {Number} [y=0.0] The Y component.\r\n * @param {Number} [z=0.0] The Z component.\r\n * @param {Number} [w=0.0] The W component.\r\n *\r\n * @see Cartesian2\r\n * @see Cartesian3\r\n * @see Packable\r\n */\r\nfunction Cartesian4(x, y, z, w) {\r\n /**\r\n * The X component.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.x = defaultValue(x, 0.0);\r\n\r\n /**\r\n * The Y component.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.y = defaultValue(y, 0.0);\r\n\r\n /**\r\n * The Z component.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.z = defaultValue(z, 0.0);\r\n\r\n /**\r\n * The W component.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.w = defaultValue(w, 0.0);\r\n}\r\n\r\n/**\r\n * Creates a Cartesian4 instance from x, y, z and w coordinates.\r\n *\r\n * @param {Number} x The x coordinate.\r\n * @param {Number} y The y coordinate.\r\n * @param {Number} z The z coordinate.\r\n * @param {Number} w The w coordinate.\r\n * @param {Cartesian4} [result] The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.\r\n */\r\nCartesian4.fromElements = function (x, y, z, w, result) {\r\n if (!defined(result)) {\r\n return new Cartesian4(x, y, z, w);\r\n }\r\n\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n result.w = w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a Cartesian4 instance from a {@link Color}. red
, green
, blue
,\r\n * and alpha
map to x
, y
, z
, and w
, respectively.\r\n *\r\n * @param {Color} color The source color.\r\n * @param {Cartesian4} [result] The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.\r\n */\r\nCartesian4.fromColor = function (color, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"color\", color);\r\n //>>includeEnd('debug');\r\n if (!defined(result)) {\r\n return new Cartesian4(color.red, color.green, color.blue, color.alpha);\r\n }\r\n\r\n result.x = color.red;\r\n result.y = color.green;\r\n result.z = color.blue;\r\n result.w = color.alpha;\r\n return result;\r\n};\r\n\r\n/**\r\n * Duplicates a Cartesian4 instance.\r\n *\r\n * @param {Cartesian4} cartesian The Cartesian to duplicate.\r\n * @param {Cartesian4} [result] The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided. (Returns undefined if cartesian is undefined)\r\n */\r\nCartesian4.clone = function (cartesian, result) {\r\n if (!defined(cartesian)) {\r\n return undefined;\r\n }\r\n\r\n if (!defined(result)) {\r\n return new Cartesian4(cartesian.x, cartesian.y, cartesian.z, cartesian.w);\r\n }\r\n\r\n result.x = cartesian.x;\r\n result.y = cartesian.y;\r\n result.z = cartesian.z;\r\n result.w = cartesian.w;\r\n return result;\r\n};\r\n\r\n/**\r\n * The number of elements used to pack the object into an array.\r\n * @type {Number}\r\n */\r\nCartesian4.packedLength = 4;\r\n\r\n/**\r\n * Stores the provided instance into the provided array.\r\n *\r\n * @param {Cartesian4} value The value to pack.\r\n * @param {Number[]} array The array to pack into.\r\n * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.\r\n *\r\n * @returns {Number[]} The array that was packed into\r\n */\r\nCartesian4.pack = function (value, array, startingIndex) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"value\", value);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n array[startingIndex++] = value.x;\r\n array[startingIndex++] = value.y;\r\n array[startingIndex++] = value.z;\r\n array[startingIndex] = value.w;\r\n\r\n return array;\r\n};\r\n\r\n/**\r\n * Retrieves an instance from a packed array.\r\n *\r\n * @param {Number[]} array The packed array.\r\n * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.\r\n * @param {Cartesian4} [result] The object into which to store the result.\r\n * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.\r\n */\r\nCartesian4.unpack = function (array, startingIndex, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian4();\r\n }\r\n result.x = array[startingIndex++];\r\n result.y = array[startingIndex++];\r\n result.z = array[startingIndex++];\r\n result.w = array[startingIndex];\r\n return result;\r\n};\r\n\r\n/**\r\n * Flattens an array of Cartesian4s into and array of components.\r\n *\r\n * @param {Cartesian4[]} array The array of cartesians to pack.\r\n * @param {Number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 4 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 4) elements.\r\n\r\n * @returns {Number[]} The packed array.\r\n */\r\nCartesian4.packArray = function (array, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n var length = array.length;\r\n var resultLength = length * 4;\r\n if (!defined(result)) {\r\n result = new Array(resultLength);\r\n } else if (!Array.isArray(result) && result.length !== resultLength) {\r\n throw new DeveloperError(\r\n \"If result is a typed array, it must have exactly array.length * 4 elements\"\r\n );\r\n } else if (result.length !== resultLength) {\r\n result.length = resultLength;\r\n }\r\n\r\n for (var i = 0; i < length; ++i) {\r\n Cartesian4.pack(array[i], result, i * 4);\r\n }\r\n return result;\r\n};\r\n\r\n/**\r\n * Unpacks an array of cartesian components into and array of Cartesian4s.\r\n *\r\n * @param {Number[]} array The array of components to unpack.\r\n * @param {Cartesian4[]} [result] The array onto which to store the result.\r\n * @returns {Cartesian4[]} The unpacked array.\r\n */\r\nCartesian4.unpackArray = function (array, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n Check.typeOf.number.greaterThanOrEquals(\"array.length\", array.length, 4);\r\n if (array.length % 4 !== 0) {\r\n throw new DeveloperError(\"array length must be a multiple of 4.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var length = array.length;\r\n if (!defined(result)) {\r\n result = new Array(length / 4);\r\n } else {\r\n result.length = length / 4;\r\n }\r\n\r\n for (var i = 0; i < length; i += 4) {\r\n var index = i / 4;\r\n result[index] = Cartesian4.unpack(array, i, result[index]);\r\n }\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a Cartesian4 from four consecutive elements in an array.\r\n * @function\r\n *\r\n * @param {Number[]} array The array whose four consecutive elements correspond to the x, y, z, and w components, respectively.\r\n * @param {Number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.\r\n * @param {Cartesian4} [result] The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.\r\n *\r\n * @example\r\n * // Create a Cartesian4 with (1.0, 2.0, 3.0, 4.0)\r\n * var v = [1.0, 2.0, 3.0, 4.0];\r\n * var p = Cesium.Cartesian4.fromArray(v);\r\n *\r\n * // Create a Cartesian4 with (1.0, 2.0, 3.0, 4.0) using an offset into an array\r\n * var v2 = [0.0, 0.0, 1.0, 2.0, 3.0, 4.0];\r\n * var p2 = Cesium.Cartesian4.fromArray(v2, 2);\r\n */\r\nCartesian4.fromArray = Cartesian4.unpack;\r\n\r\n/**\r\n * Computes the value of the maximum component for the supplied Cartesian.\r\n *\r\n * @param {Cartesian4} cartesian The cartesian to use.\r\n * @returns {Number} The value of the maximum component.\r\n */\r\nCartesian4.maximumComponent = function (cartesian) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n //>>includeEnd('debug');\r\n\r\n return Math.max(cartesian.x, cartesian.y, cartesian.z, cartesian.w);\r\n};\r\n\r\n/**\r\n * Computes the value of the minimum component for the supplied Cartesian.\r\n *\r\n * @param {Cartesian4} cartesian The cartesian to use.\r\n * @returns {Number} The value of the minimum component.\r\n */\r\nCartesian4.minimumComponent = function (cartesian) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n //>>includeEnd('debug');\r\n\r\n return Math.min(cartesian.x, cartesian.y, cartesian.z, cartesian.w);\r\n};\r\n\r\n/**\r\n * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.\r\n *\r\n * @param {Cartesian4} first A cartesian to compare.\r\n * @param {Cartesian4} second A cartesian to compare.\r\n * @param {Cartesian4} result The object into which to store the result.\r\n * @returns {Cartesian4} A cartesian with the minimum components.\r\n */\r\nCartesian4.minimumByComponent = function (first, second, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"first\", first);\r\n Check.typeOf.object(\"second\", second);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = Math.min(first.x, second.x);\r\n result.y = Math.min(first.y, second.y);\r\n result.z = Math.min(first.z, second.z);\r\n result.w = Math.min(first.w, second.w);\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.\r\n *\r\n * @param {Cartesian4} first A cartesian to compare.\r\n * @param {Cartesian4} second A cartesian to compare.\r\n * @param {Cartesian4} result The object into which to store the result.\r\n * @returns {Cartesian4} A cartesian with the maximum components.\r\n */\r\nCartesian4.maximumByComponent = function (first, second, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"first\", first);\r\n Check.typeOf.object(\"second\", second);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = Math.max(first.x, second.x);\r\n result.y = Math.max(first.y, second.y);\r\n result.z = Math.max(first.z, second.z);\r\n result.w = Math.max(first.w, second.w);\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the provided Cartesian's squared magnitude.\r\n *\r\n * @param {Cartesian4} cartesian The Cartesian instance whose squared magnitude is to be computed.\r\n * @returns {Number} The squared magnitude.\r\n */\r\nCartesian4.magnitudeSquared = function (cartesian) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n //>>includeEnd('debug');\r\n\r\n return (\r\n cartesian.x * cartesian.x +\r\n cartesian.y * cartesian.y +\r\n cartesian.z * cartesian.z +\r\n cartesian.w * cartesian.w\r\n );\r\n};\r\n\r\n/**\r\n * Computes the Cartesian's magnitude (length).\r\n *\r\n * @param {Cartesian4} cartesian The Cartesian instance whose magnitude is to be computed.\r\n * @returns {Number} The magnitude.\r\n */\r\nCartesian4.magnitude = function (cartesian) {\r\n return Math.sqrt(Cartesian4.magnitudeSquared(cartesian));\r\n};\r\n\r\nvar distanceScratch = new Cartesian4();\r\n\r\n/**\r\n * Computes the 4-space distance between two points.\r\n *\r\n * @param {Cartesian4} left The first point to compute the distance from.\r\n * @param {Cartesian4} right The second point to compute the distance to.\r\n * @returns {Number} The distance between two points.\r\n *\r\n * @example\r\n * // Returns 1.0\r\n * var d = Cesium.Cartesian4.distance(\r\n * new Cesium.Cartesian4(1.0, 0.0, 0.0, 0.0),\r\n * new Cesium.Cartesian4(2.0, 0.0, 0.0, 0.0));\r\n */\r\nCartesian4.distance = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n //>>includeEnd('debug');\r\n\r\n Cartesian4.subtract(left, right, distanceScratch);\r\n return Cartesian4.magnitude(distanceScratch);\r\n};\r\n\r\n/**\r\n * Computes the squared distance between two points. Comparing squared distances\r\n * using this function is more efficient than comparing distances using {@link Cartesian4#distance}.\r\n *\r\n * @param {Cartesian4} left The first point to compute the distance from.\r\n * @param {Cartesian4} right The second point to compute the distance to.\r\n * @returns {Number} The distance between two points.\r\n *\r\n * @example\r\n * // Returns 4.0, not 2.0\r\n * var d = Cesium.Cartesian4.distance(\r\n * new Cesium.Cartesian4(1.0, 0.0, 0.0, 0.0),\r\n * new Cesium.Cartesian4(3.0, 0.0, 0.0, 0.0));\r\n */\r\nCartesian4.distanceSquared = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n //>>includeEnd('debug');\r\n\r\n Cartesian4.subtract(left, right, distanceScratch);\r\n return Cartesian4.magnitudeSquared(distanceScratch);\r\n};\r\n\r\n/**\r\n * Computes the normalized form of the supplied Cartesian.\r\n *\r\n * @param {Cartesian4} cartesian The Cartesian to be normalized.\r\n * @param {Cartesian4} result The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter.\r\n */\r\nCartesian4.normalize = function (cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var magnitude = Cartesian4.magnitude(cartesian);\r\n\r\n result.x = cartesian.x / magnitude;\r\n result.y = cartesian.y / magnitude;\r\n result.z = cartesian.z / magnitude;\r\n result.w = cartesian.w / magnitude;\r\n\r\n //>>includeStart('debug', pragmas.debug);\r\n if (\r\n isNaN(result.x) ||\r\n isNaN(result.y) ||\r\n isNaN(result.z) ||\r\n isNaN(result.w)\r\n ) {\r\n throw new DeveloperError(\"normalized result is not a number\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the dot (scalar) product of two Cartesians.\r\n *\r\n * @param {Cartesian4} left The first Cartesian.\r\n * @param {Cartesian4} right The second Cartesian.\r\n * @returns {Number} The dot product.\r\n */\r\nCartesian4.dot = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n //>>includeEnd('debug');\r\n\r\n return (\r\n left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w\r\n );\r\n};\r\n\r\n/**\r\n * Computes the componentwise product of two Cartesians.\r\n *\r\n * @param {Cartesian4} left The first Cartesian.\r\n * @param {Cartesian4} right The second Cartesian.\r\n * @param {Cartesian4} result The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter.\r\n */\r\nCartesian4.multiplyComponents = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = left.x * right.x;\r\n result.y = left.y * right.y;\r\n result.z = left.z * right.z;\r\n result.w = left.w * right.w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the componentwise quotient of two Cartesians.\r\n *\r\n * @param {Cartesian4} left The first Cartesian.\r\n * @param {Cartesian4} right The second Cartesian.\r\n * @param {Cartesian4} result The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter.\r\n */\r\nCartesian4.divideComponents = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = left.x / right.x;\r\n result.y = left.y / right.y;\r\n result.z = left.z / right.z;\r\n result.w = left.w / right.w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the componentwise sum of two Cartesians.\r\n *\r\n * @param {Cartesian4} left The first Cartesian.\r\n * @param {Cartesian4} right The second Cartesian.\r\n * @param {Cartesian4} result The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter.\r\n */\r\nCartesian4.add = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = left.x + right.x;\r\n result.y = left.y + right.y;\r\n result.z = left.z + right.z;\r\n result.w = left.w + right.w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the componentwise difference of two Cartesians.\r\n *\r\n * @param {Cartesian4} left The first Cartesian.\r\n * @param {Cartesian4} right The second Cartesian.\r\n * @param {Cartesian4} result The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter.\r\n */\r\nCartesian4.subtract = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = left.x - right.x;\r\n result.y = left.y - right.y;\r\n result.z = left.z - right.z;\r\n result.w = left.w - right.w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Multiplies the provided Cartesian componentwise by the provided scalar.\r\n *\r\n * @param {Cartesian4} cartesian The Cartesian to be scaled.\r\n * @param {Number} scalar The scalar to multiply with.\r\n * @param {Cartesian4} result The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter.\r\n */\r\nCartesian4.multiplyByScalar = function (cartesian, scalar, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.number(\"scalar\", scalar);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = cartesian.x * scalar;\r\n result.y = cartesian.y * scalar;\r\n result.z = cartesian.z * scalar;\r\n result.w = cartesian.w * scalar;\r\n return result;\r\n};\r\n\r\n/**\r\n * Divides the provided Cartesian componentwise by the provided scalar.\r\n *\r\n * @param {Cartesian4} cartesian The Cartesian to be divided.\r\n * @param {Number} scalar The scalar to divide by.\r\n * @param {Cartesian4} result The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter.\r\n */\r\nCartesian4.divideByScalar = function (cartesian, scalar, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.number(\"scalar\", scalar);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = cartesian.x / scalar;\r\n result.y = cartesian.y / scalar;\r\n result.z = cartesian.z / scalar;\r\n result.w = cartesian.w / scalar;\r\n return result;\r\n};\r\n\r\n/**\r\n * Negates the provided Cartesian.\r\n *\r\n * @param {Cartesian4} cartesian The Cartesian to be negated.\r\n * @param {Cartesian4} result The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter.\r\n */\r\nCartesian4.negate = function (cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = -cartesian.x;\r\n result.y = -cartesian.y;\r\n result.z = -cartesian.z;\r\n result.w = -cartesian.w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the absolute value of the provided Cartesian.\r\n *\r\n * @param {Cartesian4} cartesian The Cartesian whose absolute value is to be computed.\r\n * @param {Cartesian4} result The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter.\r\n */\r\nCartesian4.abs = function (cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = Math.abs(cartesian.x);\r\n result.y = Math.abs(cartesian.y);\r\n result.z = Math.abs(cartesian.z);\r\n result.w = Math.abs(cartesian.w);\r\n return result;\r\n};\r\n\r\nvar lerpScratch = new Cartesian4();\r\n/**\r\n * Computes the linear interpolation or extrapolation at t using the provided cartesians.\r\n *\r\n * @param {Cartesian4} start The value corresponding to t at 0.0.\r\n * @param {Cartesian4}end The value corresponding to t at 1.0.\r\n * @param {Number} t The point along t at which to interpolate.\r\n * @param {Cartesian4} result The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter.\r\n */\r\nCartesian4.lerp = function (start, end, t, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"start\", start);\r\n Check.typeOf.object(\"end\", end);\r\n Check.typeOf.number(\"t\", t);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n Cartesian4.multiplyByScalar(end, t, lerpScratch);\r\n result = Cartesian4.multiplyByScalar(start, 1.0 - t, result);\r\n return Cartesian4.add(lerpScratch, result, result);\r\n};\r\n\r\nvar mostOrthogonalAxisScratch = new Cartesian4();\r\n/**\r\n * Returns the axis that is most orthogonal to the provided Cartesian.\r\n *\r\n * @param {Cartesian4} cartesian The Cartesian on which to find the most orthogonal axis.\r\n * @param {Cartesian4} result The object onto which to store the result.\r\n * @returns {Cartesian4} The most orthogonal axis.\r\n */\r\nCartesian4.mostOrthogonalAxis = function (cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var f = Cartesian4.normalize(cartesian, mostOrthogonalAxisScratch);\r\n Cartesian4.abs(f, f);\r\n\r\n if (f.x <= f.y) {\r\n if (f.x <= f.z) {\r\n if (f.x <= f.w) {\r\n result = Cartesian4.clone(Cartesian4.UNIT_X, result);\r\n } else {\r\n result = Cartesian4.clone(Cartesian4.UNIT_W, result);\r\n }\r\n } else if (f.z <= f.w) {\r\n result = Cartesian4.clone(Cartesian4.UNIT_Z, result);\r\n } else {\r\n result = Cartesian4.clone(Cartesian4.UNIT_W, result);\r\n }\r\n } else if (f.y <= f.z) {\r\n if (f.y <= f.w) {\r\n result = Cartesian4.clone(Cartesian4.UNIT_Y, result);\r\n } else {\r\n result = Cartesian4.clone(Cartesian4.UNIT_W, result);\r\n }\r\n } else if (f.z <= f.w) {\r\n result = Cartesian4.clone(Cartesian4.UNIT_Z, result);\r\n } else {\r\n result = Cartesian4.clone(Cartesian4.UNIT_W, result);\r\n }\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Compares the provided Cartesians componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Cartesian4} [left] The first Cartesian.\r\n * @param {Cartesian4} [right] The second Cartesian.\r\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\r\n */\r\nCartesian4.equals = function (left, right) {\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n left.x === right.x &&\r\n left.y === right.y &&\r\n left.z === right.z &&\r\n left.w === right.w)\r\n );\r\n};\r\n\r\n/**\r\n * @private\r\n */\r\nCartesian4.equalsArray = function (cartesian, array, offset) {\r\n return (\r\n cartesian.x === array[offset] &&\r\n cartesian.y === array[offset + 1] &&\r\n cartesian.z === array[offset + 2] &&\r\n cartesian.w === array[offset + 3]\r\n );\r\n};\r\n\r\n/**\r\n * Compares the provided Cartesians componentwise and returns\r\n * true
if they pass an absolute or relative tolerance test,\r\n * false
otherwise.\r\n *\r\n * @param {Cartesian4} [left] The first Cartesian.\r\n * @param {Cartesian4} [right] The second Cartesian.\r\n * @param {Number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\r\n * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\r\n * @returns {Boolean} true
if left and right are within the provided epsilon, false
otherwise.\r\n */\r\nCartesian4.equalsEpsilon = function (\r\n left,\r\n right,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n) {\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n CesiumMath.equalsEpsilon(\r\n left.x,\r\n right.x,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n ) &&\r\n CesiumMath.equalsEpsilon(\r\n left.y,\r\n right.y,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n ) &&\r\n CesiumMath.equalsEpsilon(\r\n left.z,\r\n right.z,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n ) &&\r\n CesiumMath.equalsEpsilon(\r\n left.w,\r\n right.w,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n ))\r\n );\r\n};\r\n\r\n/**\r\n * An immutable Cartesian4 instance initialized to (0.0, 0.0, 0.0, 0.0).\r\n *\r\n * @type {Cartesian4}\r\n * @constant\r\n */\r\nCartesian4.ZERO = Object.freeze(new Cartesian4(0.0, 0.0, 0.0, 0.0));\r\n\r\n/**\r\n * An immutable Cartesian4 instance initialized to (1.0, 0.0, 0.0, 0.0).\r\n *\r\n * @type {Cartesian4}\r\n * @constant\r\n */\r\nCartesian4.UNIT_X = Object.freeze(new Cartesian4(1.0, 0.0, 0.0, 0.0));\r\n\r\n/**\r\n * An immutable Cartesian4 instance initialized to (0.0, 1.0, 0.0, 0.0).\r\n *\r\n * @type {Cartesian4}\r\n * @constant\r\n */\r\nCartesian4.UNIT_Y = Object.freeze(new Cartesian4(0.0, 1.0, 0.0, 0.0));\r\n\r\n/**\r\n * An immutable Cartesian4 instance initialized to (0.0, 0.0, 1.0, 0.0).\r\n *\r\n * @type {Cartesian4}\r\n * @constant\r\n */\r\nCartesian4.UNIT_Z = Object.freeze(new Cartesian4(0.0, 0.0, 1.0, 0.0));\r\n\r\n/**\r\n * An immutable Cartesian4 instance initialized to (0.0, 0.0, 0.0, 1.0).\r\n *\r\n * @type {Cartesian4}\r\n * @constant\r\n */\r\nCartesian4.UNIT_W = Object.freeze(new Cartesian4(0.0, 0.0, 0.0, 1.0));\r\n\r\n/**\r\n * Duplicates this Cartesian4 instance.\r\n *\r\n * @param {Cartesian4} [result] The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.\r\n */\r\nCartesian4.prototype.clone = function (result) {\r\n return Cartesian4.clone(this, result);\r\n};\r\n\r\n/**\r\n * Compares this Cartesian against the provided Cartesian componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Cartesian4} [right] The right hand side Cartesian.\r\n * @returns {Boolean} true
if they are equal, false
otherwise.\r\n */\r\nCartesian4.prototype.equals = function (right) {\r\n return Cartesian4.equals(this, right);\r\n};\r\n\r\n/**\r\n * Compares this Cartesian against the provided Cartesian componentwise and returns\r\n * true
if they pass an absolute or relative tolerance test,\r\n * false
otherwise.\r\n *\r\n * @param {Cartesian4} [right] The right hand side Cartesian.\r\n * @param {Number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\r\n * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\r\n * @returns {Boolean} true
if they are within the provided epsilon, false
otherwise.\r\n */\r\nCartesian4.prototype.equalsEpsilon = function (\r\n right,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n) {\r\n return Cartesian4.equalsEpsilon(\r\n this,\r\n right,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n );\r\n};\r\n\r\n/**\r\n * Creates a string representing this Cartesian in the format '(x, y, z, w)'.\r\n *\r\n * @returns {String} A string representing the provided Cartesian in the format '(x, y, z, w)'.\r\n */\r\nCartesian4.prototype.toString = function () {\r\n return \"(\" + this.x + \", \" + this.y + \", \" + this.z + \", \" + this.w + \")\";\r\n};\r\n\r\n// scratchU8Array and scratchF32Array are views into the same buffer\r\nvar scratchF32Array = new Float32Array(1);\r\nvar scratchU8Array = new Uint8Array(scratchF32Array.buffer);\r\n\r\nvar testU32 = new Uint32Array([0x11223344]);\r\nvar testU8 = new Uint8Array(testU32.buffer);\r\nvar littleEndian = testU8[0] === 0x44;\r\n\r\n/**\r\n * Packs an arbitrary floating point value to 4 values representable using uint8.\r\n *\r\n * @param {Number} value A floating point number.\r\n * @param {Cartesian4} [result] The Cartesian4 that will contain the packed float.\r\n * @returns {Cartesian4} A Cartesian4 representing the float packed to values in x, y, z, and w.\r\n */\r\nCartesian4.packFloat = function (value, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number(\"value\", value);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian4();\r\n }\r\n\r\n // scratchU8Array and scratchF32Array are views into the same buffer\r\n scratchF32Array[0] = value;\r\n\r\n if (littleEndian) {\r\n result.x = scratchU8Array[0];\r\n result.y = scratchU8Array[1];\r\n result.z = scratchU8Array[2];\r\n result.w = scratchU8Array[3];\r\n } else {\r\n // convert from big-endian to little-endian\r\n result.x = scratchU8Array[3];\r\n result.y = scratchU8Array[2];\r\n result.z = scratchU8Array[1];\r\n result.w = scratchU8Array[0];\r\n }\r\n return result;\r\n};\r\n\r\n/**\r\n * Unpacks a float packed using Cartesian4.packFloat.\r\n *\r\n * @param {Cartesian4} packedFloat A Cartesian4 containing a float packed to 4 values representable using uint8.\r\n * @returns {Number} The unpacked float.\r\n * @private\r\n */\r\nCartesian4.unpackFloat = function (packedFloat) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"packedFloat\", packedFloat);\r\n //>>includeEnd('debug');\r\n\r\n // scratchU8Array and scratchF32Array are views into the same buffer\r\n if (littleEndian) {\r\n scratchU8Array[0] = packedFloat.x;\r\n scratchU8Array[1] = packedFloat.y;\r\n scratchU8Array[2] = packedFloat.z;\r\n scratchU8Array[3] = packedFloat.w;\r\n } else {\r\n // convert from little-endian to big-endian\r\n scratchU8Array[0] = packedFloat.w;\r\n scratchU8Array[1] = packedFloat.z;\r\n scratchU8Array[2] = packedFloat.y;\r\n scratchU8Array[3] = packedFloat.x;\r\n }\r\n return scratchF32Array[0];\r\n};\r\nexport default Cartesian4;\r\n","import defined from \"./defined.js\";\r\n\r\n/**\r\n * Constructs an exception object that is thrown due to an error that can occur at runtime, e.g.,\r\n * out of memory, could not compile shader, etc. If a function may throw this\r\n * exception, the calling code should be prepared to catch it.\r\n *
\r\n * On the other hand, a {@link DeveloperError} indicates an exception due\r\n * to a developer error, e.g., invalid argument, that usually indicates a bug in the\r\n * calling code.\r\n *\r\n * @alias RuntimeError\r\n * @constructor\r\n * @extends Error\r\n *\r\n * @param {String} [message] The error message for this exception.\r\n *\r\n * @see DeveloperError\r\n */\r\nfunction RuntimeError(message) {\r\n /**\r\n * 'RuntimeError' indicating that this exception was thrown due to a runtime error.\r\n * @type {String}\r\n * @readonly\r\n */\r\n this.name = \"RuntimeError\";\r\n\r\n /**\r\n * The explanation for why this exception was thrown.\r\n * @type {String}\r\n * @readonly\r\n */\r\n this.message = message;\r\n\r\n //Browsers such as IE don't have a stack property until you actually throw the error.\r\n var stack;\r\n try {\r\n throw new Error();\r\n } catch (e) {\r\n stack = e.stack;\r\n }\r\n\r\n /**\r\n * The stack trace of this exception, if available.\r\n * @type {String}\r\n * @readonly\r\n */\r\n this.stack = stack;\r\n}\r\n\r\nif (defined(Object.create)) {\r\n RuntimeError.prototype = Object.create(Error.prototype);\r\n RuntimeError.prototype.constructor = RuntimeError;\r\n}\r\n\r\nRuntimeError.prototype.toString = function () {\r\n var str = this.name + \": \" + this.message;\r\n\r\n if (defined(this.stack)) {\r\n str += \"\\n\" + this.stack.toString();\r\n }\r\n\r\n return str;\r\n};\r\nexport default RuntimeError;\r\n","import Cartesian3 from \"./Cartesian3.js\";\r\nimport Cartesian4 from \"./Cartesian4.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport CesiumMath from \"./Math.js\";\r\nimport Matrix3 from \"./Matrix3.js\";\r\nimport RuntimeError from \"./RuntimeError.js\";\r\n\r\n/**\r\n * A 4x4 matrix, indexable as a column-major order array.\r\n * Constructor parameters are in row-major order for code readability.\r\n * @alias Matrix4\r\n * @constructor\r\n * @implements {ArrayLike}\r\n *\r\n * @param {Number} [column0Row0=0.0] The value for column 0, row 0.\r\n * @param {Number} [column1Row0=0.0] The value for column 1, row 0.\r\n * @param {Number} [column2Row0=0.0] The value for column 2, row 0.\r\n * @param {Number} [column3Row0=0.0] The value for column 3, row 0.\r\n * @param {Number} [column0Row1=0.0] The value for column 0, row 1.\r\n * @param {Number} [column1Row1=0.0] The value for column 1, row 1.\r\n * @param {Number} [column2Row1=0.0] The value for column 2, row 1.\r\n * @param {Number} [column3Row1=0.0] The value for column 3, row 1.\r\n * @param {Number} [column0Row2=0.0] The value for column 0, row 2.\r\n * @param {Number} [column1Row2=0.0] The value for column 1, row 2.\r\n * @param {Number} [column2Row2=0.0] The value for column 2, row 2.\r\n * @param {Number} [column3Row2=0.0] The value for column 3, row 2.\r\n * @param {Number} [column0Row3=0.0] The value for column 0, row 3.\r\n * @param {Number} [column1Row3=0.0] The value for column 1, row 3.\r\n * @param {Number} [column2Row3=0.0] The value for column 2, row 3.\r\n * @param {Number} [column3Row3=0.0] The value for column 3, row 3.\r\n *\r\n * @see Matrix4.fromColumnMajorArray\r\n * @see Matrix4.fromRowMajorArray\r\n * @see Matrix4.fromRotationTranslation\r\n * @see Matrix4.fromTranslationRotationScale\r\n * @see Matrix4.fromTranslationQuaternionRotationScale\r\n * @see Matrix4.fromTranslation\r\n * @see Matrix4.fromScale\r\n * @see Matrix4.fromUniformScale\r\n * @see Matrix4.fromCamera\r\n * @see Matrix4.computePerspectiveFieldOfView\r\n * @see Matrix4.computeOrthographicOffCenter\r\n * @see Matrix4.computePerspectiveOffCenter\r\n * @see Matrix4.computeInfinitePerspectiveOffCenter\r\n * @see Matrix4.computeViewportTransformation\r\n * @see Matrix4.computeView\r\n * @see Matrix2\r\n * @see Matrix3\r\n * @see Packable\r\n */\r\nfunction Matrix4(\r\n column0Row0,\r\n column1Row0,\r\n column2Row0,\r\n column3Row0,\r\n column0Row1,\r\n column1Row1,\r\n column2Row1,\r\n column3Row1,\r\n column0Row2,\r\n column1Row2,\r\n column2Row2,\r\n column3Row2,\r\n column0Row3,\r\n column1Row3,\r\n column2Row3,\r\n column3Row3\r\n) {\r\n this[0] = defaultValue(column0Row0, 0.0);\r\n this[1] = defaultValue(column0Row1, 0.0);\r\n this[2] = defaultValue(column0Row2, 0.0);\r\n this[3] = defaultValue(column0Row3, 0.0);\r\n this[4] = defaultValue(column1Row0, 0.0);\r\n this[5] = defaultValue(column1Row1, 0.0);\r\n this[6] = defaultValue(column1Row2, 0.0);\r\n this[7] = defaultValue(column1Row3, 0.0);\r\n this[8] = defaultValue(column2Row0, 0.0);\r\n this[9] = defaultValue(column2Row1, 0.0);\r\n this[10] = defaultValue(column2Row2, 0.0);\r\n this[11] = defaultValue(column2Row3, 0.0);\r\n this[12] = defaultValue(column3Row0, 0.0);\r\n this[13] = defaultValue(column3Row1, 0.0);\r\n this[14] = defaultValue(column3Row2, 0.0);\r\n this[15] = defaultValue(column3Row3, 0.0);\r\n}\r\n\r\n/**\r\n * The number of elements used to pack the object into an array.\r\n * @type {Number}\r\n */\r\nMatrix4.packedLength = 16;\r\n\r\n/**\r\n * Stores the provided instance into the provided array.\r\n *\r\n * @param {Matrix4} value The value to pack.\r\n * @param {Number[]} array The array to pack into.\r\n * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.\r\n *\r\n * @returns {Number[]} The array that was packed into\r\n */\r\nMatrix4.pack = function (value, array, startingIndex) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"value\", value);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n array[startingIndex++] = value[0];\r\n array[startingIndex++] = value[1];\r\n array[startingIndex++] = value[2];\r\n array[startingIndex++] = value[3];\r\n array[startingIndex++] = value[4];\r\n array[startingIndex++] = value[5];\r\n array[startingIndex++] = value[6];\r\n array[startingIndex++] = value[7];\r\n array[startingIndex++] = value[8];\r\n array[startingIndex++] = value[9];\r\n array[startingIndex++] = value[10];\r\n array[startingIndex++] = value[11];\r\n array[startingIndex++] = value[12];\r\n array[startingIndex++] = value[13];\r\n array[startingIndex++] = value[14];\r\n array[startingIndex] = value[15];\r\n\r\n return array;\r\n};\r\n\r\n/**\r\n * Retrieves an instance from a packed array.\r\n *\r\n * @param {Number[]} array The packed array.\r\n * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.\r\n * @param {Matrix4} [result] The object into which to store the result.\r\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.\r\n */\r\nMatrix4.unpack = function (array, startingIndex, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n if (!defined(result)) {\r\n result = new Matrix4();\r\n }\r\n\r\n result[0] = array[startingIndex++];\r\n result[1] = array[startingIndex++];\r\n result[2] = array[startingIndex++];\r\n result[3] = array[startingIndex++];\r\n result[4] = array[startingIndex++];\r\n result[5] = array[startingIndex++];\r\n result[6] = array[startingIndex++];\r\n result[7] = array[startingIndex++];\r\n result[8] = array[startingIndex++];\r\n result[9] = array[startingIndex++];\r\n result[10] = array[startingIndex++];\r\n result[11] = array[startingIndex++];\r\n result[12] = array[startingIndex++];\r\n result[13] = array[startingIndex++];\r\n result[14] = array[startingIndex++];\r\n result[15] = array[startingIndex];\r\n return result;\r\n};\r\n\r\n/**\r\n * Duplicates a Matrix4 instance.\r\n *\r\n * @param {Matrix4} matrix The matrix to duplicate.\r\n * @param {Matrix4} [result] The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided. (Returns undefined if matrix is undefined)\r\n */\r\nMatrix4.clone = function (matrix, result) {\r\n if (!defined(matrix)) {\r\n return undefined;\r\n }\r\n if (!defined(result)) {\r\n return new Matrix4(\r\n matrix[0],\r\n matrix[4],\r\n matrix[8],\r\n matrix[12],\r\n matrix[1],\r\n matrix[5],\r\n matrix[9],\r\n matrix[13],\r\n matrix[2],\r\n matrix[6],\r\n matrix[10],\r\n matrix[14],\r\n matrix[3],\r\n matrix[7],\r\n matrix[11],\r\n matrix[15]\r\n );\r\n }\r\n result[0] = matrix[0];\r\n result[1] = matrix[1];\r\n result[2] = matrix[2];\r\n result[3] = matrix[3];\r\n result[4] = matrix[4];\r\n result[5] = matrix[5];\r\n result[6] = matrix[6];\r\n result[7] = matrix[7];\r\n result[8] = matrix[8];\r\n result[9] = matrix[9];\r\n result[10] = matrix[10];\r\n result[11] = matrix[11];\r\n result[12] = matrix[12];\r\n result[13] = matrix[13];\r\n result[14] = matrix[14];\r\n result[15] = matrix[15];\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a Matrix4 from 16 consecutive elements in an array.\r\n * @function\r\n *\r\n * @param {Number[]} array The array whose 16 consecutive elements correspond to the positions of the matrix. Assumes column-major order.\r\n * @param {Number} [startingIndex=0] The offset into the array of the first element, which corresponds to first column first row position in the matrix.\r\n * @param {Matrix4} [result] The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.\r\n *\r\n * @example\r\n * // Create the Matrix4:\r\n * // [1.0, 2.0, 3.0, 4.0]\r\n * // [1.0, 2.0, 3.0, 4.0]\r\n * // [1.0, 2.0, 3.0, 4.0]\r\n * // [1.0, 2.0, 3.0, 4.0]\r\n *\r\n * var v = [1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 4.0];\r\n * var m = Cesium.Matrix4.fromArray(v);\r\n *\r\n * // Create same Matrix4 with using an offset into an array\r\n * var v2 = [0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 4.0];\r\n * var m2 = Cesium.Matrix4.fromArray(v2, 2);\r\n */\r\nMatrix4.fromArray = Matrix4.unpack;\r\n\r\n/**\r\n * Computes a Matrix4 instance from a column-major order array.\r\n *\r\n * @param {Number[]} values The column-major order array.\r\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\r\n */\r\nMatrix4.fromColumnMajorArray = function (values, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"values\", values);\r\n //>>includeEnd('debug');\r\n\r\n return Matrix4.clone(values, result);\r\n};\r\n\r\n/**\r\n * Computes a Matrix4 instance from a row-major order array.\r\n * The resulting matrix will be in column-major order.\r\n *\r\n * @param {Number[]} values The row-major order array.\r\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\r\n */\r\nMatrix4.fromRowMajorArray = function (values, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"values\", values);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n return new Matrix4(\r\n values[0],\r\n values[1],\r\n values[2],\r\n values[3],\r\n values[4],\r\n values[5],\r\n values[6],\r\n values[7],\r\n values[8],\r\n values[9],\r\n values[10],\r\n values[11],\r\n values[12],\r\n values[13],\r\n values[14],\r\n values[15]\r\n );\r\n }\r\n result[0] = values[0];\r\n result[1] = values[4];\r\n result[2] = values[8];\r\n result[3] = values[12];\r\n result[4] = values[1];\r\n result[5] = values[5];\r\n result[6] = values[9];\r\n result[7] = values[13];\r\n result[8] = values[2];\r\n result[9] = values[6];\r\n result[10] = values[10];\r\n result[11] = values[14];\r\n result[12] = values[3];\r\n result[13] = values[7];\r\n result[14] = values[11];\r\n result[15] = values[15];\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a Matrix4 instance from a Matrix3 representing the rotation\r\n * and a Cartesian3 representing the translation.\r\n *\r\n * @param {Matrix3} rotation The upper left portion of the matrix representing the rotation.\r\n * @param {Cartesian3} [translation=Cartesian3.ZERO] The upper right portion of the matrix representing the translation.\r\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\r\n */\r\nMatrix4.fromRotationTranslation = function (rotation, translation, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rotation\", rotation);\r\n //>>includeEnd('debug');\r\n\r\n translation = defaultValue(translation, Cartesian3.ZERO);\r\n\r\n if (!defined(result)) {\r\n return new Matrix4(\r\n rotation[0],\r\n rotation[3],\r\n rotation[6],\r\n translation.x,\r\n rotation[1],\r\n rotation[4],\r\n rotation[7],\r\n translation.y,\r\n rotation[2],\r\n rotation[5],\r\n rotation[8],\r\n translation.z,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 1.0\r\n );\r\n }\r\n\r\n result[0] = rotation[0];\r\n result[1] = rotation[1];\r\n result[2] = rotation[2];\r\n result[3] = 0.0;\r\n result[4] = rotation[3];\r\n result[5] = rotation[4];\r\n result[6] = rotation[5];\r\n result[7] = 0.0;\r\n result[8] = rotation[6];\r\n result[9] = rotation[7];\r\n result[10] = rotation[8];\r\n result[11] = 0.0;\r\n result[12] = translation.x;\r\n result[13] = translation.y;\r\n result[14] = translation.z;\r\n result[15] = 1.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a Matrix4 instance from a translation, rotation, and scale (TRS)\r\n * representation with the rotation represented as a quaternion.\r\n *\r\n * @param {Cartesian3} translation The translation transformation.\r\n * @param {Quaternion} rotation The rotation transformation.\r\n * @param {Cartesian3} scale The non-uniform scale transformation.\r\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\r\n *\r\n * @example\r\n * var result = Cesium.Matrix4.fromTranslationQuaternionRotationScale(\r\n * new Cesium.Cartesian3(1.0, 2.0, 3.0), // translation\r\n * Cesium.Quaternion.IDENTITY, // rotation\r\n * new Cesium.Cartesian3(7.0, 8.0, 9.0), // scale\r\n * result);\r\n */\r\nMatrix4.fromTranslationQuaternionRotationScale = function (\r\n translation,\r\n rotation,\r\n scale,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"translation\", translation);\r\n Check.typeOf.object(\"rotation\", rotation);\r\n Check.typeOf.object(\"scale\", scale);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Matrix4();\r\n }\r\n\r\n var scaleX = scale.x;\r\n var scaleY = scale.y;\r\n var scaleZ = scale.z;\r\n\r\n var x2 = rotation.x * rotation.x;\r\n var xy = rotation.x * rotation.y;\r\n var xz = rotation.x * rotation.z;\r\n var xw = rotation.x * rotation.w;\r\n var y2 = rotation.y * rotation.y;\r\n var yz = rotation.y * rotation.z;\r\n var yw = rotation.y * rotation.w;\r\n var z2 = rotation.z * rotation.z;\r\n var zw = rotation.z * rotation.w;\r\n var w2 = rotation.w * rotation.w;\r\n\r\n var m00 = x2 - y2 - z2 + w2;\r\n var m01 = 2.0 * (xy - zw);\r\n var m02 = 2.0 * (xz + yw);\r\n\r\n var m10 = 2.0 * (xy + zw);\r\n var m11 = -x2 + y2 - z2 + w2;\r\n var m12 = 2.0 * (yz - xw);\r\n\r\n var m20 = 2.0 * (xz - yw);\r\n var m21 = 2.0 * (yz + xw);\r\n var m22 = -x2 - y2 + z2 + w2;\r\n\r\n result[0] = m00 * scaleX;\r\n result[1] = m10 * scaleX;\r\n result[2] = m20 * scaleX;\r\n result[3] = 0.0;\r\n result[4] = m01 * scaleY;\r\n result[5] = m11 * scaleY;\r\n result[6] = m21 * scaleY;\r\n result[7] = 0.0;\r\n result[8] = m02 * scaleZ;\r\n result[9] = m12 * scaleZ;\r\n result[10] = m22 * scaleZ;\r\n result[11] = 0.0;\r\n result[12] = translation.x;\r\n result[13] = translation.y;\r\n result[14] = translation.z;\r\n result[15] = 1.0;\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a Matrix4 instance from a {@link TranslationRotationScale} instance.\r\n *\r\n * @param {TranslationRotationScale} translationRotationScale The instance.\r\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\r\n */\r\nMatrix4.fromTranslationRotationScale = function (\r\n translationRotationScale,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"translationRotationScale\", translationRotationScale);\r\n //>>includeEnd('debug');\r\n\r\n return Matrix4.fromTranslationQuaternionRotationScale(\r\n translationRotationScale.translation,\r\n translationRotationScale.rotation,\r\n translationRotationScale.scale,\r\n result\r\n );\r\n};\r\n\r\n/**\r\n * Creates a Matrix4 instance from a Cartesian3 representing the translation.\r\n *\r\n * @param {Cartesian3} translation The upper right portion of the matrix representing the translation.\r\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\r\n *\r\n * @see Matrix4.multiplyByTranslation\r\n */\r\nMatrix4.fromTranslation = function (translation, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"translation\", translation);\r\n //>>includeEnd('debug');\r\n\r\n return Matrix4.fromRotationTranslation(Matrix3.IDENTITY, translation, result);\r\n};\r\n\r\n/**\r\n * Computes a Matrix4 instance representing a non-uniform scale.\r\n *\r\n * @param {Cartesian3} scale The x, y, and z scale factors.\r\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\r\n *\r\n * @example\r\n * // Creates\r\n * // [7.0, 0.0, 0.0, 0.0]\r\n * // [0.0, 8.0, 0.0, 0.0]\r\n * // [0.0, 0.0, 9.0, 0.0]\r\n * // [0.0, 0.0, 0.0, 1.0]\r\n * var m = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(7.0, 8.0, 9.0));\r\n */\r\nMatrix4.fromScale = function (scale, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"scale\", scale);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n return new Matrix4(\r\n scale.x,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n scale.y,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n scale.z,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 1.0\r\n );\r\n }\r\n\r\n result[0] = scale.x;\r\n result[1] = 0.0;\r\n result[2] = 0.0;\r\n result[3] = 0.0;\r\n result[4] = 0.0;\r\n result[5] = scale.y;\r\n result[6] = 0.0;\r\n result[7] = 0.0;\r\n result[8] = 0.0;\r\n result[9] = 0.0;\r\n result[10] = scale.z;\r\n result[11] = 0.0;\r\n result[12] = 0.0;\r\n result[13] = 0.0;\r\n result[14] = 0.0;\r\n result[15] = 1.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a Matrix4 instance representing a uniform scale.\r\n *\r\n * @param {Number} scale The uniform scale factor.\r\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\r\n *\r\n * @example\r\n * // Creates\r\n * // [2.0, 0.0, 0.0, 0.0]\r\n * // [0.0, 2.0, 0.0, 0.0]\r\n * // [0.0, 0.0, 2.0, 0.0]\r\n * // [0.0, 0.0, 0.0, 1.0]\r\n * var m = Cesium.Matrix4.fromUniformScale(2.0);\r\n */\r\nMatrix4.fromUniformScale = function (scale, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number(\"scale\", scale);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n return new Matrix4(\r\n scale,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n scale,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n scale,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 1.0\r\n );\r\n }\r\n\r\n result[0] = scale;\r\n result[1] = 0.0;\r\n result[2] = 0.0;\r\n result[3] = 0.0;\r\n result[4] = 0.0;\r\n result[5] = scale;\r\n result[6] = 0.0;\r\n result[7] = 0.0;\r\n result[8] = 0.0;\r\n result[9] = 0.0;\r\n result[10] = scale;\r\n result[11] = 0.0;\r\n result[12] = 0.0;\r\n result[13] = 0.0;\r\n result[14] = 0.0;\r\n result[15] = 1.0;\r\n return result;\r\n};\r\n\r\nvar fromCameraF = new Cartesian3();\r\nvar fromCameraR = new Cartesian3();\r\nvar fromCameraU = new Cartesian3();\r\n\r\n/**\r\n * Computes a Matrix4 instance from a Camera.\r\n *\r\n * @param {Camera} camera The camera to use.\r\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\r\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\r\n */\r\nMatrix4.fromCamera = function (camera, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"camera\", camera);\r\n //>>includeEnd('debug');\r\n\r\n var position = camera.position;\r\n var direction = camera.direction;\r\n var up = camera.up;\r\n\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"camera.position\", position);\r\n Check.typeOf.object(\"camera.direction\", direction);\r\n Check.typeOf.object(\"camera.up\", up);\r\n //>>includeEnd('debug');\r\n\r\n Cartesian3.normalize(direction, fromCameraF);\r\n Cartesian3.normalize(\r\n Cartesian3.cross(fromCameraF, up, fromCameraR),\r\n fromCameraR\r\n );\r\n Cartesian3.normalize(\r\n Cartesian3.cross(fromCameraR, fromCameraF, fromCameraU),\r\n fromCameraU\r\n );\r\n\r\n var sX = fromCameraR.x;\r\n var sY = fromCameraR.y;\r\n var sZ = fromCameraR.z;\r\n var fX = fromCameraF.x;\r\n var fY = fromCameraF.y;\r\n var fZ = fromCameraF.z;\r\n var uX = fromCameraU.x;\r\n var uY = fromCameraU.y;\r\n var uZ = fromCameraU.z;\r\n var positionX = position.x;\r\n var positionY = position.y;\r\n var positionZ = position.z;\r\n var t0 = sX * -positionX + sY * -positionY + sZ * -positionZ;\r\n var t1 = uX * -positionX + uY * -positionY + uZ * -positionZ;\r\n var t2 = fX * positionX + fY * positionY + fZ * positionZ;\r\n\r\n // The code below this comment is an optimized\r\n // version of the commented lines.\r\n // Rather that create two matrices and then multiply,\r\n // we just bake in the multiplcation as part of creation.\r\n // var rotation = new Matrix4(\r\n // sX, sY, sZ, 0.0,\r\n // uX, uY, uZ, 0.0,\r\n // -fX, -fY, -fZ, 0.0,\r\n // 0.0, 0.0, 0.0, 1.0);\r\n // var translation = new Matrix4(\r\n // 1.0, 0.0, 0.0, -position.x,\r\n // 0.0, 1.0, 0.0, -position.y,\r\n // 0.0, 0.0, 1.0, -position.z,\r\n // 0.0, 0.0, 0.0, 1.0);\r\n // return rotation.multiply(translation);\r\n if (!defined(result)) {\r\n return new Matrix4(\r\n sX,\r\n sY,\r\n sZ,\r\n t0,\r\n uX,\r\n uY,\r\n uZ,\r\n t1,\r\n -fX,\r\n -fY,\r\n -fZ,\r\n t2,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 1.0\r\n );\r\n }\r\n result[0] = sX;\r\n result[1] = uX;\r\n result[2] = -fX;\r\n result[3] = 0.0;\r\n result[4] = sY;\r\n result[5] = uY;\r\n result[6] = -fY;\r\n result[7] = 0.0;\r\n result[8] = sZ;\r\n result[9] = uZ;\r\n result[10] = -fZ;\r\n result[11] = 0.0;\r\n result[12] = t0;\r\n result[13] = t1;\r\n result[14] = t2;\r\n result[15] = 1.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a Matrix4 instance representing a perspective transformation matrix.\r\n *\r\n * @param {Number} fovY The field of view along the Y axis in radians.\r\n * @param {Number} aspectRatio The aspect ratio.\r\n * @param {Number} near The distance to the near plane in meters.\r\n * @param {Number} far The distance to the far plane in meters.\r\n * @param {Matrix4} result The object in which the result will be stored.\r\n * @returns {Matrix4} The modified result parameter.\r\n *\r\n * @exception {DeveloperError} fovY must be in (0, PI].\r\n * @exception {DeveloperError} aspectRatio must be greater than zero.\r\n * @exception {DeveloperError} near must be greater than zero.\r\n * @exception {DeveloperError} far must be greater than zero.\r\n */\r\nMatrix4.computePerspectiveFieldOfView = function (\r\n fovY,\r\n aspectRatio,\r\n near,\r\n far,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number.greaterThan(\"fovY\", fovY, 0.0);\r\n Check.typeOf.number.lessThan(\"fovY\", fovY, Math.PI);\r\n Check.typeOf.number.greaterThan(\"near\", near, 0.0);\r\n Check.typeOf.number.greaterThan(\"far\", far, 0.0);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var bottom = Math.tan(fovY * 0.5);\r\n\r\n var column1Row1 = 1.0 / bottom;\r\n var column0Row0 = column1Row1 / aspectRatio;\r\n var column2Row2 = (far + near) / (near - far);\r\n var column3Row2 = (2.0 * far * near) / (near - far);\r\n\r\n result[0] = column0Row0;\r\n result[1] = 0.0;\r\n result[2] = 0.0;\r\n result[3] = 0.0;\r\n result[4] = 0.0;\r\n result[5] = column1Row1;\r\n result[6] = 0.0;\r\n result[7] = 0.0;\r\n result[8] = 0.0;\r\n result[9] = 0.0;\r\n result[10] = column2Row2;\r\n result[11] = -1.0;\r\n result[12] = 0.0;\r\n result[13] = 0.0;\r\n result[14] = column3Row2;\r\n result[15] = 0.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a Matrix4 instance representing an orthographic transformation matrix.\r\n *\r\n * @param {Number} left The number of meters to the left of the camera that will be in view.\r\n * @param {Number} right The number of meters to the right of the camera that will be in view.\r\n * @param {Number} bottom The number of meters below of the camera that will be in view.\r\n * @param {Number} top The number of meters above of the camera that will be in view.\r\n * @param {Number} near The distance to the near plane in meters.\r\n * @param {Number} far The distance to the far plane in meters.\r\n * @param {Matrix4} result The object in which the result will be stored.\r\n * @returns {Matrix4} The modified result parameter.\r\n */\r\nMatrix4.computeOrthographicOffCenter = function (\r\n left,\r\n right,\r\n bottom,\r\n top,\r\n near,\r\n far,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number(\"left\", left);\r\n Check.typeOf.number(\"right\", right);\r\n Check.typeOf.number(\"bottom\", bottom);\r\n Check.typeOf.number(\"top\", top);\r\n Check.typeOf.number(\"near\", near);\r\n Check.typeOf.number(\"far\", far);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var a = 1.0 / (right - left);\r\n var b = 1.0 / (top - bottom);\r\n var c = 1.0 / (far - near);\r\n\r\n var tx = -(right + left) * a;\r\n var ty = -(top + bottom) * b;\r\n var tz = -(far + near) * c;\r\n a *= 2.0;\r\n b *= 2.0;\r\n c *= -2.0;\r\n\r\n result[0] = a;\r\n result[1] = 0.0;\r\n result[2] = 0.0;\r\n result[3] = 0.0;\r\n result[4] = 0.0;\r\n result[5] = b;\r\n result[6] = 0.0;\r\n result[7] = 0.0;\r\n result[8] = 0.0;\r\n result[9] = 0.0;\r\n result[10] = c;\r\n result[11] = 0.0;\r\n result[12] = tx;\r\n result[13] = ty;\r\n result[14] = tz;\r\n result[15] = 1.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a Matrix4 instance representing an off center perspective transformation.\r\n *\r\n * @param {Number} left The number of meters to the left of the camera that will be in view.\r\n * @param {Number} right The number of meters to the right of the camera that will be in view.\r\n * @param {Number} bottom The number of meters below of the camera that will be in view.\r\n * @param {Number} top The number of meters above of the camera that will be in view.\r\n * @param {Number} near The distance to the near plane in meters.\r\n * @param {Number} far The distance to the far plane in meters.\r\n * @param {Matrix4} result The object in which the result will be stored.\r\n * @returns {Matrix4} The modified result parameter.\r\n */\r\nMatrix4.computePerspectiveOffCenter = function (\r\n left,\r\n right,\r\n bottom,\r\n top,\r\n near,\r\n far,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number(\"left\", left);\r\n Check.typeOf.number(\"right\", right);\r\n Check.typeOf.number(\"bottom\", bottom);\r\n Check.typeOf.number(\"top\", top);\r\n Check.typeOf.number(\"near\", near);\r\n Check.typeOf.number(\"far\", far);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var column0Row0 = (2.0 * near) / (right - left);\r\n var column1Row1 = (2.0 * near) / (top - bottom);\r\n var column2Row0 = (right + left) / (right - left);\r\n var column2Row1 = (top + bottom) / (top - bottom);\r\n var column2Row2 = -(far + near) / (far - near);\r\n var column2Row3 = -1.0;\r\n var column3Row2 = (-2.0 * far * near) / (far - near);\r\n\r\n result[0] = column0Row0;\r\n result[1] = 0.0;\r\n result[2] = 0.0;\r\n result[3] = 0.0;\r\n result[4] = 0.0;\r\n result[5] = column1Row1;\r\n result[6] = 0.0;\r\n result[7] = 0.0;\r\n result[8] = column2Row0;\r\n result[9] = column2Row1;\r\n result[10] = column2Row2;\r\n result[11] = column2Row3;\r\n result[12] = 0.0;\r\n result[13] = 0.0;\r\n result[14] = column3Row2;\r\n result[15] = 0.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a Matrix4 instance representing an infinite off center perspective transformation.\r\n *\r\n * @param {Number} left The number of meters to the left of the camera that will be in view.\r\n * @param {Number} right The number of meters to the right of the camera that will be in view.\r\n * @param {Number} bottom The number of meters below of the camera that will be in view.\r\n * @param {Number} top The number of meters above of the camera that will be in view.\r\n * @param {Number} near The distance to the near plane in meters.\r\n * @param {Matrix4} result The object in which the result will be stored.\r\n * @returns {Matrix4} The modified result parameter.\r\n */\r\nMatrix4.computeInfinitePerspectiveOffCenter = function (\r\n left,\r\n right,\r\n bottom,\r\n top,\r\n near,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number(\"left\", left);\r\n Check.typeOf.number(\"right\", right);\r\n Check.typeOf.number(\"bottom\", bottom);\r\n Check.typeOf.number(\"top\", top);\r\n Check.typeOf.number(\"near\", near);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var column0Row0 = (2.0 * near) / (right - left);\r\n var column1Row1 = (2.0 * near) / (top - bottom);\r\n var column2Row0 = (right + left) / (right - left);\r\n var column2Row1 = (top + bottom) / (top - bottom);\r\n var column2Row2 = -1.0;\r\n var column2Row3 = -1.0;\r\n var column3Row2 = -2.0 * near;\r\n\r\n result[0] = column0Row0;\r\n result[1] = 0.0;\r\n result[2] = 0.0;\r\n result[3] = 0.0;\r\n result[4] = 0.0;\r\n result[5] = column1Row1;\r\n result[6] = 0.0;\r\n result[7] = 0.0;\r\n result[8] = column2Row0;\r\n result[9] = column2Row1;\r\n result[10] = column2Row2;\r\n result[11] = column2Row3;\r\n result[12] = 0.0;\r\n result[13] = 0.0;\r\n result[14] = column3Row2;\r\n result[15] = 0.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a Matrix4 instance that transforms from normalized device coordinates to window coordinates.\r\n *\r\n * @param {Object} [viewport = { x : 0.0, y : 0.0, width : 0.0, height : 0.0 }] The viewport's corners as shown in Example 1.\r\n * @param {Number} [nearDepthRange=0.0] The near plane distance in window coordinates.\r\n * @param {Number} [farDepthRange=1.0] The far plane distance in window coordinates.\r\n * @param {Matrix4} [result] The object in which the result will be stored.\r\n * @returns {Matrix4} The modified result parameter.\r\n *\r\n * @example\r\n * // Create viewport transformation using an explicit viewport and depth range.\r\n * var m = Cesium.Matrix4.computeViewportTransformation({\r\n * x : 0.0,\r\n * y : 0.0,\r\n * width : 1024.0,\r\n * height : 768.0\r\n * }, 0.0, 1.0, new Cesium.Matrix4());\r\n */\r\nMatrix4.computeViewportTransformation = function (\r\n viewport,\r\n nearDepthRange,\r\n farDepthRange,\r\n result\r\n) {\r\n if (!defined(result)) {\r\n result = new Matrix4();\r\n }\r\n\r\n viewport = defaultValue(viewport, defaultValue.EMPTY_OBJECT);\r\n var x = defaultValue(viewport.x, 0.0);\r\n var y = defaultValue(viewport.y, 0.0);\r\n var width = defaultValue(viewport.width, 0.0);\r\n var height = defaultValue(viewport.height, 0.0);\r\n nearDepthRange = defaultValue(nearDepthRange, 0.0);\r\n farDepthRange = defaultValue(farDepthRange, 1.0);\r\n\r\n var halfWidth = width * 0.5;\r\n var halfHeight = height * 0.5;\r\n var halfDepth = (farDepthRange - nearDepthRange) * 0.5;\r\n\r\n var column0Row0 = halfWidth;\r\n var column1Row1 = halfHeight;\r\n var column2Row2 = halfDepth;\r\n var column3Row0 = x + halfWidth;\r\n var column3Row1 = y + halfHeight;\r\n var column3Row2 = nearDepthRange + halfDepth;\r\n var column3Row3 = 1.0;\r\n\r\n result[0] = column0Row0;\r\n result[1] = 0.0;\r\n result[2] = 0.0;\r\n result[3] = 0.0;\r\n result[4] = 0.0;\r\n result[5] = column1Row1;\r\n result[6] = 0.0;\r\n result[7] = 0.0;\r\n result[8] = 0.0;\r\n result[9] = 0.0;\r\n result[10] = column2Row2;\r\n result[11] = 0.0;\r\n result[12] = column3Row0;\r\n result[13] = column3Row1;\r\n result[14] = column3Row2;\r\n result[15] = column3Row3;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a Matrix4 instance that transforms from world space to view space.\r\n *\r\n * @param {Cartesian3} position The position of the camera.\r\n * @param {Cartesian3} direction The forward direction.\r\n * @param {Cartesian3} up The up direction.\r\n * @param {Cartesian3} right The right direction.\r\n * @param {Matrix4} result The object in which the result will be stored.\r\n * @returns {Matrix4} The modified result parameter.\r\n */\r\nMatrix4.computeView = function (position, direction, up, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"position\", position);\r\n Check.typeOf.object(\"direction\", direction);\r\n Check.typeOf.object(\"up\", up);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result[0] = right.x;\r\n result[1] = up.x;\r\n result[2] = -direction.x;\r\n result[3] = 0.0;\r\n result[4] = right.y;\r\n result[5] = up.y;\r\n result[6] = -direction.y;\r\n result[7] = 0.0;\r\n result[8] = right.z;\r\n result[9] = up.z;\r\n result[10] = -direction.z;\r\n result[11] = 0.0;\r\n result[12] = -Cartesian3.dot(right, position);\r\n result[13] = -Cartesian3.dot(up, position);\r\n result[14] = Cartesian3.dot(direction, position);\r\n result[15] = 1.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes an Array from the provided Matrix4 instance.\r\n * The array will be in column-major order.\r\n *\r\n * @param {Matrix4} matrix The matrix to use..\r\n * @param {Number[]} [result] The Array onto which to store the result.\r\n * @returns {Number[]} The modified Array parameter or a new Array instance if one was not provided.\r\n *\r\n * @example\r\n * //create an array from an instance of Matrix4\r\n * // m = [10.0, 14.0, 18.0, 22.0]\r\n * // [11.0, 15.0, 19.0, 23.0]\r\n * // [12.0, 16.0, 20.0, 24.0]\r\n * // [13.0, 17.0, 21.0, 25.0]\r\n * var a = Cesium.Matrix4.toArray(m);\r\n *\r\n * // m remains the same\r\n * //creates a = [10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0]\r\n */\r\nMatrix4.toArray = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n return [\r\n matrix[0],\r\n matrix[1],\r\n matrix[2],\r\n matrix[3],\r\n matrix[4],\r\n matrix[5],\r\n matrix[6],\r\n matrix[7],\r\n matrix[8],\r\n matrix[9],\r\n matrix[10],\r\n matrix[11],\r\n matrix[12],\r\n matrix[13],\r\n matrix[14],\r\n matrix[15],\r\n ];\r\n }\r\n result[0] = matrix[0];\r\n result[1] = matrix[1];\r\n result[2] = matrix[2];\r\n result[3] = matrix[3];\r\n result[4] = matrix[4];\r\n result[5] = matrix[5];\r\n result[6] = matrix[6];\r\n result[7] = matrix[7];\r\n result[8] = matrix[8];\r\n result[9] = matrix[9];\r\n result[10] = matrix[10];\r\n result[11] = matrix[11];\r\n result[12] = matrix[12];\r\n result[13] = matrix[13];\r\n result[14] = matrix[14];\r\n result[15] = matrix[15];\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the array index of the element at the provided row and column.\r\n *\r\n * @param {Number} row The zero-based index of the row.\r\n * @param {Number} column The zero-based index of the column.\r\n * @returns {Number} The index of the element at the provided row and column.\r\n *\r\n * @exception {DeveloperError} row must be 0, 1, 2, or 3.\r\n * @exception {DeveloperError} column must be 0, 1, 2, or 3.\r\n *\r\n * @example\r\n * var myMatrix = new Cesium.Matrix4();\r\n * var column1Row0Index = Cesium.Matrix4.getElementIndex(1, 0);\r\n * var column1Row0 = myMatrix[column1Row0Index];\r\n * myMatrix[column1Row0Index] = 10.0;\r\n */\r\nMatrix4.getElementIndex = function (column, row) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number.greaterThanOrEquals(\"row\", row, 0);\r\n Check.typeOf.number.lessThanOrEquals(\"row\", row, 3);\r\n\r\n Check.typeOf.number.greaterThanOrEquals(\"column\", column, 0);\r\n Check.typeOf.number.lessThanOrEquals(\"column\", column, 3);\r\n //>>includeEnd('debug');\r\n\r\n return column * 4 + row;\r\n};\r\n\r\n/**\r\n * Retrieves a copy of the matrix column at the provided index as a Cartesian4 instance.\r\n *\r\n * @param {Matrix4} matrix The matrix to use.\r\n * @param {Number} index The zero-based index of the column to retrieve.\r\n * @param {Cartesian4} result The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter.\r\n *\r\n * @exception {DeveloperError} index must be 0, 1, 2, or 3.\r\n *\r\n * @example\r\n * //returns a Cartesian4 instance with values from the specified column\r\n * // m = [10.0, 11.0, 12.0, 13.0]\r\n * // [14.0, 15.0, 16.0, 17.0]\r\n * // [18.0, 19.0, 20.0, 21.0]\r\n * // [22.0, 23.0, 24.0, 25.0]\r\n *\r\n * //Example 1: Creates an instance of Cartesian\r\n * var a = Cesium.Matrix4.getColumn(m, 2, new Cesium.Cartesian4());\r\n *\r\n * @example\r\n * //Example 2: Sets values for Cartesian instance\r\n * var a = new Cesium.Cartesian4();\r\n * Cesium.Matrix4.getColumn(m, 2, a);\r\n *\r\n * // a.x = 12.0; a.y = 16.0; a.z = 20.0; a.w = 24.0;\r\n */\r\nMatrix4.getColumn = function (matrix, index, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n\r\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\r\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 3);\r\n\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var startIndex = index * 4;\r\n var x = matrix[startIndex];\r\n var y = matrix[startIndex + 1];\r\n var z = matrix[startIndex + 2];\r\n var w = matrix[startIndex + 3];\r\n\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n result.w = w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a new matrix that replaces the specified column in the provided matrix with the provided Cartesian4 instance.\r\n *\r\n * @param {Matrix4} matrix The matrix to use.\r\n * @param {Number} index The zero-based index of the column to set.\r\n * @param {Cartesian4} cartesian The Cartesian whose values will be assigned to the specified column.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n *\r\n * @exception {DeveloperError} index must be 0, 1, 2, or 3.\r\n *\r\n * @example\r\n * //creates a new Matrix4 instance with new column values from the Cartesian4 instance\r\n * // m = [10.0, 11.0, 12.0, 13.0]\r\n * // [14.0, 15.0, 16.0, 17.0]\r\n * // [18.0, 19.0, 20.0, 21.0]\r\n * // [22.0, 23.0, 24.0, 25.0]\r\n *\r\n * var a = Cesium.Matrix4.setColumn(m, 2, new Cesium.Cartesian4(99.0, 98.0, 97.0, 96.0), new Cesium.Matrix4());\r\n *\r\n * // m remains the same\r\n * // a = [10.0, 11.0, 99.0, 13.0]\r\n * // [14.0, 15.0, 98.0, 17.0]\r\n * // [18.0, 19.0, 97.0, 21.0]\r\n * // [22.0, 23.0, 96.0, 25.0]\r\n */\r\nMatrix4.setColumn = function (matrix, index, cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n\r\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\r\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 3);\r\n\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result = Matrix4.clone(matrix, result);\r\n var startIndex = index * 4;\r\n result[startIndex] = cartesian.x;\r\n result[startIndex + 1] = cartesian.y;\r\n result[startIndex + 2] = cartesian.z;\r\n result[startIndex + 3] = cartesian.w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a new matrix that replaces the translation in the rightmost column of the provided\r\n * matrix with the provided translation. This assumes the matrix is an affine transformation\r\n *\r\n * @param {Matrix4} matrix The matrix to use.\r\n * @param {Cartesian3} translation The translation that replaces the translation of the provided matrix.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n */\r\nMatrix4.setTranslation = function (matrix, translation, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"translation\", translation);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result[0] = matrix[0];\r\n result[1] = matrix[1];\r\n result[2] = matrix[2];\r\n result[3] = matrix[3];\r\n\r\n result[4] = matrix[4];\r\n result[5] = matrix[5];\r\n result[6] = matrix[6];\r\n result[7] = matrix[7];\r\n\r\n result[8] = matrix[8];\r\n result[9] = matrix[9];\r\n result[10] = matrix[10];\r\n result[11] = matrix[11];\r\n\r\n result[12] = translation.x;\r\n result[13] = translation.y;\r\n result[14] = translation.z;\r\n result[15] = matrix[15];\r\n\r\n return result;\r\n};\r\n\r\nvar scaleScratch = new Cartesian3();\r\n/**\r\n * Computes a new matrix that replaces the scale with the provided scale. This assumes the matrix is an affine transformation\r\n *\r\n * @param {Matrix4} matrix The matrix to use.\r\n * @param {Cartesian3} scale The scale that replaces the scale of the provided matrix.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n */\r\nMatrix4.setScale = function (matrix, scale, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"scale\", scale);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var existingScale = Matrix4.getScale(matrix, scaleScratch);\r\n var newScale = Cartesian3.divideComponents(\r\n scale,\r\n existingScale,\r\n scaleScratch\r\n );\r\n return Matrix4.multiplyByScale(matrix, newScale, result);\r\n};\r\n\r\n/**\r\n * Retrieves a copy of the matrix row at the provided index as a Cartesian4 instance.\r\n *\r\n * @param {Matrix4} matrix The matrix to use.\r\n * @param {Number} index The zero-based index of the row to retrieve.\r\n * @param {Cartesian4} result The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter.\r\n *\r\n * @exception {DeveloperError} index must be 0, 1, 2, or 3.\r\n *\r\n * @example\r\n * //returns a Cartesian4 instance with values from the specified column\r\n * // m = [10.0, 11.0, 12.0, 13.0]\r\n * // [14.0, 15.0, 16.0, 17.0]\r\n * // [18.0, 19.0, 20.0, 21.0]\r\n * // [22.0, 23.0, 24.0, 25.0]\r\n *\r\n * //Example 1: Returns an instance of Cartesian\r\n * var a = Cesium.Matrix4.getRow(m, 2, new Cesium.Cartesian4());\r\n *\r\n * @example\r\n * //Example 2: Sets values for a Cartesian instance\r\n * var a = new Cesium.Cartesian4();\r\n * Cesium.Matrix4.getRow(m, 2, a);\r\n *\r\n * // a.x = 18.0; a.y = 19.0; a.z = 20.0; a.w = 21.0;\r\n */\r\nMatrix4.getRow = function (matrix, index, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n\r\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\r\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 3);\r\n\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var x = matrix[index];\r\n var y = matrix[index + 4];\r\n var z = matrix[index + 8];\r\n var w = matrix[index + 12];\r\n\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n result.w = w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a new matrix that replaces the specified row in the provided matrix with the provided Cartesian4 instance.\r\n *\r\n * @param {Matrix4} matrix The matrix to use.\r\n * @param {Number} index The zero-based index of the row to set.\r\n * @param {Cartesian4} cartesian The Cartesian whose values will be assigned to the specified row.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n *\r\n * @exception {DeveloperError} index must be 0, 1, 2, or 3.\r\n *\r\n * @example\r\n * //create a new Matrix4 instance with new row values from the Cartesian4 instance\r\n * // m = [10.0, 11.0, 12.0, 13.0]\r\n * // [14.0, 15.0, 16.0, 17.0]\r\n * // [18.0, 19.0, 20.0, 21.0]\r\n * // [22.0, 23.0, 24.0, 25.0]\r\n *\r\n * var a = Cesium.Matrix4.setRow(m, 2, new Cesium.Cartesian4(99.0, 98.0, 97.0, 96.0), new Cesium.Matrix4());\r\n *\r\n * // m remains the same\r\n * // a = [10.0, 11.0, 12.0, 13.0]\r\n * // [14.0, 15.0, 16.0, 17.0]\r\n * // [99.0, 98.0, 97.0, 96.0]\r\n * // [22.0, 23.0, 24.0, 25.0]\r\n */\r\nMatrix4.setRow = function (matrix, index, cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n\r\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\r\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 3);\r\n\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result = Matrix4.clone(matrix, result);\r\n result[index] = cartesian.x;\r\n result[index + 4] = cartesian.y;\r\n result[index + 8] = cartesian.z;\r\n result[index + 12] = cartesian.w;\r\n return result;\r\n};\r\n\r\nvar scratchColumn = new Cartesian3();\r\n\r\n/**\r\n * Extracts the non-uniform scale assuming the matrix is an affine transformation.\r\n *\r\n * @param {Matrix4} matrix The matrix.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter\r\n */\r\nMatrix4.getScale = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = Cartesian3.magnitude(\r\n Cartesian3.fromElements(matrix[0], matrix[1], matrix[2], scratchColumn)\r\n );\r\n result.y = Cartesian3.magnitude(\r\n Cartesian3.fromElements(matrix[4], matrix[5], matrix[6], scratchColumn)\r\n );\r\n result.z = Cartesian3.magnitude(\r\n Cartesian3.fromElements(matrix[8], matrix[9], matrix[10], scratchColumn)\r\n );\r\n return result;\r\n};\r\n\r\nvar scratchScale = new Cartesian3();\r\n\r\n/**\r\n * Computes the maximum scale assuming the matrix is an affine transformation.\r\n * The maximum scale is the maximum length of the column vectors in the upper-left\r\n * 3x3 matrix.\r\n *\r\n * @param {Matrix4} matrix The matrix.\r\n * @returns {Number} The maximum scale.\r\n */\r\nMatrix4.getMaximumScale = function (matrix) {\r\n Matrix4.getScale(matrix, scratchScale);\r\n return Cartesian3.maximumComponent(scratchScale);\r\n};\r\n\r\n/**\r\n * Computes the product of two matrices.\r\n *\r\n * @param {Matrix4} left The first matrix.\r\n * @param {Matrix4} right The second matrix.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n */\r\nMatrix4.multiply = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var left0 = left[0];\r\n var left1 = left[1];\r\n var left2 = left[2];\r\n var left3 = left[3];\r\n var left4 = left[4];\r\n var left5 = left[5];\r\n var left6 = left[6];\r\n var left7 = left[7];\r\n var left8 = left[8];\r\n var left9 = left[9];\r\n var left10 = left[10];\r\n var left11 = left[11];\r\n var left12 = left[12];\r\n var left13 = left[13];\r\n var left14 = left[14];\r\n var left15 = left[15];\r\n\r\n var right0 = right[0];\r\n var right1 = right[1];\r\n var right2 = right[2];\r\n var right3 = right[3];\r\n var right4 = right[4];\r\n var right5 = right[5];\r\n var right6 = right[6];\r\n var right7 = right[7];\r\n var right8 = right[8];\r\n var right9 = right[9];\r\n var right10 = right[10];\r\n var right11 = right[11];\r\n var right12 = right[12];\r\n var right13 = right[13];\r\n var right14 = right[14];\r\n var right15 = right[15];\r\n\r\n var column0Row0 =\r\n left0 * right0 + left4 * right1 + left8 * right2 + left12 * right3;\r\n var column0Row1 =\r\n left1 * right0 + left5 * right1 + left9 * right2 + left13 * right3;\r\n var column0Row2 =\r\n left2 * right0 + left6 * right1 + left10 * right2 + left14 * right3;\r\n var column0Row3 =\r\n left3 * right0 + left7 * right1 + left11 * right2 + left15 * right3;\r\n\r\n var column1Row0 =\r\n left0 * right4 + left4 * right5 + left8 * right6 + left12 * right7;\r\n var column1Row1 =\r\n left1 * right4 + left5 * right5 + left9 * right6 + left13 * right7;\r\n var column1Row2 =\r\n left2 * right4 + left6 * right5 + left10 * right6 + left14 * right7;\r\n var column1Row3 =\r\n left3 * right4 + left7 * right5 + left11 * right6 + left15 * right7;\r\n\r\n var column2Row0 =\r\n left0 * right8 + left4 * right9 + left8 * right10 + left12 * right11;\r\n var column2Row1 =\r\n left1 * right8 + left5 * right9 + left9 * right10 + left13 * right11;\r\n var column2Row2 =\r\n left2 * right8 + left6 * right9 + left10 * right10 + left14 * right11;\r\n var column2Row3 =\r\n left3 * right8 + left7 * right9 + left11 * right10 + left15 * right11;\r\n\r\n var column3Row0 =\r\n left0 * right12 + left4 * right13 + left8 * right14 + left12 * right15;\r\n var column3Row1 =\r\n left1 * right12 + left5 * right13 + left9 * right14 + left13 * right15;\r\n var column3Row2 =\r\n left2 * right12 + left6 * right13 + left10 * right14 + left14 * right15;\r\n var column3Row3 =\r\n left3 * right12 + left7 * right13 + left11 * right14 + left15 * right15;\r\n\r\n result[0] = column0Row0;\r\n result[1] = column0Row1;\r\n result[2] = column0Row2;\r\n result[3] = column0Row3;\r\n result[4] = column1Row0;\r\n result[5] = column1Row1;\r\n result[6] = column1Row2;\r\n result[7] = column1Row3;\r\n result[8] = column2Row0;\r\n result[9] = column2Row1;\r\n result[10] = column2Row2;\r\n result[11] = column2Row3;\r\n result[12] = column3Row0;\r\n result[13] = column3Row1;\r\n result[14] = column3Row2;\r\n result[15] = column3Row3;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the sum of two matrices.\r\n *\r\n * @param {Matrix4} left The first matrix.\r\n * @param {Matrix4} right The second matrix.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n */\r\nMatrix4.add = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result[0] = left[0] + right[0];\r\n result[1] = left[1] + right[1];\r\n result[2] = left[2] + right[2];\r\n result[3] = left[3] + right[3];\r\n result[4] = left[4] + right[4];\r\n result[5] = left[5] + right[5];\r\n result[6] = left[6] + right[6];\r\n result[7] = left[7] + right[7];\r\n result[8] = left[8] + right[8];\r\n result[9] = left[9] + right[9];\r\n result[10] = left[10] + right[10];\r\n result[11] = left[11] + right[11];\r\n result[12] = left[12] + right[12];\r\n result[13] = left[13] + right[13];\r\n result[14] = left[14] + right[14];\r\n result[15] = left[15] + right[15];\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the difference of two matrices.\r\n *\r\n * @param {Matrix4} left The first matrix.\r\n * @param {Matrix4} right The second matrix.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n */\r\nMatrix4.subtract = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result[0] = left[0] - right[0];\r\n result[1] = left[1] - right[1];\r\n result[2] = left[2] - right[2];\r\n result[3] = left[3] - right[3];\r\n result[4] = left[4] - right[4];\r\n result[5] = left[5] - right[5];\r\n result[6] = left[6] - right[6];\r\n result[7] = left[7] - right[7];\r\n result[8] = left[8] - right[8];\r\n result[9] = left[9] - right[9];\r\n result[10] = left[10] - right[10];\r\n result[11] = left[11] - right[11];\r\n result[12] = left[12] - right[12];\r\n result[13] = left[13] - right[13];\r\n result[14] = left[14] - right[14];\r\n result[15] = left[15] - right[15];\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the product of two matrices assuming the matrices are\r\n * affine transformation matrices, where the upper left 3x3 elements\r\n * are a rotation matrix, and the upper three elements in the fourth\r\n * column are the translation. The bottom row is assumed to be [0, 0, 0, 1].\r\n * The matrix is not verified to be in the proper form.\r\n * This method is faster than computing the product for general 4x4\r\n * matrices using {@link Matrix4.multiply}.\r\n *\r\n * @param {Matrix4} left The first matrix.\r\n * @param {Matrix4} right The second matrix.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n *\r\n * @example\r\n * var m1 = new Cesium.Matrix4(1.0, 6.0, 7.0, 0.0, 2.0, 5.0, 8.0, 0.0, 3.0, 4.0, 9.0, 0.0, 0.0, 0.0, 0.0, 1.0);\r\n * var m2 = Cesium.Transforms.eastNorthUpToFixedFrame(new Cesium.Cartesian3(1.0, 1.0, 1.0));\r\n * var m3 = Cesium.Matrix4.multiplyTransformation(m1, m2, new Cesium.Matrix4());\r\n */\r\nMatrix4.multiplyTransformation = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var left0 = left[0];\r\n var left1 = left[1];\r\n var left2 = left[2];\r\n var left4 = left[4];\r\n var left5 = left[5];\r\n var left6 = left[6];\r\n var left8 = left[8];\r\n var left9 = left[9];\r\n var left10 = left[10];\r\n var left12 = left[12];\r\n var left13 = left[13];\r\n var left14 = left[14];\r\n\r\n var right0 = right[0];\r\n var right1 = right[1];\r\n var right2 = right[2];\r\n var right4 = right[4];\r\n var right5 = right[5];\r\n var right6 = right[6];\r\n var right8 = right[8];\r\n var right9 = right[9];\r\n var right10 = right[10];\r\n var right12 = right[12];\r\n var right13 = right[13];\r\n var right14 = right[14];\r\n\r\n var column0Row0 = left0 * right0 + left4 * right1 + left8 * right2;\r\n var column0Row1 = left1 * right0 + left5 * right1 + left9 * right2;\r\n var column0Row2 = left2 * right0 + left6 * right1 + left10 * right2;\r\n\r\n var column1Row0 = left0 * right4 + left4 * right5 + left8 * right6;\r\n var column1Row1 = left1 * right4 + left5 * right5 + left9 * right6;\r\n var column1Row2 = left2 * right4 + left6 * right5 + left10 * right6;\r\n\r\n var column2Row0 = left0 * right8 + left4 * right9 + left8 * right10;\r\n var column2Row1 = left1 * right8 + left5 * right9 + left9 * right10;\r\n var column2Row2 = left2 * right8 + left6 * right9 + left10 * right10;\r\n\r\n var column3Row0 =\r\n left0 * right12 + left4 * right13 + left8 * right14 + left12;\r\n var column3Row1 =\r\n left1 * right12 + left5 * right13 + left9 * right14 + left13;\r\n var column3Row2 =\r\n left2 * right12 + left6 * right13 + left10 * right14 + left14;\r\n\r\n result[0] = column0Row0;\r\n result[1] = column0Row1;\r\n result[2] = column0Row2;\r\n result[3] = 0.0;\r\n result[4] = column1Row0;\r\n result[5] = column1Row1;\r\n result[6] = column1Row2;\r\n result[7] = 0.0;\r\n result[8] = column2Row0;\r\n result[9] = column2Row1;\r\n result[10] = column2Row2;\r\n result[11] = 0.0;\r\n result[12] = column3Row0;\r\n result[13] = column3Row1;\r\n result[14] = column3Row2;\r\n result[15] = 1.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * Multiplies a transformation matrix (with a bottom row of [0.0, 0.0, 0.0, 1.0]
)\r\n * by a 3x3 rotation matrix. This is an optimization\r\n * for Matrix4.multiply(m, Matrix4.fromRotationTranslation(rotation), m);
with less allocations and arithmetic operations.\r\n *\r\n * @param {Matrix4} matrix The matrix on the left-hand side.\r\n * @param {Matrix3} rotation The 3x3 rotation matrix on the right-hand side.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n *\r\n * @example\r\n * // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromRotationTranslation(rotation), m);\r\n * Cesium.Matrix4.multiplyByMatrix3(m, rotation, m);\r\n */\r\nMatrix4.multiplyByMatrix3 = function (matrix, rotation, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"rotation\", rotation);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var left0 = matrix[0];\r\n var left1 = matrix[1];\r\n var left2 = matrix[2];\r\n var left4 = matrix[4];\r\n var left5 = matrix[5];\r\n var left6 = matrix[6];\r\n var left8 = matrix[8];\r\n var left9 = matrix[9];\r\n var left10 = matrix[10];\r\n\r\n var right0 = rotation[0];\r\n var right1 = rotation[1];\r\n var right2 = rotation[2];\r\n var right4 = rotation[3];\r\n var right5 = rotation[4];\r\n var right6 = rotation[5];\r\n var right8 = rotation[6];\r\n var right9 = rotation[7];\r\n var right10 = rotation[8];\r\n\r\n var column0Row0 = left0 * right0 + left4 * right1 + left8 * right2;\r\n var column0Row1 = left1 * right0 + left5 * right1 + left9 * right2;\r\n var column0Row2 = left2 * right0 + left6 * right1 + left10 * right2;\r\n\r\n var column1Row0 = left0 * right4 + left4 * right5 + left8 * right6;\r\n var column1Row1 = left1 * right4 + left5 * right5 + left9 * right6;\r\n var column1Row2 = left2 * right4 + left6 * right5 + left10 * right6;\r\n\r\n var column2Row0 = left0 * right8 + left4 * right9 + left8 * right10;\r\n var column2Row1 = left1 * right8 + left5 * right9 + left9 * right10;\r\n var column2Row2 = left2 * right8 + left6 * right9 + left10 * right10;\r\n\r\n result[0] = column0Row0;\r\n result[1] = column0Row1;\r\n result[2] = column0Row2;\r\n result[3] = 0.0;\r\n result[4] = column1Row0;\r\n result[5] = column1Row1;\r\n result[6] = column1Row2;\r\n result[7] = 0.0;\r\n result[8] = column2Row0;\r\n result[9] = column2Row1;\r\n result[10] = column2Row2;\r\n result[11] = 0.0;\r\n result[12] = matrix[12];\r\n result[13] = matrix[13];\r\n result[14] = matrix[14];\r\n result[15] = matrix[15];\r\n return result;\r\n};\r\n\r\n/**\r\n * Multiplies a transformation matrix (with a bottom row of [0.0, 0.0, 0.0, 1.0]
)\r\n * by an implicit translation matrix defined by a {@link Cartesian3}. This is an optimization\r\n * for Matrix4.multiply(m, Matrix4.fromTranslation(position), m);
with less allocations and arithmetic operations.\r\n *\r\n * @param {Matrix4} matrix The matrix on the left-hand side.\r\n * @param {Cartesian3} translation The translation on the right-hand side.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n *\r\n * @example\r\n * // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromTranslation(position), m);\r\n * Cesium.Matrix4.multiplyByTranslation(m, position, m);\r\n */\r\nMatrix4.multiplyByTranslation = function (matrix, translation, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"translation\", translation);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var x = translation.x;\r\n var y = translation.y;\r\n var z = translation.z;\r\n\r\n var tx = x * matrix[0] + y * matrix[4] + z * matrix[8] + matrix[12];\r\n var ty = x * matrix[1] + y * matrix[5] + z * matrix[9] + matrix[13];\r\n var tz = x * matrix[2] + y * matrix[6] + z * matrix[10] + matrix[14];\r\n\r\n result[0] = matrix[0];\r\n result[1] = matrix[1];\r\n result[2] = matrix[2];\r\n result[3] = matrix[3];\r\n result[4] = matrix[4];\r\n result[5] = matrix[5];\r\n result[6] = matrix[6];\r\n result[7] = matrix[7];\r\n result[8] = matrix[8];\r\n result[9] = matrix[9];\r\n result[10] = matrix[10];\r\n result[11] = matrix[11];\r\n result[12] = tx;\r\n result[13] = ty;\r\n result[14] = tz;\r\n result[15] = matrix[15];\r\n return result;\r\n};\r\n\r\nvar uniformScaleScratch = new Cartesian3();\r\n\r\n/**\r\n * Multiplies an affine transformation matrix (with a bottom row of [0.0, 0.0, 0.0, 1.0]
)\r\n * by an implicit uniform scale matrix. This is an optimization\r\n * for Matrix4.multiply(m, Matrix4.fromUniformScale(scale), m);
, where\r\n * m
must be an affine matrix.\r\n * This function performs fewer allocations and arithmetic operations.\r\n *\r\n * @param {Matrix4} matrix The affine matrix on the left-hand side.\r\n * @param {Number} scale The uniform scale on the right-hand side.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n *\r\n *\r\n * @example\r\n * // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromUniformScale(scale), m);\r\n * Cesium.Matrix4.multiplyByUniformScale(m, scale, m);\r\n *\r\n * @see Matrix4.fromUniformScale\r\n * @see Matrix4.multiplyByScale\r\n */\r\nMatrix4.multiplyByUniformScale = function (matrix, scale, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.number(\"scale\", scale);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n uniformScaleScratch.x = scale;\r\n uniformScaleScratch.y = scale;\r\n uniformScaleScratch.z = scale;\r\n return Matrix4.multiplyByScale(matrix, uniformScaleScratch, result);\r\n};\r\n\r\n/**\r\n * Multiplies an affine transformation matrix (with a bottom row of [0.0, 0.0, 0.0, 1.0]
)\r\n * by an implicit non-uniform scale matrix. This is an optimization\r\n * for Matrix4.multiply(m, Matrix4.fromUniformScale(scale), m);
, where\r\n * m
must be an affine matrix.\r\n * This function performs fewer allocations and arithmetic operations.\r\n *\r\n * @param {Matrix4} matrix The affine matrix on the left-hand side.\r\n * @param {Cartesian3} scale The non-uniform scale on the right-hand side.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n *\r\n *\r\n * @example\r\n * // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromScale(scale), m);\r\n * Cesium.Matrix4.multiplyByScale(m, scale, m);\r\n *\r\n * @see Matrix4.fromScale\r\n * @see Matrix4.multiplyByUniformScale\r\n */\r\nMatrix4.multiplyByScale = function (matrix, scale, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"scale\", scale);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var scaleX = scale.x;\r\n var scaleY = scale.y;\r\n var scaleZ = scale.z;\r\n\r\n // Faster than Cartesian3.equals\r\n if (scaleX === 1.0 && scaleY === 1.0 && scaleZ === 1.0) {\r\n return Matrix4.clone(matrix, result);\r\n }\r\n\r\n result[0] = scaleX * matrix[0];\r\n result[1] = scaleX * matrix[1];\r\n result[2] = scaleX * matrix[2];\r\n result[3] = 0.0;\r\n result[4] = scaleY * matrix[4];\r\n result[5] = scaleY * matrix[5];\r\n result[6] = scaleY * matrix[6];\r\n result[7] = 0.0;\r\n result[8] = scaleZ * matrix[8];\r\n result[9] = scaleZ * matrix[9];\r\n result[10] = scaleZ * matrix[10];\r\n result[11] = 0.0;\r\n result[12] = matrix[12];\r\n result[13] = matrix[13];\r\n result[14] = matrix[14];\r\n result[15] = 1.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the product of a matrix and a column vector.\r\n *\r\n * @param {Matrix4} matrix The matrix.\r\n * @param {Cartesian4} cartesian The vector.\r\n * @param {Cartesian4} result The object onto which to store the result.\r\n * @returns {Cartesian4} The modified result parameter.\r\n */\r\nMatrix4.multiplyByVector = function (matrix, cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var vX = cartesian.x;\r\n var vY = cartesian.y;\r\n var vZ = cartesian.z;\r\n var vW = cartesian.w;\r\n\r\n var x = matrix[0] * vX + matrix[4] * vY + matrix[8] * vZ + matrix[12] * vW;\r\n var y = matrix[1] * vX + matrix[5] * vY + matrix[9] * vZ + matrix[13] * vW;\r\n var z = matrix[2] * vX + matrix[6] * vY + matrix[10] * vZ + matrix[14] * vW;\r\n var w = matrix[3] * vX + matrix[7] * vY + matrix[11] * vZ + matrix[15] * vW;\r\n\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n result.w = w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the product of a matrix and a {@link Cartesian3}. This is equivalent to calling {@link Matrix4.multiplyByVector}\r\n * with a {@link Cartesian4} with a w
component of zero.\r\n *\r\n * @param {Matrix4} matrix The matrix.\r\n * @param {Cartesian3} cartesian The point.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n *\r\n * @example\r\n * var p = new Cesium.Cartesian3(1.0, 2.0, 3.0);\r\n * var result = Cesium.Matrix4.multiplyByPointAsVector(matrix, p, new Cesium.Cartesian3());\r\n * // A shortcut for\r\n * // Cartesian3 p = ...\r\n * // Cesium.Matrix4.multiplyByVector(matrix, new Cesium.Cartesian4(p.x, p.y, p.z, 0.0), result);\r\n */\r\nMatrix4.multiplyByPointAsVector = function (matrix, cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var vX = cartesian.x;\r\n var vY = cartesian.y;\r\n var vZ = cartesian.z;\r\n\r\n var x = matrix[0] * vX + matrix[4] * vY + matrix[8] * vZ;\r\n var y = matrix[1] * vX + matrix[5] * vY + matrix[9] * vZ;\r\n var z = matrix[2] * vX + matrix[6] * vY + matrix[10] * vZ;\r\n\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the product of a matrix and a {@link Cartesian3}. This is equivalent to calling {@link Matrix4.multiplyByVector}\r\n * with a {@link Cartesian4} with a w
component of 1, but returns a {@link Cartesian3} instead of a {@link Cartesian4}.\r\n *\r\n * @param {Matrix4} matrix The matrix.\r\n * @param {Cartesian3} cartesian The point.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n *\r\n * @example\r\n * var p = new Cesium.Cartesian3(1.0, 2.0, 3.0);\r\n * var result = Cesium.Matrix4.multiplyByPoint(matrix, p, new Cesium.Cartesian3());\r\n */\r\nMatrix4.multiplyByPoint = function (matrix, cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var vX = cartesian.x;\r\n var vY = cartesian.y;\r\n var vZ = cartesian.z;\r\n\r\n var x = matrix[0] * vX + matrix[4] * vY + matrix[8] * vZ + matrix[12];\r\n var y = matrix[1] * vX + matrix[5] * vY + matrix[9] * vZ + matrix[13];\r\n var z = matrix[2] * vX + matrix[6] * vY + matrix[10] * vZ + matrix[14];\r\n\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the product of a matrix and a scalar.\r\n *\r\n * @param {Matrix4} matrix The matrix.\r\n * @param {Number} scalar The number to multiply by.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n *\r\n * @example\r\n * //create a Matrix4 instance which is a scaled version of the supplied Matrix4\r\n * // m = [10.0, 11.0, 12.0, 13.0]\r\n * // [14.0, 15.0, 16.0, 17.0]\r\n * // [18.0, 19.0, 20.0, 21.0]\r\n * // [22.0, 23.0, 24.0, 25.0]\r\n *\r\n * var a = Cesium.Matrix4.multiplyByScalar(m, -2, new Cesium.Matrix4());\r\n *\r\n * // m remains the same\r\n * // a = [-20.0, -22.0, -24.0, -26.0]\r\n * // [-28.0, -30.0, -32.0, -34.0]\r\n * // [-36.0, -38.0, -40.0, -42.0]\r\n * // [-44.0, -46.0, -48.0, -50.0]\r\n */\r\nMatrix4.multiplyByScalar = function (matrix, scalar, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.number(\"scalar\", scalar);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result[0] = matrix[0] * scalar;\r\n result[1] = matrix[1] * scalar;\r\n result[2] = matrix[2] * scalar;\r\n result[3] = matrix[3] * scalar;\r\n result[4] = matrix[4] * scalar;\r\n result[5] = matrix[5] * scalar;\r\n result[6] = matrix[6] * scalar;\r\n result[7] = matrix[7] * scalar;\r\n result[8] = matrix[8] * scalar;\r\n result[9] = matrix[9] * scalar;\r\n result[10] = matrix[10] * scalar;\r\n result[11] = matrix[11] * scalar;\r\n result[12] = matrix[12] * scalar;\r\n result[13] = matrix[13] * scalar;\r\n result[14] = matrix[14] * scalar;\r\n result[15] = matrix[15] * scalar;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a negated copy of the provided matrix.\r\n *\r\n * @param {Matrix4} matrix The matrix to negate.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n *\r\n * @example\r\n * //create a new Matrix4 instance which is a negation of a Matrix4\r\n * // m = [10.0, 11.0, 12.0, 13.0]\r\n * // [14.0, 15.0, 16.0, 17.0]\r\n * // [18.0, 19.0, 20.0, 21.0]\r\n * // [22.0, 23.0, 24.0, 25.0]\r\n *\r\n * var a = Cesium.Matrix4.negate(m, new Cesium.Matrix4());\r\n *\r\n * // m remains the same\r\n * // a = [-10.0, -11.0, -12.0, -13.0]\r\n * // [-14.0, -15.0, -16.0, -17.0]\r\n * // [-18.0, -19.0, -20.0, -21.0]\r\n * // [-22.0, -23.0, -24.0, -25.0]\r\n */\r\nMatrix4.negate = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result[0] = -matrix[0];\r\n result[1] = -matrix[1];\r\n result[2] = -matrix[2];\r\n result[3] = -matrix[3];\r\n result[4] = -matrix[4];\r\n result[5] = -matrix[5];\r\n result[6] = -matrix[6];\r\n result[7] = -matrix[7];\r\n result[8] = -matrix[8];\r\n result[9] = -matrix[9];\r\n result[10] = -matrix[10];\r\n result[11] = -matrix[11];\r\n result[12] = -matrix[12];\r\n result[13] = -matrix[13];\r\n result[14] = -matrix[14];\r\n result[15] = -matrix[15];\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the transpose of the provided matrix.\r\n *\r\n * @param {Matrix4} matrix The matrix to transpose.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n *\r\n * @example\r\n * //returns transpose of a Matrix4\r\n * // m = [10.0, 11.0, 12.0, 13.0]\r\n * // [14.0, 15.0, 16.0, 17.0]\r\n * // [18.0, 19.0, 20.0, 21.0]\r\n * // [22.0, 23.0, 24.0, 25.0]\r\n *\r\n * var a = Cesium.Matrix4.transpose(m, new Cesium.Matrix4());\r\n *\r\n * // m remains the same\r\n * // a = [10.0, 14.0, 18.0, 22.0]\r\n * // [11.0, 15.0, 19.0, 23.0]\r\n * // [12.0, 16.0, 20.0, 24.0]\r\n * // [13.0, 17.0, 21.0, 25.0]\r\n */\r\nMatrix4.transpose = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var matrix1 = matrix[1];\r\n var matrix2 = matrix[2];\r\n var matrix3 = matrix[3];\r\n var matrix6 = matrix[6];\r\n var matrix7 = matrix[7];\r\n var matrix11 = matrix[11];\r\n\r\n result[0] = matrix[0];\r\n result[1] = matrix[4];\r\n result[2] = matrix[8];\r\n result[3] = matrix[12];\r\n result[4] = matrix1;\r\n result[5] = matrix[5];\r\n result[6] = matrix[9];\r\n result[7] = matrix[13];\r\n result[8] = matrix2;\r\n result[9] = matrix6;\r\n result[10] = matrix[10];\r\n result[11] = matrix[14];\r\n result[12] = matrix3;\r\n result[13] = matrix7;\r\n result[14] = matrix11;\r\n result[15] = matrix[15];\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a matrix, which contains the absolute (unsigned) values of the provided matrix's elements.\r\n *\r\n * @param {Matrix4} matrix The matrix with signed elements.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n */\r\nMatrix4.abs = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result[0] = Math.abs(matrix[0]);\r\n result[1] = Math.abs(matrix[1]);\r\n result[2] = Math.abs(matrix[2]);\r\n result[3] = Math.abs(matrix[3]);\r\n result[4] = Math.abs(matrix[4]);\r\n result[5] = Math.abs(matrix[5]);\r\n result[6] = Math.abs(matrix[6]);\r\n result[7] = Math.abs(matrix[7]);\r\n result[8] = Math.abs(matrix[8]);\r\n result[9] = Math.abs(matrix[9]);\r\n result[10] = Math.abs(matrix[10]);\r\n result[11] = Math.abs(matrix[11]);\r\n result[12] = Math.abs(matrix[12]);\r\n result[13] = Math.abs(matrix[13]);\r\n result[14] = Math.abs(matrix[14]);\r\n result[15] = Math.abs(matrix[15]);\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Compares the provided matrices componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Matrix4} [left] The first matrix.\r\n * @param {Matrix4} [right] The second matrix.\r\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\r\n *\r\n * @example\r\n * //compares two Matrix4 instances\r\n *\r\n * // a = [10.0, 14.0, 18.0, 22.0]\r\n * // [11.0, 15.0, 19.0, 23.0]\r\n * // [12.0, 16.0, 20.0, 24.0]\r\n * // [13.0, 17.0, 21.0, 25.0]\r\n *\r\n * // b = [10.0, 14.0, 18.0, 22.0]\r\n * // [11.0, 15.0, 19.0, 23.0]\r\n * // [12.0, 16.0, 20.0, 24.0]\r\n * // [13.0, 17.0, 21.0, 25.0]\r\n *\r\n * if(Cesium.Matrix4.equals(a,b)) {\r\n * console.log(\"Both matrices are equal\");\r\n * } else {\r\n * console.log(\"They are not equal\");\r\n * }\r\n *\r\n * //Prints \"Both matrices are equal\" on the console\r\n */\r\nMatrix4.equals = function (left, right) {\r\n // Given that most matrices will be transformation matrices, the elements\r\n // are tested in order such that the test is likely to fail as early\r\n // as possible. I _think_ this is just as friendly to the L1 cache\r\n // as testing in index order. It is certainty faster in practice.\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n // Translation\r\n left[12] === right[12] &&\r\n left[13] === right[13] &&\r\n left[14] === right[14] &&\r\n // Rotation/scale\r\n left[0] === right[0] &&\r\n left[1] === right[1] &&\r\n left[2] === right[2] &&\r\n left[4] === right[4] &&\r\n left[5] === right[5] &&\r\n left[6] === right[6] &&\r\n left[8] === right[8] &&\r\n left[9] === right[9] &&\r\n left[10] === right[10] &&\r\n // Bottom row\r\n left[3] === right[3] &&\r\n left[7] === right[7] &&\r\n left[11] === right[11] &&\r\n left[15] === right[15])\r\n );\r\n};\r\n\r\n/**\r\n * Compares the provided matrices componentwise and returns\r\n * true
if they are within the provided epsilon,\r\n * false
otherwise.\r\n *\r\n * @param {Matrix4} [left] The first matrix.\r\n * @param {Matrix4} [right] The second matrix.\r\n * @param {Number} [epsilon=0] The epsilon to use for equality testing.\r\n * @returns {Boolean} true
if left and right are within the provided epsilon, false
otherwise.\r\n *\r\n * @example\r\n * //compares two Matrix4 instances\r\n *\r\n * // a = [10.5, 14.5, 18.5, 22.5]\r\n * // [11.5, 15.5, 19.5, 23.5]\r\n * // [12.5, 16.5, 20.5, 24.5]\r\n * // [13.5, 17.5, 21.5, 25.5]\r\n *\r\n * // b = [10.0, 14.0, 18.0, 22.0]\r\n * // [11.0, 15.0, 19.0, 23.0]\r\n * // [12.0, 16.0, 20.0, 24.0]\r\n * // [13.0, 17.0, 21.0, 25.0]\r\n *\r\n * if(Cesium.Matrix4.equalsEpsilon(a,b,0.1)){\r\n * console.log(\"Difference between both the matrices is less than 0.1\");\r\n * } else {\r\n * console.log(\"Difference between both the matrices is not less than 0.1\");\r\n * }\r\n *\r\n * //Prints \"Difference between both the matrices is not less than 0.1\" on the console\r\n */\r\nMatrix4.equalsEpsilon = function (left, right, epsilon) {\r\n epsilon = defaultValue(epsilon, 0);\r\n\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n Math.abs(left[0] - right[0]) <= epsilon &&\r\n Math.abs(left[1] - right[1]) <= epsilon &&\r\n Math.abs(left[2] - right[2]) <= epsilon &&\r\n Math.abs(left[3] - right[3]) <= epsilon &&\r\n Math.abs(left[4] - right[4]) <= epsilon &&\r\n Math.abs(left[5] - right[5]) <= epsilon &&\r\n Math.abs(left[6] - right[6]) <= epsilon &&\r\n Math.abs(left[7] - right[7]) <= epsilon &&\r\n Math.abs(left[8] - right[8]) <= epsilon &&\r\n Math.abs(left[9] - right[9]) <= epsilon &&\r\n Math.abs(left[10] - right[10]) <= epsilon &&\r\n Math.abs(left[11] - right[11]) <= epsilon &&\r\n Math.abs(left[12] - right[12]) <= epsilon &&\r\n Math.abs(left[13] - right[13]) <= epsilon &&\r\n Math.abs(left[14] - right[14]) <= epsilon &&\r\n Math.abs(left[15] - right[15]) <= epsilon)\r\n );\r\n};\r\n\r\n/**\r\n * Gets the translation portion of the provided matrix, assuming the matrix is a affine transformation matrix.\r\n *\r\n * @param {Matrix4} matrix The matrix to use.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n */\r\nMatrix4.getTranslation = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = matrix[12];\r\n result.y = matrix[13];\r\n result.z = matrix[14];\r\n return result;\r\n};\r\n\r\n/**\r\n * Gets the upper left 3x3 rotation matrix of the provided matrix, assuming the matrix is an affine transformation matrix.\r\n *\r\n * @param {Matrix4} matrix The matrix to use.\r\n * @param {Matrix3} result The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter.\r\n *\r\n * @example\r\n * // returns a Matrix3 instance from a Matrix4 instance\r\n *\r\n * // m = [10.0, 14.0, 18.0, 22.0]\r\n * // [11.0, 15.0, 19.0, 23.0]\r\n * // [12.0, 16.0, 20.0, 24.0]\r\n * // [13.0, 17.0, 21.0, 25.0]\r\n *\r\n * var b = new Cesium.Matrix3();\r\n * Cesium.Matrix4.getMatrix3(m,b);\r\n *\r\n * // b = [10.0, 14.0, 18.0]\r\n * // [11.0, 15.0, 19.0]\r\n * // [12.0, 16.0, 20.0]\r\n */\r\nMatrix4.getMatrix3 = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result[0] = matrix[0];\r\n result[1] = matrix[1];\r\n result[2] = matrix[2];\r\n result[3] = matrix[4];\r\n result[4] = matrix[5];\r\n result[5] = matrix[6];\r\n result[6] = matrix[8];\r\n result[7] = matrix[9];\r\n result[8] = matrix[10];\r\n return result;\r\n};\r\n\r\nvar scratchInverseRotation = new Matrix3();\r\nvar scratchMatrix3Zero = new Matrix3();\r\nvar scratchBottomRow = new Cartesian4();\r\nvar scratchExpectedBottomRow = new Cartesian4(0.0, 0.0, 0.0, 1.0);\r\n\r\n/**\r\n * Computes the inverse of the provided matrix using Cramers Rule.\r\n * If the determinant is zero, the matrix can not be inverted, and an exception is thrown.\r\n * If the matrix is an affine transformation matrix, it is more efficient\r\n * to invert it with {@link Matrix4.inverseTransformation}.\r\n *\r\n * @param {Matrix4} matrix The matrix to invert.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n *\r\n * @exception {RuntimeError} matrix is not invertible because its determinate is zero.\r\n */\r\nMatrix4.inverse = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n //\r\n // Ported from:\r\n // ftp://download.intel.com/design/PentiumIII/sml/24504301.pdf\r\n //\r\n var src0 = matrix[0];\r\n var src1 = matrix[4];\r\n var src2 = matrix[8];\r\n var src3 = matrix[12];\r\n var src4 = matrix[1];\r\n var src5 = matrix[5];\r\n var src6 = matrix[9];\r\n var src7 = matrix[13];\r\n var src8 = matrix[2];\r\n var src9 = matrix[6];\r\n var src10 = matrix[10];\r\n var src11 = matrix[14];\r\n var src12 = matrix[3];\r\n var src13 = matrix[7];\r\n var src14 = matrix[11];\r\n var src15 = matrix[15];\r\n\r\n // calculate pairs for first 8 elements (cofactors)\r\n var tmp0 = src10 * src15;\r\n var tmp1 = src11 * src14;\r\n var tmp2 = src9 * src15;\r\n var tmp3 = src11 * src13;\r\n var tmp4 = src9 * src14;\r\n var tmp5 = src10 * src13;\r\n var tmp6 = src8 * src15;\r\n var tmp7 = src11 * src12;\r\n var tmp8 = src8 * src14;\r\n var tmp9 = src10 * src12;\r\n var tmp10 = src8 * src13;\r\n var tmp11 = src9 * src12;\r\n\r\n // calculate first 8 elements (cofactors)\r\n var dst0 =\r\n tmp0 * src5 +\r\n tmp3 * src6 +\r\n tmp4 * src7 -\r\n (tmp1 * src5 + tmp2 * src6 + tmp5 * src7);\r\n var dst1 =\r\n tmp1 * src4 +\r\n tmp6 * src6 +\r\n tmp9 * src7 -\r\n (tmp0 * src4 + tmp7 * src6 + tmp8 * src7);\r\n var dst2 =\r\n tmp2 * src4 +\r\n tmp7 * src5 +\r\n tmp10 * src7 -\r\n (tmp3 * src4 + tmp6 * src5 + tmp11 * src7);\r\n var dst3 =\r\n tmp5 * src4 +\r\n tmp8 * src5 +\r\n tmp11 * src6 -\r\n (tmp4 * src4 + tmp9 * src5 + tmp10 * src6);\r\n var dst4 =\r\n tmp1 * src1 +\r\n tmp2 * src2 +\r\n tmp5 * src3 -\r\n (tmp0 * src1 + tmp3 * src2 + tmp4 * src3);\r\n var dst5 =\r\n tmp0 * src0 +\r\n tmp7 * src2 +\r\n tmp8 * src3 -\r\n (tmp1 * src0 + tmp6 * src2 + tmp9 * src3);\r\n var dst6 =\r\n tmp3 * src0 +\r\n tmp6 * src1 +\r\n tmp11 * src3 -\r\n (tmp2 * src0 + tmp7 * src1 + tmp10 * src3);\r\n var dst7 =\r\n tmp4 * src0 +\r\n tmp9 * src1 +\r\n tmp10 * src2 -\r\n (tmp5 * src0 + tmp8 * src1 + tmp11 * src2);\r\n\r\n // calculate pairs for second 8 elements (cofactors)\r\n tmp0 = src2 * src7;\r\n tmp1 = src3 * src6;\r\n tmp2 = src1 * src7;\r\n tmp3 = src3 * src5;\r\n tmp4 = src1 * src6;\r\n tmp5 = src2 * src5;\r\n tmp6 = src0 * src7;\r\n tmp7 = src3 * src4;\r\n tmp8 = src0 * src6;\r\n tmp9 = src2 * src4;\r\n tmp10 = src0 * src5;\r\n tmp11 = src1 * src4;\r\n\r\n // calculate second 8 elements (cofactors)\r\n var dst8 =\r\n tmp0 * src13 +\r\n tmp3 * src14 +\r\n tmp4 * src15 -\r\n (tmp1 * src13 + tmp2 * src14 + tmp5 * src15);\r\n var dst9 =\r\n tmp1 * src12 +\r\n tmp6 * src14 +\r\n tmp9 * src15 -\r\n (tmp0 * src12 + tmp7 * src14 + tmp8 * src15);\r\n var dst10 =\r\n tmp2 * src12 +\r\n tmp7 * src13 +\r\n tmp10 * src15 -\r\n (tmp3 * src12 + tmp6 * src13 + tmp11 * src15);\r\n var dst11 =\r\n tmp5 * src12 +\r\n tmp8 * src13 +\r\n tmp11 * src14 -\r\n (tmp4 * src12 + tmp9 * src13 + tmp10 * src14);\r\n var dst12 =\r\n tmp2 * src10 +\r\n tmp5 * src11 +\r\n tmp1 * src9 -\r\n (tmp4 * src11 + tmp0 * src9 + tmp3 * src10);\r\n var dst13 =\r\n tmp8 * src11 +\r\n tmp0 * src8 +\r\n tmp7 * src10 -\r\n (tmp6 * src10 + tmp9 * src11 + tmp1 * src8);\r\n var dst14 =\r\n tmp6 * src9 +\r\n tmp11 * src11 +\r\n tmp3 * src8 -\r\n (tmp10 * src11 + tmp2 * src8 + tmp7 * src9);\r\n var dst15 =\r\n tmp10 * src10 +\r\n tmp4 * src8 +\r\n tmp9 * src9 -\r\n (tmp8 * src9 + tmp11 * src10 + tmp5 * src8);\r\n\r\n // calculate determinant\r\n var det = src0 * dst0 + src1 * dst1 + src2 * dst2 + src3 * dst3;\r\n\r\n if (Math.abs(det) < CesiumMath.EPSILON21) {\r\n // Special case for a zero scale matrix that can occur, for example,\r\n // when a model's node has a [0, 0, 0] scale.\r\n if (\r\n Matrix3.equalsEpsilon(\r\n Matrix4.getMatrix3(matrix, scratchInverseRotation),\r\n scratchMatrix3Zero,\r\n CesiumMath.EPSILON7\r\n ) &&\r\n Cartesian4.equals(\r\n Matrix4.getRow(matrix, 3, scratchBottomRow),\r\n scratchExpectedBottomRow\r\n )\r\n ) {\r\n result[0] = 0.0;\r\n result[1] = 0.0;\r\n result[2] = 0.0;\r\n result[3] = 0.0;\r\n result[4] = 0.0;\r\n result[5] = 0.0;\r\n result[6] = 0.0;\r\n result[7] = 0.0;\r\n result[8] = 0.0;\r\n result[9] = 0.0;\r\n result[10] = 0.0;\r\n result[11] = 0.0;\r\n result[12] = -matrix[12];\r\n result[13] = -matrix[13];\r\n result[14] = -matrix[14];\r\n result[15] = 1.0;\r\n return result;\r\n }\r\n\r\n throw new RuntimeError(\r\n \"matrix is not invertible because its determinate is zero.\"\r\n );\r\n }\r\n\r\n // calculate matrix inverse\r\n det = 1.0 / det;\r\n\r\n result[0] = dst0 * det;\r\n result[1] = dst1 * det;\r\n result[2] = dst2 * det;\r\n result[3] = dst3 * det;\r\n result[4] = dst4 * det;\r\n result[5] = dst5 * det;\r\n result[6] = dst6 * det;\r\n result[7] = dst7 * det;\r\n result[8] = dst8 * det;\r\n result[9] = dst9 * det;\r\n result[10] = dst10 * det;\r\n result[11] = dst11 * det;\r\n result[12] = dst12 * det;\r\n result[13] = dst13 * det;\r\n result[14] = dst14 * det;\r\n result[15] = dst15 * det;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the inverse of the provided matrix assuming it is\r\n * an affine transformation matrix, where the upper left 3x3 elements\r\n * are a rotation matrix, and the upper three elements in the fourth\r\n * column are the translation. The bottom row is assumed to be [0, 0, 0, 1].\r\n * The matrix is not verified to be in the proper form.\r\n * This method is faster than computing the inverse for a general 4x4\r\n * matrix using {@link Matrix4.inverse}.\r\n *\r\n * @param {Matrix4} matrix The matrix to invert.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n */\r\nMatrix4.inverseTransformation = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n //This function is an optimized version of the below 4 lines.\r\n //var rT = Matrix3.transpose(Matrix4.getMatrix3(matrix));\r\n //var rTN = Matrix3.negate(rT);\r\n //var rTT = Matrix3.multiplyByVector(rTN, Matrix4.getTranslation(matrix));\r\n //return Matrix4.fromRotationTranslation(rT, rTT, result);\r\n\r\n var matrix0 = matrix[0];\r\n var matrix1 = matrix[1];\r\n var matrix2 = matrix[2];\r\n var matrix4 = matrix[4];\r\n var matrix5 = matrix[5];\r\n var matrix6 = matrix[6];\r\n var matrix8 = matrix[8];\r\n var matrix9 = matrix[9];\r\n var matrix10 = matrix[10];\r\n\r\n var vX = matrix[12];\r\n var vY = matrix[13];\r\n var vZ = matrix[14];\r\n\r\n var x = -matrix0 * vX - matrix1 * vY - matrix2 * vZ;\r\n var y = -matrix4 * vX - matrix5 * vY - matrix6 * vZ;\r\n var z = -matrix8 * vX - matrix9 * vY - matrix10 * vZ;\r\n\r\n result[0] = matrix0;\r\n result[1] = matrix4;\r\n result[2] = matrix8;\r\n result[3] = 0.0;\r\n result[4] = matrix1;\r\n result[5] = matrix5;\r\n result[6] = matrix9;\r\n result[7] = 0.0;\r\n result[8] = matrix2;\r\n result[9] = matrix6;\r\n result[10] = matrix10;\r\n result[11] = 0.0;\r\n result[12] = x;\r\n result[13] = y;\r\n result[14] = z;\r\n result[15] = 1.0;\r\n return result;\r\n};\r\n\r\nvar scratchTransposeMatrix = new Matrix4();\r\n\r\n/**\r\n * Computes the inverse transpose of a matrix.\r\n *\r\n * @param {Matrix4} matrix The matrix to transpose and invert.\r\n * @param {Matrix4} result The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter.\r\n */\r\nMatrix4.inverseTranspose = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n return Matrix4.inverse(\r\n Matrix4.transpose(matrix, scratchTransposeMatrix),\r\n result\r\n );\r\n};\r\n\r\n/**\r\n * An immutable Matrix4 instance initialized to the identity matrix.\r\n *\r\n * @type {Matrix4}\r\n * @constant\r\n */\r\nMatrix4.IDENTITY = Object.freeze(\r\n new Matrix4(\r\n 1.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 1.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 1.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 1.0\r\n )\r\n);\r\n\r\n/**\r\n * An immutable Matrix4 instance initialized to the zero matrix.\r\n *\r\n * @type {Matrix4}\r\n * @constant\r\n */\r\nMatrix4.ZERO = Object.freeze(\r\n new Matrix4(\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0\r\n )\r\n);\r\n\r\n/**\r\n * The index into Matrix4 for column 0, row 0.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix4.COLUMN0ROW0 = 0;\r\n\r\n/**\r\n * The index into Matrix4 for column 0, row 1.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix4.COLUMN0ROW1 = 1;\r\n\r\n/**\r\n * The index into Matrix4 for column 0, row 2.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix4.COLUMN0ROW2 = 2;\r\n\r\n/**\r\n * The index into Matrix4 for column 0, row 3.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix4.COLUMN0ROW3 = 3;\r\n\r\n/**\r\n * The index into Matrix4 for column 1, row 0.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix4.COLUMN1ROW0 = 4;\r\n\r\n/**\r\n * The index into Matrix4 for column 1, row 1.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix4.COLUMN1ROW1 = 5;\r\n\r\n/**\r\n * The index into Matrix4 for column 1, row 2.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix4.COLUMN1ROW2 = 6;\r\n\r\n/**\r\n * The index into Matrix4 for column 1, row 3.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix4.COLUMN1ROW3 = 7;\r\n\r\n/**\r\n * The index into Matrix4 for column 2, row 0.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix4.COLUMN2ROW0 = 8;\r\n\r\n/**\r\n * The index into Matrix4 for column 2, row 1.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix4.COLUMN2ROW1 = 9;\r\n\r\n/**\r\n * The index into Matrix4 for column 2, row 2.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix4.COLUMN2ROW2 = 10;\r\n\r\n/**\r\n * The index into Matrix4 for column 2, row 3.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix4.COLUMN2ROW3 = 11;\r\n\r\n/**\r\n * The index into Matrix4 for column 3, row 0.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix4.COLUMN3ROW0 = 12;\r\n\r\n/**\r\n * The index into Matrix4 for column 3, row 1.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix4.COLUMN3ROW1 = 13;\r\n\r\n/**\r\n * The index into Matrix4 for column 3, row 2.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix4.COLUMN3ROW2 = 14;\r\n\r\n/**\r\n * The index into Matrix4 for column 3, row 3.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\nMatrix4.COLUMN3ROW3 = 15;\r\n\r\nObject.defineProperties(Matrix4.prototype, {\r\n /**\r\n * Gets the number of items in the collection.\r\n * @memberof Matrix4.prototype\r\n *\r\n * @type {Number}\r\n */\r\n length: {\r\n get: function () {\r\n return Matrix4.packedLength;\r\n },\r\n },\r\n});\r\n\r\n/**\r\n * Duplicates the provided Matrix4 instance.\r\n *\r\n * @param {Matrix4} [result] The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.\r\n */\r\nMatrix4.prototype.clone = function (result) {\r\n return Matrix4.clone(this, result);\r\n};\r\n\r\n/**\r\n * Compares this matrix to the provided matrix componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Matrix4} [right] The right hand side matrix.\r\n * @returns {Boolean} true
if they are equal, false
otherwise.\r\n */\r\nMatrix4.prototype.equals = function (right) {\r\n return Matrix4.equals(this, right);\r\n};\r\n\r\n/**\r\n * @private\r\n */\r\nMatrix4.equalsArray = function (matrix, array, offset) {\r\n return (\r\n matrix[0] === array[offset] &&\r\n matrix[1] === array[offset + 1] &&\r\n matrix[2] === array[offset + 2] &&\r\n matrix[3] === array[offset + 3] &&\r\n matrix[4] === array[offset + 4] &&\r\n matrix[5] === array[offset + 5] &&\r\n matrix[6] === array[offset + 6] &&\r\n matrix[7] === array[offset + 7] &&\r\n matrix[8] === array[offset + 8] &&\r\n matrix[9] === array[offset + 9] &&\r\n matrix[10] === array[offset + 10] &&\r\n matrix[11] === array[offset + 11] &&\r\n matrix[12] === array[offset + 12] &&\r\n matrix[13] === array[offset + 13] &&\r\n matrix[14] === array[offset + 14] &&\r\n matrix[15] === array[offset + 15]\r\n );\r\n};\r\n\r\n/**\r\n * Compares this matrix to the provided matrix componentwise and returns\r\n * true
if they are within the provided epsilon,\r\n * false
otherwise.\r\n *\r\n * @param {Matrix4} [right] The right hand side matrix.\r\n * @param {Number} [epsilon=0] The epsilon to use for equality testing.\r\n * @returns {Boolean} true
if they are within the provided epsilon, false
otherwise.\r\n */\r\nMatrix4.prototype.equalsEpsilon = function (right, epsilon) {\r\n return Matrix4.equalsEpsilon(this, right, epsilon);\r\n};\r\n\r\n/**\r\n * Computes a string representing this Matrix with each row being\r\n * on a separate line and in the format '(column0, column1, column2, column3)'.\r\n *\r\n * @returns {String} A string representing the provided Matrix with each row being on a separate line and in the format '(column0, column1, column2, column3)'.\r\n */\r\nMatrix4.prototype.toString = function () {\r\n return (\r\n \"(\" +\r\n this[0] +\r\n \", \" +\r\n this[4] +\r\n \", \" +\r\n this[8] +\r\n \", \" +\r\n this[12] +\r\n \")\\n\" +\r\n \"(\" +\r\n this[1] +\r\n \", \" +\r\n this[5] +\r\n \", \" +\r\n this[9] +\r\n \", \" +\r\n this[13] +\r\n \")\\n\" +\r\n \"(\" +\r\n this[2] +\r\n \", \" +\r\n this[6] +\r\n \", \" +\r\n this[10] +\r\n \", \" +\r\n this[14] +\r\n \")\\n\" +\r\n \"(\" +\r\n this[3] +\r\n \", \" +\r\n this[7] +\r\n \", \" +\r\n this[11] +\r\n \", \" +\r\n this[15] +\r\n \")\"\r\n );\r\n};\r\nexport default Matrix4;\r\n","import Cartographic from \"./Cartographic.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport Ellipsoid from \"./Ellipsoid.js\";\r\nimport CesiumMath from \"./Math.js\";\r\n\r\n/**\r\n * A two dimensional region specified as longitude and latitude coordinates.\r\n *\r\n * @alias Rectangle\r\n * @constructor\r\n *\r\n * @param {Number} [west=0.0] The westernmost longitude, in radians, in the range [-Pi, Pi].\r\n * @param {Number} [south=0.0] The southernmost latitude, in radians, in the range [-Pi/2, Pi/2].\r\n * @param {Number} [east=0.0] The easternmost longitude, in radians, in the range [-Pi, Pi].\r\n * @param {Number} [north=0.0] The northernmost latitude, in radians, in the range [-Pi/2, Pi/2].\r\n *\r\n * @see Packable\r\n */\r\nfunction Rectangle(west, south, east, north) {\r\n /**\r\n * The westernmost longitude in radians in the range [-Pi, Pi].\r\n *\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.west = defaultValue(west, 0.0);\r\n\r\n /**\r\n * The southernmost latitude in radians in the range [-Pi/2, Pi/2].\r\n *\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.south = defaultValue(south, 0.0);\r\n\r\n /**\r\n * The easternmost longitude in radians in the range [-Pi, Pi].\r\n *\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.east = defaultValue(east, 0.0);\r\n\r\n /**\r\n * The northernmost latitude in radians in the range [-Pi/2, Pi/2].\r\n *\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.north = defaultValue(north, 0.0);\r\n}\r\n\r\nObject.defineProperties(Rectangle.prototype, {\r\n /**\r\n * Gets the width of the rectangle in radians.\r\n * @memberof Rectangle.prototype\r\n * @type {Number}\r\n * @readonly\r\n */\r\n width: {\r\n get: function () {\r\n return Rectangle.computeWidth(this);\r\n },\r\n },\r\n\r\n /**\r\n * Gets the height of the rectangle in radians.\r\n * @memberof Rectangle.prototype\r\n * @type {Number}\r\n * @readonly\r\n */\r\n height: {\r\n get: function () {\r\n return Rectangle.computeHeight(this);\r\n },\r\n },\r\n});\r\n\r\n/**\r\n * The number of elements used to pack the object into an array.\r\n * @type {Number}\r\n */\r\nRectangle.packedLength = 4;\r\n\r\n/**\r\n * Stores the provided instance into the provided array.\r\n *\r\n * @param {Rectangle} value The value to pack.\r\n * @param {Number[]} array The array to pack into.\r\n * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.\r\n *\r\n * @returns {Number[]} The array that was packed into\r\n */\r\nRectangle.pack = function (value, array, startingIndex) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"value\", value);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n array[startingIndex++] = value.west;\r\n array[startingIndex++] = value.south;\r\n array[startingIndex++] = value.east;\r\n array[startingIndex] = value.north;\r\n\r\n return array;\r\n};\r\n\r\n/**\r\n * Retrieves an instance from a packed array.\r\n *\r\n * @param {Number[]} array The packed array.\r\n * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.\r\n * @param {Rectangle} [result] The object into which to store the result.\r\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if one was not provided.\r\n */\r\nRectangle.unpack = function (array, startingIndex, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n if (!defined(result)) {\r\n result = new Rectangle();\r\n }\r\n\r\n result.west = array[startingIndex++];\r\n result.south = array[startingIndex++];\r\n result.east = array[startingIndex++];\r\n result.north = array[startingIndex];\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the width of a rectangle in radians.\r\n * @param {Rectangle} rectangle The rectangle to compute the width of.\r\n * @returns {Number} The width.\r\n */\r\nRectangle.computeWidth = function (rectangle) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rectangle\", rectangle);\r\n //>>includeEnd('debug');\r\n var east = rectangle.east;\r\n var west = rectangle.west;\r\n if (east < west) {\r\n east += CesiumMath.TWO_PI;\r\n }\r\n return east - west;\r\n};\r\n\r\n/**\r\n * Computes the height of a rectangle in radians.\r\n * @param {Rectangle} rectangle The rectangle to compute the height of.\r\n * @returns {Number} The height.\r\n */\r\nRectangle.computeHeight = function (rectangle) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rectangle\", rectangle);\r\n //>>includeEnd('debug');\r\n return rectangle.north - rectangle.south;\r\n};\r\n\r\n/**\r\n * Creates a rectangle given the boundary longitude and latitude in degrees.\r\n *\r\n * @param {Number} [west=0.0] The westernmost longitude in degrees in the range [-180.0, 180.0].\r\n * @param {Number} [south=0.0] The southernmost latitude in degrees in the range [-90.0, 90.0].\r\n * @param {Number} [east=0.0] The easternmost longitude in degrees in the range [-180.0, 180.0].\r\n * @param {Number} [north=0.0] The northernmost latitude in degrees in the range [-90.0, 90.0].\r\n * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.\r\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.\r\n *\r\n * @example\r\n * var rectangle = Cesium.Rectangle.fromDegrees(0.0, 20.0, 10.0, 30.0);\r\n */\r\nRectangle.fromDegrees = function (west, south, east, north, result) {\r\n west = CesiumMath.toRadians(defaultValue(west, 0.0));\r\n south = CesiumMath.toRadians(defaultValue(south, 0.0));\r\n east = CesiumMath.toRadians(defaultValue(east, 0.0));\r\n north = CesiumMath.toRadians(defaultValue(north, 0.0));\r\n\r\n if (!defined(result)) {\r\n return new Rectangle(west, south, east, north);\r\n }\r\n\r\n result.west = west;\r\n result.south = south;\r\n result.east = east;\r\n result.north = north;\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a rectangle given the boundary longitude and latitude in radians.\r\n *\r\n * @param {Number} [west=0.0] The westernmost longitude in radians in the range [-Math.PI, Math.PI].\r\n * @param {Number} [south=0.0] The southernmost latitude in radians in the range [-Math.PI/2, Math.PI/2].\r\n * @param {Number} [east=0.0] The easternmost longitude in radians in the range [-Math.PI, Math.PI].\r\n * @param {Number} [north=0.0] The northernmost latitude in radians in the range [-Math.PI/2, Math.PI/2].\r\n * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.\r\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.\r\n *\r\n * @example\r\n * var rectangle = Cesium.Rectangle.fromRadians(0.0, Math.PI/4, Math.PI/8, 3*Math.PI/4);\r\n */\r\nRectangle.fromRadians = function (west, south, east, north, result) {\r\n if (!defined(result)) {\r\n return new Rectangle(west, south, east, north);\r\n }\r\n\r\n result.west = defaultValue(west, 0.0);\r\n result.south = defaultValue(south, 0.0);\r\n result.east = defaultValue(east, 0.0);\r\n result.north = defaultValue(north, 0.0);\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates the smallest possible Rectangle that encloses all positions in the provided array.\r\n *\r\n * @param {Cartographic[]} cartographics The list of Cartographic instances.\r\n * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.\r\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.\r\n */\r\nRectangle.fromCartographicArray = function (cartographics, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"cartographics\", cartographics);\r\n //>>includeEnd('debug');\r\n\r\n var west = Number.MAX_VALUE;\r\n var east = -Number.MAX_VALUE;\r\n var westOverIDL = Number.MAX_VALUE;\r\n var eastOverIDL = -Number.MAX_VALUE;\r\n var south = Number.MAX_VALUE;\r\n var north = -Number.MAX_VALUE;\r\n\r\n for (var i = 0, len = cartographics.length; i < len; i++) {\r\n var position = cartographics[i];\r\n west = Math.min(west, position.longitude);\r\n east = Math.max(east, position.longitude);\r\n south = Math.min(south, position.latitude);\r\n north = Math.max(north, position.latitude);\r\n\r\n var lonAdjusted =\r\n position.longitude >= 0\r\n ? position.longitude\r\n : position.longitude + CesiumMath.TWO_PI;\r\n westOverIDL = Math.min(westOverIDL, lonAdjusted);\r\n eastOverIDL = Math.max(eastOverIDL, lonAdjusted);\r\n }\r\n\r\n if (east - west > eastOverIDL - westOverIDL) {\r\n west = westOverIDL;\r\n east = eastOverIDL;\r\n\r\n if (east > CesiumMath.PI) {\r\n east = east - CesiumMath.TWO_PI;\r\n }\r\n if (west > CesiumMath.PI) {\r\n west = west - CesiumMath.TWO_PI;\r\n }\r\n }\r\n\r\n if (!defined(result)) {\r\n return new Rectangle(west, south, east, north);\r\n }\r\n\r\n result.west = west;\r\n result.south = south;\r\n result.east = east;\r\n result.north = north;\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates the smallest possible Rectangle that encloses all positions in the provided array.\r\n *\r\n * @param {Cartesian3[]} cartesians The list of Cartesian instances.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid the cartesians are on.\r\n * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.\r\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.\r\n */\r\nRectangle.fromCartesianArray = function (cartesians, ellipsoid, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"cartesians\", cartesians);\r\n //>>includeEnd('debug');\r\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\r\n\r\n var west = Number.MAX_VALUE;\r\n var east = -Number.MAX_VALUE;\r\n var westOverIDL = Number.MAX_VALUE;\r\n var eastOverIDL = -Number.MAX_VALUE;\r\n var south = Number.MAX_VALUE;\r\n var north = -Number.MAX_VALUE;\r\n\r\n for (var i = 0, len = cartesians.length; i < len; i++) {\r\n var position = ellipsoid.cartesianToCartographic(cartesians[i]);\r\n west = Math.min(west, position.longitude);\r\n east = Math.max(east, position.longitude);\r\n south = Math.min(south, position.latitude);\r\n north = Math.max(north, position.latitude);\r\n\r\n var lonAdjusted =\r\n position.longitude >= 0\r\n ? position.longitude\r\n : position.longitude + CesiumMath.TWO_PI;\r\n westOverIDL = Math.min(westOverIDL, lonAdjusted);\r\n eastOverIDL = Math.max(eastOverIDL, lonAdjusted);\r\n }\r\n\r\n if (east - west > eastOverIDL - westOverIDL) {\r\n west = westOverIDL;\r\n east = eastOverIDL;\r\n\r\n if (east > CesiumMath.PI) {\r\n east = east - CesiumMath.TWO_PI;\r\n }\r\n if (west > CesiumMath.PI) {\r\n west = west - CesiumMath.TWO_PI;\r\n }\r\n }\r\n\r\n if (!defined(result)) {\r\n return new Rectangle(west, south, east, north);\r\n }\r\n\r\n result.west = west;\r\n result.south = south;\r\n result.east = east;\r\n result.north = north;\r\n return result;\r\n};\r\n\r\n/**\r\n * Duplicates a Rectangle.\r\n *\r\n * @param {Rectangle} rectangle The rectangle to clone.\r\n * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.\r\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided. (Returns undefined if rectangle is undefined)\r\n */\r\nRectangle.clone = function (rectangle, result) {\r\n if (!defined(rectangle)) {\r\n return undefined;\r\n }\r\n\r\n if (!defined(result)) {\r\n return new Rectangle(\r\n rectangle.west,\r\n rectangle.south,\r\n rectangle.east,\r\n rectangle.north\r\n );\r\n }\r\n\r\n result.west = rectangle.west;\r\n result.south = rectangle.south;\r\n result.east = rectangle.east;\r\n result.north = rectangle.north;\r\n return result;\r\n};\r\n\r\n/**\r\n * Compares the provided Rectangles componentwise and returns\r\n * true
if they pass an absolute or relative tolerance test,\r\n * false
otherwise.\r\n *\r\n * @param {Rectangle} [left] The first Rectangle.\r\n * @param {Rectangle} [right] The second Rectangle.\r\n * @param {Number} [absoluteEpsilon=0] The absolute epsilon tolerance to use for equality testing.\r\n * @returns {Boolean} true
if left and right are within the provided epsilon, false
otherwise.\r\n */\r\nRectangle.equalsEpsilon = function (left, right, absoluteEpsilon) {\r\n absoluteEpsilon = defaultValue(absoluteEpsilon, 0);\r\n\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n Math.abs(left.west - right.west) <= absoluteEpsilon &&\r\n Math.abs(left.south - right.south) <= absoluteEpsilon &&\r\n Math.abs(left.east - right.east) <= absoluteEpsilon &&\r\n Math.abs(left.north - right.north) <= absoluteEpsilon)\r\n );\r\n};\r\n\r\n/**\r\n * Duplicates this Rectangle.\r\n *\r\n * @param {Rectangle} [result] The object onto which to store the result.\r\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.\r\n */\r\nRectangle.prototype.clone = function (result) {\r\n return Rectangle.clone(this, result);\r\n};\r\n\r\n/**\r\n * Compares the provided Rectangle with this Rectangle componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Rectangle} [other] The Rectangle to compare.\r\n * @returns {Boolean} true
if the Rectangles are equal, false
otherwise.\r\n */\r\nRectangle.prototype.equals = function (other) {\r\n return Rectangle.equals(this, other);\r\n};\r\n\r\n/**\r\n * Compares the provided rectangles and returns true
if they are equal,\r\n * false
otherwise.\r\n *\r\n * @param {Rectangle} [left] The first Rectangle.\r\n * @param {Rectangle} [right] The second Rectangle.\r\n * @returns {Boolean} true
if left and right are equal; otherwise false
.\r\n */\r\nRectangle.equals = function (left, right) {\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n left.west === right.west &&\r\n left.south === right.south &&\r\n left.east === right.east &&\r\n left.north === right.north)\r\n );\r\n};\r\n\r\n/**\r\n * Compares the provided Rectangle with this Rectangle componentwise and returns\r\n * true
if they are within the provided epsilon,\r\n * false
otherwise.\r\n *\r\n * @param {Rectangle} [other] The Rectangle to compare.\r\n * @param {Number} [epsilon=0] The epsilon to use for equality testing.\r\n * @returns {Boolean} true
if the Rectangles are within the provided epsilon, false
otherwise.\r\n */\r\nRectangle.prototype.equalsEpsilon = function (other, epsilon) {\r\n return Rectangle.equalsEpsilon(this, other, epsilon);\r\n};\r\n\r\n/**\r\n * Checks a Rectangle's properties and throws if they are not in valid ranges.\r\n *\r\n * @param {Rectangle} rectangle The rectangle to validate\r\n *\r\n * @exception {DeveloperError} north
must be in the interval [-Pi/2
, Pi/2
].\r\n * @exception {DeveloperError} south
must be in the interval [-Pi/2
, Pi/2
].\r\n * @exception {DeveloperError} east
must be in the interval [-Pi
, Pi
].\r\n * @exception {DeveloperError} west
must be in the interval [-Pi
, Pi
].\r\n */\r\nRectangle.validate = function (rectangle) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rectangle\", rectangle);\r\n\r\n var north = rectangle.north;\r\n Check.typeOf.number.greaterThanOrEquals(\r\n \"north\",\r\n north,\r\n -CesiumMath.PI_OVER_TWO\r\n );\r\n Check.typeOf.number.lessThanOrEquals(\"north\", north, CesiumMath.PI_OVER_TWO);\r\n\r\n var south = rectangle.south;\r\n Check.typeOf.number.greaterThanOrEquals(\r\n \"south\",\r\n south,\r\n -CesiumMath.PI_OVER_TWO\r\n );\r\n Check.typeOf.number.lessThanOrEquals(\"south\", south, CesiumMath.PI_OVER_TWO);\r\n\r\n var west = rectangle.west;\r\n Check.typeOf.number.greaterThanOrEquals(\"west\", west, -Math.PI);\r\n Check.typeOf.number.lessThanOrEquals(\"west\", west, Math.PI);\r\n\r\n var east = rectangle.east;\r\n Check.typeOf.number.greaterThanOrEquals(\"east\", east, -Math.PI);\r\n Check.typeOf.number.lessThanOrEquals(\"east\", east, Math.PI);\r\n //>>includeEnd('debug');\r\n};\r\n\r\n/**\r\n * Computes the southwest corner of a rectangle.\r\n *\r\n * @param {Rectangle} rectangle The rectangle for which to find the corner\r\n * @param {Cartographic} [result] The object onto which to store the result.\r\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.\r\n */\r\nRectangle.southwest = function (rectangle, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rectangle\", rectangle);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n return new Cartographic(rectangle.west, rectangle.south);\r\n }\r\n result.longitude = rectangle.west;\r\n result.latitude = rectangle.south;\r\n result.height = 0.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the northwest corner of a rectangle.\r\n *\r\n * @param {Rectangle} rectangle The rectangle for which to find the corner\r\n * @param {Cartographic} [result] The object onto which to store the result.\r\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.\r\n */\r\nRectangle.northwest = function (rectangle, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rectangle\", rectangle);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n return new Cartographic(rectangle.west, rectangle.north);\r\n }\r\n result.longitude = rectangle.west;\r\n result.latitude = rectangle.north;\r\n result.height = 0.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the northeast corner of a rectangle.\r\n *\r\n * @param {Rectangle} rectangle The rectangle for which to find the corner\r\n * @param {Cartographic} [result] The object onto which to store the result.\r\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.\r\n */\r\nRectangle.northeast = function (rectangle, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rectangle\", rectangle);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n return new Cartographic(rectangle.east, rectangle.north);\r\n }\r\n result.longitude = rectangle.east;\r\n result.latitude = rectangle.north;\r\n result.height = 0.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the southeast corner of a rectangle.\r\n *\r\n * @param {Rectangle} rectangle The rectangle for which to find the corner\r\n * @param {Cartographic} [result] The object onto which to store the result.\r\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.\r\n */\r\nRectangle.southeast = function (rectangle, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rectangle\", rectangle);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n return new Cartographic(rectangle.east, rectangle.south);\r\n }\r\n result.longitude = rectangle.east;\r\n result.latitude = rectangle.south;\r\n result.height = 0.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the center of a rectangle.\r\n *\r\n * @param {Rectangle} rectangle The rectangle for which to find the center\r\n * @param {Cartographic} [result] The object onto which to store the result.\r\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.\r\n */\r\nRectangle.center = function (rectangle, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rectangle\", rectangle);\r\n //>>includeEnd('debug');\r\n\r\n var east = rectangle.east;\r\n var west = rectangle.west;\r\n\r\n if (east < west) {\r\n east += CesiumMath.TWO_PI;\r\n }\r\n\r\n var longitude = CesiumMath.negativePiToPi((west + east) * 0.5);\r\n var latitude = (rectangle.south + rectangle.north) * 0.5;\r\n\r\n if (!defined(result)) {\r\n return new Cartographic(longitude, latitude);\r\n }\r\n\r\n result.longitude = longitude;\r\n result.latitude = latitude;\r\n result.height = 0.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the intersection of two rectangles. This function assumes that the rectangle's coordinates are\r\n * latitude and longitude in radians and produces a correct intersection, taking into account the fact that\r\n * the same angle can be represented with multiple values as well as the wrapping of longitude at the\r\n * anti-meridian. For a simple intersection that ignores these factors and can be used with projected\r\n * coordinates, see {@link Rectangle.simpleIntersection}.\r\n *\r\n * @param {Rectangle} rectangle On rectangle to find an intersection\r\n * @param {Rectangle} otherRectangle Another rectangle to find an intersection\r\n * @param {Rectangle} [result] The object onto which to store the result.\r\n * @returns {Rectangle|undefined} The modified result parameter, a new Rectangle instance if none was provided or undefined if there is no intersection.\r\n */\r\nRectangle.intersection = function (rectangle, otherRectangle, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rectangle\", rectangle);\r\n Check.typeOf.object(\"otherRectangle\", otherRectangle);\r\n //>>includeEnd('debug');\r\n\r\n var rectangleEast = rectangle.east;\r\n var rectangleWest = rectangle.west;\r\n\r\n var otherRectangleEast = otherRectangle.east;\r\n var otherRectangleWest = otherRectangle.west;\r\n\r\n if (rectangleEast < rectangleWest && otherRectangleEast > 0.0) {\r\n rectangleEast += CesiumMath.TWO_PI;\r\n } else if (otherRectangleEast < otherRectangleWest && rectangleEast > 0.0) {\r\n otherRectangleEast += CesiumMath.TWO_PI;\r\n }\r\n\r\n if (rectangleEast < rectangleWest && otherRectangleWest < 0.0) {\r\n otherRectangleWest += CesiumMath.TWO_PI;\r\n } else if (otherRectangleEast < otherRectangleWest && rectangleWest < 0.0) {\r\n rectangleWest += CesiumMath.TWO_PI;\r\n }\r\n\r\n var west = CesiumMath.negativePiToPi(\r\n Math.max(rectangleWest, otherRectangleWest)\r\n );\r\n var east = CesiumMath.negativePiToPi(\r\n Math.min(rectangleEast, otherRectangleEast)\r\n );\r\n\r\n if (\r\n (rectangle.west < rectangle.east ||\r\n otherRectangle.west < otherRectangle.east) &&\r\n east <= west\r\n ) {\r\n return undefined;\r\n }\r\n\r\n var south = Math.max(rectangle.south, otherRectangle.south);\r\n var north = Math.min(rectangle.north, otherRectangle.north);\r\n\r\n if (south >= north) {\r\n return undefined;\r\n }\r\n\r\n if (!defined(result)) {\r\n return new Rectangle(west, south, east, north);\r\n }\r\n result.west = west;\r\n result.south = south;\r\n result.east = east;\r\n result.north = north;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a simple intersection of two rectangles. Unlike {@link Rectangle.intersection}, this function\r\n * does not attempt to put the angular coordinates into a consistent range or to account for crossing the\r\n * anti-meridian. As such, it can be used for rectangles where the coordinates are not simply latitude\r\n * and longitude (i.e. projected coordinates).\r\n *\r\n * @param {Rectangle} rectangle On rectangle to find an intersection\r\n * @param {Rectangle} otherRectangle Another rectangle to find an intersection\r\n * @param {Rectangle} [result] The object onto which to store the result.\r\n * @returns {Rectangle|undefined} The modified result parameter, a new Rectangle instance if none was provided or undefined if there is no intersection.\r\n */\r\nRectangle.simpleIntersection = function (rectangle, otherRectangle, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rectangle\", rectangle);\r\n Check.typeOf.object(\"otherRectangle\", otherRectangle);\r\n //>>includeEnd('debug');\r\n\r\n var west = Math.max(rectangle.west, otherRectangle.west);\r\n var south = Math.max(rectangle.south, otherRectangle.south);\r\n var east = Math.min(rectangle.east, otherRectangle.east);\r\n var north = Math.min(rectangle.north, otherRectangle.north);\r\n\r\n if (south >= north || west >= east) {\r\n return undefined;\r\n }\r\n\r\n if (!defined(result)) {\r\n return new Rectangle(west, south, east, north);\r\n }\r\n\r\n result.west = west;\r\n result.south = south;\r\n result.east = east;\r\n result.north = north;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a rectangle that is the union of two rectangles.\r\n *\r\n * @param {Rectangle} rectangle A rectangle to enclose in rectangle.\r\n * @param {Rectangle} otherRectangle A rectangle to enclose in a rectangle.\r\n * @param {Rectangle} [result] The object onto which to store the result.\r\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.\r\n */\r\nRectangle.union = function (rectangle, otherRectangle, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rectangle\", rectangle);\r\n Check.typeOf.object(\"otherRectangle\", otherRectangle);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Rectangle();\r\n }\r\n\r\n var rectangleEast = rectangle.east;\r\n var rectangleWest = rectangle.west;\r\n\r\n var otherRectangleEast = otherRectangle.east;\r\n var otherRectangleWest = otherRectangle.west;\r\n\r\n if (rectangleEast < rectangleWest && otherRectangleEast > 0.0) {\r\n rectangleEast += CesiumMath.TWO_PI;\r\n } else if (otherRectangleEast < otherRectangleWest && rectangleEast > 0.0) {\r\n otherRectangleEast += CesiumMath.TWO_PI;\r\n }\r\n\r\n if (rectangleEast < rectangleWest && otherRectangleWest < 0.0) {\r\n otherRectangleWest += CesiumMath.TWO_PI;\r\n } else if (otherRectangleEast < otherRectangleWest && rectangleWest < 0.0) {\r\n rectangleWest += CesiumMath.TWO_PI;\r\n }\r\n\r\n var west = CesiumMath.convertLongitudeRange(\r\n Math.min(rectangleWest, otherRectangleWest)\r\n );\r\n var east = CesiumMath.convertLongitudeRange(\r\n Math.max(rectangleEast, otherRectangleEast)\r\n );\r\n\r\n result.west = west;\r\n result.south = Math.min(rectangle.south, otherRectangle.south);\r\n result.east = east;\r\n result.north = Math.max(rectangle.north, otherRectangle.north);\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a rectangle by enlarging the provided rectangle until it contains the provided cartographic.\r\n *\r\n * @param {Rectangle} rectangle A rectangle to expand.\r\n * @param {Cartographic} cartographic A cartographic to enclose in a rectangle.\r\n * @param {Rectangle} [result] The object onto which to store the result.\r\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if one was not provided.\r\n */\r\nRectangle.expand = function (rectangle, cartographic, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rectangle\", rectangle);\r\n Check.typeOf.object(\"cartographic\", cartographic);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Rectangle();\r\n }\r\n\r\n result.west = Math.min(rectangle.west, cartographic.longitude);\r\n result.south = Math.min(rectangle.south, cartographic.latitude);\r\n result.east = Math.max(rectangle.east, cartographic.longitude);\r\n result.north = Math.max(rectangle.north, cartographic.latitude);\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Returns true if the cartographic is on or inside the rectangle, false otherwise.\r\n *\r\n * @param {Rectangle} rectangle The rectangle\r\n * @param {Cartographic} cartographic The cartographic to test.\r\n * @returns {Boolean} true if the provided cartographic is inside the rectangle, false otherwise.\r\n */\r\nRectangle.contains = function (rectangle, cartographic) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rectangle\", rectangle);\r\n Check.typeOf.object(\"cartographic\", cartographic);\r\n //>>includeEnd('debug');\r\n\r\n var longitude = cartographic.longitude;\r\n var latitude = cartographic.latitude;\r\n\r\n var west = rectangle.west;\r\n var east = rectangle.east;\r\n\r\n if (east < west) {\r\n east += CesiumMath.TWO_PI;\r\n if (longitude < 0.0) {\r\n longitude += CesiumMath.TWO_PI;\r\n }\r\n }\r\n return (\r\n (longitude > west ||\r\n CesiumMath.equalsEpsilon(longitude, west, CesiumMath.EPSILON14)) &&\r\n (longitude < east ||\r\n CesiumMath.equalsEpsilon(longitude, east, CesiumMath.EPSILON14)) &&\r\n latitude >= rectangle.south &&\r\n latitude <= rectangle.north\r\n );\r\n};\r\n\r\nvar subsampleLlaScratch = new Cartographic();\r\n/**\r\n * Samples a rectangle so that it includes a list of Cartesian points suitable for passing to\r\n * {@link BoundingSphere#fromPoints}. Sampling is necessary to account\r\n * for rectangles that cover the poles or cross the equator.\r\n *\r\n * @param {Rectangle} rectangle The rectangle to subsample.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid to use.\r\n * @param {Number} [surfaceHeight=0.0] The height of the rectangle above the ellipsoid.\r\n * @param {Cartesian3[]} [result] The array of Cartesians onto which to store the result.\r\n * @returns {Cartesian3[]} The modified result parameter or a new Array of Cartesians instances if none was provided.\r\n */\r\nRectangle.subsample = function (rectangle, ellipsoid, surfaceHeight, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rectangle\", rectangle);\r\n //>>includeEnd('debug');\r\n\r\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\r\n surfaceHeight = defaultValue(surfaceHeight, 0.0);\r\n\r\n if (!defined(result)) {\r\n result = [];\r\n }\r\n var length = 0;\r\n\r\n var north = rectangle.north;\r\n var south = rectangle.south;\r\n var east = rectangle.east;\r\n var west = rectangle.west;\r\n\r\n var lla = subsampleLlaScratch;\r\n lla.height = surfaceHeight;\r\n\r\n lla.longitude = west;\r\n lla.latitude = north;\r\n result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);\r\n length++;\r\n\r\n lla.longitude = east;\r\n result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);\r\n length++;\r\n\r\n lla.latitude = south;\r\n result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);\r\n length++;\r\n\r\n lla.longitude = west;\r\n result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);\r\n length++;\r\n\r\n if (north < 0.0) {\r\n lla.latitude = north;\r\n } else if (south > 0.0) {\r\n lla.latitude = south;\r\n } else {\r\n lla.latitude = 0.0;\r\n }\r\n\r\n for (var i = 1; i < 8; ++i) {\r\n lla.longitude = -Math.PI + i * CesiumMath.PI_OVER_TWO;\r\n if (Rectangle.contains(rectangle, lla)) {\r\n result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);\r\n length++;\r\n }\r\n }\r\n\r\n if (lla.latitude === 0.0) {\r\n lla.longitude = west;\r\n result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);\r\n length++;\r\n lla.longitude = east;\r\n result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);\r\n length++;\r\n }\r\n result.length = length;\r\n return result;\r\n};\r\n\r\n/**\r\n * The largest possible rectangle.\r\n *\r\n * @type {Rectangle}\r\n * @constant\r\n */\r\nRectangle.MAX_VALUE = Object.freeze(\r\n new Rectangle(\r\n -Math.PI,\r\n -CesiumMath.PI_OVER_TWO,\r\n Math.PI,\r\n CesiumMath.PI_OVER_TWO\r\n )\r\n);\r\nexport default Rectangle;\r\n","import Cartesian3 from \"./Cartesian3.js\";\r\nimport Cartographic from \"./Cartographic.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport Ellipsoid from \"./Ellipsoid.js\";\r\nimport GeographicProjection from \"./GeographicProjection.js\";\r\nimport Intersect from \"./Intersect.js\";\r\nimport Interval from \"./Interval.js\";\r\nimport CesiumMath from \"./Math.js\";\r\nimport Matrix3 from \"./Matrix3.js\";\r\nimport Matrix4 from \"./Matrix4.js\";\r\nimport Rectangle from \"./Rectangle.js\";\r\n\r\n/**\r\n * A bounding sphere with a center and a radius.\r\n * @alias BoundingSphere\r\n * @constructor\r\n *\r\n * @param {Cartesian3} [center=Cartesian3.ZERO] The center of the bounding sphere.\r\n * @param {Number} [radius=0.0] The radius of the bounding sphere.\r\n *\r\n * @see AxisAlignedBoundingBox\r\n * @see BoundingRectangle\r\n * @see Packable\r\n */\r\nfunction BoundingSphere(center, radius) {\r\n /**\r\n * The center point of the sphere.\r\n * @type {Cartesian3}\r\n * @default {@link Cartesian3.ZERO}\r\n */\r\n this.center = Cartesian3.clone(defaultValue(center, Cartesian3.ZERO));\r\n\r\n /**\r\n * The radius of the sphere.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.radius = defaultValue(radius, 0.0);\r\n}\r\n\r\nvar fromPointsXMin = new Cartesian3();\r\nvar fromPointsYMin = new Cartesian3();\r\nvar fromPointsZMin = new Cartesian3();\r\nvar fromPointsXMax = new Cartesian3();\r\nvar fromPointsYMax = new Cartesian3();\r\nvar fromPointsZMax = new Cartesian3();\r\nvar fromPointsCurrentPos = new Cartesian3();\r\nvar fromPointsScratch = new Cartesian3();\r\nvar fromPointsRitterCenter = new Cartesian3();\r\nvar fromPointsMinBoxPt = new Cartesian3();\r\nvar fromPointsMaxBoxPt = new Cartesian3();\r\nvar fromPointsNaiveCenterScratch = new Cartesian3();\r\nvar volumeConstant = (4.0 / 3.0) * CesiumMath.PI;\r\n\r\n/**\r\n * Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.\r\n * The bounding sphere is computed by running two algorithms, a naive algorithm and\r\n * Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.\r\n *\r\n * @param {Cartesian3[]} [positions] An array of points that the bounding sphere will enclose. Each point must have x
, y
, and z
properties.\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.\r\n *\r\n * @see {@link http://help.agi.com/AGIComponents/html/BlogBoundingSphere.htm|Bounding Sphere computation article}\r\n */\r\nBoundingSphere.fromPoints = function (positions, result) {\r\n if (!defined(result)) {\r\n result = new BoundingSphere();\r\n }\r\n\r\n if (!defined(positions) || positions.length === 0) {\r\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\r\n result.radius = 0.0;\r\n return result;\r\n }\r\n\r\n var currentPos = Cartesian3.clone(positions[0], fromPointsCurrentPos);\r\n\r\n var xMin = Cartesian3.clone(currentPos, fromPointsXMin);\r\n var yMin = Cartesian3.clone(currentPos, fromPointsYMin);\r\n var zMin = Cartesian3.clone(currentPos, fromPointsZMin);\r\n\r\n var xMax = Cartesian3.clone(currentPos, fromPointsXMax);\r\n var yMax = Cartesian3.clone(currentPos, fromPointsYMax);\r\n var zMax = Cartesian3.clone(currentPos, fromPointsZMax);\r\n\r\n var numPositions = positions.length;\r\n var i;\r\n for (i = 1; i < numPositions; i++) {\r\n Cartesian3.clone(positions[i], currentPos);\r\n\r\n var x = currentPos.x;\r\n var y = currentPos.y;\r\n var z = currentPos.z;\r\n\r\n // Store points containing the the smallest and largest components\r\n if (x < xMin.x) {\r\n Cartesian3.clone(currentPos, xMin);\r\n }\r\n\r\n if (x > xMax.x) {\r\n Cartesian3.clone(currentPos, xMax);\r\n }\r\n\r\n if (y < yMin.y) {\r\n Cartesian3.clone(currentPos, yMin);\r\n }\r\n\r\n if (y > yMax.y) {\r\n Cartesian3.clone(currentPos, yMax);\r\n }\r\n\r\n if (z < zMin.z) {\r\n Cartesian3.clone(currentPos, zMin);\r\n }\r\n\r\n if (z > zMax.z) {\r\n Cartesian3.clone(currentPos, zMax);\r\n }\r\n }\r\n\r\n // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).\r\n var xSpan = Cartesian3.magnitudeSquared(\r\n Cartesian3.subtract(xMax, xMin, fromPointsScratch)\r\n );\r\n var ySpan = Cartesian3.magnitudeSquared(\r\n Cartesian3.subtract(yMax, yMin, fromPointsScratch)\r\n );\r\n var zSpan = Cartesian3.magnitudeSquared(\r\n Cartesian3.subtract(zMax, zMin, fromPointsScratch)\r\n );\r\n\r\n // Set the diameter endpoints to the largest span.\r\n var diameter1 = xMin;\r\n var diameter2 = xMax;\r\n var maxSpan = xSpan;\r\n if (ySpan > maxSpan) {\r\n maxSpan = ySpan;\r\n diameter1 = yMin;\r\n diameter2 = yMax;\r\n }\r\n if (zSpan > maxSpan) {\r\n maxSpan = zSpan;\r\n diameter1 = zMin;\r\n diameter2 = zMax;\r\n }\r\n\r\n // Calculate the center of the initial sphere found by Ritter's algorithm\r\n var ritterCenter = fromPointsRitterCenter;\r\n ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;\r\n ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;\r\n ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;\r\n\r\n // Calculate the radius of the initial sphere found by Ritter's algorithm\r\n var radiusSquared = Cartesian3.magnitudeSquared(\r\n Cartesian3.subtract(diameter2, ritterCenter, fromPointsScratch)\r\n );\r\n var ritterRadius = Math.sqrt(radiusSquared);\r\n\r\n // Find the center of the sphere found using the Naive method.\r\n var minBoxPt = fromPointsMinBoxPt;\r\n minBoxPt.x = xMin.x;\r\n minBoxPt.y = yMin.y;\r\n minBoxPt.z = zMin.z;\r\n\r\n var maxBoxPt = fromPointsMaxBoxPt;\r\n maxBoxPt.x = xMax.x;\r\n maxBoxPt.y = yMax.y;\r\n maxBoxPt.z = zMax.z;\r\n\r\n var naiveCenter = Cartesian3.midpoint(\r\n minBoxPt,\r\n maxBoxPt,\r\n fromPointsNaiveCenterScratch\r\n );\r\n\r\n // Begin 2nd pass to find naive radius and modify the ritter sphere.\r\n var naiveRadius = 0;\r\n for (i = 0; i < numPositions; i++) {\r\n Cartesian3.clone(positions[i], currentPos);\r\n\r\n // Find the furthest point from the naive center to calculate the naive radius.\r\n var r = Cartesian3.magnitude(\r\n Cartesian3.subtract(currentPos, naiveCenter, fromPointsScratch)\r\n );\r\n if (r > naiveRadius) {\r\n naiveRadius = r;\r\n }\r\n\r\n // Make adjustments to the Ritter Sphere to include all points.\r\n var oldCenterToPointSquared = Cartesian3.magnitudeSquared(\r\n Cartesian3.subtract(currentPos, ritterCenter, fromPointsScratch)\r\n );\r\n if (oldCenterToPointSquared > radiusSquared) {\r\n var oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);\r\n // Calculate new radius to include the point that lies outside\r\n ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;\r\n radiusSquared = ritterRadius * ritterRadius;\r\n // Calculate center of new Ritter sphere\r\n var oldToNew = oldCenterToPoint - ritterRadius;\r\n ritterCenter.x =\r\n (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) /\r\n oldCenterToPoint;\r\n ritterCenter.y =\r\n (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) /\r\n oldCenterToPoint;\r\n ritterCenter.z =\r\n (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) /\r\n oldCenterToPoint;\r\n }\r\n }\r\n\r\n if (ritterRadius < naiveRadius) {\r\n Cartesian3.clone(ritterCenter, result.center);\r\n result.radius = ritterRadius;\r\n } else {\r\n Cartesian3.clone(naiveCenter, result.center);\r\n result.radius = naiveRadius;\r\n }\r\n\r\n return result;\r\n};\r\n\r\nvar defaultProjection = new GeographicProjection();\r\nvar fromRectangle2DLowerLeft = new Cartesian3();\r\nvar fromRectangle2DUpperRight = new Cartesian3();\r\nvar fromRectangle2DSouthwest = new Cartographic();\r\nvar fromRectangle2DNortheast = new Cartographic();\r\n\r\n/**\r\n * Computes a bounding sphere from a rectangle projected in 2D.\r\n *\r\n * @param {Rectangle} [rectangle] The rectangle around which to create a bounding sphere.\r\n * @param {Object} [projection=GeographicProjection] The projection used to project the rectangle into 2D.\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\r\n */\r\nBoundingSphere.fromRectangle2D = function (rectangle, projection, result) {\r\n return BoundingSphere.fromRectangleWithHeights2D(\r\n rectangle,\r\n projection,\r\n 0.0,\r\n 0.0,\r\n result\r\n );\r\n};\r\n\r\n/**\r\n * Computes a bounding sphere from a rectangle projected in 2D. The bounding sphere accounts for the\r\n * object's minimum and maximum heights over the rectangle.\r\n *\r\n * @param {Rectangle} [rectangle] The rectangle around which to create a bounding sphere.\r\n * @param {Object} [projection=GeographicProjection] The projection used to project the rectangle into 2D.\r\n * @param {Number} [minimumHeight=0.0] The minimum height over the rectangle.\r\n * @param {Number} [maximumHeight=0.0] The maximum height over the rectangle.\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\r\n */\r\nBoundingSphere.fromRectangleWithHeights2D = function (\r\n rectangle,\r\n projection,\r\n minimumHeight,\r\n maximumHeight,\r\n result\r\n) {\r\n if (!defined(result)) {\r\n result = new BoundingSphere();\r\n }\r\n\r\n if (!defined(rectangle)) {\r\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\r\n result.radius = 0.0;\r\n return result;\r\n }\r\n\r\n projection = defaultValue(projection, defaultProjection);\r\n\r\n Rectangle.southwest(rectangle, fromRectangle2DSouthwest);\r\n fromRectangle2DSouthwest.height = minimumHeight;\r\n Rectangle.northeast(rectangle, fromRectangle2DNortheast);\r\n fromRectangle2DNortheast.height = maximumHeight;\r\n\r\n var lowerLeft = projection.project(\r\n fromRectangle2DSouthwest,\r\n fromRectangle2DLowerLeft\r\n );\r\n var upperRight = projection.project(\r\n fromRectangle2DNortheast,\r\n fromRectangle2DUpperRight\r\n );\r\n\r\n var width = upperRight.x - lowerLeft.x;\r\n var height = upperRight.y - lowerLeft.y;\r\n var elevation = upperRight.z - lowerLeft.z;\r\n\r\n result.radius =\r\n Math.sqrt(width * width + height * height + elevation * elevation) * 0.5;\r\n var center = result.center;\r\n center.x = lowerLeft.x + width * 0.5;\r\n center.y = lowerLeft.y + height * 0.5;\r\n center.z = lowerLeft.z + elevation * 0.5;\r\n return result;\r\n};\r\n\r\nvar fromRectangle3DScratch = [];\r\n\r\n/**\r\n * Computes a bounding sphere from a rectangle in 3D. The bounding sphere is created using a subsample of points\r\n * on the ellipsoid and contained in the rectangle. It may not be accurate for all rectangles on all types of ellipsoids.\r\n *\r\n * @param {Rectangle} [rectangle] The valid rectangle used to create a bounding sphere.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid used to determine positions of the rectangle.\r\n * @param {Number} [surfaceHeight=0.0] The height above the surface of the ellipsoid.\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\r\n */\r\nBoundingSphere.fromRectangle3D = function (\r\n rectangle,\r\n ellipsoid,\r\n surfaceHeight,\r\n result\r\n) {\r\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\r\n surfaceHeight = defaultValue(surfaceHeight, 0.0);\r\n\r\n if (!defined(result)) {\r\n result = new BoundingSphere();\r\n }\r\n\r\n if (!defined(rectangle)) {\r\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\r\n result.radius = 0.0;\r\n return result;\r\n }\r\n\r\n var positions = Rectangle.subsample(\r\n rectangle,\r\n ellipsoid,\r\n surfaceHeight,\r\n fromRectangle3DScratch\r\n );\r\n return BoundingSphere.fromPoints(positions, result);\r\n};\r\n\r\n/**\r\n * Computes a tight-fitting bounding sphere enclosing a list of 3D points, where the points are\r\n * stored in a flat array in X, Y, Z, order. The bounding sphere is computed by running two\r\n * algorithms, a naive algorithm and Ritter's algorithm. The smaller of the two spheres is used to\r\n * ensure a tight fit.\r\n *\r\n * @param {Number[]} [positions] An array of points that the bounding sphere will enclose. Each point\r\n * is formed from three elements in the array in the order X, Y, Z.\r\n * @param {Cartesian3} [center=Cartesian3.ZERO] The position to which the positions are relative, which need not be the\r\n * origin of the coordinate system. This is useful when the positions are to be used for\r\n * relative-to-center (RTC) rendering.\r\n * @param {Number} [stride=3] The number of array elements per vertex. It must be at least 3, but it may\r\n * be higher. Regardless of the value of this parameter, the X coordinate of the first position\r\n * is at array index 0, the Y coordinate is at array index 1, and the Z coordinate is at array index\r\n * 2. When stride is 3, the X coordinate of the next position then begins at array index 3. If\r\n * the stride is 5, however, two array elements are skipped and the next position begins at array\r\n * index 5.\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.\r\n *\r\n * @example\r\n * // Compute the bounding sphere from 3 positions, each specified relative to a center.\r\n * // In addition to the X, Y, and Z coordinates, the points array contains two additional\r\n * // elements per point which are ignored for the purpose of computing the bounding sphere.\r\n * var center = new Cesium.Cartesian3(1.0, 2.0, 3.0);\r\n * var points = [1.0, 2.0, 3.0, 0.1, 0.2,\r\n * 4.0, 5.0, 6.0, 0.1, 0.2,\r\n * 7.0, 8.0, 9.0, 0.1, 0.2];\r\n * var sphere = Cesium.BoundingSphere.fromVertices(points, center, 5);\r\n *\r\n * @see {@link http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding/|Bounding Sphere computation article}\r\n */\r\nBoundingSphere.fromVertices = function (positions, center, stride, result) {\r\n if (!defined(result)) {\r\n result = new BoundingSphere();\r\n }\r\n\r\n if (!defined(positions) || positions.length === 0) {\r\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\r\n result.radius = 0.0;\r\n return result;\r\n }\r\n\r\n center = defaultValue(center, Cartesian3.ZERO);\r\n\r\n stride = defaultValue(stride, 3);\r\n\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number.greaterThanOrEquals(\"stride\", stride, 3);\r\n //>>includeEnd('debug');\r\n\r\n var currentPos = fromPointsCurrentPos;\r\n currentPos.x = positions[0] + center.x;\r\n currentPos.y = positions[1] + center.y;\r\n currentPos.z = positions[2] + center.z;\r\n\r\n var xMin = Cartesian3.clone(currentPos, fromPointsXMin);\r\n var yMin = Cartesian3.clone(currentPos, fromPointsYMin);\r\n var zMin = Cartesian3.clone(currentPos, fromPointsZMin);\r\n\r\n var xMax = Cartesian3.clone(currentPos, fromPointsXMax);\r\n var yMax = Cartesian3.clone(currentPos, fromPointsYMax);\r\n var zMax = Cartesian3.clone(currentPos, fromPointsZMax);\r\n\r\n var numElements = positions.length;\r\n var i;\r\n for (i = 0; i < numElements; i += stride) {\r\n var x = positions[i] + center.x;\r\n var y = positions[i + 1] + center.y;\r\n var z = positions[i + 2] + center.z;\r\n\r\n currentPos.x = x;\r\n currentPos.y = y;\r\n currentPos.z = z;\r\n\r\n // Store points containing the the smallest and largest components\r\n if (x < xMin.x) {\r\n Cartesian3.clone(currentPos, xMin);\r\n }\r\n\r\n if (x > xMax.x) {\r\n Cartesian3.clone(currentPos, xMax);\r\n }\r\n\r\n if (y < yMin.y) {\r\n Cartesian3.clone(currentPos, yMin);\r\n }\r\n\r\n if (y > yMax.y) {\r\n Cartesian3.clone(currentPos, yMax);\r\n }\r\n\r\n if (z < zMin.z) {\r\n Cartesian3.clone(currentPos, zMin);\r\n }\r\n\r\n if (z > zMax.z) {\r\n Cartesian3.clone(currentPos, zMax);\r\n }\r\n }\r\n\r\n // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).\r\n var xSpan = Cartesian3.magnitudeSquared(\r\n Cartesian3.subtract(xMax, xMin, fromPointsScratch)\r\n );\r\n var ySpan = Cartesian3.magnitudeSquared(\r\n Cartesian3.subtract(yMax, yMin, fromPointsScratch)\r\n );\r\n var zSpan = Cartesian3.magnitudeSquared(\r\n Cartesian3.subtract(zMax, zMin, fromPointsScratch)\r\n );\r\n\r\n // Set the diameter endpoints to the largest span.\r\n var diameter1 = xMin;\r\n var diameter2 = xMax;\r\n var maxSpan = xSpan;\r\n if (ySpan > maxSpan) {\r\n maxSpan = ySpan;\r\n diameter1 = yMin;\r\n diameter2 = yMax;\r\n }\r\n if (zSpan > maxSpan) {\r\n maxSpan = zSpan;\r\n diameter1 = zMin;\r\n diameter2 = zMax;\r\n }\r\n\r\n // Calculate the center of the initial sphere found by Ritter's algorithm\r\n var ritterCenter = fromPointsRitterCenter;\r\n ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;\r\n ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;\r\n ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;\r\n\r\n // Calculate the radius of the initial sphere found by Ritter's algorithm\r\n var radiusSquared = Cartesian3.magnitudeSquared(\r\n Cartesian3.subtract(diameter2, ritterCenter, fromPointsScratch)\r\n );\r\n var ritterRadius = Math.sqrt(radiusSquared);\r\n\r\n // Find the center of the sphere found using the Naive method.\r\n var minBoxPt = fromPointsMinBoxPt;\r\n minBoxPt.x = xMin.x;\r\n minBoxPt.y = yMin.y;\r\n minBoxPt.z = zMin.z;\r\n\r\n var maxBoxPt = fromPointsMaxBoxPt;\r\n maxBoxPt.x = xMax.x;\r\n maxBoxPt.y = yMax.y;\r\n maxBoxPt.z = zMax.z;\r\n\r\n var naiveCenter = Cartesian3.midpoint(\r\n minBoxPt,\r\n maxBoxPt,\r\n fromPointsNaiveCenterScratch\r\n );\r\n\r\n // Begin 2nd pass to find naive radius and modify the ritter sphere.\r\n var naiveRadius = 0;\r\n for (i = 0; i < numElements; i += stride) {\r\n currentPos.x = positions[i] + center.x;\r\n currentPos.y = positions[i + 1] + center.y;\r\n currentPos.z = positions[i + 2] + center.z;\r\n\r\n // Find the furthest point from the naive center to calculate the naive radius.\r\n var r = Cartesian3.magnitude(\r\n Cartesian3.subtract(currentPos, naiveCenter, fromPointsScratch)\r\n );\r\n if (r > naiveRadius) {\r\n naiveRadius = r;\r\n }\r\n\r\n // Make adjustments to the Ritter Sphere to include all points.\r\n var oldCenterToPointSquared = Cartesian3.magnitudeSquared(\r\n Cartesian3.subtract(currentPos, ritterCenter, fromPointsScratch)\r\n );\r\n if (oldCenterToPointSquared > radiusSquared) {\r\n var oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);\r\n // Calculate new radius to include the point that lies outside\r\n ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;\r\n radiusSquared = ritterRadius * ritterRadius;\r\n // Calculate center of new Ritter sphere\r\n var oldToNew = oldCenterToPoint - ritterRadius;\r\n ritterCenter.x =\r\n (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) /\r\n oldCenterToPoint;\r\n ritterCenter.y =\r\n (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) /\r\n oldCenterToPoint;\r\n ritterCenter.z =\r\n (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) /\r\n oldCenterToPoint;\r\n }\r\n }\r\n\r\n if (ritterRadius < naiveRadius) {\r\n Cartesian3.clone(ritterCenter, result.center);\r\n result.radius = ritterRadius;\r\n } else {\r\n Cartesian3.clone(naiveCenter, result.center);\r\n result.radius = naiveRadius;\r\n }\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a tight-fitting bounding sphere enclosing a list of EncodedCartesian3s, where the points are\r\n * stored in parallel flat arrays in X, Y, Z, order. The bounding sphere is computed by running two\r\n * algorithms, a naive algorithm and Ritter's algorithm. The smaller of the two spheres is used to\r\n * ensure a tight fit.\r\n *\r\n * @param {Number[]} [positionsHigh] An array of high bits of the encoded cartesians that the bounding sphere will enclose. Each point\r\n * is formed from three elements in the array in the order X, Y, Z.\r\n * @param {Number[]} [positionsLow] An array of low bits of the encoded cartesians that the bounding sphere will enclose. Each point\r\n * is formed from three elements in the array in the order X, Y, Z.\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.\r\n *\r\n * @see {@link http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding/|Bounding Sphere computation article}\r\n */\r\nBoundingSphere.fromEncodedCartesianVertices = function (\r\n positionsHigh,\r\n positionsLow,\r\n result\r\n) {\r\n if (!defined(result)) {\r\n result = new BoundingSphere();\r\n }\r\n\r\n if (\r\n !defined(positionsHigh) ||\r\n !defined(positionsLow) ||\r\n positionsHigh.length !== positionsLow.length ||\r\n positionsHigh.length === 0\r\n ) {\r\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\r\n result.radius = 0.0;\r\n return result;\r\n }\r\n\r\n var currentPos = fromPointsCurrentPos;\r\n currentPos.x = positionsHigh[0] + positionsLow[0];\r\n currentPos.y = positionsHigh[1] + positionsLow[1];\r\n currentPos.z = positionsHigh[2] + positionsLow[2];\r\n\r\n var xMin = Cartesian3.clone(currentPos, fromPointsXMin);\r\n var yMin = Cartesian3.clone(currentPos, fromPointsYMin);\r\n var zMin = Cartesian3.clone(currentPos, fromPointsZMin);\r\n\r\n var xMax = Cartesian3.clone(currentPos, fromPointsXMax);\r\n var yMax = Cartesian3.clone(currentPos, fromPointsYMax);\r\n var zMax = Cartesian3.clone(currentPos, fromPointsZMax);\r\n\r\n var numElements = positionsHigh.length;\r\n var i;\r\n for (i = 0; i < numElements; i += 3) {\r\n var x = positionsHigh[i] + positionsLow[i];\r\n var y = positionsHigh[i + 1] + positionsLow[i + 1];\r\n var z = positionsHigh[i + 2] + positionsLow[i + 2];\r\n\r\n currentPos.x = x;\r\n currentPos.y = y;\r\n currentPos.z = z;\r\n\r\n // Store points containing the the smallest and largest components\r\n if (x < xMin.x) {\r\n Cartesian3.clone(currentPos, xMin);\r\n }\r\n\r\n if (x > xMax.x) {\r\n Cartesian3.clone(currentPos, xMax);\r\n }\r\n\r\n if (y < yMin.y) {\r\n Cartesian3.clone(currentPos, yMin);\r\n }\r\n\r\n if (y > yMax.y) {\r\n Cartesian3.clone(currentPos, yMax);\r\n }\r\n\r\n if (z < zMin.z) {\r\n Cartesian3.clone(currentPos, zMin);\r\n }\r\n\r\n if (z > zMax.z) {\r\n Cartesian3.clone(currentPos, zMax);\r\n }\r\n }\r\n\r\n // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).\r\n var xSpan = Cartesian3.magnitudeSquared(\r\n Cartesian3.subtract(xMax, xMin, fromPointsScratch)\r\n );\r\n var ySpan = Cartesian3.magnitudeSquared(\r\n Cartesian3.subtract(yMax, yMin, fromPointsScratch)\r\n );\r\n var zSpan = Cartesian3.magnitudeSquared(\r\n Cartesian3.subtract(zMax, zMin, fromPointsScratch)\r\n );\r\n\r\n // Set the diameter endpoints to the largest span.\r\n var diameter1 = xMin;\r\n var diameter2 = xMax;\r\n var maxSpan = xSpan;\r\n if (ySpan > maxSpan) {\r\n maxSpan = ySpan;\r\n diameter1 = yMin;\r\n diameter2 = yMax;\r\n }\r\n if (zSpan > maxSpan) {\r\n maxSpan = zSpan;\r\n diameter1 = zMin;\r\n diameter2 = zMax;\r\n }\r\n\r\n // Calculate the center of the initial sphere found by Ritter's algorithm\r\n var ritterCenter = fromPointsRitterCenter;\r\n ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;\r\n ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;\r\n ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;\r\n\r\n // Calculate the radius of the initial sphere found by Ritter's algorithm\r\n var radiusSquared = Cartesian3.magnitudeSquared(\r\n Cartesian3.subtract(diameter2, ritterCenter, fromPointsScratch)\r\n );\r\n var ritterRadius = Math.sqrt(radiusSquared);\r\n\r\n // Find the center of the sphere found using the Naive method.\r\n var minBoxPt = fromPointsMinBoxPt;\r\n minBoxPt.x = xMin.x;\r\n minBoxPt.y = yMin.y;\r\n minBoxPt.z = zMin.z;\r\n\r\n var maxBoxPt = fromPointsMaxBoxPt;\r\n maxBoxPt.x = xMax.x;\r\n maxBoxPt.y = yMax.y;\r\n maxBoxPt.z = zMax.z;\r\n\r\n var naiveCenter = Cartesian3.midpoint(\r\n minBoxPt,\r\n maxBoxPt,\r\n fromPointsNaiveCenterScratch\r\n );\r\n\r\n // Begin 2nd pass to find naive radius and modify the ritter sphere.\r\n var naiveRadius = 0;\r\n for (i = 0; i < numElements; i += 3) {\r\n currentPos.x = positionsHigh[i] + positionsLow[i];\r\n currentPos.y = positionsHigh[i + 1] + positionsLow[i + 1];\r\n currentPos.z = positionsHigh[i + 2] + positionsLow[i + 2];\r\n\r\n // Find the furthest point from the naive center to calculate the naive radius.\r\n var r = Cartesian3.magnitude(\r\n Cartesian3.subtract(currentPos, naiveCenter, fromPointsScratch)\r\n );\r\n if (r > naiveRadius) {\r\n naiveRadius = r;\r\n }\r\n\r\n // Make adjustments to the Ritter Sphere to include all points.\r\n var oldCenterToPointSquared = Cartesian3.magnitudeSquared(\r\n Cartesian3.subtract(currentPos, ritterCenter, fromPointsScratch)\r\n );\r\n if (oldCenterToPointSquared > radiusSquared) {\r\n var oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);\r\n // Calculate new radius to include the point that lies outside\r\n ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;\r\n radiusSquared = ritterRadius * ritterRadius;\r\n // Calculate center of new Ritter sphere\r\n var oldToNew = oldCenterToPoint - ritterRadius;\r\n ritterCenter.x =\r\n (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) /\r\n oldCenterToPoint;\r\n ritterCenter.y =\r\n (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) /\r\n oldCenterToPoint;\r\n ritterCenter.z =\r\n (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) /\r\n oldCenterToPoint;\r\n }\r\n }\r\n\r\n if (ritterRadius < naiveRadius) {\r\n Cartesian3.clone(ritterCenter, result.center);\r\n result.radius = ritterRadius;\r\n } else {\r\n Cartesian3.clone(naiveCenter, result.center);\r\n result.radius = naiveRadius;\r\n }\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes a bounding sphere from the corner points of an axis-aligned bounding box. The sphere\r\n * tighly and fully encompases the box.\r\n *\r\n * @param {Cartesian3} [corner] The minimum height over the rectangle.\r\n * @param {Cartesian3} [oppositeCorner] The maximum height over the rectangle.\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\r\n *\r\n * @example\r\n * // Create a bounding sphere around the unit cube\r\n * var sphere = Cesium.BoundingSphere.fromCornerPoints(new Cesium.Cartesian3(-0.5, -0.5, -0.5), new Cesium.Cartesian3(0.5, 0.5, 0.5));\r\n */\r\nBoundingSphere.fromCornerPoints = function (corner, oppositeCorner, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"corner\", corner);\r\n Check.typeOf.object(\"oppositeCorner\", oppositeCorner);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new BoundingSphere();\r\n }\r\n\r\n var center = Cartesian3.midpoint(corner, oppositeCorner, result.center);\r\n result.radius = Cartesian3.distance(center, oppositeCorner);\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a bounding sphere encompassing an ellipsoid.\r\n *\r\n * @param {Ellipsoid} ellipsoid The ellipsoid around which to create a bounding sphere.\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\r\n *\r\n * @example\r\n * var boundingSphere = Cesium.BoundingSphere.fromEllipsoid(ellipsoid);\r\n */\r\nBoundingSphere.fromEllipsoid = function (ellipsoid, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"ellipsoid\", ellipsoid);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new BoundingSphere();\r\n }\r\n\r\n Cartesian3.clone(Cartesian3.ZERO, result.center);\r\n result.radius = ellipsoid.maximumRadius;\r\n return result;\r\n};\r\n\r\nvar fromBoundingSpheresScratch = new Cartesian3();\r\n\r\n/**\r\n * Computes a tight-fitting bounding sphere enclosing the provided array of bounding spheres.\r\n *\r\n * @param {BoundingSphere[]} [boundingSpheres] The array of bounding spheres.\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\r\n */\r\nBoundingSphere.fromBoundingSpheres = function (boundingSpheres, result) {\r\n if (!defined(result)) {\r\n result = new BoundingSphere();\r\n }\r\n\r\n if (!defined(boundingSpheres) || boundingSpheres.length === 0) {\r\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\r\n result.radius = 0.0;\r\n return result;\r\n }\r\n\r\n var length = boundingSpheres.length;\r\n if (length === 1) {\r\n return BoundingSphere.clone(boundingSpheres[0], result);\r\n }\r\n\r\n if (length === 2) {\r\n return BoundingSphere.union(boundingSpheres[0], boundingSpheres[1], result);\r\n }\r\n\r\n var positions = [];\r\n var i;\r\n for (i = 0; i < length; i++) {\r\n positions.push(boundingSpheres[i].center);\r\n }\r\n\r\n result = BoundingSphere.fromPoints(positions, result);\r\n\r\n var center = result.center;\r\n var radius = result.radius;\r\n for (i = 0; i < length; i++) {\r\n var tmp = boundingSpheres[i];\r\n radius = Math.max(\r\n radius,\r\n Cartesian3.distance(center, tmp.center, fromBoundingSpheresScratch) +\r\n tmp.radius\r\n );\r\n }\r\n result.radius = radius;\r\n\r\n return result;\r\n};\r\n\r\nvar fromOrientedBoundingBoxScratchU = new Cartesian3();\r\nvar fromOrientedBoundingBoxScratchV = new Cartesian3();\r\nvar fromOrientedBoundingBoxScratchW = new Cartesian3();\r\n\r\n/**\r\n * Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box.\r\n *\r\n * @param {OrientedBoundingBox} orientedBoundingBox The oriented bounding box.\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\r\n */\r\nBoundingSphere.fromOrientedBoundingBox = function (\r\n orientedBoundingBox,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"orientedBoundingBox\", orientedBoundingBox);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new BoundingSphere();\r\n }\r\n\r\n var halfAxes = orientedBoundingBox.halfAxes;\r\n var u = Matrix3.getColumn(halfAxes, 0, fromOrientedBoundingBoxScratchU);\r\n var v = Matrix3.getColumn(halfAxes, 1, fromOrientedBoundingBoxScratchV);\r\n var w = Matrix3.getColumn(halfAxes, 2, fromOrientedBoundingBoxScratchW);\r\n\r\n Cartesian3.add(u, v, u);\r\n Cartesian3.add(u, w, u);\r\n\r\n result.center = Cartesian3.clone(orientedBoundingBox.center, result.center);\r\n result.radius = Cartesian3.magnitude(u);\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Duplicates a BoundingSphere instance.\r\n *\r\n * @param {BoundingSphere} sphere The bounding sphere to duplicate.\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided. (Returns undefined if sphere is undefined)\r\n */\r\nBoundingSphere.clone = function (sphere, result) {\r\n if (!defined(sphere)) {\r\n return undefined;\r\n }\r\n\r\n if (!defined(result)) {\r\n return new BoundingSphere(sphere.center, sphere.radius);\r\n }\r\n\r\n result.center = Cartesian3.clone(sphere.center, result.center);\r\n result.radius = sphere.radius;\r\n return result;\r\n};\r\n\r\n/**\r\n * The number of elements used to pack the object into an array.\r\n * @type {Number}\r\n */\r\nBoundingSphere.packedLength = 4;\r\n\r\n/**\r\n * Stores the provided instance into the provided array.\r\n *\r\n * @param {BoundingSphere} value The value to pack.\r\n * @param {Number[]} array The array to pack into.\r\n * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.\r\n *\r\n * @returns {Number[]} The array that was packed into\r\n */\r\nBoundingSphere.pack = function (value, array, startingIndex) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"value\", value);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n var center = value.center;\r\n array[startingIndex++] = center.x;\r\n array[startingIndex++] = center.y;\r\n array[startingIndex++] = center.z;\r\n array[startingIndex] = value.radius;\r\n\r\n return array;\r\n};\r\n\r\n/**\r\n * Retrieves an instance from a packed array.\r\n *\r\n * @param {Number[]} array The packed array.\r\n * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.\r\n * @param {BoundingSphere} [result] The object into which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.\r\n */\r\nBoundingSphere.unpack = function (array, startingIndex, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n if (!defined(result)) {\r\n result = new BoundingSphere();\r\n }\r\n\r\n var center = result.center;\r\n center.x = array[startingIndex++];\r\n center.y = array[startingIndex++];\r\n center.z = array[startingIndex++];\r\n result.radius = array[startingIndex];\r\n return result;\r\n};\r\n\r\nvar unionScratch = new Cartesian3();\r\nvar unionScratchCenter = new Cartesian3();\r\n/**\r\n * Computes a bounding sphere that contains both the left and right bounding spheres.\r\n *\r\n * @param {BoundingSphere} left A sphere to enclose in a bounding sphere.\r\n * @param {BoundingSphere} right A sphere to enclose in a bounding sphere.\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\r\n */\r\nBoundingSphere.union = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new BoundingSphere();\r\n }\r\n\r\n var leftCenter = left.center;\r\n var leftRadius = left.radius;\r\n var rightCenter = right.center;\r\n var rightRadius = right.radius;\r\n\r\n var toRightCenter = Cartesian3.subtract(\r\n rightCenter,\r\n leftCenter,\r\n unionScratch\r\n );\r\n var centerSeparation = Cartesian3.magnitude(toRightCenter);\r\n\r\n if (leftRadius >= centerSeparation + rightRadius) {\r\n // Left sphere wins.\r\n left.clone(result);\r\n return result;\r\n }\r\n\r\n if (rightRadius >= centerSeparation + leftRadius) {\r\n // Right sphere wins.\r\n right.clone(result);\r\n return result;\r\n }\r\n\r\n // There are two tangent points, one on far side of each sphere.\r\n var halfDistanceBetweenTangentPoints =\r\n (leftRadius + centerSeparation + rightRadius) * 0.5;\r\n\r\n // Compute the center point halfway between the two tangent points.\r\n var center = Cartesian3.multiplyByScalar(\r\n toRightCenter,\r\n (-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation,\r\n unionScratchCenter\r\n );\r\n Cartesian3.add(center, leftCenter, center);\r\n Cartesian3.clone(center, result.center);\r\n result.radius = halfDistanceBetweenTangentPoints;\r\n\r\n return result;\r\n};\r\n\r\nvar expandScratch = new Cartesian3();\r\n/**\r\n * Computes a bounding sphere by enlarging the provided sphere to contain the provided point.\r\n *\r\n * @param {BoundingSphere} sphere A sphere to expand.\r\n * @param {Cartesian3} point A point to enclose in a bounding sphere.\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\r\n */\r\nBoundingSphere.expand = function (sphere, point, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"sphere\", sphere);\r\n Check.typeOf.object(\"point\", point);\r\n //>>includeEnd('debug');\r\n\r\n result = BoundingSphere.clone(sphere, result);\r\n\r\n var radius = Cartesian3.magnitude(\r\n Cartesian3.subtract(point, result.center, expandScratch)\r\n );\r\n if (radius > result.radius) {\r\n result.radius = radius;\r\n }\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Determines which side of a plane a sphere is located.\r\n *\r\n * @param {BoundingSphere} sphere The bounding sphere to test.\r\n * @param {Plane} plane The plane to test against.\r\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire sphere is on the side of the plane\r\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire sphere is\r\n * on the opposite side, and {@link Intersect.INTERSECTING} if the sphere\r\n * intersects the plane.\r\n */\r\nBoundingSphere.intersectPlane = function (sphere, plane) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"sphere\", sphere);\r\n Check.typeOf.object(\"plane\", plane);\r\n //>>includeEnd('debug');\r\n\r\n var center = sphere.center;\r\n var radius = sphere.radius;\r\n var normal = plane.normal;\r\n var distanceToPlane = Cartesian3.dot(normal, center) + plane.distance;\r\n\r\n if (distanceToPlane < -radius) {\r\n // The center point is negative side of the plane normal\r\n return Intersect.OUTSIDE;\r\n } else if (distanceToPlane < radius) {\r\n // The center point is positive side of the plane, but radius extends beyond it; partial overlap\r\n return Intersect.INTERSECTING;\r\n }\r\n return Intersect.INSIDE;\r\n};\r\n\r\n/**\r\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\r\n *\r\n * @param {BoundingSphere} sphere The bounding sphere to apply the transformation to.\r\n * @param {Matrix4} transform The transformation matrix to apply to the bounding sphere.\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\r\n */\r\nBoundingSphere.transform = function (sphere, transform, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"sphere\", sphere);\r\n Check.typeOf.object(\"transform\", transform);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new BoundingSphere();\r\n }\r\n\r\n result.center = Matrix4.multiplyByPoint(\r\n transform,\r\n sphere.center,\r\n result.center\r\n );\r\n result.radius = Matrix4.getMaximumScale(transform) * sphere.radius;\r\n\r\n return result;\r\n};\r\n\r\nvar distanceSquaredToScratch = new Cartesian3();\r\n\r\n/**\r\n * Computes the estimated distance squared from the closest point on a bounding sphere to a point.\r\n *\r\n * @param {BoundingSphere} sphere The sphere.\r\n * @param {Cartesian3} cartesian The point\r\n * @returns {Number} The estimated distance squared from the bounding sphere to the point.\r\n *\r\n * @example\r\n * // Sort bounding spheres from back to front\r\n * spheres.sort(function(a, b) {\r\n * return Cesium.BoundingSphere.distanceSquaredTo(b, camera.positionWC) - Cesium.BoundingSphere.distanceSquaredTo(a, camera.positionWC);\r\n * });\r\n */\r\nBoundingSphere.distanceSquaredTo = function (sphere, cartesian) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"sphere\", sphere);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n //>>includeEnd('debug');\r\n\r\n var diff = Cartesian3.subtract(\r\n sphere.center,\r\n cartesian,\r\n distanceSquaredToScratch\r\n );\r\n return Cartesian3.magnitudeSquared(diff) - sphere.radius * sphere.radius;\r\n};\r\n\r\n/**\r\n * Applies a 4x4 affine transformation matrix to a bounding sphere where there is no scale\r\n * The transformation matrix is not verified to have a uniform scale of 1.\r\n * This method is faster than computing the general bounding sphere transform using {@link BoundingSphere.transform}.\r\n *\r\n * @param {BoundingSphere} sphere The bounding sphere to apply the transformation to.\r\n * @param {Matrix4} transform The transformation matrix to apply to the bounding sphere.\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\r\n *\r\n * @example\r\n * var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(positionOnEllipsoid);\r\n * var boundingSphere = new Cesium.BoundingSphere();\r\n * var newBoundingSphere = Cesium.BoundingSphere.transformWithoutScale(boundingSphere, modelMatrix);\r\n */\r\nBoundingSphere.transformWithoutScale = function (sphere, transform, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"sphere\", sphere);\r\n Check.typeOf.object(\"transform\", transform);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new BoundingSphere();\r\n }\r\n\r\n result.center = Matrix4.multiplyByPoint(\r\n transform,\r\n sphere.center,\r\n result.center\r\n );\r\n result.radius = sphere.radius;\r\n\r\n return result;\r\n};\r\n\r\nvar scratchCartesian3 = new Cartesian3();\r\n/**\r\n * The distances calculated by the vector from the center of the bounding sphere to position projected onto direction\r\n * plus/minus the radius of the bounding sphere.\r\n *
\r\n * If you imagine the infinite number of planes with normal direction, this computes the smallest distance to the\r\n * closest and farthest planes from position that intersect the bounding sphere.\r\n *\r\n * @param {BoundingSphere} sphere The bounding sphere to calculate the distance to.\r\n * @param {Cartesian3} position The position to calculate the distance from.\r\n * @param {Cartesian3} direction The direction from position.\r\n * @param {Interval} [result] A Interval to store the nearest and farthest distances.\r\n * @returns {Interval} The nearest and farthest distances on the bounding sphere from position in direction.\r\n */\r\nBoundingSphere.computePlaneDistances = function (\r\n sphere,\r\n position,\r\n direction,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"sphere\", sphere);\r\n Check.typeOf.object(\"position\", position);\r\n Check.typeOf.object(\"direction\", direction);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Interval();\r\n }\r\n\r\n var toCenter = Cartesian3.subtract(\r\n sphere.center,\r\n position,\r\n scratchCartesian3\r\n );\r\n var mag = Cartesian3.dot(direction, toCenter);\r\n\r\n result.start = mag - sphere.radius;\r\n result.stop = mag + sphere.radius;\r\n return result;\r\n};\r\n\r\nvar projectTo2DNormalScratch = new Cartesian3();\r\nvar projectTo2DEastScratch = new Cartesian3();\r\nvar projectTo2DNorthScratch = new Cartesian3();\r\nvar projectTo2DWestScratch = new Cartesian3();\r\nvar projectTo2DSouthScratch = new Cartesian3();\r\nvar projectTo2DCartographicScratch = new Cartographic();\r\nvar projectTo2DPositionsScratch = new Array(8);\r\nfor (var n = 0; n < 8; ++n) {\r\n projectTo2DPositionsScratch[n] = new Cartesian3();\r\n}\r\n\r\nvar projectTo2DProjection = new GeographicProjection();\r\n/**\r\n * Creates a bounding sphere in 2D from a bounding sphere in 3D world coordinates.\r\n *\r\n * @param {BoundingSphere} sphere The bounding sphere to transform to 2D.\r\n * @param {Object} [projection=GeographicProjection] The projection to 2D.\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\r\n */\r\nBoundingSphere.projectTo2D = function (sphere, projection, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"sphere\", sphere);\r\n //>>includeEnd('debug');\r\n\r\n projection = defaultValue(projection, projectTo2DProjection);\r\n\r\n var ellipsoid = projection.ellipsoid;\r\n var center = sphere.center;\r\n var radius = sphere.radius;\r\n\r\n var normal;\r\n if (Cartesian3.equals(center, Cartesian3.ZERO)) {\r\n // Bounding sphere is at the center. The geodetic surface normal is not\r\n // defined here so pick the x-axis as a fallback.\r\n normal = Cartesian3.clone(Cartesian3.UNIT_X, projectTo2DNormalScratch);\r\n } else {\r\n normal = ellipsoid.geodeticSurfaceNormal(center, projectTo2DNormalScratch);\r\n }\r\n var east = Cartesian3.cross(\r\n Cartesian3.UNIT_Z,\r\n normal,\r\n projectTo2DEastScratch\r\n );\r\n Cartesian3.normalize(east, east);\r\n var north = Cartesian3.cross(normal, east, projectTo2DNorthScratch);\r\n Cartesian3.normalize(north, north);\r\n\r\n Cartesian3.multiplyByScalar(normal, radius, normal);\r\n Cartesian3.multiplyByScalar(north, radius, north);\r\n Cartesian3.multiplyByScalar(east, radius, east);\r\n\r\n var south = Cartesian3.negate(north, projectTo2DSouthScratch);\r\n var west = Cartesian3.negate(east, projectTo2DWestScratch);\r\n\r\n var positions = projectTo2DPositionsScratch;\r\n\r\n // top NE corner\r\n var corner = positions[0];\r\n Cartesian3.add(normal, north, corner);\r\n Cartesian3.add(corner, east, corner);\r\n\r\n // top NW corner\r\n corner = positions[1];\r\n Cartesian3.add(normal, north, corner);\r\n Cartesian3.add(corner, west, corner);\r\n\r\n // top SW corner\r\n corner = positions[2];\r\n Cartesian3.add(normal, south, corner);\r\n Cartesian3.add(corner, west, corner);\r\n\r\n // top SE corner\r\n corner = positions[3];\r\n Cartesian3.add(normal, south, corner);\r\n Cartesian3.add(corner, east, corner);\r\n\r\n Cartesian3.negate(normal, normal);\r\n\r\n // bottom NE corner\r\n corner = positions[4];\r\n Cartesian3.add(normal, north, corner);\r\n Cartesian3.add(corner, east, corner);\r\n\r\n // bottom NW corner\r\n corner = positions[5];\r\n Cartesian3.add(normal, north, corner);\r\n Cartesian3.add(corner, west, corner);\r\n\r\n // bottom SW corner\r\n corner = positions[6];\r\n Cartesian3.add(normal, south, corner);\r\n Cartesian3.add(corner, west, corner);\r\n\r\n // bottom SE corner\r\n corner = positions[7];\r\n Cartesian3.add(normal, south, corner);\r\n Cartesian3.add(corner, east, corner);\r\n\r\n var length = positions.length;\r\n for (var i = 0; i < length; ++i) {\r\n var position = positions[i];\r\n Cartesian3.add(center, position, position);\r\n var cartographic = ellipsoid.cartesianToCartographic(\r\n position,\r\n projectTo2DCartographicScratch\r\n );\r\n projection.project(cartographic, position);\r\n }\r\n\r\n result = BoundingSphere.fromPoints(positions, result);\r\n\r\n // swizzle center components\r\n center = result.center;\r\n var x = center.x;\r\n var y = center.y;\r\n var z = center.z;\r\n center.x = z;\r\n center.y = x;\r\n center.z = y;\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Determines whether or not a sphere is hidden from view by the occluder.\r\n *\r\n * @param {BoundingSphere} sphere The bounding sphere surrounding the occludee object.\r\n * @param {Occluder} occluder The occluder.\r\n * @returns {Boolean} true
if the sphere is not visible; otherwise false
.\r\n */\r\nBoundingSphere.isOccluded = function (sphere, occluder) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"sphere\", sphere);\r\n Check.typeOf.object(\"occluder\", occluder);\r\n //>>includeEnd('debug');\r\n return !occluder.isBoundingSphereVisible(sphere);\r\n};\r\n\r\n/**\r\n * Compares the provided BoundingSphere componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {BoundingSphere} [left] The first BoundingSphere.\r\n * @param {BoundingSphere} [right] The second BoundingSphere.\r\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\r\n */\r\nBoundingSphere.equals = function (left, right) {\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n Cartesian3.equals(left.center, right.center) &&\r\n left.radius === right.radius)\r\n );\r\n};\r\n\r\n/**\r\n * Determines which side of a plane the sphere is located.\r\n *\r\n * @param {Plane} plane The plane to test against.\r\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire sphere is on the side of the plane\r\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire sphere is\r\n * on the opposite side, and {@link Intersect.INTERSECTING} if the sphere\r\n * intersects the plane.\r\n */\r\nBoundingSphere.prototype.intersectPlane = function (plane) {\r\n return BoundingSphere.intersectPlane(this, plane);\r\n};\r\n\r\n/**\r\n * Computes the estimated distance squared from the closest point on a bounding sphere to a point.\r\n *\r\n * @param {Cartesian3} cartesian The point\r\n * @returns {Number} The estimated distance squared from the bounding sphere to the point.\r\n *\r\n * @example\r\n * // Sort bounding spheres from back to front\r\n * spheres.sort(function(a, b) {\r\n * return b.distanceSquaredTo(camera.positionWC) - a.distanceSquaredTo(camera.positionWC);\r\n * });\r\n */\r\nBoundingSphere.prototype.distanceSquaredTo = function (cartesian) {\r\n return BoundingSphere.distanceSquaredTo(this, cartesian);\r\n};\r\n\r\n/**\r\n * The distances calculated by the vector from the center of the bounding sphere to position projected onto direction\r\n * plus/minus the radius of the bounding sphere.\r\n *
\r\n * If you imagine the infinite number of planes with normal direction, this computes the smallest distance to the\r\n * closest and farthest planes from position that intersect the bounding sphere.\r\n *\r\n * @param {Cartesian3} position The position to calculate the distance from.\r\n * @param {Cartesian3} direction The direction from position.\r\n * @param {Interval} [result] A Interval to store the nearest and farthest distances.\r\n * @returns {Interval} The nearest and farthest distances on the bounding sphere from position in direction.\r\n */\r\nBoundingSphere.prototype.computePlaneDistances = function (\r\n position,\r\n direction,\r\n result\r\n) {\r\n return BoundingSphere.computePlaneDistances(\r\n this,\r\n position,\r\n direction,\r\n result\r\n );\r\n};\r\n\r\n/**\r\n * Determines whether or not a sphere is hidden from view by the occluder.\r\n *\r\n * @param {Occluder} occluder The occluder.\r\n * @returns {Boolean} true
if the sphere is not visible; otherwise false
.\r\n */\r\nBoundingSphere.prototype.isOccluded = function (occluder) {\r\n return BoundingSphere.isOccluded(this, occluder);\r\n};\r\n\r\n/**\r\n * Compares this BoundingSphere against the provided BoundingSphere componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {BoundingSphere} [right] The right hand side BoundingSphere.\r\n * @returns {Boolean} true
if they are equal, false
otherwise.\r\n */\r\nBoundingSphere.prototype.equals = function (right) {\r\n return BoundingSphere.equals(this, right);\r\n};\r\n\r\n/**\r\n * Duplicates this BoundingSphere instance.\r\n *\r\n * @param {BoundingSphere} [result] The object onto which to store the result.\r\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\r\n */\r\nBoundingSphere.prototype.clone = function (result) {\r\n return BoundingSphere.clone(this, result);\r\n};\r\n\r\n/**\r\n * Computes the radius of the BoundingSphere.\r\n * @returns {Number} The radius of the BoundingSphere.\r\n */\r\nBoundingSphere.prototype.volume = function () {\r\n var radius = this.radius;\r\n return volumeConstant * radius * radius * radius;\r\n};\r\nexport default BoundingSphere;\r\n","/**\r\n * @license\r\n *\r\n * Grauw URI utilities\r\n *\r\n * See: http://hg.grauw.nl/grauw-lib/file/tip/src/uri.js\r\n *\r\n * @author Laurens Holst (http://www.grauw.nl/)\r\n *\r\n * Copyright 2012 Laurens Holst\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n *\r\n */\r\n\r\n\t/**\r\n\t * Constructs a URI object.\r\n\t * @constructor\r\n\t * @class Implementation of URI parsing and base URI resolving algorithm in RFC 3986.\r\n\t * @param {string|URI} uri A string or URI object to create the object from.\r\n\t */\r\n\tfunction URI(uri) {\r\n\t\tif (uri instanceof URI) { // copy constructor\r\n\t\t\tthis.scheme = uri.scheme;\r\n\t\t\tthis.authority = uri.authority;\r\n\t\t\tthis.path = uri.path;\r\n\t\t\tthis.query = uri.query;\r\n\t\t\tthis.fragment = uri.fragment;\r\n\t\t} else if (uri) { // uri is URI string or cast to string\r\n\t\t\tvar c = parseRegex.exec(uri);\r\n\t\t\tthis.scheme = c[1];\r\n\t\t\tthis.authority = c[2];\r\n\t\t\tthis.path = c[3];\r\n\t\t\tthis.query = c[4];\r\n\t\t\tthis.fragment = c[5];\r\n\t\t}\r\n\t}\r\n\t// Initial values on the prototype\r\n\tURI.prototype.scheme = null;\r\n\tURI.prototype.authority = null;\r\n\tURI.prototype.path = '';\r\n\tURI.prototype.query = null;\r\n\tURI.prototype.fragment = null;\r\n\r\n\t// Regular expression from RFC 3986 appendix B\r\n\tvar parseRegex = new RegExp('^(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\\\\?([^#]*))?(?:#(.*))?$');\r\n\r\n\t/**\r\n\t * Returns the scheme part of the URI.\r\n\t * In \"http://example.com:80/a/b?x#y\" this is \"http\".\r\n\t */\r\n\tURI.prototype.getScheme = function() {\r\n\t\treturn this.scheme;\r\n\t};\r\n\r\n\t/**\r\n\t * Returns the authority part of the URI.\r\n\t * In \"http://example.com:80/a/b?x#y\" this is \"example.com:80\".\r\n\t */\r\n\tURI.prototype.getAuthority = function() {\r\n\t\treturn this.authority;\r\n\t};\r\n\r\n\t/**\r\n\t * Returns the path part of the URI.\r\n\t * In \"http://example.com:80/a/b?x#y\" this is \"/a/b\".\r\n\t * In \"mailto:mike@example.com\" this is \"mike@example.com\".\r\n\t */\r\n\tURI.prototype.getPath = function() {\r\n\t\treturn this.path;\r\n\t};\r\n\r\n\t/**\r\n\t * Returns the query part of the URI.\r\n\t * In \"http://example.com:80/a/b?x#y\" this is \"x\".\r\n\t */\r\n\tURI.prototype.getQuery = function() {\r\n\t\treturn this.query;\r\n\t};\r\n\r\n\t/**\r\n\t * Returns the fragment part of the URI.\r\n\t * In \"http://example.com:80/a/b?x#y\" this is \"y\".\r\n\t */\r\n\tURI.prototype.getFragment = function() {\r\n\t\treturn this.fragment;\r\n\t};\r\n\r\n\t/**\r\n\t * Tests whether the URI is an absolute URI.\r\n\t * See RFC 3986 section 4.3.\r\n\t */\r\n\tURI.prototype.isAbsolute = function() {\r\n\t\treturn !!this.scheme && !this.fragment;\r\n\t};\r\n\r\n\t///**\r\n\t//* Extensive validation of the URI against the ABNF in RFC 3986\r\n\t//*/\r\n\t//URI.prototype.validate\r\n\r\n\t/**\r\n\t * Tests whether the URI is a same-document reference.\r\n\t * See RFC 3986 section 4.4.\r\n\t *\r\n\t * To perform more thorough comparison, you can normalise the URI objects.\r\n\t */\r\n\tURI.prototype.isSameDocumentAs = function(uri) {\r\n\t\treturn uri.scheme == this.scheme &&\r\n\t\t uri.authority == this.authority &&\r\n\t\t uri.path == this.path &&\r\n\t\t uri.query == this.query;\r\n\t};\r\n\r\n\t/**\r\n\t * Simple String Comparison of two URIs.\r\n\t * See RFC 3986 section 6.2.1.\r\n\t *\r\n\t * To perform more thorough comparison, you can normalise the URI objects.\r\n\t */\r\n\tURI.prototype.equals = function(uri) {\r\n\t\treturn this.isSameDocumentAs(uri) && uri.fragment == this.fragment;\r\n\t};\r\n\r\n\t/**\r\n\t * Normalizes the URI using syntax-based normalization.\r\n\t * This includes case normalization, percent-encoding normalization and path segment normalization.\r\n\t * XXX: Percent-encoding normalization does not escape characters that need to be escaped.\r\n\t * (Although that would not be a valid URI in the first place. See validate().)\r\n\t * See RFC 3986 section 6.2.2.\r\n\t */\r\n\tURI.prototype.normalize = function() {\r\n\t\tthis.removeDotSegments();\r\n\t\tif (this.scheme)\r\n\t\t\tthis.scheme = this.scheme.toLowerCase();\r\n\t\tif (this.authority)\r\n\t\t\tthis.authority = this.authority.replace(authorityRegex, replaceAuthority).\r\n\t\t\t\t\t\t\t\t\treplace(caseRegex, replaceCase);\r\n\t\tif (this.path)\r\n\t\t\tthis.path = this.path.replace(caseRegex, replaceCase);\r\n\t\tif (this.query)\r\n\t\t\tthis.query = this.query.replace(caseRegex, replaceCase);\r\n\t\tif (this.fragment)\r\n\t\t\tthis.fragment = this.fragment.replace(caseRegex, replaceCase);\r\n\t};\r\n\r\n\tvar caseRegex = /%[0-9a-z]{2}/gi;\r\n\tvar percentRegex = /[a-zA-Z0-9\\-\\._~]/;\r\n\tvar authorityRegex = /(.*@)?([^@:]*)(:.*)?/;\r\n\r\n\tfunction replaceCase(str) {\r\n\t\tvar dec = unescape(str);\r\n\t\treturn percentRegex.test(dec) ? dec : str.toUpperCase();\r\n\t}\r\n\r\n\tfunction replaceAuthority(str, p1, p2, p3) {\r\n\t\treturn (p1 || '') + p2.toLowerCase() + (p3 || '');\r\n\t}\r\n\r\n\t/**\r\n\t * Resolve a relative URI (this) against a base URI.\r\n\t * The base URI must be an absolute URI.\r\n\t * See RFC 3986 section 5.2\r\n\t */\r\n\tURI.prototype.resolve = function(baseURI) {\r\n\t\tvar uri = new URI();\r\n\t\tif (this.scheme) {\r\n\t\t\turi.scheme = this.scheme;\r\n\t\t\turi.authority = this.authority;\r\n\t\t\turi.path = this.path;\r\n\t\t\turi.query = this.query;\r\n\t\t} else {\r\n\t\t\turi.scheme = baseURI.scheme;\r\n\t\t\tif (this.authority) {\r\n\t\t\t\turi.authority = this.authority;\r\n\t\t\t\turi.path = this.path;\r\n\t\t\t\turi.query = this.query;\r\n\t\t\t} else {\r\n\t\t\t\turi.authority = baseURI.authority;\r\n\t\t\t\tif (this.path == '') {\r\n\t\t\t\t\turi.path = baseURI.path;\r\n\t\t\t\t\turi.query = this.query || baseURI.query;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tif (this.path.charAt(0) == '/') {\r\n\t\t\t\t\t\turi.path = this.path;\r\n\t\t\t\t\t\turi.removeDotSegments();\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tif (baseURI.authority && baseURI.path == '') {\r\n\t\t\t\t\t\t\turi.path = '/' + this.path;\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\turi.path = baseURI.path.substring(0, baseURI.path.lastIndexOf('/') + 1) + this.path;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\turi.removeDotSegments();\r\n\t\t\t\t\t}\r\n\t\t\t\t\turi.query = this.query;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\turi.fragment = this.fragment;\r\n\t\treturn uri;\r\n\t};\r\n\r\n\t/**\r\n\t * Remove dot segments from path.\r\n\t * See RFC 3986 section 5.2.4\r\n\t * @private\r\n\t */\r\n\tURI.prototype.removeDotSegments = function() {\r\n\t\tvar input = this.path.split('/'),\r\n\t\t\toutput = [],\r\n\t\t\tsegment,\r\n\t\t\tabsPath = input[0] == '';\r\n\t\tif (absPath)\r\n\t\t\tinput.shift();\r\n\t\tvar sFirst = input[0] == '' ? input.shift() : null;\r\n\t\twhile (input.length) {\r\n\t\t\tsegment = input.shift();\r\n\t\t\tif (segment == '..') {\r\n\t\t\t\toutput.pop();\r\n\t\t\t} else if (segment != '.') {\r\n\t\t\t\toutput.push(segment);\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (segment == '.' || segment == '..')\r\n\t\t\toutput.push('');\r\n\t\tif (absPath)\r\n\t\t\toutput.unshift('');\r\n\t\tthis.path = output.join('/');\r\n\t};\r\n\r\n\t// We don't like this function because it builds up a cache that is never cleared.\r\n//\t/**\r\n//\t * Resolves a relative URI against an absolute base URI.\r\n//\t * Convenience method.\r\n//\t * @param {String} uri the relative URI to resolve\r\n//\t * @param {String} baseURI the base URI (must be absolute) to resolve against\r\n//\t */\r\n//\tURI.resolve = function(sURI, sBaseURI) {\r\n//\t\tvar uri = cache[sURI] || (cache[sURI] = new URI(sURI));\r\n//\t\tvar baseURI = cache[sBaseURI] || (cache[sBaseURI] = new URI(sBaseURI));\r\n//\t\treturn uri.resolve(baseURI).toString();\r\n//\t};\r\n\r\n//\tvar cache = {};\r\n\r\n\t/**\r\n\t * Serialises the URI to a string.\r\n\t */\r\n\tURI.prototype.toString = function() {\r\n\t\tvar result = '';\r\n\t\tif (this.scheme)\r\n\t\t\tresult += this.scheme + ':';\r\n\t\tif (this.authority)\r\n\t\t\tresult += '//' + this.authority;\r\n\t\tresult += this.path;\r\n\t\tif (this.query)\r\n\t\t\tresult += '?' + this.query;\r\n\t\tif (this.fragment)\r\n\t\t\tresult += '#' + this.fragment;\r\n\t\treturn result;\r\n\t};\r\n\r\nexport default URI;\r\n","import Uri from \"../ThirdParty/Uri.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\n\r\n/**\r\n * Given a relative Uri and a base Uri, returns the absolute Uri of the relative Uri.\r\n * @function\r\n *\r\n * @param {String} relative The relative Uri.\r\n * @param {String} [base] The base Uri.\r\n * @returns {String} The absolute Uri of the given relative Uri.\r\n *\r\n * @example\r\n * //absolute Uri will be \"https://test.com/awesome.png\";\r\n * var absoluteUri = Cesium.getAbsoluteUri('awesome.png', 'https://test.com');\r\n */\r\nfunction getAbsoluteUri(relative, base) {\r\n var documentObject;\r\n if (typeof document !== \"undefined\") {\r\n documentObject = document;\r\n }\r\n\r\n return getAbsoluteUri._implementation(relative, base, documentObject);\r\n}\r\n\r\ngetAbsoluteUri._implementation = function (relative, base, documentObject) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(relative)) {\r\n throw new DeveloperError(\"relative uri is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(base)) {\r\n if (typeof documentObject === \"undefined\") {\r\n return relative;\r\n }\r\n base = defaultValue(documentObject.baseURI, documentObject.location.href);\r\n }\r\n\r\n var baseUri = new Uri(base);\r\n var relativeUri = new Uri(relative);\r\n return relativeUri.resolve(baseUri).toString();\r\n};\r\nexport default getAbsoluteUri;\r\n","/**\r\n @license\r\n when.js - https://github.com/cujojs/when\r\n\r\n MIT License (c) copyright B Cavalier & J Hann\r\n\r\n * A lightweight CommonJS Promises/A and when() implementation\r\n * when is part of the cujo.js family of libraries (http://cujojs.com/)\r\n *\r\n * Licensed under the MIT License at:\r\n * http://www.opensource.org/licenses/mit-license.php\r\n *\r\n * @version 1.7.1\r\n */\r\n\r\n\tvar reduceArray, slice, undef;\r\n\r\n\t//\r\n\t// Public API\r\n\t//\r\n\r\n\twhen.defer = defer; // Create a deferred\r\n\twhen.resolve = resolve; // Create a resolved promise\r\n\twhen.reject = reject; // Create a rejected promise\r\n\r\n\twhen.join = join; // Join 2 or more promises\r\n\r\n\twhen.all = all; // Resolve a list of promises\r\n\twhen.map = map; // Array.map() for promises\r\n\twhen.reduce = reduce; // Array.reduce() for promises\r\n\r\n\twhen.any = any; // One-winner race\r\n\twhen.some = some; // Multi-winner race\r\n\r\n\twhen.chain = chain; // Make a promise trigger another resolver\r\n\r\n\twhen.isPromise = isPromise; // Determine if a thing is a promise\r\n\r\n\t/**\r\n\t * Register an observer for a promise or immediate value.\r\n\t *\r\n\t * @param {*} promiseOrValue\r\n\t * @param {function?} [onFulfilled] callback to be called when promiseOrValue is\r\n\t * successfully fulfilled. If promiseOrValue is an immediate value, callback\r\n\t * will be invoked immediately.\r\n\t * @param {function?} [onRejected] callback to be called when promiseOrValue is\r\n\t * rejected.\r\n\t * @param {function?} [onProgress] callback to be called when progress updates\r\n\t * are issued for promiseOrValue.\r\n\t * @returns {Promise} a new {@link Promise} that will complete with the return\r\n\t * value of callback or errback or the completion value of promiseOrValue if\r\n\t * callback and/or errback is not supplied.\r\n\t */\r\n\tfunction when(promiseOrValue, onFulfilled, onRejected, onProgress) {\r\n\t\t// Get a trusted promise for the input promiseOrValue, and then\r\n\t\t// register promise handlers\r\n\t\treturn resolve(promiseOrValue).then(onFulfilled, onRejected, onProgress);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns promiseOrValue if promiseOrValue is a {@link Promise}, a new Promise if\r\n\t * promiseOrValue is a foreign promise, or a new, already-fulfilled {@link Promise}\r\n\t * whose value is promiseOrValue if promiseOrValue is an immediate value.\r\n\t *\r\n\t * @param {*} promiseOrValue\r\n\t * @returns Guaranteed to return a trusted Promise. If promiseOrValue is a when.js {@link Promise}\r\n\t * returns promiseOrValue, otherwise, returns a new, already-resolved, when.js {@link Promise}\r\n\t * whose resolution value is:\r\n\t * * the resolution value of promiseOrValue if it's a foreign promise, or\r\n\t * * promiseOrValue if it's a value\r\n\t */\r\n\tfunction resolve(promiseOrValue) {\r\n\t\tvar promise, deferred;\r\n\r\n\t\tif(promiseOrValue instanceof Promise) {\r\n\t\t\t// It's a when.js promise, so we trust it\r\n\t\t\tpromise = promiseOrValue;\r\n\r\n\t\t} else {\r\n\t\t\t// It's not a when.js promise. See if it's a foreign promise or a value.\r\n\t\t\tif(isPromise(promiseOrValue)) {\r\n\t\t\t\t// It's a thenable, but we don't know where it came from, so don't trust\r\n\t\t\t\t// its implementation entirely. Introduce a trusted middleman when.js promise\r\n\t\t\t\tdeferred = defer();\r\n\r\n\t\t\t\t// IMPORTANT: This is the only place when.js should ever call .then() on an\r\n\t\t\t\t// untrusted promise. Don't expose the return value to the untrusted promise\r\n\t\t\t\tpromiseOrValue.then(\r\n\t\t\t\t\tfunction(value) { deferred.resolve(value); },\r\n\t\t\t\t\tfunction(reason) { deferred.reject(reason); },\r\n\t\t\t\t\tfunction(update) { deferred.progress(update); }\r\n\t\t\t\t);\r\n\r\n\t\t\t\tpromise = deferred.promise;\r\n\r\n\t\t\t} else {\r\n\t\t\t\t// It's a value, not a promise. Create a resolved promise for it.\r\n\t\t\t\tpromise = fulfilled(promiseOrValue);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn promise;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a rejected promise for the supplied promiseOrValue. The returned\r\n\t * promise will be rejected with:\r\n\t * - promiseOrValue, if it is a value, or\r\n\t * - if promiseOrValue is a promise\r\n\t * - promiseOrValue's value after it is fulfilled\r\n\t * - promiseOrValue's reason after it is rejected\r\n\t * @param {*} promiseOrValue the rejected value of the returned {@link Promise}\r\n\t * @returns {Promise} rejected {@link Promise}\r\n\t */\r\n\tfunction reject(promiseOrValue) {\r\n\t\treturn when(promiseOrValue, rejected);\r\n\t}\r\n\r\n\t/**\r\n\t * Trusted Promise constructor. A Promise created from this constructor is\r\n\t * a trusted when.js promise. Any other duck-typed promise is considered\r\n\t * untrusted.\r\n\t * @constructor\r\n\t * @name Promise\r\n\t */\r\n\tfunction Promise(then) {\r\n\t\tthis.then = then;\r\n\t}\r\n\r\n\tPromise.prototype = {\r\n\t\t/**\r\n\t\t * Register a callback that will be called when a promise is\r\n\t\t * fulfilled or rejected. Optionally also register a progress handler.\r\n\t\t * Shortcut for .then(onFulfilledOrRejected, onFulfilledOrRejected, onProgress)\r\n\t\t * @param {function?} [onFulfilledOrRejected]\r\n\t\t * @param {function?} [onProgress]\r\n\t\t * @returns {Promise}\r\n\t\t */\r\n\t\talways: function(onFulfilledOrRejected, onProgress) {\r\n\t\t\treturn this.then(onFulfilledOrRejected, onFulfilledOrRejected, onProgress);\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * Register a rejection handler. Shortcut for .then(undefined, onRejected)\r\n\t\t * @param {function?} onRejected\r\n\t\t * @returns {Promise}\r\n\t\t */\r\n\t\totherwise: function(onRejected) {\r\n\t\t\treturn this.then(undef, onRejected);\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * Shortcut for .then(function() { return value; })\r\n\t\t * @param {*} value\r\n\t\t * @returns {Promise} a promise that:\r\n\t\t * - is fulfilled if value is not a promise, or\r\n\t\t * - if value is a promise, will fulfill with its value, or reject\r\n\t\t * with its reason.\r\n\t\t */\r\n\t\tyield: function(value) {\r\n\t\t\treturn this.then(function() {\r\n\t\t\t\treturn value;\r\n\t\t\t});\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * Assumes that this promise will fulfill with an array, and arranges\r\n\t\t * for the onFulfilled to be called with the array as its argument list\r\n\t\t * i.e. onFulfilled.spread(undefined, array).\r\n\t\t * @param {function} onFulfilled function to receive spread arguments\r\n\t\t * @returns {Promise}\r\n\t\t */\r\n\t\tspread: function(onFulfilled) {\r\n\t\t\treturn this.then(function(array) {\r\n\t\t\t\t// array may contain promises, so resolve its contents.\r\n\t\t\t\treturn all(array, function(array) {\r\n\t\t\t\t\treturn onFulfilled.apply(undef, array);\r\n\t\t\t\t});\r\n\t\t\t});\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Create an already-resolved promise for the supplied value\r\n\t * @private\r\n\t *\r\n\t * @param {*} value\r\n\t * @returns {Promise} fulfilled promise\r\n\t */\r\n\tfunction fulfilled(value) {\r\n\t\tvar p = new Promise(function(onFulfilled) {\r\n\t\t\t// TODO: Promises/A+ check typeof onFulfilled\r\n\t\t\ttry {\r\n\t\t\t\treturn resolve(onFulfilled ? onFulfilled(value) : value);\r\n\t\t\t} catch(e) {\r\n\t\t\t\treturn rejected(e);\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\treturn p;\r\n\t}\r\n\r\n\t/**\r\n\t * Create an already-rejected {@link Promise} with the supplied\r\n\t * rejection reason.\r\n\t * @private\r\n\t *\r\n\t * @param {*} reason\r\n\t * @returns {Promise} rejected promise\r\n\t */\r\n\tfunction rejected(reason) {\r\n\t\tvar p = new Promise(function(_, onRejected) {\r\n\t\t\t// TODO: Promises/A+ check typeof onRejected\r\n\t\t\ttry {\r\n\t\t\t\treturn onRejected ? resolve(onRejected(reason)) : rejected(reason);\r\n\t\t\t} catch(e) {\r\n\t\t\t\treturn rejected(e);\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\treturn p;\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a new, Deferred with fully isolated resolver and promise parts,\r\n\t * either or both of which may be given out safely to consumers.\r\n\t * The Deferred itself has the full API: resolve, reject, progress, and\r\n\t * then. The resolver has resolve, reject, and progress. The promise\r\n\t * only has then.\r\n\t *\r\n\t * @returns {Deferred}\r\n\t */\r\n\tfunction defer() {\r\n\t\tvar deferred, promise, handlers, progressHandlers,\r\n\t\t\t_then, _progress, _resolve;\r\n\r\n\t\t/**\r\n\t\t * The promise for the new deferred\r\n\t\t * @type {Promise}\r\n\t\t */\r\n\t\tpromise = new Promise(then);\r\n\r\n\t\t/**\r\n\t\t * The full Deferred object, with {@link Promise} and {@link Resolver} parts\r\n\t\t * @class Deferred\r\n\t\t * @name Deferred\r\n\t\t */\r\n\t\tdeferred = {\r\n\t\t\tthen: then, // DEPRECATED: use deferred.promise.then\r\n\t\t\tresolve: promiseResolve,\r\n\t\t\treject: promiseReject,\r\n\t\t\t// TODO: Consider renaming progress() to notify()\r\n\t\t\tprogress: promiseProgress,\r\n\r\n\t\t\tpromise: promise,\r\n\r\n\t\t\tresolver: {\r\n\t\t\t\tresolve: promiseResolve,\r\n\t\t\t\treject: promiseReject,\r\n\t\t\t\tprogress: promiseProgress\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\thandlers = [];\r\n\t\tprogressHandlers = [];\r\n\r\n\t\t/**\r\n\t\t * Pre-resolution then() that adds the supplied callback, errback, and progback\r\n\t\t * functions to the registered listeners\r\n\t\t * @private\r\n\t\t *\r\n\t\t * @param {function?} [onFulfilled] resolution handler\r\n\t\t * @param {function?} [onRejected] rejection handler\r\n\t\t * @param {function?} [onProgress] progress handler\r\n\t\t */\r\n\t\t_then = function(onFulfilled, onRejected, onProgress) {\r\n\t\t\t// TODO: Promises/A+ check typeof onFulfilled, onRejected, onProgress\r\n\t\t\tvar deferred, progressHandler;\r\n\r\n\t\t\tdeferred = defer();\r\n\r\n\t\t\tprogressHandler = typeof onProgress === 'function'\r\n\t\t\t\t? function(update) {\r\n\t\t\t\t\ttry {\r\n\t\t\t\t\t\t// Allow progress handler to transform progress event\r\n\t\t\t\t\t\tdeferred.progress(onProgress(update));\r\n\t\t\t\t\t} catch(e) {\r\n\t\t\t\t\t\t// Use caught value as progress\r\n\t\t\t\t\t\tdeferred.progress(e);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t: function(update) { deferred.progress(update); };\r\n\r\n\t\t\thandlers.push(function(promise) {\r\n\t\t\t\tpromise.then(onFulfilled, onRejected)\r\n\t\t\t\t\t.then(deferred.resolve, deferred.reject, progressHandler);\r\n\t\t\t});\r\n\r\n\t\t\tprogressHandlers.push(progressHandler);\r\n\r\n\t\t\treturn deferred.promise;\r\n\t\t};\r\n\r\n\t\t/**\r\n\t\t * Issue a progress event, notifying all progress listeners\r\n\t\t * @private\r\n\t\t * @param {*} update progress event payload to pass to all listeners\r\n\t\t */\r\n\t\t_progress = function(update) {\r\n\t\t\tprocessQueue(progressHandlers, update);\r\n\t\t\treturn update;\r\n\t\t};\r\n\r\n\t\t/**\r\n\t\t * Transition from pre-resolution state to post-resolution state, notifying\r\n\t\t * all listeners of the resolution or rejection\r\n\t\t * @private\r\n\t\t * @param {*} value the value of this deferred\r\n\t\t */\r\n\t\t_resolve = function(value) {\r\n\t\t\tvalue = resolve(value);\r\n\r\n\t\t\t// Replace _then with one that directly notifies with the result.\r\n\t\t\t_then = value.then;\r\n\t\t\t// Replace _resolve so that this Deferred can only be resolved once\r\n\t\t\t_resolve = resolve;\r\n\t\t\t// Make _progress a noop, to disallow progress for the resolved promise.\r\n\t\t\t_progress = noop;\r\n\r\n\t\t\t// Notify handlers\r\n\t\t\tprocessQueue(handlers, value);\r\n\r\n\t\t\t// Free progressHandlers array since we'll never issue progress events\r\n\t\t\tprogressHandlers = handlers = undef;\r\n\r\n\t\t\treturn value;\r\n\t\t};\r\n\r\n\t\treturn deferred;\r\n\r\n\t\t/**\r\n\t\t * Wrapper to allow _then to be replaced safely\r\n\t\t * @param {function?} [onFulfilled] resolution handler\r\n\t\t * @param {function?} [onRejected] rejection handler\r\n\t\t * @param {function?} [onProgress] progress handler\r\n\t\t * @returns {Promise} new promise\r\n\t\t */\r\n\t\tfunction then(onFulfilled, onRejected, onProgress) {\r\n\t\t\t// TODO: Promises/A+ check typeof onFulfilled, onRejected, onProgress\r\n\t\t\treturn _then(onFulfilled, onRejected, onProgress);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Wrapper to allow _resolve to be replaced\r\n\t\t */\r\n\t\tfunction promiseResolve(val) {\r\n\t\t\treturn _resolve(val);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Wrapper to allow _reject to be replaced\r\n\t\t */\r\n\t\tfunction promiseReject(err) {\r\n\t\t\treturn _resolve(rejected(err));\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Wrapper to allow _progress to be replaced\r\n\t\t */\r\n\t\tfunction promiseProgress(update) {\r\n\t\t\treturn _progress(update);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Determines if promiseOrValue is a promise or not. Uses the feature\r\n\t * test from http://wiki.commonjs.org/wiki/Promises/A to determine if\r\n\t * promiseOrValue is a promise.\r\n\t *\r\n\t * @param {*} promiseOrValue anything\r\n\t * @returns {boolean} true if promiseOrValue is a {@link Promise}\r\n\t */\r\n\tfunction isPromise(promiseOrValue) {\r\n\t\treturn promiseOrValue && typeof promiseOrValue.then === 'function';\r\n\t}\r\n\r\n\t/**\r\n\t * Initiates a competitive race, returning a promise that will resolve when\r\n\t * howMany of the supplied promisesOrValues have resolved, or will reject when\r\n\t * it becomes impossible for howMany to resolve, for example, when\r\n\t * (promisesOrValues.length - howMany) + 1 input promises reject.\r\n\t *\r\n\t * @param {Array} promisesOrValues array of anything, may contain a mix\r\n\t * of promises and values\r\n\t * @param howMany {number} number of promisesOrValues to resolve\r\n\t * @param {function?} [onFulfilled] resolution handler\r\n\t * @param {function?} [onRejected] rejection handler\r\n\t * @param {function?} [onProgress] progress handler\r\n\t * @returns {Promise} promise that will resolve to an array of howMany values that\r\n\t * resolved first, or will reject with an array of (promisesOrValues.length - howMany) + 1\r\n\t * rejection reasons.\r\n\t */\r\n\tfunction some(promisesOrValues, howMany, onFulfilled, onRejected, onProgress) {\r\n\r\n\t\tcheckCallbacks(2, arguments);\r\n\r\n\t\treturn when(promisesOrValues, function(promisesOrValues) {\r\n\r\n\t\t\tvar toResolve, toReject, values, reasons, deferred, fulfillOne, rejectOne, progress, len, i;\r\n\r\n\t\t\tlen = promisesOrValues.length >>> 0;\r\n\r\n\t\t\ttoResolve = Math.max(0, Math.min(howMany, len));\r\n\t\t\tvalues = [];\r\n\r\n\t\t\ttoReject = (len - toResolve) + 1;\r\n\t\t\treasons = [];\r\n\r\n\t\t\tdeferred = defer();\r\n\r\n\t\t\t// No items in the input, resolve immediately\r\n\t\t\tif (!toResolve) {\r\n\t\t\t\tdeferred.resolve(values);\r\n\r\n\t\t\t} else {\r\n\t\t\t\tprogress = deferred.progress;\r\n\r\n\t\t\t\trejectOne = function(reason) {\r\n\t\t\t\t\treasons.push(reason);\r\n\t\t\t\t\tif(!--toReject) {\r\n\t\t\t\t\t\tfulfillOne = rejectOne = noop;\r\n\t\t\t\t\t\tdeferred.reject(reasons);\r\n\t\t\t\t\t}\r\n\t\t\t\t};\r\n\r\n\t\t\t\tfulfillOne = function(val) {\r\n\t\t\t\t\t// This orders the values based on promise resolution order\r\n\t\t\t\t\t// Another strategy would be to use the original position of\r\n\t\t\t\t\t// the corresponding promise.\r\n\t\t\t\t\tvalues.push(val);\r\n\r\n\t\t\t\t\tif (!--toResolve) {\r\n\t\t\t\t\t\tfulfillOne = rejectOne = noop;\r\n\t\t\t\t\t\tdeferred.resolve(values);\r\n\t\t\t\t\t}\r\n\t\t\t\t};\r\n\r\n\t\t\t\tfor(i = 0; i < len; ++i) {\r\n\t\t\t\t\tif(i in promisesOrValues) {\r\n\t\t\t\t\t\twhen(promisesOrValues[i], fulfiller, rejecter, progress);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\treturn deferred.then(onFulfilled, onRejected, onProgress);\r\n\r\n\t\t\tfunction rejecter(reason) {\r\n\t\t\t\trejectOne(reason);\r\n\t\t\t}\r\n\r\n\t\t\tfunction fulfiller(val) {\r\n\t\t\t\tfulfillOne(val);\r\n\t\t\t}\r\n\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Initiates a competitive race, returning a promise that will resolve when\r\n\t * any one of the supplied promisesOrValues has resolved or will reject when\r\n\t * *all* promisesOrValues have rejected.\r\n\t *\r\n\t * @param {Array|Promise} promisesOrValues array of anything, may contain a mix\r\n\t * of {@link Promise}s and values\r\n\t * @param {function?} [onFulfilled] resolution handler\r\n\t * @param {function?} [onRejected] rejection handler\r\n\t * @param {function?} [onProgress] progress handler\r\n\t * @returns {Promise} promise that will resolve to the value that resolved first, or\r\n\t * will reject with an array of all rejected inputs.\r\n\t */\r\n\tfunction any(promisesOrValues, onFulfilled, onRejected, onProgress) {\r\n\r\n\t\tfunction unwrapSingleResult(val) {\r\n\t\t\treturn onFulfilled ? onFulfilled(val[0]) : val[0];\r\n\t\t}\r\n\r\n\t\treturn some(promisesOrValues, 1, unwrapSingleResult, onRejected, onProgress);\r\n\t}\r\n\r\n\t/**\r\n\t * Return a promise that will resolve only once all the supplied promisesOrValues\r\n\t * have resolved. The resolution value of the returned promise will be an array\r\n\t * containing the resolution values of each of the promisesOrValues.\r\n\t * @memberOf when\r\n\t *\r\n\t * @param {Array|Promise} promisesOrValues array of anything, may contain a mix\r\n\t * of {@link Promise}s and values\r\n\t * @param {function?} [onFulfilled] resolution handler\r\n\t * @param {function?} [onRejected] rejection handler\r\n\t * @param {function?} [onProgress] progress handler\r\n\t * @returns {Promise}\r\n\t */\r\n\tfunction all(promisesOrValues, onFulfilled, onRejected, onProgress) {\r\n\t\tcheckCallbacks(1, arguments);\r\n\t\treturn map(promisesOrValues, identity).then(onFulfilled, onRejected, onProgress);\r\n\t}\r\n\r\n\t/**\r\n\t * Joins multiple promises into a single returned promise.\r\n\t * @returns {Promise} a promise that will fulfill when *all* the input promises\r\n\t * have fulfilled, or will reject when *any one* of the input promises rejects.\r\n\t */\r\n\tfunction join(/* ...promises */) {\r\n\t\treturn map(arguments, identity);\r\n\t}\r\n\r\n\t/**\r\n\t * Traditional map function, similar to `Array.prototype.map()`, but allows\r\n\t * input to contain {@link Promise}s and/or values, and mapFunc may return\r\n\t * either a value or a {@link Promise}\r\n\t *\r\n\t * @param {Array|Promise} promise array of anything, may contain a mix\r\n\t * of {@link Promise}s and values\r\n\t * @param {function} mapFunc mapping function mapFunc(value) which may return\r\n\t * either a {@link Promise} or value\r\n\t * @returns {Promise} a {@link Promise} that will resolve to an array containing\r\n\t * the mapped output values.\r\n\t */\r\n\tfunction map(promise, mapFunc) {\r\n\t\treturn when(promise, function(array) {\r\n\t\t\tvar results, len, toResolve, resolve, i, d;\r\n\r\n\t\t\t// Since we know the resulting length, we can preallocate the results\r\n\t\t\t// array to avoid array expansions.\r\n\t\t\ttoResolve = len = array.length >>> 0;\r\n\t\t\tresults = [];\r\n\t\t\td = defer();\r\n\r\n\t\t\tif(!toResolve) {\r\n\t\t\t\td.resolve(results);\r\n\t\t\t} else {\r\n\r\n\t\t\t\tresolve = function resolveOne(item, i) {\r\n\t\t\t\t\twhen(item, mapFunc).then(function(mapped) {\r\n\t\t\t\t\t\tresults[i] = mapped;\r\n\r\n\t\t\t\t\t\tif(!--toResolve) {\r\n\t\t\t\t\t\t\td.resolve(results);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}, d.reject);\r\n\t\t\t\t};\r\n\r\n\t\t\t\t// Since mapFunc may be async, get all invocations of it into flight\r\n\t\t\t\tfor(i = 0; i < len; i++) {\r\n\t\t\t\t\tif(i in array) {\r\n\t\t\t\t\t\tresolve(array[i], i);\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\t--toResolve;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\r\n\t\t\treturn d.promise;\r\n\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Traditional reduce function, similar to `Array.prototype.reduce()`, but\r\n\t * input may contain promises and/or values, and reduceFunc\r\n\t * may return either a value or a promise, *and* initialValue may\r\n\t * be a promise for the starting value.\r\n\t *\r\n\t * @param {Array|Promise} promise array or promise for an array of anything,\r\n\t * may contain a mix of promises and values.\r\n\t * @param {function} reduceFunc reduce function reduce(currentValue, nextValue, index, total),\r\n\t * where total is the total number of items being reduced, and will be the same\r\n\t * in each call to reduceFunc.\r\n\t * @returns {Promise} that will resolve to the final reduced value\r\n\t */\r\n\tfunction reduce(promise, reduceFunc /*, initialValue */) {\r\n\t\tvar args = slice.call(arguments, 1);\r\n\r\n\t\treturn when(promise, function(array) {\r\n\t\t\tvar total;\r\n\r\n\t\t\ttotal = array.length;\r\n\r\n\t\t\t// Wrap the supplied reduceFunc with one that handles promises and then\r\n\t\t\t// delegates to the supplied.\r\n\t\t\targs[0] = function (current, val, i) {\r\n\t\t\t\treturn when(current, function (c) {\r\n\t\t\t\t\treturn when(val, function (value) {\r\n\t\t\t\t\t\treturn reduceFunc(c, value, i, total);\r\n\t\t\t\t\t});\r\n\t\t\t\t});\r\n\t\t\t};\r\n\r\n\t\t\treturn reduceArray.apply(array, args);\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Ensure that resolution of promiseOrValue will trigger resolver with the\r\n\t * value or reason of promiseOrValue, or instead with resolveValue if it is provided.\r\n\t *\r\n\t * @param promiseOrValue\r\n\t * @param {Object} resolver\r\n\t * @param {function} resolver.resolve\r\n\t * @param {function} resolver.reject\r\n\t * @param {*} [resolveValue]\r\n\t * @returns {Promise}\r\n\t */\r\n\tfunction chain(promiseOrValue, resolver, resolveValue) {\r\n\t\tvar useResolveValue = arguments.length > 2;\r\n\r\n\t\treturn when(promiseOrValue,\r\n\t\t\tfunction(val) {\r\n\t\t\t\tval = useResolveValue ? resolveValue : val;\r\n\t\t\t\tresolver.resolve(val);\r\n\t\t\t\treturn val;\r\n\t\t\t},\r\n\t\t\tfunction(reason) {\r\n\t\t\t\tresolver.reject(reason);\r\n\t\t\t\treturn rejected(reason);\r\n\t\t\t},\r\n\t\t\tresolver.progress\r\n\t\t);\r\n\t}\r\n\r\n\t//\r\n\t// Utility functions\r\n\t//\r\n\r\n\t/**\r\n\t * Apply all functions in queue to value\r\n\t * @param {Array} queue array of functions to execute\r\n\t * @param {*} value argument passed to each function\r\n\t */\r\n\tfunction processQueue(queue, value) {\r\n\t\tvar handler, i = 0;\r\n\r\n\t\twhile (handler = queue[i++]) {\r\n\t\t\thandler(value);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Helper that checks arrayOfCallbacks to ensure that each element is either\r\n\t * a function, or null or undefined.\r\n\t * @private\r\n\t * @param {number} start index at which to start checking items in arrayOfCallbacks\r\n\t * @param {Array} arrayOfCallbacks array to check\r\n\t * @throws {Error} if any element of arrayOfCallbacks is something other than\r\n\t * a functions, null, or undefined.\r\n\t */\r\n\tfunction checkCallbacks(start, arrayOfCallbacks) {\r\n\t\t// TODO: Promises/A+ update type checking and docs\r\n\t\tvar arg, i = arrayOfCallbacks.length;\r\n\r\n\t\twhile(i > start) {\r\n\t\t\targ = arrayOfCallbacks[--i];\r\n\r\n\t\t\tif (arg != null && typeof arg != 'function') {\r\n\t\t\t\tthrow new Error('arg '+i+' must be a function');\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * No-Op function used in method replacement\r\n\t * @private\r\n\t */\r\n\tfunction noop() {}\r\n\r\n\tslice = [].slice;\r\n\r\n\t// ES5 reduce implementation if native not available\r\n\t// See: http://es5.github.com/#x15.4.4.21 as there are many\r\n\t// specifics and edge cases.\r\n\treduceArray = [].reduce ||\r\n\t\tfunction(reduceFunc /*, initialValue */) {\r\n\t\t\t/*jshint maxcomplexity: 7*/\r\n\r\n\t\t\t// ES5 dictates that reduce.length === 1\r\n\r\n\t\t\t// This implementation deviates from ES5 spec in the following ways:\r\n\t\t\t// 1. It does not check if reduceFunc is a Callable\r\n\r\n\t\t\tvar arr, args, reduced, len, i;\r\n\r\n\t\t\ti = 0;\r\n\t\t\t// This generates a jshint warning, despite being valid\r\n\t\t\t// \"Missing 'new' prefix when invoking a constructor.\"\r\n\t\t\t// See https://github.com/jshint/jshint/issues/392\r\n\t\t\tarr = Object(this);\r\n\t\t\tlen = arr.length >>> 0;\r\n\t\t\targs = arguments;\r\n\r\n\t\t\t// If no initialValue, use first item of array (we know length !== 0 here)\r\n\t\t\t// and adjust i to start at second item\r\n\t\t\tif(args.length <= 1) {\r\n\t\t\t\t// Skip to the first real element in the array\r\n\t\t\t\tfor(;;) {\r\n\t\t\t\t\tif(i in arr) {\r\n\t\t\t\t\t\treduced = arr[i++];\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// If we reached the end of the array without finding any real\r\n\t\t\t\t\t// elements, it's a TypeError\r\n\t\t\t\t\tif(++i >= len) {\r\n\t\t\t\t\t\tthrow new TypeError();\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\t// If initialValue provided, use it\r\n\t\t\t\treduced = args[1];\r\n\t\t\t}\r\n\r\n\t\t\t// Do the actual reduce\r\n\t\t\tfor(;i < len; ++i) {\r\n\t\t\t\t// Skip holes\r\n\t\t\t\tif(i in arr) {\r\n\t\t\t\t\treduced = reduceFunc(reduced, arr[i], i, arr);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\treturn reduced;\r\n\t\t};\r\n\r\n\tfunction identity(x) {\r\n\t\treturn x;\r\n\t}\r\n\r\nexport default when;\r\n","import defaultValue from \"./defaultValue.js\";\r\n\r\n/**\r\n * Clones an object, returning a new object containing the same properties.\r\n *\r\n * @function\r\n *\r\n * @param {Object} object The object to clone.\r\n * @param {Boolean} [deep=false] If true, all properties will be deep cloned recursively.\r\n * @returns {Object} The cloned object.\r\n */\r\nfunction clone(object, deep) {\r\n if (object === null || typeof object !== \"object\") {\r\n return object;\r\n }\r\n\r\n deep = defaultValue(deep, false);\r\n\r\n var result = new object.constructor();\r\n for (var propertyName in object) {\r\n if (object.hasOwnProperty(propertyName)) {\r\n var value = object[propertyName];\r\n if (deep) {\r\n value = clone(value, deep);\r\n }\r\n result[propertyName] = value;\r\n }\r\n }\r\n\r\n return result;\r\n}\r\nexport default clone;\r\n","import defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\n\r\n/**\r\n * Merges two objects, copying their properties onto a new combined object. When two objects have the same\r\n * property, the value of the property on the first object is used. If either object is undefined,\r\n * it will be treated as an empty object.\r\n *\r\n * @example\r\n * var object1 = {\r\n * propOne : 1,\r\n * propTwo : {\r\n * value1 : 10\r\n * }\r\n * }\r\n * var object2 = {\r\n * propTwo : 2\r\n * }\r\n * var final = Cesium.combine(object1, object2);\r\n *\r\n * // final === {\r\n * // propOne : 1,\r\n * // propTwo : {\r\n * // value1 : 10\r\n * // }\r\n * // }\r\n *\r\n * @param {Object} [object1] The first object to merge.\r\n * @param {Object} [object2] The second object to merge.\r\n * @param {Boolean} [deep=false] Perform a recursive merge.\r\n * @returns {Object} The combined object containing all properties from both objects.\r\n *\r\n * @function\r\n */\r\nfunction combine(object1, object2, deep) {\r\n deep = defaultValue(deep, false);\r\n\r\n var result = {};\r\n\r\n var object1Defined = defined(object1);\r\n var object2Defined = defined(object2);\r\n var property;\r\n var object1Value;\r\n var object2Value;\r\n if (object1Defined) {\r\n for (property in object1) {\r\n if (object1.hasOwnProperty(property)) {\r\n object1Value = object1[property];\r\n if (\r\n object2Defined &&\r\n deep &&\r\n typeof object1Value === \"object\" &&\r\n object2.hasOwnProperty(property)\r\n ) {\r\n object2Value = object2[property];\r\n if (typeof object2Value === \"object\") {\r\n result[property] = combine(object1Value, object2Value, deep);\r\n } else {\r\n result[property] = object1Value;\r\n }\r\n } else {\r\n result[property] = object1Value;\r\n }\r\n }\r\n }\r\n }\r\n if (object2Defined) {\r\n for (property in object2) {\r\n if (\r\n object2.hasOwnProperty(property) &&\r\n !result.hasOwnProperty(property)\r\n ) {\r\n object2Value = object2[property];\r\n result[property] = object2Value;\r\n }\r\n }\r\n }\r\n return result;\r\n}\r\nexport default combine;\r\n","import Uri from \"../ThirdParty/Uri.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\n\r\n/**\r\n * Given a URI, returns the base path of the URI.\r\n * @function\r\n *\r\n * @param {String} uri The Uri.\r\n * @param {Boolean} [includeQuery = false] Whether or not to include the query string and fragment form the uri\r\n * @returns {String} The base path of the Uri.\r\n *\r\n * @example\r\n * // basePath will be \"/Gallery/\";\r\n * var basePath = Cesium.getBaseUri('/Gallery/simple.czml?value=true&example=false');\r\n *\r\n * // basePath will be \"/Gallery/?value=true&example=false\";\r\n * var basePath = Cesium.getBaseUri('/Gallery/simple.czml?value=true&example=false', true);\r\n */\r\nfunction getBaseUri(uri, includeQuery) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(uri)) {\r\n throw new DeveloperError(\"uri is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var basePath = \"\";\r\n var i = uri.lastIndexOf(\"/\");\r\n if (i !== -1) {\r\n basePath = uri.substring(0, i + 1);\r\n }\r\n\r\n if (!includeQuery) {\r\n return basePath;\r\n }\r\n\r\n uri = new Uri(uri);\r\n if (defined(uri.query)) {\r\n basePath += \"?\" + uri.query;\r\n }\r\n if (defined(uri.fragment)) {\r\n basePath += \"#\" + uri.fragment;\r\n }\r\n\r\n return basePath;\r\n}\r\nexport default getBaseUri;\r\n","import Uri from \"../ThirdParty/Uri.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\n\r\n/**\r\n * Given a URI, returns the extension of the URI.\r\n * @function getExtensionFromUri\r\n *\r\n * @param {String} uri The Uri.\r\n * @returns {String} The extension of the Uri.\r\n *\r\n * @example\r\n * //extension will be \"czml\";\r\n * var extension = Cesium.getExtensionFromUri('/Gallery/simple.czml?value=true&example=false');\r\n */\r\nfunction getExtensionFromUri(uri) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(uri)) {\r\n throw new DeveloperError(\"uri is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var uriObject = new Uri(uri);\r\n uriObject.normalize();\r\n var path = uriObject.path;\r\n var index = path.lastIndexOf(\"/\");\r\n if (index !== -1) {\r\n path = path.substr(index + 1);\r\n }\r\n index = path.lastIndexOf(\".\");\r\n if (index === -1) {\r\n path = \"\";\r\n } else {\r\n path = path.substr(index + 1);\r\n }\r\n return path;\r\n}\r\nexport default getExtensionFromUri;\r\n","import Check from \"./Check.js\";\r\n\r\nvar blobUriRegex = /^blob:/i;\r\n\r\n/**\r\n * Determines if the specified uri is a blob uri.\r\n *\r\n * @function isBlobUri\r\n *\r\n * @param {String} uri The uri to test.\r\n * @returns {Boolean} true when the uri is a blob uri; otherwise, false.\r\n *\r\n * @private\r\n */\r\nfunction isBlobUri(uri) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.string(\"uri\", uri);\r\n //>>includeEnd('debug');\r\n\r\n return blobUriRegex.test(uri);\r\n}\r\nexport default isBlobUri;\r\n","import defined from \"./defined.js\";\r\n\r\nvar a;\r\n\r\n/**\r\n * Given a URL, determine whether that URL is considered cross-origin to the current page.\r\n *\r\n * @private\r\n */\r\nfunction isCrossOriginUrl(url) {\r\n if (!defined(a)) {\r\n a = document.createElement(\"a\");\r\n }\r\n\r\n // copy window location into the anchor to get consistent results\r\n // when the port is default for the protocol (e.g. 80 for HTTP)\r\n a.href = window.location.href;\r\n\r\n // host includes both hostname and port if the port is not standard\r\n var host = a.host;\r\n var protocol = a.protocol;\r\n\r\n a.href = url;\r\n // IE only absolutizes href on get, not set\r\n // eslint-disable-next-line no-self-assign\r\n a.href = a.href;\r\n\r\n return protocol !== a.protocol || host !== a.host;\r\n}\r\nexport default isCrossOriginUrl;\r\n","import Check from \"./Check.js\";\r\n\r\nvar dataUriRegex = /^data:/i;\r\n\r\n/**\r\n * Determines if the specified uri is a data uri.\r\n *\r\n * @function isDataUri\r\n *\r\n * @param {String} uri The uri to test.\r\n * @returns {Boolean} true when the uri is a data uri; otherwise, false.\r\n *\r\n * @private\r\n */\r\nfunction isDataUri(uri) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.string(\"uri\", uri);\r\n //>>includeEnd('debug');\r\n\r\n return dataUriRegex.test(uri);\r\n}\r\nexport default isDataUri;\r\n","import when from \"../ThirdParty/when.js\";\r\n\r\n/**\r\n * @private\r\n */\r\nfunction loadAndExecuteScript(url) {\r\n var deferred = when.defer();\r\n var script = document.createElement(\"script\");\r\n script.async = true;\r\n script.src = url;\r\n\r\n var head = document.getElementsByTagName(\"head\")[0];\r\n script.onload = function () {\r\n script.onload = undefined;\r\n head.removeChild(script);\r\n deferred.resolve();\r\n };\r\n script.onerror = function (e) {\r\n deferred.reject(e);\r\n };\r\n\r\n head.appendChild(script);\r\n\r\n return deferred.promise;\r\n}\r\nexport default loadAndExecuteScript;\r\n","import defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\n\r\n/**\r\n * Converts an object representing a set of name/value pairs into a query string,\r\n * with names and values encoded properly for use in a URL. Values that are arrays\r\n * will produce multiple values with the same name.\r\n * @function objectToQuery\r\n *\r\n * @param {Object} obj The object containing data to encode.\r\n * @returns {String} An encoded query string.\r\n *\r\n *\r\n * @example\r\n * var str = Cesium.objectToQuery({\r\n * key1 : 'some value',\r\n * key2 : 'a/b',\r\n * key3 : ['x', 'y']\r\n * });\r\n *\r\n * @see queryToObject\r\n * // str will be:\r\n * // 'key1=some%20value&key2=a%2Fb&key3=x&key3=y'\r\n */\r\nfunction objectToQuery(obj) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(obj)) {\r\n throw new DeveloperError(\"obj is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var result = \"\";\r\n for (var propName in obj) {\r\n if (obj.hasOwnProperty(propName)) {\r\n var value = obj[propName];\r\n\r\n var part = encodeURIComponent(propName) + \"=\";\r\n if (Array.isArray(value)) {\r\n for (var i = 0, len = value.length; i < len; ++i) {\r\n result += part + encodeURIComponent(value[i]) + \"&\";\r\n }\r\n } else {\r\n result += part + encodeURIComponent(value) + \"&\";\r\n }\r\n }\r\n }\r\n\r\n // trim last &\r\n result = result.slice(0, -1);\r\n\r\n // This function used to replace %20 with + which is more compact and readable.\r\n // However, some servers didn't properly handle + as a space.\r\n // https://github.com/CesiumGS/cesium/issues/2192\r\n\r\n return result;\r\n}\r\nexport default objectToQuery;\r\n","import defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\n\r\n/**\r\n * Parses a query string into an object, where the keys and values of the object are the\r\n * name/value pairs from the query string, decoded. If a name appears multiple times,\r\n * the value in the object will be an array of values.\r\n * @function queryToObject\r\n *\r\n * @param {String} queryString The query string.\r\n * @returns {Object} An object containing the parameters parsed from the query string.\r\n *\r\n *\r\n * @example\r\n * var obj = Cesium.queryToObject('key1=some%20value&key2=a%2Fb&key3=x&key3=y');\r\n * // obj will be:\r\n * // {\r\n * // key1 : 'some value',\r\n * // key2 : 'a/b',\r\n * // key3 : ['x', 'y']\r\n * // }\r\n *\r\n * @see objectToQuery\r\n */\r\nfunction queryToObject(queryString) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(queryString)) {\r\n throw new DeveloperError(\"queryString is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var result = {};\r\n if (queryString === \"\") {\r\n return result;\r\n }\r\n var parts = queryString.replace(/\\+/g, \"%20\").split(/[&;]/);\r\n for (var i = 0, len = parts.length; i < len; ++i) {\r\n var subparts = parts[i].split(\"=\");\r\n\r\n var name = decodeURIComponent(subparts[0]);\r\n var value = subparts[1];\r\n if (defined(value)) {\r\n value = decodeURIComponent(value);\r\n } else {\r\n value = \"\";\r\n }\r\n\r\n var resultValue = result[name];\r\n if (typeof resultValue === \"string\") {\r\n // expand the single value to an array\r\n result[name] = [resultValue, value];\r\n } else if (Array.isArray(resultValue)) {\r\n resultValue.push(value);\r\n } else {\r\n result[name] = value;\r\n }\r\n }\r\n return result;\r\n}\r\nexport default queryToObject;\r\n","/**\r\n * State of the request.\r\n *\r\n * @enum {Number}\r\n */\r\nvar RequestState = {\r\n /**\r\n * Initial unissued state.\r\n *\r\n * @type Number\r\n * @constant\r\n */\r\n UNISSUED: 0,\r\n\r\n /**\r\n * Issued but not yet active. Will become active when open slots are available.\r\n *\r\n * @type Number\r\n * @constant\r\n */\r\n ISSUED: 1,\r\n\r\n /**\r\n * Actual http request has been sent.\r\n *\r\n * @type Number\r\n * @constant\r\n */\r\n ACTIVE: 2,\r\n\r\n /**\r\n * Request completed successfully.\r\n *\r\n * @type Number\r\n * @constant\r\n */\r\n RECEIVED: 3,\r\n\r\n /**\r\n * Request was cancelled, either explicitly or automatically because of low priority.\r\n *\r\n * @type Number\r\n * @constant\r\n */\r\n CANCELLED: 4,\r\n\r\n /**\r\n * Request failed.\r\n *\r\n * @type Number\r\n * @constant\r\n */\r\n FAILED: 5,\r\n};\r\nexport default Object.freeze(RequestState);\r\n","/**\r\n * An enum identifying the type of request. Used for finer grained logging and priority sorting.\r\n *\r\n * @enum {Number}\r\n */\r\nvar RequestType = {\r\n /**\r\n * Terrain request.\r\n *\r\n * @type Number\r\n * @constant\r\n */\r\n TERRAIN: 0,\r\n\r\n /**\r\n * Imagery request.\r\n *\r\n * @type Number\r\n * @constant\r\n */\r\n IMAGERY: 1,\r\n\r\n /**\r\n * 3D Tiles request.\r\n *\r\n * @type Number\r\n * @constant\r\n */\r\n TILES3D: 2,\r\n\r\n /**\r\n * Other request.\r\n *\r\n * @type Number\r\n * @constant\r\n */\r\n OTHER: 3,\r\n};\r\nexport default Object.freeze(RequestType);\r\n","import defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport RequestState from \"./RequestState.js\";\r\nimport RequestType from \"./RequestType.js\";\r\n\r\n/**\r\n * Stores information for making a request. In general this does not need to be constructed directly.\r\n *\r\n * @alias Request\r\n * @constructor\r\n\r\n * @param {Object} [options] An object with the following properties:\r\n * @param {String} [options.url] The url to request.\r\n * @param {Request.RequestCallback} [options.requestFunction] The function that makes the actual data request.\r\n * @param {Request.CancelCallback} [options.cancelFunction] The function that is called when the request is cancelled.\r\n * @param {Request.PriorityCallback} [options.priorityFunction] The function that is called to update the request's priority, which occurs once per frame.\r\n * @param {Number} [options.priority=0.0] The initial priority of the request.\r\n * @param {Boolean} [options.throttle=false] Whether to throttle and prioritize the request. If false, the request will be sent immediately. If true, the request will be throttled and sent based on priority.\r\n * @param {Boolean} [options.throttleByServer=false] Whether to throttle the request by server.\r\n * @param {RequestType} [options.type=RequestType.OTHER] The type of request.\r\n */\r\nfunction Request(options) {\r\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\r\n\r\n var throttleByServer = defaultValue(options.throttleByServer, false);\r\n var throttle = defaultValue(options.throttle, false);\r\n\r\n /**\r\n * The URL to request.\r\n *\r\n * @type {String}\r\n */\r\n this.url = options.url;\r\n\r\n /**\r\n * The function that makes the actual data request.\r\n *\r\n * @type {Request.RequestCallback}\r\n */\r\n this.requestFunction = options.requestFunction;\r\n\r\n /**\r\n * The function that is called when the request is cancelled.\r\n *\r\n * @type {Request.CancelCallback}\r\n */\r\n this.cancelFunction = options.cancelFunction;\r\n\r\n /**\r\n * The function that is called to update the request's priority, which occurs once per frame.\r\n *\r\n * @type {Request.PriorityCallback}\r\n */\r\n this.priorityFunction = options.priorityFunction;\r\n\r\n /**\r\n * Priority is a unit-less value where lower values represent higher priority.\r\n * For world-based objects, this is usually the distance from the camera.\r\n * A request that does not have a priority function defaults to a priority of 0.\r\n *\r\n * If priorityFunction is defined, this value is updated every frame with the result of that call.\r\n *\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.priority = defaultValue(options.priority, 0.0);\r\n\r\n /**\r\n * Whether to throttle and prioritize the request. If false, the request will be sent immediately. If true, the\r\n * request will be throttled and sent based on priority.\r\n *\r\n * @type {Boolean}\r\n * @readonly\r\n *\r\n * @default false\r\n */\r\n this.throttle = throttle;\r\n\r\n /**\r\n * Whether to throttle the request by server. Browsers typically support about 6-8 parallel connections\r\n * for HTTP/1 servers, and an unlimited amount of connections for HTTP/2 servers. Setting this value\r\n * to true
is preferable for requests going through HTTP/1 servers.\r\n *\r\n * @type {Boolean}\r\n * @readonly\r\n *\r\n * @default false\r\n */\r\n this.throttleByServer = throttleByServer;\r\n\r\n /**\r\n * Type of request.\r\n *\r\n * @type {RequestType}\r\n * @readonly\r\n *\r\n * @default RequestType.OTHER\r\n */\r\n this.type = defaultValue(options.type, RequestType.OTHER);\r\n\r\n /**\r\n * A key used to identify the server that a request is going to. It is derived from the url's authority and scheme.\r\n *\r\n * @type {String}\r\n *\r\n * @private\r\n */\r\n this.serverKey = undefined;\r\n\r\n /**\r\n * The current state of the request.\r\n *\r\n * @type {RequestState}\r\n * @readonly\r\n */\r\n this.state = RequestState.UNISSUED;\r\n\r\n /**\r\n * The requests's deferred promise.\r\n *\r\n * @type {Object}\r\n *\r\n * @private\r\n */\r\n this.deferred = undefined;\r\n\r\n /**\r\n * Whether the request was explicitly cancelled.\r\n *\r\n * @type {Boolean}\r\n *\r\n * @private\r\n */\r\n this.cancelled = false;\r\n}\r\n\r\n/**\r\n * Mark the request as cancelled.\r\n *\r\n * @private\r\n */\r\nRequest.prototype.cancel = function () {\r\n this.cancelled = true;\r\n};\r\n\r\n/**\r\n * Duplicates a Request instance.\r\n *\r\n * @param {Request} [result] The object onto which to store the result.\r\n *\r\n * @returns {Request} The modified result parameter or a new Resource instance if one was not provided.\r\n */\r\nRequest.prototype.clone = function (result) {\r\n if (!defined(result)) {\r\n return new Request(this);\r\n }\r\n\r\n result.url = this.url;\r\n result.requestFunction = this.requestFunction;\r\n result.cancelFunction = this.cancelFunction;\r\n result.priorityFunction = this.priorityFunction;\r\n result.priority = this.priority;\r\n result.throttle = this.throttle;\r\n result.throttleByServer = this.throttleByServer;\r\n result.type = this.type;\r\n result.serverKey = this.serverKey;\r\n\r\n // These get defaulted because the cloned request hasn't been issued\r\n result.state = this.RequestState.UNISSUED;\r\n result.deferred = undefined;\r\n result.cancelled = false;\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * The function that makes the actual data request.\r\n * @callback Request.RequestCallback\r\n * @returns {Promise} A promise for the requested data.\r\n */\r\n\r\n/**\r\n * The function that is called when the request is cancelled.\r\n * @callback Request.CancelCallback\r\n */\r\n\r\n/**\r\n * The function that is called to update the request's priority, which occurs once per frame.\r\n * @callback Request.PriorityCallback\r\n * @returns {Number} The updated priority value.\r\n */\r\nexport default Request;\r\n","/**\r\n * Parses the result of XMLHttpRequest's getAllResponseHeaders() method into\r\n * a dictionary.\r\n *\r\n * @function parseResponseHeaders\r\n *\r\n * @param {String} headerString The header string returned by getAllResponseHeaders(). The format is\r\n * described here: http://www.w3.org/TR/XMLHttpRequest/#the-getallresponseheaders()-method\r\n * @returns {Object} A dictionary of key/value pairs, where each key is the name of a header and the corresponding value\r\n * is that header's value.\r\n *\r\n * @private\r\n */\r\nfunction parseResponseHeaders(headerString) {\r\n var headers = {};\r\n\r\n if (!headerString) {\r\n return headers;\r\n }\r\n\r\n var headerPairs = headerString.split(\"\\u000d\\u000a\");\r\n\r\n for (var i = 0; i < headerPairs.length; ++i) {\r\n var headerPair = headerPairs[i];\r\n // Can't use split() here because it does the wrong thing\r\n // if the header value has the string \": \" in it.\r\n var index = headerPair.indexOf(\"\\u003a\\u0020\");\r\n if (index > 0) {\r\n var key = headerPair.substring(0, index);\r\n var val = headerPair.substring(index + 2);\r\n headers[key] = val;\r\n }\r\n }\r\n\r\n return headers;\r\n}\r\nexport default parseResponseHeaders;\r\n","import defined from \"./defined.js\";\r\nimport parseResponseHeaders from \"./parseResponseHeaders.js\";\r\n\r\n/**\r\n * An event that is raised when a request encounters an error.\r\n *\r\n * @constructor\r\n * @alias RequestErrorEvent\r\n *\r\n * @param {Number} [statusCode] The HTTP error status code, such as 404.\r\n * @param {Object} [response] The response included along with the error.\r\n * @param {String|Object} [responseHeaders] The response headers, represented either as an object literal or as a\r\n * string in the format returned by XMLHttpRequest's getAllResponseHeaders() function.\r\n */\r\nfunction RequestErrorEvent(statusCode, response, responseHeaders) {\r\n /**\r\n * The HTTP error status code, such as 404. If the error does not have a particular\r\n * HTTP code, this property will be undefined.\r\n *\r\n * @type {Number}\r\n */\r\n this.statusCode = statusCode;\r\n\r\n /**\r\n * The response included along with the error. If the error does not include a response,\r\n * this property will be undefined.\r\n *\r\n * @type {Object}\r\n */\r\n this.response = response;\r\n\r\n /**\r\n * The headers included in the response, represented as an object literal of key/value pairs.\r\n * If the error does not include any headers, this property will be undefined.\r\n *\r\n * @type {Object}\r\n */\r\n this.responseHeaders = responseHeaders;\r\n\r\n if (typeof this.responseHeaders === \"string\") {\r\n this.responseHeaders = parseResponseHeaders(this.responseHeaders);\r\n }\r\n}\r\n\r\n/**\r\n * Creates a string representing this RequestErrorEvent.\r\n * @memberof RequestErrorEvent\r\n *\r\n * @returns {String} A string representing the provided RequestErrorEvent.\r\n */\r\nRequestErrorEvent.prototype.toString = function () {\r\n var str = \"Request has failed.\";\r\n if (defined(this.statusCode)) {\r\n str += \" Status Code: \" + this.statusCode;\r\n }\r\n return str;\r\n};\r\nexport default RequestErrorEvent;\r\n","import Check from \"./Check.js\";\r\nimport defined from \"./defined.js\";\r\n\r\n/**\r\n * A generic utility class for managing subscribers for a particular event.\r\n * This class is usually instantiated inside of a container class and\r\n * exposed as a property for others to subscribe to.\r\n *\r\n * @alias Event\r\n * @constructor\r\n * @example\r\n * MyObject.prototype.myListener = function(arg1, arg2) {\r\n * this.myArg1Copy = arg1;\r\n * this.myArg2Copy = arg2;\r\n * }\r\n *\r\n * var myObjectInstance = new MyObject();\r\n * var evt = new Cesium.Event();\r\n * evt.addEventListener(MyObject.prototype.myListener, myObjectInstance);\r\n * evt.raiseEvent('1', '2');\r\n * evt.removeEventListener(MyObject.prototype.myListener);\r\n */\r\nfunction Event() {\r\n this._listeners = [];\r\n this._scopes = [];\r\n this._toRemove = [];\r\n this._insideRaiseEvent = false;\r\n}\r\n\r\nObject.defineProperties(Event.prototype, {\r\n /**\r\n * The number of listeners currently subscribed to the event.\r\n * @memberof Event.prototype\r\n * @type {Number}\r\n * @readonly\r\n */\r\n numberOfListeners: {\r\n get: function () {\r\n return this._listeners.length - this._toRemove.length;\r\n },\r\n },\r\n});\r\n\r\n/**\r\n * Registers a callback function to be executed whenever the event is raised.\r\n * An optional scope can be provided to serve as the this
pointer\r\n * in which the function will execute.\r\n *\r\n * @param {Function} listener The function to be executed when the event is raised.\r\n * @param {Object} [scope] An optional object scope to serve as the this
\r\n * pointer in which the listener function will execute.\r\n * @returns {Event.RemoveCallback} A function that will remove this event listener when invoked.\r\n *\r\n * @see Event#raiseEvent\r\n * @see Event#removeEventListener\r\n */\r\nEvent.prototype.addEventListener = function (listener, scope) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.func(\"listener\", listener);\r\n //>>includeEnd('debug');\r\n\r\n this._listeners.push(listener);\r\n this._scopes.push(scope);\r\n\r\n var event = this;\r\n return function () {\r\n event.removeEventListener(listener, scope);\r\n };\r\n};\r\n\r\n/**\r\n * Unregisters a previously registered callback.\r\n *\r\n * @param {Function} listener The function to be unregistered.\r\n * @param {Object} [scope] The scope that was originally passed to addEventListener.\r\n * @returns {Boolean} true
if the listener was removed; false
if the listener and scope are not registered with the event.\r\n *\r\n * @see Event#addEventListener\r\n * @see Event#raiseEvent\r\n */\r\nEvent.prototype.removeEventListener = function (listener, scope) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.func(\"listener\", listener);\r\n //>>includeEnd('debug');\r\n\r\n var listeners = this._listeners;\r\n var scopes = this._scopes;\r\n\r\n var index = -1;\r\n for (var i = 0; i < listeners.length; i++) {\r\n if (listeners[i] === listener && scopes[i] === scope) {\r\n index = i;\r\n break;\r\n }\r\n }\r\n\r\n if (index !== -1) {\r\n if (this._insideRaiseEvent) {\r\n //In order to allow removing an event subscription from within\r\n //a callback, we don't actually remove the items here. Instead\r\n //remember the index they are at and undefined their value.\r\n this._toRemove.push(index);\r\n listeners[index] = undefined;\r\n scopes[index] = undefined;\r\n } else {\r\n listeners.splice(index, 1);\r\n scopes.splice(index, 1);\r\n }\r\n return true;\r\n }\r\n\r\n return false;\r\n};\r\n\r\nfunction compareNumber(a, b) {\r\n return b - a;\r\n}\r\n\r\n/**\r\n * Raises the event by calling each registered listener with all supplied arguments.\r\n *\r\n * @param {...Object} arguments This method takes any number of parameters and passes them through to the listener functions.\r\n *\r\n * @see Event#addEventListener\r\n * @see Event#removeEventListener\r\n */\r\nEvent.prototype.raiseEvent = function () {\r\n this._insideRaiseEvent = true;\r\n\r\n var i;\r\n var listeners = this._listeners;\r\n var scopes = this._scopes;\r\n var length = listeners.length;\r\n\r\n for (i = 0; i < length; i++) {\r\n var listener = listeners[i];\r\n if (defined(listener)) {\r\n listeners[i].apply(scopes[i], arguments);\r\n }\r\n }\r\n\r\n //Actually remove items removed in removeEventListener.\r\n var toRemove = this._toRemove;\r\n length = toRemove.length;\r\n if (length > 0) {\r\n toRemove.sort(compareNumber);\r\n for (i = 0; i < length; i++) {\r\n var index = toRemove[i];\r\n listeners.splice(index, 1);\r\n scopes.splice(index, 1);\r\n }\r\n toRemove.length = 0;\r\n }\r\n\r\n this._insideRaiseEvent = false;\r\n};\r\n\r\n/**\r\n * A function that removes a listener.\r\n * @callback Event.RemoveCallback\r\n */\r\nexport default Event;\r\n","import Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\n\r\n/**\r\n * Array implementation of a heap.\r\n *\r\n * @alias Heap\r\n * @constructor\r\n * @private\r\n *\r\n * @param {Object} options Object with the following properties:\r\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.\r\n */\r\nfunction Heap(options) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"options\", options);\r\n Check.defined(\"options.comparator\", options.comparator);\r\n //>>includeEnd('debug');\r\n\r\n this._comparator = options.comparator;\r\n this._array = [];\r\n this._length = 0;\r\n this._maximumLength = undefined;\r\n}\r\n\r\nObject.defineProperties(Heap.prototype, {\r\n /**\r\n * Gets the length of the heap.\r\n *\r\n * @memberof Heap.prototype\r\n *\r\n * @type {Number}\r\n * @readonly\r\n */\r\n length: {\r\n get: function () {\r\n return this._length;\r\n },\r\n },\r\n\r\n /**\r\n * Gets the internal array.\r\n *\r\n * @memberof Heap.prototype\r\n *\r\n * @type {Array}\r\n * @readonly\r\n */\r\n internalArray: {\r\n get: function () {\r\n return this._array;\r\n },\r\n },\r\n\r\n /**\r\n * Gets and sets the maximum length of the heap.\r\n *\r\n * @memberof Heap.prototype\r\n *\r\n * @type {Number}\r\n */\r\n maximumLength: {\r\n get: function () {\r\n return this._maximumLength;\r\n },\r\n set: function (value) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number.greaterThanOrEquals(\"maximumLength\", value, 0);\r\n //>>includeEnd('debug');\r\n var originalLength = this._length;\r\n if (value < originalLength) {\r\n var array = this._array;\r\n // Remove trailing references\r\n for (var i = value; i < originalLength; ++i) {\r\n array[i] = undefined;\r\n }\r\n this._length = value;\r\n array.length = value;\r\n }\r\n this._maximumLength = value;\r\n },\r\n },\r\n\r\n /**\r\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.\r\n *\r\n * @memberof Heap.prototype\r\n *\r\n * @type {Heap.ComparatorCallback}\r\n */\r\n comparator: {\r\n get: function () {\r\n return this._comparator;\r\n },\r\n },\r\n});\r\n\r\nfunction swap(array, a, b) {\r\n var temp = array[a];\r\n array[a] = array[b];\r\n array[b] = temp;\r\n}\r\n\r\n/**\r\n * Resizes the internal array of the heap.\r\n *\r\n * @param {Number} [length] The length to resize internal array to. Defaults to the current length of the heap.\r\n */\r\nHeap.prototype.reserve = function (length) {\r\n length = defaultValue(length, this._length);\r\n this._array.length = length;\r\n};\r\n\r\n/**\r\n * Update the heap so that index and all descendants satisfy the heap property.\r\n *\r\n * @param {Number} [index=0] The starting index to heapify from.\r\n */\r\nHeap.prototype.heapify = function (index) {\r\n index = defaultValue(index, 0);\r\n var length = this._length;\r\n var comparator = this._comparator;\r\n var array = this._array;\r\n var candidate = -1;\r\n var inserting = true;\r\n\r\n while (inserting) {\r\n var right = 2 * (index + 1);\r\n var left = right - 1;\r\n\r\n if (left < length && comparator(array[left], array[index]) < 0) {\r\n candidate = left;\r\n } else {\r\n candidate = index;\r\n }\r\n\r\n if (right < length && comparator(array[right], array[candidate]) < 0) {\r\n candidate = right;\r\n }\r\n if (candidate !== index) {\r\n swap(array, candidate, index);\r\n index = candidate;\r\n } else {\r\n inserting = false;\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Resort the heap.\r\n */\r\nHeap.prototype.resort = function () {\r\n var length = this._length;\r\n for (var i = Math.ceil(length / 2); i >= 0; --i) {\r\n this.heapify(i);\r\n }\r\n};\r\n\r\n/**\r\n * Insert an element into the heap. If the length would grow greater than maximumLength\r\n * of the heap, extra elements are removed.\r\n *\r\n * @param {*} element The element to insert\r\n *\r\n * @return {*} The element that was removed from the heap if the heap is at full capacity.\r\n */\r\nHeap.prototype.insert = function (element) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"element\", element);\r\n //>>includeEnd('debug');\r\n\r\n var array = this._array;\r\n var comparator = this._comparator;\r\n var maximumLength = this._maximumLength;\r\n\r\n var index = this._length++;\r\n if (index < array.length) {\r\n array[index] = element;\r\n } else {\r\n array.push(element);\r\n }\r\n\r\n while (index !== 0) {\r\n var parent = Math.floor((index - 1) / 2);\r\n if (comparator(array[index], array[parent]) < 0) {\r\n swap(array, index, parent);\r\n index = parent;\r\n } else {\r\n break;\r\n }\r\n }\r\n\r\n var removedElement;\r\n\r\n if (defined(maximumLength) && this._length > maximumLength) {\r\n removedElement = array[maximumLength];\r\n this._length = maximumLength;\r\n }\r\n\r\n return removedElement;\r\n};\r\n\r\n/**\r\n * Remove the element specified by index from the heap and return it.\r\n *\r\n * @param {Number} [index=0] The index to remove.\r\n * @returns {*} The specified element of the heap.\r\n */\r\nHeap.prototype.pop = function (index) {\r\n index = defaultValue(index, 0);\r\n if (this._length === 0) {\r\n return undefined;\r\n }\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.number.lessThan(\"index\", index, this._length);\r\n //>>includeEnd('debug');\r\n\r\n var array = this._array;\r\n var root = array[index];\r\n swap(array, index, --this._length);\r\n this.heapify(index);\r\n array[this._length] = undefined; // Remove trailing reference\r\n return root;\r\n};\r\n\r\n/**\r\n * The comparator to use for the heap.\r\n * @callback Heap.ComparatorCallback\r\n * @param {*} a An element in the heap.\r\n * @param {*} b An element in the heap.\r\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.\r\n */\r\nexport default Heap;\r\n","import Uri from \"../ThirdParty/Uri.js\";\r\nimport when from \"../ThirdParty/when.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport Event from \"./Event.js\";\r\nimport Heap from \"./Heap.js\";\r\nimport isBlobUri from \"./isBlobUri.js\";\r\nimport isDataUri from \"./isDataUri.js\";\r\nimport RequestState from \"./RequestState.js\";\r\n\r\nfunction sortRequests(a, b) {\r\n return a.priority - b.priority;\r\n}\r\n\r\nvar statistics = {\r\n numberOfAttemptedRequests: 0,\r\n numberOfActiveRequests: 0,\r\n numberOfCancelledRequests: 0,\r\n numberOfCancelledActiveRequests: 0,\r\n numberOfFailedRequests: 0,\r\n numberOfActiveRequestsEver: 0,\r\n lastNumberOfActiveRequests: 0,\r\n};\r\n\r\nvar priorityHeapLength = 20;\r\nvar requestHeap = new Heap({\r\n comparator: sortRequests,\r\n});\r\nrequestHeap.maximumLength = priorityHeapLength;\r\nrequestHeap.reserve(priorityHeapLength);\r\n\r\nvar activeRequests = [];\r\nvar numberOfActiveRequestsByServer = {};\r\n\r\nvar pageUri =\r\n typeof document !== \"undefined\" ? new Uri(document.location.href) : new Uri();\r\n\r\nvar requestCompletedEvent = new Event();\r\n\r\n/**\r\n * The request scheduler is used to track and constrain the number of active requests in order to prioritize incoming requests. The ability\r\n * to retain control over the number of requests in CesiumJS is important because due to events such as changes in the camera position,\r\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\r\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.\r\n *\r\n * @namespace RequestScheduler\r\n *\r\n */\r\nfunction RequestScheduler() {}\r\n\r\n/**\r\n * The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit.\r\n * @type {Number}\r\n * @default 50\r\n */\r\nRequestScheduler.maximumRequests = 50;\r\n\r\n/**\r\n * The maximum number of simultaneous active requests per server. Un-throttled requests or servers specifically\r\n * listed in {@link requestsByServer} do not observe this limit.\r\n * @type {Number}\r\n * @default 6\r\n */\r\nRequestScheduler.maximumRequestsPerServer = 6;\r\n\r\n/**\r\n * A per server key list of overrides to use for throttling instead of maximumRequestsPerServer
\r\n * @type {Object}\r\n *\r\n * @example\r\n * RequestScheduler.requestsByServer = {\r\n * 'api.cesium.com:443': 18,\r\n * 'assets.cesium.com:443': 18\r\n * };\r\n */\r\nRequestScheduler.requestsByServer = {\r\n \"api.cesium.com:443\": 18,\r\n \"assets.cesium.com:443\": 18,\r\n};\r\n\r\n/**\r\n * Specifies if the request scheduler should throttle incoming requests, or let the browser queue requests under its control.\r\n * @type {Boolean}\r\n * @default true\r\n */\r\nRequestScheduler.throttleRequests = true;\r\n\r\n/**\r\n * When true, log statistics to the console every frame\r\n * @type {Boolean}\r\n * @default false\r\n * @private\r\n */\r\nRequestScheduler.debugShowStatistics = false;\r\n\r\n/**\r\n * An event that's raised when a request is completed. Event handlers are passed\r\n * the error object if the request fails.\r\n *\r\n * @type {Event}\r\n * @default Event()\r\n * @private\r\n */\r\nRequestScheduler.requestCompletedEvent = requestCompletedEvent;\r\n\r\nObject.defineProperties(RequestScheduler, {\r\n /**\r\n * Returns the statistics used by the request scheduler.\r\n *\r\n * @memberof RequestScheduler\r\n *\r\n * @type Object\r\n * @readonly\r\n * @private\r\n */\r\n statistics: {\r\n get: function () {\r\n return statistics;\r\n },\r\n },\r\n\r\n /**\r\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.\r\n *\r\n * @memberof RequestScheduler\r\n *\r\n * @type {Number}\r\n * @default 20\r\n * @private\r\n */\r\n priorityHeapLength: {\r\n get: function () {\r\n return priorityHeapLength;\r\n },\r\n set: function (value) {\r\n // If the new length shrinks the heap, need to cancel some of the requests.\r\n // Since this value is not intended to be tweaked regularly it is fine to just cancel the high priority requests.\r\n if (value < priorityHeapLength) {\r\n while (requestHeap.length > value) {\r\n var request = requestHeap.pop();\r\n cancelRequest(request);\r\n }\r\n }\r\n priorityHeapLength = value;\r\n requestHeap.maximumLength = value;\r\n requestHeap.reserve(value);\r\n },\r\n },\r\n});\r\n\r\nfunction updatePriority(request) {\r\n if (defined(request.priorityFunction)) {\r\n request.priority = request.priorityFunction();\r\n }\r\n}\r\n\r\nfunction serverHasOpenSlots(serverKey) {\r\n var maxRequests = defaultValue(\r\n RequestScheduler.requestsByServer[serverKey],\r\n RequestScheduler.maximumRequestsPerServer\r\n );\r\n return numberOfActiveRequestsByServer[serverKey] < maxRequests;\r\n}\r\n\r\nfunction issueRequest(request) {\r\n if (request.state === RequestState.UNISSUED) {\r\n request.state = RequestState.ISSUED;\r\n request.deferred = when.defer();\r\n }\r\n return request.deferred.promise;\r\n}\r\n\r\nfunction getRequestReceivedFunction(request) {\r\n return function (results) {\r\n if (request.state === RequestState.CANCELLED) {\r\n // If the data request comes back but the request is cancelled, ignore it.\r\n return;\r\n }\r\n // explicitly set to undefined to ensure GC of request response data. See #8843\r\n var deferred = request.deferred;\r\n\r\n --statistics.numberOfActiveRequests;\r\n --numberOfActiveRequestsByServer[request.serverKey];\r\n requestCompletedEvent.raiseEvent();\r\n request.state = RequestState.RECEIVED;\r\n request.deferred = undefined;\r\n\r\n deferred.resolve(results);\r\n };\r\n}\r\n\r\nfunction getRequestFailedFunction(request) {\r\n return function (error) {\r\n if (request.state === RequestState.CANCELLED) {\r\n // If the data request comes back but the request is cancelled, ignore it.\r\n return;\r\n }\r\n ++statistics.numberOfFailedRequests;\r\n --statistics.numberOfActiveRequests;\r\n --numberOfActiveRequestsByServer[request.serverKey];\r\n requestCompletedEvent.raiseEvent(error);\r\n request.state = RequestState.FAILED;\r\n request.deferred.reject(error);\r\n };\r\n}\r\n\r\nfunction startRequest(request) {\r\n var promise = issueRequest(request);\r\n request.state = RequestState.ACTIVE;\r\n activeRequests.push(request);\r\n ++statistics.numberOfActiveRequests;\r\n ++statistics.numberOfActiveRequestsEver;\r\n ++numberOfActiveRequestsByServer[request.serverKey];\r\n request\r\n .requestFunction()\r\n .then(getRequestReceivedFunction(request))\r\n .otherwise(getRequestFailedFunction(request));\r\n return promise;\r\n}\r\n\r\nfunction cancelRequest(request) {\r\n var active = request.state === RequestState.ACTIVE;\r\n request.state = RequestState.CANCELLED;\r\n ++statistics.numberOfCancelledRequests;\r\n // check that deferred has not been cleared since cancelRequest can be called\r\n // on a finished request, e.g. by clearForSpecs during tests\r\n if (defined(request.deferred)) {\r\n var deferred = request.deferred;\r\n request.deferred = undefined;\r\n deferred.reject();\r\n }\r\n\r\n if (active) {\r\n --statistics.numberOfActiveRequests;\r\n --numberOfActiveRequestsByServer[request.serverKey];\r\n ++statistics.numberOfCancelledActiveRequests;\r\n }\r\n\r\n if (defined(request.cancelFunction)) {\r\n request.cancelFunction();\r\n }\r\n}\r\n\r\n/**\r\n * Sort requests by priority and start requests.\r\n * @private\r\n */\r\nRequestScheduler.update = function () {\r\n var i;\r\n var request;\r\n\r\n // Loop over all active requests. Cancelled, failed, or received requests are removed from the array to make room for new requests.\r\n var removeCount = 0;\r\n var activeLength = activeRequests.length;\r\n for (i = 0; i < activeLength; ++i) {\r\n request = activeRequests[i];\r\n if (request.cancelled) {\r\n // Request was explicitly cancelled\r\n cancelRequest(request);\r\n }\r\n if (request.state !== RequestState.ACTIVE) {\r\n // Request is no longer active, remove from array\r\n ++removeCount;\r\n continue;\r\n }\r\n if (removeCount > 0) {\r\n // Shift back to fill in vacated slots from completed requests\r\n activeRequests[i - removeCount] = request;\r\n }\r\n }\r\n activeRequests.length -= removeCount;\r\n\r\n // Update priority of issued requests and resort the heap\r\n var issuedRequests = requestHeap.internalArray;\r\n var issuedLength = requestHeap.length;\r\n for (i = 0; i < issuedLength; ++i) {\r\n updatePriority(issuedRequests[i]);\r\n }\r\n requestHeap.resort();\r\n\r\n // Get the number of open slots and fill with the highest priority requests.\r\n // Un-throttled requests are automatically added to activeRequests, so activeRequests.length may exceed maximumRequests\r\n var openSlots = Math.max(\r\n RequestScheduler.maximumRequests - activeRequests.length,\r\n 0\r\n );\r\n var filledSlots = 0;\r\n while (filledSlots < openSlots && requestHeap.length > 0) {\r\n // Loop until all open slots are filled or the heap becomes empty\r\n request = requestHeap.pop();\r\n if (request.cancelled) {\r\n // Request was explicitly cancelled\r\n cancelRequest(request);\r\n continue;\r\n }\r\n\r\n if (request.throttleByServer && !serverHasOpenSlots(request.serverKey)) {\r\n // Open slots are available, but the request is throttled by its server. Cancel and try again later.\r\n cancelRequest(request);\r\n continue;\r\n }\r\n\r\n startRequest(request);\r\n ++filledSlots;\r\n }\r\n\r\n updateStatistics();\r\n};\r\n\r\n/**\r\n * Get the server key from a given url.\r\n *\r\n * @param {String} url The url.\r\n * @returns {String} The server key.\r\n * @private\r\n */\r\nRequestScheduler.getServerKey = function (url) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.string(\"url\", url);\r\n //>>includeEnd('debug');\r\n\r\n var uri = new Uri(url).resolve(pageUri);\r\n uri.normalize();\r\n var serverKey = uri.authority;\r\n if (!/:/.test(serverKey)) {\r\n // If the authority does not contain a port number, add port 443 for https or port 80 for http\r\n serverKey = serverKey + \":\" + (uri.scheme === \"https\" ? \"443\" : \"80\");\r\n }\r\n\r\n var length = numberOfActiveRequestsByServer[serverKey];\r\n if (!defined(length)) {\r\n numberOfActiveRequestsByServer[serverKey] = 0;\r\n }\r\n\r\n return serverKey;\r\n};\r\n\r\n/**\r\n * Issue a request. If request.throttle is false, the request is sent immediately. Otherwise the request will be\r\n * queued and sorted by priority before being sent.\r\n *\r\n * @param {Request} request The request object.\r\n *\r\n * @returns {Promise|undefined} A Promise for the requested data, or undefined if this request does not have high enough priority to be issued.\r\n *\r\n * @private\r\n */\r\nRequestScheduler.request = function (request) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"request\", request);\r\n Check.typeOf.string(\"request.url\", request.url);\r\n Check.typeOf.func(\"request.requestFunction\", request.requestFunction);\r\n //>>includeEnd('debug');\r\n\r\n if (isDataUri(request.url) || isBlobUri(request.url)) {\r\n requestCompletedEvent.raiseEvent();\r\n request.state = RequestState.RECEIVED;\r\n return request.requestFunction();\r\n }\r\n\r\n ++statistics.numberOfAttemptedRequests;\r\n\r\n if (!defined(request.serverKey)) {\r\n request.serverKey = RequestScheduler.getServerKey(request.url);\r\n }\r\n\r\n if (\r\n RequestScheduler.throttleRequests &&\r\n request.throttleByServer &&\r\n !serverHasOpenSlots(request.serverKey)\r\n ) {\r\n // Server is saturated. Try again later.\r\n return undefined;\r\n }\r\n\r\n if (!RequestScheduler.throttleRequests || !request.throttle) {\r\n return startRequest(request);\r\n }\r\n\r\n if (activeRequests.length >= RequestScheduler.maximumRequests) {\r\n // Active requests are saturated. Try again later.\r\n return undefined;\r\n }\r\n\r\n // Insert into the priority heap and see if a request was bumped off. If this request is the lowest\r\n // priority it will be returned.\r\n updatePriority(request);\r\n var removedRequest = requestHeap.insert(request);\r\n\r\n if (defined(removedRequest)) {\r\n if (removedRequest === request) {\r\n // Request does not have high enough priority to be issued\r\n return undefined;\r\n }\r\n // A previously issued request has been bumped off the priority heap, so cancel it\r\n cancelRequest(removedRequest);\r\n }\r\n\r\n return issueRequest(request);\r\n};\r\n\r\nfunction updateStatistics() {\r\n if (!RequestScheduler.debugShowStatistics) {\r\n return;\r\n }\r\n\r\n if (\r\n statistics.numberOfActiveRequests === 0 &&\r\n statistics.lastNumberOfActiveRequests > 0\r\n ) {\r\n if (statistics.numberOfAttemptedRequests > 0) {\r\n console.log(\r\n \"Number of attempted requests: \" + statistics.numberOfAttemptedRequests\r\n );\r\n statistics.numberOfAttemptedRequests = 0;\r\n }\r\n\r\n if (statistics.numberOfCancelledRequests > 0) {\r\n console.log(\r\n \"Number of cancelled requests: \" + statistics.numberOfCancelledRequests\r\n );\r\n statistics.numberOfCancelledRequests = 0;\r\n }\r\n\r\n if (statistics.numberOfCancelledActiveRequests > 0) {\r\n console.log(\r\n \"Number of cancelled active requests: \" +\r\n statistics.numberOfCancelledActiveRequests\r\n );\r\n statistics.numberOfCancelledActiveRequests = 0;\r\n }\r\n\r\n if (statistics.numberOfFailedRequests > 0) {\r\n console.log(\r\n \"Number of failed requests: \" + statistics.numberOfFailedRequests\r\n );\r\n statistics.numberOfFailedRequests = 0;\r\n }\r\n }\r\n\r\n statistics.lastNumberOfActiveRequests = statistics.numberOfActiveRequests;\r\n}\r\n\r\n/**\r\n * For testing only. Clears any requests that may not have completed from previous tests.\r\n *\r\n * @private\r\n */\r\nRequestScheduler.clearForSpecs = function () {\r\n while (requestHeap.length > 0) {\r\n var request = requestHeap.pop();\r\n cancelRequest(request);\r\n }\r\n var length = activeRequests.length;\r\n for (var i = 0; i < length; ++i) {\r\n cancelRequest(activeRequests[i]);\r\n }\r\n activeRequests.length = 0;\r\n numberOfActiveRequestsByServer = {};\r\n\r\n // Clear stats\r\n statistics.numberOfAttemptedRequests = 0;\r\n statistics.numberOfActiveRequests = 0;\r\n statistics.numberOfCancelledRequests = 0;\r\n statistics.numberOfCancelledActiveRequests = 0;\r\n statistics.numberOfFailedRequests = 0;\r\n statistics.numberOfActiveRequestsEver = 0;\r\n statistics.lastNumberOfActiveRequests = 0;\r\n};\r\n\r\n/**\r\n * For testing only.\r\n *\r\n * @private\r\n */\r\nRequestScheduler.numberOfActiveRequestsByServer = function (serverKey) {\r\n return numberOfActiveRequestsByServer[serverKey];\r\n};\r\n\r\n/**\r\n * For testing only.\r\n *\r\n * @private\r\n */\r\nRequestScheduler.requestHeap = requestHeap;\r\nexport default RequestScheduler;\r\n","import Uri from \"../ThirdParty/Uri.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\n\r\n/**\r\n * A singleton that contains all of the servers that are trusted. Credentials will be sent with\r\n * any requests to these servers.\r\n *\r\n * @namespace TrustedServers\r\n *\r\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\r\n */\r\nvar TrustedServers = {};\r\nvar _servers = {};\r\n\r\n/**\r\n * Adds a trusted server to the registry\r\n *\r\n * @param {String} host The host to be added.\r\n * @param {Number} port The port used to access the host.\r\n *\r\n * @example\r\n * // Add a trusted server\r\n * TrustedServers.add('my.server.com', 80);\r\n */\r\nTrustedServers.add = function (host, port) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(host)) {\r\n throw new DeveloperError(\"host is required.\");\r\n }\r\n if (!defined(port) || port <= 0) {\r\n throw new DeveloperError(\"port is required to be greater than 0.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var authority = host.toLowerCase() + \":\" + port;\r\n if (!defined(_servers[authority])) {\r\n _servers[authority] = true;\r\n }\r\n};\r\n\r\n/**\r\n * Removes a trusted server from the registry\r\n *\r\n * @param {String} host The host to be removed.\r\n * @param {Number} port The port used to access the host.\r\n *\r\n * @example\r\n * // Remove a trusted server\r\n * TrustedServers.remove('my.server.com', 80);\r\n */\r\nTrustedServers.remove = function (host, port) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(host)) {\r\n throw new DeveloperError(\"host is required.\");\r\n }\r\n if (!defined(port) || port <= 0) {\r\n throw new DeveloperError(\"port is required to be greater than 0.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var authority = host.toLowerCase() + \":\" + port;\r\n if (defined(_servers[authority])) {\r\n delete _servers[authority];\r\n }\r\n};\r\n\r\nfunction getAuthority(url) {\r\n var uri = new Uri(url);\r\n uri.normalize();\r\n\r\n // Removes username:password@ so we just have host[:port]\r\n var authority = uri.getAuthority();\r\n if (!defined(authority)) {\r\n return undefined; // Relative URL\r\n }\r\n\r\n if (authority.indexOf(\"@\") !== -1) {\r\n var parts = authority.split(\"@\");\r\n authority = parts[1];\r\n }\r\n\r\n // If the port is missing add one based on the scheme\r\n if (authority.indexOf(\":\") === -1) {\r\n var scheme = uri.getScheme();\r\n if (!defined(scheme)) {\r\n scheme = window.location.protocol;\r\n scheme = scheme.substring(0, scheme.length - 1);\r\n }\r\n if (scheme === \"http\") {\r\n authority += \":80\";\r\n } else if (scheme === \"https\") {\r\n authority += \":443\";\r\n } else {\r\n return undefined;\r\n }\r\n }\r\n\r\n return authority;\r\n}\r\n\r\n/**\r\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.\r\n *\r\n * @param {String} url The url to be tested against the trusted list\r\n *\r\n * @returns {boolean} Returns true if url is trusted, false otherwise.\r\n *\r\n * @example\r\n * // Add server\r\n * TrustedServers.add('my.server.com', 81);\r\n *\r\n * // Check if server is trusted\r\n * if (TrustedServers.contains('https://my.server.com:81/path/to/file.png')) {\r\n * // my.server.com:81 is trusted\r\n * }\r\n * if (TrustedServers.contains('https://my.server.com/path/to/file.png')) {\r\n * // my.server.com isn't trusted\r\n * }\r\n */\r\nTrustedServers.contains = function (url) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(url)) {\r\n throw new DeveloperError(\"url is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n var authority = getAuthority(url);\r\n if (defined(authority) && defined(_servers[authority])) {\r\n return true;\r\n }\r\n\r\n return false;\r\n};\r\n\r\n/**\r\n * Clears the registry\r\n *\r\n * @example\r\n * // Remove a trusted server\r\n * TrustedServers.clear();\r\n */\r\nTrustedServers.clear = function () {\r\n _servers = {};\r\n};\r\nexport default TrustedServers;\r\n","import Uri from \"../ThirdParty/Uri.js\";\r\nimport when from \"../ThirdParty/when.js\";\r\nimport appendForwardSlash from \"./appendForwardSlash.js\";\r\nimport Check from \"./Check.js\";\r\nimport clone from \"./clone.js\";\r\nimport combine from \"./combine.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport getAbsoluteUri from \"./getAbsoluteUri.js\";\r\nimport getBaseUri from \"./getBaseUri.js\";\r\nimport getExtensionFromUri from \"./getExtensionFromUri.js\";\r\nimport isBlobUri from \"./isBlobUri.js\";\r\nimport isCrossOriginUrl from \"./isCrossOriginUrl.js\";\r\nimport isDataUri from \"./isDataUri.js\";\r\nimport loadAndExecuteScript from \"./loadAndExecuteScript.js\";\r\nimport objectToQuery from \"./objectToQuery.js\";\r\nimport queryToObject from \"./queryToObject.js\";\r\nimport Request from \"./Request.js\";\r\nimport RequestErrorEvent from \"./RequestErrorEvent.js\";\r\nimport RequestScheduler from \"./RequestScheduler.js\";\r\nimport RequestState from \"./RequestState.js\";\r\nimport RuntimeError from \"./RuntimeError.js\";\r\nimport TrustedServers from \"./TrustedServers.js\";\r\n\r\nvar xhrBlobSupported = (function () {\r\n try {\r\n var xhr = new XMLHttpRequest();\r\n xhr.open(\"GET\", \"#\", true);\r\n xhr.responseType = \"blob\";\r\n return xhr.responseType === \"blob\";\r\n } catch (e) {\r\n return false;\r\n }\r\n})();\r\n\r\n/**\r\n * Parses a query string and returns the object equivalent.\r\n *\r\n * @param {Uri} uri The Uri with a query object.\r\n * @param {Resource} resource The Resource that will be assigned queryParameters.\r\n * @param {Boolean} merge If true, we'll merge with the resource's existing queryParameters. Otherwise they will be replaced.\r\n * @param {Boolean} preserveQueryParameters If true duplicate parameters will be concatenated into an array. If false, keys in uri will take precedence.\r\n *\r\n * @private\r\n */\r\nfunction parseQuery(uri, resource, merge, preserveQueryParameters) {\r\n var queryString = uri.query;\r\n if (!defined(queryString) || queryString.length === 0) {\r\n return {};\r\n }\r\n\r\n var query;\r\n // Special case we run into where the querystring is just a string, not key/value pairs\r\n if (queryString.indexOf(\"=\") === -1) {\r\n var result = {};\r\n result[queryString] = undefined;\r\n query = result;\r\n } else {\r\n query = queryToObject(queryString);\r\n }\r\n\r\n if (merge) {\r\n resource._queryParameters = combineQueryParameters(\r\n query,\r\n resource._queryParameters,\r\n preserveQueryParameters\r\n );\r\n } else {\r\n resource._queryParameters = query;\r\n }\r\n uri.query = undefined;\r\n}\r\n\r\n/**\r\n * Converts a query object into a string.\r\n *\r\n * @param {Uri} uri The Uri object that will have the query object set.\r\n * @param {Resource} resource The resource that has queryParameters\r\n *\r\n * @private\r\n */\r\nfunction stringifyQuery(uri, resource) {\r\n var queryObject = resource._queryParameters;\r\n\r\n var keys = Object.keys(queryObject);\r\n\r\n // We have 1 key with an undefined value, so this is just a string, not key/value pairs\r\n if (keys.length === 1 && !defined(queryObject[keys[0]])) {\r\n uri.query = keys[0];\r\n } else {\r\n uri.query = objectToQuery(queryObject);\r\n }\r\n}\r\n\r\n/**\r\n * Clones a value if it is defined, otherwise returns the default value\r\n *\r\n * @param {*} [val] The value to clone.\r\n * @param {*} [defaultVal] The default value.\r\n *\r\n * @returns {*} A clone of val or the defaultVal.\r\n *\r\n * @private\r\n */\r\nfunction defaultClone(val, defaultVal) {\r\n if (!defined(val)) {\r\n return defaultVal;\r\n }\r\n\r\n return defined(val.clone) ? val.clone() : clone(val);\r\n}\r\n\r\n/**\r\n * Checks to make sure the Resource isn't already being requested.\r\n *\r\n * @param {Request} request The request to check.\r\n *\r\n * @private\r\n */\r\nfunction checkAndResetRequest(request) {\r\n if (\r\n request.state === RequestState.ISSUED ||\r\n request.state === RequestState.ACTIVE\r\n ) {\r\n throw new RuntimeError(\"The Resource is already being fetched.\");\r\n }\r\n\r\n request.state = RequestState.UNISSUED;\r\n request.deferred = undefined;\r\n}\r\n\r\n/**\r\n * This combines a map of query parameters.\r\n *\r\n * @param {Object} q1 The first map of query parameters. Values in this map will take precedence if preserveQueryParameters is false.\r\n * @param {Object} q2 The second map of query parameters.\r\n * @param {Boolean} preserveQueryParameters If true duplicate parameters will be concatenated into an array. If false, keys in q1 will take precedence.\r\n *\r\n * @returns {Object} The combined map of query parameters.\r\n *\r\n * @example\r\n * var q1 = {\r\n * a: 1,\r\n * b: 2\r\n * };\r\n * var q2 = {\r\n * a: 3,\r\n * c: 4\r\n * };\r\n * var q3 = {\r\n * b: [5, 6],\r\n * d: 7\r\n * }\r\n *\r\n * // Returns\r\n * // {\r\n * // a: [1, 3],\r\n * // b: 2,\r\n * // c: 4\r\n * // };\r\n * combineQueryParameters(q1, q2, true);\r\n *\r\n * // Returns\r\n * // {\r\n * // a: 1,\r\n * // b: 2,\r\n * // c: 4\r\n * // };\r\n * combineQueryParameters(q1, q2, false);\r\n *\r\n * // Returns\r\n * // {\r\n * // a: 1,\r\n * // b: [2, 5, 6],\r\n * // d: 7\r\n * // };\r\n * combineQueryParameters(q1, q3, true);\r\n *\r\n * // Returns\r\n * // {\r\n * // a: 1,\r\n * // b: 2,\r\n * // d: 7\r\n * // };\r\n * combineQueryParameters(q1, q3, false);\r\n *\r\n * @private\r\n */\r\nfunction combineQueryParameters(q1, q2, preserveQueryParameters) {\r\n if (!preserveQueryParameters) {\r\n return combine(q1, q2);\r\n }\r\n\r\n var result = clone(q1, true);\r\n for (var param in q2) {\r\n if (q2.hasOwnProperty(param)) {\r\n var value = result[param];\r\n var q2Value = q2[param];\r\n if (defined(value)) {\r\n if (!Array.isArray(value)) {\r\n value = result[param] = [value];\r\n }\r\n\r\n result[param] = value.concat(q2Value);\r\n } else {\r\n result[param] = Array.isArray(q2Value) ? q2Value.slice() : q2Value;\r\n }\r\n }\r\n }\r\n\r\n return result;\r\n}\r\n\r\n/**\r\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.\r\n *\r\n * @alias Resource\r\n * @constructor\r\n *\r\n * @param {String|Object} options A url or an object with the following properties\r\n * @param {String} options.url The url of the resource.\r\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\r\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\r\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\r\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\r\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.\r\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\r\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\r\n *\r\n * @example\r\n * function refreshTokenRetryCallback(resource, error) {\r\n * if (error.statusCode === 403) {\r\n * // 403 status code means a new token should be generated\r\n * return getNewAccessToken()\r\n * .then(function(token) {\r\n * resource.queryParameters.access_token = token;\r\n * return true;\r\n * })\r\n * .otherwise(function() {\r\n * return false;\r\n * });\r\n * }\r\n *\r\n * return false;\r\n * }\r\n *\r\n * var resource = new Resource({\r\n * url: 'http://server.com/path/to/resource.json',\r\n * proxy: new DefaultProxy('/proxy/'),\r\n * headers: {\r\n * 'X-My-Header': 'valueOfHeader'\r\n * },\r\n * queryParameters: {\r\n * 'access_token': '123-435-456-000'\r\n * },\r\n * retryCallback: refreshTokenRetryCallback,\r\n * retryAttempts: 1\r\n * });\r\n */\r\nfunction Resource(options) {\r\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\r\n if (typeof options === \"string\") {\r\n options = {\r\n url: options,\r\n };\r\n }\r\n\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.string(\"options.url\", options.url);\r\n //>>includeEnd('debug');\r\n\r\n this._url = undefined;\r\n this._templateValues = defaultClone(options.templateValues, {});\r\n this._queryParameters = defaultClone(options.queryParameters, {});\r\n\r\n /**\r\n * Additional HTTP headers that will be sent with the request.\r\n *\r\n * @type {Object}\r\n */\r\n this.headers = defaultClone(options.headers, {});\r\n\r\n /**\r\n * A Request object that will be used. Intended for internal use only.\r\n *\r\n * @type {Request}\r\n */\r\n this.request = defaultValue(options.request, new Request());\r\n\r\n /**\r\n * A proxy to be used when loading the resource.\r\n *\r\n * @type {Proxy}\r\n */\r\n this.proxy = options.proxy;\r\n\r\n /**\r\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.\r\n *\r\n * @type {Function}\r\n */\r\n this.retryCallback = options.retryCallback;\r\n\r\n /**\r\n * The number of times the retryCallback should be called before giving up.\r\n *\r\n * @type {Number}\r\n */\r\n this.retryAttempts = defaultValue(options.retryAttempts, 0);\r\n this._retryCount = 0;\r\n\r\n var uri = new Uri(options.url);\r\n parseQuery(uri, this, true, true);\r\n\r\n // Remove the fragment as it's not sent with a request\r\n uri.fragment = undefined;\r\n\r\n this._url = uri.toString();\r\n}\r\n\r\n/**\r\n * A helper function to create a resource depending on whether we have a String or a Resource\r\n *\r\n * @param {Resource|String} resource A Resource or a String to use when creating a new Resource.\r\n *\r\n * @returns {Resource} If resource is a String, a Resource constructed with the url and options. Otherwise the resource parameter is returned.\r\n *\r\n * @private\r\n */\r\nResource.createIfNeeded = function (resource) {\r\n if (resource instanceof Resource) {\r\n // Keep existing request object. This function is used internally to duplicate a Resource, so that it can't\r\n // be modified outside of a class that holds it (eg. an imagery or terrain provider). Since the Request objects\r\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\r\n // in the underlying tiling code the requests for this resource will use it.\r\n return resource.getDerivedResource({\r\n request: resource.request,\r\n });\r\n }\r\n\r\n if (typeof resource !== \"string\") {\r\n return resource;\r\n }\r\n\r\n return new Resource({\r\n url: resource,\r\n });\r\n};\r\n\r\nvar supportsImageBitmapOptionsPromise;\r\n/**\r\n * A helper function to check whether createImageBitmap supports passing ImageBitmapOptions.\r\n *\r\n * @returns {Promise} A promise that resolves to true if this browser supports creating an ImageBitmap with options.\r\n *\r\n * @private\r\n */\r\nResource.supportsImageBitmapOptions = function () {\r\n // Until the HTML folks figure out what to do about this, we need to actually try loading an image to\r\n // know if this browser supports passing options to the createImageBitmap function.\r\n // https://github.com/whatwg/html/pull/4248\r\n if (defined(supportsImageBitmapOptionsPromise)) {\r\n return supportsImageBitmapOptionsPromise;\r\n }\r\n\r\n if (typeof createImageBitmap !== \"function\") {\r\n supportsImageBitmapOptionsPromise = when.resolve(false);\r\n return supportsImageBitmapOptionsPromise;\r\n }\r\n\r\n var imageDataUri =\r\n \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWP4////fwAJ+wP9CNHoHgAAAABJRU5ErkJggg==\";\r\n\r\n supportsImageBitmapOptionsPromise = Resource.fetchBlob({\r\n url: imageDataUri,\r\n })\r\n .then(function (blob) {\r\n return createImageBitmap(blob, {\r\n imageOrientation: \"flipY\",\r\n premultiplyAlpha: \"none\",\r\n });\r\n })\r\n .then(function (imageBitmap) {\r\n return true;\r\n })\r\n .otherwise(function () {\r\n return false;\r\n });\r\n\r\n return supportsImageBitmapOptionsPromise;\r\n};\r\n\r\nObject.defineProperties(Resource, {\r\n /**\r\n * Returns true if blobs are supported.\r\n *\r\n * @memberof Resource\r\n * @type {Boolean}\r\n *\r\n * @readonly\r\n */\r\n isBlobSupported: {\r\n get: function () {\r\n return xhrBlobSupported;\r\n },\r\n },\r\n});\r\n\r\nObject.defineProperties(Resource.prototype, {\r\n /**\r\n * Query parameters appended to the url.\r\n *\r\n * @memberof Resource.prototype\r\n * @type {Object}\r\n *\r\n * @readonly\r\n */\r\n queryParameters: {\r\n get: function () {\r\n return this._queryParameters;\r\n },\r\n },\r\n\r\n /**\r\n * The key/value pairs used to replace template parameters in the url.\r\n *\r\n * @memberof Resource.prototype\r\n * @type {Object}\r\n *\r\n * @readonly\r\n */\r\n templateValues: {\r\n get: function () {\r\n return this._templateValues;\r\n },\r\n },\r\n\r\n /**\r\n * The url to the resource with template values replaced, query string appended and encoded by proxy if one was set.\r\n *\r\n * @memberof Resource.prototype\r\n * @type {String}\r\n */\r\n url: {\r\n get: function () {\r\n return this.getUrlComponent(true, true);\r\n },\r\n set: function (value) {\r\n var uri = new Uri(value);\r\n\r\n parseQuery(uri, this, false);\r\n\r\n // Remove the fragment as it's not sent with a request\r\n uri.fragment = undefined;\r\n\r\n this._url = uri.toString();\r\n },\r\n },\r\n\r\n /**\r\n * The file extension of the resource.\r\n *\r\n * @memberof Resource.prototype\r\n * @type {String}\r\n *\r\n * @readonly\r\n */\r\n extension: {\r\n get: function () {\r\n return getExtensionFromUri(this._url);\r\n },\r\n },\r\n\r\n /**\r\n * True if the Resource refers to a data URI.\r\n *\r\n * @memberof Resource.prototype\r\n * @type {Boolean}\r\n */\r\n isDataUri: {\r\n get: function () {\r\n return isDataUri(this._url);\r\n },\r\n },\r\n\r\n /**\r\n * True if the Resource refers to a blob URI.\r\n *\r\n * @memberof Resource.prototype\r\n * @type {Boolean}\r\n */\r\n isBlobUri: {\r\n get: function () {\r\n return isBlobUri(this._url);\r\n },\r\n },\r\n\r\n /**\r\n * True if the Resource refers to a cross origin URL.\r\n *\r\n * @memberof Resource.prototype\r\n * @type {Boolean}\r\n */\r\n isCrossOriginUrl: {\r\n get: function () {\r\n return isCrossOriginUrl(this._url);\r\n },\r\n },\r\n\r\n /**\r\n * True if the Resource has request headers. This is equivalent to checking if the headers property has any keys.\r\n *\r\n * @memberof Resource.prototype\r\n * @type {Boolean}\r\n */\r\n hasHeaders: {\r\n get: function () {\r\n return Object.keys(this.headers).length > 0;\r\n },\r\n },\r\n});\r\n\r\n/**\r\n * Override Object#toString so that implicit string conversion gives the\r\n * complete URL represented by this Resource.\r\n *\r\n * @returns {String} The URL represented by this Resource\r\n */\r\nResource.prototype.toString = function () {\r\n return this.getUrlComponent(true, true);\r\n};\r\n\r\n/**\r\n * Returns the url, optional with the query string and processed by a proxy.\r\n *\r\n * @param {Boolean} [query=false] If true, the query string is included.\r\n * @param {Boolean} [proxy=false] If true, the url is processed by the proxy object, if defined.\r\n *\r\n * @returns {String} The url with all the requested components.\r\n */\r\nResource.prototype.getUrlComponent = function (query, proxy) {\r\n if (this.isDataUri) {\r\n return this._url;\r\n }\r\n\r\n var uri = new Uri(this._url);\r\n\r\n if (query) {\r\n stringifyQuery(uri, this);\r\n }\r\n\r\n // objectToQuery escapes the placeholders. Undo that.\r\n var url = uri.toString().replace(/%7B/g, \"{\").replace(/%7D/g, \"}\");\r\n\r\n var templateValues = this._templateValues;\r\n url = url.replace(/{(.*?)}/g, function (match, key) {\r\n var replacement = templateValues[key];\r\n if (defined(replacement)) {\r\n // use the replacement value from templateValues if there is one...\r\n return encodeURIComponent(replacement);\r\n }\r\n // otherwise leave it unchanged\r\n return match;\r\n });\r\n\r\n if (proxy && defined(this.proxy)) {\r\n url = this.proxy.getURL(url);\r\n }\r\n return url;\r\n};\r\n\r\n/**\r\n * Combines the specified object and the existing query parameters. This allows you to add many parameters at once,\r\n * as opposed to adding them one at a time to the queryParameters property. If a value is already set, it will be replaced with the new value.\r\n *\r\n * @param {Object} params The query parameters\r\n * @param {Boolean} [useAsDefault=false] If true the params will be used as the default values, so they will only be set if they are undefined.\r\n */\r\nResource.prototype.setQueryParameters = function (params, useAsDefault) {\r\n if (useAsDefault) {\r\n this._queryParameters = combineQueryParameters(\r\n this._queryParameters,\r\n params,\r\n false\r\n );\r\n } else {\r\n this._queryParameters = combineQueryParameters(\r\n params,\r\n this._queryParameters,\r\n false\r\n );\r\n }\r\n};\r\n\r\n/**\r\n * Combines the specified object and the existing query parameters. This allows you to add many parameters at once,\r\n * as opposed to adding them one at a time to the queryParameters property.\r\n *\r\n * @param {Object} params The query parameters\r\n */\r\nResource.prototype.appendQueryParameters = function (params) {\r\n this._queryParameters = combineQueryParameters(\r\n params,\r\n this._queryParameters,\r\n true\r\n );\r\n};\r\n\r\n/**\r\n * Combines the specified object and the existing template values. This allows you to add many values at once,\r\n * as opposed to adding them one at a time to the templateValues property. If a value is already set, it will become an array and the new value will be appended.\r\n *\r\n * @param {Object} template The template values\r\n * @param {Boolean} [useAsDefault=false] If true the values will be used as the default values, so they will only be set if they are undefined.\r\n */\r\nResource.prototype.setTemplateValues = function (template, useAsDefault) {\r\n if (useAsDefault) {\r\n this._templateValues = combine(this._templateValues, template);\r\n } else {\r\n this._templateValues = combine(template, this._templateValues);\r\n }\r\n};\r\n\r\n/**\r\n * Returns a resource relative to the current instance. All properties remain the same as the current instance unless overridden in options.\r\n *\r\n * @param {Object} options An object with the following properties\r\n * @param {String} [options.url] The url that will be resolved relative to the url of the current instance.\r\n * @param {Object} [options.queryParameters] An object containing query parameters that will be combined with those of the current instance.\r\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}). These will be combined with those of the current instance.\r\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\r\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\r\n * @param {Resource.RetryCallback} [options.retryCallback] The function to call when loading the resource fails.\r\n * @param {Number} [options.retryAttempts] The number of times the retryCallback should be called before giving up.\r\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\r\n * @param {Boolean} [options.preserveQueryParameters=false] If true, this will keep all query parameters from the current resource and derived resource. If false, derived parameters will replace those of the current resource.\r\n *\r\n * @returns {Resource} The resource derived from the current one.\r\n */\r\nResource.prototype.getDerivedResource = function (options) {\r\n var resource = this.clone();\r\n resource._retryCount = 0;\r\n\r\n if (defined(options.url)) {\r\n var uri = new Uri(options.url);\r\n\r\n var preserveQueryParameters = defaultValue(\r\n options.preserveQueryParameters,\r\n false\r\n );\r\n parseQuery(uri, resource, true, preserveQueryParameters);\r\n\r\n // Remove the fragment as it's not sent with a request\r\n uri.fragment = undefined;\r\n\r\n resource._url = uri.resolve(new Uri(getAbsoluteUri(this._url))).toString();\r\n }\r\n\r\n if (defined(options.queryParameters)) {\r\n resource._queryParameters = combine(\r\n options.queryParameters,\r\n resource._queryParameters\r\n );\r\n }\r\n if (defined(options.templateValues)) {\r\n resource._templateValues = combine(\r\n options.templateValues,\r\n resource.templateValues\r\n );\r\n }\r\n if (defined(options.headers)) {\r\n resource.headers = combine(options.headers, resource.headers);\r\n }\r\n if (defined(options.proxy)) {\r\n resource.proxy = options.proxy;\r\n }\r\n if (defined(options.request)) {\r\n resource.request = options.request;\r\n }\r\n if (defined(options.retryCallback)) {\r\n resource.retryCallback = options.retryCallback;\r\n }\r\n if (defined(options.retryAttempts)) {\r\n resource.retryAttempts = options.retryAttempts;\r\n }\r\n\r\n return resource;\r\n};\r\n\r\n/**\r\n * Called when a resource fails to load. This will call the retryCallback function if defined until retryAttempts is reached.\r\n *\r\n * @param {Error} [error] The error that was encountered.\r\n *\r\n * @returns {Promise} A promise to a boolean, that if true will cause the resource request to be retried.\r\n *\r\n * @private\r\n */\r\nResource.prototype.retryOnError = function (error) {\r\n var retryCallback = this.retryCallback;\r\n if (\r\n typeof retryCallback !== \"function\" ||\r\n this._retryCount >= this.retryAttempts\r\n ) {\r\n return when(false);\r\n }\r\n\r\n var that = this;\r\n return when(retryCallback(this, error)).then(function (result) {\r\n ++that._retryCount;\r\n\r\n return result;\r\n });\r\n};\r\n\r\n/**\r\n * Duplicates a Resource instance.\r\n *\r\n * @param {Resource} [result] The object onto which to store the result.\r\n *\r\n * @returns {Resource} The modified result parameter or a new Resource instance if one was not provided.\r\n */\r\nResource.prototype.clone = function (result) {\r\n if (!defined(result)) {\r\n result = new Resource({\r\n url: this._url,\r\n });\r\n }\r\n\r\n result._url = this._url;\r\n result._queryParameters = clone(this._queryParameters);\r\n result._templateValues = clone(this._templateValues);\r\n result.headers = clone(this.headers);\r\n result.proxy = this.proxy;\r\n result.retryCallback = this.retryCallback;\r\n result.retryAttempts = this.retryAttempts;\r\n result._retryCount = 0;\r\n result.request = this.request.clone();\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Returns the base path of the Resource.\r\n *\r\n * @param {Boolean} [includeQuery = false] Whether or not to include the query string and fragment form the uri\r\n *\r\n * @returns {String} The base URI of the resource\r\n */\r\nResource.prototype.getBaseUri = function (includeQuery) {\r\n return getBaseUri(this.getUrlComponent(includeQuery), includeQuery);\r\n};\r\n\r\n/**\r\n * Appends a forward slash to the URL.\r\n */\r\nResource.prototype.appendForwardSlash = function () {\r\n this._url = appendForwardSlash(this._url);\r\n};\r\n\r\n/**\r\n * Asynchronously loads the resource as raw binary data. Returns a promise that will resolve to\r\n * an ArrayBuffer once loaded, or reject if the resource failed to load. The data is loaded\r\n * using XMLHttpRequest, which means that in order to make requests to another origin,\r\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\r\n *\r\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.\r\n *\r\n * @example\r\n * // load a single URL asynchronously\r\n * resource.fetchArrayBuffer().then(function(arrayBuffer) {\r\n * // use the data\r\n * }).otherwise(function(error) {\r\n * // an error occurred\r\n * });\r\n *\r\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\r\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\r\n */\r\nResource.prototype.fetchArrayBuffer = function () {\r\n return this.fetch({\r\n responseType: \"arraybuffer\",\r\n });\r\n};\r\n\r\n/**\r\n * Creates a Resource and calls fetchArrayBuffer() on it.\r\n *\r\n * @param {String|Object} options A url or an object with the following properties\r\n * @param {String} options.url The url of the resource.\r\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\r\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\r\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\r\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\r\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.\r\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\r\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\r\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.\r\n */\r\nResource.fetchArrayBuffer = function (options) {\r\n var resource = new Resource(options);\r\n return resource.fetchArrayBuffer();\r\n};\r\n\r\n/**\r\n * Asynchronously loads the given resource as a blob. Returns a promise that will resolve to\r\n * a Blob once loaded, or reject if the resource failed to load. The data is loaded\r\n * using XMLHttpRequest, which means that in order to make requests to another origin,\r\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\r\n *\r\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.\r\n *\r\n * @example\r\n * // load a single URL asynchronously\r\n * resource.fetchBlob().then(function(blob) {\r\n * // use the data\r\n * }).otherwise(function(error) {\r\n * // an error occurred\r\n * });\r\n *\r\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\r\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\r\n */\r\nResource.prototype.fetchBlob = function () {\r\n return this.fetch({\r\n responseType: \"blob\",\r\n });\r\n};\r\n\r\n/**\r\n * Creates a Resource and calls fetchBlob() on it.\r\n *\r\n * @param {String|Object} options A url or an object with the following properties\r\n * @param {String} options.url The url of the resource.\r\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\r\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\r\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\r\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\r\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.\r\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\r\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\r\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.\r\n */\r\nResource.fetchBlob = function (options) {\r\n var resource = new Resource(options);\r\n return resource.fetchBlob();\r\n};\r\n\r\n/**\r\n * Asynchronously loads the given image resource. Returns a promise that will resolve to\r\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\r\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement|Image} once loaded, or reject if the image failed to load.\r\n *\r\n * @param {Object} [options] An object with the following properties.\r\n * @param {Boolean} [options.preferBlob=false] If true, we will load the image via a blob.\r\n * @param {Boolean} [options.preferImageBitmap=false] If true, image will be decoded during fetch and an ImageBitmap
is returned.\r\n * @param {Boolean} [options.flipY=false] If true, image will be vertically flipped during decode. Only applies if the browser supports createImageBitmap
.\r\n * @returns {Promise.|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.\r\n *\r\n *\r\n * @example\r\n * // load a single image asynchronously\r\n * resource.fetchImage().then(function(image) {\r\n * // use the loaded image\r\n * }).otherwise(function(error) {\r\n * // an error occurred\r\n * });\r\n *\r\n * // load several images in parallel\r\n * when.all([resource1.fetchImage(), resource2.fetchImage()]).then(function(images) {\r\n * // images is an array containing all the loaded images\r\n * });\r\n *\r\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\r\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\r\n */\r\nResource.prototype.fetchImage = function (options) {\r\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\r\n var preferImageBitmap = defaultValue(options.preferImageBitmap, false);\r\n var preferBlob = defaultValue(options.preferBlob, false);\r\n var flipY = defaultValue(options.flipY, false);\r\n\r\n checkAndResetRequest(this.request);\r\n\r\n // We try to load the image normally if\r\n // 1. Blobs aren't supported\r\n // 2. It's a data URI\r\n // 3. It's a blob URI\r\n // 4. It doesn't have request headers and we preferBlob is false\r\n if (\r\n !xhrBlobSupported ||\r\n this.isDataUri ||\r\n this.isBlobUri ||\r\n (!this.hasHeaders && !preferBlob)\r\n ) {\r\n return fetchImage({\r\n resource: this,\r\n flipY: flipY,\r\n preferImageBitmap: preferImageBitmap,\r\n });\r\n }\r\n\r\n var blobPromise = this.fetchBlob();\r\n if (!defined(blobPromise)) {\r\n return;\r\n }\r\n\r\n var supportsImageBitmap;\r\n var useImageBitmap;\r\n var generatedBlobResource;\r\n var generatedBlob;\r\n return Resource.supportsImageBitmapOptions()\r\n .then(function (result) {\r\n supportsImageBitmap = result;\r\n useImageBitmap = supportsImageBitmap && preferImageBitmap;\r\n return blobPromise;\r\n })\r\n .then(function (blob) {\r\n if (!defined(blob)) {\r\n return;\r\n }\r\n generatedBlob = blob;\r\n if (useImageBitmap) {\r\n return Resource.createImageBitmapFromBlob(blob, {\r\n flipY: flipY,\r\n premultiplyAlpha: false,\r\n });\r\n }\r\n var blobUrl = window.URL.createObjectURL(blob);\r\n generatedBlobResource = new Resource({\r\n url: blobUrl,\r\n });\r\n\r\n return fetchImage({\r\n resource: generatedBlobResource,\r\n flipY: flipY,\r\n preferImageBitmap: false,\r\n });\r\n })\r\n .then(function (image) {\r\n if (!defined(image)) {\r\n return;\r\n }\r\n\r\n // The blob object may be needed for use by a TileDiscardPolicy,\r\n // so attach it to the image.\r\n image.blob = generatedBlob;\r\n\r\n if (useImageBitmap) {\r\n return image;\r\n }\r\n\r\n window.URL.revokeObjectURL(generatedBlobResource.url);\r\n return image;\r\n })\r\n .otherwise(function (error) {\r\n if (defined(generatedBlobResource)) {\r\n window.URL.revokeObjectURL(generatedBlobResource.url);\r\n }\r\n\r\n // If the blob load succeeded but the image decode failed, attach the blob\r\n // to the error object for use by a TileDiscardPolicy.\r\n // In particular, BingMapsImageryProvider uses this to detect the\r\n // zero-length response that is returned when a tile is not available.\r\n error.blob = generatedBlob;\r\n\r\n return when.reject(error);\r\n });\r\n};\r\n\r\n/**\r\n * Fetches an image and returns a promise to it.\r\n *\r\n * @param {Object} [options] An object with the following properties.\r\n * @param {Resource} [options.resource] Resource object that points to an image to fetch.\r\n * @param {Boolean} [options.preferImageBitmap] If true, image will be decoded during fetch and an ImageBitmap
is returned.\r\n * @param {Boolean} [options.flipY] If true, image will be vertically flipped during decode. Only applies if the browser supports createImageBitmap
.\r\n *\r\n * @private\r\n */\r\nfunction fetchImage(options) {\r\n var resource = options.resource;\r\n var flipY = options.flipY;\r\n var preferImageBitmap = options.preferImageBitmap;\r\n\r\n var request = resource.request;\r\n request.url = resource.url;\r\n request.requestFunction = function () {\r\n var crossOrigin = false;\r\n\r\n // data URIs can't have crossorigin set.\r\n if (!resource.isDataUri && !resource.isBlobUri) {\r\n crossOrigin = resource.isCrossOriginUrl;\r\n }\r\n\r\n var deferred = when.defer();\r\n Resource._Implementations.createImage(\r\n request,\r\n crossOrigin,\r\n deferred,\r\n flipY,\r\n preferImageBitmap\r\n );\r\n\r\n return deferred.promise;\r\n };\r\n\r\n var promise = RequestScheduler.request(request);\r\n if (!defined(promise)) {\r\n return;\r\n }\r\n\r\n return promise.otherwise(function (e) {\r\n // Don't retry cancelled or otherwise aborted requests\r\n if (request.state !== RequestState.FAILED) {\r\n return when.reject(e);\r\n }\r\n\r\n return resource.retryOnError(e).then(function (retry) {\r\n if (retry) {\r\n // Reset request so it can try again\r\n request.state = RequestState.UNISSUED;\r\n request.deferred = undefined;\r\n\r\n return fetchImage({\r\n resource: resource,\r\n flipY: flipY,\r\n preferImageBitmap: preferImageBitmap,\r\n });\r\n }\r\n\r\n return when.reject(e);\r\n });\r\n });\r\n}\r\n\r\n/**\r\n * Creates a Resource and calls fetchImage() on it.\r\n *\r\n * @param {String|Object} options A url or an object with the following properties\r\n * @param {String} options.url The url of the resource.\r\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\r\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\r\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\r\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\r\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
.\r\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.\r\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\r\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\r\n * @param {Boolean} [options.preferBlob=false] If true, we will load the image via a blob.\r\n * @param {Boolean} [options.preferImageBitmap=false] If true, image will be decoded during fetch and an ImageBitmap
is returned.\r\n * @returns {Promise.|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.\r\n */\r\nResource.fetchImage = function (options) {\r\n var resource = new Resource(options);\r\n return resource.fetchImage({\r\n flipY: options.flipY,\r\n preferBlob: options.preferBlob,\r\n preferImageBitmap: options.preferImageBitmap,\r\n });\r\n};\r\n\r\n/**\r\n * Asynchronously loads the given resource as text. Returns a promise that will resolve to\r\n * a String once loaded, or reject if the resource failed to load. The data is loaded\r\n * using XMLHttpRequest, which means that in order to make requests to another origin,\r\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\r\n *\r\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.\r\n *\r\n * @example\r\n * // load text from a URL, setting a custom header\r\n * var resource = new Resource({\r\n * url: 'http://someUrl.com/someJson.txt',\r\n * headers: {\r\n * 'X-Custom-Header' : 'some value'\r\n * }\r\n * });\r\n * resource.fetchText().then(function(text) {\r\n * // Do something with the text\r\n * }).otherwise(function(error) {\r\n * // an error occurred\r\n * });\r\n *\r\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest|XMLHttpRequest}\r\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\r\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\r\n */\r\nResource.prototype.fetchText = function () {\r\n return this.fetch({\r\n responseType: \"text\",\r\n });\r\n};\r\n\r\n/**\r\n * Creates a Resource and calls fetchText() on it.\r\n *\r\n * @param {String|Object} options A url or an object with the following properties\r\n * @param {String} options.url The url of the resource.\r\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\r\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\r\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\r\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\r\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.\r\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\r\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\r\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.\r\n */\r\nResource.fetchText = function (options) {\r\n var resource = new Resource(options);\r\n return resource.fetchText();\r\n};\r\n\r\n// note: */* below is */* but that ends the comment block early\r\n/**\r\n * Asynchronously loads the given resource as JSON. Returns a promise that will resolve to\r\n * a JSON object once loaded, or reject if the resource failed to load. The data is loaded\r\n * using XMLHttpRequest, which means that in order to make requests to another origin,\r\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled. This function\r\n * adds 'Accept: application/json,*/*;q=0.01' to the request headers, if not\r\n * already specified.\r\n *\r\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.\r\n *\r\n *\r\n * @example\r\n * resource.fetchJson().then(function(jsonData) {\r\n * // Do something with the JSON object\r\n * }).otherwise(function(error) {\r\n * // an error occurred\r\n * });\r\n *\r\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\r\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\r\n */\r\nResource.prototype.fetchJson = function () {\r\n var promise = this.fetch({\r\n responseType: \"text\",\r\n headers: {\r\n Accept: \"application/json,*/*;q=0.01\",\r\n },\r\n });\r\n\r\n if (!defined(promise)) {\r\n return undefined;\r\n }\r\n\r\n return promise.then(function (value) {\r\n if (!defined(value)) {\r\n return;\r\n }\r\n return JSON.parse(value);\r\n });\r\n};\r\n\r\n/**\r\n * Creates a Resource and calls fetchJson() on it.\r\n *\r\n * @param {String|Object} options A url or an object with the following properties\r\n * @param {String} options.url The url of the resource.\r\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\r\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\r\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\r\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\r\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.\r\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\r\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\r\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.\r\n */\r\nResource.fetchJson = function (options) {\r\n var resource = new Resource(options);\r\n return resource.fetchJson();\r\n};\r\n\r\n/**\r\n * Asynchronously loads the given resource as XML. Returns a promise that will resolve to\r\n * an XML Document once loaded, or reject if the resource failed to load. The data is loaded\r\n * using XMLHttpRequest, which means that in order to make requests to another origin,\r\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\r\n *\r\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.\r\n *\r\n *\r\n * @example\r\n * // load XML from a URL, setting a custom header\r\n * Cesium.loadXML('http://someUrl.com/someXML.xml', {\r\n * 'X-Custom-Header' : 'some value'\r\n * }).then(function(document) {\r\n * // Do something with the document\r\n * }).otherwise(function(error) {\r\n * // an error occurred\r\n * });\r\n *\r\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest|XMLHttpRequest}\r\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\r\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\r\n */\r\nResource.prototype.fetchXML = function () {\r\n return this.fetch({\r\n responseType: \"document\",\r\n overrideMimeType: \"text/xml\",\r\n });\r\n};\r\n\r\n/**\r\n * Creates a Resource and calls fetchXML() on it.\r\n *\r\n * @param {String|Object} options A url or an object with the following properties\r\n * @param {String} options.url The url of the resource.\r\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\r\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\r\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\r\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\r\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.\r\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\r\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\r\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.\r\n */\r\nResource.fetchXML = function (options) {\r\n var resource = new Resource(options);\r\n return resource.fetchXML();\r\n};\r\n\r\n/**\r\n * Requests a resource using JSONP.\r\n *\r\n * @param {String} [callbackParameterName='callback'] The callback parameter name that the server expects.\r\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.\r\n *\r\n *\r\n * @example\r\n * // load a data asynchronously\r\n * resource.fetchJsonp().then(function(data) {\r\n * // use the loaded data\r\n * }).otherwise(function(error) {\r\n * // an error occurred\r\n * });\r\n *\r\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\r\n */\r\nResource.prototype.fetchJsonp = function (callbackParameterName) {\r\n callbackParameterName = defaultValue(callbackParameterName, \"callback\");\r\n\r\n checkAndResetRequest(this.request);\r\n\r\n //generate a unique function name\r\n var functionName;\r\n do {\r\n functionName = \"loadJsonp\" + Math.random().toString().substring(2, 8);\r\n } while (defined(window[functionName]));\r\n\r\n return fetchJsonp(this, callbackParameterName, functionName);\r\n};\r\n\r\nfunction fetchJsonp(resource, callbackParameterName, functionName) {\r\n var callbackQuery = {};\r\n callbackQuery[callbackParameterName] = functionName;\r\n resource.setQueryParameters(callbackQuery);\r\n\r\n var request = resource.request;\r\n request.url = resource.url;\r\n request.requestFunction = function () {\r\n var deferred = when.defer();\r\n\r\n //assign a function with that name in the global scope\r\n window[functionName] = function (data) {\r\n deferred.resolve(data);\r\n\r\n try {\r\n delete window[functionName];\r\n } catch (e) {\r\n window[functionName] = undefined;\r\n }\r\n };\r\n\r\n Resource._Implementations.loadAndExecuteScript(\r\n resource.url,\r\n functionName,\r\n deferred\r\n );\r\n return deferred.promise;\r\n };\r\n\r\n var promise = RequestScheduler.request(request);\r\n if (!defined(promise)) {\r\n return;\r\n }\r\n\r\n return promise.otherwise(function (e) {\r\n if (request.state !== RequestState.FAILED) {\r\n return when.reject(e);\r\n }\r\n\r\n return resource.retryOnError(e).then(function (retry) {\r\n if (retry) {\r\n // Reset request so it can try again\r\n request.state = RequestState.UNISSUED;\r\n request.deferred = undefined;\r\n\r\n return fetchJsonp(resource, callbackParameterName, functionName);\r\n }\r\n\r\n return when.reject(e);\r\n });\r\n });\r\n}\r\n\r\n/**\r\n * Creates a Resource from a URL and calls fetchJsonp() on it.\r\n *\r\n * @param {String|Object} options A url or an object with the following properties\r\n * @param {String} options.url The url of the resource.\r\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\r\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\r\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\r\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\r\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.\r\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\r\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\r\n * @param {String} [options.callbackParameterName='callback'] The callback parameter name that the server expects.\r\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.\r\n */\r\nResource.fetchJsonp = function (options) {\r\n var resource = new Resource(options);\r\n return resource.fetchJsonp(options.callbackParameterName);\r\n};\r\n\r\n/**\r\n * @private\r\n */\r\nResource.prototype._makeRequest = function (options) {\r\n var resource = this;\r\n checkAndResetRequest(resource.request);\r\n\r\n var request = resource.request;\r\n request.url = resource.url;\r\n\r\n request.requestFunction = function () {\r\n var responseType = options.responseType;\r\n var headers = combine(options.headers, resource.headers);\r\n var overrideMimeType = options.overrideMimeType;\r\n var method = options.method;\r\n var data = options.data;\r\n var deferred = when.defer();\r\n var xhr = Resource._Implementations.loadWithXhr(\r\n resource.url,\r\n responseType,\r\n method,\r\n data,\r\n headers,\r\n deferred,\r\n overrideMimeType\r\n );\r\n if (defined(xhr) && defined(xhr.abort)) {\r\n request.cancelFunction = function () {\r\n xhr.abort();\r\n };\r\n }\r\n return deferred.promise;\r\n };\r\n\r\n var promise = RequestScheduler.request(request);\r\n if (!defined(promise)) {\r\n return;\r\n }\r\n\r\n return promise\r\n .then(function (data) {\r\n // explicitly set to undefined to ensure GC of request response data. See #8843\r\n request.cancelFunction = undefined;\r\n return data;\r\n })\r\n .otherwise(function (e) {\r\n request.cancelFunction = undefined;\r\n if (request.state !== RequestState.FAILED) {\r\n return when.reject(e);\r\n }\r\n\r\n return resource.retryOnError(e).then(function (retry) {\r\n if (retry) {\r\n // Reset request so it can try again\r\n request.state = RequestState.UNISSUED;\r\n request.deferred = undefined;\r\n\r\n return resource.fetch(options);\r\n }\r\n\r\n return when.reject(e);\r\n });\r\n });\r\n};\r\n\r\nvar dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;\r\n\r\nfunction decodeDataUriText(isBase64, data) {\r\n var result = decodeURIComponent(data);\r\n if (isBase64) {\r\n return atob(result);\r\n }\r\n return result;\r\n}\r\n\r\nfunction decodeDataUriArrayBuffer(isBase64, data) {\r\n var byteString = decodeDataUriText(isBase64, data);\r\n var buffer = new ArrayBuffer(byteString.length);\r\n var view = new Uint8Array(buffer);\r\n for (var i = 0; i < byteString.length; i++) {\r\n view[i] = byteString.charCodeAt(i);\r\n }\r\n return buffer;\r\n}\r\n\r\nfunction decodeDataUri(dataUriRegexResult, responseType) {\r\n responseType = defaultValue(responseType, \"\");\r\n var mimeType = dataUriRegexResult[1];\r\n var isBase64 = !!dataUriRegexResult[2];\r\n var data = dataUriRegexResult[3];\r\n\r\n switch (responseType) {\r\n case \"\":\r\n case \"text\":\r\n return decodeDataUriText(isBase64, data);\r\n case \"arraybuffer\":\r\n return decodeDataUriArrayBuffer(isBase64, data);\r\n case \"blob\":\r\n var buffer = decodeDataUriArrayBuffer(isBase64, data);\r\n return new Blob([buffer], {\r\n type: mimeType,\r\n });\r\n case \"document\":\r\n var parser = new DOMParser();\r\n return parser.parseFromString(\r\n decodeDataUriText(isBase64, data),\r\n mimeType\r\n );\r\n case \"json\":\r\n return JSON.parse(decodeDataUriText(isBase64, data));\r\n default:\r\n //>>includeStart('debug', pragmas.debug);\r\n throw new DeveloperError(\"Unhandled responseType: \" + responseType);\r\n //>>includeEnd('debug');\r\n }\r\n}\r\n\r\n/**\r\n * Asynchronously loads the given resource. Returns a promise that will resolve to\r\n * the result once loaded, or reject if the resource failed to load. The data is loaded\r\n * using XMLHttpRequest, which means that in order to make requests to another origin,\r\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled. It's recommended that you use\r\n * the more specific functions eg. fetchJson, fetchBlob, etc.\r\n *\r\n * @param {Object} [options] Object with the following properties:\r\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\r\n * @param {Object} [options.headers] Additional HTTP headers to send with the request, if any.\r\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\r\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.\r\n *\r\n *\r\n * @example\r\n * resource.fetch()\r\n * .then(function(body) {\r\n * // use the data\r\n * }).otherwise(function(error) {\r\n * // an error occurred\r\n * });\r\n *\r\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\r\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\r\n */\r\nResource.prototype.fetch = function (options) {\r\n options = defaultClone(options, {});\r\n options.method = \"GET\";\r\n\r\n return this._makeRequest(options);\r\n};\r\n\r\n/**\r\n * Creates a Resource from a URL and calls fetch() on it.\r\n *\r\n * @param {String|Object} options A url or an object with the following properties\r\n * @param {String} options.url The url of the resource.\r\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\r\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\r\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\r\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\r\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.\r\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\r\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\r\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\r\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\r\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.\r\n */\r\nResource.fetch = function (options) {\r\n var resource = new Resource(options);\r\n return resource.fetch({\r\n // Make copy of just the needed fields because headers can be passed to both the constructor and to fetch\r\n responseType: options.responseType,\r\n overrideMimeType: options.overrideMimeType,\r\n });\r\n};\r\n\r\n/**\r\n * Asynchronously deletes the given resource. Returns a promise that will resolve to\r\n * the result once loaded, or reject if the resource failed to load. The data is loaded\r\n * using XMLHttpRequest, which means that in order to make requests to another origin,\r\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\r\n *\r\n * @param {Object} [options] Object with the following properties:\r\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\r\n * @param {Object} [options.headers] Additional HTTP headers to send with the request, if any.\r\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\r\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.\r\n *\r\n *\r\n * @example\r\n * resource.delete()\r\n * .then(function(body) {\r\n * // use the data\r\n * }).otherwise(function(error) {\r\n * // an error occurred\r\n * });\r\n *\r\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\r\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\r\n */\r\nResource.prototype.delete = function (options) {\r\n options = defaultClone(options, {});\r\n options.method = \"DELETE\";\r\n\r\n return this._makeRequest(options);\r\n};\r\n\r\n/**\r\n * Creates a Resource from a URL and calls delete() on it.\r\n *\r\n * @param {String|Object} options A url or an object with the following properties\r\n * @param {String} options.url The url of the resource.\r\n * @param {Object} [options.data] Data that is posted with the resource.\r\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\r\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\r\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\r\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\r\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.\r\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\r\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\r\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\r\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\r\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.\r\n */\r\nResource.delete = function (options) {\r\n var resource = new Resource(options);\r\n return resource.delete({\r\n // Make copy of just the needed fields because headers can be passed to both the constructor and to fetch\r\n responseType: options.responseType,\r\n overrideMimeType: options.overrideMimeType,\r\n data: options.data,\r\n });\r\n};\r\n\r\n/**\r\n * Asynchronously gets headers the given resource. Returns a promise that will resolve to\r\n * the result once loaded, or reject if the resource failed to load. The data is loaded\r\n * using XMLHttpRequest, which means that in order to make requests to another origin,\r\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\r\n *\r\n * @param {Object} [options] Object with the following properties:\r\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\r\n * @param {Object} [options.headers] Additional HTTP headers to send with the request, if any.\r\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\r\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.\r\n *\r\n *\r\n * @example\r\n * resource.head()\r\n * .then(function(headers) {\r\n * // use the data\r\n * }).otherwise(function(error) {\r\n * // an error occurred\r\n * });\r\n *\r\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\r\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\r\n */\r\nResource.prototype.head = function (options) {\r\n options = defaultClone(options, {});\r\n options.method = \"HEAD\";\r\n\r\n return this._makeRequest(options);\r\n};\r\n\r\n/**\r\n * Creates a Resource from a URL and calls head() on it.\r\n *\r\n * @param {String|Object} options A url or an object with the following properties\r\n * @param {String} options.url The url of the resource.\r\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\r\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\r\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\r\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\r\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.\r\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\r\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\r\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\r\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\r\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.\r\n */\r\nResource.head = function (options) {\r\n var resource = new Resource(options);\r\n return resource.head({\r\n // Make copy of just the needed fields because headers can be passed to both the constructor and to fetch\r\n responseType: options.responseType,\r\n overrideMimeType: options.overrideMimeType,\r\n });\r\n};\r\n\r\n/**\r\n * Asynchronously gets options the given resource. Returns a promise that will resolve to\r\n * the result once loaded, or reject if the resource failed to load. The data is loaded\r\n * using XMLHttpRequest, which means that in order to make requests to another origin,\r\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\r\n *\r\n * @param {Object} [options] Object with the following properties:\r\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\r\n * @param {Object} [options.headers] Additional HTTP headers to send with the request, if any.\r\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\r\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.\r\n *\r\n *\r\n * @example\r\n * resource.options()\r\n * .then(function(headers) {\r\n * // use the data\r\n * }).otherwise(function(error) {\r\n * // an error occurred\r\n * });\r\n *\r\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\r\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\r\n */\r\nResource.prototype.options = function (options) {\r\n options = defaultClone(options, {});\r\n options.method = \"OPTIONS\";\r\n\r\n return this._makeRequest(options);\r\n};\r\n\r\n/**\r\n * Creates a Resource from a URL and calls options() on it.\r\n *\r\n * @param {String|Object} options A url or an object with the following properties\r\n * @param {String} options.url The url of the resource.\r\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\r\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\r\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\r\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\r\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.\r\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\r\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\r\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\r\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\r\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.\r\n */\r\nResource.options = function (options) {\r\n var resource = new Resource(options);\r\n return resource.options({\r\n // Make copy of just the needed fields because headers can be passed to both the constructor and to fetch\r\n responseType: options.responseType,\r\n overrideMimeType: options.overrideMimeType,\r\n });\r\n};\r\n\r\n/**\r\n * Asynchronously posts data to the given resource. Returns a promise that will resolve to\r\n * the result once loaded, or reject if the resource failed to load. The data is loaded\r\n * using XMLHttpRequest, which means that in order to make requests to another origin,\r\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\r\n *\r\n * @param {Object} data Data that is posted with the resource.\r\n * @param {Object} [options] Object with the following properties:\r\n * @param {Object} [options.data] Data that is posted with the resource.\r\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\r\n * @param {Object} [options.headers] Additional HTTP headers to send with the request, if any.\r\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\r\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.\r\n *\r\n *\r\n * @example\r\n * resource.post(data)\r\n * .then(function(result) {\r\n * // use the result\r\n * }).otherwise(function(error) {\r\n * // an error occurred\r\n * });\r\n *\r\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\r\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\r\n */\r\nResource.prototype.post = function (data, options) {\r\n Check.defined(\"data\", data);\r\n\r\n options = defaultClone(options, {});\r\n options.method = \"POST\";\r\n options.data = data;\r\n\r\n return this._makeRequest(options);\r\n};\r\n\r\n/**\r\n * Creates a Resource from a URL and calls post() on it.\r\n *\r\n * @param {Object} options A url or an object with the following properties\r\n * @param {String} options.url The url of the resource.\r\n * @param {Object} options.data Data that is posted with the resource.\r\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\r\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\r\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\r\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\r\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.\r\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\r\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\r\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\r\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\r\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.\r\n */\r\nResource.post = function (options) {\r\n var resource = new Resource(options);\r\n return resource.post(options.data, {\r\n // Make copy of just the needed fields because headers can be passed to both the constructor and to post\r\n responseType: options.responseType,\r\n overrideMimeType: options.overrideMimeType,\r\n });\r\n};\r\n\r\n/**\r\n * Asynchronously puts data to the given resource. Returns a promise that will resolve to\r\n * the result once loaded, or reject if the resource failed to load. The data is loaded\r\n * using XMLHttpRequest, which means that in order to make requests to another origin,\r\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\r\n *\r\n * @param {Object} data Data that is posted with the resource.\r\n * @param {Object} [options] Object with the following properties:\r\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\r\n * @param {Object} [options.headers] Additional HTTP headers to send with the request, if any.\r\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\r\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.\r\n *\r\n *\r\n * @example\r\n * resource.put(data)\r\n * .then(function(result) {\r\n * // use the result\r\n * }).otherwise(function(error) {\r\n * // an error occurred\r\n * });\r\n *\r\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\r\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\r\n */\r\nResource.prototype.put = function (data, options) {\r\n Check.defined(\"data\", data);\r\n\r\n options = defaultClone(options, {});\r\n options.method = \"PUT\";\r\n options.data = data;\r\n\r\n return this._makeRequest(options);\r\n};\r\n\r\n/**\r\n * Creates a Resource from a URL and calls put() on it.\r\n *\r\n * @param {Object} options A url or an object with the following properties\r\n * @param {String} options.url The url of the resource.\r\n * @param {Object} options.data Data that is posted with the resource.\r\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\r\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\r\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\r\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\r\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.\r\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\r\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\r\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\r\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\r\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.\r\n */\r\nResource.put = function (options) {\r\n var resource = new Resource(options);\r\n return resource.put(options.data, {\r\n // Make copy of just the needed fields because headers can be passed to both the constructor and to post\r\n responseType: options.responseType,\r\n overrideMimeType: options.overrideMimeType,\r\n });\r\n};\r\n\r\n/**\r\n * Asynchronously patches data to the given resource. Returns a promise that will resolve to\r\n * the result once loaded, or reject if the resource failed to load. The data is loaded\r\n * using XMLHttpRequest, which means that in order to make requests to another origin,\r\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\r\n *\r\n * @param {Object} data Data that is posted with the resource.\r\n * @param {Object} [options] Object with the following properties:\r\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\r\n * @param {Object} [options.headers] Additional HTTP headers to send with the request, if any.\r\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\r\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.\r\n *\r\n *\r\n * @example\r\n * resource.patch(data)\r\n * .then(function(result) {\r\n * // use the result\r\n * }).otherwise(function(error) {\r\n * // an error occurred\r\n * });\r\n *\r\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\r\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\r\n */\r\nResource.prototype.patch = function (data, options) {\r\n Check.defined(\"data\", data);\r\n\r\n options = defaultClone(options, {});\r\n options.method = \"PATCH\";\r\n options.data = data;\r\n\r\n return this._makeRequest(options);\r\n};\r\n\r\n/**\r\n * Creates a Resource from a URL and calls patch() on it.\r\n *\r\n * @param {Object} options A url or an object with the following properties\r\n * @param {String} options.url The url of the resource.\r\n * @param {Object} options.data Data that is posted with the resource.\r\n * @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\r\n * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\r\n * @param {Object} [options.headers={}] Additional HTTP headers that will be sent.\r\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\r\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.\r\n * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\r\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\r\n * @param {String} [options.responseType] The type of response. This controls the type of item returned.\r\n * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.\r\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.\r\n */\r\nResource.patch = function (options) {\r\n var resource = new Resource(options);\r\n return resource.patch(options.data, {\r\n // Make copy of just the needed fields because headers can be passed to both the constructor and to post\r\n responseType: options.responseType,\r\n overrideMimeType: options.overrideMimeType,\r\n });\r\n};\r\n\r\n/**\r\n * Contains implementations of functions that can be replaced for testing\r\n *\r\n * @private\r\n */\r\nResource._Implementations = {};\r\n\r\nfunction loadImageElement(url, crossOrigin, deferred) {\r\n var image = new Image();\r\n\r\n image.onload = function () {\r\n deferred.resolve(image);\r\n };\r\n\r\n image.onerror = function (e) {\r\n deferred.reject(e);\r\n };\r\n\r\n if (crossOrigin) {\r\n if (TrustedServers.contains(url)) {\r\n image.crossOrigin = \"use-credentials\";\r\n } else {\r\n image.crossOrigin = \"\";\r\n }\r\n }\r\n\r\n image.src = url;\r\n}\r\n\r\nResource._Implementations.createImage = function (\r\n request,\r\n crossOrigin,\r\n deferred,\r\n flipY,\r\n preferImageBitmap\r\n) {\r\n var url = request.url;\r\n // Passing an Image to createImageBitmap will force it to run on the main thread\r\n // since DOM elements don't exist on workers. We convert it to a blob so it's non-blocking.\r\n // See:\r\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1044102#c38\r\n // https://bugs.chromium.org/p/chromium/issues/detail?id=580202#c10\r\n Resource.supportsImageBitmapOptions()\r\n .then(function (supportsImageBitmap) {\r\n // We can only use ImageBitmap if we can flip on decode.\r\n // See: https://github.com/CesiumGS/cesium/pull/7579#issuecomment-466146898\r\n if (!(supportsImageBitmap && preferImageBitmap)) {\r\n loadImageElement(url, crossOrigin, deferred);\r\n return;\r\n }\r\n var responseType = \"blob\";\r\n var method = \"GET\";\r\n var xhrDeferred = when.defer();\r\n var xhr = Resource._Implementations.loadWithXhr(\r\n url,\r\n responseType,\r\n method,\r\n undefined,\r\n undefined,\r\n xhrDeferred,\r\n undefined,\r\n undefined,\r\n undefined\r\n );\r\n\r\n if (defined(xhr) && defined(xhr.abort)) {\r\n request.cancelFunction = function () {\r\n xhr.abort();\r\n };\r\n }\r\n return xhrDeferred.promise\r\n .then(function (blob) {\r\n if (!defined(blob)) {\r\n deferred.reject(\r\n new RuntimeError(\r\n \"Successfully retrieved \" +\r\n url +\r\n \" but it contained no content.\"\r\n )\r\n );\r\n return;\r\n }\r\n\r\n return Resource.createImageBitmapFromBlob(blob, {\r\n flipY: flipY,\r\n premultiplyAlpha: false,\r\n });\r\n })\r\n .then(deferred.resolve);\r\n })\r\n .otherwise(deferred.reject);\r\n};\r\n\r\n/**\r\n * Wrapper for createImageBitmap\r\n *\r\n * @private\r\n */\r\nResource.createImageBitmapFromBlob = function (blob, options) {\r\n Check.defined(\"options\", options);\r\n Check.typeOf.bool(\"options.flipY\", options.flipY);\r\n Check.typeOf.bool(\"options.premultiplyAlpha\", options.premultiplyAlpha);\r\n\r\n return createImageBitmap(blob, {\r\n imageOrientation: options.flipY ? \"flipY\" : \"none\",\r\n premultiplyAlpha: options.premultiplyAlpha ? \"premultiply\" : \"none\",\r\n });\r\n};\r\n\r\nfunction decodeResponse(loadWithHttpResponse, responseType) {\r\n switch (responseType) {\r\n case \"text\":\r\n return loadWithHttpResponse.toString(\"utf8\");\r\n case \"json\":\r\n return JSON.parse(loadWithHttpResponse.toString(\"utf8\"));\r\n default:\r\n return new Uint8Array(loadWithHttpResponse).buffer;\r\n }\r\n}\r\n\r\nfunction loadWithHttpRequest(\r\n url,\r\n responseType,\r\n method,\r\n data,\r\n headers,\r\n deferred,\r\n overrideMimeType\r\n) {\r\n // Note: only the 'json' and 'text' responseTypes transforms the loaded buffer\r\n /* eslint-disable no-undef */\r\n var URL = require(\"url\").parse(url);\r\n var http = URL.protocol === \"https:\" ? require(\"https\") : require(\"http\");\r\n var zlib = require(\"zlib\");\r\n /* eslint-enable no-undef */\r\n\r\n var options = {\r\n protocol: URL.protocol,\r\n hostname: URL.hostname,\r\n port: URL.port,\r\n path: URL.path,\r\n query: URL.query,\r\n method: method,\r\n headers: headers,\r\n };\r\n\r\n http\r\n .request(options)\r\n .on(\"response\", function (res) {\r\n if (res.statusCode < 200 || res.statusCode >= 300) {\r\n deferred.reject(\r\n new RequestErrorEvent(res.statusCode, res, res.headers)\r\n );\r\n return;\r\n }\r\n\r\n var chunkArray = [];\r\n res.on(\"data\", function (chunk) {\r\n chunkArray.push(chunk);\r\n });\r\n\r\n res.on(\"end\", function () {\r\n // eslint-disable-next-line no-undef\r\n var result = Buffer.concat(chunkArray);\r\n if (res.headers[\"content-encoding\"] === \"gzip\") {\r\n zlib.gunzip(result, function (error, resultUnzipped) {\r\n if (error) {\r\n deferred.reject(\r\n new RuntimeError(\"Error decompressing response.\")\r\n );\r\n } else {\r\n deferred.resolve(decodeResponse(resultUnzipped, responseType));\r\n }\r\n });\r\n } else {\r\n deferred.resolve(decodeResponse(result, responseType));\r\n }\r\n });\r\n })\r\n .on(\"error\", function (e) {\r\n deferred.reject(new RequestErrorEvent());\r\n })\r\n .end();\r\n}\r\n\r\nvar noXMLHttpRequest = typeof XMLHttpRequest === \"undefined\";\r\nResource._Implementations.loadWithXhr = function (\r\n url,\r\n responseType,\r\n method,\r\n data,\r\n headers,\r\n deferred,\r\n overrideMimeType\r\n) {\r\n var dataUriRegexResult = dataUriRegex.exec(url);\r\n if (dataUriRegexResult !== null) {\r\n deferred.resolve(decodeDataUri(dataUriRegexResult, responseType));\r\n return;\r\n }\r\n\r\n if (noXMLHttpRequest) {\r\n loadWithHttpRequest(\r\n url,\r\n responseType,\r\n method,\r\n data,\r\n headers,\r\n deferred,\r\n overrideMimeType\r\n );\r\n return;\r\n }\r\n\r\n var xhr = new XMLHttpRequest();\r\n\r\n if (TrustedServers.contains(url)) {\r\n xhr.withCredentials = true;\r\n }\r\n\r\n xhr.open(method, url, true);\r\n\r\n if (defined(overrideMimeType) && defined(xhr.overrideMimeType)) {\r\n xhr.overrideMimeType(overrideMimeType);\r\n }\r\n\r\n if (defined(headers)) {\r\n for (var key in headers) {\r\n if (headers.hasOwnProperty(key)) {\r\n xhr.setRequestHeader(key, headers[key]);\r\n }\r\n }\r\n }\r\n\r\n if (defined(responseType)) {\r\n xhr.responseType = responseType;\r\n }\r\n\r\n // While non-standard, file protocol always returns a status of 0 on success\r\n var localFile = false;\r\n if (typeof url === \"string\") {\r\n localFile =\r\n url.indexOf(\"file://\") === 0 ||\r\n (typeof window !== \"undefined\" && window.location.origin === \"file://\");\r\n }\r\n\r\n xhr.onload = function () {\r\n if (\r\n (xhr.status < 200 || xhr.status >= 300) &&\r\n !(localFile && xhr.status === 0)\r\n ) {\r\n deferred.reject(\r\n new RequestErrorEvent(\r\n xhr.status,\r\n xhr.response,\r\n xhr.getAllResponseHeaders()\r\n )\r\n );\r\n return;\r\n }\r\n\r\n var response = xhr.response;\r\n var browserResponseType = xhr.responseType;\r\n\r\n if (method === \"HEAD\" || method === \"OPTIONS\") {\r\n var responseHeaderString = xhr.getAllResponseHeaders();\r\n var splitHeaders = responseHeaderString.trim().split(/[\\r\\n]+/);\r\n\r\n var responseHeaders = {};\r\n splitHeaders.forEach(function (line) {\r\n var parts = line.split(\": \");\r\n var header = parts.shift();\r\n responseHeaders[header] = parts.join(\": \");\r\n });\r\n\r\n deferred.resolve(responseHeaders);\r\n return;\r\n }\r\n\r\n //All modern browsers will go into either the first or second if block or last else block.\r\n //Other code paths support older browsers that either do not support the supplied responseType\r\n //or do not support the xhr.response property.\r\n if (xhr.status === 204) {\r\n // accept no content\r\n deferred.resolve();\r\n } else if (\r\n defined(response) &&\r\n (!defined(responseType) || browserResponseType === responseType)\r\n ) {\r\n deferred.resolve(response);\r\n } else if (responseType === \"json\" && typeof response === \"string\") {\r\n try {\r\n deferred.resolve(JSON.parse(response));\r\n } catch (e) {\r\n deferred.reject(e);\r\n }\r\n } else if (\r\n (browserResponseType === \"\" || browserResponseType === \"document\") &&\r\n defined(xhr.responseXML) &&\r\n xhr.responseXML.hasChildNodes()\r\n ) {\r\n deferred.resolve(xhr.responseXML);\r\n } else if (\r\n (browserResponseType === \"\" || browserResponseType === \"text\") &&\r\n defined(xhr.responseText)\r\n ) {\r\n deferred.resolve(xhr.responseText);\r\n } else {\r\n deferred.reject(\r\n new RuntimeError(\"Invalid XMLHttpRequest response type.\")\r\n );\r\n }\r\n };\r\n\r\n xhr.onerror = function (e) {\r\n deferred.reject(new RequestErrorEvent());\r\n };\r\n\r\n xhr.send(data);\r\n\r\n return xhr;\r\n};\r\n\r\nResource._Implementations.loadAndExecuteScript = function (\r\n url,\r\n functionName,\r\n deferred\r\n) {\r\n return loadAndExecuteScript(url, functionName).otherwise(deferred.reject);\r\n};\r\n\r\n/**\r\n * The default implementations\r\n *\r\n * @private\r\n */\r\nResource._DefaultImplementations = {};\r\nResource._DefaultImplementations.createImage =\r\n Resource._Implementations.createImage;\r\nResource._DefaultImplementations.loadWithXhr =\r\n Resource._Implementations.loadWithXhr;\r\nResource._DefaultImplementations.loadAndExecuteScript =\r\n Resource._Implementations.loadAndExecuteScript;\r\n\r\n/**\r\n * A resource instance initialized to the current browser location\r\n *\r\n * @type {Resource}\r\n * @constant\r\n */\r\nResource.DEFAULT = Object.freeze(\r\n new Resource({\r\n url:\r\n typeof document === \"undefined\"\r\n ? \"\"\r\n : document.location.href.split(\"?\")[0],\r\n })\r\n);\r\n\r\n/**\r\n * A function that returns the value of the property.\r\n * @callback Resource.RetryCallback\r\n *\r\n * @param {Resource} [resource] The resource that failed to load.\r\n * @param {Error} [error] The error that occurred during the loading of the resource.\r\n * @returns {Boolean|Promise} If true or a promise that resolved to true, the resource will be retried. Otherwise the failure will be returned.\r\n */\r\nexport default Resource;\r\n","import defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport getAbsoluteUri from \"./getAbsoluteUri.js\";\r\nimport Resource from \"./Resource.js\";\r\n\r\n/*global CESIUM_BASE_URL*/\r\n\r\nvar cesiumScriptRegex = /((?:.*\\/)|^)Cesium\\.js(?:\\?|\\#|$)/;\r\nfunction getBaseUrlFromCesiumScript() {\r\n var scripts = document.getElementsByTagName(\"script\");\r\n for (var i = 0, len = scripts.length; i < len; ++i) {\r\n var src = scripts[i].getAttribute(\"src\");\r\n var result = cesiumScriptRegex.exec(src);\r\n if (result !== null) {\r\n return result[1];\r\n }\r\n }\r\n return undefined;\r\n}\r\n\r\nvar a;\r\nfunction tryMakeAbsolute(url) {\r\n if (typeof document === \"undefined\") {\r\n //Node.js and Web Workers. In both cases, the URL will already be absolute.\r\n return url;\r\n }\r\n\r\n if (!defined(a)) {\r\n a = document.createElement(\"a\");\r\n }\r\n a.href = url;\r\n\r\n // IE only absolutizes href on get, not set\r\n // eslint-disable-next-line no-self-assign\r\n a.href = a.href;\r\n return a.href;\r\n}\r\n\r\nvar baseResource;\r\nfunction getCesiumBaseUrl() {\r\n if (defined(baseResource)) {\r\n return baseResource;\r\n }\r\n\r\n var baseUrlString;\r\n if (typeof CESIUM_BASE_URL !== \"undefined\") {\r\n baseUrlString = CESIUM_BASE_URL;\r\n } else if (\r\n typeof define === \"object\" &&\r\n defined(define.amd) &&\r\n !define.amd.toUrlUndefined &&\r\n defined(require.toUrl)\r\n ) {\r\n baseUrlString = getAbsoluteUri(\r\n \"..\",\r\n buildModuleUrl(\"Core/buildModuleUrl.js\")\r\n );\r\n } else {\r\n baseUrlString = getBaseUrlFromCesiumScript();\r\n }\r\n\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(baseUrlString)) {\r\n throw new DeveloperError(\r\n \"Unable to determine Cesium base URL automatically, try defining a global variable called CESIUM_BASE_URL.\"\r\n );\r\n }\r\n //>>includeEnd('debug');\r\n\r\n baseResource = new Resource({\r\n url: tryMakeAbsolute(baseUrlString),\r\n });\r\n baseResource.appendForwardSlash();\r\n\r\n return baseResource;\r\n}\r\n\r\nfunction buildModuleUrlFromRequireToUrl(moduleID) {\r\n //moduleID will be non-relative, so require it relative to this module, in Core.\r\n return tryMakeAbsolute(require.toUrl(\"../\" + moduleID));\r\n}\r\n\r\nfunction buildModuleUrlFromBaseUrl(moduleID) {\r\n var resource = getCesiumBaseUrl().getDerivedResource({\r\n url: moduleID,\r\n });\r\n return resource.url;\r\n}\r\n\r\nvar implementation;\r\n\r\n/**\r\n * Given a relative URL under the Cesium base URL, returns an absolute URL.\r\n * @function\r\n *\r\n * @param {String} relativeUrl The relative path.\r\n * @returns {String} The absolutely URL representation of the provided path.\r\n *\r\n * @example\r\n * var viewer = new Cesium.Viewer(\"cesiumContainer\", {\r\n * imageryProvider: new Cesium.TileMapServiceImageryProvider({\r\n * url: Cesium.buildModuleUrl(\"Assets/Textures/NaturalEarthII\"),\r\n * }),\r\n * baseLayerPicker: false,\r\n * });\r\n */\r\nfunction buildModuleUrl(relativeUrl) {\r\n if (!defined(implementation)) {\r\n //select implementation\r\n if (\r\n typeof define === \"object\" &&\r\n defined(define.amd) &&\r\n !define.amd.toUrlUndefined &&\r\n defined(require.toUrl)\r\n ) {\r\n implementation = buildModuleUrlFromRequireToUrl;\r\n } else {\r\n implementation = buildModuleUrlFromBaseUrl;\r\n }\r\n }\r\n\r\n var url = implementation(relativeUrl);\r\n return url;\r\n}\r\n\r\n// exposed for testing\r\nbuildModuleUrl._cesiumScriptRegex = cesiumScriptRegex;\r\nbuildModuleUrl._buildModuleUrlFromBaseUrl = buildModuleUrlFromBaseUrl;\r\nbuildModuleUrl._clearBaseResource = function () {\r\n baseResource = undefined;\r\n};\r\n\r\n/**\r\n * Sets the base URL for resolving modules.\r\n * @param {String} value The new base URL.\r\n */\r\nbuildModuleUrl.setBaseUrl = function (value) {\r\n baseResource = Resource.DEFAULT.getDerivedResource({\r\n url: value,\r\n });\r\n};\r\n\r\n/**\r\n * Gets the base URL for resolving modules.\r\n */\r\nbuildModuleUrl.getCesiumBaseUrl = getCesiumBaseUrl;\r\n\r\nexport default buildModuleUrl;\r\n","import Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport CesiumMath from \"./Math.js\";\r\n\r\n/**\r\n * A 2D Cartesian point.\r\n * @alias Cartesian2\r\n * @constructor\r\n *\r\n * @param {Number} [x=0.0] The X component.\r\n * @param {Number} [y=0.0] The Y component.\r\n *\r\n * @see Cartesian3\r\n * @see Cartesian4\r\n * @see Packable\r\n */\r\nfunction Cartesian2(x, y) {\r\n /**\r\n * The X component.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.x = defaultValue(x, 0.0);\r\n\r\n /**\r\n * The Y component.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.y = defaultValue(y, 0.0);\r\n}\r\n\r\n/**\r\n * Creates a Cartesian2 instance from x and y coordinates.\r\n *\r\n * @param {Number} x The x coordinate.\r\n * @param {Number} y The y coordinate.\r\n * @param {Cartesian2} [result] The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.\r\n */\r\nCartesian2.fromElements = function (x, y, result) {\r\n if (!defined(result)) {\r\n return new Cartesian2(x, y);\r\n }\r\n\r\n result.x = x;\r\n result.y = y;\r\n return result;\r\n};\r\n\r\n/**\r\n * Duplicates a Cartesian2 instance.\r\n *\r\n * @param {Cartesian2} cartesian The Cartesian to duplicate.\r\n * @param {Cartesian2} [result] The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided. (Returns undefined if cartesian is undefined)\r\n */\r\nCartesian2.clone = function (cartesian, result) {\r\n if (!defined(cartesian)) {\r\n return undefined;\r\n }\r\n if (!defined(result)) {\r\n return new Cartesian2(cartesian.x, cartesian.y);\r\n }\r\n\r\n result.x = cartesian.x;\r\n result.y = cartesian.y;\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a Cartesian2 instance from an existing Cartesian3. This simply takes the\r\n * x and y properties of the Cartesian3 and drops z.\r\n * @function\r\n *\r\n * @param {Cartesian3} cartesian The Cartesian3 instance to create a Cartesian2 instance from.\r\n * @param {Cartesian2} [result] The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.\r\n */\r\nCartesian2.fromCartesian3 = Cartesian2.clone;\r\n\r\n/**\r\n * Creates a Cartesian2 instance from an existing Cartesian4. This simply takes the\r\n * x and y properties of the Cartesian4 and drops z and w.\r\n * @function\r\n *\r\n * @param {Cartesian4} cartesian The Cartesian4 instance to create a Cartesian2 instance from.\r\n * @param {Cartesian2} [result] The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.\r\n */\r\nCartesian2.fromCartesian4 = Cartesian2.clone;\r\n\r\n/**\r\n * The number of elements used to pack the object into an array.\r\n * @type {Number}\r\n */\r\nCartesian2.packedLength = 2;\r\n\r\n/**\r\n * Stores the provided instance into the provided array.\r\n *\r\n * @param {Cartesian2} value The value to pack.\r\n * @param {Number[]} array The array to pack into.\r\n * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.\r\n *\r\n * @returns {Number[]} The array that was packed into\r\n */\r\nCartesian2.pack = function (value, array, startingIndex) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"value\", value);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n array[startingIndex++] = value.x;\r\n array[startingIndex] = value.y;\r\n\r\n return array;\r\n};\r\n\r\n/**\r\n * Retrieves an instance from a packed array.\r\n *\r\n * @param {Number[]} array The packed array.\r\n * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.\r\n * @param {Cartesian2} [result] The object into which to store the result.\r\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.\r\n */\r\nCartesian2.unpack = function (array, startingIndex, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian2();\r\n }\r\n result.x = array[startingIndex++];\r\n result.y = array[startingIndex];\r\n return result;\r\n};\r\n\r\n/**\r\n * Flattens an array of Cartesian2s into and array of components.\r\n *\r\n * @param {Cartesian2[]} array The array of cartesians to pack.\r\n * @param {Number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 2 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 2) elements.\r\n\r\n * @returns {Number[]} The packed array.\r\n */\r\nCartesian2.packArray = function (array, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n var length = array.length;\r\n var resultLength = length * 2;\r\n if (!defined(result)) {\r\n result = new Array(resultLength);\r\n } else if (!Array.isArray(result) && result.length !== resultLength) {\r\n throw new DeveloperError(\r\n \"If result is a typed array, it must have exactly array.length * 2 elements\"\r\n );\r\n } else if (result.length !== resultLength) {\r\n result.length = resultLength;\r\n }\r\n\r\n for (var i = 0; i < length; ++i) {\r\n Cartesian2.pack(array[i], result, i * 2);\r\n }\r\n return result;\r\n};\r\n\r\n/**\r\n * Unpacks an array of cartesian components into and array of Cartesian2s.\r\n *\r\n * @param {Number[]} array The array of components to unpack.\r\n * @param {Cartesian2[]} [result] The array onto which to store the result.\r\n * @returns {Cartesian2[]} The unpacked array.\r\n */\r\nCartesian2.unpackArray = function (array, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n Check.typeOf.number.greaterThanOrEquals(\"array.length\", array.length, 2);\r\n if (array.length % 2 !== 0) {\r\n throw new DeveloperError(\"array length must be a multiple of 2.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var length = array.length;\r\n if (!defined(result)) {\r\n result = new Array(length / 2);\r\n } else {\r\n result.length = length / 2;\r\n }\r\n\r\n for (var i = 0; i < length; i += 2) {\r\n var index = i / 2;\r\n result[index] = Cartesian2.unpack(array, i, result[index]);\r\n }\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a Cartesian2 from two consecutive elements in an array.\r\n * @function\r\n *\r\n * @param {Number[]} array The array whose two consecutive elements correspond to the x and y components, respectively.\r\n * @param {Number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.\r\n * @param {Cartesian2} [result] The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.\r\n *\r\n * @example\r\n * // Create a Cartesian2 with (1.0, 2.0)\r\n * var v = [1.0, 2.0];\r\n * var p = Cesium.Cartesian2.fromArray(v);\r\n *\r\n * // Create a Cartesian2 with (1.0, 2.0) using an offset into an array\r\n * var v2 = [0.0, 0.0, 1.0, 2.0];\r\n * var p2 = Cesium.Cartesian2.fromArray(v2, 2);\r\n */\r\nCartesian2.fromArray = Cartesian2.unpack;\r\n\r\n/**\r\n * Computes the value of the maximum component for the supplied Cartesian.\r\n *\r\n * @param {Cartesian2} cartesian The cartesian to use.\r\n * @returns {Number} The value of the maximum component.\r\n */\r\nCartesian2.maximumComponent = function (cartesian) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n //>>includeEnd('debug');\r\n\r\n return Math.max(cartesian.x, cartesian.y);\r\n};\r\n\r\n/**\r\n * Computes the value of the minimum component for the supplied Cartesian.\r\n *\r\n * @param {Cartesian2} cartesian The cartesian to use.\r\n * @returns {Number} The value of the minimum component.\r\n */\r\nCartesian2.minimumComponent = function (cartesian) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n //>>includeEnd('debug');\r\n\r\n return Math.min(cartesian.x, cartesian.y);\r\n};\r\n\r\n/**\r\n * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.\r\n *\r\n * @param {Cartesian2} first A cartesian to compare.\r\n * @param {Cartesian2} second A cartesian to compare.\r\n * @param {Cartesian2} result The object into which to store the result.\r\n * @returns {Cartesian2} A cartesian with the minimum components.\r\n */\r\nCartesian2.minimumByComponent = function (first, second, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"first\", first);\r\n Check.typeOf.object(\"second\", second);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = Math.min(first.x, second.x);\r\n result.y = Math.min(first.y, second.y);\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.\r\n *\r\n * @param {Cartesian2} first A cartesian to compare.\r\n * @param {Cartesian2} second A cartesian to compare.\r\n * @param {Cartesian2} result The object into which to store the result.\r\n * @returns {Cartesian2} A cartesian with the maximum components.\r\n */\r\nCartesian2.maximumByComponent = function (first, second, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"first\", first);\r\n Check.typeOf.object(\"second\", second);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = Math.max(first.x, second.x);\r\n result.y = Math.max(first.y, second.y);\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the provided Cartesian's squared magnitude.\r\n *\r\n * @param {Cartesian2} cartesian The Cartesian instance whose squared magnitude is to be computed.\r\n * @returns {Number} The squared magnitude.\r\n */\r\nCartesian2.magnitudeSquared = function (cartesian) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n //>>includeEnd('debug');\r\n\r\n return cartesian.x * cartesian.x + cartesian.y * cartesian.y;\r\n};\r\n\r\n/**\r\n * Computes the Cartesian's magnitude (length).\r\n *\r\n * @param {Cartesian2} cartesian The Cartesian instance whose magnitude is to be computed.\r\n * @returns {Number} The magnitude.\r\n */\r\nCartesian2.magnitude = function (cartesian) {\r\n return Math.sqrt(Cartesian2.magnitudeSquared(cartesian));\r\n};\r\n\r\nvar distanceScratch = new Cartesian2();\r\n\r\n/**\r\n * Computes the distance between two points.\r\n *\r\n * @param {Cartesian2} left The first point to compute the distance from.\r\n * @param {Cartesian2} right The second point to compute the distance to.\r\n * @returns {Number} The distance between two points.\r\n *\r\n * @example\r\n * // Returns 1.0\r\n * var d = Cesium.Cartesian2.distance(new Cesium.Cartesian2(1.0, 0.0), new Cesium.Cartesian2(2.0, 0.0));\r\n */\r\nCartesian2.distance = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n //>>includeEnd('debug');\r\n\r\n Cartesian2.subtract(left, right, distanceScratch);\r\n return Cartesian2.magnitude(distanceScratch);\r\n};\r\n\r\n/**\r\n * Computes the squared distance between two points. Comparing squared distances\r\n * using this function is more efficient than comparing distances using {@link Cartesian2#distance}.\r\n *\r\n * @param {Cartesian2} left The first point to compute the distance from.\r\n * @param {Cartesian2} right The second point to compute the distance to.\r\n * @returns {Number} The distance between two points.\r\n *\r\n * @example\r\n * // Returns 4.0, not 2.0\r\n * var d = Cesium.Cartesian2.distance(new Cesium.Cartesian2(1.0, 0.0), new Cesium.Cartesian2(3.0, 0.0));\r\n */\r\nCartesian2.distanceSquared = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n //>>includeEnd('debug');\r\n\r\n Cartesian2.subtract(left, right, distanceScratch);\r\n return Cartesian2.magnitudeSquared(distanceScratch);\r\n};\r\n\r\n/**\r\n * Computes the normalized form of the supplied Cartesian.\r\n *\r\n * @param {Cartesian2} cartesian The Cartesian to be normalized.\r\n * @param {Cartesian2} result The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter.\r\n */\r\nCartesian2.normalize = function (cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var magnitude = Cartesian2.magnitude(cartesian);\r\n\r\n result.x = cartesian.x / magnitude;\r\n result.y = cartesian.y / magnitude;\r\n\r\n //>>includeStart('debug', pragmas.debug);\r\n if (isNaN(result.x) || isNaN(result.y)) {\r\n throw new DeveloperError(\"normalized result is not a number\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the dot (scalar) product of two Cartesians.\r\n *\r\n * @param {Cartesian2} left The first Cartesian.\r\n * @param {Cartesian2} right The second Cartesian.\r\n * @returns {Number} The dot product.\r\n */\r\nCartesian2.dot = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n //>>includeEnd('debug');\r\n\r\n return left.x * right.x + left.y * right.y;\r\n};\r\n\r\n/**\r\n * Computes the magnitude of the cross product that would result from implicitly setting the Z coordinate of the input vectors to 0\r\n *\r\n * @param {Cartesian2} left The first Cartesian.\r\n * @param {Cartesian2} right The second Cartesian.\r\n * @returns {Number} The cross product.\r\n */\r\nCartesian2.cross = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n //>>includeEnd('debug');\r\n\r\n return left.x * right.y - left.y * right.x;\r\n};\r\n\r\n/**\r\n * Computes the componentwise product of two Cartesians.\r\n *\r\n * @param {Cartesian2} left The first Cartesian.\r\n * @param {Cartesian2} right The second Cartesian.\r\n * @param {Cartesian2} result The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter.\r\n */\r\nCartesian2.multiplyComponents = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = left.x * right.x;\r\n result.y = left.y * right.y;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the componentwise quotient of two Cartesians.\r\n *\r\n * @param {Cartesian2} left The first Cartesian.\r\n * @param {Cartesian2} right The second Cartesian.\r\n * @param {Cartesian2} result The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter.\r\n */\r\nCartesian2.divideComponents = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = left.x / right.x;\r\n result.y = left.y / right.y;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the componentwise sum of two Cartesians.\r\n *\r\n * @param {Cartesian2} left The first Cartesian.\r\n * @param {Cartesian2} right The second Cartesian.\r\n * @param {Cartesian2} result The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter.\r\n */\r\nCartesian2.add = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = left.x + right.x;\r\n result.y = left.y + right.y;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the componentwise difference of two Cartesians.\r\n *\r\n * @param {Cartesian2} left The first Cartesian.\r\n * @param {Cartesian2} right The second Cartesian.\r\n * @param {Cartesian2} result The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter.\r\n */\r\nCartesian2.subtract = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = left.x - right.x;\r\n result.y = left.y - right.y;\r\n return result;\r\n};\r\n\r\n/**\r\n * Multiplies the provided Cartesian componentwise by the provided scalar.\r\n *\r\n * @param {Cartesian2} cartesian The Cartesian to be scaled.\r\n * @param {Number} scalar The scalar to multiply with.\r\n * @param {Cartesian2} result The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter.\r\n */\r\nCartesian2.multiplyByScalar = function (cartesian, scalar, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.number(\"scalar\", scalar);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = cartesian.x * scalar;\r\n result.y = cartesian.y * scalar;\r\n return result;\r\n};\r\n\r\n/**\r\n * Divides the provided Cartesian componentwise by the provided scalar.\r\n *\r\n * @param {Cartesian2} cartesian The Cartesian to be divided.\r\n * @param {Number} scalar The scalar to divide by.\r\n * @param {Cartesian2} result The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter.\r\n */\r\nCartesian2.divideByScalar = function (cartesian, scalar, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.number(\"scalar\", scalar);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = cartesian.x / scalar;\r\n result.y = cartesian.y / scalar;\r\n return result;\r\n};\r\n\r\n/**\r\n * Negates the provided Cartesian.\r\n *\r\n * @param {Cartesian2} cartesian The Cartesian to be negated.\r\n * @param {Cartesian2} result The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter.\r\n */\r\nCartesian2.negate = function (cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = -cartesian.x;\r\n result.y = -cartesian.y;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the absolute value of the provided Cartesian.\r\n *\r\n * @param {Cartesian2} cartesian The Cartesian whose absolute value is to be computed.\r\n * @param {Cartesian2} result The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter.\r\n */\r\nCartesian2.abs = function (cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = Math.abs(cartesian.x);\r\n result.y = Math.abs(cartesian.y);\r\n return result;\r\n};\r\n\r\nvar lerpScratch = new Cartesian2();\r\n/**\r\n * Computes the linear interpolation or extrapolation at t using the provided cartesians.\r\n *\r\n * @param {Cartesian2} start The value corresponding to t at 0.0.\r\n * @param {Cartesian2} end The value corresponding to t at 1.0.\r\n * @param {Number} t The point along t at which to interpolate.\r\n * @param {Cartesian2} result The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter.\r\n */\r\nCartesian2.lerp = function (start, end, t, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"start\", start);\r\n Check.typeOf.object(\"end\", end);\r\n Check.typeOf.number(\"t\", t);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n Cartesian2.multiplyByScalar(end, t, lerpScratch);\r\n result = Cartesian2.multiplyByScalar(start, 1.0 - t, result);\r\n return Cartesian2.add(lerpScratch, result, result);\r\n};\r\n\r\nvar angleBetweenScratch = new Cartesian2();\r\nvar angleBetweenScratch2 = new Cartesian2();\r\n/**\r\n * Returns the angle, in radians, between the provided Cartesians.\r\n *\r\n * @param {Cartesian2} left The first Cartesian.\r\n * @param {Cartesian2} right The second Cartesian.\r\n * @returns {Number} The angle between the Cartesians.\r\n */\r\nCartesian2.angleBetween = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n //>>includeEnd('debug');\r\n\r\n Cartesian2.normalize(left, angleBetweenScratch);\r\n Cartesian2.normalize(right, angleBetweenScratch2);\r\n return CesiumMath.acosClamped(\r\n Cartesian2.dot(angleBetweenScratch, angleBetweenScratch2)\r\n );\r\n};\r\n\r\nvar mostOrthogonalAxisScratch = new Cartesian2();\r\n/**\r\n * Returns the axis that is most orthogonal to the provided Cartesian.\r\n *\r\n * @param {Cartesian2} cartesian The Cartesian on which to find the most orthogonal axis.\r\n * @param {Cartesian2} result The object onto which to store the result.\r\n * @returns {Cartesian2} The most orthogonal axis.\r\n */\r\nCartesian2.mostOrthogonalAxis = function (cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var f = Cartesian2.normalize(cartesian, mostOrthogonalAxisScratch);\r\n Cartesian2.abs(f, f);\r\n\r\n if (f.x <= f.y) {\r\n result = Cartesian2.clone(Cartesian2.UNIT_X, result);\r\n } else {\r\n result = Cartesian2.clone(Cartesian2.UNIT_Y, result);\r\n }\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Compares the provided Cartesians componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Cartesian2} [left] The first Cartesian.\r\n * @param {Cartesian2} [right] The second Cartesian.\r\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\r\n */\r\nCartesian2.equals = function (left, right) {\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n left.x === right.x &&\r\n left.y === right.y)\r\n );\r\n};\r\n\r\n/**\r\n * @private\r\n */\r\nCartesian2.equalsArray = function (cartesian, array, offset) {\r\n return cartesian.x === array[offset] && cartesian.y === array[offset + 1];\r\n};\r\n\r\n/**\r\n * Compares the provided Cartesians componentwise and returns\r\n * true
if they pass an absolute or relative tolerance test,\r\n * false
otherwise.\r\n *\r\n * @param {Cartesian2} [left] The first Cartesian.\r\n * @param {Cartesian2} [right] The second Cartesian.\r\n * @param {Number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\r\n * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\r\n * @returns {Boolean} true
if left and right are within the provided epsilon, false
otherwise.\r\n */\r\nCartesian2.equalsEpsilon = function (\r\n left,\r\n right,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n) {\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n CesiumMath.equalsEpsilon(\r\n left.x,\r\n right.x,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n ) &&\r\n CesiumMath.equalsEpsilon(\r\n left.y,\r\n right.y,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n ))\r\n );\r\n};\r\n\r\n/**\r\n * An immutable Cartesian2 instance initialized to (0.0, 0.0).\r\n *\r\n * @type {Cartesian2}\r\n * @constant\r\n */\r\nCartesian2.ZERO = Object.freeze(new Cartesian2(0.0, 0.0));\r\n\r\n/**\r\n * An immutable Cartesian2 instance initialized to (1.0, 0.0).\r\n *\r\n * @type {Cartesian2}\r\n * @constant\r\n */\r\nCartesian2.UNIT_X = Object.freeze(new Cartesian2(1.0, 0.0));\r\n\r\n/**\r\n * An immutable Cartesian2 instance initialized to (0.0, 1.0).\r\n *\r\n * @type {Cartesian2}\r\n * @constant\r\n */\r\nCartesian2.UNIT_Y = Object.freeze(new Cartesian2(0.0, 1.0));\r\n\r\n/**\r\n * Duplicates this Cartesian2 instance.\r\n *\r\n * @param {Cartesian2} [result] The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.\r\n */\r\nCartesian2.prototype.clone = function (result) {\r\n return Cartesian2.clone(this, result);\r\n};\r\n\r\n/**\r\n * Compares this Cartesian against the provided Cartesian componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Cartesian2} [right] The right hand side Cartesian.\r\n * @returns {Boolean} true
if they are equal, false
otherwise.\r\n */\r\nCartesian2.prototype.equals = function (right) {\r\n return Cartesian2.equals(this, right);\r\n};\r\n\r\n/**\r\n * Compares this Cartesian against the provided Cartesian componentwise and returns\r\n * true
if they pass an absolute or relative tolerance test,\r\n * false
otherwise.\r\n *\r\n * @param {Cartesian2} [right] The right hand side Cartesian.\r\n * @param {Number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\r\n * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\r\n * @returns {Boolean} true
if they are within the provided epsilon, false
otherwise.\r\n */\r\nCartesian2.prototype.equalsEpsilon = function (\r\n right,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n) {\r\n return Cartesian2.equalsEpsilon(\r\n this,\r\n right,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n );\r\n};\r\n\r\n/**\r\n * Creates a string representing this Cartesian in the format '(x, y)'.\r\n *\r\n * @returns {String} A string representing the provided Cartesian in the format '(x, y)'.\r\n */\r\nCartesian2.prototype.toString = function () {\r\n return \"(\" + this.x + \", \" + this.y + \")\";\r\n};\r\nexport default Cartesian2;\r\n","import Cartesian2 from \"./Cartesian2.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport Ellipsoid from \"./Ellipsoid.js\";\r\nimport GeographicProjection from \"./GeographicProjection.js\";\r\nimport CesiumMath from \"./Math.js\";\r\nimport Rectangle from \"./Rectangle.js\";\r\n\r\n/**\r\n * A tiling scheme for geometry referenced to a simple {@link GeographicProjection} where\r\n * longitude and latitude are directly mapped to X and Y. This projection is commonly\r\n * known as geographic, equirectangular, equidistant cylindrical, or plate carrée.\r\n *\r\n * @alias GeographicTilingScheme\r\n * @constructor\r\n *\r\n * @param {Object} [options] Object with the following properties:\r\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid whose surface is being tiled. Defaults to\r\n * the WGS84 ellipsoid.\r\n * @param {Rectangle} [options.rectangle=Rectangle.MAX_VALUE] The rectangle, in radians, covered by the tiling scheme.\r\n * @param {Number} [options.numberOfLevelZeroTilesX=2] The number of tiles in the X direction at level zero of\r\n * the tile tree.\r\n * @param {Number} [options.numberOfLevelZeroTilesY=1] The number of tiles in the Y direction at level zero of\r\n * the tile tree.\r\n */\r\nfunction GeographicTilingScheme(options) {\r\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\r\n\r\n this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\r\n this._rectangle = defaultValue(options.rectangle, Rectangle.MAX_VALUE);\r\n this._projection = new GeographicProjection(this._ellipsoid);\r\n this._numberOfLevelZeroTilesX = defaultValue(\r\n options.numberOfLevelZeroTilesX,\r\n 2\r\n );\r\n this._numberOfLevelZeroTilesY = defaultValue(\r\n options.numberOfLevelZeroTilesY,\r\n 1\r\n );\r\n}\r\n\r\nObject.defineProperties(GeographicTilingScheme.prototype, {\r\n /**\r\n * Gets the ellipsoid that is tiled by this tiling scheme.\r\n * @memberof GeographicTilingScheme.prototype\r\n * @type {Ellipsoid}\r\n */\r\n ellipsoid: {\r\n get: function () {\r\n return this._ellipsoid;\r\n },\r\n },\r\n\r\n /**\r\n * Gets the rectangle, in radians, covered by this tiling scheme.\r\n * @memberof GeographicTilingScheme.prototype\r\n * @type {Rectangle}\r\n */\r\n rectangle: {\r\n get: function () {\r\n return this._rectangle;\r\n },\r\n },\r\n\r\n /**\r\n * Gets the map projection used by this tiling scheme.\r\n * @memberof GeographicTilingScheme.prototype\r\n * @type {MapProjection}\r\n */\r\n projection: {\r\n get: function () {\r\n return this._projection;\r\n },\r\n },\r\n});\r\n\r\n/**\r\n * Gets the total number of tiles in the X direction at a specified level-of-detail.\r\n *\r\n * @param {Number} level The level-of-detail.\r\n * @returns {Number} The number of tiles in the X direction at the given level.\r\n */\r\nGeographicTilingScheme.prototype.getNumberOfXTilesAtLevel = function (level) {\r\n return this._numberOfLevelZeroTilesX << level;\r\n};\r\n\r\n/**\r\n * Gets the total number of tiles in the Y direction at a specified level-of-detail.\r\n *\r\n * @param {Number} level The level-of-detail.\r\n * @returns {Number} The number of tiles in the Y direction at the given level.\r\n */\r\nGeographicTilingScheme.prototype.getNumberOfYTilesAtLevel = function (level) {\r\n return this._numberOfLevelZeroTilesY << level;\r\n};\r\n\r\n/**\r\n * Transforms a rectangle specified in geodetic radians to the native coordinate system\r\n * of this tiling scheme.\r\n *\r\n * @param {Rectangle} rectangle The rectangle to transform.\r\n * @param {Rectangle} [result] The instance to which to copy the result, or undefined if a new instance\r\n * should be created.\r\n * @returns {Rectangle} The specified 'result', or a new object containing the native rectangle if 'result'\r\n * is undefined.\r\n */\r\nGeographicTilingScheme.prototype.rectangleToNativeRectangle = function (\r\n rectangle,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"rectangle\", rectangle);\r\n //>>includeEnd('debug');\r\n\r\n var west = CesiumMath.toDegrees(rectangle.west);\r\n var south = CesiumMath.toDegrees(rectangle.south);\r\n var east = CesiumMath.toDegrees(rectangle.east);\r\n var north = CesiumMath.toDegrees(rectangle.north);\r\n\r\n if (!defined(result)) {\r\n return new Rectangle(west, south, east, north);\r\n }\r\n\r\n result.west = west;\r\n result.south = south;\r\n result.east = east;\r\n result.north = north;\r\n return result;\r\n};\r\n\r\n/**\r\n * Converts tile x, y coordinates and level to a rectangle expressed in the native coordinates\r\n * of the tiling scheme.\r\n *\r\n * @param {Number} x The integer x coordinate of the tile.\r\n * @param {Number} y The integer y coordinate of the tile.\r\n * @param {Number} level The tile level-of-detail. Zero is the least detailed.\r\n * @param {Object} [result] The instance to which to copy the result, or undefined if a new instance\r\n * should be created.\r\n * @returns {Rectangle} The specified 'result', or a new object containing the rectangle\r\n * if 'result' is undefined.\r\n */\r\nGeographicTilingScheme.prototype.tileXYToNativeRectangle = function (\r\n x,\r\n y,\r\n level,\r\n result\r\n) {\r\n var rectangleRadians = this.tileXYToRectangle(x, y, level, result);\r\n rectangleRadians.west = CesiumMath.toDegrees(rectangleRadians.west);\r\n rectangleRadians.south = CesiumMath.toDegrees(rectangleRadians.south);\r\n rectangleRadians.east = CesiumMath.toDegrees(rectangleRadians.east);\r\n rectangleRadians.north = CesiumMath.toDegrees(rectangleRadians.north);\r\n return rectangleRadians;\r\n};\r\n\r\n/**\r\n * Converts tile x, y coordinates and level to a cartographic rectangle in radians.\r\n *\r\n * @param {Number} x The integer x coordinate of the tile.\r\n * @param {Number} y The integer y coordinate of the tile.\r\n * @param {Number} level The tile level-of-detail. Zero is the least detailed.\r\n * @param {Object} [result] The instance to which to copy the result, or undefined if a new instance\r\n * should be created.\r\n * @returns {Rectangle} The specified 'result', or a new object containing the rectangle\r\n * if 'result' is undefined.\r\n */\r\nGeographicTilingScheme.prototype.tileXYToRectangle = function (\r\n x,\r\n y,\r\n level,\r\n result\r\n) {\r\n var rectangle = this._rectangle;\r\n\r\n var xTiles = this.getNumberOfXTilesAtLevel(level);\r\n var yTiles = this.getNumberOfYTilesAtLevel(level);\r\n\r\n var xTileWidth = rectangle.width / xTiles;\r\n var west = x * xTileWidth + rectangle.west;\r\n var east = (x + 1) * xTileWidth + rectangle.west;\r\n\r\n var yTileHeight = rectangle.height / yTiles;\r\n var north = rectangle.north - y * yTileHeight;\r\n var south = rectangle.north - (y + 1) * yTileHeight;\r\n\r\n if (!defined(result)) {\r\n result = new Rectangle(west, south, east, north);\r\n }\r\n\r\n result.west = west;\r\n result.south = south;\r\n result.east = east;\r\n result.north = north;\r\n return result;\r\n};\r\n\r\n/**\r\n * Calculates the tile x, y coordinates of the tile containing\r\n * a given cartographic position.\r\n *\r\n * @param {Cartographic} position The position.\r\n * @param {Number} level The tile level-of-detail. Zero is the least detailed.\r\n * @param {Cartesian2} [result] The instance to which to copy the result, or undefined if a new instance\r\n * should be created.\r\n * @returns {Cartesian2} The specified 'result', or a new object containing the tile x, y coordinates\r\n * if 'result' is undefined.\r\n */\r\nGeographicTilingScheme.prototype.positionToTileXY = function (\r\n position,\r\n level,\r\n result\r\n) {\r\n var rectangle = this._rectangle;\r\n if (!Rectangle.contains(rectangle, position)) {\r\n // outside the bounds of the tiling scheme\r\n return undefined;\r\n }\r\n\r\n var xTiles = this.getNumberOfXTilesAtLevel(level);\r\n var yTiles = this.getNumberOfYTilesAtLevel(level);\r\n\r\n var xTileWidth = rectangle.width / xTiles;\r\n var yTileHeight = rectangle.height / yTiles;\r\n\r\n var longitude = position.longitude;\r\n if (rectangle.east < rectangle.west) {\r\n longitude += CesiumMath.TWO_PI;\r\n }\r\n\r\n var xTileCoordinate = ((longitude - rectangle.west) / xTileWidth) | 0;\r\n if (xTileCoordinate >= xTiles) {\r\n xTileCoordinate = xTiles - 1;\r\n }\r\n\r\n var yTileCoordinate =\r\n ((rectangle.north - position.latitude) / yTileHeight) | 0;\r\n if (yTileCoordinate >= yTiles) {\r\n yTileCoordinate = yTiles - 1;\r\n }\r\n\r\n if (!defined(result)) {\r\n return new Cartesian2(xTileCoordinate, yTileCoordinate);\r\n }\r\n\r\n result.x = xTileCoordinate;\r\n result.y = yTileCoordinate;\r\n return result;\r\n};\r\nexport default GeographicTilingScheme;\r\n","import BoundingSphere from \"./BoundingSphere.js\";\r\nimport buildModuleUrl from \"./buildModuleUrl.js\";\r\nimport Cartesian2 from \"./Cartesian2.js\";\r\nimport Cartesian3 from \"./Cartesian3.js\";\r\nimport Cartographic from \"./Cartographic.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport Ellipsoid from \"./Ellipsoid.js\";\r\nimport GeographicTilingScheme from \"./GeographicTilingScheme.js\";\r\nimport Rectangle from \"./Rectangle.js\";\r\nimport Resource from \"./Resource.js\";\r\n\r\nvar scratchDiagonalCartesianNE = new Cartesian3();\r\nvar scratchDiagonalCartesianSW = new Cartesian3();\r\nvar scratchDiagonalCartographic = new Cartographic();\r\nvar scratchCenterCartesian = new Cartesian3();\r\nvar scratchSurfaceCartesian = new Cartesian3();\r\n\r\nvar scratchBoundingSphere = new BoundingSphere();\r\nvar tilingScheme = new GeographicTilingScheme();\r\nvar scratchCorners = [\r\n new Cartographic(),\r\n new Cartographic(),\r\n new Cartographic(),\r\n new Cartographic(),\r\n];\r\nvar scratchTileXY = new Cartesian2();\r\n\r\n/**\r\n * A collection of functions for approximating terrain height\r\n * @private\r\n */\r\nvar ApproximateTerrainHeights = {};\r\n\r\n/**\r\n * Initializes the minimum and maximum terrain heights\r\n * @return {Promise}\r\n */\r\nApproximateTerrainHeights.initialize = function () {\r\n var initPromise = ApproximateTerrainHeights._initPromise;\r\n if (defined(initPromise)) {\r\n return initPromise;\r\n }\r\n\r\n initPromise = Resource.fetchJson(\r\n buildModuleUrl(\"Assets/approximateTerrainHeights.json\")\r\n ).then(function (json) {\r\n ApproximateTerrainHeights._terrainHeights = json;\r\n });\r\n ApproximateTerrainHeights._initPromise = initPromise;\r\n\r\n return initPromise;\r\n};\r\n\r\n/**\r\n * Computes the minimum and maximum terrain heights for a given rectangle\r\n * @param {Rectangle} rectangle The bounding rectangle\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid\r\n * @return {{minimumTerrainHeight: Number, maximumTerrainHeight: Number}}\r\n */\r\nApproximateTerrainHeights.getMinimumMaximumHeights = function (\r\n rectangle,\r\n ellipsoid\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"rectangle\", rectangle);\r\n if (!defined(ApproximateTerrainHeights._terrainHeights)) {\r\n throw new DeveloperError(\r\n \"You must call ApproximateTerrainHeights.initialize and wait for the promise to resolve before using this function\"\r\n );\r\n }\r\n //>>includeEnd('debug');\r\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\r\n\r\n var xyLevel = getTileXYLevel(rectangle);\r\n\r\n // Get the terrain min/max for that tile\r\n var minTerrainHeight = ApproximateTerrainHeights._defaultMinTerrainHeight;\r\n var maxTerrainHeight = ApproximateTerrainHeights._defaultMaxTerrainHeight;\r\n if (defined(xyLevel)) {\r\n var key = xyLevel.level + \"-\" + xyLevel.x + \"-\" + xyLevel.y;\r\n var heights = ApproximateTerrainHeights._terrainHeights[key];\r\n if (defined(heights)) {\r\n minTerrainHeight = heights[0];\r\n maxTerrainHeight = heights[1];\r\n }\r\n\r\n // Compute min by taking the center of the NE->SW diagonal and finding distance to the surface\r\n ellipsoid.cartographicToCartesian(\r\n Rectangle.northeast(rectangle, scratchDiagonalCartographic),\r\n scratchDiagonalCartesianNE\r\n );\r\n ellipsoid.cartographicToCartesian(\r\n Rectangle.southwest(rectangle, scratchDiagonalCartographic),\r\n scratchDiagonalCartesianSW\r\n );\r\n\r\n Cartesian3.midpoint(\r\n scratchDiagonalCartesianSW,\r\n scratchDiagonalCartesianNE,\r\n scratchCenterCartesian\r\n );\r\n var surfacePosition = ellipsoid.scaleToGeodeticSurface(\r\n scratchCenterCartesian,\r\n scratchSurfaceCartesian\r\n );\r\n if (defined(surfacePosition)) {\r\n var distance = Cartesian3.distance(\r\n scratchCenterCartesian,\r\n surfacePosition\r\n );\r\n minTerrainHeight = Math.min(minTerrainHeight, -distance);\r\n } else {\r\n minTerrainHeight = ApproximateTerrainHeights._defaultMinTerrainHeight;\r\n }\r\n }\r\n\r\n minTerrainHeight = Math.max(\r\n ApproximateTerrainHeights._defaultMinTerrainHeight,\r\n minTerrainHeight\r\n );\r\n\r\n return {\r\n minimumTerrainHeight: minTerrainHeight,\r\n maximumTerrainHeight: maxTerrainHeight,\r\n };\r\n};\r\n\r\n/**\r\n * Computes the bounding sphere based on the tile heights in the rectangle\r\n * @param {Rectangle} rectangle The bounding rectangle\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid\r\n * @return {BoundingSphere} The result bounding sphere\r\n */\r\nApproximateTerrainHeights.getBoundingSphere = function (rectangle, ellipsoid) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"rectangle\", rectangle);\r\n if (!defined(ApproximateTerrainHeights._terrainHeights)) {\r\n throw new DeveloperError(\r\n \"You must call ApproximateTerrainHeights.initialize and wait for the promise to resolve before using this function\"\r\n );\r\n }\r\n //>>includeEnd('debug');\r\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\r\n\r\n var xyLevel = getTileXYLevel(rectangle);\r\n\r\n // Get the terrain max for that tile\r\n var maxTerrainHeight = ApproximateTerrainHeights._defaultMaxTerrainHeight;\r\n if (defined(xyLevel)) {\r\n var key = xyLevel.level + \"-\" + xyLevel.x + \"-\" + xyLevel.y;\r\n var heights = ApproximateTerrainHeights._terrainHeights[key];\r\n if (defined(heights)) {\r\n maxTerrainHeight = heights[1];\r\n }\r\n }\r\n\r\n var result = BoundingSphere.fromRectangle3D(rectangle, ellipsoid, 0.0);\r\n BoundingSphere.fromRectangle3D(\r\n rectangle,\r\n ellipsoid,\r\n maxTerrainHeight,\r\n scratchBoundingSphere\r\n );\r\n\r\n return BoundingSphere.union(result, scratchBoundingSphere, result);\r\n};\r\n\r\nfunction getTileXYLevel(rectangle) {\r\n Cartographic.fromRadians(\r\n rectangle.east,\r\n rectangle.north,\r\n 0.0,\r\n scratchCorners[0]\r\n );\r\n Cartographic.fromRadians(\r\n rectangle.west,\r\n rectangle.north,\r\n 0.0,\r\n scratchCorners[1]\r\n );\r\n Cartographic.fromRadians(\r\n rectangle.east,\r\n rectangle.south,\r\n 0.0,\r\n scratchCorners[2]\r\n );\r\n Cartographic.fromRadians(\r\n rectangle.west,\r\n rectangle.south,\r\n 0.0,\r\n scratchCorners[3]\r\n );\r\n\r\n // Determine which tile the bounding rectangle is in\r\n var lastLevelX = 0,\r\n lastLevelY = 0;\r\n var currentX = 0,\r\n currentY = 0;\r\n var maxLevel = ApproximateTerrainHeights._terrainHeightsMaxLevel;\r\n var i;\r\n for (i = 0; i <= maxLevel; ++i) {\r\n var failed = false;\r\n for (var j = 0; j < 4; ++j) {\r\n var corner = scratchCorners[j];\r\n tilingScheme.positionToTileXY(corner, i, scratchTileXY);\r\n if (j === 0) {\r\n currentX = scratchTileXY.x;\r\n currentY = scratchTileXY.y;\r\n } else if (currentX !== scratchTileXY.x || currentY !== scratchTileXY.y) {\r\n failed = true;\r\n break;\r\n }\r\n }\r\n\r\n if (failed) {\r\n break;\r\n }\r\n\r\n lastLevelX = currentX;\r\n lastLevelY = currentY;\r\n }\r\n\r\n if (i === 0) {\r\n return undefined;\r\n }\r\n\r\n return {\r\n x: lastLevelX,\r\n y: lastLevelY,\r\n level: i > maxLevel ? maxLevel : i - 1,\r\n };\r\n}\r\n\r\nApproximateTerrainHeights._terrainHeightsMaxLevel = 6;\r\nApproximateTerrainHeights._defaultMaxTerrainHeight = 9000.0;\r\nApproximateTerrainHeights._defaultMinTerrainHeight = -100000.0;\r\nApproximateTerrainHeights._terrainHeights = undefined;\r\nApproximateTerrainHeights._initPromise = undefined;\r\n\r\nObject.defineProperties(ApproximateTerrainHeights, {\r\n /**\r\n * Determines if the terrain heights are initialized and ready to use. To initialize the terrain heights,\r\n * call {@link ApproximateTerrainHeights#initialize} and wait for the returned promise to resolve.\r\n * @type {Boolean}\r\n * @readonly\r\n * @memberof ApproximateTerrainHeights\r\n */\r\n initialized: {\r\n get: function () {\r\n return defined(ApproximateTerrainHeights._terrainHeights);\r\n },\r\n },\r\n});\r\nexport default ApproximateTerrainHeights;\r\n","/*! @license DOMPurify | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.0.8/LICENSE */\r\n\r\nfunction _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }\r\n\r\nvar hasOwnProperty = Object.hasOwnProperty,\r\n setPrototypeOf = Object.setPrototypeOf,\r\n isFrozen = Object.isFrozen;\r\nvar freeze = Object.freeze,\r\n seal = Object.seal,\r\n create = Object.create; // eslint-disable-line import/no-mutable-exports\r\n\r\nvar _ref = typeof Reflect !== 'undefined' && Reflect,\r\n apply = _ref.apply,\r\n construct = _ref.construct;\r\n\r\nif (!apply) {\r\n apply = function apply(fun, thisValue, args) {\r\n return fun.apply(thisValue, args);\r\n };\r\n}\r\n\r\nif (!freeze) {\r\n freeze = function freeze(x) {\r\n return x;\r\n };\r\n}\r\n\r\nif (!seal) {\r\n seal = function seal(x) {\r\n return x;\r\n };\r\n}\r\n\r\nif (!construct) {\r\n construct = function construct(Func, args) {\r\n return new (Function.prototype.bind.apply(Func, [null].concat(_toConsumableArray(args))))();\r\n };\r\n}\r\n\r\nvar arrayForEach = unapply(Array.prototype.forEach);\r\nvar arrayPop = unapply(Array.prototype.pop);\r\nvar arrayPush = unapply(Array.prototype.push);\r\n\r\nvar stringToLowerCase = unapply(String.prototype.toLowerCase);\r\nvar stringMatch = unapply(String.prototype.match);\r\nvar stringReplace = unapply(String.prototype.replace);\r\nvar stringIndexOf = unapply(String.prototype.indexOf);\r\nvar stringTrim = unapply(String.prototype.trim);\r\n\r\nvar regExpTest = unapply(RegExp.prototype.test);\r\n\r\nvar typeErrorCreate = unconstruct(TypeError);\r\n\r\nfunction unapply(func) {\r\n return function (thisArg) {\r\n for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\r\n args[_key - 1] = arguments[_key];\r\n }\r\n\r\n return apply(func, thisArg, args);\r\n };\r\n}\r\n\r\nfunction unconstruct(func) {\r\n return function () {\r\n for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {\r\n args[_key2] = arguments[_key2];\r\n }\r\n\r\n return construct(func, args);\r\n };\r\n}\r\n\r\n/* Add properties to a lookup table */\r\nfunction addToSet(set, array) {\r\n if (setPrototypeOf) {\r\n // Make 'in' and truthy checks like Boolean(set.constructor)\r\n // independent of any properties defined on Object.prototype.\r\n // Prevent prototype setters from intercepting set as a this value.\r\n setPrototypeOf(set, null);\r\n }\r\n\r\n var l = array.length;\r\n while (l--) {\r\n var element = array[l];\r\n if (typeof element === 'string') {\r\n var lcElement = stringToLowerCase(element);\r\n if (lcElement !== element) {\r\n // Config presets (e.g. tags.js, attrs.js) are immutable.\r\n if (!isFrozen(array)) {\r\n array[l] = lcElement;\r\n }\r\n\r\n element = lcElement;\r\n }\r\n }\r\n\r\n set[element] = true;\r\n }\r\n\r\n return set;\r\n}\r\n\r\n/* Shallow clone an object */\r\nfunction clone(object) {\r\n var newObject = create(null);\r\n\r\n var property = void 0;\r\n for (property in object) {\r\n if (apply(hasOwnProperty, object, [property])) {\r\n newObject[property] = object[property];\r\n }\r\n }\r\n\r\n return newObject;\r\n}\r\n\r\nvar html = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);\r\n\r\n// SVG\r\nvar svg = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'audio', 'canvas', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'video', 'view', 'vkern']);\r\n\r\nvar svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);\r\n\r\nvar mathMl = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover']);\r\n\r\nvar text = freeze(['#text']);\r\n\r\nvar html$1 = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'playsinline', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'xmlns']);\r\n\r\nvar svg$1 = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'targetx', 'targety', 'transform', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);\r\n\r\nvar mathMl$1 = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);\r\n\r\nvar xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);\r\n\r\n// eslint-disable-next-line unicorn/better-regex\r\nvar MUSTACHE_EXPR = seal(/\\{\\{[\\s\\S]*|[\\s\\S]*\\}\\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode\r\nvar ERB_EXPR = seal(/<%[\\s\\S]*|[\\s\\S]*%>/gm);\r\nvar DATA_ATTR = seal(/^data-[\\-\\w.\\u00B7-\\uFFFF]/); // eslint-disable-line no-useless-escape\r\nvar ARIA_ATTR = seal(/^aria-[\\-\\w]+$/); // eslint-disable-line no-useless-escape\r\nvar IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\\-]+(?:[^a-z+.\\-:]|$))/i // eslint-disable-line no-useless-escape\r\n);\r\nvar IS_SCRIPT_OR_DATA = seal(/^(?:\\w+script|data):/i);\r\nvar ATTR_WHITESPACE = seal(/[\\u0000-\\u0020\\u00A0\\u1680\\u180E\\u2000-\\u2029\\u205F\\u3000]/g // eslint-disable-line no-control-regex\r\n);\r\n\r\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\r\n\r\nfunction _toConsumableArray$1(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }\r\n\r\nvar getGlobal = function getGlobal() {\r\n return typeof window === 'undefined' ? null : window;\r\n};\r\n\r\n/**\r\n * Creates a no-op policy for internal use only.\r\n * Don't export this function outside this module!\r\n * @param {?TrustedTypePolicyFactory} trustedTypes The policy factory.\r\n * @param {Document} document The document object (to determine policy name suffix)\r\n * @return {?TrustedTypePolicy} The policy created (or null, if Trusted Types\r\n * are not supported).\r\n */\r\nvar _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, document) {\r\n if ((typeof trustedTypes === 'undefined' ? 'undefined' : _typeof(trustedTypes)) !== 'object' || typeof trustedTypes.createPolicy !== 'function') {\r\n return null;\r\n }\r\n\r\n // Allow the callers to control the unique policy name\r\n // by adding a data-tt-policy-suffix to the script element with the DOMPurify.\r\n // Policy creation with duplicate names throws in Trusted Types.\r\n var suffix = null;\r\n var ATTR_NAME = 'data-tt-policy-suffix';\r\n if (document.currentScript && document.currentScript.hasAttribute(ATTR_NAME)) {\r\n suffix = document.currentScript.getAttribute(ATTR_NAME);\r\n }\r\n\r\n var policyName = 'dompurify' + (suffix ? '#' + suffix : '');\r\n\r\n try {\r\n return trustedTypes.createPolicy(policyName, {\r\n createHTML: function createHTML(html$$1) {\r\n return html$$1;\r\n }\r\n });\r\n } catch (_) {\r\n // Policy creation failed (most likely another DOMPurify script has\r\n // already run). Skip creating the policy, as this will only cause errors\r\n // if TT are enforced.\r\n console.warn('TrustedTypes policy ' + policyName + ' could not be created.');\r\n return null;\r\n }\r\n};\r\n\r\nfunction createDOMPurify() {\r\n var window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();\r\n\r\n var DOMPurify = function DOMPurify(root) {\r\n return createDOMPurify(root);\r\n };\r\n\r\n /**\r\n * Version label, exposed for easier checks\r\n * if DOMPurify is up to date or not\r\n */\r\n DOMPurify.version = '2.2.2';\r\n\r\n /**\r\n * Array of elements that DOMPurify removed during sanitation.\r\n * Empty if nothing was removed.\r\n */\r\n DOMPurify.removed = [];\r\n\r\n if (!window || !window.document || window.document.nodeType !== 9) {\r\n // Not running in a browser, provide a factory function\r\n // so that you can pass your own Window\r\n DOMPurify.isSupported = false;\r\n\r\n return DOMPurify;\r\n }\r\n\r\n var originalDocument = window.document;\r\n\r\n var document = window.document;\r\n var DocumentFragment = window.DocumentFragment,\r\n HTMLTemplateElement = window.HTMLTemplateElement,\r\n Node = window.Node,\r\n NodeFilter = window.NodeFilter,\r\n _window$NamedNodeMap = window.NamedNodeMap,\r\n NamedNodeMap = _window$NamedNodeMap === undefined ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap,\r\n Text = window.Text,\r\n Comment = window.Comment,\r\n DOMParser = window.DOMParser,\r\n trustedTypes = window.trustedTypes;\r\n\r\n // As per issue #47, the web-components registry is inherited by a\r\n // new document created via createHTMLDocument. As per the spec\r\n // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)\r\n // a new empty registry is used when creating a template contents owner\r\n // document, so we use that as our parent document to ensure nothing\r\n // is inherited.\r\n\r\n if (typeof HTMLTemplateElement === 'function') {\r\n var template = document.createElement('template');\r\n if (template.content && template.content.ownerDocument) {\r\n document = template.content.ownerDocument;\r\n }\r\n }\r\n\r\n var trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, originalDocument);\r\n var emptyHTML = trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML('') : '';\r\n\r\n var _document = document,\r\n implementation = _document.implementation,\r\n createNodeIterator = _document.createNodeIterator,\r\n getElementsByTagName = _document.getElementsByTagName,\r\n createDocumentFragment = _document.createDocumentFragment;\r\n var importNode = originalDocument.importNode;\r\n\r\n\r\n var documentMode = {};\r\n try {\r\n documentMode = clone(document).documentMode ? document.documentMode : {};\r\n } catch (_) {}\r\n\r\n var hooks = {};\r\n\r\n /**\r\n * Expose whether this browser supports running the full DOMPurify.\r\n */\r\n DOMPurify.isSupported = implementation && typeof implementation.createHTMLDocument !== 'undefined' && documentMode !== 9;\r\n\r\n var MUSTACHE_EXPR$$1 = MUSTACHE_EXPR,\r\n ERB_EXPR$$1 = ERB_EXPR,\r\n DATA_ATTR$$1 = DATA_ATTR,\r\n ARIA_ATTR$$1 = ARIA_ATTR,\r\n IS_SCRIPT_OR_DATA$$1 = IS_SCRIPT_OR_DATA,\r\n ATTR_WHITESPACE$$1 = ATTR_WHITESPACE;\r\n var IS_ALLOWED_URI$$1 = IS_ALLOWED_URI;\r\n\r\n /**\r\n * We consider the elements and attributes below to be safe. Ideally\r\n * don't add any new ones but feel free to remove unwanted ones.\r\n */\r\n\r\n /* allowed element names */\r\n\r\n var ALLOWED_TAGS = null;\r\n var DEFAULT_ALLOWED_TAGS = addToSet({}, [].concat(_toConsumableArray$1(html), _toConsumableArray$1(svg), _toConsumableArray$1(svgFilters), _toConsumableArray$1(mathMl), _toConsumableArray$1(text)));\r\n\r\n /* Allowed attribute names */\r\n var ALLOWED_ATTR = null;\r\n var DEFAULT_ALLOWED_ATTR = addToSet({}, [].concat(_toConsumableArray$1(html$1), _toConsumableArray$1(svg$1), _toConsumableArray$1(mathMl$1), _toConsumableArray$1(xml)));\r\n\r\n /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */\r\n var FORBID_TAGS = null;\r\n\r\n /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */\r\n var FORBID_ATTR = null;\r\n\r\n /* Decide if ARIA attributes are okay */\r\n var ALLOW_ARIA_ATTR = true;\r\n\r\n /* Decide if custom data attributes are okay */\r\n var ALLOW_DATA_ATTR = true;\r\n\r\n /* Decide if unknown protocols are okay */\r\n var ALLOW_UNKNOWN_PROTOCOLS = false;\r\n\r\n /* Output should be safe for common template engines.\r\n * This means, DOMPurify removes data attributes, mustaches and ERB\r\n */\r\n var SAFE_FOR_TEMPLATES = false;\r\n\r\n /* Decide if document with ... should be returned */\r\n var WHOLE_DOCUMENT = false;\r\n\r\n /* Track whether config is already set on this instance of DOMPurify. */\r\n var SET_CONFIG = false;\r\n\r\n /* Decide if all elements (e.g. style, script) must be children of\r\n * document.body. By default, browsers might move them to document.head */\r\n var FORCE_BODY = false;\r\n\r\n /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html\r\n * string (or a TrustedHTML object if Trusted Types are supported).\r\n * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead\r\n */\r\n var RETURN_DOM = false;\r\n\r\n /* Decide if a DOM `DocumentFragment` should be returned, instead of a html\r\n * string (or a TrustedHTML object if Trusted Types are supported) */\r\n var RETURN_DOM_FRAGMENT = false;\r\n\r\n /* If `RETURN_DOM` or `RETURN_DOM_FRAGMENT` is enabled, decide if the returned DOM\r\n * `Node` is imported into the current `Document`. If this flag is not enabled the\r\n * `Node` will belong (its ownerDocument) to a fresh `HTMLDocument`, created by\r\n * DOMPurify.\r\n *\r\n * This defaults to `true` starting DOMPurify 2.2.0. Note that setting it to `false`\r\n * might cause XSS from attacks hidden in closed shadowroots in case the browser\r\n * supports Declarative Shadow: DOM https://web.dev/declarative-shadow-dom/\r\n */\r\n var RETURN_DOM_IMPORT = true;\r\n\r\n /* Try to return a Trusted Type object instead of a string, return a string in\r\n * case Trusted Types are not supported */\r\n var RETURN_TRUSTED_TYPE = false;\r\n\r\n /* Output should be free from DOM clobbering attacks? */\r\n var SANITIZE_DOM = true;\r\n\r\n /* Keep element content when removing element? */\r\n var KEEP_CONTENT = true;\r\n\r\n /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead\r\n * of importing it into a new Document and returning a sanitized copy */\r\n var IN_PLACE = false;\r\n\r\n /* Allow usage of profiles like html, svg and mathMl */\r\n var USE_PROFILES = {};\r\n\r\n /* Tags to ignore content of when KEEP_CONTENT is true */\r\n var FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);\r\n\r\n /* Tags that are safe for data: URIs */\r\n var DATA_URI_TAGS = null;\r\n var DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);\r\n\r\n /* Attributes safe for values like \"javascript:\" */\r\n var URI_SAFE_ATTRIBUTES = null;\r\n var DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'summary', 'title', 'value', 'style', 'xmlns']);\r\n\r\n /* Keep a reference to config to pass to hooks */\r\n var CONFIG = null;\r\n\r\n /* Ideally, do not touch anything below this line */\r\n /* ______________________________________________ */\r\n\r\n var formElement = document.createElement('form');\r\n\r\n /**\r\n * _parseConfig\r\n *\r\n * @param {Object} cfg optional config literal\r\n */\r\n // eslint-disable-next-line complexity\r\n var _parseConfig = function _parseConfig(cfg) {\r\n if (CONFIG && CONFIG === cfg) {\r\n return;\r\n }\r\n\r\n /* Shield configuration object from tampering */\r\n if (!cfg || (typeof cfg === 'undefined' ? 'undefined' : _typeof(cfg)) !== 'object') {\r\n cfg = {};\r\n }\r\n\r\n /* Shield configuration object from prototype pollution */\r\n cfg = clone(cfg);\r\n\r\n /* Set configuration parameters */\r\n ALLOWED_TAGS = 'ALLOWED_TAGS' in cfg ? addToSet({}, cfg.ALLOWED_TAGS) : DEFAULT_ALLOWED_TAGS;\r\n ALLOWED_ATTR = 'ALLOWED_ATTR' in cfg ? addToSet({}, cfg.ALLOWED_ATTR) : DEFAULT_ALLOWED_ATTR;\r\n URI_SAFE_ATTRIBUTES = 'ADD_URI_SAFE_ATTR' in cfg ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR) : DEFAULT_URI_SAFE_ATTRIBUTES;\r\n DATA_URI_TAGS = 'ADD_DATA_URI_TAGS' in cfg ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS) : DEFAULT_DATA_URI_TAGS;\r\n FORBID_TAGS = 'FORBID_TAGS' in cfg ? addToSet({}, cfg.FORBID_TAGS) : {};\r\n FORBID_ATTR = 'FORBID_ATTR' in cfg ? addToSet({}, cfg.FORBID_ATTR) : {};\r\n USE_PROFILES = 'USE_PROFILES' in cfg ? cfg.USE_PROFILES : false;\r\n ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true\r\n ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true\r\n ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false\r\n SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false\r\n WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false\r\n RETURN_DOM = cfg.RETURN_DOM || false; // Default false\r\n RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false\r\n RETURN_DOM_IMPORT = cfg.RETURN_DOM_IMPORT !== false; // Default true\r\n RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false\r\n FORCE_BODY = cfg.FORCE_BODY || false; // Default false\r\n SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true\r\n KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true\r\n IN_PLACE = cfg.IN_PLACE || false; // Default false\r\n IS_ALLOWED_URI$$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI$$1;\r\n if (SAFE_FOR_TEMPLATES) {\r\n ALLOW_DATA_ATTR = false;\r\n }\r\n\r\n if (RETURN_DOM_FRAGMENT) {\r\n RETURN_DOM = true;\r\n }\r\n\r\n /* Parse profile info */\r\n if (USE_PROFILES) {\r\n ALLOWED_TAGS = addToSet({}, [].concat(_toConsumableArray$1(text)));\r\n ALLOWED_ATTR = [];\r\n if (USE_PROFILES.html === true) {\r\n addToSet(ALLOWED_TAGS, html);\r\n addToSet(ALLOWED_ATTR, html$1);\r\n }\r\n\r\n if (USE_PROFILES.svg === true) {\r\n addToSet(ALLOWED_TAGS, svg);\r\n addToSet(ALLOWED_ATTR, svg$1);\r\n addToSet(ALLOWED_ATTR, xml);\r\n }\r\n\r\n if (USE_PROFILES.svgFilters === true) {\r\n addToSet(ALLOWED_TAGS, svgFilters);\r\n addToSet(ALLOWED_ATTR, svg$1);\r\n addToSet(ALLOWED_ATTR, xml);\r\n }\r\n\r\n if (USE_PROFILES.mathMl === true) {\r\n addToSet(ALLOWED_TAGS, mathMl);\r\n addToSet(ALLOWED_ATTR, mathMl$1);\r\n addToSet(ALLOWED_ATTR, xml);\r\n }\r\n }\r\n\r\n /* Merge configuration parameters */\r\n if (cfg.ADD_TAGS) {\r\n if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {\r\n ALLOWED_TAGS = clone(ALLOWED_TAGS);\r\n }\r\n\r\n addToSet(ALLOWED_TAGS, cfg.ADD_TAGS);\r\n }\r\n\r\n if (cfg.ADD_ATTR) {\r\n if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {\r\n ALLOWED_ATTR = clone(ALLOWED_ATTR);\r\n }\r\n\r\n addToSet(ALLOWED_ATTR, cfg.ADD_ATTR);\r\n }\r\n\r\n if (cfg.ADD_URI_SAFE_ATTR) {\r\n addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR);\r\n }\r\n\r\n /* Add #text in case KEEP_CONTENT is set to true */\r\n if (KEEP_CONTENT) {\r\n ALLOWED_TAGS['#text'] = true;\r\n }\r\n\r\n /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */\r\n if (WHOLE_DOCUMENT) {\r\n addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);\r\n }\r\n\r\n /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */\r\n if (ALLOWED_TAGS.table) {\r\n addToSet(ALLOWED_TAGS, ['tbody']);\r\n delete FORBID_TAGS.tbody;\r\n }\r\n\r\n // Prevent further manipulation of configuration.\r\n // Not available in IE8, Safari 5, etc.\r\n if (freeze) {\r\n freeze(cfg);\r\n }\r\n\r\n CONFIG = cfg;\r\n };\r\n\r\n /**\r\n * _forceRemove\r\n *\r\n * @param {Node} node a DOM node\r\n */\r\n var _forceRemove = function _forceRemove(node) {\r\n arrayPush(DOMPurify.removed, { element: node });\r\n try {\r\n node.parentNode.removeChild(node);\r\n } catch (_) {\r\n node.outerHTML = emptyHTML;\r\n }\r\n };\r\n\r\n /**\r\n * _removeAttribute\r\n *\r\n * @param {String} name an Attribute name\r\n * @param {Node} node a DOM node\r\n */\r\n var _removeAttribute = function _removeAttribute(name, node) {\r\n try {\r\n arrayPush(DOMPurify.removed, {\r\n attribute: node.getAttributeNode(name),\r\n from: node\r\n });\r\n } catch (_) {\r\n arrayPush(DOMPurify.removed, {\r\n attribute: null,\r\n from: node\r\n });\r\n }\r\n\r\n node.removeAttribute(name);\r\n };\r\n\r\n /**\r\n * _initDocument\r\n *\r\n * @param {String} dirty a string of dirty markup\r\n * @return {Document} a DOM, filled with the dirty markup\r\n */\r\n var _initDocument = function _initDocument(dirty) {\r\n /* Create a HTML document */\r\n var doc = void 0;\r\n var leadingWhitespace = void 0;\r\n\r\n if (FORCE_BODY) {\r\n dirty = ' ' + dirty;\r\n } else {\r\n /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */\r\n var matches = stringMatch(dirty, /^[\\r\\n\\t ]+/);\r\n leadingWhitespace = matches && matches[0];\r\n }\r\n\r\n var dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;\r\n /* Use the DOMParser API by default, fallback later if needs be */\r\n try {\r\n doc = new DOMParser().parseFromString(dirtyPayload, 'text/html');\r\n } catch (_) {}\r\n\r\n /* Use createHTMLDocument in case DOMParser is not available */\r\n if (!doc || !doc.documentElement) {\r\n doc = implementation.createHTMLDocument('');\r\n var _doc = doc,\r\n body = _doc.body;\r\n\r\n body.parentNode.removeChild(body.parentNode.firstElementChild);\r\n body.outerHTML = dirtyPayload;\r\n }\r\n\r\n if (dirty && leadingWhitespace) {\r\n doc.body.insertBefore(document.createTextNode(leadingWhitespace), doc.body.childNodes[0] || null);\r\n }\r\n\r\n /* Work on whole document or just its body */\r\n return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];\r\n };\r\n\r\n /**\r\n * _createIterator\r\n *\r\n * @param {Document} root document/fragment to create iterator for\r\n * @return {Iterator} iterator instance\r\n */\r\n var _createIterator = function _createIterator(root) {\r\n return createNodeIterator.call(root.ownerDocument || root, root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT, function () {\r\n return NodeFilter.FILTER_ACCEPT;\r\n }, false);\r\n };\r\n\r\n /**\r\n * _isClobbered\r\n *\r\n * @param {Node} elm element to check for clobbering attacks\r\n * @return {Boolean} true if clobbered, false if safe\r\n */\r\n var _isClobbered = function _isClobbered(elm) {\r\n if (elm instanceof Text || elm instanceof Comment) {\r\n return false;\r\n }\r\n\r\n if (typeof elm.nodeName !== 'string' || typeof elm.textContent !== 'string' || typeof elm.removeChild !== 'function' || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== 'function' || typeof elm.setAttribute !== 'function' || typeof elm.namespaceURI !== 'string') {\r\n return true;\r\n }\r\n\r\n return false;\r\n };\r\n\r\n /**\r\n * _isNode\r\n *\r\n * @param {Node} obj object to check whether it's a DOM node\r\n * @return {Boolean} true is object is a DOM node\r\n */\r\n var _isNode = function _isNode(object) {\r\n return (typeof Node === 'undefined' ? 'undefined' : _typeof(Node)) === 'object' ? object instanceof Node : object && (typeof object === 'undefined' ? 'undefined' : _typeof(object)) === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string';\r\n };\r\n\r\n /**\r\n * _executeHook\r\n * Execute user configurable hooks\r\n *\r\n * @param {String} entryPoint Name of the hook's entry point\r\n * @param {Node} currentNode node to work on with the hook\r\n * @param {Object} data additional hook parameters\r\n */\r\n var _executeHook = function _executeHook(entryPoint, currentNode, data) {\r\n if (!hooks[entryPoint]) {\r\n return;\r\n }\r\n\r\n arrayForEach(hooks[entryPoint], function (hook) {\r\n hook.call(DOMPurify, currentNode, data, CONFIG);\r\n });\r\n };\r\n\r\n /**\r\n * _sanitizeElements\r\n *\r\n * @protect nodeName\r\n * @protect textContent\r\n * @protect removeChild\r\n *\r\n * @param {Node} currentNode to check for permission to exist\r\n * @return {Boolean} true if node was killed, false if left alive\r\n */\r\n var _sanitizeElements = function _sanitizeElements(currentNode) {\r\n var content = void 0;\r\n\r\n /* Execute a hook if present */\r\n _executeHook('beforeSanitizeElements', currentNode, null);\r\n\r\n /* Check if element is clobbered or can clobber */\r\n if (_isClobbered(currentNode)) {\r\n _forceRemove(currentNode);\r\n return true;\r\n }\r\n\r\n /* Check if tagname contains Unicode */\r\n if (stringMatch(currentNode.nodeName, /[\\u0080-\\uFFFF]/)) {\r\n _forceRemove(currentNode);\r\n return true;\r\n }\r\n\r\n /* Now let's check the element's type and name */\r\n var tagName = stringToLowerCase(currentNode.nodeName);\r\n\r\n /* Execute a hook if present */\r\n _executeHook('uponSanitizeElement', currentNode, {\r\n tagName: tagName,\r\n allowedTags: ALLOWED_TAGS\r\n });\r\n\r\n /* Take care of an mXSS pattern using p, br inside svg, math */\r\n if ((tagName === 'svg' || tagName === 'math') && currentNode.querySelectorAll('p, br, form, table').length !== 0) {\r\n _forceRemove(currentNode);\r\n return true;\r\n }\r\n\r\n /* Detect mXSS attempts abusing namespace confusion */\r\n if (!_isNode(currentNode.firstElementChild) && (!_isNode(currentNode.content) || !_isNode(currentNode.content.firstElementChild)) && regExpTest(/<[!/\\w]/g, currentNode.innerHTML) && regExpTest(/<[!/\\w]/g, currentNode.textContent)) {\r\n _forceRemove(currentNode);\r\n return true;\r\n }\r\n\r\n /* Remove element if anything forbids its presence */\r\n if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {\r\n /* Keep content except for bad-listed elements */\r\n if (KEEP_CONTENT && !FORBID_CONTENTS[tagName] && typeof currentNode.insertAdjacentHTML === 'function') {\r\n try {\r\n var htmlToInsert = currentNode.innerHTML;\r\n currentNode.insertAdjacentHTML('AfterEnd', trustedTypesPolicy ? trustedTypesPolicy.createHTML(htmlToInsert) : htmlToInsert);\r\n } catch (_) {}\r\n }\r\n\r\n _forceRemove(currentNode);\r\n return true;\r\n }\r\n\r\n /* Remove in case a noscript/noembed XSS is suspected */\r\n if ((tagName === 'noscript' || tagName === 'noembed') && regExpTest(/<\\/no(script|embed)/i, currentNode.innerHTML)) {\r\n _forceRemove(currentNode);\r\n return true;\r\n }\r\n\r\n /* Sanitize element content to be template-safe */\r\n if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {\r\n /* Get the element's text content */\r\n content = currentNode.textContent;\r\n content = stringReplace(content, MUSTACHE_EXPR$$1, ' ');\r\n content = stringReplace(content, ERB_EXPR$$1, ' ');\r\n if (currentNode.textContent !== content) {\r\n arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });\r\n currentNode.textContent = content;\r\n }\r\n }\r\n\r\n /* Execute a hook if present */\r\n _executeHook('afterSanitizeElements', currentNode, null);\r\n\r\n return false;\r\n };\r\n\r\n /**\r\n * _isValidAttribute\r\n *\r\n * @param {string} lcTag Lowercase tag name of containing element.\r\n * @param {string} lcName Lowercase attribute name.\r\n * @param {string} value Attribute value.\r\n * @return {Boolean} Returns true if `value` is valid, otherwise false.\r\n */\r\n // eslint-disable-next-line complexity\r\n var _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {\r\n /* Make sure attribute cannot clobber */\r\n if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {\r\n return false;\r\n }\r\n\r\n /* Allow valid data-* attributes: At least one character after \"-\"\r\n (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)\r\n XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)\r\n We don't need to check the value; it's always URI safe. */\r\n if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$$1, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {\r\n return false;\r\n\r\n /* Check value is safe. First, is attr inert? If so, is safe */\r\n } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$$1, stringReplace(value, ATTR_WHITESPACE$$1, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$$1, stringReplace(value, ATTR_WHITESPACE$$1, ''))) ; else if (!value) ; else {\r\n return false;\r\n }\r\n\r\n return true;\r\n };\r\n\r\n /**\r\n * _sanitizeAttributes\r\n *\r\n * @protect attributes\r\n * @protect nodeName\r\n * @protect removeAttribute\r\n * @protect setAttribute\r\n *\r\n * @param {Node} currentNode to sanitize\r\n */\r\n var _sanitizeAttributes = function _sanitizeAttributes(currentNode) {\r\n var attr = void 0;\r\n var value = void 0;\r\n var lcName = void 0;\r\n var l = void 0;\r\n /* Execute a hook if present */\r\n _executeHook('beforeSanitizeAttributes', currentNode, null);\r\n\r\n var attributes = currentNode.attributes;\r\n\r\n /* Check if we have attributes; if not we might have a text node */\r\n\r\n if (!attributes) {\r\n return;\r\n }\r\n\r\n var hookEvent = {\r\n attrName: '',\r\n attrValue: '',\r\n keepAttr: true,\r\n allowedAttributes: ALLOWED_ATTR\r\n };\r\n l = attributes.length;\r\n\r\n /* Go backwards over all attributes; safely remove bad ones */\r\n while (l--) {\r\n attr = attributes[l];\r\n var _attr = attr,\r\n name = _attr.name,\r\n namespaceURI = _attr.namespaceURI;\r\n\r\n value = stringTrim(attr.value);\r\n lcName = stringToLowerCase(name);\r\n\r\n /* Execute a hook if present */\r\n hookEvent.attrName = lcName;\r\n hookEvent.attrValue = value;\r\n hookEvent.keepAttr = true;\r\n hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set\r\n _executeHook('uponSanitizeAttribute', currentNode, hookEvent);\r\n value = hookEvent.attrValue;\r\n /* Did the hooks approve of the attribute? */\r\n if (hookEvent.forceKeepAttr) {\r\n continue;\r\n }\r\n\r\n /* Remove attribute */\r\n _removeAttribute(name, currentNode);\r\n\r\n /* Did the hooks approve of the attribute? */\r\n if (!hookEvent.keepAttr) {\r\n continue;\r\n }\r\n\r\n /* Work around a security issue in jQuery 3.0 */\r\n if (regExpTest(/\\/>/i, value)) {\r\n _removeAttribute(name, currentNode);\r\n continue;\r\n }\r\n\r\n /* Sanitize attribute content to be template-safe */\r\n if (SAFE_FOR_TEMPLATES) {\r\n value = stringReplace(value, MUSTACHE_EXPR$$1, ' ');\r\n value = stringReplace(value, ERB_EXPR$$1, ' ');\r\n }\r\n\r\n /* Is `value` valid for this attribute? */\r\n var lcTag = currentNode.nodeName.toLowerCase();\r\n if (!_isValidAttribute(lcTag, lcName, value)) {\r\n continue;\r\n }\r\n\r\n /* Handle invalid data-* attribute set by try-catching it */\r\n try {\r\n if (namespaceURI) {\r\n currentNode.setAttributeNS(namespaceURI, name, value);\r\n } else {\r\n /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. \"x-schema\". */\r\n currentNode.setAttribute(name, value);\r\n }\r\n\r\n arrayPop(DOMPurify.removed);\r\n } catch (_) {}\r\n }\r\n\r\n /* Execute a hook if present */\r\n _executeHook('afterSanitizeAttributes', currentNode, null);\r\n };\r\n\r\n /**\r\n * _sanitizeShadowDOM\r\n *\r\n * @param {DocumentFragment} fragment to iterate over recursively\r\n */\r\n var _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {\r\n var shadowNode = void 0;\r\n var shadowIterator = _createIterator(fragment);\r\n\r\n /* Execute a hook if present */\r\n _executeHook('beforeSanitizeShadowDOM', fragment, null);\r\n\r\n while (shadowNode = shadowIterator.nextNode()) {\r\n /* Execute a hook if present */\r\n _executeHook('uponSanitizeShadowNode', shadowNode, null);\r\n\r\n /* Sanitize tags and elements */\r\n if (_sanitizeElements(shadowNode)) {\r\n continue;\r\n }\r\n\r\n /* Deep shadow DOM detected */\r\n if (shadowNode.content instanceof DocumentFragment) {\r\n _sanitizeShadowDOM(shadowNode.content);\r\n }\r\n\r\n /* Check attributes, sanitize if necessary */\r\n _sanitizeAttributes(shadowNode);\r\n }\r\n\r\n /* Execute a hook if present */\r\n _executeHook('afterSanitizeShadowDOM', fragment, null);\r\n };\r\n\r\n /**\r\n * Sanitize\r\n * Public method providing core sanitation functionality\r\n *\r\n * @param {String|Node} dirty string or DOM node\r\n * @param {Object} configuration object\r\n */\r\n // eslint-disable-next-line complexity\r\n DOMPurify.sanitize = function (dirty, cfg) {\r\n var body = void 0;\r\n var importedNode = void 0;\r\n var currentNode = void 0;\r\n var oldNode = void 0;\r\n var returnNode = void 0;\r\n /* Make sure we have a string to sanitize.\r\n DO NOT return early, as this will return the wrong type if\r\n the user has requested a DOM object rather than a string */\r\n if (!dirty) {\r\n dirty = '';\r\n }\r\n\r\n /* Stringify, in case dirty is an object */\r\n if (typeof dirty !== 'string' && !_isNode(dirty)) {\r\n // eslint-disable-next-line no-negated-condition\r\n if (typeof dirty.toString !== 'function') {\r\n throw typeErrorCreate('toString is not a function');\r\n } else {\r\n dirty = dirty.toString();\r\n if (typeof dirty !== 'string') {\r\n throw typeErrorCreate('dirty is not a string, aborting');\r\n }\r\n }\r\n }\r\n\r\n /* Check we can run. Otherwise fall back or ignore */\r\n if (!DOMPurify.isSupported) {\r\n if (_typeof(window.toStaticHTML) === 'object' || typeof window.toStaticHTML === 'function') {\r\n if (typeof dirty === 'string') {\r\n return window.toStaticHTML(dirty);\r\n }\r\n\r\n if (_isNode(dirty)) {\r\n return window.toStaticHTML(dirty.outerHTML);\r\n }\r\n }\r\n\r\n return dirty;\r\n }\r\n\r\n /* Assign config vars */\r\n if (!SET_CONFIG) {\r\n _parseConfig(cfg);\r\n }\r\n\r\n /* Clean up removed elements */\r\n DOMPurify.removed = [];\r\n\r\n /* Check if dirty is correctly typed for IN_PLACE */\r\n if (typeof dirty === 'string') {\r\n IN_PLACE = false;\r\n }\r\n\r\n if (IN_PLACE) ; else if (dirty instanceof Node) {\r\n /* If dirty is a DOM element, append to an empty document to avoid\r\n elements being stripped by the parser */\r\n body = _initDocument('');\r\n importedNode = body.ownerDocument.importNode(dirty, true);\r\n if (importedNode.nodeType === 1 && importedNode.nodeName === 'BODY') {\r\n /* Node is already a body, use as is */\r\n body = importedNode;\r\n } else if (importedNode.nodeName === 'HTML') {\r\n body = importedNode;\r\n } else {\r\n // eslint-disable-next-line unicorn/prefer-node-append\r\n body.appendChild(importedNode);\r\n }\r\n } else {\r\n /* Exit directly if we have nothing to do */\r\n if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&\r\n // eslint-disable-next-line unicorn/prefer-includes\r\n dirty.indexOf('<') === -1) {\r\n return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;\r\n }\r\n\r\n /* Initialize the document to work on */\r\n body = _initDocument(dirty);\r\n\r\n /* Check we have a DOM node from the data */\r\n if (!body) {\r\n return RETURN_DOM ? null : emptyHTML;\r\n }\r\n }\r\n\r\n /* Remove first element node (ours) if FORCE_BODY is set */\r\n if (body && FORCE_BODY) {\r\n _forceRemove(body.firstChild);\r\n }\r\n\r\n /* Get node iterator */\r\n var nodeIterator = _createIterator(IN_PLACE ? dirty : body);\r\n\r\n /* Now start iterating over the created document */\r\n while (currentNode = nodeIterator.nextNode()) {\r\n /* Fix IE's strange behavior with manipulated textNodes #89 */\r\n if (currentNode.nodeType === 3 && currentNode === oldNode) {\r\n continue;\r\n }\r\n\r\n /* Sanitize tags and elements */\r\n if (_sanitizeElements(currentNode)) {\r\n continue;\r\n }\r\n\r\n /* Shadow DOM detected, sanitize it */\r\n if (currentNode.content instanceof DocumentFragment) {\r\n _sanitizeShadowDOM(currentNode.content);\r\n }\r\n\r\n /* Check attributes, sanitize if necessary */\r\n _sanitizeAttributes(currentNode);\r\n\r\n oldNode = currentNode;\r\n }\r\n\r\n oldNode = null;\r\n\r\n /* If we sanitized `dirty` in-place, return it. */\r\n if (IN_PLACE) {\r\n return dirty;\r\n }\r\n\r\n /* Return sanitized string or DOM */\r\n if (RETURN_DOM) {\r\n if (RETURN_DOM_FRAGMENT) {\r\n returnNode = createDocumentFragment.call(body.ownerDocument);\r\n\r\n while (body.firstChild) {\r\n // eslint-disable-next-line unicorn/prefer-node-append\r\n returnNode.appendChild(body.firstChild);\r\n }\r\n } else {\r\n returnNode = body;\r\n }\r\n\r\n if (RETURN_DOM_IMPORT) {\r\n /*\r\n AdoptNode() is not used because internal state is not reset\r\n (e.g. the past names map of a HTMLFormElement), this is safe\r\n in theory but we would rather not risk another attack vector.\r\n The state that is cloned by importNode() is explicitly defined\r\n by the specs.\r\n */\r\n returnNode = importNode.call(originalDocument, returnNode, true);\r\n }\r\n\r\n return returnNode;\r\n }\r\n\r\n var serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;\r\n\r\n /* Sanitize final string template-safe */\r\n if (SAFE_FOR_TEMPLATES) {\r\n serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR$$1, ' ');\r\n serializedHTML = stringReplace(serializedHTML, ERB_EXPR$$1, ' ');\r\n }\r\n\r\n return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;\r\n };\r\n\r\n /**\r\n * Public method to set the configuration once\r\n * setConfig\r\n *\r\n * @param {Object} cfg configuration object\r\n */\r\n DOMPurify.setConfig = function (cfg) {\r\n _parseConfig(cfg);\r\n SET_CONFIG = true;\r\n };\r\n\r\n /**\r\n * Public method to remove the configuration\r\n * clearConfig\r\n *\r\n */\r\n DOMPurify.clearConfig = function () {\r\n CONFIG = null;\r\n SET_CONFIG = false;\r\n };\r\n\r\n /**\r\n * Public method to check if an attribute value is valid.\r\n * Uses last set config, if any. Otherwise, uses config defaults.\r\n * isValidAttribute\r\n *\r\n * @param {string} tag Tag name of containing element.\r\n * @param {string} attr Attribute name.\r\n * @param {string} value Attribute value.\r\n * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.\r\n */\r\n DOMPurify.isValidAttribute = function (tag, attr, value) {\r\n /* Initialize shared config vars if necessary. */\r\n if (!CONFIG) {\r\n _parseConfig({});\r\n }\r\n\r\n var lcTag = stringToLowerCase(tag);\r\n var lcName = stringToLowerCase(attr);\r\n return _isValidAttribute(lcTag, lcName, value);\r\n };\r\n\r\n /**\r\n * AddHook\r\n * Public method to add DOMPurify hooks\r\n *\r\n * @param {String} entryPoint entry point for the hook to add\r\n * @param {Function} hookFunction function to execute\r\n */\r\n DOMPurify.addHook = function (entryPoint, hookFunction) {\r\n if (typeof hookFunction !== 'function') {\r\n return;\r\n }\r\n\r\n hooks[entryPoint] = hooks[entryPoint] || [];\r\n arrayPush(hooks[entryPoint], hookFunction);\r\n };\r\n\r\n /**\r\n * RemoveHook\r\n * Public method to remove a DOMPurify hook at a given entryPoint\r\n * (pops it from the stack of hooks if more are present)\r\n *\r\n * @param {String} entryPoint entry point for the hook to remove\r\n */\r\n DOMPurify.removeHook = function (entryPoint) {\r\n if (hooks[entryPoint]) {\r\n arrayPop(hooks[entryPoint]);\r\n }\r\n };\r\n\r\n /**\r\n * RemoveHooks\r\n * Public method to remove all DOMPurify hooks at a given entryPoint\r\n *\r\n * @param {String} entryPoint entry point for the hooks to remove\r\n */\r\n DOMPurify.removeHooks = function (entryPoint) {\r\n if (hooks[entryPoint]) {\r\n hooks[entryPoint] = [];\r\n }\r\n };\r\n\r\n /**\r\n * RemoveAllHooks\r\n * Public method to remove all DOMPurify hooks\r\n *\r\n */\r\n DOMPurify.removeAllHooks = function () {\r\n hooks = {};\r\n };\r\n\r\n return DOMPurify;\r\n}\r\n\r\nvar purify = createDOMPurify();\r\n\r\nexport default purify;\r\n//# sourceMappingURL=purify.es.js.map\r\n","import DOMPurify from \"../ThirdParty/purify.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\n\r\nvar nextCreditId = 0;\r\nvar creditToId = {};\r\n\r\n/**\r\n * A credit contains data pertaining to how to display attributions/credits for certain content on the screen.\r\n * @param {String} html An string representing an html code snippet\r\n * @param {Boolean} [showOnScreen=false] If true, the credit will be visible in the main credit container. Otherwise, it will appear in a popover\r\n *\r\n * @alias Credit\r\n * @constructor\r\n *\r\n * @exception {DeveloperError} html is required.\r\n *\r\n * @example\r\n * //Create a credit with a tooltip, image and link\r\n * var credit = new Cesium.Credit('
');\r\n */\r\nfunction Credit(html, showOnScreen) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.string(\"html\", html);\r\n //>>includeEnd('debug');\r\n var id;\r\n var key = html;\r\n\r\n if (defined(creditToId[key])) {\r\n id = creditToId[key];\r\n } else {\r\n id = nextCreditId++;\r\n creditToId[key] = id;\r\n }\r\n\r\n showOnScreen = defaultValue(showOnScreen, false);\r\n\r\n // Credits are immutable so generate an id to use to optimize equal()\r\n this._id = id;\r\n this._html = html;\r\n this._showOnScreen = showOnScreen;\r\n this._element = undefined;\r\n}\r\n\r\nObject.defineProperties(Credit.prototype, {\r\n /**\r\n * The credit content\r\n * @memberof Credit.prototype\r\n * @type {String}\r\n * @readonly\r\n */\r\n html: {\r\n get: function () {\r\n return this._html;\r\n },\r\n },\r\n\r\n /**\r\n * @memberof Credit.prototype\r\n * @type {Number}\r\n * @readonly\r\n *\r\n * @private\r\n */\r\n id: {\r\n get: function () {\r\n return this._id;\r\n },\r\n },\r\n\r\n /**\r\n * Whether the credit should be displayed on screen or in a lightbox\r\n * @memberof Credit.prototype\r\n * @type {Boolean}\r\n * @readonly\r\n */\r\n showOnScreen: {\r\n get: function () {\r\n return this._showOnScreen;\r\n },\r\n },\r\n\r\n /**\r\n * Gets the credit element\r\n * @memberof Credit.prototype\r\n * @type {HTMLElement}\r\n * @readonly\r\n */\r\n element: {\r\n get: function () {\r\n if (!defined(this._element)) {\r\n var html = DOMPurify.sanitize(this._html);\r\n\r\n var div = document.createElement(\"div\");\r\n div._creditId = this._id;\r\n div.style.display = \"inline\";\r\n div.innerHTML = html;\r\n\r\n var links = div.querySelectorAll(\"a\");\r\n for (var i = 0; i < links.length; i++) {\r\n links[i].setAttribute(\"target\", \"_blank\");\r\n }\r\n\r\n this._element = div;\r\n }\r\n return this._element;\r\n },\r\n },\r\n});\r\n\r\n/**\r\n * Returns true if the credits are equal\r\n *\r\n * @param {Credit} left The first credit\r\n * @param {Credit} right The second credit\r\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\r\n */\r\nCredit.equals = function (left, right) {\r\n return (\r\n left === right ||\r\n (defined(left) && defined(right) && left._id === right._id)\r\n );\r\n};\r\n\r\n/**\r\n * Returns true if the credits are equal\r\n *\r\n * @param {Credit} credit The credit to compare to.\r\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\r\n */\r\nCredit.prototype.equals = function (credit) {\r\n return Credit.equals(this, credit);\r\n};\r\n\r\n/**\r\n * @private\r\n * @param attribution\r\n * @return {Credit}\r\n */\r\nCredit.getIonCredit = function (attribution) {\r\n var showOnScreen =\r\n defined(attribution.collapsible) && !attribution.collapsible;\r\n var credit = new Credit(attribution.html, showOnScreen);\r\n\r\n credit._isIon = credit.html.indexOf(\"ion-credit.png\") !== -1;\r\n return credit;\r\n};\r\n\r\n/**\r\n * Duplicates a Credit instance.\r\n *\r\n * @param {Credit} [credit] The Credit to duplicate.\r\n * @returns {Credit} A new Credit instance that is a duplicate of the one provided. (Returns undefined if the credit is undefined)\r\n */\r\nCredit.clone = function (credit) {\r\n if (defined(credit)) {\r\n return new Credit(credit.html, credit.showOnScreen);\r\n }\r\n};\r\nexport default Credit;\r\n","/**\r\n * The encoding that is used for a heightmap\r\n *\r\n * @enum {Number}\r\n */\r\nvar HeightmapEncoding = {\r\n /**\r\n * No encoding\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\n NONE: 0,\r\n\r\n /**\r\n * LERC encoding\r\n *\r\n * @type {Number}\r\n * @constant\r\n *\r\n * @see {@link https://github.com/Esri/lerc|The LERC specification}\r\n */\r\n LERC: 1,\r\n};\r\nexport default Object.freeze(HeightmapEncoding);\r\n","import Cartesian3 from \"./Cartesian3.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport Intersect from \"./Intersect.js\";\r\n\r\n/**\r\n * Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.\r\n * @alias AxisAlignedBoundingBox\r\n * @constructor\r\n *\r\n * @param {Cartesian3} [minimum=Cartesian3.ZERO] The minimum point along the x, y, and z axes.\r\n * @param {Cartesian3} [maximum=Cartesian3.ZERO] The maximum point along the x, y, and z axes.\r\n * @param {Cartesian3} [center] The center of the box; automatically computed if not supplied.\r\n *\r\n * @see BoundingSphere\r\n * @see BoundingRectangle\r\n */\r\nfunction AxisAlignedBoundingBox(minimum, maximum, center) {\r\n /**\r\n * The minimum point defining the bounding box.\r\n * @type {Cartesian3}\r\n * @default {@link Cartesian3.ZERO}\r\n */\r\n this.minimum = Cartesian3.clone(defaultValue(minimum, Cartesian3.ZERO));\r\n\r\n /**\r\n * The maximum point defining the bounding box.\r\n * @type {Cartesian3}\r\n * @default {@link Cartesian3.ZERO}\r\n */\r\n this.maximum = Cartesian3.clone(defaultValue(maximum, Cartesian3.ZERO));\r\n\r\n //If center was not defined, compute it.\r\n if (!defined(center)) {\r\n center = Cartesian3.midpoint(this.minimum, this.maximum, new Cartesian3());\r\n } else {\r\n center = Cartesian3.clone(center);\r\n }\r\n\r\n /**\r\n * The center point of the bounding box.\r\n * @type {Cartesian3}\r\n */\r\n this.center = center;\r\n}\r\n\r\n/**\r\n * Computes an instance of an AxisAlignedBoundingBox. The box is determined by\r\n * finding the points spaced the farthest apart on the x, y, and z axes.\r\n *\r\n * @param {Cartesian3[]} positions List of points that the bounding box will enclose. Each point must have a x
, y
, and z
properties.\r\n * @param {AxisAlignedBoundingBox} [result] The object onto which to store the result.\r\n * @returns {AxisAlignedBoundingBox} The modified result parameter or a new AxisAlignedBoundingBox instance if one was not provided.\r\n *\r\n * @example\r\n * // Compute an axis aligned bounding box enclosing two points.\r\n * var box = Cesium.AxisAlignedBoundingBox.fromPoints([new Cesium.Cartesian3(2, 0, 0), new Cesium.Cartesian3(-2, 0, 0)]);\r\n */\r\nAxisAlignedBoundingBox.fromPoints = function (positions, result) {\r\n if (!defined(result)) {\r\n result = new AxisAlignedBoundingBox();\r\n }\r\n\r\n if (!defined(positions) || positions.length === 0) {\r\n result.minimum = Cartesian3.clone(Cartesian3.ZERO, result.minimum);\r\n result.maximum = Cartesian3.clone(Cartesian3.ZERO, result.maximum);\r\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\r\n return result;\r\n }\r\n\r\n var minimumX = positions[0].x;\r\n var minimumY = positions[0].y;\r\n var minimumZ = positions[0].z;\r\n\r\n var maximumX = positions[0].x;\r\n var maximumY = positions[0].y;\r\n var maximumZ = positions[0].z;\r\n\r\n var length = positions.length;\r\n for (var i = 1; i < length; i++) {\r\n var p = positions[i];\r\n var x = p.x;\r\n var y = p.y;\r\n var z = p.z;\r\n\r\n minimumX = Math.min(x, minimumX);\r\n maximumX = Math.max(x, maximumX);\r\n minimumY = Math.min(y, minimumY);\r\n maximumY = Math.max(y, maximumY);\r\n minimumZ = Math.min(z, minimumZ);\r\n maximumZ = Math.max(z, maximumZ);\r\n }\r\n\r\n var minimum = result.minimum;\r\n minimum.x = minimumX;\r\n minimum.y = minimumY;\r\n minimum.z = minimumZ;\r\n\r\n var maximum = result.maximum;\r\n maximum.x = maximumX;\r\n maximum.y = maximumY;\r\n maximum.z = maximumZ;\r\n\r\n result.center = Cartesian3.midpoint(minimum, maximum, result.center);\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Duplicates a AxisAlignedBoundingBox instance.\r\n *\r\n * @param {AxisAlignedBoundingBox} box The bounding box to duplicate.\r\n * @param {AxisAlignedBoundingBox} [result] The object onto which to store the result.\r\n * @returns {AxisAlignedBoundingBox} The modified result parameter or a new AxisAlignedBoundingBox instance if none was provided. (Returns undefined if box is undefined)\r\n */\r\nAxisAlignedBoundingBox.clone = function (box, result) {\r\n if (!defined(box)) {\r\n return undefined;\r\n }\r\n\r\n if (!defined(result)) {\r\n return new AxisAlignedBoundingBox(box.minimum, box.maximum, box.center);\r\n }\r\n\r\n result.minimum = Cartesian3.clone(box.minimum, result.minimum);\r\n result.maximum = Cartesian3.clone(box.maximum, result.maximum);\r\n result.center = Cartesian3.clone(box.center, result.center);\r\n return result;\r\n};\r\n\r\n/**\r\n * Compares the provided AxisAlignedBoundingBox componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {AxisAlignedBoundingBox} [left] The first AxisAlignedBoundingBox.\r\n * @param {AxisAlignedBoundingBox} [right] The second AxisAlignedBoundingBox.\r\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\r\n */\r\nAxisAlignedBoundingBox.equals = function (left, right) {\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n Cartesian3.equals(left.center, right.center) &&\r\n Cartesian3.equals(left.minimum, right.minimum) &&\r\n Cartesian3.equals(left.maximum, right.maximum))\r\n );\r\n};\r\n\r\nvar intersectScratch = new Cartesian3();\r\n/**\r\n * Determines which side of a plane a box is located.\r\n *\r\n * @param {AxisAlignedBoundingBox} box The bounding box to test.\r\n * @param {Plane} plane The plane to test against.\r\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire box is on the side of the plane\r\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire box is\r\n * on the opposite side, and {@link Intersect.INTERSECTING} if the box\r\n * intersects the plane.\r\n */\r\nAxisAlignedBoundingBox.intersectPlane = function (box, plane) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"box\", box);\r\n Check.defined(\"plane\", plane);\r\n //>>includeEnd('debug');\r\n\r\n intersectScratch = Cartesian3.subtract(\r\n box.maximum,\r\n box.minimum,\r\n intersectScratch\r\n );\r\n var h = Cartesian3.multiplyByScalar(intersectScratch, 0.5, intersectScratch); //The positive half diagonal\r\n var normal = plane.normal;\r\n var e =\r\n h.x * Math.abs(normal.x) +\r\n h.y * Math.abs(normal.y) +\r\n h.z * Math.abs(normal.z);\r\n var s = Cartesian3.dot(box.center, normal) + plane.distance; //signed distance from center\r\n\r\n if (s - e > 0) {\r\n return Intersect.INSIDE;\r\n }\r\n\r\n if (s + e < 0) {\r\n //Not in front because normals point inward\r\n return Intersect.OUTSIDE;\r\n }\r\n\r\n return Intersect.INTERSECTING;\r\n};\r\n\r\n/**\r\n * Duplicates this AxisAlignedBoundingBox instance.\r\n *\r\n * @param {AxisAlignedBoundingBox} [result] The object onto which to store the result.\r\n * @returns {AxisAlignedBoundingBox} The modified result parameter or a new AxisAlignedBoundingBox instance if one was not provided.\r\n */\r\nAxisAlignedBoundingBox.prototype.clone = function (result) {\r\n return AxisAlignedBoundingBox.clone(this, result);\r\n};\r\n\r\n/**\r\n * Determines which side of a plane this box is located.\r\n *\r\n * @param {Plane} plane The plane to test against.\r\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire box is on the side of the plane\r\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire box is\r\n * on the opposite side, and {@link Intersect.INTERSECTING} if the box\r\n * intersects the plane.\r\n */\r\nAxisAlignedBoundingBox.prototype.intersectPlane = function (plane) {\r\n return AxisAlignedBoundingBox.intersectPlane(this, plane);\r\n};\r\n\r\n/**\r\n * Compares this AxisAlignedBoundingBox against the provided AxisAlignedBoundingBox componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {AxisAlignedBoundingBox} [right] The right hand side AxisAlignedBoundingBox.\r\n * @returns {Boolean} true
if they are equal, false
otherwise.\r\n */\r\nAxisAlignedBoundingBox.prototype.equals = function (right) {\r\n return AxisAlignedBoundingBox.equals(this, right);\r\n};\r\nexport default AxisAlignedBoundingBox;\r\n","import BoundingSphere from \"./BoundingSphere.js\";\r\nimport Cartesian3 from \"./Cartesian3.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport Ellipsoid from \"./Ellipsoid.js\";\r\nimport Rectangle from \"./Rectangle.js\";\r\n\r\n/**\r\n * Determine whether or not other objects are visible or hidden behind the visible horizon defined by\r\n * an {@link Ellipsoid} and a camera position. The ellipsoid is assumed to be located at the\r\n * origin of the coordinate system. This class uses the algorithm described in the\r\n * {@link https://cesium.com/blog/2013/04/25/Horizon-culling/|Horizon Culling} blog post.\r\n *\r\n * @alias EllipsoidalOccluder\r\n *\r\n * @param {Ellipsoid} ellipsoid The ellipsoid to use as an occluder.\r\n * @param {Cartesian3} [cameraPosition] The coordinate of the viewer/camera. If this parameter is not\r\n * specified, {@link EllipsoidalOccluder#cameraPosition} must be called before\r\n * testing visibility.\r\n *\r\n * @constructor\r\n *\r\n * @example\r\n * // Construct an ellipsoidal occluder with radii 1.0, 1.1, and 0.9.\r\n * var cameraPosition = new Cesium.Cartesian3(5.0, 6.0, 7.0);\r\n * var occluderEllipsoid = new Cesium.Ellipsoid(1.0, 1.1, 0.9);\r\n * var occluder = new Cesium.EllipsoidalOccluder(occluderEllipsoid, cameraPosition);\r\n *\r\n * @private\r\n */\r\nfunction EllipsoidalOccluder(ellipsoid, cameraPosition) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"ellipsoid\", ellipsoid);\r\n //>>includeEnd('debug');\r\n\r\n this._ellipsoid = ellipsoid;\r\n this._cameraPosition = new Cartesian3();\r\n this._cameraPositionInScaledSpace = new Cartesian3();\r\n this._distanceToLimbInScaledSpaceSquared = 0.0;\r\n\r\n // cameraPosition fills in the above values\r\n if (defined(cameraPosition)) {\r\n this.cameraPosition = cameraPosition;\r\n }\r\n}\r\n\r\nObject.defineProperties(EllipsoidalOccluder.prototype, {\r\n /**\r\n * Gets the occluding ellipsoid.\r\n * @memberof EllipsoidalOccluder.prototype\r\n * @type {Ellipsoid}\r\n */\r\n ellipsoid: {\r\n get: function () {\r\n return this._ellipsoid;\r\n },\r\n },\r\n /**\r\n * Gets or sets the position of the camera.\r\n * @memberof EllipsoidalOccluder.prototype\r\n * @type {Cartesian3}\r\n */\r\n cameraPosition: {\r\n get: function () {\r\n return this._cameraPosition;\r\n },\r\n set: function (cameraPosition) {\r\n // See https://cesium.com/blog/2013/04/25/Horizon-culling/\r\n var ellipsoid = this._ellipsoid;\r\n var cv = ellipsoid.transformPositionToScaledSpace(\r\n cameraPosition,\r\n this._cameraPositionInScaledSpace\r\n );\r\n var vhMagnitudeSquared = Cartesian3.magnitudeSquared(cv) - 1.0;\r\n\r\n Cartesian3.clone(cameraPosition, this._cameraPosition);\r\n this._cameraPositionInScaledSpace = cv;\r\n this._distanceToLimbInScaledSpaceSquared = vhMagnitudeSquared;\r\n },\r\n },\r\n});\r\n\r\nvar scratchCartesian = new Cartesian3();\r\n\r\n/**\r\n * Determines whether or not a point, the occludee
, is hidden from view by the occluder.\r\n *\r\n * @param {Cartesian3} occludee The point to test for visibility.\r\n * @returns {Boolean} true
if the occludee is visible; otherwise false
.\r\n *\r\n * @example\r\n * var cameraPosition = new Cesium.Cartesian3(0, 0, 2.5);\r\n * var ellipsoid = new Cesium.Ellipsoid(1.0, 1.1, 0.9);\r\n * var occluder = new Cesium.EllipsoidalOccluder(ellipsoid, cameraPosition);\r\n * var point = new Cesium.Cartesian3(0, -3, -3);\r\n * occluder.isPointVisible(point); //returns true\r\n */\r\nEllipsoidalOccluder.prototype.isPointVisible = function (occludee) {\r\n var ellipsoid = this._ellipsoid;\r\n var occludeeScaledSpacePosition = ellipsoid.transformPositionToScaledSpace(\r\n occludee,\r\n scratchCartesian\r\n );\r\n return isScaledSpacePointVisible(\r\n occludeeScaledSpacePosition,\r\n this._cameraPositionInScaledSpace,\r\n this._distanceToLimbInScaledSpaceSquared\r\n );\r\n};\r\n\r\n/**\r\n * Determines whether or not a point expressed in the ellipsoid scaled space, is hidden from view by the\r\n * occluder. To transform a Cartesian X, Y, Z position in the coordinate system aligned with the ellipsoid\r\n * into the scaled space, call {@link Ellipsoid#transformPositionToScaledSpace}.\r\n *\r\n * @param {Cartesian3} occludeeScaledSpacePosition The point to test for visibility, represented in the scaled space.\r\n * @returns {Boolean} true
if the occludee is visible; otherwise false
.\r\n *\r\n * @example\r\n * var cameraPosition = new Cesium.Cartesian3(0, 0, 2.5);\r\n * var ellipsoid = new Cesium.Ellipsoid(1.0, 1.1, 0.9);\r\n * var occluder = new Cesium.EllipsoidalOccluder(ellipsoid, cameraPosition);\r\n * var point = new Cesium.Cartesian3(0, -3, -3);\r\n * var scaledSpacePoint = ellipsoid.transformPositionToScaledSpace(point);\r\n * occluder.isScaledSpacePointVisible(scaledSpacePoint); //returns true\r\n */\r\nEllipsoidalOccluder.prototype.isScaledSpacePointVisible = function (\r\n occludeeScaledSpacePosition\r\n) {\r\n return isScaledSpacePointVisible(\r\n occludeeScaledSpacePosition,\r\n this._cameraPositionInScaledSpace,\r\n this._distanceToLimbInScaledSpaceSquared\r\n );\r\n};\r\n\r\nvar scratchCameraPositionInScaledSpaceShrunk = new Cartesian3();\r\n\r\n/**\r\n * Similar to {@link EllipsoidalOccluder#isScaledSpacePointVisible} except tests against an\r\n * ellipsoid that has been shrunk by the minimum height when the minimum height is below\r\n * the ellipsoid. This is intended to be used with points generated by\r\n * {@link EllipsoidalOccluder#computeHorizonCullingPointPossiblyUnderEllipsoid} or\r\n * {@link EllipsoidalOccluder#computeHorizonCullingPointFromVerticesPossiblyUnderEllipsoid}.\r\n *\r\n * @param {Cartesian3} occludeeScaledSpacePosition The point to test for visibility, represented in the scaled space of the possibly-shrunk ellipsoid.\r\n * @returns {Boolean} true
if the occludee is visible; otherwise false
.\r\n */\r\nEllipsoidalOccluder.prototype.isScaledSpacePointVisiblePossiblyUnderEllipsoid = function (\r\n occludeeScaledSpacePosition,\r\n minimumHeight\r\n) {\r\n var ellipsoid = this._ellipsoid;\r\n var vhMagnitudeSquared;\r\n var cv;\r\n\r\n if (\r\n defined(minimumHeight) &&\r\n minimumHeight < 0.0 &&\r\n ellipsoid.minimumRadius > -minimumHeight\r\n ) {\r\n // This code is similar to the cameraPosition setter, but unrolled for performance because it will be called a lot.\r\n cv = scratchCameraPositionInScaledSpaceShrunk;\r\n cv.x = this._cameraPosition.x / (ellipsoid.radii.x + minimumHeight);\r\n cv.y = this._cameraPosition.y / (ellipsoid.radii.y + minimumHeight);\r\n cv.z = this._cameraPosition.z / (ellipsoid.radii.z + minimumHeight);\r\n vhMagnitudeSquared = cv.x * cv.x + cv.y * cv.y + cv.z * cv.z - 1.0;\r\n } else {\r\n cv = this._cameraPositionInScaledSpace;\r\n vhMagnitudeSquared = this._distanceToLimbInScaledSpaceSquared;\r\n }\r\n\r\n return isScaledSpacePointVisible(\r\n occludeeScaledSpacePosition,\r\n cv,\r\n vhMagnitudeSquared\r\n );\r\n};\r\n\r\n/**\r\n * Computes a point that can be used for horizon culling from a list of positions. If the point is below\r\n * the horizon, all of the positions are guaranteed to be below the horizon as well. The returned point\r\n * is expressed in the ellipsoid-scaled space and is suitable for use with\r\n * {@link EllipsoidalOccluder#isScaledSpacePointVisible}.\r\n *\r\n * @param {Cartesian3} directionToPoint The direction that the computed point will lie along.\r\n * A reasonable direction to use is the direction from the center of the ellipsoid to\r\n * the center of the bounding sphere computed from the positions. The direction need not\r\n * be normalized.\r\n * @param {Cartesian3[]} positions The positions from which to compute the horizon culling point. The positions\r\n * must be expressed in a reference frame centered at the ellipsoid and aligned with the\r\n * ellipsoid's axes.\r\n * @param {Cartesian3} [result] The instance on which to store the result instead of allocating a new instance.\r\n * @returns {Cartesian3} The computed horizon culling point, expressed in the ellipsoid-scaled space.\r\n */\r\nEllipsoidalOccluder.prototype.computeHorizonCullingPoint = function (\r\n directionToPoint,\r\n positions,\r\n result\r\n) {\r\n return computeHorizonCullingPointFromPositions(\r\n this._ellipsoid,\r\n directionToPoint,\r\n positions,\r\n result\r\n );\r\n};\r\n\r\nvar scratchEllipsoidShrunk = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);\r\n\r\n/**\r\n * Similar to {@link EllipsoidalOccluder#computeHorizonCullingPoint} except computes the culling\r\n * point relative to an ellipsoid that has been shrunk by the minimum height when the minimum height is below\r\n * the ellipsoid. The returned point is expressed in the possibly-shrunk ellipsoid-scaled space and is suitable\r\n * for use with {@link EllipsoidalOccluder#isScaledSpacePointVisiblePossiblyUnderEllipsoid}.\r\n *\r\n * @param {Cartesian3} directionToPoint The direction that the computed point will lie along.\r\n * A reasonable direction to use is the direction from the center of the ellipsoid to\r\n * the center of the bounding sphere computed from the positions. The direction need not\r\n * be normalized.\r\n * @param {Cartesian3[]} positions The positions from which to compute the horizon culling point. The positions\r\n * must be expressed in a reference frame centered at the ellipsoid and aligned with the\r\n * ellipsoid's axes.\r\n * @param {Number} [minimumHeight] The minimum height of all positions. If this value is undefined, all positions are assumed to be above the ellipsoid.\r\n * @param {Cartesian3} [result] The instance on which to store the result instead of allocating a new instance.\r\n * @returns {Cartesian3} The computed horizon culling point, expressed in the possibly-shrunk ellipsoid-scaled space.\r\n */\r\nEllipsoidalOccluder.prototype.computeHorizonCullingPointPossiblyUnderEllipsoid = function (\r\n directionToPoint,\r\n positions,\r\n minimumHeight,\r\n result\r\n) {\r\n var possiblyShrunkEllipsoid = getPossiblyShrunkEllipsoid(\r\n this._ellipsoid,\r\n minimumHeight,\r\n scratchEllipsoidShrunk\r\n );\r\n return computeHorizonCullingPointFromPositions(\r\n possiblyShrunkEllipsoid,\r\n directionToPoint,\r\n positions,\r\n result\r\n );\r\n};\r\n/**\r\n * Computes a point that can be used for horizon culling from a list of positions. If the point is below\r\n * the horizon, all of the positions are guaranteed to be below the horizon as well. The returned point\r\n * is expressed in the ellipsoid-scaled space and is suitable for use with\r\n * {@link EllipsoidalOccluder#isScaledSpacePointVisible}.\r\n *\r\n * @param {Cartesian3} directionToPoint The direction that the computed point will lie along.\r\n * A reasonable direction to use is the direction from the center of the ellipsoid to\r\n * the center of the bounding sphere computed from the positions. The direction need not\r\n * be normalized.\r\n * @param {Number[]} vertices The vertices from which to compute the horizon culling point. The positions\r\n * must be expressed in a reference frame centered at the ellipsoid and aligned with the\r\n * ellipsoid's axes.\r\n * @param {Number} [stride=3]\r\n * @param {Cartesian3} [center=Cartesian3.ZERO]\r\n * @param {Cartesian3} [result] The instance on which to store the result instead of allocating a new instance.\r\n * @returns {Cartesian3} The computed horizon culling point, expressed in the ellipsoid-scaled space.\r\n */\r\nEllipsoidalOccluder.prototype.computeHorizonCullingPointFromVertices = function (\r\n directionToPoint,\r\n vertices,\r\n stride,\r\n center,\r\n result\r\n) {\r\n return computeHorizonCullingPointFromVertices(\r\n this._ellipsoid,\r\n directionToPoint,\r\n vertices,\r\n stride,\r\n center,\r\n result\r\n );\r\n};\r\n\r\n/**\r\n * Similar to {@link EllipsoidalOccluder#computeHorizonCullingPointFromVertices} except computes the culling\r\n * point relative to an ellipsoid that has been shrunk by the minimum height when the minimum height is below\r\n * the ellipsoid. The returned point is expressed in the possibly-shrunk ellipsoid-scaled space and is suitable\r\n * for use with {@link EllipsoidalOccluder#isScaledSpacePointVisiblePossiblyUnderEllipsoid}.\r\n *\r\n * @param {Cartesian3} directionToPoint The direction that the computed point will lie along.\r\n * A reasonable direction to use is the direction from the center of the ellipsoid to\r\n * the center of the bounding sphere computed from the positions. The direction need not\r\n * be normalized.\r\n * @param {Number[]} vertices The vertices from which to compute the horizon culling point. The positions\r\n * must be expressed in a reference frame centered at the ellipsoid and aligned with the\r\n * ellipsoid's axes.\r\n * @param {Number} [stride=3]\r\n * @param {Cartesian3} [center=Cartesian3.ZERO]\r\n * @param {Number} [minimumHeight] The minimum height of all vertices. If this value is undefined, all vertices are assumed to be above the ellipsoid.\r\n * @param {Cartesian3} [result] The instance on which to store the result instead of allocating a new instance.\r\n * @returns {Cartesian3} The computed horizon culling point, expressed in the possibly-shrunk ellipsoid-scaled space.\r\n */\r\nEllipsoidalOccluder.prototype.computeHorizonCullingPointFromVerticesPossiblyUnderEllipsoid = function (\r\n directionToPoint,\r\n vertices,\r\n stride,\r\n center,\r\n minimumHeight,\r\n result\r\n) {\r\n var possiblyShrunkEllipsoid = getPossiblyShrunkEllipsoid(\r\n this._ellipsoid,\r\n minimumHeight,\r\n scratchEllipsoidShrunk\r\n );\r\n return computeHorizonCullingPointFromVertices(\r\n possiblyShrunkEllipsoid,\r\n directionToPoint,\r\n vertices,\r\n stride,\r\n center,\r\n result\r\n );\r\n};\r\n\r\nvar subsampleScratch = [];\r\n\r\n/**\r\n * Computes a point that can be used for horizon culling of a rectangle. If the point is below\r\n * the horizon, the ellipsoid-conforming rectangle is guaranteed to be below the horizon as well.\r\n * The returned point is expressed in the ellipsoid-scaled space and is suitable for use with\r\n * {@link EllipsoidalOccluder#isScaledSpacePointVisible}.\r\n *\r\n * @param {Rectangle} rectangle The rectangle for which to compute the horizon culling point.\r\n * @param {Ellipsoid} ellipsoid The ellipsoid on which the rectangle is defined. This may be different from\r\n * the ellipsoid used by this instance for occlusion testing.\r\n * @param {Cartesian3} [result] The instance on which to store the result instead of allocating a new instance.\r\n * @returns {Cartesian3} The computed horizon culling point, expressed in the ellipsoid-scaled space.\r\n */\r\nEllipsoidalOccluder.prototype.computeHorizonCullingPointFromRectangle = function (\r\n rectangle,\r\n ellipsoid,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"rectangle\", rectangle);\r\n //>>includeEnd('debug');\r\n\r\n var positions = Rectangle.subsample(\r\n rectangle,\r\n ellipsoid,\r\n 0.0,\r\n subsampleScratch\r\n );\r\n var bs = BoundingSphere.fromPoints(positions);\r\n\r\n // If the bounding sphere center is too close to the center of the occluder, it doesn't make\r\n // sense to try to horizon cull it.\r\n if (Cartesian3.magnitude(bs.center) < 0.1 * ellipsoid.minimumRadius) {\r\n return undefined;\r\n }\r\n\r\n return this.computeHorizonCullingPoint(bs.center, positions, result);\r\n};\r\n\r\nvar scratchEllipsoidShrunkRadii = new Cartesian3();\r\n\r\nfunction getPossiblyShrunkEllipsoid(ellipsoid, minimumHeight, result) {\r\n if (\r\n defined(minimumHeight) &&\r\n minimumHeight < 0.0 &&\r\n ellipsoid.minimumRadius > -minimumHeight\r\n ) {\r\n var ellipsoidShrunkRadii = Cartesian3.fromElements(\r\n ellipsoid.radii.x + minimumHeight,\r\n ellipsoid.radii.y + minimumHeight,\r\n ellipsoid.radii.z + minimumHeight,\r\n scratchEllipsoidShrunkRadii\r\n );\r\n ellipsoid = Ellipsoid.fromCartesian3(ellipsoidShrunkRadii, result);\r\n }\r\n return ellipsoid;\r\n}\r\n\r\nfunction computeHorizonCullingPointFromPositions(\r\n ellipsoid,\r\n directionToPoint,\r\n positions,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"directionToPoint\", directionToPoint);\r\n Check.defined(\"positions\", positions);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n\r\n var scaledSpaceDirectionToPoint = computeScaledSpaceDirectionToPoint(\r\n ellipsoid,\r\n directionToPoint\r\n );\r\n var resultMagnitude = 0.0;\r\n\r\n for (var i = 0, len = positions.length; i < len; ++i) {\r\n var position = positions[i];\r\n var candidateMagnitude = computeMagnitude(\r\n ellipsoid,\r\n position,\r\n scaledSpaceDirectionToPoint\r\n );\r\n if (candidateMagnitude < 0.0) {\r\n // all points should face the same direction, but this one doesn't, so return undefined\r\n return undefined;\r\n }\r\n resultMagnitude = Math.max(resultMagnitude, candidateMagnitude);\r\n }\r\n\r\n return magnitudeToPoint(scaledSpaceDirectionToPoint, resultMagnitude, result);\r\n}\r\n\r\nvar positionScratch = new Cartesian3();\r\n\r\nfunction computeHorizonCullingPointFromVertices(\r\n ellipsoid,\r\n directionToPoint,\r\n vertices,\r\n stride,\r\n center,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"directionToPoint\", directionToPoint);\r\n Check.defined(\"vertices\", vertices);\r\n Check.typeOf.number(\"stride\", stride);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n\r\n stride = defaultValue(stride, 3);\r\n center = defaultValue(center, Cartesian3.ZERO);\r\n var scaledSpaceDirectionToPoint = computeScaledSpaceDirectionToPoint(\r\n ellipsoid,\r\n directionToPoint\r\n );\r\n var resultMagnitude = 0.0;\r\n\r\n for (var i = 0, len = vertices.length; i < len; i += stride) {\r\n positionScratch.x = vertices[i] + center.x;\r\n positionScratch.y = vertices[i + 1] + center.y;\r\n positionScratch.z = vertices[i + 2] + center.z;\r\n\r\n var candidateMagnitude = computeMagnitude(\r\n ellipsoid,\r\n positionScratch,\r\n scaledSpaceDirectionToPoint\r\n );\r\n if (candidateMagnitude < 0.0) {\r\n // all points should face the same direction, but this one doesn't, so return undefined\r\n return undefined;\r\n }\r\n resultMagnitude = Math.max(resultMagnitude, candidateMagnitude);\r\n }\r\n\r\n return magnitudeToPoint(scaledSpaceDirectionToPoint, resultMagnitude, result);\r\n}\r\n\r\nfunction isScaledSpacePointVisible(\r\n occludeeScaledSpacePosition,\r\n cameraPositionInScaledSpace,\r\n distanceToLimbInScaledSpaceSquared\r\n) {\r\n // See https://cesium.com/blog/2013/04/25/Horizon-culling/\r\n var cv = cameraPositionInScaledSpace;\r\n var vhMagnitudeSquared = distanceToLimbInScaledSpaceSquared;\r\n var vt = Cartesian3.subtract(\r\n occludeeScaledSpacePosition,\r\n cv,\r\n scratchCartesian\r\n );\r\n var vtDotVc = -Cartesian3.dot(vt, cv);\r\n // If vhMagnitudeSquared < 0 then we are below the surface of the ellipsoid and\r\n // in this case, set the culling plane to be on V.\r\n var isOccluded =\r\n vhMagnitudeSquared < 0\r\n ? vtDotVc > 0\r\n : vtDotVc > vhMagnitudeSquared &&\r\n (vtDotVc * vtDotVc) / Cartesian3.magnitudeSquared(vt) >\r\n vhMagnitudeSquared;\r\n return !isOccluded;\r\n}\r\n\r\nvar scaledSpaceScratch = new Cartesian3();\r\nvar directionScratch = new Cartesian3();\r\n\r\nfunction computeMagnitude(ellipsoid, position, scaledSpaceDirectionToPoint) {\r\n var scaledSpacePosition = ellipsoid.transformPositionToScaledSpace(\r\n position,\r\n scaledSpaceScratch\r\n );\r\n var magnitudeSquared = Cartesian3.magnitudeSquared(scaledSpacePosition);\r\n var magnitude = Math.sqrt(magnitudeSquared);\r\n var direction = Cartesian3.divideByScalar(\r\n scaledSpacePosition,\r\n magnitude,\r\n directionScratch\r\n );\r\n\r\n // For the purpose of this computation, points below the ellipsoid are consider to be on it instead.\r\n magnitudeSquared = Math.max(1.0, magnitudeSquared);\r\n magnitude = Math.max(1.0, magnitude);\r\n\r\n var cosAlpha = Cartesian3.dot(direction, scaledSpaceDirectionToPoint);\r\n var sinAlpha = Cartesian3.magnitude(\r\n Cartesian3.cross(direction, scaledSpaceDirectionToPoint, direction)\r\n );\r\n var cosBeta = 1.0 / magnitude;\r\n var sinBeta = Math.sqrt(magnitudeSquared - 1.0) * cosBeta;\r\n\r\n return 1.0 / (cosAlpha * cosBeta - sinAlpha * sinBeta);\r\n}\r\n\r\nfunction magnitudeToPoint(\r\n scaledSpaceDirectionToPoint,\r\n resultMagnitude,\r\n result\r\n) {\r\n // The horizon culling point is undefined if there were no positions from which to compute it,\r\n // the directionToPoint is pointing opposite all of the positions, or if we computed NaN or infinity.\r\n if (\r\n resultMagnitude <= 0.0 ||\r\n resultMagnitude === 1.0 / 0.0 ||\r\n resultMagnitude !== resultMagnitude\r\n ) {\r\n return undefined;\r\n }\r\n\r\n return Cartesian3.multiplyByScalar(\r\n scaledSpaceDirectionToPoint,\r\n resultMagnitude,\r\n result\r\n );\r\n}\r\n\r\nvar directionToPointScratch = new Cartesian3();\r\n\r\nfunction computeScaledSpaceDirectionToPoint(ellipsoid, directionToPoint) {\r\n if (Cartesian3.equals(directionToPoint, Cartesian3.ZERO)) {\r\n return directionToPoint;\r\n }\r\n\r\n ellipsoid.transformPositionToScaledSpace(\r\n directionToPoint,\r\n directionToPointScratch\r\n );\r\n return Cartesian3.normalize(directionToPointScratch, directionToPointScratch);\r\n}\r\nexport default EllipsoidalOccluder;\r\n","import DeveloperError from \"./DeveloperError.js\";\r\nimport CesiumMath from \"./Math.js\";\r\n\r\n/**\r\n * Defines functions for 2nd order polynomial functions of one variable with only real coefficients.\r\n *\r\n * @namespace QuadraticRealPolynomial\r\n */\r\nvar QuadraticRealPolynomial = {};\r\n\r\n/**\r\n * Provides the discriminant of the quadratic equation from the supplied coefficients.\r\n *\r\n * @param {Number} a The coefficient of the 2nd order monomial.\r\n * @param {Number} b The coefficient of the 1st order monomial.\r\n * @param {Number} c The coefficient of the 0th order monomial.\r\n * @returns {Number} The value of the discriminant.\r\n */\r\nQuadraticRealPolynomial.computeDiscriminant = function (a, b, c) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (typeof a !== \"number\") {\r\n throw new DeveloperError(\"a is a required number.\");\r\n }\r\n if (typeof b !== \"number\") {\r\n throw new DeveloperError(\"b is a required number.\");\r\n }\r\n if (typeof c !== \"number\") {\r\n throw new DeveloperError(\"c is a required number.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var discriminant = b * b - 4.0 * a * c;\r\n return discriminant;\r\n};\r\n\r\nfunction addWithCancellationCheck(left, right, tolerance) {\r\n var difference = left + right;\r\n if (\r\n CesiumMath.sign(left) !== CesiumMath.sign(right) &&\r\n Math.abs(difference / Math.max(Math.abs(left), Math.abs(right))) < tolerance\r\n ) {\r\n return 0.0;\r\n }\r\n\r\n return difference;\r\n}\r\n\r\n/**\r\n * Provides the real valued roots of the quadratic polynomial with the provided coefficients.\r\n *\r\n * @param {Number} a The coefficient of the 2nd order monomial.\r\n * @param {Number} b The coefficient of the 1st order monomial.\r\n * @param {Number} c The coefficient of the 0th order monomial.\r\n * @returns {Number[]} The real valued roots.\r\n */\r\nQuadraticRealPolynomial.computeRealRoots = function (a, b, c) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (typeof a !== \"number\") {\r\n throw new DeveloperError(\"a is a required number.\");\r\n }\r\n if (typeof b !== \"number\") {\r\n throw new DeveloperError(\"b is a required number.\");\r\n }\r\n if (typeof c !== \"number\") {\r\n throw new DeveloperError(\"c is a required number.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var ratio;\r\n if (a === 0.0) {\r\n if (b === 0.0) {\r\n // Constant function: c = 0.\r\n return [];\r\n }\r\n\r\n // Linear function: b * x + c = 0.\r\n return [-c / b];\r\n } else if (b === 0.0) {\r\n if (c === 0.0) {\r\n // 2nd order monomial: a * x^2 = 0.\r\n return [0.0, 0.0];\r\n }\r\n\r\n var cMagnitude = Math.abs(c);\r\n var aMagnitude = Math.abs(a);\r\n\r\n if (\r\n cMagnitude < aMagnitude &&\r\n cMagnitude / aMagnitude < CesiumMath.EPSILON14\r\n ) {\r\n // c ~= 0.0.\r\n // 2nd order monomial: a * x^2 = 0.\r\n return [0.0, 0.0];\r\n } else if (\r\n cMagnitude > aMagnitude &&\r\n aMagnitude / cMagnitude < CesiumMath.EPSILON14\r\n ) {\r\n // a ~= 0.0.\r\n // Constant function: c = 0.\r\n return [];\r\n }\r\n\r\n // a * x^2 + c = 0\r\n ratio = -c / a;\r\n\r\n if (ratio < 0.0) {\r\n // Both roots are complex.\r\n return [];\r\n }\r\n\r\n // Both roots are real.\r\n var root = Math.sqrt(ratio);\r\n return [-root, root];\r\n } else if (c === 0.0) {\r\n // a * x^2 + b * x = 0\r\n ratio = -b / a;\r\n if (ratio < 0.0) {\r\n return [ratio, 0.0];\r\n }\r\n\r\n return [0.0, ratio];\r\n }\r\n\r\n // a * x^2 + b * x + c = 0\r\n var b2 = b * b;\r\n var four_ac = 4.0 * a * c;\r\n var radicand = addWithCancellationCheck(b2, -four_ac, CesiumMath.EPSILON14);\r\n\r\n if (radicand < 0.0) {\r\n // Both roots are complex.\r\n return [];\r\n }\r\n\r\n var q =\r\n -0.5 *\r\n addWithCancellationCheck(\r\n b,\r\n CesiumMath.sign(b) * Math.sqrt(radicand),\r\n CesiumMath.EPSILON14\r\n );\r\n if (b > 0.0) {\r\n return [q / a, c / q];\r\n }\r\n\r\n return [c / q, q / a];\r\n};\r\nexport default QuadraticRealPolynomial;\r\n","import DeveloperError from \"./DeveloperError.js\";\r\nimport QuadraticRealPolynomial from \"./QuadraticRealPolynomial.js\";\r\n\r\n/**\r\n * Defines functions for 3rd order polynomial functions of one variable with only real coefficients.\r\n *\r\n * @namespace CubicRealPolynomial\r\n */\r\nvar CubicRealPolynomial = {};\r\n\r\n/**\r\n * Provides the discriminant of the cubic equation from the supplied coefficients.\r\n *\r\n * @param {Number} a The coefficient of the 3rd order monomial.\r\n * @param {Number} b The coefficient of the 2nd order monomial.\r\n * @param {Number} c The coefficient of the 1st order monomial.\r\n * @param {Number} d The coefficient of the 0th order monomial.\r\n * @returns {Number} The value of the discriminant.\r\n */\r\nCubicRealPolynomial.computeDiscriminant = function (a, b, c, d) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (typeof a !== \"number\") {\r\n throw new DeveloperError(\"a is a required number.\");\r\n }\r\n if (typeof b !== \"number\") {\r\n throw new DeveloperError(\"b is a required number.\");\r\n }\r\n if (typeof c !== \"number\") {\r\n throw new DeveloperError(\"c is a required number.\");\r\n }\r\n if (typeof d !== \"number\") {\r\n throw new DeveloperError(\"d is a required number.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var a2 = a * a;\r\n var b2 = b * b;\r\n var c2 = c * c;\r\n var d2 = d * d;\r\n\r\n var discriminant =\r\n 18.0 * a * b * c * d +\r\n b2 * c2 -\r\n 27.0 * a2 * d2 -\r\n 4.0 * (a * c2 * c + b2 * b * d);\r\n return discriminant;\r\n};\r\n\r\nfunction computeRealRoots(a, b, c, d) {\r\n var A = a;\r\n var B = b / 3.0;\r\n var C = c / 3.0;\r\n var D = d;\r\n\r\n var AC = A * C;\r\n var BD = B * D;\r\n var B2 = B * B;\r\n var C2 = C * C;\r\n var delta1 = A * C - B2;\r\n var delta2 = A * D - B * C;\r\n var delta3 = B * D - C2;\r\n\r\n var discriminant = 4.0 * delta1 * delta3 - delta2 * delta2;\r\n var temp;\r\n var temp1;\r\n\r\n if (discriminant < 0.0) {\r\n var ABar;\r\n var CBar;\r\n var DBar;\r\n\r\n if (B2 * BD >= AC * C2) {\r\n ABar = A;\r\n CBar = delta1;\r\n DBar = -2.0 * B * delta1 + A * delta2;\r\n } else {\r\n ABar = D;\r\n CBar = delta3;\r\n DBar = -D * delta2 + 2.0 * C * delta3;\r\n }\r\n\r\n var s = DBar < 0.0 ? -1.0 : 1.0; // This is not Math.Sign()!\r\n var temp0 = -s * Math.abs(ABar) * Math.sqrt(-discriminant);\r\n temp1 = -DBar + temp0;\r\n\r\n var x = temp1 / 2.0;\r\n var p = x < 0.0 ? -Math.pow(-x, 1.0 / 3.0) : Math.pow(x, 1.0 / 3.0);\r\n var q = temp1 === temp0 ? -p : -CBar / p;\r\n\r\n temp = CBar <= 0.0 ? p + q : -DBar / (p * p + q * q + CBar);\r\n\r\n if (B2 * BD >= AC * C2) {\r\n return [(temp - B) / A];\r\n }\r\n\r\n return [-D / (temp + C)];\r\n }\r\n\r\n var CBarA = delta1;\r\n var DBarA = -2.0 * B * delta1 + A * delta2;\r\n\r\n var CBarD = delta3;\r\n var DBarD = -D * delta2 + 2.0 * C * delta3;\r\n\r\n var squareRootOfDiscriminant = Math.sqrt(discriminant);\r\n var halfSquareRootOf3 = Math.sqrt(3.0) / 2.0;\r\n\r\n var theta = Math.abs(Math.atan2(A * squareRootOfDiscriminant, -DBarA) / 3.0);\r\n temp = 2.0 * Math.sqrt(-CBarA);\r\n var cosine = Math.cos(theta);\r\n temp1 = temp * cosine;\r\n var temp3 = temp * (-cosine / 2.0 - halfSquareRootOf3 * Math.sin(theta));\r\n\r\n var numeratorLarge = temp1 + temp3 > 2.0 * B ? temp1 - B : temp3 - B;\r\n var denominatorLarge = A;\r\n\r\n var root1 = numeratorLarge / denominatorLarge;\r\n\r\n theta = Math.abs(Math.atan2(D * squareRootOfDiscriminant, -DBarD) / 3.0);\r\n temp = 2.0 * Math.sqrt(-CBarD);\r\n cosine = Math.cos(theta);\r\n temp1 = temp * cosine;\r\n temp3 = temp * (-cosine / 2.0 - halfSquareRootOf3 * Math.sin(theta));\r\n\r\n var numeratorSmall = -D;\r\n var denominatorSmall = temp1 + temp3 < 2.0 * C ? temp1 + C : temp3 + C;\r\n\r\n var root3 = numeratorSmall / denominatorSmall;\r\n\r\n var E = denominatorLarge * denominatorSmall;\r\n var F =\r\n -numeratorLarge * denominatorSmall - denominatorLarge * numeratorSmall;\r\n var G = numeratorLarge * numeratorSmall;\r\n\r\n var root2 = (C * F - B * G) / (-B * F + C * E);\r\n\r\n if (root1 <= root2) {\r\n if (root1 <= root3) {\r\n if (root2 <= root3) {\r\n return [root1, root2, root3];\r\n }\r\n return [root1, root3, root2];\r\n }\r\n return [root3, root1, root2];\r\n }\r\n if (root1 <= root3) {\r\n return [root2, root1, root3];\r\n }\r\n if (root2 <= root3) {\r\n return [root2, root3, root1];\r\n }\r\n return [root3, root2, root1];\r\n}\r\n\r\n/**\r\n * Provides the real valued roots of the cubic polynomial with the provided coefficients.\r\n *\r\n * @param {Number} a The coefficient of the 3rd order monomial.\r\n * @param {Number} b The coefficient of the 2nd order monomial.\r\n * @param {Number} c The coefficient of the 1st order monomial.\r\n * @param {Number} d The coefficient of the 0th order monomial.\r\n * @returns {Number[]} The real valued roots.\r\n */\r\nCubicRealPolynomial.computeRealRoots = function (a, b, c, d) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (typeof a !== \"number\") {\r\n throw new DeveloperError(\"a is a required number.\");\r\n }\r\n if (typeof b !== \"number\") {\r\n throw new DeveloperError(\"b is a required number.\");\r\n }\r\n if (typeof c !== \"number\") {\r\n throw new DeveloperError(\"c is a required number.\");\r\n }\r\n if (typeof d !== \"number\") {\r\n throw new DeveloperError(\"d is a required number.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var roots;\r\n var ratio;\r\n if (a === 0.0) {\r\n // Quadratic function: b * x^2 + c * x + d = 0.\r\n return QuadraticRealPolynomial.computeRealRoots(b, c, d);\r\n } else if (b === 0.0) {\r\n if (c === 0.0) {\r\n if (d === 0.0) {\r\n // 3rd order monomial: a * x^3 = 0.\r\n return [0.0, 0.0, 0.0];\r\n }\r\n\r\n // a * x^3 + d = 0\r\n ratio = -d / a;\r\n var root =\r\n ratio < 0.0 ? -Math.pow(-ratio, 1.0 / 3.0) : Math.pow(ratio, 1.0 / 3.0);\r\n return [root, root, root];\r\n } else if (d === 0.0) {\r\n // x * (a * x^2 + c) = 0.\r\n roots = QuadraticRealPolynomial.computeRealRoots(a, 0, c);\r\n\r\n // Return the roots in ascending order.\r\n if (roots.Length === 0) {\r\n return [0.0];\r\n }\r\n return [roots[0], 0.0, roots[1]];\r\n }\r\n\r\n // Deflated cubic polynomial: a * x^3 + c * x + d= 0.\r\n return computeRealRoots(a, 0, c, d);\r\n } else if (c === 0.0) {\r\n if (d === 0.0) {\r\n // x^2 * (a * x + b) = 0.\r\n ratio = -b / a;\r\n if (ratio < 0.0) {\r\n return [ratio, 0.0, 0.0];\r\n }\r\n return [0.0, 0.0, ratio];\r\n }\r\n // a * x^3 + b * x^2 + d = 0.\r\n return computeRealRoots(a, b, 0, d);\r\n } else if (d === 0.0) {\r\n // x * (a * x^2 + b * x + c) = 0\r\n roots = QuadraticRealPolynomial.computeRealRoots(a, b, c);\r\n\r\n // Return the roots in ascending order.\r\n if (roots.length === 0) {\r\n return [0.0];\r\n } else if (roots[1] <= 0.0) {\r\n return [roots[0], roots[1], 0.0];\r\n } else if (roots[0] >= 0.0) {\r\n return [0.0, roots[0], roots[1]];\r\n }\r\n return [roots[0], 0.0, roots[1]];\r\n }\r\n\r\n return computeRealRoots(a, b, c, d);\r\n};\r\nexport default CubicRealPolynomial;\r\n","import CubicRealPolynomial from \"./CubicRealPolynomial.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport CesiumMath from \"./Math.js\";\r\nimport QuadraticRealPolynomial from \"./QuadraticRealPolynomial.js\";\r\n\r\n/**\r\n * Defines functions for 4th order polynomial functions of one variable with only real coefficients.\r\n *\r\n * @namespace QuarticRealPolynomial\r\n */\r\nvar QuarticRealPolynomial = {};\r\n\r\n/**\r\n * Provides the discriminant of the quartic equation from the supplied coefficients.\r\n *\r\n * @param {Number} a The coefficient of the 4th order monomial.\r\n * @param {Number} b The coefficient of the 3rd order monomial.\r\n * @param {Number} c The coefficient of the 2nd order monomial.\r\n * @param {Number} d The coefficient of the 1st order monomial.\r\n * @param {Number} e The coefficient of the 0th order monomial.\r\n * @returns {Number} The value of the discriminant.\r\n */\r\nQuarticRealPolynomial.computeDiscriminant = function (a, b, c, d, e) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (typeof a !== \"number\") {\r\n throw new DeveloperError(\"a is a required number.\");\r\n }\r\n if (typeof b !== \"number\") {\r\n throw new DeveloperError(\"b is a required number.\");\r\n }\r\n if (typeof c !== \"number\") {\r\n throw new DeveloperError(\"c is a required number.\");\r\n }\r\n if (typeof d !== \"number\") {\r\n throw new DeveloperError(\"d is a required number.\");\r\n }\r\n if (typeof e !== \"number\") {\r\n throw new DeveloperError(\"e is a required number.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var a2 = a * a;\r\n var a3 = a2 * a;\r\n var b2 = b * b;\r\n var b3 = b2 * b;\r\n var c2 = c * c;\r\n var c3 = c2 * c;\r\n var d2 = d * d;\r\n var d3 = d2 * d;\r\n var e2 = e * e;\r\n var e3 = e2 * e;\r\n\r\n var discriminant =\r\n b2 * c2 * d2 -\r\n 4.0 * b3 * d3 -\r\n 4.0 * a * c3 * d2 +\r\n 18 * a * b * c * d3 -\r\n 27.0 * a2 * d2 * d2 +\r\n 256.0 * a3 * e3 +\r\n e *\r\n (18.0 * b3 * c * d -\r\n 4.0 * b2 * c3 +\r\n 16.0 * a * c2 * c2 -\r\n 80.0 * a * b * c2 * d -\r\n 6.0 * a * b2 * d2 +\r\n 144.0 * a2 * c * d2) +\r\n e2 *\r\n (144.0 * a * b2 * c -\r\n 27.0 * b2 * b2 -\r\n 128.0 * a2 * c2 -\r\n 192.0 * a2 * b * d);\r\n return discriminant;\r\n};\r\n\r\nfunction original(a3, a2, a1, a0) {\r\n var a3Squared = a3 * a3;\r\n\r\n var p = a2 - (3.0 * a3Squared) / 8.0;\r\n var q = a1 - (a2 * a3) / 2.0 + (a3Squared * a3) / 8.0;\r\n var r =\r\n a0 -\r\n (a1 * a3) / 4.0 +\r\n (a2 * a3Squared) / 16.0 -\r\n (3.0 * a3Squared * a3Squared) / 256.0;\r\n\r\n // Find the roots of the cubic equations: h^6 + 2 p h^4 + (p^2 - 4 r) h^2 - q^2 = 0.\r\n var cubicRoots = CubicRealPolynomial.computeRealRoots(\r\n 1.0,\r\n 2.0 * p,\r\n p * p - 4.0 * r,\r\n -q * q\r\n );\r\n\r\n if (cubicRoots.length > 0) {\r\n var temp = -a3 / 4.0;\r\n\r\n // Use the largest positive root.\r\n var hSquared = cubicRoots[cubicRoots.length - 1];\r\n\r\n if (Math.abs(hSquared) < CesiumMath.EPSILON14) {\r\n // y^4 + p y^2 + r = 0.\r\n var roots = QuadraticRealPolynomial.computeRealRoots(1.0, p, r);\r\n\r\n if (roots.length === 2) {\r\n var root0 = roots[0];\r\n var root1 = roots[1];\r\n\r\n var y;\r\n if (root0 >= 0.0 && root1 >= 0.0) {\r\n var y0 = Math.sqrt(root0);\r\n var y1 = Math.sqrt(root1);\r\n\r\n return [temp - y1, temp - y0, temp + y0, temp + y1];\r\n } else if (root0 >= 0.0 && root1 < 0.0) {\r\n y = Math.sqrt(root0);\r\n return [temp - y, temp + y];\r\n } else if (root0 < 0.0 && root1 >= 0.0) {\r\n y = Math.sqrt(root1);\r\n return [temp - y, temp + y];\r\n }\r\n }\r\n return [];\r\n } else if (hSquared > 0.0) {\r\n var h = Math.sqrt(hSquared);\r\n\r\n var m = (p + hSquared - q / h) / 2.0;\r\n var n = (p + hSquared + q / h) / 2.0;\r\n\r\n // Now solve the two quadratic factors: (y^2 + h y + m)(y^2 - h y + n);\r\n var roots1 = QuadraticRealPolynomial.computeRealRoots(1.0, h, m);\r\n var roots2 = QuadraticRealPolynomial.computeRealRoots(1.0, -h, n);\r\n\r\n if (roots1.length !== 0) {\r\n roots1[0] += temp;\r\n roots1[1] += temp;\r\n\r\n if (roots2.length !== 0) {\r\n roots2[0] += temp;\r\n roots2[1] += temp;\r\n\r\n if (roots1[1] <= roots2[0]) {\r\n return [roots1[0], roots1[1], roots2[0], roots2[1]];\r\n } else if (roots2[1] <= roots1[0]) {\r\n return [roots2[0], roots2[1], roots1[0], roots1[1]];\r\n } else if (roots1[0] >= roots2[0] && roots1[1] <= roots2[1]) {\r\n return [roots2[0], roots1[0], roots1[1], roots2[1]];\r\n } else if (roots2[0] >= roots1[0] && roots2[1] <= roots1[1]) {\r\n return [roots1[0], roots2[0], roots2[1], roots1[1]];\r\n } else if (roots1[0] > roots2[0] && roots1[0] < roots2[1]) {\r\n return [roots2[0], roots1[0], roots2[1], roots1[1]];\r\n }\r\n return [roots1[0], roots2[0], roots1[1], roots2[1]];\r\n }\r\n return roots1;\r\n }\r\n\r\n if (roots2.length !== 0) {\r\n roots2[0] += temp;\r\n roots2[1] += temp;\r\n\r\n return roots2;\r\n }\r\n return [];\r\n }\r\n }\r\n return [];\r\n}\r\n\r\nfunction neumark(a3, a2, a1, a0) {\r\n var a1Squared = a1 * a1;\r\n var a2Squared = a2 * a2;\r\n var a3Squared = a3 * a3;\r\n\r\n var p = -2.0 * a2;\r\n var q = a1 * a3 + a2Squared - 4.0 * a0;\r\n var r = a3Squared * a0 - a1 * a2 * a3 + a1Squared;\r\n\r\n var cubicRoots = CubicRealPolynomial.computeRealRoots(1.0, p, q, r);\r\n\r\n if (cubicRoots.length > 0) {\r\n // Use the most positive root\r\n var y = cubicRoots[0];\r\n\r\n var temp = a2 - y;\r\n var tempSquared = temp * temp;\r\n\r\n var g1 = a3 / 2.0;\r\n var h1 = temp / 2.0;\r\n\r\n var m = tempSquared - 4.0 * a0;\r\n var mError = tempSquared + 4.0 * Math.abs(a0);\r\n\r\n var n = a3Squared - 4.0 * y;\r\n var nError = a3Squared + 4.0 * Math.abs(y);\r\n\r\n var g2;\r\n var h2;\r\n\r\n if (y < 0.0 || m * nError < n * mError) {\r\n var squareRootOfN = Math.sqrt(n);\r\n g2 = squareRootOfN / 2.0;\r\n h2 = squareRootOfN === 0.0 ? 0.0 : (a3 * h1 - a1) / squareRootOfN;\r\n } else {\r\n var squareRootOfM = Math.sqrt(m);\r\n g2 = squareRootOfM === 0.0 ? 0.0 : (a3 * h1 - a1) / squareRootOfM;\r\n h2 = squareRootOfM / 2.0;\r\n }\r\n\r\n var G;\r\n var g;\r\n if (g1 === 0.0 && g2 === 0.0) {\r\n G = 0.0;\r\n g = 0.0;\r\n } else if (CesiumMath.sign(g1) === CesiumMath.sign(g2)) {\r\n G = g1 + g2;\r\n g = y / G;\r\n } else {\r\n g = g1 - g2;\r\n G = y / g;\r\n }\r\n\r\n var H;\r\n var h;\r\n if (h1 === 0.0 && h2 === 0.0) {\r\n H = 0.0;\r\n h = 0.0;\r\n } else if (CesiumMath.sign(h1) === CesiumMath.sign(h2)) {\r\n H = h1 + h2;\r\n h = a0 / H;\r\n } else {\r\n h = h1 - h2;\r\n H = a0 / h;\r\n }\r\n\r\n // Now solve the two quadratic factors: (y^2 + G y + H)(y^2 + g y + h);\r\n var roots1 = QuadraticRealPolynomial.computeRealRoots(1.0, G, H);\r\n var roots2 = QuadraticRealPolynomial.computeRealRoots(1.0, g, h);\r\n\r\n if (roots1.length !== 0) {\r\n if (roots2.length !== 0) {\r\n if (roots1[1] <= roots2[0]) {\r\n return [roots1[0], roots1[1], roots2[0], roots2[1]];\r\n } else if (roots2[1] <= roots1[0]) {\r\n return [roots2[0], roots2[1], roots1[0], roots1[1]];\r\n } else if (roots1[0] >= roots2[0] && roots1[1] <= roots2[1]) {\r\n return [roots2[0], roots1[0], roots1[1], roots2[1]];\r\n } else if (roots2[0] >= roots1[0] && roots2[1] <= roots1[1]) {\r\n return [roots1[0], roots2[0], roots2[1], roots1[1]];\r\n } else if (roots1[0] > roots2[0] && roots1[0] < roots2[1]) {\r\n return [roots2[0], roots1[0], roots2[1], roots1[1]];\r\n }\r\n return [roots1[0], roots2[0], roots1[1], roots2[1]];\r\n }\r\n return roots1;\r\n }\r\n if (roots2.length !== 0) {\r\n return roots2;\r\n }\r\n }\r\n return [];\r\n}\r\n\r\n/**\r\n * Provides the real valued roots of the quartic polynomial with the provided coefficients.\r\n *\r\n * @param {Number} a The coefficient of the 4th order monomial.\r\n * @param {Number} b The coefficient of the 3rd order monomial.\r\n * @param {Number} c The coefficient of the 2nd order monomial.\r\n * @param {Number} d The coefficient of the 1st order monomial.\r\n * @param {Number} e The coefficient of the 0th order monomial.\r\n * @returns {Number[]} The real valued roots.\r\n */\r\nQuarticRealPolynomial.computeRealRoots = function (a, b, c, d, e) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (typeof a !== \"number\") {\r\n throw new DeveloperError(\"a is a required number.\");\r\n }\r\n if (typeof b !== \"number\") {\r\n throw new DeveloperError(\"b is a required number.\");\r\n }\r\n if (typeof c !== \"number\") {\r\n throw new DeveloperError(\"c is a required number.\");\r\n }\r\n if (typeof d !== \"number\") {\r\n throw new DeveloperError(\"d is a required number.\");\r\n }\r\n if (typeof e !== \"number\") {\r\n throw new DeveloperError(\"e is a required number.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n if (Math.abs(a) < CesiumMath.EPSILON15) {\r\n return CubicRealPolynomial.computeRealRoots(b, c, d, e);\r\n }\r\n var a3 = b / a;\r\n var a2 = c / a;\r\n var a1 = d / a;\r\n var a0 = e / a;\r\n\r\n var k = a3 < 0.0 ? 1 : 0;\r\n k += a2 < 0.0 ? k + 1 : k;\r\n k += a1 < 0.0 ? k + 1 : k;\r\n k += a0 < 0.0 ? k + 1 : k;\r\n\r\n switch (k) {\r\n case 0:\r\n return original(a3, a2, a1, a0);\r\n case 1:\r\n return neumark(a3, a2, a1, a0);\r\n case 2:\r\n return neumark(a3, a2, a1, a0);\r\n case 3:\r\n return original(a3, a2, a1, a0);\r\n case 4:\r\n return original(a3, a2, a1, a0);\r\n case 5:\r\n return neumark(a3, a2, a1, a0);\r\n case 6:\r\n return original(a3, a2, a1, a0);\r\n case 7:\r\n return original(a3, a2, a1, a0);\r\n case 8:\r\n return neumark(a3, a2, a1, a0);\r\n case 9:\r\n return original(a3, a2, a1, a0);\r\n case 10:\r\n return original(a3, a2, a1, a0);\r\n case 11:\r\n return neumark(a3, a2, a1, a0);\r\n case 12:\r\n return original(a3, a2, a1, a0);\r\n case 13:\r\n return original(a3, a2, a1, a0);\r\n case 14:\r\n return original(a3, a2, a1, a0);\r\n case 15:\r\n return original(a3, a2, a1, a0);\r\n default:\r\n return undefined;\r\n }\r\n};\r\nexport default QuarticRealPolynomial;\r\n","import Cartesian3 from \"./Cartesian3.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\n\r\n/**\r\n * Represents a ray that extends infinitely from the provided origin in the provided direction.\r\n * @alias Ray\r\n * @constructor\r\n *\r\n * @param {Cartesian3} [origin=Cartesian3.ZERO] The origin of the ray.\r\n * @param {Cartesian3} [direction=Cartesian3.ZERO] The direction of the ray.\r\n */\r\nfunction Ray(origin, direction) {\r\n direction = Cartesian3.clone(defaultValue(direction, Cartesian3.ZERO));\r\n if (!Cartesian3.equals(direction, Cartesian3.ZERO)) {\r\n Cartesian3.normalize(direction, direction);\r\n }\r\n\r\n /**\r\n * The origin of the ray.\r\n * @type {Cartesian3}\r\n * @default {@link Cartesian3.ZERO}\r\n */\r\n this.origin = Cartesian3.clone(defaultValue(origin, Cartesian3.ZERO));\r\n\r\n /**\r\n * The direction of the ray.\r\n * @type {Cartesian3}\r\n */\r\n this.direction = direction;\r\n}\r\n\r\n/**\r\n * Duplicates a Ray instance.\r\n *\r\n * @param {Ray} ray The ray to duplicate.\r\n * @param {Ray} [result] The object onto which to store the result.\r\n * @returns {Ray} The modified result parameter or a new Ray instance if one was not provided. (Returns undefined if ray is undefined)\r\n */\r\nRay.clone = function (ray, result) {\r\n if (!defined(ray)) {\r\n return undefined;\r\n }\r\n if (!defined(result)) {\r\n return new Ray(ray.origin, ray.direction);\r\n }\r\n result.origin = Cartesian3.clone(ray.origin);\r\n result.direction = Cartesian3.clone(ray.direction);\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the point along the ray given by r(t) = o + t*d,\r\n * where o is the origin of the ray and d is the direction.\r\n *\r\n * @param {Ray} ray The ray.\r\n * @param {Number} t A scalar value.\r\n * @param {Cartesian3} [result] The object in which the result will be stored.\r\n * @returns {Cartesian3} The modified result parameter, or a new instance if none was provided.\r\n *\r\n * @example\r\n * //Get the first intersection point of a ray and an ellipsoid.\r\n * var intersection = Cesium.IntersectionTests.rayEllipsoid(ray, ellipsoid);\r\n * var point = Cesium.Ray.getPoint(ray, intersection.start);\r\n */\r\nRay.getPoint = function (ray, t, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"ray\", ray);\r\n Check.typeOf.number(\"t\", t);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n\r\n result = Cartesian3.multiplyByScalar(ray.direction, t, result);\r\n return Cartesian3.add(ray.origin, result, result);\r\n};\r\nexport default Ray;\r\n","import Cartesian3 from \"./Cartesian3.js\";\r\nimport Cartographic from \"./Cartographic.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport Interval from \"./Interval.js\";\r\nimport CesiumMath from \"./Math.js\";\r\nimport Matrix3 from \"./Matrix3.js\";\r\nimport QuadraticRealPolynomial from \"./QuadraticRealPolynomial.js\";\r\nimport QuarticRealPolynomial from \"./QuarticRealPolynomial.js\";\r\nimport Ray from \"./Ray.js\";\r\n\r\n/**\r\n * Functions for computing the intersection between geometries such as rays, planes, triangles, and ellipsoids.\r\n *\r\n * @namespace IntersectionTests\r\n */\r\nvar IntersectionTests = {};\r\n\r\n/**\r\n * Computes the intersection of a ray and a plane.\r\n *\r\n * @param {Ray} ray The ray.\r\n * @param {Plane} plane The plane.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The intersection point or undefined if there is no intersections.\r\n */\r\nIntersectionTests.rayPlane = function (ray, plane, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(ray)) {\r\n throw new DeveloperError(\"ray is required.\");\r\n }\r\n if (!defined(plane)) {\r\n throw new DeveloperError(\"plane is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n\r\n var origin = ray.origin;\r\n var direction = ray.direction;\r\n var normal = plane.normal;\r\n var denominator = Cartesian3.dot(normal, direction);\r\n\r\n if (Math.abs(denominator) < CesiumMath.EPSILON15) {\r\n // Ray is parallel to plane. The ray may be in the polygon's plane.\r\n return undefined;\r\n }\r\n\r\n var t = (-plane.distance - Cartesian3.dot(normal, origin)) / denominator;\r\n\r\n if (t < 0) {\r\n return undefined;\r\n }\r\n\r\n result = Cartesian3.multiplyByScalar(direction, t, result);\r\n return Cartesian3.add(origin, result, result);\r\n};\r\n\r\nvar scratchEdge0 = new Cartesian3();\r\nvar scratchEdge1 = new Cartesian3();\r\nvar scratchPVec = new Cartesian3();\r\nvar scratchTVec = new Cartesian3();\r\nvar scratchQVec = new Cartesian3();\r\n\r\n/**\r\n * Computes the intersection of a ray and a triangle as a parametric distance along the input ray. The result is negative when the triangle is behind the ray.\r\n *\r\n * Implements {@link https://cadxfem.org/inf/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf|\r\n * Fast Minimum Storage Ray/Triangle Intersection} by Tomas Moller and Ben Trumbore.\r\n *\r\n * @memberof IntersectionTests\r\n *\r\n * @param {Ray} ray The ray.\r\n * @param {Cartesian3} p0 The first vertex of the triangle.\r\n * @param {Cartesian3} p1 The second vertex of the triangle.\r\n * @param {Cartesian3} p2 The third vertex of the triangle.\r\n * @param {Boolean} [cullBackFaces=false] If true
, will only compute an intersection with the front face of the triangle\r\n * and return undefined for intersections with the back face.\r\n * @returns {Number} The intersection as a parametric distance along the ray, or undefined if there is no intersection.\r\n */\r\nIntersectionTests.rayTriangleParametric = function (\r\n ray,\r\n p0,\r\n p1,\r\n p2,\r\n cullBackFaces\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(ray)) {\r\n throw new DeveloperError(\"ray is required.\");\r\n }\r\n if (!defined(p0)) {\r\n throw new DeveloperError(\"p0 is required.\");\r\n }\r\n if (!defined(p1)) {\r\n throw new DeveloperError(\"p1 is required.\");\r\n }\r\n if (!defined(p2)) {\r\n throw new DeveloperError(\"p2 is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n cullBackFaces = defaultValue(cullBackFaces, false);\r\n\r\n var origin = ray.origin;\r\n var direction = ray.direction;\r\n\r\n var edge0 = Cartesian3.subtract(p1, p0, scratchEdge0);\r\n var edge1 = Cartesian3.subtract(p2, p0, scratchEdge1);\r\n\r\n var p = Cartesian3.cross(direction, edge1, scratchPVec);\r\n var det = Cartesian3.dot(edge0, p);\r\n\r\n var tvec;\r\n var q;\r\n\r\n var u;\r\n var v;\r\n var t;\r\n\r\n if (cullBackFaces) {\r\n if (det < CesiumMath.EPSILON6) {\r\n return undefined;\r\n }\r\n\r\n tvec = Cartesian3.subtract(origin, p0, scratchTVec);\r\n u = Cartesian3.dot(tvec, p);\r\n if (u < 0.0 || u > det) {\r\n return undefined;\r\n }\r\n\r\n q = Cartesian3.cross(tvec, edge0, scratchQVec);\r\n\r\n v = Cartesian3.dot(direction, q);\r\n if (v < 0.0 || u + v > det) {\r\n return undefined;\r\n }\r\n\r\n t = Cartesian3.dot(edge1, q) / det;\r\n } else {\r\n if (Math.abs(det) < CesiumMath.EPSILON6) {\r\n return undefined;\r\n }\r\n var invDet = 1.0 / det;\r\n\r\n tvec = Cartesian3.subtract(origin, p0, scratchTVec);\r\n u = Cartesian3.dot(tvec, p) * invDet;\r\n if (u < 0.0 || u > 1.0) {\r\n return undefined;\r\n }\r\n\r\n q = Cartesian3.cross(tvec, edge0, scratchQVec);\r\n\r\n v = Cartesian3.dot(direction, q) * invDet;\r\n if (v < 0.0 || u + v > 1.0) {\r\n return undefined;\r\n }\r\n\r\n t = Cartesian3.dot(edge1, q) * invDet;\r\n }\r\n\r\n return t;\r\n};\r\n\r\n/**\r\n * Computes the intersection of a ray and a triangle as a Cartesian3 coordinate.\r\n *\r\n * Implements {@link https://cadxfem.org/inf/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf|\r\n * Fast Minimum Storage Ray/Triangle Intersection} by Tomas Moller and Ben Trumbore.\r\n *\r\n * @memberof IntersectionTests\r\n *\r\n * @param {Ray} ray The ray.\r\n * @param {Cartesian3} p0 The first vertex of the triangle.\r\n * @param {Cartesian3} p1 The second vertex of the triangle.\r\n * @param {Cartesian3} p2 The third vertex of the triangle.\r\n * @param {Boolean} [cullBackFaces=false] If true
, will only compute an intersection with the front face of the triangle\r\n * and return undefined for intersections with the back face.\r\n * @param {Cartesian3} [result] The Cartesian3
onto which to store the result.\r\n * @returns {Cartesian3} The intersection point or undefined if there is no intersections.\r\n */\r\nIntersectionTests.rayTriangle = function (\r\n ray,\r\n p0,\r\n p1,\r\n p2,\r\n cullBackFaces,\r\n result\r\n) {\r\n var t = IntersectionTests.rayTriangleParametric(\r\n ray,\r\n p0,\r\n p1,\r\n p2,\r\n cullBackFaces\r\n );\r\n if (!defined(t) || t < 0.0) {\r\n return undefined;\r\n }\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n\r\n Cartesian3.multiplyByScalar(ray.direction, t, result);\r\n return Cartesian3.add(ray.origin, result, result);\r\n};\r\n\r\nvar scratchLineSegmentTriangleRay = new Ray();\r\n\r\n/**\r\n * Computes the intersection of a line segment and a triangle.\r\n * @memberof IntersectionTests\r\n *\r\n * @param {Cartesian3} v0 The an end point of the line segment.\r\n * @param {Cartesian3} v1 The other end point of the line segment.\r\n * @param {Cartesian3} p0 The first vertex of the triangle.\r\n * @param {Cartesian3} p1 The second vertex of the triangle.\r\n * @param {Cartesian3} p2 The third vertex of the triangle.\r\n * @param {Boolean} [cullBackFaces=false] If true
, will only compute an intersection with the front face of the triangle\r\n * and return undefined for intersections with the back face.\r\n * @param {Cartesian3} [result] The Cartesian3
onto which to store the result.\r\n * @returns {Cartesian3} The intersection point or undefined if there is no intersections.\r\n */\r\nIntersectionTests.lineSegmentTriangle = function (\r\n v0,\r\n v1,\r\n p0,\r\n p1,\r\n p2,\r\n cullBackFaces,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(v0)) {\r\n throw new DeveloperError(\"v0 is required.\");\r\n }\r\n if (!defined(v1)) {\r\n throw new DeveloperError(\"v1 is required.\");\r\n }\r\n if (!defined(p0)) {\r\n throw new DeveloperError(\"p0 is required.\");\r\n }\r\n if (!defined(p1)) {\r\n throw new DeveloperError(\"p1 is required.\");\r\n }\r\n if (!defined(p2)) {\r\n throw new DeveloperError(\"p2 is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var ray = scratchLineSegmentTriangleRay;\r\n Cartesian3.clone(v0, ray.origin);\r\n Cartesian3.subtract(v1, v0, ray.direction);\r\n Cartesian3.normalize(ray.direction, ray.direction);\r\n\r\n var t = IntersectionTests.rayTriangleParametric(\r\n ray,\r\n p0,\r\n p1,\r\n p2,\r\n cullBackFaces\r\n );\r\n if (!defined(t) || t < 0.0 || t > Cartesian3.distance(v0, v1)) {\r\n return undefined;\r\n }\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n\r\n Cartesian3.multiplyByScalar(ray.direction, t, result);\r\n return Cartesian3.add(ray.origin, result, result);\r\n};\r\n\r\nfunction solveQuadratic(a, b, c, result) {\r\n var det = b * b - 4.0 * a * c;\r\n if (det < 0.0) {\r\n return undefined;\r\n } else if (det > 0.0) {\r\n var denom = 1.0 / (2.0 * a);\r\n var disc = Math.sqrt(det);\r\n var root0 = (-b + disc) * denom;\r\n var root1 = (-b - disc) * denom;\r\n\r\n if (root0 < root1) {\r\n result.root0 = root0;\r\n result.root1 = root1;\r\n } else {\r\n result.root0 = root1;\r\n result.root1 = root0;\r\n }\r\n\r\n return result;\r\n }\r\n\r\n var root = -b / (2.0 * a);\r\n if (root === 0.0) {\r\n return undefined;\r\n }\r\n\r\n result.root0 = result.root1 = root;\r\n return result;\r\n}\r\n\r\nvar raySphereRoots = {\r\n root0: 0.0,\r\n root1: 0.0,\r\n};\r\n\r\nfunction raySphere(ray, sphere, result) {\r\n if (!defined(result)) {\r\n result = new Interval();\r\n }\r\n\r\n var origin = ray.origin;\r\n var direction = ray.direction;\r\n\r\n var center = sphere.center;\r\n var radiusSquared = sphere.radius * sphere.radius;\r\n\r\n var diff = Cartesian3.subtract(origin, center, scratchPVec);\r\n\r\n var a = Cartesian3.dot(direction, direction);\r\n var b = 2.0 * Cartesian3.dot(direction, diff);\r\n var c = Cartesian3.magnitudeSquared(diff) - radiusSquared;\r\n\r\n var roots = solveQuadratic(a, b, c, raySphereRoots);\r\n if (!defined(roots)) {\r\n return undefined;\r\n }\r\n\r\n result.start = roots.root0;\r\n result.stop = roots.root1;\r\n return result;\r\n}\r\n\r\n/**\r\n * Computes the intersection points of a ray with a sphere.\r\n * @memberof IntersectionTests\r\n *\r\n * @param {Ray} ray The ray.\r\n * @param {BoundingSphere} sphere The sphere.\r\n * @param {Interval} [result] The result onto which to store the result.\r\n * @returns {Interval} The interval containing scalar points along the ray or undefined if there are no intersections.\r\n */\r\nIntersectionTests.raySphere = function (ray, sphere, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(ray)) {\r\n throw new DeveloperError(\"ray is required.\");\r\n }\r\n if (!defined(sphere)) {\r\n throw new DeveloperError(\"sphere is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n result = raySphere(ray, sphere, result);\r\n if (!defined(result) || result.stop < 0.0) {\r\n return undefined;\r\n }\r\n\r\n result.start = Math.max(result.start, 0.0);\r\n return result;\r\n};\r\n\r\nvar scratchLineSegmentRay = new Ray();\r\n\r\n/**\r\n * Computes the intersection points of a line segment with a sphere.\r\n * @memberof IntersectionTests\r\n *\r\n * @param {Cartesian3} p0 An end point of the line segment.\r\n * @param {Cartesian3} p1 The other end point of the line segment.\r\n * @param {BoundingSphere} sphere The sphere.\r\n * @param {Interval} [result] The result onto which to store the result.\r\n * @returns {Interval} The interval containing scalar points along the ray or undefined if there are no intersections.\r\n */\r\nIntersectionTests.lineSegmentSphere = function (p0, p1, sphere, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(p0)) {\r\n throw new DeveloperError(\"p0 is required.\");\r\n }\r\n if (!defined(p1)) {\r\n throw new DeveloperError(\"p1 is required.\");\r\n }\r\n if (!defined(sphere)) {\r\n throw new DeveloperError(\"sphere is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var ray = scratchLineSegmentRay;\r\n Cartesian3.clone(p0, ray.origin);\r\n var direction = Cartesian3.subtract(p1, p0, ray.direction);\r\n\r\n var maxT = Cartesian3.magnitude(direction);\r\n Cartesian3.normalize(direction, direction);\r\n\r\n result = raySphere(ray, sphere, result);\r\n if (!defined(result) || result.stop < 0.0 || result.start > maxT) {\r\n return undefined;\r\n }\r\n\r\n result.start = Math.max(result.start, 0.0);\r\n result.stop = Math.min(result.stop, maxT);\r\n return result;\r\n};\r\n\r\nvar scratchQ = new Cartesian3();\r\nvar scratchW = new Cartesian3();\r\n\r\n/**\r\n * Computes the intersection points of a ray with an ellipsoid.\r\n *\r\n * @param {Ray} ray The ray.\r\n * @param {Ellipsoid} ellipsoid The ellipsoid.\r\n * @returns {Interval} The interval containing scalar points along the ray or undefined if there are no intersections.\r\n */\r\nIntersectionTests.rayEllipsoid = function (ray, ellipsoid) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(ray)) {\r\n throw new DeveloperError(\"ray is required.\");\r\n }\r\n if (!defined(ellipsoid)) {\r\n throw new DeveloperError(\"ellipsoid is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var inverseRadii = ellipsoid.oneOverRadii;\r\n var q = Cartesian3.multiplyComponents(inverseRadii, ray.origin, scratchQ);\r\n var w = Cartesian3.multiplyComponents(inverseRadii, ray.direction, scratchW);\r\n\r\n var q2 = Cartesian3.magnitudeSquared(q);\r\n var qw = Cartesian3.dot(q, w);\r\n\r\n var difference, w2, product, discriminant, temp;\r\n\r\n if (q2 > 1.0) {\r\n // Outside ellipsoid.\r\n if (qw >= 0.0) {\r\n // Looking outward or tangent (0 intersections).\r\n return undefined;\r\n }\r\n\r\n // qw < 0.0.\r\n var qw2 = qw * qw;\r\n difference = q2 - 1.0; // Positively valued.\r\n w2 = Cartesian3.magnitudeSquared(w);\r\n product = w2 * difference;\r\n\r\n if (qw2 < product) {\r\n // Imaginary roots (0 intersections).\r\n return undefined;\r\n } else if (qw2 > product) {\r\n // Distinct roots (2 intersections).\r\n discriminant = qw * qw - product;\r\n temp = -qw + Math.sqrt(discriminant); // Avoid cancellation.\r\n var root0 = temp / w2;\r\n var root1 = difference / temp;\r\n if (root0 < root1) {\r\n return new Interval(root0, root1);\r\n }\r\n\r\n return {\r\n start: root1,\r\n stop: root0,\r\n };\r\n }\r\n // qw2 == product. Repeated roots (2 intersections).\r\n var root = Math.sqrt(difference / w2);\r\n return new Interval(root, root);\r\n } else if (q2 < 1.0) {\r\n // Inside ellipsoid (2 intersections).\r\n difference = q2 - 1.0; // Negatively valued.\r\n w2 = Cartesian3.magnitudeSquared(w);\r\n product = w2 * difference; // Negatively valued.\r\n\r\n discriminant = qw * qw - product;\r\n temp = -qw + Math.sqrt(discriminant); // Positively valued.\r\n return new Interval(0.0, temp / w2);\r\n }\r\n // q2 == 1.0. On ellipsoid.\r\n if (qw < 0.0) {\r\n // Looking inward.\r\n w2 = Cartesian3.magnitudeSquared(w);\r\n return new Interval(0.0, -qw / w2);\r\n }\r\n\r\n // qw >= 0.0. Looking outward or tangent.\r\n return undefined;\r\n};\r\n\r\nfunction addWithCancellationCheck(left, right, tolerance) {\r\n var difference = left + right;\r\n if (\r\n CesiumMath.sign(left) !== CesiumMath.sign(right) &&\r\n Math.abs(difference / Math.max(Math.abs(left), Math.abs(right))) < tolerance\r\n ) {\r\n return 0.0;\r\n }\r\n\r\n return difference;\r\n}\r\n\r\nfunction quadraticVectorExpression(A, b, c, x, w) {\r\n var xSquared = x * x;\r\n var wSquared = w * w;\r\n\r\n var l2 = (A[Matrix3.COLUMN1ROW1] - A[Matrix3.COLUMN2ROW2]) * wSquared;\r\n var l1 =\r\n w *\r\n (x *\r\n addWithCancellationCheck(\r\n A[Matrix3.COLUMN1ROW0],\r\n A[Matrix3.COLUMN0ROW1],\r\n CesiumMath.EPSILON15\r\n ) +\r\n b.y);\r\n var l0 =\r\n A[Matrix3.COLUMN0ROW0] * xSquared +\r\n A[Matrix3.COLUMN2ROW2] * wSquared +\r\n x * b.x +\r\n c;\r\n\r\n var r1 =\r\n wSquared *\r\n addWithCancellationCheck(\r\n A[Matrix3.COLUMN2ROW1],\r\n A[Matrix3.COLUMN1ROW2],\r\n CesiumMath.EPSILON15\r\n );\r\n var r0 =\r\n w *\r\n (x *\r\n addWithCancellationCheck(A[Matrix3.COLUMN2ROW0], A[Matrix3.COLUMN0ROW2]) +\r\n b.z);\r\n\r\n var cosines;\r\n var solutions = [];\r\n if (r0 === 0.0 && r1 === 0.0) {\r\n cosines = QuadraticRealPolynomial.computeRealRoots(l2, l1, l0);\r\n if (cosines.length === 0) {\r\n return solutions;\r\n }\r\n\r\n var cosine0 = cosines[0];\r\n var sine0 = Math.sqrt(Math.max(1.0 - cosine0 * cosine0, 0.0));\r\n solutions.push(new Cartesian3(x, w * cosine0, w * -sine0));\r\n solutions.push(new Cartesian3(x, w * cosine0, w * sine0));\r\n\r\n if (cosines.length === 2) {\r\n var cosine1 = cosines[1];\r\n var sine1 = Math.sqrt(Math.max(1.0 - cosine1 * cosine1, 0.0));\r\n solutions.push(new Cartesian3(x, w * cosine1, w * -sine1));\r\n solutions.push(new Cartesian3(x, w * cosine1, w * sine1));\r\n }\r\n\r\n return solutions;\r\n }\r\n\r\n var r0Squared = r0 * r0;\r\n var r1Squared = r1 * r1;\r\n var l2Squared = l2 * l2;\r\n var r0r1 = r0 * r1;\r\n\r\n var c4 = l2Squared + r1Squared;\r\n var c3 = 2.0 * (l1 * l2 + r0r1);\r\n var c2 = 2.0 * l0 * l2 + l1 * l1 - r1Squared + r0Squared;\r\n var c1 = 2.0 * (l0 * l1 - r0r1);\r\n var c0 = l0 * l0 - r0Squared;\r\n\r\n if (c4 === 0.0 && c3 === 0.0 && c2 === 0.0 && c1 === 0.0) {\r\n return solutions;\r\n }\r\n\r\n cosines = QuarticRealPolynomial.computeRealRoots(c4, c3, c2, c1, c0);\r\n var length = cosines.length;\r\n if (length === 0) {\r\n return solutions;\r\n }\r\n\r\n for (var i = 0; i < length; ++i) {\r\n var cosine = cosines[i];\r\n var cosineSquared = cosine * cosine;\r\n var sineSquared = Math.max(1.0 - cosineSquared, 0.0);\r\n var sine = Math.sqrt(sineSquared);\r\n\r\n //var left = l2 * cosineSquared + l1 * cosine + l0;\r\n var left;\r\n if (CesiumMath.sign(l2) === CesiumMath.sign(l0)) {\r\n left = addWithCancellationCheck(\r\n l2 * cosineSquared + l0,\r\n l1 * cosine,\r\n CesiumMath.EPSILON12\r\n );\r\n } else if (CesiumMath.sign(l0) === CesiumMath.sign(l1 * cosine)) {\r\n left = addWithCancellationCheck(\r\n l2 * cosineSquared,\r\n l1 * cosine + l0,\r\n CesiumMath.EPSILON12\r\n );\r\n } else {\r\n left = addWithCancellationCheck(\r\n l2 * cosineSquared + l1 * cosine,\r\n l0,\r\n CesiumMath.EPSILON12\r\n );\r\n }\r\n\r\n var right = addWithCancellationCheck(r1 * cosine, r0, CesiumMath.EPSILON15);\r\n var product = left * right;\r\n\r\n if (product < 0.0) {\r\n solutions.push(new Cartesian3(x, w * cosine, w * sine));\r\n } else if (product > 0.0) {\r\n solutions.push(new Cartesian3(x, w * cosine, w * -sine));\r\n } else if (sine !== 0.0) {\r\n solutions.push(new Cartesian3(x, w * cosine, w * -sine));\r\n solutions.push(new Cartesian3(x, w * cosine, w * sine));\r\n ++i;\r\n } else {\r\n solutions.push(new Cartesian3(x, w * cosine, w * sine));\r\n }\r\n }\r\n\r\n return solutions;\r\n}\r\n\r\nvar firstAxisScratch = new Cartesian3();\r\nvar secondAxisScratch = new Cartesian3();\r\nvar thirdAxisScratch = new Cartesian3();\r\nvar referenceScratch = new Cartesian3();\r\nvar bCart = new Cartesian3();\r\nvar bScratch = new Matrix3();\r\nvar btScratch = new Matrix3();\r\nvar diScratch = new Matrix3();\r\nvar dScratch = new Matrix3();\r\nvar cScratch = new Matrix3();\r\nvar tempMatrix = new Matrix3();\r\nvar aScratch = new Matrix3();\r\nvar sScratch = new Cartesian3();\r\nvar closestScratch = new Cartesian3();\r\nvar surfPointScratch = new Cartographic();\r\n\r\n/**\r\n * Provides the point along the ray which is nearest to the ellipsoid.\r\n *\r\n * @param {Ray} ray The ray.\r\n * @param {Ellipsoid} ellipsoid The ellipsoid.\r\n * @returns {Cartesian3} The nearest planetodetic point on the ray.\r\n */\r\nIntersectionTests.grazingAltitudeLocation = function (ray, ellipsoid) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(ray)) {\r\n throw new DeveloperError(\"ray is required.\");\r\n }\r\n if (!defined(ellipsoid)) {\r\n throw new DeveloperError(\"ellipsoid is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var position = ray.origin;\r\n var direction = ray.direction;\r\n\r\n if (!Cartesian3.equals(position, Cartesian3.ZERO)) {\r\n var normal = ellipsoid.geodeticSurfaceNormal(position, firstAxisScratch);\r\n if (Cartesian3.dot(direction, normal) >= 0.0) {\r\n // The location provided is the closest point in altitude\r\n return position;\r\n }\r\n }\r\n\r\n var intersects = defined(this.rayEllipsoid(ray, ellipsoid));\r\n\r\n // Compute the scaled direction vector.\r\n var f = ellipsoid.transformPositionToScaledSpace(direction, firstAxisScratch);\r\n\r\n // Constructs a basis from the unit scaled direction vector. Construct its rotation and transpose.\r\n var firstAxis = Cartesian3.normalize(f, f);\r\n var reference = Cartesian3.mostOrthogonalAxis(f, referenceScratch);\r\n var secondAxis = Cartesian3.normalize(\r\n Cartesian3.cross(reference, firstAxis, secondAxisScratch),\r\n secondAxisScratch\r\n );\r\n var thirdAxis = Cartesian3.normalize(\r\n Cartesian3.cross(firstAxis, secondAxis, thirdAxisScratch),\r\n thirdAxisScratch\r\n );\r\n var B = bScratch;\r\n B[0] = firstAxis.x;\r\n B[1] = firstAxis.y;\r\n B[2] = firstAxis.z;\r\n B[3] = secondAxis.x;\r\n B[4] = secondAxis.y;\r\n B[5] = secondAxis.z;\r\n B[6] = thirdAxis.x;\r\n B[7] = thirdAxis.y;\r\n B[8] = thirdAxis.z;\r\n\r\n var B_T = Matrix3.transpose(B, btScratch);\r\n\r\n // Get the scaling matrix and its inverse.\r\n var D_I = Matrix3.fromScale(ellipsoid.radii, diScratch);\r\n var D = Matrix3.fromScale(ellipsoid.oneOverRadii, dScratch);\r\n\r\n var C = cScratch;\r\n C[0] = 0.0;\r\n C[1] = -direction.z;\r\n C[2] = direction.y;\r\n C[3] = direction.z;\r\n C[4] = 0.0;\r\n C[5] = -direction.x;\r\n C[6] = -direction.y;\r\n C[7] = direction.x;\r\n C[8] = 0.0;\r\n\r\n var temp = Matrix3.multiply(\r\n Matrix3.multiply(B_T, D, tempMatrix),\r\n C,\r\n tempMatrix\r\n );\r\n var A = Matrix3.multiply(Matrix3.multiply(temp, D_I, aScratch), B, aScratch);\r\n var b = Matrix3.multiplyByVector(temp, position, bCart);\r\n\r\n // Solve for the solutions to the expression in standard form:\r\n var solutions = quadraticVectorExpression(\r\n A,\r\n Cartesian3.negate(b, firstAxisScratch),\r\n 0.0,\r\n 0.0,\r\n 1.0\r\n );\r\n\r\n var s;\r\n var altitude;\r\n var length = solutions.length;\r\n if (length > 0) {\r\n var closest = Cartesian3.clone(Cartesian3.ZERO, closestScratch);\r\n var maximumValue = Number.NEGATIVE_INFINITY;\r\n\r\n for (var i = 0; i < length; ++i) {\r\n s = Matrix3.multiplyByVector(\r\n D_I,\r\n Matrix3.multiplyByVector(B, solutions[i], sScratch),\r\n sScratch\r\n );\r\n var v = Cartesian3.normalize(\r\n Cartesian3.subtract(s, position, referenceScratch),\r\n referenceScratch\r\n );\r\n var dotProduct = Cartesian3.dot(v, direction);\r\n\r\n if (dotProduct > maximumValue) {\r\n maximumValue = dotProduct;\r\n closest = Cartesian3.clone(s, closest);\r\n }\r\n }\r\n\r\n var surfacePoint = ellipsoid.cartesianToCartographic(\r\n closest,\r\n surfPointScratch\r\n );\r\n maximumValue = CesiumMath.clamp(maximumValue, 0.0, 1.0);\r\n altitude =\r\n Cartesian3.magnitude(\r\n Cartesian3.subtract(closest, position, referenceScratch)\r\n ) * Math.sqrt(1.0 - maximumValue * maximumValue);\r\n altitude = intersects ? -altitude : altitude;\r\n surfacePoint.height = altitude;\r\n return ellipsoid.cartographicToCartesian(surfacePoint, new Cartesian3());\r\n }\r\n\r\n return undefined;\r\n};\r\n\r\nvar lineSegmentPlaneDifference = new Cartesian3();\r\n\r\n/**\r\n * Computes the intersection of a line segment and a plane.\r\n *\r\n * @param {Cartesian3} endPoint0 An end point of the line segment.\r\n * @param {Cartesian3} endPoint1 The other end point of the line segment.\r\n * @param {Plane} plane The plane.\r\n * @param {Cartesian3} [result] The object onto which to store the result.\r\n * @returns {Cartesian3} The intersection point or undefined if there is no intersection.\r\n *\r\n * @example\r\n * var origin = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);\r\n * var normal = ellipsoid.geodeticSurfaceNormal(origin);\r\n * var plane = Cesium.Plane.fromPointNormal(origin, normal);\r\n *\r\n * var p0 = new Cesium.Cartesian3(...);\r\n * var p1 = new Cesium.Cartesian3(...);\r\n *\r\n * // find the intersection of the line segment from p0 to p1 and the tangent plane at origin.\r\n * var intersection = Cesium.IntersectionTests.lineSegmentPlane(p0, p1, plane);\r\n */\r\nIntersectionTests.lineSegmentPlane = function (\r\n endPoint0,\r\n endPoint1,\r\n plane,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(endPoint0)) {\r\n throw new DeveloperError(\"endPoint0 is required.\");\r\n }\r\n if (!defined(endPoint1)) {\r\n throw new DeveloperError(\"endPoint1 is required.\");\r\n }\r\n if (!defined(plane)) {\r\n throw new DeveloperError(\"plane is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n\r\n var difference = Cartesian3.subtract(\r\n endPoint1,\r\n endPoint0,\r\n lineSegmentPlaneDifference\r\n );\r\n var normal = plane.normal;\r\n var nDotDiff = Cartesian3.dot(normal, difference);\r\n\r\n // check if the segment and plane are parallel\r\n if (Math.abs(nDotDiff) < CesiumMath.EPSILON6) {\r\n return undefined;\r\n }\r\n\r\n var nDotP0 = Cartesian3.dot(normal, endPoint0);\r\n var t = -(plane.distance + nDotP0) / nDotDiff;\r\n\r\n // intersection only if t is in [0, 1]\r\n if (t < 0.0 || t > 1.0) {\r\n return undefined;\r\n }\r\n\r\n // intersection is endPoint0 + t * (endPoint1 - endPoint0)\r\n Cartesian3.multiplyByScalar(difference, t, result);\r\n Cartesian3.add(endPoint0, result, result);\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the intersection of a triangle and a plane\r\n *\r\n * @param {Cartesian3} p0 First point of the triangle\r\n * @param {Cartesian3} p1 Second point of the triangle\r\n * @param {Cartesian3} p2 Third point of the triangle\r\n * @param {Plane} plane Intersection plane\r\n * @returns {Object} An object with properties positions
and indices
, which are arrays that represent three triangles that do not cross the plane. (Undefined if no intersection exists)\r\n *\r\n * @example\r\n * var origin = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);\r\n * var normal = ellipsoid.geodeticSurfaceNormal(origin);\r\n * var plane = Cesium.Plane.fromPointNormal(origin, normal);\r\n *\r\n * var p0 = new Cesium.Cartesian3(...);\r\n * var p1 = new Cesium.Cartesian3(...);\r\n * var p2 = new Cesium.Cartesian3(...);\r\n *\r\n * // convert the triangle composed of points (p0, p1, p2) to three triangles that don't cross the plane\r\n * var triangles = Cesium.IntersectionTests.trianglePlaneIntersection(p0, p1, p2, plane);\r\n */\r\nIntersectionTests.trianglePlaneIntersection = function (p0, p1, p2, plane) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(p0) || !defined(p1) || !defined(p2) || !defined(plane)) {\r\n throw new DeveloperError(\"p0, p1, p2, and plane are required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var planeNormal = plane.normal;\r\n var planeD = plane.distance;\r\n var p0Behind = Cartesian3.dot(planeNormal, p0) + planeD < 0.0;\r\n var p1Behind = Cartesian3.dot(planeNormal, p1) + planeD < 0.0;\r\n var p2Behind = Cartesian3.dot(planeNormal, p2) + planeD < 0.0;\r\n // Given these dots products, the calls to lineSegmentPlaneIntersection\r\n // always have defined results.\r\n\r\n var numBehind = 0;\r\n numBehind += p0Behind ? 1 : 0;\r\n numBehind += p1Behind ? 1 : 0;\r\n numBehind += p2Behind ? 1 : 0;\r\n\r\n var u1, u2;\r\n if (numBehind === 1 || numBehind === 2) {\r\n u1 = new Cartesian3();\r\n u2 = new Cartesian3();\r\n }\r\n\r\n if (numBehind === 1) {\r\n if (p0Behind) {\r\n IntersectionTests.lineSegmentPlane(p0, p1, plane, u1);\r\n IntersectionTests.lineSegmentPlane(p0, p2, plane, u2);\r\n\r\n return {\r\n positions: [p0, p1, p2, u1, u2],\r\n indices: [\r\n // Behind\r\n 0,\r\n 3,\r\n 4,\r\n\r\n // In front\r\n 1,\r\n 2,\r\n 4,\r\n 1,\r\n 4,\r\n 3,\r\n ],\r\n };\r\n } else if (p1Behind) {\r\n IntersectionTests.lineSegmentPlane(p1, p2, plane, u1);\r\n IntersectionTests.lineSegmentPlane(p1, p0, plane, u2);\r\n\r\n return {\r\n positions: [p0, p1, p2, u1, u2],\r\n indices: [\r\n // Behind\r\n 1,\r\n 3,\r\n 4,\r\n\r\n // In front\r\n 2,\r\n 0,\r\n 4,\r\n 2,\r\n 4,\r\n 3,\r\n ],\r\n };\r\n } else if (p2Behind) {\r\n IntersectionTests.lineSegmentPlane(p2, p0, plane, u1);\r\n IntersectionTests.lineSegmentPlane(p2, p1, plane, u2);\r\n\r\n return {\r\n positions: [p0, p1, p2, u1, u2],\r\n indices: [\r\n // Behind\r\n 2,\r\n 3,\r\n 4,\r\n\r\n // In front\r\n 0,\r\n 1,\r\n 4,\r\n 0,\r\n 4,\r\n 3,\r\n ],\r\n };\r\n }\r\n } else if (numBehind === 2) {\r\n if (!p0Behind) {\r\n IntersectionTests.lineSegmentPlane(p1, p0, plane, u1);\r\n IntersectionTests.lineSegmentPlane(p2, p0, plane, u2);\r\n\r\n return {\r\n positions: [p0, p1, p2, u1, u2],\r\n indices: [\r\n // Behind\r\n 1,\r\n 2,\r\n 4,\r\n 1,\r\n 4,\r\n 3,\r\n\r\n // In front\r\n 0,\r\n 3,\r\n 4,\r\n ],\r\n };\r\n } else if (!p1Behind) {\r\n IntersectionTests.lineSegmentPlane(p2, p1, plane, u1);\r\n IntersectionTests.lineSegmentPlane(p0, p1, plane, u2);\r\n\r\n return {\r\n positions: [p0, p1, p2, u1, u2],\r\n indices: [\r\n // Behind\r\n 2,\r\n 0,\r\n 4,\r\n 2,\r\n 4,\r\n 3,\r\n\r\n // In front\r\n 1,\r\n 3,\r\n 4,\r\n ],\r\n };\r\n } else if (!p2Behind) {\r\n IntersectionTests.lineSegmentPlane(p0, p2, plane, u1);\r\n IntersectionTests.lineSegmentPlane(p1, p2, plane, u2);\r\n\r\n return {\r\n positions: [p0, p1, p2, u1, u2],\r\n indices: [\r\n // Behind\r\n 0,\r\n 1,\r\n 4,\r\n 0,\r\n 4,\r\n 3,\r\n\r\n // In front\r\n 2,\r\n 3,\r\n 4,\r\n ],\r\n };\r\n }\r\n }\r\n\r\n // if numBehind is 3, the triangle is completely behind the plane;\r\n // otherwise, it is completely in front (numBehind is 0).\r\n return undefined;\r\n};\r\nexport default IntersectionTests;\r\n","import Cartesian3 from \"./Cartesian3.js\";\r\nimport Cartesian4 from \"./Cartesian4.js\";\r\nimport Check from \"./Check.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport CesiumMath from \"./Math.js\";\r\nimport Matrix4 from \"./Matrix4.js\";\r\n\r\n/**\r\n * A plane in Hessian Normal Form defined by\r\n * \r\n * ax + by + cz + d = 0\r\n *
\r\n * where (a, b, c) is the plane's normal
, d is the signed\r\n * distance
to the plane, and (x, y, z) is any point on\r\n * the plane.\r\n *\r\n * @alias Plane\r\n * @constructor\r\n *\r\n * @param {Cartesian3} normal The plane's normal (normalized).\r\n * @param {Number} distance The shortest distance from the origin to the plane. The sign of\r\n * distance
determines which side of the plane the origin\r\n * is on. If distance
is positive, the origin is in the half-space\r\n * in the direction of the normal; if negative, the origin is in the half-space\r\n * opposite to the normal; if zero, the plane passes through the origin.\r\n *\r\n * @example\r\n * // The plane x=0\r\n * var plane = new Cesium.Plane(Cesium.Cartesian3.UNIT_X, 0.0);\r\n *\r\n * @exception {DeveloperError} Normal must be normalized\r\n */\r\nfunction Plane(normal, distance) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"normal\", normal);\r\n if (\r\n !CesiumMath.equalsEpsilon(\r\n Cartesian3.magnitude(normal),\r\n 1.0,\r\n CesiumMath.EPSILON6\r\n )\r\n ) {\r\n throw new DeveloperError(\"normal must be normalized.\");\r\n }\r\n Check.typeOf.number(\"distance\", distance);\r\n //>>includeEnd('debug');\r\n\r\n /**\r\n * The plane's normal.\r\n *\r\n * @type {Cartesian3}\r\n */\r\n this.normal = Cartesian3.clone(normal);\r\n\r\n /**\r\n * The shortest distance from the origin to the plane. The sign of\r\n * distance
determines which side of the plane the origin\r\n * is on. If distance
is positive, the origin is in the half-space\r\n * in the direction of the normal; if negative, the origin is in the half-space\r\n * opposite to the normal; if zero, the plane passes through the origin.\r\n *\r\n * @type {Number}\r\n */\r\n this.distance = distance;\r\n}\r\n\r\n/**\r\n * Creates a plane from a normal and a point on the plane.\r\n *\r\n * @param {Cartesian3} point The point on the plane.\r\n * @param {Cartesian3} normal The plane's normal (normalized).\r\n * @param {Plane} [result] The object onto which to store the result.\r\n * @returns {Plane} A new plane instance or the modified result parameter.\r\n *\r\n * @example\r\n * var point = Cesium.Cartesian3.fromDegrees(-72.0, 40.0);\r\n * var normal = ellipsoid.geodeticSurfaceNormal(point);\r\n * var tangentPlane = Cesium.Plane.fromPointNormal(point, normal);\r\n *\r\n * @exception {DeveloperError} Normal must be normalized\r\n */\r\nPlane.fromPointNormal = function (point, normal, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"point\", point);\r\n Check.typeOf.object(\"normal\", normal);\r\n if (\r\n !CesiumMath.equalsEpsilon(\r\n Cartesian3.magnitude(normal),\r\n 1.0,\r\n CesiumMath.EPSILON6\r\n )\r\n ) {\r\n throw new DeveloperError(\"normal must be normalized.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var distance = -Cartesian3.dot(normal, point);\r\n\r\n if (!defined(result)) {\r\n return new Plane(normal, distance);\r\n }\r\n\r\n Cartesian3.clone(normal, result.normal);\r\n result.distance = distance;\r\n return result;\r\n};\r\n\r\nvar scratchNormal = new Cartesian3();\r\n/**\r\n * Creates a plane from the general equation\r\n *\r\n * @param {Cartesian4} coefficients The plane's normal (normalized).\r\n * @param {Plane} [result] The object onto which to store the result.\r\n * @returns {Plane} A new plane instance or the modified result parameter.\r\n *\r\n * @exception {DeveloperError} Normal must be normalized\r\n */\r\nPlane.fromCartesian4 = function (coefficients, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"coefficients\", coefficients);\r\n //>>includeEnd('debug');\r\n\r\n var normal = Cartesian3.fromCartesian4(coefficients, scratchNormal);\r\n var distance = coefficients.w;\r\n\r\n //>>includeStart('debug', pragmas.debug);\r\n if (\r\n !CesiumMath.equalsEpsilon(\r\n Cartesian3.magnitude(normal),\r\n 1.0,\r\n CesiumMath.EPSILON6\r\n )\r\n ) {\r\n throw new DeveloperError(\"normal must be normalized.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n return new Plane(normal, distance);\r\n }\r\n Cartesian3.clone(normal, result.normal);\r\n result.distance = distance;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the signed shortest distance of a point to a plane.\r\n * The sign of the distance determines which side of the plane the point\r\n * is on. If the distance is positive, the point is in the half-space\r\n * in the direction of the normal; if negative, the point is in the half-space\r\n * opposite to the normal; if zero, the plane passes through the point.\r\n *\r\n * @param {Plane} plane The plane.\r\n * @param {Cartesian3} point The point.\r\n * @returns {Number} The signed shortest distance of the point to the plane.\r\n */\r\nPlane.getPointDistance = function (plane, point) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"plane\", plane);\r\n Check.typeOf.object(\"point\", point);\r\n //>>includeEnd('debug');\r\n\r\n return Cartesian3.dot(plane.normal, point) + plane.distance;\r\n};\r\n\r\nvar scratchCartesian = new Cartesian3();\r\n/**\r\n * Projects a point onto the plane.\r\n * @param {Plane} plane The plane to project the point onto\r\n * @param {Cartesian3} point The point to project onto the plane\r\n * @param {Cartesian3} [result] The result point. If undefined, a new Cartesian3 will be created.\r\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.\r\n */\r\nPlane.projectPointOntoPlane = function (plane, point, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"plane\", plane);\r\n Check.typeOf.object(\"point\", point);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n\r\n // projectedPoint = point - (normal.point + scale) * normal\r\n var pointDistance = Plane.getPointDistance(plane, point);\r\n var scaledNormal = Cartesian3.multiplyByScalar(\r\n plane.normal,\r\n pointDistance,\r\n scratchCartesian\r\n );\r\n\r\n return Cartesian3.subtract(point, scaledNormal, result);\r\n};\r\n\r\nvar scratchInverseTranspose = new Matrix4();\r\nvar scratchPlaneCartesian4 = new Cartesian4();\r\nvar scratchTransformNormal = new Cartesian3();\r\n/**\r\n * Transforms the plane by the given transformation matrix.\r\n *\r\n * @param {Plane} plane The plane.\r\n * @param {Matrix4} transform The transformation matrix.\r\n * @param {Plane} [result] The object into which to store the result.\r\n * @returns {Plane} The plane transformed by the given transformation matrix.\r\n */\r\nPlane.transform = function (plane, transform, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"plane\", plane);\r\n Check.typeOf.object(\"transform\", transform);\r\n //>>includeEnd('debug');\r\n\r\n var normal = plane.normal;\r\n var distance = plane.distance;\r\n var inverseTranspose = Matrix4.inverseTranspose(\r\n transform,\r\n scratchInverseTranspose\r\n );\r\n var planeAsCartesian4 = Cartesian4.fromElements(\r\n normal.x,\r\n normal.y,\r\n normal.z,\r\n distance,\r\n scratchPlaneCartesian4\r\n );\r\n planeAsCartesian4 = Matrix4.multiplyByVector(\r\n inverseTranspose,\r\n planeAsCartesian4,\r\n planeAsCartesian4\r\n );\r\n\r\n // Convert the transformed plane to Hessian Normal Form\r\n var transformedNormal = Cartesian3.fromCartesian4(\r\n planeAsCartesian4,\r\n scratchTransformNormal\r\n );\r\n\r\n planeAsCartesian4 = Cartesian4.divideByScalar(\r\n planeAsCartesian4,\r\n Cartesian3.magnitude(transformedNormal),\r\n planeAsCartesian4\r\n );\r\n\r\n return Plane.fromCartesian4(planeAsCartesian4, result);\r\n};\r\n\r\n/**\r\n * Duplicates a Plane instance.\r\n *\r\n * @param {Plane} plane The plane to duplicate.\r\n * @param {Plane} [result] The object onto which to store the result.\r\n * @returns {Plane} The modified result parameter or a new Plane instance if one was not provided.\r\n */\r\nPlane.clone = function (plane, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"plane\", plane);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n return new Plane(plane.normal, plane.distance);\r\n }\r\n\r\n Cartesian3.clone(plane.normal, result.normal);\r\n result.distance = plane.distance;\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Compares the provided Planes by normal and distance and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Plane} left The first plane.\r\n * @param {Plane} right The second plane.\r\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\r\n */\r\nPlane.equals = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n //>>includeEnd('debug');\r\n\r\n return (\r\n left.distance === right.distance &&\r\n Cartesian3.equals(left.normal, right.normal)\r\n );\r\n};\r\n\r\n/**\r\n * A constant initialized to the XY plane passing through the origin, with normal in positive Z.\r\n *\r\n * @type {Plane}\r\n * @constant\r\n */\r\nPlane.ORIGIN_XY_PLANE = Object.freeze(new Plane(Cartesian3.UNIT_Z, 0.0));\r\n\r\n/**\r\n * A constant initialized to the YZ plane passing through the origin, with normal in positive X.\r\n *\r\n * @type {Plane}\r\n * @constant\r\n */\r\nPlane.ORIGIN_YZ_PLANE = Object.freeze(new Plane(Cartesian3.UNIT_X, 0.0));\r\n\r\n/**\r\n * A constant initialized to the ZX plane passing through the origin, with normal in positive Y.\r\n *\r\n * @type {Plane}\r\n * @constant\r\n */\r\nPlane.ORIGIN_ZX_PLANE = Object.freeze(new Plane(Cartesian3.UNIT_Y, 0.0));\r\nexport default Plane;\r\n","import Check from \"./Check.js\";\r\n\r\n/**\r\n * Finds an item in a sorted array.\r\n *\r\n * @function\r\n * @param {Array} array The sorted array to search.\r\n * @param {*} itemToFind The item to find in the array.\r\n * @param {binarySearchComparator} comparator The function to use to compare the item to\r\n * elements in the array.\r\n * @returns {Number} The index of itemToFind
in the array, if it exists. If itemToFind
\r\n * does not exist, the return value is a negative number which is the bitwise complement (~)\r\n * of the index before which the itemToFind should be inserted in order to maintain the\r\n * sorted order of the array.\r\n *\r\n * @example\r\n * // Create a comparator function to search through an array of numbers.\r\n * function comparator(a, b) {\r\n * return a - b;\r\n * };\r\n * var numbers = [0, 2, 4, 6, 8];\r\n * var index = Cesium.binarySearch(numbers, 6, comparator); // 3\r\n */\r\nfunction binarySearch(array, itemToFind, comparator) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n Check.defined(\"itemToFind\", itemToFind);\r\n Check.defined(\"comparator\", comparator);\r\n //>>includeEnd('debug');\r\n\r\n var low = 0;\r\n var high = array.length - 1;\r\n var i;\r\n var comparison;\r\n\r\n while (low <= high) {\r\n i = ~~((low + high) / 2);\r\n comparison = comparator(array[i], itemToFind);\r\n if (comparison < 0) {\r\n low = i + 1;\r\n continue;\r\n }\r\n if (comparison > 0) {\r\n high = i - 1;\r\n continue;\r\n }\r\n return i;\r\n }\r\n return ~(high + 1);\r\n}\r\n\r\n/**\r\n * A function used to compare two items while performing a binary search.\r\n * @callback binarySearchComparator\r\n *\r\n * @param {*} a An item in the array.\r\n * @param {*} b The item being searched for.\r\n * @returns {Number} Returns a negative value if a
is less than b
,\r\n * a positive value if a
is greater than b
, or\r\n * 0 if a
is equal to b
.\r\n *\r\n * @example\r\n * function compareNumbers(a, b) {\r\n * return a - b;\r\n * }\r\n */\r\nexport default binarySearch;\r\n","/**\r\n * A set of Earth Orientation Parameters (EOP) sampled at a time.\r\n *\r\n * @alias EarthOrientationParametersSample\r\n * @constructor\r\n *\r\n * @param {Number} xPoleWander The pole wander about the X axis, in radians.\r\n * @param {Number} yPoleWander The pole wander about the Y axis, in radians.\r\n * @param {Number} xPoleOffset The offset to the Celestial Intermediate Pole (CIP) about the X axis, in radians.\r\n * @param {Number} yPoleOffset The offset to the Celestial Intermediate Pole (CIP) about the Y axis, in radians.\r\n * @param {Number} ut1MinusUtc The difference in time standards, UT1 - UTC, in seconds.\r\n *\r\n * @private\r\n */\r\nfunction EarthOrientationParametersSample(\r\n xPoleWander,\r\n yPoleWander,\r\n xPoleOffset,\r\n yPoleOffset,\r\n ut1MinusUtc\r\n) {\r\n /**\r\n * The pole wander about the X axis, in radians.\r\n * @type {Number}\r\n */\r\n this.xPoleWander = xPoleWander;\r\n\r\n /**\r\n * The pole wander about the Y axis, in radians.\r\n * @type {Number}\r\n */\r\n this.yPoleWander = yPoleWander;\r\n\r\n /**\r\n * The offset to the Celestial Intermediate Pole (CIP) about the X axis, in radians.\r\n * @type {Number}\r\n */\r\n this.xPoleOffset = xPoleOffset;\r\n\r\n /**\r\n * The offset to the Celestial Intermediate Pole (CIP) about the Y axis, in radians.\r\n * @type {Number}\r\n */\r\n this.yPoleOffset = yPoleOffset;\r\n\r\n /**\r\n * The difference in time standards, UT1 - UTC, in seconds.\r\n * @type {Number}\r\n */\r\n this.ut1MinusUtc = ut1MinusUtc;\r\n}\r\nexport default EarthOrientationParametersSample;\r\n","/**\r\n@license\r\nsprintf.js from the php.js project - https://github.com/kvz/phpjs\r\nDirectly from https://github.com/kvz/phpjs/blob/master/functions/strings/sprintf.js\r\n\r\nphp.js is copyright 2012 Kevin van Zonneveld.\r\n\r\nPortions copyright Brett Zamir (http://brett-zamir.me), Kevin van Zonneveld\r\n(http://kevin.vanzonneveld.net), Onno Marsman, Theriault, Michael White\r\n(http://getsprink.com), Waldo Malqui Silva, Paulo Freitas, Jack, Jonas\r\nRaoni Soares Silva (http://www.jsfromhell.com), Philip Peterson, Legaev\r\nAndrey, Ates Goral (http://magnetiq.com), Alex, Ratheous, Martijn Wieringa,\r\nRafa? Kukawski (http://blog.kukawski.pl), lmeyrick\r\n(https://sourceforge.net/projects/bcmath-js/), Nate, Philippe Baumann,\r\nEnrique Gonzalez, Webtoolkit.info (http://www.webtoolkit.info/), Carlos R.\r\nL. Rodrigues (http://www.jsfromhell.com), Ash Searle\r\n(http://hexmen.com/blog/), Jani Hartikainen, travc, Ole Vrijenhoek,\r\nErkekjetter, Michael Grier, Rafa? Kukawski (http://kukawski.pl), Johnny\r\nMast (http://www.phpvrouwen.nl), T.Wild, d3x,\r\nhttp://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript,\r\nRafa? Kukawski (http://blog.kukawski.pl/), stag019, pilus, WebDevHobo\r\n(http://webdevhobo.blogspot.com/), marrtins, GeekFG\r\n(http://geekfg.blogspot.com), Andrea Giammarchi\r\n(http://webreflection.blogspot.com), Arpad Ray (mailto:arpad@php.net),\r\ngorthaur, Paul Smith, Tim de Koning (http://www.kingsquare.nl), Joris, Oleg\r\nEremeev, Steve Hilder, majak, gettimeofday, KELAN, Josh Fraser\r\n(http://onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/),\r\nMarc Palau, Martin\r\n(http://www.erlenwiese.de/), Breaking Par Consulting Inc\r\n(http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256CFB006C45F7),\r\nChris, Mirek Slugen, saulius, Alfonso Jimenez\r\n(http://www.alfonsojimenez.com), Diplom@t (http://difane.com/), felix,\r\nMailfaker (http://www.weedem.fr/), Tyler Akins (http://rumkin.com), Caio\r\nAriede (http://caioariede.com), Robin, Kankrelune\r\n(http://www.webfaktory.info/), Karol Kowalski, Imgen Tata\r\n(http://www.myipdf.com/), mdsjack (http://www.mdsjack.bo.it), Dreamer,\r\nFelix Geisendoerfer (http://www.debuggable.com/felix), Lars Fischer, AJ,\r\nDavid, Aman Gupta, Michael White, Public Domain\r\n(http://www.json.org/json2.js), Steven Levithan\r\n(http://blog.stevenlevithan.com), Sakimori, Pellentesque Malesuada,\r\nThunder.m, Dj (http://phpjs.org/functions/htmlentities:425#comment_134018),\r\nSteve Clay, David James, Francois, class_exists, nobbler, T. Wild, Itsacon\r\n(http://www.itsacon.net/), date, Ole Vrijenhoek (http://www.nervous.nl/),\r\nFox, Raphael (Ao RUDLER), Marco, noname, Mateusz \"loonquawl\" Zalega, Frank\r\nForte, Arno, ger, mktime, john (http://www.jd-tech.net), Nick Kolosov\r\n(http://sammy.ru), marc andreu, Scott Cariss, Douglas Crockford\r\n(http://javascript.crockford.com), madipta, Slawomir Kaniecki,\r\nReverseSyntax, Nathan, Alex Wilson, kenneth, Bayron Guevara, Adam Wallner\r\n(http://web2.bitbaro.hu/), paulo kuong, jmweb, Lincoln Ramsay, djmix,\r\nPyerre, Jon Hohle, Thiago Mata (http://thiagomata.blog.com), lmeyrick\r\n(https://sourceforge.net/projects/bcmath-js/this.), Linuxworld, duncan,\r\nGilbert, Sanjoy Roy, Shingo, sankai, Oskar Larsson H?gfeldt\r\n(http://oskar-lh.name/), Denny Wardhana, 0m3r, Everlasto, Subhasis Deb,\r\njosh, jd, Pier Paolo Ramon (http://www.mastersoup.com/), P, merabi, Soren\r\nHansen, Eugene Bulkin (http://doubleaw.com/), Der Simon\r\n(http://innerdom.sourceforge.net/), echo is bad, Ozh, XoraX\r\n(http://www.xorax.info), EdorFaus, JB, J A R, Marc Jansen, Francesco, LH,\r\nStoyan Kyosev (http://www.svest.org/), nord_ua, omid\r\n(http://phpjs.org/functions/380:380#comment_137122), Brad Touesnard, MeEtc\r\n(http://yass.meetcweb.com), Peter-Paul Koch\r\n(http://www.quirksmode.org/js/beat.html), Olivier Louvignes\r\n(http://mg-crea.com/), T0bsn, Tim Wiel, Bryan Elliott, Jalal Berrami,\r\nMartin, JT, David Randall, Thomas Beaucourt (http://www.webapp.fr), taith,\r\nvlado houba, Pierre-Luc Paour, Kristof Coomans (SCK-CEN Belgian Nucleair\r\nResearch Centre), Martin Pool, Kirk Strobeck, Rick Waldron, Brant Messenger\r\n(http://www.brantmessenger.com/), Devan Penner-Woelk, Saulo Vallory, Wagner\r\nB. Soares, Artur Tchernychev, Valentina De Rosa, Jason Wong\r\n(http://carrot.org/), Christoph, Daniel Esteban, strftime, Mick@el, rezna,\r\nSimon Willison (http://simonwillison.net), Anton Ongson, Gabriel Paderni,\r\nMarco van Oort, penutbutterjelly, Philipp Lenssen, Bjorn Roesbeke\r\n(http://www.bjornroesbeke.be/), Bug?, Eric Nagel, Tomasz Wesolowski,\r\nEvertjan Garretsen, Bobby Drake, Blues (http://tech.bluesmoon.info/), Luke\r\nGodfrey, Pul, uestla, Alan C, Ulrich, Rafal Kukawski, Yves Sucaet,\r\nsowberry, Norman \"zEh\" Fuchs, hitwork, Zahlii, johnrembo, Nick Callen,\r\nSteven Levithan (stevenlevithan.com), ejsanders, Scott Baker, Brian Tafoya\r\n(http://www.premasolutions.com/), Philippe Jausions\r\n(http://pear.php.net/user/jausions), Aidan Lister\r\n(http://aidanlister.com/), Rob, e-mike, HKM, ChaosNo1, metjay, strcasecmp,\r\nstrcmp, Taras Bogach, jpfle, Alexander Ermolaev\r\n(http://snippets.dzone.com/user/AlexanderErmolaev), DxGx, kilops, Orlando,\r\ndptr1988, Le Torbi, James (http://www.james-bell.co.uk/), Pedro Tainha\r\n(http://www.pedrotainha.com), James, Arnout Kazemier\r\n(http://www.3rd-Eden.com), Chris McMacken, gabriel paderni, Yannoo,\r\nFGFEmperor, baris ozdil, Tod Gentille, Greg Frazier, jakes, 3D-GRAF, Allan\r\nJensen (http://www.winternet.no), Howard Yeend, Benjamin Lupton, davook,\r\ndaniel airton wermann (http://wermann.com.br), Atli T¨®r, Maximusya, Ryan\r\nW Tenney (http://ryan.10e.us), Alexander M Beedie, fearphage\r\n(http://http/my.opera.com/fearphage/), Nathan Sepulveda, Victor, Matteo,\r\nBilly, stensi, Cord, Manish, T.J. Leahy, Riddler\r\n(http://www.frontierwebdev.com/), Rafa? Kukawski, FremyCompany, Matt\r\nBradley, Tim de Koning, Luis Salazar (http://www.freaky-media.com/), Diogo\r\nResende, Rival, Andrej Pavlovic, Garagoth, Le Torbi\r\n(http://www.letorbi.de/), Dino, Josep Sanz (http://www.ws3.es/), rem,\r\nRussell Walker (http://www.nbill.co.uk/), Jamie Beck\r\n(http://www.terabit.ca/), setcookie, Michael, YUI Library:\r\nhttp://developer.yahoo.com/yui/docs/YAHOO.util.DateLocale.html, Blues at\r\nhttp://hacks.bluesmoon.info/strftime/strftime.js, Ben\r\n(http://benblume.co.uk/), DtTvB\r\n(http://dt.in.th/2008-09-16.string-length-in-bytes.html), Andreas, William,\r\nmeo, incidence, Cagri Ekin, Amirouche, Amir Habibi\r\n(http://www.residence-mixte.com/), Luke Smith (http://lucassmith.name),\r\nKheang Hok Chin (http://www.distantia.ca/), Jay Klehr, Lorenzo Pisani,\r\nTony, Yen-Wei Liu, Greenseed, mk.keck, Leslie Hoare, dude, booeyOH, Ben\r\nBryan\r\n\r\nLicensed under the MIT (MIT-LICENSE.txt) license.\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a\r\ncopy of this software and associated documentation files (the\r\n\"Software\"), to deal in the Software without restriction, including\r\nwithout limitation the rights to use, copy, modify, merge, publish,\r\ndistribute, sublicense, and/or sell copies of the Software, and to\r\npermit persons to whom the Software is furnished to do so, subject to\r\nthe following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included\r\nin all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r\nOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r\nIN NO EVENT SHALL KEVIN VAN ZONNEVELD BE LIABLE FOR ANY CLAIM, DAMAGES\r\nOR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\r\nARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\r\nOTHER DEALINGS IN THE SOFTWARE.\r\n*/\r\n\r\nfunction sprintf () {\r\n // http://kevin.vanzonneveld.net\r\n // + original by: Ash Searle (http://hexmen.com/blog/)\r\n // + namespaced by: Michael White (http://getsprink.com)\r\n // + tweaked by: Jack\r\n // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)\r\n // + input by: Paulo Freitas\r\n // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)\r\n // + input by: Brett Zamir (http://brett-zamir.me)\r\n // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)\r\n // + improved by: Dj\r\n // + improved by: Allidylls\r\n // * example 1: sprintf(\"%01.2f\", 123.1);\r\n // * returns 1: 123.10\r\n // * example 2: sprintf(\"[%10s]\", 'monkey');\r\n // * returns 2: '[ monkey]'\r\n // * example 3: sprintf(\"[%'#10s]\", 'monkey');\r\n // * returns 3: '[####monkey]'\r\n // * example 4: sprintf(\"%d\", 123456789012345);\r\n // * returns 4: '123456789012345'\r\n var regex = /%%|%(\\d+\\$)?([-+\\'#0 ]*)(\\*\\d+\\$|\\*|\\d+)?(\\.(\\*\\d+\\$|\\*|\\d+))?([scboxXuideEfFgG])/g;\r\n var a = arguments,\r\n i = 0,\r\n format = a[i++];\r\n\r\n // pad()\r\n var pad = function (str, len, chr, leftJustify) {\r\n if (!chr) {\r\n chr = ' ';\r\n }\r\n\r\n var padding = (str.length >= len) ? '' : Array(1 + len - str.length >>> 0).join(chr);\r\n return leftJustify ? str + padding : padding + str;\r\n };\r\n\r\n // justify()\r\n var justify = function (value, prefix, leftJustify, minWidth, zeroPad, customPadChar) {\r\n var diff = minWidth - value.length;\r\n if (diff > 0) {\r\n if (leftJustify || !zeroPad) {\r\n value = pad(value, minWidth, customPadChar, leftJustify);\r\n } else {\r\n value = value.slice(0, prefix.length) + pad('', diff, '0', true) + value.slice(prefix.length);\r\n }\r\n }\r\n return value;\r\n };\r\n\r\n // formatBaseX()\r\n var formatBaseX = function (value, base, prefix, leftJustify, minWidth, precision, zeroPad) {\r\n // Note: casts negative numbers to positive ones\r\n var number = value >>> 0;\r\n prefix = prefix && number && {\r\n '2': '0b',\r\n '8': '0',\r\n '16': '0x'\r\n }[base] || '';\r\n value = prefix + pad(number.toString(base), precision || 0, '0', false);\r\n return justify(value, prefix, leftJustify, minWidth, zeroPad);\r\n };\r\n\r\n // formatString()\r\n var formatString = function (value, leftJustify, minWidth, precision, zeroPad, customPadChar) {\r\n if (precision != null) {\r\n value = value.slice(0, precision);\r\n }\r\n return justify(value, '', leftJustify, minWidth, zeroPad, customPadChar);\r\n };\r\n\r\n // doFormat()\r\n var doFormat = function (substring, valueIndex, flags, minWidth, _, precision, type) {\r\n var number;\r\n var prefix;\r\n var method;\r\n var textTransform;\r\n var value;\r\n\r\n if (substring == '%%') {\r\n return '%';\r\n }\r\n\r\n // parse flags\r\n var leftJustify = false,\r\n positivePrefix = '',\r\n zeroPad = false,\r\n prefixBaseX = false,\r\n customPadChar = ' ';\r\n var flagsl = flags.length;\r\n for (var j = 0; flags && j < flagsl; j++) {\r\n switch (flags.charAt(j)) {\r\n case ' ':\r\n positivePrefix = ' ';\r\n break;\r\n case '+':\r\n positivePrefix = '+';\r\n break;\r\n case '-':\r\n leftJustify = true;\r\n break;\r\n case \"'\":\r\n customPadChar = flags.charAt(j + 1);\r\n break;\r\n case '0':\r\n zeroPad = true;\r\n break;\r\n case '#':\r\n prefixBaseX = true;\r\n break;\r\n }\r\n }\r\n\r\n // parameters may be null, undefined, empty-string or real valued\r\n // we want to ignore null, undefined and empty-string values\r\n if (!minWidth) {\r\n minWidth = 0;\r\n } else if (minWidth == '*') {\r\n minWidth = +a[i++];\r\n } else if (minWidth.charAt(0) == '*') {\r\n minWidth = +a[minWidth.slice(1, -1)];\r\n } else {\r\n minWidth = +minWidth;\r\n }\r\n\r\n // Note: undocumented perl feature:\r\n if (minWidth < 0) {\r\n minWidth = -minWidth;\r\n leftJustify = true;\r\n }\r\n\r\n if (!isFinite(minWidth)) {\r\n throw new Error('sprintf: (minimum-)width must be finite');\r\n }\r\n\r\n if (!precision) {\r\n precision = 'fFeE'.indexOf(type) > -1 ? 6 : (type == 'd') ? 0 : undefined;\r\n } else if (precision == '*') {\r\n precision = +a[i++];\r\n } else if (precision.charAt(0) == '*') {\r\n precision = +a[precision.slice(1, -1)];\r\n } else {\r\n precision = +precision;\r\n }\r\n\r\n // grab value using valueIndex if required?\r\n value = valueIndex ? a[valueIndex.slice(0, -1)] : a[i++];\r\n\r\n switch (type) {\r\n case 's':\r\n return formatString(String(value), leftJustify, minWidth, precision, zeroPad, customPadChar);\r\n case 'c':\r\n return formatString(String.fromCharCode(+value), leftJustify, minWidth, precision, zeroPad);\r\n case 'b':\r\n return formatBaseX(value, 2, prefixBaseX, leftJustify, minWidth, precision, zeroPad);\r\n case 'o':\r\n return formatBaseX(value, 8, prefixBaseX, leftJustify, minWidth, precision, zeroPad);\r\n case 'x':\r\n return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad);\r\n case 'X':\r\n return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad).toUpperCase();\r\n case 'u':\r\n return formatBaseX(value, 10, prefixBaseX, leftJustify, minWidth, precision, zeroPad);\r\n case 'i':\r\n case 'd':\r\n number = +value || 0;\r\n number = Math.round(number - number % 1); // Plain Math.round doesn't just truncate\r\n prefix = number < 0 ? '-' : positivePrefix;\r\n value = prefix + pad(String(Math.abs(number)), precision, '0', false);\r\n return justify(value, prefix, leftJustify, minWidth, zeroPad);\r\n case 'e':\r\n case 'E':\r\n case 'f': // Should handle locales (as per setlocale)\r\n case 'F':\r\n case 'g':\r\n case 'G':\r\n number = +value;\r\n prefix = number < 0 ? '-' : positivePrefix;\r\n method = ['toExponential', 'toFixed', 'toPrecision']['efg'.indexOf(type.toLowerCase())];\r\n textTransform = ['toString', 'toUpperCase']['eEfFgG'.indexOf(type) % 2];\r\n value = prefix + Math.abs(number)[method](precision);\r\n return justify(value, prefix, leftJustify, minWidth, zeroPad)[textTransform]();\r\n default:\r\n return substring;\r\n }\r\n };\r\n\r\n return format.replace(regex, doFormat);\r\n}\r\n\r\nexport default sprintf;\r\n","/**\r\n * Represents a Gregorian date in a more precise format than the JavaScript Date object.\r\n * In addition to submillisecond precision, this object can also represent leap seconds.\r\n * @alias GregorianDate\r\n * @constructor\r\n *\r\n * @param {Number} [year] The year as a whole number.\r\n * @param {Number} [month] The month as a whole number with range [1, 12].\r\n * @param {Number} [day] The day of the month as a whole number starting at 1.\r\n * @param {Number} [hour] The hour as a whole number with range [0, 23].\r\n * @param {Number} [minute] The minute of the hour as a whole number with range [0, 59].\r\n * @param {Number} [second] The second of the minute as a whole number with range [0, 60], with 60 representing a leap second.\r\n * @param {Number} [millisecond] The millisecond of the second as a floating point number with range [0.0, 1000.0).\r\n * @param {Boolean} [isLeapSecond] Whether this time is during a leap second.\r\n *\r\n * @see JulianDate#toGregorianDate\r\n */\r\nfunction GregorianDate(\r\n year,\r\n month,\r\n day,\r\n hour,\r\n minute,\r\n second,\r\n millisecond,\r\n isLeapSecond\r\n) {\r\n /**\r\n * Gets or sets the year as a whole number.\r\n * @type {Number}\r\n */\r\n this.year = year;\r\n /**\r\n * Gets or sets the month as a whole number with range [1, 12].\r\n * @type {Number}\r\n */\r\n this.month = month;\r\n /**\r\n * Gets or sets the day of the month as a whole number starting at 1.\r\n * @type {Number}\r\n */\r\n this.day = day;\r\n /**\r\n * Gets or sets the hour as a whole number with range [0, 23].\r\n * @type {Number}\r\n */\r\n this.hour = hour;\r\n /**\r\n * Gets or sets the minute of the hour as a whole number with range [0, 59].\r\n * @type {Number}\r\n */\r\n this.minute = minute;\r\n /**\r\n * Gets or sets the second of the minute as a whole number with range [0, 60], with 60 representing a leap second.\r\n * @type {Number}\r\n */\r\n this.second = second;\r\n /**\r\n * Gets or sets the millisecond of the second as a floating point number with range [0.0, 1000.0).\r\n * @type {Number}\r\n */\r\n this.millisecond = millisecond;\r\n /**\r\n * Gets or sets whether this time is during a leap second.\r\n * @type {Boolean}\r\n */\r\n this.isLeapSecond = isLeapSecond;\r\n}\r\nexport default GregorianDate;\r\n","import DeveloperError from \"./DeveloperError.js\";\r\n\r\n/**\r\n * Determines if a given date is a leap year.\r\n *\r\n * @function isLeapYear\r\n *\r\n * @param {Number} year The year to be tested.\r\n * @returns {Boolean} True if year
is a leap year.\r\n *\r\n * @example\r\n * var leapYear = Cesium.isLeapYear(2000); // true\r\n */\r\nfunction isLeapYear(year) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (year === null || isNaN(year)) {\r\n throw new DeveloperError(\"year is required and must be a number.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\r\n}\r\nexport default isLeapYear;\r\n","/**\r\n * Describes a single leap second, which is constructed from a {@link JulianDate} and a\r\n * numerical offset representing the number of seconds TAI is ahead of the UTC time standard.\r\n * @alias LeapSecond\r\n * @constructor\r\n *\r\n * @param {JulianDate} [date] A Julian date representing the time of the leap second.\r\n * @param {Number} [offset] The cumulative number of seconds that TAI is ahead of UTC at the provided date.\r\n */\r\nfunction LeapSecond(date, offset) {\r\n /**\r\n * Gets or sets the date at which this leap second occurs.\r\n * @type {JulianDate}\r\n */\r\n this.julianDate = date;\r\n\r\n /**\r\n * Gets or sets the cumulative number of seconds between the UTC and TAI time standards at the time\r\n * of this leap second.\r\n * @type {Number}\r\n */\r\n this.offset = offset;\r\n}\r\nexport default LeapSecond;\r\n","/**\r\n * Constants for time conversions like those done by {@link JulianDate}.\r\n *\r\n * @namespace TimeConstants\r\n *\r\n * @see JulianDate\r\n *\r\n * @private\r\n */\r\nvar TimeConstants = {\r\n /**\r\n * The number of seconds in one millisecond: 0.001
\r\n * @type {Number}\r\n * @constant\r\n */\r\n SECONDS_PER_MILLISECOND: 0.001,\r\n\r\n /**\r\n * The number of seconds in one minute: 60
.\r\n * @type {Number}\r\n * @constant\r\n */\r\n SECONDS_PER_MINUTE: 60.0,\r\n\r\n /**\r\n * The number of minutes in one hour: 60
.\r\n * @type {Number}\r\n * @constant\r\n */\r\n MINUTES_PER_HOUR: 60.0,\r\n\r\n /**\r\n * The number of hours in one day: 24
.\r\n * @type {Number}\r\n * @constant\r\n */\r\n HOURS_PER_DAY: 24.0,\r\n\r\n /**\r\n * The number of seconds in one hour: 3600
.\r\n * @type {Number}\r\n * @constant\r\n */\r\n SECONDS_PER_HOUR: 3600.0,\r\n\r\n /**\r\n * The number of minutes in one day: 1440
.\r\n * @type {Number}\r\n * @constant\r\n */\r\n MINUTES_PER_DAY: 1440.0,\r\n\r\n /**\r\n * The number of seconds in one day, ignoring leap seconds: 86400
.\r\n * @type {Number}\r\n * @constant\r\n */\r\n SECONDS_PER_DAY: 86400.0,\r\n\r\n /**\r\n * The number of days in one Julian century: 36525
.\r\n * @type {Number}\r\n * @constant\r\n */\r\n DAYS_PER_JULIAN_CENTURY: 36525.0,\r\n\r\n /**\r\n * One trillionth of a second.\r\n * @type {Number}\r\n * @constant\r\n */\r\n PICOSECOND: 0.000000001,\r\n\r\n /**\r\n * The number of days to subtract from a Julian date to determine the\r\n * modified Julian date, which gives the number of days since midnight\r\n * on November 17, 1858.\r\n * @type {Number}\r\n * @constant\r\n */\r\n MODIFIED_JULIAN_DATE_DIFFERENCE: 2400000.5,\r\n};\r\nexport default Object.freeze(TimeConstants);\r\n","/**\r\n * Provides the type of time standards which JulianDate can take as input.\r\n *\r\n * @enum {Number}\r\n *\r\n * @see JulianDate\r\n */\r\nvar TimeStandard = {\r\n /**\r\n * Represents the coordinated Universal Time (UTC) time standard.\r\n *\r\n * UTC is related to TAI according to the relationship\r\n * UTC = TAI - deltaT
where deltaT
is the number of leap\r\n * seconds which have been introduced as of the time in TAI.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\n UTC: 0,\r\n\r\n /**\r\n * Represents the International Atomic Time (TAI) time standard.\r\n * TAI is the principal time standard to which the other time standards are related.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\n TAI: 1,\r\n};\r\nexport default Object.freeze(TimeStandard);\r\n","import sprintf from \"../ThirdParty/sprintf.js\";\r\nimport binarySearch from \"./binarySearch.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport GregorianDate from \"./GregorianDate.js\";\r\nimport isLeapYear from \"./isLeapYear.js\";\r\nimport LeapSecond from \"./LeapSecond.js\";\r\nimport TimeConstants from \"./TimeConstants.js\";\r\nimport TimeStandard from \"./TimeStandard.js\";\r\n\r\nvar gregorianDateScratch = new GregorianDate();\r\nvar daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\r\nvar daysInLeapFeburary = 29;\r\n\r\nfunction compareLeapSecondDates(leapSecond, dateToFind) {\r\n return JulianDate.compare(leapSecond.julianDate, dateToFind.julianDate);\r\n}\r\n\r\n// we don't really need a leap second instance, anything with a julianDate property will do\r\nvar binarySearchScratchLeapSecond = new LeapSecond();\r\n\r\nfunction convertUtcToTai(julianDate) {\r\n //Even though julianDate is in UTC, we'll treat it as TAI and\r\n //search the leap second table for it.\r\n binarySearchScratchLeapSecond.julianDate = julianDate;\r\n var leapSeconds = JulianDate.leapSeconds;\r\n var index = binarySearch(\r\n leapSeconds,\r\n binarySearchScratchLeapSecond,\r\n compareLeapSecondDates\r\n );\r\n\r\n if (index < 0) {\r\n index = ~index;\r\n }\r\n\r\n if (index >= leapSeconds.length) {\r\n index = leapSeconds.length - 1;\r\n }\r\n\r\n var offset = leapSeconds[index].offset;\r\n if (index > 0) {\r\n //Now we have the index of the closest leap second that comes on or after our UTC time.\r\n //However, if the difference between the UTC date being converted and the TAI\r\n //defined leap second is greater than the offset, we are off by one and need to use\r\n //the previous leap second.\r\n var difference = JulianDate.secondsDifference(\r\n leapSeconds[index].julianDate,\r\n julianDate\r\n );\r\n if (difference > offset) {\r\n index--;\r\n offset = leapSeconds[index].offset;\r\n }\r\n }\r\n\r\n JulianDate.addSeconds(julianDate, offset, julianDate);\r\n}\r\n\r\nfunction convertTaiToUtc(julianDate, result) {\r\n binarySearchScratchLeapSecond.julianDate = julianDate;\r\n var leapSeconds = JulianDate.leapSeconds;\r\n var index = binarySearch(\r\n leapSeconds,\r\n binarySearchScratchLeapSecond,\r\n compareLeapSecondDates\r\n );\r\n if (index < 0) {\r\n index = ~index;\r\n }\r\n\r\n //All times before our first leap second get the first offset.\r\n if (index === 0) {\r\n return JulianDate.addSeconds(julianDate, -leapSeconds[0].offset, result);\r\n }\r\n\r\n //All times after our leap second get the last offset.\r\n if (index >= leapSeconds.length) {\r\n return JulianDate.addSeconds(\r\n julianDate,\r\n -leapSeconds[index - 1].offset,\r\n result\r\n );\r\n }\r\n\r\n //Compute the difference between the found leap second and the time we are converting.\r\n var difference = JulianDate.secondsDifference(\r\n leapSeconds[index].julianDate,\r\n julianDate\r\n );\r\n\r\n if (difference === 0) {\r\n //The date is in our leap second table.\r\n return JulianDate.addSeconds(\r\n julianDate,\r\n -leapSeconds[index].offset,\r\n result\r\n );\r\n }\r\n\r\n if (difference <= 1.0) {\r\n //The requested date is during the moment of a leap second, then we cannot convert to UTC\r\n return undefined;\r\n }\r\n\r\n //The time is in between two leap seconds, index is the leap second after the date\r\n //we're converting, so we subtract one to get the correct LeapSecond instance.\r\n return JulianDate.addSeconds(\r\n julianDate,\r\n -leapSeconds[--index].offset,\r\n result\r\n );\r\n}\r\n\r\nfunction setComponents(wholeDays, secondsOfDay, julianDate) {\r\n var extraDays = (secondsOfDay / TimeConstants.SECONDS_PER_DAY) | 0;\r\n wholeDays += extraDays;\r\n secondsOfDay -= TimeConstants.SECONDS_PER_DAY * extraDays;\r\n\r\n if (secondsOfDay < 0) {\r\n wholeDays--;\r\n secondsOfDay += TimeConstants.SECONDS_PER_DAY;\r\n }\r\n\r\n julianDate.dayNumber = wholeDays;\r\n julianDate.secondsOfDay = secondsOfDay;\r\n return julianDate;\r\n}\r\n\r\nfunction computeJulianDateComponents(\r\n year,\r\n month,\r\n day,\r\n hour,\r\n minute,\r\n second,\r\n millisecond\r\n) {\r\n // Algorithm from page 604 of the Explanatory Supplement to the\r\n // Astronomical Almanac (Seidelmann 1992).\r\n\r\n var a = ((month - 14) / 12) | 0;\r\n var b = year + 4800 + a;\r\n var dayNumber =\r\n (((1461 * b) / 4) | 0) +\r\n (((367 * (month - 2 - 12 * a)) / 12) | 0) -\r\n (((3 * (((b + 100) / 100) | 0)) / 4) | 0) +\r\n day -\r\n 32075;\r\n\r\n // JulianDates are noon-based\r\n hour = hour - 12;\r\n if (hour < 0) {\r\n hour += 24;\r\n }\r\n\r\n var secondsOfDay =\r\n second +\r\n (hour * TimeConstants.SECONDS_PER_HOUR +\r\n minute * TimeConstants.SECONDS_PER_MINUTE +\r\n millisecond * TimeConstants.SECONDS_PER_MILLISECOND);\r\n\r\n if (secondsOfDay >= 43200.0) {\r\n dayNumber -= 1;\r\n }\r\n\r\n return [dayNumber, secondsOfDay];\r\n}\r\n\r\n//Regular expressions used for ISO8601 date parsing.\r\n//YYYY\r\nvar matchCalendarYear = /^(\\d{4})$/;\r\n//YYYY-MM (YYYYMM is invalid)\r\nvar matchCalendarMonth = /^(\\d{4})-(\\d{2})$/;\r\n//YYYY-DDD or YYYYDDD\r\nvar matchOrdinalDate = /^(\\d{4})-?(\\d{3})$/;\r\n//YYYY-Www or YYYYWww or YYYY-Www-D or YYYYWwwD\r\nvar matchWeekDate = /^(\\d{4})-?W(\\d{2})-?(\\d{1})?$/;\r\n//YYYY-MM-DD or YYYYMMDD\r\nvar matchCalendarDate = /^(\\d{4})-?(\\d{2})-?(\\d{2})$/;\r\n// Match utc offset\r\nvar utcOffset = /([Z+\\-])?(\\d{2})?:?(\\d{2})?$/;\r\n// Match hours HH or HH.xxxxx\r\nvar matchHours = /^(\\d{2})(\\.\\d+)?/.source + utcOffset.source;\r\n// Match hours/minutes HH:MM HHMM.xxxxx\r\nvar matchHoursMinutes = /^(\\d{2}):?(\\d{2})(\\.\\d+)?/.source + utcOffset.source;\r\n// Match hours/minutes HH:MM:SS HHMMSS.xxxxx\r\nvar matchHoursMinutesSeconds =\r\n /^(\\d{2}):?(\\d{2}):?(\\d{2})(\\.\\d+)?/.source + utcOffset.source;\r\n\r\nvar iso8601ErrorMessage = \"Invalid ISO 8601 date.\";\r\n\r\n/**\r\n * Represents an astronomical Julian date, which is the number of days since noon on January 1, -4712 (4713 BC).\r\n * For increased precision, this class stores the whole number part of the date and the seconds\r\n * part of the date in separate components. In order to be safe for arithmetic and represent\r\n * leap seconds, the date is always stored in the International Atomic Time standard\r\n * {@link TimeStandard.TAI}.\r\n * @alias JulianDate\r\n * @constructor\r\n *\r\n * @param {Number} [julianDayNumber=0.0] The Julian Day Number representing the number of whole days. Fractional days will also be handled correctly.\r\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.\r\n * @param {TimeStandard} [timeStandard=TimeStandard.UTC] The time standard in which the first two parameters are defined.\r\n */\r\nfunction JulianDate(julianDayNumber, secondsOfDay, timeStandard) {\r\n /**\r\n * Gets or sets the number of whole days.\r\n * @type {Number}\r\n */\r\n this.dayNumber = undefined;\r\n\r\n /**\r\n * Gets or sets the number of seconds into the current day.\r\n * @type {Number}\r\n */\r\n this.secondsOfDay = undefined;\r\n\r\n julianDayNumber = defaultValue(julianDayNumber, 0.0);\r\n secondsOfDay = defaultValue(secondsOfDay, 0.0);\r\n timeStandard = defaultValue(timeStandard, TimeStandard.UTC);\r\n\r\n //If julianDayNumber is fractional, make it an integer and add the number of seconds the fraction represented.\r\n var wholeDays = julianDayNumber | 0;\r\n secondsOfDay =\r\n secondsOfDay +\r\n (julianDayNumber - wholeDays) * TimeConstants.SECONDS_PER_DAY;\r\n\r\n setComponents(wholeDays, secondsOfDay, this);\r\n\r\n if (timeStandard === TimeStandard.UTC) {\r\n convertUtcToTai(this);\r\n }\r\n}\r\n\r\n/**\r\n * Creates a new instance from a GregorianDate.\r\n *\r\n * @param {GregorianDate} date A GregorianDate.\r\n * @param {JulianDate} [result] An existing instance to use for the result.\r\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided.\r\n *\r\n * @exception {DeveloperError} date must be a valid GregorianDate.\r\n */\r\nJulianDate.fromGregorianDate = function (date, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!(date instanceof GregorianDate)) {\r\n throw new DeveloperError(\"date must be a valid GregorianDate.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var components = computeJulianDateComponents(\r\n date.year,\r\n date.month,\r\n date.day,\r\n date.hour,\r\n date.minute,\r\n date.second,\r\n date.millisecond\r\n );\r\n if (!defined(result)) {\r\n return new JulianDate(components[0], components[1], TimeStandard.UTC);\r\n }\r\n setComponents(components[0], components[1], result);\r\n convertUtcToTai(result);\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a new instance from a JavaScript Date.\r\n *\r\n * @param {Date} date A JavaScript Date.\r\n * @param {JulianDate} [result] An existing instance to use for the result.\r\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided.\r\n *\r\n * @exception {DeveloperError} date must be a valid JavaScript Date.\r\n */\r\nJulianDate.fromDate = function (date, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!(date instanceof Date) || isNaN(date.getTime())) {\r\n throw new DeveloperError(\"date must be a valid JavaScript Date.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var components = computeJulianDateComponents(\r\n date.getUTCFullYear(),\r\n date.getUTCMonth() + 1,\r\n date.getUTCDate(),\r\n date.getUTCHours(),\r\n date.getUTCMinutes(),\r\n date.getUTCSeconds(),\r\n date.getUTCMilliseconds()\r\n );\r\n if (!defined(result)) {\r\n return new JulianDate(components[0], components[1], TimeStandard.UTC);\r\n }\r\n setComponents(components[0], components[1], result);\r\n convertUtcToTai(result);\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a new instance from a from an {@link http://en.wikipedia.org/wiki/ISO_8601|ISO 8601} date.\r\n * This method is superior to Date.parse
because it will handle all valid formats defined by the ISO 8601\r\n * specification, including leap seconds and sub-millisecond times, which discarded by most JavaScript implementations.\r\n *\r\n * @param {String} iso8601String An ISO 8601 date.\r\n * @param {JulianDate} [result] An existing instance to use for the result.\r\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided.\r\n *\r\n * @exception {DeveloperError} Invalid ISO 8601 date.\r\n */\r\nJulianDate.fromIso8601 = function (iso8601String, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (typeof iso8601String !== \"string\") {\r\n throw new DeveloperError(iso8601ErrorMessage);\r\n }\r\n //>>includeEnd('debug');\r\n\r\n //Comma and decimal point both indicate a fractional number according to ISO 8601,\r\n //start out by blanket replacing , with . which is the only valid such symbol in JS.\r\n iso8601String = iso8601String.replace(\",\", \".\");\r\n\r\n //Split the string into its date and time components, denoted by a mandatory T\r\n var tokens = iso8601String.split(\"T\");\r\n var year;\r\n var month = 1;\r\n var day = 1;\r\n var hour = 0;\r\n var minute = 0;\r\n var second = 0;\r\n var millisecond = 0;\r\n\r\n //Lacking a time is okay, but a missing date is illegal.\r\n var date = tokens[0];\r\n var time = tokens[1];\r\n var tmp;\r\n var inLeapYear;\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(date)) {\r\n throw new DeveloperError(iso8601ErrorMessage);\r\n }\r\n\r\n var dashCount;\r\n //>>includeEnd('debug');\r\n\r\n //First match the date against possible regular expressions.\r\n tokens = date.match(matchCalendarDate);\r\n if (tokens !== null) {\r\n //>>includeStart('debug', pragmas.debug);\r\n dashCount = date.split(\"-\").length - 1;\r\n if (dashCount > 0 && dashCount !== 2) {\r\n throw new DeveloperError(iso8601ErrorMessage);\r\n }\r\n //>>includeEnd('debug');\r\n year = +tokens[1];\r\n month = +tokens[2];\r\n day = +tokens[3];\r\n } else {\r\n tokens = date.match(matchCalendarMonth);\r\n if (tokens !== null) {\r\n year = +tokens[1];\r\n month = +tokens[2];\r\n } else {\r\n tokens = date.match(matchCalendarYear);\r\n if (tokens !== null) {\r\n year = +tokens[1];\r\n } else {\r\n //Not a year/month/day so it must be an ordinal date.\r\n var dayOfYear;\r\n tokens = date.match(matchOrdinalDate);\r\n if (tokens !== null) {\r\n year = +tokens[1];\r\n dayOfYear = +tokens[2];\r\n inLeapYear = isLeapYear(year);\r\n\r\n //This validation is only applicable for this format.\r\n //>>includeStart('debug', pragmas.debug);\r\n if (\r\n dayOfYear < 1 ||\r\n (inLeapYear && dayOfYear > 366) ||\r\n (!inLeapYear && dayOfYear > 365)\r\n ) {\r\n throw new DeveloperError(iso8601ErrorMessage);\r\n }\r\n //>>includeEnd('debug')\r\n } else {\r\n tokens = date.match(matchWeekDate);\r\n if (tokens !== null) {\r\n //ISO week date to ordinal date from\r\n //http://en.wikipedia.org/w/index.php?title=ISO_week_date&oldid=474176775\r\n year = +tokens[1];\r\n var weekNumber = +tokens[2];\r\n var dayOfWeek = +tokens[3] || 0;\r\n\r\n //>>includeStart('debug', pragmas.debug);\r\n dashCount = date.split(\"-\").length - 1;\r\n if (\r\n dashCount > 0 &&\r\n ((!defined(tokens[3]) && dashCount !== 1) ||\r\n (defined(tokens[3]) && dashCount !== 2))\r\n ) {\r\n throw new DeveloperError(iso8601ErrorMessage);\r\n }\r\n //>>includeEnd('debug')\r\n\r\n var january4 = new Date(Date.UTC(year, 0, 4));\r\n dayOfYear = weekNumber * 7 + dayOfWeek - january4.getUTCDay() - 3;\r\n } else {\r\n //None of our regular expressions succeeded in parsing the date properly.\r\n //>>includeStart('debug', pragmas.debug);\r\n throw new DeveloperError(iso8601ErrorMessage);\r\n //>>includeEnd('debug')\r\n }\r\n }\r\n //Split an ordinal date into month/day.\r\n tmp = new Date(Date.UTC(year, 0, 1));\r\n tmp.setUTCDate(dayOfYear);\r\n month = tmp.getUTCMonth() + 1;\r\n day = tmp.getUTCDate();\r\n }\r\n }\r\n }\r\n\r\n //Now that we have all of the date components, validate them to make sure nothing is out of range.\r\n inLeapYear = isLeapYear(year);\r\n //>>includeStart('debug', pragmas.debug);\r\n if (\r\n month < 1 ||\r\n month > 12 ||\r\n day < 1 ||\r\n ((month !== 2 || !inLeapYear) && day > daysInMonth[month - 1]) ||\r\n (inLeapYear && month === 2 && day > daysInLeapFeburary)\r\n ) {\r\n throw new DeveloperError(iso8601ErrorMessage);\r\n }\r\n //>>includeEnd('debug')\r\n\r\n //Now move onto the time string, which is much simpler.\r\n //If no time is specified, it is considered the beginning of the day, UTC to match Javascript's implementation.\r\n var offsetIndex;\r\n if (defined(time)) {\r\n tokens = time.match(matchHoursMinutesSeconds);\r\n if (tokens !== null) {\r\n //>>includeStart('debug', pragmas.debug);\r\n dashCount = time.split(\":\").length - 1;\r\n if (dashCount > 0 && dashCount !== 2 && dashCount !== 3) {\r\n throw new DeveloperError(iso8601ErrorMessage);\r\n }\r\n //>>includeEnd('debug')\r\n\r\n hour = +tokens[1];\r\n minute = +tokens[2];\r\n second = +tokens[3];\r\n millisecond = +(tokens[4] || 0) * 1000.0;\r\n offsetIndex = 5;\r\n } else {\r\n tokens = time.match(matchHoursMinutes);\r\n if (tokens !== null) {\r\n //>>includeStart('debug', pragmas.debug);\r\n dashCount = time.split(\":\").length - 1;\r\n if (dashCount > 2) {\r\n throw new DeveloperError(iso8601ErrorMessage);\r\n }\r\n //>>includeEnd('debug')\r\n\r\n hour = +tokens[1];\r\n minute = +tokens[2];\r\n second = +(tokens[3] || 0) * 60.0;\r\n offsetIndex = 4;\r\n } else {\r\n tokens = time.match(matchHours);\r\n if (tokens !== null) {\r\n hour = +tokens[1];\r\n minute = +(tokens[2] || 0) * 60.0;\r\n offsetIndex = 3;\r\n } else {\r\n //>>includeStart('debug', pragmas.debug);\r\n throw new DeveloperError(iso8601ErrorMessage);\r\n //>>includeEnd('debug')\r\n }\r\n }\r\n }\r\n\r\n //Validate that all values are in proper range. Minutes and hours have special cases at 60 and 24.\r\n //>>includeStart('debug', pragmas.debug);\r\n if (\r\n minute >= 60 ||\r\n second >= 61 ||\r\n hour > 24 ||\r\n (hour === 24 && (minute > 0 || second > 0 || millisecond > 0))\r\n ) {\r\n throw new DeveloperError(iso8601ErrorMessage);\r\n }\r\n //>>includeEnd('debug');\r\n\r\n //Check the UTC offset value, if no value exists, use local time\r\n //a Z indicates UTC, + or - are offsets.\r\n var offset = tokens[offsetIndex];\r\n var offsetHours = +tokens[offsetIndex + 1];\r\n var offsetMinutes = +(tokens[offsetIndex + 2] || 0);\r\n switch (offset) {\r\n case \"+\":\r\n hour = hour - offsetHours;\r\n minute = minute - offsetMinutes;\r\n break;\r\n case \"-\":\r\n hour = hour + offsetHours;\r\n minute = minute + offsetMinutes;\r\n break;\r\n case \"Z\":\r\n break;\r\n default:\r\n minute =\r\n minute +\r\n new Date(\r\n Date.UTC(year, month - 1, day, hour, minute)\r\n ).getTimezoneOffset();\r\n break;\r\n }\r\n }\r\n\r\n //ISO8601 denotes a leap second by any time having a seconds component of 60 seconds.\r\n //If that's the case, we need to temporarily subtract a second in order to build a UTC date.\r\n //Then we add it back in after converting to TAI.\r\n var isLeapSecond = second === 60;\r\n if (isLeapSecond) {\r\n second--;\r\n }\r\n\r\n //Even if we successfully parsed the string into its components, after applying UTC offset or\r\n //special cases like 24:00:00 denoting midnight, we need to normalize the data appropriately.\r\n\r\n //milliseconds can never be greater than 1000, and seconds can't be above 60, so we start with minutes\r\n while (minute >= 60) {\r\n minute -= 60;\r\n hour++;\r\n }\r\n\r\n while (hour >= 24) {\r\n hour -= 24;\r\n day++;\r\n }\r\n\r\n tmp = inLeapYear && month === 2 ? daysInLeapFeburary : daysInMonth[month - 1];\r\n while (day > tmp) {\r\n day -= tmp;\r\n month++;\r\n\r\n if (month > 12) {\r\n month -= 12;\r\n year++;\r\n }\r\n\r\n tmp =\r\n inLeapYear && month === 2 ? daysInLeapFeburary : daysInMonth[month - 1];\r\n }\r\n\r\n //If UTC offset is at the beginning/end of the day, minutes can be negative.\r\n while (minute < 0) {\r\n minute += 60;\r\n hour--;\r\n }\r\n\r\n while (hour < 0) {\r\n hour += 24;\r\n day--;\r\n }\r\n\r\n while (day < 1) {\r\n month--;\r\n if (month < 1) {\r\n month += 12;\r\n year--;\r\n }\r\n\r\n tmp =\r\n inLeapYear && month === 2 ? daysInLeapFeburary : daysInMonth[month - 1];\r\n day += tmp;\r\n }\r\n\r\n //Now create the JulianDate components from the Gregorian date and actually create our instance.\r\n var components = computeJulianDateComponents(\r\n year,\r\n month,\r\n day,\r\n hour,\r\n minute,\r\n second,\r\n millisecond\r\n );\r\n\r\n if (!defined(result)) {\r\n result = new JulianDate(components[0], components[1], TimeStandard.UTC);\r\n } else {\r\n setComponents(components[0], components[1], result);\r\n convertUtcToTai(result);\r\n }\r\n\r\n //If we were on a leap second, add it back.\r\n if (isLeapSecond) {\r\n JulianDate.addSeconds(result, 1, result);\r\n }\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a new instance that represents the current system time.\r\n * This is equivalent to calling JulianDate.fromDate(new Date());
.\r\n *\r\n * @param {JulianDate} [result] An existing instance to use for the result.\r\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided.\r\n */\r\nJulianDate.now = function (result) {\r\n return JulianDate.fromDate(new Date(), result);\r\n};\r\n\r\nvar toGregorianDateScratch = new JulianDate(0, 0, TimeStandard.TAI);\r\n\r\n/**\r\n * Creates a {@link GregorianDate} from the provided instance.\r\n *\r\n * @param {JulianDate} julianDate The date to be converted.\r\n * @param {GregorianDate} [result] An existing instance to use for the result.\r\n * @returns {GregorianDate} The modified result parameter or a new instance if none was provided.\r\n */\r\nJulianDate.toGregorianDate = function (julianDate, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(julianDate)) {\r\n throw new DeveloperError(\"julianDate is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var isLeapSecond = false;\r\n var thisUtc = convertTaiToUtc(julianDate, toGregorianDateScratch);\r\n if (!defined(thisUtc)) {\r\n //Conversion to UTC will fail if we are during a leap second.\r\n //If that's the case, subtract a second and convert again.\r\n //JavaScript doesn't support leap seconds, so this results in second 59 being repeated twice.\r\n JulianDate.addSeconds(julianDate, -1, toGregorianDateScratch);\r\n thisUtc = convertTaiToUtc(toGregorianDateScratch, toGregorianDateScratch);\r\n isLeapSecond = true;\r\n }\r\n\r\n var julianDayNumber = thisUtc.dayNumber;\r\n var secondsOfDay = thisUtc.secondsOfDay;\r\n\r\n if (secondsOfDay >= 43200.0) {\r\n julianDayNumber += 1;\r\n }\r\n\r\n // Algorithm from page 604 of the Explanatory Supplement to the\r\n // Astronomical Almanac (Seidelmann 1992).\r\n var L = (julianDayNumber + 68569) | 0;\r\n var N = ((4 * L) / 146097) | 0;\r\n L = (L - (((146097 * N + 3) / 4) | 0)) | 0;\r\n var I = ((4000 * (L + 1)) / 1461001) | 0;\r\n L = (L - (((1461 * I) / 4) | 0) + 31) | 0;\r\n var J = ((80 * L) / 2447) | 0;\r\n var day = (L - (((2447 * J) / 80) | 0)) | 0;\r\n L = (J / 11) | 0;\r\n var month = (J + 2 - 12 * L) | 0;\r\n var year = (100 * (N - 49) + I + L) | 0;\r\n\r\n var hour = (secondsOfDay / TimeConstants.SECONDS_PER_HOUR) | 0;\r\n var remainingSeconds = secondsOfDay - hour * TimeConstants.SECONDS_PER_HOUR;\r\n var minute = (remainingSeconds / TimeConstants.SECONDS_PER_MINUTE) | 0;\r\n remainingSeconds =\r\n remainingSeconds - minute * TimeConstants.SECONDS_PER_MINUTE;\r\n var second = remainingSeconds | 0;\r\n var millisecond =\r\n (remainingSeconds - second) / TimeConstants.SECONDS_PER_MILLISECOND;\r\n\r\n // JulianDates are noon-based\r\n hour += 12;\r\n if (hour > 23) {\r\n hour -= 24;\r\n }\r\n\r\n //If we were on a leap second, add it back.\r\n if (isLeapSecond) {\r\n second += 1;\r\n }\r\n\r\n if (!defined(result)) {\r\n return new GregorianDate(\r\n year,\r\n month,\r\n day,\r\n hour,\r\n minute,\r\n second,\r\n millisecond,\r\n isLeapSecond\r\n );\r\n }\r\n\r\n result.year = year;\r\n result.month = month;\r\n result.day = day;\r\n result.hour = hour;\r\n result.minute = minute;\r\n result.second = second;\r\n result.millisecond = millisecond;\r\n result.isLeapSecond = isLeapSecond;\r\n return result;\r\n};\r\n\r\n/**\r\n * Creates a JavaScript Date from the provided instance.\r\n * Since JavaScript dates are only accurate to the nearest millisecond and\r\n * cannot represent a leap second, consider using {@link JulianDate.toGregorianDate} instead.\r\n * If the provided JulianDate is during a leap second, the previous second is used.\r\n *\r\n * @param {JulianDate} julianDate The date to be converted.\r\n * @returns {Date} A new instance representing the provided date.\r\n */\r\nJulianDate.toDate = function (julianDate) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(julianDate)) {\r\n throw new DeveloperError(\"julianDate is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var gDate = JulianDate.toGregorianDate(julianDate, gregorianDateScratch);\r\n var second = gDate.second;\r\n if (gDate.isLeapSecond) {\r\n second -= 1;\r\n }\r\n return new Date(\r\n Date.UTC(\r\n gDate.year,\r\n gDate.month - 1,\r\n gDate.day,\r\n gDate.hour,\r\n gDate.minute,\r\n second,\r\n gDate.millisecond\r\n )\r\n );\r\n};\r\n\r\n/**\r\n * Creates an ISO8601 representation of the provided date.\r\n *\r\n * @param {JulianDate} julianDate The date to be converted.\r\n * @param {Number} [precision] The number of fractional digits used to represent the seconds component. By default, the most precise representation is used.\r\n * @returns {String} The ISO8601 representation of the provided date.\r\n */\r\nJulianDate.toIso8601 = function (julianDate, precision) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(julianDate)) {\r\n throw new DeveloperError(\"julianDate is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var gDate = JulianDate.toGregorianDate(julianDate, gregorianDateScratch);\r\n var year = gDate.year;\r\n var month = gDate.month;\r\n var day = gDate.day;\r\n var hour = gDate.hour;\r\n var minute = gDate.minute;\r\n var second = gDate.second;\r\n var millisecond = gDate.millisecond;\r\n\r\n // special case - Iso8601.MAXIMUM_VALUE produces a string which we can't parse unless we adjust.\r\n // 10000-01-01T00:00:00 is the same instant as 9999-12-31T24:00:00\r\n if (\r\n year === 10000 &&\r\n month === 1 &&\r\n day === 1 &&\r\n hour === 0 &&\r\n minute === 0 &&\r\n second === 0 &&\r\n millisecond === 0\r\n ) {\r\n year = 9999;\r\n month = 12;\r\n day = 31;\r\n hour = 24;\r\n }\r\n\r\n var millisecondStr;\r\n\r\n if (!defined(precision) && millisecond !== 0) {\r\n //Forces milliseconds into a number with at least 3 digits to whatever the default toString() precision is.\r\n millisecondStr = (millisecond * 0.01).toString().replace(\".\", \"\");\r\n return sprintf(\r\n \"%04d-%02d-%02dT%02d:%02d:%02d.%sZ\",\r\n year,\r\n month,\r\n day,\r\n hour,\r\n minute,\r\n second,\r\n millisecondStr\r\n );\r\n }\r\n\r\n //Precision is either 0 or milliseconds is 0 with undefined precision, in either case, leave off milliseconds entirely\r\n if (!defined(precision) || precision === 0) {\r\n return sprintf(\r\n \"%04d-%02d-%02dT%02d:%02d:%02dZ\",\r\n year,\r\n month,\r\n day,\r\n hour,\r\n minute,\r\n second\r\n );\r\n }\r\n\r\n //Forces milliseconds into a number with at least 3 digits to whatever the specified precision is.\r\n millisecondStr = (millisecond * 0.01)\r\n .toFixed(precision)\r\n .replace(\".\", \"\")\r\n .slice(0, precision);\r\n return sprintf(\r\n \"%04d-%02d-%02dT%02d:%02d:%02d.%sZ\",\r\n year,\r\n month,\r\n day,\r\n hour,\r\n minute,\r\n second,\r\n millisecondStr\r\n );\r\n};\r\n\r\n/**\r\n * Duplicates a JulianDate instance.\r\n *\r\n * @param {JulianDate} julianDate The date to duplicate.\r\n * @param {JulianDate} [result] An existing instance to use for the result.\r\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided. Returns undefined if julianDate is undefined.\r\n */\r\nJulianDate.clone = function (julianDate, result) {\r\n if (!defined(julianDate)) {\r\n return undefined;\r\n }\r\n if (!defined(result)) {\r\n return new JulianDate(\r\n julianDate.dayNumber,\r\n julianDate.secondsOfDay,\r\n TimeStandard.TAI\r\n );\r\n }\r\n result.dayNumber = julianDate.dayNumber;\r\n result.secondsOfDay = julianDate.secondsOfDay;\r\n return result;\r\n};\r\n\r\n/**\r\n * Compares two instances.\r\n *\r\n * @param {JulianDate} left The first instance.\r\n * @param {JulianDate} right The second instance.\r\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.\r\n */\r\nJulianDate.compare = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(left)) {\r\n throw new DeveloperError(\"left is required.\");\r\n }\r\n if (!defined(right)) {\r\n throw new DeveloperError(\"right is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var julianDayNumberDifference = left.dayNumber - right.dayNumber;\r\n if (julianDayNumberDifference !== 0) {\r\n return julianDayNumberDifference;\r\n }\r\n return left.secondsOfDay - right.secondsOfDay;\r\n};\r\n\r\n/**\r\n * Compares two instances and returns true
if they are equal, false
otherwise.\r\n *\r\n * @param {JulianDate} [left] The first instance.\r\n * @param {JulianDate} [right] The second instance.\r\n * @returns {Boolean} true
if the dates are equal; otherwise, false
.\r\n */\r\nJulianDate.equals = function (left, right) {\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n left.dayNumber === right.dayNumber &&\r\n left.secondsOfDay === right.secondsOfDay)\r\n );\r\n};\r\n\r\n/**\r\n * Compares two instances and returns true
if they are within epsilon
seconds of\r\n * each other. That is, in order for the dates to be considered equal (and for\r\n * this function to return true
), the absolute value of the difference between them, in\r\n * seconds, must be less than epsilon
.\r\n *\r\n * @param {JulianDate} [left] The first instance.\r\n * @param {JulianDate} [right] The second instance.\r\n * @param {Number} [epsilon=0] The maximum number of seconds that should separate the two instances.\r\n * @returns {Boolean} true
if the two dates are within epsilon
seconds of each other; otherwise false
.\r\n */\r\nJulianDate.equalsEpsilon = function (left, right, epsilon) {\r\n epsilon = defaultValue(epsilon, 0);\r\n\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n Math.abs(JulianDate.secondsDifference(left, right)) <= epsilon)\r\n );\r\n};\r\n\r\n/**\r\n * Computes the total number of whole and fractional days represented by the provided instance.\r\n *\r\n * @param {JulianDate} julianDate The date.\r\n * @returns {Number} The Julian date as single floating point number.\r\n */\r\nJulianDate.totalDays = function (julianDate) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(julianDate)) {\r\n throw new DeveloperError(\"julianDate is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n return (\r\n julianDate.dayNumber +\r\n julianDate.secondsOfDay / TimeConstants.SECONDS_PER_DAY\r\n );\r\n};\r\n\r\n/**\r\n * Computes the difference in seconds between the provided instance.\r\n *\r\n * @param {JulianDate} left The first instance.\r\n * @param {JulianDate} right The second instance.\r\n * @returns {Number} The difference, in seconds, when subtracting right
from left
.\r\n */\r\nJulianDate.secondsDifference = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(left)) {\r\n throw new DeveloperError(\"left is required.\");\r\n }\r\n if (!defined(right)) {\r\n throw new DeveloperError(\"right is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var dayDifference =\r\n (left.dayNumber - right.dayNumber) * TimeConstants.SECONDS_PER_DAY;\r\n return dayDifference + (left.secondsOfDay - right.secondsOfDay);\r\n};\r\n\r\n/**\r\n * Computes the difference in days between the provided instance.\r\n *\r\n * @param {JulianDate} left The first instance.\r\n * @param {JulianDate} right The second instance.\r\n * @returns {Number} The difference, in days, when subtracting right
from left
.\r\n */\r\nJulianDate.daysDifference = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(left)) {\r\n throw new DeveloperError(\"left is required.\");\r\n }\r\n if (!defined(right)) {\r\n throw new DeveloperError(\"right is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var dayDifference = left.dayNumber - right.dayNumber;\r\n var secondDifference =\r\n (left.secondsOfDay - right.secondsOfDay) / TimeConstants.SECONDS_PER_DAY;\r\n return dayDifference + secondDifference;\r\n};\r\n\r\n/**\r\n * Computes the number of seconds the provided instance is ahead of UTC.\r\n *\r\n * @param {JulianDate} julianDate The date.\r\n * @returns {Number} The number of seconds the provided instance is ahead of UTC\r\n */\r\nJulianDate.computeTaiMinusUtc = function (julianDate) {\r\n binarySearchScratchLeapSecond.julianDate = julianDate;\r\n var leapSeconds = JulianDate.leapSeconds;\r\n var index = binarySearch(\r\n leapSeconds,\r\n binarySearchScratchLeapSecond,\r\n compareLeapSecondDates\r\n );\r\n if (index < 0) {\r\n index = ~index;\r\n --index;\r\n if (index < 0) {\r\n index = 0;\r\n }\r\n }\r\n return leapSeconds[index].offset;\r\n};\r\n\r\n/**\r\n * Adds the provided number of seconds to the provided date instance.\r\n *\r\n * @param {JulianDate} julianDate The date.\r\n * @param {Number} seconds The number of seconds to add or subtract.\r\n * @param {JulianDate} result An existing instance to use for the result.\r\n * @returns {JulianDate} The modified result parameter.\r\n */\r\nJulianDate.addSeconds = function (julianDate, seconds, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(julianDate)) {\r\n throw new DeveloperError(\"julianDate is required.\");\r\n }\r\n if (!defined(seconds)) {\r\n throw new DeveloperError(\"seconds is required.\");\r\n }\r\n if (!defined(result)) {\r\n throw new DeveloperError(\"result is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n return setComponents(\r\n julianDate.dayNumber,\r\n julianDate.secondsOfDay + seconds,\r\n result\r\n );\r\n};\r\n\r\n/**\r\n * Adds the provided number of minutes to the provided date instance.\r\n *\r\n * @param {JulianDate} julianDate The date.\r\n * @param {Number} minutes The number of minutes to add or subtract.\r\n * @param {JulianDate} result An existing instance to use for the result.\r\n * @returns {JulianDate} The modified result parameter.\r\n */\r\nJulianDate.addMinutes = function (julianDate, minutes, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(julianDate)) {\r\n throw new DeveloperError(\"julianDate is required.\");\r\n }\r\n if (!defined(minutes)) {\r\n throw new DeveloperError(\"minutes is required.\");\r\n }\r\n if (!defined(result)) {\r\n throw new DeveloperError(\"result is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var newSecondsOfDay =\r\n julianDate.secondsOfDay + minutes * TimeConstants.SECONDS_PER_MINUTE;\r\n return setComponents(julianDate.dayNumber, newSecondsOfDay, result);\r\n};\r\n\r\n/**\r\n * Adds the provided number of hours to the provided date instance.\r\n *\r\n * @param {JulianDate} julianDate The date.\r\n * @param {Number} hours The number of hours to add or subtract.\r\n * @param {JulianDate} result An existing instance to use for the result.\r\n * @returns {JulianDate} The modified result parameter.\r\n */\r\nJulianDate.addHours = function (julianDate, hours, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(julianDate)) {\r\n throw new DeveloperError(\"julianDate is required.\");\r\n }\r\n if (!defined(hours)) {\r\n throw new DeveloperError(\"hours is required.\");\r\n }\r\n if (!defined(result)) {\r\n throw new DeveloperError(\"result is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var newSecondsOfDay =\r\n julianDate.secondsOfDay + hours * TimeConstants.SECONDS_PER_HOUR;\r\n return setComponents(julianDate.dayNumber, newSecondsOfDay, result);\r\n};\r\n\r\n/**\r\n * Adds the provided number of days to the provided date instance.\r\n *\r\n * @param {JulianDate} julianDate The date.\r\n * @param {Number} days The number of days to add or subtract.\r\n * @param {JulianDate} result An existing instance to use for the result.\r\n * @returns {JulianDate} The modified result parameter.\r\n */\r\nJulianDate.addDays = function (julianDate, days, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(julianDate)) {\r\n throw new DeveloperError(\"julianDate is required.\");\r\n }\r\n if (!defined(days)) {\r\n throw new DeveloperError(\"days is required.\");\r\n }\r\n if (!defined(result)) {\r\n throw new DeveloperError(\"result is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var newJulianDayNumber = julianDate.dayNumber + days;\r\n return setComponents(newJulianDayNumber, julianDate.secondsOfDay, result);\r\n};\r\n\r\n/**\r\n * Compares the provided instances and returns true
if left
is earlier than right
, false
otherwise.\r\n *\r\n * @param {JulianDate} left The first instance.\r\n * @param {JulianDate} right The second instance.\r\n * @returns {Boolean} true
if left
is earlier than right
, false
otherwise.\r\n */\r\nJulianDate.lessThan = function (left, right) {\r\n return JulianDate.compare(left, right) < 0;\r\n};\r\n\r\n/**\r\n * Compares the provided instances and returns true
if left
is earlier than or equal to right
, false
otherwise.\r\n *\r\n * @param {JulianDate} left The first instance.\r\n * @param {JulianDate} right The second instance.\r\n * @returns {Boolean} true
if left
is earlier than or equal to right
, false
otherwise.\r\n */\r\nJulianDate.lessThanOrEquals = function (left, right) {\r\n return JulianDate.compare(left, right) <= 0;\r\n};\r\n\r\n/**\r\n * Compares the provided instances and returns true
if left
is later than right
, false
otherwise.\r\n *\r\n * @param {JulianDate} left The first instance.\r\n * @param {JulianDate} right The second instance.\r\n * @returns {Boolean} true
if left
is later than right
, false
otherwise.\r\n */\r\nJulianDate.greaterThan = function (left, right) {\r\n return JulianDate.compare(left, right) > 0;\r\n};\r\n\r\n/**\r\n * Compares the provided instances and returns true
if left
is later than or equal to right
, false
otherwise.\r\n *\r\n * @param {JulianDate} left The first instance.\r\n * @param {JulianDate} right The second instance.\r\n * @returns {Boolean} true
if left
is later than or equal to right
, false
otherwise.\r\n */\r\nJulianDate.greaterThanOrEquals = function (left, right) {\r\n return JulianDate.compare(left, right) >= 0;\r\n};\r\n\r\n/**\r\n * Duplicates this instance.\r\n *\r\n * @param {JulianDate} [result] An existing instance to use for the result.\r\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided.\r\n */\r\nJulianDate.prototype.clone = function (result) {\r\n return JulianDate.clone(this, result);\r\n};\r\n\r\n/**\r\n * Compares this and the provided instance and returns true
if they are equal, false
otherwise.\r\n *\r\n * @param {JulianDate} [right] The second instance.\r\n * @returns {Boolean} true
if the dates are equal; otherwise, false
.\r\n */\r\nJulianDate.prototype.equals = function (right) {\r\n return JulianDate.equals(this, right);\r\n};\r\n\r\n/**\r\n * Compares this and the provided instance and returns true
if they are within epsilon
seconds of\r\n * each other. That is, in order for the dates to be considered equal (and for\r\n * this function to return true
), the absolute value of the difference between them, in\r\n * seconds, must be less than epsilon
.\r\n *\r\n * @param {JulianDate} [right] The second instance.\r\n * @param {Number} [epsilon=0] The maximum number of seconds that should separate the two instances.\r\n * @returns {Boolean} true
if the two dates are within epsilon
seconds of each other; otherwise false
.\r\n */\r\nJulianDate.prototype.equalsEpsilon = function (right, epsilon) {\r\n return JulianDate.equalsEpsilon(this, right, epsilon);\r\n};\r\n\r\n/**\r\n * Creates a string representing this date in ISO8601 format.\r\n *\r\n * @returns {String} A string representing this date in ISO8601 format.\r\n */\r\nJulianDate.prototype.toString = function () {\r\n return JulianDate.toIso8601(this);\r\n};\r\n\r\n/**\r\n * Gets or sets the list of leap seconds used throughout Cesium.\r\n * @memberof JulianDate\r\n * @type {LeapSecond[]}\r\n */\r\nJulianDate.leapSeconds = [\r\n new LeapSecond(new JulianDate(2441317, 43210.0, TimeStandard.TAI), 10), // January 1, 1972 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2441499, 43211.0, TimeStandard.TAI), 11), // July 1, 1972 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2441683, 43212.0, TimeStandard.TAI), 12), // January 1, 1973 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2442048, 43213.0, TimeStandard.TAI), 13), // January 1, 1974 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2442413, 43214.0, TimeStandard.TAI), 14), // January 1, 1975 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2442778, 43215.0, TimeStandard.TAI), 15), // January 1, 1976 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2443144, 43216.0, TimeStandard.TAI), 16), // January 1, 1977 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2443509, 43217.0, TimeStandard.TAI), 17), // January 1, 1978 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2443874, 43218.0, TimeStandard.TAI), 18), // January 1, 1979 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2444239, 43219.0, TimeStandard.TAI), 19), // January 1, 1980 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2444786, 43220.0, TimeStandard.TAI), 20), // July 1, 1981 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2445151, 43221.0, TimeStandard.TAI), 21), // July 1, 1982 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2445516, 43222.0, TimeStandard.TAI), 22), // July 1, 1983 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2446247, 43223.0, TimeStandard.TAI), 23), // July 1, 1985 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2447161, 43224.0, TimeStandard.TAI), 24), // January 1, 1988 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2447892, 43225.0, TimeStandard.TAI), 25), // January 1, 1990 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2448257, 43226.0, TimeStandard.TAI), 26), // January 1, 1991 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2448804, 43227.0, TimeStandard.TAI), 27), // July 1, 1992 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2449169, 43228.0, TimeStandard.TAI), 28), // July 1, 1993 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2449534, 43229.0, TimeStandard.TAI), 29), // July 1, 1994 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2450083, 43230.0, TimeStandard.TAI), 30), // January 1, 1996 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2450630, 43231.0, TimeStandard.TAI), 31), // July 1, 1997 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2451179, 43232.0, TimeStandard.TAI), 32), // January 1, 1999 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2453736, 43233.0, TimeStandard.TAI), 33), // January 1, 2006 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2454832, 43234.0, TimeStandard.TAI), 34), // January 1, 2009 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2456109, 43235.0, TimeStandard.TAI), 35), // July 1, 2012 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2457204, 43236.0, TimeStandard.TAI), 36), // July 1, 2015 00:00:00 UTC\r\n new LeapSecond(new JulianDate(2457754, 43237.0, TimeStandard.TAI), 37), // January 1, 2017 00:00:00 UTC\r\n];\r\nexport default JulianDate;\r\n","import when from \"../ThirdParty/when.js\";\r\nimport binarySearch from \"./binarySearch.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport EarthOrientationParametersSample from \"./EarthOrientationParametersSample.js\";\r\nimport JulianDate from \"./JulianDate.js\";\r\nimport LeapSecond from \"./LeapSecond.js\";\r\nimport Resource from \"./Resource.js\";\r\nimport RuntimeError from \"./RuntimeError.js\";\r\nimport TimeConstants from \"./TimeConstants.js\";\r\nimport TimeStandard from \"./TimeStandard.js\";\r\n\r\n/**\r\n * Specifies Earth polar motion coordinates and the difference between UT1 and UTC.\r\n * These Earth Orientation Parameters (EOP) are primarily used in the transformation from\r\n * the International Celestial Reference Frame (ICRF) to the International Terrestrial\r\n * Reference Frame (ITRF).\r\n *\r\n * @alias EarthOrientationParameters\r\n * @constructor\r\n *\r\n * @param {Object} [options] Object with the following properties:\r\n * @param {Resource|String} [options.url] The URL from which to obtain EOP data. If neither this\r\n * parameter nor options.data is specified, all EOP values are assumed\r\n * to be 0.0. If options.data is specified, this parameter is\r\n * ignored.\r\n * @param {Object} [options.data] The actual EOP data. If neither this\r\n * parameter nor options.data is specified, all EOP values are assumed\r\n * to be 0.0.\r\n * @param {Boolean} [options.addNewLeapSeconds=true] True if leap seconds that\r\n * are specified in the EOP data but not in {@link JulianDate.leapSeconds}\r\n * should be added to {@link JulianDate.leapSeconds}. False if\r\n * new leap seconds should be handled correctly in the context\r\n * of the EOP data but otherwise ignored.\r\n *\r\n * @example\r\n * // An example EOP data file, EOP.json:\r\n * {\r\n * \"columnNames\" : [\"dateIso8601\",\"modifiedJulianDateUtc\",\"xPoleWanderRadians\",\"yPoleWanderRadians\",\"ut1MinusUtcSeconds\",\"lengthOfDayCorrectionSeconds\",\"xCelestialPoleOffsetRadians\",\"yCelestialPoleOffsetRadians\",\"taiMinusUtcSeconds\"],\r\n * \"samples\" : [\r\n * \"2011-07-01T00:00:00Z\",55743.0,2.117957047295119e-7,2.111518721609984e-6,-0.2908948,-2.956e-4,3.393695767766752e-11,3.3452143996557983e-10,34.0,\r\n * \"2011-07-02T00:00:00Z\",55744.0,2.193297093339541e-7,2.115460256837405e-6,-0.29065,-1.824e-4,-8.241832578862112e-11,5.623838700870617e-10,34.0,\r\n * \"2011-07-03T00:00:00Z\",55745.0,2.262286080161428e-7,2.1191157519929706e-6,-0.2905572,1.9e-6,-3.490658503988659e-10,6.981317007977318e-10,34.0\r\n * ]\r\n * }\r\n *\r\n * @example\r\n * // Loading the EOP data\r\n * var eop = new Cesium.EarthOrientationParameters({ url : 'Data/EOP.json' });\r\n * Cesium.Transforms.earthOrientationParameters = eop;\r\n *\r\n * @private\r\n */\r\nfunction EarthOrientationParameters(options) {\r\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\r\n\r\n this._dates = undefined;\r\n this._samples = undefined;\r\n\r\n this._dateColumn = -1;\r\n this._xPoleWanderRadiansColumn = -1;\r\n this._yPoleWanderRadiansColumn = -1;\r\n this._ut1MinusUtcSecondsColumn = -1;\r\n this._xCelestialPoleOffsetRadiansColumn = -1;\r\n this._yCelestialPoleOffsetRadiansColumn = -1;\r\n this._taiMinusUtcSecondsColumn = -1;\r\n\r\n this._columnCount = 0;\r\n this._lastIndex = -1;\r\n\r\n this._downloadPromise = undefined;\r\n this._dataError = undefined;\r\n\r\n this._addNewLeapSeconds = defaultValue(options.addNewLeapSeconds, true);\r\n\r\n if (defined(options.data)) {\r\n // Use supplied EOP data.\r\n onDataReady(this, options.data);\r\n } else if (defined(options.url)) {\r\n var resource = Resource.createIfNeeded(options.url);\r\n\r\n // Download EOP data.\r\n var that = this;\r\n this._downloadPromise = resource\r\n .fetchJson()\r\n .then(function (eopData) {\r\n onDataReady(that, eopData);\r\n })\r\n .otherwise(function () {\r\n that._dataError =\r\n \"An error occurred while retrieving the EOP data from the URL \" +\r\n resource.url +\r\n \".\";\r\n });\r\n } else {\r\n // Use all zeros for EOP data.\r\n onDataReady(this, {\r\n columnNames: [\r\n \"dateIso8601\",\r\n \"modifiedJulianDateUtc\",\r\n \"xPoleWanderRadians\",\r\n \"yPoleWanderRadians\",\r\n \"ut1MinusUtcSeconds\",\r\n \"lengthOfDayCorrectionSeconds\",\r\n \"xCelestialPoleOffsetRadians\",\r\n \"yCelestialPoleOffsetRadians\",\r\n \"taiMinusUtcSeconds\",\r\n ],\r\n samples: [],\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * A default {@link EarthOrientationParameters} instance that returns zero for all EOP values.\r\n */\r\nEarthOrientationParameters.NONE = Object.freeze({\r\n getPromiseToLoad: function () {\r\n return when.resolve();\r\n },\r\n compute: function (date, result) {\r\n if (!defined(result)) {\r\n result = new EarthOrientationParametersSample(0.0, 0.0, 0.0, 0.0, 0.0);\r\n } else {\r\n result.xPoleWander = 0.0;\r\n result.yPoleWander = 0.0;\r\n result.xPoleOffset = 0.0;\r\n result.yPoleOffset = 0.0;\r\n result.ut1MinusUtc = 0.0;\r\n }\r\n return result;\r\n },\r\n});\r\n\r\n/**\r\n * Gets a promise that, when resolved, indicates that the EOP data has been loaded and is\r\n * ready to use.\r\n *\r\n * @returns {Promise} The promise.\r\n */\r\nEarthOrientationParameters.prototype.getPromiseToLoad = function () {\r\n return when(this._downloadPromise);\r\n};\r\n\r\n/**\r\n * Computes the Earth Orientation Parameters (EOP) for a given date by interpolating.\r\n * If the EOP data has not yet been download, this method returns undefined.\r\n *\r\n * @param {JulianDate} date The date for each to evaluate the EOP.\r\n * @param {EarthOrientationParametersSample} [result] The instance to which to copy the result.\r\n * If this parameter is undefined, a new instance is created and returned.\r\n * @returns {EarthOrientationParametersSample} The EOP evaluated at the given date, or\r\n * undefined if the data necessary to evaluate EOP at the date has not yet been\r\n * downloaded.\r\n *\r\n * @exception {RuntimeError} The loaded EOP data has an error and cannot be used.\r\n *\r\n * @see EarthOrientationParameters#getPromiseToLoad\r\n */\r\nEarthOrientationParameters.prototype.compute = function (date, result) {\r\n // We cannot compute until the samples are available.\r\n if (!defined(this._samples)) {\r\n if (defined(this._dataError)) {\r\n throw new RuntimeError(this._dataError);\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n if (!defined(result)) {\r\n result = new EarthOrientationParametersSample(0.0, 0.0, 0.0, 0.0, 0.0);\r\n }\r\n\r\n if (this._samples.length === 0) {\r\n result.xPoleWander = 0.0;\r\n result.yPoleWander = 0.0;\r\n result.xPoleOffset = 0.0;\r\n result.yPoleOffset = 0.0;\r\n result.ut1MinusUtc = 0.0;\r\n return result;\r\n }\r\n\r\n var dates = this._dates;\r\n var lastIndex = this._lastIndex;\r\n\r\n var before = 0;\r\n var after = 0;\r\n if (defined(lastIndex)) {\r\n var previousIndexDate = dates[lastIndex];\r\n var nextIndexDate = dates[lastIndex + 1];\r\n var isAfterPrevious = JulianDate.lessThanOrEquals(previousIndexDate, date);\r\n var isAfterLastSample = !defined(nextIndexDate);\r\n var isBeforeNext =\r\n isAfterLastSample || JulianDate.greaterThanOrEquals(nextIndexDate, date);\r\n\r\n if (isAfterPrevious && isBeforeNext) {\r\n before = lastIndex;\r\n\r\n if (!isAfterLastSample && nextIndexDate.equals(date)) {\r\n ++before;\r\n }\r\n after = before + 1;\r\n\r\n interpolate(this, dates, this._samples, date, before, after, result);\r\n return result;\r\n }\r\n }\r\n\r\n var index = binarySearch(dates, date, JulianDate.compare, this._dateColumn);\r\n if (index >= 0) {\r\n // If the next entry is the same date, use the later entry. This way, if two entries\r\n // describe the same moment, one before a leap second and the other after, then we will use\r\n // the post-leap second data.\r\n if (index < dates.length - 1 && dates[index + 1].equals(date)) {\r\n ++index;\r\n }\r\n before = index;\r\n after = index;\r\n } else {\r\n after = ~index;\r\n before = after - 1;\r\n\r\n // Use the first entry if the date requested is before the beginning of the data.\r\n if (before < 0) {\r\n before = 0;\r\n }\r\n }\r\n\r\n this._lastIndex = before;\r\n\r\n interpolate(this, dates, this._samples, date, before, after, result);\r\n return result;\r\n};\r\n\r\nfunction compareLeapSecondDates(leapSecond, dateToFind) {\r\n return JulianDate.compare(leapSecond.julianDate, dateToFind);\r\n}\r\n\r\nfunction onDataReady(eop, eopData) {\r\n if (!defined(eopData.columnNames)) {\r\n eop._dataError =\r\n \"Error in loaded EOP data: The columnNames property is required.\";\r\n return;\r\n }\r\n\r\n if (!defined(eopData.samples)) {\r\n eop._dataError =\r\n \"Error in loaded EOP data: The samples property is required.\";\r\n return;\r\n }\r\n\r\n var dateColumn = eopData.columnNames.indexOf(\"modifiedJulianDateUtc\");\r\n var xPoleWanderRadiansColumn = eopData.columnNames.indexOf(\r\n \"xPoleWanderRadians\"\r\n );\r\n var yPoleWanderRadiansColumn = eopData.columnNames.indexOf(\r\n \"yPoleWanderRadians\"\r\n );\r\n var ut1MinusUtcSecondsColumn = eopData.columnNames.indexOf(\r\n \"ut1MinusUtcSeconds\"\r\n );\r\n var xCelestialPoleOffsetRadiansColumn = eopData.columnNames.indexOf(\r\n \"xCelestialPoleOffsetRadians\"\r\n );\r\n var yCelestialPoleOffsetRadiansColumn = eopData.columnNames.indexOf(\r\n \"yCelestialPoleOffsetRadians\"\r\n );\r\n var taiMinusUtcSecondsColumn = eopData.columnNames.indexOf(\r\n \"taiMinusUtcSeconds\"\r\n );\r\n\r\n if (\r\n dateColumn < 0 ||\r\n xPoleWanderRadiansColumn < 0 ||\r\n yPoleWanderRadiansColumn < 0 ||\r\n ut1MinusUtcSecondsColumn < 0 ||\r\n xCelestialPoleOffsetRadiansColumn < 0 ||\r\n yCelestialPoleOffsetRadiansColumn < 0 ||\r\n taiMinusUtcSecondsColumn < 0\r\n ) {\r\n eop._dataError =\r\n \"Error in loaded EOP data: The columnNames property must include modifiedJulianDateUtc, xPoleWanderRadians, yPoleWanderRadians, ut1MinusUtcSeconds, xCelestialPoleOffsetRadians, yCelestialPoleOffsetRadians, and taiMinusUtcSeconds columns\";\r\n return;\r\n }\r\n\r\n var samples = (eop._samples = eopData.samples);\r\n var dates = (eop._dates = []);\r\n\r\n eop._dateColumn = dateColumn;\r\n eop._xPoleWanderRadiansColumn = xPoleWanderRadiansColumn;\r\n eop._yPoleWanderRadiansColumn = yPoleWanderRadiansColumn;\r\n eop._ut1MinusUtcSecondsColumn = ut1MinusUtcSecondsColumn;\r\n eop._xCelestialPoleOffsetRadiansColumn = xCelestialPoleOffsetRadiansColumn;\r\n eop._yCelestialPoleOffsetRadiansColumn = yCelestialPoleOffsetRadiansColumn;\r\n eop._taiMinusUtcSecondsColumn = taiMinusUtcSecondsColumn;\r\n\r\n eop._columnCount = eopData.columnNames.length;\r\n eop._lastIndex = undefined;\r\n\r\n var lastTaiMinusUtc;\r\n\r\n var addNewLeapSeconds = eop._addNewLeapSeconds;\r\n\r\n // Convert the ISO8601 dates to JulianDates.\r\n for (var i = 0, len = samples.length; i < len; i += eop._columnCount) {\r\n var mjd = samples[i + dateColumn];\r\n var taiMinusUtc = samples[i + taiMinusUtcSecondsColumn];\r\n var day = mjd + TimeConstants.MODIFIED_JULIAN_DATE_DIFFERENCE;\r\n var date = new JulianDate(day, taiMinusUtc, TimeStandard.TAI);\r\n dates.push(date);\r\n\r\n if (addNewLeapSeconds) {\r\n if (taiMinusUtc !== lastTaiMinusUtc && defined(lastTaiMinusUtc)) {\r\n // We crossed a leap second boundary, so add the leap second\r\n // if it does not already exist.\r\n var leapSeconds = JulianDate.leapSeconds;\r\n var leapSecondIndex = binarySearch(\r\n leapSeconds,\r\n date,\r\n compareLeapSecondDates\r\n );\r\n if (leapSecondIndex < 0) {\r\n var leapSecond = new LeapSecond(date, taiMinusUtc);\r\n leapSeconds.splice(~leapSecondIndex, 0, leapSecond);\r\n }\r\n }\r\n lastTaiMinusUtc = taiMinusUtc;\r\n }\r\n }\r\n}\r\n\r\nfunction fillResultFromIndex(eop, samples, index, columnCount, result) {\r\n var start = index * columnCount;\r\n result.xPoleWander = samples[start + eop._xPoleWanderRadiansColumn];\r\n result.yPoleWander = samples[start + eop._yPoleWanderRadiansColumn];\r\n result.xPoleOffset = samples[start + eop._xCelestialPoleOffsetRadiansColumn];\r\n result.yPoleOffset = samples[start + eop._yCelestialPoleOffsetRadiansColumn];\r\n result.ut1MinusUtc = samples[start + eop._ut1MinusUtcSecondsColumn];\r\n}\r\n\r\nfunction linearInterp(dx, y1, y2) {\r\n return y1 + dx * (y2 - y1);\r\n}\r\n\r\nfunction interpolate(eop, dates, samples, date, before, after, result) {\r\n var columnCount = eop._columnCount;\r\n\r\n // First check the bounds on the EOP data\r\n // If we are after the bounds of the data, return zeros.\r\n // The 'before' index should never be less than zero.\r\n if (after > dates.length - 1) {\r\n result.xPoleWander = 0;\r\n result.yPoleWander = 0;\r\n result.xPoleOffset = 0;\r\n result.yPoleOffset = 0;\r\n result.ut1MinusUtc = 0;\r\n return result;\r\n }\r\n\r\n var beforeDate = dates[before];\r\n var afterDate = dates[after];\r\n if (beforeDate.equals(afterDate) || date.equals(beforeDate)) {\r\n fillResultFromIndex(eop, samples, before, columnCount, result);\r\n return result;\r\n } else if (date.equals(afterDate)) {\r\n fillResultFromIndex(eop, samples, after, columnCount, result);\r\n return result;\r\n }\r\n\r\n var factor =\r\n JulianDate.secondsDifference(date, beforeDate) /\r\n JulianDate.secondsDifference(afterDate, beforeDate);\r\n\r\n var startBefore = before * columnCount;\r\n var startAfter = after * columnCount;\r\n\r\n // Handle UT1 leap second edge case\r\n var beforeUt1MinusUtc = samples[startBefore + eop._ut1MinusUtcSecondsColumn];\r\n var afterUt1MinusUtc = samples[startAfter + eop._ut1MinusUtcSecondsColumn];\r\n\r\n var offsetDifference = afterUt1MinusUtc - beforeUt1MinusUtc;\r\n if (offsetDifference > 0.5 || offsetDifference < -0.5) {\r\n // The absolute difference between the values is more than 0.5, so we may have\r\n // crossed a leap second. Check if this is the case and, if so, adjust the\r\n // afterValue to account for the leap second. This way, our interpolation will\r\n // produce reasonable results.\r\n var beforeTaiMinusUtc =\r\n samples[startBefore + eop._taiMinusUtcSecondsColumn];\r\n var afterTaiMinusUtc = samples[startAfter + eop._taiMinusUtcSecondsColumn];\r\n if (beforeTaiMinusUtc !== afterTaiMinusUtc) {\r\n if (afterDate.equals(date)) {\r\n // If we are at the end of the leap second interval, take the second value\r\n // Otherwise, the interpolation below will yield the wrong side of the\r\n // discontinuity\r\n // At the end of the leap second, we need to start accounting for the jump\r\n beforeUt1MinusUtc = afterUt1MinusUtc;\r\n } else {\r\n // Otherwise, remove the leap second so that the interpolation is correct\r\n afterUt1MinusUtc -= afterTaiMinusUtc - beforeTaiMinusUtc;\r\n }\r\n }\r\n }\r\n\r\n result.xPoleWander = linearInterp(\r\n factor,\r\n samples[startBefore + eop._xPoleWanderRadiansColumn],\r\n samples[startAfter + eop._xPoleWanderRadiansColumn]\r\n );\r\n result.yPoleWander = linearInterp(\r\n factor,\r\n samples[startBefore + eop._yPoleWanderRadiansColumn],\r\n samples[startAfter + eop._yPoleWanderRadiansColumn]\r\n );\r\n result.xPoleOffset = linearInterp(\r\n factor,\r\n samples[startBefore + eop._xCelestialPoleOffsetRadiansColumn],\r\n samples[startAfter + eop._xCelestialPoleOffsetRadiansColumn]\r\n );\r\n result.yPoleOffset = linearInterp(\r\n factor,\r\n samples[startBefore + eop._yCelestialPoleOffsetRadiansColumn],\r\n samples[startAfter + eop._yCelestialPoleOffsetRadiansColumn]\r\n );\r\n result.ut1MinusUtc = linearInterp(\r\n factor,\r\n beforeUt1MinusUtc,\r\n afterUt1MinusUtc\r\n );\r\n return result;\r\n}\r\nexport default EarthOrientationParameters;\r\n","import defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport CesiumMath from \"./Math.js\";\r\n\r\n/**\r\n * A rotation expressed as a heading, pitch, and roll. Heading is the rotation about the\r\n * negative z axis. Pitch is the rotation about the negative y axis. Roll is the rotation about\r\n * the positive x axis.\r\n * @alias HeadingPitchRoll\r\n * @constructor\r\n *\r\n * @param {Number} [heading=0.0] The heading component in radians.\r\n * @param {Number} [pitch=0.0] The pitch component in radians.\r\n * @param {Number} [roll=0.0] The roll component in radians.\r\n */\r\nfunction HeadingPitchRoll(heading, pitch, roll) {\r\n /**\r\n * Gets or sets the heading.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.heading = defaultValue(heading, 0.0);\r\n /**\r\n * Gets or sets the pitch.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.pitch = defaultValue(pitch, 0.0);\r\n /**\r\n * Gets or sets the roll.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.roll = defaultValue(roll, 0.0);\r\n}\r\n\r\n/**\r\n * Computes the heading, pitch and roll from a quaternion (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles )\r\n *\r\n * @param {Quaternion} quaternion The quaternion from which to retrieve heading, pitch, and roll, all expressed in radians.\r\n * @param {HeadingPitchRoll} [result] The object in which to store the result. If not provided, a new instance is created and returned.\r\n * @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if one was not provided.\r\n */\r\nHeadingPitchRoll.fromQuaternion = function (quaternion, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(quaternion)) {\r\n throw new DeveloperError(\"quaternion is required\");\r\n }\r\n //>>includeEnd('debug');\r\n if (!defined(result)) {\r\n result = new HeadingPitchRoll();\r\n }\r\n var test = 2 * (quaternion.w * quaternion.y - quaternion.z * quaternion.x);\r\n var denominatorRoll =\r\n 1 - 2 * (quaternion.x * quaternion.x + quaternion.y * quaternion.y);\r\n var numeratorRoll =\r\n 2 * (quaternion.w * quaternion.x + quaternion.y * quaternion.z);\r\n var denominatorHeading =\r\n 1 - 2 * (quaternion.y * quaternion.y + quaternion.z * quaternion.z);\r\n var numeratorHeading =\r\n 2 * (quaternion.w * quaternion.z + quaternion.x * quaternion.y);\r\n result.heading = -Math.atan2(numeratorHeading, denominatorHeading);\r\n result.roll = Math.atan2(numeratorRoll, denominatorRoll);\r\n result.pitch = -CesiumMath.asinClamped(test);\r\n return result;\r\n};\r\n\r\n/**\r\n * Returns a new HeadingPitchRoll instance from angles given in degrees.\r\n *\r\n * @param {Number} heading the heading in degrees\r\n * @param {Number} pitch the pitch in degrees\r\n * @param {Number} roll the heading in degrees\r\n * @param {HeadingPitchRoll} [result] The object in which to store the result. If not provided, a new instance is created and returned.\r\n * @returns {HeadingPitchRoll} A new HeadingPitchRoll instance\r\n */\r\nHeadingPitchRoll.fromDegrees = function (heading, pitch, roll, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(heading)) {\r\n throw new DeveloperError(\"heading is required\");\r\n }\r\n if (!defined(pitch)) {\r\n throw new DeveloperError(\"pitch is required\");\r\n }\r\n if (!defined(roll)) {\r\n throw new DeveloperError(\"roll is required\");\r\n }\r\n //>>includeEnd('debug');\r\n if (!defined(result)) {\r\n result = new HeadingPitchRoll();\r\n }\r\n result.heading = heading * CesiumMath.RADIANS_PER_DEGREE;\r\n result.pitch = pitch * CesiumMath.RADIANS_PER_DEGREE;\r\n result.roll = roll * CesiumMath.RADIANS_PER_DEGREE;\r\n return result;\r\n};\r\n\r\n/**\r\n * Duplicates a HeadingPitchRoll instance.\r\n *\r\n * @param {HeadingPitchRoll} headingPitchRoll The HeadingPitchRoll to duplicate.\r\n * @param {HeadingPitchRoll} [result] The object onto which to store the result.\r\n * @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if one was not provided. (Returns undefined if headingPitchRoll is undefined)\r\n */\r\nHeadingPitchRoll.clone = function (headingPitchRoll, result) {\r\n if (!defined(headingPitchRoll)) {\r\n return undefined;\r\n }\r\n if (!defined(result)) {\r\n return new HeadingPitchRoll(\r\n headingPitchRoll.heading,\r\n headingPitchRoll.pitch,\r\n headingPitchRoll.roll\r\n );\r\n }\r\n result.heading = headingPitchRoll.heading;\r\n result.pitch = headingPitchRoll.pitch;\r\n result.roll = headingPitchRoll.roll;\r\n return result;\r\n};\r\n\r\n/**\r\n * Compares the provided HeadingPitchRolls componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {HeadingPitchRoll} [left] The first HeadingPitchRoll.\r\n * @param {HeadingPitchRoll} [right] The second HeadingPitchRoll.\r\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\r\n */\r\nHeadingPitchRoll.equals = function (left, right) {\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n left.heading === right.heading &&\r\n left.pitch === right.pitch &&\r\n left.roll === right.roll)\r\n );\r\n};\r\n\r\n/**\r\n * Compares the provided HeadingPitchRolls componentwise and returns\r\n * true
if they pass an absolute or relative tolerance test,\r\n * false
otherwise.\r\n *\r\n * @param {HeadingPitchRoll} [left] The first HeadingPitchRoll.\r\n * @param {HeadingPitchRoll} [right] The second HeadingPitchRoll.\r\n * @param {Number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\r\n * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\r\n * @returns {Boolean} true
if left and right are within the provided epsilon, false
otherwise.\r\n */\r\nHeadingPitchRoll.equalsEpsilon = function (\r\n left,\r\n right,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n) {\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n CesiumMath.equalsEpsilon(\r\n left.heading,\r\n right.heading,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n ) &&\r\n CesiumMath.equalsEpsilon(\r\n left.pitch,\r\n right.pitch,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n ) &&\r\n CesiumMath.equalsEpsilon(\r\n left.roll,\r\n right.roll,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n ))\r\n );\r\n};\r\n\r\n/**\r\n * Duplicates this HeadingPitchRoll instance.\r\n *\r\n * @param {HeadingPitchRoll} [result] The object onto which to store the result.\r\n * @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if one was not provided.\r\n */\r\nHeadingPitchRoll.prototype.clone = function (result) {\r\n return HeadingPitchRoll.clone(this, result);\r\n};\r\n\r\n/**\r\n * Compares this HeadingPitchRoll against the provided HeadingPitchRoll componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {HeadingPitchRoll} [right] The right hand side HeadingPitchRoll.\r\n * @returns {Boolean} true
if they are equal, false
otherwise.\r\n */\r\nHeadingPitchRoll.prototype.equals = function (right) {\r\n return HeadingPitchRoll.equals(this, right);\r\n};\r\n\r\n/**\r\n * Compares this HeadingPitchRoll against the provided HeadingPitchRoll componentwise and returns\r\n * true
if they pass an absolute or relative tolerance test,\r\n * false
otherwise.\r\n *\r\n * @param {HeadingPitchRoll} [right] The right hand side HeadingPitchRoll.\r\n * @param {Number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\r\n * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\r\n * @returns {Boolean} true
if they are within the provided epsilon, false
otherwise.\r\n */\r\nHeadingPitchRoll.prototype.equalsEpsilon = function (\r\n right,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n) {\r\n return HeadingPitchRoll.equalsEpsilon(\r\n this,\r\n right,\r\n relativeEpsilon,\r\n absoluteEpsilon\r\n );\r\n};\r\n\r\n/**\r\n * Creates a string representing this HeadingPitchRoll in the format '(heading, pitch, roll)' in radians.\r\n *\r\n * @returns {String} A string representing the provided HeadingPitchRoll in the format '(heading, pitch, roll)'.\r\n */\r\nHeadingPitchRoll.prototype.toString = function () {\r\n return \"(\" + this.heading + \", \" + this.pitch + \", \" + this.roll + \")\";\r\n};\r\nexport default HeadingPitchRoll;\r\n","/**\r\n * An IAU 2006 XYS value sampled at a particular time.\r\n *\r\n * @alias Iau2006XysSample\r\n * @constructor\r\n *\r\n * @param {Number} x The X value.\r\n * @param {Number} y The Y value.\r\n * @param {Number} s The S value.\r\n *\r\n * @private\r\n */\r\nfunction Iau2006XysSample(x, y, s) {\r\n /**\r\n * The X value.\r\n * @type {Number}\r\n */\r\n this.x = x;\r\n\r\n /**\r\n * The Y value.\r\n * @type {Number}\r\n */\r\n this.y = y;\r\n\r\n /**\r\n * The S value.\r\n * @type {Number}\r\n */\r\n this.s = s;\r\n}\r\nexport default Iau2006XysSample;\r\n","import when from \"../ThirdParty/when.js\";\r\nimport buildModuleUrl from \"./buildModuleUrl.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport Iau2006XysSample from \"./Iau2006XysSample.js\";\r\nimport JulianDate from \"./JulianDate.js\";\r\nimport Resource from \"./Resource.js\";\r\nimport TimeStandard from \"./TimeStandard.js\";\r\n\r\n/**\r\n * A set of IAU2006 XYS data that is used to evaluate the transformation between the International\r\n * Celestial Reference Frame (ICRF) and the International Terrestrial Reference Frame (ITRF).\r\n *\r\n * @alias Iau2006XysData\r\n * @constructor\r\n *\r\n * @param {Object} [options] Object with the following properties:\r\n * @param {Resource|String} [options.xysFileUrlTemplate='Assets/IAU2006_XYS/IAU2006_XYS_{0}.json'] A template URL for obtaining the XYS data. In the template,\r\n * `{0}` will be replaced with the file index.\r\n * @param {Number} [options.interpolationOrder=9] The order of interpolation to perform on the XYS data.\r\n * @param {Number} [options.sampleZeroJulianEphemerisDate=2442396.5] The Julian ephemeris date (JED) of the\r\n * first XYS sample.\r\n * @param {Number} [options.stepSizeDays=1.0] The step size, in days, between successive XYS samples.\r\n * @param {Number} [options.samplesPerXysFile=1000] The number of samples in each XYS file.\r\n * @param {Number} [options.totalSamples=27426] The total number of samples in all XYS files.\r\n *\r\n * @private\r\n */\r\nfunction Iau2006XysData(options) {\r\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\r\n\r\n this._xysFileUrlTemplate = Resource.createIfNeeded(\r\n options.xysFileUrlTemplate\r\n );\r\n this._interpolationOrder = defaultValue(options.interpolationOrder, 9);\r\n this._sampleZeroJulianEphemerisDate = defaultValue(\r\n options.sampleZeroJulianEphemerisDate,\r\n 2442396.5\r\n );\r\n this._sampleZeroDateTT = new JulianDate(\r\n this._sampleZeroJulianEphemerisDate,\r\n 0.0,\r\n TimeStandard.TAI\r\n );\r\n this._stepSizeDays = defaultValue(options.stepSizeDays, 1.0);\r\n this._samplesPerXysFile = defaultValue(options.samplesPerXysFile, 1000);\r\n this._totalSamples = defaultValue(options.totalSamples, 27426);\r\n this._samples = new Array(this._totalSamples * 3);\r\n this._chunkDownloadsInProgress = [];\r\n\r\n var order = this._interpolationOrder;\r\n\r\n // Compute denominators and X values for interpolation.\r\n var denom = (this._denominators = new Array(order + 1));\r\n var xTable = (this._xTable = new Array(order + 1));\r\n\r\n var stepN = Math.pow(this._stepSizeDays, order);\r\n\r\n for (var i = 0; i <= order; ++i) {\r\n denom[i] = stepN;\r\n xTable[i] = i * this._stepSizeDays;\r\n\r\n for (var j = 0; j <= order; ++j) {\r\n if (j !== i) {\r\n denom[i] *= i - j;\r\n }\r\n }\r\n\r\n denom[i] = 1.0 / denom[i];\r\n }\r\n\r\n // Allocate scratch arrays for interpolation.\r\n this._work = new Array(order + 1);\r\n this._coef = new Array(order + 1);\r\n}\r\n\r\nvar julianDateScratch = new JulianDate(0, 0.0, TimeStandard.TAI);\r\n\r\nfunction getDaysSinceEpoch(xys, dayTT, secondTT) {\r\n var dateTT = julianDateScratch;\r\n dateTT.dayNumber = dayTT;\r\n dateTT.secondsOfDay = secondTT;\r\n return JulianDate.daysDifference(dateTT, xys._sampleZeroDateTT);\r\n}\r\n\r\n/**\r\n * Preloads XYS data for a specified date range.\r\n *\r\n * @param {Number} startDayTT The Julian day number of the beginning of the interval to preload, expressed in\r\n * the Terrestrial Time (TT) time standard.\r\n * @param {Number} startSecondTT The seconds past noon of the beginning of the interval to preload, expressed in\r\n * the Terrestrial Time (TT) time standard.\r\n * @param {Number} stopDayTT The Julian day number of the end of the interval to preload, expressed in\r\n * the Terrestrial Time (TT) time standard.\r\n * @param {Number} stopSecondTT The seconds past noon of the end of the interval to preload, expressed in\r\n * the Terrestrial Time (TT) time standard.\r\n * @returns {Promise} A promise that, when resolved, indicates that the requested interval has been\r\n * preloaded.\r\n */\r\nIau2006XysData.prototype.preload = function (\r\n startDayTT,\r\n startSecondTT,\r\n stopDayTT,\r\n stopSecondTT\r\n) {\r\n var startDaysSinceEpoch = getDaysSinceEpoch(this, startDayTT, startSecondTT);\r\n var stopDaysSinceEpoch = getDaysSinceEpoch(this, stopDayTT, stopSecondTT);\r\n\r\n var startIndex =\r\n (startDaysSinceEpoch / this._stepSizeDays - this._interpolationOrder / 2) |\r\n 0;\r\n if (startIndex < 0) {\r\n startIndex = 0;\r\n }\r\n\r\n var stopIndex =\r\n (stopDaysSinceEpoch / this._stepSizeDays - this._interpolationOrder / 2) |\r\n (0 + this._interpolationOrder);\r\n if (stopIndex >= this._totalSamples) {\r\n stopIndex = this._totalSamples - 1;\r\n }\r\n\r\n var startChunk = (startIndex / this._samplesPerXysFile) | 0;\r\n var stopChunk = (stopIndex / this._samplesPerXysFile) | 0;\r\n\r\n var promises = [];\r\n for (var i = startChunk; i <= stopChunk; ++i) {\r\n promises.push(requestXysChunk(this, i));\r\n }\r\n\r\n return when.all(promises);\r\n};\r\n\r\n/**\r\n * Computes the XYS values for a given date by interpolating. If the required data is not yet downloaded,\r\n * this method will return undefined.\r\n *\r\n * @param {Number} dayTT The Julian day number for which to compute the XYS value, expressed in\r\n * the Terrestrial Time (TT) time standard.\r\n * @param {Number} secondTT The seconds past noon of the date for which to compute the XYS value, expressed in\r\n * the Terrestrial Time (TT) time standard.\r\n * @param {Iau2006XysSample} [result] The instance to which to copy the interpolated result. If this parameter\r\n * is undefined, a new instance is allocated and returned.\r\n * @returns {Iau2006XysSample} The interpolated XYS values, or undefined if the required data for this\r\n * computation has not yet been downloaded.\r\n *\r\n * @see Iau2006XysData#preload\r\n */\r\nIau2006XysData.prototype.computeXysRadians = function (\r\n dayTT,\r\n secondTT,\r\n result\r\n) {\r\n var daysSinceEpoch = getDaysSinceEpoch(this, dayTT, secondTT);\r\n if (daysSinceEpoch < 0.0) {\r\n // Can't evaluate prior to the epoch of the data.\r\n return undefined;\r\n }\r\n\r\n var centerIndex = (daysSinceEpoch / this._stepSizeDays) | 0;\r\n if (centerIndex >= this._totalSamples) {\r\n // Can't evaluate after the last sample in the data.\r\n return undefined;\r\n }\r\n\r\n var degree = this._interpolationOrder;\r\n\r\n var firstIndex = centerIndex - ((degree / 2) | 0);\r\n if (firstIndex < 0) {\r\n firstIndex = 0;\r\n }\r\n var lastIndex = firstIndex + degree;\r\n if (lastIndex >= this._totalSamples) {\r\n lastIndex = this._totalSamples - 1;\r\n firstIndex = lastIndex - degree;\r\n if (firstIndex < 0) {\r\n firstIndex = 0;\r\n }\r\n }\r\n\r\n // Are all the samples we need present?\r\n // We can assume so if the first and last are present\r\n var isDataMissing = false;\r\n var samples = this._samples;\r\n if (!defined(samples[firstIndex * 3])) {\r\n requestXysChunk(this, (firstIndex / this._samplesPerXysFile) | 0);\r\n isDataMissing = true;\r\n }\r\n\r\n if (!defined(samples[lastIndex * 3])) {\r\n requestXysChunk(this, (lastIndex / this._samplesPerXysFile) | 0);\r\n isDataMissing = true;\r\n }\r\n\r\n if (isDataMissing) {\r\n return undefined;\r\n }\r\n\r\n if (!defined(result)) {\r\n result = new Iau2006XysSample(0.0, 0.0, 0.0);\r\n } else {\r\n result.x = 0.0;\r\n result.y = 0.0;\r\n result.s = 0.0;\r\n }\r\n\r\n var x = daysSinceEpoch - firstIndex * this._stepSizeDays;\r\n\r\n var work = this._work;\r\n var denom = this._denominators;\r\n var coef = this._coef;\r\n var xTable = this._xTable;\r\n\r\n var i, j;\r\n for (i = 0; i <= degree; ++i) {\r\n work[i] = x - xTable[i];\r\n }\r\n\r\n for (i = 0; i <= degree; ++i) {\r\n coef[i] = 1.0;\r\n\r\n for (j = 0; j <= degree; ++j) {\r\n if (j !== i) {\r\n coef[i] *= work[j];\r\n }\r\n }\r\n\r\n coef[i] *= denom[i];\r\n\r\n var sampleIndex = (firstIndex + i) * 3;\r\n result.x += coef[i] * samples[sampleIndex++];\r\n result.y += coef[i] * samples[sampleIndex++];\r\n result.s += coef[i] * samples[sampleIndex];\r\n }\r\n\r\n return result;\r\n};\r\n\r\nfunction requestXysChunk(xysData, chunkIndex) {\r\n if (xysData._chunkDownloadsInProgress[chunkIndex]) {\r\n // Chunk has already been requested.\r\n return xysData._chunkDownloadsInProgress[chunkIndex];\r\n }\r\n\r\n var deferred = when.defer();\r\n\r\n xysData._chunkDownloadsInProgress[chunkIndex] = deferred;\r\n\r\n var chunkUrl;\r\n var xysFileUrlTemplate = xysData._xysFileUrlTemplate;\r\n if (defined(xysFileUrlTemplate)) {\r\n chunkUrl = xysFileUrlTemplate.getDerivedResource({\r\n templateValues: {\r\n 0: chunkIndex,\r\n },\r\n });\r\n } else {\r\n chunkUrl = new Resource({\r\n url: buildModuleUrl(\r\n \"Assets/IAU2006_XYS/IAU2006_XYS_\" + chunkIndex + \".json\"\r\n ),\r\n });\r\n }\r\n\r\n when(chunkUrl.fetchJson(), function (chunk) {\r\n xysData._chunkDownloadsInProgress[chunkIndex] = false;\r\n\r\n var samples = xysData._samples;\r\n var newSamples = chunk.samples;\r\n var startIndex = chunkIndex * xysData._samplesPerXysFile * 3;\r\n\r\n for (var i = 0, len = newSamples.length; i < len; ++i) {\r\n samples[startIndex + i] = newSamples[i];\r\n }\r\n\r\n deferred.resolve();\r\n });\r\n\r\n return deferred.promise;\r\n}\r\nexport default Iau2006XysData;\r\n","import defined from \"./defined.js\";\r\n\r\nvar _supportsFullscreen;\r\nvar _names = {\r\n requestFullscreen: undefined,\r\n exitFullscreen: undefined,\r\n fullscreenEnabled: undefined,\r\n fullscreenElement: undefined,\r\n fullscreenchange: undefined,\r\n fullscreenerror: undefined,\r\n};\r\n\r\n/**\r\n * Browser-independent functions for working with the standard fullscreen API.\r\n *\r\n * @namespace Fullscreen\r\n *\r\n * @see {@link http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html|W3C Fullscreen Living Specification}\r\n */\r\nvar Fullscreen = {};\r\n\r\nObject.defineProperties(Fullscreen, {\r\n /**\r\n * The element that is currently fullscreen, if any. To simply check if the\r\n * browser is in fullscreen mode or not, use {@link Fullscreen#fullscreen}.\r\n * @memberof Fullscreen\r\n * @type {Object}\r\n * @readonly\r\n */\r\n element: {\r\n get: function () {\r\n if (!Fullscreen.supportsFullscreen()) {\r\n return undefined;\r\n }\r\n\r\n return document[_names.fullscreenElement];\r\n },\r\n },\r\n\r\n /**\r\n * The name of the event on the document that is fired when fullscreen is\r\n * entered or exited. This event name is intended for use with addEventListener.\r\n * In your event handler, to determine if the browser is in fullscreen mode or not,\r\n * use {@link Fullscreen#fullscreen}.\r\n * @memberof Fullscreen\r\n * @type {String}\r\n * @readonly\r\n */\r\n changeEventName: {\r\n get: function () {\r\n if (!Fullscreen.supportsFullscreen()) {\r\n return undefined;\r\n }\r\n\r\n return _names.fullscreenchange;\r\n },\r\n },\r\n\r\n /**\r\n * The name of the event that is fired when a fullscreen error\r\n * occurs. This event name is intended for use with addEventListener.\r\n * @memberof Fullscreen\r\n * @type {String}\r\n * @readonly\r\n */\r\n errorEventName: {\r\n get: function () {\r\n if (!Fullscreen.supportsFullscreen()) {\r\n return undefined;\r\n }\r\n\r\n return _names.fullscreenerror;\r\n },\r\n },\r\n\r\n /**\r\n * Determine whether the browser will allow an element to be made fullscreen, or not.\r\n * For example, by default, iframes cannot go fullscreen unless the containing page\r\n * adds an \"allowfullscreen\" attribute (or prefixed equivalent).\r\n * @memberof Fullscreen\r\n * @type {Boolean}\r\n * @readonly\r\n */\r\n enabled: {\r\n get: function () {\r\n if (!Fullscreen.supportsFullscreen()) {\r\n return undefined;\r\n }\r\n\r\n return document[_names.fullscreenEnabled];\r\n },\r\n },\r\n\r\n /**\r\n * Determines if the browser is currently in fullscreen mode.\r\n * @memberof Fullscreen\r\n * @type {Boolean}\r\n * @readonly\r\n */\r\n fullscreen: {\r\n get: function () {\r\n if (!Fullscreen.supportsFullscreen()) {\r\n return undefined;\r\n }\r\n\r\n return Fullscreen.element !== null;\r\n },\r\n },\r\n});\r\n\r\n/**\r\n * Detects whether the browser supports the standard fullscreen API.\r\n *\r\n * @returns {Boolean} true
if the browser supports the standard fullscreen API,\r\n * false
otherwise.\r\n */\r\nFullscreen.supportsFullscreen = function () {\r\n if (defined(_supportsFullscreen)) {\r\n return _supportsFullscreen;\r\n }\r\n\r\n _supportsFullscreen = false;\r\n\r\n var body = document.body;\r\n if (typeof body.requestFullscreen === \"function\") {\r\n // go with the unprefixed, standard set of names\r\n _names.requestFullscreen = \"requestFullscreen\";\r\n _names.exitFullscreen = \"exitFullscreen\";\r\n _names.fullscreenEnabled = \"fullscreenEnabled\";\r\n _names.fullscreenElement = \"fullscreenElement\";\r\n _names.fullscreenchange = \"fullscreenchange\";\r\n _names.fullscreenerror = \"fullscreenerror\";\r\n _supportsFullscreen = true;\r\n return _supportsFullscreen;\r\n }\r\n\r\n //check for the correct combination of prefix plus the various names that browsers use\r\n var prefixes = [\"webkit\", \"moz\", \"o\", \"ms\", \"khtml\"];\r\n var name;\r\n for (var i = 0, len = prefixes.length; i < len; ++i) {\r\n var prefix = prefixes[i];\r\n\r\n // casing of Fullscreen differs across browsers\r\n name = prefix + \"RequestFullscreen\";\r\n if (typeof body[name] === \"function\") {\r\n _names.requestFullscreen = name;\r\n _supportsFullscreen = true;\r\n } else {\r\n name = prefix + \"RequestFullScreen\";\r\n if (typeof body[name] === \"function\") {\r\n _names.requestFullscreen = name;\r\n _supportsFullscreen = true;\r\n }\r\n }\r\n\r\n // disagreement about whether it's \"exit\" as per spec, or \"cancel\"\r\n name = prefix + \"ExitFullscreen\";\r\n if (typeof document[name] === \"function\") {\r\n _names.exitFullscreen = name;\r\n } else {\r\n name = prefix + \"CancelFullScreen\";\r\n if (typeof document[name] === \"function\") {\r\n _names.exitFullscreen = name;\r\n }\r\n }\r\n\r\n // casing of Fullscreen differs across browsers\r\n name = prefix + \"FullscreenEnabled\";\r\n if (document[name] !== undefined) {\r\n _names.fullscreenEnabled = name;\r\n } else {\r\n name = prefix + \"FullScreenEnabled\";\r\n if (document[name] !== undefined) {\r\n _names.fullscreenEnabled = name;\r\n }\r\n }\r\n\r\n // casing of Fullscreen differs across browsers\r\n name = prefix + \"FullscreenElement\";\r\n if (document[name] !== undefined) {\r\n _names.fullscreenElement = name;\r\n } else {\r\n name = prefix + \"FullScreenElement\";\r\n if (document[name] !== undefined) {\r\n _names.fullscreenElement = name;\r\n }\r\n }\r\n\r\n // thankfully, event names are all lowercase per spec\r\n name = prefix + \"fullscreenchange\";\r\n // event names do not have 'on' in the front, but the property on the document does\r\n if (document[\"on\" + name] !== undefined) {\r\n //except on IE\r\n if (prefix === \"ms\") {\r\n name = \"MSFullscreenChange\";\r\n }\r\n _names.fullscreenchange = name;\r\n }\r\n\r\n name = prefix + \"fullscreenerror\";\r\n if (document[\"on\" + name] !== undefined) {\r\n //except on IE\r\n if (prefix === \"ms\") {\r\n name = \"MSFullscreenError\";\r\n }\r\n _names.fullscreenerror = name;\r\n }\r\n }\r\n\r\n return _supportsFullscreen;\r\n};\r\n\r\n/**\r\n * Asynchronously requests the browser to enter fullscreen mode on the given element.\r\n * If fullscreen mode is not supported by the browser, does nothing.\r\n *\r\n * @param {Object} element The HTML element which will be placed into fullscreen mode.\r\n * @param {Object} [vrDevice] The HMDVRDevice device.\r\n *\r\n * @example\r\n * // Put the entire page into fullscreen.\r\n * Cesium.Fullscreen.requestFullscreen(document.body)\r\n *\r\n * // Place only the Cesium canvas into fullscreen.\r\n * Cesium.Fullscreen.requestFullscreen(scene.canvas)\r\n */\r\nFullscreen.requestFullscreen = function (element, vrDevice) {\r\n if (!Fullscreen.supportsFullscreen()) {\r\n return;\r\n }\r\n\r\n element[_names.requestFullscreen]({ vrDisplay: vrDevice });\r\n};\r\n\r\n/**\r\n * Asynchronously exits fullscreen mode. If the browser is not currently\r\n * in fullscreen, or if fullscreen mode is not supported by the browser, does nothing.\r\n */\r\nFullscreen.exitFullscreen = function () {\r\n if (!Fullscreen.supportsFullscreen()) {\r\n return;\r\n }\r\n\r\n document[_names.exitFullscreen]();\r\n};\r\n\r\n//For unit tests\r\nFullscreen._names = _names;\r\nexport default Fullscreen;\r\n","import when from \"../ThirdParty/when.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport Fullscreen from \"./Fullscreen.js\";\r\n\r\nvar theNavigator;\r\nif (typeof navigator !== \"undefined\") {\r\n theNavigator = navigator;\r\n} else {\r\n theNavigator = {};\r\n}\r\n\r\nfunction extractVersion(versionString) {\r\n var parts = versionString.split(\".\");\r\n for (var i = 0, len = parts.length; i < len; ++i) {\r\n parts[i] = parseInt(parts[i], 10);\r\n }\r\n return parts;\r\n}\r\n\r\nvar isChromeResult;\r\nvar chromeVersionResult;\r\nfunction isChrome() {\r\n if (!defined(isChromeResult)) {\r\n isChromeResult = false;\r\n // Edge contains Chrome in the user agent too\r\n if (!isEdge()) {\r\n var fields = / Chrome\\/([\\.0-9]+)/.exec(theNavigator.userAgent);\r\n if (fields !== null) {\r\n isChromeResult = true;\r\n chromeVersionResult = extractVersion(fields[1]);\r\n }\r\n }\r\n }\r\n\r\n return isChromeResult;\r\n}\r\n\r\nfunction chromeVersion() {\r\n return isChrome() && chromeVersionResult;\r\n}\r\n\r\nvar isSafariResult;\r\nvar safariVersionResult;\r\nfunction isSafari() {\r\n if (!defined(isSafariResult)) {\r\n isSafariResult = false;\r\n\r\n // Chrome and Edge contain Safari in the user agent too\r\n if (\r\n !isChrome() &&\r\n !isEdge() &&\r\n / Safari\\/[\\.0-9]+/.test(theNavigator.userAgent)\r\n ) {\r\n var fields = / Version\\/([\\.0-9]+)/.exec(theNavigator.userAgent);\r\n if (fields !== null) {\r\n isSafariResult = true;\r\n safariVersionResult = extractVersion(fields[1]);\r\n }\r\n }\r\n }\r\n\r\n return isSafariResult;\r\n}\r\n\r\nfunction safariVersion() {\r\n return isSafari() && safariVersionResult;\r\n}\r\n\r\nvar isWebkitResult;\r\nvar webkitVersionResult;\r\nfunction isWebkit() {\r\n if (!defined(isWebkitResult)) {\r\n isWebkitResult = false;\r\n\r\n var fields = / AppleWebKit\\/([\\.0-9]+)(\\+?)/.exec(theNavigator.userAgent);\r\n if (fields !== null) {\r\n isWebkitResult = true;\r\n webkitVersionResult = extractVersion(fields[1]);\r\n webkitVersionResult.isNightly = !!fields[2];\r\n }\r\n }\r\n\r\n return isWebkitResult;\r\n}\r\n\r\nfunction webkitVersion() {\r\n return isWebkit() && webkitVersionResult;\r\n}\r\n\r\nvar isInternetExplorerResult;\r\nvar internetExplorerVersionResult;\r\nfunction isInternetExplorer() {\r\n if (!defined(isInternetExplorerResult)) {\r\n isInternetExplorerResult = false;\r\n\r\n var fields;\r\n if (theNavigator.appName === \"Microsoft Internet Explorer\") {\r\n fields = /MSIE ([0-9]{1,}[\\.0-9]{0,})/.exec(theNavigator.userAgent);\r\n if (fields !== null) {\r\n isInternetExplorerResult = true;\r\n internetExplorerVersionResult = extractVersion(fields[1]);\r\n }\r\n } else if (theNavigator.appName === \"Netscape\") {\r\n fields = /Trident\\/.*rv:([0-9]{1,}[\\.0-9]{0,})/.exec(\r\n theNavigator.userAgent\r\n );\r\n if (fields !== null) {\r\n isInternetExplorerResult = true;\r\n internetExplorerVersionResult = extractVersion(fields[1]);\r\n }\r\n }\r\n }\r\n return isInternetExplorerResult;\r\n}\r\n\r\nfunction internetExplorerVersion() {\r\n return isInternetExplorer() && internetExplorerVersionResult;\r\n}\r\n\r\nvar isEdgeResult;\r\nvar edgeVersionResult;\r\nfunction isEdge() {\r\n if (!defined(isEdgeResult)) {\r\n isEdgeResult = false;\r\n var fields = / Edge\\/([\\.0-9]+)/.exec(theNavigator.userAgent);\r\n if (fields !== null) {\r\n isEdgeResult = true;\r\n edgeVersionResult = extractVersion(fields[1]);\r\n }\r\n }\r\n return isEdgeResult;\r\n}\r\n\r\nfunction edgeVersion() {\r\n return isEdge() && edgeVersionResult;\r\n}\r\n\r\nvar isFirefoxResult;\r\nvar firefoxVersionResult;\r\nfunction isFirefox() {\r\n if (!defined(isFirefoxResult)) {\r\n isFirefoxResult = false;\r\n\r\n var fields = /Firefox\\/([\\.0-9]+)/.exec(theNavigator.userAgent);\r\n if (fields !== null) {\r\n isFirefoxResult = true;\r\n firefoxVersionResult = extractVersion(fields[1]);\r\n }\r\n }\r\n return isFirefoxResult;\r\n}\r\n\r\nvar isWindowsResult;\r\nfunction isWindows() {\r\n if (!defined(isWindowsResult)) {\r\n isWindowsResult = /Windows/i.test(theNavigator.appVersion);\r\n }\r\n return isWindowsResult;\r\n}\r\n\r\nfunction firefoxVersion() {\r\n return isFirefox() && firefoxVersionResult;\r\n}\r\n\r\nvar hasPointerEvents;\r\nfunction supportsPointerEvents() {\r\n if (!defined(hasPointerEvents)) {\r\n //While navigator.pointerEnabled is deprecated in the W3C specification\r\n //we still need to use it if it exists in order to support browsers\r\n //that rely on it, such as the Windows WebBrowser control which defines\r\n //PointerEvent but sets navigator.pointerEnabled to false.\r\n\r\n //Firefox disabled because of https://github.com/CesiumGS/cesium/issues/6372\r\n hasPointerEvents =\r\n !isFirefox() &&\r\n typeof PointerEvent !== \"undefined\" &&\r\n (!defined(theNavigator.pointerEnabled) || theNavigator.pointerEnabled);\r\n }\r\n return hasPointerEvents;\r\n}\r\n\r\nvar imageRenderingValueResult;\r\nvar supportsImageRenderingPixelatedResult;\r\nfunction supportsImageRenderingPixelated() {\r\n if (!defined(supportsImageRenderingPixelatedResult)) {\r\n var canvas = document.createElement(\"canvas\");\r\n canvas.setAttribute(\r\n \"style\",\r\n \"image-rendering: -moz-crisp-edges;\" + \"image-rendering: pixelated;\"\r\n );\r\n //canvas.style.imageRendering will be undefined, null or an empty string on unsupported browsers.\r\n var tmp = canvas.style.imageRendering;\r\n supportsImageRenderingPixelatedResult = defined(tmp) && tmp !== \"\";\r\n if (supportsImageRenderingPixelatedResult) {\r\n imageRenderingValueResult = tmp;\r\n }\r\n }\r\n return supportsImageRenderingPixelatedResult;\r\n}\r\n\r\nfunction imageRenderingValue() {\r\n return supportsImageRenderingPixelated()\r\n ? imageRenderingValueResult\r\n : undefined;\r\n}\r\n\r\nfunction supportsWebP() {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!supportsWebP.initialized) {\r\n throw new DeveloperError(\r\n \"You must call FeatureDetection.supportsWebP.initialize and wait for the promise to resolve before calling FeatureDetection.supportsWebP\"\r\n );\r\n }\r\n //>>includeEnd('debug');\r\n return supportsWebP._result;\r\n}\r\nsupportsWebP._promise = undefined;\r\nsupportsWebP._result = undefined;\r\nsupportsWebP.initialize = function () {\r\n // From https://developers.google.com/speed/webp/faq#how_can_i_detect_browser_support_for_webp\r\n if (defined(supportsWebP._promise)) {\r\n return supportsWebP._promise;\r\n }\r\n\r\n var supportsWebPDeferred = when.defer();\r\n supportsWebP._promise = supportsWebPDeferred.promise;\r\n if (isEdge()) {\r\n // Edge's WebP support with WebGL is incomplete.\r\n // See bug report: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/19221241/\r\n supportsWebP._result = false;\r\n supportsWebPDeferred.resolve(supportsWebP._result);\r\n return supportsWebPDeferred.promise;\r\n }\r\n\r\n var image = new Image();\r\n image.onload = function () {\r\n supportsWebP._result = image.width > 0 && image.height > 0;\r\n supportsWebPDeferred.resolve(supportsWebP._result);\r\n };\r\n\r\n image.onerror = function () {\r\n supportsWebP._result = false;\r\n supportsWebPDeferred.resolve(supportsWebP._result);\r\n };\r\n\r\n image.src =\r\n \"data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA\";\r\n\r\n return supportsWebPDeferred.promise;\r\n};\r\nObject.defineProperties(supportsWebP, {\r\n initialized: {\r\n get: function () {\r\n return defined(supportsWebP._result);\r\n },\r\n },\r\n});\r\n\r\nvar typedArrayTypes = [];\r\nif (typeof ArrayBuffer !== \"undefined\") {\r\n typedArrayTypes.push(\r\n Int8Array,\r\n Uint8Array,\r\n Int16Array,\r\n Uint16Array,\r\n Int32Array,\r\n Uint32Array,\r\n Float32Array,\r\n Float64Array\r\n );\r\n\r\n if (typeof Uint8ClampedArray !== \"undefined\") {\r\n typedArrayTypes.push(Uint8ClampedArray);\r\n }\r\n\r\n if (typeof Uint8ClampedArray !== \"undefined\") {\r\n typedArrayTypes.push(Uint8ClampedArray);\r\n }\r\n}\r\n\r\n/**\r\n * A set of functions to detect whether the current browser supports\r\n * various features.\r\n *\r\n * @namespace FeatureDetection\r\n */\r\nvar FeatureDetection = {\r\n isChrome: isChrome,\r\n chromeVersion: chromeVersion,\r\n isSafari: isSafari,\r\n safariVersion: safariVersion,\r\n isWebkit: isWebkit,\r\n webkitVersion: webkitVersion,\r\n isInternetExplorer: isInternetExplorer,\r\n internetExplorerVersion: internetExplorerVersion,\r\n isEdge: isEdge,\r\n edgeVersion: edgeVersion,\r\n isFirefox: isFirefox,\r\n firefoxVersion: firefoxVersion,\r\n isWindows: isWindows,\r\n hardwareConcurrency: defaultValue(theNavigator.hardwareConcurrency, 3),\r\n supportsPointerEvents: supportsPointerEvents,\r\n supportsImageRenderingPixelated: supportsImageRenderingPixelated,\r\n supportsWebP: supportsWebP,\r\n imageRenderingValue: imageRenderingValue,\r\n typedArrayTypes: typedArrayTypes,\r\n};\r\n\r\n/**\r\n * Detects whether the current browser supports the full screen standard.\r\n *\r\n * @returns {Boolean} true if the browser supports the full screen standard, false if not.\r\n *\r\n * @see Fullscreen\r\n * @see {@link http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html|W3C Fullscreen Living Specification}\r\n */\r\nFeatureDetection.supportsFullscreen = function () {\r\n return Fullscreen.supportsFullscreen();\r\n};\r\n\r\n/**\r\n * Detects whether the current browser supports typed arrays.\r\n *\r\n * @returns {Boolean} true if the browser supports typed arrays, false if not.\r\n *\r\n * @see {@link http://www.khronos.org/registry/typedarray/specs/latest/|Typed Array Specification}\r\n */\r\nFeatureDetection.supportsTypedArrays = function () {\r\n return typeof ArrayBuffer !== \"undefined\";\r\n};\r\n\r\n/**\r\n * Detects whether the current browser supports Web Workers.\r\n *\r\n * @returns {Boolean} true if the browsers supports Web Workers, false if not.\r\n *\r\n * @see {@link http://www.w3.org/TR/workers/}\r\n */\r\nFeatureDetection.supportsWebWorkers = function () {\r\n return typeof Worker !== \"undefined\";\r\n};\r\n\r\n/**\r\n * Detects whether the current browser supports Web Assembly.\r\n *\r\n * @returns {Boolean} true if the browsers supports Web Assembly, false if not.\r\n *\r\n * @see {@link https://developer.mozilla.org/en-US/docs/WebAssembly}\r\n */\r\nFeatureDetection.supportsWebAssembly = function () {\r\n return typeof WebAssembly !== \"undefined\" && !FeatureDetection.isEdge();\r\n};\r\nexport default FeatureDetection;\r\n","import Cartesian3 from \"./Cartesian3.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport FeatureDetection from \"./FeatureDetection.js\";\r\nimport CesiumMath from \"./Math.js\";\r\nimport Matrix3 from \"./Matrix3.js\";\r\n\r\n/**\r\n * A set of 4-dimensional coordinates used to represent rotation in 3-dimensional space.\r\n * @alias Quaternion\r\n * @constructor\r\n *\r\n * @param {Number} [x=0.0] The X component.\r\n * @param {Number} [y=0.0] The Y component.\r\n * @param {Number} [z=0.0] The Z component.\r\n * @param {Number} [w=0.0] The W component.\r\n *\r\n * @see PackableForInterpolation\r\n */\r\nfunction Quaternion(x, y, z, w) {\r\n /**\r\n * The X component.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.x = defaultValue(x, 0.0);\r\n\r\n /**\r\n * The Y component.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.y = defaultValue(y, 0.0);\r\n\r\n /**\r\n * The Z component.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.z = defaultValue(z, 0.0);\r\n\r\n /**\r\n * The W component.\r\n * @type {Number}\r\n * @default 0.0\r\n */\r\n this.w = defaultValue(w, 0.0);\r\n}\r\n\r\nvar fromAxisAngleScratch = new Cartesian3();\r\n\r\n/**\r\n * Computes a quaternion representing a rotation around an axis.\r\n *\r\n * @param {Cartesian3} axis The axis of rotation.\r\n * @param {Number} angle The angle in radians to rotate around the axis.\r\n * @param {Quaternion} [result] The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.\r\n */\r\nQuaternion.fromAxisAngle = function (axis, angle, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"axis\", axis);\r\n Check.typeOf.number(\"angle\", angle);\r\n //>>includeEnd('debug');\r\n\r\n var halfAngle = angle / 2.0;\r\n var s = Math.sin(halfAngle);\r\n fromAxisAngleScratch = Cartesian3.normalize(axis, fromAxisAngleScratch);\r\n\r\n var x = fromAxisAngleScratch.x * s;\r\n var y = fromAxisAngleScratch.y * s;\r\n var z = fromAxisAngleScratch.z * s;\r\n var w = Math.cos(halfAngle);\r\n if (!defined(result)) {\r\n return new Quaternion(x, y, z, w);\r\n }\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n result.w = w;\r\n return result;\r\n};\r\n\r\nvar fromRotationMatrixNext = [1, 2, 0];\r\nvar fromRotationMatrixQuat = new Array(3);\r\n/**\r\n * Computes a Quaternion from the provided Matrix3 instance.\r\n *\r\n * @param {Matrix3} matrix The rotation matrix.\r\n * @param {Quaternion} [result] The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.\r\n *\r\n * @see Matrix3.fromQuaternion\r\n */\r\nQuaternion.fromRotationMatrix = function (matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"matrix\", matrix);\r\n //>>includeEnd('debug');\r\n\r\n var root;\r\n var x;\r\n var y;\r\n var z;\r\n var w;\r\n\r\n var m00 = matrix[Matrix3.COLUMN0ROW0];\r\n var m11 = matrix[Matrix3.COLUMN1ROW1];\r\n var m22 = matrix[Matrix3.COLUMN2ROW2];\r\n var trace = m00 + m11 + m22;\r\n\r\n if (trace > 0.0) {\r\n // |w| > 1/2, may as well choose w > 1/2\r\n root = Math.sqrt(trace + 1.0); // 2w\r\n w = 0.5 * root;\r\n root = 0.5 / root; // 1/(4w)\r\n\r\n x = (matrix[Matrix3.COLUMN1ROW2] - matrix[Matrix3.COLUMN2ROW1]) * root;\r\n y = (matrix[Matrix3.COLUMN2ROW0] - matrix[Matrix3.COLUMN0ROW2]) * root;\r\n z = (matrix[Matrix3.COLUMN0ROW1] - matrix[Matrix3.COLUMN1ROW0]) * root;\r\n } else {\r\n // |w| <= 1/2\r\n var next = fromRotationMatrixNext;\r\n\r\n var i = 0;\r\n if (m11 > m00) {\r\n i = 1;\r\n }\r\n if (m22 > m00 && m22 > m11) {\r\n i = 2;\r\n }\r\n var j = next[i];\r\n var k = next[j];\r\n\r\n root = Math.sqrt(\r\n matrix[Matrix3.getElementIndex(i, i)] -\r\n matrix[Matrix3.getElementIndex(j, j)] -\r\n matrix[Matrix3.getElementIndex(k, k)] +\r\n 1.0\r\n );\r\n\r\n var quat = fromRotationMatrixQuat;\r\n quat[i] = 0.5 * root;\r\n root = 0.5 / root;\r\n w =\r\n (matrix[Matrix3.getElementIndex(k, j)] -\r\n matrix[Matrix3.getElementIndex(j, k)]) *\r\n root;\r\n quat[j] =\r\n (matrix[Matrix3.getElementIndex(j, i)] +\r\n matrix[Matrix3.getElementIndex(i, j)]) *\r\n root;\r\n quat[k] =\r\n (matrix[Matrix3.getElementIndex(k, i)] +\r\n matrix[Matrix3.getElementIndex(i, k)]) *\r\n root;\r\n\r\n x = -quat[0];\r\n y = -quat[1];\r\n z = -quat[2];\r\n }\r\n\r\n if (!defined(result)) {\r\n return new Quaternion(x, y, z, w);\r\n }\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n result.w = w;\r\n return result;\r\n};\r\n\r\nvar scratchHPRQuaternion = new Quaternion();\r\nvar scratchHeadingQuaternion = new Quaternion();\r\nvar scratchPitchQuaternion = new Quaternion();\r\nvar scratchRollQuaternion = new Quaternion();\r\n\r\n/**\r\n * Computes a rotation from the given heading, pitch and roll angles. Heading is the rotation about the\r\n * negative z axis. Pitch is the rotation about the negative y axis. Roll is the rotation about\r\n * the positive x axis.\r\n *\r\n * @param {HeadingPitchRoll} headingPitchRoll The rotation expressed as a heading, pitch and roll.\r\n * @param {Quaternion} [result] The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if none was provided.\r\n */\r\nQuaternion.fromHeadingPitchRoll = function (headingPitchRoll, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"headingPitchRoll\", headingPitchRoll);\r\n //>>includeEnd('debug');\r\n\r\n scratchRollQuaternion = Quaternion.fromAxisAngle(\r\n Cartesian3.UNIT_X,\r\n headingPitchRoll.roll,\r\n scratchHPRQuaternion\r\n );\r\n scratchPitchQuaternion = Quaternion.fromAxisAngle(\r\n Cartesian3.UNIT_Y,\r\n -headingPitchRoll.pitch,\r\n result\r\n );\r\n result = Quaternion.multiply(\r\n scratchPitchQuaternion,\r\n scratchRollQuaternion,\r\n scratchPitchQuaternion\r\n );\r\n scratchHeadingQuaternion = Quaternion.fromAxisAngle(\r\n Cartesian3.UNIT_Z,\r\n -headingPitchRoll.heading,\r\n scratchHPRQuaternion\r\n );\r\n return Quaternion.multiply(scratchHeadingQuaternion, result, result);\r\n};\r\n\r\nvar sampledQuaternionAxis = new Cartesian3();\r\nvar sampledQuaternionRotation = new Cartesian3();\r\nvar sampledQuaternionTempQuaternion = new Quaternion();\r\nvar sampledQuaternionQuaternion0 = new Quaternion();\r\nvar sampledQuaternionQuaternion0Conjugate = new Quaternion();\r\n\r\n/**\r\n * The number of elements used to pack the object into an array.\r\n * @type {Number}\r\n */\r\nQuaternion.packedLength = 4;\r\n\r\n/**\r\n * Stores the provided instance into the provided array.\r\n *\r\n * @param {Quaternion} value The value to pack.\r\n * @param {Number[]} array The array to pack into.\r\n * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.\r\n *\r\n * @returns {Number[]} The array that was packed into\r\n */\r\nQuaternion.pack = function (value, array, startingIndex) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"value\", value);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n array[startingIndex++] = value.x;\r\n array[startingIndex++] = value.y;\r\n array[startingIndex++] = value.z;\r\n array[startingIndex] = value.w;\r\n\r\n return array;\r\n};\r\n\r\n/**\r\n * Retrieves an instance from a packed array.\r\n *\r\n * @param {Number[]} array The packed array.\r\n * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.\r\n * @param {Quaternion} [result] The object into which to store the result.\r\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.\r\n */\r\nQuaternion.unpack = function (array, startingIndex, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n if (!defined(result)) {\r\n result = new Quaternion();\r\n }\r\n result.x = array[startingIndex];\r\n result.y = array[startingIndex + 1];\r\n result.z = array[startingIndex + 2];\r\n result.w = array[startingIndex + 3];\r\n return result;\r\n};\r\n\r\n/**\r\n * The number of elements used to store the object into an array in its interpolatable form.\r\n * @type {Number}\r\n */\r\nQuaternion.packedInterpolationLength = 3;\r\n\r\n/**\r\n * Converts a packed array into a form suitable for interpolation.\r\n *\r\n * @param {Number[]} packedArray The packed array.\r\n * @param {Number} [startingIndex=0] The index of the first element to be converted.\r\n * @param {Number} [lastIndex=packedArray.length] The index of the last element to be converted.\r\n * @param {Number[]} [result] The object into which to store the result.\r\n */\r\nQuaternion.convertPackedArrayForInterpolation = function (\r\n packedArray,\r\n startingIndex,\r\n lastIndex,\r\n result\r\n) {\r\n Quaternion.unpack(\r\n packedArray,\r\n lastIndex * 4,\r\n sampledQuaternionQuaternion0Conjugate\r\n );\r\n Quaternion.conjugate(\r\n sampledQuaternionQuaternion0Conjugate,\r\n sampledQuaternionQuaternion0Conjugate\r\n );\r\n\r\n for (var i = 0, len = lastIndex - startingIndex + 1; i < len; i++) {\r\n var offset = i * 3;\r\n Quaternion.unpack(\r\n packedArray,\r\n (startingIndex + i) * 4,\r\n sampledQuaternionTempQuaternion\r\n );\r\n\r\n Quaternion.multiply(\r\n sampledQuaternionTempQuaternion,\r\n sampledQuaternionQuaternion0Conjugate,\r\n sampledQuaternionTempQuaternion\r\n );\r\n\r\n if (sampledQuaternionTempQuaternion.w < 0) {\r\n Quaternion.negate(\r\n sampledQuaternionTempQuaternion,\r\n sampledQuaternionTempQuaternion\r\n );\r\n }\r\n\r\n Quaternion.computeAxis(\r\n sampledQuaternionTempQuaternion,\r\n sampledQuaternionAxis\r\n );\r\n var angle = Quaternion.computeAngle(sampledQuaternionTempQuaternion);\r\n if (!defined(result)) {\r\n result = [];\r\n }\r\n result[offset] = sampledQuaternionAxis.x * angle;\r\n result[offset + 1] = sampledQuaternionAxis.y * angle;\r\n result[offset + 2] = sampledQuaternionAxis.z * angle;\r\n }\r\n};\r\n\r\n/**\r\n * Retrieves an instance from a packed array converted with {@link convertPackedArrayForInterpolation}.\r\n *\r\n * @param {Number[]} array The array previously packed for interpolation.\r\n * @param {Number[]} sourceArray The original packed array.\r\n * @param {Number} [firstIndex=0] The firstIndex used to convert the array.\r\n * @param {Number} [lastIndex=packedArray.length] The lastIndex used to convert the array.\r\n * @param {Quaternion} [result] The object into which to store the result.\r\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.\r\n */\r\nQuaternion.unpackInterpolationResult = function (\r\n array,\r\n sourceArray,\r\n firstIndex,\r\n lastIndex,\r\n result\r\n) {\r\n if (!defined(result)) {\r\n result = new Quaternion();\r\n }\r\n Cartesian3.fromArray(array, 0, sampledQuaternionRotation);\r\n var magnitude = Cartesian3.magnitude(sampledQuaternionRotation);\r\n\r\n Quaternion.unpack(sourceArray, lastIndex * 4, sampledQuaternionQuaternion0);\r\n\r\n if (magnitude === 0) {\r\n Quaternion.clone(Quaternion.IDENTITY, sampledQuaternionTempQuaternion);\r\n } else {\r\n Quaternion.fromAxisAngle(\r\n sampledQuaternionRotation,\r\n magnitude,\r\n sampledQuaternionTempQuaternion\r\n );\r\n }\r\n\r\n return Quaternion.multiply(\r\n sampledQuaternionTempQuaternion,\r\n sampledQuaternionQuaternion0,\r\n result\r\n );\r\n};\r\n\r\n/**\r\n * Duplicates a Quaternion instance.\r\n *\r\n * @param {Quaternion} quaternion The quaternion to duplicate.\r\n * @param {Quaternion} [result] The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided. (Returns undefined if quaternion is undefined)\r\n */\r\nQuaternion.clone = function (quaternion, result) {\r\n if (!defined(quaternion)) {\r\n return undefined;\r\n }\r\n\r\n if (!defined(result)) {\r\n return new Quaternion(\r\n quaternion.x,\r\n quaternion.y,\r\n quaternion.z,\r\n quaternion.w\r\n );\r\n }\r\n\r\n result.x = quaternion.x;\r\n result.y = quaternion.y;\r\n result.z = quaternion.z;\r\n result.w = quaternion.w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the conjugate of the provided quaternion.\r\n *\r\n * @param {Quaternion} quaternion The quaternion to conjugate.\r\n * @param {Quaternion} result The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter.\r\n */\r\nQuaternion.conjugate = function (quaternion, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"quaternion\", quaternion);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = -quaternion.x;\r\n result.y = -quaternion.y;\r\n result.z = -quaternion.z;\r\n result.w = quaternion.w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes magnitude squared for the provided quaternion.\r\n *\r\n * @param {Quaternion} quaternion The quaternion to conjugate.\r\n * @returns {Number} The magnitude squared.\r\n */\r\nQuaternion.magnitudeSquared = function (quaternion) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"quaternion\", quaternion);\r\n //>>includeEnd('debug');\r\n\r\n return (\r\n quaternion.x * quaternion.x +\r\n quaternion.y * quaternion.y +\r\n quaternion.z * quaternion.z +\r\n quaternion.w * quaternion.w\r\n );\r\n};\r\n\r\n/**\r\n * Computes magnitude for the provided quaternion.\r\n *\r\n * @param {Quaternion} quaternion The quaternion to conjugate.\r\n * @returns {Number} The magnitude.\r\n */\r\nQuaternion.magnitude = function (quaternion) {\r\n return Math.sqrt(Quaternion.magnitudeSquared(quaternion));\r\n};\r\n\r\n/**\r\n * Computes the normalized form of the provided quaternion.\r\n *\r\n * @param {Quaternion} quaternion The quaternion to normalize.\r\n * @param {Quaternion} result The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter.\r\n */\r\nQuaternion.normalize = function (quaternion, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var inverseMagnitude = 1.0 / Quaternion.magnitude(quaternion);\r\n var x = quaternion.x * inverseMagnitude;\r\n var y = quaternion.y * inverseMagnitude;\r\n var z = quaternion.z * inverseMagnitude;\r\n var w = quaternion.w * inverseMagnitude;\r\n\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n result.w = w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the inverse of the provided quaternion.\r\n *\r\n * @param {Quaternion} quaternion The quaternion to normalize.\r\n * @param {Quaternion} result The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter.\r\n */\r\nQuaternion.inverse = function (quaternion, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var magnitudeSquared = Quaternion.magnitudeSquared(quaternion);\r\n result = Quaternion.conjugate(quaternion, result);\r\n return Quaternion.multiplyByScalar(result, 1.0 / magnitudeSquared, result);\r\n};\r\n\r\n/**\r\n * Computes the componentwise sum of two quaternions.\r\n *\r\n * @param {Quaternion} left The first quaternion.\r\n * @param {Quaternion} right The second quaternion.\r\n * @param {Quaternion} result The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter.\r\n */\r\nQuaternion.add = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = left.x + right.x;\r\n result.y = left.y + right.y;\r\n result.z = left.z + right.z;\r\n result.w = left.w + right.w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the componentwise difference of two quaternions.\r\n *\r\n * @param {Quaternion} left The first quaternion.\r\n * @param {Quaternion} right The second quaternion.\r\n * @param {Quaternion} result The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter.\r\n */\r\nQuaternion.subtract = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = left.x - right.x;\r\n result.y = left.y - right.y;\r\n result.z = left.z - right.z;\r\n result.w = left.w - right.w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Negates the provided quaternion.\r\n *\r\n * @param {Quaternion} quaternion The quaternion to be negated.\r\n * @param {Quaternion} result The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter.\r\n */\r\nQuaternion.negate = function (quaternion, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"quaternion\", quaternion);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = -quaternion.x;\r\n result.y = -quaternion.y;\r\n result.z = -quaternion.z;\r\n result.w = -quaternion.w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the dot (scalar) product of two quaternions.\r\n *\r\n * @param {Quaternion} left The first quaternion.\r\n * @param {Quaternion} right The second quaternion.\r\n * @returns {Number} The dot product.\r\n */\r\nQuaternion.dot = function (left, right) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n //>>includeEnd('debug');\r\n\r\n return (\r\n left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w\r\n );\r\n};\r\n\r\n/**\r\n * Computes the product of two quaternions.\r\n *\r\n * @param {Quaternion} left The first quaternion.\r\n * @param {Quaternion} right The second quaternion.\r\n * @param {Quaternion} result The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter.\r\n */\r\nQuaternion.multiply = function (left, right, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"left\", left);\r\n Check.typeOf.object(\"right\", right);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var leftX = left.x;\r\n var leftY = left.y;\r\n var leftZ = left.z;\r\n var leftW = left.w;\r\n\r\n var rightX = right.x;\r\n var rightY = right.y;\r\n var rightZ = right.z;\r\n var rightW = right.w;\r\n\r\n var x = leftW * rightX + leftX * rightW + leftY * rightZ - leftZ * rightY;\r\n var y = leftW * rightY - leftX * rightZ + leftY * rightW + leftZ * rightX;\r\n var z = leftW * rightZ + leftX * rightY - leftY * rightX + leftZ * rightW;\r\n var w = leftW * rightW - leftX * rightX - leftY * rightY - leftZ * rightZ;\r\n\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n result.w = w;\r\n return result;\r\n};\r\n\r\n/**\r\n * Multiplies the provided quaternion componentwise by the provided scalar.\r\n *\r\n * @param {Quaternion} quaternion The quaternion to be scaled.\r\n * @param {Number} scalar The scalar to multiply with.\r\n * @param {Quaternion} result The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter.\r\n */\r\nQuaternion.multiplyByScalar = function (quaternion, scalar, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"quaternion\", quaternion);\r\n Check.typeOf.number(\"scalar\", scalar);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = quaternion.x * scalar;\r\n result.y = quaternion.y * scalar;\r\n result.z = quaternion.z * scalar;\r\n result.w = quaternion.w * scalar;\r\n return result;\r\n};\r\n\r\n/**\r\n * Divides the provided quaternion componentwise by the provided scalar.\r\n *\r\n * @param {Quaternion} quaternion The quaternion to be divided.\r\n * @param {Number} scalar The scalar to divide by.\r\n * @param {Quaternion} result The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter.\r\n */\r\nQuaternion.divideByScalar = function (quaternion, scalar, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"quaternion\", quaternion);\r\n Check.typeOf.number(\"scalar\", scalar);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n result.x = quaternion.x / scalar;\r\n result.y = quaternion.y / scalar;\r\n result.z = quaternion.z / scalar;\r\n result.w = quaternion.w / scalar;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the axis of rotation of the provided quaternion.\r\n *\r\n * @param {Quaternion} quaternion The quaternion to use.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n */\r\nQuaternion.computeAxis = function (quaternion, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"quaternion\", quaternion);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var w = quaternion.w;\r\n if (Math.abs(w - 1.0) < CesiumMath.EPSILON6) {\r\n result.x = result.y = result.z = 0;\r\n return result;\r\n }\r\n\r\n var scalar = 1.0 / Math.sqrt(1.0 - w * w);\r\n\r\n result.x = quaternion.x * scalar;\r\n result.y = quaternion.y * scalar;\r\n result.z = quaternion.z * scalar;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the angle of rotation of the provided quaternion.\r\n *\r\n * @param {Quaternion} quaternion The quaternion to use.\r\n * @returns {Number} The angle of rotation.\r\n */\r\nQuaternion.computeAngle = function (quaternion) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"quaternion\", quaternion);\r\n //>>includeEnd('debug');\r\n\r\n if (Math.abs(quaternion.w - 1.0) < CesiumMath.EPSILON6) {\r\n return 0.0;\r\n }\r\n return 2.0 * Math.acos(quaternion.w);\r\n};\r\n\r\nvar lerpScratch = new Quaternion();\r\n/**\r\n * Computes the linear interpolation or extrapolation at t using the provided quaternions.\r\n *\r\n * @param {Quaternion} start The value corresponding to t at 0.0.\r\n * @param {Quaternion} end The value corresponding to t at 1.0.\r\n * @param {Number} t The point along t at which to interpolate.\r\n * @param {Quaternion} result The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter.\r\n */\r\nQuaternion.lerp = function (start, end, t, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"start\", start);\r\n Check.typeOf.object(\"end\", end);\r\n Check.typeOf.number(\"t\", t);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n lerpScratch = Quaternion.multiplyByScalar(end, t, lerpScratch);\r\n result = Quaternion.multiplyByScalar(start, 1.0 - t, result);\r\n return Quaternion.add(lerpScratch, result, result);\r\n};\r\n\r\nvar slerpEndNegated = new Quaternion();\r\nvar slerpScaledP = new Quaternion();\r\nvar slerpScaledR = new Quaternion();\r\n/**\r\n * Computes the spherical linear interpolation or extrapolation at t using the provided quaternions.\r\n *\r\n * @param {Quaternion} start The value corresponding to t at 0.0.\r\n * @param {Quaternion} end The value corresponding to t at 1.0.\r\n * @param {Number} t The point along t at which to interpolate.\r\n * @param {Quaternion} result The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter.\r\n *\r\n * @see Quaternion#fastSlerp\r\n */\r\nQuaternion.slerp = function (start, end, t, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"start\", start);\r\n Check.typeOf.object(\"end\", end);\r\n Check.typeOf.number(\"t\", t);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var dot = Quaternion.dot(start, end);\r\n\r\n // The angle between start must be acute. Since q and -q represent\r\n // the same rotation, negate q to get the acute angle.\r\n var r = end;\r\n if (dot < 0.0) {\r\n dot = -dot;\r\n r = slerpEndNegated = Quaternion.negate(end, slerpEndNegated);\r\n }\r\n\r\n // dot > 0, as the dot product approaches 1, the angle between the\r\n // quaternions vanishes. use linear interpolation.\r\n if (1.0 - dot < CesiumMath.EPSILON6) {\r\n return Quaternion.lerp(start, r, t, result);\r\n }\r\n\r\n var theta = Math.acos(dot);\r\n slerpScaledP = Quaternion.multiplyByScalar(\r\n start,\r\n Math.sin((1 - t) * theta),\r\n slerpScaledP\r\n );\r\n slerpScaledR = Quaternion.multiplyByScalar(\r\n r,\r\n Math.sin(t * theta),\r\n slerpScaledR\r\n );\r\n result = Quaternion.add(slerpScaledP, slerpScaledR, result);\r\n return Quaternion.multiplyByScalar(result, 1.0 / Math.sin(theta), result);\r\n};\r\n\r\n/**\r\n * The logarithmic quaternion function.\r\n *\r\n * @param {Quaternion} quaternion The unit quaternion.\r\n * @param {Cartesian3} result The object onto which to store the result.\r\n * @returns {Cartesian3} The modified result parameter.\r\n */\r\nQuaternion.log = function (quaternion, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"quaternion\", quaternion);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var theta = CesiumMath.acosClamped(quaternion.w);\r\n var thetaOverSinTheta = 0.0;\r\n\r\n if (theta !== 0.0) {\r\n thetaOverSinTheta = theta / Math.sin(theta);\r\n }\r\n\r\n return Cartesian3.multiplyByScalar(quaternion, thetaOverSinTheta, result);\r\n};\r\n\r\n/**\r\n * The exponential quaternion function.\r\n *\r\n * @param {Cartesian3} cartesian The cartesian.\r\n * @param {Quaternion} result The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter.\r\n */\r\nQuaternion.exp = function (cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"cartesian\", cartesian);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var theta = Cartesian3.magnitude(cartesian);\r\n var sinThetaOverTheta = 0.0;\r\n\r\n if (theta !== 0.0) {\r\n sinThetaOverTheta = Math.sin(theta) / theta;\r\n }\r\n\r\n result.x = cartesian.x * sinThetaOverTheta;\r\n result.y = cartesian.y * sinThetaOverTheta;\r\n result.z = cartesian.z * sinThetaOverTheta;\r\n result.w = Math.cos(theta);\r\n\r\n return result;\r\n};\r\n\r\nvar squadScratchCartesian0 = new Cartesian3();\r\nvar squadScratchCartesian1 = new Cartesian3();\r\nvar squadScratchQuaternion0 = new Quaternion();\r\nvar squadScratchQuaternion1 = new Quaternion();\r\n\r\n/**\r\n * Computes an inner quadrangle point.\r\n * This will compute quaternions that ensure a squad curve is C1.
\r\n *\r\n * @param {Quaternion} q0 The first quaternion.\r\n * @param {Quaternion} q1 The second quaternion.\r\n * @param {Quaternion} q2 The third quaternion.\r\n * @param {Quaternion} result The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter.\r\n *\r\n * @see Quaternion#squad\r\n */\r\nQuaternion.computeInnerQuadrangle = function (q0, q1, q2, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"q0\", q0);\r\n Check.typeOf.object(\"q1\", q1);\r\n Check.typeOf.object(\"q2\", q2);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var qInv = Quaternion.conjugate(q1, squadScratchQuaternion0);\r\n Quaternion.multiply(qInv, q2, squadScratchQuaternion1);\r\n var cart0 = Quaternion.log(squadScratchQuaternion1, squadScratchCartesian0);\r\n\r\n Quaternion.multiply(qInv, q0, squadScratchQuaternion1);\r\n var cart1 = Quaternion.log(squadScratchQuaternion1, squadScratchCartesian1);\r\n\r\n Cartesian3.add(cart0, cart1, cart0);\r\n Cartesian3.multiplyByScalar(cart0, 0.25, cart0);\r\n Cartesian3.negate(cart0, cart0);\r\n Quaternion.exp(cart0, squadScratchQuaternion0);\r\n\r\n return Quaternion.multiply(q1, squadScratchQuaternion0, result);\r\n};\r\n\r\n/**\r\n * Computes the spherical quadrangle interpolation between quaternions.\r\n *\r\n * @param {Quaternion} q0 The first quaternion.\r\n * @param {Quaternion} q1 The second quaternion.\r\n * @param {Quaternion} s0 The first inner quadrangle.\r\n * @param {Quaternion} s1 The second inner quadrangle.\r\n * @param {Number} t The time in [0,1] used to interpolate.\r\n * @param {Quaternion} result The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter.\r\n *\r\n *\r\n * @example\r\n * // 1. compute the squad interpolation between two quaternions on a curve\r\n * var s0 = Cesium.Quaternion.computeInnerQuadrangle(quaternions[i - 1], quaternions[i], quaternions[i + 1], new Cesium.Quaternion());\r\n * var s1 = Cesium.Quaternion.computeInnerQuadrangle(quaternions[i], quaternions[i + 1], quaternions[i + 2], new Cesium.Quaternion());\r\n * var q = Cesium.Quaternion.squad(quaternions[i], quaternions[i + 1], s0, s1, t, new Cesium.Quaternion());\r\n *\r\n * // 2. compute the squad interpolation as above but where the first quaternion is a end point.\r\n * var s1 = Cesium.Quaternion.computeInnerQuadrangle(quaternions[0], quaternions[1], quaternions[2], new Cesium.Quaternion());\r\n * var q = Cesium.Quaternion.squad(quaternions[0], quaternions[1], quaternions[0], s1, t, new Cesium.Quaternion());\r\n *\r\n * @see Quaternion#computeInnerQuadrangle\r\n */\r\nQuaternion.squad = function (q0, q1, s0, s1, t, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"q0\", q0);\r\n Check.typeOf.object(\"q1\", q1);\r\n Check.typeOf.object(\"s0\", s0);\r\n Check.typeOf.object(\"s1\", s1);\r\n Check.typeOf.number(\"t\", t);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var slerp0 = Quaternion.slerp(q0, q1, t, squadScratchQuaternion0);\r\n var slerp1 = Quaternion.slerp(s0, s1, t, squadScratchQuaternion1);\r\n return Quaternion.slerp(slerp0, slerp1, 2.0 * t * (1.0 - t), result);\r\n};\r\n\r\nvar fastSlerpScratchQuaternion = new Quaternion();\r\nvar opmu = 1.90110745351730037;\r\nvar u = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];\r\nvar v = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];\r\nvar bT = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];\r\nvar bD = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];\r\n\r\nfor (var i = 0; i < 7; ++i) {\r\n var s = i + 1.0;\r\n var t = 2.0 * s + 1.0;\r\n u[i] = 1.0 / (s * t);\r\n v[i] = s / t;\r\n}\r\n\r\nu[7] = opmu / (8.0 * 17.0);\r\nv[7] = (opmu * 8.0) / 17.0;\r\n\r\n/**\r\n * Computes the spherical linear interpolation or extrapolation at t using the provided quaternions.\r\n * This implementation is faster than {@link Quaternion#slerp}, but is only accurate up to 10-6.\r\n *\r\n * @param {Quaternion} start The value corresponding to t at 0.0.\r\n * @param {Quaternion} end The value corresponding to t at 1.0.\r\n * @param {Number} t The point along t at which to interpolate.\r\n * @param {Quaternion} result The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter.\r\n *\r\n * @see Quaternion#slerp\r\n */\r\nQuaternion.fastSlerp = function (start, end, t, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"start\", start);\r\n Check.typeOf.object(\"end\", end);\r\n Check.typeOf.number(\"t\", t);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var x = Quaternion.dot(start, end);\r\n\r\n var sign;\r\n if (x >= 0) {\r\n sign = 1.0;\r\n } else {\r\n sign = -1.0;\r\n x = -x;\r\n }\r\n\r\n var xm1 = x - 1.0;\r\n var d = 1.0 - t;\r\n var sqrT = t * t;\r\n var sqrD = d * d;\r\n\r\n for (var i = 7; i >= 0; --i) {\r\n bT[i] = (u[i] * sqrT - v[i]) * xm1;\r\n bD[i] = (u[i] * sqrD - v[i]) * xm1;\r\n }\r\n\r\n var cT =\r\n sign *\r\n t *\r\n (1.0 +\r\n bT[0] *\r\n (1.0 +\r\n bT[1] *\r\n (1.0 +\r\n bT[2] *\r\n (1.0 +\r\n bT[3] *\r\n (1.0 +\r\n bT[4] *\r\n (1.0 + bT[5] * (1.0 + bT[6] * (1.0 + bT[7]))))))));\r\n var cD =\r\n d *\r\n (1.0 +\r\n bD[0] *\r\n (1.0 +\r\n bD[1] *\r\n (1.0 +\r\n bD[2] *\r\n (1.0 +\r\n bD[3] *\r\n (1.0 +\r\n bD[4] *\r\n (1.0 + bD[5] * (1.0 + bD[6] * (1.0 + bD[7]))))))));\r\n\r\n var temp = Quaternion.multiplyByScalar(start, cD, fastSlerpScratchQuaternion);\r\n Quaternion.multiplyByScalar(end, cT, result);\r\n return Quaternion.add(temp, result, result);\r\n};\r\n\r\n/**\r\n * Computes the spherical quadrangle interpolation between quaternions.\r\n * An implementation that is faster than {@link Quaternion#squad}, but less accurate.\r\n *\r\n * @param {Quaternion} q0 The first quaternion.\r\n * @param {Quaternion} q1 The second quaternion.\r\n * @param {Quaternion} s0 The first inner quadrangle.\r\n * @param {Quaternion} s1 The second inner quadrangle.\r\n * @param {Number} t The time in [0,1] used to interpolate.\r\n * @param {Quaternion} result The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter or a new instance if none was provided.\r\n *\r\n * @see Quaternion#squad\r\n */\r\nQuaternion.fastSquad = function (q0, q1, s0, s1, t, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"q0\", q0);\r\n Check.typeOf.object(\"q1\", q1);\r\n Check.typeOf.object(\"s0\", s0);\r\n Check.typeOf.object(\"s1\", s1);\r\n Check.typeOf.number(\"t\", t);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var slerp0 = Quaternion.fastSlerp(q0, q1, t, squadScratchQuaternion0);\r\n var slerp1 = Quaternion.fastSlerp(s0, s1, t, squadScratchQuaternion1);\r\n return Quaternion.fastSlerp(slerp0, slerp1, 2.0 * t * (1.0 - t), result);\r\n};\r\n\r\n/**\r\n * Compares the provided quaternions componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Quaternion} [left] The first quaternion.\r\n * @param {Quaternion} [right] The second quaternion.\r\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\r\n */\r\nQuaternion.equals = function (left, right) {\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n left.x === right.x &&\r\n left.y === right.y &&\r\n left.z === right.z &&\r\n left.w === right.w)\r\n );\r\n};\r\n\r\n/**\r\n * Compares the provided quaternions componentwise and returns\r\n * true
if they are within the provided epsilon,\r\n * false
otherwise.\r\n *\r\n * @param {Quaternion} [left] The first quaternion.\r\n * @param {Quaternion} [right] The second quaternion.\r\n * @param {Number} [epsilon=0] The epsilon to use for equality testing.\r\n * @returns {Boolean} true
if left and right are within the provided epsilon, false
otherwise.\r\n */\r\nQuaternion.equalsEpsilon = function (left, right, epsilon) {\r\n epsilon = defaultValue(epsilon, 0);\r\n\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n Math.abs(left.x - right.x) <= epsilon &&\r\n Math.abs(left.y - right.y) <= epsilon &&\r\n Math.abs(left.z - right.z) <= epsilon &&\r\n Math.abs(left.w - right.w) <= epsilon)\r\n );\r\n};\r\n\r\n/**\r\n * An immutable Quaternion instance initialized to (0.0, 0.0, 0.0, 0.0).\r\n *\r\n * @type {Quaternion}\r\n * @constant\r\n */\r\nQuaternion.ZERO = Object.freeze(new Quaternion(0.0, 0.0, 0.0, 0.0));\r\n\r\n/**\r\n * An immutable Quaternion instance initialized to (0.0, 0.0, 0.0, 1.0).\r\n *\r\n * @type {Quaternion}\r\n * @constant\r\n */\r\nQuaternion.IDENTITY = Object.freeze(new Quaternion(0.0, 0.0, 0.0, 1.0));\r\n\r\n/**\r\n * Duplicates this Quaternion instance.\r\n *\r\n * @param {Quaternion} [result] The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.\r\n */\r\nQuaternion.prototype.clone = function (result) {\r\n return Quaternion.clone(this, result);\r\n};\r\n\r\n/**\r\n * Compares this and the provided quaternion componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {Quaternion} [right] The right hand side quaternion.\r\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\r\n */\r\nQuaternion.prototype.equals = function (right) {\r\n return Quaternion.equals(this, right);\r\n};\r\n\r\n/**\r\n * Compares this and the provided quaternion componentwise and returns\r\n * true
if they are within the provided epsilon,\r\n * false
otherwise.\r\n *\r\n * @param {Quaternion} [right] The right hand side quaternion.\r\n * @param {Number} [epsilon=0] The epsilon to use for equality testing.\r\n * @returns {Boolean} true
if left and right are within the provided epsilon, false
otherwise.\r\n */\r\nQuaternion.prototype.equalsEpsilon = function (right, epsilon) {\r\n return Quaternion.equalsEpsilon(this, right, epsilon);\r\n};\r\n\r\n/**\r\n * Returns a string representing this quaternion in the format (x, y, z, w).\r\n *\r\n * @returns {String} A string representing this Quaternion.\r\n */\r\nQuaternion.prototype.toString = function () {\r\n return \"(\" + this.x + \", \" + this.y + \", \" + this.z + \", \" + this.w + \")\";\r\n};\r\nexport default Quaternion;\r\n","import when from \"../ThirdParty/when.js\";\r\nimport Cartesian2 from \"./Cartesian2.js\";\r\nimport Cartesian3 from \"./Cartesian3.js\";\r\nimport Cartesian4 from \"./Cartesian4.js\";\r\nimport Cartographic from \"./Cartographic.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport EarthOrientationParameters from \"./EarthOrientationParameters.js\";\r\nimport EarthOrientationParametersSample from \"./EarthOrientationParametersSample.js\";\r\nimport Ellipsoid from \"./Ellipsoid.js\";\r\nimport HeadingPitchRoll from \"./HeadingPitchRoll.js\";\r\nimport Iau2006XysData from \"./Iau2006XysData.js\";\r\nimport Iau2006XysSample from \"./Iau2006XysSample.js\";\r\nimport JulianDate from \"./JulianDate.js\";\r\nimport CesiumMath from \"./Math.js\";\r\nimport Matrix3 from \"./Matrix3.js\";\r\nimport Matrix4 from \"./Matrix4.js\";\r\nimport Quaternion from \"./Quaternion.js\";\r\nimport TimeConstants from \"./TimeConstants.js\";\r\n\r\n/**\r\n * Contains functions for transforming positions to various reference frames.\r\n *\r\n * @namespace Transforms\r\n */\r\nvar Transforms = {};\r\n\r\nvar vectorProductLocalFrame = {\r\n up: {\r\n south: \"east\",\r\n north: \"west\",\r\n west: \"south\",\r\n east: \"north\",\r\n },\r\n down: {\r\n south: \"west\",\r\n north: \"east\",\r\n west: \"north\",\r\n east: \"south\",\r\n },\r\n south: {\r\n up: \"west\",\r\n down: \"east\",\r\n west: \"down\",\r\n east: \"up\",\r\n },\r\n north: {\r\n up: \"east\",\r\n down: \"west\",\r\n west: \"up\",\r\n east: \"down\",\r\n },\r\n west: {\r\n up: \"north\",\r\n down: \"south\",\r\n north: \"down\",\r\n south: \"up\",\r\n },\r\n east: {\r\n up: \"south\",\r\n down: \"north\",\r\n north: \"up\",\r\n south: \"down\",\r\n },\r\n};\r\n\r\nvar degeneratePositionLocalFrame = {\r\n north: [-1, 0, 0],\r\n east: [0, 1, 0],\r\n up: [0, 0, 1],\r\n south: [1, 0, 0],\r\n west: [0, -1, 0],\r\n down: [0, 0, -1],\r\n};\r\n\r\nvar localFrameToFixedFrameCache = {};\r\n\r\nvar scratchCalculateCartesian = {\r\n east: new Cartesian3(),\r\n north: new Cartesian3(),\r\n up: new Cartesian3(),\r\n west: new Cartesian3(),\r\n south: new Cartesian3(),\r\n down: new Cartesian3(),\r\n};\r\nvar scratchFirstCartesian = new Cartesian3();\r\nvar scratchSecondCartesian = new Cartesian3();\r\nvar scratchThirdCartesian = new Cartesian3();\r\n/**\r\n * Generates a function that computes a 4x4 transformation matrix from a reference frame\r\n * centered at the provided origin to the provided ellipsoid's fixed reference frame.\r\n * @param {String} firstAxis name of the first axis of the local reference frame. Must be\r\n * 'east', 'north', 'up', 'west', 'south' or 'down'.\r\n * @param {String} secondAxis name of the second axis of the local reference frame. Must be\r\n * 'east', 'north', 'up', 'west', 'south' or 'down'.\r\n * @return {Transforms.LocalFrameToFixedFrame} The function that will computes a\r\n * 4x4 transformation matrix from a reference frame, with first axis and second axis compliant with the parameters,\r\n */\r\nTransforms.localFrameToFixedFrameGenerator = function (firstAxis, secondAxis) {\r\n if (\r\n !vectorProductLocalFrame.hasOwnProperty(firstAxis) ||\r\n !vectorProductLocalFrame[firstAxis].hasOwnProperty(secondAxis)\r\n ) {\r\n throw new DeveloperError(\r\n \"firstAxis and secondAxis must be east, north, up, west, south or down.\"\r\n );\r\n }\r\n var thirdAxis = vectorProductLocalFrame[firstAxis][secondAxis];\r\n\r\n /**\r\n * Computes a 4x4 transformation matrix from a reference frame\r\n * centered at the provided origin to the provided ellipsoid's fixed reference frame.\r\n * @callback Transforms.LocalFrameToFixedFrame\r\n * @param {Cartesian3} origin The center point of the local reference frame.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\r\n * @param {Matrix4} [result] The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.\r\n */\r\n var resultat;\r\n var hashAxis = firstAxis + secondAxis;\r\n if (defined(localFrameToFixedFrameCache[hashAxis])) {\r\n resultat = localFrameToFixedFrameCache[hashAxis];\r\n } else {\r\n resultat = function (origin, ellipsoid, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(origin)) {\r\n throw new DeveloperError(\"origin is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n if (!defined(result)) {\r\n result = new Matrix4();\r\n }\r\n if (\r\n Cartesian3.equalsEpsilon(origin, Cartesian3.ZERO, CesiumMath.EPSILON14)\r\n ) {\r\n // If x, y, and z are zero, use the degenerate local frame, which is a special case\r\n Cartesian3.unpack(\r\n degeneratePositionLocalFrame[firstAxis],\r\n 0,\r\n scratchFirstCartesian\r\n );\r\n Cartesian3.unpack(\r\n degeneratePositionLocalFrame[secondAxis],\r\n 0,\r\n scratchSecondCartesian\r\n );\r\n Cartesian3.unpack(\r\n degeneratePositionLocalFrame[thirdAxis],\r\n 0,\r\n scratchThirdCartesian\r\n );\r\n } else if (\r\n CesiumMath.equalsEpsilon(origin.x, 0.0, CesiumMath.EPSILON14) &&\r\n CesiumMath.equalsEpsilon(origin.y, 0.0, CesiumMath.EPSILON14)\r\n ) {\r\n // If x and y are zero, assume origin is at a pole, which is a special case.\r\n var sign = CesiumMath.sign(origin.z);\r\n\r\n Cartesian3.unpack(\r\n degeneratePositionLocalFrame[firstAxis],\r\n 0,\r\n scratchFirstCartesian\r\n );\r\n if (firstAxis !== \"east\" && firstAxis !== \"west\") {\r\n Cartesian3.multiplyByScalar(\r\n scratchFirstCartesian,\r\n sign,\r\n scratchFirstCartesian\r\n );\r\n }\r\n\r\n Cartesian3.unpack(\r\n degeneratePositionLocalFrame[secondAxis],\r\n 0,\r\n scratchSecondCartesian\r\n );\r\n if (secondAxis !== \"east\" && secondAxis !== \"west\") {\r\n Cartesian3.multiplyByScalar(\r\n scratchSecondCartesian,\r\n sign,\r\n scratchSecondCartesian\r\n );\r\n }\r\n\r\n Cartesian3.unpack(\r\n degeneratePositionLocalFrame[thirdAxis],\r\n 0,\r\n scratchThirdCartesian\r\n );\r\n if (thirdAxis !== \"east\" && thirdAxis !== \"west\") {\r\n Cartesian3.multiplyByScalar(\r\n scratchThirdCartesian,\r\n sign,\r\n scratchThirdCartesian\r\n );\r\n }\r\n } else {\r\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\r\n ellipsoid.geodeticSurfaceNormal(origin, scratchCalculateCartesian.up);\r\n\r\n var up = scratchCalculateCartesian.up;\r\n var east = scratchCalculateCartesian.east;\r\n east.x = -origin.y;\r\n east.y = origin.x;\r\n east.z = 0.0;\r\n Cartesian3.normalize(east, scratchCalculateCartesian.east);\r\n Cartesian3.cross(up, east, scratchCalculateCartesian.north);\r\n\r\n Cartesian3.multiplyByScalar(\r\n scratchCalculateCartesian.up,\r\n -1,\r\n scratchCalculateCartesian.down\r\n );\r\n Cartesian3.multiplyByScalar(\r\n scratchCalculateCartesian.east,\r\n -1,\r\n scratchCalculateCartesian.west\r\n );\r\n Cartesian3.multiplyByScalar(\r\n scratchCalculateCartesian.north,\r\n -1,\r\n scratchCalculateCartesian.south\r\n );\r\n\r\n scratchFirstCartesian = scratchCalculateCartesian[firstAxis];\r\n scratchSecondCartesian = scratchCalculateCartesian[secondAxis];\r\n scratchThirdCartesian = scratchCalculateCartesian[thirdAxis];\r\n }\r\n result[0] = scratchFirstCartesian.x;\r\n result[1] = scratchFirstCartesian.y;\r\n result[2] = scratchFirstCartesian.z;\r\n result[3] = 0.0;\r\n result[4] = scratchSecondCartesian.x;\r\n result[5] = scratchSecondCartesian.y;\r\n result[6] = scratchSecondCartesian.z;\r\n result[7] = 0.0;\r\n result[8] = scratchThirdCartesian.x;\r\n result[9] = scratchThirdCartesian.y;\r\n result[10] = scratchThirdCartesian.z;\r\n result[11] = 0.0;\r\n result[12] = origin.x;\r\n result[13] = origin.y;\r\n result[14] = origin.z;\r\n result[15] = 1.0;\r\n return result;\r\n };\r\n localFrameToFixedFrameCache[hashAxis] = resultat;\r\n }\r\n return resultat;\r\n};\r\n\r\n/**\r\n * Computes a 4x4 transformation matrix from a reference frame with an east-north-up axes\r\n * centered at the provided origin to the provided ellipsoid's fixed reference frame.\r\n * The local axes are defined as:\r\n * \r\n * - The
x
axis points in the local east direction. \r\n * - The
y
axis points in the local north direction. \r\n * - The
z
axis points in the direction of the ellipsoid surface normal which passes through the position. \r\n *
\r\n *\r\n * @function\r\n * @param {Cartesian3} origin The center point of the local reference frame.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\r\n * @param {Matrix4} [result] The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.\r\n *\r\n * @example\r\n * // Get the transform from local east-north-up at cartographic (0.0, 0.0) to Earth's fixed frame.\r\n * var center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);\r\n * var transform = Cesium.Transforms.eastNorthUpToFixedFrame(center);\r\n */\r\nTransforms.eastNorthUpToFixedFrame = Transforms.localFrameToFixedFrameGenerator(\r\n \"east\",\r\n \"north\"\r\n);\r\n\r\n/**\r\n * Computes a 4x4 transformation matrix from a reference frame with an north-east-down axes\r\n * centered at the provided origin to the provided ellipsoid's fixed reference frame.\r\n * The local axes are defined as:\r\n * \r\n * - The
x
axis points in the local north direction. \r\n * - The
y
axis points in the local east direction. \r\n * - The
z
axis points in the opposite direction of the ellipsoid surface normal which passes through the position. \r\n *
\r\n *\r\n * @function\r\n * @param {Cartesian3} origin The center point of the local reference frame.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\r\n * @param {Matrix4} [result] The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.\r\n *\r\n * @example\r\n * // Get the transform from local north-east-down at cartographic (0.0, 0.0) to Earth's fixed frame.\r\n * var center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);\r\n * var transform = Cesium.Transforms.northEastDownToFixedFrame(center);\r\n */\r\nTransforms.northEastDownToFixedFrame = Transforms.localFrameToFixedFrameGenerator(\r\n \"north\",\r\n \"east\"\r\n);\r\n\r\n/**\r\n * Computes a 4x4 transformation matrix from a reference frame with an north-up-east axes\r\n * centered at the provided origin to the provided ellipsoid's fixed reference frame.\r\n * The local axes are defined as:\r\n * \r\n * - The
x
axis points in the local north direction. \r\n * - The
y
axis points in the direction of the ellipsoid surface normal which passes through the position. \r\n * - The
z
axis points in the local east direction. \r\n *
\r\n *\r\n * @function\r\n * @param {Cartesian3} origin The center point of the local reference frame.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\r\n * @param {Matrix4} [result] The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.\r\n *\r\n * @example\r\n * // Get the transform from local north-up-east at cartographic (0.0, 0.0) to Earth's fixed frame.\r\n * var center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);\r\n * var transform = Cesium.Transforms.northUpEastToFixedFrame(center);\r\n */\r\nTransforms.northUpEastToFixedFrame = Transforms.localFrameToFixedFrameGenerator(\r\n \"north\",\r\n \"up\"\r\n);\r\n\r\n/**\r\n * Computes a 4x4 transformation matrix from a reference frame with an north-west-up axes\r\n * centered at the provided origin to the provided ellipsoid's fixed reference frame.\r\n * The local axes are defined as:\r\n * \r\n * - The
x
axis points in the local north direction. \r\n * - The
y
axis points in the local west direction. \r\n * - The
z
axis points in the direction of the ellipsoid surface normal which passes through the position. \r\n *
\r\n *\r\n * @function\r\n * @param {Cartesian3} origin The center point of the local reference frame.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\r\n * @param {Matrix4} [result] The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.\r\n *\r\n * @example\r\n * // Get the transform from local north-West-Up at cartographic (0.0, 0.0) to Earth's fixed frame.\r\n * var center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);\r\n * var transform = Cesium.Transforms.northWestUpToFixedFrame(center);\r\n */\r\nTransforms.northWestUpToFixedFrame = Transforms.localFrameToFixedFrameGenerator(\r\n \"north\",\r\n \"west\"\r\n);\r\n\r\nvar scratchHPRQuaternion = new Quaternion();\r\nvar scratchScale = new Cartesian3(1.0, 1.0, 1.0);\r\nvar scratchHPRMatrix4 = new Matrix4();\r\n\r\n/**\r\n * Computes a 4x4 transformation matrix from a reference frame with axes computed from the heading-pitch-roll angles\r\n * centered at the provided origin to the provided ellipsoid's fixed reference frame. Heading is the rotation from the local north\r\n * direction where a positive angle is increasing eastward. Pitch is the rotation from the local east-north plane. Positive pitch angles\r\n * are above the plane. Negative pitch angles are below the plane. Roll is the first rotation applied about the local east axis.\r\n *\r\n * @param {Cartesian3} origin The center point of the local reference frame.\r\n * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\r\n * @param {Transforms.LocalFrameToFixedFrame} [fixedFrameTransform=Transforms.eastNorthUpToFixedFrame] A 4x4 transformation\r\n * matrix from a reference frame to the provided ellipsoid's fixed reference frame\r\n * @param {Matrix4} [result] The object onto which to store the result.\r\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.\r\n *\r\n * @example\r\n * // Get the transform from local heading-pitch-roll at cartographic (0.0, 0.0) to Earth's fixed frame.\r\n * var center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);\r\n * var heading = -Cesium.Math.PI_OVER_TWO;\r\n * var pitch = Cesium.Math.PI_OVER_FOUR;\r\n * var roll = 0.0;\r\n * var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);\r\n * var transform = Cesium.Transforms.headingPitchRollToFixedFrame(center, hpr);\r\n */\r\nTransforms.headingPitchRollToFixedFrame = function (\r\n origin,\r\n headingPitchRoll,\r\n ellipsoid,\r\n fixedFrameTransform,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"HeadingPitchRoll\", headingPitchRoll);\r\n //>>includeEnd('debug');\r\n\r\n fixedFrameTransform = defaultValue(\r\n fixedFrameTransform,\r\n Transforms.eastNorthUpToFixedFrame\r\n );\r\n var hprQuaternion = Quaternion.fromHeadingPitchRoll(\r\n headingPitchRoll,\r\n scratchHPRQuaternion\r\n );\r\n var hprMatrix = Matrix4.fromTranslationQuaternionRotationScale(\r\n Cartesian3.ZERO,\r\n hprQuaternion,\r\n scratchScale,\r\n scratchHPRMatrix4\r\n );\r\n result = fixedFrameTransform(origin, ellipsoid, result);\r\n return Matrix4.multiply(result, hprMatrix, result);\r\n};\r\n\r\nvar scratchENUMatrix4 = new Matrix4();\r\nvar scratchHPRMatrix3 = new Matrix3();\r\n\r\n/**\r\n * Computes a quaternion from a reference frame with axes computed from the heading-pitch-roll angles\r\n * centered at the provided origin. Heading is the rotation from the local north\r\n * direction where a positive angle is increasing eastward. Pitch is the rotation from the local east-north plane. Positive pitch angles\r\n * are above the plane. Negative pitch angles are below the plane. Roll is the first rotation applied about the local east axis.\r\n *\r\n * @param {Cartesian3} origin The center point of the local reference frame.\r\n * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\r\n * @param {Transforms.LocalFrameToFixedFrame} [fixedFrameTransform=Transforms.eastNorthUpToFixedFrame] A 4x4 transformation\r\n * matrix from a reference frame to the provided ellipsoid's fixed reference frame\r\n * @param {Quaternion} [result] The object onto which to store the result.\r\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if none was provided.\r\n *\r\n * @example\r\n * // Get the quaternion from local heading-pitch-roll at cartographic (0.0, 0.0) to Earth's fixed frame.\r\n * var center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);\r\n * var heading = -Cesium.Math.PI_OVER_TWO;\r\n * var pitch = Cesium.Math.PI_OVER_FOUR;\r\n * var roll = 0.0;\r\n * var hpr = new HeadingPitchRoll(heading, pitch, roll);\r\n * var quaternion = Cesium.Transforms.headingPitchRollQuaternion(center, hpr);\r\n */\r\nTransforms.headingPitchRollQuaternion = function (\r\n origin,\r\n headingPitchRoll,\r\n ellipsoid,\r\n fixedFrameTransform,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"HeadingPitchRoll\", headingPitchRoll);\r\n //>>includeEnd('debug');\r\n\r\n var transform = Transforms.headingPitchRollToFixedFrame(\r\n origin,\r\n headingPitchRoll,\r\n ellipsoid,\r\n fixedFrameTransform,\r\n scratchENUMatrix4\r\n );\r\n var rotation = Matrix4.getMatrix3(transform, scratchHPRMatrix3);\r\n return Quaternion.fromRotationMatrix(rotation, result);\r\n};\r\n\r\nvar noScale = new Cartesian3(1.0, 1.0, 1.0);\r\nvar hprCenterScratch = new Cartesian3();\r\nvar ffScratch = new Matrix4();\r\nvar hprTransformScratch = new Matrix4();\r\nvar hprRotationScratch = new Matrix3();\r\nvar hprQuaternionScratch = new Quaternion();\r\n/**\r\n * Computes heading-pitch-roll angles from a transform in a particular reference frame. Heading is the rotation from the local north\r\n * direction where a positive angle is increasing eastward. Pitch is the rotation from the local east-north plane. Positive pitch angles\r\n * are above the plane. Negative pitch angles are below the plane. Roll is the first rotation applied about the local east axis.\r\n *\r\n * @param {Matrix4} transform The transform\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\r\n * @param {Transforms.LocalFrameToFixedFrame} [fixedFrameTransform=Transforms.eastNorthUpToFixedFrame] A 4x4 transformation\r\n * matrix from a reference frame to the provided ellipsoid's fixed reference frame\r\n * @param {HeadingPitchRoll} [result] The object onto which to store the result.\r\n * @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if none was provided.\r\n */\r\nTransforms.fixedFrameToHeadingPitchRoll = function (\r\n transform,\r\n ellipsoid,\r\n fixedFrameTransform,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"transform\", transform);\r\n //>>includeEnd('debug');\r\n\r\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\r\n fixedFrameTransform = defaultValue(\r\n fixedFrameTransform,\r\n Transforms.eastNorthUpToFixedFrame\r\n );\r\n if (!defined(result)) {\r\n result = new HeadingPitchRoll();\r\n }\r\n\r\n var center = Matrix4.getTranslation(transform, hprCenterScratch);\r\n if (Cartesian3.equals(center, Cartesian3.ZERO)) {\r\n result.heading = 0;\r\n result.pitch = 0;\r\n result.roll = 0;\r\n return result;\r\n }\r\n var toFixedFrame = Matrix4.inverseTransformation(\r\n fixedFrameTransform(center, ellipsoid, ffScratch),\r\n ffScratch\r\n );\r\n var transformCopy = Matrix4.setScale(transform, noScale, hprTransformScratch);\r\n transformCopy = Matrix4.setTranslation(\r\n transformCopy,\r\n Cartesian3.ZERO,\r\n transformCopy\r\n );\r\n\r\n toFixedFrame = Matrix4.multiply(toFixedFrame, transformCopy, toFixedFrame);\r\n var quaternionRotation = Quaternion.fromRotationMatrix(\r\n Matrix4.getMatrix3(toFixedFrame, hprRotationScratch),\r\n hprQuaternionScratch\r\n );\r\n quaternionRotation = Quaternion.normalize(\r\n quaternionRotation,\r\n quaternionRotation\r\n );\r\n\r\n return HeadingPitchRoll.fromQuaternion(quaternionRotation, result);\r\n};\r\n\r\nvar gmstConstant0 = 6 * 3600 + 41 * 60 + 50.54841;\r\nvar gmstConstant1 = 8640184.812866;\r\nvar gmstConstant2 = 0.093104;\r\nvar gmstConstant3 = -6.2e-6;\r\nvar rateCoef = 1.1772758384668e-19;\r\nvar wgs84WRPrecessing = 7.2921158553e-5;\r\nvar twoPiOverSecondsInDay = CesiumMath.TWO_PI / 86400.0;\r\nvar dateInUtc = new JulianDate();\r\n\r\n/**\r\n * Computes a rotation matrix to transform a point or vector from True Equator Mean Equinox (TEME) axes to the\r\n * pseudo-fixed axes at a given time. This method treats the UT1 time standard as equivalent to UTC.\r\n *\r\n * @param {JulianDate} date The time at which to compute the rotation matrix.\r\n * @param {Matrix3} [result] The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if none was provided.\r\n *\r\n * @example\r\n * //Set the view to the inertial frame.\r\n * scene.postUpdate.addEventListener(function(scene, time) {\r\n * var now = Cesium.JulianDate.now();\r\n * var offset = Cesium.Matrix4.multiplyByPoint(camera.transform, camera.position, new Cesium.Cartesian3());\r\n * var transform = Cesium.Matrix4.fromRotationTranslation(Cesium.Transforms.computeTemeToPseudoFixedMatrix(now));\r\n * var inverseTransform = Cesium.Matrix4.inverseTransformation(transform, new Cesium.Matrix4());\r\n * Cesium.Matrix4.multiplyByPoint(inverseTransform, offset, offset);\r\n * camera.lookAtTransform(transform, offset);\r\n * });\r\n */\r\nTransforms.computeTemeToPseudoFixedMatrix = function (date, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(date)) {\r\n throw new DeveloperError(\"date is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n // GMST is actually computed using UT1. We're using UTC as an approximation of UT1.\r\n // We do not want to use the function like convertTaiToUtc in JulianDate because\r\n // we explicitly do not want to fail when inside the leap second.\r\n\r\n dateInUtc = JulianDate.addSeconds(\r\n date,\r\n -JulianDate.computeTaiMinusUtc(date),\r\n dateInUtc\r\n );\r\n var utcDayNumber = dateInUtc.dayNumber;\r\n var utcSecondsIntoDay = dateInUtc.secondsOfDay;\r\n\r\n var t;\r\n var diffDays = utcDayNumber - 2451545;\r\n if (utcSecondsIntoDay >= 43200.0) {\r\n t = (diffDays + 0.5) / TimeConstants.DAYS_PER_JULIAN_CENTURY;\r\n } else {\r\n t = (diffDays - 0.5) / TimeConstants.DAYS_PER_JULIAN_CENTURY;\r\n }\r\n\r\n var gmst0 =\r\n gmstConstant0 +\r\n t * (gmstConstant1 + t * (gmstConstant2 + t * gmstConstant3));\r\n var angle = (gmst0 * twoPiOverSecondsInDay) % CesiumMath.TWO_PI;\r\n var ratio = wgs84WRPrecessing + rateCoef * (utcDayNumber - 2451545.5);\r\n var secondsSinceMidnight =\r\n (utcSecondsIntoDay + TimeConstants.SECONDS_PER_DAY * 0.5) %\r\n TimeConstants.SECONDS_PER_DAY;\r\n var gha = angle + ratio * secondsSinceMidnight;\r\n var cosGha = Math.cos(gha);\r\n var sinGha = Math.sin(gha);\r\n\r\n if (!defined(result)) {\r\n return new Matrix3(\r\n cosGha,\r\n sinGha,\r\n 0.0,\r\n -sinGha,\r\n cosGha,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 1.0\r\n );\r\n }\r\n result[0] = cosGha;\r\n result[1] = -sinGha;\r\n result[2] = 0.0;\r\n result[3] = sinGha;\r\n result[4] = cosGha;\r\n result[5] = 0.0;\r\n result[6] = 0.0;\r\n result[7] = 0.0;\r\n result[8] = 1.0;\r\n return result;\r\n};\r\n\r\n/**\r\n * The source of IAU 2006 XYS data, used for computing the transformation between the\r\n * Fixed and ICRF axes.\r\n * @type {Iau2006XysData}\r\n *\r\n * @see Transforms.computeIcrfToFixedMatrix\r\n * @see Transforms.computeFixedToIcrfMatrix\r\n *\r\n * @private\r\n */\r\nTransforms.iau2006XysData = new Iau2006XysData();\r\n\r\n/**\r\n * The source of Earth Orientation Parameters (EOP) data, used for computing the transformation\r\n * between the Fixed and ICRF axes. By default, zero values are used for all EOP values,\r\n * yielding a reasonable but not completely accurate representation of the ICRF axes.\r\n * @type {EarthOrientationParameters}\r\n *\r\n * @see Transforms.computeIcrfToFixedMatrix\r\n * @see Transforms.computeFixedToIcrfMatrix\r\n *\r\n * @private\r\n */\r\nTransforms.earthOrientationParameters = EarthOrientationParameters.NONE;\r\n\r\nvar ttMinusTai = 32.184;\r\nvar j2000ttDays = 2451545.0;\r\n\r\n/**\r\n * Preloads the data necessary to transform between the ICRF and Fixed axes, in either\r\n * direction, over a given interval. This function returns a promise that, when resolved,\r\n * indicates that the preload has completed.\r\n *\r\n * @param {TimeInterval} timeInterval The interval to preload.\r\n * @returns {Promise} A promise that, when resolved, indicates that the preload has completed\r\n * and evaluation of the transformation between the fixed and ICRF axes will\r\n * no longer return undefined for a time inside the interval.\r\n *\r\n *\r\n * @example\r\n * var interval = new Cesium.TimeInterval(...);\r\n * when(Cesium.Transforms.preloadIcrfFixed(interval), function() {\r\n * // the data is now loaded\r\n * });\r\n *\r\n * @see Transforms.computeIcrfToFixedMatrix\r\n * @see Transforms.computeFixedToIcrfMatrix\r\n * @see when\r\n */\r\nTransforms.preloadIcrfFixed = function (timeInterval) {\r\n var startDayTT = timeInterval.start.dayNumber;\r\n var startSecondTT = timeInterval.start.secondsOfDay + ttMinusTai;\r\n var stopDayTT = timeInterval.stop.dayNumber;\r\n var stopSecondTT = timeInterval.stop.secondsOfDay + ttMinusTai;\r\n\r\n var xysPromise = Transforms.iau2006XysData.preload(\r\n startDayTT,\r\n startSecondTT,\r\n stopDayTT,\r\n stopSecondTT\r\n );\r\n var eopPromise = Transforms.earthOrientationParameters.getPromiseToLoad();\r\n\r\n return when.all([xysPromise, eopPromise]);\r\n};\r\n\r\n/**\r\n * Computes a rotation matrix to transform a point or vector from the International Celestial\r\n * Reference Frame (GCRF/ICRF) inertial frame axes to the Earth-Fixed frame axes (ITRF)\r\n * at a given time. This function may return undefined if the data necessary to\r\n * do the transformation is not yet loaded.\r\n *\r\n * @param {JulianDate} date The time at which to compute the rotation matrix.\r\n * @param {Matrix3} [result] The object onto which to store the result. If this parameter is\r\n * not specified, a new instance is created and returned.\r\n * @returns {Matrix3} The rotation matrix, or undefined if the data necessary to do the\r\n * transformation is not yet loaded.\r\n *\r\n *\r\n * @example\r\n * scene.postUpdate.addEventListener(function(scene, time) {\r\n * // View in ICRF.\r\n * var icrfToFixed = Cesium.Transforms.computeIcrfToFixedMatrix(time);\r\n * if (Cesium.defined(icrfToFixed)) {\r\n * var offset = Cesium.Cartesian3.clone(camera.position);\r\n * var transform = Cesium.Matrix4.fromRotationTranslation(icrfToFixed);\r\n * camera.lookAtTransform(transform, offset);\r\n * }\r\n * });\r\n *\r\n * @see Transforms.preloadIcrfFixed\r\n */\r\nTransforms.computeIcrfToFixedMatrix = function (date, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(date)) {\r\n throw new DeveloperError(\"date is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n if (!defined(result)) {\r\n result = new Matrix3();\r\n }\r\n\r\n var fixedToIcrfMtx = Transforms.computeFixedToIcrfMatrix(date, result);\r\n if (!defined(fixedToIcrfMtx)) {\r\n return undefined;\r\n }\r\n\r\n return Matrix3.transpose(fixedToIcrfMtx, result);\r\n};\r\n\r\nvar xysScratch = new Iau2006XysSample(0.0, 0.0, 0.0);\r\nvar eopScratch = new EarthOrientationParametersSample(\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0\r\n);\r\nvar rotation1Scratch = new Matrix3();\r\nvar rotation2Scratch = new Matrix3();\r\n\r\n/**\r\n * Computes a rotation matrix to transform a point or vector from the Earth-Fixed frame axes (ITRF)\r\n * to the International Celestial Reference Frame (GCRF/ICRF) inertial frame axes\r\n * at a given time. This function may return undefined if the data necessary to\r\n * do the transformation is not yet loaded.\r\n *\r\n * @param {JulianDate} date The time at which to compute the rotation matrix.\r\n * @param {Matrix3} [result] The object onto which to store the result. If this parameter is\r\n * not specified, a new instance is created and returned.\r\n * @returns {Matrix3} The rotation matrix, or undefined if the data necessary to do the\r\n * transformation is not yet loaded.\r\n *\r\n *\r\n * @example\r\n * // Transform a point from the ICRF axes to the Fixed axes.\r\n * var now = Cesium.JulianDate.now();\r\n * var pointInFixed = Cesium.Cartesian3.fromDegrees(0.0, 0.0);\r\n * var fixedToIcrf = Cesium.Transforms.computeIcrfToFixedMatrix(now);\r\n * var pointInInertial = new Cesium.Cartesian3();\r\n * if (Cesium.defined(fixedToIcrf)) {\r\n * pointInInertial = Cesium.Matrix3.multiplyByVector(fixedToIcrf, pointInFixed, pointInInertial);\r\n * }\r\n *\r\n * @see Transforms.preloadIcrfFixed\r\n */\r\nTransforms.computeFixedToIcrfMatrix = function (date, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(date)) {\r\n throw new DeveloperError(\"date is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Matrix3();\r\n }\r\n\r\n // Compute pole wander\r\n var eop = Transforms.earthOrientationParameters.compute(date, eopScratch);\r\n if (!defined(eop)) {\r\n return undefined;\r\n }\r\n\r\n // There is no external conversion to Terrestrial Time (TT).\r\n // So use International Atomic Time (TAI) and convert using offsets.\r\n // Here we are assuming that dayTT and secondTT are positive\r\n var dayTT = date.dayNumber;\r\n // It's possible here that secondTT could roll over 86400\r\n // This does not seem to affect the precision (unit tests check for this)\r\n var secondTT = date.secondsOfDay + ttMinusTai;\r\n\r\n var xys = Transforms.iau2006XysData.computeXysRadians(\r\n dayTT,\r\n secondTT,\r\n xysScratch\r\n );\r\n if (!defined(xys)) {\r\n return undefined;\r\n }\r\n\r\n var x = xys.x + eop.xPoleOffset;\r\n var y = xys.y + eop.yPoleOffset;\r\n\r\n // Compute XYS rotation\r\n var a = 1.0 / (1.0 + Math.sqrt(1.0 - x * x - y * y));\r\n\r\n var rotation1 = rotation1Scratch;\r\n rotation1[0] = 1.0 - a * x * x;\r\n rotation1[3] = -a * x * y;\r\n rotation1[6] = x;\r\n rotation1[1] = -a * x * y;\r\n rotation1[4] = 1 - a * y * y;\r\n rotation1[7] = y;\r\n rotation1[2] = -x;\r\n rotation1[5] = -y;\r\n rotation1[8] = 1 - a * (x * x + y * y);\r\n\r\n var rotation2 = Matrix3.fromRotationZ(-xys.s, rotation2Scratch);\r\n var matrixQ = Matrix3.multiply(rotation1, rotation2, rotation1Scratch);\r\n\r\n // Similar to TT conversions above\r\n // It's possible here that secondTT could roll over 86400\r\n // This does not seem to affect the precision (unit tests check for this)\r\n var dateUt1day = date.dayNumber;\r\n var dateUt1sec =\r\n date.secondsOfDay - JulianDate.computeTaiMinusUtc(date) + eop.ut1MinusUtc;\r\n\r\n // Compute Earth rotation angle\r\n // The IERS standard for era is\r\n // era = 0.7790572732640 + 1.00273781191135448 * Tu\r\n // where\r\n // Tu = JulianDateInUt1 - 2451545.0\r\n // However, you get much more precision if you make the following simplification\r\n // era = a + (1 + b) * (JulianDayNumber + FractionOfDay - 2451545)\r\n // era = a + (JulianDayNumber - 2451545) + FractionOfDay + b (JulianDayNumber - 2451545 + FractionOfDay)\r\n // era = a + FractionOfDay + b (JulianDayNumber - 2451545 + FractionOfDay)\r\n // since (JulianDayNumber - 2451545) represents an integer number of revolutions which will be discarded anyway.\r\n var daysSinceJ2000 = dateUt1day - 2451545;\r\n var fractionOfDay = dateUt1sec / TimeConstants.SECONDS_PER_DAY;\r\n var era =\r\n 0.779057273264 +\r\n fractionOfDay +\r\n 0.00273781191135448 * (daysSinceJ2000 + fractionOfDay);\r\n era = (era % 1.0) * CesiumMath.TWO_PI;\r\n\r\n var earthRotation = Matrix3.fromRotationZ(era, rotation2Scratch);\r\n\r\n // pseudoFixed to ICRF\r\n var pfToIcrf = Matrix3.multiply(matrixQ, earthRotation, rotation1Scratch);\r\n\r\n // Compute pole wander matrix\r\n var cosxp = Math.cos(eop.xPoleWander);\r\n var cosyp = Math.cos(eop.yPoleWander);\r\n var sinxp = Math.sin(eop.xPoleWander);\r\n var sinyp = Math.sin(eop.yPoleWander);\r\n\r\n var ttt = dayTT - j2000ttDays + secondTT / TimeConstants.SECONDS_PER_DAY;\r\n ttt /= 36525.0;\r\n\r\n // approximate sp value in rad\r\n var sp = (-47.0e-6 * ttt * CesiumMath.RADIANS_PER_DEGREE) / 3600.0;\r\n var cossp = Math.cos(sp);\r\n var sinsp = Math.sin(sp);\r\n\r\n var fToPfMtx = rotation2Scratch;\r\n fToPfMtx[0] = cosxp * cossp;\r\n fToPfMtx[1] = cosxp * sinsp;\r\n fToPfMtx[2] = sinxp;\r\n fToPfMtx[3] = -cosyp * sinsp + sinyp * sinxp * cossp;\r\n fToPfMtx[4] = cosyp * cossp + sinyp * sinxp * sinsp;\r\n fToPfMtx[5] = -sinyp * cosxp;\r\n fToPfMtx[6] = -sinyp * sinsp - cosyp * sinxp * cossp;\r\n fToPfMtx[7] = sinyp * cossp - cosyp * sinxp * sinsp;\r\n fToPfMtx[8] = cosyp * cosxp;\r\n\r\n return Matrix3.multiply(pfToIcrf, fToPfMtx, result);\r\n};\r\n\r\nvar pointToWindowCoordinatesTemp = new Cartesian4();\r\n\r\n/**\r\n * Transform a point from model coordinates to window coordinates.\r\n *\r\n * @param {Matrix4} modelViewProjectionMatrix The 4x4 model-view-projection matrix.\r\n * @param {Matrix4} viewportTransformation The 4x4 viewport transformation.\r\n * @param {Cartesian3} point The point to transform.\r\n * @param {Cartesian2} [result] The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if none was provided.\r\n */\r\nTransforms.pointToWindowCoordinates = function (\r\n modelViewProjectionMatrix,\r\n viewportTransformation,\r\n point,\r\n result\r\n) {\r\n result = Transforms.pointToGLWindowCoordinates(\r\n modelViewProjectionMatrix,\r\n viewportTransformation,\r\n point,\r\n result\r\n );\r\n result.y = 2.0 * viewportTransformation[5] - result.y;\r\n return result;\r\n};\r\n\r\n/**\r\n * @private\r\n */\r\nTransforms.pointToGLWindowCoordinates = function (\r\n modelViewProjectionMatrix,\r\n viewportTransformation,\r\n point,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(modelViewProjectionMatrix)) {\r\n throw new DeveloperError(\"modelViewProjectionMatrix is required.\");\r\n }\r\n\r\n if (!defined(viewportTransformation)) {\r\n throw new DeveloperError(\"viewportTransformation is required.\");\r\n }\r\n\r\n if (!defined(point)) {\r\n throw new DeveloperError(\"point is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian2();\r\n }\r\n\r\n var tmp = pointToWindowCoordinatesTemp;\r\n\r\n Matrix4.multiplyByVector(\r\n modelViewProjectionMatrix,\r\n Cartesian4.fromElements(point.x, point.y, point.z, 1, tmp),\r\n tmp\r\n );\r\n Cartesian4.multiplyByScalar(tmp, 1.0 / tmp.w, tmp);\r\n Matrix4.multiplyByVector(viewportTransformation, tmp, tmp);\r\n return Cartesian2.fromCartesian4(tmp, result);\r\n};\r\n\r\nvar normalScratch = new Cartesian3();\r\nvar rightScratch = new Cartesian3();\r\nvar upScratch = new Cartesian3();\r\n\r\n/**\r\n * Transform a position and velocity to a rotation matrix.\r\n *\r\n * @param {Cartesian3} position The position to transform.\r\n * @param {Cartesian3} velocity The velocity vector to transform.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\r\n * @param {Matrix3} [result] The object onto which to store the result.\r\n * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if none was provided.\r\n */\r\nTransforms.rotationMatrixFromPositionVelocity = function (\r\n position,\r\n velocity,\r\n ellipsoid,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(position)) {\r\n throw new DeveloperError(\"position is required.\");\r\n }\r\n\r\n if (!defined(velocity)) {\r\n throw new DeveloperError(\"velocity is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var normal = defaultValue(ellipsoid, Ellipsoid.WGS84).geodeticSurfaceNormal(\r\n position,\r\n normalScratch\r\n );\r\n var right = Cartesian3.cross(velocity, normal, rightScratch);\r\n\r\n if (Cartesian3.equalsEpsilon(right, Cartesian3.ZERO, CesiumMath.EPSILON6)) {\r\n right = Cartesian3.clone(Cartesian3.UNIT_X, right);\r\n }\r\n\r\n var up = Cartesian3.cross(right, velocity, upScratch);\r\n Cartesian3.normalize(up, up);\r\n Cartesian3.cross(velocity, up, right);\r\n Cartesian3.negate(right, right);\r\n Cartesian3.normalize(right, right);\r\n\r\n if (!defined(result)) {\r\n result = new Matrix3();\r\n }\r\n\r\n result[0] = velocity.x;\r\n result[1] = velocity.y;\r\n result[2] = velocity.z;\r\n result[3] = right.x;\r\n result[4] = right.y;\r\n result[5] = right.z;\r\n result[6] = up.x;\r\n result[7] = up.y;\r\n result[8] = up.z;\r\n\r\n return result;\r\n};\r\n\r\nvar swizzleMatrix = new Matrix4(\r\n 0.0,\r\n 0.0,\r\n 1.0,\r\n 0.0,\r\n 1.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 1.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 1.0\r\n);\r\n\r\nvar scratchCartographic = new Cartographic();\r\nvar scratchCartesian3Projection = new Cartesian3();\r\nvar scratchCenter = new Cartesian3();\r\nvar scratchRotation = new Matrix3();\r\nvar scratchFromENU = new Matrix4();\r\nvar scratchToENU = new Matrix4();\r\n\r\n/**\r\n * @private\r\n */\r\nTransforms.basisTo2D = function (projection, matrix, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(projection)) {\r\n throw new DeveloperError(\"projection is required.\");\r\n }\r\n if (!defined(matrix)) {\r\n throw new DeveloperError(\"matrix is required.\");\r\n }\r\n if (!defined(result)) {\r\n throw new DeveloperError(\"result is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var rtcCenter = Matrix4.getTranslation(matrix, scratchCenter);\r\n var ellipsoid = projection.ellipsoid;\r\n\r\n // Get the 2D Center\r\n var cartographic = ellipsoid.cartesianToCartographic(\r\n rtcCenter,\r\n scratchCartographic\r\n );\r\n var projectedPosition = projection.project(\r\n cartographic,\r\n scratchCartesian3Projection\r\n );\r\n Cartesian3.fromElements(\r\n projectedPosition.z,\r\n projectedPosition.x,\r\n projectedPosition.y,\r\n projectedPosition\r\n );\r\n\r\n // Assuming the instance are positioned in WGS84, invert the WGS84 transform to get the local transform and then convert to 2D\r\n var fromENU = Transforms.eastNorthUpToFixedFrame(\r\n rtcCenter,\r\n ellipsoid,\r\n scratchFromENU\r\n );\r\n var toENU = Matrix4.inverseTransformation(fromENU, scratchToENU);\r\n var rotation = Matrix4.getMatrix3(matrix, scratchRotation);\r\n var local = Matrix4.multiplyByMatrix3(toENU, rotation, result);\r\n Matrix4.multiply(swizzleMatrix, local, result); // Swap x, y, z for 2D\r\n Matrix4.setTranslation(result, projectedPosition, result); // Use the projected center\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * @private\r\n */\r\nTransforms.wgs84To2DModelMatrix = function (projection, center, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(projection)) {\r\n throw new DeveloperError(\"projection is required.\");\r\n }\r\n if (!defined(center)) {\r\n throw new DeveloperError(\"center is required.\");\r\n }\r\n if (!defined(result)) {\r\n throw new DeveloperError(\"result is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var ellipsoid = projection.ellipsoid;\r\n\r\n var fromENU = Transforms.eastNorthUpToFixedFrame(\r\n center,\r\n ellipsoid,\r\n scratchFromENU\r\n );\r\n var toENU = Matrix4.inverseTransformation(fromENU, scratchToENU);\r\n\r\n var cartographic = ellipsoid.cartesianToCartographic(\r\n center,\r\n scratchCartographic\r\n );\r\n var projectedPosition = projection.project(\r\n cartographic,\r\n scratchCartesian3Projection\r\n );\r\n Cartesian3.fromElements(\r\n projectedPosition.z,\r\n projectedPosition.x,\r\n projectedPosition.y,\r\n projectedPosition\r\n );\r\n\r\n var translation = Matrix4.fromTranslation(projectedPosition, scratchFromENU);\r\n Matrix4.multiply(swizzleMatrix, toENU, result);\r\n Matrix4.multiply(translation, result, result);\r\n\r\n return result;\r\n};\r\nexport default Transforms;\r\n","import AxisAlignedBoundingBox from \"./AxisAlignedBoundingBox.js\";\r\nimport Cartesian2 from \"./Cartesian2.js\";\r\nimport Cartesian3 from \"./Cartesian3.js\";\r\nimport Cartesian4 from \"./Cartesian4.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport Ellipsoid from \"./Ellipsoid.js\";\r\nimport IntersectionTests from \"./IntersectionTests.js\";\r\nimport Matrix4 from \"./Matrix4.js\";\r\nimport Plane from \"./Plane.js\";\r\nimport Ray from \"./Ray.js\";\r\nimport Transforms from \"./Transforms.js\";\r\n\r\nvar scratchCart4 = new Cartesian4();\r\n/**\r\n * A plane tangent to the provided ellipsoid at the provided origin.\r\n * If origin is not on the surface of the ellipsoid, it's surface projection will be used.\r\n * If origin is at the center of the ellipsoid, an exception will be thrown.\r\n * @alias EllipsoidTangentPlane\r\n * @constructor\r\n *\r\n * @param {Cartesian3} origin The point on the surface of the ellipsoid where the tangent plane touches.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid to use.\r\n *\r\n * @exception {DeveloperError} origin must not be at the center of the ellipsoid.\r\n */\r\nfunction EllipsoidTangentPlane(origin, ellipsoid) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"origin\", origin);\r\n //>>includeEnd('debug');\r\n\r\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\r\n origin = ellipsoid.scaleToGeodeticSurface(origin);\r\n\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(origin)) {\r\n throw new DeveloperError(\r\n \"origin must not be at the center of the ellipsoid.\"\r\n );\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var eastNorthUp = Transforms.eastNorthUpToFixedFrame(origin, ellipsoid);\r\n this._ellipsoid = ellipsoid;\r\n this._origin = origin;\r\n this._xAxis = Cartesian3.fromCartesian4(\r\n Matrix4.getColumn(eastNorthUp, 0, scratchCart4)\r\n );\r\n this._yAxis = Cartesian3.fromCartesian4(\r\n Matrix4.getColumn(eastNorthUp, 1, scratchCart4)\r\n );\r\n\r\n var normal = Cartesian3.fromCartesian4(\r\n Matrix4.getColumn(eastNorthUp, 2, scratchCart4)\r\n );\r\n this._plane = Plane.fromPointNormal(origin, normal);\r\n}\r\n\r\nObject.defineProperties(EllipsoidTangentPlane.prototype, {\r\n /**\r\n * Gets the ellipsoid.\r\n * @memberof EllipsoidTangentPlane.prototype\r\n * @type {Ellipsoid}\r\n */\r\n ellipsoid: {\r\n get: function () {\r\n return this._ellipsoid;\r\n },\r\n },\r\n\r\n /**\r\n * Gets the origin.\r\n * @memberof EllipsoidTangentPlane.prototype\r\n * @type {Cartesian3}\r\n */\r\n origin: {\r\n get: function () {\r\n return this._origin;\r\n },\r\n },\r\n\r\n /**\r\n * Gets the plane which is tangent to the ellipsoid.\r\n * @memberof EllipsoidTangentPlane.prototype\r\n * @readonly\r\n * @type {Plane}\r\n */\r\n plane: {\r\n get: function () {\r\n return this._plane;\r\n },\r\n },\r\n\r\n /**\r\n * Gets the local X-axis (east) of the tangent plane.\r\n * @memberof EllipsoidTangentPlane.prototype\r\n * @readonly\r\n * @type {Cartesian3}\r\n */\r\n xAxis: {\r\n get: function () {\r\n return this._xAxis;\r\n },\r\n },\r\n\r\n /**\r\n * Gets the local Y-axis (north) of the tangent plane.\r\n * @memberof EllipsoidTangentPlane.prototype\r\n * @readonly\r\n * @type {Cartesian3}\r\n */\r\n yAxis: {\r\n get: function () {\r\n return this._yAxis;\r\n },\r\n },\r\n\r\n /**\r\n * Gets the local Z-axis (up) of the tangent plane.\r\n * @memberof EllipsoidTangentPlane.prototype\r\n * @readonly\r\n * @type {Cartesian3}\r\n */\r\n zAxis: {\r\n get: function () {\r\n return this._plane.normal;\r\n },\r\n },\r\n});\r\n\r\nvar tmp = new AxisAlignedBoundingBox();\r\n/**\r\n * Creates a new instance from the provided ellipsoid and the center\r\n * point of the provided Cartesians.\r\n *\r\n * @param {Cartesian3[]} cartesians The list of positions surrounding the center point.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid to use.\r\n * @returns {EllipsoidTangentPlane} The new instance of EllipsoidTangentPlane.\r\n */\r\nEllipsoidTangentPlane.fromPoints = function (cartesians, ellipsoid) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"cartesians\", cartesians);\r\n //>>includeEnd('debug');\r\n\r\n var box = AxisAlignedBoundingBox.fromPoints(cartesians, tmp);\r\n return new EllipsoidTangentPlane(box.center, ellipsoid);\r\n};\r\n\r\nvar scratchProjectPointOntoPlaneRay = new Ray();\r\nvar scratchProjectPointOntoPlaneCartesian3 = new Cartesian3();\r\n\r\n/**\r\n * Computes the projection of the provided 3D position onto the 2D plane, radially outward from the {@link EllipsoidTangentPlane.ellipsoid} coordinate system origin.\r\n *\r\n * @param {Cartesian3} cartesian The point to project.\r\n * @param {Cartesian2} [result] The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if none was provided. Undefined if there is no intersection point\r\n */\r\nEllipsoidTangentPlane.prototype.projectPointOntoPlane = function (\r\n cartesian,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"cartesian\", cartesian);\r\n //>>includeEnd('debug');\r\n\r\n var ray = scratchProjectPointOntoPlaneRay;\r\n ray.origin = cartesian;\r\n Cartesian3.normalize(cartesian, ray.direction);\r\n\r\n var intersectionPoint = IntersectionTests.rayPlane(\r\n ray,\r\n this._plane,\r\n scratchProjectPointOntoPlaneCartesian3\r\n );\r\n if (!defined(intersectionPoint)) {\r\n Cartesian3.negate(ray.direction, ray.direction);\r\n intersectionPoint = IntersectionTests.rayPlane(\r\n ray,\r\n this._plane,\r\n scratchProjectPointOntoPlaneCartesian3\r\n );\r\n }\r\n\r\n if (defined(intersectionPoint)) {\r\n var v = Cartesian3.subtract(\r\n intersectionPoint,\r\n this._origin,\r\n intersectionPoint\r\n );\r\n var x = Cartesian3.dot(this._xAxis, v);\r\n var y = Cartesian3.dot(this._yAxis, v);\r\n\r\n if (!defined(result)) {\r\n return new Cartesian2(x, y);\r\n }\r\n result.x = x;\r\n result.y = y;\r\n return result;\r\n }\r\n return undefined;\r\n};\r\n\r\n/**\r\n * Computes the projection of the provided 3D positions onto the 2D plane (where possible), radially outward from the global origin.\r\n * The resulting array may be shorter than the input array - if a single projection is impossible it will not be included.\r\n *\r\n * @see EllipsoidTangentPlane.projectPointOntoPlane\r\n *\r\n * @param {Cartesian3[]} cartesians The array of points to project.\r\n * @param {Cartesian2[]} [result] The array of Cartesian2 instances onto which to store results.\r\n * @returns {Cartesian2[]} The modified result parameter or a new array of Cartesian2 instances if none was provided.\r\n */\r\nEllipsoidTangentPlane.prototype.projectPointsOntoPlane = function (\r\n cartesians,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"cartesians\", cartesians);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = [];\r\n }\r\n\r\n var count = 0;\r\n var length = cartesians.length;\r\n for (var i = 0; i < length; i++) {\r\n var p = this.projectPointOntoPlane(cartesians[i], result[count]);\r\n if (defined(p)) {\r\n result[count] = p;\r\n count++;\r\n }\r\n }\r\n result.length = count;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the projection of the provided 3D position onto the 2D plane, along the plane normal.\r\n *\r\n * @param {Cartesian3} cartesian The point to project.\r\n * @param {Cartesian2} [result] The object onto which to store the result.\r\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if none was provided.\r\n */\r\nEllipsoidTangentPlane.prototype.projectPointToNearestOnPlane = function (\r\n cartesian,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"cartesian\", cartesian);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian2();\r\n }\r\n\r\n var ray = scratchProjectPointOntoPlaneRay;\r\n ray.origin = cartesian;\r\n Cartesian3.clone(this._plane.normal, ray.direction);\r\n\r\n var intersectionPoint = IntersectionTests.rayPlane(\r\n ray,\r\n this._plane,\r\n scratchProjectPointOntoPlaneCartesian3\r\n );\r\n if (!defined(intersectionPoint)) {\r\n Cartesian3.negate(ray.direction, ray.direction);\r\n intersectionPoint = IntersectionTests.rayPlane(\r\n ray,\r\n this._plane,\r\n scratchProjectPointOntoPlaneCartesian3\r\n );\r\n }\r\n\r\n var v = Cartesian3.subtract(\r\n intersectionPoint,\r\n this._origin,\r\n intersectionPoint\r\n );\r\n var x = Cartesian3.dot(this._xAxis, v);\r\n var y = Cartesian3.dot(this._yAxis, v);\r\n\r\n result.x = x;\r\n result.y = y;\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the projection of the provided 3D positions onto the 2D plane, along the plane normal.\r\n *\r\n * @see EllipsoidTangentPlane.projectPointToNearestOnPlane\r\n *\r\n * @param {Cartesian3[]} cartesians The array of points to project.\r\n * @param {Cartesian2[]} [result] The array of Cartesian2 instances onto which to store results.\r\n * @returns {Cartesian2[]} The modified result parameter or a new array of Cartesian2 instances if none was provided. This will have the same length as cartesians
.\r\n */\r\nEllipsoidTangentPlane.prototype.projectPointsToNearestOnPlane = function (\r\n cartesians,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"cartesians\", cartesians);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = [];\r\n }\r\n\r\n var length = cartesians.length;\r\n result.length = length;\r\n for (var i = 0; i < length; i++) {\r\n result[i] = this.projectPointToNearestOnPlane(cartesians[i], result[i]);\r\n }\r\n return result;\r\n};\r\n\r\nvar projectPointsOntoEllipsoidScratch = new Cartesian3();\r\n/**\r\n * Computes the projection of the provided 2D position onto the 3D ellipsoid.\r\n *\r\n * @param {Cartesian2} cartesian The points to project.\r\n * @param {Cartesian3} [result] The Cartesian3 instance to store result.\r\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.\r\n */\r\nEllipsoidTangentPlane.prototype.projectPointOntoEllipsoid = function (\r\n cartesian,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"cartesian\", cartesian);\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n\r\n var ellipsoid = this._ellipsoid;\r\n var origin = this._origin;\r\n var xAxis = this._xAxis;\r\n var yAxis = this._yAxis;\r\n var tmp = projectPointsOntoEllipsoidScratch;\r\n\r\n Cartesian3.multiplyByScalar(xAxis, cartesian.x, tmp);\r\n result = Cartesian3.add(origin, tmp, result);\r\n Cartesian3.multiplyByScalar(yAxis, cartesian.y, tmp);\r\n Cartesian3.add(result, tmp, result);\r\n ellipsoid.scaleToGeocentricSurface(result, result);\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Computes the projection of the provided 2D positions onto the 3D ellipsoid.\r\n *\r\n * @param {Cartesian2[]} cartesians The array of points to project.\r\n * @param {Cartesian3[]} [result] The array of Cartesian3 instances onto which to store results.\r\n * @returns {Cartesian3[]} The modified result parameter or a new array of Cartesian3 instances if none was provided.\r\n */\r\nEllipsoidTangentPlane.prototype.projectPointsOntoEllipsoid = function (\r\n cartesians,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"cartesians\", cartesians);\r\n //>>includeEnd('debug');\r\n\r\n var length = cartesians.length;\r\n if (!defined(result)) {\r\n result = new Array(length);\r\n } else {\r\n result.length = length;\r\n }\r\n\r\n for (var i = 0; i < length; ++i) {\r\n result[i] = this.projectPointOntoEllipsoid(cartesians[i], result[i]);\r\n }\r\n\r\n return result;\r\n};\r\nexport default EllipsoidTangentPlane;\r\n","import BoundingSphere from \"./BoundingSphere.js\";\r\nimport Cartesian2 from \"./Cartesian2.js\";\r\nimport Cartesian3 from \"./Cartesian3.js\";\r\nimport Cartographic from \"./Cartographic.js\";\r\nimport Check from \"./Check.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport Ellipsoid from \"./Ellipsoid.js\";\r\nimport EllipsoidTangentPlane from \"./EllipsoidTangentPlane.js\";\r\nimport Intersect from \"./Intersect.js\";\r\nimport Interval from \"./Interval.js\";\r\nimport CesiumMath from \"./Math.js\";\r\nimport Matrix3 from \"./Matrix3.js\";\r\nimport Plane from \"./Plane.js\";\r\nimport Rectangle from \"./Rectangle.js\";\r\n\r\n/**\r\n * Creates an instance of an OrientedBoundingBox.\r\n * An OrientedBoundingBox of some object is a closed and convex cuboid. It can provide a tighter bounding volume than {@link BoundingSphere} or {@link AxisAlignedBoundingBox} in many cases.\r\n * @alias OrientedBoundingBox\r\n * @constructor\r\n *\r\n * @param {Cartesian3} [center=Cartesian3.ZERO] The center of the box.\r\n * @param {Matrix3} [halfAxes=Matrix3.ZERO] The three orthogonal half-axes of the bounding box.\r\n * Equivalently, the transformation matrix, to rotate and scale a 0x0x0\r\n * cube centered at the origin.\r\n *\r\n *\r\n * @example\r\n * // Create an OrientedBoundingBox using a transformation matrix, a position where the box will be translated, and a scale.\r\n * var center = new Cesium.Cartesian3(1.0, 0.0, 0.0);\r\n * var halfAxes = Cesium.Matrix3.fromScale(new Cesium.Cartesian3(1.0, 3.0, 2.0), new Cesium.Matrix3());\r\n *\r\n * var obb = new Cesium.OrientedBoundingBox(center, halfAxes);\r\n *\r\n * @see BoundingSphere\r\n * @see BoundingRectangle\r\n */\r\nfunction OrientedBoundingBox(center, halfAxes) {\r\n /**\r\n * The center of the box.\r\n * @type {Cartesian3}\r\n * @default {@link Cartesian3.ZERO}\r\n */\r\n this.center = Cartesian3.clone(defaultValue(center, Cartesian3.ZERO));\r\n /**\r\n * The transformation matrix, to rotate the box to the right position.\r\n * @type {Matrix3}\r\n * @default {@link Matrix3.ZERO}\r\n */\r\n this.halfAxes = Matrix3.clone(defaultValue(halfAxes, Matrix3.ZERO));\r\n}\r\n\r\n/**\r\n * The number of elements used to pack the object into an array.\r\n * @type {Number}\r\n */\r\nOrientedBoundingBox.packedLength =\r\n Cartesian3.packedLength + Matrix3.packedLength;\r\n\r\n/**\r\n * Stores the provided instance into the provided array.\r\n *\r\n * @param {OrientedBoundingBox} value The value to pack.\r\n * @param {Number[]} array The array to pack into.\r\n * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.\r\n *\r\n * @returns {Number[]} The array that was packed into\r\n */\r\nOrientedBoundingBox.pack = function (value, array, startingIndex) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"value\", value);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n Cartesian3.pack(value.center, array, startingIndex);\r\n Matrix3.pack(value.halfAxes, array, startingIndex + Cartesian3.packedLength);\r\n\r\n return array;\r\n};\r\n\r\n/**\r\n * Retrieves an instance from a packed array.\r\n *\r\n * @param {Number[]} array The packed array.\r\n * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.\r\n * @param {OrientedBoundingBox} [result] The object into which to store the result.\r\n * @returns {OrientedBoundingBox} The modified result parameter or a new OrientedBoundingBox instance if one was not provided.\r\n */\r\nOrientedBoundingBox.unpack = function (array, startingIndex, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"array\", array);\r\n //>>includeEnd('debug');\r\n\r\n startingIndex = defaultValue(startingIndex, 0);\r\n\r\n if (!defined(result)) {\r\n result = new OrientedBoundingBox();\r\n }\r\n\r\n Cartesian3.unpack(array, startingIndex, result.center);\r\n Matrix3.unpack(\r\n array,\r\n startingIndex + Cartesian3.packedLength,\r\n result.halfAxes\r\n );\r\n return result;\r\n};\r\n\r\nvar scratchCartesian1 = new Cartesian3();\r\nvar scratchCartesian2 = new Cartesian3();\r\nvar scratchCartesian3 = new Cartesian3();\r\nvar scratchCartesian4 = new Cartesian3();\r\nvar scratchCartesian5 = new Cartesian3();\r\nvar scratchCartesian6 = new Cartesian3();\r\nvar scratchCovarianceResult = new Matrix3();\r\nvar scratchEigenResult = {\r\n unitary: new Matrix3(),\r\n diagonal: new Matrix3(),\r\n};\r\n\r\n/**\r\n * Computes an instance of an OrientedBoundingBox of the given positions.\r\n * This is an implementation of Stefan Gottschalk's Collision Queries using Oriented Bounding Boxes solution (PHD thesis).\r\n * Reference: http://gamma.cs.unc.edu/users/gottschalk/main.pdf\r\n *\r\n * @param {Cartesian3[]} [positions] List of {@link Cartesian3} points that the bounding box will enclose.\r\n * @param {OrientedBoundingBox} [result] The object onto which to store the result.\r\n * @returns {OrientedBoundingBox} The modified result parameter or a new OrientedBoundingBox instance if one was not provided.\r\n *\r\n * @example\r\n * // Compute an object oriented bounding box enclosing two points.\r\n * var box = Cesium.OrientedBoundingBox.fromPoints([new Cesium.Cartesian3(2, 0, 0), new Cesium.Cartesian3(-2, 0, 0)]);\r\n */\r\nOrientedBoundingBox.fromPoints = function (positions, result) {\r\n if (!defined(result)) {\r\n result = new OrientedBoundingBox();\r\n }\r\n\r\n if (!defined(positions) || positions.length === 0) {\r\n result.halfAxes = Matrix3.ZERO;\r\n result.center = Cartesian3.ZERO;\r\n return result;\r\n }\r\n\r\n var i;\r\n var length = positions.length;\r\n\r\n var meanPoint = Cartesian3.clone(positions[0], scratchCartesian1);\r\n for (i = 1; i < length; i++) {\r\n Cartesian3.add(meanPoint, positions[i], meanPoint);\r\n }\r\n var invLength = 1.0 / length;\r\n Cartesian3.multiplyByScalar(meanPoint, invLength, meanPoint);\r\n\r\n var exx = 0.0;\r\n var exy = 0.0;\r\n var exz = 0.0;\r\n var eyy = 0.0;\r\n var eyz = 0.0;\r\n var ezz = 0.0;\r\n var p;\r\n\r\n for (i = 0; i < length; i++) {\r\n p = Cartesian3.subtract(positions[i], meanPoint, scratchCartesian2);\r\n exx += p.x * p.x;\r\n exy += p.x * p.y;\r\n exz += p.x * p.z;\r\n eyy += p.y * p.y;\r\n eyz += p.y * p.z;\r\n ezz += p.z * p.z;\r\n }\r\n\r\n exx *= invLength;\r\n exy *= invLength;\r\n exz *= invLength;\r\n eyy *= invLength;\r\n eyz *= invLength;\r\n ezz *= invLength;\r\n\r\n var covarianceMatrix = scratchCovarianceResult;\r\n covarianceMatrix[0] = exx;\r\n covarianceMatrix[1] = exy;\r\n covarianceMatrix[2] = exz;\r\n covarianceMatrix[3] = exy;\r\n covarianceMatrix[4] = eyy;\r\n covarianceMatrix[5] = eyz;\r\n covarianceMatrix[6] = exz;\r\n covarianceMatrix[7] = eyz;\r\n covarianceMatrix[8] = ezz;\r\n\r\n var eigenDecomposition = Matrix3.computeEigenDecomposition(\r\n covarianceMatrix,\r\n scratchEigenResult\r\n );\r\n var rotation = Matrix3.clone(eigenDecomposition.unitary, result.halfAxes);\r\n\r\n var v1 = Matrix3.getColumn(rotation, 0, scratchCartesian4);\r\n var v2 = Matrix3.getColumn(rotation, 1, scratchCartesian5);\r\n var v3 = Matrix3.getColumn(rotation, 2, scratchCartesian6);\r\n\r\n var u1 = -Number.MAX_VALUE;\r\n var u2 = -Number.MAX_VALUE;\r\n var u3 = -Number.MAX_VALUE;\r\n var l1 = Number.MAX_VALUE;\r\n var l2 = Number.MAX_VALUE;\r\n var l3 = Number.MAX_VALUE;\r\n\r\n for (i = 0; i < length; i++) {\r\n p = positions[i];\r\n u1 = Math.max(Cartesian3.dot(v1, p), u1);\r\n u2 = Math.max(Cartesian3.dot(v2, p), u2);\r\n u3 = Math.max(Cartesian3.dot(v3, p), u3);\r\n\r\n l1 = Math.min(Cartesian3.dot(v1, p), l1);\r\n l2 = Math.min(Cartesian3.dot(v2, p), l2);\r\n l3 = Math.min(Cartesian3.dot(v3, p), l3);\r\n }\r\n\r\n v1 = Cartesian3.multiplyByScalar(v1, 0.5 * (l1 + u1), v1);\r\n v2 = Cartesian3.multiplyByScalar(v2, 0.5 * (l2 + u2), v2);\r\n v3 = Cartesian3.multiplyByScalar(v3, 0.5 * (l3 + u3), v3);\r\n\r\n var center = Cartesian3.add(v1, v2, result.center);\r\n Cartesian3.add(center, v3, center);\r\n\r\n var scale = scratchCartesian3;\r\n scale.x = u1 - l1;\r\n scale.y = u2 - l2;\r\n scale.z = u3 - l3;\r\n Cartesian3.multiplyByScalar(scale, 0.5, scale);\r\n Matrix3.multiplyByScale(result.halfAxes, scale, result.halfAxes);\r\n\r\n return result;\r\n};\r\n\r\nvar scratchOffset = new Cartesian3();\r\nvar scratchScale = new Cartesian3();\r\nfunction fromPlaneExtents(\r\n planeOrigin,\r\n planeXAxis,\r\n planeYAxis,\r\n planeZAxis,\r\n minimumX,\r\n maximumX,\r\n minimumY,\r\n maximumY,\r\n minimumZ,\r\n maximumZ,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (\r\n !defined(minimumX) ||\r\n !defined(maximumX) ||\r\n !defined(minimumY) ||\r\n !defined(maximumY) ||\r\n !defined(minimumZ) ||\r\n !defined(maximumZ)\r\n ) {\r\n throw new DeveloperError(\r\n \"all extents (minimum/maximum X/Y/Z) are required.\"\r\n );\r\n }\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new OrientedBoundingBox();\r\n }\r\n\r\n var halfAxes = result.halfAxes;\r\n Matrix3.setColumn(halfAxes, 0, planeXAxis, halfAxes);\r\n Matrix3.setColumn(halfAxes, 1, planeYAxis, halfAxes);\r\n Matrix3.setColumn(halfAxes, 2, planeZAxis, halfAxes);\r\n\r\n var centerOffset = scratchOffset;\r\n centerOffset.x = (minimumX + maximumX) / 2.0;\r\n centerOffset.y = (minimumY + maximumY) / 2.0;\r\n centerOffset.z = (minimumZ + maximumZ) / 2.0;\r\n\r\n var scale = scratchScale;\r\n scale.x = (maximumX - minimumX) / 2.0;\r\n scale.y = (maximumY - minimumY) / 2.0;\r\n scale.z = (maximumZ - minimumZ) / 2.0;\r\n\r\n var center = result.center;\r\n centerOffset = Matrix3.multiplyByVector(halfAxes, centerOffset, centerOffset);\r\n Cartesian3.add(planeOrigin, centerOffset, center);\r\n Matrix3.multiplyByScale(halfAxes, scale, halfAxes);\r\n\r\n return result;\r\n}\r\n\r\nvar scratchRectangleCenterCartographic = new Cartographic();\r\nvar scratchRectangleCenter = new Cartesian3();\r\nvar scratchPerimeterCartographicNC = new Cartographic();\r\nvar scratchPerimeterCartographicNW = new Cartographic();\r\nvar scratchPerimeterCartographicCW = new Cartographic();\r\nvar scratchPerimeterCartographicSW = new Cartographic();\r\nvar scratchPerimeterCartographicSC = new Cartographic();\r\nvar scratchPerimeterCartesianNC = new Cartesian3();\r\nvar scratchPerimeterCartesianNW = new Cartesian3();\r\nvar scratchPerimeterCartesianCW = new Cartesian3();\r\nvar scratchPerimeterCartesianSW = new Cartesian3();\r\nvar scratchPerimeterCartesianSC = new Cartesian3();\r\nvar scratchPerimeterProjectedNC = new Cartesian2();\r\nvar scratchPerimeterProjectedNW = new Cartesian2();\r\nvar scratchPerimeterProjectedCW = new Cartesian2();\r\nvar scratchPerimeterProjectedSW = new Cartesian2();\r\nvar scratchPerimeterProjectedSC = new Cartesian2();\r\n\r\nvar scratchPlaneOrigin = new Cartesian3();\r\nvar scratchPlaneNormal = new Cartesian3();\r\nvar scratchPlaneXAxis = new Cartesian3();\r\nvar scratchHorizonCartesian = new Cartesian3();\r\nvar scratchHorizonProjected = new Cartesian2();\r\nvar scratchMaxY = new Cartesian3();\r\nvar scratchMinY = new Cartesian3();\r\nvar scratchZ = new Cartesian3();\r\nvar scratchPlane = new Plane(Cartesian3.UNIT_X, 0.0);\r\n\r\n/**\r\n * Computes an OrientedBoundingBox that bounds a {@link Rectangle} on the surface of an {@link Ellipsoid}.\r\n * There are no guarantees about the orientation of the bounding box.\r\n *\r\n * @param {Rectangle} rectangle The cartographic rectangle on the surface of the ellipsoid.\r\n * @param {Number} [minimumHeight=0.0] The minimum height (elevation) within the tile.\r\n * @param {Number} [maximumHeight=0.0] The maximum height (elevation) within the tile.\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the rectangle is defined.\r\n * @param {OrientedBoundingBox} [result] The object onto which to store the result.\r\n * @returns {OrientedBoundingBox} The modified result parameter or a new OrientedBoundingBox instance if none was provided.\r\n *\r\n * @exception {DeveloperError} rectangle.width must be between 0 and pi.\r\n * @exception {DeveloperError} rectangle.height must be between 0 and pi.\r\n * @exception {DeveloperError} ellipsoid must be an ellipsoid of revolution (radii.x == radii.y
)\r\n */\r\nOrientedBoundingBox.fromRectangle = function (\r\n rectangle,\r\n minimumHeight,\r\n maximumHeight,\r\n ellipsoid,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(rectangle)) {\r\n throw new DeveloperError(\"rectangle is required\");\r\n }\r\n if (rectangle.width < 0.0 || rectangle.width > CesiumMath.TWO_PI) {\r\n throw new DeveloperError(\"Rectangle width must be between 0 and 2*pi\");\r\n }\r\n if (rectangle.height < 0.0 || rectangle.height > CesiumMath.PI) {\r\n throw new DeveloperError(\"Rectangle height must be between 0 and pi\");\r\n }\r\n if (\r\n defined(ellipsoid) &&\r\n !CesiumMath.equalsEpsilon(\r\n ellipsoid.radii.x,\r\n ellipsoid.radii.y,\r\n CesiumMath.EPSILON15\r\n )\r\n ) {\r\n throw new DeveloperError(\r\n \"Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)\"\r\n );\r\n }\r\n //>>includeEnd('debug');\r\n\r\n minimumHeight = defaultValue(minimumHeight, 0.0);\r\n maximumHeight = defaultValue(maximumHeight, 0.0);\r\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\r\n\r\n var minX, maxX, minY, maxY, minZ, maxZ, plane;\r\n\r\n if (rectangle.width <= CesiumMath.PI) {\r\n // The bounding box will be aligned with the tangent plane at the center of the rectangle.\r\n var tangentPointCartographic = Rectangle.center(\r\n rectangle,\r\n scratchRectangleCenterCartographic\r\n );\r\n var tangentPoint = ellipsoid.cartographicToCartesian(\r\n tangentPointCartographic,\r\n scratchRectangleCenter\r\n );\r\n var tangentPlane = new EllipsoidTangentPlane(tangentPoint, ellipsoid);\r\n plane = tangentPlane.plane;\r\n\r\n // If the rectangle spans the equator, CW is instead aligned with the equator (because it sticks out the farthest at the equator).\r\n var lonCenter = tangentPointCartographic.longitude;\r\n var latCenter =\r\n rectangle.south < 0.0 && rectangle.north > 0.0\r\n ? 0.0\r\n : tangentPointCartographic.latitude;\r\n\r\n // Compute XY extents using the rectangle at maximum height\r\n var perimeterCartographicNC = Cartographic.fromRadians(\r\n lonCenter,\r\n rectangle.north,\r\n maximumHeight,\r\n scratchPerimeterCartographicNC\r\n );\r\n var perimeterCartographicNW = Cartographic.fromRadians(\r\n rectangle.west,\r\n rectangle.north,\r\n maximumHeight,\r\n scratchPerimeterCartographicNW\r\n );\r\n var perimeterCartographicCW = Cartographic.fromRadians(\r\n rectangle.west,\r\n latCenter,\r\n maximumHeight,\r\n scratchPerimeterCartographicCW\r\n );\r\n var perimeterCartographicSW = Cartographic.fromRadians(\r\n rectangle.west,\r\n rectangle.south,\r\n maximumHeight,\r\n scratchPerimeterCartographicSW\r\n );\r\n var perimeterCartographicSC = Cartographic.fromRadians(\r\n lonCenter,\r\n rectangle.south,\r\n maximumHeight,\r\n scratchPerimeterCartographicSC\r\n );\r\n\r\n var perimeterCartesianNC = ellipsoid.cartographicToCartesian(\r\n perimeterCartographicNC,\r\n scratchPerimeterCartesianNC\r\n );\r\n var perimeterCartesianNW = ellipsoid.cartographicToCartesian(\r\n perimeterCartographicNW,\r\n scratchPerimeterCartesianNW\r\n );\r\n var perimeterCartesianCW = ellipsoid.cartographicToCartesian(\r\n perimeterCartographicCW,\r\n scratchPerimeterCartesianCW\r\n );\r\n var perimeterCartesianSW = ellipsoid.cartographicToCartesian(\r\n perimeterCartographicSW,\r\n scratchPerimeterCartesianSW\r\n );\r\n var perimeterCartesianSC = ellipsoid.cartographicToCartesian(\r\n perimeterCartographicSC,\r\n scratchPerimeterCartesianSC\r\n );\r\n\r\n var perimeterProjectedNC = tangentPlane.projectPointToNearestOnPlane(\r\n perimeterCartesianNC,\r\n scratchPerimeterProjectedNC\r\n );\r\n var perimeterProjectedNW = tangentPlane.projectPointToNearestOnPlane(\r\n perimeterCartesianNW,\r\n scratchPerimeterProjectedNW\r\n );\r\n var perimeterProjectedCW = tangentPlane.projectPointToNearestOnPlane(\r\n perimeterCartesianCW,\r\n scratchPerimeterProjectedCW\r\n );\r\n var perimeterProjectedSW = tangentPlane.projectPointToNearestOnPlane(\r\n perimeterCartesianSW,\r\n scratchPerimeterProjectedSW\r\n );\r\n var perimeterProjectedSC = tangentPlane.projectPointToNearestOnPlane(\r\n perimeterCartesianSC,\r\n scratchPerimeterProjectedSC\r\n );\r\n\r\n minX = Math.min(\r\n perimeterProjectedNW.x,\r\n perimeterProjectedCW.x,\r\n perimeterProjectedSW.x\r\n );\r\n maxX = -minX; // symmetrical\r\n\r\n maxY = Math.max(perimeterProjectedNW.y, perimeterProjectedNC.y);\r\n minY = Math.min(perimeterProjectedSW.y, perimeterProjectedSC.y);\r\n\r\n // Compute minimum Z using the rectangle at minimum height, since it will be deeper than the maximum height\r\n perimeterCartographicNW.height = perimeterCartographicSW.height = minimumHeight;\r\n perimeterCartesianNW = ellipsoid.cartographicToCartesian(\r\n perimeterCartographicNW,\r\n scratchPerimeterCartesianNW\r\n );\r\n perimeterCartesianSW = ellipsoid.cartographicToCartesian(\r\n perimeterCartographicSW,\r\n scratchPerimeterCartesianSW\r\n );\r\n\r\n minZ = Math.min(\r\n Plane.getPointDistance(plane, perimeterCartesianNW),\r\n Plane.getPointDistance(plane, perimeterCartesianSW)\r\n );\r\n maxZ = maximumHeight; // Since the tangent plane touches the surface at height = 0, this is okay\r\n\r\n return fromPlaneExtents(\r\n tangentPlane.origin,\r\n tangentPlane.xAxis,\r\n tangentPlane.yAxis,\r\n tangentPlane.zAxis,\r\n minX,\r\n maxX,\r\n minY,\r\n maxY,\r\n minZ,\r\n maxZ,\r\n result\r\n );\r\n }\r\n\r\n // Handle the case where rectangle width is greater than PI (wraps around more than half the ellipsoid).\r\n var fullyAboveEquator = rectangle.south > 0.0;\r\n var fullyBelowEquator = rectangle.north < 0.0;\r\n var latitudeNearestToEquator = fullyAboveEquator\r\n ? rectangle.south\r\n : fullyBelowEquator\r\n ? rectangle.north\r\n : 0.0;\r\n var centerLongitude = Rectangle.center(\r\n rectangle,\r\n scratchRectangleCenterCartographic\r\n ).longitude;\r\n\r\n // Plane is located at the rectangle's center longitude and the rectangle's latitude that is closest to the equator. It rotates around the Z axis.\r\n // This results in a better fit than the obb approach for smaller rectangles, which orients with the rectangle's center normal.\r\n var planeOrigin = Cartesian3.fromRadians(\r\n centerLongitude,\r\n latitudeNearestToEquator,\r\n maximumHeight,\r\n ellipsoid,\r\n scratchPlaneOrigin\r\n );\r\n planeOrigin.z = 0.0; // center the plane on the equator to simpify plane normal calculation\r\n var isPole =\r\n Math.abs(planeOrigin.x) < CesiumMath.EPSILON10 &&\r\n Math.abs(planeOrigin.y) < CesiumMath.EPSILON10;\r\n var planeNormal = !isPole\r\n ? Cartesian3.normalize(planeOrigin, scratchPlaneNormal)\r\n : Cartesian3.UNIT_X;\r\n var planeYAxis = Cartesian3.UNIT_Z;\r\n var planeXAxis = Cartesian3.cross(planeNormal, planeYAxis, scratchPlaneXAxis);\r\n plane = Plane.fromPointNormal(planeOrigin, planeNormal, scratchPlane);\r\n\r\n // Get the horizon point relative to the center. This will be the farthest extent in the plane's X dimension.\r\n var horizonCartesian = Cartesian3.fromRadians(\r\n centerLongitude + CesiumMath.PI_OVER_TWO,\r\n latitudeNearestToEquator,\r\n maximumHeight,\r\n ellipsoid,\r\n scratchHorizonCartesian\r\n );\r\n maxX = Cartesian3.dot(\r\n Plane.projectPointOntoPlane(\r\n plane,\r\n horizonCartesian,\r\n scratchHorizonProjected\r\n ),\r\n planeXAxis\r\n );\r\n minX = -maxX; // symmetrical\r\n\r\n // Get the min and max Y, using the height that will give the largest extent\r\n maxY = Cartesian3.fromRadians(\r\n 0.0,\r\n rectangle.north,\r\n fullyBelowEquator ? minimumHeight : maximumHeight,\r\n ellipsoid,\r\n scratchMaxY\r\n ).z;\r\n minY = Cartesian3.fromRadians(\r\n 0.0,\r\n rectangle.south,\r\n fullyAboveEquator ? minimumHeight : maximumHeight,\r\n ellipsoid,\r\n scratchMinY\r\n ).z;\r\n\r\n var farZ = Cartesian3.fromRadians(\r\n rectangle.east,\r\n latitudeNearestToEquator,\r\n maximumHeight,\r\n ellipsoid,\r\n scratchZ\r\n );\r\n minZ = Plane.getPointDistance(plane, farZ);\r\n maxZ = 0.0; // plane origin starts at maxZ already\r\n\r\n // min and max are local to the plane axes\r\n return fromPlaneExtents(\r\n planeOrigin,\r\n planeXAxis,\r\n planeYAxis,\r\n planeNormal,\r\n minX,\r\n maxX,\r\n minY,\r\n maxY,\r\n minZ,\r\n maxZ,\r\n result\r\n );\r\n};\r\n\r\n/**\r\n * Duplicates a OrientedBoundingBox instance.\r\n *\r\n * @param {OrientedBoundingBox} box The bounding box to duplicate.\r\n * @param {OrientedBoundingBox} [result] The object onto which to store the result.\r\n * @returns {OrientedBoundingBox} The modified result parameter or a new OrientedBoundingBox instance if none was provided. (Returns undefined if box is undefined)\r\n */\r\nOrientedBoundingBox.clone = function (box, result) {\r\n if (!defined(box)) {\r\n return undefined;\r\n }\r\n\r\n if (!defined(result)) {\r\n return new OrientedBoundingBox(box.center, box.halfAxes);\r\n }\r\n\r\n Cartesian3.clone(box.center, result.center);\r\n Matrix3.clone(box.halfAxes, result.halfAxes);\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Determines which side of a plane the oriented bounding box is located.\r\n *\r\n * @param {OrientedBoundingBox} box The oriented bounding box to test.\r\n * @param {Plane} plane The plane to test against.\r\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire box is on the side of the plane\r\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire box is\r\n * on the opposite side, and {@link Intersect.INTERSECTING} if the box\r\n * intersects the plane.\r\n */\r\nOrientedBoundingBox.intersectPlane = function (box, plane) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(box)) {\r\n throw new DeveloperError(\"box is required.\");\r\n }\r\n\r\n if (!defined(plane)) {\r\n throw new DeveloperError(\"plane is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var center = box.center;\r\n var normal = plane.normal;\r\n var halfAxes = box.halfAxes;\r\n var normalX = normal.x,\r\n normalY = normal.y,\r\n normalZ = normal.z;\r\n // plane is used as if it is its normal; the first three components are assumed to be normalized\r\n var radEffective =\r\n Math.abs(\r\n normalX * halfAxes[Matrix3.COLUMN0ROW0] +\r\n normalY * halfAxes[Matrix3.COLUMN0ROW1] +\r\n normalZ * halfAxes[Matrix3.COLUMN0ROW2]\r\n ) +\r\n Math.abs(\r\n normalX * halfAxes[Matrix3.COLUMN1ROW0] +\r\n normalY * halfAxes[Matrix3.COLUMN1ROW1] +\r\n normalZ * halfAxes[Matrix3.COLUMN1ROW2]\r\n ) +\r\n Math.abs(\r\n normalX * halfAxes[Matrix3.COLUMN2ROW0] +\r\n normalY * halfAxes[Matrix3.COLUMN2ROW1] +\r\n normalZ * halfAxes[Matrix3.COLUMN2ROW2]\r\n );\r\n var distanceToPlane = Cartesian3.dot(normal, center) + plane.distance;\r\n\r\n if (distanceToPlane <= -radEffective) {\r\n // The entire box is on the negative side of the plane normal\r\n return Intersect.OUTSIDE;\r\n } else if (distanceToPlane >= radEffective) {\r\n // The entire box is on the positive side of the plane normal\r\n return Intersect.INSIDE;\r\n }\r\n return Intersect.INTERSECTING;\r\n};\r\n\r\nvar scratchCartesianU = new Cartesian3();\r\nvar scratchCartesianV = new Cartesian3();\r\nvar scratchCartesianW = new Cartesian3();\r\nvar scratchPPrime = new Cartesian3();\r\n\r\n/**\r\n * Computes the estimated distance squared from the closest point on a bounding box to a point.\r\n *\r\n * @param {OrientedBoundingBox} box The box.\r\n * @param {Cartesian3} cartesian The point\r\n * @returns {Number} The estimated distance squared from the bounding sphere to the point.\r\n *\r\n * @example\r\n * // Sort bounding boxes from back to front\r\n * boxes.sort(function(a, b) {\r\n * return Cesium.OrientedBoundingBox.distanceSquaredTo(b, camera.positionWC) - Cesium.OrientedBoundingBox.distanceSquaredTo(a, camera.positionWC);\r\n * });\r\n */\r\nOrientedBoundingBox.distanceSquaredTo = function (box, cartesian) {\r\n // See Geometric Tools for Computer Graphics 10.4.2\r\n\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(box)) {\r\n throw new DeveloperError(\"box is required.\");\r\n }\r\n if (!defined(cartesian)) {\r\n throw new DeveloperError(\"cartesian is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var offset = Cartesian3.subtract(cartesian, box.center, scratchOffset);\r\n\r\n var halfAxes = box.halfAxes;\r\n var u = Matrix3.getColumn(halfAxes, 0, scratchCartesianU);\r\n var v = Matrix3.getColumn(halfAxes, 1, scratchCartesianV);\r\n var w = Matrix3.getColumn(halfAxes, 2, scratchCartesianW);\r\n\r\n var uHalf = Cartesian3.magnitude(u);\r\n var vHalf = Cartesian3.magnitude(v);\r\n var wHalf = Cartesian3.magnitude(w);\r\n\r\n Cartesian3.normalize(u, u);\r\n Cartesian3.normalize(v, v);\r\n Cartesian3.normalize(w, w);\r\n\r\n var pPrime = scratchPPrime;\r\n pPrime.x = Cartesian3.dot(offset, u);\r\n pPrime.y = Cartesian3.dot(offset, v);\r\n pPrime.z = Cartesian3.dot(offset, w);\r\n\r\n var distanceSquared = 0.0;\r\n var d;\r\n\r\n if (pPrime.x < -uHalf) {\r\n d = pPrime.x + uHalf;\r\n distanceSquared += d * d;\r\n } else if (pPrime.x > uHalf) {\r\n d = pPrime.x - uHalf;\r\n distanceSquared += d * d;\r\n }\r\n\r\n if (pPrime.y < -vHalf) {\r\n d = pPrime.y + vHalf;\r\n distanceSquared += d * d;\r\n } else if (pPrime.y > vHalf) {\r\n d = pPrime.y - vHalf;\r\n distanceSquared += d * d;\r\n }\r\n\r\n if (pPrime.z < -wHalf) {\r\n d = pPrime.z + wHalf;\r\n distanceSquared += d * d;\r\n } else if (pPrime.z > wHalf) {\r\n d = pPrime.z - wHalf;\r\n distanceSquared += d * d;\r\n }\r\n\r\n return distanceSquared;\r\n};\r\n\r\nvar scratchCorner = new Cartesian3();\r\nvar scratchToCenter = new Cartesian3();\r\n\r\n/**\r\n * The distances calculated by the vector from the center of the bounding box to position projected onto direction.\r\n *
\r\n * If you imagine the infinite number of planes with normal direction, this computes the smallest distance to the\r\n * closest and farthest planes from position that intersect the bounding box.\r\n *\r\n * @param {OrientedBoundingBox} box The bounding box to calculate the distance to.\r\n * @param {Cartesian3} position The position to calculate the distance from.\r\n * @param {Cartesian3} direction The direction from position.\r\n * @param {Interval} [result] A Interval to store the nearest and farthest distances.\r\n * @returns {Interval} The nearest and farthest distances on the bounding box from position in direction.\r\n */\r\nOrientedBoundingBox.computePlaneDistances = function (\r\n box,\r\n position,\r\n direction,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(box)) {\r\n throw new DeveloperError(\"box is required.\");\r\n }\r\n\r\n if (!defined(position)) {\r\n throw new DeveloperError(\"position is required.\");\r\n }\r\n\r\n if (!defined(direction)) {\r\n throw new DeveloperError(\"direction is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n if (!defined(result)) {\r\n result = new Interval();\r\n }\r\n\r\n var minDist = Number.POSITIVE_INFINITY;\r\n var maxDist = Number.NEGATIVE_INFINITY;\r\n\r\n var center = box.center;\r\n var halfAxes = box.halfAxes;\r\n\r\n var u = Matrix3.getColumn(halfAxes, 0, scratchCartesianU);\r\n var v = Matrix3.getColumn(halfAxes, 1, scratchCartesianV);\r\n var w = Matrix3.getColumn(halfAxes, 2, scratchCartesianW);\r\n\r\n // project first corner\r\n var corner = Cartesian3.add(u, v, scratchCorner);\r\n Cartesian3.add(corner, w, corner);\r\n Cartesian3.add(corner, center, corner);\r\n\r\n var toCenter = Cartesian3.subtract(corner, position, scratchToCenter);\r\n var mag = Cartesian3.dot(direction, toCenter);\r\n\r\n minDist = Math.min(mag, minDist);\r\n maxDist = Math.max(mag, maxDist);\r\n\r\n // project second corner\r\n Cartesian3.add(center, u, corner);\r\n Cartesian3.add(corner, v, corner);\r\n Cartesian3.subtract(corner, w, corner);\r\n\r\n Cartesian3.subtract(corner, position, toCenter);\r\n mag = Cartesian3.dot(direction, toCenter);\r\n\r\n minDist = Math.min(mag, minDist);\r\n maxDist = Math.max(mag, maxDist);\r\n\r\n // project third corner\r\n Cartesian3.add(center, u, corner);\r\n Cartesian3.subtract(corner, v, corner);\r\n Cartesian3.add(corner, w, corner);\r\n\r\n Cartesian3.subtract(corner, position, toCenter);\r\n mag = Cartesian3.dot(direction, toCenter);\r\n\r\n minDist = Math.min(mag, minDist);\r\n maxDist = Math.max(mag, maxDist);\r\n\r\n // project fourth corner\r\n Cartesian3.add(center, u, corner);\r\n Cartesian3.subtract(corner, v, corner);\r\n Cartesian3.subtract(corner, w, corner);\r\n\r\n Cartesian3.subtract(corner, position, toCenter);\r\n mag = Cartesian3.dot(direction, toCenter);\r\n\r\n minDist = Math.min(mag, minDist);\r\n maxDist = Math.max(mag, maxDist);\r\n\r\n // project fifth corner\r\n Cartesian3.subtract(center, u, corner);\r\n Cartesian3.add(corner, v, corner);\r\n Cartesian3.add(corner, w, corner);\r\n\r\n Cartesian3.subtract(corner, position, toCenter);\r\n mag = Cartesian3.dot(direction, toCenter);\r\n\r\n minDist = Math.min(mag, minDist);\r\n maxDist = Math.max(mag, maxDist);\r\n\r\n // project sixth corner\r\n Cartesian3.subtract(center, u, corner);\r\n Cartesian3.add(corner, v, corner);\r\n Cartesian3.subtract(corner, w, corner);\r\n\r\n Cartesian3.subtract(corner, position, toCenter);\r\n mag = Cartesian3.dot(direction, toCenter);\r\n\r\n minDist = Math.min(mag, minDist);\r\n maxDist = Math.max(mag, maxDist);\r\n\r\n // project seventh corner\r\n Cartesian3.subtract(center, u, corner);\r\n Cartesian3.subtract(corner, v, corner);\r\n Cartesian3.add(corner, w, corner);\r\n\r\n Cartesian3.subtract(corner, position, toCenter);\r\n mag = Cartesian3.dot(direction, toCenter);\r\n\r\n minDist = Math.min(mag, minDist);\r\n maxDist = Math.max(mag, maxDist);\r\n\r\n // project eighth corner\r\n Cartesian3.subtract(center, u, corner);\r\n Cartesian3.subtract(corner, v, corner);\r\n Cartesian3.subtract(corner, w, corner);\r\n\r\n Cartesian3.subtract(corner, position, toCenter);\r\n mag = Cartesian3.dot(direction, toCenter);\r\n\r\n minDist = Math.min(mag, minDist);\r\n maxDist = Math.max(mag, maxDist);\r\n\r\n result.start = minDist;\r\n result.stop = maxDist;\r\n return result;\r\n};\r\n\r\nvar scratchBoundingSphere = new BoundingSphere();\r\n\r\n/**\r\n * Determines whether or not a bounding box is hidden from view by the occluder.\r\n *\r\n * @param {OrientedBoundingBox} box The bounding box surrounding the occludee object.\r\n * @param {Occluder} occluder The occluder.\r\n * @returns {Boolean} true
if the box is not visible; otherwise false
.\r\n */\r\nOrientedBoundingBox.isOccluded = function (box, occluder) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(box)) {\r\n throw new DeveloperError(\"box is required.\");\r\n }\r\n if (!defined(occluder)) {\r\n throw new DeveloperError(\"occluder is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var sphere = BoundingSphere.fromOrientedBoundingBox(\r\n box,\r\n scratchBoundingSphere\r\n );\r\n\r\n return !occluder.isBoundingSphereVisible(sphere);\r\n};\r\n\r\n/**\r\n * Determines which side of a plane the oriented bounding box is located.\r\n *\r\n * @param {Plane} plane The plane to test against.\r\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire box is on the side of the plane\r\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire box is\r\n * on the opposite side, and {@link Intersect.INTERSECTING} if the box\r\n * intersects the plane.\r\n */\r\nOrientedBoundingBox.prototype.intersectPlane = function (plane) {\r\n return OrientedBoundingBox.intersectPlane(this, plane);\r\n};\r\n\r\n/**\r\n * Computes the estimated distance squared from the closest point on a bounding box to a point.\r\n *\r\n * @param {Cartesian3} cartesian The point\r\n * @returns {Number} The estimated distance squared from the bounding sphere to the point.\r\n *\r\n * @example\r\n * // Sort bounding boxes from back to front\r\n * boxes.sort(function(a, b) {\r\n * return b.distanceSquaredTo(camera.positionWC) - a.distanceSquaredTo(camera.positionWC);\r\n * });\r\n */\r\nOrientedBoundingBox.prototype.distanceSquaredTo = function (cartesian) {\r\n return OrientedBoundingBox.distanceSquaredTo(this, cartesian);\r\n};\r\n\r\n/**\r\n * The distances calculated by the vector from the center of the bounding box to position projected onto direction.\r\n *
\r\n * If you imagine the infinite number of planes with normal direction, this computes the smallest distance to the\r\n * closest and farthest planes from position that intersect the bounding box.\r\n *\r\n * @param {Cartesian3} position The position to calculate the distance from.\r\n * @param {Cartesian3} direction The direction from position.\r\n * @param {Interval} [result] A Interval to store the nearest and farthest distances.\r\n * @returns {Interval} The nearest and farthest distances on the bounding box from position in direction.\r\n */\r\nOrientedBoundingBox.prototype.computePlaneDistances = function (\r\n position,\r\n direction,\r\n result\r\n) {\r\n return OrientedBoundingBox.computePlaneDistances(\r\n this,\r\n position,\r\n direction,\r\n result\r\n );\r\n};\r\n\r\n/**\r\n * Determines whether or not a bounding box is hidden from view by the occluder.\r\n *\r\n * @param {Occluder} occluder The occluder.\r\n * @returns {Boolean} true
if the sphere is not visible; otherwise false
.\r\n */\r\nOrientedBoundingBox.prototype.isOccluded = function (occluder) {\r\n return OrientedBoundingBox.isOccluded(this, occluder);\r\n};\r\n\r\n/**\r\n * Compares the provided OrientedBoundingBox componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {OrientedBoundingBox} left The first OrientedBoundingBox.\r\n * @param {OrientedBoundingBox} right The second OrientedBoundingBox.\r\n * @returns {Boolean} true
if left and right are equal, false
otherwise.\r\n */\r\nOrientedBoundingBox.equals = function (left, right) {\r\n return (\r\n left === right ||\r\n (defined(left) &&\r\n defined(right) &&\r\n Cartesian3.equals(left.center, right.center) &&\r\n Matrix3.equals(left.halfAxes, right.halfAxes))\r\n );\r\n};\r\n\r\n/**\r\n * Duplicates this OrientedBoundingBox instance.\r\n *\r\n * @param {OrientedBoundingBox} [result] The object onto which to store the result.\r\n * @returns {OrientedBoundingBox} The modified result parameter or a new OrientedBoundingBox instance if one was not provided.\r\n */\r\nOrientedBoundingBox.prototype.clone = function (result) {\r\n return OrientedBoundingBox.clone(this, result);\r\n};\r\n\r\n/**\r\n * Compares this OrientedBoundingBox against the provided OrientedBoundingBox componentwise and returns\r\n * true
if they are equal, false
otherwise.\r\n *\r\n * @param {OrientedBoundingBox} [right] The right hand side OrientedBoundingBox.\r\n * @returns {Boolean} true
if they are equal, false
otherwise.\r\n */\r\nOrientedBoundingBox.prototype.equals = function (right) {\r\n return OrientedBoundingBox.equals(this, right);\r\n};\r\nexport default OrientedBoundingBox;\r\n","import Cartesian2 from \"./Cartesian2.js\";\r\nimport Cartesian3 from \"./Cartesian3.js\";\r\nimport Check from \"./Check.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport CesiumMath from \"./Math.js\";\r\n\r\nvar RIGHT_SHIFT = 1.0 / 256.0;\r\nvar LEFT_SHIFT = 256.0;\r\n\r\n/**\r\n * Attribute compression and decompression functions.\r\n *\r\n * @namespace AttributeCompression\r\n *\r\n * @private\r\n */\r\nvar AttributeCompression = {};\r\n\r\n/**\r\n * Encodes a normalized vector into 2 SNORM values in the range of [0-rangeMax] following the 'oct' encoding.\r\n *\r\n * Oct encoding is a compact representation of unit length vectors.\r\n * The 'oct' encoding is described in \"A Survey of Efficient Representations of Independent Unit Vectors\",\r\n * Cigolle et al 2014: {@link http://jcgt.org/published/0003/02/01/}\r\n *\r\n * @param {Cartesian3} vector The normalized vector to be compressed into 2 component 'oct' encoding.\r\n * @param {Cartesian2} result The 2 component oct-encoded unit length vector.\r\n * @param {Number} rangeMax The maximum value of the SNORM range. The encoded vector is stored in log2(rangeMax+1) bits.\r\n * @returns {Cartesian2} The 2 component oct-encoded unit length vector.\r\n *\r\n * @exception {DeveloperError} vector must be normalized.\r\n *\r\n * @see AttributeCompression.octDecodeInRange\r\n */\r\nAttributeCompression.octEncodeInRange = function (vector, rangeMax, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"vector\", vector);\r\n Check.defined(\"result\", result);\r\n var magSquared = Cartesian3.magnitudeSquared(vector);\r\n if (Math.abs(magSquared - 1.0) > CesiumMath.EPSILON6) {\r\n throw new DeveloperError(\"vector must be normalized.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n result.x =\r\n vector.x / (Math.abs(vector.x) + Math.abs(vector.y) + Math.abs(vector.z));\r\n result.y =\r\n vector.y / (Math.abs(vector.x) + Math.abs(vector.y) + Math.abs(vector.z));\r\n if (vector.z < 0) {\r\n var x = result.x;\r\n var y = result.y;\r\n result.x = (1.0 - Math.abs(y)) * CesiumMath.signNotZero(x);\r\n result.y = (1.0 - Math.abs(x)) * CesiumMath.signNotZero(y);\r\n }\r\n\r\n result.x = CesiumMath.toSNorm(result.x, rangeMax);\r\n result.y = CesiumMath.toSNorm(result.y, rangeMax);\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Encodes a normalized vector into 2 SNORM values in the range of [0-255] following the 'oct' encoding.\r\n *\r\n * @param {Cartesian3} vector The normalized vector to be compressed into 2 byte 'oct' encoding.\r\n * @param {Cartesian2} result The 2 byte oct-encoded unit length vector.\r\n * @returns {Cartesian2} The 2 byte oct-encoded unit length vector.\r\n *\r\n * @exception {DeveloperError} vector must be normalized.\r\n *\r\n * @see AttributeCompression.octEncodeInRange\r\n * @see AttributeCompression.octDecode\r\n */\r\nAttributeCompression.octEncode = function (vector, result) {\r\n return AttributeCompression.octEncodeInRange(vector, 255, result);\r\n};\r\n\r\nvar octEncodeScratch = new Cartesian2();\r\nvar uint8ForceArray = new Uint8Array(1);\r\nfunction forceUint8(value) {\r\n uint8ForceArray[0] = value;\r\n return uint8ForceArray[0];\r\n}\r\n/**\r\n * @param {Cartesian3} vector The normalized vector to be compressed into 4 byte 'oct' encoding.\r\n * @param {Cartesian4} result The 4 byte oct-encoded unit length vector.\r\n * @returns {Cartesian4} The 4 byte oct-encoded unit length vector.\r\n *\r\n * @exception {DeveloperError} vector must be normalized.\r\n *\r\n * @see AttributeCompression.octEncodeInRange\r\n * @see AttributeCompression.octDecodeFromCartesian4\r\n */\r\nAttributeCompression.octEncodeToCartesian4 = function (vector, result) {\r\n AttributeCompression.octEncodeInRange(vector, 65535, octEncodeScratch);\r\n result.x = forceUint8(octEncodeScratch.x * RIGHT_SHIFT);\r\n result.y = forceUint8(octEncodeScratch.x);\r\n result.z = forceUint8(octEncodeScratch.y * RIGHT_SHIFT);\r\n result.w = forceUint8(octEncodeScratch.y);\r\n return result;\r\n};\r\n\r\n/**\r\n * Decodes a unit-length vector in 'oct' encoding to a normalized 3-component vector.\r\n *\r\n * @param {Number} x The x component of the oct-encoded unit length vector.\r\n * @param {Number} y The y component of the oct-encoded unit length vector.\r\n * @param {Number} rangeMax The maximum value of the SNORM range. The encoded vector is stored in log2(rangeMax+1) bits.\r\n * @param {Cartesian3} result The decoded and normalized vector\r\n * @returns {Cartesian3} The decoded and normalized vector.\r\n *\r\n * @exception {DeveloperError} x and y must be unsigned normalized integers between 0 and rangeMax.\r\n *\r\n * @see AttributeCompression.octEncodeInRange\r\n */\r\nAttributeCompression.octDecodeInRange = function (x, y, rangeMax, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"result\", result);\r\n if (x < 0 || x > rangeMax || y < 0 || y > rangeMax) {\r\n throw new DeveloperError(\r\n \"x and y must be unsigned normalized integers between 0 and \" + rangeMax\r\n );\r\n }\r\n //>>includeEnd('debug');\r\n\r\n result.x = CesiumMath.fromSNorm(x, rangeMax);\r\n result.y = CesiumMath.fromSNorm(y, rangeMax);\r\n result.z = 1.0 - (Math.abs(result.x) + Math.abs(result.y));\r\n\r\n if (result.z < 0.0) {\r\n var oldVX = result.x;\r\n result.x = (1.0 - Math.abs(result.y)) * CesiumMath.signNotZero(oldVX);\r\n result.y = (1.0 - Math.abs(oldVX)) * CesiumMath.signNotZero(result.y);\r\n }\r\n\r\n return Cartesian3.normalize(result, result);\r\n};\r\n\r\n/**\r\n * Decodes a unit-length vector in 2 byte 'oct' encoding to a normalized 3-component vector.\r\n *\r\n * @param {Number} x The x component of the oct-encoded unit length vector.\r\n * @param {Number} y The y component of the oct-encoded unit length vector.\r\n * @param {Cartesian3} result The decoded and normalized vector.\r\n * @returns {Cartesian3} The decoded and normalized vector.\r\n *\r\n * @exception {DeveloperError} x and y must be an unsigned normalized integer between 0 and 255.\r\n *\r\n * @see AttributeCompression.octDecodeInRange\r\n */\r\nAttributeCompression.octDecode = function (x, y, result) {\r\n return AttributeCompression.octDecodeInRange(x, y, 255, result);\r\n};\r\n\r\n/**\r\n * Decodes a unit-length vector in 4 byte 'oct' encoding to a normalized 3-component vector.\r\n *\r\n * @param {Cartesian4} encoded The oct-encoded unit length vector.\r\n * @param {Cartesian3} result The decoded and normalized vector.\r\n * @returns {Cartesian3} The decoded and normalized vector.\r\n *\r\n * @exception {DeveloperError} x, y, z, and w must be unsigned normalized integers between 0 and 255.\r\n *\r\n * @see AttributeCompression.octDecodeInRange\r\n * @see AttributeCompression.octEncodeToCartesian4\r\n */\r\nAttributeCompression.octDecodeFromCartesian4 = function (encoded, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.typeOf.object(\"encoded\", encoded);\r\n Check.typeOf.object(\"result\", result);\r\n //>>includeEnd('debug');\r\n var x = encoded.x;\r\n var y = encoded.y;\r\n var z = encoded.z;\r\n var w = encoded.w;\r\n //>>includeStart('debug', pragmas.debug);\r\n if (\r\n x < 0 ||\r\n x > 255 ||\r\n y < 0 ||\r\n y > 255 ||\r\n z < 0 ||\r\n z > 255 ||\r\n w < 0 ||\r\n w > 255\r\n ) {\r\n throw new DeveloperError(\r\n \"x, y, z, and w must be unsigned normalized integers between 0 and 255\"\r\n );\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var xOct16 = x * LEFT_SHIFT + y;\r\n var yOct16 = z * LEFT_SHIFT + w;\r\n return AttributeCompression.octDecodeInRange(xOct16, yOct16, 65535, result);\r\n};\r\n\r\n/**\r\n * Packs an oct encoded vector into a single floating-point number.\r\n *\r\n * @param {Cartesian2} encoded The oct encoded vector.\r\n * @returns {Number} The oct encoded vector packed into a single float.\r\n *\r\n */\r\nAttributeCompression.octPackFloat = function (encoded) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"encoded\", encoded);\r\n //>>includeEnd('debug');\r\n return 256.0 * encoded.x + encoded.y;\r\n};\r\n\r\nvar scratchEncodeCart2 = new Cartesian2();\r\n\r\n/**\r\n * Encodes a normalized vector into 2 SNORM values in the range of [0-255] following the 'oct' encoding and\r\n * stores those values in a single float-point number.\r\n *\r\n * @param {Cartesian3} vector The normalized vector to be compressed into 2 byte 'oct' encoding.\r\n * @returns {Number} The 2 byte oct-encoded unit length vector.\r\n *\r\n * @exception {DeveloperError} vector must be normalized.\r\n */\r\nAttributeCompression.octEncodeFloat = function (vector) {\r\n AttributeCompression.octEncode(vector, scratchEncodeCart2);\r\n return AttributeCompression.octPackFloat(scratchEncodeCart2);\r\n};\r\n\r\n/**\r\n * Decodes a unit-length vector in 'oct' encoding packed in a floating-point number to a normalized 3-component vector.\r\n *\r\n * @param {Number} value The oct-encoded unit length vector stored as a single floating-point number.\r\n * @param {Cartesian3} result The decoded and normalized vector\r\n * @returns {Cartesian3} The decoded and normalized vector.\r\n *\r\n */\r\nAttributeCompression.octDecodeFloat = function (value, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"value\", value);\r\n //>>includeEnd('debug');\r\n\r\n var temp = value / 256.0;\r\n var x = Math.floor(temp);\r\n var y = (temp - x) * 256.0;\r\n\r\n return AttributeCompression.octDecode(x, y, result);\r\n};\r\n\r\n/**\r\n * Encodes three normalized vectors into 6 SNORM values in the range of [0-255] following the 'oct' encoding and\r\n * packs those into two floating-point numbers.\r\n *\r\n * @param {Cartesian3} v1 A normalized vector to be compressed.\r\n * @param {Cartesian3} v2 A normalized vector to be compressed.\r\n * @param {Cartesian3} v3 A normalized vector to be compressed.\r\n * @param {Cartesian2} result The 'oct' encoded vectors packed into two floating-point numbers.\r\n * @returns {Cartesian2} The 'oct' encoded vectors packed into two floating-point numbers.\r\n *\r\n */\r\nAttributeCompression.octPack = function (v1, v2, v3, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"v1\", v1);\r\n Check.defined(\"v2\", v2);\r\n Check.defined(\"v3\", v3);\r\n Check.defined(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var encoded1 = AttributeCompression.octEncodeFloat(v1);\r\n var encoded2 = AttributeCompression.octEncodeFloat(v2);\r\n\r\n var encoded3 = AttributeCompression.octEncode(v3, scratchEncodeCart2);\r\n result.x = 65536.0 * encoded3.x + encoded1;\r\n result.y = 65536.0 * encoded3.y + encoded2;\r\n return result;\r\n};\r\n\r\n/**\r\n * Decodes three unit-length vectors in 'oct' encoding packed into a floating-point number to a normalized 3-component vector.\r\n *\r\n * @param {Cartesian2} packed The three oct-encoded unit length vectors stored as two floating-point number.\r\n * @param {Cartesian3} v1 One decoded and normalized vector.\r\n * @param {Cartesian3} v2 One decoded and normalized vector.\r\n * @param {Cartesian3} v3 One decoded and normalized vector.\r\n */\r\nAttributeCompression.octUnpack = function (packed, v1, v2, v3) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"packed\", packed);\r\n Check.defined(\"v1\", v1);\r\n Check.defined(\"v2\", v2);\r\n Check.defined(\"v3\", v3);\r\n //>>includeEnd('debug');\r\n\r\n var temp = packed.x / 65536.0;\r\n var x = Math.floor(temp);\r\n var encodedFloat1 = (temp - x) * 65536.0;\r\n\r\n temp = packed.y / 65536.0;\r\n var y = Math.floor(temp);\r\n var encodedFloat2 = (temp - y) * 65536.0;\r\n\r\n AttributeCompression.octDecodeFloat(encodedFloat1, v1);\r\n AttributeCompression.octDecodeFloat(encodedFloat2, v2);\r\n AttributeCompression.octDecode(x, y, v3);\r\n};\r\n\r\n/**\r\n * Pack texture coordinates into a single float. The texture coordinates will only preserve 12 bits of precision.\r\n *\r\n * @param {Cartesian2} textureCoordinates The texture coordinates to compress. Both coordinates must be in the range 0.0-1.0.\r\n * @returns {Number} The packed texture coordinates.\r\n *\r\n */\r\nAttributeCompression.compressTextureCoordinates = function (\r\n textureCoordinates\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"textureCoordinates\", textureCoordinates);\r\n //>>includeEnd('debug');\r\n\r\n // Move x and y to the range 0-4095;\r\n var x = (textureCoordinates.x * 4095.0) | 0;\r\n var y = (textureCoordinates.y * 4095.0) | 0;\r\n return 4096.0 * x + y;\r\n};\r\n\r\n/**\r\n * Decompresses texture coordinates that were packed into a single float.\r\n *\r\n * @param {Number} compressed The compressed texture coordinates.\r\n * @param {Cartesian2} result The decompressed texture coordinates.\r\n * @returns {Cartesian2} The modified result parameter.\r\n *\r\n */\r\nAttributeCompression.decompressTextureCoordinates = function (\r\n compressed,\r\n result\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"compressed\", compressed);\r\n Check.defined(\"result\", result);\r\n //>>includeEnd('debug');\r\n\r\n var temp = compressed / 4096.0;\r\n var xZeroTo4095 = Math.floor(temp);\r\n result.x = xZeroTo4095 / 4095.0;\r\n result.y = (compressed - xZeroTo4095 * 4096) / 4095;\r\n return result;\r\n};\r\n\r\nfunction zigZagDecode(value) {\r\n return (value >> 1) ^ -(value & 1);\r\n}\r\n\r\n/**\r\n * Decodes delta and ZigZag encoded vertices. This modifies the buffers in place.\r\n *\r\n * @param {Uint16Array} uBuffer The buffer view of u values.\r\n * @param {Uint16Array} vBuffer The buffer view of v values.\r\n * @param {Uint16Array} [heightBuffer] The buffer view of height values.\r\n *\r\n * @see {@link https://github.com/CesiumGS/quantized-mesh|quantized-mesh-1.0 terrain format}\r\n */\r\nAttributeCompression.zigZagDeltaDecode = function (\r\n uBuffer,\r\n vBuffer,\r\n heightBuffer\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n Check.defined(\"uBuffer\", uBuffer);\r\n Check.defined(\"vBuffer\", vBuffer);\r\n Check.typeOf.number.equals(\r\n \"uBuffer.length\",\r\n \"vBuffer.length\",\r\n uBuffer.length,\r\n vBuffer.length\r\n );\r\n if (defined(heightBuffer)) {\r\n Check.typeOf.number.equals(\r\n \"uBuffer.length\",\r\n \"heightBuffer.length\",\r\n uBuffer.length,\r\n heightBuffer.length\r\n );\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var count = uBuffer.length;\r\n\r\n var u = 0;\r\n var v = 0;\r\n var height = 0;\r\n\r\n for (var i = 0; i < count; ++i) {\r\n u += zigZagDecode(uBuffer[i]);\r\n v += zigZagDecode(vBuffer[i]);\r\n\r\n uBuffer[i] = u;\r\n vBuffer[i] = v;\r\n\r\n if (defined(heightBuffer)) {\r\n height += zigZagDecode(heightBuffer[i]);\r\n heightBuffer[i] = height;\r\n }\r\n }\r\n};\r\nexport default AttributeCompression;\r\n","/**\r\n * Enum containing WebGL Constant values by name.\r\n * for use without an active WebGL context, or in cases where certain constants are unavailable using the WebGL context\r\n * (For example, in [Safari 9]{@link https://github.com/CesiumGS/cesium/issues/2989}).\r\n *\r\n * These match the constants from the [WebGL 1.0]{@link https://www.khronos.org/registry/webgl/specs/latest/1.0/}\r\n * and [WebGL 2.0]{@link https://www.khronos.org/registry/webgl/specs/latest/2.0/}\r\n * specifications.\r\n *\r\n * @enum {Number}\r\n */\r\nvar WebGLConstants = {\r\n DEPTH_BUFFER_BIT: 0x00000100,\r\n STENCIL_BUFFER_BIT: 0x00000400,\r\n COLOR_BUFFER_BIT: 0x00004000,\r\n POINTS: 0x0000,\r\n LINES: 0x0001,\r\n LINE_LOOP: 0x0002,\r\n LINE_STRIP: 0x0003,\r\n TRIANGLES: 0x0004,\r\n TRIANGLE_STRIP: 0x0005,\r\n TRIANGLE_FAN: 0x0006,\r\n ZERO: 0,\r\n ONE: 1,\r\n SRC_COLOR: 0x0300,\r\n ONE_MINUS_SRC_COLOR: 0x0301,\r\n SRC_ALPHA: 0x0302,\r\n ONE_MINUS_SRC_ALPHA: 0x0303,\r\n DST_ALPHA: 0x0304,\r\n ONE_MINUS_DST_ALPHA: 0x0305,\r\n DST_COLOR: 0x0306,\r\n ONE_MINUS_DST_COLOR: 0x0307,\r\n SRC_ALPHA_SATURATE: 0x0308,\r\n FUNC_ADD: 0x8006,\r\n BLEND_EQUATION: 0x8009,\r\n BLEND_EQUATION_RGB: 0x8009, // same as BLEND_EQUATION\r\n BLEND_EQUATION_ALPHA: 0x883d,\r\n FUNC_SUBTRACT: 0x800a,\r\n FUNC_REVERSE_SUBTRACT: 0x800b,\r\n BLEND_DST_RGB: 0x80c8,\r\n BLEND_SRC_RGB: 0x80c9,\r\n BLEND_DST_ALPHA: 0x80ca,\r\n BLEND_SRC_ALPHA: 0x80cb,\r\n CONSTANT_COLOR: 0x8001,\r\n ONE_MINUS_CONSTANT_COLOR: 0x8002,\r\n CONSTANT_ALPHA: 0x8003,\r\n ONE_MINUS_CONSTANT_ALPHA: 0x8004,\r\n BLEND_COLOR: 0x8005,\r\n ARRAY_BUFFER: 0x8892,\r\n ELEMENT_ARRAY_BUFFER: 0x8893,\r\n ARRAY_BUFFER_BINDING: 0x8894,\r\n ELEMENT_ARRAY_BUFFER_BINDING: 0x8895,\r\n STREAM_DRAW: 0x88e0,\r\n STATIC_DRAW: 0x88e4,\r\n DYNAMIC_DRAW: 0x88e8,\r\n BUFFER_SIZE: 0x8764,\r\n BUFFER_USAGE: 0x8765,\r\n CURRENT_VERTEX_ATTRIB: 0x8626,\r\n FRONT: 0x0404,\r\n BACK: 0x0405,\r\n FRONT_AND_BACK: 0x0408,\r\n CULL_FACE: 0x0b44,\r\n BLEND: 0x0be2,\r\n DITHER: 0x0bd0,\r\n STENCIL_TEST: 0x0b90,\r\n DEPTH_TEST: 0x0b71,\r\n SCISSOR_TEST: 0x0c11,\r\n POLYGON_OFFSET_FILL: 0x8037,\r\n SAMPLE_ALPHA_TO_COVERAGE: 0x809e,\r\n SAMPLE_COVERAGE: 0x80a0,\r\n NO_ERROR: 0,\r\n INVALID_ENUM: 0x0500,\r\n INVALID_VALUE: 0x0501,\r\n INVALID_OPERATION: 0x0502,\r\n OUT_OF_MEMORY: 0x0505,\r\n CW: 0x0900,\r\n CCW: 0x0901,\r\n LINE_WIDTH: 0x0b21,\r\n ALIASED_POINT_SIZE_RANGE: 0x846d,\r\n ALIASED_LINE_WIDTH_RANGE: 0x846e,\r\n CULL_FACE_MODE: 0x0b45,\r\n FRONT_FACE: 0x0b46,\r\n DEPTH_RANGE: 0x0b70,\r\n DEPTH_WRITEMASK: 0x0b72,\r\n DEPTH_CLEAR_VALUE: 0x0b73,\r\n DEPTH_FUNC: 0x0b74,\r\n STENCIL_CLEAR_VALUE: 0x0b91,\r\n STENCIL_FUNC: 0x0b92,\r\n STENCIL_FAIL: 0x0b94,\r\n STENCIL_PASS_DEPTH_FAIL: 0x0b95,\r\n STENCIL_PASS_DEPTH_PASS: 0x0b96,\r\n STENCIL_REF: 0x0b97,\r\n STENCIL_VALUE_MASK: 0x0b93,\r\n STENCIL_WRITEMASK: 0x0b98,\r\n STENCIL_BACK_FUNC: 0x8800,\r\n STENCIL_BACK_FAIL: 0x8801,\r\n STENCIL_BACK_PASS_DEPTH_FAIL: 0x8802,\r\n STENCIL_BACK_PASS_DEPTH_PASS: 0x8803,\r\n STENCIL_BACK_REF: 0x8ca3,\r\n STENCIL_BACK_VALUE_MASK: 0x8ca4,\r\n STENCIL_BACK_WRITEMASK: 0x8ca5,\r\n VIEWPORT: 0x0ba2,\r\n SCISSOR_BOX: 0x0c10,\r\n COLOR_CLEAR_VALUE: 0x0c22,\r\n COLOR_WRITEMASK: 0x0c23,\r\n UNPACK_ALIGNMENT: 0x0cf5,\r\n PACK_ALIGNMENT: 0x0d05,\r\n MAX_TEXTURE_SIZE: 0x0d33,\r\n MAX_VIEWPORT_DIMS: 0x0d3a,\r\n SUBPIXEL_BITS: 0x0d50,\r\n RED_BITS: 0x0d52,\r\n GREEN_BITS: 0x0d53,\r\n BLUE_BITS: 0x0d54,\r\n ALPHA_BITS: 0x0d55,\r\n DEPTH_BITS: 0x0d56,\r\n STENCIL_BITS: 0x0d57,\r\n POLYGON_OFFSET_UNITS: 0x2a00,\r\n POLYGON_OFFSET_FACTOR: 0x8038,\r\n TEXTURE_BINDING_2D: 0x8069,\r\n SAMPLE_BUFFERS: 0x80a8,\r\n SAMPLES: 0x80a9,\r\n SAMPLE_COVERAGE_VALUE: 0x80aa,\r\n SAMPLE_COVERAGE_INVERT: 0x80ab,\r\n COMPRESSED_TEXTURE_FORMATS: 0x86a3,\r\n DONT_CARE: 0x1100,\r\n FASTEST: 0x1101,\r\n NICEST: 0x1102,\r\n GENERATE_MIPMAP_HINT: 0x8192,\r\n BYTE: 0x1400,\r\n UNSIGNED_BYTE: 0x1401,\r\n SHORT: 0x1402,\r\n UNSIGNED_SHORT: 0x1403,\r\n INT: 0x1404,\r\n UNSIGNED_INT: 0x1405,\r\n FLOAT: 0x1406,\r\n DEPTH_COMPONENT: 0x1902,\r\n ALPHA: 0x1906,\r\n RGB: 0x1907,\r\n RGBA: 0x1908,\r\n LUMINANCE: 0x1909,\r\n LUMINANCE_ALPHA: 0x190a,\r\n UNSIGNED_SHORT_4_4_4_4: 0x8033,\r\n UNSIGNED_SHORT_5_5_5_1: 0x8034,\r\n UNSIGNED_SHORT_5_6_5: 0x8363,\r\n FRAGMENT_SHADER: 0x8b30,\r\n VERTEX_SHADER: 0x8b31,\r\n MAX_VERTEX_ATTRIBS: 0x8869,\r\n MAX_VERTEX_UNIFORM_VECTORS: 0x8dfb,\r\n MAX_VARYING_VECTORS: 0x8dfc,\r\n MAX_COMBINED_TEXTURE_IMAGE_UNITS: 0x8b4d,\r\n MAX_VERTEX_TEXTURE_IMAGE_UNITS: 0x8b4c,\r\n MAX_TEXTURE_IMAGE_UNITS: 0x8872,\r\n MAX_FRAGMENT_UNIFORM_VECTORS: 0x8dfd,\r\n SHADER_TYPE: 0x8b4f,\r\n DELETE_STATUS: 0x8b80,\r\n LINK_STATUS: 0x8b82,\r\n VALIDATE_STATUS: 0x8b83,\r\n ATTACHED_SHADERS: 0x8b85,\r\n ACTIVE_UNIFORMS: 0x8b86,\r\n ACTIVE_ATTRIBUTES: 0x8b89,\r\n SHADING_LANGUAGE_VERSION: 0x8b8c,\r\n CURRENT_PROGRAM: 0x8b8d,\r\n NEVER: 0x0200,\r\n LESS: 0x0201,\r\n EQUAL: 0x0202,\r\n LEQUAL: 0x0203,\r\n GREATER: 0x0204,\r\n NOTEQUAL: 0x0205,\r\n GEQUAL: 0x0206,\r\n ALWAYS: 0x0207,\r\n KEEP: 0x1e00,\r\n REPLACE: 0x1e01,\r\n INCR: 0x1e02,\r\n DECR: 0x1e03,\r\n INVERT: 0x150a,\r\n INCR_WRAP: 0x8507,\r\n DECR_WRAP: 0x8508,\r\n VENDOR: 0x1f00,\r\n RENDERER: 0x1f01,\r\n VERSION: 0x1f02,\r\n NEAREST: 0x2600,\r\n LINEAR: 0x2601,\r\n NEAREST_MIPMAP_NEAREST: 0x2700,\r\n LINEAR_MIPMAP_NEAREST: 0x2701,\r\n NEAREST_MIPMAP_LINEAR: 0x2702,\r\n LINEAR_MIPMAP_LINEAR: 0x2703,\r\n TEXTURE_MAG_FILTER: 0x2800,\r\n TEXTURE_MIN_FILTER: 0x2801,\r\n TEXTURE_WRAP_S: 0x2802,\r\n TEXTURE_WRAP_T: 0x2803,\r\n TEXTURE_2D: 0x0de1,\r\n TEXTURE: 0x1702,\r\n TEXTURE_CUBE_MAP: 0x8513,\r\n TEXTURE_BINDING_CUBE_MAP: 0x8514,\r\n TEXTURE_CUBE_MAP_POSITIVE_X: 0x8515,\r\n TEXTURE_CUBE_MAP_NEGATIVE_X: 0x8516,\r\n TEXTURE_CUBE_MAP_POSITIVE_Y: 0x8517,\r\n TEXTURE_CUBE_MAP_NEGATIVE_Y: 0x8518,\r\n TEXTURE_CUBE_MAP_POSITIVE_Z: 0x8519,\r\n TEXTURE_CUBE_MAP_NEGATIVE_Z: 0x851a,\r\n MAX_CUBE_MAP_TEXTURE_SIZE: 0x851c,\r\n TEXTURE0: 0x84c0,\r\n TEXTURE1: 0x84c1,\r\n TEXTURE2: 0x84c2,\r\n TEXTURE3: 0x84c3,\r\n TEXTURE4: 0x84c4,\r\n TEXTURE5: 0x84c5,\r\n TEXTURE6: 0x84c6,\r\n TEXTURE7: 0x84c7,\r\n TEXTURE8: 0x84c8,\r\n TEXTURE9: 0x84c9,\r\n TEXTURE10: 0x84ca,\r\n TEXTURE11: 0x84cb,\r\n TEXTURE12: 0x84cc,\r\n TEXTURE13: 0x84cd,\r\n TEXTURE14: 0x84ce,\r\n TEXTURE15: 0x84cf,\r\n TEXTURE16: 0x84d0,\r\n TEXTURE17: 0x84d1,\r\n TEXTURE18: 0x84d2,\r\n TEXTURE19: 0x84d3,\r\n TEXTURE20: 0x84d4,\r\n TEXTURE21: 0x84d5,\r\n TEXTURE22: 0x84d6,\r\n TEXTURE23: 0x84d7,\r\n TEXTURE24: 0x84d8,\r\n TEXTURE25: 0x84d9,\r\n TEXTURE26: 0x84da,\r\n TEXTURE27: 0x84db,\r\n TEXTURE28: 0x84dc,\r\n TEXTURE29: 0x84dd,\r\n TEXTURE30: 0x84de,\r\n TEXTURE31: 0x84df,\r\n ACTIVE_TEXTURE: 0x84e0,\r\n REPEAT: 0x2901,\r\n CLAMP_TO_EDGE: 0x812f,\r\n MIRRORED_REPEAT: 0x8370,\r\n FLOAT_VEC2: 0x8b50,\r\n FLOAT_VEC3: 0x8b51,\r\n FLOAT_VEC4: 0x8b52,\r\n INT_VEC2: 0x8b53,\r\n INT_VEC3: 0x8b54,\r\n INT_VEC4: 0x8b55,\r\n BOOL: 0x8b56,\r\n BOOL_VEC2: 0x8b57,\r\n BOOL_VEC3: 0x8b58,\r\n BOOL_VEC4: 0x8b59,\r\n FLOAT_MAT2: 0x8b5a,\r\n FLOAT_MAT3: 0x8b5b,\r\n FLOAT_MAT4: 0x8b5c,\r\n SAMPLER_2D: 0x8b5e,\r\n SAMPLER_CUBE: 0x8b60,\r\n VERTEX_ATTRIB_ARRAY_ENABLED: 0x8622,\r\n VERTEX_ATTRIB_ARRAY_SIZE: 0x8623,\r\n VERTEX_ATTRIB_ARRAY_STRIDE: 0x8624,\r\n VERTEX_ATTRIB_ARRAY_TYPE: 0x8625,\r\n VERTEX_ATTRIB_ARRAY_NORMALIZED: 0x886a,\r\n VERTEX_ATTRIB_ARRAY_POINTER: 0x8645,\r\n VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: 0x889f,\r\n IMPLEMENTATION_COLOR_READ_TYPE: 0x8b9a,\r\n IMPLEMENTATION_COLOR_READ_FORMAT: 0x8b9b,\r\n COMPILE_STATUS: 0x8b81,\r\n LOW_FLOAT: 0x8df0,\r\n MEDIUM_FLOAT: 0x8df1,\r\n HIGH_FLOAT: 0x8df2,\r\n LOW_INT: 0x8df3,\r\n MEDIUM_INT: 0x8df4,\r\n HIGH_INT: 0x8df5,\r\n FRAMEBUFFER: 0x8d40,\r\n RENDERBUFFER: 0x8d41,\r\n RGBA4: 0x8056,\r\n RGB5_A1: 0x8057,\r\n RGB565: 0x8d62,\r\n DEPTH_COMPONENT16: 0x81a5,\r\n STENCIL_INDEX: 0x1901,\r\n STENCIL_INDEX8: 0x8d48,\r\n DEPTH_STENCIL: 0x84f9,\r\n RENDERBUFFER_WIDTH: 0x8d42,\r\n RENDERBUFFER_HEIGHT: 0x8d43,\r\n RENDERBUFFER_INTERNAL_FORMAT: 0x8d44,\r\n RENDERBUFFER_RED_SIZE: 0x8d50,\r\n RENDERBUFFER_GREEN_SIZE: 0x8d51,\r\n RENDERBUFFER_BLUE_SIZE: 0x8d52,\r\n RENDERBUFFER_ALPHA_SIZE: 0x8d53,\r\n RENDERBUFFER_DEPTH_SIZE: 0x8d54,\r\n RENDERBUFFER_STENCIL_SIZE: 0x8d55,\r\n FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: 0x8cd0,\r\n FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: 0x8cd1,\r\n FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: 0x8cd2,\r\n FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: 0x8cd3,\r\n COLOR_ATTACHMENT0: 0x8ce0,\r\n DEPTH_ATTACHMENT: 0x8d00,\r\n STENCIL_ATTACHMENT: 0x8d20,\r\n DEPTH_STENCIL_ATTACHMENT: 0x821a,\r\n NONE: 0,\r\n FRAMEBUFFER_COMPLETE: 0x8cd5,\r\n FRAMEBUFFER_INCOMPLETE_ATTACHMENT: 0x8cd6,\r\n FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: 0x8cd7,\r\n FRAMEBUFFER_INCOMPLETE_DIMENSIONS: 0x8cd9,\r\n FRAMEBUFFER_UNSUPPORTED: 0x8cdd,\r\n FRAMEBUFFER_BINDING: 0x8ca6,\r\n RENDERBUFFER_BINDING: 0x8ca7,\r\n MAX_RENDERBUFFER_SIZE: 0x84e8,\r\n INVALID_FRAMEBUFFER_OPERATION: 0x0506,\r\n UNPACK_FLIP_Y_WEBGL: 0x9240,\r\n UNPACK_PREMULTIPLY_ALPHA_WEBGL: 0x9241,\r\n CONTEXT_LOST_WEBGL: 0x9242,\r\n UNPACK_COLORSPACE_CONVERSION_WEBGL: 0x9243,\r\n BROWSER_DEFAULT_WEBGL: 0x9244,\r\n\r\n // WEBGL_compressed_texture_s3tc\r\n COMPRESSED_RGB_S3TC_DXT1_EXT: 0x83f0,\r\n COMPRESSED_RGBA_S3TC_DXT1_EXT: 0x83f1,\r\n COMPRESSED_RGBA_S3TC_DXT3_EXT: 0x83f2,\r\n COMPRESSED_RGBA_S3TC_DXT5_EXT: 0x83f3,\r\n\r\n // WEBGL_compressed_texture_pvrtc\r\n COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 0x8c00,\r\n COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 0x8c01,\r\n COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 0x8c02,\r\n COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 0x8c03,\r\n\r\n // WEBGL_compressed_texture_etc1\r\n COMPRESSED_RGB_ETC1_WEBGL: 0x8d64,\r\n\r\n // EXT_color_buffer_half_float\r\n HALF_FLOAT_OES: 0x8d61,\r\n\r\n // Desktop OpenGL\r\n DOUBLE: 0x140a,\r\n\r\n // WebGL 2\r\n READ_BUFFER: 0x0c02,\r\n UNPACK_ROW_LENGTH: 0x0cf2,\r\n UNPACK_SKIP_ROWS: 0x0cf3,\r\n UNPACK_SKIP_PIXELS: 0x0cf4,\r\n PACK_ROW_LENGTH: 0x0d02,\r\n PACK_SKIP_ROWS: 0x0d03,\r\n PACK_SKIP_PIXELS: 0x0d04,\r\n COLOR: 0x1800,\r\n DEPTH: 0x1801,\r\n STENCIL: 0x1802,\r\n RED: 0x1903,\r\n RGB8: 0x8051,\r\n RGBA8: 0x8058,\r\n RGB10_A2: 0x8059,\r\n TEXTURE_BINDING_3D: 0x806a,\r\n UNPACK_SKIP_IMAGES: 0x806d,\r\n UNPACK_IMAGE_HEIGHT: 0x806e,\r\n TEXTURE_3D: 0x806f,\r\n TEXTURE_WRAP_R: 0x8072,\r\n MAX_3D_TEXTURE_SIZE: 0x8073,\r\n UNSIGNED_INT_2_10_10_10_REV: 0x8368,\r\n MAX_ELEMENTS_VERTICES: 0x80e8,\r\n MAX_ELEMENTS_INDICES: 0x80e9,\r\n TEXTURE_MIN_LOD: 0x813a,\r\n TEXTURE_MAX_LOD: 0x813b,\r\n TEXTURE_BASE_LEVEL: 0x813c,\r\n TEXTURE_MAX_LEVEL: 0x813d,\r\n MIN: 0x8007,\r\n MAX: 0x8008,\r\n DEPTH_COMPONENT24: 0x81a6,\r\n MAX_TEXTURE_LOD_BIAS: 0x84fd,\r\n TEXTURE_COMPARE_MODE: 0x884c,\r\n TEXTURE_COMPARE_FUNC: 0x884d,\r\n CURRENT_QUERY: 0x8865,\r\n QUERY_RESULT: 0x8866,\r\n QUERY_RESULT_AVAILABLE: 0x8867,\r\n STREAM_READ: 0x88e1,\r\n STREAM_COPY: 0x88e2,\r\n STATIC_READ: 0x88e5,\r\n STATIC_COPY: 0x88e6,\r\n DYNAMIC_READ: 0x88e9,\r\n DYNAMIC_COPY: 0x88ea,\r\n MAX_DRAW_BUFFERS: 0x8824,\r\n DRAW_BUFFER0: 0x8825,\r\n DRAW_BUFFER1: 0x8826,\r\n DRAW_BUFFER2: 0x8827,\r\n DRAW_BUFFER3: 0x8828,\r\n DRAW_BUFFER4: 0x8829,\r\n DRAW_BUFFER5: 0x882a,\r\n DRAW_BUFFER6: 0x882b,\r\n DRAW_BUFFER7: 0x882c,\r\n DRAW_BUFFER8: 0x882d,\r\n DRAW_BUFFER9: 0x882e,\r\n DRAW_BUFFER10: 0x882f,\r\n DRAW_BUFFER11: 0x8830,\r\n DRAW_BUFFER12: 0x8831,\r\n DRAW_BUFFER13: 0x8832,\r\n DRAW_BUFFER14: 0x8833,\r\n DRAW_BUFFER15: 0x8834,\r\n MAX_FRAGMENT_UNIFORM_COMPONENTS: 0x8b49,\r\n MAX_VERTEX_UNIFORM_COMPONENTS: 0x8b4a,\r\n SAMPLER_3D: 0x8b5f,\r\n SAMPLER_2D_SHADOW: 0x8b62,\r\n FRAGMENT_SHADER_DERIVATIVE_HINT: 0x8b8b,\r\n PIXEL_PACK_BUFFER: 0x88eb,\r\n PIXEL_UNPACK_BUFFER: 0x88ec,\r\n PIXEL_PACK_BUFFER_BINDING: 0x88ed,\r\n PIXEL_UNPACK_BUFFER_BINDING: 0x88ef,\r\n FLOAT_MAT2x3: 0x8b65,\r\n FLOAT_MAT2x4: 0x8b66,\r\n FLOAT_MAT3x2: 0x8b67,\r\n FLOAT_MAT3x4: 0x8b68,\r\n FLOAT_MAT4x2: 0x8b69,\r\n FLOAT_MAT4x3: 0x8b6a,\r\n SRGB: 0x8c40,\r\n SRGB8: 0x8c41,\r\n SRGB8_ALPHA8: 0x8c43,\r\n COMPARE_REF_TO_TEXTURE: 0x884e,\r\n RGBA32F: 0x8814,\r\n RGB32F: 0x8815,\r\n RGBA16F: 0x881a,\r\n RGB16F: 0x881b,\r\n VERTEX_ATTRIB_ARRAY_INTEGER: 0x88fd,\r\n MAX_ARRAY_TEXTURE_LAYERS: 0x88ff,\r\n MIN_PROGRAM_TEXEL_OFFSET: 0x8904,\r\n MAX_PROGRAM_TEXEL_OFFSET: 0x8905,\r\n MAX_VARYING_COMPONENTS: 0x8b4b,\r\n TEXTURE_2D_ARRAY: 0x8c1a,\r\n TEXTURE_BINDING_2D_ARRAY: 0x8c1d,\r\n R11F_G11F_B10F: 0x8c3a,\r\n UNSIGNED_INT_10F_11F_11F_REV: 0x8c3b,\r\n RGB9_E5: 0x8c3d,\r\n UNSIGNED_INT_5_9_9_9_REV: 0x8c3e,\r\n TRANSFORM_FEEDBACK_BUFFER_MODE: 0x8c7f,\r\n MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS: 0x8c80,\r\n TRANSFORM_FEEDBACK_VARYINGS: 0x8c83,\r\n TRANSFORM_FEEDBACK_BUFFER_START: 0x8c84,\r\n TRANSFORM_FEEDBACK_BUFFER_SIZE: 0x8c85,\r\n TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: 0x8c88,\r\n RASTERIZER_DISCARD: 0x8c89,\r\n MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS: 0x8c8a,\r\n MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS: 0x8c8b,\r\n INTERLEAVED_ATTRIBS: 0x8c8c,\r\n SEPARATE_ATTRIBS: 0x8c8d,\r\n TRANSFORM_FEEDBACK_BUFFER: 0x8c8e,\r\n TRANSFORM_FEEDBACK_BUFFER_BINDING: 0x8c8f,\r\n RGBA32UI: 0x8d70,\r\n RGB32UI: 0x8d71,\r\n RGBA16UI: 0x8d76,\r\n RGB16UI: 0x8d77,\r\n RGBA8UI: 0x8d7c,\r\n RGB8UI: 0x8d7d,\r\n RGBA32I: 0x8d82,\r\n RGB32I: 0x8d83,\r\n RGBA16I: 0x8d88,\r\n RGB16I: 0x8d89,\r\n RGBA8I: 0x8d8e,\r\n RGB8I: 0x8d8f,\r\n RED_INTEGER: 0x8d94,\r\n RGB_INTEGER: 0x8d98,\r\n RGBA_INTEGER: 0x8d99,\r\n SAMPLER_2D_ARRAY: 0x8dc1,\r\n SAMPLER_2D_ARRAY_SHADOW: 0x8dc4,\r\n SAMPLER_CUBE_SHADOW: 0x8dc5,\r\n UNSIGNED_INT_VEC2: 0x8dc6,\r\n UNSIGNED_INT_VEC3: 0x8dc7,\r\n UNSIGNED_INT_VEC4: 0x8dc8,\r\n INT_SAMPLER_2D: 0x8dca,\r\n INT_SAMPLER_3D: 0x8dcb,\r\n INT_SAMPLER_CUBE: 0x8dcc,\r\n INT_SAMPLER_2D_ARRAY: 0x8dcf,\r\n UNSIGNED_INT_SAMPLER_2D: 0x8dd2,\r\n UNSIGNED_INT_SAMPLER_3D: 0x8dd3,\r\n UNSIGNED_INT_SAMPLER_CUBE: 0x8dd4,\r\n UNSIGNED_INT_SAMPLER_2D_ARRAY: 0x8dd7,\r\n DEPTH_COMPONENT32F: 0x8cac,\r\n DEPTH32F_STENCIL8: 0x8cad,\r\n FLOAT_32_UNSIGNED_INT_24_8_REV: 0x8dad,\r\n FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: 0x8210,\r\n FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: 0x8211,\r\n FRAMEBUFFER_ATTACHMENT_RED_SIZE: 0x8212,\r\n FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: 0x8213,\r\n FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: 0x8214,\r\n FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: 0x8215,\r\n FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: 0x8216,\r\n FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: 0x8217,\r\n FRAMEBUFFER_DEFAULT: 0x8218,\r\n UNSIGNED_INT_24_8: 0x84fa,\r\n DEPTH24_STENCIL8: 0x88f0,\r\n UNSIGNED_NORMALIZED: 0x8c17,\r\n DRAW_FRAMEBUFFER_BINDING: 0x8ca6, // Same as FRAMEBUFFER_BINDING\r\n READ_FRAMEBUFFER: 0x8ca8,\r\n DRAW_FRAMEBUFFER: 0x8ca9,\r\n READ_FRAMEBUFFER_BINDING: 0x8caa,\r\n RENDERBUFFER_SAMPLES: 0x8cab,\r\n FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: 0x8cd4,\r\n MAX_COLOR_ATTACHMENTS: 0x8cdf,\r\n COLOR_ATTACHMENT1: 0x8ce1,\r\n COLOR_ATTACHMENT2: 0x8ce2,\r\n COLOR_ATTACHMENT3: 0x8ce3,\r\n COLOR_ATTACHMENT4: 0x8ce4,\r\n COLOR_ATTACHMENT5: 0x8ce5,\r\n COLOR_ATTACHMENT6: 0x8ce6,\r\n COLOR_ATTACHMENT7: 0x8ce7,\r\n COLOR_ATTACHMENT8: 0x8ce8,\r\n COLOR_ATTACHMENT9: 0x8ce9,\r\n COLOR_ATTACHMENT10: 0x8cea,\r\n COLOR_ATTACHMENT11: 0x8ceb,\r\n COLOR_ATTACHMENT12: 0x8cec,\r\n COLOR_ATTACHMENT13: 0x8ced,\r\n COLOR_ATTACHMENT14: 0x8cee,\r\n COLOR_ATTACHMENT15: 0x8cef,\r\n FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: 0x8d56,\r\n MAX_SAMPLES: 0x8d57,\r\n HALF_FLOAT: 0x140b,\r\n RG: 0x8227,\r\n RG_INTEGER: 0x8228,\r\n R8: 0x8229,\r\n RG8: 0x822b,\r\n R16F: 0x822d,\r\n R32F: 0x822e,\r\n RG16F: 0x822f,\r\n RG32F: 0x8230,\r\n R8I: 0x8231,\r\n R8UI: 0x8232,\r\n R16I: 0x8233,\r\n R16UI: 0x8234,\r\n R32I: 0x8235,\r\n R32UI: 0x8236,\r\n RG8I: 0x8237,\r\n RG8UI: 0x8238,\r\n RG16I: 0x8239,\r\n RG16UI: 0x823a,\r\n RG32I: 0x823b,\r\n RG32UI: 0x823c,\r\n VERTEX_ARRAY_BINDING: 0x85b5,\r\n R8_SNORM: 0x8f94,\r\n RG8_SNORM: 0x8f95,\r\n RGB8_SNORM: 0x8f96,\r\n RGBA8_SNORM: 0x8f97,\r\n SIGNED_NORMALIZED: 0x8f9c,\r\n COPY_READ_BUFFER: 0x8f36,\r\n COPY_WRITE_BUFFER: 0x8f37,\r\n COPY_READ_BUFFER_BINDING: 0x8f36, // Same as COPY_READ_BUFFER\r\n COPY_WRITE_BUFFER_BINDING: 0x8f37, // Same as COPY_WRITE_BUFFER\r\n UNIFORM_BUFFER: 0x8a11,\r\n UNIFORM_BUFFER_BINDING: 0x8a28,\r\n UNIFORM_BUFFER_START: 0x8a29,\r\n UNIFORM_BUFFER_SIZE: 0x8a2a,\r\n MAX_VERTEX_UNIFORM_BLOCKS: 0x8a2b,\r\n MAX_FRAGMENT_UNIFORM_BLOCKS: 0x8a2d,\r\n MAX_COMBINED_UNIFORM_BLOCKS: 0x8a2e,\r\n MAX_UNIFORM_BUFFER_BINDINGS: 0x8a2f,\r\n MAX_UNIFORM_BLOCK_SIZE: 0x8a30,\r\n MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS: 0x8a31,\r\n MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS: 0x8a33,\r\n UNIFORM_BUFFER_OFFSET_ALIGNMENT: 0x8a34,\r\n ACTIVE_UNIFORM_BLOCKS: 0x8a36,\r\n UNIFORM_TYPE: 0x8a37,\r\n UNIFORM_SIZE: 0x8a38,\r\n UNIFORM_BLOCK_INDEX: 0x8a3a,\r\n UNIFORM_OFFSET: 0x8a3b,\r\n UNIFORM_ARRAY_STRIDE: 0x8a3c,\r\n UNIFORM_MATRIX_STRIDE: 0x8a3d,\r\n UNIFORM_IS_ROW_MAJOR: 0x8a3e,\r\n UNIFORM_BLOCK_BINDING: 0x8a3f,\r\n UNIFORM_BLOCK_DATA_SIZE: 0x8a40,\r\n UNIFORM_BLOCK_ACTIVE_UNIFORMS: 0x8a42,\r\n UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: 0x8a43,\r\n UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: 0x8a44,\r\n UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: 0x8a46,\r\n INVALID_INDEX: 0xffffffff,\r\n MAX_VERTEX_OUTPUT_COMPONENTS: 0x9122,\r\n MAX_FRAGMENT_INPUT_COMPONENTS: 0x9125,\r\n MAX_SERVER_WAIT_TIMEOUT: 0x9111,\r\n OBJECT_TYPE: 0x9112,\r\n SYNC_CONDITION: 0x9113,\r\n SYNC_STATUS: 0x9114,\r\n SYNC_FLAGS: 0x9115,\r\n SYNC_FENCE: 0x9116,\r\n SYNC_GPU_COMMANDS_COMPLETE: 0x9117,\r\n UNSIGNALED: 0x9118,\r\n SIGNALED: 0x9119,\r\n ALREADY_SIGNALED: 0x911a,\r\n TIMEOUT_EXPIRED: 0x911b,\r\n CONDITION_SATISFIED: 0x911c,\r\n WAIT_FAILED: 0x911d,\r\n SYNC_FLUSH_COMMANDS_BIT: 0x00000001,\r\n VERTEX_ATTRIB_ARRAY_DIVISOR: 0x88fe,\r\n ANY_SAMPLES_PASSED: 0x8c2f,\r\n ANY_SAMPLES_PASSED_CONSERVATIVE: 0x8d6a,\r\n SAMPLER_BINDING: 0x8919,\r\n RGB10_A2UI: 0x906f,\r\n INT_2_10_10_10_REV: 0x8d9f,\r\n TRANSFORM_FEEDBACK: 0x8e22,\r\n TRANSFORM_FEEDBACK_PAUSED: 0x8e23,\r\n TRANSFORM_FEEDBACK_ACTIVE: 0x8e24,\r\n TRANSFORM_FEEDBACK_BINDING: 0x8e25,\r\n COMPRESSED_R11_EAC: 0x9270,\r\n COMPRESSED_SIGNED_R11_EAC: 0x9271,\r\n COMPRESSED_RG11_EAC: 0x9272,\r\n COMPRESSED_SIGNED_RG11_EAC: 0x9273,\r\n COMPRESSED_RGB8_ETC2: 0x9274,\r\n COMPRESSED_SRGB8_ETC2: 0x9275,\r\n COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 0x9276,\r\n COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 0x9277,\r\n COMPRESSED_RGBA8_ETC2_EAC: 0x9278,\r\n COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 0x9279,\r\n TEXTURE_IMMUTABLE_FORMAT: 0x912f,\r\n MAX_ELEMENT_INDEX: 0x8d6b,\r\n TEXTURE_IMMUTABLE_LEVELS: 0x82df,\r\n\r\n // Extensions\r\n MAX_TEXTURE_MAX_ANISOTROPY_EXT: 0x84ff,\r\n};\r\nexport default Object.freeze(WebGLConstants);\r\n","import defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport WebGLConstants from \"./WebGLConstants.js\";\r\n\r\n/**\r\n * WebGL component datatypes. Components are intrinsics,\r\n * which form attributes, which form vertices.\r\n *\r\n * @enum {Number}\r\n */\r\nvar ComponentDatatype = {\r\n /**\r\n * 8-bit signed byte corresponding to gl.BYTE
and the type\r\n * of an element in Int8Array
.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\n BYTE: WebGLConstants.BYTE,\r\n\r\n /**\r\n * 8-bit unsigned byte corresponding to UNSIGNED_BYTE
and the type\r\n * of an element in Uint8Array
.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\n UNSIGNED_BYTE: WebGLConstants.UNSIGNED_BYTE,\r\n\r\n /**\r\n * 16-bit signed short corresponding to SHORT
and the type\r\n * of an element in Int16Array
.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\n SHORT: WebGLConstants.SHORT,\r\n\r\n /**\r\n * 16-bit unsigned short corresponding to UNSIGNED_SHORT
and the type\r\n * of an element in Uint16Array
.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\n UNSIGNED_SHORT: WebGLConstants.UNSIGNED_SHORT,\r\n\r\n /**\r\n * 32-bit signed int corresponding to INT
and the type\r\n * of an element in Int32Array
.\r\n *\r\n * @memberOf ComponentDatatype\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\n INT: WebGLConstants.INT,\r\n\r\n /**\r\n * 32-bit unsigned int corresponding to UNSIGNED_INT
and the type\r\n * of an element in Uint32Array
.\r\n *\r\n * @memberOf ComponentDatatype\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\n UNSIGNED_INT: WebGLConstants.UNSIGNED_INT,\r\n\r\n /**\r\n * 32-bit floating-point corresponding to FLOAT
and the type\r\n * of an element in Float32Array
.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\n FLOAT: WebGLConstants.FLOAT,\r\n\r\n /**\r\n * 64-bit floating-point corresponding to gl.DOUBLE
(in Desktop OpenGL;\r\n * this is not supported in WebGL, and is emulated in Cesium via {@link GeometryPipeline.encodeAttribute})\r\n * and the type of an element in Float64Array
.\r\n *\r\n * @memberOf ComponentDatatype\r\n *\r\n * @type {Number}\r\n * @constant\r\n * @default 0x140A\r\n */\r\n DOUBLE: WebGLConstants.DOUBLE,\r\n};\r\n\r\n/**\r\n * Returns the size, in bytes, of the corresponding datatype.\r\n *\r\n * @param {ComponentDatatype} componentDatatype The component datatype to get the size of.\r\n * @returns {Number} The size in bytes.\r\n *\r\n * @exception {DeveloperError} componentDatatype is not a valid value.\r\n *\r\n * @example\r\n * // Returns Int8Array.BYTES_PER_ELEMENT\r\n * var size = Cesium.ComponentDatatype.getSizeInBytes(Cesium.ComponentDatatype.BYTE);\r\n */\r\nComponentDatatype.getSizeInBytes = function (componentDatatype) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(componentDatatype)) {\r\n throw new DeveloperError(\"value is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n switch (componentDatatype) {\r\n case ComponentDatatype.BYTE:\r\n return Int8Array.BYTES_PER_ELEMENT;\r\n case ComponentDatatype.UNSIGNED_BYTE:\r\n return Uint8Array.BYTES_PER_ELEMENT;\r\n case ComponentDatatype.SHORT:\r\n return Int16Array.BYTES_PER_ELEMENT;\r\n case ComponentDatatype.UNSIGNED_SHORT:\r\n return Uint16Array.BYTES_PER_ELEMENT;\r\n case ComponentDatatype.INT:\r\n return Int32Array.BYTES_PER_ELEMENT;\r\n case ComponentDatatype.UNSIGNED_INT:\r\n return Uint32Array.BYTES_PER_ELEMENT;\r\n case ComponentDatatype.FLOAT:\r\n return Float32Array.BYTES_PER_ELEMENT;\r\n case ComponentDatatype.DOUBLE:\r\n return Float64Array.BYTES_PER_ELEMENT;\r\n //>>includeStart('debug', pragmas.debug);\r\n default:\r\n throw new DeveloperError(\"componentDatatype is not a valid value.\");\r\n //>>includeEnd('debug');\r\n }\r\n};\r\n\r\n/**\r\n * Gets the {@link ComponentDatatype} for the provided TypedArray instance.\r\n *\r\n * @param {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} array The typed array.\r\n * @returns {ComponentDatatype} The ComponentDatatype for the provided array, or undefined if the array is not a TypedArray.\r\n */\r\nComponentDatatype.fromTypedArray = function (array) {\r\n if (array instanceof Int8Array) {\r\n return ComponentDatatype.BYTE;\r\n }\r\n if (array instanceof Uint8Array) {\r\n return ComponentDatatype.UNSIGNED_BYTE;\r\n }\r\n if (array instanceof Int16Array) {\r\n return ComponentDatatype.SHORT;\r\n }\r\n if (array instanceof Uint16Array) {\r\n return ComponentDatatype.UNSIGNED_SHORT;\r\n }\r\n if (array instanceof Int32Array) {\r\n return ComponentDatatype.INT;\r\n }\r\n if (array instanceof Uint32Array) {\r\n return ComponentDatatype.UNSIGNED_INT;\r\n }\r\n if (array instanceof Float32Array) {\r\n return ComponentDatatype.FLOAT;\r\n }\r\n if (array instanceof Float64Array) {\r\n return ComponentDatatype.DOUBLE;\r\n }\r\n};\r\n\r\n/**\r\n * Validates that the provided component datatype is a valid {@link ComponentDatatype}\r\n *\r\n * @param {ComponentDatatype} componentDatatype The component datatype to validate.\r\n * @returns {Boolean} true
if the provided component datatype is a valid value; otherwise, false
.\r\n *\r\n * @example\r\n * if (!Cesium.ComponentDatatype.validate(componentDatatype)) {\r\n * throw new Cesium.DeveloperError('componentDatatype must be a valid value.');\r\n * }\r\n */\r\nComponentDatatype.validate = function (componentDatatype) {\r\n return (\r\n defined(componentDatatype) &&\r\n (componentDatatype === ComponentDatatype.BYTE ||\r\n componentDatatype === ComponentDatatype.UNSIGNED_BYTE ||\r\n componentDatatype === ComponentDatatype.SHORT ||\r\n componentDatatype === ComponentDatatype.UNSIGNED_SHORT ||\r\n componentDatatype === ComponentDatatype.INT ||\r\n componentDatatype === ComponentDatatype.UNSIGNED_INT ||\r\n componentDatatype === ComponentDatatype.FLOAT ||\r\n componentDatatype === ComponentDatatype.DOUBLE)\r\n );\r\n};\r\n\r\n/**\r\n * Creates a typed array corresponding to component data type.\r\n *\r\n * @param {ComponentDatatype} componentDatatype The component data type.\r\n * @param {Number|Array} valuesOrLength The length of the array to create or an array.\r\n * @returns {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} A typed array.\r\n *\r\n * @exception {DeveloperError} componentDatatype is not a valid value.\r\n *\r\n * @example\r\n * // creates a Float32Array with length of 100\r\n * var typedArray = Cesium.ComponentDatatype.createTypedArray(Cesium.ComponentDatatype.FLOAT, 100);\r\n */\r\nComponentDatatype.createTypedArray = function (\r\n componentDatatype,\r\n valuesOrLength\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(componentDatatype)) {\r\n throw new DeveloperError(\"componentDatatype is required.\");\r\n }\r\n if (!defined(valuesOrLength)) {\r\n throw new DeveloperError(\"valuesOrLength is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n switch (componentDatatype) {\r\n case ComponentDatatype.BYTE:\r\n return new Int8Array(valuesOrLength);\r\n case ComponentDatatype.UNSIGNED_BYTE:\r\n return new Uint8Array(valuesOrLength);\r\n case ComponentDatatype.SHORT:\r\n return new Int16Array(valuesOrLength);\r\n case ComponentDatatype.UNSIGNED_SHORT:\r\n return new Uint16Array(valuesOrLength);\r\n case ComponentDatatype.INT:\r\n return new Int32Array(valuesOrLength);\r\n case ComponentDatatype.UNSIGNED_INT:\r\n return new Uint32Array(valuesOrLength);\r\n case ComponentDatatype.FLOAT:\r\n return new Float32Array(valuesOrLength);\r\n case ComponentDatatype.DOUBLE:\r\n return new Float64Array(valuesOrLength);\r\n //>>includeStart('debug', pragmas.debug);\r\n default:\r\n throw new DeveloperError(\"componentDatatype is not a valid value.\");\r\n //>>includeEnd('debug');\r\n }\r\n};\r\n\r\n/**\r\n * Creates a typed view of an array of bytes.\r\n *\r\n * @param {ComponentDatatype} componentDatatype The type of the view to create.\r\n * @param {ArrayBuffer} buffer The buffer storage to use for the view.\r\n * @param {Number} [byteOffset] The offset, in bytes, to the first element in the view.\r\n * @param {Number} [length] The number of elements in the view.\r\n * @returns {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} A typed array view of the buffer.\r\n *\r\n * @exception {DeveloperError} componentDatatype is not a valid value.\r\n */\r\nComponentDatatype.createArrayBufferView = function (\r\n componentDatatype,\r\n buffer,\r\n byteOffset,\r\n length\r\n) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(componentDatatype)) {\r\n throw new DeveloperError(\"componentDatatype is required.\");\r\n }\r\n if (!defined(buffer)) {\r\n throw new DeveloperError(\"buffer is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n byteOffset = defaultValue(byteOffset, 0);\r\n length = defaultValue(\r\n length,\r\n (buffer.byteLength - byteOffset) /\r\n ComponentDatatype.getSizeInBytes(componentDatatype)\r\n );\r\n\r\n switch (componentDatatype) {\r\n case ComponentDatatype.BYTE:\r\n return new Int8Array(buffer, byteOffset, length);\r\n case ComponentDatatype.UNSIGNED_BYTE:\r\n return new Uint8Array(buffer, byteOffset, length);\r\n case ComponentDatatype.SHORT:\r\n return new Int16Array(buffer, byteOffset, length);\r\n case ComponentDatatype.UNSIGNED_SHORT:\r\n return new Uint16Array(buffer, byteOffset, length);\r\n case ComponentDatatype.INT:\r\n return new Int32Array(buffer, byteOffset, length);\r\n case ComponentDatatype.UNSIGNED_INT:\r\n return new Uint32Array(buffer, byteOffset, length);\r\n case ComponentDatatype.FLOAT:\r\n return new Float32Array(buffer, byteOffset, length);\r\n case ComponentDatatype.DOUBLE:\r\n return new Float64Array(buffer, byteOffset, length);\r\n //>>includeStart('debug', pragmas.debug);\r\n default:\r\n throw new DeveloperError(\"componentDatatype is not a valid value.\");\r\n //>>includeEnd('debug');\r\n }\r\n};\r\n\r\n/**\r\n * Get the ComponentDatatype from its name.\r\n *\r\n * @param {String} name The name of the ComponentDatatype.\r\n * @returns {ComponentDatatype} The ComponentDatatype.\r\n *\r\n * @exception {DeveloperError} name is not a valid value.\r\n */\r\nComponentDatatype.fromName = function (name) {\r\n switch (name) {\r\n case \"BYTE\":\r\n return ComponentDatatype.BYTE;\r\n case \"UNSIGNED_BYTE\":\r\n return ComponentDatatype.UNSIGNED_BYTE;\r\n case \"SHORT\":\r\n return ComponentDatatype.SHORT;\r\n case \"UNSIGNED_SHORT\":\r\n return ComponentDatatype.UNSIGNED_SHORT;\r\n case \"INT\":\r\n return ComponentDatatype.INT;\r\n case \"UNSIGNED_INT\":\r\n return ComponentDatatype.UNSIGNED_INT;\r\n case \"FLOAT\":\r\n return ComponentDatatype.FLOAT;\r\n case \"DOUBLE\":\r\n return ComponentDatatype.DOUBLE;\r\n //>>includeStart('debug', pragmas.debug);\r\n default:\r\n throw new DeveloperError(\"name is not a valid value.\");\r\n //>>includeEnd('debug');\r\n }\r\n};\r\nexport default Object.freeze(ComponentDatatype);\r\n","/**\r\n * This enumerated type is used to determine how the vertices of the terrain mesh are compressed.\r\n *\r\n * @enum {Number}\r\n *\r\n * @private\r\n */\r\nvar TerrainQuantization = {\r\n /**\r\n * The vertices are not compressed.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\n NONE: 0,\r\n\r\n /**\r\n * The vertices are compressed to 12 bits.\r\n *\r\n * @type {Number}\r\n * @constant\r\n */\r\n BITS12: 1,\r\n};\r\nexport default Object.freeze(TerrainQuantization);\r\n","import AttributeCompression from \"./AttributeCompression.js\";\r\nimport Cartesian2 from \"./Cartesian2.js\";\r\nimport Cartesian3 from \"./Cartesian3.js\";\r\nimport ComponentDatatype from \"./ComponentDatatype.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport CesiumMath from \"./Math.js\";\r\nimport Matrix4 from \"./Matrix4.js\";\r\nimport TerrainQuantization from \"./TerrainQuantization.js\";\r\n\r\nvar cartesian3Scratch = new Cartesian3();\r\nvar cartesian3DimScratch = new Cartesian3();\r\nvar cartesian2Scratch = new Cartesian2();\r\nvar matrix4Scratch = new Matrix4();\r\nvar matrix4Scratch2 = new Matrix4();\r\n\r\nvar SHIFT_LEFT_12 = Math.pow(2.0, 12.0);\r\n\r\n/**\r\n * Data used to quantize and pack the terrain mesh. The position can be unpacked for picking and all attributes\r\n * are unpacked in the vertex shader.\r\n *\r\n * @alias TerrainEncoding\r\n * @constructor\r\n *\r\n * @param {AxisAlignedBoundingBox} axisAlignedBoundingBox The bounds of the tile in the east-north-up coordinates at the tiles center.\r\n * @param {Number} minimumHeight The minimum height.\r\n * @param {Number} maximumHeight The maximum height.\r\n * @param {Matrix4} fromENU The east-north-up to fixed frame matrix at the center of the terrain mesh.\r\n * @param {Boolean} hasVertexNormals If the mesh has vertex normals.\r\n * @param {Boolean} [hasWebMercatorT=false] true if the terrain data includes a Web Mercator texture coordinate; otherwise, false.\r\n *\r\n * @private\r\n */\r\nfunction TerrainEncoding(\r\n axisAlignedBoundingBox,\r\n minimumHeight,\r\n maximumHeight,\r\n fromENU,\r\n hasVertexNormals,\r\n hasWebMercatorT\r\n) {\r\n var quantization = TerrainQuantization.NONE;\r\n var center;\r\n var toENU;\r\n var matrix;\r\n\r\n if (\r\n defined(axisAlignedBoundingBox) &&\r\n defined(minimumHeight) &&\r\n defined(maximumHeight) &&\r\n defined(fromENU)\r\n ) {\r\n var minimum = axisAlignedBoundingBox.minimum;\r\n var maximum = axisAlignedBoundingBox.maximum;\r\n\r\n var dimensions = Cartesian3.subtract(\r\n maximum,\r\n minimum,\r\n cartesian3DimScratch\r\n );\r\n var hDim = maximumHeight - minimumHeight;\r\n var maxDim = Math.max(Cartesian3.maximumComponent(dimensions), hDim);\r\n\r\n if (maxDim < SHIFT_LEFT_12 - 1.0) {\r\n quantization = TerrainQuantization.BITS12;\r\n } else {\r\n quantization = TerrainQuantization.NONE;\r\n }\r\n\r\n center = axisAlignedBoundingBox.center;\r\n toENU = Matrix4.inverseTransformation(fromENU, new Matrix4());\r\n\r\n var translation = Cartesian3.negate(minimum, cartesian3Scratch);\r\n Matrix4.multiply(\r\n Matrix4.fromTranslation(translation, matrix4Scratch),\r\n toENU,\r\n toENU\r\n );\r\n\r\n var scale = cartesian3Scratch;\r\n scale.x = 1.0 / dimensions.x;\r\n scale.y = 1.0 / dimensions.y;\r\n scale.z = 1.0 / dimensions.z;\r\n Matrix4.multiply(Matrix4.fromScale(scale, matrix4Scratch), toENU, toENU);\r\n\r\n matrix = Matrix4.clone(fromENU);\r\n Matrix4.setTranslation(matrix, Cartesian3.ZERO, matrix);\r\n\r\n fromENU = Matrix4.clone(fromENU, new Matrix4());\r\n\r\n var translationMatrix = Matrix4.fromTranslation(minimum, matrix4Scratch);\r\n var scaleMatrix = Matrix4.fromScale(dimensions, matrix4Scratch2);\r\n var st = Matrix4.multiply(translationMatrix, scaleMatrix, matrix4Scratch);\r\n\r\n Matrix4.multiply(fromENU, st, fromENU);\r\n Matrix4.multiply(matrix, st, matrix);\r\n }\r\n\r\n /**\r\n * How the vertices of the mesh were compressed.\r\n * @type {TerrainQuantization}\r\n */\r\n this.quantization = quantization;\r\n\r\n /**\r\n * The minimum height of the tile including the skirts.\r\n * @type {Number}\r\n */\r\n this.minimumHeight = minimumHeight;\r\n\r\n /**\r\n * The maximum height of the tile.\r\n * @type {Number}\r\n */\r\n this.maximumHeight = maximumHeight;\r\n\r\n /**\r\n * The center of the tile.\r\n * @type {Cartesian3}\r\n */\r\n this.center = center;\r\n\r\n /**\r\n * A matrix that takes a vertex from the tile, transforms it to east-north-up at the center and scales\r\n * it so each component is in the [0, 1] range.\r\n * @type {Matrix4}\r\n */\r\n this.toScaledENU = toENU;\r\n\r\n /**\r\n * A matrix that restores a vertex transformed with toScaledENU back to the earth fixed reference frame\r\n * @type {Matrix4}\r\n */\r\n this.fromScaledENU = fromENU;\r\n\r\n /**\r\n * The matrix used to decompress the terrain vertices in the shader for RTE rendering.\r\n * @type {Matrix4}\r\n */\r\n this.matrix = matrix;\r\n\r\n /**\r\n * The terrain mesh contains normals.\r\n * @type {Boolean}\r\n */\r\n this.hasVertexNormals = hasVertexNormals;\r\n\r\n /**\r\n * The terrain mesh contains a vertical texture coordinate following the Web Mercator projection.\r\n * @type {Boolean}\r\n */\r\n this.hasWebMercatorT = defaultValue(hasWebMercatorT, false);\r\n}\r\n\r\nTerrainEncoding.prototype.encode = function (\r\n vertexBuffer,\r\n bufferIndex,\r\n position,\r\n uv,\r\n height,\r\n normalToPack,\r\n webMercatorT\r\n) {\r\n var u = uv.x;\r\n var v = uv.y;\r\n\r\n if (this.quantization === TerrainQuantization.BITS12) {\r\n position = Matrix4.multiplyByPoint(\r\n this.toScaledENU,\r\n position,\r\n cartesian3Scratch\r\n );\r\n\r\n position.x = CesiumMath.clamp(position.x, 0.0, 1.0);\r\n position.y = CesiumMath.clamp(position.y, 0.0, 1.0);\r\n position.z = CesiumMath.clamp(position.z, 0.0, 1.0);\r\n\r\n var hDim = this.maximumHeight - this.minimumHeight;\r\n var h = CesiumMath.clamp((height - this.minimumHeight) / hDim, 0.0, 1.0);\r\n\r\n Cartesian2.fromElements(position.x, position.y, cartesian2Scratch);\r\n var compressed0 = AttributeCompression.compressTextureCoordinates(\r\n cartesian2Scratch\r\n );\r\n\r\n Cartesian2.fromElements(position.z, h, cartesian2Scratch);\r\n var compressed1 = AttributeCompression.compressTextureCoordinates(\r\n cartesian2Scratch\r\n );\r\n\r\n Cartesian2.fromElements(u, v, cartesian2Scratch);\r\n var compressed2 = AttributeCompression.compressTextureCoordinates(\r\n cartesian2Scratch\r\n );\r\n\r\n vertexBuffer[bufferIndex++] = compressed0;\r\n vertexBuffer[bufferIndex++] = compressed1;\r\n vertexBuffer[bufferIndex++] = compressed2;\r\n\r\n if (this.hasWebMercatorT) {\r\n Cartesian2.fromElements(webMercatorT, 0.0, cartesian2Scratch);\r\n var compressed3 = AttributeCompression.compressTextureCoordinates(\r\n cartesian2Scratch\r\n );\r\n vertexBuffer[bufferIndex++] = compressed3;\r\n }\r\n } else {\r\n Cartesian3.subtract(position, this.center, cartesian3Scratch);\r\n\r\n vertexBuffer[bufferIndex++] = cartesian3Scratch.x;\r\n vertexBuffer[bufferIndex++] = cartesian3Scratch.y;\r\n vertexBuffer[bufferIndex++] = cartesian3Scratch.z;\r\n vertexBuffer[bufferIndex++] = height;\r\n vertexBuffer[bufferIndex++] = u;\r\n vertexBuffer[bufferIndex++] = v;\r\n\r\n if (this.hasWebMercatorT) {\r\n vertexBuffer[bufferIndex++] = webMercatorT;\r\n }\r\n }\r\n\r\n if (this.hasVertexNormals) {\r\n vertexBuffer[bufferIndex++] = AttributeCompression.octPackFloat(\r\n normalToPack\r\n );\r\n }\r\n\r\n return bufferIndex;\r\n};\r\n\r\nTerrainEncoding.prototype.decodePosition = function (buffer, index, result) {\r\n if (!defined(result)) {\r\n result = new Cartesian3();\r\n }\r\n\r\n index *= this.getStride();\r\n\r\n if (this.quantization === TerrainQuantization.BITS12) {\r\n var xy = AttributeCompression.decompressTextureCoordinates(\r\n buffer[index],\r\n cartesian2Scratch\r\n );\r\n result.x = xy.x;\r\n result.y = xy.y;\r\n\r\n var zh = AttributeCompression.decompressTextureCoordinates(\r\n buffer[index + 1],\r\n cartesian2Scratch\r\n );\r\n result.z = zh.x;\r\n\r\n return Matrix4.multiplyByPoint(this.fromScaledENU, result, result);\r\n }\r\n\r\n result.x = buffer[index];\r\n result.y = buffer[index + 1];\r\n result.z = buffer[index + 2];\r\n return Cartesian3.add(result, this.center, result);\r\n};\r\n\r\nTerrainEncoding.prototype.decodeTextureCoordinates = function (\r\n buffer,\r\n index,\r\n result\r\n) {\r\n if (!defined(result)) {\r\n result = new Cartesian2();\r\n }\r\n\r\n index *= this.getStride();\r\n\r\n if (this.quantization === TerrainQuantization.BITS12) {\r\n return AttributeCompression.decompressTextureCoordinates(\r\n buffer[index + 2],\r\n result\r\n );\r\n }\r\n\r\n return Cartesian2.fromElements(buffer[index + 4], buffer[index + 5], result);\r\n};\r\n\r\nTerrainEncoding.prototype.decodeHeight = function (buffer, index) {\r\n index *= this.getStride();\r\n\r\n if (this.quantization === TerrainQuantization.BITS12) {\r\n var zh = AttributeCompression.decompressTextureCoordinates(\r\n buffer[index + 1],\r\n cartesian2Scratch\r\n );\r\n return (\r\n zh.y * (this.maximumHeight - this.minimumHeight) + this.minimumHeight\r\n );\r\n }\r\n\r\n return buffer[index + 3];\r\n};\r\n\r\nTerrainEncoding.prototype.decodeWebMercatorT = function (buffer, index) {\r\n index *= this.getStride();\r\n\r\n if (this.quantization === TerrainQuantization.BITS12) {\r\n return AttributeCompression.decompressTextureCoordinates(\r\n buffer[index + 3],\r\n cartesian2Scratch\r\n ).x;\r\n }\r\n\r\n return buffer[index + 6];\r\n};\r\n\r\nTerrainEncoding.prototype.getOctEncodedNormal = function (\r\n buffer,\r\n index,\r\n result\r\n) {\r\n var stride = this.getStride();\r\n index = (index + 1) * stride - 1;\r\n\r\n var temp = buffer[index] / 256.0;\r\n var x = Math.floor(temp);\r\n var y = (temp - x) * 256.0;\r\n\r\n return Cartesian2.fromElements(x, y, result);\r\n};\r\n\r\nTerrainEncoding.prototype.getStride = function () {\r\n var vertexStride;\r\n\r\n switch (this.quantization) {\r\n case TerrainQuantization.BITS12:\r\n vertexStride = 3;\r\n break;\r\n default:\r\n vertexStride = 6;\r\n }\r\n\r\n if (this.hasWebMercatorT) {\r\n ++vertexStride;\r\n }\r\n\r\n if (this.hasVertexNormals) {\r\n ++vertexStride;\r\n }\r\n\r\n return vertexStride;\r\n};\r\n\r\nvar attributesNone = {\r\n position3DAndHeight: 0,\r\n textureCoordAndEncodedNormals: 1,\r\n};\r\nvar attributes = {\r\n compressed0: 0,\r\n compressed1: 1,\r\n};\r\n\r\nTerrainEncoding.prototype.getAttributes = function (buffer) {\r\n var datatype = ComponentDatatype.FLOAT;\r\n var sizeInBytes = ComponentDatatype.getSizeInBytes(datatype);\r\n var stride;\r\n\r\n if (this.quantization === TerrainQuantization.NONE) {\r\n var position3DAndHeightLength = 4;\r\n var numTexCoordComponents = 2;\r\n\r\n if (this.hasWebMercatorT) {\r\n ++numTexCoordComponents;\r\n }\r\n\r\n if (this.hasVertexNormals) {\r\n ++numTexCoordComponents;\r\n }\r\n\r\n stride = (position3DAndHeightLength + numTexCoordComponents) * sizeInBytes;\r\n\r\n return [\r\n {\r\n index: attributesNone.position3DAndHeight,\r\n vertexBuffer: buffer,\r\n componentDatatype: datatype,\r\n componentsPerAttribute: position3DAndHeightLength,\r\n offsetInBytes: 0,\r\n strideInBytes: stride,\r\n },\r\n {\r\n index: attributesNone.textureCoordAndEncodedNormals,\r\n vertexBuffer: buffer,\r\n componentDatatype: datatype,\r\n componentsPerAttribute: numTexCoordComponents,\r\n offsetInBytes: position3DAndHeightLength * sizeInBytes,\r\n strideInBytes: stride,\r\n },\r\n ];\r\n }\r\n\r\n var numCompressed0 = 3;\r\n var numCompressed1 = 0;\r\n\r\n if (this.hasWebMercatorT || this.hasVertexNormals) {\r\n ++numCompressed0;\r\n }\r\n\r\n if (this.hasWebMercatorT && this.hasVertexNormals) {\r\n ++numCompressed1;\r\n\r\n stride = (numCompressed0 + numCompressed1) * sizeInBytes;\r\n\r\n return [\r\n {\r\n index: attributes.compressed0,\r\n vertexBuffer: buffer,\r\n componentDatatype: datatype,\r\n componentsPerAttribute: numCompressed0,\r\n offsetInBytes: 0,\r\n strideInBytes: stride,\r\n },\r\n {\r\n index: attributes.compressed1,\r\n vertexBuffer: buffer,\r\n componentDatatype: datatype,\r\n componentsPerAttribute: numCompressed1,\r\n offsetInBytes: numCompressed0 * sizeInBytes,\r\n strideInBytes: stride,\r\n },\r\n ];\r\n }\r\n return [\r\n {\r\n index: attributes.compressed0,\r\n vertexBuffer: buffer,\r\n componentDatatype: datatype,\r\n componentsPerAttribute: numCompressed0,\r\n },\r\n ];\r\n};\r\n\r\nTerrainEncoding.prototype.getAttributeLocations = function () {\r\n if (this.quantization === TerrainQuantization.NONE) {\r\n return attributesNone;\r\n }\r\n return attributes;\r\n};\r\n\r\nTerrainEncoding.clone = function (encoding, result) {\r\n if (!defined(result)) {\r\n result = new TerrainEncoding();\r\n }\r\n\r\n result.quantization = encoding.quantization;\r\n result.minimumHeight = encoding.minimumHeight;\r\n result.maximumHeight = encoding.maximumHeight;\r\n result.center = Cartesian3.clone(encoding.center);\r\n result.toScaledENU = Matrix4.clone(encoding.toScaledENU);\r\n result.fromScaledENU = Matrix4.clone(encoding.fromScaledENU);\r\n result.matrix = Matrix4.clone(encoding.matrix);\r\n result.hasVertexNormals = encoding.hasVertexNormals;\r\n result.hasWebMercatorT = encoding.hasWebMercatorT;\r\n return result;\r\n};\r\nexport default TerrainEncoding;\r\n","import Cartesian3 from \"./Cartesian3.js\";\r\nimport Cartographic from \"./Cartographic.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport Ellipsoid from \"./Ellipsoid.js\";\r\nimport CesiumMath from \"./Math.js\";\r\n\r\n/**\r\n * The map projection used by Google Maps, Bing Maps, and most of ArcGIS Online, EPSG:3857. This\r\n * projection use longitude and latitude expressed with the WGS84 and transforms them to Mercator using\r\n * the spherical (rather than ellipsoidal) equations.\r\n *\r\n * @alias WebMercatorProjection\r\n * @constructor\r\n *\r\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid.\r\n *\r\n * @see GeographicProjection\r\n */\r\nfunction WebMercatorProjection(ellipsoid) {\r\n this._ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\r\n this._semimajorAxis = this._ellipsoid.maximumRadius;\r\n this._oneOverSemimajorAxis = 1.0 / this._semimajorAxis;\r\n}\r\n\r\nObject.defineProperties(WebMercatorProjection.prototype, {\r\n /**\r\n * Gets the {@link Ellipsoid}.\r\n *\r\n * @memberof WebMercatorProjection.prototype\r\n *\r\n * @type {Ellipsoid}\r\n * @readonly\r\n */\r\n ellipsoid: {\r\n get: function () {\r\n return this._ellipsoid;\r\n },\r\n },\r\n});\r\n\r\n/**\r\n * Converts a Mercator angle, in the range -PI to PI, to a geodetic latitude\r\n * in the range -PI/2 to PI/2.\r\n *\r\n * @param {Number} mercatorAngle The angle to convert.\r\n * @returns {Number} The geodetic latitude in radians.\r\n */\r\nWebMercatorProjection.mercatorAngleToGeodeticLatitude = function (\r\n mercatorAngle\r\n) {\r\n return CesiumMath.PI_OVER_TWO - 2.0 * Math.atan(Math.exp(-mercatorAngle));\r\n};\r\n\r\n/**\r\n * Converts a geodetic latitude in radians, in the range -PI/2 to PI/2, to a Mercator\r\n * angle in the range -PI to PI.\r\n *\r\n * @param {Number} latitude The geodetic latitude in radians.\r\n * @returns {Number} The Mercator angle.\r\n */\r\nWebMercatorProjection.geodeticLatitudeToMercatorAngle = function (latitude) {\r\n // Clamp the latitude coordinate to the valid Mercator bounds.\r\n if (latitude > WebMercatorProjection.MaximumLatitude) {\r\n latitude = WebMercatorProjection.MaximumLatitude;\r\n } else if (latitude < -WebMercatorProjection.MaximumLatitude) {\r\n latitude = -WebMercatorProjection.MaximumLatitude;\r\n }\r\n var sinLatitude = Math.sin(latitude);\r\n return 0.5 * Math.log((1.0 + sinLatitude) / (1.0 - sinLatitude));\r\n};\r\n\r\n/**\r\n * The maximum latitude (both North and South) supported by a Web Mercator\r\n * (EPSG:3857) projection. Technically, the Mercator projection is defined\r\n * for any latitude up to (but not including) 90 degrees, but it makes sense\r\n * to cut it off sooner because it grows exponentially with increasing latitude.\r\n * The logic behind this particular cutoff value, which is the one used by\r\n * Google Maps, Bing Maps, and Esri, is that it makes the projection\r\n * square. That is, the rectangle is equal in the X and Y directions.\r\n *\r\n * The constant value is computed by calling:\r\n * WebMercatorProjection.mercatorAngleToGeodeticLatitude(Math.PI)\r\n *\r\n * @type {Number}\r\n */\r\nWebMercatorProjection.MaximumLatitude = WebMercatorProjection.mercatorAngleToGeodeticLatitude(\r\n Math.PI\r\n);\r\n\r\n/**\r\n * Converts geodetic ellipsoid coordinates, in radians, to the equivalent Web Mercator\r\n * X, Y, Z coordinates expressed in meters and returned in a {@link Cartesian3}. The height\r\n * is copied unmodified to the Z coordinate.\r\n *\r\n * @param {Cartographic} cartographic The cartographic coordinates in radians.\r\n * @param {Cartesian3} [result] The instance to which to copy the result, or undefined if a\r\n * new instance should be created.\r\n * @returns {Cartesian3} The equivalent web mercator X, Y, Z coordinates, in meters.\r\n */\r\nWebMercatorProjection.prototype.project = function (cartographic, result) {\r\n var semimajorAxis = this._semimajorAxis;\r\n var x = cartographic.longitude * semimajorAxis;\r\n var y =\r\n WebMercatorProjection.geodeticLatitudeToMercatorAngle(\r\n cartographic.latitude\r\n ) * semimajorAxis;\r\n var z = cartographic.height;\r\n\r\n if (!defined(result)) {\r\n return new Cartesian3(x, y, z);\r\n }\r\n\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n return result;\r\n};\r\n\r\n/**\r\n * Converts Web Mercator X, Y coordinates, expressed in meters, to a {@link Cartographic}\r\n * containing geodetic ellipsoid coordinates. The Z coordinate is copied unmodified to the\r\n * height.\r\n *\r\n * @param {Cartesian3} cartesian The web mercator Cartesian position to unrproject with height (z) in meters.\r\n * @param {Cartographic} [result] The instance to which to copy the result, or undefined if a\r\n * new instance should be created.\r\n * @returns {Cartographic} The equivalent cartographic coordinates.\r\n */\r\nWebMercatorProjection.prototype.unproject = function (cartesian, result) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(cartesian)) {\r\n throw new DeveloperError(\"cartesian is required\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n var oneOverEarthSemimajorAxis = this._oneOverSemimajorAxis;\r\n var longitude = cartesian.x * oneOverEarthSemimajorAxis;\r\n var latitude = WebMercatorProjection.mercatorAngleToGeodeticLatitude(\r\n cartesian.y * oneOverEarthSemimajorAxis\r\n );\r\n var height = cartesian.z;\r\n\r\n if (!defined(result)) {\r\n return new Cartographic(longitude, latitude, height);\r\n }\r\n\r\n result.longitude = longitude;\r\n result.latitude = latitude;\r\n result.height = height;\r\n return result;\r\n};\r\nexport default WebMercatorProjection;\r\n","import AxisAlignedBoundingBox from \"./AxisAlignedBoundingBox.js\";\r\nimport BoundingSphere from \"./BoundingSphere.js\";\r\nimport Cartesian2 from \"./Cartesian2.js\";\r\nimport Cartesian3 from \"./Cartesian3.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport Ellipsoid from \"./Ellipsoid.js\";\r\nimport EllipsoidalOccluder from \"./EllipsoidalOccluder.js\";\r\nimport CesiumMath from \"./Math.js\";\r\nimport Matrix4 from \"./Matrix4.js\";\r\nimport OrientedBoundingBox from \"./OrientedBoundingBox.js\";\r\nimport Rectangle from \"./Rectangle.js\";\r\nimport TerrainEncoding from \"./TerrainEncoding.js\";\r\nimport Transforms from \"./Transforms.js\";\r\nimport WebMercatorProjection from \"./WebMercatorProjection.js\";\r\n\r\n/**\r\n * Contains functions to create a mesh from a heightmap image.\r\n *\r\n * @namespace HeightmapTessellator\r\n *\r\n * @private\r\n */\r\nvar HeightmapTessellator = {};\r\n\r\n/**\r\n * The default structure of a heightmap, as given to {@link HeightmapTessellator.computeVertices}.\r\n *\r\n * @constant\r\n */\r\nHeightmapTessellator.DEFAULT_STRUCTURE = Object.freeze({\r\n heightScale: 1.0,\r\n heightOffset: 0.0,\r\n elementsPerHeight: 1,\r\n stride: 1,\r\n elementMultiplier: 256.0,\r\n isBigEndian: false,\r\n});\r\n\r\nvar cartesian3Scratch = new Cartesian3();\r\nvar matrix4Scratch = new Matrix4();\r\nvar minimumScratch = new Cartesian3();\r\nvar maximumScratch = new Cartesian3();\r\n\r\n/**\r\n * Fills an array of vertices from a heightmap image.\r\n *\r\n * @param {Object} options Object with the following properties:\r\n * @param {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} options.heightmap The heightmap to tessellate.\r\n * @param {Number} options.width The width of the heightmap, in height samples.\r\n * @param {Number} options.height The height of the heightmap, in height samples.\r\n * @param {Number} options.skirtHeight The height of skirts to drape at the edges of the heightmap.\r\n * @param {Rectangle} options.nativeRectangle A rectangle in the native coordinates of the heightmap's projection. For\r\n * a heightmap with a geographic projection, this is degrees. For the web mercator\r\n * projection, this is meters.\r\n * @param {Number} [options.exaggeration=1.0] The scale used to exaggerate the terrain.\r\n * @param {Rectangle} [options.rectangle] The rectangle covered by the heightmap, in geodetic coordinates with north, south, east and\r\n * west properties in radians. Either rectangle or nativeRectangle must be provided. If both\r\n * are provided, they're assumed to be consistent.\r\n * @param {Boolean} [options.isGeographic=true] True if the heightmap uses a {@link GeographicProjection}, or false if it uses\r\n * a {@link WebMercatorProjection}.\r\n * @param {Cartesian3} [options.relativeToCenter=Cartesian3.ZERO] The positions will be computed as Cartesian3.subtract(worldPosition, relativeToCenter)
.\r\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to which the heightmap applies.\r\n * @param {Object} [options.structure] An object describing the structure of the height data.\r\n * @param {Number} [options.structure.heightScale=1.0] The factor by which to multiply height samples in order to obtain\r\n * the height above the heightOffset, in meters. The heightOffset is added to the resulting\r\n * height after multiplying by the scale.\r\n * @param {Number} [options.structure.heightOffset=0.0] The offset to add to the scaled height to obtain the final\r\n * height in meters. The offset is added after the height sample is multiplied by the\r\n * heightScale.\r\n * @param {Number} [options.structure.elementsPerHeight=1] The number of elements in the buffer that make up a single height\r\n * sample. This is usually 1, indicating that each element is a separate height sample. If\r\n * it is greater than 1, that number of elements together form the height sample, which is\r\n * computed according to the structure.elementMultiplier and structure.isBigEndian properties.\r\n * @param {Number} [options.structure.stride=1] The number of elements to skip to get from the first element of\r\n * one height to the first element of the next height.\r\n * @param {Number} [options.structure.elementMultiplier=256.0] The multiplier used to compute the height value when the\r\n * stride property is greater than 1. For example, if the stride is 4 and the strideMultiplier\r\n * is 256, the height is computed as follows:\r\n * `height = buffer[index] + buffer[index + 1] * 256 + buffer[index + 2] * 256 * 256 + buffer[index + 3] * 256 * 256 * 256`\r\n * This is assuming that the isBigEndian property is false. If it is true, the order of the\r\n * elements is reversed.\r\n * @param {Number} [options.structure.lowestEncodedHeight] The lowest value that can be stored in the height buffer. Any heights that are lower\r\n * than this value after encoding with the `heightScale` and `heightOffset` are clamped to this value. For example, if the height\r\n * buffer is a `Uint16Array`, this value should be 0 because a `Uint16Array` cannot store negative numbers. If this parameter is\r\n * not specified, no minimum value is enforced.\r\n * @param {Number} [options.structure.highestEncodedHeight] The highest value that can be stored in the height buffer. Any heights that are higher\r\n * than this value after encoding with the `heightScale` and `heightOffset` are clamped to this value. For example, if the height\r\n * buffer is a `Uint16Array`, this value should be `256 * 256 - 1` or 65535 because a `Uint16Array` cannot store numbers larger\r\n * than 65535. If this parameter is not specified, no maximum value is enforced.\r\n * @param {Boolean} [options.structure.isBigEndian=false] Indicates endianness of the elements in the buffer when the\r\n * stride property is greater than 1. If this property is false, the first element is the\r\n * low-order element. If it is true, the first element is the high-order element.\r\n *\r\n * @example\r\n * var width = 5;\r\n * var height = 5;\r\n * var statistics = Cesium.HeightmapTessellator.computeVertices({\r\n * heightmap : [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0],\r\n * width : width,\r\n * height : height,\r\n * skirtHeight : 0.0,\r\n * nativeRectangle : {\r\n * west : 10.0,\r\n * east : 20.0,\r\n * south : 30.0,\r\n * north : 40.0\r\n * }\r\n * });\r\n *\r\n * var encoding = statistics.encoding;\r\n * var position = encoding.decodePosition(statistics.vertices, index * encoding.getStride());\r\n */\r\nHeightmapTessellator.computeVertices = function (options) {\r\n //>>includeStart('debug', pragmas.debug);\r\n if (!defined(options) || !defined(options.heightmap)) {\r\n throw new DeveloperError(\"options.heightmap is required.\");\r\n }\r\n if (!defined(options.width) || !defined(options.height)) {\r\n throw new DeveloperError(\"options.width and options.height are required.\");\r\n }\r\n if (!defined(options.nativeRectangle)) {\r\n throw new DeveloperError(\"options.nativeRectangle is required.\");\r\n }\r\n if (!defined(options.skirtHeight)) {\r\n throw new DeveloperError(\"options.skirtHeight is required.\");\r\n }\r\n //>>includeEnd('debug');\r\n\r\n // This function tends to be a performance hotspot for terrain rendering,\r\n // so it employs a lot of inlining and unrolling as an optimization.\r\n // In particular, the functionality of Ellipsoid.cartographicToCartesian\r\n // is inlined.\r\n\r\n var cos = Math.cos;\r\n var sin = Math.sin;\r\n var sqrt = Math.sqrt;\r\n var atan = Math.atan;\r\n var exp = Math.exp;\r\n var piOverTwo = CesiumMath.PI_OVER_TWO;\r\n var toRadians = CesiumMath.toRadians;\r\n\r\n var heightmap = options.heightmap;\r\n var width = options.width;\r\n var height = options.height;\r\n var skirtHeight = options.skirtHeight;\r\n\r\n var isGeographic = defaultValue(options.isGeographic, true);\r\n var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\r\n\r\n var oneOverGlobeSemimajorAxis = 1.0 / ellipsoid.maximumRadius;\r\n\r\n var nativeRectangle = options.nativeRectangle;\r\n\r\n var geographicWest;\r\n var geographicSouth;\r\n var geographicEast;\r\n var geographicNorth;\r\n\r\n var rectangle = options.rectangle;\r\n if (!defined(rectangle)) {\r\n if (isGeographic) {\r\n geographicWest = toRadians(nativeRectangle.west);\r\n geographicSouth = toRadians(nativeRectangle.south);\r\n geographicEast = toRadians(nativeRectangle.east);\r\n geographicNorth = toRadians(nativeRectangle.north);\r\n } else {\r\n geographicWest = nativeRectangle.west * oneOverGlobeSemimajorAxis;\r\n geographicSouth =\r\n piOverTwo -\r\n 2.0 * atan(exp(-nativeRectangle.south * oneOverGlobeSemimajorAxis));\r\n geographicEast = nativeRectangle.east * oneOverGlobeSemimajorAxis;\r\n geographicNorth =\r\n piOverTwo -\r\n 2.0 * atan(exp(-nativeRectangle.north * oneOverGlobeSemimajorAxis));\r\n }\r\n } else {\r\n geographicWest = rectangle.west;\r\n geographicSouth = rectangle.south;\r\n geographicEast = rectangle.east;\r\n geographicNorth = rectangle.north;\r\n }\r\n\r\n var relativeToCenter = options.relativeToCenter;\r\n var hasRelativeToCenter = defined(relativeToCenter);\r\n relativeToCenter = hasRelativeToCenter ? relativeToCenter : Cartesian3.ZERO;\r\n var exaggeration = defaultValue(options.exaggeration, 1.0);\r\n var includeWebMercatorT = defaultValue(options.includeWebMercatorT, false);\r\n\r\n var structure = defaultValue(\r\n options.structure,\r\n HeightmapTessellator.DEFAULT_STRUCTURE\r\n );\r\n var heightScale = defaultValue(\r\n structure.heightScale,\r\n HeightmapTessellator.DEFAULT_STRUCTURE.heightScale\r\n );\r\n var heightOffset = defaultValue(\r\n structure.heightOffset,\r\n HeightmapTessellator.DEFAULT_STRUCTURE.heightOffset\r\n );\r\n var elementsPerHeight = defaultValue(\r\n structure.elementsPerHeight,\r\n HeightmapTessellator.DEFAULT_STRUCTURE.elementsPerHeight\r\n );\r\n var stride = defaultValue(\r\n structure.stride,\r\n HeightmapTessellator.DEFAULT_STRUCTURE.stride\r\n );\r\n var elementMultiplier = defaultValue(\r\n structure.elementMultiplier,\r\n HeightmapTessellator.DEFAULT_STRUCTURE.elementMultiplier\r\n );\r\n var isBigEndian = defaultValue(\r\n structure.isBigEndian,\r\n HeightmapTessellator.DEFAULT_STRUCTURE.isBigEndian\r\n );\r\n\r\n var rectangleWidth = Rectangle.computeWidth(nativeRectangle);\r\n var rectangleHeight = Rectangle.computeHeight(nativeRectangle);\r\n\r\n var granularityX = rectangleWidth / (width - 1);\r\n var granularityY = rectangleHeight / (height - 1);\r\n\r\n if (!isGeographic) {\r\n rectangleWidth *= oneOverGlobeSemimajorAxis;\r\n rectangleHeight *= oneOverGlobeSemimajorAxis;\r\n }\r\n\r\n var radiiSquared = ellipsoid.radiiSquared;\r\n var radiiSquaredX = radiiSquared.x;\r\n var radiiSquaredY = radiiSquared.y;\r\n var radiiSquaredZ = radiiSquared.z;\r\n\r\n var minimumHeight = 65536.0;\r\n var maximumHeight = -65536.0;\r\n\r\n var fromENU = Transforms.eastNorthUpToFixedFrame(relativeToCenter, ellipsoid);\r\n var toENU = Matrix4.inverseTransformation(fromENU, matrix4Scratch);\r\n\r\n var southMercatorY;\r\n var oneOverMercatorHeight;\r\n if (includeWebMercatorT) {\r\n southMercatorY = WebMercatorProjection.geodeticLatitudeToMercatorAngle(\r\n geographicSouth\r\n );\r\n oneOverMercatorHeight =\r\n 1.0 /\r\n (WebMercatorProjection.geodeticLatitudeToMercatorAngle(geographicNorth) -\r\n southMercatorY);\r\n }\r\n\r\n var minimum = minimumScratch;\r\n minimum.x = Number.POSITIVE_INFINITY;\r\n minimum.y = Number.POSITIVE_INFINITY;\r\n minimum.z = Number.POSITIVE_INFINITY;\r\n\r\n var maximum = maximumScratch;\r\n maximum.x = Number.NEGATIVE_INFINITY;\r\n maximum.y = Number.NEGATIVE_INFINITY;\r\n maximum.z = Number.NEGATIVE_INFINITY;\r\n\r\n var hMin = Number.POSITIVE_INFINITY;\r\n\r\n var gridVertexCount = width * height;\r\n var edgeVertexCount = skirtHeight > 0.0 ? width * 2 + height * 2 : 0;\r\n var vertexCount = gridVertexCount + edgeVertexCount;\r\n\r\n var positions = new Array(vertexCount);\r\n var heights = new Array(vertexCount);\r\n var uvs = new Array(vertexCount);\r\n var webMercatorTs = includeWebMercatorT ? new Array(vertexCount) : [];\r\n\r\n var startRow = 0;\r\n var endRow = height;\r\n var startCol = 0;\r\n var endCol = width;\r\n\r\n if (skirtHeight > 0.0) {\r\n --startRow;\r\n ++endRow;\r\n --startCol;\r\n ++endCol;\r\n }\r\n\r\n var skirtOffsetPercentage = 0.00001;\r\n\r\n for (var rowIndex = startRow; rowIndex < endRow; ++rowIndex) {\r\n var row = rowIndex;\r\n if (row < 0) {\r\n row = 0;\r\n }\r\n if (row >= height) {\r\n row = height - 1;\r\n }\r\n\r\n var latitude = nativeRectangle.north - granularityY * row;\r\n\r\n if (!isGeographic) {\r\n latitude =\r\n piOverTwo - 2.0 * atan(exp(-latitude * oneOverGlobeSemimajorAxis));\r\n } else {\r\n latitude = toRadians(latitude);\r\n }\r\n\r\n var v = (latitude - geographicSouth) / (geographicNorth - geographicSouth);\r\n v = CesiumMath.clamp(v, 0.0, 1.0);\r\n\r\n var isNorthEdge = rowIndex === startRow;\r\n var isSouthEdge = rowIndex === endRow - 1;\r\n if (skirtHeight > 0.0) {\r\n if (isNorthEdge) {\r\n latitude += skirtOffsetPercentage * rectangleHeight;\r\n } else if (isSouthEdge) {\r\n latitude -= skirtOffsetPercentage * rectangleHeight;\r\n }\r\n }\r\n\r\n var cosLatitude = cos(latitude);\r\n var nZ = sin(latitude);\r\n var kZ = radiiSquaredZ * nZ;\r\n\r\n var webMercatorT;\r\n if (includeWebMercatorT) {\r\n webMercatorT =\r\n (WebMercatorProjection.geodeticLatitudeToMercatorAngle(latitude) -\r\n southMercatorY) *\r\n oneOverMercatorHeight;\r\n }\r\n\r\n for (var colIndex = startCol; colIndex < endCol; ++colIndex) {\r\n var col = colIndex;\r\n if (col < 0) {\r\n col = 0;\r\n }\r\n if (col >= width) {\r\n col = width - 1;\r\n }\r\n\r\n var terrainOffset = row * (width * stride) + col * stride;\r\n\r\n var heightSample;\r\n if (elementsPerHeight === 1) {\r\n heightSample = heightmap[terrainOffset];\r\n } else {\r\n heightSample = 0;\r\n\r\n var elementOffset;\r\n if (isBigEndian) {\r\n for (\r\n elementOffset = 0;\r\n elementOffset < elementsPerHeight;\r\n ++elementOffset\r\n ) {\r\n heightSample =\r\n heightSample * elementMultiplier +\r\n heightmap[terrainOffset + elementOffset];\r\n }\r\n } else {\r\n for (\r\n elementOffset = elementsPerHeight - 1;\r\n elementOffset >= 0;\r\n --elementOffset\r\n ) {\r\n heightSample =\r\n heightSample * elementMultiplier +\r\n heightmap[terrainOffset + elementOffset];\r\n }\r\n }\r\n }\r\n\r\n heightSample = (heightSample * heightScale + heightOffset) * exaggeration;\r\n\r\n maximumHeight = Math.max(maximumHeight, heightSample);\r\n minimumHeight = Math.min(minimumHeight, heightSample);\r\n\r\n var longitude = nativeRectangle.west + granularityX * col;\r\n\r\n if (!isGeographic) {\r\n longitude = longitude * oneOverGlobeSemimajorAxis;\r\n } else {\r\n longitude = toRadians(longitude);\r\n }\r\n\r\n var u = (longitude - geographicWest) / (geographicEast - geographicWest);\r\n u = CesiumMath.clamp(u, 0.0, 1.0);\r\n\r\n var index = row * width + col;\r\n\r\n if (skirtHeight > 0.0) {\r\n var isWestEdge = colIndex === startCol;\r\n var isEastEdge = colIndex === endCol - 1;\r\n var isEdge = isNorthEdge || isSouthEdge || isWestEdge || isEastEdge;\r\n var isCorner =\r\n (isNorthEdge || isSouthEdge) && (isWestEdge || isEastEdge);\r\n if (isCorner) {\r\n // Don't generate skirts on the corners.\r\n continue;\r\n } else if (isEdge) {\r\n heightSample -= skirtHeight;\r\n\r\n if (isWestEdge) {\r\n // The outer loop iterates north to south but the indices are ordered south to north, hence the index flip below\r\n index = gridVertexCount + (height - row - 1);\r\n longitude -= skirtOffsetPercentage * rectangleWidth;\r\n } else if (isSouthEdge) {\r\n // Add after west indices. South indices are ordered east to west.\r\n index = gridVertexCount + height + (width - col - 1);\r\n } else if (isEastEdge) {\r\n // Add after west and south indices. East indices are ordered north to south. The index is flipped like above.\r\n index = gridVertexCount + height + width + row;\r\n longitude += skirtOffsetPercentage * rectangleWidth;\r\n } else if (isNorthEdge) {\r\n // Add after west, south, and east indices. North indices are ordered west to east.\r\n index = gridVertexCount + height + width + height + col;\r\n }\r\n }\r\n }\r\n\r\n var nX = cosLatitude * cos(longitude);\r\n var nY = cosLatitude * sin(longitude);\r\n\r\n var kX = radiiSquaredX * nX;\r\n var kY = radiiSquaredY * nY;\r\n\r\n var gamma = sqrt(kX * nX + kY * nY + kZ * nZ);\r\n var oneOverGamma = 1.0 / gamma;\r\n\r\n var rSurfaceX = kX * oneOverGamma;\r\n var rSurfaceY = kY * oneOverGamma;\r\n var rSurfaceZ = kZ * oneOverGamma;\r\n\r\n var position = new Cartesian3();\r\n position.x = rSurfaceX + nX * heightSample;\r\n position.y = rSurfaceY + nY * heightSample;\r\n position.z = rSurfaceZ + nZ * heightSample;\r\n\r\n positions[index] = position;\r\n heights[index] = heightSample;\r\n uvs[index] = new Cartesian2(u, v);\r\n\r\n if (includeWebMercatorT) {\r\n webMercatorTs[index] = webMercatorT;\r\n }\r\n\r\n Matrix4.multiplyByPoint(toENU, position, cartesian3Scratch);\r\n\r\n Cartesian3.minimumByComponent(cartesian3Scratch, minimum, minimum);\r\n Cartesian3.maximumByComponent(cartesian3Scratch, maximum, maximum);\r\n hMin = Math.min(hMin, heightSample);\r\n }\r\n }\r\n\r\n var boundingSphere3D = BoundingSphere.fromPoints(positions);\r\n var orientedBoundingBox;\r\n if (defined(rectangle)) {\r\n orientedBoundingBox = OrientedBoundingBox.fromRectangle(\r\n rectangle,\r\n minimumHeight,\r\n maximumHeight,\r\n ellipsoid\r\n );\r\n }\r\n\r\n var occludeePointInScaledSpace;\r\n if (hasRelativeToCenter) {\r\n var occluder = new EllipsoidalOccluder(ellipsoid);\r\n occludeePointInScaledSpace = occluder.computeHorizonCullingPointPossiblyUnderEllipsoid(\r\n relativeToCenter,\r\n positions,\r\n minimumHeight\r\n );\r\n }\r\n\r\n var aaBox = new AxisAlignedBoundingBox(minimum, maximum, relativeToCenter);\r\n var encoding = new TerrainEncoding(\r\n aaBox,\r\n hMin,\r\n maximumHeight,\r\n fromENU,\r\n false,\r\n includeWebMercatorT\r\n );\r\n var vertices = new Float32Array(vertexCount * encoding.getStride());\r\n\r\n var bufferIndex = 0;\r\n for (var j = 0; j < vertexCount; ++j) {\r\n bufferIndex = encoding.encode(\r\n vertices,\r\n bufferIndex,\r\n positions[j],\r\n uvs[j],\r\n heights[j],\r\n undefined,\r\n webMercatorTs[j]\r\n );\r\n }\r\n\r\n return {\r\n vertices: vertices,\r\n maximumHeight: maximumHeight,\r\n minimumHeight: minimumHeight,\r\n encoding: encoding,\r\n boundingSphere3D: boundingSphere3D,\r\n orientedBoundingBox: orientedBoundingBox,\r\n occludeePointInScaledSpace: occludeePointInScaledSpace,\r\n };\r\n};\r\nexport default HeightmapTessellator;\r\n","import defaultValue from \"./defaultValue.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\n\r\nfunction returnTrue() {\r\n return true;\r\n}\r\n\r\n/**\r\n * Destroys an object. Each of the object's functions, including functions in its prototype,\r\n * is replaced with a function that throws a {@link DeveloperError}, except for the object's\r\n * isDestroyed
function, which is set to a function that returns true
.\r\n * The object's properties are removed with delete
.\r\n *
\r\n * This function is used by objects that hold native resources, e.g., WebGL resources, which\r\n * need to be explicitly released. Client code calls an object's destroy
function,\r\n * which then releases the native resource and calls destroyObject
to put itself\r\n * in a destroyed state.\r\n *\r\n * @function\r\n *\r\n * @param {Object} object The object to destroy.\r\n * @param {String} [message] The message to include in the exception that is thrown if\r\n * a destroyed object's function is called.\r\n *\r\n *\r\n * @example\r\n * // How a texture would destroy itself.\r\n * this.destroy = function () {\r\n * _gl.deleteTexture(_texture);\r\n * return Cesium.destroyObject(this);\r\n * };\r\n *\r\n * @see DeveloperError\r\n */\r\nfunction destroyObject(object, message) {\r\n message = defaultValue(\r\n message,\r\n \"This object was destroyed, i.e., destroy() was called.\"\r\n );\r\n\r\n function throwOnDestroyed() {\r\n //>>includeStart('debug', pragmas.debug);\r\n throw new DeveloperError(message);\r\n //>>includeEnd('debug');\r\n }\r\n\r\n for (var key in object) {\r\n if (typeof object[key] === \"function\") {\r\n object[key] = throwOnDestroyed;\r\n }\r\n }\r\n\r\n object.isDestroyed = returnTrue;\r\n\r\n return undefined;\r\n}\r\nexport default destroyObject;\r\n","import Uri from \"../ThirdParty/Uri.js\";\r\nimport when from \"../ThirdParty/when.js\";\r\nimport buildModuleUrl from \"./buildModuleUrl.js\";\r\nimport defaultValue from \"./defaultValue.js\";\r\nimport defined from \"./defined.js\";\r\nimport destroyObject from \"./destroyObject.js\";\r\nimport DeveloperError from \"./DeveloperError.js\";\r\nimport Event from \"./Event.js\";\r\nimport FeatureDetection from \"./FeatureDetection.js\";\r\nimport isCrossOriginUrl from \"./isCrossOriginUrl.js\";\r\nimport Resource from \"./Resource.js\";\r\nimport RuntimeError from \"./RuntimeError.js\";\r\n\r\nfunction canTransferArrayBuffer() {\r\n if (!defined(TaskProcessor._canTransferArrayBuffer)) {\r\n var worker = new Worker(getWorkerUrl(\"Workers/transferTypedArrayTest.js\"));\r\n worker.postMessage = defaultValue(\r\n worker.webkitPostMessage,\r\n worker.postMessage\r\n );\r\n\r\n var value = 99;\r\n var array = new Int8Array([value]);\r\n\r\n try {\r\n // postMessage might fail with a DataCloneError\r\n // if transferring array buffers is not supported.\r\n worker.postMessage(\r\n {\r\n array: array,\r\n },\r\n [array.buffer]\r\n );\r\n } catch (e) {\r\n TaskProcessor._canTransferArrayBuffer = false;\r\n return TaskProcessor._canTransferArrayBuffer;\r\n }\r\n\r\n var deferred = when.defer();\r\n\r\n worker.onmessage = function (event) {\r\n var array = event.data.array;\r\n\r\n // some versions of Firefox silently fail to transfer typed arrays.\r\n // https://bugzilla.mozilla.org/show_bug.cgi?id=841904\r\n // Check to make sure the value round-trips successfully.\r\n var result = defined(array) && array[0] === value;\r\n deferred.resolve(result);\r\n\r\n worker.terminate();\r\n\r\n TaskProcessor._canTransferArrayBuffer = result;\r\n };\r\n\r\n TaskProcessor._canTransferArrayBuffer = deferred.promise;\r\n }\r\n\r\n return TaskProcessor._canTransferArrayBuffer;\r\n}\r\n\r\nvar taskCompletedEvent = new Event();\r\n\r\nfunction completeTask(processor, data) {\r\n --processor._activeTasks;\r\n\r\n var id = data.id;\r\n if (!defined(id)) {\r\n // This is not one of ours.\r\n return;\r\n }\r\n\r\n var deferreds = processor._deferreds;\r\n var deferred = deferreds[id];\r\n\r\n if (defined(data.error)) {\r\n var error = data.error;\r\n if (error.name === \"RuntimeError\") {\r\n error = new RuntimeError(data.error.message);\r\n error.stack = data.error.stack;\r\n } else if (error.name === \"DeveloperError\") {\r\n error = new DeveloperError(data.error.message);\r\n error.stack = data.error.stack;\r\n }\r\n taskCompletedEvent.raiseEvent(error);\r\n deferred.reject(error);\r\n } else {\r\n taskCompletedEvent.raiseEvent();\r\n deferred.resolve(data.result);\r\n }\r\n\r\n delete deferreds[id];\r\n}\r\n\r\nfunction getWorkerUrl(moduleID) {\r\n var url = buildModuleUrl(moduleID);\r\n\r\n if (isCrossOriginUrl(url)) {\r\n //to load cross-origin, create a shim worker from a blob URL\r\n var script = 'importScripts(\"' + url + '\");';\r\n\r\n var blob;\r\n try {\r\n blob = new Blob([script], {\r\n type: \"application/javascript\",\r\n });\r\n } catch (e) {\r\n var BlobBuilder =\r\n window.BlobBuilder ||\r\n window.WebKitBlobBuilder ||\r\n window.MozBlobBuilder ||\r\n window.MSBlobBuilder;\r\n var blobBuilder = new BlobBuilder();\r\n blobBuilder.append(script);\r\n blob = blobBuilder.getBlob(\"application/javascript\");\r\n }\r\n\r\n var URL = window.URL || window.webkitURL;\r\n url = URL.createObjectURL(blob);\r\n }\r\n\r\n return url;\r\n}\r\n\r\nvar bootstrapperUrlResult;\r\nfunction getBootstrapperUrl() {\r\n if (!defined(bootstrapperUrlResult)) {\r\n bootstrapperUrlResult = getWorkerUrl(\"Workers/cesiumWorkerBootstrapper.js\");\r\n }\r\n return bootstrapperUrlResult;\r\n}\r\n\r\nfunction createWorker(processor) {\r\n var worker = new Worker(getBootstrapperUrl());\r\n worker.postMessage = defaultValue(\r\n worker.webkitPostMessage,\r\n worker.postMessage\r\n );\r\n\r\n var bootstrapMessage = {\r\n loaderConfig: {\r\n paths: {\r\n Workers: buildModuleUrl(\"Workers\"),\r\n },\r\n baseUrl: buildModuleUrl.getCesiumBaseUrl().url,\r\n },\r\n workerModule: processor._workerPath,\r\n };\r\n\r\n worker.postMessage(bootstrapMessage);\r\n worker.onmessage = function (event) {\r\n completeTask(processor, event.data);\r\n };\r\n\r\n return worker;\r\n}\r\n\r\nfunction getWebAssemblyLoaderConfig(processor, wasmOptions) {\r\n var config = {\r\n modulePath: undefined,\r\n wasmBinaryFile: undefined,\r\n wasmBinary: undefined,\r\n };\r\n\r\n // Web assembly not supported, use fallback js module if provided\r\n if (!FeatureDetection.supportsWebAssembly()) {\r\n if (!defined(wasmOptions.fallbackModulePath)) {\r\n throw new RuntimeError(\r\n \"This browser does not support Web Assembly, and no backup module was provided for \" +\r\n processor._workerPath\r\n );\r\n }\r\n\r\n config.modulePath = buildModuleUrl(wasmOptions.fallbackModulePath);\r\n return when.resolve(config);\r\n }\r\n\r\n config.modulePath = buildModuleUrl(wasmOptions.modulePath);\r\n config.wasmBinaryFile = buildModuleUrl(wasmOptions.wasmBinaryFile);\r\n\r\n return Resource.fetchArrayBuffer({\r\n url: config.wasmBinaryFile,\r\n }).then(function (arrayBuffer) {\r\n config.wasmBinary = arrayBuffer;\r\n return config;\r\n });\r\n}\r\n\r\n/**\r\n * A wrapper around a web worker that allows scheduling tasks for a given worker,\r\n * returning results asynchronously via a promise.\r\n *\r\n * The Worker is not constructed until a task is scheduled.\r\n *\r\n * @alias TaskProcessor\r\n * @constructor\r\n *\r\n * @param {String} workerPath The Url to the worker. This can either be an absolute path or relative to the Cesium Workers folder.\r\n * @param {Number} [maximumActiveTasks=Number.POSITIVE_INFINITY] The maximum number of active tasks. Once exceeded,\r\n * scheduleTask will not queue any more tasks, allowing\r\n * work to be rescheduled in future frames.\r\n */\r\nfunction TaskProcessor(workerPath, maximumActiveTasks) {\r\n this._workerPath = new Uri(workerPath).isAbsolute()\r\n ? workerPath\r\n : TaskProcessor._workerModulePrefix + workerPath;\r\n this._maximumActiveTasks = defaultValue(\r\n maximumActiveTasks,\r\n Number.POSITIVE_INFINITY\r\n );\r\n this._activeTasks = 0;\r\n this._deferreds = {};\r\n this._nextID = 0;\r\n}\r\n\r\nvar emptyTransferableObjectArray = [];\r\n\r\n/**\r\n * Schedule a task to be processed by the web worker asynchronously. If there are currently more\r\n * tasks active than the maximum set by the constructor, will immediately return undefined.\r\n * Otherwise, returns a promise that will resolve to the result posted back by the worker when\r\n * finished.\r\n *\r\n * @param {Object} parameters Any input data that will be posted to the worker.\r\n * @param {Object[]} [transferableObjects] An array of objects contained in parameters that should be\r\n * transferred to the worker instead of copied.\r\n * @returns {Promise.