index error in stone_color fixed
authorTomas Musil <tomik.musil@gmail.com>
Sat, 25 Aug 2012 16:19:48 +0000 (18:19 +0200)
committerTomas Musil <tomik.musil@gmail.com>
Sat, 25 Aug 2012 16:19:48 +0000 (18:19 +0200)
imago.py

index cf04f53..3c4ca56 100755 (executable)
--- a/imago.py
+++ b/imago.py
@@ -167,7 +167,10 @@ def stone_color(image, (x, y)):
     suma = 0.
     for i in range(-2, 3):
         for j in range(-2, 3):
-            suma += sum(image.getpixel((x + i, y + j)))
+            try:
+                suma += sum(image.getpixel((x + i, y + j)))
+            except IndexError:
+                pass
     suma /= 3 * 25
     if suma < 55:
         return 'B'
@@ -212,7 +215,9 @@ def intersections_from_angl_dist(lines, size):
             if abs(angl1 - angl2) > 0.4:
                 x =  - ((dist2 / math.cos(angl2))-(dist1 / math.cos(angl1))) / (math.tan(angl1) - math.tan(angl2))
                 y = (math.tan(angl1) * x) - (dist1 / math.cos(angl1))
-                line.append((int(x + size[0] / 2), int(y + size[1] / 2)))
+                if (-size[0] / 2 < x < size[0] / 2 and 
+                    -size[1] / 2 < y < size[1] / 2):
+                    line.append((int(x + size[0] / 2), int(y + size[1] / 2)))
         intersections.append(line)
     return intersections