
    lj                       d dl mZ d dlZd dlZd dlmZmZm	Z	 d dl
mZmZ d dlmZmZ d dlZd dlZd dlmZ d dlT d dlmZmZ d d	lmZ d d
lmZmZmZ d dlm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' d dl(m)Z)m*Z*m+Z+m,Z, d dl-m.Z. d dl/m0Z0m1Z1m2Z2 d dl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 g dZ:d Z; G d de          Z< G d de<          Z= G d dee<          Z> G d de=          Z? G d de<          Z@dS )    )annotationsN)CallableIterableSequence)reducewraps)AnySelf)config)*)OpenGLMobjectOpenGLPoint)ShaderWrapper)Point3DPoint3DLikePoint3DLike_Array)bezierbezier_remap$get_quadratic_approximation_of_cubic%get_smooth_cubic_bezier_handle_pointsinteger_interpolateinterpolatepartial_bezier_points(proportions_along_bezier_curve_for_point)BLACKWHITE
ManimColorParsableManimColor)_Data)	make_evenresize_with_interpolationtuplify)angle_between_vectorscross2dearclip_triangulationget_unit_normalshoelace_directionz_to_vector) triggers_refreshed_triangulationOpenGLVMobjectOpenGLVGroupOpenGLVectorizedPointOpenGLCurvesAsSubmobjectsOpenGLDashedVMobjectc                <     t                      fd            }|S )Nc                   t          j        d          }|                                 D ]}t          j        ||j        fd          }  | g|R i | t          j        d          }|                                 D ]}t          j        ||j        fd          } t          j        ||          s(|                                  |                                  | S )N)r      r   )axis)npemptyfamily_members_with_pointsconcatenatepointsarray_equalrefresh_triangulationrefresh_unit_normal)selfargskwargs
old_pointsmob
new_pointsfuncs         i/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/mobject/opengl/opengl_vectorized_mobject.pywrapperz1triggers_refreshed_triangulation.<locals>.wrapper2   s    Xf%%
2244 	J 	JCSZ(@qIIIJJT#D###F###Xf%%
2244 	J 	JCSZ(@qIIIJJ~j*55 	'&&((($$&&&    )r   )rA   rC   s   ` rB   r)   r)   1   s3    
4[[    [ NrD   c                      e Zd ZdZdej        dfdej        dfdej        dfdej        dfgZdej        dfd	ej        dfd
ej        dfdej        dfdej        dfdej        dfgZdZdZ	 e
            Z e
            Z e
            Z e
            Zddddedddddddddddej        dfd fd,Zdd1Zd2 Zed3             Zedd5            Zej        dd8            Z fd9Zd: Z	 	 	 ddd>Z	 	 	 	 	 dd?Z	 	 	 	 	 	 	 	 	 	 dd@ZdA ZddBZ ddCZ!ddDZ"dˈ fdF	Z#dG Z$dH Z%dI Z&dJ Z'dK Z(dL Z)dM Z*dN Z+dO Z,dP Z-dQ Z.dR Z/ ee+e          Z0 ee.e!          Z1 ee)e          Z2dS Z3dT Z4dU Z5ddVZ6dW Z7dX Z8dY Z9dd_Z:d` Z;da Z<ddcZ=dd Z>de Z?df Z@dg ZAdh ZBdi ZCdj ZDdkeEz  dfdlZFdm ZGddpZH	 dddrZIds ZJdt ZKdu ZLdv ZMdw ZNdx ZOdy ZPdd|ZQd} ZRd~ ZSd ZTd ZUd ZVddZWddZX	 dddZYddZZ	 dddZ[ddZ\	 dddZ]ddZ^ddZ_ddZ`ddZaddZbddZcddZdddZedddZfd Zgd ZhddZid Zjd ZkdddZlddZm fdZn	 dddZoddZpddZqddZres fd            Ztes fd            ZuesdЈ fd	            Zves fd            Zwes fd            Zxd Zyd Zzd Z{d Z|d Z}d Z~d Z fdZd Zd Zd Zd Zd Z xZS )r*   zA vectorized mobject.point)r1   unit_normalcolor)   
vert_index)   
prev_point
next_pointstroke_widthquadratic_bezier_strokequadratic_bezier_fillNg              ?F{Gz?g:0yE>r1   T
fill_colorParsableManimColor | Nonefill_opacityfloatstroke_colorstroke_opacitydraw_stroke_behind_fillbool*pre_function_handle_to_anchor_scale_factor$make_smooth_after_applying_functionsbackground_image_file
str | Nonetolerance_for_point_equalityn_points_per_curveint
long_linesshould_subdivide_sharp_curvesshould_remove_null_curves
joint_typeLineJointType | Noneflat_stroketriangulation_lockedc                   i | _         || _        || _        || _        || _        || _        || _        |	| _        |
| _        || _	        || _
        || _        || _        |t          j        }|| _        || _        || _        || _        d| _        t)          j        dd          | _        d| _        d | _        d | _        d | _        d | _        |                                   t;                      j        di | |                                  |tA          j!        |          | _"        |tA          j!        |          | _#        d S d S )NTr   i4dtyperK    )$datarU   rX   rN   rY   r[   r\   r]   r_   r`   rb   rc   rd   LineJointTypeAUTOre   rg   render_primitiverh   needs_new_triangulationr3   zerostriangulationorientation	fill_datastroke_datafill_shader_wrapperstroke_shader_wrapperinit_shader_datasuper__init__r:   r   parserS   rW   )r;   rS   rU   rW   rX   rN   rY   r[   r\   r]   r_   r`   rb   rc   rd   re   rg   rq   rh   r=   	__class__s                       rB   r|   zOpenGLVMobject.__init___   si   8 	(,('>$ 7 	7 5Y1%:" -I)"4$-J*)B&&+J$& 0$8!'+$Xat444#' %)"""6"""  """!(.z::DO# * 0 > >D $#rD   submobjectsIterable[OpenGLVMobject]returnr
   c                8    |                      |t                    S N)"_assert_valid_submobjects_internalr*   )r;   r   s     rB   _assert_valid_submobjectsz(OpenGLVMobject._assert_valid_submobjects   s    66{NSSSrD   c                    t           S r   )r+   r;   s    rB   get_group_classzOpenGLVMobject.get_group_class   s    rD   c                     t           S r   )r*   rm   rD   rB   get_mobject_type_classz%OpenGLVMobject.get_mobject_type_class   s    rD   Sequence[OpenGLVMobject]c                4    t          | d          r| j        ng S )N_submobjects)hasattrr   r   s    rB   r   zOpenGLVMobject.submobjects   s    $+D.$A$AIt  rIrD   submobject_listNonec                8     | j         | j           | j        |  d S r   )remover   add)r;   r   s     rB   r   zOpenGLVMobject.submobjects   s)    T%&&/""""rD   c                   t                                                       | j                            d           t	          j        d          | _        t	          j        d          | _        t	          j        d          | _        d S )Nrgbas)rK   rI   )rK   r1   )	r{   	init_datarn   popr3   rs   	fill_rgbastroke_rgbarG   )r;   r~   s    rB   r   zOpenGLVMobject.init_data   sh    	g&))8F++8F++rD   c                &   |                      | j        p| j        | j                   |                     | j        p| j        | j        | j        | j                   | 	                    | j
                   |                     | j                   | S )N)rH   opacity)rH   widthr   
background)set_fillrS   rH   rU   
set_strokerW   rN   rX   rY   	set_glossglossset_flat_strokerg   r   s    rB   init_colorszOpenGLVMobject.init_colors   s    //TZ% 	 	
 	
 	
 	#1tz#'3	 	 	
 	
 	
 	tz"""T-...rD   r   float | Nonerecursec                    ||| _         |r!| j        D ]}|                    |||           |                     ||d|           | S )aP  Set the fill color and fill opacity of a :class:`OpenGLVMobject`.

        Parameters
        ----------
        color
            Fill color of the :class:`OpenGLVMobject`.
        opacity
            Fill opacity of the :class:`OpenGLVMobject`.
        recurse
            If ``True``, the fill color of all submobjects is also set.

        Returns
        -------
        OpenGLVMobject
            self. For chaining purposes.

        Examples
        --------
        .. manim:: SetFill
            :save_last_frame:

            class SetFill(Scene):
                def construct(self):
                    square = Square().scale(2).set_fill(WHITE,1)
                    circle1 = Circle().set_fill(GREEN,0.8)
                    circle2 = Circle().set_fill(YELLOW) # No fill_opacity
                    circle3 = Circle().set_fill(color = '#FF2135', opacity = 0.2)
                    group = Group(circle1,circle2,circle3).arrange()
                    self.add(square)
                    self.add(group)

        See Also
        --------
        :meth:`~.OpenGLVMobject.set_style`
        Nr   )rU   r   r   set_rgba_array)r;   rH   r   r   
