
    j1b                     t   d dl Z d dl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 ej        dd          Z ej        dd          Z ej        dd          Z G d de          Zd  Zd! Zd" Z d# Z!d$ Z"d% Z#	 	  G d& d'e$          Z%e&d(k    r e' e j(                               dS dS ))    Nz0.2.0topbottomleftrighttoplefttopright
bottomleftbottomrightmidtopmidrightmidleft	midbottomcentercenterxcenterywidthheightsizeboxarea	perimeterBoxzleft top width heightPointzx ySizezwidth heightc                       e Zd ZdZdS )PyRectExceptionz
    This class exists for PyRect exceptions. If the PyRect module raises any
    non-PyRectException exceptions, this indicates there's a bug in PyRect.
    N)__name__
__module____qualname____doc__     R/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/pyrect/__init__.pyr   r   '   s         
 	Dr"   r   c                 v    t          | t          t          f          st          d| j        j        z            dS )zGRaises an exception if arg is not an int or float. Always returns None.%argument must be int or float, not %sN)
isinstanceintfloatr   	__class__r   args    r#   _checkForIntOrFloatr,   0   sA    cC<(( 
3s}7MN
 
 	

 
r"   c                 h    t          | t                    st          d| j        j        z            dS )z>Raises an exception if arg is not an int. Always returns None.r%   N)r&   r'   r   r)   r   r*   s    r#   _checkForIntr.   8   s=    c3 
3s}7MN
 
 	

 
r"   c                     	 t          | d         t          t          f          r"t          | d         t          t          f          st          d          d S #  t          d          xY w)Nr      z@argument must be a two-item tuple containing int or float valuesr&   r'   r(   r   r*   s    r#   _checkForTwoIntOrFloatTupler2   @   sx    
#a&3,// 	z#a&3PU,7W7W 	!R  	 	
N
 
 	
s   AA A(c                 ^   	 t          | d         t          t          f          rft          | d         t          t          f          rDt          | d         t          t          f          r"t          | d         t          t          f          st          d          d S #  t          d          xY w)Nr   r0         zAargument must be a four-item tuple containing int or float valuesr1   r*   s    r#   _checkForFourIntOrFloatTupler6   L   s    
3q6C<00	c!fsEl33	 c!fsEl33	 c!fsEl33		 "S  	 	
O
 
 	
s   BB B,c                     dS )zFReturns True if rectOrPoint1 and rectOrPoint2 collide with each other.Nr!   )rectOrPoint1rectOrPoint2s     r#   	_collidesr:   ]   s      r"   c                     g }g }| D ]q}	 t          |           |                    |           (# t          $ r= 	 t          |           n#  t          d          xY w|                    |           Y nw xY w||fS )Nz'argument is not a point or a rect tuple)r2   appendr   r6   )rectsOrPointspointsrectsrectOrPoints       r#   _getRectsAndPointsrA   a   s    FE$ 	& 	&	&'444MM+&&&& 	& 	& 	&Q,[9999Q%&OPPPLL%%%%%	& 6?s&   $/
A6A
	A6
AA65A6c                      e Zd Z	 	 	 	 	 	 	 	 d?dZd Zd Zd Zed             Zej	        d	             Zed
             Z
