From 297fd145076614e85949748512f97d884d2c0a05 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 26 Jan 2018 15:35:14 +0100 Subject: [PATCH] Named exports from ol/geom/flat/topology --- src/ol/geom/flat/topology.js | 6 ++---- src/ol/render/webgl/LineStringReplay.js | 10 ++++------ test/spec/ol/geom/flat/topologyflatgeom.test.js | 10 +++++----- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/ol/geom/flat/topology.js b/src/ol/geom/flat/topology.js index bb58e50db1..e594c975f0 100644 --- a/src/ol/geom/flat/topology.js +++ b/src/ol/geom/flat/topology.js @@ -2,7 +2,6 @@ * @module ol/geom/flat/topology */ import {linearRing as linearRingArea} from '../flat/area.js'; -const _ol_geom_flat_topology_ = {}; /** * Check if the linestring is a boundary. @@ -12,12 +11,11 @@ const _ol_geom_flat_topology_ = {}; * @param {number} stride Stride. * @return {boolean} The linestring is a boundary. */ -_ol_geom_flat_topology_.lineStringIsClosed = function(flatCoordinates, offset, end, stride) { +export function lineStringIsClosed(flatCoordinates, offset, end, stride) { const lastCoord = end - stride; if (flatCoordinates[offset] === flatCoordinates[lastCoord] && flatCoordinates[offset + 1] === flatCoordinates[lastCoord + 1] && (end - offset) / stride > 3) { return !!linearRingArea(flatCoordinates, offset, end, stride); } return false; -}; -export default _ol_geom_flat_topology_; +} diff --git a/src/ol/render/webgl/LineStringReplay.js b/src/ol/render/webgl/LineStringReplay.js index e0d2dbabd7..ccdf19a898 100644 --- a/src/ol/render/webgl/LineStringReplay.js +++ b/src/ol/render/webgl/LineStringReplay.js @@ -7,7 +7,7 @@ import {asArray} from '../../color.js'; import {intersects} from '../../extent.js'; import _ol_geom_flat_orient_ from '../../geom/flat/orient.js'; import _ol_geom_flat_transform_ from '../../geom/flat/transform.js'; -import _ol_geom_flat_topology_ from '../../geom/flat/topology.js'; +import {lineStringIsClosed} from '../../geom/flat/topology.js'; import {isEmpty} from '../../obj.js'; import _ol_render_webgl_ from '../webgl.js'; import WebGLReplay from '../webgl/Replay.js'; @@ -91,7 +91,7 @@ WebGLLineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, off this.state_.lineJoin === 'miter' ? 1 : 2; const lineCap = this.state_.lineCap === 'butt' ? 0 : this.state_.lineCap === 'square' ? 1 : 2; - const closed = _ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, offset, end, stride); + const closed = lineStringIsClosed(flatCoordinates, offset, end, stride); let startCoords, sign, n; let lastIndex = numIndices; let lastSign = 1; @@ -357,8 +357,7 @@ WebGLLineStringReplay.prototype.drawMultiLineString = function(multiLineStringGe */ WebGLLineStringReplay.prototype.drawPolygonCoordinates = function( flatCoordinates, holeFlatCoordinates, stride) { - if (!_ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, - flatCoordinates.length, stride)) { + if (!lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, stride)) { flatCoordinates.push(flatCoordinates[0]); flatCoordinates.push(flatCoordinates[1]); } @@ -366,8 +365,7 @@ WebGLLineStringReplay.prototype.drawPolygonCoordinates = function( if (holeFlatCoordinates.length) { let i, ii; for (i = 0, ii = holeFlatCoordinates.length; i < ii; ++i) { - if (!_ol_geom_flat_topology_.lineStringIsClosed(holeFlatCoordinates[i], 0, - holeFlatCoordinates[i].length, stride)) { + if (!lineStringIsClosed(holeFlatCoordinates[i], 0, holeFlatCoordinates[i].length, stride)) { holeFlatCoordinates[i].push(holeFlatCoordinates[i][0]); holeFlatCoordinates[i].push(holeFlatCoordinates[i][1]); } diff --git a/test/spec/ol/geom/flat/topologyflatgeom.test.js b/test/spec/ol/geom/flat/topologyflatgeom.test.js index d9a6dc5865..f0d17999d0 100644 --- a/test/spec/ol/geom/flat/topologyflatgeom.test.js +++ b/test/spec/ol/geom/flat/topologyflatgeom.test.js @@ -1,4 +1,4 @@ -import _ol_geom_flat_topology_ from '../../../../../src/ol/geom/flat/topology.js'; +import {lineStringIsClosed} from '../../../../../src/ol/geom/flat/topology.js'; describe('ol.geom.flat.topology', function() { @@ -6,23 +6,23 @@ describe('ol.geom.flat.topology', function() { it('identifies closed lines aka boundaries', function() { const flatCoordinates = [0, 0, 3, 0, 0, 3, 0, 0]; - const isClosed = _ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2); + const isClosed = lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2); expect(isClosed).to.be(true); }); it('identifies regular linestrings', function() { const flatCoordinates = [0, 0, 3, 0, 0, 3, 5, 2]; - const isClosed = _ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2); + const isClosed = lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2); expect(isClosed).to.be(false); }); it('identifies degenerate boundaries', function() { let flatCoordinates = [0, 0, 3, 0, 0, 0]; - let isClosed = _ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2); + let isClosed = lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2); expect(isClosed).to.be(false); flatCoordinates = [0, 0, 1, 1, 3, 3, 5, 5, 0, 0]; - isClosed = _ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2); + isClosed = lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2); expect(isClosed).to.be(false); });