
    lj)                    P   U d Z ddlmZ g dZddlmZmZmZ ddlZ	ddl
mZ ddlT ddlmZmZmZmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZmZ ddlmZ ddl m!Z!m"Z"m#Z# er>ddlm$Z$m%Z% ddl&m'Z'm(Z(m)Z)m*Z*m+Z+ ddlm,Z, ddl-m.Z. e/ed         ed         f         Z0de1d<   	  G d de          Z2 G d de2          Z3 G d de2          Z4 G d dee           Z5 G d! d"e2          Z6 G d# d$e6          Z7 G d% d&e6          Z8 G d' d(ee           Z9 G d) d*e9          Z:dS )+z.Mobjects that are lines or variations of them.    )annotations)	Line
DashedLineTangentLineElbowArrowVectorDoubleArrowAngle
RightAngle)TYPE_CHECKINGAnyLiteralN)config)*)ArcArcBetweenPointsDotTipableVMobject)ArrowTriangleFilledTip)Mobject)ConvertToOpenGL)OpenGLMobject)DashedVMobjectVGroupVMobject)WHITE)angle_of_vectorline_intersection	normalize)Self	TypeAlias)Point3DPoint3DLikeVector2DLikeVector3DVector3DLike)ParsableManimColor   Matrix)   r"   AngleQuadrantc                       e Zd ZdZeeddfd, fdZd-dZ	 	 d.d/dZd-dZ	d0dZ
d1dZ	 d2d3dZd4dZd5 fdZd6d Zd6d!Zd7d"Zd8d$Zd7d%Zd2d9d)Zd:d+Z xZS );r   al  A straight or curved line segment between two points or mobjects.

    Parameters
    ----------
    start
        The starting point or Mobject of the line.
    end
        The ending point or Mobject of the line.
    buff
        The distance to shorten the line from both ends.
    path_arc
        If nonzero, the line will be curved into an arc with this angle (in radians).
    kwargs
        Additional arguments to be passed to :class:`TipableVMobject`

    Examples
    --------
    .. manim:: LineExample
        :save_last_frame:

        class LineExample(Scene):
            def construct(self):
                line1 = Line(LEFT*2, RIGHT*2)
                line2 = Line(LEFT*2, RIGHT*2, buff=0.5)
                line3 = Line(LEFT*2, RIGHT*2, path_arc=PI/2)
                grp = VGroup(line1,line2,line3).arrange(DOWN, buff=2)
                self.add(grp)
    r   startPoint3DLike | Mobjectendbufffloatpath_arckwargsr   returnNonec                    d| _         || _        || _        |                     ||            t	                      j        di | d S )N    )dimr3   r5   _set_start_and_end_attrssuper__init__)selfr0   r2   r3   r5   r6   	__class__s         V/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/mobject/geometry/line.pyr?   zLine.__init___   sS     	 %%eS111""6"""""    c                `    |                      | j        | j        | j        | j                   d S )N)r0   r2   r3   r5   )set_points_by_endsr0   r2   r3   r5   r@   s    rB   generate_pointszLine.generate_pointsm   s=    *]	 	  	
 	
 	
 	
 	
rC   c                >   |                      ||           |r<t          | j        | j        | j                  }|                     |j                   n3|                     t          j	        | j        | j        g                     | 
                    |           dS )a-  Sets the points of the line based on its start and end points.
        Unlike :meth:`put_start_and_end_on`, this method respects `self.buff` and
        Mobject bounding boxes.

        Parameters
        ----------
        start
            The start point or Mobject of the line.
        end
            The end point or Mobject of the line.
        buff
            The empty space between the start and end of the line, by default 0.
        path_arc
            The angle of a circle spanned by this arc, by default 0 which is a straight line.
        )angleN)r=   r   r0   r2   r5   
set_pointspointsset_points_as_cornersnpasarray_account_for_buff)r@   r0   r2   r3   r5   arcs         rB   rE   zLine.set_points_by_endsu   s    , 	%%eS111 	K"4:txt}MMMCOOCJ''''&&rz4:tx2H'I'IJJJt$$$$$rC   c                .    |                                   d S N)rG   rF   s    rB   init_pointszLine.init_points   s    rC   c                    |dk    rd S | j         dk    r|                                 n|                                 }|d|z  k     rd S ||z  }|                     | |d|z
             d S )Nr   r)   r-   )r5   
get_lengthget_arc_lengthpointwise_become_partial)r@   r3   lengthbuff_proportions       rB   rO   zLine._account_for_buff   s|    199F&*mq&8&8"""d>Q>Q>S>SAHF-%%dOQ=PQQQQQrC   c                    |                      |          }|                      |          }t          ||z
            }|                      ||          | _        |                      ||           | _        d S rR   )	_pointifyr    r0   r2   )r@   r0   r2   rough_start	rough_endvects         rB   r=   zLine._set_start_and_end_attrs   sj    
 nnU++NN3''	[011 ^^E400
>>#u--rC   Nmob_or_pointMobject | Point3DLike	directionVector3DLike | Noner#   c                    t          |t          t          f          r-|}||                                S |                    |          S t          j        |          S )aO  Transforms a mobject into its corresponding point. Does nothing if a point is passed.

        ``direction`` determines the location of the point along its bounding box in that direction.

        Parameters
        ----------
        mob_or_point
            The mobject or point.
        direction
            The direction.
        )