e
j	        d             Z
e
Zed             Zej	        d             ZeZed             Zej	        d             Zed             Zej	        d             Zed             Zej	        d             Zed             Zej	        d             Zed             Zej	        d             Zed             Zej	        d             Zed             Zej	        d             Zed             Zej	        d             Zed             Zej	        d             Zed              Zej	        d!             Zed"             Zej	        d#             Zed$             Zej	        d%             Zed&             Zej	        d'             Zed(             Zej	        d)             Zed*             Zej	        d+             ZeZed,             Zej	        d-             ZeZed.             Z ed/             Z!ed0             Z"e"j	        d1             Z"d2 Z#d3 Z$d4 Z%d5 Z&d@d6Z'd7 Z(	 d8 Z)d9 Z*	 d: Z+d; Z,d< Z-	 	 	 d= Z.d> Z/dS )ARectr   FNc	                    t          |           t          |           t          |           t          |           t          |          | _        t          |          | _        |t	          |          st          d          || _        |t	          |          st          d          || _        |rRt          |          | _	        t          |          | _
        t          |          | _        t          |          | _        d S t          |          | _	        t          |          | _
        t          |          | _        t          |          | _        d S )NzConChange argument must be None or callable (function, method, etc.)zAonRead argument must be None or callable (function, method, etc.))r,   bool_enableFloat	_readOnlycallabler   onChangeonReadr(   _width_height_left_topr'   )	selfr   r   r   r   enableFloatreadOnlyrI   rJ   s	            r#   __init__zRect.__init__   s3    	E"""F###D!!!C    --h(:(:!U   !hv&6&6!S    		!,,DK ==DLtDJc

DIIIe**DKv;;DLTDJCDIIIr"   c           
      `    | j         j        d| j        d| j        d| j        d| j        d
S )zLReturn a string of the constructor function call to create this Rect object.z(left=z, top=z, width=z	, height=))r)   r   rM   rN   rK   rL   rO   s    r#   __repr__zRect.__repr__   s@     N###JJJIIIKKKLLL
 	
r"   c           	      H    d| j         d| j        d| j        d| j        d	S )z3Return a string representation of this Rect object.z(x=z, y=z, w=z, h=rT   )rM   rN   rK   rL   rU   s    r#   __str__zRect.__str__   s4      JJJIIIKKKLLL	
 	
r"   c           	          | j         L|                      t          ||||          t          | j        | j        | j        | j                             d S d S )N)rI   r   rM   rN   rK   rL   )rO   oldLeftoldTopoldWidth	oldHeights        r#   callOnChangezRect.callOnChange   s^     =$MMGVXy99DJ	4;EE     %$r"   c                     | j         S )ag  
        A Boolean attribute that determines if this rectangle uses floating point
        numbers for its position and size. False, by default.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.enableFloat
        False
        >>> r.enableFloat = True
        >>> r.top = 3.14
        >>> r
        Rect(left=0.0, top=3.14, width=10.0, height=20.0)
        )rF   rU   s    r#   rP   zRect.enableFloat   s       r"   c                    t          |t                    st          d          || _        | j        rft	          | j                  | _        t	          | j                  | _        t	          | j                  | _        t	          | j                  | _        d S t          | j                  | _        t          | j                  | _        t          | j                  | _        t          | j                  | _        d S )Nz'enableFloat must be set to a bool value)
r&   rE   r   rF   r(   rM   rN   rK   rL   r'   )rO   values     r#   rP   zRect.enableFloat	  s    %&& 	M!"KLLL! 		-tz**DJdi((DI,,DK ..DLLLTZDJDIDIdk**DKt|,,DLLLr"   c                 R    | j         |                      t                     | j        S )z
        The x coordinate for the left edge of the rectangle. `x` is an alias for `left`.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.left
        0
        >>> r.left = 50
        >>> r
        Rect(left=50, top=0, width=10, height=20)
        )rJ   LEFTrM   rU   s    r#   r   z	Rect.left  s&     ;"KKzr"   c                    | j         rt          d          t          |           || j        k    rS| j        }| j        r|| _        nt          |          | _        |                     || j        | j        | j	                   d S d S NRect object is read-only)
rG   r   r,   rM   rF   r'   r^   rN   rK   rL   )rO   newLeftoriginalLefts      r#   r   z	Rect.left+  s    > 	>!"<===G$$$tz!!:L  *$

 \\
lDIt{DLQQQQQ "!r"   c                 R    | j         |                      t                     | j        S )z
        The y coordinate for the top edge of the rectangle. `y` is an alias for `top`.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.top
        0
        >>> r.top = 50
        >>> r
        Rect(left=0, top=50, width=10, height=20)
        )rJ   TOPrN   rU   s    r#   r   zRect.top>  s&     ;"KKyr"   c                    | j         rt          d          t          |           || j        k    rS| j        }| j        r|| _        nt          |          | _        |                     | j        || j        | j	                   d S d S re   )
rG   r   r,   rN   rF   r'   r^   rM   rK   rL   )rO   newToporiginalTops      r#   r   zRect.topN  s    > 	>!"<===F###TY)K  ("		KK	dj+t{DLQQQQQ r"   c                 b    | j         |                      t                     | j        | j        z   S )z
        The x coordinate for the right edge of the rectangle.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.right
        10
        >>> r.right = 50
        >>> r
        Rect(left=40, top=0, width=10, height=20)
        )rJ   RIGHTrM   rK   rU   s    r#   r   z
Rect.right_  s-     ;"KKzDK''r"   c                 <   | j         rt          d          t          |           || j        | j        z   k    rc| j        }| j        r|| j        z
  | _        nt          |          | j        z
  | _        |                     || j        | j        | j	                   d S d S re   )
rG   r   r,   rM   rK   rF   r'   r^   rN   rL   )rO   newRightrh   s      r#   r   z
Rect.righto  s    > 	>!"<===H%%%
T[000:L  9%3

 ]]T[8
lDIt{DLQQQQQ 10r"   c                 b    | j         |                      t                     | j        | j        z   S )zThe y coordinate for the bottom edge of the rectangle.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.bottom
        20
        >>> r.bottom = 30
        >>> r
        Rect(left=0, top=10, width=10, height=20)
        )rJ   BOTTOMrN   rL   rU   s    r#   r   zRect.bottom  s-     ;"KKy4<''r"   c                 <   | j         rt          d          t          |           || j        | j        z   k    rc| j        }| j        r|| j        z
  | _        nt          |          | j        z
  | _        |                     | j        || j	        | j                   d S d S re   )
rG   r   r,   rN   rL   rF   r'   r^   rM   rK   )rO   	newBottomrm   s      r#   r   zRect.bottom  s    > 	>!"<===I&&&T\111)K  :%4			NNT\9	dj+t{DLQQQQQ 21r"   c                 z    | j         |                      t                     t          | j        | j                  S )a  
        The x and y coordinates for the top right corner of the rectangle, as a tuple.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.topleft
        (0, 0)
        >>> r.topleft = (30, 30)
        >>> r
        Rect(left=30, top=30, width=10, height=20)
        Nxy)rJ   TOPLEFTr   rM   rN   rU   s    r#   r   zRect.topleft  s5     ;"KK   tzTY////r"   c                 f   | j         rt          d          t          |           |\  }}|| j        k    s|| j        k    rp| j        }| j        }| j        r|| _        || _        n(t          |          | _        t          |          | _        |                     ||| j        | j	                   d S d S re   )
rG   r   r2   rM   rN   rF   r'   r^   rK   rL   )rO   ra   rg   rl   rh   rm   s         r#   r   zRect.topleft  s    > 	>!"<===#E***tz!!di:L)K  ($
"		 \\
KK	lKdlSSSSS  r"   c                     | j         |                      t                     t          | j        | j        | j        z             S )a  
        The x and y coordinates for the bottom right corner of the rectangle, as a tuple.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.bottomleft
        (0, 20)
        >>> r.bottomleft = (30, 30)
        >>> r
        Rect(left=30, top=10, width=10, height=20)
        Nrw   )rJ   
BOTTOMLEFTr   rM   rN   rL   rU   s    r#   r	   zRect.bottomleft  s<     ;"KK
###tzTY%=>>>>r"   c                    | j         rt          d          t          |           |\  }}|| j        k    s|| j        | j        z   k    r| j        }| j        }| j        r|| _        || j        z
  | _        n0t          |          | _        t          |          | j        z
  | _        |                     ||| j	        | j                   d S d S re   )
rG   r   r2   rM   rN   rL   rF   r'   r^   rK   )rO   ra   rg   ru   rh   rm   s         r#   r	   zRect.bottomleft  s    > 	>!"<===#E***"tz!!T\111:L)K  :$
%4		 \\
	NNT\9	lKdlSSSSS 21r"   c                     | j         |                      t                     t          | j        | j        z   | j                  S )a  
        The x and y coordinates for the top right corner of the rectangle, as a tuple.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.topright
        (10, 0)
        >>> r.topright = (30, 30)
        >>> r
        Rect(left=20, top=30, width=10, height=20)
        Nrw   )rJ   TOPRIGHTr   rM   rK   rN   rU   s    r#   r   zRect.topright  s<     ;"KK!!!tzDK/49====r"   c                    | j         rt          d          t          |           |\  }}|| j        | j        z   k    s|| j        k    r| j        }| j        }| j        r|| j        z
  | _        || _        n0t          |          | j        z
  | _        t          |          | _        |                     ||| j        | j	                   d S d S re   )
rG   r   r2   rM   rK   rN   rF   r'   r^   rL   )rO   ra   rq   rl   rh   rm   s         r#   r   zRect.topright  s    > 	>!"<===#E*** &
T[000di:L)K  (%3
"		 ]]T[8
KK	lKdlSSSSS  r"   c                     | j         |                      t                     t          | j        | j        z   | j        | j        z             S )a  
        The x and y coordinates for the bottom right corner of the rectangle, as a tuple.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.bottomright
        (10, 20)
        >>> r.bottomright = (30, 30)
        >>> r
        Rect(left=20, top=10, width=10, height=20)
        Nrw   )rJ   BOTTOMRIGHTr   rM   rK   rN   rL   rU   s    r#   r
   zRect.bottomright  sC     ;"KK$$$tzDK/49t|3KLLLLr"   c                    | j         rt          d          t          |           |\  }}|| j        | j        z   k    s|| j        | j        z   k    r| j        }| j        }| j        r|| j        z
  | _        || j        z
  | _        n8t          |          | j        z
  | _        t          |          | j        z
  | _        | 	                    ||| j        | j                   d S d S re   )
rG   r   r2   rN   rL   rM   rK   rF   r'   r^   )rO   ra   rq   ru   rh   rm   s         r#   r
   zRect.bottomright  s    > 	>!"<===#E***#)T\111
T[000:L)K  :%3
%4		 ]]T[8
	NNT\9	lKdlSSSSS 10r"   c                     | j         |                      t                     | j        r&t          | j        | j        dz  z   | j                  S t          | j        | j        dz  z   | j                  S )a  
        The x and y coordinates for the midpoint of the top edge of the rectangle, as a tuple.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.midtop
        (5, 0)
        >>> r.midtop = (40, 50)
        >>> r
        Rect(left=35, top=50, width=10, height=20)
        N       @rw   r4   )rJ   MIDTOPrF   r   rM   rK   rN   rU   s    r#   r   zRect.midtop4  sp     ;"KK 	I4:s):;tyIIII4:)9:diHHHHr"   c                 4   | j         rt          d          t          |           |\  }}| j        }| j        }| j        r`|| j        | j        dz  z   k    s|| j        k    r=|| j        dz  z
  | _        || _        |                     ||| j        | j                   d S d S || j        | j        dz  z   k    s|| j        k    rWt          |          | j        dz  z
  | _        t          |          | _        |                     ||| j        | j                   d S d S Nrf   r   r4   )
