Add __getitem__ and __setitem__ for linesegment
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-03-22 18:40:54 +01:00
parent a348c9c035
commit cf004ec5de

View File

@@ -56,6 +56,20 @@ class LineSegment:
def get_max_y(self):
"""Get the highest y coordinate of the line segment"""
return max(self.__startpoint.get_y(), self.__endpoint.get_y())
def __getitem__(self, index):
"""Get an Endpoint by index"""
if index == 0:
return self.__startpoint
elif index == 1:
return self.__endpoint
else:
return None
def __setitem__(self, index, value):
"""Set an Endpoint by index"""
if index == 0:
self.set_startpoint(value)
elif index == 1:
self.set_endpoint(value)
def __str__(self):
"""Return the line segment values as string."""
return str(self.__startpoint) + "-->" + str(self.__endpoint)