isinstancer   r   
get_centerget_boundary_pointrM   array)r@   r_   ra   mobs       rB   r[   zLine._pointify   sZ      lWm$<== 	9C ~~'''--i888x%%%rC   	new_valuec                <    || _         |                                  d S rR   )r5   rS   )r@   ri   s     rB   set_path_arczLine.set_path_arc   s!    !rC   r$   r!   c                2   |                                  \  }}t          j        ||k              rFt          j        |          | _        t          j        |          | _        |                                  t                                          ||          S )a  Sets starts and end coordinates of a line.

        Examples
        --------
        .. manim:: LineExample

            class LineExample(Scene):
                def construct(self):
                    d = VGroup()
                    for i in range(0,10):
                        d.add(Dot())
                    d.arrange_in_grid(buff=1)
                    self.add(d)
                    l= Line(d[0], d[1])
                    self.add(l)
                    self.wait()
                    l.put_start_and_end_on(d[1].get_center(), d[2].get_center())
                    self.wait()
                    l.put_start_and_end_on(d[4].get_center(), d[7].get_center())
                    self.wait()
        )	get_start_and_endrM   allrN   r0   r2   rG   r>   put_start_and_end_on)r@   r0   r2   
curr_startcurr_endrA   s        rB   ro   zLine.put_start_and_end_on   s    4  $5577
H6*()) 	# E**DJz#DH  """ww++E3777rC   r&   c                T    |                                  |                                 z
  S rR   )get_end	get_startrF   s    rB   
get_vectorzLine.get_vector   s    ||~~ 0 000rC   c                D    t          |                                           S rR   )r    ru   rF   s    rB   get_unit_vectorzLine.get_unit_vector   s    **+++rC   c                D    t          |                                           S rR   )r   ru   rF   s    rB   	get_anglezLine.get_angle   s    t00111rC   pointc                    |                                  }|                                 }t          ||z
            }|t          t	          j        ||z
  |                    |z  z   S )zReturns the projection of a point onto a line.

        Parameters
        ----------
        point
            The point to which the line is projected.
        )rt   rs   r    r4   rM   dot)r@   rz   r0   r2   	unit_vects        rB   get_projectionzLine.get_projection   sY       llnncEk**	uRVEEM9==>>JJJrC   c                h    t          t          j        |                                                     S rR   )r4   rM   tanry   rF   s    rB   	get_slopezLine.get_slope  s$    RVDNN,,--...rC   rI   about_pointPoint3DLike | Nonec                    ||                                  }|                     ||                                 z
  |           | S )Nr   )rt   rotatery   )r@   rI   r   s      rB   	set_anglezLine.set_angle  sN    ..**KDNN$$$# 	 	
 	
 	

 rC   rX   c                Z    ||                                  z  }|                     |          S rR   )rU   scale)r@   rX   scale_factors      rB   
set_lengthzLine.set_length  s(    $t'8'88zz,'''rC   )r0   r1   r2   r1   r3   r4   r5   r4   r6   r   r7   r8   )r7   r8   )r   r   )
r0   r1   r2   r1   r3   r4   r5   r4   r7   r8   )r3   r4   r7   r8   )r0   r1   r2   r1   r7   r8   rR   )r_   r`   ra   rb   r7   r#   )ri   r4   r7   r8   )r0   r$   r2   r$   r7   r!   r7   r&   r7   r4   )rz   r$   r7   r#   )rI   r4   r   r   r7   r!   )rX   r4   r7   r!   )__name__
__module____qualname____doc__LEFTRIGHTr?   rG   rE   rS   rO   r=   r[   rk   ro   ru   rw   ry   r~   r   r   r   __classcell__rA   s   @rB   r   r   A   s        > (,%*# # # # # # #
 
 
 
 % % % % %>   R R R R. . . ." *.& & & & &0   !8 !8 !8 !8 !8 !8F1 1 1 1, , , ,2 2 2 2K K K K/ / / /	 	 	 	 	( ( ( ( ( ( ( (rC   r   c                  \     e Zd ZdZeddd fdZddZd fdZd fdZddZ	ddZ
 xZS )r   a  A dashed :class:`Line`.

    Parameters
    ----------
    args
        Arguments to be passed to :class:`Line`
    dash_length
        The length of each individual dash of the line.
    dashed_ratio
        The ratio of dash space to empty space. Range of 0-1.
    kwargs
        Additional arguments to be passed to :class:`Line`


    .. seealso::
        :class:`~.DashedVMobject`

    Examples
    --------
    .. manim:: DashedLineExample
        :save_last_frame:

        class DashedLineExample(Scene):
            def construct(self):
                # dash_length increased
                dashed_1 = DashedLine(config.left_side, config.right_side, dash_length=2.0).shift(UP*2)
                # normal
                dashed_2 = DashedLine(config.left_side, config.right_side)
                # dashed_ratio decreased
                dashed_3 = DashedLine(config.left_side, config.right_side, dashed_ratio=0.1).shift(DOWN*2)
                self.add(dashed_1, dashed_2, dashed_3)
    g      ?)dash_lengthdashed_ratioargsr   r   r4   r   r6   r7   r8   c                   || _         || _         t                      j        |i | t	          | |                                 |          }|                                   | j        |  d S )N)
num_dashesr   )r   r   r>   r?   r   _calculate_num_dashesclear_pointsadd)r@   r   r   r   r6   dashesrA   s         rB   r?   zDashedLine.__init__8  s     '($)&)))1133%
 
 

 	&rC   intc           	         t          dt          t          j        |                                 | j        z  | j        z                                S )zReturns the number of dashes in the dashed line.

        Examples
        --------
        ::

            >>> DashedLine()._calculate_num_dashes()
            20
        r)   )maxr   rM   ceilrU   r   r   rF   s    rB   r   z DashedLine._calculate_num_dashesJ  sH     **T-==ARRSSTT
 
 	
rC   r#   c                    t          | j                  dk    r| j        d                                         S t                                                      S )zReturns the start point of the line.

        Examples
        --------
        ::

            >>> DashedLine().get_start()
            array([-1.,  0.,  0.])
        r   )lensubmobjectsrt   r>   r@   rA   s    rB   rt   zDashedLine.get_startZ  sK     t  1$$#A&0022277$$&&&rC   c                    t          | j                  dk    r| j        d                                         S t                                                      S )zReturns the end point of the line.

        Examples
        --------
        ::

            >>> DashedLine().get_end()
            array([1., 0., 0.])
        r   r,   )r   r   rs   r>   r   s    rB   rs   zDashedLine.get_endi  sI     t  1$$#B'//11177??$$$rC   c                6    | j         d         j        d         }|S )zReturns the point of the first handle.

        Examples
        --------
        ::

            >>> DashedLine().get_first_handle()
            array([-0.98333333,  0.        ,  0.        ])
        r   r-   r   rK   )r@   first_handles     rB   get_first_handlezDashedLine.get_first_handlex  s     !% 0 3 :1 =rC   c                6    | j         d         j        d         }|S )zReturns the point of the last handle.

        Examples
        --------
        ::

            >>> DashedLine().get_last_handle()
            array([0.98333333, 0.        , 0.        ])
        r,   r)   r   )r@   last_handles     rB   get_last_handlezDashedLine.get_last_handle  s      $/3:1=rC   )
r   r   r   r4   r   r4   r6   r   r7   r8   )r7   r   )r7   r#   )r   r   r   r   DEFAULT_DASH_LENGTHr?   r   rt   rs   r   r   r   r   s   @rB   r   r     s         H 1!	       $
 
 
 
 ' ' ' ' ' '% % % % % %           rC   r   c                  *     e Zd ZdZ	 	 dd fdZ xZS )r   a  Constructs a line tangent to a :class:`~.VMobject` at a specific point.

    Parameters
    ----------
    vmob
        The VMobject on which the tangent line is drawn.
    alpha
        How far along the shape that the line will be constructed. range: 0-1.
    length
        Length of the tangent line.
    d_alpha
        The ``dx`` value
    kwargs
        Additional arguments to be passed to :class:`Line`


    .. seealso::
        :meth:`~.VMobject.point_from_proportion`

    Examples
    --------
    .. manim:: TangentLineExample
        :save_last_frame:

        class TangentLineExample(Scene):
            def construct(self):
                circle = Circle(radius=2)
                line_1 = TangentLine(circle, alpha=0.0, length=4, color=BLUE_D) # right
                line_2 = TangentLine(circle, alpha=0.4, length=4, color=GREEN) # top left
                self.add(circle, line_1, line_2)
    r-   ư>vmobr   alphar4   rX   d_alphar6   r   r7   r8   c                v   || _         || _        | j        }t          j        ||z
  dd          }t          j        ||z   dd          } t	                      j        |                    |          |                    |          fi | |                     | j         |                                 z             d S )Nr   r-   )	rX   r   rM   clipr>   r?   point_from_proportionr   rU   )
r@   r   r   rX   r   r6   daa1a2rA   s
            rB   r?   zTangentLine.__init__  s     \WURZA&&WURZA&&&&r**D,F,Fr,J,J	
 	
NT	
 	
 	
 	

4;!2!2233333rC   )r-   r   )r   r   r   r4   rX   r4   r   r4   r6   r   r7   r8   r   r   r   r   r?   r   r   s   @rB   r   r     sU         H 4 4 4 4 4 4 4 4 4 4 4rC   r   c                  &     e Zd ZdZdd fdZ xZS )r   a  Two lines that create a right angle about each other: L-shape.

    Parameters
    ----------
    width
        The length of the elbow's sides.
    angle
        The rotation of the elbow.
    kwargs
        Additional arguments to be passed to :class:`~.VMobject`

    .. seealso::
        :class:`RightAngle`

    Examples
    --------
    .. manim:: ElbowExample
        :save_last_frame:

        class ElbowExample(Scene):
            def construct(self):
                elbow_1 = Elbow()
                elbow_2 = Elbow(width=2.0)
                elbow_3 = Elbow(width=2.0, angle=5*PI/4)

                elbow_group = Group(elbow_1, elbow_2, elbow_3).arrange(buff=1)
                self.add(elbow_group)
    皙?r   widthr4   rI   r6   r   r7   r8   c                D   || _          t                      j        di | |                     t	          j        t          t          t          z   t          g                     |                     |t                     | 
                    | j         t                     d S )Nr   r;   )rI   r>   r?   rL   rM   rg   UPr   scale_to_fit_widthORIGINr   )r@   r   rI   r6   rA   s       rB   r?   zElbow.__init__  s    
""6"""""28ReU,C#D#DEEE6:::DJF33333rC   )r   r   )r   r4   rI   r4   r6   r   r7   r8   r   r   s   @rB   r   r     sL         :4 4 4 4 4 4 4 4 4 4 4rC   r   )	metaclassc                  ^     e Zd ZdZdedddd fdZdd fdZddZd dZd!dZ	d dZ
 xZS )"r   a  An arrow.

    Parameters
    ----------
    args
        Arguments to be passed to :class:`Line`.
    stroke_width
        The thickness of the arrow. Influenced by :attr:`max_stroke_width_to_length_ratio`.
    buff
        The distance of the arrow from its start and end points.
    max_tip_length_to_length_ratio
        :attr:`tip_length` scales with the length of the arrow. Increasing this ratio raises the max value of :attr:`tip_length`.
    max_stroke_width_to_length_ratio
        :attr:`stroke_width` scales with the length of the arrow. Increasing this ratio ratios the max value of :attr:`stroke_width`.
    kwargs
        Additional arguments to be passed to :class:`Line`.


    .. seealso::
        :class:`ArrowTip`
        :class:`CurvedArrow`

    Examples
    --------
    .. manim:: ArrowExample
        :save_last_frame:

        from manim.mobject.geometry.tips import ArrowSquareTip
        class ArrowExample(Scene):
            def construct(self):
                arrow_1 = Arrow(start=RIGHT, end=LEFT, color=GOLD)
                arrow_2 = Arrow(start=RIGHT, end=LEFT, color=GOLD, tip_shape=ArrowSquareTip).shift(DOWN)
                g1 = Group(arrow_1, arrow_2)

                # the effect of buff
                square = Square(color=MAROON_A)
                arrow_3 = Arrow(start=LEFT, end=RIGHT)
                arrow_4 = Arrow(start=LEFT, end=RIGHT, buff=0).next_to(arrow_1, UP)
                g2 = Group(arrow_3, arrow_4, square)

                # a shorter arrow has a shorter tip and smaller stroke width
                arrow_5 = Arrow(start=ORIGIN, end=config.top).shift(LEFT * 4)
                arrow_6 = Arrow(start=config.top + DOWN, end=config.top).shift(LEFT * 3)
                g3 = Group(arrow_5, arrow_6)

                self.add(Group(g1, g2, g3).arrange(buff=2))


    .. manim:: ArrowExample
        :save_last_frame:

        class ArrowExample(Scene):
            def construct(self):
                left_group = VGroup()
                # As buff increases, the size of the arrow decreases.
                for buff in np.arange(0, 2.2, 0.45):
                    left_group += Arrow(buff=buff, start=2 * LEFT, end=2 * RIGHT)
                # Required to arrange arrows.
                left_group.arrange(DOWN)
                left_group.move_to(4 * LEFT)

                middle_group = VGroup()
                # As max_stroke_width_to_length_ratio gets bigger,
                # the width of stroke increases.
                for i in np.arange(0, 5, 0.5):
                    middle_group += Arrow(max_stroke_width_to_length_ratio=i)
                middle_group.arrange(DOWN)

                UR_group = VGroup()
                # As max_tip_length_to_length_ratio increases,
                # the length of the tip increases.
                for i in np.arange(0, 0.3, 0.1):
                    UR_group += Arrow(max_tip_length_to_length_ratio=i)
                UR_group.arrange(DOWN)
                UR_group.move_to(4 * RIGHT + 2 * UP)

                DR_group = VGroup()
                DR_group += Arrow(start=LEFT, end=RIGHT, color=BLUE, tip_shape=ArrowSquareTip)
                DR_group += Arrow(start=LEFT, end=RIGHT, color=BLUE, tip_shape=ArrowSquareFilledTip)
                DR_group += Arrow(start=LEFT, end=RIGHT, color=YELLOW, tip_shape=ArrowCircleTip)
                DR_group += Arrow(start=LEFT, end=RIGHT, color=YELLOW, tip_shape=ArrowCircleFilledTip)
                DR_group.arrange(DOWN)
                DR_group.move_to(4 * RIGHT + 2 * DOWN)

                self.add(left_group, middle_group, UR_group, DR_group)
       g      ?   )stroke_widthr3   max_tip_length_to_length_ratio max_stroke_width_to_length_ratior   r   r   r4   r3   r   r   r6   r7   r8   c                   || _         || _        |                    dt                    } t	                      j        |||d| | j        | _        |                     |           | 	                                 d S )N	tip_shape)r3   r   )r   )
r   r   popr   r>   r?   r   initial_stroke_widthadd_tip_set_stroke_width_from_length)	r@   r   r3   r   r   r   r6   r   rA   s	           rB   r?   zArrow.__init__K  s     /M+0P-JJ{,BCC	$TOOOOO %)$5!y)))**,,,,,rC   Ffactor
scale_tipsboolr!   c                   |                                  dk    r| S |r0 t                      j        |fi | |                                  | S |                                 }|                                 }|s|r|                                 } t                      j        |fi | |                                  |r|                     |d                    |r|                     |d         d           | S )a~  Scale an arrow, but keep stroke width and arrow tip size fixed.


        .. seealso::
            :meth:`~.Mobject.scale`

        Examples
        --------
        ::

            >>> arrow = Arrow(np.array([-1, -1, 0]), np.array([1, 1, 0]), buff=0)
            >>> scaled_arrow = arrow.scale(2)
            >>> np.round(scaled_arrow.get_start_and_end(), 8) + 0
            array([[-2., -2.,  0.],
                   [ 2.,  2.,  0.]])
            >>> arrow.tip.length == scaled_arrow.tip.length
            True

        Manually scaling the object using the default method
        :meth:`~.Mobject.scale` does not have the same properties::

            >>> new_arrow = Arrow(np.array([-1, -1, 0]), np.array([1, 1, 0]), buff=0)
            >>> another_scaled_arrow = VMobject.scale(new_arrow, 2)
            >>> another_scaled_arrow.tip.length == arrow.tip.length
            False

        r   )tipr-   T)r   at_start)rU   r>   r   r   has_tiphas_start_tippop_tipsr   )r@   r   r   r6   r   r   old_tipsrA   s          rB   r   zArrow.scale^  s   8 ??!!K 	EGGM&++F+++..000K,,..**,, 	'm 	'}}Hf'''''**,,, 	*LLXa[L))) 	9LLXa[4L888rC   r&   c                    | j                                         dd         \  }}}t          t          j        ||z
  ||z
                      S )zReturns the normal of a vector.

        Examples
        --------
        ::

            >>> np.round(Arrow().get_normal_vector()) + 0. # add 0. to avoid negative 0 in output
            array([ 0.,  0., -1.])
        Nr:   )r   get_start_anchorsr    rM   cross)r@   p0p1p2s       rB   get_normal_vectorzArrow.get_normal_vector  sH     X//11"1"5
B"r'2733444rC   c                8    |                                  | _        | S )zResets the normal of a vector)r   normal_vectorrF   s    rB   reset_normal_vectorzArrow.reset_normal_vector  s    !3355rC   c                d    | j         }t          | j        ||                                 z            S )zReturns the default tip_length of the arrow.

        Examples
        --------

        ::

            >>> Arrow().get_default_tip_length()
            0.35
        )r   min
tip_lengthrU   r@   	max_ratios     rB   get_default_tip_lengthzArrow.get_default_tip_length  s-     7	4?I0A0A$ABBBrC   c                F   | j         }t          j        t          j        k    r@|                     t          | j        ||                                 z            d           n?|                     t          | j        ||                                 z            d           | S )z"Sets stroke width based on length.F)r   recurse)r   family)	r   r   rendererRendererTypeOPENGL
set_stroker   r   rU   r   s     rB   r   z#Arrow._set_stroke_width_from_length  s    9	?l111
 OO$3YARAR5RSS     
 OO$3YARAR5RSS     rC   )r   r   r   r4   r3   r4   r   r4   r   r4   r6   r   r7   r8   F)r   r4   r   r   r6   r   r7   r!   r   )r7   r!   r   )r   r   r   r   MED_SMALL_BUFFr?   r   r   r   r   r   r   r   s   @rB   r   r     s        U Ut  $0423- - - - - - - -&0 0 0 0 0 0 0d5 5 5 5   
C C C C       rC   r   c                  :     e Zd ZdZedfd fdZ	 	 	 dddZ xZS )r	   a  A vector specialized for use in graphs.

    .. caution::
        Do not confuse with the :class:`~.Vector2D`,
        :class:`~.Vector3D` or :class:`~.VectorND` type aliases,
        which are not Mobjects!

    Parameters
    ----------
    direction
        The direction of the arrow.
    buff
         The distance of the vector from its endpoints.
    kwargs
        Additional arguments to be passed to :class:`Arrow`

    Examples
    --------
    .. manim:: VectorExample
        :save_last_frame:

        class VectorExample(Scene):
            def construct(self):
                plane = NumberPlane()
                vector_1 = Vector([1,2])
                vector_2 = Vector([-5,-2])
                self.add(plane, vector_1, vector_2)
    r   ra   Vector2DLike | Vector3DLiker3   r4   r6   r   r7   r8   c                    || _         t          |          dk    rt          j        |dg          } t	                      j        t          |fd|i| d S )Nr)   r   r3   )r3   r   rM   hstackr>   r?   r   )r@   ra   r3   r6   rA   s       rB   r?   zVector.__init__  s\     	y>>Q	9a.11I@@@@@@@@rC   Tr)   Ninteger_labelsr   n_dimr   colorParsableManimColor | Noner+   c                   ddl m} t          j        |                                           }|r,t          j        |                              t                    }|d|         }|                    |df          } ||fi |}|	                    t          dz
             t          j        |                                           }|d         dk    r(||                                t          t          z  z   z  }n'||                                t          t          z  z   z  }|                    |           ||                    |           |S )a  Creates a label based on the coordinates of the vector.

        Parameters
        ----------
        integer_labels
            Whether or not to round the coordinates to integers.
        n_dim
            The number of dimensions of the vector.
        color
            Sets the color of label, optional.
        kwargs
            Additional arguments to be passed to :class:`~.Matrix`.

        Returns
        -------
        :class:`~.Matrix`
            The label.

        Examples
        --------
        .. manim:: VectorCoordinateLabel
            :save_last_frame:

            class VectorCoordinateLabel(Scene):
                def construct(self):
                    plane = NumberPlane()

                    vec_1 = Vector([1, 2])
                    vec_2 = Vector([-3, -2])
                    label_1 = vec_1.coordinate_label()
                    label_2 = vec_2.coordinate_label(color=YELLOW)

                    self.add(plane, vec_1, vec_2, label_1, label_2)
        r)   r*   Nr-   r   r   )matrixr+   rM   rg   rs   roundastyper   reshaper   
LARGE_BUFFget_left!DEFAULT_MOBJECT_TO_MOBJECT_BUFFERr   	get_rightr   shift	set_color)	r@   r   r   r   r6   r+   r^   label	shift_dirs	            rB   coordinate_labelzVector.coordinate_label  s8   T 	$#####x'' 	.8D>>((--DFUF|||UAJ''t&&v&&J$%%%HT\\^^,,	Q<1)),MPT,TTTII**-NQV-VVVIIOOE"""rC   )ra   r   r3   r4   r6   r   r7   r8   )Tr)   N)
r   r   r   r   r   r   r6   r   r7   r+   )r   r   r   r   r   r?   r	  r   r   s   @rB   r	   r	     s         > 27
A 
A 
A 
A 
A 
A 
A  $+/	< < < < < < < < <rC   r	   c                  $     e Zd ZdZd fdZ xZS )	r
   a  An arrow with tips on both ends.

    Parameters
    ----------
    args
        Arguments to be passed to :class:`Arrow`
    kwargs
        Additional arguments to be passed to :class:`Arrow`


    .. seealso::
        :class:`.~ArrowTip`
        :class:`.~CurvedDoubleArrow`

    Examples
    --------
    .. manim:: DoubleArrowExample
        :save_last_frame:

        from manim.mobject.geometry.tips import ArrowCircleFilledTip
        class DoubleArrowExample(Scene):
            def construct(self):
                circle = Circle(radius=2.0)
                d_arrow = DoubleArrow(start=circle.get_left(), end=circle.get_right())
                d_arrow_2 = DoubleArrow(tip_shape_end=ArrowCircleFilledTip, tip_shape_start=ArrowCircleFilledTip)
                group = Group(Group(circle, d_arrow), d_arrow_2).arrange(UP, buff=1)
                self.add(group)


    .. manim:: DoubleArrowExample2
        :save_last_frame:

        class DoubleArrowExample2(Scene):
            def construct(self):
                box = Square()
                p1 = box.get_left()
                p2 = box.get_right()
                d1 = DoubleArrow(p1, p2, buff=0)
                d2 = DoubleArrow(p1, p2, buff=0, tip_length=0.2, color=YELLOW)
                d3 = DoubleArrow(p1, p2, buff=0, tip_length=0.4, color=BLUE)
                Group(d1, d2, d3).arrange(DOWN)
                self.add(box, d1, d2, d3)
    r   r   r6   r7   r8   c                    d|v r|                     d          |d<   |                     dt                    } t                      j        |i | |                     d|           d S )Ntip_shape_endr   tip_shape_startT)r   r   )r   r   r>   r?   r   )r@   r   r6   r  rA   s       rB   r?   zDoubleArrow.__init__Z  sq    f$$"(**_"="=F; **%68NOO$)&)))do>>>>>rC   )r   r   r6   r   r7   r8   r   r   s   @rB   r
   r
   -  sH        * *X? ? ? ? ? ? ? ? ? ?rC   r
   c                  `     e Zd ZdZddddddedfd$ fdZd%dZd&d'dZed(d#            Z	 xZ
