From 75f9a6b2e04b6b85125cb2bc811536dea433e204 Mon Sep 17 00:00:00 2001 From: euzuro Date: Fri, 26 May 2006 02:42:58 +0000 Subject: [PATCH] add equals() function to OpenLayers.Bounds. plus test git-svn-id: http://svn.openlayers.org/trunk/openlayers@389 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Util.js | 12 ++++++++++++ tests/test_Bounds.html | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 338fadc9b8..a2f50c3f48 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -267,6 +267,18 @@ OpenLayers.Bounds.prototype = { this.right, this.top); }, + /** + * @param {OpenLayers.Bounds} bounds + * @returns Boolean value indicating whether the passed-in OpenLayers.Bounds + * object has the same left, right, top, bottom components as this + * + * @type bool + */ + equals:function(bounds) { + return ((this.left == bounds.left) && (this.right == bounds.right) && + (this.top == bounds.top) && (this.bottom == bounds.bottom)); + }, + /** * @return String representation of OpenLayers.Bounds object. * (ex."left-bottom=(5,42) right-top=(10,45)") diff --git a/tests/test_Bounds.html b/tests/test_Bounds.html index adb6613a7f..cb02090229 100644 --- a/tests/test_Bounds.html +++ b/tests/test_Bounds.html @@ -163,7 +163,18 @@ t.eq( OpenLayers.Bounds.oppositeQuadrant("tr"), "bl", "OpenLayers.Bounds.oppositeQuadrant returns 'bl' for 'tr'"); t.eq( OpenLayers.Bounds.oppositeQuadrant("bl"), "tr", "OpenLayers.Bounds.oppositeQuadrant returns 'tr' for 'bl'"); t.eq( OpenLayers.Bounds.oppositeQuadrant("br"), "tl", "OpenLayers.Bounds.oppositeQuadrant returns 'tl' for 'br'"); - } + } + + function test_11_Bounds_equals(t) { + t.plan( 2 ); + var boundsA = new OpenLayers.Bounds(1,2,3,4); + var boundsB = new OpenLayers.Bounds(1,2,3,4); + var boundsC = new OpenLayers.Bounds(1,5,3,4); + + t.ok( boundsA.equals(boundsB), "equals() returns true on two equal bounds." ); + t.ok( !boundsA.equals(boundsC), "equals() returns false on two different bounds." ); + } + // -->