
    ljP=                       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
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 ddl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# ddl$T ddl%m&Z& ddl'm(Z( ddl)m*Z* erddl+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1  G d de*          Z2 G d de&e          Z3 G d de3          Z4 G d  d!e2          Z5 G d" d#e2          Z6dS )$z"Mobject representing curly braces.    )annotations)Brace
BraceLabelArcBrace	BraceTextBraceBetweenPoints)TYPE_CHECKINGAnySelfN)config)Arc)Line)Mobject)ConvertToOpenGL)MathTexSingleStringMathTexTex)Text   )	Animation)AnimationGroup)FadeIn)GrowFromCenter)*)VMobject)BLACK   )VMobjectFromSVGPath)Point3DPoint3DLikeVector3DVector3DLike)ParsableManimColorc                  ^     e Zd ZdZedddddefd' fdZd(d)dZd*dZd+d"Z	d,d$Z
d-d&Z xZS ).r   a  Takes a mobject and draws a brace adjacent to it.

    Passing a direction vector determines the direction from which the
    brace is drawn. By default it is drawn from below.

    Parameters
    ----------
    mobject
        The mobject adjacent to which the brace is placed.
    direction :
        The direction from which the brace faces the mobject.

    See Also
    --------
    :class:`BraceBetweenPoints`

    Examples
    --------
    .. manim:: BraceExample
        :save_last_frame:

        class BraceExample(Scene):
            def construct(self):
                s = Square()
                self.add(s)
                for i in np.linspace(0.1,1.0,4):
                    br = Brace(s, sharpness=i)
                    t = Text(f"sharpness= {i}").next_to(br, RIGHT)
                    self.add(t)
                    self.add(br)
                VGroup(*self.mobjects).arrange(DOWN, buff=0.2)

    皙?r   r   g      ?mobjectr   	directionr"   bufffloat	sharpnessstroke_widthfill_opacitybackground_stroke_widthbackground_stroke_colorr#   kwargsr
   c	           	     @   d}
d}|| _         t          j        |d d           t          j        z   }|                    | t
                     |                    t          t          z             }|                    t          t          z             }|d         |d         z
  }t          d||z  |z
  dz            }t          j        |
                    ||                     } t                      j        d|||||d|	 |                     t                     |                     |           |                     ||                     t&          t          z             z
  | j         t          z  z              || fD ]}|                    |t
                     d S )Na  m0.01216 0c-0.01152 0-0.01216 6.103e-4 -0.01216 0.01311v0.007762c0.06776 0.122 0.1799 0.1455 0.2307 0.1455h{0}c0.03046 3.899e-4 0.07964 0.00449 0.1246 0.02636 0.0537 0.02695 0.07418 0.05816 0.08648 0.07769 0.001562 0.002538 0.004539 0.002563 0.01098 0.002563 0.006444-2e-8 0.009421-2.47e-5 0.01098-0.002563 0.0123-0.01953 0.03278-0.05074 0.08648-0.07769 0.04491-0.02187 0.09409-0.02597 0.1246-0.02636h{0}c0.05077 0 0.1629-0.02346 0.2307-0.1455v-0.007762c-1.78e-6 -0.0125-6.365e-4 -0.01311-0.01216-0.01311-0.006444-3.919e-8 -0.009348 2.448e-5 -0.01091 0.002563-0.0123 0.01953-0.03278 0.05074-0.08648 0.07769-0.04491 0.02187-0.09416 0.02597-0.1246 0.02636h{1}c-0.04786 0-0.1502 0.02094-0.2185 0.1256-0.06833-0.1046-0.1706-0.1256-0.2185-0.1256h{1}c-0.03046-3.899e-4 -0.07972-0.004491-0.1246-0.02636-0.0537-0.02695-0.07418-0.05816-0.08648-0.07769-0.001562-0.002538-0.004467-0.002563-0.01091-0.002563zg';?r   about_pointr   )path_objr+   r,   r-   r.    )r(   nparctan2pirotateORIGIN
get_cornerDOWNLEFTRIGHTmaxsePathformatsuper__init__flipstretch_to_fit_widthshiftUP)selfr&   r'   r(   r*   r+   r,   r-   r.   r/   path_string_templatedefault_min_widthangleleftrighttarget_widthlinear_section_lengthpathmob	__class__s                      R/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/mobject/svg/brace.pyrC   zBrace.__init__E   s   2 	 $	Yrr]++be3v6222!!$+..""4%<00Qx$q') #I%(99Q>!
 !

 w ''%&& 
 
 	 	
%%$;$;	
 	
 	
 	
 	
 			%!!,///