S ))r   aG  A circular arc or elbow-type mobject representing an angle of two lines.

    Parameters
    ----------
    line1 :
        The first line.
    line2 :
        The second line.
    radius :
        The radius of the :class:`Arc`.
    quadrant
        A sequence of two :class:`int` numbers determining which of the 4 quadrants should be used.
        The first value indicates whether to anchor the arc on the first line closer to the end point (1)
        or start point (-1), and the second value functions similarly for the
        end (1) or start (-1) of the second line.
        Possibilities: (1,1), (-1,1), (1,-1), (-1,-1).
    other_angle :
        Toggles between the two possible angles defined by two points and an arc center. If set to
        False (default), the arc will always go counterclockwise from the point on line1 until
        the point on line2 is reached. If set to True, the angle will go clockwise from line1 to line2.
    dot
        Allows for a :class:`Dot` in the arc. Mainly used as an convention to indicate a right angle.
        The dot can be customized in the next three parameters.
    dot_radius
        The radius of the :class:`Dot`. If not specified otherwise, this radius will be 1/10 of the arc radius.
    dot_distance
        Relative distance from the center to the arc: 0 puts the dot in the center and 1 on the arc itself.
    dot_color
        The color of the :class:`Dot`.
    elbow
        Produces an elbow-type mobject indicating a right angle, see :class:`RightAngle` for more information
        and a shorthand.
    **kwargs
        Further keyword arguments that are passed to the constructor of :class:`Arc` or :class:`Elbow`.

    Examples
    --------
    The first example shows some right angles with a dot in the middle while the second example shows
    all 8 possible angles defined by two lines.

    .. manim:: RightArcAngleExample
        :save_last_frame:

        class RightArcAngleExample(Scene):
            def construct(self):
                line1 = Line( LEFT, RIGHT )
                line2 = Line( DOWN, UP )
                rightarcangles = [
                    Angle(line1, line2, dot=True),
                    Angle(line1, line2, radius=0.4, quadrant=(1,-1), dot=True, other_angle=True),
                    Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8, dot=True, dot_color=YELLOW, dot_radius=0.04, other_angle=True),
                    Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED, dot=True, dot_color=GREEN, dot_radius=0.08),
                ]
                plots = VGroup()
                for angle in rightarcangles:
                    plot=VGroup(line1.copy(),line2.copy(), angle)
                    plots.add(plot)
                plots.arrange(buff=1.5)
                self.add(plots)

    .. manim:: AngleExample
        :save_last_frame:

        class AngleExample(Scene):
            def construct(self):
                line1 = Line( LEFT + (1/3) * UP, RIGHT + (1/3) * DOWN )
                line2 = Line( DOWN + (1/3) * RIGHT, UP + (1/3) * LEFT )
                angles = [
                    Angle(line1, line2),
                    Angle(line1, line2, radius=0.4, quadrant=(1,-1), other_angle=True),
                    Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8, other_angle=True),
                    Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED),
                    Angle(line1, line2, other_angle=True),
                    Angle(line1, line2, radius=0.4, quadrant=(1,-1)),
                    Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8),
                    Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED, other_angle=True),
                ]
                plots = VGroup()
                for angle in angles:
                    plot=VGroup(line1.copy(),line2.copy(), angle)
                    plots.add(VGroup(plot,SurroundingRectangle(plot, buff=0.3)))
                plots.arrange_in_grid(rows=2,buff=1)
                self.add(plots)

    .. manim:: FilledAngle
        :save_last_frame:

        class FilledAngle(Scene):
            def construct(self):
                l1 = Line(ORIGIN, 2 * UP + RIGHT).set_color(GREEN)
                l2 = (
                    Line(ORIGIN, 2 * UP + RIGHT)
                    .set_color(GREEN)
                    .rotate(-20 * DEGREES, about_point=ORIGIN)
                )
                norm = l1.get_length()
                a1 = Angle(l1, l2, other_angle=True, radius=norm - 0.5).set_color(GREEN)
                a2 = Angle(l1, l2, other_angle=True, radius=norm).set_color(GREEN)
                q1 = a1.points #  save all coordinates of points of angle a1
                q2 = a2.reverse_direction().points  #  save all coordinates of points of angle a1 (in reversed direction)
                pnts = np.concatenate([q1, q2, q1[0].reshape(1, 3)])  # adds points and ensures that path starts and ends at same point
                mfill = VMobject().set_color(ORANGE)
                mfill.set_points_as_corners(pnts).set_fill(GREEN, opacity=1)
                self.add(l1, l2)
                self.add(mfill)

    N)r-   r-   Fg?line1r   line2radiusfloat | Nonequadrantr.   other_angler   r|   
