
    et#                         d Z ddlmZ ddlmZ  G d d          Z G d de          Z G d	 d
e          Z G d d          ZdS )zY
Bounding regions and bounding boxes.

File originally part of the Topographica project.
    )get_occupied_slots   )datetime_typesc                   X    e Zd ZdZdZdgZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd ZdS )BoundingRegionz{
    Abstract bounding region class, for any portion of a 2D plane.

    Only subclasses can be instantiated directly.
    T_aarectc                     t           NNotImplementedError)selfxys      =lib/python3.11/site-packages/holoviews/core/boundingregion.pycontainszBoundingRegion.contains       !!    c                 8    |\  }}|                      ||          S r
   )r   )r   pointr   r   s       r   __contains__zBoundingRegion.__contains__   s    A}}Q"""r   c                     t           r
   r   )r   xsyss      r   scalezBoundingRegion.scale#   r   r   c                     |                                                                  \  }}}}t          ||z   ||z   f||z   ||z   f          | _        d S r
   )aarectlbrtAARectangler   )r   xoffyofflbrts          r   	translatezBoundingRegion.translate'   sR    [[]]''))
1a"AHa$h#7!d(AH9MNNr   c                     t           r
   r   )r   thetas     r   rotatezBoundingRegion.rotate,   r   r   c                     t           r
   r   r   s    r   r   zBoundingRegion.aarect0   r   r   c                 N    |                                                                  S )zJ
        Return the coordinates of the center of this BoundingBox
        )r   centroidr*   s    r   r,   zBoundingRegion.centroid4   s     {{}}%%'''r   c                 "    t          | | _        d S r
   )r   r   r   pointss     r   setzBoundingRegion.set;   s    "F+r   c                 T    i }t          |           D ]}t          | |          ||<   |S r
   )r   getattr)r   stateslots      r   __getstate__zBoundingRegion.__getstate__@   s:     &t,, 	. 	.D!$--E$KKr   c                 \    |                                 D ]\  }}t          | ||           d S r
   itemssetattrr   r3   kvs       r   __setstate__zBoundingRegion.__setstate__I   s<    kkmm 	  	 FQD!Q	  	 r   N)__name__
__module____qualname____doc___BoundingRegion__abstract	__slots__r   r   r   r%   r(   r   r,   r0   r5   r=    r   r   r   r      s         
 JI" " "# # #
" " "O O O
" " "" " "( ( (, , ,
           r   r   c                   p     e Zd ZdZg Zd Zd ZddZ fdZd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Z xZS )BoundingBoxz
    A rectangular bounding box defined either by two points forming
    an axis-aligned rectangle (or simply a radius for a square).
    c           	          | j                                         \  }}}}t          |t                    s/|| k    r(t          |t                    s|| k    r||k    rd| dS d| d| d| d| d	S )z
        Return BoundingBox(points=((left,bottom),(right,top)))

        Reimplemented here so that 'print' for a BoundingBox
        will display the bounds.
        zBoundingBox(radius=)zBoundingBox(points=((,z),(z))))r   r   
isinstancer   r   r!   r"   r#   r$   s        r   __str__zBoundingBox.__str__V   s     \&&((
1a1n-- 	@!r''1n-- 3:23r''a1ff-----?1??q??Q??????r   c                 *    |                                  S r
   )rL   r*   s    r   __repr__zBoundingBox.__repr__e   s    ||~~r   N    c                     |g }| j         j        }| j        }|                    d| d|            |                                 S )Nzfrom z import )	__class__r>   r?   appendrL   )r   importsprefixclsmods        r   script_reprzBoundingBox.script_repri   sN    ?Gn%o1s11C11222||~~r   c                     d|v r'|d         }|d= t          | | f||f          | _        n1d|v rt          |d          | _        |d= nt          dd          | _         t                      j        di | dS )z
        Create a BoundingBox.

        Either 'radius' or 'points' can be specified for the AARectangle.

        If neither radius nor points is passed in, create a default
        AARectangle defined by (-0.5,-0.5),(0.5,0.5).
        radiusr/   )      rZ   )      ?r[   NrD   )r   r   super__init__)r   argsr#   rQ   s      r   r]   zBoundingBox.__init__s   s     tXAX&QBx!Q88DLL&X7DLX&|Z@@DL  4     r   c                     t          |t                    r|                     |          S |\  }}|                     ||          S r
   )rJ   rF   containsbb_inclusiver   )r   otherr   r   s       r   r   zBoundingBox.__contains__   sE    e[)) 	4,,U333A}}Q"""r   c                     |                                                                  \  }}}}||cxk    o|k    nc o||cxk    o|k    nc S )z
        Returns true if the given point is contained within the
        bounding box, where all boundaries of the box are
        considered to be inclusive.
        r   r   r   r   r   leftbottomrighttops          r   r   zBoundingBox.contains   si     $(;;==#5#5#7#7 feS""""U""""<1););););););););<r   c                 ~    | j                                         \  }}}}||cxk    o|k     nc o||cxk     o|k    nc S )z
        Return True if the given point is contained within the
        bounding box, where the bottom and right boundaries are
        considered exclusive.
        r   r   rd   s          r   contains_exclusivezBoundingBox.contains_exclusive   sc     $(<#4#4#6#6 feS!!!!E!!!!:(9(9(9(9c(9(9(9(9:r   c                    |                                                                  \  }}}}|                                                                 \  }}}}	||k    o*||k    o$||k    o||	k    o||k    o||k    o||k    o||	k     S )z
        Returns true if the given BoundingBox x is contained within the
        bounding box, where at least one of the boundaries of the box has
        to be exclusive.
        rc   
r   r   re   rf   rg   rh   leftxbottomxrightxtopxs
             r   containsbb_exclusivez BoundingBox.containsbb_exclusive   s     $(;;==#5#5#7#7 feS'(xxzz'8'8$w gFg$5 gEVO gRUY]R] gemd&G*;d%6/dX[_cXce	gr   c                     |                                                                  \  }}}}|                                                                 \  }}}}	||k    o||k    o||k    o||	k    S )z
        Returns true if the given BoundingBox x is contained within the
        bounding box, including cases of exact match.
        rc   rm   s
             r   r`   z BoundingBox.containsbb_inclusive   sv    
 $(;;==#5#5#7#7 feS'(xxzz'8'8$w +Fg$5 ++!Tk	+r   c                     |                                                                  \  }}}}||cxk    o|k     nc o||cxk    o|k     nc S )a  
        Returns true if the given point is contained within the
        bounding box, where the right and upper boundaries
        are exclusive, and the left and lower boundaries are
        inclusive.  Useful for tiling a plane into non-overlapping
        regions.
        rc   rd   s          r   upperexclusive_containsz#BoundingBox.upperexclusive_contains   si     $(;;==#5#5#7#7 feS!!!!E!!!!:!(9(9(9(9c(9(9(9(9:r   c                     | j         S r
   )r   r*   s    r   r   zBoundingBox.aarect   s
    |r   c                 4    | j                                         S )zJ
        return left,bottom,right,top values for the BoundingBox.
        rj   r*   s    r   r   zBoundingBox.lbrt   s     |  """r   c                     t          | t                    r?t          |t                    r*|                                 |                                k    S dS )NF)rJ   rF   r   )r   ra   s     r   __eq__zBoundingBox.__eq__   sE    dK(( 	Z{-K-K 	99;;%**,,..5r   )NrO   )r>   r?   r@   rA   rC   rL   rN   rW   r]   r   r   rk   rr   r`   ru   r   r   ry   __classcell__)rQ   s   @r   rF   rF   N   s         I@ @ @     ! ! ! ! !6# # #= = =; ; ;	g 	g 	g+ + +	; 	; 	;  # # #      r   rF   c                       e Zd ZdZg Zd ZdS )BoundingEllipsezc
    Similar to BoundingBox, but the region is the ellipse
    inscribed within the rectangle.
    c                     |                                                                  \  }}}}||z
  dz  }||z
  dz  }||z   }	||z   }