submobjects        rB   r   zOpenGLVMobject.set_fill   sg    R  'D 	=". = =
##E7G<<<<E7KAAArD   c                   ||| _         |r$| j        D ]}|                    |||||           |                     ||d|           |j|                     |          D ]T}t          |t          j                  r||_        $t          j	        d t          |          D                       |_        U||                     |          D ]	}||_        
| S )N)rH   r   r   r   r   r   c                    g | ]}|gS rm   rm   ).0r   s     rB   
<listcomp>z-OpenGLVMobject.set_stroke.<locals>.<listcomp>   s    0U0U0UU%0U0U0UrD   )rX   r   r   r   
get_family
isinstancer3   ndarrayrN   arrayr"   rY   )r;   rH   r   r   r   r   r   r?   s           rB   r   zOpenGLVMobject.set_stroke  s    ")D 	".  
%%#)# &     	E7M7CCCw// W WeRZ00 W',C$$')x0U0Ugenn0U0U0U'V'VC$$!w// 9 9.8++rD   c                   |#t          |t          |                    | _        n|                     |||
           |9t          |t          |                    | _        |                     |           n|                     ||||
           ||                     ||
           |	|                     |	|
           | S )N)rH   r   r   )r   )rH   r   r   r   r   )r!   lenr   r   r   r   r   
