
    lj1                    ,   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mZ ddl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 ddlmZ ddlmZ erddlmZ  G d de          Z G d de          Z  G d de e          Z! G d de          Z"dS )zFMobjects that inherit from lines and contain a label along the length.    )annotations)LabelLabeledLineLabeledArrowLabeledPolygram)TYPE_CHECKINGAnyN)*)ArrowLine)Polygram)BackgroundRectangleSurroundingRectangle)MathTexTex)Text)VGroup)WHITE)	polylabel)Point3DLike_Arrayc                  ,     e Zd ZdZ	 	 	 dd fdZ xZS )r   a  A Label consisting of text surrounded by a frame.

    Parameters
    ----------
    label
        Label that will be displayed.
    label_config
        A dictionary containing the configuration for the label.
        This is only applied if ``label`` is of type ``str``.
    box_config
        A dictionary containing the configuration for the background box.
    frame_config
         A dictionary containing the configuration for the frame.

    Examples
    --------
    .. manim:: LabelExample
        :save_last_frame:
        :quality: high

        class LabelExample(Scene):
            def construct(self):
                label = Label(
                    label=Text('Label Text', font='sans-serif'),
                    box_config = {
                        "color" : BLUE,
                        "fill_opacity" : 0.75
                    }
                )
                label.scale(3)
                self.add(label)
    Nlabelstr | Tex | MathTex | Textlabel_configdict[str, Any] | None
box_configframe_configkwargsr	   returnNonec                    t                      j        di | t          t          d}d dddd}t          ddd}||pi z  }||pi z  }||pi z  }|  t	          |t
                    rt          |fi || _        n9t	          |t          t          t          f          r|| _        nt          d          t          | j        fi || _        t          | j        fi || _        |                     | j        | j        | j                   d S )	N)color	font_sizeg?         ?)r"   bufffill_opacitystroke_width)r"   r&   r(   z6Unsupported label type. Must be MathTex, Tex, or Text. )super__init__r   DEFAULT_FONT_SIZE
