From 0845dea366a7ee38e2a454a37706fb6f96405e2e Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 23 Jan 2013 22:03:08 -0700 Subject: [PATCH 1/3] Care with transform Since the transform method takes an arbitrary transform function, new coordinates may not be ordered in the same way as the originals. --- src/ol/extent.js | 7 ++++--- test/spec/ol/extent.test.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/ol/extent.js b/src/ol/extent.js index 1cbeb217ea..3d0ab215d6 100644 --- a/src/ol/extent.js +++ b/src/ol/extent.js @@ -94,7 +94,8 @@ ol.Extent.prototype.getTopRight = function() { * @return {ol.Extent} Extent. */ ol.Extent.prototype.transform = function(transformFn) { - var min = transformFn(new ol.Coordinate(this.minX, this.minY)); - var max = transformFn(new ol.Coordinate(this.maxX, this.maxY)); - return new ol.Extent(min.x, min.y, max.x, max.y); + var a = transformFn(new ol.Coordinate(this.minX, this.minY)); + var b = transformFn(new ol.Coordinate(this.maxX, this.maxY)); + return new ol.Extent(Math.min(a.x, b.x), Math.min(a.y, b.y), + Math.max(a.x, b.x), Math.max(a.y, b.y)); }; diff --git a/test/spec/ol/extent.test.js b/test/spec/ol/extent.test.js index 8763aaf0d3..4d80e64f03 100644 --- a/test/spec/ol/extent.test.js +++ b/test/spec/ol/extent.test.js @@ -55,6 +55,23 @@ describe('ol.Extent', function() { expect(destinationExtent.maxX).toRoughlyEqual(5009377.085697311, 1e-9); expect(destinationExtent.maxY).toRoughlyEqual(8399737.889818361, 1e-9); }); + + it('takes arbitrary function', function() { + var transformFn = function(coordinate) { + return new ol.Coordinate(-coordinate.x, -coordinate.y); + } + var sourceExtent = new ol.Extent(-15, -30, 45, 60); + var destinationExtent = sourceExtent.transform(transformFn); + expect(destinationExtent).not.toBeUndefined(); + expect(destinationExtent).not.toBeNull(); + // FIXME check values with third-party tool + expect(destinationExtent.minX).toBe(-45); + expect(destinationExtent.minY).toBe(-60); + expect(destinationExtent.maxX).toBe(15); + expect(destinationExtent.maxY).toBe(30); + }); + + }); }); From afb9add911a590672717e823f5f432de978f0fbe Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 23 Jan 2013 22:12:17 -0700 Subject: [PATCH 2/3] Checked with third-party tool --- test/spec/ol/extent.test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/spec/ol/extent.test.js b/test/spec/ol/extent.test.js index 4d80e64f03..83e20e15e6 100644 --- a/test/spec/ol/extent.test.js +++ b/test/spec/ol/extent.test.js @@ -64,14 +64,12 @@ describe('ol.Extent', function() { var destinationExtent = sourceExtent.transform(transformFn); expect(destinationExtent).not.toBeUndefined(); expect(destinationExtent).not.toBeNull(); - // FIXME check values with third-party tool expect(destinationExtent.minX).toBe(-45); expect(destinationExtent.minY).toBe(-60); expect(destinationExtent.maxX).toBe(15); expect(destinationExtent.maxY).toBe(30); }); - }); }); From 3ccfaebcfc7ded68f3a9ba96db36de95af24e87d Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 23 Jan 2013 22:18:00 -0700 Subject: [PATCH 3/3] Punctuated --- test/spec/ol/extent.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/ol/extent.test.js b/test/spec/ol/extent.test.js index 83e20e15e6..d1312fad3c 100644 --- a/test/spec/ol/extent.test.js +++ b/test/spec/ol/extent.test.js @@ -59,7 +59,7 @@ describe('ol.Extent', function() { it('takes arbitrary function', function() { var transformFn = function(coordinate) { return new ol.Coordinate(-coordinate.x, -coordinate.y); - } + }; var sourceExtent = new ol.Extent(-15, -30, 45, 60); var destinationExtent = sourceExtent.transform(transformFn); expect(destinationExtent).not.toBeUndefined();