
    ljKa                    Z   d Z ddlmZ ddlmZ ddlmZ ddgZddlm	Z	m
Z
mZ ddlmZ erdd	lmZmZ dd
lm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 ddlmZmZ ddl m!Z!m"Z" ddl#m$Z$m%Z% 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/m0Z0  G d de          Z1 G d de1          Z2dS )z#Mobject representing a number line.    )annotations)Mobject)OpenGLVMobject
NumberLineUnitInterval)CallableIterableSequence)TYPE_CHECKING)AnySelf)ArrowTip)Point3DPoint3DLikeVector3DN)config)*)Line)
LinearBase
_ScaleBase)DecimalNumberInteger)MathTexTex)Text)VGroupVMobject)interpolate)merge_dicts_recursively)	normalizec                  L    e Zd ZdZdddddddddd	deeddd
ee e            edddfdh fd/Z	e
fdid5Ze
fdjd7Zdkd9Zdldmd=Zdnd?ZdodAZdpdCZdqdFZdrdHZdsdIZdtdJZdu fdKZ	 	 	 	 dvdwdSZdxdUZdndVZ	 	 	 	 dvdydYZ	 	 	 	 dvdzd]Z	 dld{daZed|dc            Zd}deZd~dgZ  xZ!S )r   a  Creates a number line with tick marks.

    Parameters
    ----------
    x_range
        The ``[x_min, x_max, x_step]`` values to create the line.
    length
        The length of the number line.
    unit_size
        The distance between each tick of the line. Overwritten by :attr:`length`, if specified.
    include_ticks
        Whether to include ticks on the number line.
    tick_size
        The length of each tick mark.
    numbers_with_elongated_ticks
        An iterable of specific values with elongated ticks.
    longer_tick_multiple
        Influences how many times larger elongated ticks are than regular ticks (2 = 2x).
    rotation
        The angle (in radians) at which the line is rotated.
    stroke_width
        The thickness of the line.
    include_tip
        Whether to add a tip to the end of the line.
    tip_width
        The width of the tip.
    tip_height
        The height of the tip.
    tip_shape
        The mobject class used to construct the tip, or ``None`` (the
        default) for the default arrow tip. Passed classes have to inherit
        from :class:`.ArrowTip`.
    include_numbers
        Whether to add numbers to the tick marks. The number of decimal places is determined
        by the step size, this default can be overridden by ``decimal_number_config``.
    scaling
        The way the ``x_range`` is value is scaled, i.e. :class:`~.LogBase` for a logarithmic numberline. Defaults to :class:`~.LinearBase`.
    font_size
        The size of the label mobjects. Defaults to 36.
    label_direction
        The specific position to which label mobjects are added on the line.
    label_constructor
        Determines the mobject class that will be used to construct the labels of the number line.
    line_to_number_buff
        The distance between the line and the label mobject.
    decimal_number_config
        Arguments that can be passed to :class:`~.numbers.DecimalNumber` to influence number mobjects.
    numbers_to_exclude
        An explicit iterable of numbers to not be added to the number line.
    numbers_to_include
        An explicit iterable of numbers to add to the number line
    kwargs
        Additional arguments to be passed to :class:`~.Line`.


    .. note::

        Number ranges that include both negative and positive values will be generated
        from the 0 point, and may not include a tick at the min / max
        values as the tick locations are dependent on the step size.

    Examples
    --------
    .. manim:: NumberLineExample
        :save_last_frame:

        class NumberLineExample(Scene):
            def construct(self):
                l0 = NumberLine(
                    x_range=[-10, 10, 2],
                    length=10,
                    color=BLUE,
                    include_numbers=True,
                    label_direction=UP,
                )

                l1 = NumberLine(
                    x_range=[-10, 10, 2],
                    unit_size=0.5,
                    numbers_with_elongated_ticks=[-2, 4],
                    include_numbers=True,
                    font_size=24,
                )
                num6 = l1.numbers[8]
                num6.set_color(RED)

                l2 = NumberLine(
                    x_range=[-2.5, 2.5 + 0.5, 0.5],
                    length=12,
                    decimal_number_config={"num_decimal_places": 2},
                    include_numbers=True,
                )

                l3 = NumberLine(
                    x_range=[-5, 5 + 1, 1],
                    length=6,
                    include_tip=True,
                    include_numbers=True,
                    rotation=10 * DEGREES,
                )

                line_group = VGroup(l0, l1, l2, l3).arrange(DOWN, buff=1)
                self.add(line_group)
    N   T皙?   Fr   g       @$   x_rangeSequence[float] | Nonelengthfloat | None	unit_sizefloatinclude_ticksbool	tick_sizenumbers_with_elongated_ticksIterable[float] | Nonelonger_tick_multipleintexclude_origin_tickrotationstroke_widthinclude_tip	tip_width