rG   r   r2   rM   rN   rF   rK   r^   rL   r'   )rO   ra   	newMidToprl   rh   rm   s         r#   r   zRect.midtopG  s3   > 	>!"<===#E***!	6zi 	XTZ$+*;;;;$)##&$+*;<
"	!!,T[$,WWWWW	 $# TZ$+*::::$)## ^^t{a/?@
KK	!!,T[$,WWWWW	 $#r"   c                 
   | j         |                      t                     | j        r.t          | j        | j        dz  z   | j        | j        z             S t          | j        | j        dz  z   | j        | j        z             S )a  
        The x and y coordinates for the midpoint of the bottom edge of the rectangle, as a tuple.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.midbottom
        (5, 20)
        >>> r.midbottom = (40, 50)
        >>> r
        Rect(left=35, top=30, width=10, height=20)
        Nr   rw   r4   )rJ   	MIDBOTTOMrF   r   rM   rK   rN   rL   rU   s    r#   r   zRect.midbottom`  s~     ;"KK	""" 	X4:s):;ty4<?WXXXX4:)9:di$,>VWWWWr"   c                 t   | j         rt          d          t          |           |\  }}| j        }| j        }| j        rp|| j        | j        dz  z   k    s|| j        | j        z   k    rE|| j        dz  z
  | _        || j        z
  | _        |                     ||| j        | j                   d S d S || j        | j        dz  z   k    s|| j        | j        z   k    r_t          |          | j        dz  z
  | _        t          |          | j        z
  | _        |                     ||| j        | j                   d S d S r   
