
    lj(                    |   d Z ddlmZ g dZddlmZmZ ddlZddl	T ddl
mZ ddlmZmZ dd	lmZ dd
lmZ ddlmZ erddlmZmZ  G d dee          Z G d de          Z G d dee          Z G d de          Z G d dee          Z G d de          Z G d dee          Z G d de          ZdS )zEA collection of tip mobjects for use with :class:`~.TipableVMobject`.    )annotations)ArrowTipArrowCircleFilledTipArrowCircleTipArrowSquareTipArrowSquareFilledTipArrowTriangleTipArrowTriangleFilledTip
StealthTip)TYPE_CHECKINGAnyN)*)Circle)SquareTriangle)ConvertToOpenGL)VMobject)angle_of_vector)Point3DVector3Dc                      e Zd ZdZddZedd	            Zedd
            Zedd            Zedd            Z	edd            Z
dS )r   a  Base class for arrow tips.

    .. seealso::
        :class:`ArrowTriangleTip`
        :class:`ArrowTriangleFilledTip`
        :class:`ArrowCircleTip`
        :class:`ArrowCircleFilledTip`
        :class:`ArrowSquareTip`
        :class:`ArrowSquareFilledTip`
        :class:`StealthTip`

    Examples
    --------
    Cannot be used directly, only intended for inheritance::

        >>> tip = ArrowTip()
        Traceback (most recent call last):
        ...
        NotImplementedError: Has to be implemented in inheriting subclasses.

    Instead, use one of the pre-defined ones, or make
    a custom one like this:

    .. manim:: CustomTipExample

        >>> from manim import RegularPolygon, Arrow
        >>> class MyCustomArrowTip(ArrowTip, RegularPolygon):
        ...     def __init__(self, length=0.35, **kwargs):
        ...         RegularPolygon.__init__(self, n=5, **kwargs)
        ...         self.width = length
        ...         self.stretch_to_fit_height(length)
        >>> arr = Arrow(
        ...     np.array([-2, -2, 0]), np.array([2, 2, 0]), tip_shape=MyCustomArrowTip
        ... )
        >>> isinstance(arr.tip, RegularPolygon)
        True
        >>> from manim import Scene, Create
        >>> class CustomTipExample(Scene):
        ...     def construct(self):
        ...         self.play(Create(arr))

    Using a class inherited from :class:`ArrowTip` to get a non-filled
    tip is a shorthand to manually specifying the arrow tip style as follows::

        >>> arrow = Arrow(np.array([0, 0, 0]), np.array([1, 1, 0]),
        ...               tip_style={'fill_opacity': 0, 'stroke_width': 3})

    The following example illustrates the usage of all of the predefined
    arrow tips.

    .. manim:: ArrowTipsShowcase
        :save_last_frame:

        class ArrowTipsShowcase(Scene):
            def construct(self):
                tip_names = [
                    'Default (YELLOW)', 'ArrowTriangleTip', 'Default', 'ArrowSquareTip',
                    'ArrowSquareFilledTip', 'ArrowCircleTip', 'ArrowCircleFilledTip', 'StealthTip'
                ]

                big_arrows = [
                    Arrow(start=[-4, 3.5, 0], end=[2, 3.5, 0], color=YELLOW),
                    Arrow(start=[-4, 2.5, 0], end=[2, 2.5, 0], tip_shape=ArrowTriangleTip),
                    Arrow(start=[-4, 1.5, 0], end=[2, 1.5, 0]),
                    Arrow(start=[-4, 0.5, 0], end=[2, 0.5, 0], tip_shape=ArrowSquareTip),

                    Arrow([-4, -0.5, 0], [2, -0.5, 0], tip_shape=ArrowSquareFilledTip),
                    Arrow([-4, -1.5, 0], [2, -1.5, 0], tip_shape=ArrowCircleTip),
                    Arrow([-4, -2.5, 0], [2, -2.5, 0], tip_shape=ArrowCircleFilledTip),
                    Arrow([-4, -3.5, 0], [2, -3.5, 0], tip_shape=StealthTip)
                ]

                small_arrows = (
                    arrow.copy().scale(0.5, scale_tips=True).next_to(arrow, RIGHT) for arrow in big_arrows
                )

                labels = (
                    Text(tip_names[i], font='monospace', font_size=20, color=BLUE).next_to(big_arrows[i], LEFT) for i in range(len(big_arrows))
                )

                self.add(*big_arrows, *small_arrows, *labels)
    argsr   kwargsreturnNonec                     t          d          )Nz/Has to be implemented in inheriting subclasses.)NotImplementedError)selfr   r   s      V/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/mobject/geometry/tips.py__init__zArrowTip.__init__s   s    !"STTT    r   c                ,    |                      d          S )a  The base point of the arrow tip.

        This is the point connecting to the arrow line.

        Examples
        --------
        ::

            >>> from manim import Arrow
            >>> arrow = Arrow(np.array([0, 0, 0]), np.array([2, 0, 0]), buff=0)
            >>> arrow.tip.base.round(2) + 0.  # add 0. to avoid negative 0 in output
            array([1.65, 0.  , 0.  ])

        g      ?)point_from_proportionr   s    r   basezArrowTip.basev   s      ))#...r!   c                     | j         d         }|S )a"  The tip point of the arrow tip.

        Examples
        --------
        ::

            >>> from manim import Arrow
            >>> arrow = Arrow(np.array([0, 0, 0]), np.array([2, 0, 0]), buff=0)
            >>> arrow.tip.tip_point.round(2) + 0.
            array([2., 0., 0.])

        r   )points)r   	tip_points     r   r(   zArrowTip.tip_point   s    " "[^	r!   r   c                     | j         | j        z
  S )a?  The vector pointing from the base point to the tip point.

        Examples
        --------
        ::

            >>> from manim import Arrow
            >>> arrow = Arrow(np.array([0, 0, 0]), np.array([2, 2, 0]), buff=0)
            >>> arrow.tip.vector.round(2) + 0.
            array([0.25, 0.25, 0.  ])

        )r(   r%   r$   s    r   vectorzArrowTip.vector   s     ~	))r!   floatc                *    t          | j                  S )a#  The angle of the arrow tip.

        Examples
        --------
        ::

            >>> from manim import Arrow
            >>> arrow = Arrow(np.array([0, 0, 0]), np.array([1, 1, 0]), buff=0)
            >>> bool(round(arrow.tip.tip_angle, 5) == round(PI/4, 5))
            True

        )r   r*   r$   s    r   	tip_anglezArrowTip.tip_angle   s     t{+++r!   c                d    t          t          j                            | j                            S )a  The length of the arrow tip.

        Examples
        --------
        ::

            >>> from manim import Arrow
            >>> arrow = Arrow(np.array([0, 0, 0]), np.array([1, 2, 0]))
            >>> round(arrow.tip.length, 3)
            0.35

        r+   nplinalgnormr*   r$   s    r   lengthzArrowTip.length   s"     RY^^DK00111r!   N)r   r   r   r   r   r   )r   r   )r   r   r   r+   )__name__
