Fix creation or animation of a zero-length DashedLine (#4606)

* fixing #4591

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Abdelsalam 2026-02-22 12:10:21 +02:00 committed by GitHub
commit e34e707858
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 2 deletions

View file

@ -241,7 +241,8 @@ class TipableVMobject(VMobject, metaclass=ConvertToOpenGL):
if self.has_start_tip():
result.add(self.start_tip)
self.remove(self.start_tip)
self.put_start_and_end_on(start, end)
if result.submobjects:
self.put_start_and_end_on(start, end)
return result
def get_tips(self) -> VGroup:

View file

@ -1,4 +1,4 @@
from manim import ORIGIN, UR, Arrow, DashedVMobject, VGroup
from manim import ORIGIN, UR, Arrow, DashedLine, DashedVMobject, VGroup
from manim.mobject.geometry.tips import ArrowTip, StealthTip
@ -41,3 +41,19 @@ def test_dashed_arrow_with_start_tip_has_two_tips():
tips = _collect_tips(dashed)
assert len(tips) == 2
def test_zero_length_dashed_line_submobjects_have_2d_points():
"""Submobjects of a zero-length DashedLine must have 2-D point arrays."""
line = DashedLine(ORIGIN, ORIGIN)
for sub in line.submobjects:
assert sub.points.ndim == 2, (
f"Expected 2-D points array, got shape {sub.points.shape}"
)
def test_become_nonzero_to_zero_dashed_line_does_not_crash():
"""become() from a normal DashedLine to a zero-length one should not crash."""
normal = DashedLine(ORIGIN, 2 * UR)
zero = DashedLine(ORIGIN, ORIGIN)
normal.become(zero)