def setUp(self): self.polygon = Polygon([ Point(1, 1), Point(-2, -3), Point(-2, -6), Point(1, -8), Point(5, -8), Point(7, -3) ]) self.other = Polygon([Point(1, 1), Point(-21, 20), Point(3, 10)])
def test_get_three(self): parser = self.parser('{[(0,0),(0,2),(0,10)],' '[(1,1),(0,3),(5,5)]},' '{[(1,5),(2,3),(6,5)]}') result = [{0: Polygon([Point(x=0, y=0), Point(x=0, y=2), Point(x=0, y=10)]), 1: Polygon([Point(x=1, y=1), Point(x=0, y=3), Point(x=5, y=5)])}, {0: Polygon([Point(x=1, y=5), Point(x=2, y=3), Point(x=6, y=5)])}] tree = parser.get_tree() self.assertEqual(tree[0][0].points, result[0][0].points) self.assertEqual(tree[0][1].points, result[0][1].points) self.assertEqual(tree[1][0].points, result[1][0].points)
def test_get_segments(self): segments = self.other._get_segments() true_segments = [ Segment(Point(1, 1), Point(-21, 20)), Segment(Point(-21, 20), Point(3, 10)), Segment(Point(3, 10), Point(1, 1)) ] self.assertEqual(segments, true_segments)
def generate_polygon(self): count_of_points = np.random.randint(5, 6) x = np.random.randint(-30, 30, count_of_points) y = np.random.randint(-30, 30, count_of_points) center_point = [ ceil(np.sum(x) / count_of_points), ceil(np.sum(y) / count_of_points) ] angles = np.arctan2(x - center_point[0], y - center_point[1]) sort_tups =\ sorted([(i, j, k) for i, j, k in zip(x, y, angles)], key=lambda t: t[2]) x, y, angles = zip(*sort_tups) x = list(x) y = list(y) x.append(x[0]) y.append(y[0]) coordinates = list() for i in range(count_of_points): coordinates.append(Point(x[i], y[i])) return coordinates
def test_is_not_have_common_side(self): other = Polygon([Point(100, 100), Point(-201, 200), Point(30, 100)]) self.assertFalse(self.polygon._is_have_common_side(other))
def test_is_have_common_side(self): other = Polygon([Point(1, 1), Point(-2, -3), Point(-2, -6)]) self.assertTrue(self.polygon._is_have_common_side(other))
def test_point_in_the_polygon(self): is_in_polygon = \ self.polygon.point_in_polygon(Point(2, -3)) self.assertTrue(is_in_polygon)
def test_point_not_in_the_polygon(self): is_in_polygon = \ self.polygon.point_in_polygon(Point(-5, 5)) self.assertFalse(is_in_polygon)