4$//"t)444ty47GGHHHD= 	2 	2CJJu&J1111	2 	2    TrQ   use_next_toboolreturnr   c                   |rF |j         |                                 t          j        |                                           fi | ny|                    |                                            |                    dt                    }|j        dz  |z   }|	                    |                                 |z             | S )a  Puts the given mobject at the brace tip.

        Parameters
        ----------
        mob
            The mobject to be placed at the tip.
        use_next_to
            If true, then :meth:`next_to` is used to place the mobject at the
            tip.
        kwargs
            Any additional keyword arguments are passed to :meth:`next_to` which
            is used to put the mobject next to the brace tip.
        r(   g       @)
next_toget_tipr5   roundget_directionmove_toget!DEFAULT_MOBJECT_TO_MOBJECT_BUFFERwidthrF   )rH   rQ   rU   r/   r(   shift_distances         rS   
put_at_tipzBrace.put_at_tip   s      	=CK1C1C1E1E(F(FQQ&QQQQKK'''::f&GHHD Y_t3NIId((**^;<<<rT   textstrr   c                4    t          | } | j        |fi | |S )ai  Places the text at the brace tip.

        Parameters
        ----------
        text
            The text to be placed at the brace tip.
        kwargs
            Any additional keyword arguments are passed to :meth:`.put_at_tip` which
            is used to position the text at the brace tip.

        Returns
        -------
        :class:`~.Tex`
        )r   rb   )rH   rc   r/   text_mobs       rS   get_textzBrace.get_text   s,     :++F+++rT   texr   c                4    t          | } | j        |fi | |S )af  Places the tex at the brace tip.

        Parameters
        ----------
        tex
            The tex to be placed at the brace tip.
        kwargs
            Any further keyword arguments are passed to :meth:`.put_at_tip` which
            is used to position the tex at the brace tip.

        Returns
        -------
        :class:`~.MathTex`
        )r   rb   )rH   rh   r/   tex_mobs       rS   get_texzBrace.get_tex   s,     3-**6***rT   r   c                X    t           d         dk    r| j        d         S | j        d         S )z#Returns the point at the brace tip.rendereropengl"      )r   points)rH   s    rS   rZ   zBrace.get_tip   s,     *));r?"{2rT   r!   c                    |                                  |                                 z
  }|t          j                            |          z  S )z7Returns the direction from the center to the brace tip.)rZ   
get_centerr5   linalgnorm)rH   vects     rS   r\   zBrace.get_direction   s7    ||~~ 1 11binnT****rT   )r&   r   r'   r"   r(   r)   r*   r)   r+   r)   r,   r)   r-   r)   r.   r#   r/   r
   )T)rQ   r   rU   rV   r/   r
   rW   r   )rc   rd   r/   r
   rW   r   )rh   rd   r/   r
   rW   r   )rW   r   )rW   r!   )__name__
__module____qualname____doc__r;   r   rC   rb   rg   rk   rZ   r\   __classcell__rR   s   @rS   r   r   "   s           J #'!)*6;=2 =2 =2 =2 =2 =2 =2~    .   &   &   + + + + + + + +rT   r   c                  V     e Zd ZdZeeeddfd fdZee	fddZ
d dZd!dZd"dZ xZS )#r   a  Create a brace with a label attached.

    Parameters
    ----------
    obj
        The mobject adjacent to which the brace is placed.
    text
        The label text.
    brace_direction
        The direction of the brace. By default ``DOWN``.
    label_constructor
        A class or function used to construct a mobject representing
        the label. By default :class:`~.MathTex`.
    font_size
        The font size of the label, passed to the ``label_constructor``.
    buff
        The buffer between the mobject and the brace.
    brace_config
        Arguments to be passed to :class:`.Brace`.
    kwargs
        Additional arguments to be passed to :class:`~.VMobject`.
    r%   Nobjr   rc   rd   brace_directionr"   label_constructor type[SingleStringMathTex | Text]	font_sizer)   r(   brace_configdict[str, Any] | Noner/   r
   c                   || _          t                      j        di | || _        |i }t	          |||fi || _        t          |t          t          f          r | j         |d|i|| _	        n)|                      t          |          |          | _	        | j                            | j	                   |                     | j        | j	                   d S )Nr   )r   r4   )r   rB   rC   r   r   brace
isinstancetuplelistlabelrd   rb   add)
rH   r~   rc   r   r   r   r(   r   r/   rR   s
            rS   rC   zBraceLabel.__init__   s     "3""6""".L3FFFF
dUDM** 	P#94#9$!*$.4$ $DJJ //D		Y/OODJ
dj)))TZ(((((rT   
label_animtype[Animation]
brace_animrW   r   c                Z    t           || j                   || j                            S N)r   r   r   )rH   r   r   s      rS   creation_animzBraceLabel.creation_anim  s,    
 jj44jj6L6LMMMrT   r   c                    t          |t                    r |                                 | }t          || j        fi || _        | j                            | j                   | S r   )r   r   get_group_classr   r   r   rb   r   )rH   r~   r/   s      rS   shift_bracezBraceLabel.shift_brace  se    c4   	/($&&((#.C3 4????

dj)))rT   c                    |                      | j                    | j        |i || _        | j                            | j                   |                     | j                   | S r   )remover   r   r   rb   r   )rH   rc   r/   s      rS   change_labelzBraceLabel.change_label  s`    DJ+T+T<V<<

dj)))rT   c                J    |                      |            | j        |i | | S r   )r   r   )rH   r~   rc   r/   s       rS   change_brace_labelzBraceLabel.change_brace_label  s3    4*6***rT   )r~   r   rc   rd   r   r"   r   r   r   r)   r(   r)   r   r   r/   r
   )r   r   r   r   rW   r   )r~   r   r/   r
   rW   r   )rc   rd   r/   r
   rW   r   )r~   r   rc   rd   r/   r
   rW   r   )rw   rx   ry   rz   r;   r   DEFAULT_FONT_SIZErC   r   r   r   r   r   r   r{   r|   s   @rS   r   r      s         6 )->E,.2) ) ) ) ) ) )> '-&4N N N N N             rT   r   )	metaclassc                  (     e Zd ZdZefd fd
Z xZS )r   a  Create a brace with a text label attached.

    Parameters
    ----------
    obj
        The mobject adjacent to which the brace is placed.
    text
        The label text.
    brace_direction
        The direction of the brace. By default ``DOWN``.
    label_constructor
        A class or function used to construct a mobject representing
        the label. By default :class:`~.Text`.
    font_size
        The font size of the label, passed to the ``label_constructor``.
    buff
        The buffer between the mobject and the brace.
    brace_config
        Arguments to be passed to :class:`.Brace`.
    kwargs
        Additional arguments to be passed to :class:`~.VMobject`.


    Examples
    --------
        .. manim:: BraceTextExample
            :save_last_frame:

            class BraceTextExample(Scene):
                def construct(self):
                    s1 = Square().move_to(2*LEFT)
                    self.add(s1)
                    br1 = BraceText(s1, "Label")
                    self.add(br1)

                    s2 = Square().move_to(2*RIGHT)
                    self.add(s2)
                    br2 = BraceText(s2, "Label")

                    br2.change_label("new")
                    self.add(br2)
                    self.wait(0.1)
    r~   r   rc   rd   r   r   r/   r
   c                B     t                      j        ||fd|i| d S )Nr   )rB   rC   )rH   r~   rc   r   r/   rR   s        rS   rC   zBraceText.__init__L  s2     	dRR6GR6RRRRRrT   )r~   r   rc   rd   r   r   r/   r
   )rw   rx   ry   rz   r   rC   r{   r|   s   @rS   r   r     s^        * *` ?C	S S S S S S S S S S SrT   r   c                  (     e Zd ZdZefd
 fd	Z xZS )r   a  Similar to Brace, but instead of taking a mobject it uses 2
    points to place the brace.

    A fitting direction for the brace is
    computed, but it still can be manually overridden.
    If the points go from left to right, the brace is drawn from below.
    Swapping the points places the brace on the opposite side.

    Parameters
    ----------
    point_1 :
        The first point.
    point_2 :
        The second point.
    direction :
        The direction from which the brace faces towards the points.

    Examples
    --------
        .. manim:: BraceBPExample

            class BraceBPExample(Scene):
                def construct(self):
                    p1 = [0,0,0]
                    p2 = [1,2,0]
                    brace = BraceBetweenPoints(p1,p2)
                    self.play(Create(NumberPlane()))
                    self.play(Create(brace))
                    self.wait(2)
    point_1r    point_2r'   r"   r/   r
   c                &   t          |t          k              rMt          j        |          t          j        |          z
  }t          j        |d         |d          dg          } t	                      j        t          ||          fd|i| d S )N   r   r'   )allr9   r5   arrayrB   rC   r   )rH   r   r   r'   r/   line_vectorrR   s         rS   rC   zBraceBetweenPoints.__init__v  s     yF"## 	G(7++bhw.?.??K+a.;q>/1!EFFIgw//OO9OOOOOOrT   )r   r    r   r    r'   r"   r/   r
   )rw   rx   ry   rz   r9   rC   r{   r|   s   @rS   r   r   V  s]         F #)	
P 
P 
P 
P 
P 
P 
P 
P 
P 
P 
PrT   r   c                  *     e Zd ZdZdefd
 fd	Z xZS )r   a  Creates a :class:`~Brace` that wraps around an :class:`~.Arc`.

    The direction parameter allows the brace to be applied
    from outside or inside the arc.

    .. warning::
        The :class:`ArcBrace` is smaller for arcs with smaller radii.

    .. note::
        The :class:`ArcBrace` is initially a vertical :class:`Brace` defined by the
        length of the :class:`~.Arc`, but is scaled down to match the start and end
        angles. An exponential function is then applied after it is shifted based on
        the radius of the arc.

        The scaling effect is not applied for arcs with radii smaller than 1 to prevent
        over-scaling.

    Parameters
    ----------
    arc
        The :class:`~.Arc` that wraps around the :class:`Brace` mobject.
    direction
        The direction from which the brace faces the arc.
        ``LEFT`` for inside the arc, and ``RIGHT`` for the outside.

    Example
    -------
        .. manim:: ArcBraceExample
            :save_last_frame:
            :ref_classes: Arc

            class ArcBraceExample(Scene):
                def construct(self):
                    arc_1 = Arc(radius=1.5,start_angle=0,angle=2*PI/3).set_color(RED)
                    brace_1 = ArcBrace(arc_1,LEFT)
                    group_1 = VGroup(arc_1,brace_1)

                    arc_2 = Arc(radius=3,start_angle=0,angle=5*PI/6).set_color(YELLOW)
                    brace_2 = ArcBrace(arc_2)
                    group_2 = VGroup(arc_2,brace_2)

                    arc_3 = Arc(radius=0.5,start_angle=-0,angle=PI).set_color(BLUE)
                    brace_3 = ArcBrace(arc_3)
                    group_3 = VGroup(arc_3,brace_3)

                    arc_4 = Arc(radius=0.2,start_angle=0,angle=3*PI/2).set_color(GREEN)
                    brace_4 = ArcBrace(arc_4)
                    group_4 = VGroup(arc_4,brace_4)

                    arc_group = VGroup(group_1, group_2, group_3, group_4).arrange_in_grid(buff=1.5)
                    self.add(arc_group.center())

    Narc
Arc | Noner'   r"   r/   r
   c                   |t          ddd          }|j        |j        z   }t          t          |j        z  t          |z            }t
          t          j        |j                  z  }|j        dk    rb|	                    |j        t                      t                      j        |fd|i| | 	                    d|j        z  t                     n t                      j        |fd|i| |j        dk    r|                     |           n/|                     t
          t          j        d          z             |                     t          j                   |                     |                                           d S )Nr   r   )start_anglerK   radiusr1   r'   g333333?)r   r   rK   r   rG   r=   r5   logr   scaler9   rB   rC   rF   apply_complex_functionexpget_arc_center)rH   r   r'   r/   arc_end_anglelinescale_shiftrR   s          rS   rC   zArcBrace.__init__  sc    ;"Aa888C#)3B("}*<==bfSZ000:??JJszvJ666EGGTAAYA&AAAJJqCJ'VJ<<<<EGGTAAYA&AAA:JJ{####JJurvc{{*+++##BF+++

3%%''(((((rT   )r   r   r'   r"   r/   r
   )rw   rx   ry   rz   r=   rC   r{   r|   s   @rS   r   r     sU        4 4p "') ) ) ) ) ) ) ) ) ) )rT   r   )7rz   
__future__r   __all__typingr	   r
   r   numpyr5   svgelementsr?   manim._configr   manim.mobject.geometry.arcr   manim.mobject.geometry.liner   manim.mobject.mobjectr   )manim.mobject.opengl.opengl_compatibilityr   manim.mobject.text.tex_mobjectr   r   r   manim.mobject.text.text_mobjectr   animation.animationr   animation.compositionr   animation.fadingr   animation.growingr   	constants mobject.types.vectorized_mobjectr   utils.colorr   svg.svg_mobjectr   manim.typingr   r    r!   r"   manim.utils.color.corer#   r   r   r   r   r   r4   rT   rS   <module>r      s   ( ( " " " " " "
P
P
P + + + + + + + + + +                     * * * * * * , , , , , , ) ) ) ) ) ) E E E E E E L L L L L L L L L L 0 0 0 0 0 0 , , , , , , 3 3 3 3 3 3 & & & & & & / / / / / /     8 8 8 8 8 8             1 1 1 1 1 1 :IIIIIIIIIIII999999j+ j+ j+ j+ j+ j+ j+ j+ZM M M M M_ M M M M`4S 4S 4S 4S 4S
 4S 4S 4Sn*P *P *P *P *P *P *P *PZP) P) P) P) P)u P) P) P) P) P)rT   