2007-03-06 10:05:38 -05:00
|
|
|
LOGICAL = "logical"
|
|
|
|
PHYSICAL = "physical"
|
|
|
|
|
2007-06-05 00:49:24 -04:00
|
|
|
|
2007-03-06 10:05:38 -05:00
|
|
|
class Point:
|
|
|
|
def __init__(self, x=0, y=0, t=None):
|
2007-06-05 00:49:24 -04:00
|
|
|
raise Exception, "argh!"
|
2007-03-06 10:05:38 -05:00
|
|
|
assert t is None or \
|
|
|
|
t == LOGICAL or \
|
|
|
|
t == PHYSICAL
|
|
|
|
self.x = x
|
|
|
|
self.y = y
|
|
|
|
self.type = t
|
|
|
|
|
|
|
|
def offset(self, x, y, t=None):
|
|
|
|
return Point(self.x + x, self.y + y, t)
|
|
|
|
|
|
|
|
def copy(self):
|
|
|
|
return Point(self.x, self.y, self.type)
|
|
|
|
|
|
|
|
def __cmp__(self, other):
|
|
|
|
assert self.type == other.type or \
|
|
|
|
self.type is None or \
|
|
|
|
other.type is None
|
|
|
|
c = cmp(self.y, other.y)
|
|
|
|
if c == 0:
|
|
|
|
return cmp(self.x, other.x)
|
|
|
|
else:
|
|
|
|
return c
|
|
|
|
|
|
|
|
def __add__(self, other):
|
|
|
|
assert self.type == other.type or \
|
|
|
|
self.type is None or \
|
|
|
|
other.type is None
|
|
|
|
return Point(self.x + other.x,
|
|
|
|
self.y + other.y)
|
|
|
|
def __iadd__(self, other):
|
|
|
|
assert self.type == other.type or \
|
|
|
|
self.type is None or \
|
|
|
|
other.type is None
|
|
|
|
x = other.x
|
|
|
|
y = other.y
|
|
|
|
self.x += x
|
|
|
|
self.y += y
|
|
|
|
|
|
|
|
def __sub__(self, other):
|
|
|
|
assert self.type == other.type or \
|
|
|
|
self.type is None or \
|
|
|
|
other.type is None
|
|
|
|
return Point(self.x - other.x,
|
|
|
|
self.y - other.y)
|
|
|
|
def __isub__(self, other):
|
|
|
|
assert self.type == other.type or \
|
|
|
|
self.type is None or \
|
|
|
|
other.type is None
|
|
|
|
x = other.x
|
|
|
|
y = other.y
|
|
|
|
self.x -= x
|
|
|
|
self.y -= y
|
|
|
|
|
|
|
|
def __abs__(self):
|
|
|
|
return Point(abs(self.x), abs(self.y))
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
if self.type is None:
|
|
|
|
return "Point(%d, %d)" % (self.x, self.y)
|
|
|
|
else:
|
|
|
|
return "Point(%s:%d, %d)" % (self.type[0], self.x, self.y)
|