
    h:                        S SK Jr  S SKJrJrJrJrJrJr  S SK	r	S SK
r
S SKrS SKJrJrJr  \" S\\5      r/ SQr " S S\\   \	R&                  5      r " S	 S
\\   5      r " S S\\   5      rSS jrSS jrg)    )annotations)IterableOptionalIteratorSequenceTypeVarGenericN)Vec3Vec2UVecT)BoundingBox2dBoundingBoxAbstractBoundingBoxc                     \ rS rSr% S\S'   S\S'   \R                  SSS jj5       rS rSS jr	SS	 jr
SS
 jr\R                  SS j5       r\\R                  S S j5       5       r\R                  S!S j5       r\R                  S"S j5       r\R                  S"S j5       r\R                  S#S j5       rS"S jrS$S jrS$S jr\S S j5       r\S%S j5       r\S%S j5       rS#S jrS&S jrS'S jrSrg)(r      r   extminextmaxNc                    g N selfverticess     A/var/www/html/env/lib/python3.13/site-packages/ezdxf/math/bbox.py__init__AbstractBoundingBox.__init__           c                j    U R                  5       nU R                  Ul        U R                  Ul        U$ r   )	__class__r   r   )r   boxs     r   copyAbstractBoundingBox.copy   s)    nn[[
[[

r   c                <    SU R                    SU R                   S3$ )N[z, ]r   r   r   s    r   __str__AbstractBoundingBox.__str__   s    4;;-r$++a00r   c                    U R                   R                  nU R                  (       a  U SU R                  5        S3$ U S3$ )N()z())r!   __name__has_datar*   )r   names     r   __repr__AbstractBoundingBox.__repr__!   s>    ~~&&==V1T\\^,A..V2;r   c              #  h   #    U R                   (       a  U R                  v   U R                  v   g g 7fr   )r0   r   r   r)   s    r   __iter__AbstractBoundingBox.__iter__(   s%     ==++++ s   02c                    g r   r   r   s     r   extendAbstractBoundingBox.extend-   r   r   c                    g r   r   r)   s    r   is_emptyAbstractBoundingBox.is_empty1   s     	r   c                    g r   r   )r   vertexs     r   insideAbstractBoundingBox.inside6   r   r   c                    g r   r   r   others     r   has_intersection$AbstractBoundingBox.has_intersection:   r   r   c                    g r   r   rB   s     r   has_overlapAbstractBoundingBox.has_overlap>   r   r   c                    g r   r   rB   s     r   intersection AbstractBoundingBox.intersectionB   r   r   c                |    U R                  UR                  5      =(       a    U R                  UR                  5      $ )zVReturns ``True`` if the `other` bounding box is completely inside
this bounding box.

)r?   r   r   rB   s     r   containsAbstractBoundingBox.containsF   s)    
 {{5<<(FT[[-FFr   c                R   ^  T R                   (       a  [        U 4S jU 5       5      $ g)zdReturns ``True`` if any vertex is inside this bounding box.

Vertices at the box border are inside!
c              3  F   >#    U  H  nTR                  U5      v   M     g 7fr   )r?   ).0vr   s     r   	<genexpr>1AbstractBoundingBox.any_inside.<locals>.<genexpr>S   s     8x!t{{1~~xs   !F)r0   anyr   s   ` r   
any_insideAbstractBoundingBox.any_insideM   s     
 ==8x888r   c                t    U R                   (       a'  SnU H  nSnU R                  U5      (       a  M    g   U$ g)zgReturns ``True`` if all vertices are inside this bounding box.

Vertices at the box border are inside!
FT)r0   r?   )r   r   has_anyrR   s       r   
all_insideAbstractBoundingBox.all_insideV   s9    
 ==G{{1~~   Nr   c                V    [         R                  " U R                  R                  5      $ )z5Returns ``True`` if the bonding box has known limits.)mathisfiniter   xr)   s    r   r0   AbstractBoundingBox.has_datae   s     }}T[[]]++r   c                4    U R                   U R                  -
  $ )zReturns size of bounding box.r   r   r)   s    r   sizeAbstractBoundingBox.sizej   s     {{T[[((r   c                L    U R                   R                  U R                  5      $ )zReturns center of bounding box.)r   lerpr   r)   s    r   centerAbstractBoundingBox.centero   s     {{,,r   c                    / nU R                   (       a  UR                  U 5        UR                   (       a  UR                  U5        U R                  U5      $ )zFReturns a new bounding box as union of this and `other` bounding
box.
)r0   r8   r!   )r   rC   r   s      r   unionAbstractBoundingBox.uniont   s>     ==OOD!>>OOE"~~h''r   c                    U R                   (       aF  U R                  tpnU R                  tpEn[        X5      [        XB5      [        XE5      [        X5      4$ [	        S5      e)zRReturns the corners of the bounding box in the xy-plane as
:class:`Vec2` objects.
empty bounding box)r0   r   r   r   
ValueError)r   x0y0_x1y1s         r   rect_vertices!AbstractBoundingBox.rect_vertices   sP     ==JBQJBQ<btB|T"\II122r   c                   U R                   (       as  US:  a*  [        U R                  5      nU* US-  :  a  [        S5      eU =R                  [        XU5      -  sl        U =R                  [        U* U* U* 5      -  sl        gg)zGrow or shrink the bounding box by an uniform value in x, y and
z-axis. A negative value shrinks the bounding box.
Raises :class:`ValueError` for shrinking the size of the bounding box to
zero or below in any dimension.
        g       @z%shrinking one or more dimensions <= 0N)r0   minrc   rn   r   r
   r   )r   valuemin_exts      r   growAbstractBoundingBox.grow   sp     ==s{dii.6Ws]*$%LMMKK4e44KKK477K r   r   r   r   zOptional[Iterable[UVec]])returnstr)r~   zIterator[T]r   Iterable[UVec]r~   Noner~   boolr>   r   r~   r   rC   AbstractBoundingBox[T]r~   r   )rC   r   r~   r   )r   r   r~   r   )r~   r   )r~   zSequence[Vec2])ry   floatr~   r   )r/   
