I have written the following piece of code (which is actually a toy example for a more complex application I have).
We have the class Points, which are basically two lists of equal length containing x et y coordinates of points. We can add a point to a Points object with the add_point method.
Then we have the LayersOfPoints class, which represents several numbered layers of Points. We can add a point to a specific layer with the add_layer_point method.
class Points:
def __init__(self,x_coordinates=(),y_coordinates=()):
if len(x_coordinates)!=len(y_coordinates) : raise ValueError("Each should have both a x and a y coordinate")
self.x_coordinates= x_coordinates
self.y_coordinates= y_coordinates
def add_point(self,x_coordinate,y_coordinate):
self.x_coordinates.append(x_coordinate)
self.y_coordinates.append(y_coordinate)
class LayersOfPoints:
def __init__(self,number_of_layers):
self.number_of_layers= number_of_layers
self.layers = (Points() for l in range(number_of_layers))
def add_layer_point(self,layer,x_coordinate,y_coordinate):
self.layers(layer-1).add_point(x_coordinate,y_coordinate)
layer_of_points = LayersOfPoints(2)
layer_of_points.add_layer_point(1,12,15)
layer_of_points.add_layer_point(2,9,5)
print(layer_of_points.layers(0).x_coordinates,layer_of_points.layers(0).y_coordinates)
print(layer_of_points.layers(1).x_coordinates,layer_of_points.layers(0).y_coordinates)
It returns
(12, 9) (15, 5)
(12, 9) (15, 5)
While to me it should return
(12) (15)
(9) (5)