diff --git a/point.py b/point.py index 41f3024..52c5bf7 100644 --- a/point.py +++ b/point.py @@ -31,31 +31,26 @@ class Point(): def get_y(self): """Returns the Y-Coordinate of the Point""" return self.__y - def set_random(self, min_x=0, max_x=100, min_y=0, max_y=100): - """Set the point to a random place inside the boundaries""" - self.set_x(random.randint(min_x, max_x)) - self.set_y(random.randint(min_y, max_y)) - return self def str(self): """Returns the coordinates as a string""" return "(" + str(self.get_x()) + "/" + str(self.get_y()) + ")" def draw(self): """TODO: Draw the point in a canvas""" +def get_random(min_x=0, max_x=100, min_y=0, max_y=100): + """Set the point to a random place inside the boundaries""" + return Point(random.randint(min_x, max_x), random.randint(min_y, max_y)) -def sort_point_set(point_set, sort_by_y=False): +def sort_set(point_set, sort_by_y=False): """Sort a Point set using merge sort""" num_compares = 0 - for pnt in point_set: - if not isinstance(pnt, Point): - raise Exception("Elements of point set are not all of type point.Point") if len(point_set) > 1: mid = len(point_set)//2 #Finding the mid of the array left = copy.deepcopy(point_set[:mid]) # Dividing the array elements right = copy.deepcopy(point_set[mid:]) # into 2 halves - num_compares += sort_point_set(left, sort_by_y) # Sorting the first half - num_compares += sort_point_set(right, sort_by_y) # Sorting the second half + num_compares += sort_set(left, sort_by_y) # Sorting the first half + num_compares += sort_set(right, sort_by_y) # Sorting the second half i = j = k = 0