__module____qualname____firstlineno____annotations__abcabstractmethodr   r#   r*   r2   r5   r8   propertyr;   r?   rD   rG   rJ   rM   rV   rZ   r0   rc   rg   rj   rt   r{   __static_attributes__r   r   r   r   r      s7   II 1
 	     	  	  	  	 G , , ) ) - -	(	38r   r   c                  z    \ rS rSrSrSrSSS jjr\SS j5       rSS jr	SS jr
SS	 jrSS
 jrSS jrSS jrSrg)r      za3D bounding box.

Args:
    vertices: iterable of ``(x, y, z)`` tuples or :class:`Vec3` objects

r(   Nc                    [        [        R                  [        R                  [        R                  5      U l        U R                  U l        Ub   [        U5      u  U l        U l        g g ! [         a     g f = fr   )r
   r]   infr   r   	extents3drn   r   s     r   r   BoundingBox.__init__   s`    488TXXtxx8kk+4X+>(T[    s   A, ,
A98A9c                X    U R                   (       a  U R                  u  pnX-  U-  S:H  $ g)z}Returns ``True`` if the bounding box is empty or the bounding box
has a size of 0 in any or all dimensions or is undefined.

rw   Tr0   rc   )r   sxsyszs       r   r;   BoundingBox.is_empty   s,     ==JBB7R<3&&r   c                    [        U5      nU(       d  gU R                  (       a'  UR                  U R                  U R                  /5        [        U5      u  U l        U l        gzHExtend bounds by `vertices`.

Args:
    vertices: iterable of vertices

N)listr0   r8   r   r   r   r   r   rR   s      r   r8   BoundingBox.extend   E     N==HHdkk4;;/0#,Q< T[r   c                N   U R                   (       d  g[        U5      R                  u  p#nU R                  R                  u  pVnU R                  R                  u  pn
XRs=:*  =(       a    U:*  Os  =(       a/    Xcs=:*  =(       a    U	:*  Os  =(       a    Xts=:*  =(       a    U
:*  $ s  $ zbReturns ``True`` if `vertex` is inside this bounding box.

Vertices at the box border are inside!
F)r0   r
   xyzr   r   )r   r>   r_   yzxminyminzminxmaxymaxzmaxs              r   r?   BoundingBox.inside   s|    
 }}v,""a;;??D;;??D!!T!R(9(9T(9R@Q@QT@QR@QRr   c                Z   U R                   (       a  UR                   (       d  g[        UR                  5      n[        UR                  5      nU R                  R                  UR                  :  a  gU R                  R                  UR                  ::  a  gU R                  R
                  UR
                  :  a  gU R                  R
                  UR
                  ::  a  gU R                  R                  UR                  :  a  gU R                  R                  UR                  ::  a  gg)a  Returns ``True`` if this bounding box intersects with `other` but does
not include touching bounding boxes, see also :meth:`has_overlap`::

    bbox1 = BoundingBox([(0, 0, 0), (1, 1, 1)])
    bbox2 = BoundingBox([(1, 1, 1), (2, 2, 2)])
    assert bbox1.has_intersection(bbox2) is False

FTr0   r
   r   r   r_   r   r   r   rC   o_mino_maxs       r   rD   BoundingBox.has_intersection   s     }}ENNU\\"U\\" ;;==EGG#;;==EGG#;;==EGG#;;==EGG#;;==EGG#;;==EGG#r   c                Z   U R                   (       a  UR                   (       d  g[        UR                  5      n[        UR                  5      nU R                  R                  UR                  :  a  gU R                  R                  UR                  :  a  gU R                  R
                  UR
                  :  a  gU R                  R
                  UR
                  :  a  gU R                  R                  UR                  :  a  gU R                  R                  UR                  :  a  gg)a  Returns ``True`` if this bounding box intersects with `other` but
in contrast to :meth:`has_intersection` includes touching bounding boxes too::

    bbox1 = BoundingBox([(0, 0, 0), (1, 1, 1)])
    bbox2 = BoundingBox([(1, 1, 1), (2, 2, 2)])
    assert bbox1.has_overlap(bbox2) is True

FTr   r   s       r   rG   BoundingBox.has_overlap   s     }}ENNU\\"U\\";;==577";;==577";;==577";;==577";;==577";;==577"r   c                *   U R                   (       ax  U R                  u  pnU R                  u  pEn[        XU5      [        XBU5      [        XEU5      [        XU5      [        XU5      [        XBU5      [        XEU5      [        XU5      4$ [	        S5      e)zDReturns the 3D corners of the bounding box as :class:`Vec3` objects.rm   )r0   r   r   r
   rn   )r   ro   rp   z0rr   rs   z1s          r   cube_verticesBoundingBox.cube_vertices  s    ==JBBJBBRR RR RR RR RR RR RR RR 	 	 122r   c           	        U R                  5       nU R                  U5      (       d  U$ [        U R                  5      u  p4n[        UR                  5      u  pgn[        U R                  5      u  pn[        UR                  5      u  pnUR                  [        X65      [        XG5      [        XX5      4[        X5      [        X5      [        X5      4/5        U$ )zReturns the bounding box of the intersection cube of both
3D bounding boxes. Returns an empty bounding box if the intersection
volume is 0.

)r!   rD   r
   r   r   r8   maxrx   )r   rC   new_bboxs_min_xs_min_ys_min_zo_min_xo_min_yo_min_zs_max_xs_max_ys_max_zo_max_xo_max_yo_max_zs                  r   rJ   BoundingBox.intersection!  s     >>#$$U++O$($5!'$($6!'$($5!'$($6!' ))) )))	
 r   rb   r   r}   r   r   r   r   )r~   zSequence[Vec3])rC   r   r~   r   )r/   r   r   r   __doc__	__slots__r   r   r;   r8   r?   rD   rG   r   rJ   r   r   r   r   r   r      sF     %I  0
S><3$r   r   c                  p    \ rS rSrSrSrSSS jjr\SS j5       rSS jr	SS jr
SS	 jrSS
 jrSS jrSrg)r   i?  zc2D bounding box.

Args:
    vertices: iterable of ``(x, y[, z])`` tuples or :class:`Vec3` objects

r(   Nc                    [        [        R                  [        R                  5      U l        U R                  U l        Ub   [        U5      u  U l        U l        g g ! [         a     g f = fr   )r   r]   r   r   r   	extents2drn   r   s     r   r   BoundingBox2d.__init__I  sZ    488TXX.kk+4X+>(T[    s   A 
A*)A*c                P    U R                   (       a  U R                  u  pX-  S:H  $ g)zzReturns ``True`` if the bounding box is empty. The bounding box has a
size of 0 in any or all dimensions or is undefined.
rw   Tr   )r   r   r   s      r   r;   BoundingBox2d.is_emptyS  s%    
 ==YYFB7c>!r   c                    [        U5      nU(       d  gU R                  (       a'  UR                  U R                  U R                  /5        [        U5      u  U l        U l        gr   )r   r0   r8   r   r   r   r   s      r   r8   BoundingBox2d.extend]  r   r   c                F   U R                   (       d  g[        U5      nU R                  nU R                  nUR                  UR                  s=:*  =(       a    UR                  :*  Os  =(       a3    UR
                  UR
                  s=:*  =(       a    UR
                  :*  $ s  $ r   )r0   r   r   r   r_   r   )r   r>   rR   min_max_s        r   r?   BoundingBox2d.insidek  sl    
 }}L{{{{!##'''Fdff.E.Etvv.EF.EFr   c                   U R                   (       a  UR                   (       d  gU R                  R                  UR                  R                  :  a  gU R                  R                  UR                  R                  ::  a  gU R                  R                  UR                  R                  :  a  gU R                  R                  UR                  R                  ::  a  gg)a  Returns ``True`` if this bounding box intersects with `other` but does
not include touching bounding boxes, see also :meth:`has_overlap`::

    bbox1 = BoundingBox2d([(0, 0), (1, 1)])
    bbox2 = BoundingBox2d([(1, 1), (2, 2)])
    assert bbox1.has_intersection(bbox2) is False

FTr0   r   r_   r   r   rB   s     r   rD   BoundingBox2d.has_intersectionw  s     }}ENN;;==ELLNN*;;==ELLNN*;;==ELLNN*;;==ELLNN*r   c                   U R                  5       nU R                  U5      (       d  U$ [        U R                  5      u  p4[        UR                  5      u  pV[        U R                  5      u  px[        UR                  5      u  pUR                  [        X55      [        XF5      4[        Xy5      [        X5      4/5        U$ )zReturns the bounding box of the intersection rectangle of both
2D bounding boxes. Returns an empty bounding box if the intersection
area is 0.
)r!   rD   r   r   r   r8   r   rx   )r   rC   r   r   r   r   r   r   r   r   r   s              r   rJ   BoundingBox2d.intersection  s    
 >>#$$U++O,-,-W&G(=>W&G(=>	
 r   c                   U R                   (       a  UR                   (       d  gU R                  R                  UR                  R                  :  a  gU R                  R                  UR                  R                  :  a  gU R                  R                  UR                  R                  :  a  gU R                  R                  UR                  R                  :  a  gg)a  Returns ``True`` if this bounding box intersects with `other` but
in contrast to :meth:`has_intersection` includes touching bounding boxes too::

    bbox1 = BoundingBox2d([(0, 0), (1, 1)])
    bbox2 = BoundingBox2d([(1, 1), (2, 2)])
    assert bbox1.has_overlap(bbox2) is True

FTr   rB   s     r   rG   BoundingBox2d.has_overlap  s     }}ENN;;==5<<>>);;==5<<>>);;==5<<>>);;==5<<>>)r   rb   r   r}   r   r   r   r   )rC   r   r~   r   )r/   r   r   r   r   r   r   r   r;   r8   r?   rD   rJ   rG   r   r   r   r   r   r   ?  sA     %I  0
G.(r   r   c                8   [         R                  " U  Vs/ s H  n[        U5      R                  PM     sn[         R                  S9n [        U 5      (       a4  [        U R                  S5      5      [        U R                  S5      5      4$ [        S5      es  snf zBReturns the extents of the bounding box as tuple (extmin, extmax).)dtyper   zno vertices given)	nparrayr
   r   float64lenrx   r   rn   )r   rR   s     r   r   r     sl    xxh7hah7rzzJH
8}}HLLO$d8<<?&;;;,--	 8s   Bc           
     $   [         R                  " U  VVVs/ s H  tpo1U4PM
     snnn[         R                  S9n [        U 5      (       a4  [	        U R                  S5      5      [	        U R                  S5      5      4$ [        S5      es  snnnf r   )r   r   r   r   r   rx   r   rn   )r   r_   r   rq   s       r   r   r     sj    xx9HA1Q9LH
8}}HLLO$d8<<?&;;;,--	 :s   B)r   r   r~   ztuple[Vec3, Vec3])r   r   r~   ztuple[Vec2, Vec2])
__future__r   typingr   r   r   r   r   r	   r   r]   numpyr   
ezdxf.mathr
   r   r   r   __all__ABCr   r   r   r   r   r   r   r   <module>r      s    # K K 
   ' 'Ct
AF8'!*cgg F8Rc%d+ cLx'- xv..r   