Add point module
The point module defines a Point class, that displays a Point in a two-dimensional coordinate system. An object of the class contains a x- and y-coordinate and a setter and getter method for each at this point.
This commit is contained in:
32
point.py
Normal file
32
point.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
"""The Point Module defines a Point class"""
|
||||||
|
|
||||||
|
class Point():
|
||||||
|
"""The Point class handles a single two-dimensional point in the coordinate system"""
|
||||||
|
def __init__(self, x=0, y=0):
|
||||||
|
self.set_x(x)
|
||||||
|
self.set_y(y)
|
||||||
|
def set_x(self, new_x):
|
||||||
|
"""Set the X-Coordinate of the Point"""
|
||||||
|
if int == type(new_x):
|
||||||
|
self.__x = new_x
|
||||||
|
elif float == type(new_x):
|
||||||
|
self.__x = int(new_x)
|
||||||
|
else:
|
||||||
|
raise Exception(self, "Type of x has to be int")
|
||||||
|
def get_x(self):
|
||||||
|
"""Returns the X-Coordinate of the Point"""
|
||||||
|
return self.__x
|
||||||
|
def set_y(self, new_y):
|
||||||
|
"""Set the Y-Coordinate of the Point"""
|
||||||
|
if int == type(new_y):
|
||||||
|
self.__y = new_y
|
||||||
|
elif float == type(new_y):
|
||||||
|
self.__x = int(new_y)
|
||||||
|
else:
|
||||||
|
raise Exception(self, "Type of y has to be int")
|
||||||
|
def get_y(self):
|
||||||
|
"""Returns the Y-Coordinate of the Point"""
|
||||||
|
return self.__y
|
||||||
|
def draw(self):
|
||||||
|
"""TODO: Draw the point in a canvas"""
|
||||||
Reference in New Issue
Block a user