Commits

Matthew Marshall  committed 61a25c1

Fix to allow multidimension anims to ommit start or end (but not both.)

  • Participants
  • Parent commits f55cbc7

Comments (0)

Files changed (2)

File rabbyt/anims.py

         t=None, extend="constant"):
 
     try:
-        iter(start), iter(end)
+        if start is not None:
+            iter(start)
+        if end is not None:
+            iter(end)
+        # hack to force a single dimension when both start and end are none.
+        # (This needs a proper solution.)
+        if start is None and end is None:
+            raise TypeError
     except TypeError:
         args = dict(start=start, end=end, startt=startt, endt=endt, dt=dt,
                 t=t, extend=extend, method=method)

File tests/anim_tests.py

 
     # TODO test using multiple dimensions.
 
+class TestMultidimensional(unittest.TestCase, Animable):
+    x = anim_slot()
+    y = anim_slot()
+    xy = swizzle('x', 'y')
+
+    def __init__(self, *pargs, **kwargs):
+        Animable.__init__(self)
+        unittest.TestCase.__init__(self, *pargs, **kwargs)
+
+    def test_incomplete_start(self):
+        self.xy = 10,20
+        self.xy = lerp(end=(20,30), dt=10)
+        add_time(5)
+        self.assertEqual(self.xy, (15, 25))
+
 class TestArithmeticAnim(unittest.TestCase):
     def test_add(self):
         self.assertEqual(ArithmeticAnim("add", 1, 4.5).get_value(), 5.5)
         set_time(35)
         self.assertEqual(t.xy, (0,5))
 
+    def test_tupled_chain_incomplete(self):
+        class Test(Animable):
+            x = anim_slot()
+            y = anim_slot()
+            xy = swizzle('x','y')
+        set_time(0)
+        t = Test()
+        t.xy = chain(
+                lerp(end=(10, 0), dt=10),
+                lerp(end=(10,10), dt=10),
+                lerp(end=( 0,10), dt=10),
+                lerp(end=( 0, 0), dt=10))
+
+        self.assertEqual(t.xy, (0,0))
+        set_time(15)
+        self.assertEqual(t.xy, (10,5))
+        set_time(35)
+        self.assertEqual(t.xy, (0,5))
+
     # TODO test anims using t argument in a chain.
 
 class Test_rate(unittest.TestCase):