rG   r   r2   rM   rN   rF   rK   rL   r^   r'   )rO   ra   newMidBottomru   rh   rm   s         r#   r   zRect.midbottoms  sQ   > 	>!"<===#E***"'izi 	X
T[3-> >>>TY555)T[3->?
%4	!!,T[$,WWWWW	 65 
T[A-= ===TY555 ..$+2BC
	NNT\9	!!,T[$,WWWWW	 65r"   c                     | j         |                      t                     | j        r&t          | j        | j        | j        dz  z             S t          | j        | j        | j        dz  z             S )a  
        The x and y coordinates for the midpoint of the left edge of the rectangle, as a tuple.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.midleft
        (0, 10)
        >>> r.midleft = (40, 50)
        >>> r
        Rect(left=40, top=40, width=10, height=20)
        Nr   rw   r4   )rJ   MIDLEFTrF   r   rM   rN   rL   rU   s    r#   r   zRect.midleft  sp     ;"KK    	J4:dlS6H)IJJJJ4:dla6G)HIIIIr"   c                 4   | j         rt          d          t          |           |\  }}| j        }| j        }| j        r`|| j        k    s|| j        | j        dz  z   k    r=|| _        || j        dz  z
  | _        |                     ||| j        | j                   d S d S || j        k    s|| j        | j        dz  z   k    rWt          |          | _        t          |          | j        dz  z
  | _        |                     ||| j        | j                   d S d S r   )
rG   r   r2   rM   rN   rF   rL   r^   rK   r'   )rO   ra   rg   
newMidLeftrh   rm   s         r#   r   zRect.midleft  s3   > 	>!"<===#E***#zi 	X4:%%di4<#+=>>>$
&$,*<=	!!,T[$,WWWWW	 ?> 4:%%di4<1+<=== \\

OOt|q/@A	!!,T[$,WWWWW	 >=r"   c                 
   | j         |                      t                     | j        r.t          | j        | j        z   | j        | j        dz  z             S t          | j        | j        z   | j        | j        dz  z             S )a  
        The x and y coordinates for the midpoint of the right edge of the rectangle, as a tuple.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.midright
        (10, 10)
        >>> r.midright = (40, 50)
        >>> r
        Rect(left=30, top=40, width=10, height=20)
        Nr   rw   r4   )rJ   MIDRIGHTrF   r   rM   rK   rN   rL   rU   s    r#   r   zRect.midright  s     ;"KK!!! 	X4:3tyDLSVDV7WXXXX4:3tyDLTUDU7VWWWWr"   c                 t   | j         rt          d          t          |           |\  }}| j        }| j        }| j        rp|| j        | j        z   k    s|| j        | j        dz  z   k    rE|| j        z
  | _        || j        dz  z
  | _        |                     ||| j        | j                   d S d S || j        | j        z   k    s|| j        | j        dz  z   k    r_t          |          | j        z
  | _        t          |          | j        dz  z
  | _        |                     ||| j        | j                   d S d S r   r   )rO   ra   rq   newMidRightrh   rm   s         r#   r   zRect.midright  sQ   > 	>!"<===#E*** %+zi 	XDJ444ty4<#+====%3
'4<#+=>	!!,T[$,WWWWW	 >= DJ444ty4<1+<<<< ]]T[8
,,0AB	!!,T[$,WWWWW	 =<r"   c                    | j         |                      t                     | j        r1t          | j        | j        dz  z   | j        | j        dz  z             S t          | j        | j        dz  z   | j        | j        dz  z             S )a   
        The x and y coordinates for the center of the rectangle, as a tuple.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.center
        (5, 10)
        >>> r.center = (40, 50)
        >>> r
        Rect(left=35, top=40, width=10, height=20)
        Nr   rw   r4   )rJ   CENTERrF   r   rM   rK   rN   rL   rU   s    r#   r   zRect.center  s     ;"KK 	*c 12di4<RUCU6V    *q 01TY$,RSBS5T   r"   c                    | j         rt          d          t          |           |\  }}| j        }| j        }| j        rv|| j        | j        dz  z   k    s|| j        | j        dz  z   k    rH|| j        dz  z
  | _        || j        dz  z
  | _        |                     ||| j        | j                   d S d S || j        | j        dz  z   k    s|| j        | j        dz  z   k    rbt          |          | j        dz  z
  | _        t          |          | j        dz  z
  | _        |                     ||| j        | j                   d S d S r   r   )rO   ra   