isinstancestrr   rendered_labelr   r   	TypeErrorr   background_rectr   frameadd)
selfr   r   r   r   r   default_label_configdefault_box_configdefault_frame_config	__class__s
            Y/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/mobject/geometry/labeled.pyr+   zLabel.__init__>   sb    	""6""" *0
 0
 	.
 .
 0
 0
 ,|/ArB':+;<
+|/ArB 	1eS!! 	V")%"@"@<"@"@Dd344 	V"'DTUUU  343FUU*UU *$*=NNNN
 	%t':DJGGGGG    )NNN)r   r   r   r   r   r   r   r   r   r	   r   r    __name__
__module____qualname____doc__r+   __classcell__r8   s   @r9   r   r      sc         H /3,0.22H 2H 2H 2H 2H 2H 2H 2H 2H 2H 2Hr:   r   c                  .     e Zd ZdZ	 	 	 	 dd fdZ xZS )r   a  Constructs a line containing a label box somewhere along its length.

    Parameters
    ----------
    label
        Label that will be displayed on the line.
    label_position
        A ratio in the range [0-1] to indicate the position of the label with respect to the length of the line. Default value is 0.5.
    label_config
        A dictionary containing the configuration for the label.
        This is only applied if ``label`` is of type ``str``.
    box_config
        A dictionary containing the configuration for the background box.
    frame_config
         A dictionary containing the configuration for the frame.

        .. seealso::
            :class:`LabeledArrow`

    Examples
    --------
    .. manim:: LabeledLineExample
        :save_last_frame:
        :quality: high

        class LabeledLineExample(Scene):
            def construct(self):
                line = LabeledLine(
                    label          = '0.5',
                    label_position = 0.8,
                    label_config = {
                        "font_size" : 20
                    },
                    start=LEFT+DOWN,
                    end=RIGHT+UP)

                line.set_length(line.get_length() * 2)
                self.add(line)
    r%   Nr   r   label_positionfloatr   r   r   r   argsr	   r   r   r    c                    t                      j        |i | t          ||||          | _        |                                 \  }}	|	|z
  |z  }
||
z   }| j                            |           |                     | j                   d S )Nr   r   r   r   )r*   r+   r   r   get_start_and_endmove_tor3   )r4   r   rC   r   r   r   rE   r   
line_startline_endnew_veclabel_coordsr8   s               r9   r+   zLabeledLine.__init__   s     	$)&))) %!%	
 
 

  $5577
Hj(N:!G+
<(((r:   )r%   NNN)r   r   rC   rD   r   r   r   r   r   r   rE   r	   r   r	   r   r    r;   rA   s   @r9   r   r   s   s[        & &V !$.2,0.2          r:   r   c                  $     e Zd ZdZd fdZ xZS )	r   ak  Constructs an arrow containing a label box somewhere along its length.
    This class inherits its label properties from `LabeledLine`, so the main parameters controlling it are the same.

    Parameters
    ----------
    label
        Label that will be displayed on the Arrow.
    label_position
        A ratio in the range [0-1] to indicate the position of the label with respect to the length of the line. Default value is 0.5.
    label_config
        A dictionary containing the configuration for the label.
        This is only applied if ``label`` is of type ``str``.
    box_config
        A dictionary containing the configuration for the background box.
    frame_config
         A dictionary containing the configuration for the frame.

        .. seealso::
            :class:`LabeledLine`

    Examples
    --------
    .. manim:: LabeledArrowExample
        :save_last_frame:
        :quality: high

        class LabeledArrowExample(Scene):
            def construct(self):
                l_arrow = LabeledArrow("0.5", start=LEFT*3, end=RIGHT*3 + UP*2, label_position=0.5)

                self.add(l_arrow)
    rE   r	   r   r   r    c                :     t                      j        |i | d S )N)r*   r+   )r4   rE   r   r8   s      r9   r+   zLabeledArrow.__init__   s'    
 	$)&)))))r:   )rE   r	   r   r	   r   r    r;   rA   s   @r9   r   r      sH         B* * * * * * * * * *r:   r   c                  0     e Zd ZdZdddddd fdZ xZS )r   a  Constructs a polygram containing a label box at its pole of inaccessibility.

    Parameters
    ----------
    vertex_groups
        Vertices passed to the :class:`~.Polygram` constructor.
    label
        Label that will be displayed on the Polygram.
    precision
        The precision used by the PolyLabel algorithm.
    label_config
        A dictionary containing the configuration for the label.
        This is only applied if ``label`` is of type ``str``.
    box_config
        A dictionary containing the configuration for the background box.
    frame_config
         A dictionary containing the configuration for the frame.

        .. note::
            The PolyLabel Algorithm expects each vertex group to form a closed ring.
            If the input is open, :class:`LabeledPolygram` will attempt to close it.
            This may cause the polygon to intersect itself leading to unexpected results.

        .. tip::
            Make sure the precision corresponds to the scale of your inputs!
            For instance, if the bounding box of your polygon stretches from 0 to 10,000, a precision of 1.0 or 10.0 should be sufficient.

    Examples
    --------
    .. manim:: LabeledPolygramExample
        :save_last_frame:
        :quality: high

        class LabeledPolygramExample(Scene):
            def construct(self):
                # Define Rings
                ring1 = [
                    [-3.8, -2.4, 0], [-2.4, -2.5, 0], [-1.3, -1.6, 0], [-0.2, -1.7, 0],
                    [1.7, -2.5, 0], [2.9, -2.6, 0], [3.5, -1.5, 0], [4.9, -1.4, 0],
                    [4.5, 0.2, 0], [4.7, 1.6, 0], [3.5, 2.4, 0], [1.1, 2.5, 0],
                    [-0.1, 0.9, 0], [-1.2, 0.5, 0], [-1.6, 0.7, 0], [-1.4, 1.9, 0],
                    [-2.6, 2.6, 0], [-4.4, 1.2, 0], [-4.9, -0.8, 0], [-3.8, -2.4, 0]
                ]
                ring2 = [
                    [0.2, -1.2, 0], [0.9, -1.2, 0], [1.4, -2.0, 0], [2.1, -1.6, 0],
                    [2.2, -0.5, 0], [1.4, 0.0, 0], [0.4, -0.2, 0], [0.2, -1.2, 0]
                ]
                ring3 = [[-2.7, 1.4, 0], [-2.3, 1.7, 0], [-2.8, 1.9, 0], [-2.7, 1.4, 0]]

                # Create Polygons (for reference)
                p1 = Polygon(*ring1, fill_opacity=0.75)
                p2 = Polygon(*ring2, fill_color=BLACK, fill_opacity=1)
                p3 = Polygon(*ring3, fill_color=BLACK, fill_opacity=1)

                # Create Labeled Polygram
                polygram = LabeledPolygram(
                    *[ring1, ring2, ring3],
                    label=Text('Pole', font='sans-serif'),
                    precision=0.01,
                )

                # Display Circle (for reference)
                circle = Circle(radius=polygram.radius, color=WHITE).move_to(polygram.pole)

                self.add(p1, p2, p3)
                self.add(polygram)
                self.add(circle)

    .. manim:: LabeledCountryExample
        :save_last_frame:
        :quality: high

        import requests
        import json

        class LabeledCountryExample(Scene):
            def construct(self):
                # Fetch JSON data and process arcs
                data = requests.get('https://cdn.jsdelivr.net/npm/us-atlas@3/nation-10m.json').json()
                arcs, transform = data['arcs'], data['transform']
                sarcs = [np.cumsum(arc, axis=0) * transform['scale'] + transform['translate'] for arc in arcs]
                ssarcs = sorted(sarcs, key=len, reverse=True)[:1]

                # Compute Bounding Box
                points = np.concatenate(ssarcs)
                mins, maxs = np.min(points, axis=0), np.max(points, axis=0)

                # Build Axes
                ax = Axes(
                    x_range=[mins[0], maxs[0], maxs[0] - mins[0]], x_length=10,
                    y_range=[mins[1], maxs[1], maxs[1] - mins[1]], y_length=7,
                    tips=False
                )

                # Adjust Coordinates
                array = [[ax.c2p(*point) for point in sarc] for sarc in ssarcs]

                # Add Polygram
                polygram = LabeledPolygram(
                    *array,
                    label=Text('USA', font='sans-serif'),
                    precision=0.01,
                    fill_color=BLUE,
                    stroke_width=0,
                    fill_opacity=0.75
                )

                # Display Circle (for reference)
                circle = Circle(radius=polygram.radius, color=WHITE).move_to(polygram.pole)

                self.add(ax)
                self.add(polygram)
                self.add(circle)
    g{Gz?N)	precisionr   r   r   vertex_groupsr   r   r   rQ   rD   r   r   r   r   r   r	   r   r    c               p    t                      j        |i | t          ||||          | _        d |D             }t	          ||          }	t          j        |	j        dd          |	j        c| _	        | _
        | j                            | j	                   |                     | j                   d S )NrG   c                    g | ]>}t          j        |d          |d                   r|nt          |          |d          gz   ?S )r   )nparray_equallist).0groups     r9   
<listcomp>z,LabeledPolygram.__init__.<locals>.<listcomp>m  sW     
 
 
 ^E!HeBi88VEEd5kkUSTXJ>V
 
 
r:   )rQ   )r   r$   constant)r*   r+   r   r   r   rV   padcdpoleradiusrI   r3   )r4   r   rQ   r   r   r   rR   r   ringscellr8   s             r9   r+   zLabeledPolygram.__init__W  s     	-26222 %!%	
 
 


 
&
 
 
 )444!#
!C!CTV	4; 	
49%%%r:   )rR   r   r   r   rQ   rD   r   r   r   r   r   r   r   r	   r   r    r;   rA   s   @r9   r   r      sb        q qn  .2,0.2! ! ! ! ! ! ! ! ! ! ! !r:   r   )#r?   
__future__r   __all__typingr   r	   numpyrV   manim.constantsmanim.mobject.geometry.liner   r   manim.mobject.geometry.polygramr   %manim.mobject.geometry.shape_matchersr   r   manim.mobject.text.tex_mobjectr   r   manim.mobject.text.text_mobjectr   &manim.mobject.types.vectorized_mobjectr   manim.utils.colorr   manim.utils.polylabelr   manim.typingr   r   r   r   r   r)   r:   r9   <module>rr      s   M M " " " " " "
E
E
E % % % % % % % %         3 3 3 3 3 3 3 3 4 4 4 4 4 4        8 7 7 7 7 7 7 7 0 0 0 0 0 0 9 9 9 9 9 9 # # # # # # + + + + + + /......TH TH TH TH THF TH TH THnC C C C C$ C C CL'* '* '* '* '*; '* '* '*TU U U U Uh U U U U Ur:   