set_shadow)r;   rS   rU   r   rW   rX   r   rN   r   shadowr   s              rB   	set_stylezOpenGLVMobject.set_style'  s      6y#i..QQDNNMM
L'MRRR"8c)nnUUDOO,O////OO""&	     NN5'N222OOFGO444rD   c                D    | j         | j        | j        | j        | j        dS )Nr   r   rN   r   r   r   r   s    rB   	get_stylezOpenGLVMobject.get_styleJ  s,    + -Zk
 
 	
rD   c                   |                                 }t          j        t          j        k    r.|d         d         d         |d<   |                                 |d<    | j        di |ddi |rn| j        |j        }}t          |          dk    r| S t          |          dk    r|g}t          t          ||          ddiD ]\  }}|                    |           | S )	NrN   r   rU   r   FstrictTrm   )r   r   rendererRendererTypeOPENGLget_fill_opacityr   r   r   zipr    match_style)r;   vmobjectr   vmobject_stylesubmobs1submobs2sm1sm2s           rB   r   zOpenGLVMobject.match_styleS  s    !++--?l111-;N-KA-Nq-QN>*-1-B-B-D-DN>*77777777 		% "&!183GhH8}}!!X!##$:8X!>!>LtLL % %S$$$$rD   c                x    ||| _         |                     |||           |                     |||           | S Nr   r   )r   r   r   )r;   rH   r   r   s       rB   	set_colorzOpenGLVMobject.set_colore  sD    "DLeWg>>>w@@@rD   c                b    |                      ||           |                     ||           | S r   )r   r   )r;   r   r   s      rB   set_opacityzOpenGLVMobject.set_opacitym  s3    gw777999rD         ?c                   d|z
  }|                      ||                                 z  d           |                     ||                                 z  d           t	                                          ||           | S )NrQ   Fr   )r   r   r   get_stroke_opacityr{   fade)r;   darknessr   factorr~   s       rB   r   zOpenGLVMobject.fader  s    xT22444 	 	
 	
 	
 	T44666 	 	
 	
 	
 	Xw'''rD   c                $    d | j         D             S )Nc                F    g | ]}t          j        |d d                   S Nr1   r   from_rgbr   rgbas     rB   r   z2OpenGLVMobject.get_fill_colors.<locals>.<listcomp>  s+    III$
#D!H--IIIrD   r   r   s    rB   get_fill_colorszOpenGLVMobject.get_fill_colors  s    II$.IIIIrD   c                $    | j         d d df         S r   r   r   s    rB   get_fill_opacitiesz!OpenGLVMobject.get_fill_opacities  s    ~aaad##rD   c                $    d | j         D             S )Nc                F    g | ]}t          j        |d d                   S r   r   r   s     rB   r   z4OpenGLVMobject.get_stroke_colors.<locals>.<listcomp>  s+    KKK$
#D!H--KKKrD   r   r   s    rB   get_stroke_colorsz OpenGLVMobject.get_stroke_colors  s    KK$:JKKKKrD   c                $    | j         d d df         S r   r   r   s    rB   get_stroke_opacitiesz#OpenGLVMobject.get_stroke_opacities  s    1%%rD   c                    | j         S r   )rN   r   s    rB   get_stroke_widthsz OpenGLVMobject.get_stroke_widths  s      rD   c                6    |                                  d         S )z`
        If there are multiple colors (for gradient)
        this returns the first one
        r   )r   r   s    rB   get_fill_colorzOpenGLVMobject.get_fill_color  s    
 ##%%a((rD   c                6    |                                  d         S )zQ
        If there are multiple opacities, this returns the
        first
        r   )r   r   s    rB   r   zOpenGLVMobject.get_fill_opacity  s    
 &&((++rD   c                6    |                                  d         S Nr   )r   r   s    rB   get_stroke_colorzOpenGLVMobject.get_stroke_color      %%''**rD   c                6    |                                  d         S r   )r   r   s    rB   get_stroke_widthzOpenGLVMobject.get_stroke_width  r   rD   c                6    |                                  d         S r   )r   r   s    rB   r   z!OpenGLVMobject.get_stroke_opacity  s    ((**1--rD   c                z    |                                  s|                                 S |                                 S r   )has_fillr   r   r   s    rB   	get_colorzOpenGLVMobject.get_color  s6    }} 	+((***""$$$rD   c                z    |                                  r|                                 S |                                 S r   )
has_stroker   r   r   s    rB   
get_colorszOpenGLVMobject.get_colors  s8    ?? 	,))+++##%%%rD   c                    |                                  }|                                 }|d uo!|d uot          |          ot          |          S r   )r   r   any)r;   stroke_widthsstroke_opacitiess      rB   r   zOpenGLVMobject.has_stroke  sb    ..004466% & ,&M""& $%%		
rD   c                P    |                                  }|d uot          |          S r   )r   r   )r;   fill_opacitiess     rB   r   zOpenGLVMobject.has_fill  s+    0022T)Ac..A.AArD   c                z    |                                  r|                                 S |                                 S r   )r   r   r   r   s    rB   get_opacityzOpenGLVMobject.get_opacity  s6    ==?? 	+((***&&(((rD   c                D    |                      |          D ]	}||_        
| S r   )r   rg   )r;   rg   r   r?   s       rB   r   zOpenGLVMobject.set_flat_stroke  s+    ??7++ 	* 	*C)COOrD   c                    | j         S r   )rg   r   s    rB   get_flat_strokezOpenGLVMobject.get_flat_stroke  s    rD   c                H   t          |          t          |          cxk    rt          |          k    sn J | j        }t          j        |t          |          z  | j        f          }|||g}t          |          D ]\  }}|||d |<   |                     |           | S r   )r   r`   r3   rs   dim	enumerate
set_points)	r;   anchors1handlesanchors2nppcr@   arraysindexr   s	            rB   set_anchors_and_handlesz&OpenGLVMobject.set_anchors_and_handles  s    8}}G====H======&Xtc(mm3TX>??
GX.%f-- 	, 	,LE5&+Ju{d{##
###rD   c                v    |                                  | j        z  dk    sJ |                     |g           | S r   )get_num_pointsr`   append_points)r;   rF   s     rB   start_new_pathzOpenGLVMobject.start_new_path  sB    ""$$t'>>!CCCCE7###rD   anchor1r   handle1handle2anchor2c                T    t          ||||          }|                     |           d S r   )r   r  )r;   r  r  r  r  r@   s         rB   add_cubic_bezier_curvez%OpenGLVMobject.add_cubic_bezier_curve  s;     :	
 

 	:&&&&&rD   c                   |                                   t          |                                 |||          }|                                 r|                     |dd                    dS |                     |           dS )z#Add cubic bezier curve to the path.rK   N)throw_error_if_no_pointsr   get_last_pointhas_new_path_startedr  )r;   r  r  anchorquadratic_approxs        rB   add_cubic_bezier_curve_toz(OpenGLVMobject.add_cubic_bezier_curve_to  s    %%'''?!!	
 
 $$&& 	1/344444/00000rD   c                    |                                   |                                 r|                     ||g           d S |                     |                                 ||g           d S r   )r  r  r  r  )r;   handler  s      rB   add_quadratic_bezier_curve_toz,OpenGLVMobject.add_quadratic_bezier_curve_to  su    %%'''$$&& 	H/00000 3 3 5 5vvFGGGGGrD   Sequence[float]c                P   | j         d         t          j        dd| j                  }| j        r1t          d          fd|D             fd|D             z   }nfd|D             }|                                 r
|dd         }|                     |           | S )	zAdd a straight line from the last point of OpenGLVMobject to the given point.

        Parameters
        ----------

        point
            end of the straight line.
        r   rK   r   c                2    g | ]}t          |          S rm   r   )r   aendhalfways     rB   r   z.OpenGLVMobject.add_line_to.<locals>.<listcomp>  s%    CCCqk#w22CCCrD   c                2    g | ]}t          |          S rm   r%  )r   r&  r(  rF   s     rB   r   z.OpenGLVMobject.add_line_to.<locals>.<listcomp>  s8     G G G34GUA..G G GrD   c                2    g | ]}t          |          S rm   r%  )r   r&  r'  rF   s     rB   r   z.OpenGLVMobject.add_line_to.<locals>.<listcomp>  s%    AAAQk#ua00AAArD   N)r7   r3   linspacer`   rb   r   r  r  )r;   rF   alphasr7   r'  r(  s    `  @@rB   add_line_tozOpenGLVMobject.add_line_to  s     k"oQ4#:;;? 	B!#uc22GCCCCCFCCC G G G G G8>G G G FF BAAAA&AAAF$$&& 	 ABBZF6"""rD   c                    |                                  r|                     |           n>|                                  |                                 }|                     ||           | S r   )r  r-  r  get_reflection_of_last_handler   )r;   rF   
new_handles      rB   add_smooth_curve_toz"OpenGLVMobject.add_smooth_curve_to  sl    $$&& 	BU####))+++;;==J..z5AAArD   c                    |                                   |                                 }|                     |||           d S r   )r  r/  r  )r;   r  rF   r0  s       rB   add_smooth_cubic_curve_toz(OpenGLVMobject.add_smooth_cubic_curve_to%  sC    %%'''7799
&&z65AAAAArD   c                B    |                                  | j        z  dk    S NrK   r  r`   r   s    rB   r  z#OpenGLVMobject.has_new_path_started*  s!    ""$$t'>>!CCrD   c                    | j         d         S )Nr#  r7   r   s    rB   r  zOpenGLVMobject.get_last_point-  s    {2rD   c                8    | j         }d|d         z  |d         z
  S )N   r#  r8  r;   r7   s     rB   r/  z,OpenGLVMobject.get_reflection_of_last_handle0  s     6":~r
**rD   c                    |                                  s5|                     |                                 d         d                    d S d S )Nr#  r   )	is_closedr-  get_subpathsr   s    rB   
close_pathzOpenGLVMobject.close_path4  sN    ~~ 	9T..004Q788888	9 	9rD   c                Z    |                      | j        d         | j        d                   S )Nr   r#  )consider_points_equalsr7   r   s    rB   r>  zOpenGLVMobject.is_closed8  s$    **4;q>4;r?KKKrD      c                d  	 d |                      |          D             }|D ]}g }|                                D ]ʊ	t          	d         	d         z
  	d         	d         z
            }||k    rt          t	          j        ||z                      }t	          j        dd|dz             }|                    	fdt          |d d         |dd          d          D                        |	                    	           |
                    t	          j        |                     | S )	Nc                :    g | ]}|                                 |S rm   )
has_points)r   vms     rB   r   z9OpenGLVMobject.subdivide_sharp_curves.<locals>.<listcomp><  s%    JJJ"--//JJJJrD   rK   r   r:  c                8    g | ]\  }}t          ||          S rm   )r   )r   a1a2tups      rB   r   z9OpenGLVMobject.subdivide_sharp_curves.<locals>.<listcomp>E  s9        &B 2#r2>>  rD   r#  Tr   )r   get_bezier_tuplesr#   ra   r3   ceilr+  extendr   appendr  vstack)
r;   angle_thresholdr   vmobsvmobr@   anglenr,  rK  s
            @rB   subdivide_sharp_curvesz%OpenGLVMobject.subdivide_sharp_curves;  sU   JJdoog66JJJ 	3 	3DJ--// + +-c!fs1vos1vAOO?**BGEO$;<<==A[Aq1u55F%%   *-fSbSk6!"":d*S*S*S      %%c****OOBIj112222rD   c                :    |D ]}|                      |           |S r   )r-  )r;   r7   rF   s      rB   add_points_as_cornersz$OpenGLVMobject.add_points_as_cornersO  s-     	$ 	$EU####rD   r7   r   c                    | j         }t          j                   | j        fdt          j        dd|          D               | S )a  Given an array of points, set them as corner of the vmobject.

        To achieve that, this algorithm sets handles aligned with the anchors such that the resultant bezier curve will be the segment
        between the two anchors.

        Parameters
        ----------
        points
            Array of points that will be set as corners.

        Returns
        -------
        OpenGLVMobject
            self. For chaining purposes.
        c              3  Z   K   | ]%}t          d d         dd          |          V  &d S Nr#  rK   r%  )r   r&  r7   s     rB   	<genexpr>z7OpenGLVMobject.set_points_as_corners.<locals>.<genexpr>g  s?      WW!k&"+vabbz155WWWWWWrD   r   rK   )r`   r3   r   r  r+  r;   r7   r	  s    ` rB   set_points_as_cornersz$OpenGLVMobject.set_points_as_cornersT  s[      &&!!$$WWWWr{1aQU?V?VWWW	
 	
 rD   true_smoothc                X    |                      |           |                                  | S r   )r_  make_smooth)r;   r7   r`  s      rB   set_points_smoothlyz"OpenGLVMobject.set_points_smoothlyk  s/     	""6***rD   c           
     j   |dv sJ | j         }|                                 D ]}|                                }|                                 |D ]}t	          j        |dd|         |dd         g          }t	          j        |          }|dk    rt          |          |dd|<   n_|dk    r5t          |          \  }}	t          |dd         ||	|dd                   }n$|dk    rd|dd         |dd         z   z  |dd|<   |
                    |           |                                 | S )	a  Changes the anchor mode of the bezier curves. This will modify the handles.

        There can be only three modes, "jagged", "approx_smooth"  and "true_smooth".

        Returns
        -------
        OpenGLVMobject
            For chaining purposes.
        )jaggedapprox_smoothr`  Nr#  rf  rK   r`  re  r   )r`   r5   r?  clear_pointsr3   rQ  r   )get_smooth_quadratic_bezier_handle_pointsr   r   r  r9   )
r;   moder	  submobsubpathssubpathanchorsnew_subpathh1h2s
             rB   change_anchor_modez!OpenGLVMobject.change_anchor_moder  s~    AAAAA&5577 	+ 	+F**,,H!!!# 2 2)WVVtV_gbccl$CDD hw//?**+T, ,K4(( ]**B7KKFB"F	# #KK X%%+.'#2#,2L+MK4($$[1111((****rD   c                0    |                      d           | S )z
        This will double the number of points in the mobject,
        so should not be called repeatedly.  It also means
        transforming between states before and after calling
        this might have strange artifacts
        r`  rq  r   s    rB   rb  zOpenGLVMobject.make_smooth  s     	...rD   c                0    |                      d           | S )a1  
        Unlike make_smooth, this will not change the number of
        points, but it also does not result in a perfectly smooth
        curve.  It's most useful when the points have been
        sampled at a not-too-low rate from a continuous function,
        as in the case of ParametricCurve
        rf  rs  r   s    rB   make_approximately_smoothz(OpenGLVMobject.make_approximately_smooth  s     	000rD   c                0    |                      d           | S )Nre  rs  r   s    rB   make_jaggedzOpenGLVMobject.make_jagged  s    )))rD   c                j    t          |          | j        z  dk    sJ |                     |           | S r   )r   r`   r  r<  s     rB   add_subpathzOpenGLVMobject.add_subpath  s:    6{{T4499996"""rD   c                    t          |j                  }|                                 r*|                     t	          | j        dz
                       |                     |           | S r5  )listr7   r  resize_datar   r  )r;   vectorized_mobjectr@   s      rB   append_vectorized_mobjectz(OpenGLVMobject.append_vectorized_mobject  sd    ,344
$$&& 	3 Sq11222:&&&rD   c                X    t           j                            ||z
            | j        k     S r   )r3   linalgnormr_   )r;   p0p1s      rB   rB  z%OpenGLVMobject.consider_points_equals  s"    y~~b2g&&)JJJrD   target_directionstrc                    |dvrt          d          |                                 |k    r|                                  | S )zMakes sure that points are either directed clockwise or
        counterclockwise.

        Parameters
        ----------
        target_direction
            Either ``"CW"`` or ``"CCW"``.
        )CWCCWz4Invalid input for force_direction. Use "CW" or "CCW")
ValueErrorget_directionreverse_points)r;   r  s     rB   force_directionzOpenGLVMobject.force_direction  sM     =00STTT#333!!!rD   c                L    |                      | j        ddd                    | S )aB  Reverts the point direction by inverting the point order.

        Returns
        -------
        :class:`OpenGLVMobject`
            Returns self.

        Examples
        --------
        .. manim:: ChangeOfDirection

            class ChangeOfDirection(Scene):
                def construct(self):
                    ccw = RegularPolygon(5)
                    ccw.shift(LEFT)
                    cw = RegularPolygon(5)
                    cw.shift(RIGHT).reverse_direction()

                    self.play(Create(ccw), Create(cw),
                    run_time=4)
        Nr#  )r  r7   r   s    rB   reverse_directionz OpenGLVMobject.reverse_direction  s(    , 	DDbD)***rD   c                    | j         }t          |          |z  }|d t          |          |z
           }|                    d|df          S )Nr#  r1   )r`   r   reshape)r;   r7   r	  	remainders       rB   get_bezier_tuples_from_pointsz,OpenGLVMobject.get_bezier_tuples_from_points  sM    &KK$&	1#f++	112~~r4m,,,rD   c                6    |                      | j                  S r   )r  r7   r   s    rB   rM  z OpenGLVMobject.get_bezier_tuples  s    11$+>>>rD   c                p   | j         dz
  d         d          z
  }||z                      d          | j        k    }t          j        t                    t                    |         }dg|t                    }fdt          |d d         |dd          d          D             S )NrK   r#  rk   r   c                <    g | ]\  }}||z
  k    ||         S rm   rm   )r   i1i2r	  r7   s      rB   r   z;OpenGLVMobject.get_subpaths_from_points.<locals>.<listcomp>  s>     
 
 
