o
    &h                     @   s   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ddZeddZeddZG dd deZd d! Zd"d# Zd$d% Z d&d' Z!d(d) Z"d*d+ Z#	 	 G d,d- d-e$Z%e&d.kr|e'e (  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                   @   s   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   r   f/Users/merlin/projects/employee-monitoring-system/venv/lib/python3.10/site-packages/pyrect/__init__.pyr   '   s    r   c                 C   s"   t | ttfstd| jj 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   argr   r   r    _checkForIntOrFloat0   s
   
r(   c                 C   s   t | tstd| jj dS )z>Raises an exception if arg is not an int. Always returns None.r!   N)r"   r#   r   r%   r   r&   r   r   r    _checkForInt8   s
   

r)   c                 C   sB   zt | d ttfrt | d ttfstdW d S    td)Nr      z@argument must be a two-item tuple containing int or float valuesr"   r#   r$   r   r&   r   r   r    _checkForTwoIntOrFloatTuple@   s   $r,   c                 C   sf   z+t | d ttfr%t | d ttfr%t | d ttfr%t | d ttfs)tdW d S    td)Nr   r*         zAargument must be a four-item tuple containing int or float valuesr+   r&   r   r   r    _checkForFourIntOrFloatTupleL   s"   	r/   c                 C   s   dS )zFReturns True if rectOrPoint1 and rectOrPoint2 collide with each other.Nr   )ZrectOrPoint1ZrectOrPoint2r   r   r    	_collides]   s    r0   c              
   C   sh   g }g }| D ])}zt | || W q ty/   zt| W n   td|| Y qw ||fS )Nz'argument is not a point or a rect tuple)r,   appendr   r/   )ZrectsOrPointsZpointsZrectsZrectOrPointr   r   r    _getRectsAndPointsa   s   r2   c                   @   s  e Zd Z								dfddZdd Zdd	 Zd
