arrayRemoveDuplicates-1ded18d8.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './when-e6985d2a', './Check-24cae389', './Math-392d0035'], function (exports, when, Check, _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 (!when.defined(values)) {
  39. return undefined;
  40. }
  41. wrapAround = when.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 (
  58. wrapAround &&
  59. equalsEpsilon(
  60. values[0],
  61. values[values.length - 1],
  62. removeDuplicatesEpsilon
  63. )
  64. ) {
  65. return values.slice(1);
  66. }
  67. return values;
  68. }
  69. var cleanedvalues = values.slice(0, i);
  70. for (; i < length; ++i) {
  71. // v0 is set by either the previous loop, or the previous clean point.
  72. v1 = values[i];
  73. if (!equalsEpsilon(v0, v1, removeDuplicatesEpsilon)) {
  74. cleanedvalues.push(v1);
  75. v0 = v1;
  76. }
  77. }
  78. if (
  79. wrapAround &&
  80. cleanedvalues.length > 1 &&
  81. equalsEpsilon(
  82. cleanedvalues[0],
  83. cleanedvalues[cleanedvalues.length - 1],
  84. removeDuplicatesEpsilon
  85. )
  86. ) {
  87. cleanedvalues.shift();
  88. }
  89. return cleanedvalues;
  90. }
  91. exports.arrayRemoveDuplicates = arrayRemoveDuplicates;
  92. });