BRD   2b5M   rD   TrL  )r`   sumr_   r3   aranger   ra   r   )r;   r7   diffssplitssplit_indicesr	  s    `   @rB   get_subpaths_from_pointsz'OpenGLVMobject.get_subpaths_from_points  s    &tax"t+,vdjDj/AA%-$$Q''$*KK	$FTEEEfM 8]8CKK8
 
 
 
 
mCRC0-2CDQQQ
 
 
 	
rD   c                6    |                      | j                  S )a  Returns subpaths formed by the curves of the OpenGLVMobject.

        Subpaths are ranges of curves with each pair of consecutive
        curves having their end/start points coincident.

        Returns
        -------
        Tuple
            subpaths.
        )r  r7   r   s    rB   r?  zOpenGLVMobject.get_subpaths  s     ,,T[999rD   rV  
np.ndarrayc                t    ||                                  k     sJ | j        }| j        ||z  ||dz   z           S )a  Returns the points defining the nth curve of the vmobject.

        Parameters
        ----------
        n
            index of the desired bezier curve.

        Returns
        -------
        np.ndarray
            points defininf the nth bezier curve (anchors, handles)
        rK   )get_num_curvesr`   r7   )r;   rV  r	  s      rB   get_nth_curve_pointsz#OpenGLVMobject.get_nth_curve_points  sG     4&&((((((&{4!8da!en455rD   Callable[[float], np.ndarray]c                F    t          |                     |                    S )zReturns the expression of the nth curve.

        Parameters
        ----------
        n
            index of the desired curve.

        Returns
        -------
        typing.Callable[float]
            expression of the nth bezier curve.
        )r   r  )r;   rV  s     rB   get_nth_curve_functionz%OpenGLVMobject.get_nth_curve_function&  s      d//22333rD   sample_points
int | None+tuple[Callable[[float], np.ndarray], float]c                    |d}|                      |          }|                     ||          }t          j        |          }||fS )a  Returns the expression of the nth curve along with its (approximate) length.

        Parameters
        ----------
        n
            The index of the desired curve.
        sample_points
            The number of points to sample to find the length.

        Returns
        -------
        curve : Callable[[float], np.ndarray]
            The function for the nth curve.
        length : :class:`float`
            The length of the nth curve.
        N
   )r  get_nth_curve_length_piecesr3   r  )r;   rV  r  curvenormslengths         rB   "get_nth_curve_function_with_lengthz1OpenGLVMobject.get_nth_curve_function_with_length5  sN    *  M++A..00MBBf}rD   c                :    |                                  | j        z  S )zReturns the number of curves of the vmobject.

        Returns
        -------
        int
            number of curves. of the vmobject.
        r6  r   s    rB   r  zOpenGLVMobject.get_num_curvesT  s     ""$$(???rD   c                8    |                      ||          \  }}|S )aW  Returns the (approximate) length of the nth curve.

        Parameters
        ----------
        n
            The index of the desired curve.
        sample_points
            The number of points to sample to find the length.

        Returns
        -------
        length : :class:`float`
            The length of the nth curve.
        )r  )r;   rV  r  _r  s        rB   get_nth_curve_lengthz#OpenGLVMobject.get_nth_curve_length^  s"    & ;;A}MM	6rD   'Iterable[Callable[[float], np.ndarray]]c              #     K   |                                  }t          |          D ]}|                     |          V  dS )zGets the functions for the curves of the mobject.

        Returns
        -------
        Iterable[Callable[[float], np.ndarray]]
            The functions for the curves.
        N)r  ranger  )r;   
num_curvesrV  s      rB   get_curve_functionsz"OpenGLVMobject.get_curve_functionsu  sW       ((**
z"" 	1 	1A--a000000	1 	1rD   c                   |d}|                      |          t          j        fdt          j        dd|          D                       }|dd         |dd         z
  }t          j        t          j        j        d|          }|S )ak  Returns the array of short line lengths used for length approximation.

        Parameters
        ----------
        n
            The index of the desired curve.
        sample_points
            The number of points to sample to find the length.

        Returns
        -------
        np.ndarray
            The short length-pieces of the nth curve.
        Nr  c                &    g | ]} |          S rm   rm   )r   r&  r  s     rB   r   z>OpenGLVMobject.get_nth_curve_length_pieces.<locals>.<listcomp>  s!    NNN5588NNNrD   r   rK   r#  )r  r3   r   r+  apply_along_axisr  r  )r;   rV  r  r7   r  r  r  s         @rB   r  z*OpenGLVMobject.get_nth_curve_length_pieces  s    &  M++A..NNNNR[A}-M-MNNNOOqrr
VCRC[(#BINAu==rD   5Iterable[tuple[Callable[[float], np.ndarray], float]]c              +  v   K   |                                  }t          |          D ]} | j        |fi |V  dS )ai  Gets the functions and lengths of the curves for the mobject.

        Parameters
        ----------
        **kwargs
            The keyword arguments passed to :meth:`get_nth_curve_function_with_length`

        Returns
        -------
        Iterable[Tuple[Callable[[float], np.ndarray], float]]
            The functions and lengths of the curves.
        N)r  r  r  )r;   r=   r  rV  s       rB    get_curve_functions_with_lengthsz/OpenGLVMobject.get_curve_functions_with_lengths  sb       ((**
z"" 	G 	GA9$9!FFvFFFFFF	G 	GrD   alphar   c                   |dk     s|dk    rt          d| d          |                                  |dk    r| j        d         S t          |                                           }|t          j        t          j        d |D             t
          j                            z  }d}|D ]1\  }}||z   |k    r|dk    r	||z
  |z  }nd} ||          c S ||z  }2dS )	a  Gets the point at a proportion along the path of the :class:`OpenGLVMobject`.

        Parameters
        ----------
        alpha
            The proportion along the the path of the :class:`OpenGLVMobject`.

        Returns
        -------
        :class:`Point3D`
            The point on the :class:`OpenGLVMobject`.

        Raises
        ------
        :exc:`ValueError`
            If ``alpha`` is not between 0 and 1.
        :exc:`Exception`
            If the :class:`OpenGLVMobject` has no points.
        r   rK   zAlpha z not between 0 and 1.r#  c              3      K   | ]	\  }}|V  
d S r   rm   r   r  r  s      rB   r]  z7OpenGLVMobject.point_from_proportion.<locals>.<genexpr>  s&      DDIAvDDDDDDrD   rk   N)	r  r  r7   tupler  r3   r  fromiterfloat64)r;   r  curves_and_lengthstarget_lengthcurrent_lengthr  r  residues           rB   point_from_proportionz$OpenGLVMobject.point_from_proportion  s   ( 199		BeBBBCCC%%'''A::;r?""4#H#H#J#JKKKDD1CDDDBJWWW!
 !
 
 / 		% 		%ME6&-77Q;;,~=GGGGuW~~%%%f$NN		% 		%rD   c                   |                                   |                                 }|                                 }d}t          |          D ]m}|                     |          }|                     |          }t          ||          }t          |          dk    rt          |          }	|||	z  z  } n||z  }nt          d| d          ||z  }
|
S )aN  Returns the proportion along the path of the :class:`OpenGLVMobject`
        a particular given point is at.

        Parameters
        ----------
        point
            The Cartesian coordinates of the point which may or may not lie on the :class:`OpenGLVMobject`

        Returns
        -------
        float
            The proportion along the path of the :class:`OpenGLVMobject`.

        Raises
        ------
        :exc:`ValueError`
            If ``point`` does not lie on the curve.
        :exc:`Exception`
            If the :class:`OpenGLVMobject` has no points.
        r   zPoint z does not lie on this curve.)
r  r  get_arc_lengthr  r  r  r   r   maxr  )r;   rF   r  total_lengthr  rV  control_pointsr  proportions_along_bezierproportion_along_nth_curver  s              rB   proportion_from_pointz$OpenGLVMobject.proportion_from_point  s   0 	%%''' ((**
**,,z"" 	K 	KA!66q99N..q11F'O( ($ +,,q00-01I-J-J**D!DDV#MMIeIIIJJJ,rD   Iterable[np.ndarray]c                Z    | j         | j        fdt                    D             S )z
        Returns anchors1, handles, anchors2,
        where (anchors1[i], handles[i], anchors2[i])
        will be three points defining a quadratic bezier curve
        for any i in range(0, len(anchors1))
        c                &    g | ]}|d          S r   rm   )r   ir	  r7   s     rB   r   z:OpenGLVMobject.get_anchors_and_handles.<locals>.<listcomp>#  s#    555Aqw$w555rD   )r`   r7   r  )r;   r	  r7   s    @@rB   get_anchors_and_handlesz&OpenGLVMobject.get_anchors_and_handles  s8     &55555t5555rD   c                ,    | j         dd| j                 S )zReturns the start anchors of the bezier curves.

        Returns
        -------
        np.ndarray
            Starting anchors
        r   N)r7   r`   r   s    rB   get_start_anchorsz OpenGLVMobject.get_start_anchors%  s     {17 7788rD   c                6    | j         }| j        |dz
  d|         S )zReturn the starting anchors of the bezier curves.

        Returns
        -------
        np.ndarray
            Starting anchors
        rK   N)r`   r7   )r;   r	  s     rB   get_end_anchorszOpenGLVMobject.get_end_anchors/  s%     &{4!8+t+,,rD   c           	        | j         }t          |          dk    r|S |                                 }|                                 }t	          t
          j                            t          ||d                              S )zReturns the anchors of the curves forming the OpenGLVMobject.

        Returns
        -------
        Iterable[np.ndarray]
            The anchors.
        rK   TrL  )	r7   r   r  r  r{  itchainfrom_iterabler   )r;   r7   ses       rB   get_anchorszOpenGLVMobject.get_anchors:  sp     v;;!M""$$  ""BH**3q!D+A+A+ABBCCCrD   &.>c                    | j         | j        t          t          j        fdt          d          D                       }|                                       S )Nc           	         g | ]=}t          |d          dd          z
            k                        d          >S )Nr   rK   )absr   )r   r  atolr	  r7   s     rB   r   zAOpenGLVMobject.get_points_without_null_curves.<locals>.<listcomp>O  s]        VAGtG_vagg677$>CCAFF  rD   rK   )r`   r7   r   opor_r  repeat)r;   r  distinct_curvesr	  r7   s    ` @@rB   get_points_without_null_curvesz-OpenGLVMobject.get_points_without_null_curvesJ  s{    & F     q$  
 
 o,,T2233rD   sample_points_per_curvec                f    t          j        d |                     |          D                       S )ad  Return the approximated length of the whole curve.

        Parameters
        ----------
        sample_points_per_curve
            Number of sample points per curve used to approximate the length. More points result in a better approximation.

        Returns
        -------
        float
            The length of the :class:`OpenGLVMobject`.
        c              3      K   | ]	\  }}|V  
