diff --git a/src/ol/geom/LineString.js b/src/ol/geom/LineString.js index beb3d7a8df..a219e6e8a6 100644 --- a/src/ol/geom/LineString.js +++ b/src/ol/geom/LineString.js @@ -10,7 +10,7 @@ import SimpleGeometry from '../geom/SimpleGeometry.js'; import {assignClosestPoint, maxSquaredDelta} from '../geom/flat/closest.js'; import {deflateCoordinates} from '../geom/flat/deflate.js'; import {inflateCoordinates} from '../geom/flat/inflate.js'; -import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js'; +import {interpolatePoint, lineStringCoordinateAtM} from '../geom/flat/interpolate.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; import {lineStringLength} from '../geom/flat/length.js'; import {forEach as forEachSegment} from '../geom/flat/segments.js'; @@ -143,7 +143,7 @@ LineString.prototype.getCoordinateAtM = function(m, opt_extrapolate) { return null; } const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false; - return _ol_geom_flat_interpolate_.lineStringCoordinateAtM(this.flatCoordinates, 0, + return lineStringCoordinateAtM(this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, m, extrapolate); }; @@ -171,7 +171,7 @@ LineString.prototype.getCoordinates = function() { * @api */ LineString.prototype.getCoordinateAt = function(fraction, opt_dest) { - return _ol_geom_flat_interpolate_.lineString( + return interpolatePoint( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, fraction, opt_dest); }; diff --git a/src/ol/geom/MultiLineString.js b/src/ol/geom/MultiLineString.js index 7d4e8d1106..dc6a07193f 100644 --- a/src/ol/geom/MultiLineString.js +++ b/src/ol/geom/MultiLineString.js @@ -11,7 +11,7 @@ import SimpleGeometry from '../geom/SimpleGeometry.js'; import {assignClosestArrayPoint, arrayMaxSquaredDelta} from '../geom/flat/closest.js'; import {deflateCoordinatesArray} from '../geom/flat/deflate.js'; import {inflateCoordinatesArray} from '../geom/flat/inflate.js'; -import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js'; +import {interpolatePoint, lineStringsCoordinateAtM} from '../geom/flat/interpolate.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; import {douglasPeuckerArray} from '../geom/flat/simplify.js'; @@ -132,7 +132,7 @@ MultiLineString.prototype.getCoordinateAtM = function(m, opt_extrapolate, opt_in } const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false; const interpolate = opt_interpolate !== undefined ? opt_interpolate : false; - return _ol_geom_flat_interpolate_.lineStringsCoordinateAtM(this.flatCoordinates, 0, + return lineStringsCoordinateAtM(this.flatCoordinates, 0, this.ends_, this.stride, m, extrapolate, interpolate); }; @@ -208,7 +208,7 @@ MultiLineString.prototype.getFlatMidpoints = function() { const stride = this.stride; for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; - const midpoint = _ol_geom_flat_interpolate_.lineString( + const midpoint = interpolatePoint( flatCoordinates, offset, end, stride, 0.5); extend(midpoints, midpoint); offset = end; diff --git a/src/ol/geom/flat/interpolate.js b/src/ol/geom/flat/interpolate.js index 04d238fa83..37aa638bc3 100644 --- a/src/ol/geom/flat/interpolate.js +++ b/src/ol/geom/flat/interpolate.js @@ -3,7 +3,6 @@ */ import {binarySearch} from '../../array.js'; import {lerp} from '../../math.js'; -const _ol_geom_flat_interpolate_ = {}; /** @@ -15,7 +14,7 @@ const _ol_geom_flat_interpolate_ = {}; * @param {Array.=} opt_dest Destination. * @return {Array.} Destination. */ -_ol_geom_flat_interpolate_.lineString = function(flatCoordinates, offset, end, stride, fraction, opt_dest) { +export function interpolatePoint(flatCoordinates, offset, end, stride, fraction, opt_dest) { let pointX = NaN; let pointY = NaN; const n = (end - offset) / stride; @@ -62,7 +61,7 @@ _ol_geom_flat_interpolate_.lineString = function(flatCoordinates, offset, end, s } else { return [pointX, pointY]; } -}; +} /** @@ -74,7 +73,7 @@ _ol_geom_flat_interpolate_.lineString = function(flatCoordinates, offset, end, s * @param {boolean} extrapolate Extrapolate. * @return {ol.Coordinate} Coordinate. */ -_ol_geom_flat_interpolate_.lineStringCoordinateAtM = function(flatCoordinates, offset, end, stride, m, extrapolate) { +export function lineStringCoordinateAtM(flatCoordinates, offset, end, stride, m, extrapolate) { if (end == offset) { return null; } @@ -123,7 +122,7 @@ _ol_geom_flat_interpolate_.lineStringCoordinateAtM = function(flatCoordinates, o } coordinate.push(m); return coordinate; -}; +} /** @@ -136,10 +135,10 @@ _ol_geom_flat_interpolate_.lineStringCoordinateAtM = function(flatCoordinates, o * @param {boolean} interpolate Interpolate. * @return {ol.Coordinate} Coordinate. */ -_ol_geom_flat_interpolate_.lineStringsCoordinateAtM = function( +export function lineStringsCoordinateAtM( flatCoordinates, offset, ends, stride, m, extrapolate, interpolate) { if (interpolate) { - return _ol_geom_flat_interpolate_.lineStringCoordinateAtM( + return lineStringCoordinateAtM( flatCoordinates, offset, ends[ends.length - 1], stride, m, extrapolate); } let coordinate; @@ -169,11 +168,10 @@ _ol_geom_flat_interpolate_.lineStringsCoordinateAtM = function( if (m < flatCoordinates[offset + stride - 1]) { return null; } else if (m <= flatCoordinates[end - 1]) { - return _ol_geom_flat_interpolate_.lineStringCoordinateAtM( + return lineStringCoordinateAtM( flatCoordinates, offset, end, stride, m, false); } offset = end; } return null; -}; -export default _ol_geom_flat_interpolate_; +} diff --git a/src/ol/render/Feature.js b/src/ol/render/Feature.js index f72aa7c40f..97450de4c5 100644 --- a/src/ol/render/Feature.js +++ b/src/ol/render/Feature.js @@ -7,7 +7,7 @@ import {createOrUpdateFromCoordinate, createOrUpdateFromFlatCoordinates, getCent import GeometryType from '../geom/GeometryType.js'; import {linearRingss as linearRingssCenter} from '../geom/flat/center.js'; import {getInteriorPointOfArray, getInteriorPointsOfMultiArray} from '../geom/flat/interiorpoint.js'; -import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js'; +import {interpolatePoint} from '../geom/flat/interpolate.js'; import _ol_geom_flat_transform_ from '../geom/flat/transform.js'; import _ol_transform_ from '../transform.js'; @@ -151,7 +151,7 @@ RenderFeature.prototype.getFlatInteriorPoints = function() { */ RenderFeature.prototype.getFlatMidpoint = function() { if (!this.flatMidpoints_) { - this.flatMidpoints_ = _ol_geom_flat_interpolate_.lineString( + this.flatMidpoints_ = interpolatePoint( this.flatCoordinates_, 0, this.flatCoordinates_.length, 2, 0.5); } return this.flatMidpoints_; @@ -169,7 +169,7 @@ RenderFeature.prototype.getFlatMidpoints = function() { const ends = this.ends_; for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; - const midpoint = _ol_geom_flat_interpolate_.lineString( + const midpoint = interpolatePoint( flatCoordinates, offset, end, 2, 0.5); extend(this.flatMidpoints_, midpoint); offset = end; diff --git a/test/spec/ol/geom/flat/interpolate.test.js b/test/spec/ol/geom/flat/interpolate.test.js index a8ca28830e..ae65f9e7e6 100644 --- a/test/spec/ol/geom/flat/interpolate.test.js +++ b/test/spec/ol/geom/flat/interpolate.test.js @@ -1,4 +1,4 @@ -import _ol_geom_flat_interpolate_ from '../../../../../src/ol/geom/flat/interpolate.js'; +import {interpolatePoint} from '../../../../../src/ol/geom/flat/interpolate.js'; describe('ol.geom.flat.interpolate', function() { @@ -8,14 +8,14 @@ describe('ol.geom.flat.interpolate', function() { it('returns the expected value for single points', function() { const flatCoordinates = [0, 1]; const point = - _ol_geom_flat_interpolate_.lineString(flatCoordinates, 0, 2, 2, 0.5); + interpolatePoint(flatCoordinates, 0, 2, 2, 0.5); expect(point).to.eql([0, 1]); }); it('returns the expected value for simple line segments', function() { const flatCoordinates = [0, 1, 2, 3]; const point = - _ol_geom_flat_interpolate_.lineString(flatCoordinates, 0, 4, 2, 0.5); + interpolatePoint(flatCoordinates, 0, 4, 2, 0.5); expect(point).to.eql([1, 2]); }); @@ -23,14 +23,14 @@ describe('ol.geom.flat.interpolate', function() { 'coordinate', function() { const flatCoordinates = [0, 1, 2, 3, 4, 5]; - const point = _ol_geom_flat_interpolate_.lineString( + const point = interpolatePoint( flatCoordinates, 0, 6, 2, 0.5); expect(point).to.eql([2, 3]); }); xit('also when vertices are repeated', function() { const flatCoordinates = [0, 1, 2, 3, 2, 3, 4, 5]; - const point = _ol_geom_flat_interpolate_.lineString( + const point = interpolatePoint( flatCoordinates, 0, 6, 2, 0.5); expect(point).to.eql([2, 3]); }); @@ -39,14 +39,14 @@ describe('ol.geom.flat.interpolate', function() { 'two existing coordinates', function() { const flatCoordinates = [0, 1, 2, 3, 4, 5, 6, 7]; - const point = _ol_geom_flat_interpolate_.lineString( + const point = interpolatePoint( flatCoordinates, 0, 8, 2, 0.5); expect(point).to.eql([3, 4]); }); xit('also when vertices are repeated', function() { const flatCoordinates = [0, 1, 2, 3, 2, 3, 4, 5, 6, 7]; - const point = _ol_geom_flat_interpolate_.lineString( + const point = interpolatePoint( flatCoordinates, 0, 8, 2, 0.5); expect(point).to.eql([3, 4]); }); @@ -54,7 +54,7 @@ describe('ol.geom.flat.interpolate', function() { it('returns the expected value when the coordinates are not evenly spaced', function() { const flatCoordinates = [0, 1, 2, 3, 6, 7]; - const point = _ol_geom_flat_interpolate_.lineString( + const point = interpolatePoint( flatCoordinates, 0, 6, 2, 0.5); expect(point).to.eql([3, 4]); }); @@ -62,7 +62,7 @@ describe('ol.geom.flat.interpolate', function() { xit('also when vertices are repeated', function() { const flatCoordinates = [0, 1, 2, 3, 2, 3, 6, 7]; - const point = _ol_geom_flat_interpolate_.lineString( + const point = interpolatePoint( flatCoordinates, 0, 6, 2, 0.5); expect(point).to.eql([3, 4]); }); @@ -70,7 +70,7 @@ describe('ol.geom.flat.interpolate', function() { it('returns the expected value when using opt_dest', function() { const flatCoordinates = [0, 1, 2, 3, 6, 7]; - const point = _ol_geom_flat_interpolate_.lineString( + const point = interpolatePoint( flatCoordinates, 0, 6, 2, 0.5, [0, 0]); expect(point).to.eql([3, 4]); });