
    ^jK                       d Z ddlmZ ddlZddlZddlZdd	Z	 G d
 dej
                  Z G d dej
                  Z G d dej
                  Z G d dej
                  Z G d dej
                  Z G d dej
                  ZdS )a-  Matrix and Vector math.

This module provides Vector and Matrix objects, including Vec2, Vec3,
Vec4, Mat3, and Mat4. Most common matrix and vector operations are
supported. Helper methods are included for rotating, scaling, and
transforming. The :py:class:`~pyglet.matrix.Mat4` includes class methods
for creating orthographic and perspective projection matrixes.

Matrices behave just like they do in GLSL: they are specified in column-major
order and multiply on the left of vectors, which are treated as columns.

All objects are immutable and hashable.
    )annotationsNnumfloatminimummaximumreturnc                >    t          t          | |          |          S )z2Clamp a value between a minimum and maximum limit.)maxmin)r   r   r   s      F/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/math.pyclampr      s    s3  '***    c                     e Zd ZU dZdZded<   dZded<   d ZdHd
ZdHdZ	dHdZ
dHdZdIdZdIdZdIdZdIdZdIdZdIdZdJdZdJdZdKdLdZdJdZdJdZdJdZdHdZdHd ZdMd#ZedNdOd'            ZedNdPd)            ZdQd*ZdQd+ZdQd,Z dRd/Z!dSd1Z"dTd3Z#dUd4Z$dVd6Z%dJd7Z&e'j(        rDe'j)        dWd:            Z*e'j)        dXd;            Z*e'j)        dYd<            Z*e'j)        dZd=            Z*d[d>Z*d\d?Z+d]dCZ,d^dGZ-dS )_Vec2a  A two-dimensional vector represented as an X Y coordinate pair.

    `Vec2` is an immutable 2D Vector, including most common
    operators. As an immutable type, all operations return a new object.

    .. note:: The Python ``len`` operator returns the number of elements in
              the vector. For the vector length, use the `length()` method.

    .. note:: Python's :py:func:`sum` requires the first item to be a ``Vec2``.

              After that, you can mix ``Vec2``-like :py:class:`tuple`
              and ``Vec2`` instances freely in the iterable.

              If you do not, you will see a :py:class:`TypeError` about being
              unable to add a :py:class:`tuple` and a :py:class:`int`.

            r   xyc                .    | j         dk    p
| j        dk    S Nr   )r   r   selfs    r   __bool__zVec2.__bool__6   s    v}-#-r   other"Vec2 | tuple[float, float] | floatr   c                    	 t          | d         |d         z   | d         |d         z             S # t          $ r% t          | d         |z   | d         |z             cY S w xY wNr      r   	TypeErrorr   r   s     r   __add__zVec2.__add__9       	Q%("DGeAh$6    	 	 	Q%a5    	   -0 ,AAc                p    	 |                      |          S # t          $ r}|dk    r| cY d }~S |d }~ww xY wNr   )r!   r   r   r   errs      r   __radd__zVec2.__radd__C   sU    	<<&&& 	 	 	zzI	s    
50505c                    	 t          | d         |d         z
  | d         |d         z
            S # t          $ r% t          | d         |z
  | d         |z
            cY S w xY wr   r   r    s     r   __sub__zVec2.__sub__K   r"   r#   c                    	 t          |d         | d         z
  |d         | d         z
            S # t          $ r% t          || d         z
  || d         z
            cY S w xY wr   r   r    s     r   __rsub__zVec2.__rsub__U   s    	a47"E!HtAw$6    	 	 	Qa    	r#   scalar"float | Vec2 | tuple[float, float]c                    	 t          | d         |d         z  | d         |d         z            S # t          $ r% t          | d         |z  | d         |z            cY S w xY wr   r   r   r-   s     r   __mul__zVec2.__mul___       	Q&)#T!Wvay%8    	 	 	Q& $q'F"2    	r#   c                    	 t          | d         |d         z  | d         |d         z            S # t          $ r% t          | d         |z  | d         |z            cY S w xY wr   r   r0   s     r   __rmul__zVec2.__rmul__i   r2   r#   c                    	 t          | d         |d         z  | d         |d         z            S # t          $ r% t          | d         |z  | d         |z            cY S w xY wr   r   r0   s     r   __truediv__zVec2.__truediv__s   r2   r#   c                    	 t          |d         | d         z  |d         | d         z            S # t          $ r% t          || d         z  || d         z            cY S w xY wr   r   r0   s     r   __rtruediv__zVec2.__rtruediv__}   s    	q	DG#VAYa%8    	 	 	a &47"2    	r#   c                    	 t          | j        |d         z  | j        |d         z            S # t          $ r% t          | d         |z  | d         |z            cY S w xY wr   )r   r   r   r   r0   s     r   __floordiv__zVec2.__floordiv__   s    	&)#TVvay%8    	 	 	Q6!47f#4    	s   +. ,AAc                    	 t          |d         | d         z  |d         | d         z            S # t          $ r% t          || d         z  || d         z            cY S w xY wr   r   r0   s     r   __rfloordiv__zVec2.__rfloordiv__   s    	q	T!W$fQi47&:    	 	 	$q'!6T!W#4    	r#   c                n    t          t          | d                   t          | d                             S r   )r   absr   s    r   __abs__zVec2.__abs__   s&    CQLL#d1g,,///r   c                >    t          | d          | d                    S r   r   r   s    r   __neg__zVec2.__neg__   s    T!WHtAwh'''r   Nn_digits