tip_height	tip_shapetype[ArrowTip] | Noneinclude_numbers	font_sizelabel_directionr   label_constructortype[MathTex]scalingr   line_to_number_buffdecimal_number_configdict | Nonenumbers_to_excludenumbers_to_includekwargsr   c           	     p   |g }|g }|7t          t          d                    t          t          d                   dg}nt          |          dk    rg |d}|d|                     |d                   i}t	          j        |t                    | _        |  |  |  |                    | j                  \  | _	        | _
        | _        || _        || _        || _        || _        || _        || _        || _        |	| _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _         tA                      j!        | j        d         tD          z  | j        d         tD          z  fd|
i| | j        r4| #                    | j                   | $                                | _        n| %                    | j                   | &                                 | j        rG| '                    | j        | j        |           | j(        )                    | j*        | j+                   | j        r| ,                                 | -                    | j                   | j        s| j        | j        j.        rj| /                                }| j        0                    ||d         	          }| 1                    te          tg          ||d
                               d S | 4                    | j        | j        | j                   d S d S )Nframe_x_radiusr"   r$   num_decimal_places)dtyper   r5   )
tip_lengthr7   r9   )unit_decimal_placesT)strict)x_values	excludingr<   )5roundr   len_decimal_places_from_stepnparrayr+   r&   functionx_minx_maxx_stepr(   r*   r,   r.   r/   r1   r3   r4   r6   r7   r8   r<   r;   r=   r>   rA   rB   rD   rE   r@   super__init__RIGHT
set_lengthget_unit_sizescalecenteradd_tiptip
set_strokestroke_colorr5   	add_ticksrotatecustom_labelsget_tick_rangeget_custom_labels
add_labelsdictzipadd_numbers)selfr&   r(   r*   r,   r.   r/   r1   r3   r4   r5   r6   r7   r8   r9   r;   r<   r=   r>   r@   rA   rB   rD   rE   rF   
tick_rangerf   	__class__s                              ]/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/mobject/graphing/number_line.pyrZ   zNumberLine.__init__   s   @ %!#'/+-(?v.//00f-.//GG
 \\Q#mmG ($d&D&DWQZ&P&P%!
 xu555.5.>.>t|.L.L+
