From 76cd52325d17f76c8ebb6ecb6da3a49f1faa9ba6 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 7 Feb 2018 14:22:07 +0100 Subject: [PATCH 1/2] Fix getIntersection return value when an opt extent is provided The return value was not an empty extent when the extents didn't intersect. --- test/spec/ol/extent.test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/spec/ol/extent.test.js b/test/spec/ol/extent.test.js index 1d83f0d656..e0984eb4b9 100644 --- a/test/spec/ol/extent.test.js +++ b/test/spec/ol/extent.test.js @@ -291,6 +291,20 @@ describe('ol.extent', function() { expect(_ol_extent_.getIntersection(north, west)).to.eql([-180, 0, 0, 90]); expect(_ol_extent_.getIntersection(east, south)).to.eql([0, -90, 180, 0]); }); + + + it('can take an destination extent', function() { + const world = [-180, -90, 180, 90]; + const north = [-180, 0, 180, 90]; + const none = _ol_extent_.createEmpty(); + let tmpExtent = [-180, 45, 180, 90]; + expect(_ol_extent_.getIntersection(world, north, tmpExtent)).to.eql(north); + expect(_ol_extent_.getIntersection(world, none, tmpExtent)).to.eql(none); + + tmpExtent = [-180, -90, 180, 90]; + expect(_ol_extent_.getIntersection(tmpExtent, north, tmpExtent)).to.eql(north); + }); + }); describe('containsCoordinate', function() { From b2d3d142f03cb854dad24b3b9dcce2eddc94cb71 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 7 Feb 2018 14:52:54 +0100 Subject: [PATCH 2/2] Pass destination extent to avoid garbage generation --- src/ol/VectorImageTile.js | 2 +- src/ol/extent.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ol/VectorImageTile.js b/src/ol/VectorImageTile.js index bde4b57c76..6a57370d1e 100644 --- a/src/ol/VectorImageTile.js +++ b/src/ol/VectorImageTile.js @@ -97,7 +97,7 @@ const VectorImageTile = function(tileCoord, state, sourceRevision, format, sourceTileGrid.getTileCoordExtent(sourceTileCoord)); const sourceExtent = sourceTileGrid.getExtent(); if (sourceExtent) { - sharedExtent = getIntersection(sharedExtent, sourceExtent); + sharedExtent = getIntersection(sharedExtent, sourceExtent, sharedExtent); } if (getWidth(sharedExtent) / resolution >= 0.5 && getHeight(sharedExtent) / resolution >= 0.5) { diff --git a/src/ol/extent.js b/src/ol/extent.js index b90eaf9006..53567b6765 100644 --- a/src/ol/extent.js +++ b/src/ol/extent.js @@ -593,6 +593,8 @@ export function getIntersection(extent1, extent2, opt_extent) { } else { intersection[3] = extent2[3]; } + } else { + createOrUpdateEmpty(intersection); } return intersection; }