jxdnsong
2020-10-24 da0104cede61a05a93e97b96ba0aaa7e222bb7d6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
 * Cesium - https://github.com/AnalyticalGraphicsInc/cesium
 *
 * Copyright 2011-2017 Cesium Contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Columbus View (Pat. Pend.)
 *
 * Portions licensed separately.
 * See https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md for full licensing details.
 */
define(['exports', './when-8d13db60', './Check-70bec281', './Math-61ede240'], function (exports, when, Check, _Math) { 'use strict';
 
    var removeDuplicatesEpsilon = _Math.CesiumMath.EPSILON10;
 
        /**
         * Removes adjacent duplicate values in an array of values.
         *
         * @param {Array.<*>} [values] The array of values.
         * @param {Function} equalsEpsilon Function to compare values with an epsilon. Boolean equalsEpsilon(left, right, epsilon).
         * @param {Boolean} [wrapAround=false] Compare the last value in the array against the first value.
         * @returns {Array.<*>|undefined} A new array of values with no adjacent duplicate values or the input array if no duplicates were found.
         *
         * @example
         * // 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)]
         * var values = [
         *     new Cesium.Cartesian3(1.0, 1.0, 1.0),
         *     new Cesium.Cartesian3(1.0, 1.0, 1.0),
         *     new Cesium.Cartesian3(2.0, 2.0, 2.0),
         *     new Cesium.Cartesian3(3.0, 3.0, 3.0),
         *     new Cesium.Cartesian3(1.0, 1.0, 1.0)];
         * var nonDuplicatevalues = Cesium.PolylinePipeline.removeDuplicates(values, Cartesian3.equalsEpsilon);
         *
         * @example
         * // Returns [(1.0, 1.0, 1.0), (2.0, 2.0, 2.0), (3.0, 3.0, 3.0)]
         * var values = [
         *     new Cesium.Cartesian3(1.0, 1.0, 1.0),
         *     new Cesium.Cartesian3(1.0, 1.0, 1.0),
         *     new Cesium.Cartesian3(2.0, 2.0, 2.0),
         *     new Cesium.Cartesian3(3.0, 3.0, 3.0),
         *     new Cesium.Cartesian3(1.0, 1.0, 1.0)];
         * var nonDuplicatevalues = Cesium.PolylinePipeline.removeDuplicates(values, Cartesian3.equalsEpsilon, true);
         *
         * @private
         */
        function arrayRemoveDuplicates(values, equalsEpsilon, wrapAround) {
            //>>includeStart('debug', pragmas.debug);
            Check.Check.defined('equalsEpsilon', equalsEpsilon);
            //>>includeEnd('debug');
 
            if (!when.defined(values)) {
                return undefined;
            }
 
            wrapAround = when.defaultValue(wrapAround, false);
 
            var length = values.length;
            if (length < 2) {
                return values;
            }
 
            var i;
            var v0;
            var v1;
 
            for (i = 1; i < length; ++i) {
                v0 = values[i - 1];
                v1 = values[i];
                if (equalsEpsilon(v0, v1, removeDuplicatesEpsilon)) {
                    break;
                }
            }
 
            if (i === length) {
                if (wrapAround && equalsEpsilon(values[0], values[values.length - 1], removeDuplicatesEpsilon)) {
                    return values.slice(1);
                }
                return values;
            }
 
            var cleanedvalues = values.slice(0, i);
            for (; i < length; ++i) {
                // v0 is set by either the previous loop, or the previous clean point.
                v1 = values[i];
                if (!equalsEpsilon(v0, v1, removeDuplicatesEpsilon)) {
                    cleanedvalues.push(v1);
                    v0 = v1;
                }
            }
 
            if (wrapAround && cleanedvalues.length > 1 && equalsEpsilon(cleanedvalues[0], cleanedvalues[cleanedvalues.length - 1], removeDuplicatesEpsilon)) {
                cleanedvalues.shift();
            }
 
            return cleanedvalues;
        }
 
    exports.arrayRemoveDuplicates = arrayRemoveDuplicates;
 
});