コード例 #1
0
    def test_clamp_rect_pos_exception(self):
        clamped = Rect(Vec2(43, 13), Vec2(6, 155))
        bounds = Rect(Vec2(), Vec2(12, 44))
        with self.assertRaises(ValueError):
            clamp_rect_pos(clamped, bounds)

        bounds = Rect(Vec2(179, 13), Vec2(8, 200))
        with self.assertRaises(ValueError):
            clamp_rect_pos(clamped, bounds, padding=2)
コード例 #2
0
    def test_clamp_rect_pos(self):
        clamped = Rect(Vec2(-23, -44), Vec2(5, 0.4))
        clamped_copy = copy.copy(clamped)
        bounds = Rect(Vec2(), Vec2(12, 44))
        self.assertEqual(clamp_rect_pos(clamped, bounds), Vec2(0, 0))
        self.assertEqual(clamped, clamped_copy, "clamped rect was modified!")

        clamped = Rect(Vec2(15, 700), Vec2(4, 32))
        bounds = Rect(Vec2(10, 3), Vec2(20, 60))
        self.assertEqual(clamp_rect_pos(clamped, bounds), Vec2(15, 31))
コード例 #3
0
 def test_clamp_rect_pos_zero(self):
     bounds_pos = Vec2(100, 1722)
     clamped = Rect(Vec2(), Vec2(10, 10))
     bounds = Rect(bounds_pos, Vec2(10, 10))
     self.assertEqual(clamp_rect_pos(clamped, bounds), bounds_pos)
コード例 #4
0
 def test_clamp_rect_pos_padding(self):
     clamped = Rect(Vec2(-23, -44), Vec2(5, 0.4))
     bounds = Rect(Vec2(10, 32.67), Vec2(34, 71))
     self.assertEqual(clamp_rect_pos(clamped, bounds, padding=10),
                      Vec2(20, 42.67))