[GRASS-SVN] r55656 - in grass-addons/grass7/raster/r.agent: libagent tests

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Apr 8 05:54:15 PDT 2013


Author: mic
Date: 2013-04-08 05:54:15 -0700 (Mon, 08 Apr 2013)
New Revision: 55656

Modified:
   grass-addons/grass7/raster/r.agent/libagent/playground.py
   grass-addons/grass7/raster/r.agent/tests/test_playground.py
Log:
adding string coordinate converter

Modified: grass-addons/grass7/raster/r.agent/libagent/playground.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/playground.py	2013-04-08 09:27:09 UTC (rev 55655)
+++ grass-addons/grass7/raster/r.agent/libagent/playground.py	2013-04-08 12:54:15 UTC (rev 55656)
@@ -23,6 +23,25 @@
         self.region = dict()
         self.setregion(1,1)
 
+    def stringcoordinate(self, x, y):
+        """
+        Convert string coordinates to float coordinates.
+        @param x string x coordinate
+        @param y string y coordinate
+        @return position as a list of floats
+        """
+        try:
+            # try to convert the string value to a float
+            x = float(x)
+            y = float(y)
+            # also catch 'inf' and 'nan' ..
+            if ( x == x ) and ( y == y ) and ( x + y - 1 != x + y ):
+                return [float(x), float(y)]
+            else:
+                return []
+        except ValueError:
+            return []
+
     def setregion(self, rows, cols):
         """
         Set the geometry of the playground, based only on the number

Modified: grass-addons/grass7/raster/r.agent/tests/test_playground.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_playground.py	2013-04-08 09:27:09 UTC (rev 55655)
+++ grass-addons/grass7/raster/r.agent/tests/test_playground.py	2013-04-08 12:54:15 UTC (rev 55656)
@@ -8,6 +8,11 @@
     def setUp(self):
         self.pg = playground.Playground()
 
+    def test_stringcoordinate(self):
+        self.assertEqual(self.pg.stringcoordinate("foo","bar"), [])
+        self.assertEqual(self.pg.stringcoordinate("inf","nan"), [])
+        self.assertEqual(self.pg.stringcoordinate("2","3"), [2,3])
+
     def test_setregion(self):
         self.assertTrue(self.pg.region["rows"] == 1)
         self.pg.setregion(2,1)



More information about the grass-commit mailing list