DJ"*",H)$8!#6  &"$"..!2#6 %:""4"4LOe#LOe#	
 	
 &	
 		
 	
 	
 ; 	'OODK(((!//11DNNJJt~&&& 	FLL?.#    
 H 143DEEE 	NNDM""" 	4#:#F|) !0022
 $ > >(=>R(S !? ! !
 &)#'          !4"5"n !     ) $G#F    angleaxisr   returnr   c                "     | j         d||fi |S )Nr   )rotate_about_number)rm   rr   rs   rF   s       rp   rotate_about_zerozNumberLine.rotate_about_zero  s#     (t'5$AA&AAArq   numberc                J     | j         ||fd|                     |          i|S )Nabout_point)re   n2p)rm   rx   rr   rs   rF   s        rp   rv   zNumberLine.rotate_about_number  s1     t{5$OODHHV4D4DOOOOrq   Nonec                   t                      }| j        | j        z  }t          j        | j                  | j        z
  }|                                 D ]c}| j        }t          j        t          j	        || j        z
  |                    r|}|
                    |                     ||                     d| 
                    |           || _        dS )zhAdds ticks to the number line. Ticks can be accessed after creation
        via ``self.ticks``.
        N)r   r.   r1   rS   rT   r/   rV   rg   anyiscloseaddget_tickticks)rm   r   elongated_tick_sizeelongated_tick_offsetsxsizes         rp   rd   zNumberLine.add_ticks  s     "nt/HHHT677$*D 	 $$&& 	. 	.A>DvbjTZ1GHHII +*IIdmmAt,,----


rq   r   r   r   c                    || j         }t          |t          z  |t          z            }|                    |                                            |                    |                     |                     |                    |            |S )a1  Generates a tick and positions it along the number line.

        Parameters
        ----------
        x
            The position of the tick.
        size
            The factor by which the tick is scaled.

        Returns
        -------
        :class:`~.Line`
            A positioned tick.
        )	r.   r   DOWNUPre   	get_anglemove_tonumber_to_pointmatch_style)rm   r   r   results       rp   r   zNumberLine.get_tick0  s|     <>DdTk4"9--dnn&&'''t++A..///4   rq   r   c                    | j         S N)r   rm   s    rp   get_tick_markszNumberLine.get_tick_marksG  s
    zrq   
np.ndarrayc                   | j         \  }}}| j        s|dz  }||cxk     rdk     sn ||cxk    rdk    rn nt          j        |||          }nzd}| j        r||z  }t          j        |t          j        |          dz   |          dz  }t          j        |||          }t          j        t          j        ||f                    }| j        	                    |          S )a  Generates the range of values on which labels are plotted based on the
        ``x_range`` attribute of the number line.

        Returns
        -------
        np.ndarray
            A numpy array of floats represnting values along the number line.
        gư>r   )
r&   r6   rS   aranger3   absuniqueconcatenater@   rU   )rm   rV   rW   rX   rn   start_pointx_min_segmentx_max_segments           rp   rg   zNumberLine.get_tick_rangeJ  s     $|uf 	TME 51 1 1 1 1 1 1 1 1 15%88JJK' &v%Ik26%==43GPPSUUMIk5&AAM2>=-2P#Q#QRRJ|$$Z000rq   float | np.ndarrayc                   t          j        |          }|j        dk    }| j                            |          }|| j        d         z
  | j        d         | j        d         z
  z  }|rt          |          nt          j        |          }t          | 	                                | 
                                |          }|S )a  Accepts a value along the number line and returns a point with
        respect to the scene.
        Equivalent to `NumberLine @ number`

        Parameters
        ----------
        number
            The value to be transformed into a coordinate. Or a list of values.

        Returns
        -------
        np.ndarray
            A point with respect to the scene's coordinate system. Or a list of points.

        Examples
        --------

            >>> from manim import NumberLine
            >>> number_line = NumberLine()
            >>> number_line.number_to_point(0)
            array([0., 0., 0.])
            >>> number_line.number_to_point(1)
            array([1., 0., 0.])
            >>> number_line @ 1
            array([1., 0., 0.])
            >>> number_line.number_to_point([1, 2, 3])
            array([[1., 0., 0.],
                   [2., 0., 0.],
                   [3., 0., 0.]])
        r   r"   )rS   asarrayndimr@   inverse_functionr&   r+   vstackr   	get_startget_end)rm   rx   scalaralphasvals        rp   r   zNumberLine.number_to_pointf  s    > F##!..v664<?*t|Aa/PQ"(?vbi.?.?$..**DLLNNFCC
rq   pointSequence[float]c                   t          j        |          }|                                 \  }}t          ||z
            }t          j        ||z
  |          t          j        ||z
  |          z  }t          | j        | j        |          S )a  Accepts a point with respect to the scene and returns
        a float along the number line.

        Parameters
        ----------
        point
            A sequence of values consisting of ``(x_coord, y_coord, z_coord)``.

        Returns
        -------
        float
            A float representing a value along the number line.

        Examples
        --------

            >>> from manim import NumberLine
            >>> number_line = NumberLine()
            >>> number_line.point_to_number((0, 0, 0))
            np.float64(0.0)
            >>> number_line.point_to_number((1, 0, 0))
            np.float64(1.0)
            >>> number_line.point_to_number([[0.5, 0, 0], [1, 0, 0], [1.5, 0, 0]])
            array([0.5, 1. , 1.5])

        )rS   r   get_start_and_endr    dotr   rV   rW   )rm   r   startend	unit_vect
proportions         rp   point_to_numberzNumberLine.point_to_number  s    6 
5!!++--
scEk**	F55=)<<rv%K@
 @
 

 4:tz:>>>rq   r   c                ,    |                      |          S )z6Abbreviation for :meth:`~.NumberLine.number_to_point`.)r   )rm   rx   s     rp   r{   zNumberLine.n2p  s    ##F+++rq   c                ,    |                      |          S )z6Abbreviation for :meth:`~.NumberLine.point_to_number`.)r   )rm   r   s     rp   p2nzNumberLine.p2n  s    ##E***rq   c                f    |                                  | j        d         | j        d         z
  z  }|S )Nr"   r   )
get_lengthr&   )rm   r   s     rp   r]   zNumberLine.get_unit_size  s,    __&&$,q/DLO*KL
rq   c                T    t                                                      | j        z  S r   )rY   get_unit_vectorr*   )rm   ro   s    rp   r   zNumberLine.get_unit_vector  s     ww&&((4>99rq   	directionVector3D | Nonebufftype[MathTex] | Nonenumber_configdict[str, Any]r   c                r   t          | j        |          }|| j        }|| j        }|| j        }|| j        }t          |f||d|}|                    |                     |          ||           |dk     r<| j        d         dk    r+|	                    |d         j
        t          z  dz             |S )a  Generates a positioned :class:`~.DecimalNumber` mobject
        generated according to ``label_constructor``.

        Parameters
        ----------
        x
            The x-value at which the mobject should be positioned.
        direction
            Determines the direction at which the label is positioned next to the line.
        buff
            The distance of the label from the line.
        font_size
            The font size of the label mobject.
        label_constructor
            The :class:`~.VMobject` class that will be used to construct the label.
            Defaults to the ``label_constructor`` attribute of the number line
            if not specified.

        Returns
        -------
        :class:`~.DecimalNumber`
            The positioned mobject.
        N)r<   	mob_classr   r   r   r$   )r   rB   r=   rA   r<   r>   r   next_tor   shiftwidthLEFT)	rm   r   r   r   r<   r>   r   number_config_mergednum_mobs	            rp   get_number_mobjectzNumberLine.get_number_mobject  s    @  7& 
  
 ,I<+DI$ $ 6
'
 
 #	
 
 	,,Q//94PPPq55T)!,11MM'!**T1A5666rq   numbersc                     t          |          dk    r                                 }t           fd|D                       S )Nr   c                ,    g | ]} j         |fi S  )r   ).0rx   rF   rm   s     rp   
<listcomp>z2NumberLine.get_number_mobjects.<locals>.<listcomp>  s/    WWWV.t.v@@@@WWWrq   )rQ   default_numbers_to_displayr   )rm   r   rF   s   ` `rp   get_number_mobjectszNumberLine.get_number_mobjects  sL    w<<15577GWWWWWwWWWXXXrq   c                *    |                                  S r   )r   r   s    rp   
get_labelszNumberLine.get_labels  s    '')))rq   rN   rO   c           	        ||                                  }|| j        }|| j        }|| j        }t	                      }|D ]+}||v r|                     | j        |f||d|           ,|                     |           || _        | S )aE  Adds :class:`~.DecimalNumber` mobjects representing their position
        at each tick of the number line. The numbers can be accessed after creation
        via ``self.numbers``.

        Parameters
        ----------
        x_values
            An iterable of the values used to position and create the labels.
            Defaults to the output produced by :meth:`~.NumberLine.get_tick_range`
        excluding
            A list of values to exclude from :attr:`x_values`.
        font_size
            The font size of the labels. Defaults to the ``font_size`` attribute
            of the number line.
        label_constructor
            The :class:`~.VMobject` class that will be used to construct the label.
            Defaults to the ``label_constructor`` attribute of the number line
            if not specified.
        N)r<   r>   )rg   rD   r<   r>   r   r   r   r   )rm   rN   rO   r<   r>   rF   r   r   s           rp   rl   zNumberLine.add_numbers  s    6 **,,H/II$ $ 6(( 
	 
	AI~~KK'''&7  	     	rq   dict_values#dict[float, str | float | VMobject]Point3DLike | Nonec                   || j         n|}|| j        n|}|| j        n|}|| j        }t	                      }|                                D ]\  }}t          |t                    r|t          u rt          |          }n| 
                    ||          }t          |d          r:t          |t          t          t          t          f          s
J |            ||_        nt          | d          |                    |                     |          ||           |                    |           || _        |                     |           | S )ai  Adds specifically positioned labels to the :class:`~.NumberLine` using a ``dict``.
        The labels can be accessed after creation via ``self.labels``.

        Parameters
        ----------
        dict_values
            A dictionary consisting of the position along the number line and the mobject to be added:
            ``{1: Tex("Monday"), 3: Tex("Tuesday")}``. :attr:`label_constructor` will be used
            to construct the labels if the value is not a mobject (``str`` or ``float``).
        direction
            Determines the direction at which the label is positioned next to the line.
        buff
            The distance of the label from the line.
        font_size
            The font size of the mobject to be positioned.
        label_constructor
            The :class:`~.VMobject` class that will be used to construct the label.
            Defaults to the ``label_constructor`` attribute of the number line
            if not specified.

        Raises
        ------
        AttributeError
            If the label does not have a ``font_size`` attribute, an ``AttributeError`` is raised.
        Nr<   z# is not compatible with add_labels.r   )r=   rA   r<   r>   r   items
isinstancestrr   r   _create_label_texhasattrr   r   AttributeErrorr   r   r   labels)	rm   r   r   r   r<   r>   r   r   labels	            rp   ri   zNumberLine.add_labels8  se   B -6,=D((9	+/<t''T&/&7DNNY	$ $ 6#))++ 	 	HAu %%% I*;w*F*FE

..u6GHHuk** T!%'3g)FGGNNNNG"+$%R%R%RSSSMM$..q11YTMRRRJJurq   	label_texstr | float | VMobjectCallable | Nonec                    t          |t          t          f          r|S || j        }t          |t                    r	 ||fi |S  |t	          |          fi |S )a  Checks if the label is a :class:`~.VMobject`, otherwise, creates a
        label by passing ``label_tex`` to ``label_constructor``.

        Parameters
        ----------
        label_tex
            The label for which a mobject should be created. If the label already
            is a mobject, no new mobject is created.
        label_constructor
            Optional. A class or function returning a mobject when
            passing ``label_tex`` as an argument. If ``None`` is passed
            (the default), the label constructor from the :attr:`.label_constructor`
            attribute is used.

        Returns
        -------
        :class:`~.VMobject`
            The label.
        )r   r   r   r>   r   )rm   r   r>   rF   s       rp   r   zNumberLine._create_label_texu  sz    2 i(N!;<< 	$ $ 6i%% 	:$$Y99&999  Y::6:::rq   stepc                |    t          |           }d|vrdS t          |                    d          d                   S )N.r   r   )r   rQ   split)r   step_strs     rp   rR   z$NumberLine._decimal_places_from_step  s<    t99h18>>#&&r*+++rq   otherc                ,    |                      |          S r   )r{   rm   r   s     rp   
__matmul__zNumberLine.__matmul__  s    xxrq   Point3DLike | Mobjectc                ~    t          |t                    r|                                }|                     |          S r   )r   r   
get_centerr   r   s     rp   __rmatmul__zNumberLine.__rmatmul__  s5    eW%% 	'$$&&Exxrq   )0r&   r'   r(   r)   r*   r+   r,   r-   r.   r+   r/   r0   r1   r2   r3   r-   r4   r+   r5   r+   r6   r-   r7   r+   r8   r+   r9   r:   r;   r-   r<   r+   r=   r   r>   r?   r@   r   rA   r+   rB   rC   rD   r0   rE   r0   rF   r   )rr   r+   rs   r   rF   r   rt   r   )
rx   r+   rr   r+   rs   r   rF   r   rt   r   )rt   r|   r   )r   r+   r   r)   rt   r   )rt   r   )rt   r   )rx   r   rt   r   )r   r   rt   r+   )rx   r   rt   r   )r   r   rt   r+   )rt   r+   )rt   r   )NNNN)r   r+   r   r   r   r)   r<   r)   r>   r   r   r   rt   r   )r   r+   rF   r   rt   r   )rN   r0   rO   r0   r<   r)   r>   r   rF   r   rt   r   )r   r   r   r   r   r)   r<   r)   r>   r   rt   r   )r   r   r>   r   rF   r   rt   r   )r   r+   rt   r2   )r   r+   rt   r   )r   r   rt   r+   )"__name__
__module____qualname____doc__DEFAULT_ARROW_TIP_LENGTHr   r   r   MED_SMALL_BUFFrZ   OUTrw   rv   rd   r   r   rg   r   r   r{   r   r]   r   r   r   r   rl   ri   r   staticmethodrR   r   r   __classcell__ro   s   @rp   r   r   #   s       g gV +/#"?C$%$)!!34+/ %'++2(jll%3-159599F F F F F F FR .1B B B B B =@P P P P P
   "    .   1 1 1 18% % % %N!? !? !? !?F, , , ,+ + + +   : : : : : : &*!"&268 8 8 8 8tY Y Y Y
* * * *
 ,0,0"&265 5 5 5 5t )-!"&26; ; ; ; ;@ .2; ; ; ; ;B , , , \,          rq   c                  (     e Zd Z	 	 	 dd fdZ xZS )r   
   Nr*   r+   r/   list[float] | NonerB   dict[str, Any] | NonerF   r   c                d    |ddgn|}|ddin|} t                      j        dd|||d| d S )Nr   r"   rI   )r   r"   r#   )r&   r*   r/   rB   r   )rY   rZ   )rm   r*   r/   rB   rF   ro   s        rp   rZ   zUnitInterval.__init__  s     ,3 FF- 	% %, %a  ' 	 	 	
)E"7		
 	

 	
 	
 	
 	
 	
rq   )r   NN)r*   r+   r/   r   rB   r   rF   r   )r   r   r   rZ   r   r   s   @rp   r   r     sM         ;?7;	
 
 
 
 
 
 
 
 
 
 
rq   )3r   
__future__r   manim.mobject.mobjectr   .manim.mobject.opengl.opengl_vectorized_mobjectr   __all__collections.abcr   r	   r
   typingr   r   r   manim.mobject.geometry.tipsr   manim.typingr   r   r   numpyrS   manimr   manim.constantsmanim.mobject.geometry.liner   manim.mobject.graphing.scaler   r   manim.mobject.text.numbersr   r   manim.mobject.text.tex_mobjectr   r   manim.mobject.text.text_mobjectr   &manim.mobject.types.vectorized_mobjectr   r   manim.utils.bezierr   manim.utils.config_opsr   manim.utils.space_opsr    r   r   r   rq   rp   <module>r     s   ) ) " " " " " " ) ) ) ) ) ) I I I I I I
( 9 8 8 8 8 8 8 8 8 8             <        444444;;;;;;;;;;               , , , , , , ? ? ? ? ? ? ? ? = = = = = = = = 7 7 7 7 7 7 7 7 0 0 0 0 0 0 C C C C C C C C * * * * * * : : : : : : + + + + + +@
 @
 @
 @
 @
 @
 @
 @
F
 
 
 
 
: 
 
 
 
 
rq   