d Zedd Zej	dd Zedd Z
e
j	dd Z
e
Zedd Zej	dd ZeZedd Zej	dd Zedd Zej	dd Zedd Zej	dd Zedd Zej	d d Zed!d" Zej	d#d" Zed$d% Zej	d&d% Zed'd( Zej	d)d( Zed*d+ Zej	d,d+ Zed-d. Zej	d/d. Zed0d1 Zej	d2d1 Zed3d4 Zej	d5d4 Zed6d7 Zej	d8d7 Zed9d: Zej	d;d: Zed<d= Zej	d>d= Zed?d@ Zej	dAd@ ZeZedBdC Zej	dDdC ZeZedEdF Z edGdH Z!edIdJ Z"e"j	dKdJ Z"dLdM Z#dNdO Z$dPdQ Z%dRdS Z&dgdTdUZ'dVdW Z(	 dXdY Z)dZd[ Z*	 d\d] Z+d^d_ Z,d`da Z-	 	 	 dbdc Z.ddde Z/dS )hRectr   FNc	           	      C   s   t | t | t | t | t|| _t|| _|d ur&t|s&td|| _|d ur5t|s5td|| _|rPt|| _	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   enableFloatZreadOnlyr8   r9   r   r   r    __init__   s2   







zRect.__init__c                 C   s   d| j j| j| j| j| jf S )zLReturn a string of the constructor function call to create this Rect object.z(%s(left=%s, top=%s, width=%s, height=%s))r%   r   r<   r=   r:   r;   r>   r   r   r    __repr__   s   zRect.__repr__c                 C   s   d| j | j| j| jf S )z3Return a string representation of this Rect object.z(x=%s, y=%s, w=%s, h=%s))r<   r=   r:   r;   rA   r   r   r    __str__   s   zRect.__str__c                 C   s:   | j d ur|  t||||t| j| j| j| j d S d S )N)r8   r   r<   r=   r:   r;   )r>   ZoldLeftZoldTopZoldWidthZ	oldHeightr   r   r    callOnChange   s   
zRect.callOnChangec                 C   s   | 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)
        )r5   rA   r   r   r    r?      s   zRect.enableFloatc                 C   s   t |ts	td|| _| jr)t| 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"   r4   r   r5   r$   r<   r=   r:   r;   r#   )r>   valuer   r   r    r?   	  s   
c                 C      | j dur
|  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)
        N)r9   LEFTr<   rA   r   r   r    r        

z	Rect.leftc                 C   s\   | j rtdt| || jkr,| j}| jr|| _nt|| _| || j| j| j	 d S d S NRect object is read-only)
r6   r   r(   r<   r5   r#   rD   r=   r:   r;   )r>   newLeftoriginalLeftr   r   r    r   +     

c                 C   rF   )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)
        N)r9   TOPr=   rA   r   r   r    r   >  rH   zRect.topc                 C   s\   | j rtdt| || jkr,| j}| jr|| _nt|| _| | j|| j| j	 d S d S rI   )
r6   r   r(   r=   r5   r#   rD   r<   r:   r;   )r>   newToporiginalTopr   r   r    r   N  s   

c                 C       | j dur
|  t | j| j 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)
        N)r9   RIGHTr<   r:   rA   r   r   r    r   _  s   

z
Rect.rightc                 C   sn   | j rtdt| || j| j kr5| j}| jr || j | _nt|| j | _| || j| j| j	 d S d S rI   )
r6   r   r(   r<   r:   r5   r#   rD   r=   r;   )r>   newRightrL   r   r   r    r   o     c                 C   rQ   )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)
        N)r9   BOTTOMr=   r;   rA   r   r   r    r     s   

zRect.bottomc                 C   sn   | j rtdt| || j| j kr5| j}| jr || j | _nt|| j | _| | j|| j	| j d S d S rI   )
r6   r   r(   r=   r;   r5   r#   rD   r<   r:   )r>   	newBottomrP   r   r   r    r     rT   c                 C   $   | j dur
|  t t| j| jd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)r9   TOPLEFTr   r<   r=   rA   r   r   r    r        

zRect.topleftc                 C   s   | j rtdt| |\}}|| jks|| jkr?| j}| j}| jr)|| _|| _n
t|| _t|| _| ||| j| j	 d S d S rI   )
r6   r   r,   r<   r=   r5   r#   rD   r:   r;   )r>   rE   rK   rO   rL   rP   r   r   r    r     s   



c                 C   s*   | j dur
|  t t| j| j| j d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)
        NrX   )r9   
BOTTOMLEFTr   r<   r=   r;   rA   r   r   r    r        

zRect.bottomleftc                 C   s   | j rtdt| |\}}|| jks|| j| j krH| j}| j}| jr/|| _|| j | _nt|| _t|| j | _| ||| j	| j d S d S rI   )
r6   r   r,   r<   r=   r;   r5   r#   rD   r:   )r>   rE   rK   rV   rL   rP   r   r   r    r     s   

c                 C   s*   | j dur
|  t t| j| j | jd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)
        NrX   )r9   TOPRIGHTr   r<   r:   r=   rA   r   r   r    r     r^   zRect.toprightc                 C   s   | j rtdt| |\}}|| j| j ks|| jkrH| j}| j}| jr/|| j | _|| _nt|| j | _t|| _| ||| j| j	 d S d S rI   )
r6   r   r,   r<   r:   r=   r5   r#   rD   r;   )r>   rE   rS   rO   rL   rP   r   r   r    r     s   

c                 C   s0   | j dur
|  t t| j| j | j| j d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)
        NrX   )r9   BOTTOMRIGHTr   r<   r:   r=   r;   rA   r   r   r    r	     s   

zRect.bottomrightc                 C   s   | j rtdt| |\}}|| j| j ks|| j| j krQ| j}| j}| jr5|| j | _|| j | _nt|| j | _t|| j | _| 	||| j| j d S d S rI   )
r6   r   r,   r=   r;   r<   r:   r5   r#   rD   )r>   rE   rS   rV   rL   rP   r   r   r    r	     s   c                 C   sN   | j dur
|  t | jrt| j| jd  | jdS t| j| jd  | jd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       @rX   r-   )r9   MIDTOPr5   r   r<   r:   r=   rA   r   r   r    r
   4  
   

zRect.midtopc                 C   s   | j rtdt| |\}}| j}| j}| jr@|| j| jd  ks'|| jkr>|| jd  | _|| _| ||| j| j d S d S || j| jd  ksO|| jkrjt	|| jd  | _t	|| _| ||| j| j d S d S NrJ   ra   r-   )
r6   r   r,   r<   r=   r5   r:   rD   r;   r#   )r>   rE   Z	newMidToprO   rL   rP   r   r   r    r
   G  s&   


c                 C   sZ   | j dur
|  t | jrt| j| jd  | j| j dS t| j| jd  | j| j d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)
        Nra   rX   r-   )r9   	MIDBOTTOMr5   r   r<   r:   r=   r;   rA   r   r   r    r   `  
   

  zRect.midbottomc                 C   s   | j rtdt| |\}}| j}| j}| jrF|| j| jd  ks*|| j| j krD|| jd  | _|| j | _| ||| j| j d S d S || j| jd  ksX|| j| j krvt	|| jd  | _t	|| j | _| ||| j| j d S d S rd   
