Named exports from ol/geom/flat/topology

This commit is contained in:
Frederic Junod
2018-01-26 15:35:14 +01:00
parent 135f713236
commit 297fd14507
3 changed files with 11 additions and 15 deletions
+2 -4
View File
@@ -2,7 +2,6 @@
* @module ol/geom/flat/topology * @module ol/geom/flat/topology
*/ */
import {linearRing as linearRingArea} from '../flat/area.js'; import {linearRing as linearRingArea} from '../flat/area.js';
const _ol_geom_flat_topology_ = {};
/** /**
* Check if the linestring is a boundary. * Check if the linestring is a boundary.
@@ -12,12 +11,11 @@ const _ol_geom_flat_topology_ = {};
* @param {number} stride Stride. * @param {number} stride Stride.
* @return {boolean} The linestring is a boundary. * @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; const lastCoord = end - stride;
if (flatCoordinates[offset] === flatCoordinates[lastCoord] && if (flatCoordinates[offset] === flatCoordinates[lastCoord] &&
flatCoordinates[offset + 1] === flatCoordinates[lastCoord + 1] && (end - offset) / stride > 3) { flatCoordinates[offset + 1] === flatCoordinates[lastCoord + 1] && (end - offset) / stride > 3) {
return !!linearRingArea(flatCoordinates, offset, end, stride); return !!linearRingArea(flatCoordinates, offset, end, stride);
} }
return false; return false;
}; }
export default _ol_geom_flat_topology_;
+4 -6
View File
@@ -7,7 +7,7 @@ import {asArray} from '../../color.js';
import {intersects} from '../../extent.js'; import {intersects} from '../../extent.js';
import _ol_geom_flat_orient_ from '../../geom/flat/orient.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_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 {isEmpty} from '../../obj.js';
import _ol_render_webgl_ from '../webgl.js'; import _ol_render_webgl_ from '../webgl.js';
import WebGLReplay from '../webgl/Replay.js'; import WebGLReplay from '../webgl/Replay.js';
@@ -91,7 +91,7 @@ WebGLLineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, off
this.state_.lineJoin === 'miter' ? 1 : 2; this.state_.lineJoin === 'miter' ? 1 : 2;
const lineCap = this.state_.lineCap === 'butt' ? 0 : const lineCap = this.state_.lineCap === 'butt' ? 0 :
this.state_.lineCap === 'square' ? 1 : 2; 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 startCoords, sign, n;
let lastIndex = numIndices; let lastIndex = numIndices;
let lastSign = 1; let lastSign = 1;
@@ -357,8 +357,7 @@ WebGLLineStringReplay.prototype.drawMultiLineString = function(multiLineStringGe
*/ */
WebGLLineStringReplay.prototype.drawPolygonCoordinates = function( WebGLLineStringReplay.prototype.drawPolygonCoordinates = function(
flatCoordinates, holeFlatCoordinates, stride) { flatCoordinates, holeFlatCoordinates, stride) {
if (!_ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, if (!lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, stride)) {
flatCoordinates.length, stride)) {
flatCoordinates.push(flatCoordinates[0]); flatCoordinates.push(flatCoordinates[0]);
flatCoordinates.push(flatCoordinates[1]); flatCoordinates.push(flatCoordinates[1]);
} }
@@ -366,8 +365,7 @@ WebGLLineStringReplay.prototype.drawPolygonCoordinates = function(
if (holeFlatCoordinates.length) { if (holeFlatCoordinates.length) {
let i, ii; let i, ii;
for (i = 0, ii = holeFlatCoordinates.length; i < ii; ++i) { for (i = 0, ii = holeFlatCoordinates.length; i < ii; ++i) {
if (!_ol_geom_flat_topology_.lineStringIsClosed(holeFlatCoordinates[i], 0, if (!lineStringIsClosed(holeFlatCoordinates[i], 0, holeFlatCoordinates[i].length, stride)) {
holeFlatCoordinates[i].length, stride)) {
holeFlatCoordinates[i].push(holeFlatCoordinates[i][0]); holeFlatCoordinates[i].push(holeFlatCoordinates[i][0]);
holeFlatCoordinates[i].push(holeFlatCoordinates[i][1]); holeFlatCoordinates[i].push(holeFlatCoordinates[i][1]);
} }
@@ -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() { describe('ol.geom.flat.topology', function() {
@@ -6,23 +6,23 @@ describe('ol.geom.flat.topology', function() {
it('identifies closed lines aka boundaries', function() { it('identifies closed lines aka boundaries', function() {
const flatCoordinates = [0, 0, 3, 0, 0, 3, 0, 0]; 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); expect(isClosed).to.be(true);
}); });
it('identifies regular linestrings', function() { it('identifies regular linestrings', function() {
const flatCoordinates = [0, 0, 3, 0, 0, 3, 5, 2]; 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); expect(isClosed).to.be(false);
}); });
it('identifies degenerate boundaries', function() { it('identifies degenerate boundaries', function() {
let flatCoordinates = [0, 0, 3, 0, 0, 0]; 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); expect(isClosed).to.be(false);
flatCoordinates = [0, 0, 1, 1, 3, 3, 5, 5, 0, 0]; 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); expect(isClosed).to.be(false);
}); });