Fix Line.add_tip() distorting polyline paths#4650
Fix Line.add_tip() distorting polyline paths#4650BrightonXX wants to merge 1 commit intoManimCommunity:mainfrom
Conversation
0876b68 to
a41aba2
Compare
|
in the fixed add_tip() situation: shouldn't the arrowhead generate at the end of the line, right after crossing the red dot. |
The red dot is meant to indicate the interior elbow corner, not the endpoint of the line. The fix keeps that corner fixed and only shortens the final segment to the tip base, so the arrowhead should still remain at the end of the line. If I misunderstood your question, feel free to clarify what you mean by "crossing the red dot". |
|
At present, even in the fixed add_tip() scenario (in the animation that you posted above), the arrowhead is coming up very late in the animation. It should be at the tip of the arrow all the time. That would look better. I suppose that would require more modifications than this PR is supposed to do. |
Sorry for the confusion. The demo animation I posted was only meant to illustrate the mechanism behind the bug: when the arrow tip is added, the whole line gets transformed/remapped, which causes the elbow corner to shift out of alignment. In actual usage, the line and the arrowhead are part of the same final object, so they appear together rather than with the staged timing used in the demo. |
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 viaset_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/OpenGLLinepaths withpath_arc == 0trim 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:
Expected behavior:
(-3, 1, 0)stays fixedActual behavior before this patch:
To fix this,
LineandOpenGLLinenow trim only the boundary segment whenpath_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 -qI also ran targeted checks locally for:
Arrow/DoubleArrowLinepath_arc != 0OpenGLLineVisual 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.Animated comparison video:
Issue4444Animated.mp4
Reviewer Checklist