int | Nonec                .    t          fd| D              S )Nc              3  8   K   | ]}t          |          V  d S Nround.0vrC   s     r   	<genexpr>z!Vec2.__round__.<locals>.<genexpr>   -      77QeAx((777777r   rA   r   rC   s    `r   	__round__zVec2.__round__   #    7777$77788r   c                    t          t          j        | d                   t          j        | d                             S r   )r   _mathceilr   s    r   __ceil__zVec2.__ceil__   s.    EJtAw''DG)<)<===r   c                    t          t          j        | d                   t          j        | d                             S r   )r   rS   floorr   s    r   	__floor__zVec2.__floor__   .    EKQ((%+d1g*>*>???r   c                    t          t          j        | d                   t          j        | d                             S r   )r   rS   truncr   s    r   	__trunc__zVec2.__trunc__   rY   r   c                    	 t          | d         |d         z  | d         |d         z            S # t          $ r% t          | d         |z  | d         |z            cY S w xY wr   r   r    s     r   __mod__zVec2.__mod__   r"   r#   c                    	 t          | d         |d         z  | d         |d         z            S # t          $ r% t          | d         |z  | d         |z            cY S w xY wr   r   r    s     r   __pow__zVec2.__pow__   s    	Q58#T!Wa%8    	 	 	Q5 $q'U"2    	r#   tuple[float, float]boolc                b    | d         dz  | d         dz  z   |d         dz  |d         dz  z   k     S Nr      r    r    s     r   __lt__zVec2.__lt__   s7    Aw!|d1gl*U1X]U1X]-JJJr         ?headinglengthc                v    t          |t          j        |           z  |t          j        |           z            S )zCreate a new vector from the given heading and length.

        Args:
          heading: The desired heading, in radians
          length: The desired length of the vector
        r   rS   cossin)ri   rj   s     r   from_headingzVec2.from_heading   s2     FUYw///%)G:L:L1LMMMr   anglec                v    t          |t          j        |           z  |t          j        |           z            S )zCreate a new vector from the given polar coordinates.

        Args:
          angle: The angle, in radians.
          length: The desired length
        rl   )rp   rj   s     r   
from_polarzVec2.from_polar   s2     FUYu---v	%8H8H/HIIIr   c                T    t          j        | d         dz  | d         dz  z             S )z>Calculate the length of the vector: ``sqrt(x ** 2 + y ** 2)``.r   re   r   rS   sqrtr   s    r   rj   zVec2.length   s'    z$q'Q,aA5666r   c                D    t          j        | d         | d                   S )a#  Calculate the heading of the vector in radians.

        Shortcut for `atan2(y, x)` meaning it returns a value between
        -pi and pi. ``Vec2(1, 0)`` will have a heading of 0. Counter-clockwise
        is positive moving towards pi, and clockwise is negative moving towards -pi.
        r   r   )rS   atan2r   s    r   ri   zVec2.heading   s     {47DG,,,r   c                0    | d         dz  | d         dz  z   S )zCalculate the squared length of the vector.

        This is simply shortcut for `x ** 2 + y ** 2` and can be used
        for faster comparisons without the need for a square root.
        r          @r   rf   r   s    r   length_squaredzVec2.length_squared   s     Aw#~Q3..r   Vec2 | tuple[float, float]amountc                    t          | d         ||d         | j        z
  z  z   | d         ||d         | d         z
  z  z             S )a  Create a new Vec2 linearly interpolated between this vector and another Vec2.

        The equivalent in GLSL is `mix`.

        Args:
          other: Another Vec2 instance.
          amount: The amount of interpolation between this vector, and the other
                  vector. This should be a value between 0.0 and 1.0. For example:
                  0.5 is the midway point between both vectors.
        r   r   )r   r   r   r   r|   s      r   lerpz	Vec2.lerp   sN     DGvqDF):;<d1gSXYZS[^bcd^eSeIf>ghhhr   edgec                r    t          | d         |d         k     rdnd| d         |d         k     rdnd          S )a  A step function that returns 0.0 for a component if it is less than the edge, and 1.0 otherwise.

        This can be used enable and disable some behavior based on a condition.

        Example::

            # First component is less than 1.0, second component is greater than 1.0
            Vec2(0.5, 1.5).step((1.0, 1.0))
            Vec2(1.0, 0.0)

        Args:
            edge: A Vec2 instance.
        r   r   rh   r   rA   )r   r   s     r   stepz	Vec2.step   sA     47T!W,,CC#d1gQ>O>OssUXYYYr   vectorc                    |                      |          dz  }t          | d         ||d         z  z
  | d         ||d         z  z
            S )zCreate a new Vec2 reflected (ricochet) from the given normalized vector.

        Args:
            vector: A normalized Vec2 or Vec2-like tuple.
        re   r   r   )dotr   )r   r   twice_dot_values      r   reflectzVec2.reflect
  sV     ((6**Q.Goq	11Goq	11
 
 	
r   c                    t          j        |          }t          j        |          }t          || d         z  || d         z  z
  || d         z  || d         z  z             S )zCreate a new vector rotated by the angle. The length remains unchanged.

        Args:
            angle: The desired angle, in radians.
        r   r   )rS   rn   rm   r   )r   rp   scs       r   rotatezVec2.rotate  s\     IeIeAQK!d1g+-q47{Qa[/HIIIr   Vec2 | tuple[int, int]c                x    t          j        |d         | d         z
  dz  |d         | d         z
  dz  z             S )zCalculate the distance between this vector and another vector.

        Args:
            other: The point to calculate the distance to.
        r   re   r   rt   r    s     r   distancezVec2.distance"  s>     zE!HtAw.14%(T!W:LQR9RSTTTr   c                    t          j        | d         dz  | d         dz  z             x}r"t          | d         |z  | d         |z            S | S zReturn a normalized version of the vector.

        This simply means the vector will have a length of 1.0. If the vector
        has a length of 0, the original vector will be returned.
        r   re   r   )rS   ru   r   r   ds     r   	normalizezVec2.normalize*  sU     
47a<$q'Q,67771 	2Q!T!Wq[111r   min_valmax_valc                    d S rG   rf   r   r   r   s      r   r   z
Vec2.clamp5      Cr   c                    d S rG   rf   r   s      r   r   z
Vec2.clamp9  r   r   c                    d S rG   rf   r   s      r   r   z
Vec2.clamp>  r   r   c                    d S rG   rf   r   s      r   r   z
Vec2.clampB  r   r   c                   	 |d         |d         }}n# t           $ r |}|}Y nw xY w	 |d         |d         }}n# t           $ r |}|}Y nw xY wt          t          | d         ||          t          | d         ||                    S )ap  Restrict the value of the X and Y components of the vector to be within the given values.

        If a single value is provided, it will be used for both X and Y.
        If a tuple or Vec2 is provided, the first value will be used for X and the second for Y.

        Args:
            min_val: The minimum value(s)
            max_val: The maximum value(s)
        r   r   )r   r   r   )r   r   r   min_xmin_ymax_xmax_ys          r   r   z
Vec2.clampG  s    	"1:wqz5EE 	 	 	EEEE		"1:wqz5EE 	 	 	EEEE	 $q'5%((%Q*F*F
 
 	
s    $$9 A
	A
c                H    | d         |d         z  | d         |d         z  z   S )z?Calculate the dot product of this vector and another 2D vector.r   r   rf   r    s     r   r   zVec2.dot`  s'    Awq!DGeAh$666r   args_typing.Anyintc                     t          d          Nz"Vec types can be indexed directly.NotImplementedErrorr   r   s     r   indexz
Vec2.indexd      !"FGGGr   attrsstrVec2 | Vec3 | Vec4c                     	 t           t          t          dt          |                   } | fd|D              S # t          t
          t          f$ r}d| d}t          |          |d }~ww xY w)Nre         c              3  N   K   | ]}d                      |                   V   dS )xyNr   rK   r   r   s     r   rM   z#Vec2.__getattr__.<locals>.<genexpr>k  s2      BBqtDJJqMM2BBBBBBr   z'Vec2' has no attribute: ''.r   Vec3Vec4len
