From 450f7b046053949e373b48084401a4654f8804fe Mon Sep 17 00:00:00 2001 From: euzuro Date: Tue, 6 Jun 2006 16:52:45 +0000 Subject: [PATCH] add a static function to make a Bounds from a Size. test included. git-svn-id: http://svn.openlayers.org/trunk/openlayers@531 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Util.js | 17 +++++++++++++++++ tests/test_Bounds.html | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 9102a2916e..f7f1211e0a 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -490,6 +490,23 @@ OpenLayers.Bounds.fromArray = function(bbox) { parseFloat(bbox[3])); }; +/** Alternative constructor that builds a new OpenLayers.Bounds +* from an OpenLayers.Size +* +* @constructor +* +* @param {OpenLayers.Size} size +* +* @returns New OpenLayers.Bounds object built with top and left set to 0 and +* bottom right taken from the passed-in OpenLayers.Size. +* @type OpenLayers.Bounds +*/ +OpenLayers.Bounds.fromSize = function(size) { + return new OpenLayers.Bounds(0, + size.h, + size.w, + 0); +}; /** * @param {String} quadrant * diff --git a/tests/test_Bounds.html b/tests/test_Bounds.html index 0fcde05593..08874a0a6a 100644 --- a/tests/test_Bounds.html +++ b/tests/test_Bounds.html @@ -209,6 +209,20 @@ t.eq( bounds.top, 4, "bounds.top is set correctly" ); } + function test_14_Bounds_fromSize(t) { + t.plan( 5 ); + + var height = 15; + var width = 16; + var size = new OpenLayers.Size(width, height); + bounds = OpenLayers.Bounds.fromSize(size); + t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" ); + t.eq( bounds.left, 0, "bounds.left is set correctly" ); + t.eq( bounds.bottom, height, "bounds.bottom is set correctly" ); + t.eq( bounds.right, width, "bounds.right is set correctly" ); + t.eq( bounds.top, 0, "bounds.top is set correctly" ); + } + // -->