
    ]j.?                     <    d dl Z d dlT  G d de j                  ZdS )    N)*c                      e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d-S ).TestPathMatrixz.Tests the functionality of the Matrix element.c                    t          d          }t          d          }||z  }|                     d|                                           t          d          }t          d          }||z  }|                     d|                                           t          d          }t          d          }||z  }|                     d|                                           t          d          }t          d          }||z  }|                     d|                                           t          d          }t          d          }||z  }|                     d|                                           d S )Nzrotate(90, 100,100)zM0,0Z	M 200,0 Zzrotate(90deg, 100,100)zrotate(0.25turn, 100,100)zrotate(100grad, 100,100)z&rotate(1.5707963267948966rad, 100,100))MatrixPathassertEqualdselfmatrixpaths      K/home/agentuser/manim-venv/lib/python3.11/site-packages/test/test_matrix.pytest_rotate_css_anglesz%TestPathMatrix.test_rotate_css_angles	   sH   -..G}}dffhh///011G}}dffhh///344G}}dffhh///233G}}dffhh///@AAG}}dffhh/////    c                    |                      t          d          t          d          t          d          z             |                      t          d          t          d          t          d          z             d S )Nzscale(0.2) translate(-5,-5)ztranslate(-5,-5)z
scale(0.2)ztranslate(-5,-5) scale(0.2))r
   r   r   s    r   test_matrix_multiplicationz)TestPathMatrix.test_matrix_multiplication   s    011%&&)=)==	
 	
 	
 	011<  6*<#=#==	
 	
 	
 	
 	
r   c                 j   t          d          }|                    t                     t          d          }||z  }t	          d                              t                    }t          d          t          d|z            z  }t          |j        t          <   | 	                    ||           d S )Nzrotate(90deg,100cm,100cm)ppizM0,0z1cmr   z	scale(%f))
r   renderDEFAULT_PPIr	   LengthvalueSVG_VALUE_NON_SCALING_STROKEvaluesSVG_ATTR_VECTOR_EFFECTr
   )r   r   r   r   p2s        r   test_rotate_css_distancez'TestPathMatrix.test_rotate_css_distance)   s    344+&&&G}}5MMK00+a!8!88,H	()T"""""r   c                     t          d          }t          d          }|                     ||           t          d          }t          d          }|                     ||           d S )Nzskew(15deg,0deg)zskewX(15deg)zskew(0deg,15deg)zskewY(15deg)r   r
   r   m0m1s      r   test_skew_single_valuez%TestPathMatrix.test_skew_single_value3   sj    &''N##R   &''N##R     r   c                     t          d          }t          d          }|                     ||           t          d          }t          d          }|                     ||           d S )Nz
