From 837490b4a466495c9af8ba3cfe8093e32893e119 Mon Sep 17 00:00:00 2001 From: raiyni Date: Tue, 13 Feb 2018 00:08:20 -0600 Subject: [PATCH] ol/geom/flat/simplify export --- src/ol/geom/LineString.js | 4 +- src/ol/geom/LinearRing.js | 4 +- src/ol/geom/MultiLineString.js | 4 +- src/ol/geom/MultiPolygon.js | 4 +- src/ol/geom/Polygon.js | 4 +- src/ol/geom/flat/simplify.js | 62 +++++++++---------- src/ol/render/canvas/PolygonReplay.js | 4 +- test/spec/ol/geom/flat/simplify.test.js | 82 ++++++++++++------------- 8 files changed, 83 insertions(+), 85 deletions(-) diff --git a/src/ol/geom/LineString.js b/src/ol/geom/LineString.js index 22117d03fc..2b41259834 100644 --- a/src/ol/geom/LineString.js +++ b/src/ol/geom/LineString.js @@ -14,7 +14,7 @@ import _ol_geom_flat_interpolate_ 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'; -import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js'; +import {douglasPeucker} from '../geom/flat/simplify.js'; /** * @classdesc @@ -205,7 +205,7 @@ LineString.prototype.getFlatMidpoint = function() { */ LineString.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) { const simplifiedFlatCoordinates = []; - simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.douglasPeucker( + simplifiedFlatCoordinates.length = douglasPeucker( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, squaredTolerance, simplifiedFlatCoordinates, 0); const simplifiedLineString = new LineString(null); diff --git a/src/ol/geom/LinearRing.js b/src/ol/geom/LinearRing.js index 4346897b42..e80193eae8 100644 --- a/src/ol/geom/LinearRing.js +++ b/src/ol/geom/LinearRing.js @@ -10,7 +10,7 @@ import {linearRing as linearRingArea} from '../geom/flat/area.js'; import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; import {deflateCoordinates} from '../geom/flat/deflate.js'; import {inflateCoordinates} from '../geom/flat/inflate.js'; -import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js'; +import {douglasPeucker} from '../geom/flat/simplify.js'; /** * @classdesc @@ -104,7 +104,7 @@ LinearRing.prototype.getCoordinates = function() { */ LinearRing.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) { const simplifiedFlatCoordinates = []; - simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.douglasPeucker( + simplifiedFlatCoordinates.length = douglasPeucker( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, squaredTolerance, simplifiedFlatCoordinates, 0); const simplifiedLinearRing = new LinearRing(null); diff --git a/src/ol/geom/MultiLineString.js b/src/ol/geom/MultiLineString.js index de620b2f28..fb72c107fb 100644 --- a/src/ol/geom/MultiLineString.js +++ b/src/ol/geom/MultiLineString.js @@ -13,7 +13,7 @@ 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 _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; -import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js'; +import {douglasPeuckerArray} from '../geom/flat/simplify.js'; /** * @classdesc @@ -223,7 +223,7 @@ MultiLineString.prototype.getFlatMidpoints = function() { MultiLineString.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) { const simplifiedFlatCoordinates = []; const simplifiedEnds = []; - simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.douglasPeuckers( + simplifiedFlatCoordinates.length = douglasPeuckerArray( this.flatCoordinates, 0, this.ends_, this.stride, squaredTolerance, simplifiedFlatCoordinates, 0, simplifiedEnds); const simplifiedMultiLineString = new MultiLineString(null); diff --git a/src/ol/geom/MultiPolygon.js b/src/ol/geom/MultiPolygon.js index 517e3b9773..5fe7cd98e6 100644 --- a/src/ol/geom/MultiPolygon.js +++ b/src/ol/geom/MultiPolygon.js @@ -18,7 +18,7 @@ import {inflateMultiCoordinatesArray} from '../geom/flat/inflate.js'; import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; import _ol_geom_flat_orient_ from '../geom/flat/orient.js'; -import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js'; +import {quantizeMultiArray} from '../geom/flat/simplify.js'; /** * @classdesc @@ -259,7 +259,7 @@ MultiPolygon.prototype.getOrientedFlatCoordinates = function() { MultiPolygon.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) { const simplifiedFlatCoordinates = []; const simplifiedEndss = []; - simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.quantizess( + simplifiedFlatCoordinates.length = quantizeMultiArray( this.flatCoordinates, 0, this.endss_, this.stride, Math.sqrt(squaredTolerance), simplifiedFlatCoordinates, 0, simplifiedEndss); diff --git a/src/ol/geom/Polygon.js b/src/ol/geom/Polygon.js index c345404903..55841b9ead 100644 --- a/src/ol/geom/Polygon.js +++ b/src/ol/geom/Polygon.js @@ -18,7 +18,7 @@ import {inflateCoordinatesArray} from '../geom/flat/inflate.js'; import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; import _ol_geom_flat_orient_ from '../geom/flat/orient.js'; -import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js'; +import {quantizeArray} from '../geom/flat/simplify.js'; import {modulo} from '../math.js'; /** @@ -300,7 +300,7 @@ Polygon.prototype.getOrientedFlatCoordinates = function() { Polygon.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) { const simplifiedFlatCoordinates = []; const simplifiedEnds = []; - simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.quantizes( + simplifiedFlatCoordinates.length = quantizeArray( this.flatCoordinates, 0, this.ends_, this.stride, Math.sqrt(squaredTolerance), simplifiedFlatCoordinates, 0, simplifiedEnds); diff --git a/src/ol/geom/flat/simplify.js b/src/ol/geom/flat/simplify.js index a9928896a3..393a8a362b 100644 --- a/src/ol/geom/flat/simplify.js +++ b/src/ol/geom/flat/simplify.js @@ -28,7 +28,6 @@ // POSSIBILITY OF SUCH DAMAGE. import {squaredSegmentDistance, squaredDistance} from '../../math.js'; -const _ol_geom_flat_simplify_ = {}; /** @@ -42,23 +41,23 @@ const _ol_geom_flat_simplify_ = {}; * coordinates. * @return {Array.} Simplified line string. */ -_ol_geom_flat_simplify_.lineString = function(flatCoordinates, offset, end, +export function simplifyLineString(flatCoordinates, offset, end, stride, squaredTolerance, highQuality, opt_simplifiedFlatCoordinates) { const simplifiedFlatCoordinates = opt_simplifiedFlatCoordinates !== undefined ? opt_simplifiedFlatCoordinates : []; if (!highQuality) { - end = _ol_geom_flat_simplify_.radialDistance(flatCoordinates, offset, end, + end = radialDistance(flatCoordinates, offset, end, stride, squaredTolerance, simplifiedFlatCoordinates, 0); flatCoordinates = simplifiedFlatCoordinates; offset = 0; stride = 2; } - simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.douglasPeucker( + simplifiedFlatCoordinates.length = douglasPeucker( flatCoordinates, offset, end, stride, squaredTolerance, simplifiedFlatCoordinates, 0); return simplifiedFlatCoordinates; -}; +} /** @@ -72,7 +71,7 @@ _ol_geom_flat_simplify_.lineString = function(flatCoordinates, offset, end, * @param {number} simplifiedOffset Simplified offset. * @return {number} Simplified offset. */ -_ol_geom_flat_simplify_.douglasPeucker = function(flatCoordinates, offset, end, +export function douglasPeucker(flatCoordinates, offset, end, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) { const n = (end - offset) / stride; if (n < 3) { @@ -128,7 +127,7 @@ _ol_geom_flat_simplify_.douglasPeucker = function(flatCoordinates, offset, end, } } return simplifiedOffset; -}; +} /** @@ -143,19 +142,19 @@ _ol_geom_flat_simplify_.douglasPeucker = function(flatCoordinates, offset, end, * @param {Array.} simplifiedEnds Simplified ends. * @return {number} Simplified offset. */ -_ol_geom_flat_simplify_.douglasPeuckers = function(flatCoordinates, offset, +export function douglasPeuckerArray(flatCoordinates, offset, ends, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds) { for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; - simplifiedOffset = _ol_geom_flat_simplify_.douglasPeucker( + simplifiedOffset = douglasPeucker( flatCoordinates, offset, end, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset); simplifiedEnds.push(simplifiedOffset); offset = end; } return simplifiedOffset; -}; +} /** @@ -170,20 +169,20 @@ _ol_geom_flat_simplify_.douglasPeuckers = function(flatCoordinates, offset, * @param {Array.>} simplifiedEndss Simplified endss. * @return {number} Simplified offset. */ -_ol_geom_flat_simplify_.douglasPeuckerss = function( +export function douglasPeuckerMultiArray( flatCoordinates, offset, endss, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) { for (let i = 0, ii = endss.length; i < ii; ++i) { const ends = endss[i]; const simplifiedEnds = []; - simplifiedOffset = _ol_geom_flat_simplify_.douglasPeuckers( + simplifiedOffset = douglasPeuckerArray( flatCoordinates, offset, ends, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds); simplifiedEndss.push(simplifiedEnds); offset = ends[ends.length - 1]; } return simplifiedOffset; -}; +} /** @@ -197,7 +196,7 @@ _ol_geom_flat_simplify_.douglasPeuckerss = function( * @param {number} simplifiedOffset Simplified offset. * @return {number} Simplified offset. */ -_ol_geom_flat_simplify_.radialDistance = function(flatCoordinates, offset, end, +export function radialDistance(flatCoordinates, offset, end, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) { if (end <= offset + stride) { // zero or one point, no simplification possible, so copy and return @@ -232,7 +231,7 @@ _ol_geom_flat_simplify_.radialDistance = function(flatCoordinates, offset, end, simplifiedFlatCoordinates[simplifiedOffset++] = y2; } return simplifiedOffset; -}; +} /** @@ -240,9 +239,9 @@ _ol_geom_flat_simplify_.radialDistance = function(flatCoordinates, offset, end, * @param {number} tolerance Tolerance. * @return {number} Rounded value. */ -_ol_geom_flat_simplify_.snap = function(value, tolerance) { +export function snap(value, tolerance) { return tolerance * Math.round(value / tolerance); -}; +} /** @@ -264,15 +263,15 @@ _ol_geom_flat_simplify_.snap = function(value, tolerance) { * @param {number} simplifiedOffset Simplified offset. * @return {number} Simplified offset. */ -_ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride, +export function quantize(flatCoordinates, offset, end, stride, tolerance, simplifiedFlatCoordinates, simplifiedOffset) { // do nothing if the line is empty if (offset == end) { return simplifiedOffset; } // snap the first coordinate (P1) - let x1 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance); - let y1 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance); + let x1 = snap(flatCoordinates[offset], tolerance); + let y1 = snap(flatCoordinates[offset + 1], tolerance); offset += stride; // add the first coordinate to the output simplifiedFlatCoordinates[simplifiedOffset++] = x1; @@ -281,8 +280,8 @@ _ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride // coordinate (P2) let x2, y2; do { - x2 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance); - y2 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance); + x2 = snap(flatCoordinates[offset], tolerance); + y2 = snap(flatCoordinates[offset + 1], tolerance); offset += stride; if (offset == end) { // all coordinates snap to the same value, the line collapses to a point @@ -296,8 +295,8 @@ _ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride } while (x2 == x1 && y2 == y1); while (offset < end) { // snap the next coordinate (P3) - const x3 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance); - const y3 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance); + const x3 = snap(flatCoordinates[offset], tolerance); + const y3 = snap(flatCoordinates[offset + 1], tolerance); offset += stride; // skip P3 if it is equal to P2 if (x3 == x2 && y3 == y2) { @@ -334,7 +333,7 @@ _ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride simplifiedFlatCoordinates[simplifiedOffset++] = x2; simplifiedFlatCoordinates[simplifiedOffset++] = y2; return simplifiedOffset; -}; +} /** @@ -349,13 +348,13 @@ _ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride * @param {Array.} simplifiedEnds Simplified ends. * @return {number} Simplified offset. */ -_ol_geom_flat_simplify_.quantizes = function( +export function quantizeArray( flatCoordinates, offset, ends, stride, tolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds) { for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; - simplifiedOffset = _ol_geom_flat_simplify_.quantize( + simplifiedOffset = quantize( flatCoordinates, offset, end, stride, tolerance, simplifiedFlatCoordinates, simplifiedOffset); @@ -363,7 +362,7 @@ _ol_geom_flat_simplify_.quantizes = function( offset = end; } return simplifiedOffset; -}; +} /** @@ -378,14 +377,14 @@ _ol_geom_flat_simplify_.quantizes = function( * @param {Array.>} simplifiedEndss Simplified endss. * @return {number} Simplified offset. */ -_ol_geom_flat_simplify_.quantizess = function( +export function quantizeMultiArray( flatCoordinates, offset, endss, stride, tolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) { for (let i = 0, ii = endss.length; i < ii; ++i) { const ends = endss[i]; const simplifiedEnds = []; - simplifiedOffset = _ol_geom_flat_simplify_.quantizes( + simplifiedOffset = quantizeArray( flatCoordinates, offset, ends, stride, tolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds); @@ -393,5 +392,4 @@ _ol_geom_flat_simplify_.quantizess = function( offset = ends[ends.length - 1]; } return simplifiedOffset; -}; -export default _ol_geom_flat_simplify_; +} diff --git a/src/ol/render/canvas/PolygonReplay.js b/src/ol/render/canvas/PolygonReplay.js index 07328c96fb..8b4f403f8e 100644 --- a/src/ol/render/canvas/PolygonReplay.js +++ b/src/ol/render/canvas/PolygonReplay.js @@ -3,7 +3,7 @@ */ import {inherits} from '../../index.js'; import {asString} from '../../color.js'; -import _ol_geom_flat_simplify_ from '../../geom/flat/simplify.js'; +import {snap} from '../../geom/flat/simplify.js'; import _ol_render_canvas_ from '../canvas.js'; import CanvasInstruction from '../canvas/Instruction.js'; import CanvasReplay from '../canvas/Replay.js'; @@ -199,7 +199,7 @@ CanvasPolygonReplay.prototype.finish = function() { if (tolerance !== 0) { const coordinates = this.coordinates; for (let i = 0, ii = coordinates.length; i < ii; ++i) { - coordinates[i] = _ol_geom_flat_simplify_.snap(coordinates[i], tolerance); + coordinates[i] = snap(coordinates[i], tolerance); } } }; diff --git a/test/spec/ol/geom/flat/simplify.test.js b/test/spec/ol/geom/flat/simplify.test.js index 69eb49dbb7..2e3caec2e0 100644 --- a/test/spec/ol/geom/flat/simplify.test.js +++ b/test/spec/ol/geom/flat/simplify.test.js @@ -1,4 +1,4 @@ -import _ol_geom_flat_simplify_ from '../../../../../src/ol/geom/flat/simplify.js'; +import {douglasPeucker, quantize, radialDistance, simplifyLineString} from '../../../../../src/ol/geom/flat/simplify.js'; describe('ol.geom.flat.simplify', function() { @@ -81,31 +81,31 @@ describe('ol.geom.flat.simplify', function() { 866.36, 480.77 ]; - describe('ol.geom.flat.simplify.lineString', function() { + describe('ol.geom.flat.simplify.simplifyLineString', function() { it('works with empty line strings', function() { - expect(_ol_geom_flat_simplify_.lineString([], 0, 0, 2, 1, true)).to. + expect(simplifyLineString([], 0, 0, 2, 1, true)).to. eql([]); - expect(_ol_geom_flat_simplify_.lineString([], 0, 0, 2, 1, false)).to. + expect(simplifyLineString([], 0, 0, 2, 1, false)).to. eql([]); }); it('works with a line string with a single point', function() { - expect(_ol_geom_flat_simplify_.lineString([1, 2], 0, 2, 2, 1, true)).to. + expect(simplifyLineString([1, 2], 0, 2, 2, 1, true)).to. eql([1, 2]); - expect(_ol_geom_flat_simplify_.lineString([1, 2], 0, 2, 2, 1, false)).to. + expect(simplifyLineString([1, 2], 0, 2, 2, 1, false)).to. eql([1, 2]); }); it('returns the expected result with low quality', function() { - const result = _ol_geom_flat_simplify_.lineString( + const result = simplifyLineString( flatCoordinates, 0, flatCoordinates.length, 2, 25, false); expect(result.length).to.be(simplifiedFlatCoordinates.length); expect(result).to.eql(simplifiedFlatCoordinates); }); it('returns the expected result with high quality', function() { - const result = _ol_geom_flat_simplify_.lineString( + const result = simplifyLineString( flatCoordinates, 0, flatCoordinates.length, 2, 25, true); expect(result.length).to.be(simplifiedHighQualityFlatCoordinates.length); expect(result).to.eql(simplifiedHighQualityFlatCoordinates); @@ -121,63 +121,63 @@ describe('ol.geom.flat.simplify', function() { }); it('works with empty line strings', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [], 0, 0, 2, 1, dest, 0)).to.be(0); expect(dest).to.eql([]); }); it('works with a line string with a single point', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [1, 2], 0, 2, 2, 1, dest, 0)).to.be(2); expect(dest).to.eql([1, 2]); }); it('works with a line string with two points', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [1, 2, 3, 4], 0, 4, 2, 1, dest, 0)).to.be(4); expect(dest).to.eql([1, 2, 3, 4]); }); it('works when the points are widely spaced', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 0.5, dest, 0)).to.be(8); expect(dest).to.eql([0, 0, 1, 0, 2, 0, 3, 0]); }); it('works when the spacing matches the tolerance', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1, dest, 0)).to.be(6); expect(dest).to.eql([0, 0, 2, 0, 3, 0]); }); it('works when the points are closely spaced', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1.5, dest, 0)).to.be(6); expect(dest).to.eql([0, 0, 2, 0, 3, 0]); }); it('works when the line oscillates with widely spaced points', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 1, dest, 0)). to.be(12); expect(dest).to.eql([0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]); }); it('works when the line oscillates with closely spaced points', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 2, dest, 0)).to.be(4); expect(dest).to.eql([0, 0, 1, 1]); }); it('works when the line oscillates within the tolerance', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0], 0, 14, 2, 2, dest, 0)). to.be(2); expect(dest).to.eql([0, 0]); }); it('works with real data', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( flatCoordinates, 0, flatCoordinates.length, 2, 25, dest, 0)). to.be(simplifiedRadiallyFlatCoordinates.length); expect(dest).to.eql(simplifiedRadiallyFlatCoordinates); @@ -193,93 +193,93 @@ describe('ol.geom.flat.simplify', function() { }); it('works with empty line strings', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [], 0, 0, 2, 1, dest, 0)).to.be(0); expect(dest).to.eql([]); }); it('works with a line string with a single point', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [1, 2], 0, 2, 2, 1, dest, 0)).to.be(2); expect(dest).to.eql([1, 2]); }); it('works with a line string with two points', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [1, 2, 3, 4], 0, 4, 2, 1, dest, 0)).to.be(4); expect(dest).to.eql([1, 2, 3, 4]); }); it('works when the points are widely spaced', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 0.5, dest, 0)).to.be(4); expect(dest).to.eql([0, 0, 3, 0]); }); it('works when the spacing matches the tolerance', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1, dest, 0)).to.be(4); expect(dest).to.eql([0, 0, 3, 0]); }); it('works when the points are closely spaced', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1.5, dest, 0)).to.be(4); expect(dest).to.eql([0, 0, 3, 0]); }); it('does not elimnate points outside the tolerance', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 1, 2, 0], 0, 6, 2, 0.5, dest, 0)).to.be(6); expect(dest).to.eql([0, 0, 1, 1, 2, 0]); }); it('does eliminate points within the tolerance', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 1, 2, 0], 0, 6, 2, 2, dest, 0)).to.be(4); expect(dest).to.eql([0, 0, 2, 0]); }); it('does not eliminate multiple points outside the tolerance', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 1, 1, -1, 2, 0], 0, 8, 2, 0.5, dest, 0)).to.be(8); expect(dest).to.eql([0, 0, 1, 1, 1, -1, 2, 0]); }); it('does eliminate multiple points within the tolerance', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 1, 1, -1, 2, 0], 0, 8, 2, 2, dest, 0)).to.be(4); expect(dest).to.eql([0, 0, 2, 0]); }); it('works when the line oscillates with widely spaced points', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 1, dest, 0)).to.be(4); expect(dest).to.eql([0, 0, 1, 1]); }); it('works when the line oscillates with closely spaced points', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 2, dest, 0)). to.be(4); expect(dest).to.eql([0, 0, 1, 1]); }); it('works when the line oscillates within the tolerance', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0], 0, 14, 2, 2, dest, 0)). to.be(4); expect(dest).to.eql([0, 0, 0, 0]); }); it('works on small triangles', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [3, 0, 4, 1, 5, 2, 5, 0], 0, 8, 2, 1, dest, 0)).to.be(6); expect(dest).to.eql([3, 0, 5, 2, 5, 0]); }); it('is the same as high quality simplification', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( flatCoordinates, 0, flatCoordinates.length, 2, 25, dest, 0)). to.be(simplifiedHighQualityFlatCoordinates.length); expect(dest).to.eql(simplifiedHighQualityFlatCoordinates); @@ -291,28 +291,28 @@ describe('ol.geom.flat.simplify', function() { it('handles empty coordinates', function() { const simplifiedFlatCoordinates = []; - expect(_ol_geom_flat_simplify_.quantize( + expect(quantize( [], 0, 0, 2, 2, simplifiedFlatCoordinates, 0)).to.be(0); expect(simplifiedFlatCoordinates).to.be.empty(); }); it('expands points to a zero-length line', function() { const simplifiedFlatCoordinates = []; - expect(_ol_geom_flat_simplify_.quantize( + expect(quantize( [0, 0, 0, 0], 0, 4, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4); expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, 0]); }); it('snaps near-by points to the same value', function() { const simplifiedFlatCoordinates = []; - expect(_ol_geom_flat_simplify_.quantize( + expect(quantize( [0.1, 0, 0, 0.1], 0, 4, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4); expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, 0]); }); it('eliminates duplicate snapped points', function() { const simplifiedFlatCoordinates = []; - expect(_ol_geom_flat_simplify_.quantize( + expect(quantize( [0.1, 0, 2, 0, 2.1, 0, 2, 0.1, 1.9, 0, 2, -0.1], 0, 12, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4); expect(simplifiedFlatCoordinates).to.eql([0, 0, 2, 0]); @@ -320,7 +320,7 @@ describe('ol.geom.flat.simplify', function() { it('eliminates horizontal colinear points', function() { const simplifiedFlatCoordinates = []; - expect(_ol_geom_flat_simplify_.quantize( + expect(quantize( [0, 0, 2, 0, 4, 0, 6, 0], 0, 8, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4); expect(simplifiedFlatCoordinates).to.eql([0, 0, 6, 0]); @@ -328,7 +328,7 @@ describe('ol.geom.flat.simplify', function() { it('eliminates vertical colinear points', function() { const simplifiedFlatCoordinates = []; - expect(_ol_geom_flat_simplify_.quantize( + expect(quantize( [0, 0, 0, -2, 0, -4, 0, -6], 0, 8, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4); expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, -6]); @@ -336,7 +336,7 @@ describe('ol.geom.flat.simplify', function() { it('eliminates diagonal colinear points', function() { const simplifiedFlatCoordinates = []; - expect(_ol_geom_flat_simplify_.quantize( + expect(quantize( [0, 0, 2, -2, 4, -4, 6, -6], 0, 8, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4); expect(simplifiedFlatCoordinates).to.eql([0, 0, 6, -6]); @@ -344,7 +344,7 @@ describe('ol.geom.flat.simplify', function() { it('handles switchbacks', function() { const simplifiedFlatCoordinates = []; - expect(_ol_geom_flat_simplify_.quantize( + expect(quantize( [0, 0, 2, 0, 0, 0, 4, 0], 0, 8, 2, 2, simplifiedFlatCoordinates, 0)).to.be(8); expect(simplifiedFlatCoordinates).to.eql([0, 0, 2, 0, 0, 0, 4, 0]);