Permalink
Browse files

Merge pull request #6360 from openlayers/rm_ol.array.flatten

Remove ol.array.flatten function
  • Loading branch information...
2 parents 3c751ca + d8c5e81 commit 66ef6ecd203780eefb1ab87469c85fa5ad413880 @fredj fredj committed on GitHub Jan 12, 2017
Showing with 5 additions and 29 deletions.
  1. +0 −16 src/ol/array.js
  2. +5 −3 src/ol/format/esrijson.js
  3. +0 −10 test/spec/ol/array.test.js
View
@@ -125,22 +125,6 @@ ol.array.reverseSubArray = function(arr, begin, end) {
/**
- * @param {Array.<*>} arr Array.
- * @return {!Array.<?>} Flattened Array.
- */
-ol.array.flatten = function(arr) {
- var data = arr.reduce(function(flattened, value) {
- if (Array.isArray(value)) {
- return flattened.concat(ol.array.flatten(value));
- } else {
- return flattened.concat(value);
- }
- }, []);
- return data;
-};
-
-
-/**
* @param {Array.<VALUE>} arr The array to modify.
* @param {Array.<VALUE>|VALUE} data The elements or arrays of elements
* to add to arr.
@@ -2,7 +2,6 @@ goog.provide('ol.format.EsriJSON');
goog.require('ol');
goog.require('ol.Feature');
-goog.require('ol.array');
goog.require('ol.asserts');
goog.require('ol.extent');
goog.require('ol.format.Feature');
@@ -16,6 +15,7 @@ goog.require('ol.geom.MultiPoint');
goog.require('ol.geom.MultiPolygon');
goog.require('ol.geom.Point');
goog.require('ol.geom.Polygon');
+goog.require('ol.geom.flat.deflate');
goog.require('ol.geom.flat.orient');
goog.require('ol.obj');
goog.require('ol.proj');
@@ -96,14 +96,16 @@ ol.format.EsriJSON.readGeometry_ = function(object, opt_options) {
* @param {Array.<!Array.<!Array.<number>>>} rings Rings.
* @param {ol.geom.GeometryLayout} layout Geometry layout.
* @private
- * @return {Array.<!Array.<!Array.<number>>>} Transoformed rings.
+ * @return {Array.<!Array.<!Array.<number>>>} Transformed rings.
*/
ol.format.EsriJSON.convertRings_ = function(rings, layout) {
+ var flatRing = [];
var outerRings = [];
var holes = [];
var i, ii;
for (i = 0, ii = rings.length; i < ii; ++i) {
- var flatRing = ol.array.flatten(rings[i]);
+ flatRing.length = 0;
+ ol.geom.flat.deflate.coordinates(flatRing, 0, rings[i], layout.length);
// is this ring an outer ring? is it clockwise?
var clockwise = ol.geom.flat.orient.linearRingIsClockwise(flatRing, 0,
flatRing.length, layout.length);
@@ -427,16 +427,6 @@ describe('ol.array', function() {
});
});
- describe('flatten', function() {
- it('flattens different kinds of nested arrays', function() {
- expect(ol.array.flatten([1, 2])).to.eql([1, 2]);
- expect(ol.array.flatten([1, [2, [3, [4, 5]]]])).to.eql([1, 2, 3, 4, 5]);
- expect(ol.array.flatten([[[[1], 2], 3], 4])).to.eql([1, 2, 3, 4]);
- expect(ol.array.flatten([[1]])).to.eql([1]);
- expect(ol.array.flatten([])).to.eql([]);
- });
- });
-
describe('isSorted', function() {
it('works with just an array as argument', function() {
expect(ol.array.isSorted([1, 2, 3])).to.be(true);

0 comments on commit 66ef6ec

Please sign in to comment.