newCenterx
newCenteryrh   rm   s         r#   r   zRect.center  sc   > 	>!"<===#E***!&
Jzi 	Xdj4;+<<<<di$,*<<<<'4;+<=
&$,*<=	!!,T[$,WWWWW	 =< dj4;!+;;;;di$,!*;;;; __q0@A

OOt|q/@A	!!,T[$,WWWWW	 <;r"   c                     | j         |                      t                     | j        r| j        | j        dz  z   S | j        | j        dz  z   S )z
        The x coordinate for the center of the rectangle, as a tuple.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.centerx
        5
        >>> r.centerx = 50
        >>> r
        Rect(left=45, top=0, width=10, height=20)
        Nr   r4   )rJ   CENTERXrF   rM   rK   rU   s    r#   r   zRect.centerx  sQ     ;"KK    	3:s!233:!122r"   c                    | j         rt          d          t          |           | j        }| j        rS|| j        | j        dz  z   k    r;|| j        dz  z
  | _        |                     || j        | j        | j                   d S d S || j        | j        dz  z   k    rHt          |          | j        dz  z
  | _        |                     || j        | j        | j                   d S d S r   )
rG   r   r,   rM   rF   rK   r^   rN   rL   r'   )rO   r   rh   s      r#   r   zRect.centerx'  s    > 	>!"<===J'''z 	Vdj4;+<<<<'4;+<=
!!,	4;UUUUU =< dj4;!+;;;; __q0@A
!!,	4;UUUUU <;r"   c                     | j         |                      t                     | j        r| j        | j        dz  z   S | j        | j        dz  z   S )z
        The y coordinate for the center of the rectangle, as a tuple.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.centery
        10
        >>> r.centery = 50
        >>> r
        Rect(left=0, top=40, width=10, height=20)
        Nr   r4   )rJ   CENTERYrF   rN   rL   rU   s    r#   r   zRect.centery<  sQ     ;"KK    	39s 2339 122r"   c                    | j         rt          d          t          |           | j        }| j        rS|| j        | j        dz  z   k    r;|| j        dz  z
  | _        |                     | j        || j        | j                   d S d S || j        | j        dz  z   k    rHt          |          | j        dz  z
  | _        |                     | j        || j        | j                   d S d S r   )
rG   r   r,   rN   rF   rL   r^   rM   rK   r'   )rO   r   rm   s      r#   r   zRect.centeryO  s    > 	>!"<===J'''i 	Vdi$,*<<<<&$,*<=	!!$*k4;UUUUU =< di$,!*;;;;
OOt|q/@A	!!$*k4;UUUUU <;r"   c                 z    | j         |                      t                     t          | j        | j                  S )z
        The width and height of the rectangle, as a tuple.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.size
        (10, 20)
        >>> r.size = (40, 50)
        >>> r
        Rect(left=0, top=0, width=40, height=50)
        N)r   r   )rJ   SIZEr   rK   rL   rU   s    r#   r   z	Rect.sized  s5     ;"KK$+dl;;;;r"   c                 f   | j         rt          d          t          |           |\  }}|| j        k    s|| j        k    rp| j        }| j        }| j        r|| _        || _        n(t          |          | _        t          |          | _        |                     | j        | j	        ||           d S d S re   )
rG   r   r2   rK   rL   rF   r'   r^   rM   rN   )rO   ra   newWidth	newHeightoriginalWidthoriginalHeights         r#   r   z	Rect.sizet  s    > 	>!"<===#E***#)t{""i4<&?&? KM!\N  .&(!(mm"9~~dj$)]NSSSSS '@&?r"   c                 R    | j         |                      t                     | j        S )z
        The width of the rectangle. `w` is an alias for `width`.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.width
        10
        >>> r.width = 50
        >>> r
        Rect(left=0, top=0, width=50, height=20)
        )rJ   WIDTHrK   rU   s    r#   r   z
