def test_rect_in_circle(self):
        """ Test rect_in_circle returns correct result """
        r1 = Rectangle(Point(0, 0), width=5, height=3)
        c1 = Circle(Point(0, 0), radius=6)

        self.assertTrue(rect_in_circle(c1, r1))
        r1.bl = Point(3, 0)  # TODO: Create a shift method that moves shapes
        self.assertFalse(rect_in_circle(c1, r1))
    def test_line_distance(self):
        """ Test Line object distance method """
        l = Line(Point(0, 0), Point(1, 1))
        xy = Point(0, 2.5)

        half_hypoteneuse = math.sqrt((2.5**2) + (2.5**2)) / 2
        self.assertTrue(math.isclose(l.distance(xy), half_hypoteneuse))

        xy = Point(0, 2)
        d = 2 * math.sin(math.pi / 4)
        self.assertTrue(math.isclose(l.distance(xy), d))
    def test_line_segment_dot_product(self):
        """ Test vector dot product implementaiton from https://www.geeksforgeeks.org/minimum-distance-from-a-point-to-the-line-segment-using-vectors/"""
        a = Point(0, 0)
        b = Point(2, 0)
        e = Point(4, 0)

        ab = LineSegment(a, b)
        be = LineSegment(b, e)
        ae = LineSegment(a, e)

        self.assertTrue(ab.dot_product(be) == 4)
        self.assertTrue(ab.dot_product(ae) == 8)
    def test_rect_circle_overlap(self):
        """ Test some expected values for this overlap function"""
        c = Circle(Point(), 5)
        r = Rectangle(Point(0, 5), 1, 1)

        self.assertTrue(rect_circle_overlap(c, r))

        r.bl = Point(4, 3)
        self.assertTrue(rect_circle_overlap(c, r))

        r.bl = Point(3.75, 3.75)
        self.assertFalse(rect_circle_overlap(c, r))

        r.bl = Point(5, -0.5)
        self.assertTrue(rect_circle_overlap(c, r))
Example #5
0
def main():
    bob = turtle.Turtle()

    box = Rectangle()
    box.width = 100
    box.height = 50
    box.corner = Point()
    box.corner.x = 0
    box.corner.y = 0

    circle = Circle()
    circle.radius = 50
    circle.center = Point()
    circle.center.x = 0
    circle.center.y = 0

    draw_rect(bob, box)
    draw_circle(bob, circle)

    turtle.Screen().mainloop()
    def test_line_segment_shortest_distance(self):
        a = Point(0, 0)
        b = Point(2, 0)
        e = Point(4, 0)

        ab = LineSegment(a, b)
        be = LineSegment(b, e)
        ae = LineSegment(a, e)

        self.assertTrue(ab.distance(e) == 2)

        b = Point(2, 2)
        e = Point(2, 0)

        ab = LineSegment(a, b)
        be = LineSegment(b, e)
        ae = LineSegment(a, e)

        d = 2 * math.sin(math.pi / 4)

        self.assertTrue(math.isclose(ab.distance(e), d))
 def setUp(self):
     self.rectangle = Rectangle(Point(0, 0), 100, 100)
 def test_point_distance(self):
     """Helper method behaves as expected"""
     pointa = Point(0, 0)
     pointb = Point(3, 4)
     self.assertTrue(pointa.distance(pointb) == 5)