
    'j:                       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dS )    )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        d0d            Zd/dZd1dZd1dZed-d            Zed2d             Zed2d!            Zd0d"Zd3d$Zd4d'ZdS )5r   r   extminextmaxNverticesOptional[Iterable[UVec]]c                    d S N selfr   s     I/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/math/bbox.py__init__zAbstractBoundingBox.__init__           c                ^    |                                  }| j        |_        | j        |_        |S r   )	__class__r   r   )r   boxs     r   copyzAbstractBoundingBox.copy   s(    nn[
[

r   returnstrc                (    d| j          d| j         dS )N[z, ]r   r   r   s    r   __str__zAbstractBoundingBox.__str__   s    04;00$+0000r   c                f    | j         j        }| j        r| d|                                  dS | dS )N()z())r    __name__has_datar*   )r   names     r   __repr__zAbstractBoundingBox.__repr__!   sA    ~&= 	..T\\^^....;;;r   Iterator[T]c              #  @   K   | j         r| j        V  | j        V  d S d S r   )r/   r   r   r)   s    r   __iter__zAbstractBoundingBox.__iter__(   s<      = 	++	 	r   Iterable[UVec]Nonec                    d S r   r   r   s     r   extendzAbstractBoundingBox.extend-   r   r   boolc                    d S r   r   r)   s    r   is_emptyzAbstractBoundingBox.is_empty1   s	     	r   vertexr   c                    d S r   r   )r   r<   s     r   insidezAbstractBoundingBox.inside6   r   r   otherAbstractBoundingBox[T]c                    d S r   r   r   r?   s     r   has_intersectionz$AbstractBoundingBox.has_intersection:   r   r   c                    d S r   r   rB   s     r   has_overlapzAbstractBoundingBox.has_overlap>   r   r   c                    d S r   r   rB   s     r   intersectionz AbstractBoundingBox.intersectionB   r   r   c                j    |                      |j                  o|                      |j                  S )zfReturns ``True`` if the `other` bounding box is completely inside
        this bounding box.

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

        Vertices at the box border are inside!
        c              3  B   K   | ]}                     |          V  d S r   )r>   ).0vr   s     r   	<genexpr>z1AbstractBoundingBox.any_inside.<locals>.<genexpr>S   s-      88!t{{1~~888888r   F)r/   anyr   s   ` r   
any_insidezAbstractBoundingBox.any_insideM   s7    
 = 	98888x888888ur   c                Z    | j         r#d}|D ]}d}|                     |          s dS |S dS )zwReturns ``True`` if all vertices are inside this bounding box.

        Vertices at the box border are inside!
        FT)r/   r>   )r   r   has_anyrM   s       r   
all_insidezAbstractBoundingBox.all_insideV   sO    
 = 	G ! !{{1~~ ! 55!Nur   c                >    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                     | j         | j        z
  S )zReturns size of bounding box.)r   r   r)   s    r   sizezAbstractBoundingBox.sizej   s     {T[((r   c                @    | j                             | j                  S )zReturns center of bounding box.)r   lerpr   r)   s    r   centerzAbstractBoundingBox.centero   s     {,,,r   c                    g }| j         r|                    |            |j         r|                    |           |                     |          S )zVReturns a new bounding box as union of this and `other` bounding
        box.
        )r/   r8   r    )r   r?   r   s      r   unionzAbstractBoundingBox.uniont   sS     = 	"OOD!!!> 	#OOE"""~~h'''r   Sequence[Vec2]c                    | j         rR| 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   sf     = 	3JBQJBQB<<b"tB||T"b\\II1222r   valuefloatc                    | j         rv|dk     r-t          | j                  }| |dz  k    rt          d          | xj        t          |||          z  c_        | xj        t          | | |           z  c_        dS dS )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/   minrY   rb   r   r
   r   )r   ri   min_exts      r   growzAbstractBoundingBox.grow   s     = 	8s{{di..6Ws]**$%LMMMKK4ue444KKKK4777KKKK	8 	8r   r   r   r   )r#   r$   )r#   r2   r   r5   r#   r6   r#   r9   r<   r   r#   r9   r?   r@   r#   r9   )r?   r@   r#   r@   )r   r5   r#   r9   )r#   r   )r#   r_   )ri   rj   r#   r6   )r.   
__module____qualname____annotations__abcabstractmethodr   r"   r*   r1   r4   r8   propertyr;   r>   rC   rE   rG   rI   rP   rS   r/   rY   r\   r^   rh   ro   r   r   r   r   r      sX        IIIIII      1 1 1 1      
 	        X 	    	    	    	   G G G G       , , , X, ) ) ) X) - - - X-	( 	( 	( 	(	3 	3 	3 	38 8 8 8 8 8r   r   c                  h    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dS )r   zm3D bounding box.

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

    r(   Nr   r   c                    t          t          j        t          j        t          j                  | _        | j        | _        |0	 t          |          \  | _        | _        d S # t          $ r Y d S w xY wd S r   )r
   rU   infr   r   	extents3drb   r   s     r   r   zBoundingBox.__init__   ss    48TXtx88k+4X+>+>(T[[[     s   A" "
A0/A0r#   r9   c                B    | j         r| j        \  }}}||z  |z  dk    S dS )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.

        rl   Tr/   rY   )r   sxsyszs       r   r;   zBoundingBox.is_empty   s3     = 	'JBB7R<3&&tr   r5   r6   c                    t          |          }|sdS | j        r!|                    | j        | j        g           t          |          \  | _        | _        dS z`Extend bounds by `vertices`.

        Args:
            vertices: iterable of vertices

        N)listr/   r8   r   r   r~   r   r   rM   s      r   r8   zBoundingBox.extend   Y     NN 	F= 	1HHdk4;/000#,Q<< T[[[r   r<   r   c                    | j         sdS t          |          j        \  }}}| j        j        \  }}}| j        j        \  }}	}