ValueErrorKeyErrorr   AttributeErrorr   r   	vec_classr'   msgs   `    r   __getattr__zVec2.__getattr__g  s    	/ Td33CJJ?I9BBBBEBBBCCHi0 	/ 	/ 	/8u888C %%3.	/   8< A.A))A.)r   r   r   r   )r-   r.   r   r   )r   r   rG   )rC   rD   r   r   )r   ra   r   rb   )rh   )ri   r   rj   r   r   r   )rp   r   rj   r   r   r   r   r   )r   r{   r|   r   r   r   )r   r{   r   r   )r   r{   r   r   )rp   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   r{   r   r   )r   r   r   r   r   r   )r   r{   r   r   r   r   r   r   r   r   r   r   ).__name__
__module____qualname____doc__r   __annotations__r   r   r!   r(   r*   r,   r1   r4   r6   r8   r:   r<   r?   rB   rP   rU   rX   r\   r^   r`   rg   staticmethodro   rr   rj   ri   rz   r   r   r   r   r   r   _typingTYPE_CHECKINGoverloadr   r   r   r   rf   r   r   r   r       s         $ ANNNNANNNN. . .                              0 0 0 0( ( ( (9 9 9 9 9> > > >@ @ @ @@ @ @ @      K K K K N N N N \N J J J J \J7 7 7 7- - - -/ / / /i i i iZ Z Z Z 
 
 
 
J J J JU U U U     			 	 	 
		 
		 	 	 
		 
		 	 	 
		 
		 	 	 
		
 
 
 
27 7 7 7H H H H/ / / / / /r   r   c                     e Zd ZU dZdZded<   dZded<   dZded<   d ZdAdZ	dAdZ
dAdZdAdZdBdZdBdZdBdZdCdZdCdZdCdZdDdZdDdZdEdFdZdDdZdDdZdDdZdAd ZdAd!ZdGd$ZedHd'            ZdId)ZdJd*ZdJd+Z dKd,Z!dLd-Z"dMd/Z#dLd0Z$dDd1Z%e&j'        rDe&j(        dNd4            Z)e&j(        dOd5            Z)e&j(        dPd6            Z)e&j(        dQd7            Z)dRd8Z)dSd<Z*dTd@Z+dS )Ur   a`  A three-dimensional vector represented as X Y Z coordinates.

    `Vec3` is an immutable 3D Vector, including most common operators.
    As an immutable type, all operations return a new object.

    .. note:: The Python ``len`` operator returns the number of elements in
              the vector. For the vector length, use the `length()` method.
    r   r   r   r   zc                D    | j         dk    p| j        dk    p
| j        dk    S r   r   r   r   r   s    r   r   zVec3.__bool__  s$    v}>#>3>r   r   )Vec3 | tuple[float, float, float] | floatr   c                    	 t          | d         |d         z   | d         |d         z   | d         |d         z             S # t          $ r/ t          | d         |z   | d         |z   | d         |z             cY S w xY wNr   r   re   r   r   r    s     r   r!   zVec3.__add__      	Q%("DGeAh$6Q%(8J    	 	 	Q%a5$q'E/    	   =A   6A98A9c                    	 |                      t          j        t          |                    S # t          $ r}|dk    r| cY d }~S |d }~ww xY wr%   )r!   r   castr   r   r&   s      r   r(   zVec3.__radd__  a    	<<T5 9 9::: 	 	 	zzI	    ,/ 
AA AAAc                    	 t          | d         |d         z
  | d         |d         z
  | d         |d         z
            S # t          $ r/ t          | d         |z
  | d         |z
  | d         |z
            cY S w xY wr   r   r    s     r   r*   zVec3.__sub__  r   r   c                    	 t          |d         | d         z
  |d         | d         z
  |d         | d         z
            S # t          $ r/ t          || d         z
  || d         z
  || d         z
            cY S w xY wr   r   r    s     r   r,   zVec3.__rsub__      	a47"E!HtAw$6a478J    	 	 	Qa%$q'/    	r   r-   )float | Vec3 | tuple[float, float, float]c                    	 t          | d         |d         z  | d         |d         z  | d         |d         z            S # t          $ r/ t          | d         |z  | d         |z  | d         |z            cY S w xY wr   r   r0   s     r   r1   zVec3.__mul__      	Q&)#T!Wvay%8$q'F1I:M    	 	 	Q& $q'F"2DGf4D    	r   c                    	 t          | d         |d         z  | d         |d         z  | d         |d         z            S # t          $ r/ t          | d         |z  | d         |z  | d         |z            cY S w xY wr   r   r0   s     r   r4   zVec3.__rmul__  r   r   c                    	 t          | d         |d         z  | d         |d         z  | d         |d         z            S # t          $ r/ t          | d         |z  | d         |z  | d         |z            cY S w xY wr   r   r0   s     r   r6   zVec3.__truediv__  r   r   c                    	 t          |d         | d         z  |d         | d         z  |d         | d         z            S # t          $ r/ t          || d         z  || d         z  || d         z            cY S w xY wr   r   r    s     r   r8   zVec3.__rtruediv__  r   r   c                    	 t          | d         |d         z  | d         |d         z  | d         |d         z            S # t          $ r/ t          | d         |z  | d         |z  | d         |z            cY S w xY wr   r   r    s     r   r:   zVec3.__floordiv__      	Q58#T!Wa%8$q'U1X:M    	 	 	Q5 $q'U"2DGu4D    	r   c                    	 t          |d         | d         z  |d         | d         z  |d         | d         z            S # t          $ r/ t          || d         z  || d         z  || d         z            cY S w xY wr   r   r    s     r   r<   zVec3.__rfloordiv__  s    	aDG#U1Xa%8%(d1g:M    	 	 	a %47"2ET!W4D    	r   c                    t          t          | d                   t          | d                   t          | d                             S r   )r   r>   r   s    r   r?   zVec3.__abs__  s2    CQLL#d1g,,DG===r   c                N    t          | d          | d          | d                    S r   r   r   s    r   rB   zVec3.__neg__  s&    T!WHtAwha111r   NrC   rD   c                .    t          fd| D              S )Nc              3  8   K   | ]}t          |          V  d S rG   rH   rJ   s     r   rM   z!Vec3.__round__.<locals>.<genexpr>  rN   r   r   rO   s    `r   rP   zVec3.__round__  rQ   r   c                    t          t          j        | d                   t          j        | d                   t          j        | d                             S r   )r   rS   rT   r   s    r   rU   zVec3.__ceil__  s>    EJtAw''DG)<)<eja>Q>QRRRr   c                    t          t          j        | d                   t          j        | d                   t          j        | d                             S r   )r   rS   rW   r   s    r   rX   zVec3.__floor__  ?    EKQ((%+d1g*>*>DQRG@T@TUUUr   c                    t          t          j        | d                   t          j        | d                   t          j        | d                             S r   )r   rS   r[   r   s    r   r\   zVec3.__trunc__  r   r   c                    	 t          | d         |d         z  | d         |d         z  | d         |d         z            S # t          $ r/ t          | d         |z  | d         |z  | d         |z            cY S w xY wr   r   r    s     r   r^   zVec3.__mod__  r   r   c                    	 t          | d         |d         z  | d         |d         z  | d         |d         z            S # t          $ r/ t          | d         |z  | d         |z  | d         |z            cY S w xY wr   r   r    s     r   r`   zVec3.__pow__   r   r   !Vec3 | tuple[float, float, float]rb   c                    | d         dz  | d         dz  z   | d         dz  z   |d         dz  |d         dz  z   |d         dz  z   k     S rd   rf   r    s     r   rg   zVec3.__lt__
  sX    Aw!|d1gl*T!W\9E!HMERSHXYM<Y\abc\dhi\i<iiir   pitchyawc                   t          t          j        |          t          j        |          z  t          j        |          t          j        |          t          j        |          z                                            S )zCreate a unit vector from pitch and yaw in radians.

        Args:
            pitch: The pitch value in radians
            yaw: The yaw value in radians
        )r   rS   rm   rn   r   )clsr   r   s      r   from_pitch_yawzVec3.from_pitch_yaw  sb     IcNNUYu---IeIcNNUYu---
 
 )++		r   ra   c                r    t          j        | j                  t          j        | j        | j                  fS )z;Get the pitch and yaw angles from a unit vector in radians.)rS   asinr   rw   r   r   r   s    r   get_pitch_yawzVec3.get_pitch_yaw  s)    z$&!!5;tvtv#>#>>>r   c                l    t          j        | d         dz  | d         dz  z   | d         dz  z             S )zGCalculate the length of the vector: ``sqrt(x ** 2 + y ** 2 + z ** 2)``.r   re   r   rt   r   s    r   rj   zVec3.length  s4    z$q'Q,aA5Q1DEEEr   c                H    | d         dz  | d         dz  z   | d         dz  z   S )zCalculate the squared length of the vector.

        This is simply shortcut for `x ** 2 + y ** 2 + z ** 2` and can be used
        for faster comparisons without the need for a square root.
        r   re   r   rf   r   s    r   rz   zVec3.length_squared#  s,     Aw!|d1gl*T!W\99r   c                    t          | j        |d         z  | j        |d         z  z
  | j        |d         z  | j        |d         z  z
  | j        |d         z  | j        |d         z  z
            S )zCalculate the cross product of this vector and another 3D vector.

        Args:
            other: Another Vec3 or tuple of 3 floats.
        re   r   r   )r   r   r   r   r    s     r   crossz
Vec3.cross+  sp     VeAh46E!H#45VeAh46E!H#45VeAh46E!H#45
 
 	
r   c                f    | j         |d         z  | j        |d         z  z   | j        |d         z  z   S )zCalculate the dot product of this vector and another 3D vector.

        Args:
            other: Another Vec3 or tuple of 3 floats.
        r   r   re   r   r    s     r   r   zVec3.dot7  s5     va 46E!H#44tva7HHHr   alphac                    t          | j        ||d         | j        z
  z  z   | j        ||d         | j        z
  z  z   | j        ||d         | j        z
  z  z             S )a  Create a new Vec3 linearly interpolated between this vector and another Vec3-like.

        Args:
          other: Another Vec3 instance or tuple of 3 floats.
          alpha: The amount of interpolation between this vector, and the other
                 vector. This should be a value between 0.0 and 1.0. For example:
                 0.5 is the midway point between both vectors.
        r   r   re   )r   r   r   r   )r   r   r  s      r   r   z	Vec3.lerp?  sd     FeuQx$&012FeuQx$&012FeuQx$&012
 
 	
r   c                    t          j        |d         | j        z
  dz  |d         | j        z
  dz  z   |d         | j        z
  dz  z             S )zCalculate the distance between this vector and another 3D vector.

        Args:
            other: The point to calculate the distance to.
        r   re   r   )rS   ru   r   r   r   r    s     r   r   zVec3.distanceN  sT     zE!Htv-!3qDF9Jq8PQV[\]V^aeagVglmUmnooor   c                    	 t          j        | d         dz  | d         dz  z   | d         dz  z             }t          | j        |z  | j        |z  | j        |z            S # t          $ r | cY S w xY wr   )rS   ru   r   r   r   r   ZeroDivisionErrorr   s     r   r   zVec3.normalizeV  s    	
47a<$q'Q,6aAEFFA
DFQJ
;;;  	 	 	KKK	s   AA   A/.A/r   r   c                    d S rG   rf   r   s      r   r   z
Vec3.clampc  r   r   c                    d S rG   rf   r   s      r   r   z
Vec3.clampg  r   r   c                    d S rG   rf   r   s      r   r   z
Vec3.clampl  r   r   c                    d S rG   rf   r   s      r   r   z
Vec3.clampp  r   r   c           	     b   	 |d         |d         |d         }}}n# t           $ r	 |}|}|}Y nw xY w	 |d         |d         |d         }}}n# t           $ r	 |}|}|}Y nw xY wt          t          | d         ||          t          | d         ||          t          | d         ||                    S )a  Restrict the value of the X, Y and Z components of the vector to be within the given values.

        If a single value is provided, it will be used for all components.
        If a tuple or Vec3 is provided, the first value will be used for X, the second for Y, and the third for Z.

        Args:
            min_val: The minimum value(s)
            max_val: The maximum value(s)
        r   r   re   )r   r   r   )	r   r   r   r   r   min_zr   r   max_zs	            r   r   z
