arrayRemoveDuplicates-dd708d81.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './defined-26bd4a03', './Check-da037458', './defaultValue-f2e68450', './Math-fa6e45cb'], function (exports, defined, Check, defaultValue, _Math) { 'use strict';
  3. var removeDuplicatesEpsilon = _Math.CesiumMath.EPSILON10;
  4. /**
  5. * Removes adjacent duplicate values in an array of values.
  6. *
  7. * @param {Array.<*>} [values] The array of values.
  8. * @param {Function} equalsEpsilon Function to compare values with an epsilon. Boolean equalsEpsilon(left, right, epsilon).
  9. * @param {Boolean} [wrapAround=false] Compare the last value in the array against the first value.
  10. * @returns {Array.<*>|undefined} A new array of values with no adjacent duplicate values or the input array if no duplicates were found.
  11. *
  12. * @example
  13. * // 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)]
  14. * var values = [
  15. * new Cesium.Cartesian3(1.0, 1.0, 1.0),
  16. * new Cesium.Cartesian3(1.0, 1.0, 1.0),
  17. * new Cesium.Cartesian3(2.0, 2.0, 2.0),
  18. * new Cesium.Cartesian3(3.0, 3.0, 3.0),
  19. * new Cesium.Cartesian3(1.0, 1.0, 1.0)];
  20. * var nonDuplicatevalues = Cesium.PolylinePipeline.removeDuplicates(values, Cartesian3.equalsEpsilon);
  21. *
  22. * @example
  23. * // Returns [(1.0, 1.0, 1.0), (2.0, 2.0, 2.0), (3.0, 3.0, 3.0)]
  24. * var values = [
  25. * new Cesium.Cartesian3(1.0, 1.0, 1.0),
  26. * new Cesium.Cartesian3(1.0, 1.0, 1.0),
  27. * new Cesium.Cartesian3(2.0, 2.0, 2.0),
  28. * new Cesium.Cartesian3(3.0, 3.0, 3.0),
  29. * new Cesium.Cartesian3(1.0, 1.0, 1.0)];
  30. * var nonDuplicatevalues = Cesium.PolylinePipeline.removeDuplicates(values, Cartesian3.equalsEpsilon, true);
  31. *
  32. * @private
  33. */
  34. function arrayRemoveDuplicates(values, equalsEpsilon, wrapAround) {
  35. //>>includeStart('debug', pragmas.debug);
  36. Check.Check.defined('equalsEpsilon', equalsEpsilon);
  37. //>>includeEnd('debug');
  38. if (!defined.defined(values)) {
  39. return undefined;
  40. }
  41. wrapAround = defaultValue.defaultValue(wrapAround, false);
  42. var length = values.length;
  43. if (length < 2) {
  44. return values;
  45. }
  46. var i;
  47. var v0;
  48. var v1;
  49. for (i = 1; i < length; ++i) {
  50. v0 = values[i - 1];
  51. v1 = values[i];
  52. if (equalsEpsilon(v0, v1, removeDuplicatesEpsilon)) {
  53. break;
  54. }
  55. }
  56. if (i === length) {
  57. if (wrapAround && equalsEpsilon(values[0], values[values.length - 1], removeDuplicatesEpsilon)) {
  58. return values.slice(1);
  59. }
  60. return values;
  61. }
  62. var cleanedvalues = values.slice(0, i);
  63. for (; i < length; ++i) {
  64. // v0 is set by either the previous loop, or the previous clean point.
  65. v1 = values[i];
  66. if (!equalsEpsilon(v0, v1, removeDuplicatesEpsilon)) {
  67. cleanedvalues.push(v1);
  68. v0 = v1;
  69. }
  70. }
  71. if (wrapAround && cleanedvalues.length > 1 && equalsEpsilon(cleanedvalues[0], cleanedvalues[cleanedvalues.length - 1], removeDuplicatesEpsilon)) {
  72. cleanedvalues.shift();
  73. }
  74. return cleanedvalues;
  75. }
  76. exports.arrayRemoveDuplicates = arrayRemoveDuplicates;
  77. });