Add __getitem__ and __setitem__ for linesegment
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user