Fix errors in trackplacer's overlap detector.

This commit is contained in:
Eric S. Raymond 2009-04-28 17:56:17 +00:00
parent 75831da950
commit ae4ff983a9
2 changed files with 19 additions and 10 deletions

View file

@ -114,6 +114,7 @@
{OLD_JOURNEY 284 89}
{OLD_JOURNEY 298 83}
{OLD_BATTLE 309 76}
{NEW_JOURNEY 325 65}
{NEW_BATTLE 337 53}
#enddef
@ -134,6 +135,7 @@
{OLD_JOURNEY 284 89}
{OLD_JOURNEY 298 83}
{OLD_BATTLE 309 76}
{OLD_JOURNEY 325 65}
{NEW_BATTLE 337 53}
#enddef
@ -154,6 +156,7 @@
{OLD_JOURNEY 284 89}
{OLD_JOURNEY 298 83}
{OLD_BATTLE 309 76}
{OLD_JOURNEY 325 65}
{OLD_BATTLE 337 53}
{NEW_BATTLE 368 60}
#enddef
@ -175,6 +178,7 @@
{OLD_JOURNEY 284 89}
{OLD_JOURNEY 298 83}
{OLD_BATTLE 309 76}
{OLD_JOURNEY 325 65}
{OLD_BATTLE 337 53}
{NEW_BATTLE 368 60}
#enddef
@ -196,6 +200,7 @@
{OLD_JOURNEY 284 89}
{OLD_JOURNEY 298 83}
{OLD_BATTLE 309 76}
{OLD_JOURNEY 325 65}
{OLD_BATTLE 337 53}
{OLD_BATTLE 368 60}
{NEW_BATTLE 381 30}
@ -218,6 +223,7 @@
{OLD_JOURNEY 284 89}
{OLD_JOURNEY 298 83}
{OLD_BATTLE 309 76}
{OLD_JOURNEY 325 65}
{OLD_BATTLE 337 53}
{OLD_BATTLE 368 60}
{NEW_BATTLE 381 30}
@ -240,6 +246,7 @@
{OLD_JOURNEY 284 89}
{OLD_JOURNEY 298 83}
{OLD_BATTLE 309 76}
{OLD_JOURNEY 325 65}
{OLD_BATTLE 337 53}
{OLD_BATTLE 368 60}
{OLD_BATTLE 381 30}

View file

@ -121,20 +121,22 @@ def distance(x1, y1, x2, y2):
def within(x, y, (l, t, r, d)):
"Is point within specified rectangle?"
if x >= l and x < l + r and y >= t and y < t + d:
if x >= l and x <= l + r - 1 and y >= t and y <= t + d - 1:
return True
return False
def overlaps((x1,y1,x1d,y1d),(x2,y2,x2d,y2d)):
"Do two rectangles overlap?"
return within(x1, y1, (x2, y2, x2, y2d)) or \
within(x1+x1d-1, y1, (x2, y2, x2, y2d)) or \
within(x1, y1+y1d-1, (x2, y2, x2, y2d)) or \
within(x1+x1d-1, y1+y1d+1, (x2, y2, x2, y2d)) or \
within(x2, y2, (x1, y1, x1, y1d)) or \
within(x2+x2d-2, y2, (x1, y1, x1, y1d)) or \
within(x2, y2+y2d-2, (x1, y1, x1, y1d)) or \
within(x2+x2d-2, y2+y2d+2, (x1, y1, x1, y1d))
(x1,y1,x1d,y1d) = p1
(x2,y2,x2d,y2d) = p2
return within(x1, y1, p2) or \
within(x1+x1d, y1, p2) or \
within(x1, y1+y1d, p2) or \
within(x1+x1d, y1+y1d, p2) or \
within(x2, y2, p1) or \
within(x2+x2d, y2, p1) or \
within(x2, y2+y2d, p1) or \
within(x2+x2d, y2+y2d, p1)
class JourneyTracks:
"Represent a set of named journey tracks on a map."
@ -719,7 +721,7 @@ class TracksEditor:
def box(self, (action, x, y)):
"Compute the bounding box for an icon of type ACTION at X, Y."
# Assumers selected and unselected icons are the same size
# Assumes selected and unselected icons are the same size
return self.selected_dictionary[action].bounding_box(x, y)
def snap_to(self, x, y):