{"version":3,"file":"EncodedCartesian3-da8f96bc.js","sources":["../../../../Source/Core/EncodedCartesian3.js"],"sourcesContent":["import Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport defined from \"./defined.js\";\n\n/**\n * A fixed-point encoding of a {@link Cartesian3} with 64-bit floating-point components, as two {@link Cartesian3}\n * values that, when converted to 32-bit floating-point and added, approximate the original input.\n *

\n * This is used to encode positions in vertex buffers for rendering without jittering artifacts\n * as described in {@link http://help.agi.com/AGIComponents/html/BlogPrecisionsPrecisions.htm|Precisions, Precisions}.\n *

\n *\n * @alias EncodedCartesian3\n * @constructor\n *\n * @private\n */\nfunction EncodedCartesian3() {\n /**\n * The high bits for each component. Bits 0 to 22 store the whole value. Bits 23 to 31 are not used.\n *\n * @type {Cartesian3}\n * @default {@link Cartesian3.ZERO}\n */\n this.high = Cartesian3.clone(Cartesian3.ZERO);\n\n /**\n * The low bits for each component. Bits 7 to 22 store the whole value, and bits 0 to 6 store the fraction. Bits 23 to 31 are not used.\n *\n * @type {Cartesian3}\n * @default {@link Cartesian3.ZERO}\n */\n this.low = Cartesian3.clone(Cartesian3.ZERO);\n}\n\n/**\n * Encodes a 64-bit floating-point value as two floating-point values that, when converted to\n * 32-bit floating-point and added, approximate the original input. The returned object\n * has high and low properties for the high and low bits, respectively.\n *

\n * The fixed-point encoding follows {@link http://help.agi.com/AGIComponents/html/BlogPrecisionsPrecisions.htm|Precisions, Precisions}.\n *

\n *\n * @param {Number} value The floating-point value to encode.\n * @param {Object} [result] The object onto which to store the result.\n * @returns {Object} The modified result parameter or a new instance if one was not provided.\n *\n * @example\n * const value = 1234567.1234567;\n * const splitValue = Cesium.EncodedCartesian3.encode(value);\n */\nEncodedCartesian3.encode = function (value, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"value\", value);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = {\n high: 0.0,\n low: 0.0,\n };\n }\n\n let doubleHigh;\n if (value >= 0.0) {\n doubleHigh = Math.floor(value / 65536.0) * 65536.0;\n result.high = doubleHigh;\n result.low = value - doubleHigh;\n } else {\n doubleHigh = Math.floor(-value / 65536.0) * 65536.0;\n result.high = -doubleHigh;\n result.low = value + doubleHigh;\n }\n\n return result;\n};\n\nconst scratchEncode = {\n high: 0.0,\n low: 0.0,\n};\n\n/**\n * Encodes a {@link Cartesian3} with 64-bit floating-point components as two {@link Cartesian3}\n * values that, when converted to 32-bit floating-point and added, approximate the original input.\n *

\n * The fixed-point encoding follows {@link https://help.agi.com/AGIComponents/html/BlogPrecisionsPrecisions.htm|Precisions, Precisions}.\n *

\n *\n * @param {Cartesian3} cartesian The cartesian to encode.\n * @param {EncodedCartesian3} [result] The object onto which to store the result.\n * @returns {EncodedCartesian3} The modified result parameter or a new EncodedCartesian3 instance if one was not provided.\n *\n * @example\n * const cart = new Cesium.Cartesian3(-10000000.0, 0.0, 10000000.0);\n * const encoded = Cesium.EncodedCartesian3.fromCartesian(cart);\n */\nEncodedCartesian3.fromCartesian = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new EncodedCartesian3();\n }\n\n const high = result.high;\n const low = result.low;\n\n EncodedCartesian3.encode(cartesian.x, scratchEncode);\n high.x = scratchEncode.high;\n low.x = scratchEncode.low;\n\n EncodedCartesian3.encode(cartesian.y, scratchEncode);\n high.y = scratchEncode.high;\n low.y = scratchEncode.low;\n\n EncodedCartesian3.encode(cartesian.z, scratchEncode);\n high.z = scratchEncode.high;\n low.z = scratchEncode.low;\n\n return result;\n};\n\nconst encodedP = new EncodedCartesian3();\n\n/**\n * Encodes the provided cartesian, and writes it to an array with high\n * components followed by low components, i.e. [high.x, high.y, high.z, low.x, low.y, low.z].\n *

\n * This is used to create interleaved high-precision position vertex attributes.\n *

\n *\n * @param {Cartesian3} cartesian The cartesian to encode.\n * @param {Number[]} cartesianArray The array to write to.\n * @param {Number} index The index into the array to start writing. Six elements will be written.\n *\n * @exception {DeveloperError} index must be a number greater than or equal to 0.\n *\n * @example\n * const positions = [\n * new Cesium.Cartesian3(),\n * // ...\n * ];\n * const encodedPositions = new Float32Array(2 * 3 * positions.length);\n * let j = 0;\n * for (let i = 0; i < positions.length; ++i) {\n * Cesium.EncodedCartesian3.writeElement(positions[i], encodedPositions, j);\n * j += 6;\n * }\n */\nEncodedCartesian3.writeElements = function (cartesian, cartesianArray, index) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"cartesianArray\", cartesianArray);\n Check.typeOf.number(\"index\", index);\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\n //>>includeEnd('debug');\n\n EncodedCartesian3.fromCartesian(cartesian, encodedP);\n const high = encodedP.high;\n const low = encodedP.low;\n\n cartesianArray[index] = high.x;\n cartesianArray[index + 1] = high.y;\n cartesianArray[index + 2] = high.z;\n cartesianArray[index + 3] = low.x;\n cartesianArray[index + 4] = low.y;\n cartesianArray[index + 5] = low.z;\n};\nexport default EncodedCartesian3;\n"],"names":["Cartesian3","Check","defined"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;EAIA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,SAAS,iBAAiB,GAAG;EAC7B;EACA;EACA;EACA;EACA;EACA;EACA,EAAE,IAAI,CAAC,IAAI,GAAGA,kBAAU,CAAC,KAAK,CAACA,kBAAU,CAAC,IAAI,CAAC,CAAC;AAChD;EACA;EACA;EACA;EACA;EACA;EACA;EACA,EAAE,IAAI,CAAC,GAAG,GAAGA,kBAAU,CAAC,KAAK,CAACA,kBAAU,CAAC,IAAI,CAAC,CAAC;EAC/C,CAAC;AACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,iBAAiB,CAAC,MAAM,GAAG,UAAU,KAAK,EAAE,MAAM,EAAE;EACpD;EACA,EAAEC,kBAAK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