d S r   rm   r  s      rB   r]  z0OpenGLVMobject.get_arc_length.<locals>.<genexpr>c  s:       
 
6 
 
 
 
 
 
rD   )r  )r3   r  r  )r;   r  s     rB   r  zOpenGLVMobject.get_arc_lengthV  sM     v 
 
!BB5 C  
 
 
 
 
 	
rD   c                H   |                                  st          j        d          S | j        }| j        }|dd |         }||dz
  d |         }dt          j        t          |d d df         |d d df         z   |d d df         |d d df         z
  z            t          |d d df         |d d df         z   |d d df         |d d df         z
  z            t          |d d df         |d d df         z   |d d df         |d d df         z
  z            g          z  S )Nr1   r   rK   r   r:  )rF  r3   rs   r`   r7   r   r  )r;   r	  r7   r  r  s        rB   get_area_vectorzOpenGLVMobject.get_area_vectorj  sk   
    	8A;;&AGtG_D1H$$% RX1X111a4(R1X111a4-@A  1X111a4(R1X111a4-@A  1X111a4(R1X111a4-@A 

 
 
 	
rD   c                D    t          |                                           S )a  Uses :func:`~.space_ops.shoelace_direction` to calculate the direction.
        The direction of points determines in which direction the
        object is drawn, clockwise or counterclockwise.

        Examples
        --------
        The default direction of a :class:`~.Circle` is counterclockwise::

            >>> from manim import Circle
            >>> Circle().get_direction()
            'CCW'

        Returns
        -------
        :class:`str`
            Either ``"CW"`` or ``"CCW"``.
        )r'   r  r   s    rB   r  zOpenGLVMobject.get_direction  s    $ "$"8"8":":;;;rD   c                D   |s| j         d         S t          | j                  dk     rt          S |                                 }t
          j                            |          }|dk    r||z  S | j        }t          |d         |d         z
  |d         |d         z
            S )Nr   r1   rK   r:  )	rG   r   r7   OUTr  r3   r  r  r&   )r;   	recompute	area_vectarear7   s        rB   r&   zOpenGLVMobject.get_unit_normal  s     	'#A&&t{aJ((**	y~~i((!88t##[F"q	F1I%q	F1I%  rD   c                t    |                                  D ]"}|                    d          |j        d d <   #| S )NT)r  )r   r&   rG   r;   r?   s     rB   r:   z"OpenGLVMobject.refresh_unit_normal  sF    ??$$ 	E 	EC!$!4!4t!4!D!DCOAAArD   c                                                      t          |j                  k    rd S  |fD ]q}|                                s'|                    |                                           |                                r |                    |j        d                    r                                 }|                                }t          t          |          t          |                    }g }g } j
         fd}t          |          D ]}	t          j         |||	                    }
t          j         |||	                    }t          dt          |          t          |
          z
  z            }t          dt          |
          t          |          z
  z            }                     ||
          }
                     ||          }|                    |
           |                    |                                t          j        |                     |                    t          j        |                      S )Nr   c                   |t          |           k    r| d         d         gz  S | |         }t          |          k    rI                    | d          | dz
                     r|d           }nnt          |          k    I|S r\  )r   rB  )	path_listrV  pathr	  r;   s      rB   get_nth_subpathz4OpenGLVMobject.align_points.<locals>.get_nth_subpath  s    C	NN""!"b)*T11Q<D d))d""..tTEFF|T4%!)_MM $<DD d))d"" KrD   )r  r   r7   rF  r  
get_centerr  r-  r?  r  r`   r  r3   asarrayinsert_n_curves_to_point_listrP  r  rQ  )r;   r   r?   	subpaths1	subpaths2
n_subpathsnew_subpaths1new_subpaths2r  rV  sp1sp2diff1diff2r	  s   `             @rB   align_pointszOpenGLVMobject.align_points  s:     C$8$888F> 	/ 	/C >>## 5""3>>#3#3444 '')) /
1... %%''	))++	YY88
&	 	 	 	 	 	 z"" 	& 	&A*__Y::;;C*__Y::;;CCHHs3xx/D899ECHHs3xx/D899E44UC@@C44UC@@C  %%%  %%%%	-00111BIm44555rD   c                >   |                      |          D ]}|                                dk    rl|                    ||j                  }|                                r(t          j        ||                                g          }|                    |           | S )zInserts n curves to the bezier curves of the vmobject.

        Parameters
        ----------
        n
            Number of curves to insert.

        Returns
        -------
        OpenGLVMobject
            for chaining.
        r   )	r   r  r  r7   r  r3   rQ  r  r  )r;   rV  r   r?   r@   s        rB   insert_n_curveszOpenGLVMobject.insert_n_curves  s     ??7++ 	+ 	+C!!##a'' >>q#*MM
++-- O!#J8J8J8L8L+M!N!NJz***rD   c                
   | j         }t          |          dk    rt          j        |||z  d          S |                     |          }t          |          }||z   }t          ||          }|                    dd          }|S )an  Given an array of k points defining a bezier curves
         (anchors and handles), returns points defining exactly
        k + n bezier curves.

        Parameters
        ----------
        n
            Number of desired curves.
        points
            Starting points.

        Returns
        -------
        np.ndarray
            Points generated.
        rK   r   r#  r1   )r`   r   r3   r  r  r   r  )	r;   rV  r7   r	  bezier_tuplescurrent_number_of_curvesnew_number_of_curvesnew_bezier_tuplesr@   s	            rB   r  z,OpenGLVMobject.insert_n_curves_to_point_list  s    " &v;;!9VTAXq111::6BB#&}#5#5 7!;(8LMM&..r155
