def test_convex_hull_jarvis_simple_case(self):
     point_list = [(0, 3), (2, 2), (1, 1), (2, 1), (3, 0), (0, 0), (3, 3)]
     # Convex Hull Graham Scan
     mock_convex_hull_graham = ConvexHullGraham(point_list)
     convex_hull_graham_output = mock_convex_hull_graham.convex_hull()
     expected = [Point(0, 0), Point(0, 3), Point(3, 3), Point(3, 0)]
     self.assertCountEqual(expected, convex_hull_graham_output)
 def test_convex_hull_jarvis_simple_case(self):
     point_list = [(0, 3), (2, 2), (1, 1), (2, 1), (3, 0), (0, 0), (3, 3)]
     # Convex Hull Jarvis Algorithm
     mock_convex_hull_jarvis = ConvexHullJarvis(point_list)
     convex_hull_jarvis_output = mock_convex_hull_jarvis.convex_hull()
     expected = [Point(0, 0), Point(0, 3), Point(3, 3), Point(3, 0)]
     self.assertCountEqual(expected, convex_hull_jarvis_output)
 def test_convex_hull_jarvis_complicated_case(self):
     point_list = [(0, 0), (1, 4), (3, 3), (3, 1), (5, 5), (5, 2), (7, 0),
                   (9, 6)]
     # Convex Hull Graham Scan
     mock_convex_hull_graham = ConvexHullGraham(point_list)
     convex_hull_graham_output = mock_convex_hull_graham.convex_hull()
     expected = [Point(0, 0), Point(7, 0), Point(9, 6), Point(1, 4)]
     self.assertCountEqual(expected, convex_hull_graham_output)
 def test_convex_hull_jarvis_complicated_case(self):
     point_list = [(0, 0), (1, 4), (3, 3), (3, 1), (5, 5), (5, 2), (7, 0),
                   (9, 6)]
     # Convex Hull Jarvis Algorithm
     mock_convex_hull_jarvis = ConvexHullJarvis(point_list)
     convex_hull_jarvis_output = mock_convex_hull_jarvis.convex_hull()
     expected = [Point(0, 0), Point(7, 0), Point(9, 6), Point(1, 4)]
     self.assertCountEqual(expected, convex_hull_jarvis_output)
    def test_lower_tangent_case3(self):
        point_list_a = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        polygon_a = Polygon(point_list_a)
        point_list_b = [(4, 1), (3, 3), (5, 2), (4, 4)]
        polygon_b = Polygon(point_list_b)

        # After polygons are created
        mock_tangent_polygon_calculator = TangentPolygonCalculator()
        mock_tangent_polygon_calculator['a'] = polygon_a
        mock_tangent_polygon_calculator['b'] = polygon_b

        expected = [Point(0, -1), Point(4, 1)]
        self.assertCountEqual(
            expected, mock_tangent_polygon_calculator.lower_tangent('a', 'b'))
    def test_upper_tangent_case2(self):
        point_list_a = [(3, 1), (4, 2), (3, 3), (2, 2)]
        polygon_a = Polygon(point_list_a)
        point_list_b = [(0, 1), (0, 2), (-1, 1), (-1, 2)]
        polygon_b = Polygon(point_list_b)

        # After polygons are created
        mock_tangent_polygon_calculator = TangentPolygonCalculator()
        mock_tangent_polygon_calculator['a'] = polygon_a
        mock_tangent_polygon_calculator['b'] = polygon_b

        expected = [Point(-1, 2), Point(3, 3)]
        self.assertCountEqual(
            expected, mock_tangent_polygon_calculator.upper_tangent('a', 'b'))
 def __init__(self, point_list):
     self.point_list = []
     for point in point_list:
         if isinstance(point, Point):
             self.point_list.append(point)
         else:
             self.point_list.append(Point(point[0], point[1]))
 def __init__(self, point_list):
     super(ConvexHullDivideNConquer, self).__init__()
     self.point_list = []
     self.midpoint = None
     for val in point_list:
         new_point = Point(val[0], val[1])
         self.point_list.append(new_point)
 def set_midpoint(self):
     """
     Set centroid positions
     :return: None
     """
     x_sum, y_sum = 0, 0
     for point in self.point_list:
         x_sum += point.x
         y_sum += point.y
     n = len(self.point_list)
     self.midpoint = Point(x_sum / n, y_sum / n)
 def test_sort_by_angle_and_distance(self):
     mock_point_list = [
         Point(0, 0),
         Point(2, 2),
         Point(1, 1),
         Point(2, 1),
         Point(3, 0),
         Point(0, 3),
         Point(3, 3)
     ]
     mock_point_list[1:] = sorted(
         mock_point_list[1:],
         key=lambda p: sort_by_angle_and_distance(mock_point_list[0], p))
     expected = [
         Point(0, 0),
         Point(3, 0),
         Point(2, 1),
         Point(1, 1),
         Point(2, 2),
         Point(3, 3),
         Point(0, 3)
     ]
     self.assertEqual(expected, mock_point_list)