Make Point unpackable

This commit is contained in:
Felix Bargfeldt 2019-01-19 17:18:37 +01:00
parent 2c505fae97
commit e92a90976c
No known key found for this signature in database
GPG key ID: 99184F5FDC589A67
2 changed files with 5 additions and 1 deletions

View file

@ -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__':

View file

@ -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)