Vec3.clampu  s    	")!*gaj'!*%5EE 	 	 	EEEEE		")!*gaj'!*%5EE 	 	 	EEEEE	
 $q'5%((%Q*F*FdSTgW\^cHdHd
 
 	
s    ..A AAr   r   r   c                     t          d          r   r   r   s     r   r   z
Vec3.index  r   r   r   r   r   c                     	 t           t          t          dt          |                   } | fd|D              S # t          t
          t          f$ r}d| d}t          |          |d }~ww xY w)Nr   c              3  N   K   | ]}d                      |                   V   dS )xyzNr   r   s     r   rM   z#Vec3.__getattr__.<locals>.<genexpr>  s2      CCtEKKNN3CCCCCCr   z'Vec3' has no attribute: 'r   r   r   s   `    r   r   zVec3.__getattr__  s    	/ Td33CJJ?I9CCCCUCCCDDHi0 	/ 	/ 	/8u888C %%3.	/r   )r   r   r   r   )r-   r   r   r   )r   r   r   r   )r   r   rG   )rC   rD   r   r   )r   r   r   rb   )r   r   r   r   r   r   )r   ra   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   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   r!   r(   r*   r,   r1   r4   r6   r8   r:   r<   r?   rB   rP   rU   rX   r\   r^   r`   rg   classmethodr   r   rj   rz   r  r   r   r   r   r   r   r   r   r   r   rf   r   r   r   r   q  s          ANNNNANNNNANNNN? ? ?                              > > > >2 2 2 29 9 9 9 9S S S SV V V VV V V V      j j j j    [? ? ? ?F F F F: : : :

 

 

 

I I I I
 
 
 
p p p p
 
 
 
  			 	 	 
		 
		 	 	 
		 
		 	 	 
		 
		 	 	 
		
 
 
 
8H H H H/ / / / / /r   r   c                     e Zd ZU dZdZded<   dZded<   dZded<   dZded<   d Z	d@dZ
dAdZd@dZd@dZdBdZdBdZdBdZdBdZdBdZdBdZdCdZdCdZdDdEdZdCdZdCd ZdCd!ZdFd#ZdFd$ZdGd'ZdHd(ZdHd)ZdId+ZdJd,Z dCd-Z!e"j#        rDe"j$        dKd0            Z%e"j$        dLd2            Z%e"j$        dMd3            Z%e"j$        dNd4            Z%dOd6Z%dJd7Z&dPd;Z'dQd?Z(dS )Rr   a`  A four-dimensional vector represented as X Y Z W coordinates.

    `Vec4` is an immutable 4D Vector, including most common operators.
    As an immutable type, all operations return a new object.

    .. note:: The Python ``len` operator returns the number of elements in
              the vector. For the vector length, use the `length()` method.
    r   r   r   r   r   wc                Z    | j         dk    p | j        dk    p| j        dk    p
| j        dk    S r   r   r   r   r  r   s    r   r   zVec4.__bool__  s/    v}O#O3O$&C-Or   r   0Vec4 | tuple[float, float, float, float] | floatr   c           	     ,   	 t          |d         | d         z   |d         | d         z   |d         | d         z   |d         | d         z             S # t          $ r9 t          || d         z   || d         z   || d         z   || d         z             cY S w xY wNr   r   re   r   r   r   r    s     r   r!   zVec4.__add__      	a47"E!HtAw$6a478JERSHW[\]W^L^    	 	 	Qa%$q'/54PQ7?    	   AA A BB.Vec4 | tuple[float, float, float, float] | intc                    	 |                      t          j        t          |                    S # t          $ r}|dk    r| cY d }~S |d }~ww xY wr%   )r!   r   r   r   r   r&   s      r   r(   zVec4.__radd__  r   r   c                ,   	 t          | d         |d         z
  | d         |d         z
  | d         |d         z
  | d         |d         z
            S # t          $ r9 t          | d         |z
  | d         |z
  | d         |z
  | d         |z
            cY S w xY wr  r  r    s     r   r*   zVec4.__sub__      	Q%("DGeAh$6Q%(8JDQRGV[\]V^L^    	 	 	Q%a5$q'E/47U?    	r  c           	     ,   	 t          |d         | d         z
  |d         | d         z
  |d         | d         z
  |d         | d         z
            S # t          $ r9 t          || d         z
  || d         z
  || d         z
  || d         z
            cY S w xY wr  r  r    s     r   r,   zVec4.__rsub__  r  r  r-   0float | Vec4 | tuple[float, float, float, float]c                ,   	 t          | d         |d         z  | d         |d         z  | d         |d         z  | d         |d         z            S # t          $ r9 t          | d         |z  | d         |z  | d         |z  | d         |z            cY S w xY wr  r  r0   s     r   r1   zVec4.__mul__      	Q&)#T!Wvay%8$q'F1I:MtTUwY_`aYbOb    	 	 	Q& $q'F"2DGf4Dd1gPVFV    	r  c                ,   	 t          | d         |d         z  | d         |d         z  | d         |d         z  | d         |d         z            S # t          $ r9 t          | d         |z  | d         |z  | d         |z  | d         |z            cY S w xY wr  r  r0   s     r   r4   zVec4.__rmul__  r&  r  c                ,   	 t          | d         |d         z  | d         |d         z  | d         |d         z  | d         |d         z            S # t          $ r9 t          | d         |z  | d         |z  | d         |z  | d         |z            cY S w xY wr  r  r0   s     r   r6   zVec4.__truediv__  r&  r  c           	     ,   	 t          |d         | d         z  |d         | d         z  |d         | d         z  |d         | d         z            S # t          $ r9 t          || d         z  || d         z  || d         z  || d         z            cY S w xY wr  r  r0   s     r   r8   zVec4.__rtruediv__  s    	q	DG#VAYa%8&)d1g:MvVWy[_`a[bOb    	 	 	a &47"2FT!W4DftTUwFV    	r  c                ,   	 t          | d         |d         z  | d         |d         z  | d         |d         z  | d         |d         z            S # t          $ r9 t          | d         |z  | d         |z  | d         |z  | d         |z            cY S w xY wr  r  r0   s     r   r:   zVec4.__floordiv__  s    	Q6!9$d1g&:DGvay<PRVWXRY]cde]fRf    	 	 	Q6!47f#4d1g6GaTZIZ    	r  c           	     ,   	 t          |d         | d         z  |d         | d         z  |d         | d         z  |d         | d         z            S # t          $ r9 t          || d         z  || d         z  || d         z  || d         z            cY S w xY wr  r  r0   s     r   r<   zVec4.__rfloordiv__  s    	q	T!W$fQi47&:F1Ia<PRXYZR[_cde_fRf    	 	 	$q'!6T!W#4fQ6GSWXYSZIZ    	r  c           	         t          t          | d                   t          | d                   t          | d                   t          | d                             S r  )r   r>   r   s    r   r?   zVec4.__abs__  s>    CQLL#d1g,,DGc$q'llKKKr   c                V    t          | j         | j         | j         | j                   S rG   r   r   r   r   r  r   s    r   rB   zVec4.__neg__  s&    TVGdfWtvgw777r   NrC   rD   c                .    t          fd| D              S )Nc              3  8   K   | ]}t          |          V  d S rG   rH   rJ   s     r   rM   z!Vec4.__round__.<locals>.<genexpr>  rN   r   )r   rO   s    `r   rP   zVec4.__round__  rQ   r   c           	         t          t          j        | d                   t          j        | d                   t          j        | d                   t          j        | d                             S r  )r   rS   rT   r   s    r   rU   zVec4.__ceil__  sS    EJtAw''DG)<)<eja>Q>QSXS]^bcd^eSfSfgggr   c           	         t          t          j        | d                   t          j        | d                   t          j        | d                   t          j        | d                             S r  )r   rS   rW   r   s    r   rX   zVec4.__floor__  T    EKQ((%+d1g*>*>DQRG@T@TV[VabfghbiVjVjkkkr   c           	         t          t          j        | d                   t          j        | d                   t          j        | d                   t          j        | d                             S r  )r   rS   r[   r   s    r   r\   zVec4.__trunc__!  r3  r   (Vec4 | tuple[int, int, int, int] | floatc                ,   	 t          | d         |d         z  | d         |d         z  | d         |d         z  | d         |d         z            S # t          $ r9 t          | d         |z  | d         |z  | d         |z  | d         |z            cY S w xY wr  r  r    s     r   r^   zVec4.__mod__$  r"  r  c                ,   	 t          | d         |d         z  | d         |d         z  | d         |d         z  | d         |d         z            S # t          $ r9 t          | d         |z  | d         |z  | d         |z  | d         |z            cY S w xY wr  r  r    s     r   r`   zVec4.__pow__.  s    	Q58#T!Wa%8$q'U1X:MtTUwZ_`aZbOb    	 	 	Q5 $q'U"2DGu4Dd1gQVFV    	r  (Vec4 | tuple[float, float, float, float]rb   c                    | d         dz  | d         dz  z   | d         dz  z   | d         dz  z   |d         dz  |d         dz  z   |d         dz  z   |d         dz  z   k     S )Nr   re   r   r   rf   r    s     r   rg   zVec4.__lt__8  sr    Q1tAw!|+d1gl:T!W\IaAaA-aA=aAMN 	Or   c                    t          j        | d         dz  | d         dz  z   | d         dz  z   | d         dz  z             S )zPCalculate the length of the vector: ``sqrt(x ** 2 + y ** 2 + z ** 2 + w ** 2)``.r   re   r   r   rt   r   s    r   rj   zVec4.length<  sB    z$q'Q,aA5Q1DtAwRS|STTTr   c                `    | d         dz  | d         dz  z   | d         dz  z   | d         dz  z   S )zCalculate the squared length of the vector.

        This is simply shortcut for `x ** 2 + y ** 2 + z ** 2 + w ** 2` and can be used
        for faster comparisons without the need for a square root.
        r   re   r   r   rf   r   s    r   rz   zVec4.length_squared@  s9     Aw!|d1gl*T!W\9DGqLHHr   r|   c           	         t          | j        ||j        | j        z
  z  z   | j        ||j        | j        z
  z  z   | j        ||j        | j        z
  z  z   | j        ||j        | j        z
  z  z             S )aq  Create a new Vec4 linearly interpolated between this vector and another Vec4.

        Args:
          other: Another Vec4 instance.
          amount: The amount of interpolation between this vector, and the other
                  vector. This should be a value between 0.0 and 1.0. For example:
                  0.5 is the midway point between both vectors.
        r.  r~   s      r   r   z	Vec4.lerpH  sv     Ff$& 012Ff$& 012Ff$& 012Ff$& 012	
 
 	
