Skip to content

Fix Line.add_tip() distorting polyline paths#4650

Open
BrightonXX wants to merge 1 commit intoManimCommunity:mainfrom
BrightonXX:codex/fix-add-tip-polyline-distortion
Open

Fix Line.add_tip() distorting polyline paths#4650
BrightonXX wants to merge 1 commit intoManimCommunity:mainfrom
BrightonXX:codex/fix-add-tip-polyline-distortion

Conversation

@BrightonXX
Copy link

Fixes #4444

Overview: What does this pull request change?

This PR fixes a geometry bug in Line.add_tip() / OpenGLLine.add_tip() when working with polylines created via set_points_as_corners(...), as reported in #4444 by @tobiasBora.

Before this patch, adding a tip shortened the path by resetting the whole line's start and end points. That behavior is fine for a single straight segment, but for multi-segment polylines it remaps the entire path and shifts interior corners.

With this patch, plain Line / OpenGLLine paths with path_arc == 0 trim only the first or last boundary segment to the tip base, so the existing elbow geometry stays intact.

Motivation and Explanation: Why and how do your changes improve the library?

An example is:

from manim import *

class BrokenElbow(Scene):
    def construct(self):
        line = Line()
        line.set_points_as_corners(
            [
                [-3, -1, 0],
                [-3, 1, 0],
                [1, 1, 0],
            ]
        ).add_tip(tip_length=0.4)

        self.add(NumberPlane(), line)

Expected behavior:

  • the corner at (-3, 1, 0) stays fixed
  • only the last horizontal segment is shortened to make room for the tip

Actual behavior before this patch:

  • the whole polyline is remapped when the tip is added
  • the elbow corner shifts away from its original location

To fix this, Line and OpenGLLine now trim only the boundary segment when path_arc == 0, while other cases still fall back to the existing generic implementation.

I also added regression tests covering both end tips and start tips preserving the polyline corner.

Links to added or changed documentation pages

No documentation pages were changed.

Further Information and Comments

Local tests run:

  • python -m pytest -o addopts='' tests/module/mobject/geometry/test_unit_geometry.py -q

I also ran targeted checks locally for:

  • straight lines with tips
  • both start and end tips
  • Arrow / DoubleArrow
  • zero-length Line
  • path_arc != 0
  • OpenGLLine

Visual comparison:

The red dot marks the intended elbow corner. Before this patch, add_tip() remaps the whole polyline when shortening it for the tip. After the patch, the corner stays fixed and only the boundary segment is trimmed.

Issue4444Comparison_ManimCE_v0 20 1

Animated comparison video:

Issue4444Animated.mp4

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@BrightonXX BrightonXX force-pushed the codex/fix-add-tip-polyline-distortion branch from 0876b68 to a41aba2 Compare March 20, 2026 20:22
@GoThrones
Copy link
Contributor

GoThrones commented Mar 22, 2026

in the fixed add_tip() situation: shouldn't the arrowhead generate at the end of the line, right after crossing the red dot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add_tip shifts the line

2 participants