scale(2,1)z	scaleX(2)z
scale(1,2)z	scaleY(2)r$   r%   s      r   test_scale_single_valuez&TestPathMatrix.test_scale_single_value;   sh    L!!K  R   L!!K  R     r   c                 >   t          d          }t          d          }|                     ||           t          d          }t          d          }|                     ||           t          d          }t          d          }|                     ||           d S )Nztranslate(500cm,0)ztranslateX(500cm)ztranslate(0,500cm)ztranslateY(500cm)ztranslate(500cm)r$   r%   s      r   test_translate_single_valuez*TestPathMatrix.test_translate_single_valueC   s    ())'((R   ())'((R   &'''((R     r   c                 n    t          d          }t          d          }|                     ||           d S )Nztranslate(50mm,5cm)ztranslate(5cm,5cm)r$   r%   s      r   test_translate_css_valuez'TestPathMatrix.test_translate_css_valueN   s:    )**())R     r   c                     t          dt                    }t          dt                    }|                     ||           d S )Nzrotate(90deg, 50cm,50cm)r   zrotate(0.25turn, 500mm,500mm))r   r   r
   r%   s      r   test_rotate_css_valuez$TestPathMatrix.test_rotate_css_valueS   sD    .K@@@3EEER     r   c                     t          d          }t                      }|                    ddddd                                           ||z  }|                     d|                                           d S )Nztranslate(5,4)r   r   r   d   r4   r4         Y@        zz'M 5,4 L 5,104 L 105,104 L 105,4 L 5,4 Zr   r	   moveclosedr
   r   r   s      r   test_transform_translatez'TestPathMatrix.test_transform_translateX   sm    ())vv		&(J#>>EEGGGBDFFHHMMMMMr   c                     t          d          }t                      }|                    ddddd                                           ||z  }|                     d|                                           d S )Nscale(2)r2   r3   r5   r6   r7   z'M 0,0 L 0,200 L 200,200 L 200,0 L 0,0 Zr8   r   s      r   test_transform_scalez#TestPathMatrix.test_transform_scale_   sl    
##vv		&(J#>>EEGGGBDFFHHMMMMMr   c                    t          d          }t                      }|                    ddddd           ||z  }|                     |d         d         j        d           |                     |d         d         j        d           |                     |d         d         j        d           |                     |d         d         j        d	           |                     |d
         d         j        d	           |                     |d
         d         j        d	           |                     |d         d         j        d	           |                     |d         d         j        d           |                     |d         d         j        d           |                     |d         d         j        d           d S )Nzrotate(360)r2   r3   r5   r6   r7   r      r4            r   r	   r9   assertAlmostEqualxyr   s      r   test_transform_rotatez$TestPathMatrix.test_transform_rotatef   s   &&vv		&(J#>>>tAwqz|Q///tAwqz|Q///tAwqz|Q///tAwqz|S111tAwqz|S111tAwqz|S111tAwqz|S111tAwqz|Q///tAwqz|Q///tAwqz|Q/////r   c                    t          d          }t                      }|                    ddddd           ||z  }|                     |d         d         j        d           |                     |d         d         j        d           |                     |d         d         j        d           |                     |d         d         j        d	           |                     |d
         d         j        d	           |                     |d
         d         j        d	           |                     |d         d         j        d	           |                     |d         d         j        d           |                     |d         d         j        d           |                     |d         d         j        d           d S )Nzrotate(360,50,50)r2   r3   r5   r6   r7   r   r@   r4   rA   rB   rC   rD   r   s      r   test_transform_valuez#TestPathMatrix.test_transform_valuex   s   +,,vv		&(J#>>>tAwqz|Q///tAwqz|Q///tAwqz|Q///tAwqz|S111tAwqz|S111tAwqz|S111tAwqz|S111tAwqz|Q///tAwqz|Q///tAwqz|Q/////r   c                     t          d          }t                      }|                    ddddd                                           ||z  }|                     d|                                           d S )NzskewX(10,50,50)r2   r3   r5   r6   r7   zaM -8.81634903542,0 L 8.81634903542,100 L 108.816349035,100 L 91.1836509646,0 L -8.81634903542,0 Zr8   r   s      r   test_transform_skewxz#TestPathMatrix.test_transform_skewx   sx    )**vv		&(J#>>EEGGGoFFHH	
 	
 	
 	
 	
r   c                     t          d          }t                      }|                    ddddd                                           ||z  }|                     d|                                           d S )NzskewY(10, 50,50)r2   r3   r5   r6   r7   zaM 0,-8.81634903542 L 0,91.1836509646 L 100,108.816349035 L 100,8.81634903542 L 0,-8.81634903542 Zr8   r   s      r   test_transform_skewyz#TestPathMatrix.test_transform_skewy   sx    *++vv		&(J#>>EEGGGoFFHH	
 	
 	
 	
 	
r   c           
          |                      t          dddddd          t                              t          d                               dS ))
        [a c e]
        [b d f]
        r   r@   Z   N)r
   r   rotateradiansr   s    r   test_matrix_repr_rotatez&TestPathMatrix.test_matrix_repr_rotate   sD    
 	1b!Q22FMM'"++4N4NOOOOOr   c           
          |                      t          dddddd          t                              d                     dS )rP   rA   r   Nr
   r   scaler   s    r   test_matrix_repr_scalez%TestPathMatrix.test_matrix_repr_scale   s<    
 	1aAq116<<??CCCCCr   c           
          |                      t          dddddd          t                              dd                     dS )rP   rQ   r   r@   NrW   r   s    r   test_matrix_repr_hflipz%TestPathMatrix.test_matrix_repr_hflip   s@    
 	Aq!Q22FLLQ4G4GHHHHHr   c           
          |                      t          dddddd          t                              dd                     dS )rP   r@   r   rQ   NrW   r   s    r   test_matrix_repr_vflipz%TestPathMatrix.test_matrix_repr_vflip   s@    
 	1aQ22FLLB4G4GHHHHHr   c           
          t                               d          }|                    t                               dd                     |                     t          dddddd          |           dS )rP   rA   r   N)r   rX   post_cat	translater
   r   ms     r   test_matrix_repr_post_catz(TestPathMatrix.test_matrix_repr_post_cat   sc    
 LLOO	

6##C--...1aC55q99999r   c           
          t                               dd          }|                    t                               d                     |                     t          dddddd          |           dS )rP   r_   rA   r   N)r   ra   pre_catrX   r
   rb   s     r   test_matrix_repr_pre_catz'TestPathMatrix.test_matrix_repr_pre_cat   sc    
 S#&&			&,,q//"""1aC55q99999r   c                    t                      }|                    t          d          dd           |                    d          }|                     |d         d           |                     |d         d           d S )NrR   r4   2   rj   r      r@   rj   )r   post_rotaterT   point_in_matrix_spacerE   r   r   ps      r   #test_matrix_point_rotated_by_matrixz2TestPathMatrix.test_matrix_point_rotated_by_matrix   sv    72;;S111((22qtS)))qtR(((((r   c                    t                      }|                    dddd           |                    d          }|                     |d         d           |                     |d         d           |                    d          }|                     |d         d           |                     |d         d           |                    t          d          dd           |                    d          }|                     |d         d           t                      }|                    dd           |                    d	          }|                     |d         d           |                     |d         d           t                      }|                    ddd
d
           |                    d          }|                     |d         d           |                     |d         d           d S )NrA   rj   ri   r   r@   )   rr   -         ?r5   r4   )r   
post_scalerm   rE   rl   rT   rn   s      r   !test_matrix_point_scaled_in_spacez0TestPathMatrix.test_matrix_point_scaled_in_space   s   !QB'''((22qtR(((qtR(((((22qtQ'''qtQ'''72;;B///((22qtR(((#s###((44qtR(((qtR(((!QS)))((22qtQ'''qtQ'''''r   c           
      N   t                      }ddlm} t          d          D ]}t           |             |             |             |             |             |                      }t          |          }|                    |           |                     ||           d S )Nr   randomrj   )r   ry   rangecopyr`   r
   )r   identityry   iqro   s         r   test_matrix_cat_identityz'TestPathMatrix.test_matrix_cat_identity   s    88!!!!!!r 	# 	#Avvxx6688VVXXvvxxRRAQAJJx   Q""""		# 	#r   c                    ddl m } t          d          D ]/} |            dz  dz
  } |            dz  dz
  } |            dz  } |            dz  } |            t          z  }t                      }|                    ||           t                      }	|	                    ||           |                     |	|           t                      }|                    ||||           t                      }	|	                    ||||           |                     |	|           t                      }|	                    |||           t                      }	|	
                    |||           |                     |	|           t                      }|                    |||           t                      }	|	                    |||           |                     |	|           t                      }|                    |||           t                      }	|	                    |||           |                     |	|           1d S )Nr   rx   rj   i  i  rA   )ry   rz   taur   post_translatepre_translater
   ru   	pre_scalerl   
pre_rotatepost_skew_x
pre_skew_xpost_skew_y
pre_skew_y)
r   ry   r}   txtyrxryar~   ro   s
             r   test_matrix_pre_and_post_1z)TestPathMatrix.test_matrix_pre_and_post_1   s2   !!!!!!r "	# "	#AD3&BD3&BABAB3AAR$$$AOOB###Q"""ALLRR(((AKKBB'''Q"""AMM!R$$$ALLB###Q"""AMM!R$$$ALLB###Q"""AMM!R$$$ALLB###Q""""E"	# "	#r   c           
      :   |                      t          d          t          t          t          d                              k               |                     t          d          t          t          t          d                              k               d S )Nz
rotate(20))
assertTruer   evalreprassertFalser   s    r   test_matrix_eval_reprz$TestPathMatrix.test_matrix_eval_repr   sx    |,,T&:N:N5O5O0P0PPQQQ--d6,;O;O6P6P1Q1QQRRRRRr   c                     t          d          }|                                 t          d          }|                     ||           |                                 |                     |d           d S )Nr=   z
scale(0.5)r   inverser
   r   r'   m2s      r   test_matrix_reverse_scalez(TestPathMatrix.test_matrix_reverse_scale$  sh    J


L!!R   


Z(((((r   c                     t          d          }|                                 |                     |t          d                     d S )Nztranslate(20,20)ztranslate(-20,-20)r   r   r'   s     r   test_matrix_reverse_translatez,TestPathMatrix.test_matrix_reverse_translate,  sB    &''


V$899:::::r   c                     t          d          }|                                 |                     |t          d                     d S )Nz
rotate(30)zrotate(-30)r   r   s     r   test_matrix_reverse_rotatez)TestPathMatrix.test_matrix_reverse_rotate1  s@    L!!


VM2233333r   c                    t          d          }|                                 |                     |t          d                     t          d          }|                                 |                     |t          d                     d S )NzskewX(1)z	skewX(-1)zskewY(1)z	skewY(-1)r   r   s     r   test_matrix_reverse_skewz'TestPathMatrix.test_matrix_reverse_skew6  sx    J


VK00111J


VK0011111r   c                     t          d          }|                                 |                     |t          d                     d S )Nzscale(2) translate(40,40)ztranslate(-40,-40) scale(0.5)r   r   s     r   #test_matrix_reverse_scale_translatez2TestPathMatrix.test_matrix_reverse_scale_translate?  sB    /00


V$CDDEEEEEr   c                    t                               t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          t          dd                    }|                     |                                           t                               t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          t          dd                    }|                     |                                           dS )z<
        Maps one perspective the same perspective.
        r@   rQ   e   c   N)r   mapPointr   is_identityr   s     r   test_matrix_map_identityz'TestPathMatrix.test_matrix_map_identityD  s    ZZ!QKK!RLL"bMM"aLL!QKK!RLL"bMM"aLL	
 	
 	(()))ZZ#sOO#rNN"bMM"cNN#sOO#rNN"bMM"cNN	
 	
 	(()))))r   c                    t                               t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          t          dd                    }|                     |t                               d                     d S )NrA   r@   rQ   rt   )r   r   r   r
   rX   r   s     r   test_matrix_map_scale_halfz)TestPathMatrix.test_matrix_map_scale_half`  s    ZZ!QKK!RLL"bMM"aLL!QKK!RLL"bMM"aLL	
 	
 	V\\#../////r   c                    t                               t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          t          dd                    }|                     |t                               dd                     d S )Nr   r@   r4   r   )r   r   r   r
   ra   r   s     r   test_matrix_map_translatez(TestPathMatrix.test_matrix_map_translatem  s    ZZ!QKK!QKK!QKK!QKK#sOO#sOO#sOO#sOO	
 	
 	V--c37788888r   c                 r   t                               t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          t          dd                    }t          d          }|                     ||           d S )Nr   r@   zrotate(-90deg, 0.5, 0.5))r   r   r   r
   r   s      r   test_matrix_map_rotatez%TestPathMatrix.test_matrix_map_rotatez  s    ZZ!QKK!QKK!QKK!QKK!QKK!QKK!QKK!QKK	
 	
 .//R     r   c                    t                               t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          t          dd                    }|                     |t                               d          t                               dd          z             d S )Nr   r@   r4   f   r   rA   )r   r   r   r
   scale_yra   r   s     r   !test_matrix_map_translate_scale_yz0TestPathMatrix.test_matrix_map_translate_scale_y  s    ZZ!QKK!QKK!QKK!QKK#sOO#sOO#sOO#sOO	
 	
 	V^^A..1A1A#s1K1KKLLLLLr   c                    t          dd          t          dd          t          dd          t          dd          g}t          d          t          d          t          d          t          d          t          d          t          d          t          d          t          d          t          d	          t          d
          f
D ]9fd|D             }t          j        g ||R  }|                     |           :d S )Nr   r@   skewX(10deg)skewX(8deg)skewX(5deg)skewY(10deg)scale(1.4235)scale(1.4235,4.39392)translate(100,200)translate(-50,-20.3949)c                 :    g | ]}                     |          S  rm   .0ro   rc   s     r   
<listcomp>z6TestPathMatrix.test_matrix_map_map.<locals>.<listcomp>  '    DDD0033DDDr   )r   r   r   r
   r   points	points_tor'   rc   s       @r   test_matrix_map_mapz"TestPathMatrix.test_matrix_map_map  s   1++uQ{{E!QKKq!E >""=!!=!!>""=!!=!!?##*++'((,--
 	$ 	$A EDDDVDDDI0V0i000BQ####	$ 	$r   c           	      2   t                               t          dd          t          dd          t          dd          t          dd                    }t                               dd          t          d          z  }|                     ||           dS zr
        This is the unit square ccw. So we mirror it across the x-axis and rotate it back into position.
        r   r@   rQ   zrotate(-90deg)N)r   perspectiver   rX   r
   r   s      r   'test_matrix_perspective_ccw_unit_squarez6TestPathMatrix.test_matrix_perspective_ccw_unit_square  s{     aU1a[[%1++uQPQ{{SS\\"a  6*:#;#;;R     r   c           	          t                               t          dd          t          dd          t          dd          t          dd                    }t                      }|                     ||           dS zs
        This is the cw unit square, which is our default perspective, meaning we have the identity matrix
        r   r@   Nr   r   r   r
   r   s      r   #test_matrix_perspective_unit_squarez2TestPathMatrix.test_matrix_perspective_unit_square  sc     aU1a[[%1++uQPQ{{SSXXR     r   c           	         t                               t          dd          t          dd          t          dd          t          dd                    }t          d          t          d          z  }|                     ||           d S Nr   rA   zscale(4)ztranslate(-2,-2)r   r   s      r   $test_matrix_perspective_scale_rotatez3TestPathMatrix.test_matrix_perspective_scale_rotate  st    b"uR||U1a[[%PQSU,,WWJ&);"<"<<R     r   c                    t          dd          t          dd          t          dd          g}t          d          t          d          t          d          t          d          t          d          t          d          t          d          t          d          t          d	          t          d
          f
D ]9fd|D             }t          j        g ||R  }|                     |           :d S )Nr   r@   r   r   r   r   r   r   r   r   c                 :    g | ]}                     |          S r   r   r   s     r   r   z7TestPathMatrix.test_matrix_map_map3.<locals>.<listcomp>  r   r   )r   r   map3r
   r   s       @r   test_matrix_map_map3z#TestPathMatrix.test_matrix_map_map3  s   1++uQ{{E!QKK8 >""=!!=!!>""=!!=!!?##*++'((,--
 	$ 	$A EDDDVDDDI1f1y111BQ####	$ 	$r   c                    t                               t          dd          t          dd          t          dd                    }t                               dd          t          d          z  }|                     ||           dS r   )r   affiner   rX   r
   r   s      r   "test_matrix_affine_ccw_unit_squarez1TestPathMatrix.test_matrix_affine_ccw_unit_square  sn     ]]5A;;aU1a[[AA\\"a  6*:#;#;;R     r   c                     t                               t          dd          t          dd          t          dd                    }t                      }|                     ||           dS r   r   r   r   r
   r   s      r   test_matrix_affine_unit_squarez-TestPathMatrix.test_matrix_affine_unit_square  sV     ]]5A;;aU1a[[AAXXR     r   c                     t                               t          dd          t          dd          t          dd                    }t          d          t          d          z  }|                     ||           d S r   r   r   s      r   test_matrix_affine_scale_rotatez.TestPathMatrix.test_matrix_affine_scale_rotate  sf    ]]5R==%A,,aEEJ&);"<"<<R     r   N)/__name__
__module____qualname____doc__r   r   r"   r(   r*   r,   r.   r0   r;   r>   rH   rJ   rL   rN   rU   rY   r[   r]   rd   rg   rp   rv   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      s       880 0 0,
 
 
# # #! ! !! ! !	! 	! 	!! ! !
! ! !
N N NN N N0 0 0$0 0 0$
 
 

 
 
P P PD D DI I II I I: : :: : :) ) )( ( (8# # #%# %# %#NS S S) ) ); ; ;
4 4 4
2 2 2F F F
* * *80 0 09 9 9! ! !M M M$ $ $&! ! !! ! !! ! !
$ $ $&! ! !! ! !! ! ! ! !r   r   )unittestsvgelementsTestCaser   r   r   r   <module>r      s[        ]! ]! ]! ]! ]!X& ]! ]! ]! ]! ]!r   