diff --git a/src/ol/geom/flat/straightchunk.js b/src/ol/geom/flat/straightchunk.js index 16c77598bc..f394537724 100644 --- a/src/ol/geom/flat/straightchunk.js +++ b/src/ol/geom/flat/straightchunk.js @@ -1,7 +1,6 @@ /** * @module ol/geom/flat/straightchunk */ -const _ol_geom_flat_straightchunk_ = {}; /** @@ -13,7 +12,7 @@ const _ol_geom_flat_straightchunk_ = {}; * @return {Array.} Start and end of the first suitable chunk of the * given `flatCoordinates`. */ -_ol_geom_flat_straightchunk_.lineString = function(maxAngle, flatCoordinates, offset, end, stride) { +export function matchingChunk(maxAngle, flatCoordinates, offset, end, stride) { let chunkStart = offset; let chunkEnd = offset; let chunkM = 0; @@ -49,5 +48,4 @@ _ol_geom_flat_straightchunk_.lineString = function(maxAngle, flatCoordinates, of } m += m23; return m > chunkM ? [start, i] : [chunkStart, chunkEnd]; -}; -export default _ol_geom_flat_straightchunk_; +} diff --git a/src/ol/render/canvas/TextReplay.js b/src/ol/render/canvas/TextReplay.js index f24b19a6c6..9db0c5305b 100644 --- a/src/ol/render/canvas/TextReplay.js +++ b/src/ol/render/canvas/TextReplay.js @@ -5,7 +5,7 @@ import {getUid, inherits} from '../../index.js'; import {asColorLike} from '../../colorlike.js'; import {createCanvasContext2D} from '../../dom.js'; import {intersects} from '../../extent.js'; -import _ol_geom_flat_straightchunk_ from '../../geom/flat/straightchunk.js'; +import {matchingChunk} from '../../geom/flat/straightchunk.js'; import GeometryType from '../../geom/GeometryType.js'; import {CANVAS_LINE_DASH, SAFARI} from '../../has.js'; import _ol_render_canvas_ from '../canvas.js'; @@ -202,7 +202,7 @@ CanvasTextReplay.prototype.drawText = function(geometry, feature) { let flatEnd; for (let o = 0, oo = ends.length; o < oo; ++o) { if (textAlign == undefined) { - const range = _ol_geom_flat_straightchunk_.lineString( + const range = matchingChunk( textState.maxAngle, flatCoordinates, flatOffset, ends[o], stride); flatOffset = range[0]; flatEnd = range[1]; diff --git a/test/spec/ol/geom/flat/straightchunk.test.js b/test/spec/ol/geom/flat/straightchunk.test.js index 087ebf6a2b..7b58017117 100644 --- a/test/spec/ol/geom/flat/straightchunk.test.js +++ b/test/spec/ol/geom/flat/straightchunk.test.js @@ -1,4 +1,4 @@ -import _ol_geom_flat_straightchunk_ from '../../../../../src/ol/geom/flat/straightchunk.js'; +import {matchingChunk} from '../../../../../src/ol/geom/flat/straightchunk.js'; describe('ol.geom.flat.straightchunk', function() { @@ -10,12 +10,12 @@ describe('ol.geom.flat.straightchunk', function() { const stride = 3; it('returns whole line with angle delta', function() { - const got = _ol_geom_flat_straightchunk_.lineString(Math.PI / 4, flatCoords, 0, 6, stride); + const got = matchingChunk(Math.PI / 4, flatCoords, 0, 6, stride); expect(got).to.eql([0, 6]); }); it('returns whole line with zero angle delta', function() { - const got = _ol_geom_flat_straightchunk_.lineString(0, flatCoords, 0, 6, stride); + const got = matchingChunk(0, flatCoords, 0, 6, stride); expect(got).to.eql([0, 6]); }); @@ -26,12 +26,12 @@ describe('ol.geom.flat.straightchunk', function() { const stride = 2; it('returns whole line if straight enough', function() { - const got = _ol_geom_flat_straightchunk_.lineString(Math.PI, flatCoords, 0, 8, stride); + const got = matchingChunk(Math.PI, flatCoords, 0, 8, stride); expect(got).to.eql([0, 8]); }); it('returns first matching chunk if all chunk lengths are the same', function() { - const got = _ol_geom_flat_straightchunk_.lineString(Math.PI / 4, flatCoords, 0, 8, stride); + const got = matchingChunk(Math.PI / 4, flatCoords, 0, 8, stride); expect(got).to.eql([0, 4]); }); @@ -42,12 +42,12 @@ describe('ol.geom.flat.straightchunk', function() { const stride = 2; it('returns stright chunk from within the linestring', function() { - const got = _ol_geom_flat_straightchunk_.lineString(0, flatCoords, 0, 18, stride); + const got = matchingChunk(0, flatCoords, 0, 18, stride); expect(got).to.eql([10, 16]); }); it('returns long chunk at the end if angle and length within threshold', function() { - const got = _ol_geom_flat_straightchunk_.lineString(Math.PI / 4, flatCoords, 0, 18, stride); + const got = matchingChunk(Math.PI / 4, flatCoords, 0, 18, stride); expect(got).to.eql([10, 18]); });