Add ol.geom.{in,de}flateCoordinates
This commit is contained in:
@@ -163,3 +163,46 @@ ol.geom.RawMultiLineString;
|
||||
* @typedef {Array.<ol.geom.RawPolygon>}
|
||||
*/
|
||||
ol.geom.RawMultiPolygon;
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
* @param {Array.<ol.Coordinate>} coordinates Coordinates.
|
||||
* @param {number} stride Stride.
|
||||
* @return {number} offset Offset.
|
||||
*/
|
||||
ol.geom.deflateCoordinates =
|
||||
function(flatCoordinates, offset, coordinates, stride) {
|
||||
var i, ii;
|
||||
for (i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
var coordinate = coordinates[i];
|
||||
goog.asserts.assert(coordinate.length == stride);
|
||||
var j;
|
||||
for (j = 0; j < stride; ++j) {
|
||||
flatCoordinates[offset++] = coordinate[j];
|
||||
}
|
||||
}
|
||||
return offset;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @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.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;
|
||||
};
|
||||
|
||||
31
test/spec/ol/geom/geom.test.js
Normal file
31
test/spec/ol/geom/geom.test.js
Normal file
@@ -0,0 +1,31 @@
|
||||
goog.provide('ol.test.geom');
|
||||
|
||||
|
||||
describe('ol.geom', function() {
|
||||
|
||||
describe('ol.geom.deflateCoordinates', function() {
|
||||
|
||||
var flatCoordinates;
|
||||
beforeEach(function() {
|
||||
flatCoordinates = [];
|
||||
});
|
||||
|
||||
it('flattens coordinates', function() {
|
||||
var offset = ol.geom.deflateCoordinates(
|
||||
flatCoordinates, 0, [[1, 2], [3, 4]], 2);
|
||||
expect(offset).to.be(4);
|
||||
expect(flatCoordinates).to.eql([1, 2, 3, 4]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.geom.inflateCoordinates', function() {
|
||||
|
||||
it('inflates coordinates', function() {
|
||||
var coordinates = ol.geom.inflateCoordinates([1, 2, 3, 4], 0, 4, 2);
|
||||
expect(coordinates).to.eql([[1, 2], [3, 4]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user