Named exports from ol/geom/flat/flip

This commit is contained in:
Frederic Junod
2018-01-26 16:33:02 +01:00
parent d15c4ce511
commit 62bc7b75d7
3 changed files with 10 additions and 18 deletions

View File

@@ -9,7 +9,7 @@ import TextFeature from '../format/TextFeature.js';
import GeometryLayout from '../geom/GeometryLayout.js'; import GeometryLayout from '../geom/GeometryLayout.js';
import LineString from '../geom/LineString.js'; import LineString from '../geom/LineString.js';
import {getStrideForLayout} from '../geom/SimpleGeometry.js'; import {getStrideForLayout} from '../geom/SimpleGeometry.js';
import _ol_geom_flat_flip_ from '../geom/flat/flip.js'; import {flipXY} from '../geom/flat/flip.js';
import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js'; import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js';
import {get as getProjection} from '../proj.js'; import {get as getProjection} from '../proj.js';
@@ -326,8 +326,7 @@ Polyline.prototype.readGeometry;
Polyline.prototype.readGeometryFromText = function(text, opt_options) { Polyline.prototype.readGeometryFromText = function(text, opt_options) {
const stride = getStrideForLayout(this.geometryLayout_); const stride = getStrideForLayout(this.geometryLayout_);
const flatCoordinates = decodeDeltas(text, stride, this.factor_); const flatCoordinates = decodeDeltas(text, stride, this.factor_);
_ol_geom_flat_flip_.flipXY( flipXY(flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
const coordinates = _ol_geom_flat_inflate_.coordinates( const coordinates = _ol_geom_flat_inflate_.coordinates(
flatCoordinates, 0, flatCoordinates.length, stride); flatCoordinates, 0, flatCoordinates.length, stride);
@@ -392,8 +391,7 @@ Polyline.prototype.writeGeometryText = function(geometry, opt_options) {
(transformWithOptions(geometry, true, this.adaptOptions(opt_options))); (transformWithOptions(geometry, true, this.adaptOptions(opt_options)));
const flatCoordinates = geometry.getFlatCoordinates(); const flatCoordinates = geometry.getFlatCoordinates();
const stride = geometry.getStride(); const stride = geometry.getStride();
_ol_geom_flat_flip_.flipXY( flipXY(flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
return encodeDeltas(flatCoordinates, stride, this.factor_); return encodeDeltas(flatCoordinates, stride, this.factor_);
}; };
export default Polyline; export default Polyline;

View File

@@ -1,7 +1,6 @@
/** /**
* @module ol/geom/flat/flip * @module ol/geom/flat/flip
*/ */
const _ol_geom_flat_flip_ = {};
/** /**
@@ -13,7 +12,7 @@ const _ol_geom_flat_flip_ = {};
* @param {number=} opt_destOffset Destination offset. * @param {number=} opt_destOffset Destination offset.
* @return {Array.<number>} Flat coordinates. * @return {Array.<number>} Flat coordinates.
*/ */
_ol_geom_flat_flip_.flipXY = function(flatCoordinates, offset, end, stride, opt_dest, opt_destOffset) { export function flipXY(flatCoordinates, offset, end, stride, opt_dest, opt_destOffset) {
let dest, destOffset; let dest, destOffset;
if (opt_dest !== undefined) { if (opt_dest !== undefined) {
dest = opt_dest; dest = opt_dest;
@@ -33,5 +32,4 @@ _ol_geom_flat_flip_.flipXY = function(flatCoordinates, offset, end, stride, opt_
} }
dest.length = destOffset; dest.length = destOffset;
return dest; return dest;
}; }
export default _ol_geom_flat_flip_;

View File

@@ -1,4 +1,4 @@
import _ol_geom_flat_flip_ from '../../../../../src/ol/geom/flat/flip.js'; import {flipXY} from '../../../../../src/ol/geom/flat/flip.js';
describe('ol.geom.flat.flip', function() { describe('ol.geom.flat.flip', function() {
@@ -6,29 +6,25 @@ describe('ol.geom.flat.flip', function() {
describe('ol.geom.flat.flip.flipXY', function() { describe('ol.geom.flat.flip.flipXY', function() {
it('can flip XY coordinates', function() { it('can flip XY coordinates', function() {
const flatCoordinates = _ol_geom_flat_flip_.flipXY([1, 2, 3, 4], 0, 4, 2); const flatCoordinates = flipXY([1, 2, 3, 4], 0, 4, 2);
expect(flatCoordinates).to.eql([2, 1, 4, 3]); expect(flatCoordinates).to.eql([2, 1, 4, 3]);
}); });
it('can flip XY coordinates while preserving other dimensions', function() { it('can flip XY coordinates while preserving other dimensions', function() {
const flatCoordinates = _ol_geom_flat_flip_.flipXY( const flatCoordinates = flipXY([1, 2, 3, 4, 5, 6, 7, 8], 0, 8, 4);
[1, 2, 3, 4, 5, 6, 7, 8], 0, 8, 4);
expect(flatCoordinates).to.eql([2, 1, 3, 4, 6, 5, 7, 8]); expect(flatCoordinates).to.eql([2, 1, 3, 4, 6, 5, 7, 8]);
}); });
it('can flip XY coordinates in place', function() { it('can flip XY coordinates in place', function() {
const flatCoordinates = [1, 2, 3, 4]; const flatCoordinates = [1, 2, 3, 4];
expect(_ol_geom_flat_flip_.flipXY( expect(flipXY(flatCoordinates, 0, 4, 2, flatCoordinates)).to.be(flatCoordinates);
flatCoordinates, 0, 4, 2, flatCoordinates)).to.be(flatCoordinates);
expect(flatCoordinates).to.eql([2, 1, 4, 3]); expect(flatCoordinates).to.eql([2, 1, 4, 3]);
}); });
it('can flip XY coordinates in place while preserving other dimensions', it('can flip XY coordinates in place while preserving other dimensions',
function() { function() {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9]; const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9];
expect(_ol_geom_flat_flip_.flipXY( expect(flipXY(flatCoordinates, 0, 9, 3, flatCoordinates)).to.be(flatCoordinates);
flatCoordinates, 0, 9, 3, flatCoordinates)).
to.be(flatCoordinates);
expect(flatCoordinates).to.eql([2, 1, 3, 5, 4, 6, 8, 7, 9]); expect(flatCoordinates).to.eql([2, 1, 3, 5, 4, 6, 8, 7, 9]);
}); });