__module____qualname____doc__r    propertyr%   r(   r*   r-   r3    r!   r   r   r      s        Q QfU U U U / / / X/"    X& * * * X* , , , X, 2 2 2 X2 2 2r!   r   )	metaclassc                  B    e Zd ZdZddedz  efddZedd            ZdS )r   z'Stealth' fighter / kite arrow shape.

    Naming is inspired by the corresponding
    `TikZ arrow shape <https://tikz.dev/tikz-arrows#sec-16.3>`__.
             fill_opacityr+   stroke_widthr3   start_angler   r   c           
         || _         t          j        | f||d| |                     t	          j        g dg dg dg dg dg                     |                     || j        z             d S )Nr@   rA   )r?   r   r   )333333皙?r   )r   r   r   )rE   gr   )rB   r   r    set_points_as_cornersr0   arrayscaler3   r   r@   rA   r3   rB   r   s         r   r    zStealthTip.__init__   s     '	
+,	
 	
JP	
 	
 	
 	""HII"NNII#OOII 
	
 
	
 
	
 	

6DK'(((((r!   r   c                j    t          t          j                            | j                  dz            S )zThe length of the arrow tip.

        In this case, the length is computed as the height of
        the triangle encompassing the stealth tip (otherwise,
        the tip is scaled too large).
        rF   r/   r$   s    r   r3   zStealthTip.length   s'     RY^^DK0036777r!   N)