rD   c                    t                      j        |||g|R i | t          d         r|                                  n|                                 rt|                                }|                                }t          |          t          |          k    st          j        ||k              s|                                  | S )Nuse_projection_fill_shaders)	r{   r   r   r9   r   get_triangulationr   r3   all)	r;   mobject1mobject2r  r<   r=   tri1tri2r~   s	           rB   r   zOpenGLVMobject.interpolate  s    HhGGGGGGG/0 	1&&((((}} 111331133t99D		))1E1E)..000rD   r   r&  bremapc                B   t          |t                    sJ |dk    r"|dk    r|                     |j                   | S |                                }t          |          }t          d||          \  }}t          d||          \  }	}
|                                  |dk    r| S ||	k    r+|                     t          ||         ||
                     n|                     t          ||         |d                     ||dz   |	         }t          |          dk    rS|rt          ||dz
            }n|}|                     t          j        |                              dd                     |                     t          ||	         d|
                     | S )aZ  Given two bounds a and b, transforms the points of the self vmobject into the points of the vmobject
        passed as parameter with respect to the bounds. Points here stand for control points of the bezier curves (anchors and handles)

        Parameters
        ----------
        vmobject
            The vmobject that will serve as a model.
        a
            upper-bound.
        b
            lower-bound
        remap
            if the point amount should be kept the same (True)
            This option should be manually set to False if keeping the number of points is not needed
        r   rK   r:  r#  r1   )r   r*   r  r7   rM  r   r   rg  r  r   r   r3   r   r  )r;   r   r&  r  r  bezier_tripletsnum_quadraticslower_indexlower_residueupper_indexupper_residueinner_pointsnew_tripletss                rB   pointwise_become_partialz'OpenGLVMobject.pointwise_become_partial%  s   $ (N33333
 66a1ffOOHO,,,K"4466_--
 &9NA%N%N"]%8NA%N%N"]QK+%%%#K0!!     %ok&BMSTUU   +;?[+HIL<  1$$ 3#/nq>P#Q#QLL#2L""2:l#;#;#C#CB#J#JKKK%ok&BA}UU   rD   c                \    |                                  }|                    | ||           |S )aW  Returns the subcurve of the OpenGLVMobject between the interval [a, b].
        The curve is a OpenGLVMobject itself.

        Parameters
        ----------

        a
            The lower bound.
        b
            The upper bound.

        Returns
        -------
        OpenGLVMobject
            The subcurve between of [a, b]
        )copyr&  )r;   r&  r  rT  s       rB   get_subcurvezOpenGLVMobject.get_subcurvec  s.    " yy{{%%dAq111rD   c                B    |                                  D ]	}d|_        
| S NT)r   rr   r  s     rB   r9   z$OpenGLVMobject.refresh_triangulationz  s+    ??$$ 	/ 	/C*.C''rD   c                   ||                                  }| j        s| j        S | j        }t	          |          dk    r)t          j        dd          | _        d| _        | j        S t          j        |t                    	                                s"t          j
        |t          |                    }t          j        t	          |          t                    }|dd d         }|dd d         }|dd d         }||z
  }||z
  }t          ||          }	t          j        |	          }
| j        }t          j        t	          |          t"                    }t          j        |d d         |dd          z
            |k                        d          |d d<   d	|d<   |
dk     }t          j        |dd d         |dd d         |         |dd d         |         g          }|                                 t          j        dt	          |          dz             |dz  dk             }||         }|t-          ||                   }t          j        ||g          }|| _        d| _        |S )
NrK   r   rj   rk   Fr1   r:  r#  T)r&   rr   rt   r7   r   r3   rs   iscloser  r  dotr(   r  ra   r$   signr_   rZ   r  r   hstacksortr%   )r;   normal_vectorr7   indicesb0sb1sb2sv01sv12scrossesconvexitiesr  end_of_loopconcave_partsinner_vert_indicesringsinner_vertsinner_tri_indicestri_indicess                      rB   r  z OpenGLVMobject.get_triangulation  st      0022M+ 	&%%v;;!!#!4!8!8!8D+0D(%%z---1133 	@VFK$>$>??F)CKKs333QTTlQTTlQTTlSySy$%%gg&&0hs3xxt444F3ss8c!""g#566=BB1EECRCB#a  Y11m,1k*
 
 	!!!	!S!344q899:Lq:PTU:UV /0.!+u55
 i*; <==(',$rD   c                J    t                                          |           | S r   )r{   r  )r;   r7   r~   s     rB   r  zOpenGLVMobject.set_points  s     6"""rD   c                J    t                                          |           | S r   )r{   set_data)r;   rn   r~   s     rB   rD  zOpenGLVMobject.set_data  s     rD   c                v     t                      j        |fi | | j        s|r|                                  | S r   )r{   apply_functionr\   ru  )r;   functionrb  r=   r~   s       rB   rF  zOpenGLVMobject.apply_function  sK    x2262224 	- 	-**,,,rD   c                :     t                      j        |i | | S r   )r{   apply_points_functionr;   r<   r=   r~   s      rB   rI  z$OpenGLVMobject.apply_points_function  s$    %%t6v666rD   c                :     t                      j        |i | | S r   )r{   fliprJ  s      rB   rL  zOpenGLVMobject.flip  s#    d%f%%%rD   c                H   t          j        d| j                  | _        t          j        d| j                  | _        t          | j        t          j        dd          | j        | j                  | _	        t          | j        | j
        | j                  | _        d S )Nr   rk   rj   )	vert_datavert_indicesshader_folderrq   )rN  rP  rq   )r3   rs   
fill_dtyperv   stroke_dtyperw   r   fill_shader_folderrq   rx   stroke_shader_folderry   r   s    rB   rz   zOpenGLVMobject.init_shader_data  s    !4?;;;8AT->???#0n!40001!2	$
 $
 $
  &3&3!2&
 &
 &
