diff --git a/src/ol/geom/LineString.js b/src/ol/geom/LineString.js index ba1fe244ef..010e5f1cb5 100644 --- a/src/ol/geom/LineString.js +++ b/src/ol/geom/LineString.js @@ -13,7 +13,7 @@ import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js'; import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; import _ol_geom_flat_length_ from '../geom/flat/length.js'; -import _ol_geom_flat_segments_ from '../geom/flat/segments.js'; +import {forEach as forEachSegment} from '../geom/flat/segments.js'; import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js'; /** @@ -119,8 +119,7 @@ LineString.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDis * @api */ LineString.prototype.forEachSegment = function(callback) { - return _ol_geom_flat_segments_.forEach(this.flatCoordinates, 0, - this.flatCoordinates.length, this.stride, callback); + return forEachSegment(this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, callback); }; diff --git a/src/ol/geom/flat/intersectsextent.js b/src/ol/geom/flat/intersectsextent.js index c12cc82eb7..e4dfb1f200 100644 --- a/src/ol/geom/flat/intersectsextent.js +++ b/src/ol/geom/flat/intersectsextent.js @@ -3,7 +3,7 @@ */ import {containsExtent, createEmpty, extendFlatCoordinates, intersects, intersectsSegment} from '../../extent.js'; import {linearRingContainsXY, linearRingContainsExtent} from '../flat/contains.js'; -import _ol_geom_flat_segments_ from '../flat/segments.js'; +import {forEach as forEachSegment} from '../flat/segments.js'; const _ol_geom_flat_intersectsextent_ = {}; @@ -32,13 +32,13 @@ _ol_geom_flat_intersectsextent_.lineString = function(flatCoordinates, offset, e coordinatesExtent[3] <= extent[3]) { return true; } - return _ol_geom_flat_segments_.forEach(flatCoordinates, offset, end, stride, + return forEachSegment(flatCoordinates, offset, end, stride, /** - * @param {ol.Coordinate} point1 Start point. - * @param {ol.Coordinate} point2 End point. - * @return {boolean} `true` if the segment and the extent intersect, - * `false` otherwise. - */ + * @param {ol.Coordinate} point1 Start point. + * @param {ol.Coordinate} point2 End point. + * @return {boolean} `true` if the segment and the extent intersect, + * `false` otherwise. + */ function(point1, point2) { return intersectsSegment(extent, point1, point2); }); diff --git a/src/ol/geom/flat/segments.js b/src/ol/geom/flat/segments.js index d97150bee0..c7cb402ced 100644 --- a/src/ol/geom/flat/segments.js +++ b/src/ol/geom/flat/segments.js @@ -1,7 +1,6 @@ /** * @module ol/geom/flat/segments */ -const _ol_geom_flat_segments_ = {}; /** @@ -19,7 +18,7 @@ const _ol_geom_flat_segments_ = {}; * @return {T|boolean} Value. * @template T,S */ -_ol_geom_flat_segments_.forEach = function(flatCoordinates, offset, end, stride, callback, opt_this) { +export function forEach(flatCoordinates, offset, end, stride, callback, opt_this) { const point1 = [flatCoordinates[offset], flatCoordinates[offset + 1]]; const point2 = []; let ret; @@ -34,5 +33,4 @@ _ol_geom_flat_segments_.forEach = function(flatCoordinates, offset, end, stride, point1[1] = point2[1]; } return false; -}; -export default _ol_geom_flat_segments_; +} diff --git a/test/spec/ol/geom/flat/segments.test.js b/test/spec/ol/geom/flat/segments.test.js index e0e7315323..8f36a891ea 100644 --- a/test/spec/ol/geom/flat/segments.test.js +++ b/test/spec/ol/geom/flat/segments.test.js @@ -1,4 +1,4 @@ -import _ol_geom_flat_segments_ from '../../../../../src/ol/geom/flat/segments.js'; +import {forEach as forEachSegment} from '../../../../../src/ol/geom/flat/segments.js'; describe('ol.geom.flat.segments', function() { @@ -17,8 +17,7 @@ describe('ol.geom.flat.segments', function() { const spy = sinon.spy(function(point1, point2) { args.push([point1[0], point1[1], point2[0], point2[1]]); }); - const ret = _ol_geom_flat_segments_.forEach( - flatCoordinates, offset, end, stride, spy); + const ret = forEachSegment(flatCoordinates, offset, end, stride, spy); expect(spy.callCount).to.be(3); expect(args[0][0]).to.be(0); expect(args[0][1]).to.be(0); @@ -42,8 +41,7 @@ describe('ol.geom.flat.segments', function() { args.push([point1[0], point1[1], point2[0], point2[1]]); return true; }); - const ret = _ol_geom_flat_segments_.forEach( - flatCoordinates, offset, end, stride, spy); + const ret = forEachSegment(flatCoordinates, offset, end, stride, spy); expect(spy.callCount).to.be(1); expect(args[0][0]).to.be(0); expect(args[0][1]).to.be(0);