[OpenLayers-Commits] r11493 - in sandbox/ahocevar/layercontainer: . lib/OpenLayers/BaseTypes tests/BaseTypes

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Fri Feb 25 08:40:45 EST 2011


Author: ahocevar
Date: 2011-02-25 05:40:44 -0800 (Fri, 25 Feb 2011)
New Revision: 11493

Modified:
   sandbox/ahocevar/layercontainer/
   sandbox/ahocevar/layercontainer/lib/OpenLayers/BaseTypes/Pixel.js
   sandbox/ahocevar/layercontainer/tests/BaseTypes/Pixel.html
Log:
merging from trunk


Property changes on: sandbox/ahocevar/layercontainer
___________________________________________________________________
Modified: svn:mergeinfo
   - /sandbox/roberthl/openlayers:9745-9748
/trunk/openlayers:11266-11374,11376-11383,11385-11397,11400-11413,11415-11446,11448-11486
   + /sandbox/roberthl/openlayers:9745-9748
/trunk/openlayers:11266-11374,11376-11383,11385-11397,11400-11413,11415-11446,11448-11486,11489-11492

Modified: sandbox/ahocevar/layercontainer/lib/OpenLayers/BaseTypes/Pixel.js
===================================================================
--- sandbox/ahocevar/layercontainer/lib/OpenLayers/BaseTypes/Pixel.js	2011-02-25 13:36:33 UTC (rev 11492)
+++ sandbox/ahocevar/layercontainer/lib/OpenLayers/BaseTypes/Pixel.js	2011-02-25 13:40:44 UTC (rev 11493)
@@ -86,6 +86,24 @@
     },
 
     /**
+     * APIMethod: distanceTo
+     * Returns the distance to the pixel point passed in as a parameter.
+     *
+     * Parameters:
+     * px - {<OpenLayers.Pixel>}
+     *
+     * Returns:
+     * {Float} The pixel point passed in as parameter to calculate the
+     *     distance to.
+     */
+    distanceTo:function(px) {
+        return Math.sqrt(
+            Math.pow(this.x - px.x, 2) +
+            Math.pow(this.y - px.y, 2)
+        );
+    },
+
+    /**
      * APIMethod: add
      *
      * Parameters:

Modified: sandbox/ahocevar/layercontainer/tests/BaseTypes/Pixel.html
===================================================================
--- sandbox/ahocevar/layercontainer/tests/BaseTypes/Pixel.html	2011-02-25 13:36:33 UTC (rev 11492)
+++ sandbox/ahocevar/layercontainer/tests/BaseTypes/Pixel.html	2011-02-25 13:40:44 UTC (rev 11493)
@@ -40,11 +40,22 @@
         t.eq( pixel.x, 5, "changing oldPixel.x doesn't change pixel.x");
     }
 
+    function test_Pixel_distanceTo(t) {
+        t.plan( 2 );
+        var px = new OpenLayers.Pixel(0,-2);
+        pixel = new OpenLayers.Pixel(0,0);
+        t.eq( pixel.distanceTo(px), 2, "(0,0) distanceTo (0,-2) = 2");
+
+        px = new OpenLayers.Pixel(-4,6);
+        pixel = new OpenLayers.Pixel(4,6);
+        t.eq( pixel.distanceTo(px), 8, "(4,6) distanceTo (-4,6) = 8");
+    }
+
     function test_Pixel_equals(t) {
         t.plan( 5 );
         pixel = new OpenLayers.Pixel(5,6);
 
-        px = new OpenLayers.Pixel(5,6);
+        var px = new OpenLayers.Pixel(5,6);
         t.eq( pixel.equals(px), true, "(5,6) equals (5,6)");
 
         px = new OpenLayers.Pixel(1,6);



More information about the Commits mailing list