From c8165a8168e67a2ac7684d510e8961816bfe579b Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Wed, 12 Mar 2014 11:21:55 +0100 Subject: [PATCH] Factor out ol.geom.flat.simplify --- .../simplifyflatgeom.js} | 46 +++++----- src/ol/geom/linearring.js | 4 +- src/ol/geom/linestring.js | 4 +- src/ol/geom/multilinestring.js | 4 +- src/ol/geom/multipolygon.js | 4 +- src/ol/geom/polygon.js | 4 +- src/ol/render/canvas/canvasreplay.js | 4 +- .../simplifyflatgeom.test.js} | 91 ++++++++++--------- 8 files changed, 81 insertions(+), 80 deletions(-) rename src/ol/geom/{simplifygeom.js => flat/simplifyflatgeom.js} (89%) rename test/spec/ol/geom/{simplifygeom.test.js => flat/simplifyflatgeom.test.js} (83%) diff --git a/src/ol/geom/simplifygeom.js b/src/ol/geom/flat/simplifyflatgeom.js similarity index 89% rename from src/ol/geom/simplifygeom.js rename to src/ol/geom/flat/simplifyflatgeom.js index 1e361ae3e5..fa6bce3485 100644 --- a/src/ol/geom/simplifygeom.js +++ b/src/ol/geom/flat/simplifyflatgeom.js @@ -24,7 +24,7 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -goog.provide('ol.geom.simplify'); +goog.provide('ol.geom.flat.simplify'); goog.require('ol.geom.flat'); @@ -40,19 +40,19 @@ goog.require('ol.geom.flat'); * coordinates. * @return {Array.} Simplified line string. */ -ol.geom.simplify.lineString = function(flatCoordinates, offset, end, stride, - squaredTolerance, highQuality, opt_simplifiedFlatCoordinates) { +ol.geom.flat.simplify.lineString = function(flatCoordinates, offset, end, + stride, squaredTolerance, highQuality, opt_simplifiedFlatCoordinates) { var simplifiedFlatCoordinates = goog.isDef(opt_simplifiedFlatCoordinates) ? opt_simplifiedFlatCoordinates : []; if (!highQuality) { - end = ol.geom.simplify.radialDistance(flatCoordinates, offset, end, + end = ol.geom.flat.simplify.radialDistance(flatCoordinates, offset, end, stride, squaredTolerance, simplifiedFlatCoordinates, 0); flatCoordinates = simplifiedFlatCoordinates; offset = 0; stride = 2; } - simplifiedFlatCoordinates.length = ol.geom.simplify.douglasPeucker( + simplifiedFlatCoordinates.length = ol.geom.flat.simplify.douglasPeucker( flatCoordinates, offset, end, stride, squaredTolerance, simplifiedFlatCoordinates, 0); return simplifiedFlatCoordinates; @@ -70,7 +70,7 @@ ol.geom.simplify.lineString = function(flatCoordinates, offset, end, stride, * @param {number} simplifiedOffset Simplified offset. * @return {number} Simplified offset. */ -ol.geom.simplify.douglasPeucker = function(flatCoordinates, offset, end, +ol.geom.flat.simplify.douglasPeucker = function(flatCoordinates, offset, end, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) { var n = (end - offset) / stride; if (n < 3) { @@ -142,13 +142,13 @@ ol.geom.simplify.douglasPeucker = function(flatCoordinates, offset, end, * @param {Array.} simplifiedEnds Simplified ends. * @return {number} Simplified offset. */ -ol.geom.simplify.douglasPeuckers = function(flatCoordinates, offset, +ol.geom.flat.simplify.douglasPeuckers = function(flatCoordinates, offset, ends, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds) { var i, ii; for (i = 0, ii = ends.length; i < ii; ++i) { var end = ends[i]; - simplifiedOffset = ol.geom.simplify.douglasPeucker( + simplifiedOffset = ol.geom.flat.simplify.douglasPeucker( flatCoordinates, offset, end, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset); simplifiedEnds.push(simplifiedOffset); @@ -170,14 +170,14 @@ ol.geom.simplify.douglasPeuckers = function(flatCoordinates, offset, * @param {Array.>} simplifiedEndss Simplified endss. * @return {number} Simplified offset. */ -ol.geom.simplify.douglasPeuckerss = function( +ol.geom.flat.simplify.douglasPeuckerss = function( flatCoordinates, offset, endss, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) { var i, ii; for (i = 0, ii = endss.length; i < ii; ++i) { var ends = endss[i]; var simplifiedEnds = []; - simplifiedOffset = ol.geom.simplify.douglasPeuckers( + simplifiedOffset = ol.geom.flat.simplify.douglasPeuckers( flatCoordinates, offset, ends, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds); simplifiedEndss.push(simplifiedEnds); @@ -198,7 +198,7 @@ ol.geom.simplify.douglasPeuckerss = function( * @param {number} simplifiedOffset Simplified offset. * @return {number} Simplified offset. */ -ol.geom.simplify.radialDistance = function(flatCoordinates, offset, end, +ol.geom.flat.simplify.radialDistance = function(flatCoordinates, offset, end, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) { if (end <= offset + stride) { // zero or one point, no simplification possible, so copy and return @@ -241,7 +241,7 @@ ol.geom.simplify.radialDistance = function(flatCoordinates, offset, end, * @param {number} tolerance Squared tolerance. * @return {number} Rounded value. */ -ol.geom.simplify.snap = function(value, tolerance) { +ol.geom.flat.simplify.snap = function(value, tolerance) { return tolerance * Math.round(value / tolerance); }; @@ -265,15 +265,15 @@ ol.geom.simplify.snap = function(value, tolerance) { * @param {number} simplifiedOffset Simplified offset. * @return {number} Simplified offset. */ -ol.geom.simplify.quantize = function(flatCoordinates, offset, end, stride, +ol.geom.flat.simplify.quantize = function(flatCoordinates, offset, end, stride, tolerance, simplifiedFlatCoordinates, simplifiedOffset) { // do nothing if the line is empty if (offset == end) { return simplifiedOffset; } // snap the first coordinate (P1) - var x1 = ol.geom.simplify.snap(flatCoordinates[offset], tolerance); - var y1 = ol.geom.simplify.snap(flatCoordinates[offset + 1], tolerance); + var x1 = ol.geom.flat.simplify.snap(flatCoordinates[offset], tolerance); + var y1 = ol.geom.flat.simplify.snap(flatCoordinates[offset + 1], tolerance); offset += stride; // add the first coordinate to the output simplifiedFlatCoordinates[simplifiedOffset++] = x1; @@ -282,8 +282,8 @@ ol.geom.simplify.quantize = function(flatCoordinates, offset, end, stride, // coordinate (P2) var x2, y2; do { - x2 = ol.geom.simplify.snap(flatCoordinates[offset], tolerance); - y2 = ol.geom.simplify.snap(flatCoordinates[offset + 1], tolerance); + x2 = ol.geom.flat.simplify.snap(flatCoordinates[offset], tolerance); + y2 = ol.geom.flat.simplify.snap(flatCoordinates[offset + 1], tolerance); offset += stride; if (offset == end) { // all coordinates snap to the same value, the line collapses to a point @@ -298,8 +298,8 @@ ol.geom.simplify.quantize = function(flatCoordinates, offset, end, stride, while (offset < end) { var x3, y3; // snap the next coordinate (P3) - x3 = ol.geom.simplify.snap(flatCoordinates[offset], tolerance); - y3 = ol.geom.simplify.snap(flatCoordinates[offset + 1], tolerance); + x3 = ol.geom.flat.simplify.snap(flatCoordinates[offset], tolerance); + y3 = ol.geom.flat.simplify.snap(flatCoordinates[offset + 1], tolerance); offset += stride; // skip P3 if it is equal to P2 if (x3 == x2 && y3 == y2) { @@ -351,14 +351,14 @@ ol.geom.simplify.quantize = function(flatCoordinates, offset, end, stride, * @param {Array.} simplifiedEnds Simplified ends. * @return {number} Simplified offset. */ -ol.geom.simplify.quantizes = function( +ol.geom.flat.simplify.quantizes = function( flatCoordinates, offset, ends, stride, tolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds) { var i, ii; for (i = 0, ii = ends.length; i < ii; ++i) { var end = ends[i]; - simplifiedOffset = ol.geom.simplify.quantize( + simplifiedOffset = ol.geom.flat.simplify.quantize( flatCoordinates, offset, end, stride, tolerance, simplifiedFlatCoordinates, simplifiedOffset); @@ -381,7 +381,7 @@ ol.geom.simplify.quantizes = function( * @param {Array.>} simplifiedEndss Simplified endss. * @return {number} Simplified offset. */ -ol.geom.simplify.quantizess = function( +ol.geom.flat.simplify.quantizess = function( flatCoordinates, offset, endss, stride, tolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) { @@ -389,7 +389,7 @@ ol.geom.simplify.quantizess = function( for (i = 0, ii = endss.length; i < ii; ++i) { var ends = endss[i]; var simplifiedEnds = []; - simplifiedOffset = ol.geom.simplify.quantizes( + simplifiedOffset = ol.geom.flat.simplify.quantizes( flatCoordinates, offset, ends, stride, tolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds); diff --git a/src/ol/geom/linearring.js b/src/ol/geom/linearring.js index 71bde3380a..19e7214b9e 100644 --- a/src/ol/geom/linearring.js +++ b/src/ol/geom/linearring.js @@ -5,7 +5,7 @@ goog.require('ol.geom.GeometryType'); goog.require('ol.geom.SimpleGeometry'); goog.require('ol.geom.flat'); goog.require('ol.geom.flat.closest'); -goog.require('ol.geom.simplify'); +goog.require('ol.geom.flat.simplify'); @@ -94,7 +94,7 @@ ol.geom.LinearRing.prototype.getCoordinates = function() { ol.geom.LinearRing.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) { var simplifiedFlatCoordinates = []; - simplifiedFlatCoordinates.length = ol.geom.simplify.douglasPeucker( + simplifiedFlatCoordinates.length = ol.geom.flat.simplify.douglasPeucker( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, squaredTolerance, simplifiedFlatCoordinates, 0); var simplifiedLinearRing = new ol.geom.LinearRing(null); diff --git a/src/ol/geom/linestring.js b/src/ol/geom/linestring.js index ab3b55dfb0..15ebb69cc8 100644 --- a/src/ol/geom/linestring.js +++ b/src/ol/geom/linestring.js @@ -7,7 +7,7 @@ goog.require('ol.geom.GeometryType'); goog.require('ol.geom.SimpleGeometry'); goog.require('ol.geom.flat'); goog.require('ol.geom.flat.closest'); -goog.require('ol.geom.simplify'); +goog.require('ol.geom.flat.simplify'); @@ -160,7 +160,7 @@ ol.geom.LineString.prototype.getFlatMidpoint = function() { ol.geom.LineString.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) { var simplifiedFlatCoordinates = []; - simplifiedFlatCoordinates.length = ol.geom.simplify.douglasPeucker( + simplifiedFlatCoordinates.length = ol.geom.flat.simplify.douglasPeucker( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, squaredTolerance, simplifiedFlatCoordinates, 0); var simplifiedLineString = new ol.geom.LineString(null); diff --git a/src/ol/geom/multilinestring.js b/src/ol/geom/multilinestring.js index d859c34bae..8581fde85b 100644 --- a/src/ol/geom/multilinestring.js +++ b/src/ol/geom/multilinestring.js @@ -8,7 +8,7 @@ goog.require('ol.geom.LineString'); goog.require('ol.geom.SimpleGeometry'); goog.require('ol.geom.flat'); goog.require('ol.geom.flat.closest'); -goog.require('ol.geom.simplify'); +goog.require('ol.geom.flat.simplify'); @@ -214,7 +214,7 @@ ol.geom.MultiLineString.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) { var simplifiedFlatCoordinates = []; var simplifiedEnds = []; - simplifiedFlatCoordinates.length = ol.geom.simplify.douglasPeuckers( + simplifiedFlatCoordinates.length = ol.geom.flat.simplify.douglasPeuckers( this.flatCoordinates, 0, this.ends_, this.stride, squaredTolerance, simplifiedFlatCoordinates, 0, simplifiedEnds); var simplifiedMultiLineString = new ol.geom.MultiLineString(null); diff --git a/src/ol/geom/multipolygon.js b/src/ol/geom/multipolygon.js index 0e14f3798e..9cc90a7a25 100644 --- a/src/ol/geom/multipolygon.js +++ b/src/ol/geom/multipolygon.js @@ -9,7 +9,7 @@ goog.require('ol.geom.Polygon'); goog.require('ol.geom.SimpleGeometry'); goog.require('ol.geom.flat'); goog.require('ol.geom.flat.closest'); -goog.require('ol.geom.simplify'); +goog.require('ol.geom.flat.simplify'); @@ -219,7 +219,7 @@ ol.geom.MultiPolygon.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) { var simplifiedFlatCoordinates = []; var simplifiedEndss = []; - simplifiedFlatCoordinates.length = ol.geom.simplify.quantizess( + simplifiedFlatCoordinates.length = ol.geom.flat.simplify.quantizess( 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 2fa6eebae5..3507cc5152 100644 --- a/src/ol/geom/polygon.js +++ b/src/ol/geom/polygon.js @@ -9,7 +9,7 @@ goog.require('ol.geom.Point'); goog.require('ol.geom.SimpleGeometry'); goog.require('ol.geom.flat'); goog.require('ol.geom.flat.closest'); -goog.require('ol.geom.simplify'); +goog.require('ol.geom.flat.simplify'); @@ -243,7 +243,7 @@ ol.geom.Polygon.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) { var simplifiedFlatCoordinates = []; var simplifiedEnds = []; - simplifiedFlatCoordinates.length = ol.geom.simplify.quantizes( + simplifiedFlatCoordinates.length = ol.geom.flat.simplify.quantizes( this.flatCoordinates, 0, this.ends_, this.stride, Math.sqrt(squaredTolerance), simplifiedFlatCoordinates, 0, simplifiedEnds); diff --git a/src/ol/render/canvas/canvasreplay.js b/src/ol/render/canvas/canvasreplay.js index 5f89a901cb..594b7b3c21 100644 --- a/src/ol/render/canvas/canvasreplay.js +++ b/src/ol/render/canvas/canvasreplay.js @@ -17,7 +17,7 @@ goog.require('ol.color'); goog.require('ol.extent'); goog.require('ol.extent.Relationship'); goog.require('ol.geom.flat'); -goog.require('ol.geom.simplify'); +goog.require('ol.geom.flat.simplify'); goog.require('ol.render.IReplayGroup'); goog.require('ol.render.IVectorContext'); goog.require('ol.render.canvas'); @@ -1310,7 +1310,7 @@ ol.render.canvas.PolygonReplay.prototype.finish = function() { var coordinates = this.coordinates; var i, ii; for (i = 0, ii = coordinates.length; i < ii; ++i) { - coordinates[i] = ol.geom.simplify.snap(coordinates[i], tolerance); + coordinates[i] = ol.geom.flat.simplify.snap(coordinates[i], tolerance); } } }; diff --git a/test/spec/ol/geom/simplifygeom.test.js b/test/spec/ol/geom/flat/simplifyflatgeom.test.js similarity index 83% rename from test/spec/ol/geom/simplifygeom.test.js rename to test/spec/ol/geom/flat/simplifyflatgeom.test.js index a59f128304..c18029a5c4 100644 --- a/test/spec/ol/geom/simplifygeom.test.js +++ b/test/spec/ol/geom/flat/simplifyflatgeom.test.js @@ -1,7 +1,7 @@ goog.provide('ol.test.geom.simplify'); -describe('ol.geom.simplify', function() { +describe('ol.geom.flat.simplify', function() { var flatCoordinates = [ 224.55, 250.15, 226.91, 244.19, 233.31, 241.45, 234.98, 236.06, @@ -81,31 +81,31 @@ describe('ol.geom.simplify', function() { 866.36, 480.77 ]; - describe('ol.geom.simplify.lineString', function() { + describe('ol.geom.flat.simplify.lineString', function() { it('works with empty line strings', function() { - expect(ol.geom.simplify.lineString([], 0, 0, 2, 1, true)).to. + expect(ol.geom.flat.simplify.lineString([], 0, 0, 2, 1, true)).to. eql([]); - expect(ol.geom.simplify.lineString([], 0, 0, 2, 1, false)).to. + expect(ol.geom.flat.simplify.lineString([], 0, 0, 2, 1, false)).to. eql([]); }); it('works with a line string with a single point', function() { - expect(ol.geom.simplify.lineString([1, 2], 0, 2, 2, 1, true)).to. + expect(ol.geom.flat.simplify.lineString([1, 2], 0, 2, 2, 1, true)).to. eql([1, 2]); - expect(ol.geom.simplify.lineString([1, 2], 0, 2, 2, 1, false)).to. + expect(ol.geom.flat.simplify.lineString([1, 2], 0, 2, 2, 1, false)).to. eql([1, 2]); }); it('returns the expected result with low quality', function() { - var result = ol.geom.simplify.lineString( + var result = ol.geom.flat.simplify.lineString( 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() { - var result = ol.geom.simplify.lineString( + var result = ol.geom.flat.simplify.lineString( flatCoordinates, 0, flatCoordinates.length, 2, 25, true); expect(result.length).to.be(simplifiedHighQualityFlatCoordinates.length); expect(result).to.eql(simplifiedHighQualityFlatCoordinates); @@ -113,7 +113,7 @@ describe('ol.geom.simplify', function() { }); - describe('ol.geom.simplify.radialDistance', function() { + describe('ol.geom.flat.simplify.radialDistance', function() { var dest; beforeEach(function() { @@ -121,63 +121,63 @@ describe('ol.geom.simplify', function() { }); it('works with empty line strings', function() { - expect(ol.geom.simplify.radialDistance( + expect(ol.geom.flat.simplify.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.simplify.radialDistance( + expect(ol.geom.flat.simplify.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.simplify.radialDistance( + expect(ol.geom.flat.simplify.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.simplify.radialDistance( + expect(ol.geom.flat.simplify.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.simplify.radialDistance( + expect(ol.geom.flat.simplify.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.simplify.radialDistance( + expect(ol.geom.flat.simplify.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.simplify.radialDistance( + expect(ol.geom.flat.simplify.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.simplify.radialDistance( + expect(ol.geom.flat.simplify.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.simplify.radialDistance( + expect(ol.geom.flat.simplify.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.simplify.radialDistance( + expect(ol.geom.flat.simplify.radialDistance( flatCoordinates, 0, flatCoordinates.length, 2, 25, dest, 0)). to.be(simplifiedRadiallyFlatCoordinates.length); expect(dest).to.eql(simplifiedRadiallyFlatCoordinates); @@ -185,7 +185,7 @@ describe('ol.geom.simplify', function() { }); - describe('ol.geom.simplify.douglasPeucker', function() { + describe('ol.geom.flat.simplify.douglasPeucker', function() { var dest; beforeEach(function() { @@ -193,93 +193,93 @@ describe('ol.geom.simplify', function() { }); it('works with empty line strings', function() { - expect(ol.geom.simplify.douglasPeucker( + expect(ol.geom.flat.simplify.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.simplify.douglasPeucker( + expect(ol.geom.flat.simplify.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.simplify.douglasPeucker( + expect(ol.geom.flat.simplify.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.simplify.douglasPeucker( + expect(ol.geom.flat.simplify.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.simplify.douglasPeucker( + expect(ol.geom.flat.simplify.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.simplify.douglasPeucker( + expect(ol.geom.flat.simplify.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.simplify.douglasPeucker( + expect(ol.geom.flat.simplify.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.simplify.douglasPeucker( + expect(ol.geom.flat.simplify.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.simplify.douglasPeucker( + expect(ol.geom.flat.simplify.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.simplify.douglasPeucker( + expect(ol.geom.flat.simplify.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.simplify.douglasPeucker( + expect(ol.geom.flat.simplify.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.simplify.douglasPeucker( + expect(ol.geom.flat.simplify.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.simplify.douglasPeucker( + expect(ol.geom.flat.simplify.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.simplify.douglasPeucker( + expect(ol.geom.flat.simplify.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.simplify.douglasPeucker( + expect(ol.geom.flat.simplify.douglasPeucker( flatCoordinates, 0, flatCoordinates.length, 2, 25, dest, 0)). to.be(simplifiedHighQualityFlatCoordinates.length); expect(dest).to.eql(simplifiedHighQualityFlatCoordinates); @@ -287,32 +287,32 @@ describe('ol.geom.simplify', function() { }); - describe('ol.geom.simplify.quantize', function() { + describe('ol.geom.flat.simplify.quantize', function() { it('handles empty coordinates', function() { var simplifiedFlatCoordinates = []; - expect(ol.geom.simplify.quantize( + expect(ol.geom.flat.simplify.quantize( [], 0, 0, 2, 2, simplifiedFlatCoordinates, 0)).to.be(0); expect(simplifiedFlatCoordinates).to.be.empty(); }); it('expands points to a zero-length line', function() { var simplifiedFlatCoordinates = []; - expect(ol.geom.simplify.quantize( + expect(ol.geom.flat.simplify.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() { var simplifiedFlatCoordinates = []; - expect(ol.geom.simplify.quantize( + expect(ol.geom.flat.simplify.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() { var simplifiedFlatCoordinates = []; - expect(ol.geom.simplify.quantize( + expect(ol.geom.flat.simplify.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.simplify', function() { it('eliminates horizontal colinear points', function() { var simplifiedFlatCoordinates = []; - expect(ol.geom.simplify.quantize( + expect(ol.geom.flat.simplify.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.simplify', function() { it('eliminates vertical colinear points', function() { var simplifiedFlatCoordinates = []; - expect(ol.geom.simplify.quantize( + expect(ol.geom.flat.simplify.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.simplify', function() { it('eliminates diagonal colinear points', function() { var simplifiedFlatCoordinates = []; - expect(ol.geom.simplify.quantize( + expect(ol.geom.flat.simplify.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.simplify', function() { it('handles switchbacks', function() { var simplifiedFlatCoordinates = []; - expect(ol.geom.simplify.quantize( + expect(ol.geom.flat.simplify.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]); @@ -355,4 +355,5 @@ describe('ol.geom.simplify', function() { }); -goog.require('ol.geom.simplify'); +goog.require('ol.geom.flat'); +goog.require('ol.geom.flat.simplify');