X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/10466a9c920f1d67bf85d85af671bcb8e5fbd533..577a280086d400b3ab83caed89424b6f5e064be9:/manual.py?ds=sidebyside diff --git a/manual.py b/manual.py index e60a848..cecca75 100644 --- a/manual.py +++ b/manual.py @@ -1,7 +1,7 @@ """Manual grid selection module""" import pygame -import Image, ImageDraw +import ImageDraw from math import atan, sin, cos, pi, sqrt, acos, copysign class UserQuitError(Exception): @@ -14,8 +14,8 @@ class Screen: pygame.display.set_caption("Imago manual mode") self._screen = pygame.display.get_surface() - def display_picture(self, im): - pg_img = pygame.image.frombuffer(im.tostring(), im.size, im.mode) + def display_picture(self, img): + pg_img = pygame.image.frombuffer(img.tostring(), img.size, img.mode) self._screen.blit(pg_img, (0,0)) pygame.display.flip() @@ -31,7 +31,7 @@ def find_lines(im_orig): hoshi = lambda c: draw.ellipse((c[0] - 1, c[1] - 1, c[0] + 1, c[1] + 1), fill=(255, 64, 64)) corners = [] - color=(64, 64, 255) + color = (64, 64, 255) line_width = 1 lines_r = [] @@ -77,7 +77,7 @@ def lines(corners): corners[1:]] cor_d = [(float(a[0] * b[0] + a[1] * b[1]) / (sqrt(a[0] ** 2 + a[1] ** 2) * sqrt(b[0] **2 + b[1] ** 2)), a[0] * b[1] - b[0] * a[1], c) for a, b, c in cor_d] - cor_d = sorted([(copysign(acos(a), b), c) for a, b, c in cor_d]) + cor_d = sorted([(copysign(acos(min(a, 1)), b), c) for a, b, c in cor_d]) corners = [corners[0]] + [c for _, c in cor_d] return (_lines(corners, 0) + [(corners[0], corners[3]), (corners[1], corners[2])], @@ -94,8 +94,8 @@ def _lines(corners, n): c = intersection(line(x[0], corners[2]), line(corners[1], corners[3])) d = intersection(line(corners[0], corners[3]), line(corners[1], corners[2])) if d: - l = (intersection(line(corners[0], corners[1]), line(c,d)), - intersection(line(corners[2], corners[3]), line(c,d))) + l = (intersection(line(corners[0], corners[1]), line(c, d)), + intersection(line(corners[2], corners[3]), line(c, d))) else: lx = line(c, (c[0] + corners[0][0] - corners[3][0], c[1] + corners[0][1] - corners[3][1]))