Make Point unpackable
This commit is contained in:
parent
2c505fae97
commit
e92a90976c
2 changed files with 5 additions and 1 deletions
2
koch.py
2
koch.py
|
@ -59,7 +59,7 @@ class Koch(QWidget):
|
|||
|
||||
curve = self.iterations[self.current_iteration]
|
||||
for p1, p2 in zip(curve[:-1], curve[1:]):
|
||||
qp.drawLine(p1.x, p1.y, p2.x, p2.y)
|
||||
qp.drawLine(*p1, *p2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -17,6 +17,10 @@ class Point:
|
|||
def __repr__(self) -> str:
|
||||
return f"Point(x={self.x}, y={self.y})"
|
||||
|
||||
def __iter__(self):
|
||||
yield self.x
|
||||
yield self.y
|
||||
|
||||
def __add__(self, other):
|
||||
assert isinstance(other, Point)
|
||||
return Point(self.x + other.x, self.y + other.y)
|
||||
|
|
Reference in a new issue