Skip to content

Refactored line.py file#4752

Open
GoThrones wants to merge 8 commits into
ManimCommunity:mainfrom
GoThrones:line
Open

Refactored line.py file#4752
GoThrones wants to merge 8 commits into
ManimCommunity:mainfrom
GoThrones:line

Conversation

@GoThrones
Copy link
Copy Markdown
Contributor

@GoThrones GoThrones commented May 30, 2026

Overview: What does this pull request change?

The changes of this PR are completely backwards compatible.
This PR makes following changes:

(1) In Line class, modified the _pointify method to convert 2D points to 3D points. This will work for all subclass of Line.

(2) In Arrow class, added explicit start, end, and tip_shape parameters in init, while maintaining full backwards compatibility via *args.

(3) In DoubleArrow class, added explicit start, end, tip_shape_at_start, tip_shape_at_end parameters. Also, this PR renames tip_shape_start/tip_shape_end to tip_shape_at_start/tip_shape_at_end with deprecation warnings for the old names.
tip_shape_start/end gives the impression that it's the starting point of the tip itself, not that of the mobject to which the tip is attached.

(4) In Vector class, improved the init with better parameter handling and refactored the coordinate_label method supporting both start and end labels. Also, the positioning of labels has been improved, which is can be seen in this video below. In the main branch, there is only end label, and no provision of start label. Also, in the main branch, if the Vector is rotating, then the labels jump suddenly, when the vector points towards negative direction from positive direction, and vice-a-versa.
Here's the code, which i used to demonstrate this:

class VectorCoordinateLabel1(Scene):
    def construct(self):
        plane = NumberPlane()        
        vec = Vector(start = [-2,-2,0], direction = [3,2.6])        
        label = vec.coordinate_label(color = RED, show_start_label=True)
        self.add(plane, vec, label)
        vec.add_updater(lambda x,dt: x.rotate(2*PI*dt*0.2, about_point= x.get_center()))
        def upd_label(mob):
            mob.become(vec.coordinate_label(color = RED, show_start_label=True))        
        label.add_updater(upd_label)        
        self.wait(5)

This video is from the PR branch. In the video, the Matrix box is flickering because it's size is not constant throughout, and that is because of the + or - sign before the numbers in addition to the width of the numbers themselves. But in main branch, the matrix box itself was shifting from right to left or from left to right, because of the code. So that caused sudden jump in the box's position, in addition to the existing flicker due to + or - sign before the numbers. Jumping of the box itself has been cured by this PR.

VectorCoordinateLabel1.mp4

(5) Some minor modifications in VectorScene class.

(6) The reference frame for test_vector_to_coords was regenerated because the improved coordinate_label method of Vector class, positions the coordinate label differently from the original implementation. The new positioning places the label along the vector's direction using buff and buff_multiplier, which is more geometrically correct than the original approach which only checked whether the vector was pointing left or right.

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

The Arrow class, Vector class, DoubleArrowClass etc, didn't had explicit parameters start, end, tip shape, etc.

Further Information and Comments

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

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.

1 participant