Clean up TransformMatchingStrings

This commit is contained in:
Grant Sanderson 2022-12-30 15:09:07 -08:00
parent 3aa9eb6372
commit 4c1f1f8749

View file

@ -83,19 +83,22 @@ class TransformMatchingParts(AnimationGroup):
new_source_pieces = source.family_members_with_points() new_source_pieces = source.family_members_with_points()
new_target_pieces = target.family_members_with_points() new_target_pieces = target.family_members_with_points()
if len(new_source_pieces) == 0 or len(new_target_pieces) == 0: if len(new_source_pieces) == 0 or len(new_target_pieces) == 0:
# Don't animate null sorces # Don't animate null sorces or null targets
return return
source_is_new = all(char in self.source_pieces for char in new_source_pieces) source_is_new = all(char in self.source_pieces for char in new_source_pieces)
target_is_new = all(char in self.target_pieces for char in new_target_pieces) target_is_new = all(char in self.target_pieces for char in new_target_pieces)
if source_is_new and target_is_new: if not source_is_new or not target_is_new:
transform_type = self.mismatch_animation return
if source.has_same_shape_as(target):
transform_type = self.match_animation transform_type = self.mismatch_animation
self.anims.append(transform_type(source, target, **self.anim_config)) if source.has_same_shape_as(target):
for char in new_source_pieces: transform_type = self.match_animation
self.source_pieces.remove(char)
for char in new_target_pieces: self.anims.append(transform_type(source, target, **self.anim_config))
self.target_pieces.remove(char) for char in new_source_pieces:
self.source_pieces.remove(char)
for char in new_target_pieces:
self.target_pieces.remove(char)
def find_pairs_with_matching_shapes( def find_pairs_with_matching_shapes(
self, self,
@ -136,8 +139,8 @@ class TransformMatchingStrings(TransformMatchingParts):
for substr in [ for substr in [
*source.get_specified_substrings(), *source.get_specified_substrings(),
*target.get_specified_substrings(), *target.get_specified_substrings(),
*source.get_string(), # TODO, have this return symbols, not characters *source.get_symbol_substrings(),
*target.get_string(), *target.get_symbol_substrings(),
] ]
] ]
] ]