r   c                    t          j        |j        | j        z
  dz  |j        | j        z
  dz  z   |j        | j        z
  dz  z   |j        | j        z
  dz  z             S )zCalculate the distance between this vector and another 4D vector.

        Args:
            other: The point to calculate the distance to.
        re   )rS   ru   r   r   r   r  r    s     r   r   zVec4.distanceX  sm     zg1$$& Q&($& Q&( $& Q&(
 
 	
r   c                    t          j        | d         dz  | d         dz  z   | d         dz  z   | d         dz  z             x}r6t          | d         |z  | d         |z  | d         |z  | d         |z            S | S )zReturns a normalized version of the vector meaning a version that has length 1.

        This means that the vector will have the same direction, but a length of 1.0.
        If the vector has a length of 0, the original vector will be returned.
        r   re   r   r   )rS   ru   r   r   s     r   r   zVec4.normalizee  s     
47a<$q'Q,6aAEQSTTUUU1 	LQ!T!Wq[$q'A+tAw{KKKr   r   r   c                    d S rG   rf   r   s      r   r   z
Vec4.clampp  r   r   !tuple[float, float, float, float]c                    d S rG   rf   r   s      r   r   z
Vec4.clampt  r   r   c                    d S rG   rf   r   s      r   r   z
Vec4.clampy  r   r   c                    d S rG   rf   r   s      r   r   z
Vec4.clamp}  r   r   )float | tuple[float, float, float, float]c           
        	 |d         |d         |d         |d         f\  }}}}n# t           $ r |}|}|}|}Y nw xY w	 |d         |d         |d         |d         f\  }}}	}
n# t           $ r |}|}|}	|}
Y nw xY wt          t          | d         ||          t          | d         ||          t          | d         ||	          t          | d         ||
                    S )a  Restrict the value of the X, Y, Z and W components of the vector to be within the given values.

        The minimum and maximum values can be a single value that will be applied to all components,
        or a tuple of 4 values that will be applied to each component respectively.

        Args:
            min_val: The minimum value(s)
            max_val: The maximum value(s)
        r   r   re   r   )r   r   r   )r   r   r   r   r   r  min_wr   r   r  max_ws              r   r   z
Vec4.clamp  s$   	)0WQZWUVZ)W&E5% 	 	 	EEEEEE		
	)0WQZ'!*gVWj)X&E5% 	 	 	EEEEEE		 $q'5%((%Q*F*F$q'5%((%Q*F*F
 
 	
s   #& ;;#A# #A87A8c                    | j         |j         z  | j        |j        z  z   | j        |j        z  z   | j        |j        z  z   S )zCalculate the dot product of this vector and another 4D vector.

        Args:
            other: Another Vec4 instance.
        r  r    s     r   r   zVec4.dot  s?     v$&57"22TVeg5EEQVQXHXXXr   r   r   r   c                     t          d          r   r   r   s     r   r   z
Vec4.index  r   r   r   r   r   c                     	 t           t          t          dt          |                   } | fd|D              S # t          t
          t          f$ r}d| d}t          |          |d }~ww xY w)Nr   c              3  N   K   | ]}d                      |                   V   dS )xyzwNr   r   s     r   rM   z#Vec4.__getattr__.<locals>.<genexpr>  s2      DDtFLLOO4DDDDDDr   z'Vec4' has no attribute: 'r   r   r   s   `    r   r   zVec4.__getattr__  s    	/ Td33CJJ?I9DDDDeDDDEEHi0 	/ 	/ 	/8u888C %%3.	/r   )r   r  r   r   )r   r  r   r   )r-   r$  r   r   )r   r   rG   )rC   rD   r   r   )r   r5  r   r   )r   r8  r   rb   r   )r   r8  r|   r   r   r   )r   r8  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   rD  r   rD  r   r   r   r   ))r   r   r   r   r   r   r   r   r  r   r!   r(   r*   r,   r1   r4   r6   r8   r:   r<   r?   rB   rP   rU   rX   r\   r^   r`   rg   rj   rz   r   r   r   r   r   r   r   r   r   r   rf   r   r   r   r     s]          ANNNNANNNNANNNNANNNNP P P                              L L L L8 8 8 89 9 9 9 9h h h hl l l ll l l l      O O O OU U U UI I I I
 
 
 
 
 
 
 
     			 	 	 
		 
		 	 	 
		 
		 	 	 
		 
		 	 	 
		 
  
  
  
DY Y Y YH H H H/ / / / / /r   r   c                  @   e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	ded	<   dZ
ded
<   dZded<   dZded<   dZded<   d,dZd-dZd.dZd,dZd/dZd/dZd0dZd0dZd0dZd1d2d!Zd3d$Zej        d4d&            Zej        d/d'            Zd5d)Zd6d+ZdS )7Mat3a  A 3x3 Matrix.

    `Mat3` is an immutable 3x3 Matrix, which includes most common operators.

    A Matrix can be created with a list or tuple of 9 values.
    If no values are provided, an "identity matrix" will be created
    (1.0 on the main diagonal). Because Mat3 objects are immutable,
    all operations return a new Mat3 object.

    .. note:: Matrix multiplication is performed using the "@" operator.
    rh   r   ar   br   r   efghisxsyr   c                B    | t          d|z  dddd|z  dddd	  	        z  S Nrh   r   rN  r   rV  rW  s      r   scalez