||cxk    o|k    nc o||cxk    o|	k    nc o||cxk    o|
k    nc S zrReturns ``True`` if `vertex` is inside this bounding box.

        Vertices at the box border are inside!
        F)r/   r
   xyzr   r   )r   r<   rW   yzxminyminzminxmaxymaxzmaxs              r   r>   zBoundingBox.inside   s    
 } 	5v,,"1a;?dD;?dD!!!!T!!!!R(9(9(9(9T(9(9(9(9R@Q@Q@Q@QT@Q@Q@Q@QRr   r?   r@   c                   | j         r|j         sdS t          |j                  }t          |j                  }| j        j        |j        k    rdS | j        j        |j        k    rdS | j        j        |j        k    rdS | j        j        |j        k    rdS | j        j        |j        k    rdS | j        j        |j        k    rdS dS )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   rW   r   r   r   r?   o_mino_maxs       r   rC   zBoundingBox.has_intersection   s     } 	EN 	5U\""U\"" ;=EG##5;=EG##5;=EG##5;=EG##5;=EG##5;=EG##5tr   c                   | j         r|j         sdS t          |j                  }t          |j                  }| j        j        |j        k    rdS | j        j        |j        k     rdS | j        j        |j        k    rdS | j        j        |j        k     rdS | j        j        |j        k    rdS | j        j        |j        k     rdS dS )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   rE   zBoundingBox.has_overlap   s     } 	EN 	5U\""U\"";=57""5;=57""5;=57""5;=57""5;=57""5;=57""5tr   Sequence[Vec3]c                ^   | 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.ra   )r/   r   r   r
   rb   )r   rc   rd   z0rf   rg   z1s          r   cube_verticeszBoundingBox.cube_vertices  s    = 	3JBBJBBRR  RR  RR  RR  RR  RR  RR  RR  	 	 1222r   c           	        |                                  }|                     |          s|S t          | j                  \  }}}t          |j                  \  }}}t          | j                  \  }	}
}t          |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    rC   r
   r   r   r8   maxrm   )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   rG   zBoundingBox.intersection!  s    >>##$$U++ 	O$($5$5!'$($6$6!'$($5$5!'$($6$6!' )))))) ))))))	
 	
 	
 r   r   rp   rr   rq   rs   rt   )r#   r   )r?   r@   r#   r   )r.   ru   rv   __doc__	__slots__r   rz   r;   r8   r>   rC   rE   r   rG   r   r   r   r   r      s          %I        X0 0 0 0
