X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/3a843a5f148dd7728130b33ef406c0de08cb4dcc..e3efa906f4d1c8203c88b5129cfa63598dbf3476:/manual.py?ds=inline diff --git a/manual.py b/manual.py index cecca75..467882e 100644 --- a/manual.py +++ b/manual.py @@ -2,7 +2,8 @@ import pygame import ImageDraw -from math import atan, sin, cos, pi, sqrt, acos, copysign +from math import sqrt, acos, copysign +from geometry import l2ad, line, intersection class UserQuitError(Exception): pass @@ -126,31 +127,3 @@ def half_line(corners): def center(corners): return intersection(line(corners[0], corners[2]), line(corners[1], corners[3])) -def line(x, y): - a = x[1] - y[1] - b = y[0] - x[0] - c = a * y[0] + b * y[1] - return (a, b, c) - -def intersection(p, q): - det = p[0] * q[1] - p[1] * q[0] - if det == 0: - return None - return (int(round(float(q[1] * p[2] - p[1] * q[2]) / det)), - int(round(float(p[0] * q[2] - q[0] * p[2]) / det))) - -def l2ad((a, b), size): - if (a[0] - b[0]) == 0: - angle = pi / 2 - else: - q = float(a[1] - b[1]) / (a[0] - b[0]) - angle = atan(q) - - if angle < 0: - angle += pi - if angle > pi: - angle -= pi - - distance = (((a[0] - (size[0] / 2)) * sin(angle)) + - ((a[1] - (size[1] / 2)) * - cos(angle))) - return (angle, distance)