||	z
  }||
z
  }|dz  |dz  z  |dz  |dz  z  z   dk    S )N       @   r   rc   )r   r   r   re   rf   rg   rh   xryrxcycxdyds                r   r   zBoundingEllipse.contains   s    #';;==#5#5#7#7 feSdlc!Flc!BYb[VVa"'!B!GbAg$55!;;r   N)r>   r?   r@   rA   rC   r   rD   r   r   r|   r|      s4          I
< 
< 
< 
< 
<r   r|   c                   h    e Zd ZdZg dZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd ZdS )r   z
    Axis-aligned rectangle class.

    Defines the smallest axis-aligned rectangle that encloses a set of
    points.

    Usage:  aar = AARectangle( (x1,y1),(x2,y2), ... , (xN,yN) )
    _left_bottom_right_topc                     t          d |D                       | _        t          d |D                       | _        t          d |D                       | _        t          d |D                       | _        d S )Nc                     g | ]\  }}|S rD   rD   .0r   r   s      r   
<listcomp>z(AARectangle.__init__.<locals>.<listcomp>  s    ...tq!...r   c                     g | ]\  }}|S rD   rD   r   s      r   r   z(AARectangle.__init__.<locals>.<listcomp>  s    111$!QA111r   c                     g | ]\  }}|S rD   rD   r   s      r   r   z(AARectangle.__init__.<locals>.<listcomp>  s    ///1!///r   c                     g | ]\  }}|S rD   rD   r   s      r   r   z(AARectangle.__init__.<locals>.<listcomp>  s    000A1000r   )maxr   minr   r   r   r.   s     r   r]   zAARectangle.__init__  s~    ..v...//	11&11122/////00
0000011r   c                 D    i }| j         D ]}t          | |          ||<   |S r
   )rC   r2   )r   r3   r;   s      r   r5   zAARectangle.__getstate__  s2     	( 	(AtQ''E!HHr   c                 \    |                                 D ]\  }}t          | ||           d S r
   r7   r:   s       r   r=   zAARectangle.__setstate__  s<    KKMM 	  	 DAqD!Q	  	 r   c                     | j         S )z4Return the y-coordinate of the top of the rectangle.)r   r*   s    r   rh   zAARectangle.top  s
    yr   c                     | j         S )z7Return the y-coordinate of the bottom of the rectangle.)r   r*   s    r   rf   zAARectangle.bottom  s
    |r   c                     | j         S )z:Return the x-coordinate of the left side of the rectangle.)r   r*   s    r   re   zAARectangle.left"  s
    zr   c                     | j         S )z;Return the x-coordinate of the right side of the rectangle.)r   r*   s    r   rg   zAARectangle.right'  s
    {r   c                 6    | j         | j        | j        | j        fS )z*Return (left,bottom,right,top) as a tuple.r   r*   s    r   r   zAARectangle.lbrt,  s    z4<di??r   c                 T    |                                  \  }}}}||z   dz  ||z   dz  fS )z7
        Return the centroid of the rectangle.
        r~   r   )r   re   rf   rg   rh   s        r   r,   zAARectangle.centroid1  s7     $(99;; feS#cFlc%999r   c                    |                                  \  }}}}|                                 \  }}}}	t          ||          }
t          ||          }t          ||          }t          ||	          }t          |
|f||ff          S )N)r/   )r   r   r   r   )r   ra   l1b1r1t1l2b2r2t2r!   r"   r#   r$   s                 r   	intersectzAARectangle.intersect9  s~    BBBBBKKBKKBKKBKKAq6Aq6"23333r   c                      | j         | j        z
  S r
   )r   r   r*   s    r   widthzAARectangle.widthE  s    {TZ''r   c                      | j         | j        z
  S r
   )r   r   r*   s    r   heightzAARectangle.heightI  s    y4<''r   c                 L    |                                  \  }}}}||k    p||k    S r
   r   rK   s        r   emptyzAARectangle.emptyM  s*    YY[[
1aQ#AF#r   N)r>   r?   r@   rA   rC   r]   r5   r=   rh   rf   re   rg   r   r,   r   r   r   r   rD   r   r   r   r      s          766I2 2 2       
  
  
  
  
@ @ @
: : :	4 	4 	4( ( (( ( ($ $ $ $ $r   r   N)	rA   param.parameterizedr   utilr   r   rF   r|   r   rD   r   r   <module>r      s     3 2 2 2 2 2            <  <  <  <  <  <  <  < ~M M M M M. M M Mb< < < < <k < < <0X$ X$ X$ X$ X$ X$ X$ X$ X$ X$r   