dot_radiusdot_distancer4   	dot_colorr(   elbowr6   r   r7   r8   c                    t                      j        di | ||f| _        || _        || _        |
| _        t          |                                |                                g|                                |                                g          }||d         dk    r5t          j
                            |                                |z
            }n4t          j
                            |                                |z
            }|d         dk    r5t          j
                            |                                |z
            }n4t          j
                            |                                |z
            }t          j        ||          dk     rdt          j        ||          z  }n
d}n|| _        ||d         |z  |                                z  z   }||d         |z  |                                z  z   }|
r|||d         |z  |                                z  z   |d         |z  |                                z  z   }t          di |}|                    t          j        |||g                     n2t%          ||z
            }t%          ||z
            }|s$|}||k    r||z
  }n:dt          j        z  ||z
  z
  }n$|}||k     r| |z   }ndt          j        z  ||z
  z   }|| _        t+          d|| j        ||d|}|r||d	z  }n|| _        t/          t0          ||	
          }||                                |z
  t          j
                            |                                |z
            z  |z  |z  z   }|                    |           |                     |           |                     |j                   d S )Nr   r-   g333333?gUUUUUU?g?r)   )r  rI   start_angle
arc_center
   )r  r   r;   )r>   r?   linesr  r  r  r   rt   rs   rM   linalgnormminimumr  rw   r   rL   rg   r   piangle_valuer   r  r   r   re   move_tor   rJ   rK   )r@   r  r  r  r  r  r|   r  r  r  r  r6   interdist_1dist_2anchor_angle_1anchor_angle_2anchor_middleangle_mobjectangle_1angle_2r  	angle_fin	right_dot
