def test_intersect_ray_pass(self):
     circle = ConstructionCircle((10., 10.), 3)
     ray1_hor = ConstructionRay((10., 15.), angle=0)
     ray2_hor = ConstructionRay((10., 5.), angle=0)
     ray1_vert = ConstructionRay((5., 10.), angle=HALF_PI)
     ray2_vert = ConstructionRay((15., 10.), angle=-HALF_PI)
     ray3 = ConstructionRay((13.24, 14.95), angle=0.3992)
     self.assertFalse(circle.intersect_ray(ray1_hor))
     self.assertFalse(circle.intersect_ray(ray2_hor))
     self.assertFalse(circle.intersect_ray(ray1_vert))
     self.assertFalse(circle.intersect_ray(ray2_vert))
     self.assertFalse(circle.intersect_ray(ray3))
    def test_intersect_ray_intersect(self):
        circle = ConstructionCircle((10., 10.), 3)
        ray_vert = ConstructionRay((8.5, 10.), angle=HALF_PI)
        cross_points = circle.intersect_ray(ray_vert)
        self.assertEqual(len(cross_points), 2)
        p1, p2 = cross_points
        if p1[1] > p2[1]: p1, p2 = p2, p1
        self.assertTrue(is_close_points(p1, (8.5, 7.4019), abs_tol=1e-4))
        self.assertTrue(is_close_points(p2, (8.5, 12.5981), abs_tol=1e-4))

        ray_hor = ConstructionRay((10, 8.5), angle=0.)
        cross_points = circle.intersect_ray(ray_hor)
        self.assertEqual(len(cross_points), 2)
        p1, p2 = cross_points
        if p1[0] > p2[0]: p1, p2 = p2, p1
        self.assertTrue(is_close_points(p1, (7.4019, 8.5), abs_tol=1e-4))
        self.assertTrue(is_close_points(p2, (12.5981, 8.5), abs_tol=1e-4))

        ray_slope = ConstructionRay((5, 5), (16, 12))
        cross_points = circle.intersect_ray(ray_slope)
        self.assertEqual(len(cross_points), 2)
        p1, p2 = cross_points
        if p1[0] > p2[0]: p1, p2 = p2, p1
        self.assertTrue(is_close_points(p1, (8.64840, 7.3217), abs_tol=1e-4))
        self.assertTrue(is_close_points(p2, (12.9986, 10.0900), abs_tol=1e-4))

        # ray with slope through midpoint
        ray_slope = ConstructionRay((10, 10), angle=HALF_PI / 2)
        cross_points = circle.intersect_ray(ray_slope)
        self.assertEqual(len(cross_points), 2)
        p1, p2 = cross_points
        if p1[0] > p2[0]: p1, p2 = p2, p1
        # print (p1[0], p1[1], p2[0], p2[1])
        self.assertTrue(is_close_points(p1, (7.8787, 7.8787), abs_tol=1e-4))
        self.assertTrue(is_close_points(p2, (12.1213, 12.1213), abs_tol=1e-4))

        # horizontal ray through midpoint
        ray_hor = ConstructionRay((10, 10), angle=0)
        cross_points = circle.intersect_ray(ray_hor)
        self.assertEqual(len(cross_points), 2)
        p1, p2 = cross_points
        if p1[0] > p2[0]: p1, p2 = p2, p1
        # print (p1[0], p1[1], p2[0], p2[1])
        self.assertTrue(is_close_points(p1, (7, 10), abs_tol=1e-5))
        self.assertTrue(is_close_points(p2, (13, 10), abs_tol=1e-5))

        # vertical ray through midpoint
        ray_vert = ConstructionRay((10, 10), angle=HALF_PI)
        cross_points = circle.intersect_ray(ray_vert)
        self.assertEqual(len(cross_points), 2)
        p1, p2 = cross_points
        if p1[1] > p2[1]: p1, p2 = p2, p1
        # print (p1[0], p1[1], p2[0], p2[1])
        self.assertTrue(is_close_points(p1, (10, 7), abs_tol=1e-5))
        self.assertTrue(is_close_points(p2, (10, 13), abs_tol=1e-5))