r6   r   r,   r<   r=   r5   r:   r;   rD   r#   )r>   rE   ZnewMidBottomrV   rL   rP   r   r   r    r   s  s&   c                 C   sN   | j dur
|  t | jrt| j| j| jd  dS t| j| j| jd  d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)
        Nra   rX   r-   )r9   MIDLEFTr5   r   r<   r=   r;   rA   r   r   r    r     rc   zRect.midleftc                 C   s   | j rtdt| |\}}| j}| j}| jr@|| jks'|| j| jd  kr>|| _|| jd  | _| ||| j| j d S d S || jksO|| j| jd  krjt	|| _t	|| jd  | _| ||| j| j d S d S rd   )
r6   r   r,   r<   r=   r5   r;   rD   r:   r#   )r>   rE   rK   Z
newMidLeftrL   rP   r   r   r    r     s&   


c                 C   sZ   | j dur
|  t | jrt| j| j | j| jd  dS t| j| j | j| jd  d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)
        Nra   rX   r-   )r9   MIDRIGHTr5   r   r<   r:   r=   r;   rA   r   r   r    r     rf   zRect.midrightc                 C   s   | j rtdt| |\}}| j}| j}| jrF|| j| j ks*|| j| jd  krD|| j | _|| jd  | _| ||| j| j d S d S || j| j ksX|| j| jd  krvt	|| j | _t	|| jd  | _| ||| j| j d S d S rd   rg   )r>   rE   rS   ZnewMidRightrL   rP   r   r   r    r     s&   c                 C   sb   | j dur
|  t | jrt| j| jd  | j| jd  dS t| j| jd  | j| jd  d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)
        Nra   rX   r-   )r9   CENTERr5   r   r<   r:   r=   r;   rA   r   r   r    r     s   

zRect.centerc                 C   s   | j rtdt| |\}}| j}| j}| jrJ|| j| jd  ks,|| j| jd  krH|| jd  | _|| jd  | _| ||| j| j d S d S || j| jd  ks^|| j| jd  kr~t	|| jd  | _t	|| jd  | _| ||| j| j d S d S rd   rg   )r>   rE   
newCenterx
newCenteryrL   rP   r   r   r    r     s&   c                 C   :   | j dur
|  t | jr| j| jd  S | j| jd  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)
        Nra   r-   )r9   CENTERXr5   r<   r:   rA   r   r   r    r     
   

zRect.centerxc                 C   s   | j rtdt| | j}| jr2|| j| jd  kr0|| jd  | _| || j| j| j d S d S || j| jd  krSt	|| jd  | _| || j| j| j d S d S rd   )
r6   r   r(   r<   r5   r:   rD   r=   r;   r#   )r>   rk   rL   r   r   r    r   '     c                 C   rm   )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)
        Nra   r-   )r9   CENTERYr5   r=   r;   rA   r   r   r    r   <  ro   zRect.centeryc                 C   s   | j rtdt| | j}| jr2|| j| jd  kr0|| jd  | _| | j|| j| j d S d S || j| jd  krSt	|| jd  | _| | j|| j| j d S d S rd   )