"""rD   c                P    | j         | j        fD ]}|                                 | S r   )rx   ry   
refresh_id)r;   rC   s     rB   refresh_shader_wrapper_idz(OpenGLVMobject.refresh_shader_wrapper_id  s6    0$2LM 	! 	!G    rD   c                8    |                                   | j        S r   )update_fill_shader_wrapperrx   r   s    rB   get_fill_shader_wrapperz&OpenGLVMobject.get_fill_shader_wrapper  s    '')))''rD   c                    |                                  | j        _        |                                 | j        _        |                                 | j        _        | j        | j        _        d S r   )get_fill_shader_datarx   rN  r  rO  get_fill_uniformsuniforms
depth_testr   s    rB   rY  z)OpenGLVMobject.update_fill_shader_wrapper  sZ    -1-F-F-H-H *040F0F0H0H -,0,B,B,D,D ).2o +++rD   c                8    |                                   | j        S r   )update_stroke_shader_wrapperry   r   s    rB   get_stroke_shader_wrapperz(OpenGLVMobject.get_stroke_shader_wrapper  s    ))+++))rD   c                    |                                  | j        _        |                                 | j        _        | j        | j        _        d S r   )get_stroke_shader_datary   rN  get_stroke_uniformsr^  r_  r   s    rB   ra  z+OpenGLVMobject.update_stroke_shader_wrapper  sC    /3/J/J/L/L",.2.F.F.H.H"+04"---rD   c                   g }g }g }|                                  D ]}|                                r4t          d         s'|                    |                                           |                                rSt          d         sF|                                }|j        r|                    |           |                    |           |||g}g }|D ]3}|r/|d         }	 |	j        |dd            |                    |	           4|S )Nr  use_projection_stroke_shadersr   rK   )	r5   r   r   rP  rZ  r   rb  rY   combine_with)
r;   fill_shader_wrappersstroke_shader_wrappersback_stroke_shader_wrappersrj  sswwrapper_listsresultwlistrC   s
             rB   get_shader_wrapper_listz&OpenGLVMobject.get_shader_wrapper_list  sB   !!#&(#5577 	7 	7F   N0M)N N$++F,J,J,L,LMMM  "" 762Q+R 766881 7/66s;;;;*11#666 ( "

 " 	' 	'E '($$eABBi00g&&&rD   c                    t          t                                                                }| j        j        |d<   t          | j                  |d<   |S )Nre   rg   )dictr{   get_shader_uniformsre   valuerV   rg   )r;   rn  r~   s     rB   re  z"OpenGLVMobject.get_stroke_uniforms  sI    egg113344#4| %d&6 7 7}rD   c                x    t          | j                  t          | j                  | j        | j        | j        dS )N)is_fixed_in_frameis_fixed_orientationfixed_orientation_centerr   r   )rV   rv  rw  rx  r   r   r   s    rB   r]  z OpenGLVMobject.get_fill_uniforms"  s=    !&t'=!>!>$)$*C$D$D(,(EZk
 
 	
rD   c                   | j         }t          | j                  t          |          k    r2t          j        t          |          t
          j                  | _        d| j        vr}| j        }|| j        d<   || d          | j        d         d |<   |d |          | j        d         |d <   ||d          | j        d         d | <   |d |         | j        d         | d <   | 	                    | j        dd           | 	                    | j        dd           | 	                    | j        d	d	           | j        S )
Nrk   r7   rF   rL   rM   rH   r   rN   rG   )
r7   r   rw   r3   rs   r*   rR  locked_data_keysr`   read_data_to_shaderr^  s      rB   rd  z%OpenGLVMobject.get_stroke_shader_data+  sB   t  CKK//!xF>;VWWWD4000*D(.DW%4:D566ND\*5D514:6TE6ND\*45515;DEE]D\*6TE625;ETE]D\*D5662  !17MJJJ  !1>>RRR  !1=-PPPrD   c                   | j         }t          | j                  t          |          k    r`t          j        t          |          t
          j                  | _        t          t          |                    | j        d         d d df<   |                     | j        dd           |                     | j        dd           |                     | j        dd           | j        S )	Nrk   rJ   r   rF   r7   rH   r   rG   )	r7   r   rv   r3   rs   r*   rQ  r  r{  r<  s     rB   r\  z#OpenGLVMobject.get_fill_shader_data>  s    t~#f++--Xc&kk9RSSSDN16s6{{1C1CDN<(A.  (CCC  +FFF  NNN~rD   c                V    |                                   |                                  d S r   )r\  rd  r   s    rB   refresh_shader_dataz"OpenGLVMobject.refresh_shader_dataJ  s,    !!#####%%%%%rD   c                *    |                                  S r   )r  r   s    rB   get_fill_shader_vert_indicesz+OpenGLVMobject.get_fill_shader_vert_indicesN  s    %%'''rD   )"rS   rT   rU   rV   rW   rT   rX   rV   rN   rV   rY   rZ   r[   rV   r\   rV   r]   r^   r_   rV   r`   ra   rb   rZ   rc   rZ   rd   rZ   re   rf   rg   rZ   rh   rZ   )r   r   r   r
   )r   r   )r   r   r   r   )NNT)rH   rT   r   r   r   rZ   r   r*   )NNNNT)
NNNNNNNNNT)Tr+  )r   T)TT)r  r   r  r   r  r   r  r   )rF   r!  r   r*   )r7   r   r   r*   )F)r7   r   r`  rZ   r   r
   )r  r  )rV  ra   r   r  )rV  ra   r   r  r   )rV  ra   r  r  r   r  )r   ra   )rV  ra   r  r  r   rV   )r   r  )rV  ra   r  r  r   r  )r   r  )r  rV   r   r   )rF   r   r   rV   )r   r  )r   r  )r  )r  r  r   rV   )rV  ra   r   r*   )rV  ra   r7   r  r   r  )
r   r*   r&  rV   r  rV   r  rZ   r   r*   )r&  rV   r  rV   r   r*   )r   r
   )__name__
__module____qualname____doc__r3   float32rQ  rR  rT  rS  r   r   r   rN   rG   DEFAULT_STROKE_WIDTHmoderngl	TRIANGLESr|   r   r   staticmethodr   propertyr   setterr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rW   rH   rS   r   r   r   r   r  r  r  r  r  r   r-  r1  r3  r  r  r/  r@  r>  DEGREESrW  rY  r_  rc  rq  rb  ru  rw  ry  r~  rB  r  r  r  rM  r  r?  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r&   r:   r  r  r  r   r&  r)  r9   r  r)   r  rD  rF  rI  rL  rz   rW  rZ  rY  rb  ra  rp  re  r]  rd  r\  r~  r  __classcell__r~   s   @rB   r*   r*   C   s3
        
"*d#	
D)	"*d#	rz4(	J 
"*d#	rz4(	rz4(	
D)	T*	"*d#L 50
 I%''K577L%''K 15!26 #2(- =A6;,0 /3"# .3*/+/ !+%*3G? G? G? G? G? G? G?RT T T T     \ J J J XJ # # # #, , , , ,  " ,0 $	0 0 0 0 0h        H ! ! ! !F
 
 
   $      
     J J J$ $ $L L L& & &! ! !
) ) ), , ,+ + ++ + +. . .% % %
& & &
 8,j99LHY	**E.(33J
 
 
B B B) ) )
   
         
' ' ' '1 1 1H H H   .  B B B
D D D  + + +9 9 9L L L 68'\4    (  
   0 >C    # # #J  	 	 	    
  K K K   "  2- - -? ? ?
 
 
": : :6 6 6 6"4 4 4 4$ %)    >@ @ @ @ %)    .1 1 1 1$ %)    :G G G G(+% +% +% +%Z6 6 6 6p	6 	6 	6 	69 9 9 9	- 	- 	- 	-D D D D 
4 
4 
4 
4
 
 
 
 
(
 
 
8< < <(   $  3 3 3j    ,   8
 
 
 
 
 KO< < < < <|   .   
: : : :x &    &% &    &%
 &     &% &    &% &    &%

 
 
  
( ( (> > >* * *@ @ @
  :    
 
 
     &
 
 
& & &( ( ( ( ( ( (rD   r*   c                  \     e Zd ZdZd fdZd Zd Zd fd	Zd
 Zd Z	d Z
d ZddZ xZS )r+   ax  A group of vectorized mobjects.

    This can be used to group multiple :class:`~.OpenGLVMobject` instances together
    in order to scale, move, ... them together.

    Examples
    --------

    To add :class:`~.OpenGLVMobject`s to a :class:`~.OpenGLVGroup`, you can either use the
    :meth:`~.OpenGLVGroup.add` method, or use the `+` and `+=` operators. Similarly, you
    can subtract elements of a OpenGLVGroup via :meth:`~.OpenGLVGroup.remove` method, or
    `-` and `-=` operators:

    .. doctest::

        >>> from manim import config
        >>> original_renderer = config.renderer
        >>> config.renderer = "opengl"

        >>> from manim import Triangle, Square
        >>> from manim.opengl import OpenGLVGroup
        >>> config.renderer
        <RendererType.OPENGL: 'opengl'>
        >>> vg = OpenGLVGroup()
        >>> triangle, square = Triangle(), Square()
        >>> vg.add(triangle)
        OpenGLVGroup(Triangle)
        >>> vg + square  # a new OpenGLVGroup is constructed
        OpenGLVGroup(Triangle, Square)
        >>> vg  # not modified
        OpenGLVGroup(Triangle)
        >>> vg += square  # modifies vg
        >>> vg
        OpenGLVGroup(Triangle, Square)
        >>> vg.remove(triangle)
        OpenGLVGroup(Square)
        >>> vg - square  # a new OpenGLVGroup is constructed
        OpenGLVGroup()
        >>> vg  # not modified
        OpenGLVGroup(Square)
        >>> vg -= square  # modifies vg
        >>> vg
        OpenGLVGroup()

        >>> config.renderer = original_renderer

    .. manim:: ArcShapeIris
        :save_last_frame:

        class ArcShapeIris(Scene):
            def construct(self):
                colors = [DARK_BROWN, BLUE_E, BLUE_D, BLUE_A, TEAL_B, GREEN_B, YELLOW_E]
                radius = [1 + rad * 0.1 for rad in range(len(colors))]

                circles_group = OpenGLVGroup()

                # zip(radius, color) makes the iterator [(radius[i], color[i]) for i in range(radius)]
                circles_group.add(*[Circle(radius=rad, stroke_width=10, color=col)
                                    for rad, col in zip(radius, colors)])
                self.add(circles_group)
    	vmobjectsr*   r=   r	   c                N     t                      j        di |  | j        |  d S Nrm   )r{   r|   r   )r;   r  r=   r~   s      rB   r|   zOpenGLVGroup.__init__  s5    ""6""")rD   c                p    | j         j        dz   d                    d | j        D                       z   dz   S )N(z, c              3  4   K   | ]}t          |          V  d S r   )r  )r   r?   s     rB   r]  z(OpenGLVGroup.__repr__.<locals>.<genexpr>  s(      ==SC======rD   ))r~   r  joinr   r   s    rB   __repr__zOpenGLVGroup.__repr__  sG    N#ii==D,<=====> 	
