Factor out ol.geom.flat.inflate
This commit is contained in:
@@ -4,7 +4,7 @@ goog.require('goog.asserts');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.format.TextFeature');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.flat');
|
||||
goog.require('ol.geom.flat.inflate');
|
||||
goog.require('ol.proj');
|
||||
|
||||
|
||||
@@ -279,7 +279,7 @@ ol.format.Polyline.prototype.readFeaturesFromText = function(text) {
|
||||
*/
|
||||
ol.format.Polyline.prototype.readGeometryFromText = function(text) {
|
||||
var flatCoordinates = ol.format.Polyline.decodeFlatCoordinates(text, 2);
|
||||
var coordinates = ol.geom.flat.inflateCoordinates(
|
||||
var coordinates = ol.geom.flat.inflate.coordinates(
|
||||
flatCoordinates, 0, flatCoordinates.length, 2);
|
||||
return new ol.geom.LineString(coordinates);
|
||||
};
|
||||
|
||||
71
src/ol/geom/flat/inflateflatgeom.js
Normal file
71
src/ol/geom/flat/inflateflatgeom.js
Normal file
@@ -0,0 +1,71 @@
|
||||
goog.provide('ol.geom.flat.inflate');
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
* @param {number} end End.
|
||||
* @param {number} stride Stride.
|
||||
* @param {Array.<ol.Coordinate>=} opt_coordinates Coordinates.
|
||||
* @return {Array.<ol.Coordinate>} Coordinates.
|
||||
*/
|
||||
ol.geom.flat.inflate.coordinates =
|
||||
function(flatCoordinates, offset, end, stride, opt_coordinates) {
|
||||
var coordinates = goog.isDef(opt_coordinates) ? opt_coordinates : [];
|
||||
var i = 0;
|
||||
var j;
|
||||
for (j = offset; j < end; j += stride) {
|
||||
coordinates[i++] = flatCoordinates.slice(j, j + stride);
|
||||
}
|
||||
coordinates.length = i;
|
||||
return coordinates;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
* @param {Array.<number>} ends Ends.
|
||||
* @param {number} stride Stride.
|
||||
* @param {Array.<Array.<ol.Coordinate>>=} opt_coordinatess Coordinatess.
|
||||
* @return {Array.<Array.<ol.Coordinate>>} Coordinatess.
|
||||
*/
|
||||
ol.geom.flat.inflate.coordinatess =
|
||||
function(flatCoordinates, offset, ends, stride, opt_coordinatess) {
|
||||
var coordinatess = goog.isDef(opt_coordinatess) ? opt_coordinatess : [];
|
||||
var i = 0;
|
||||
var j, jj;
|
||||
for (j = 0, jj = ends.length; j < jj; ++j) {
|
||||
var end = ends[j];
|
||||
coordinatess[i++] = ol.geom.flat.inflate.coordinates(
|
||||
flatCoordinates, offset, end, stride, coordinatess[i]);
|
||||
offset = end;
|
||||
}
|
||||
coordinatess.length = i;
|
||||
return coordinatess;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
* @param {Array.<Array.<number>>} endss Endss.
|
||||
* @param {number} stride Stride.
|
||||
* @param {Array.<Array.<Array.<ol.Coordinate>>>=} opt_coordinatesss
|
||||
* Coordinatesss.
|
||||
* @return {Array.<Array.<Array.<ol.Coordinate>>>} Coordinatesss.
|
||||
*/
|
||||
ol.geom.flat.inflate.coordinatesss =
|
||||
function(flatCoordinates, offset, endss, stride, opt_coordinatesss) {
|
||||
var coordinatesss = goog.isDef(opt_coordinatesss) ? opt_coordinatesss : [];
|
||||
var i = 0;
|
||||
var j, jj;
|
||||
for (j = 0, jj = endss.length; j < jj; ++j) {
|
||||
var ends = endss[j];
|
||||
coordinatesss[i++] = ol.geom.flat.inflate.coordinatess(
|
||||
flatCoordinates, offset, ends, stride, coordinatesss[i]);
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
coordinatesss.length = i;
|
||||
return coordinatesss;
|
||||
};
|
||||
@@ -5,76 +5,6 @@ goog.require('goog.vec.Mat4');
|
||||
goog.require('ol.extent');
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
* @param {number} end End.
|
||||
* @param {number} stride Stride.
|
||||
* @param {Array.<ol.Coordinate>=} opt_coordinates Coordinates.
|
||||
* @return {Array.<ol.Coordinate>} Coordinates.
|
||||
*/
|
||||
ol.geom.flat.inflateCoordinates =
|
||||
function(flatCoordinates, offset, end, stride, opt_coordinates) {
|
||||
var coordinates = goog.isDef(opt_coordinates) ? opt_coordinates : [];
|
||||
var i = 0;
|
||||
var j;
|
||||
for (j = offset; j < end; j += stride) {
|
||||
coordinates[i++] = flatCoordinates.slice(j, j + stride);
|
||||
}
|
||||
coordinates.length = i;
|
||||
return coordinates;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
* @param {Array.<number>} ends Ends.
|
||||
* @param {number} stride Stride.
|
||||
* @param {Array.<Array.<ol.Coordinate>>=} opt_coordinatess Coordinatess.
|
||||
* @return {Array.<Array.<ol.Coordinate>>} Coordinatess.
|
||||
*/
|
||||
ol.geom.flat.inflateCoordinatess =
|
||||
function(flatCoordinates, offset, ends, stride, opt_coordinatess) {
|
||||
var coordinatess = goog.isDef(opt_coordinatess) ? opt_coordinatess : [];
|
||||
var i = 0;
|
||||
var j, jj;
|
||||
for (j = 0, jj = ends.length; j < jj; ++j) {
|
||||
var end = ends[j];
|
||||
coordinatess[i++] = ol.geom.flat.inflateCoordinates(
|
||||
flatCoordinates, offset, end, stride, coordinatess[i]);
|
||||
offset = end;
|
||||
}
|
||||
coordinatess.length = i;
|
||||
return coordinatess;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
* @param {Array.<Array.<number>>} endss Endss.
|
||||
* @param {number} stride Stride.
|
||||
* @param {Array.<Array.<Array.<ol.Coordinate>>>=} opt_coordinatesss
|
||||
* Coordinatesss.
|
||||
* @return {Array.<Array.<Array.<ol.Coordinate>>>} Coordinatesss.
|
||||
*/
|
||||
ol.geom.flat.inflateCoordinatesss =
|
||||
function(flatCoordinates, offset, endss, stride, opt_coordinatesss) {
|
||||
var coordinatesss = goog.isDef(opt_coordinatesss) ? opt_coordinatesss : [];
|
||||
var i = 0;
|
||||
var j, jj;
|
||||
for (j = 0, jj = endss.length; j < jj; ++j) {
|
||||
var ends = endss[j];
|
||||
coordinatesss[i++] = ol.geom.flat.inflateCoordinatess(
|
||||
flatCoordinates, offset, ends, stride, coordinatesss[i]);
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
coordinatesss.length = i;
|
||||
return coordinatesss;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
|
||||
@@ -7,6 +7,7 @@ goog.require('ol.geom.flat');
|
||||
goog.require('ol.geom.flat.area');
|
||||
goog.require('ol.geom.flat.closest');
|
||||
goog.require('ol.geom.flat.deflate');
|
||||
goog.require('ol.geom.flat.inflate');
|
||||
goog.require('ol.geom.flat.simplify');
|
||||
|
||||
|
||||
@@ -85,7 +86,7 @@ ol.geom.LinearRing.prototype.getArea = function() {
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.LinearRing.prototype.getCoordinates = function() {
|
||||
return ol.geom.flat.inflateCoordinates(
|
||||
return ol.geom.flat.inflate.coordinates(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
};
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ goog.require('ol.geom.SimpleGeometry');
|
||||
goog.require('ol.geom.flat');
|
||||
goog.require('ol.geom.flat.closest');
|
||||
goog.require('ol.geom.flat.deflate');
|
||||
goog.require('ol.geom.flat.inflate');
|
||||
goog.require('ol.geom.flat.interpolate');
|
||||
goog.require('ol.geom.flat.length');
|
||||
goog.require('ol.geom.flat.simplify');
|
||||
@@ -128,7 +129,7 @@ ol.geom.LineString.prototype.getCoordinateAtM = function(m, opt_extrapolate) {
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.LineString.prototype.getCoordinates = function() {
|
||||
return ol.geom.flat.inflateCoordinates(
|
||||
return ol.geom.flat.inflate.coordinates(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
};
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ goog.require('ol.geom.SimpleGeometry');
|
||||
goog.require('ol.geom.flat');
|
||||
goog.require('ol.geom.flat.closest');
|
||||
goog.require('ol.geom.flat.deflate');
|
||||
goog.require('ol.geom.flat.inflate');
|
||||
goog.require('ol.geom.flat.interpolate');
|
||||
goog.require('ol.geom.flat.simplify');
|
||||
|
||||
@@ -136,7 +137,7 @@ ol.geom.MultiLineString.prototype.getCoordinateAtM =
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.getCoordinates = function() {
|
||||
return ol.geom.flat.inflateCoordinatess(
|
||||
return ol.geom.flat.inflate.coordinatess(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride);
|
||||
};
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.SimpleGeometry');
|
||||
goog.require('ol.geom.flat');
|
||||
goog.require('ol.geom.flat.deflate');
|
||||
goog.require('ol.geom.flat.inflate');
|
||||
|
||||
|
||||
|
||||
@@ -81,7 +82,7 @@ ol.geom.MultiPoint.prototype.closestPointXY =
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.getCoordinates = function() {
|
||||
return ol.geom.flat.inflateCoordinates(
|
||||
return ol.geom.flat.inflate.coordinates(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ goog.require('ol.geom.flat.area');
|
||||
goog.require('ol.geom.flat.closest');
|
||||
goog.require('ol.geom.flat.contains');
|
||||
goog.require('ol.geom.flat.deflate');
|
||||
goog.require('ol.geom.flat.inflate');
|
||||
goog.require('ol.geom.flat.interiorpoint');
|
||||
goog.require('ol.geom.flat.orient');
|
||||
goog.require('ol.geom.flat.simplify');
|
||||
@@ -157,7 +158,7 @@ ol.geom.MultiPolygon.prototype.getArea = function() {
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.MultiPolygon.prototype.getCoordinates = function() {
|
||||
return ol.geom.flat.inflateCoordinatesss(
|
||||
return ol.geom.flat.inflate.coordinatesss(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride);
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ goog.require('ol.geom.flat.area');
|
||||
goog.require('ol.geom.flat.closest');
|
||||
goog.require('ol.geom.flat.contains');
|
||||
goog.require('ol.geom.flat.deflate');
|
||||
goog.require('ol.geom.flat.inflate');
|
||||
goog.require('ol.geom.flat.interiorpoint');
|
||||
goog.require('ol.geom.flat.orient');
|
||||
goog.require('ol.geom.flat.simplify');
|
||||
@@ -147,7 +148,7 @@ ol.geom.Polygon.prototype.getArea = function() {
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.Polygon.prototype.getCoordinates = function() {
|
||||
return ol.geom.flat.inflateCoordinatess(
|
||||
return ol.geom.flat.inflate.coordinatess(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride);
|
||||
};
|
||||
|
||||
|
||||
27
test/spec/ol/geom/flat/inflateflatgeom.test.js
Normal file
27
test/spec/ol/geom/flat/inflateflatgeom.test.js
Normal file
@@ -0,0 +1,27 @@
|
||||
goog.provide('ol.test.geom.flat.inflate');
|
||||
|
||||
describe('ol.geom.flat.inflate', function() {
|
||||
|
||||
describe('ol.geom.flat.inflate.coordinates', function() {
|
||||
|
||||
it('inflates coordinates', function() {
|
||||
var coordinates = ol.geom.flat.inflate.coordinates([1, 2, 3, 4], 0, 4, 2);
|
||||
expect(coordinates).to.eql([[1, 2], [3, 4]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.inflate.coordinatess', function() {
|
||||
|
||||
it('inflates arrays of coordinates', function() {
|
||||
var coordinatess = ol.geom.flat.inflate.coordinatess(
|
||||
[1, 2, 3, 4, 5, 6, 7, 8], 0, [4, 8], 2);
|
||||
expect(coordinatess).to.eql([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.geom.flat');
|
||||
goog.require('ol.geom.flat.inflate');
|
||||
@@ -3,25 +3,6 @@ goog.provide('ol.test.geom.flat');
|
||||
|
||||
describe('ol.geom.flat', function() {
|
||||
|
||||
describe('ol.geom.flat.inflateCoordinates', function() {
|
||||
|
||||
it('inflates coordinates', function() {
|
||||
var coordinates = ol.geom.flat.inflateCoordinates([1, 2, 3, 4], 0, 4, 2);
|
||||
expect(coordinates).to.eql([[1, 2], [3, 4]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.inflateCoordinatess', function() {
|
||||
|
||||
it('inflates arrays of coordinates', function() {
|
||||
var coordinatess = ol.geom.flat.inflateCoordinatess(
|
||||
[1, 2, 3, 4, 5, 6, 7, 8], 0, [4, 8], 2);
|
||||
expect(coordinatess).to.eql([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.reverseCoordinates', function() {
|
||||
|
||||
describe('with a stride of 2', function() {
|
||||
|
||||
Reference in New Issue
Block a user