r6   r   r(   r=   r5   r;   rD   r<   r:   r#   )r>   rl   rP   r   r   r    r   O  rp   c                 C   rW   )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   )r9   SIZEr   r:   r;   rA   r   r   r    r   d  r\   z	Rect.sizec                 C   s   | j rtdt| |\}}|| jks|| jkr?| j}| j}| jr)|| _|| _n
t|| _t|| _| | j| j	|| d S d S rI   )
r6   r   r,   r:   r;   r5   r#   rD   r<   r=   )r>   rE   newWidth	newHeightoriginalWidthoriginalHeightr   r   r    r   t  s   

c                 C   rF   )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)
        N)r9   WIDTHr:   rA   r   r   r    r     rH   z
Rect.widthc                 C   s\   | j rtdt| || jkr,| j}| jr|| _nt|| _| | j| j|| j	 d S d S rI   )
r6   r   r(   r:   r5   r#   rD   r<   r=   r;   )r>   rs   ru   r   r   r    r     rM   c                 C   rF   )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)
        N)r9   HEIGHTr;   rA   r   r   r    r     rH   zRect.heightc                 C   s\   | j rtdt| || jkr,| j}| jr|| _nt|| _| | j| j| j	| d S d S rI   )
r6   r   r(   r;   r5   r#   rD   r<   r=   r:   )r>   rt   rv   r   r   r    r     rM   c                 C   s    | j dur
|  t | j| j 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
        Nr9   AREAr:   r;   rA   r   r   r    r     s   
	
z	Rect.areac                 C   s$   | j dur
|  t | j| j d 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
        Nr-   ry   rA   r   r   r    r     s   
	
zRect.perimeterc                 C   s,   | j dur
|  t t| j| j| j| jd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   )r9   BOXr   r<   r=   r:   r;   rA   r   r   r    r     s
   


zRect.boxc           
      C   s   | j rtdt| |\}}}}|| jks%|| jks%|| jks%|| jkrg| j}| j}| j}| j}	| jrIt|| _t|| _t|| _t|| _nt	|| _t	|| _t	|| _t	|| _| 
||||	 d S d S rI   )r6   r   r/   r<   r=   r:   r;   r5   r$   r#   rD   )
r>   rE   rK   rO   rs   rt   rL   rP   ru   rv   r   r   r    r     s.   










c                 C   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r1| jS |tkr8| jS |tkr?| jS |tkrF| jS |tkrM| jS |tkrT| jS |tkr[| jS |tkrb| jS |tkri| jS |tkrp| jS |t krw| j!S |t"kr~| j#S |t$kr| j%S |t&kr| j'S t(d| )N"'%s' is not a valid attribute name))rN   r   rU   r   rG   r   rR   r   r[   r   r_   r   r]   r   r`   r	   rb   r
   re   r   rh   r   ri   r   rj   r   rn   r   rq   r   rw   r   rx   r   rr   r   rz   r   r{   r   r   )r>   rectAttrNamer   r   r    get  sR   zRect.getc                 C   sr  |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r6|| _d S |tkr?|| _d S |tkrH|| _d S |tkrQ|| _d S |tkrZ|| _d S |tkrc|| _d S |tkrl|| _d S |tkru|| _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rt%d|t&kr|| _'d S t%d| )Nzarea is a read-only attributer|   )(rN   r   rU   r   rG   r   rR   r   r[   r   r_   r   r]   r   r`   r	   rb   r
   re   r   rh   r   ri   r   rj   r   rn   r   rq   r   rw   r   rx   r   rr   r   rz   r   r{   r   )r>   r}   rE   r   r   r    setE  sR   


















