# Path: convexhull/grahamscan.py
# class GrahamScan(ConvexHullBase):
# 
#     def calculate(self):
#         self.bottom_right = self.get_bottom_right_point()
#         sorted_list = [point for point in sorted(self.points, cmp=self.__compare_with_x_angle) if point != self.bottom_right]
# 
#         result_list = list()
#         result_list.append(self.bottom_right)
#         result_list.append(sorted_list[0])
# 
#         for i in xrange(1, len(sorted_list)):
#             point = sorted_list[i]
#             ind = len(result_list) - 2
# 
#             while self.__cross_product(result_list[ind], result_list[ind+1], point) < 0:
#                 result_list.pop()
#                 ind -= 1
# 
#             result_list.append(point)
# 
#         return result_list
# 
#     def __cross_product(self, p1, p2, p3):
#         return (p2.x - p1.x)*(p3.y - p1.y) - (p2.y - p1.y)*(p3.x - p1.x)
# 
#     def __compare_with_x_angle(self, p1, p2):
#         a1 = self.bottom_right.angle_x(p1)
#         a2 = self.bottom_right.angle_x(p2)
#         if a1 > a2:
#             return 1
#         if a1 == a2:
#             return 0
#         return -1
# 
#     def get_bottom_right_point(self):
#         bottom_point = self.points[0]
#         for point in self.points:
#             if (point.y < bottom_point.y) or (point.y == bottom_point.y and point.x > bottom_point.x):
#                 bottom_point = point
# 
#         return bottom_point
# 
# Path: common/geometry.py
# class Point:
#     def __init__(self, x, y=0.0, z=0.0):
#         self.x = x
#         self.y = y
#         self.z = z
# 
#     def angle_x(self, p2):
#         dy = self.y - p2.y
#         dx = self.x - p2.x
#         h = sqrt(dy ** 2 + dx ** 2)
#         if h == 0:
#             return 0
# 
#         return degrees(asin(dx / h))
# 
#     def __cmp__(self, other):
#         return (self.x - other.x) or (self.y - other.y) or (self.z - other.z)
# 
#     def __eq__(self, other):
#         return self.__cmp__(other) == 0.0
# 
#     def __ne__(self, other):
#         return self.__cmp__(other) != 0.0


from unittest.case import TestCase
from convexhull.grahamscan import GrahamScan
from common.geometry import Point
__author__ = 'orhan'



class GeometryTests(TestCase):

    def test_1(self):
        gs = GrahamScan()

# Path: convexhull/grahamscan.py
# class GrahamScan(ConvexHullBase):
# 
#     def calculate(self):
#         self.bottom_right = self.get_bottom_right_point()
#         sorted_list = [point for point in sorted(self.points, cmp=self.__compare_with_x_angle) if point != self.bottom_right]
# 
#         result_list = list()
#         result_list.append(self.bottom_right)
#         result_list.append(sorted_list[0])
# 
#         for i in xrange(1, len(sorted_list)):
#             point = sorted_list[i]
#             ind = len(result_list) - 2
# 
#             while self.__cross_product(result_list[ind], result_list[ind+1], point) < 0:
#                 result_list.pop()
#                 ind -= 1
# 
#             result_list.append(point)
# 
#         return result_list
# 
#     def __cross_product(self, p1, p2, p3):
#         return (p2.x - p1.x)*(p3.y - p1.y) - (p2.y - p1.y)*(p3.x - p1.x)
# 
#     def __compare_with_x_angle(self, p1, p2):
#         a1 = self.bottom_right.angle_x(p1)
#         a2 = self.bottom_right.angle_x(p2)
#         if a1 > a2:
#             return 1
#         if a1 == a2:
#             return 0
#         return -1
# 
#     def get_bottom_right_point(self):
#         bottom_point = self.points[0]
#         for point in self.points:
#             if (point.y < bottom_point.y) or (point.y == bottom_point.y and point.x > bottom_point.x):
#                 bottom_point = point
# 
#         return bottom_point
# 
# Path: common/geometry.py
# class Point:
#     def __init__(self, x, y=0.0, z=0.0):
#         self.x = x
#         self.y = y
#         self.z = z
# 
#     def angle_x(self, p2):
#         dy = self.y - p2.y
#         dx = self.x - p2.x
#         h = sqrt(dy ** 2 + dx ** 2)
#         if h == 0:
#             return 0
# 
#         return degrees(asin(dx / h))
# 
#     def __cmp__(self, other):
#         return (self.x - other.x) or (self.y - other.y) or (self.z - other.z)
# 
#     def __eq__(self, other):
#         return self.__cmp__(other) == 0.0
# 
#     def __ne__(self, other):
#         return self.__cmp__(other) != 0.0


# Path: tests/convexhull/grahamscan_test.py
from unittest.case import TestCase
from convexhull.grahamscan import GrahamScan
from common.geometry import Point

__author__ = 'orhan'



class GeometryTests(TestCase):

    def test_1(self):
        gs = GrahamScan()

        gs.add_point(Point(0.0, 0.0))