ITADN

Shape morphing/interpolation

#62ClosedCoffeeStraw 创建于 2025-06-07
C
CoffeeStrawcommented
Add a new method to the `Shape` class that can morph/interpolate between two shapes using a float parameter (0.0 to 1.0) to create smooth transitions. ## Proposed API ```python def morph(self, target_shape: Shape, t: float) -> Shape: """ Morphs this shape into the target shape using linear interpolation. Parameters: target_shape (Shape): The target shape to morph towards t (float): Interpolation factor (0.0 = source shape, 1.0 = target shape) Returns: Shape: A new interpolated shape Raises: ValueError: If t is not between 0.0 and 1.0 TypeError: If target_shape is not a Shape instance ValueError: If shapes cannot be morphed (incompatible structures) """ ``` ## Implementation Approach 1. **Preprocessing Phase**: - Validate both shapes using existing `has_error()` method - Normalize shapes to have compatible structures - Convert curves to lines if needed using existing `flatten()` method - Ensure equal number of points using existing `split()` method 2. **Interpolation Phase**: - Parse both shapes into point arrays - Use existing `Utils.interpolate()` for coordinate interpolation - Reconstruct shape command string
关闭于 2025-06-22 0 条评论