qd-changjing/public/static/Build/CesiumUnminified/Workers/arrayRemoveDuplicates-65de6...

1 line
7.0 KiB
Plaintext
Raw Normal View History

2022-07-05 16:56:29 +08:00
{"version":3,"file":"arrayRemoveDuplicates-65de6756.js","sources":["../../../../Source/Core/arrayRemoveDuplicates.js"],"sourcesContent":["import Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport CesiumMath from \"./Math.js\";\n\nconst removeDuplicatesEpsilon = CesiumMath.EPSILON10;\n\n/**\n * Removes adjacent duplicate values in an array of values.\n *\n * @param {Array.<*>} [values] The array of values.\n * @param {Function} equalsEpsilon Function to compare values with an epsilon. Boolean equalsEpsilon(left, right, epsilon).\n * @param {Boolean} [wrapAround=false] Compare the last value in the array against the first value. If they are equal, the last value is removed.\n * @param {Array.<Number>} [removedIndices=undefined] Store the indices that correspond to the duplicate items removed from the array, if there were any.\n * @returns {Array.<*>|undefined} A new array of values with no adjacent duplicate values or the input array if no duplicates were found.\n *\n * @example\n * // Returns [(1.0, 1.0, 1.0), (2.0, 2.0, 2.0), (3.0, 3.0, 3.0), (1.0, 1.0, 1.0)]\n * const values = [\n * new Cesium.Cartesian3(1.0, 1.0, 1.0),\n * new Cesium.Cartesian3(1.0, 1.0, 1.0),\n * new Cesium.Cartesian3(2.0, 2.0, 2.0),\n * new Cesium.Cartesian3(3.0, 3.0, 3.0),\n * new Cesium.Cartesian3(1.0, 1.0, 1.0)];\n * const nonDuplicatevalues = Cesium.PolylinePipeline.removeDuplicates(values, Cartesian3.equalsEpsilon);\n *\n * @example\n * // Returns [(1.0, 1.0, 1.0), (2.0, 2.0, 2.0), (3.0, 3.0, 3.0)]\n * const values = [\n * new Cesium.Cartesian3(1.0, 1.0, 1.0),\n * new Cesium.Cartesian3(1.0, 1.0, 1.0),\n * new Cesium.Cartesian3(2.0, 2.0, 2.0),\n * new Cesium.Cartesian3(3.0, 3.0, 3.0),\n * new Cesium.Cartesian3(1.0, 1.0, 1.0)];\n * const nonDuplicatevalues = Cesium.PolylinePipeline.removeDuplicates(values, Cartesian3.equalsEpsilon, true);\n *\n * @example\n * // Returns [(1.0, 1.0, 1.0), (2.0, 2.0, 2.0), (3.0, 3.0, 3.0)]\n * // removedIndices will be equal to [1, 3, 5]\n * const values = [\n * new Cesium.Cartesian3(1.0, 1.0, 1.0),\n * new Cesium.Cartesian3(1.0, 1.0, 1.0),\n * new Cesium.Cartesian3(2.0, 2.0, 2.0),\n * new Cesium.Cartesian3(2.0, 2.0, 2.0),\n * new Cesium.Cartesian3(3.0, 3.0, 3.0),\n * new Cesium.Cartesian3(1.0, 1.0, 1.0)];\n * const nonDuplicatevalues = Cesium.PolylinePipeline.removeDuplicates(values, Cartesian3.equalsEpsilon, true);\n * @private\n */\nfunction arrayRemoveDuplicates(\n values,\n equalsEpsilon,\n wrapAround,\n removedIndices\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"equalsEpsilon\", equalsEpsilon);\n //>>includeEnd('debug');\n\n if (!defined(values)) {\n return undefined;\n }\n\n wrapAround = defaultValue(wrapAround, false);\n const storeRemovedIndices = defined(removedIndices);\n\n const length = values.length;\n if (length < 2) {\n return values;\n }\n\n let i;\n let v0 = values[0];\n let v1;\n\n // We only want to create a new array if there are duplicates in the array.\n // As such, cleanedValues is undefined until it encounters the first duplicate, if it exists.\n let cleanedValues;\n let lastCleanIndex = 0;\n\n // removedIndexLCI keeps track of where lastCleanIndex would be if it were sorted into the removedIndices array.\n // In case of arrays such as [A, B, C, ..., A, A, A], removedIndices will not be sorted properly without this.\n let removedIndexLCI = -1;\n\n for (i = 1; i < length; ++i) {\n v1 = values[i];\n if (equalsEpsilon(v0, v1, removeDuplicatesEpsilon)) {\n if (!defined(cleanedValues)) {\n cleanedValues = values.slice(0, i);\n lastCleanIndex = i - 1;\n removedIndexLCI = 0;\n }\n if (storeRemovedIndices) {\n removedIndices.push(i);\n }\n } else {\n if (defined(cleanedValues)) {\n cleanedValues.push(v1);\n lastCleanIndex = i;\n if (storeRemovedIndices) {\n removedIndexLCI = removedIndices.length;\n }\n }\n