1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
class : def __init__(self,p1,p2): self.start = p1 self.end = p2 def __sub__(self,p): if isinstance(p,Point): if p is self.start: return self.end if p is self.end: return self.start class Point: def __init__(self,x,y): self.x = x self.x = x def __add__(self,p): if isinstance(p,Point): return Line(self,p) if __name__ == '__main__': p1 = Point(1,2) p2 = Point(2,3) line = p1 + p2 print l print line - p1
|
近期评论