From dbccb8b23170ca19c415a1e1058c722afb94322f Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Tue, 3 Sep 2013 17:38:10 -0600 Subject: [PATCH] Function for cloning extents --- src/ol/extent.js | 11 +++++++++++ test/spec/ol/extent.test.js | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/ol/extent.js b/src/ol/extent.js index 7dad3efbd7..b1309b5ff8 100644 --- a/src/ol/extent.js +++ b/src/ol/extent.js @@ -48,6 +48,17 @@ ol.extent.boundingExtentXYs_ = function(xs, ys, opt_extent) { }; +/** + * Creates a clone of an extent. + * + * @param {ol.Extent} extent Extent to clone. + * @return {ol.Extent} The clone. + */ +ol.extent.clone = function(extent) { + return [[extent[0][0], extent[0][1]], [extent[1][0], extent[1][1]]]; +}; + + /** * Checks if the passed coordinate is contained or on the edge of the extent. * diff --git a/test/spec/ol/extent.test.js b/test/spec/ol/extent.test.js index 6f8a5b3875..efb0368e1e 100644 --- a/test/spec/ol/extent.test.js +++ b/test/spec/ol/extent.test.js @@ -3,6 +3,19 @@ goog.provide('ol.test.extent'); describe('ol.extent', function() { + describe('clone', function() { + + it('creates a copy of an extent', function() { + var extent = ol.extent.createOrUpdate(1, 2, 3, 4); + var clone = ol.extent.clone(extent); + expect(ol.extent.equals(extent, clone)).to.be(true); + + ol.extent.extendCoordinate(extent, [10, 20]); + expect(ol.extent.equals(extent, clone)).to.be(false); + }); + + }); + describe('containsCoordinate', function() { describe('positive', function() {