zRect.setc                 C   sl   | j rtdt| t| | jr"|  j|7  _|  j|7  _dS |  jt|7  _|  jt|7  _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)
        rJ   N)r6   r   r(   r5   r<   r=   r#   )r>   ZxOffsetZyOffsetr   r   r    mover  s   z	Rect.movec                 C   s   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)
        )r3   r<   r=   r:   r;   r5   r6   rA   r   r   r    copy  s   z	Rect.copyc                 C   s:   | j rtd| j}|  j|7  _|  j|7  _|| _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)
        rJ   N)r6   r   r   r   r   )r>   ZwidthChangeZheightChangeZoriginalCenterr   r   r    inflate  s   

zRect.inflatec                 C   s   | 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
        rJ   N)r6   r   r   )r>   	otherRectr   r   r    clamp  s   z
Rect.clampc                 C   s\   t | j|j}t | j|j}t| j|j}t| j|j}|| _|| _|| | _|| | _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)minr<   r=   maxr   r   r:   r;   )r>   r   	unionLeftunionTop
unionRightunionBottomr   r   r    union  s   
z
Rect.unionc                 C   s~   t |}||  tdd |D }tdd |D }tdd |D }tdd |D }|| _|| _|| | _|| | _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                 S      g | ]}|j qS r   )r<   .0rr   r   r    
<listcomp>      z!Rect.unionAll.<locals>.<listcomp>c                 S   r   r   )r=   r   r   r   r    r     r   c                 S   r   r   )r   r   r   r   r    r     r   c                 S   r   r   )r   r   r   r   r    r     r   N)listr1   r   r   r<   r=   r:   r;   )r>   Z
otherRectsr   r   r   r   r   r   r    unionAll  s   

zRect.unionAllc                 C   s^   | j rtd| jdk r| j | _|  j| j8  _| jdk r-| j | _|  j| j8  _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)
        rJ   r   N)r6   r   r:   r<   r;   r=   rA   r   r   r    	normalize  s   



zRect.normalizec                 C   s&  t |tr|j| v o|j| v o|j| v o|j| v S zt| W n   td|jj	 t|dkr[t
| |\}}| j|  k oG| j| j k n  oZ| j|  k oX| j| j k S   S t|dkrt| |\}}}}||f| v o|| |f| v o||| f| v o|| || f| v S td|jj	 )Npin <Rect> requires an (x, y) tuple, a (left, top, width, height) tuple, or a Rect object as left operand, not %sr-      )r"   r3   r   r   r   r	   lenr   r%   r   r,   r<   r:   r=   r;   r/   r>   rE   rY   rZ   r   r   r   r   r   r   r    __contains__  sN   

"zRect.__contains__c                 C   s  t |tr|j| v p|j| v p|j| v p|j| v S zt| W n   td|jj	 t|dkr[t
| |\}}| j|  k oG| j| j k n  oZ| j|  k oX| j| j k S   S t|dkr|\}}}}||f| v p|| |f| v p||| f| v p|| || f| v S td|jj	 )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   r-   r   )r"   r3   r   r   r   r	   r   r   r%   r   r,   r<   r:   r=   r;   r   r   r   r    collideD  sL   


"zRect.collidec                 C   s   t |tr|j| jkS tdNz9Rect objects can only be compared with other Rect objectsr"   r3   r   r   r>   otherr   r   r    __eq__  
   
zRect.__eq__c                 C   s   t |tr|j| jkS tdr   r   r   r   r   r    __ne__  r   zRect.__ne__)r   r   r   r   FFNN)r   r   )0r   r   r   r@   rB   rC   rD   propertyr?   setterr   rY   r   rZ   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   r    r3      s    
+
		









































--
-3r3   __main__))doctestcollections__version__rN   rU   rG   rR   r[   r_   r]   r`   rb   ri   rh   re   rj   rn   rq   rw   rx   rr   r{   rz   Z	PERIMETER
namedtupler   r   r   	Exceptionr   r(   r)   r,   r/   r0   r2   objectr3   r   printtestmodr   r   r   r    <module>   sd    	"          