Mercurial > traipse
annotate orpg/mapper/map_utils.py @ 20:39ebe168ceb3 ornery-orc
Traipse 'OpenRPG' {090827-02}
Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc''s main goal is to offer more advanced features and enhance the productivity of the user.
Update Summary:
Update Manager is now in version 0.8. While not every button works, users can now browse the different revisions and their different changesets. The code has been refined some with feature from Core added to it. A Crash report is now created if the users software crashes. Update Manager has been moved to the Traipse Suite menu item, and a Debug Console as been added as well.
Please Check the Controls Panel to see the other files changed.
author | sirebral |
---|---|
date | Thu, 27 Aug 2009 01:11:22 -0500 |
parents | 97265586402b |
children |
rev | line source |
---|---|
18 | 1 """ |
2 file: map_utils.py | |
3 | |
4 This file contains generic utility functions | |
5 for use in the openrpg mapping system | |
6 """ | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
7 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
8 import math |
18 | 9 """ |
10 distance_between() | |
11 Returns the distance between two points | |
12 """ | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
13 def distance_between( x1, y1, x2, y2 ): |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
14 "Returns the distance between two points" |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
15 dx = x2 - x1 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
16 dy = y2 - y1 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
17 return math.sqrt( dx*dx + dy*dy ) |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
18 |
18 | 19 """ |
20 proximity_test() | |
21 Tests if 'test_point' (T) is close (within 'threshold' units) to the | |
22 line segment 'start_point' to 'end_point' (PQ). | |
23 | |
24 The closest point (R) to T on the line PQ is given by: | |
25 R = P + u (Q - P) | |
26 TR is perpendicular to PQ so: | |
27 (T - R) dot (Q - P) = 0 | |
28 Solving these two equations gives the equation for u (see below). | |
29 | |
30 If u < 0 or u > 1 then R is not within the line segment and we simply | |
31 test against point P or Q. | |
32 """ | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
33 def proximity_test( start_point, end_point, test_point, threshold ): |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
34 "Test if a point is close to a line segment" |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
35 x1,y1 = start_point |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
36 x2,y2 = end_point |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
37 xt,yt = test_point |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
38 x1 = float(x1) |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
39 x2 = float(x2) |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
40 y1 = float(y1) |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
41 y2 = float(y2) |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
42 xt = float(xt) |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
43 yt = float(yt) |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
44 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
45 # Coincident points? |
13
211ac836b6a0
{090731-00} Fixes problem with Name & Settings window, cleans code.
sirebral
parents:
0
diff
changeset
|
46 if x1 == x2 and y1 == y2: d = distance_between(xt, yt, x1, y1) |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
47 else: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
48 dx = x2 - x1 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
49 dy = y2 - y1 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
50 u = ((xt - x1) * dx + (yt - y1) * dy) / (dx*dx + dy*dy) |
13
211ac836b6a0
{090731-00} Fixes problem with Name & Settings window, cleans code.
sirebral
parents:
0
diff
changeset
|
51 if u < 0: d = distance_between(xt, yt, x1, y1) |
211ac836b6a0
{090731-00} Fixes problem with Name & Settings window, cleans code.
sirebral
parents:
0
diff
changeset
|
52 elif u > 1: d = distance_between(xt, yt, x2, y2) |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
53 else: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
54 xr = x1 + u * dx |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
55 yr = y1 + u * dy |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
56 d = distance_between(xt, yt, xr, yr) |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
57 return d <= threshold |