Ejemplo n.º 1
0
    def test_pygame2_base_Rect_fit(self):

        # __doc__ (as of 2008-10-17) for pygame2.base.Rect.fit:

        # Rect.fit (Rect) -> Rect
        # 
        # Resize and move a rectangle with aspect ratio.
        # 
        # Returns a new rectangle that is moved and resized to fit
        # another. The aspect ratio of the original Rect is preserved,
        # so the new rectangle may be smaller than the target in either
        # width or height.

        r = Rect(10, 10, 30, 30)

        r2 = Rect(30, 30, 15, 10)

        f = r.fit(r2)
        self.assertTrue(r2.contains(f))
        
        f2 = r2.fit(r)
        self.assertTrue(r.contains(f2))
Ejemplo n.º 2
0
    def test_pygame2_base_Rect_contains(self):

        # __doc__ (as of 2008-10-17) for pygame2.base.Rect.contains:

        # Rect.contains (Rect) -> bool
        # 
        # Test if one rectangle is inside another.
        # 
        # Returns true when the argument rectangle is completely inside
        # the Rect.
        r = Rect( 1, 2, 3, 4 )
        
        self.assertTrue( r.contains( Rect( 2, 3, 1, 1 ) ),
                         "r does not contain Rect(2,3,1,1)" )
        self.assertTrue( r.contains( Rect(r) ),
                         "r does not contain the same rect as itself" )
        self.assertTrue( r.contains( Rect(2,3,0,0) ),
                         "r does not contain an empty rect within its bounds" )
        self.assertFalse( r.contains( Rect(0,0,1,2) ),
                     "r contains Rect(0,0,1,2)" )
        self.assertFalse( r.contains( Rect(4,6,1,1) ),
                     "r contains Rect(4,6,1,1)" )
        self.assertFalse( r.contains( Rect(4,6,0,0) ),
                     "r contains Rect(4,6,0,0)" )