dot_anchorrA   s                            rB   r?   zAngle.__init__  s    	""6"""U^
 (
!__0__0
 

 >{a%(?@@(9(9E(ABB{a%(?@@(9(9E(ABBz&&))C//2:ff#=#== DK!v!58M8M8O8O!OO!v!58M8M8O8O!OO 3	$1+&)>)>)@)@@A1+&)>)>)@)@@A 
 ',oofooM//.-HII    &nu&<==G%nu&<==G A%W$$ '' 1II !BE	Ww-> ?II%W$$!(7 2II "RU
g.? @I(D &' 	 
  M  $%!'"JJ&0DOzKKK	$//11E9inn]%=%=%?%?%%GHHI ###  !!*---###,-----rC   r   c                    t          | j         S )a  Get the lines forming an angle of the :class:`Angle` class.

        Returns
        -------
        :class:`~.VGroup`
            A :class:`~.VGroup` containing the lines that form the angle of the :class:`Angle` class.

        Examples
        --------
        ::

            >>> line_1, line_2 = Line(ORIGIN, RIGHT), Line(ORIGIN, UR)
            >>> angle = Angle(line_1, line_2)
            >>> angle.get_lines()
            VGroup(Line, Line)
        )r   r  rF   s    rB   	get_lineszAngle.get_lines1  s    " tz""rC   degreesc                2    |r| j         t          z  n| j         S )a  Get the value of an angle of the :class:`Angle` class.

        Parameters
        ----------
        degrees
            A boolean to decide the unit (deg/rad) in which the value of the angle is returned.

        Returns
        -------
        :class:`float`
            The value in degrees/radians of an angle of the :class:`Angle` class.

        Examples
        --------

        .. manim:: GetValueExample
            :save_last_frame:

            class GetValueExample(Scene):
                def construct(self):
                    line1 = Line(LEFT+(1/3)*UP, RIGHT+(1/3)*DOWN)
                    line2 = Line(DOWN+(1/3)*RIGHT, UP+(1/3)*LEFT)

                    angle = Angle(line1, line2, radius=0.4)

                    value = DecimalNumber(angle.get_value(degrees=True), unit=r"^{\circ}")
                    value.next_to(angle, UR)

                    self.add(line1, line2, angle, value)
        )r#  DEGREES)r@   r3  s     rB   	get_valuezAngle.get_valueD  s    > .5Jt'))$:JJrC   Ar$   BCc                V    t          t          ||           t          ||          fi |S )a  The angle between the lines AB and BC.

        This constructs the angle :math:`\\angle ABC`.

        Parameters
        ----------
        A
            The endpoint of the first angle leg
        B
            The vertex of the angle
        C
            The endpoint of the second angle leg

        **kwargs
            Further keyword arguments are passed to :class:`.Angle`

        Returns
        -------
        The Angle calculated from the three points

                    Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8),
                    Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED, other_angle=True),

        Examples
        --------
        .. manim:: AngleFromThreePointsExample
            :save_last_frame:

            class AngleFromThreePointsExample(Scene):
                def construct(self):
                    sample_angle = Angle.from_three_points(UP, ORIGIN, LEFT)
                    red_angle = Angle.from_three_points(LEFT + UP, ORIGIN, RIGHT, radius=.8, quadrant=(-1,-1), color=RED, stroke_width=8, other_angle=True)
                    self.add(red_angle, sample_angle)
        )r   r   )r7  r8  r9  r6   s       rB   from_three_pointszAngle.from_three_pointse  s-    L T!QZZa66v666rC   )r  r   r  r   r  r  r  r.   r  r   r|   r   r  r  r  r4   r  r(   r  r   r6   r   r7   r8   )r7   r   r   )r3  r   r7   r4   )
r7  r$   r8  r$   r9  r$   r6   r   r7   r   )r   r   r   r   r   r?   r2  r6  staticmethodr;  r   r   s   @rB   r   r   b  s        j j`  $"(!#'"(-`. `. `. `. `. `. `.D# # # #&K K K K KB %7 %7 %7 \%7 %7 %7 %7 %7rC   r   c                  (     e Zd ZdZ	 dd fdZ xZS )r   a  An elbow-type mobject representing a right angle between two lines.

    Parameters
    ----------
    line1
        The first line.
    line2
        The second line.
    length
        The length of the arms.
    **kwargs
        Further keyword arguments that are passed to the constructor of :class:`Angle`.

    Examples
    --------
    .. manim:: RightAngleExample
        :save_last_frame:

        class RightAngleExample(Scene):
            def construct(self):
                line1 = Line( LEFT, RIGHT )
                line2 = Line( DOWN, UP )
                rightangles = [
                    RightAngle(line1, line2),
                    RightAngle(line1, line2, length=0.4, quadrant=(1,-1)),
                    RightAngle(line1, line2, length=0.5, quadrant=(-1,1), stroke_width=8),
                    RightAngle(line1, line2, length=0.7, quadrant=(-1,-1), color=RED),
                ]
                plots = VGroup()
                for rightangle in rightangles:
                    plot=VGroup(line1.copy(),line2.copy(), rightangle)
                    plots.add(plot)
                plots.arrange(buff=1.5)
                self.add(plots)
    Nr  r   r  rX   r  r6   r   r7   r8   c                D     t                      j        ||f|dd| d S )NT)r  r  )r>   r?   )r@   r  r  rX   r6   rA   s        rB   r?   zRightAngle.__init__  s3     	KfDKKFKKKKKrC   rR   )
r  r   r  r   rX   r  r6   r   r7   r8   r   r   s   @rB   r   r     s]        " "P  $	L L L L L L L L L L LrC   r   );r   
__future__r   __all__typingr   r   r   numpyrM   manimr   manim.constantsmanim.mobject.geometry.arcr   r   r   r   manim.mobject.geometry.tipsr   manim.mobject.mobjectr   )manim.mobject.opengl.opengl_compatibilityr   #manim.mobject.opengl.opengl_mobjectr   &manim.mobject.types.vectorized_mobjectr   r   r   manim.utils.colorr   manim.utils.space_opsr   r   r    r!   r"   manim.typingr#   r$   r%   r&   r'   r(   r   r+   tupler.   __annotations__r   r   r   r   r   r	   r
   r   r   r;   rC   rB   <module>rP     s   5 5 5 " " " " " "
 
 
 / . . . . . . . . .               R R R R R R R R R R R R > > > > > > ) ) ) ) ) ) E E E E E E = = = = = = S S S S S S S S S S # # # # # # O O O O O O O O O O &&&&&&&&WWWWWWWWWWWWWW444444$WU^WU^%CDMDDDD0R( R( R( R( R(? R( R( R(j@ @ @ @ @ @ @ @F14 14 14 14 14$ 14 14 14h#4 #4 #4 #4 #4H #4 #4 #4 #4LN N N N ND N N Nbf f f f fU f f fR2? 2? 2? 2? 2?% 2? 2? 2?ji7 i7 i7 i7 i7H i7 i7 i7 i7X	,L ,L ,L ,L ,L ,L ,L ,L ,L ,LrC   