diff pyink/frameline.py @ 1193:0e3a65b7b00c

Simplify extendScened()
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 02 Jan 2011 18:26:30 +0800
parents bfd7d466a022
children 8c5492b096f1
line wrap: on
line diff
--- a/pyink/frameline.py	Sun Jan 02 14:18:48 2011 +0800
+++ b/pyink/frameline.py	Sun Jan 02 18:26:30 2011 +0800
@@ -790,23 +790,46 @@
     # - If the indexed frame is a key frame with no right_tween, returns the
     #   range that start and stop are both equivalent to idx.
     #
+    # - If both earlier two are not meat, the previesou keyframe or tween is
+    #   returned.
+    #
+    # - Otherwise, raise an exception.
+    #
+    # \param idx is the index number of a frame.
+    # \return A tuple of (start, stop, tween_type)
+    #
+    def get_frame_block_floor(self, idx):
+	pos = self._find_keyframe_floor(idx)
+	if pos != -1:
+	    key = self._keys[pos]
+	    if key.right_tween:
+		next_key = self._keys[pos + 1]
+		return key.idx, next_key.idx, key.right_tween_type
+	    if key.left_tween:
+		prev_key = self._keys[pos - 1]
+		return prev_key.idx, key.idx, prev_key.right_tween_type
+	    return key.idx, key.idx, 0
+	raise ValueError, \
+	    'the frame specified by idx is not in any tween or a key frame'
+
+    ## \brief Return the range of a block of consequence frames (tween).
+    # 
+    # - If the index frame is in a tween, it returns the range of the tween.
+    #
+    # - If the indexed frame is a key frame with no right_tween, returns the
+    #   range that start and stop are both equivalent to idx.
+    #
     # - Otherwise, raise an exception.
     #
     # \param idx is the index number of a frame.
     # \return A tuple of (start, stop, tween_type)
     #
     def get_frame_block(self, idx):
-	pos = self._find_keyframe_floor(idx)
-	if pos != -1:
-	    key = self._keys[pos]
-	    if key.right_tween:
-		next_key = self._keys[pos + 1]
-		return key.idx, next_key.idx, key.right_tween_type
-	    elif key.idx == idx:
-		return key.idx, key.idx, 0
-	    pass
-	raise ValueError, \
-	    'the frame specified by idx is not in any tween or a key frame'
+	start, stop, tween_type = self.get_frame_block_floor(idx)
+	if stop < idx:
+	    raise ValueError, \
+		'the frame specified by idx is not in any tween or a key frame'
+	return start, stop, tween_type
     
     def get_frame_data(self, idx):
 	pos = self._find_keyframe(idx)