
    Og:                        d dl mZ d dlmZmZmZmZmZmZ d dl	Z	d dl
Z
d dlZd dlmZmZmZ  edee      Zg dZ G d dee   e	j&                        Z G d	 d
ee         Z G d dee         ZddZddZy)    )annotations)IterableOptionalIteratorSequenceTypeVarGenericN)Vec3Vec2UVecT)BoundingBox2dBoundingBoxAbstractBoundingBoxc                     e Zd ZU ded<   ded<   ej
                  ddd       Zd ZddZddZ	dd	Z
ej
                  dd
       Zeej
                  dd              Zej
                  dd       Zej
                  d d       Zej
                  d d       Zej
                  d!d       Zd dZd"dZd"dZedd       Zed#d       Zed#d       Zd!dZd$dZd%dZy)&r   r   extminextmaxNc                     y N selfverticess     T/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/math/bbox.py__init__zAbstractBoundingBox.__init__           c                j    | j                         }| j                  |_        | j                  |_        |S r   )	__class__r   r   )r   boxs     r   copyzAbstractBoundingBox.copy   s)    nn[[
[[

r   c                <    d| j                    d| j                   dS )N[z, ]r   r   r   s    r   __str__zAbstractBoundingBox.__str__   s    4;;-r$++a00r   c                |    | j                   j                  }| j                  r| d| j                          dS | dS )N()z())r   __name__has_datar'   )r   names     r   __repr__zAbstractBoundingBox.__repr__!   s>    ~~&&==V1T\\^,A..V2;r   c              #  ^   K   | j                   r| j                   | j                   y y wr   )r,   r   r   r&   s    r   __iter__zAbstractBoundingBox.__iter__(   s&     ==++++ s   +-c                     y r   r   r   s     r   extendzAbstractBoundingBox.extend-   r   r   c                     y r   r   r&   s    r   is_emptyzAbstractBoundingBox.is_empty1   s     	r   c                     y r   r   )r   vertexs     r   insidezAbstractBoundingBox.inside6   r   r   c                     y r   r   r   others     r   has_intersectionz$AbstractBoundingBox.has_intersection:   r   r   c                     y r   r   r9   s     r   has_overlapzAbstractBoundingBox.has_overlap>   r   r   c                     y r   r   r9   s     r   intersectionz AbstractBoundingBox.intersectionB   r   r   c                r    | j                  |j                        xr | j                  |j                        S )zfReturns ``True`` if the `other` bounding box is completely inside
        this bounding box.

        )r7   r   r   r9   s     r   containszAbstractBoundingBox.containsF   s)    
 {{5<<(FT[[-FFr   c                F      j                   rt         fd|D              S y)ztReturns ``True`` if any vertex is inside this bounding box.

        Vertices at the box border are inside!
        c              3  @   K   | ]  }j                  |        y wr   )r7   ).0vr   s     r   	<genexpr>z1AbstractBoundingBox.any_inside.<locals>.<genexpr>S   s     8!t{{1~8s   F)r,   anyr   s   ` r   
any_insidezAbstractBoundingBox.any_insideM   s     
 ==8x888r   c                \    | j                   r d}|D ]  }d}| j                  |      r y |S y)zwReturns ``True`` if all vertices are inside this bounding box.

        Vertices at the box border are inside!
        FT)r,   r7   )r   r   has_anyrE   s       r   
all_insidezAbstractBoundingBox.all_insideV   s<    
 ==G !{{1~ ! Nr   c                T    t        j                  | j                  j                        S )z5Returns ``True`` if the bonding box has known limits.)mathisfiniter   xr&   s    r   r,   zAbstractBoundingBox.has_datae   s     }}T[[]]++r   c                4    | j                   | j                  z
  S )zReturns size of bounding box.)r   r   r&   s    r   sizezAbstractBoundingBox.sizej   s     {{T[[((r   c                L    | j                   j                  | j                        S )zReturns center of bounding box.)r   lerpr   r&   s    r   centerzAbstractBoundingBox.centero   s     {{,,r   c                    g }| j                   r|j                  |        |j                   r|j                  |       | j                  |      S )zVReturns a new bounding box as union of this and `other` bounding
        box.
        )r,   r2   r   )r   r:   r   s      r   unionzAbstractBoundingBox.uniont   s>     ==OOD!>>OOE"~~h''r   c                    | j                   rL| j                  ^}}}| j                  ^}}}t        ||      t        ||      t        ||      t        ||      fS t	        d      )zbReturns the corners of the bounding box in the xy-plane as
        :class:`Vec2` objects.
        empty bounding box)r,   r   r   r   
ValueError)r   x0y0_x1y1s         r   rect_verticesz!AbstractBoundingBox.rect_vertices   s\     ==JBQJBQB<b"tB|T"b\II122r   c                    | j                   rr|dk  r)t        | j                        }| |dz  k\  rt        d      | xj                  t        |||      z  c_        | xj                  t        | | |       z  c_        yy)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)r,   minrQ   rY   r   r
   r   )r   valuemin_exts      r   growzAbstractBoundingBox.grow   sr     ==s{dii.6Ws]*$%LMMKK4ue44KKK477K r   r   r   zOptional[Iterable[UVec]])returnstr)rg   zIterator[T]r   Iterable[UVec]rg   Nonerg   boolr6   r   rg   rm   r:   AbstractBoundingBox[T]rg   rm   )r:   rp   rg   rp   )r   rj   rg   rm   )rg   r   )rg   zSequence[Vec2])rc   floatrg   rk   )r+   
__module____qualname____annotations__abcabstractmethodr   r!   r'   r.   r0   r2   propertyr4   r7   r;   r=   r?   rA   rH   rK   r,   rQ   rT   rV   r_   re   r   r   r   r   r      s7   II 1
 	     	  	  	  	 G , , ) ) - -	(	38r   r   c                  `    e Zd ZdZdZdddZedd       ZddZddZ	ddZ
dd	Zdd
ZddZy)r   zm3D bounding box.

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

    r%   Nc                    t        t        j                  t        j                  t        j                        | _        | j                  | _        |	 t        |      \  | _        | _        y y # t        $ r Y y w xY wr   )r
   rM   infr   r   	extents3drY   r   s     r   r   zBoundingBox.__init__   s`    488TXXtxx8kk+4X+>(T[    s   A+ +	A76A7c                R    | j                   r| j                  \  }}}||z  |z  dk(  S y)zReturns ``True`` if the bounding box is empty or the bounding box
        has a size of 0 in any or all dimensions or is undefined.

        ra   Tr,   rQ   )r   sxsyszs       r   r4   zBoundingBox.is_empty   s0     ==JBB7R<3&&r   c                    t        |      }|sy| j                  r'|j                  | j                  | j                  g       t        |      \  | _        | _        yz`Extend bounds by `vertices`.

        Args:
            vertices: iterable of vertices

        N)listr,   r2   r   r   r{   r   r   rE   s      r   r2   zBoundingBox.extend   E     N==HHdkk4;;/0#,Q< T[r   c                   | j                   syt        |      j                  \  }}}| j                  j                  \  }}}| j                  j                  \  }}	}
||cxk  xr |k  nc xr" ||cxk  xr |	k  nc xr ||cxk  xr |
k  S c S zrReturns ``True`` if `vertex` is inside this bounding box.

        Vertices at the box border are inside!
        F)r,   r
   xyzr   r   )r   r6   rO   yzxminyminzminxmaxymaxzmaxs              r   r7   zBoundingBox.inside   s    
 }}v,""1a;;??dD;;??dD!T!R(9T(9R@QT@QR@QRr   c                :   | j                   r|j                   syt        |j                        }t        |j                        }| j                  j                  |j                  k\  ry| j                  j                  |j                  k  ry| j                  j
                  |j
                  k\  ry| j                  j
                  |j
                  k  ry| j                  j                  |j                  k\  ry| j                  j                  |j                  k  ryy)aG  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r,   r
   r   r   rO   r   r   r   r:   o_mino_maxs       r   r;   zBoundingBox.has_intersection   s     }}ENNU\\"U\\" ;;==EGG#;;==EGG#;;==EGG#;;==EGG#;;==EGG#;;==EGG#r   c                :   | j                   r|j                   syt        |j                        }t        |j                        }| j                  j                  |j                  kD  ry| j                  j                  |j                  k  ry| j                  j
                  |j
                  kD  ry| j                  j
                  |j
                  k  ry| j                  j                  |j                  kD  ry| j                  j                  |j                  k  ryy)aG  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   r=   zBoundingBox.has_overlap   s     }}ENNU\\"U\\";;==577";;==577";;==577";;==577";;==577";;==577"r   c                4   | j                   r| j                  \  }}}| j                  \  }}}t        |||      t        |||      t        |||      t        |||      t        |||      t        |||      t        |||      t        |||      fS t	        d      )zDReturns the 3D corners of the bounding box as :class:`Vec3` objects.rX   )r,   r   r   r
   rY   )r   rZ   r[   z0r]   r^   z1s          r   cube_verticeszBoundingBox.cube_vertices  s    ==JBBJBBRR RR RR RR RR RR RR RR 	 	 122r   c           	        | j                         }| j                  |      s|S t        | j                        \  }}}t        |j                        \  }}}t        | j                        \  }	}
}t        |j                        \  }}}|j                  t        ||      t        ||      t        ||      ft        |	|      t        |
|      t        ||      fg       |S )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   r;   r
   r   r   r2   maxrb   )r   r:   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   r?   zBoundingBox.intersection!  s     >>#$$U+O$($5!'$($6!'$($5!'$($6!' ))) )))	
 r   r   rf   rl   ri   rn   ro   )rg   zSequence[Vec3])r:   rp   rg   r   )r+   rr   rs   __doc__	__slots__r   rw   r4   r2   r7   r;   r=   r   r?   r   r   r   r   r      sF     %I  0
