From: Tomas Musil Date: Sat, 25 Aug 2012 16:19:48 +0000 (+0200) Subject: index error in stone_color fixed X-Git-Url: http://git.tomasm.cz/imago.git/commitdiff_plain/2644b4adc0fd0a5c7e8b726c79705f283e37d43f index error in stone_color fixed --- diff --git a/imago.py b/imago.py index cf04f53..3c4ca56 100755 --- 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