"""Manual grid selection module"""
-import pygame
import ImageDraw
from math import sqrt, acos, copysign
def find_lines(im_orig):
# TODO rename, refactor, comment
+ import pygame
im = im_orig.copy()
def lines(corners):
# TODO Error on triangle
+ corners.sort() # TODO does this help?
+ # TODO refactor this vvv
cor_d = [(corners[0], (c[0] - corners[0][0], c[1] - corners[0][1]), c) for c in
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(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])],
+ return (_lines(corners, 0) +
+ [(corners[0], corners[3]), (corners[1], corners[2])],
_lines(corners[1:4] + [corners[0]], 0) +
[(corners[0], corners[1]), (corners[2], corners[3])])
# TODO what is this?
if n == 0:
x = half_line(corners)
- return (_lines([corners[0], x[0], x[1], corners[3]], n + 1) + [x] +
- _lines([x[0], corners[1], corners[2], x[1]], n + 1))
+ return (_lines([corners[0], x[0], x[1], corners[3]], 1) + [x] +
+ _lines([x[0], corners[1], corners[2], x[1]], 1))
else:
x = half_line(corners)
c = intersection(line(x[0], corners[2]), line(corners[1], corners[3]))