Mat3.scale  s-    d38S#sC"Hc3SQQQQr   txtyc                8    | t          dddddd| |d	  	        z  S rY  rZ  )r   r]  r^  s      r   	translatezMat3.translate  s'    d3S#sC"b#FFFFr   phic                    t          j        t          j        |                    }t          j        t          j        |                    }| t	          ||d| |dddd	  	        z  S )Nr   rh   )rS   rn   radiansrm   rN  )r   ra  r   r   s       r   r   zMat3.rotate  sY    IemC(())IemC(())d1aqb!S#sC@@@@r   c                6    | t          d|d|ddddd	  	        z  S rY  rZ  r[  s      r   shearz
Mat3.shear  s%    d3CS#sCEEEEr   r   c                    t          |t                    st          d          t          d t          | |          D              S )Nz Can only add to other Mat3 typesc              3  &   K   | ]\  }}||z   V  d S rG   rf   rK   r   os      r   rM   zMat3.__add__.<locals>.<genexpr>  *      991a!e999999r   
isinstancerN  r   zipr    s     r   r!   zMat3.__add__  H    %&& 	@>???99D%(8(8999::r   c                    t          |t                    st          d          t          d t          | |          D              S )Nz'Can only subtract from other Mat3 typesc              3  &   K   | ]\  }}||z
  V  d S rG   rf   rh  s      r   rM   zMat3.__sub__.<locals>.<genexpr>  rj  r   rk  r    s     r   r*   zMat3.__sub__  H    %&& 	GEFFF99D%(8(8999::r   c                    | S rG   rf   r   s    r   __pos__zMat3.__pos__      r   c                (    t          d | D              S )Nc              3     K   | ]}| V  d S rG   rf   rK   rL   s     r   rM   zMat3.__neg__.<locals>.<genexpr>  $      ''Qqb''''''r   rZ  r   s    r   rB   zMat3.__neg__      ''$'''((r   c                   | \	  }}}}}}}}}	||	z  ||z  z
  }
||z  ||	z  z
  }||z  ||z  z
  }||z  ||	z  z
  }||	z  ||z  z
  }||z  ||z  z
  }||z  ||z  z
  }||z  ||z  z
  }||z  ||z  z
  }||
z  ||z  z   ||z  z   }|dk    rt          j        d           | S d|z  }t          |
|z  ||z  ||z  ||z  ||z  ||z  ||z  ||z  ||z  f	 S )Nr   .Unable to calculate inverse of singular Matrixrh   )	_warningswarnrN  )r   a11a12a13a21a22a23a31a32a33rO  rP  r   r   rQ  rR  rS  rT  rU  detreps                        r   
__invert__zMat3.__invert__  sQ   6:3S#sCc3 #Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	! Aga#')!88NKLLLK Ci a#gq3wC#gq3wC#gq3wC1 2 	2r   NndigitsrD   c                .    t          fd| D              S )Nc              3  8   K   | ]}t          |          V  d S rG   rH   rK   rL   r  s     r   rM   z!Mat3.__round__.<locals>.<genexpr>  -      66AeAw''666666r   rZ  r   r  s    `r   rP   zMat3.__round__  #    666666677r   object_typing.NoReturnc                $    d}t          |          Nz4Please use the @ operator for Matrix multiplication.r   r   r   r   s      r   r1   zMat3.__mul__      D!#&&&r   r   c                    d S rG   rf   r    s     r   
__matmul__zMat3.__matmul__      /2sr   c                    d S rG   rf   r    s     r   r  zMat3.__matmul__  r  r   Vec3 | Mat3c                0   	 | \	  }}}}}}}}	}
|\	  }}}}}}}}}t          ||z  ||z  z   ||z  z   ||z  ||z  z   |	|z  z   ||z  ||z  z   |
|z  z   ||z  ||z  z   ||z  z   ||z  ||z  z   |	|z  z   ||z  ||z  z   |
|z  z   ||z  ||z  z   ||z  z   ||z  ||z  z   |	|z  z   ||z  ||z  z   |
|z  z   	  	        S # t          $ rS |\  }}}| \	  }}}}}}}}	}
t          ||z  ||z  z   ||z  z   ||z  ||z  z   |	|z  z   ||z  ||z  z   |
|z  z             cY S w xY wrG   )rN  r   r   )r   r   r~  r  r  r  r  r  r  r  r  b11b12b13b21b22b23b31b32b33r   r   r   s                          r   r  zMat3.__matmul__  s   	:>7Cc3S#sC:?7Cc3S#sC c	C#I%c	139sSy3H3QT93TVY\_V_behkbkVknqtwnwVwc	C#I%c	139sSy3H3QT93TVY\_V_behkbkVknqtwnwVwc	C#I%c	139sSy3H3QT93TVY\_V_behkbkVknqtwnwVw    	 	 	GAq!:>7Cc3S#sCa#'!C!G+a#'!C!G+a#'!C!G+    		s   B5B8 8ADDr   c                ^    | j         j         | dd          d| dd          d| dd          S )Nr   r   
       	   	__class__r   r   s    r   __repr__zMat3.__repr__7  sC    .)X4!9XXD1IXXTRSTURUYXXXr   )rV  r   rW  r   r   rN  )r]  r   r^  r   r   rN  )ra  r   r   rN  )r   rN  r   rN  r   rN  rG   )r  rD   r   rN  )r   r  r   r  )r   r   r   r   )r   r  r   r   )r   r   r   r   rO  r   rP  r   r   rQ  rR  rS  rT  rU  r\  r`  r   re  r!   r*   rs  rB   r  rP   r1   r   r   r  r  rf   r   r   rN  rN    s        
 
 ANNNNANNNNANNNNANNNNANNNNANNNNANNNNANNNNANNNNR R R RG G G GA A A A
F F F F; ; ; ;
; ; ; ;
   ) ) ) )2 2 2 2B8 8 8 8 8' ' ' ' 222 2222 2   2Y Y Y Y Y Yr   rN  c                  @   e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	ded	<   dZ
ded
<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   edHd            ZedIdJd"            ZedKd&            ZedLd'            ZedLd(            ZedMd,            ZdNd0ZdNd1ZdKd2ZdOd3ZdOd4Z dPd5Z!dQd7Z"dQd8Z#dPd9Z$dPd:Z%dPd;Z&dRd>Z'dSd@Z(e)j*        dTdB            Z+e)j*        dQdC            Z+dD Z+dUdFZ,dGS )VMat4a?  A 4x4 Matrix.

    ``Mat4`` is an immutable 4x4 Matrix object with most common operators.
    This includes class methods for creating orthogonal and perspective
    projection matrixes, which can be used directly by OpenGL.

    You can create a Matrix with 16 initial values (floats), or no values
    at all. If no values are provided, an "identity matrix" will be created
    (1.0 on the main diagonal). ``Mat4`` objects are immutable, so all
    operations will return a new Mat4 object.

    Note:
        Matrix multiplication is performed using the "@" operator.
    rh   r   rO  r   rP  r   r   rQ  rR  rS  rT  rU  jklmnri  pr   
type[Mat4]leftrightbottomtopz_nearz_farr   c                    ||z
  }||z
  }||z
  }	d|z  }
d|z  }d|	 z  }||z    |z  }||z    |z  }||z    |	z  } | |
dddd|dddd|d|||d          S )a	  Create a Mat4 orthographic projection matrix for use with OpenGL.

        Given left, right, bottom, top values, and near/far z planes,
        create a 4x4 Projection Matrix. This is useful for setting
        :py:attr:`~pyglet.window.Window.projection`.
        ry   r   rh   rf   )r   r  r  r  r  r  r  widthheightdepths_xs_ys_zt_xt_yt_zs                   r   orthogonal_projectionzMat4.orthogonal_projection_  s     vEkFlUFlo%fo&%'s3S#S#S#S#' ' 	'r   <   aspectfovc                    |t          j        |t           j        z  dz            z  }| }| }||z
  }||z
  }	||z
  }
||z    |
z  }d|z  |z  |
z  }d|z  |z  }||z  }d|z  |	z  } | |dddd|dddd|ddd|d          S )a  Create a Mat4 perspective projection matrix for use with OpenGL.

        Given a desired aspect ratio, near/far planes, and fov (field of view),
        create a 4x4 Projection Matrix. This is useful for setting
        :py:attr:`~pyglet.window.Window.projection`.
        ih  re   r   )rS   tanpi)r   r  r  r  r  xy_maxy_minx_minr  r  r  qqnr  rT  s                  r   perspective_projectionzMat4.perspective_projectiony  s     %)C%(NS$8999%fn%%Z& 5(JJJs1aAaAaBaQ    	 r   rp   r   r   c                >     |                                  ||          S )zCreate a rotation matrix from an angle and Vec3.

        Args:
          angle: The desired angle, in radians.
          vector: A Vec3 indicating the direction.
        )r   )r   rp   r   s      r   from_rotationzMat4.from_rotation  s     suu||E6***r   c                T     | |j         dddd|j        dddd|j        ddddd          S )z"Create a scale matrix from a Vec3.r   rh   r   r   r   s     r   
from_scalezMat4.from_scale  sA     s68S#s#sVXsS#' ' 	'r   c                T     | dddddddddddd|j         |j        |j        d          S )z(Create a translation matrix from a Vec3.rh   r   r   r  s     r   from_translationzMat4.from_translation  sA     s3S#S#S#8VXvx6 6 	6r   positiontargetupc                   ||z
                                   }|                                 }|                    |                                           }|                    |          } | |j        |j        |j         d|j        |j        |j         d|j        |j        |j         d|                    |           |                    |           |                    |          d          S )a  Create a viewing matrix that points toward a target.

        This method takes three Vec3s, describing the viewer's position,
        where they are looking, and the upward axis (typically positive
        on the Y axis). The resulting Mat4 can be used as the projection
        matrix.

        Args:
          position: The location of the viewer in the scene.
          target: The point that the viewer is looking towards.
          up: A vector pointing "up" in the scene, typically `Vec3(0.0, 1.0, 0.0)`.
        r   rh   )r   r  r   r   r   r   )r   r  r  r  rR  ur   s          r   look_atzMat4.look_at  s     h))++LLNNGGAJJ  ""GGAJJs13acT33acT33acT3EE(OO#aeeHoo%5quuXM M 	Mr   r   r   tuplec                    | |dd         S )zGet a specific row as a tuple.Nr   rf   r   r   s     r   rowzMat4.row  s    EH1H~r   c                (    | |dz  |dz  dz            S )z!Get a specific column as a tuple.r   rf   r  s     r   columnzMat4.column  s    EAIuqy1},--r   c                   t          d |D                       st          d          |\  }}}t          j        |          }t          j        |          }d|z
  }||z  ||z  ||z  }}
}	||	|z  z   }d|	|z  z   ||z  z   }d|	|z  z   ||z  z
  }d|
|z  z   ||z  z
  }||
|z  z   }d|
|z  z   ||z  z   }d||z  z   ||z  z   }d||z  z   ||z  z
  }|||z  z   }| t          |||d|||d|||ddddd          z  S )z)Get a rotation Matrix on x, y, or z axis.c              3  <   K   | ]}t          |          d k    V  dS )r   N)r>   )rK   r  s     r   rM   zMat4.rotate.<locals>.<genexpr>  s,      //13q66Q;//////r   zvector must be normalized (<=1)r   r   )allr   rS   rm   rn   r  )r   rp   r   r   r   r   r   r   ttemp_xtemp_ytemp_zrarbrcrerfrgrirjrks                        r   r   zMat4.rotate  s[   /////// 	@>???1aIeIeE!"QAq1u!^!^a!e#!^a!e#!^a!e#!^!^a!e#!^a!e#!^a!e#!^ d2r2q"b"aRQ1aQRSSSSr   c                    t          |           }|dxx         |d         z  cc<   |dxx         |d         z  cc<   |dxx         |d         z  cc<   t          | S )z&Get a scale Matrix on x, y, or z axis.r      r   
   re   )listr  )r   r   temps      r   r\  z
Mat4.scale  se    DzzQ6!9Q6!9RF1IT{r   c                <    | t          ddddddddddddg|dR  z  S )z0Get a translation Matrix along x, y, and z axis.r   r   r  )r   r   s     r   r`  zMat4.translate  s8    d1aAq!Q1aAJJJJJJJr   c                n    t          g | ddd         | ddd         | ddd         | ddd         R  S )zGet a transpose of this Matrix.r   Nr   r   re   r   r   r   s    r   	transposezMat4.transpose  sM    GT!$Q$ZG$qt!t*GtADqDzGDAJGGGGr   r   c                    t          |t                    st          d          t          d t          | |          D              S )Nz Can only add to other Mat4 typesc              3  &   K   | ]\  }}||z   V  d S rG   rf   rh  s      r   rM   zMat4.__add__.<locals>.<genexpr>  rj  r   rl  r  r   rm  r    s     r   r!   zMat4.__add__  rn  r   c                    t          |t                    st          d          t          d t          | |          D              S )Nz'Can only subtract from other Mat4 typesc              3  &   K   | ]\  }}||z
  V  d S rG   rf   rh  s      r   rM   zMat4.__sub__.<locals>.<genexpr>  rj  r   r  r    s     r   r*   zMat4.__sub__  rq  r   c                    | S rG   rf   r   s    r   rs  zMat4.__pos__  rt  r   c                (    t          d | D              S )Nc              3     K   | ]}| V  d S rG   rf   rw  s     r   rM   zMat4.__neg__.<locals>.<genexpr>  rx  r   r   r   s    r   rB   zMat4.__neg__  ry  r   c                   | \  }}}}}}}}}	}
}}}}}}||z  ||z  z
  }|
|z  ||z  z
  }|
|z  ||z  z
  }|	|z  ||z  z
  }|	|z  ||z  z
  }|	|z  |
|z  z
  }||z  ||z  z
  }||z  ||z  z
  }||z  ||z  z
  }||z  ||z  z
  }||z  ||
z  z
  }||z  ||
z  z
  }||z  ||z  z
  }||z  ||z  z
  }||z  ||	z  z
  }||z  ||	z  z
  } ||z  ||z  z
  }!||
z  ||	z  z
  }"|||z  ||z  z
  ||z  z   z  |||z  ||z  z
  ||z  z   z  z
  |||z  ||z  z
  ||z  z   z  z   |||z  ||z  z
  ||z  z   z  z
  }#|#dk    rt          j        d           | S d|#z  }$|$ }%t          |$||z  ||z  z
  ||z  z   z  |%||z  ||z  z
  ||z  z   z  |$||z  ||z  z
  ||z  z   z  |%||z  ||z  z
  ||z  z   z  |%||z  ||z  z
  ||z  z   z  |$||z  ||z  z
  ||z  z   z  |%||z  ||z  z
  ||z  z   z  |$||z  ||z  z
  || z  z   z  |$||z  ||z  z
  ||z  z   z  |%||z  ||z  z
  ||z  z   z  |$||z  ||z  z
  ||!z  z   z  |%||z  ||z  z
  ||"z  z   z  |%||z  ||z  z
  ||z  z   z  |$||z  ||z  z
  ||z  z   z  |%||z  ||z  z
  ||!z  z   z  |$||z  || z  z
  ||"z  z   z            S )Nr   r{  r   )r|  r}  r  )&r   r~  r  r  a14r  r  r  a24r  r  r  a34a41a42a43a44rO  rP  r   r   rQ  rR  rS  rT  rU  r  r  r  r  r  ri  r  r  rr  pdetndets&                                         r   r  zMat4.__invert__	  s   Y]VS#sCc3S#sCcSV#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!#Ic	!cAga'#'12cAga'#'123cAga'#'123 cAga'#'123
 !88NKLLLK3wuDC!GcAg-a78C!GcAg-a78C!GcAg-a78C!GcAg-a78C!GcAg-a78C!GcAg-a78C!GcAg-a78C!GcAg-a78C!GcAg-a78C!GcAg-a78C!GcAg-a78C!GcAg-a78C!GcAg-a78C!GcAg-a78C!GcAg-a78C!GcAg-a78: : 	:r   r  rD   c                .    t          fd| D              S )Nc              3  8   K   | ]}t          |          V  d S rG   rH   r  s     r   rM   z!Mat4.__round__.<locals>.<genexpr>>  r  r   r   r  s    `r   rP   zMat4.__round__=  r  r   r  c                $    d}t          |          r  r   r  s      r   r1   zMat4.__mul__@  r  r   r   c                    d S rG   rf   r    s     r   r  zMat4.__matmul__D  r  r   c                    d S rG   rf   r    s     r   r  zMat4.__matmul__G  r  r   c                L   	 | \  }}}}}}}}	}
}}}}}}}|\  }}}}}}}}}}}}}}} }!t          ||z  ||z  z   |
|z  z   ||z  z   ||z  ||z  z   ||z  z   ||z  z   ||z  ||z  z   ||z  z   ||z  z   ||z  |	|z  z   ||z  z   ||z  z   ||z  ||z  z   |
|z  z   ||z  z   ||z  ||z  z   ||z  z   ||z  z   ||z  ||z  z   ||z  z   ||z  z   ||z  |	|z  z   ||z  z   ||z  z   ||z  ||z  z   |
|z  z   ||z  z   ||z  ||z  z   ||z  z   ||z  z   ||z  ||z  z   ||z  z   ||z  z   ||z  |	|z  z   ||z  z   ||z  z   ||z  ||z  z   |
| z  z   ||!z  z   ||z  ||z  z   || z  z   ||!z  z   ||z  ||z  z   || z  z   ||!z  z   ||z  |	|z  z   || z  z   ||!z  z             S # t          $ r |\  }"}#}$}%| \  }}}}}}}}	}
}}}}}}}t          |"|z  |#|z  z   |$|
z  z   |%|z  z   |"|z  |#|z  z   |$|z  z   |%|z  z   |"|z  |#|z  z   |$|z  z   |%|z  z   |"|z  |#|	z  z   |$|z  z   |%|z  z             cY S w xY wrG   )r  r   r   )&r   r   r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  b14r  r  r  b24r  r  r  b34b41b42b43b44r   r   r   r  s&                                         r   r  zMat4.__matmul__J  s   	]aZCc3S#sCc3SRUWZ]bZCc3S#sCc3SRUWZc	C#I%c	1C#I=sSy3QT9?TWZ]`W`?`cfilcl?lc	C#I%c	1C#I=sSy3QT9?TWZ]`W`?`cfilcl?lc	C#I%c	1C#I=sSy3QT9?TWZ]`W`?`cfilcl?lc	C#I%c	1C#I=sSy3QT9?TWZ]`W`?`cfilcl?lc	C#I%c	1C#I=sSy3QT9?TWZ]`W`?`cfilcl?lc	C#I%c	1C#I=sSy3QT9?TWZ]`W`?`cfilcl?lc	C#I%c	1C#I=sSy3QT9?TWZ]`W`?`cfilcl?lc	C#I%c	1C#I=sSy3QT9?TWZ]`W`?`cfilcl?l    		 		 		JAq!Q]aZCc3S#sCc3SRUWZC!c'!AG+a#g5C!c'!AG+a#g5C!c'!AG+a#g5C!c'!AG+a#g5	    			s   FF B
H#"H#r   c           
     t    | j         j         | dd          d| dd          d| dd          d| dd          S )Nr   r   r           r  r   s    r   r  zMat4.__repr__i  sX    .)l4!9llD1IllTRSTVRVZll_cdfgidi_jlllr   N)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   r  )rp   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   r  r   r  )r   r  r   r  )r  rD   r   r  )r   r   r   r  )r   r   r   r   r  )-r   r   r   r   rO  r   rP  r   r   rQ  rR  rS  rT  rU  r  r  r  r  r  ri  r  r  r  r  r  r  r  r  r  r  r   r\  r`  r  r!   r*   rs  rB   r  rP   r1   r   r   r  r  rf   r   r   r  r  ;  s)          ANNNNANNNNANNNNANNNNANNNNANNNNANNNNANNNNANNNNANNNNANNNNANNNNANNNNANNNNANNNNANNNN' ' ' ['2         [ 4 + + + [+ ' ' ' [' 6 6 6 [6 M M M [M.   . . . .T T T T6   K K K KH H H H; ; ; ;
; ; ; ;
   ) ) ) )2: 2: 2: 2:h8 8 8 8' ' ' ' 222 2222 2  >m m m m m mr   r  c                      e Zd ZU dZdZded<   dZded<   dZded<   dZded<   e	dd            Z
e	dd            Zd dZd!dZd"dZd#dZd$dZd#dZd%dZd%dZd&dZd%dZd#dZd%dZdS )'
QuaternionzhQuaternion.

    Quaternions are 4-dimensional complex numbers, useful for describing 3D rotations.
    rh   r   r  r   r   r   r   matrN  r   c                    t           rG   r   r   r*  s     r   	from_mat3zQuaternion.from_mat3x      !!r   r  c                    t           rG   r   r,  s     r   	from_mat4zQuaternion.from_mat4|  r.  r   c                   | j         }| j        }| j        }| j        }d|dz  |dz  z   dz  z
  }d||z  ||z  z
  z  }d||z  ||z  z   z  }d||z  ||z  z   z  }d|dz  |dz  z   dz  z
  }	d||z  ||z  z
  z  }
d||z  ||z  z
  z  }d||z  ||z  z   z  }d|dz  |dz  z   dz  z
  }t	          |||d||	|
d|||ddddd          S )z:Calculate a 4x4 transform matrix which applies a rotation.r   re   r   rh   )r  r   r   r   r  r   r  r   r   r   rO  rP  r   rQ  rR  rS  rU  r  r  s                 r   to_mat4zQuaternion.to_mat4  s#    FFFFA1!!QQQQQQA1!!QQQQQQA1!! Aq!S!Q31ac3SQQQr   c                l   | j         }| j        }| j        }| j        }d|dz  |dz  z   dz  z
  }d||z  ||z  z
  z  }d||z  ||z  z   z  }d||z  ||z  z   z  }d|dz  |dz  z   dz  z
  }	d||z  ||z  z
  z  }
d||z  ||z  z
  z  }d||z  ||z  z   z  }d|dz  |dz  z   dz  z
  }t	          |||||	|
|||f	 S )zCreate a 3x3 rotation matrix.r   re   )r  r   r   r   rN  r2  s                 r   to_mat3zQuaternion.to_mat3  s    FFFFA1!!QQQQQQA1!!QQQQQQA1!! aAq!Q1a011r   c                |    t          j        | j        dz  | j        dz  z   | j        dz  z   | j        dz  z             S )z7Calculate the length of the quaternion from the origin.re   )rS   ru   r  r   r   r   r   s    r   rj   zQuaternion.length  s9    z$&!)dfai/$&!);dfaiGHHHr   c                T    t          | j        | j         | j         | j                   S )zCalculate the conjugate of this quaternion.

        This operation:
        #. leaves the :py:attr:`.w` component alone
        #. inverts the sign of the :py:attr:`.x`, :py:attr:`.y`, and :py:attr:`.z` components

        )r)  r  r   r   r   r   s    r   	conjugatezQuaternion.conjugate  s&     $&46'DF7TVG<<<r   r   c                L    | \  }}}}|\  }}}}	||z  ||z  z   ||z  z   ||	z  z   S )z2Calculate the dot product with another quaternion.rf   
r   r   rO  rP  r   r   rQ  rR  rS  rT  s
             r   r   zQuaternion.dot  s@    
1a
1a1uq1u}q1u$q1u,,r   c                    |                                  }|dk    r| S t          | j        |z  | j        |z  | j        |z  | j        |z            S )zCalculate a unit quaternion from the instance.

        The returned quaternion will be a scaled-down version
        of the instance which has:

        * a length of ``1``
        * the same relative of its components
        r   )rj   r)  r  r   r   r   )r   r  s     r   r   zQuaternion.normalize  sK     KKMM66K$&1*dfqj$&1*dfqjIIIr   c                Z    | \  }}}}|\  }}}}	t          ||z   ||z   ||z   ||	z             S rG   r)  r:  s
             r   r!   zQuaternion.__add__  @    
1a
1a!a%QAq1u555r   c                Z    | \  }}}}|\  }}}}	t          ||z
  ||z
  ||z
  ||	z
            S rG   r=  r:  s
             r   r*   zQuaternion.__sub__  r>  r   r-   c                v    | j         |z  | j        |z  }}| j        |z  | j        |z  }}t	          ||||          S rG   )r  r   r   r   r)  )r   r-   r  r   r   r   s         r   r1   zQuaternion.__mul__  s@    v1v1!Q1%%%r   c                    |  |z  S rG   rf   r    s     r   r6   zQuaternion.__truediv__  s    uu}r   c                \    |                                  d|                     |           z  z  S Nr   )r8  r   r   s    r   r  zQuaternion.__invert__  s&    ~~1txx~~#566r   c                    | j         t          | dd           }}|j         t          |dd           }}||z  |                    |          z
  }||z  ||z  z   |                    |          z   }t	          |g|R  S rC  )r  r   r   r  r)  )r   r   rO  r  rP  rL   r-   r   s           r   r  zQuaternion.__matmul__  s    vtT!""X1weABBi(1Qq!QQ+&*6****r   N)r*  rN  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  r   r   r   r   r  r-  r0  r3  r5  rj   r8  r   r   r!   r*   r1   r6   r  r  rf   r   r   r)  r)  m  s         
 ANNNNANNNNANNNNANNNN" " " [" " " " ["R R R R62 2 2 26I I I I= = = =- - - -J J J J6 6 6 6
6 6 6 6
& & & &
   7 7 7 7+ + + + + +r   r)  )r   r   r   r   r   r   r   r   )r   
__future__r   mathrS   typingr   warningsr|  r   
NamedTupler   r   r   rN  r  r)  rf   r   r   <module>rJ     s   & # " " " " "            + + + +
N/ N/ N/ N/ N/7 N/ N/ N/b
j/ j/ j/ j/ j/7 j/ j/ j/Z	X/ X/ X/ X/ X/7 X/ X/ X/vY Y Y Y Y7 Y Y YDom om om om om7 om om omd	E+ E+ E+ E+ E+# E+ E+ E+ E+ E+r   