Ejemplo n.º 1
0
    def test_border_non_intersect(self):
        polygon = Polygon()
        polygon.add_point(0, 0)
        polygon.add_point(0, 1)
        polygon.add_point(1, 1)
        polygon.add_point(1, 0)

        line1 = [Vec2d(0, 0), Vec2d(1, 0)]

        self.assertFalse(intersect_polygon(line1, polygon))
Ejemplo n.º 2
0
    def test_same_start_point_is_node(self):
        polygon = Polygon()
        polygon.add_point(0, 1)
        polygon.add_point(0, 2)
        polygon.add_point(1, 2)
        polygon.add_point(1, 1)

        planner = AStarPlanner()
        planner.add_polygon(polygon)
        planner.init()

        planner.find_path(0, 0, 1, 2)
Ejemplo n.º 3
0
    def test_basic_polygon_intersect(self):
        poly = Polygon()
        poly.add_point(0, 0)
        poly.add_point(0, 1)
        poly.add_point(1, 1)
        poly.add_point(1, 0)

        line = [Vec2d(-0.5, -0.5), Vec2d(0.5, 0.5)]
        self.assertTrue(intersect_polygon(line, poly))

        line = [Vec2d(1, -1), Vec2d(1, 0)]
        self.assertFalse(intersect_polygon(line, poly))
Ejemplo n.º 4
0
    def ztest_visual(self):
        pygame.init()
        size = width, height = 320, 240
        screen = pygame.display.set_mode(size, 0, 32)
        clock = pygame.time.Clock()

        black = (0, 0, 0)
        white = (255, 255, 255)
        green = (0, 255, 0)
        red = (255, 0, 0)
        bleh = (155, 10, 110)

        poly = Polygon()
        poly.add_point(50, 0)
        poly.add_point(50, 50)
        poly.add_point(0, 50)
        poly.add_point(0, 0)

        poly2 = Polygon()
        poly2.add_point(50, 0)
        poly2.add_point(50, 50)
        poly2.add_point(0, 50)
        poly2.add_point(0, 0)

        c_poly = poly.compute_c_polygon(poly2)
        print c_poly

        screen.fill(white)

        for point in poly.get_points():
            print point
            draw_color = black
            pygame.draw.circle(screen, draw_color,
                               (point.x + 200, height - point.y - 100), 3, 3)
            print(point.x + 200, height - point.y - 200)

        for point in c_poly.get_points():
            print point
            draw_color = green
            pygame.draw.circle(screen, draw_color,
                               (point.x + 200, height - point.y - 100), 3, 3)
            print(point.x + 200, 200 + height - point.y)

        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT: sys.exit()

            keys = pygame.key.get_pressed()
            if keys[pygame.K_ESCAPE]:
                sys.exit()

            # num_hull_points = len(hull_points)
            # for i in range(num_hull_points):
            #     point_a = (hull_points[(i + 1) % num_hull_points].x, -hull_points[(i + 1) % num_hull_points].y)
            #     point_b = (hull_points[i].x, -hull_points[i].y)

            #     pygame.draw.line(screen, red, point_a, point_b)
            #     pygame.display.flip()

            pygame.display.flip()
            pygame.display.update()
            clock.tick(30)