r@   r+   rA   r+   r3   r+   rB   r+   r   r   r4   )	r5   r6   r7   r8   DEFAULT_ARROW_TIP_LENGTHPIr    r9   r3   r:   r!   r   r   r      sj           014) ) ) ) )2 8 8 8 X8 8 8r!   r   c                  &    e Zd ZdZddeeefddZdS )r	   zTriangular arrow tip.r   r>   r@   r+   rA   r3   widthrB   r   r   r   r   c                    t          j        | f|||d| || _        |                     |           |                     |           d S )N)r@   rA   rB   )r   r    rO   stretch_to_fit_widthstretch_to_fit_height)r   r@   rA   r3   rO   rB   r   s          r   r    zArrowTriangleTip.__init__   sp     		
%%#		
 	

 	
 	
 	
 
!!&)))""5)))))r!   N)r@   r+   rA   r+   r3   r+   rO   r+   rB   r+   r   r   r   r   r5   r6   r7   r8   rL   rM   r    r:   r!   r   r	   r	      sD            0/* * * * * * *r!   r	   c                  (     e Zd ZdZ	 dd fdZ xZS )r
   zTTriangular arrow tip with filled tip.

    This is the default arrow tip shape.
    r=   r   r@   r+   rA   r   r   r   r   c                @     t                      j        d||d| d S NrD   r:   superr    r   r@   rA   r   	__class__s       r   r    zArrowTriangleFilledTip.__init__  0     	XlXXQWXXXXXr!   r=   r   r@   r+   rA   r+   r   r   r   r   r5   r6   r7   r8   r    __classcell__rZ   s   @r   r
   r
     s\          >?Y Y Y Y Y Y Y Y Y Y Yr!   r
   c                  $    e Zd ZdZddeefddZdS )r   zCircular arrow tip.r   r>   r@   r+   rA   r3   rB   r   r   r   r   c                v    || _         t          j        | f||d| || _        |                     |           d S )NrD   )rB   r   r    rO   rR   rJ   s         r   r    zArrowCircleTip.__init__   s]     '	
+,	
 	
JP	
 	
 	
 
""6*****r!   Nr@   r+   rA   r+   r3   r+   rB   r+   r   r   r   r   rS   r:   r!   r   r   r     sA          0+ + + + + + +r!   r   c                  (     e Zd ZdZ	 dd fdZ xZS )r   z#Circular arrow tip with filled tip.r=   r   r@   r+   rA   r   r   r   r   c                @     t                      j        d||d| d S rV   rW   rY   s       r   r    zArrowCircleFilledTip.__init__3  r[   r!   r\   r]   r^   r`   s   @r   r   r   0  sX        .. >?Y Y Y Y Y Y Y Y Y Y Yr!   r   c                  $    e Zd ZdZddeefddZdS )r   zSquare arrow tip.r   r>   r@   r+   rA   r3   rB   r   r   r   r   c                x    || _         t          j        | f|||d| || _        |                     |           d S )N)r@   rA   side_length)rB   r   r    rO   rR   rJ   s         r   r    zArrowSquareTip.__init__<  sc     '	
%%		
 	

 	
 	
 	
 
""6*****r!   Nrc   rS   r:   r!   r   r   r   9  sA          0+ + + + + + +r!   r   c                  (     e Zd ZdZ	 dd fdZ xZS )r   z!Square arrow tip with filled tip.r=   r   r@   r+   rA   r   r   r   r   c                @     t                      j        d||d| d S rV   rW   rY   s       r   r    zArrowSquareFilledTip.__init__S  r[   r!   r\   r]   r^   r`   s   @r   r   r   P  sX        ,, >?Y Y Y Y Y Y Y Y Y Y Yr!   r   ) r8   
__future__r   __all__typingr   r   numpyr0   manim.constantsmanim.mobject.geometry.arcr   manim.mobject.geometry.polygramr   r   )manim.mobject.opengl.opengl_compatibilityr   &manim.mobject.types.vectorized_mobjectr   manim.utils.space_opsr   manim.typingr   r   r   r   r	   r
   r   r   r   r   r:   r!   r   <module>rv      sm   L L " " " " " "	 	 	 & % % % % % % %         - - - - - - < < < < < < < < E E E E E E ; ; ; ; ; ; 1 1 1 1 1 1 /........k2 k2 k2 k2 k2x? k2 k2 k2 k2\(8 (8 (8 (8 (8 (8 (8 (8V* * * * *x * * *2	Y 	Y 	Y 	Y 	Y- 	Y 	Y 	Y+ + + + +Xv + + +&Y Y Y Y Y> Y Y Y+ + + + +Xv + + +.Y Y Y Y Y> Y Y Y Y Yr!   