From 05a648d4f36485bb0f68029b9cf2099bbc1336b2 Mon Sep 17 00:00:00 2001 From: raiyni Date: Mon, 12 Feb 2018 23:27:38 -0600 Subject: [PATCH] ol/geom/flat/length export --- src/ol/geom/LineString.js | 4 ++-- src/ol/geom/flat/length.js | 12 +++++------- src/ol/render/canvas/Replay.js | 4 ++-- test/spec/ol/geom/flat/length.test.js | 18 +++++++++--------- test/spec/ol/geom/flat/textpath.test.js | 12 ++++++------ 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/ol/geom/LineString.js b/src/ol/geom/LineString.js index 16ca750acb..22117d03fc 100644 --- a/src/ol/geom/LineString.js +++ b/src/ol/geom/LineString.js @@ -12,7 +12,7 @@ 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 _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; -import _ol_geom_flat_length_ from '../geom/flat/length.js'; +import {lineStringLength} from '../geom/flat/length.js'; import {forEach as forEachSegment} from '../geom/flat/segments.js'; import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js'; @@ -183,7 +183,7 @@ LineString.prototype.getCoordinateAt = function(fraction, opt_dest) { * @api */ LineString.prototype.getLength = function() { - return _ol_geom_flat_length_.lineString( + return lineStringLength( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride); }; diff --git a/src/ol/geom/flat/length.js b/src/ol/geom/flat/length.js index c1139211a4..3a329da814 100644 --- a/src/ol/geom/flat/length.js +++ b/src/ol/geom/flat/length.js @@ -1,7 +1,6 @@ /** * @module ol/geom/flat/length */ -const _ol_geom_flat_length_ = {}; /** @@ -11,7 +10,7 @@ const _ol_geom_flat_length_ = {}; * @param {number} stride Stride. * @return {number} Length. */ -_ol_geom_flat_length_.lineString = function(flatCoordinates, offset, end, stride) { +export function lineStringLength(flatCoordinates, offset, end, stride) { let x1 = flatCoordinates[offset]; let y1 = flatCoordinates[offset + 1]; let length = 0; @@ -23,7 +22,7 @@ _ol_geom_flat_length_.lineString = function(flatCoordinates, offset, end, stride y1 = y2; } return length; -}; +} /** @@ -33,11 +32,10 @@ _ol_geom_flat_length_.lineString = function(flatCoordinates, offset, end, stride * @param {number} stride Stride. * @return {number} Perimeter. */ -_ol_geom_flat_length_.linearRing = function(flatCoordinates, offset, end, stride) { - let perimeter = _ol_geom_flat_length_.lineString(flatCoordinates, offset, end, stride); +export function linearRingLength(flatCoordinates, offset, end, stride) { + let perimeter = lineStringLength(flatCoordinates, offset, end, stride); const dx = flatCoordinates[end - stride] - flatCoordinates[offset]; const dy = flatCoordinates[end - stride + 1] - flatCoordinates[offset + 1]; perimeter += Math.sqrt(dx * dx + dy * dy); return perimeter; -}; -export default _ol_geom_flat_length_; +} diff --git a/src/ol/render/canvas/Replay.js b/src/ol/render/canvas/Replay.js index 329815acac..b43195e582 100644 --- a/src/ol/render/canvas/Replay.js +++ b/src/ol/render/canvas/Replay.js @@ -9,7 +9,7 @@ import {buffer, clone, coordinateRelationship, createEmpty, createOrUpdate, import Relationship from '../../extent/Relationship.js'; import GeometryType from '../../geom/GeometryType.js'; import {inflateCoordinates, inflateCoordinatesArray, inflateMultiCoordinatesArray} from '../../geom/flat/inflate.js'; -import _ol_geom_flat_length_ from '../../geom/flat/length.js'; +import {lineStringLength} from '../../geom/flat/length.js'; import _ol_geom_flat_textpath_ from '../../geom/flat/textpath.js'; import _ol_geom_flat_transform_ from '../../geom/flat/transform.js'; import {CANVAS_LINE_DASH} from '../../has.js'; @@ -710,7 +710,7 @@ CanvasReplay.prototype.replay_ = function( const textKey = /** @type {string} */ (instruction[13]); const textScale = /** @type {number} */ (instruction[14]); - const pathLength = _ol_geom_flat_length_.lineString(pixelCoordinates, begin, end, 2); + const pathLength = lineStringLength(pixelCoordinates, begin, end, 2); const textLength = measure(text); if (overflow || textLength <= pathLength) { const textAlign = /** @type {ol.render.canvas.TextReplay} */ (this).textStates[textKey].textAlign; diff --git a/test/spec/ol/geom/flat/length.test.js b/test/spec/ol/geom/flat/length.test.js index 9539557176..030608b545 100644 --- a/test/spec/ol/geom/flat/length.test.js +++ b/test/spec/ol/geom/flat/length.test.js @@ -1,4 +1,4 @@ -import _ol_geom_flat_length_ from '../../../../../src/ol/geom/flat/length.js'; +import {lineStringLength, linearRingLength} from '../../../../../src/ol/geom/flat/length.js'; describe('ol.geom.flat.length', function() { @@ -13,7 +13,7 @@ describe('ol.geom.flat.length', function() { const offset = 0; const end = 8; const expected = 3; - const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride); + const got = lineStringLength(flatCoords, offset, end, stride); expect(got).to.be(expected); }); @@ -21,7 +21,7 @@ describe('ol.geom.flat.length', function() { const offset = 2; const end = 8; const expected = 2; - const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride); + const got = lineStringLength(flatCoords, offset, end, stride); expect(got).to.be(expected); }); @@ -29,7 +29,7 @@ describe('ol.geom.flat.length', function() { const offset = 0; const end = 4; const expected = 1; - const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride); + const got = lineStringLength(flatCoords, offset, end, stride); expect(got).to.be(expected); }); @@ -43,7 +43,7 @@ describe('ol.geom.flat.length', function() { const offset = 0; const end = 12; const expected = 3; - const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride); + const got = lineStringLength(flatCoords, offset, end, stride); expect(got).to.be(expected); }); @@ -51,7 +51,7 @@ describe('ol.geom.flat.length', function() { const offset = 3; const end = 12; const expected = 2; - const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride); + const got = lineStringLength(flatCoords, offset, end, stride); expect(got).to.be(expected); }); @@ -59,7 +59,7 @@ describe('ol.geom.flat.length', function() { const offset = 0; const end = 6; const expected = 1; - const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride); + const got = lineStringLength(flatCoords, offset, end, stride); expect(got).to.be(expected); }); @@ -74,7 +74,7 @@ describe('ol.geom.flat.length', function() { const offset = 0; const end = 8; const expected = 4; - const got = _ol_geom_flat_length_.linearRing(flatCoords, offset, end, stride); + const got = linearRingLength(flatCoords, offset, end, stride); expect(got).to.be(expected); }); @@ -84,7 +84,7 @@ describe('ol.geom.flat.length', function() { const offset = 0; const end = 14; const expected = 8; - const got = _ol_geom_flat_length_.linearRing(flatCoords, offset, end, stride); + const got = linearRingLength(flatCoords, offset, end, stride); expect(got).to.be(expected); }); diff --git a/test/spec/ol/geom/flat/textpath.test.js b/test/spec/ol/geom/flat/textpath.test.js index dea6fda047..4b63c0bd02 100644 --- a/test/spec/ol/geom/flat/textpath.test.js +++ b/test/spec/ol/geom/flat/textpath.test.js @@ -1,5 +1,5 @@ import _ol_geom_flat_textpath_ from '../../../../../src/ol/geom/flat/textpath.js'; -import _ol_geom_flat_length_ from '../../../../../src/ol/geom/flat/length.js'; +import {lineStringLength} from '../../../../../src/ol/geom/flat/length.js'; describe('textpath', function() { @@ -67,7 +67,7 @@ describe('textpath', function() { }); it('renders angled text', function() { - const length = _ol_geom_flat_length_.lineString(angled, 0, angled.length, 2); + const length = lineStringLength(angled, 0, angled.length, 2); const startM = length / 2 - 15; const instructions = _ol_geom_flat_textpath_.lineString( angled, 0, angled.length, 2, 'foo', measure, startM, Infinity); @@ -78,7 +78,7 @@ describe('textpath', function() { }); it('respects maxAngle', function() { - const length = _ol_geom_flat_length_.lineString(angled, 0, angled.length, 2); + const length = lineStringLength(angled, 0, angled.length, 2); const startM = length / 2 - 15; const instructions = _ol_geom_flat_textpath_.lineString( angled, 0, angled.length, 2, 'foo', measure, startM, Math.PI / 4); @@ -86,7 +86,7 @@ describe('textpath', function() { }); it('uses the smallest angle for maxAngleDelta', function() { - const length = _ol_geom_flat_length_.lineString(reverseangled, 0, reverseangled.length, 2); + const length = lineStringLength(reverseangled, 0, reverseangled.length, 2); const startM = length / 2 - 15; const instructions = _ol_geom_flat_textpath_.lineString( reverseangled, 0, reverseangled.length, 2, 'foo', measure, startM, Math.PI); @@ -94,7 +94,7 @@ describe('textpath', function() { }); it('respects the offset option', function() { - const length = _ol_geom_flat_length_.lineString(angled, 2, angled.length, 2); + const length = lineStringLength(angled, 2, angled.length, 2); const startM = length / 2 - 15; const instructions = _ol_geom_flat_textpath_.lineString( angled, 2, angled.length, 2, 'foo', measure, startM, Infinity); @@ -103,7 +103,7 @@ describe('textpath', function() { }); it('respects the end option', function() { - const length = _ol_geom_flat_length_.lineString(angled, 0, 4, 2); + const length = lineStringLength(angled, 0, 4, 2); const startM = length / 2 - 15; const instructions = _ol_geom_flat_textpath_.lineString( angled, 0, 4, 2, 'foo', measure, startM, Infinity);