parent
ff64e1a3ff
commit
1e9365d52c
68
point.py
68
point.py
|
@ -1,68 +0,0 @@
|
||||||
LOGICAL = "logical"
|
|
||||||
PHYSICAL = "physical"
|
|
||||||
|
|
||||||
|
|
||||||
class Point:
|
|
||||||
def __init__(self, x=0, y=0, t=None):
|
|
||||||
raise Exception, "argh!"
|
|
||||||
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)
|
|
Loading…
Reference in New Issue