Rect.width  s&     ;"KK{r"   c                    | j         rt          d          t          |           || j        k    rS| j        }| j        r|| _        nt          |          | _        |                     | j        | j        || j	                   d S d S re   )
rG   r   r,   rK   rF   r'   r^   rM   rN   rL   )rO   r   r   s      r#   r   z
Rect.width  s    > 	>!"<===H%%%## KM  ,&!(mmdj$)]DLQQQQQ $#r"   c                 R    | j         |                      t                     | j        S )z
        The height of the rectangle. `h` is an alias for `height`

        >>> r = Rect(0, 0, 10, 20)
        >>> r.height
        20
        >>> r.height = 50
        >>> r
        Rect(left=0, top=0, width=10, height=50)
        )rJ   HEIGHTrL   rU   s    r#   r   zRect.height  s&     ;"KK|r"   c                    | j         rt          d          t          |           || j        k    rS| j        }| j        r|| _        nt          |          | _        |                     | j        | j        | j	        |           d S d S re   )
rG   r   r,   rL   rF   r'   r^   rM   rN   rK   )rO   r   r   s      r#   r   zRect.height  s    > 	>!"<===I&&&%%!\N  .("9~~dj$)T[.QQQQQ &%r"   c                 b    | j         |                      t                     | j        | j        z  S )zThe area of the `Rect`, which is simply the width times the height.
        This is a read-only attribute.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.area
        200
        rJ   AREArK   rL   rU   s    r#   r   z	Rect.area  s-     ;"KK{T\))r"   c                 h    | j         |                      t                     | j        | j        z   dz  S )zThe perimeter of the `Rect`, which is simply the (width + height) * 2.
        This is a read-only attribute.

        >>> r = Rect(0, 0, 10, 20)
        >>> r.area
        200
        Nr4   r   rU   s    r#   r   zRect.perimeter  s2     ;"KKdl*a//r"   c                     | j         |                      t                     t          | j        | j        | j        | j                  S )zA tuple of four integers: (left, top, width, height).

        >>> r = Rect(0, 0, 10, 20)
        >>> r.box
        (0, 0, 10, 20)
        >>> r.box = (5, 15, 100, 200)
        >>> r.box
        (5, 15, 100, 200)N)r   r   r   r   )rJ   BOXr   rM   rN   rK   rL   rU   s    r#   r   zRect.box  sF     ;"KK$+dl
 
 
 	
r"   c                 r   | j         rt          d          t          |           |\  }}}}|| j        k    s!|| j        k    s|| j        k    s|| j        k    r| j        }| j        }| j        }| j        }	| j        rQt          |          | _        t          |          | _        t          |          | _        t          |          | _        nPt          |          | _        t          |          | _        t          |          | _        t          |          | _        | 
                    ||||	           d S d S re   )rG   r   r6   rM   rN   rK   rL   rF   r(   r'   r^   )
rO   ra   rg   rl   r   r   rh   rm   r   r   s
             r#   r   zRect.box  s&   > 	>!"<===$U+++/4,9
""$)##DK''T\)):L)K KM!\N  	."7^^
!&MM	#Hoo$Y// \\
KK	!(mm"9~~lKWWWWW! *)r"   c                    |t           k    r| j        S |t          k    r| j        S |t          k    r| j        S |t          k    r| j        S |t          k    r| j	        S |t          k    r| j        S |t          k    r| j        S |t          k    r| j        S |t           k    r| j        S |t$          k    r| j        S |t(          k    r| j        S |t,          k    r| j        S |t0          k    r| j        S |t4          k    r| j        S |t8          k    r| j        S |t<          k    r| j        S |t@          k    r| j!        S |tD          k    r| j#        S |tH          k    r| j%        S |tL          k    r| j'        S tQ          d|z            )N"'%s' is not a valid attribute name))rj   r   rs   r   rc   r   ro   r   rz   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   )rO   rectAttrNames     r#   getzRect.get  s   38OV##;T!!9U"":W$$<X%%= Z''?"[((##V##;Y&&>!W$$<X%%= V##;W$$<W$$<U"":V##;T!!9T!!9S  8O!"F,"WXXXr"   c                 R   |t           k    r	|| _        d S |t          k    r	|| _        d S |t          k    r	|| _        d S |t          k    r	|| _        d S |t          k    r	|| _	        d S |t          k    r	|| _        d S |t          k    r	|| _        d S |t          k    r	|| _        d S |t           k    r	|| _        d S |t$          k    r	|| _        d S |t(          k    r	|| _        d S |t,          k    r	|| _        d S |t0          k    r	|| _        d S |t4          k    r	|| _        d S |t8          k    r	|| _        d S |t<          k    r	|| _        d S |t@          k    r	|| _!        d S |tD          k    r	|| _#        d S |tH          k    rtK          d          |tL          k    r	|| _'        d S tK          d|z            )Nzarea is a read-only attributer   )(rj   r   rs   r   rc   r   ro   r   rz   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   )rO   r   ra   s      r#   setzRect.setE  s   3DHHHV##DKKKT!!DIIIU""DJJJW$$ DLLLX%%!DMMMZ''#DOOO[(($DV##DKKKY&&"DNNNW$$ DLLLX%%!DMMMV##DKKKW$$ DLLLW$$ DLLLU""DJJJV##DKKKT!!DIIIT!!!"ABBBS  DHHH!"F,"WXXXr"   c                 4   | j         rt          d          t          |           t          |           | j        r"| xj        |z  c_        | xj        |z  c_        dS | xj        t          |          z  c_        | xj        t          |          z  c_        dS )a  Moves this Rect object by the given offsets. The xOffset and yOffset
        arguments can be any integer value, positive or negative.
        >>> r = Rect(0, 0, 100, 100)
        >>> r.move(10, 20)
        >>> r
        Rect(left=10, top=20, width=100, height=100)
        rf   N)rG   r   r,   rF   rM   rN   r'   )rO   xOffsetyOffsets      r#   movez	Rect.mover  s     > 	>!"<===G$$$G$$$ 	&JJ'!JJII IIIIJJ#g,,&JJIIW%IIIIr"   c                 f    t          | j        | j        | j        | j        | j        | j                  S )a  Return a copied `Rect` object with the same position and size as this
        `Rect` object.

        >>> r1 = Rect(0, 0, 100, 150)
        >>> r2 = r1.copy()
        >>> r1 == r2
        True
        >>> r2
        Rect(left=0, top=0, width=100, height=150)
        )rC   rM   rN   rK   rL   rF   rG   rU   s    r#   copyz	Rect.copy  s5     JIKLN
 
 	