rD   c                    | j         j         dt          | j                   dt          | j                  dk    rdnd S )Nz of z submobjectr   r   )r~   r  r   r   r   s    rB   __str__zOpenGLVGroup.__str__  s\    ~& D DC0@,A,A D D #D$4 5 5 9 9rD D	
rD   c                0     t                      j        | S )a  Checks if all passed elements are an instance of OpenGLVMobject and then add them to submobjects

        Parameters
        ----------
        vmobjects
            List of OpenGLVMobject to add

        Returns
        -------
        :class:`OpenGLVGroup`

        Raises
        ------
        TypeError
            If one element of the list is not an instance of OpenGLVMobject

        Examples
        --------
        .. manim:: AddToOpenGLVGroup

            class AddToOpenGLVGroup(Scene):
                def construct(self):
                    circle_red = Circle(color=RED)
                    circle_green = Circle(color=GREEN)
                    circle_blue = Circle(color=BLUE)
                    circle_red.shift(LEFT)
                    circle_blue.shift(RIGHT)
                    gr = OpenGLVGroup(circle_red, circle_green)
                    gr2 = OpenGLVGroup(circle_blue) # Constructor uses add directly
                    self.add(gr,gr2)
                    self.wait()
                    gr += gr2 # Add group to another
                    self.play(
                        gr.animate.shift(DOWN),
                    )
                    gr -= gr2 # Remove group
                    self.play( # Animate groups separately
                        gr.animate.shift(LEFT),
                        gr2.animate.shift(UP),
                    )
                    self.play( #Animate groups without modification
                        (gr+gr2).animate.shift(RIGHT)
                    )
                    self.play( # Animate group without component
                        (gr-circle_red).animate.shift(RIGHT)
                    )
        )r{   r   )r;   r  r~   s     rB   r   zOpenGLVGroup.add  s    ` uww{I&&rD   c                (    t          g | j        |R  S r   )r+   r   r;   r   s     rB   __add__zOpenGLVGroup.__add__  s    8T-8x8888rD   c                ,    |                      |          S r   )r   r  s     rB   __iadd__zOpenGLVGroup.__iadd__  s    xx!!!rD   c                L    t          | j         }|                    |           |S r   )r+   r   r   )r;   r   r(  s      rB   __sub__zOpenGLVGroup.__sub__  s&    T-.HrD   c                ,    |                      |          S r   )r   r  s     rB   __isub__zOpenGLVGroup.__isub__  s    {{8$$$rD   keyra   rt  )OpenGLVMobject | Sequence[OpenGLVMobject]c                ^    |                      t          |                     || j        |<   dS )a  Override the [] operator for item assignment.

        Parameters
        ----------
        key
            The index of the submobject to be assigned
        value
            The vmobject value to assign to the key

        Returns
        -------
        None

        Tests
        -----

        .. doctest::

            >>> from manim import config
            >>> original_renderer = config.renderer
            >>> config.renderer = "opengl"

            >>> vgroup = OpenGLVGroup(OpenGLVMobject())
            >>> new_obj = OpenGLVMobject()
            >>> vgroup[0] = new_obj

            >>> config.renderer = original_renderer
        N)r   r"   r   )r;   r  rt  s      rB   __setitem__zOpenGLVGroup.__setitem__  s1    : 	&&wu~~666 %rD   )r  r*   r=   r	   )r  r*   )r  ra   rt  r  )r  r  r  r  r|   r  r  r   r  r  r  r  r  r  r  s   @rB   r+   r+   R  s        < <|     
 
 

 
 
0' 0' 0' 0' 0' 0'd9 9 9" " "  
% % %& & & & & & & &rD   r+   c                  ,     e Zd Zeeddddf fd	Z xZS )r,   r   rR   c                    || _         || _         t                      j        d|||d| |                     t          j        |g                     d S )N)rH   rU   rN   rm   )artificial_widthartificial_heightr{   r|   r  r3   r   )	r;   locationrH   rU   rN   r  r  r=   r~   s	           rB   r|   zOpenGLVectorizedPoint.__init__  so     !1!2 	
l	
 	
QW	
 	
 	
 	(,,-----rD   )r  r  r  ORIGINr   r|   r  r  s   @rB   r,   r,     sQ         . . . . . . . . . .rD   r,   c                  "     e Zd ZdZ fdZ xZS )r-   a  Convert a curve's elements to submobjects.

    Examples
    --------
    .. manim:: LineGradientExample
        :save_last_frame:

        class LineGradientExample(Scene):
            def construct(self):
                curve = ParametricFunction(lambda t: [t, np.sin(t), 0], t_range=[-PI, PI, 0.01], stroke_width=10)
                new_curve = CurvesAsSubmobjects(curve)
                new_curve.set_color_by_gradient(BLUE, RED)
                self.add(new_curve.shift(UP), curve)

    c                    t                      j        di | |                                D ]O}t                      }|                    |           |                    |           |                     |           Pd S r  )r{   r|   rM  r*   r  r   r   )r;   r   r=   rK  partr~   s        rB   r|   z"OpenGLCurvesAsSubmobjects.__init__)  s    ""6"""--// 	 	C!##DOOC   X&&&HHTNNNN		 	rD   )r  r  r  r  r|   r  r  s   @rB   r-   r-     sB                  rD   r-   c                  ,     e Zd ZdZddefd fdZ xZS )r.   a  A :class:`OpenGLVMobject` composed of dashes instead of lines.

    Examples
    --------
    .. manim:: DashedVMobjectExample
        :save_last_frame:

        class DashedVMobjectExample(Scene):
            def construct(self):
                r = 0.5

                top_row = OpenGLVGroup()  # Increasing num_dashes
                for dashes in range(2, 12):
                    circ = DashedVMobject(Circle(radius=r, color=WHITE), num_dashes=dashes)
                    top_row.add(circ)

                middle_row = OpenGLVGroup()  # Increasing dashed_ratio
                for ratio in np.arange(1 / 11, 1, 1 / 11):
                    circ = DashedVMobject(
                        Circle(radius=r, color=WHITE), dashed_ratio=ratio
                    )
                    middle_row.add(circ)

                sq = DashedVMobject(Square(1.5, color=RED))
                penta = DashedVMobject(RegularPolygon(5, color=BLUE))
                bottom_row = OpenGLVGroup(sq, penta)

                top_row.arrange(buff=0.4)
                middle_row.arrange()
                bottom_row.arrange(buff=1)
                everything = OpenGLVGroup(top_row, middle_row, bottom_row).arrange(DOWN, buff=1)
                self.add(everything)
       r   r   r*   
num_dashesra   dashed_ratiorV   rH   r   c                X  	 || _         || _         t                      j        dd|i| | j         }| j        }|dk    rQ||z                                  rd|z
  |z  n
d|z
  |dz
  z  	 | j        	fdt          |          D               |                     d           d S )NrH   r   rK   c              3  b   K   | ])}                     |z   z  |z   z  z             V  *d S r   )r)  )r   r  dash_lenr   void_lens     rB   r]  z0OpenGLDashedVMobject.__init__.<locals>.<genexpr>h  sh        
 	 ))X01X01H<      rD   Fr   rm   )r  r  r{   r|   r>  r   r  r   )r;   r   r  r  rH   r=   rrV  r  r  r~   s    `      @@rB   r|   zOpenGLDashedVMobject.__init__U  s     )$//u////O>>1uH&.&8&8&:&:QA{{Q1q5@QHDH     
 #1XX    	511111rD   )r   r*   r  ra   r  rV   rH   r   )r  r  r  r  r   r|   r  r  s   @rB   r.   r.   2  sX           J !$)2 2 2 2 2 2 2 2 2 2 2rD   r.   )A
__future__r   	itertoolsr  operatorr  collections.abcr   r   r   	functoolsr   r   typingr	   r
   r  numpyr3   manimr   manim.constants#manim.mobject.opengl.opengl_mobjectr   r   manim.renderer.shader_wrapperr   manim.typingr   r   r   manim.utils.bezierr   r   r   r   r   r   r   r   manim.utils.colorr   r   r   r   manim.utils.config_opsr   manim.utils.iterablesr    r!   r"   manim.utils.space_opsr#   r$   r%   r&   r'   r(   __all__r)   r*   r+   r,   r-   r.   rm   rD   rB   <module>r     s   " " " " " "         8 8 8 8 8 8 8 8 8 8 # # # # # # # #                        J J J J J J J J 7 7 7 7 7 7 @ @ @ @ @ @ @ @ @ @	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 K J J J J J J J J J J J ( ( ( ( ( ( O O O O O O O O O O                   $L( L( L( L( L(] L( L( L(^0o& o& o& o& o&> o& o& o&d. . . . .K . . .(       4@2 @2 @2 @2 @2> @2 @2 @2 @2 @2rD   