S><3$r   r   c                  X    e Zd ZdZdZdddZedd       ZddZddZ	ddZ
dd	Zdd
Zy)r   zo2D bounding box.

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

    r%   Nc                    t        t        j                  t        j                        | _        | j                  | _        |	 t        |      \  | _        | _        y y # t        $ r Y y w xY wr   )r   rM   rz   r   r   	extents2drY   r   s     r   r   zBoundingBox2d.__init__I  sZ    488TXX.kk+4X+>(T[    s   A 	A('A(c                J    | j                   r| j                  \  }}||z  dk(  S y)zReturns ``True`` if the bounding box is empty. The bounding box has a
        size of 0 in any or all dimensions or is undefined.
        ra   Tr}   )r   r~   r   s      r   r4   zBoundingBox2d.is_emptyS  s)    
 ==YYFB7c>!r   c                    t        |      }|sy| j                  r'|j                  | j                  | j                  g       t        |      \  | _        | _        yr   )r   r,   r2   r   r   r   r   s      r   r2   zBoundingBox2d.extend]  r   r   c                   | j                   syt        |      }| j                  }| j                  }|j                  |j                  cxk  xr |j                  k  nc xr. |j
                  |j
                  cxk  xr |j
                  k  S c S r   )r,   r   r   r   rO   r   )r   r6   rE   min_max_s        r   r7   zBoundingBox2d.insidek  sf    
 }}L{{{{!##''Fdff.Etvv.EF.EFr   c                   | j                   r|j                   sy| j                  j                  |j                  j                  k\  ry| j                  j                  |j                  j                  k  ry| j                  j                  |j                  j                  k\  ry| j                  j                  |j                  j                  k  ryy)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r,   r   rO   r   r   r9   s     r   r;   zBoundingBox2d.has_intersectionw  s     }}ENN;;==ELLNN*;;==ELLNN*;;==ELLNN*;;==ELLNN*r   c                   | j                         }| j                  |      s|S t        | j                        \  }}t        |j                        \  }}t        | j                        \  }}t        |j                        \  }	}
|j                  t        ||      t        ||      ft        ||	      t        ||
      fg       |S )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   r;   r   r   r   r2   r   rb   )r   r:   r   r   r   r   r   r   r   r   r   s              r   r?   zBoundingBox2d.intersection  s    
 >>#$$U+O,-,-Wg&GW(=>Wg&GW(=>	
 r   c                   | j                   r|j                   sy| j                  j                  |j                  j                  kD  ry| j                  j                  |j                  j                  k  ry| j                  j                  |j                  j                  kD  ry| j                  j                  |j                  j                  k  ryy)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   r9   s     r   r=   zBoundingBox2d.has_overlap  s     }}ENN;;==5<<>>);;==5<<>>);;==5<<>>);;==5<<>>)r   r   rf   rl   ri   rn   ro   )r:   rp   rg   r   )r+   rr   rs   r   r   r   rw   r4   r2   r7   r;   r?   r=   r   r   r   r   r   ?  sA     %I  0
G.(r   r   c                ,   t        j                  | D cg c]  }t        |      j                   c}t         j                        } t        |       r4t        | j                  d            t        | j                  d            fS t        d      c c}w zBReturns the extents of the bounding box as tuple (extmin, extmax).)dtyper   zno vertices given)	nparrayr
   r   float64lenrb   r   rY   )r   rE   s     r   r{   r{     sf    xxh7a7rzzJH
8}HLLO$d8<<?&;;;,--	 8s   Bc           
        t        j                  | D cg c]	  ^}}}||f c}}}t         j                        } t        |       r4t	        | j                  d            t	        | j                  d            fS t        d      c c}}}w r   )r   r   r   r   r   rb   r   rY   )r   rO   r   r\   s       r   r   r     sk    xx99HAq1!Q9LH
8}HLLO$d8<<?&;;;,--	 :s   B)r   rj   rg   ztuple[Vec3, Vec3])r   rj   rg   ztuple[Vec2, Vec2])
__future__r   typingr   r   r   r   r   r	   ru   rM   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   