diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 303d8156e0..93d22f4e59 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -66,6 +66,17 @@ OpenLayers.Pixel.prototype = { return new OpenLayers.Pixel(this.x + x, this.y + y); }, + /** + * @param {OpenLayers.Pixel} px + * + * @return a new Pixel with this pixel's x&y augmented by the + * x&y values of the pixel passed in. + * @type OpenLayers.Pixel + */ + offset:function(px) { + return this.add(px.x, px.y); + }, + /** @final @type str */ CLASS_NAME: "OpenLayers.Pixel" }; diff --git a/tests/test_Pixel.html b/tests/test_Pixel.html index 71a3d4df95..cda6524a10 100644 --- a/tests/test_Pixel.html +++ b/tests/test_Pixel.html @@ -61,6 +61,21 @@ t.eq( pixel.y, 26, "pixel.y is set correctly"); } + function test_08_Pixel_offset(t) { + t.plan( 4 ); + + var oldPixel = new OpenLayers.Pixel(5,6); + var offset = new OpenLayers.Pixel(10,20); + + pixel = oldPixel.offset(offset); + + t.eq( oldPixel.x, 5, "oldPixel.x not modified by offset operation"); + t.eq( oldPixel.y, 6, "oldPixel.y not modified by offset operation"); + + t.eq( pixel.x, 15, "pixel.x is set correctly"); + t.eq( pixel.y, 26, "pixel.y is set correctly"); + } + // -->