Mercurial > traipse_dev
comparison orpg/mapper/map_utils.py @ 20:072ffc1d466f traipse_dev
2nd attempt. Still untested.
author | sirebral |
---|---|
date | Sat, 25 Jul 2009 19:23:25 -0500 |
parents | 4385a7d0efd1 |
children | 449a8900f9ac |
comparison
equal
deleted
inserted
replaced
19:78407d627cba | 20:072ffc1d466f |
---|---|
42 y2 = float(y2) | 42 y2 = float(y2) |
43 xt = float(xt) | 43 xt = float(xt) |
44 yt = float(yt) | 44 yt = float(yt) |
45 | 45 |
46 # Coincident points? | 46 # Coincident points? |
47 if x1 == x2 and y1 == y2: | 47 if x1 == x2 and y1 == y2: d = distance_between(xt, yt, x1, y1) |
48 d = distance_between(xt, yt, x1, y1) | |
49 else: | 48 else: |
50 dx = x2 - x1 | 49 dx = x2 - x1 |
51 dy = y2 - y1 | 50 dy = y2 - y1 |
52 u = ((xt - x1) * dx + (yt - y1) * dy) / (dx*dx + dy*dy) | 51 u = ((xt - x1) * dx + (yt - y1) * dy) / (dx*dx + dy*dy) |
53 if u < 0: | 52 if u < 0: d = distance_between(xt, yt, x1, y1) |
54 d = distance_between(xt, yt, x1, y1) | 53 elif u > 1: d = distance_between(xt, yt, x2, y2) |
55 elif u > 1: | |
56 d = distance_between(xt, yt, x2, y2) | |
57 else: | 54 else: |
58 xr = x1 + u * dx | 55 xr = x1 + u * dx |
59 yr = y1 + u * dy | 56 yr = y1 + u * dy |
60 d = distance_between(xt, yt, xr, yr) | 57 d = distance_between(xt, yt, xr, yr) |
61 return d <= threshold | 58 return d <= threshold |