r"   c                     | j         rt          d          | j        }| xj        |z  c_        | xj        |z  c_        || _        dS )a.  Increases the size of this Rect object by the given offsets. The
        rectangle's center doesn't move. Negative values will shrink the
        rectangle.

        >>> r = Rect(0, 0, 100, 150)
        >>> r.inflate(20, 40)
        >>> r
        Rect(left=-10, top=-20, width=120, height=190)
        rf   N)rG   r   r   r   r   )rO   widthChangeheightChangeoriginalCenters       r#   inflatezRect.inflate  sO     > 	>!"<===

k!

|#$r"   c                 J    | j         rt          d          |j        | _        dS )a  Centers this Rect object at the center of otherRect.

        >>> r1 =Rect(0, 0, 100, 100)
        >>> r2 = Rect(-20, -90, 50, 50)
        >>> r2.clamp(r1)
        >>> r2
        Rect(left=25, top=25, width=50, height=50)
        >>> r1.center == r2.center
        True
        rf   N)rG   r   r   )rO   	otherRects     r#   clampz
Rect.clamp  s+     > 	>!"<===&r"   c                    t          | j        |j                  }t          | j        |j                  }t          | j        |j                  }t          | j        |j                  }|| _        || _        ||z
  | _        ||z
  | _        dS )zAdjusts the width and height to also cover the area of `otherRect`.

        >>> r1 = Rect(0, 0, 100, 100)
        >>> r2 = Rect(-10, -10, 100, 100)
        >>> r1.union(r2)
        >>> r1
        Rect(left=-10, top=-10, width=110, height=110)
        N)minrM   rN   maxr   r   rK   rL   )rO   r   	unionLeftunionTop
unionRightunionBottoms         r#   unionz
Rect.union  s{     
IO44	ty).11Y_55
$+y'788
	 9,"X-r"   c                 Z   t          |          }|                    |            t          d |D                       }t          d |D                       }t          d |D                       }t          d |D                       }|| _        || _        ||z
  | _        ||z
  | _        dS )aL  Adjusts the width and height to also cover all the `Rect` objects in
        the `otherRects` sequence.

        >>> r = Rect(0, 0, 100, 100)
        >>> r1 = Rect(0, 0, 150, 100)
        >>> r2 = Rect(-10, -10, 100, 100)
        >>> r.unionAll([r1, r2])
        >>> r
        Rect(left=-10, top=-10, width=160, height=110)
        c                     g | ]	}|j         