S 
S 
S 
S   >   <3 3 3 3$     r   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S )r   zo2D bounding box.

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

    r(   Nr   r   c                    t          t          j        t          j                  | _        | j        | _        |0	 t          |          \  | _        | _        d S # t          $ r Y d S w xY wd S r   )r   rU   r}   r   r   	extents2drb   r   s     r   r   zBoundingBox2d.__init__I  so    48TX..k+4X+>+>(T[[[     s   A 
A%$A%r#   r9   c                :    | j         r| j        \  }}||z  dk    S dS )zReturns ``True`` if the bounding box is empty. The bounding box has a
        size of 0 in any or all dimensions or is undefined.
        rl   Tr   )r   r   r   s      r   r;   zBoundingBox2d.is_emptyS  s,    
 = 	"YFB7c>!tr   r5   r6   c                    t          |          }|sdS | j        r!|                    | j        | j        g           t          |          \  | _        | _        dS r   )r   r/   r8   r   r   r   r   s      r   r8   zBoundingBox2d.extend]  r   r   r<   r   c                    | j         sdS t          |          }| j        }| j        }|j        |j        cxk    o
|j        k    nc o|j        |j        cxk    o
|j        k    nc S r   )r/   r   r   r   rW   r   )r   r<   rM   min_max_s        r   r>   zBoundingBox2d.insidek  s{    
 } 	5LL{{!#''''''''Fdf.E.E.E.Etv.E.E.E.EFr   r?   r@   c                   | j         r|j         sdS | j        j        |j        j        k    rdS | j        j        |j        j        k    rdS | j        j        |j        j        k    rdS | j        j        |j        j        k    rdS dS )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   rW   r   r   rB   s     r   rC   zBoundingBox2d.has_intersectionw  s     } 	EN 	5;=ELN**5;=ELN**5;=ELN**5;=ELN**5tr   c                   |                                  }|                     |          s|S t          | j                  \  }}t          |j                  \  }}t          | j                  \  }}t          |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    rC   r   r   r   r8   r   rm   )r   r?   r   r   r   r   r   r   r   r   r   s              r   rG   zBoundingBox2d.intersection  s    
 >>##$$U++ 	O,,--,,--Wg&&GW(=(=>Wg&&GW(=(=>	
 	
 	
 r   c                   | j         r|j         sdS | j        j        |j        j        k    rdS | j        j        |j        j        k     rdS | j        j        |j        j        k    rdS | j        j        |j        j        k     rdS dS )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   rE   zBoundingBox2d.has_overlap  s     } 	EN 	5;=5<>))5;=5<>))5;=5<>))5;=5<>))5tr   r   rp   rr   rq   rs   rt   )r?   r@   r#   r   )r.   ru   rv   r   r   r   rz   r;   r8   r>   rC   rG   rE   r   r   r   r   r   ?  s          %I        X0 0 0 0
G 
G 
G 
G   .   (     r   r   r   r5   r#   tuple[Vec3, Vec3]c                   t          j        d | D             t           j                  } t          |           rDt	          |                     d                    t	          |                     d                    fS t          d          )BReturns the extents of the bounding box as tuple (extmin, extmax).c                6    g | ]}t          |          j        S r   )r
   r   )rL   rM   s     r   
<listcomp>zextents3d.<locals>.<listcomp>  s     777a777r   dtyper   no vertices given)nparrayfloat64lenr
   rm   r   rb   r   s    r   r~   r~     ss    x77h777rzJJJH
8}} .HLLOO$$d8<<??&;&;;;,---r   tuple[Vec2, Vec2]c                   t          j        d | D             t           j                  } t          |           rDt	          |                     d                    t	          |                     d                    fS t          d          )r   c                    g | ]	^}}}||f
S r   r   )rL   rW   r   re   s       r   r   zextents2d.<locals>.<listcomp>  s"    999HAq1!Q999r   r   r   r   )r   r   r   r   r   rm   r   rb   r   s    r   r   r     ss    x99999LLLH
8}} .HLLOO$$d8<<??&;&;;;,---r   )r   r5   r#   r   )r   r5   r#   r   )
__future__r   typingr   r   r   r   r   r	   rx   rU   numpyr   
ezdxf.mathr
   r   r   r   __all__ABCr   r   r   r~   r   r   r   r   <module>r      s   # " " " " " K K K K K K K K K K K K K K K K 



      ' ' ' ' ' ' ' ' ' 'GCt
A
A
AF8 F8 F8 F8 F8'!*cg F8 F8 F8Rc c c c c%d+ c c cLx x x x x'- x x xv. . . .. . . . . .r   