X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/3fa492032fb6f72fc8d153c0d11ad61155e8c1b9..f16fe1e775f2159741146264a6494e63b0e2d618:/intrsc.py?ds=sidebyside diff --git a/intrsc.py b/intrsc.py index 564faaa..00165b1 100644 --- a/intrsc.py +++ b/intrsc.py @@ -1,7 +1,7 @@ -from math import sin, cos, tan +from math import cos, tan from operator import itemgetter -import Image, ImageDraw +import ImageDraw def board(image, lines, show_all, do_something): intersections = intersections_from_angl_dist(lines, image.size) @@ -14,22 +14,23 @@ def board(image, lines, show_all, do_something): if show_all: do_something(image_g, "intersections") - board = [] + board_r = [] for line in intersections: - board.append([stone_color(image, intersection) for intersection in + board_r.append([stone_color(image, intersection) for intersection in line]) - return board + return board_r -def intersections_from_angl_dist(lines, size): +def intersections_from_angl_dist(lines, size, get_all=False): intersections = [] for (angl1, dist1) in sorted(lines[1], key=itemgetter(1)): line = [] for (angl2, dist2) in sorted(lines[0], key=itemgetter(1)): if abs(angl1 - angl2) > 0.4: - x = - ((dist2 / cos(angl2)) - (dist1 / cos(angl1))) / (tan(angl1) - tan(angl2)) + x = (- ((dist2 / cos(angl2)) - (dist1 / cos(angl1))) + / (tan(angl1) - tan(angl2))) y = (tan(angl1) * x) - (dist1 / cos(angl1)) - if (-size[0] / 2 < x < size[0] / 2 and + if get_all or (-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)