S r!   )rM   .0rs     r#   
<listcomp>z!Rect.unionAll.<locals>.<listcomp>  s    555Q555r"   c                     g | ]	}|j         
S r!   )rN   r   s     r#   r   z!Rect.unionAll.<locals>.<listcomp>  s    3331333r"   c                     g | ]	}|j         
S r!   )r   r   s     r#   r   z!Rect.unionAll.<locals>.<listcomp>  s    666a!'666r"   c                     g | ]	}|j         
S r!   )r   r   s     r#   r   z!Rect.unionAll.<locals>.<listcomp>  s    88818888r"   N)listr<   r   r   rM   rN   rK   rL   )rO   
otherRectsr   r   r   r   s         r#   unionAllzRect.unionAll  s     *%%
$55*55566	33
3334466:66677
88Z88899
	 9,"X-r"   c                     | j         rt          d          | j        dk     r"| j         | _        | xj        | j        z  c_        | j        dk     r$| j         | _        | xj        | j        z  c_        dS dS )a  Rect objects with a negative width or height cover a region where the
        right/bottom edge is to the left/above of the left/top edge, respectively.
        The `normalize()` method sets the `width` and `height` to positive if they
        were negative.

        The Rect stays in the same place, though with the `top` and `left`
        attributes representing the true top and left side.

        >>> r = Rect(0, 0, -10, -20)
        >>> r.normalize()
        >>> r
        Rect(left=-10, top=-20, width=10, height=20)
        rf   r   N)rG   r   rK   rM   rL   rN   rU   s    r#   	normalizezRect.normalize  s{     > 	>!"<===;??;,DKJJ$+%JJ<! L=DLII%IIII r"   c                    t          |t                    r$|j        | v o|j        | v o|j        | v o|j        | v S 	 t          |           n!#  t          d|j        j	        z            xY wt          |          dk    rXt          |           |\  }}| j        |cxk     o| j        | j        z   k     nc o!| j        |cxk     o| j        | j        z   k     nc S t          |          dk    r:t          |           |\  }}}}||f| v o||z   |f| v o|||z   f| v o||z   ||z   f| v S t          d|j        j	        z            )Npin <Rect> requires an (x, y) tuple, a (left, top, width, height) tuple, or a Rect object as left operand, not %sr4      )r&   rC   r   r   r	   r
   lenr   r)   r   r2   rM   rK   rN   rL   r6   rO   ra   rx   ry   r   r   r   r   s           r#   __contains__zRect.__contains__  s    eT"" 	% .Nd*.$,. %-		JJJJ	! C?+-  
 u::??'...DAq
Q9999dk!99999 =I<<<<DI$<<<<<
 ZZ1__(///',$D#ufst# 9E\3'4/93<(D09 E\3<0D8	 " C?+-     A A)c                 b   t          |t                    r$|j        | v p|j        | v p|j        | v p|j        | v S 	 t          |           n!#  t          d|j        j	        z            xY wt          |          dk    rXt          |           |\  }}| j        |cxk     o| j        | j        z   k     nc o!| j        |cxk     o| j        | j        z   k     nc S t          |          dk    r+|\  }}}}||f| v p||z   |f| v p|||z   f| v p||z   ||z   f| v S t          d|j        j	        z            )a`  Returns `True` if value collides with this `Rect` object, where value can
        be an (x, y) tuple, a (left, top, width, height) box tuple, or another `Rect`
        object. If value represents a rectangular area, any part of that area
        can collide with this `Rect` object to make `collide()` return `True`.
        Otherwise, returns `False`.r   r4   r   )r&   rC   r   r   r	   r
   r   r   r)   r   r2   rM   rK   rN   rL   r   s           r#   collidezRect.collideD  s    eT"" 	% ->T)-#t+- $,		JJJJ	! C?+-  
 u::??'...DAq
Q9999dk!99999 =I<<<<DI$<<<<<
 ZZ1__',$D#ufst# 85L#&$.8#,'4/8 5L#,/47	 " C?+-  r   c                 j    t          |t                    r|j        | j        k    S t          d          Nz9Rect objects can only be compared with other Rect objectsr&   rC   r   r   rO   others     r#   __eq__zRect.__eq__  8    eT"" 	9((!K  r"   c                 j    t          |t                    r|j        | j        k    S t          d          r   r   r   s     r#   __ne__zRect.__ne__  r   r"   )r   r   r   r   FFNN)r   r   )0r   r   r   rR   rV   rX   r^   propertyrP   setterr   rx   r   ry   r   r   r   r	   r   r
   r   r   r   r   r   r   r   r   r   wr   hr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   r"   r#   rC   rC      s]        (! (! (! (!V
 
 

 
 
   ! ! X! - - -"   X 
[R R [R 	A   X 	ZR R ZR 	A ( ( X( \R R \R  ( ( X( ]R R ]R  0 0 X0 ^T T ^T( ? ? X? T T T( > > X> _T T _T( M M XM T T T( I I XI$ ]X X ]X0 X X XX$ X X X0 J J XJ$ ^X X ^X0 X X XX$ _X X _X0   X, ]X X ]X0 3 3 X3$ ^V V ^V( 3 3 X3$ ^V V ^V( < < X< 
[T T [T$   X \R R \R 	A   X ]R R ]R 	A 
* 
* X
* 
0 
0 X
0 
 
 X
 	ZX X ZX8+Y +Y +YZ+Y +Y +YZ& & &(
 
 
(% % % %$' ' ' 
. . .,. . .6
& & &2+ + +Z1 1 1f*
      r"   rC   __main__))doctestcollections__version__rj   rs   rc   ro   rz   r   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   	PERIMETER
namedtupler   r   r   	Exceptionr   r,   r.   r2   r6   r:   rA   objectrC   r   printtestmodr!   r"   r#   <module>r     s         	

	
		

		kU$;<<w..{fn55	 	 	 	 	i 	 	 	
 
 

 
 
	
 	
 	

 
 
"Q Q Q   <DA A A A A6 A A AH( z	E/'/

 r"   