
    'j!                        d dl mZ d dlmZmZ d dlZd dlmZmZ ddl	m
Z
 ddlmZ ddlmZ d	Zd
gZ G d d
          ZdS )    )annotations)SequenceIterableN)Vec2UVec   )BoundingBox2d)ConstructionLinepoint_to_line_relationg-q=ConstructionBoxc                     e Zd ZdZ	 	 	 	 dAdBdZedCd            ZdDdZedEd            Z	edFd            Z
e
j        dGd            Z
edHd            Zej        dId            ZedHd            Zej        dJd            ZedHd            ZedHd            ZedHd             Zej        dKd"            ZedLd$            ZdMd&ZdFd'ZdNd)ZdOd,ZdPd/ZdQd2ZdRd3ZdSd6ZdTd8ZdTd9ZdUd;ZdVd?Zd@S )Wr   zConstruction tool for 2D rectangles.

    Args:
        center: center of rectangle
        width: width of rectangle
        height: height of rectangle
        angle: angle of rectangle in degrees

    r   r   r   r   centerr   widthfloatheightanglec                    t          |          | _        t          |          | _        t          |          | _        || _        t                      | _        d| _        d S NT)	r   _centerabs_width_height_angletuple_corners_tainted)selfr   r   r   r   s        H/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/math/box.py__init__zConstructionBox.__init__   sH     F|| ZZ!&kk"(-"    p1p2returnc                    t          |          }t          |          }t          |j        |j        z
            }t          |j        |j        z
            }|                    |          } | |||          S )zCreates a box from two opposite corners, box sides are parallel to x-
        and y-axis.

        Args:
            p1: first corner as :class:`Vec2` compatible object
            p2: second corner as :class:`Vec2` compatible object

        )r   r   r   )r   r   xylerp)clsr#   r$   _p1_p2r   r   r   s           r    from_pointszConstructionBox.from_points+   sj     2hh2hh3535=))CECEM**xx}}s&f====r"   Nonec                   | j         sd S | j        }t          j        | j        | j        dz            }t          j        | j        dz   | j        dz            }||z
  |z
  ||z   |z
  ||z   |z   ||z
  |z   f| _        d| _         d S )N       @Z   F)r   r   r   from_deg_angler   r   r   r   )r   r   w2h2s       r    updatezConstructionBox.update<   s    } 	F dkC.?@@ r!14<#3EFFRK"RK"RK"RK"	
 r"   r	   c                *    t          | j                  S )z:class:`BoundingBox2d`)r	   cornersr   s    r    bounding_boxzConstructionBox.bounding_boxJ   s     T\***r"   r   c                    | j         S )z
box center)r   r8   s    r    r   zConstructionBox.centerO        |r"   cc                <    t          |          | _        d| _        d S r   )r   r   r   )r   r<   s     r    r   zConstructionBox.centerT   s    Awwr"   c                    | j         S )z	box width)r   r8   s    r    r   zConstructionBox.widthY        {r"   wc                <    t          |          | _        d| _        d S r   )r   r   r   )r   r@   s     r    r   zConstructionBox.width^   s    !ffr"   c                    | j         S )z
box height)r   r8   s    r    r   zConstructionBox.heightc   r;   r"   hc                <    t          |          | _        d| _        d S r   )r   r   r   )r   rC   s     r    r   zConstructionBox.heighth   s    1vvr"   c                <    t          | j        | j                  dz  S )zincircle radius      ?)minr   r   r8   s    r    incircle_radiuszConstructionBox.incircle_radiusm   s     4;--33r"   c                F    t          j        | j        | j                  dz  S )zcircum circle radiusrF   )mathhypotr   r   r8   s    r    circumcircle_radiusz#ConstructionBox.circumcircle_radiusr   s     z$+t|44s::r"   c                    | j         S )zrotation angle in degrees)r   r8   s    r    r   zConstructionBox.anglew   r?   r"   ac                "    || _         d| _        d S r   )r   r   )r   rN   s     r    r   zConstructionBox.angle|   s    r"   Sequence[Vec2]c                8    |                                   | j        S )z1box corners as sequence of :class:`Vec2` objects.)r5   r   r8   s    r    r7   zConstructionBox.corners   s     	}r"   Iterable[Vec2]c                *    t          | j                  S )z1Iterable of box corners as :class:`Vec2` objects.)iterr7   r8   s    r    __iter__zConstructionBox.__iter__   s    DL!!!r"   c                    | j         |         S )zAGet corner by index `corner`, ``list`` like slicing is supported.)r7   )r   corners     r    __getitem__zConstructionBox.__getitem__   s    |F##r"   strc           	     H    d| j          d| j         d| j         d| j         d	S )zaReturns string representation of box as
        ``ConstructionBox(center, width, height, angle)``zConstructionBox(z, ))r   r   r   r   r8   s    r    __repr__zConstructionBox.__repr__   s6     \$+[[[[t{[[dj[[[[r"   dxdyc                D    | xj         t          ||f          z  c_         dS )zMove box about `dx` in x-axis and about `dy` in y-axis.

        Args:
            dx: translation in x-axis
            dy: translation in y-axis

        N)r   r   )r   r]   r^   s      r    	translatezConstructionBox.translate   s"     	tRH~~%r"   dwdhc                F    | xj         |z  c_         | xj        |z  c_        dS )z2Expand box: `dw` expand width, `dh` expand height.Nr   r   )r   ra   rb   s      r    expandzConstructionBox.expand   &    

b

rr"   swshc                F    | xj         |z  c_         | xj        |z  c_        dS )z1Scale box: `sw` scales width, `sh` scales height.Nrd   )r   rg   rh   s      r    scalezConstructionBox.scale   rf   r"   c                &    | xj         |z  c_         dS )z!Rotate box by `angle` in degrees.N)r   )r   r   s     r    rotatezConstructionBox.rotate   s    

e



r"   pointboolc                   t                    | j        z
  }t          | j                  t          k     r@t          |j                  | j        dz  k    ot          |j                  | j        dz  k    S |j	        }|| j
        k    rdS || j        k    rdS | j        \  }}}}t          fd||f||f||f||ffD                       S )z-Returns ``True`` if `point` is inside of box.r0   FTc              3  H   K   | ]\  }}t          ||          d k     V  dS )r   Nr   ).0rN   brm   s      r    	<genexpr>z,ConstructionBox.is_inside.<locals>.<genexpr>   sL         Aq /ua;;a?     r"   )r   r   r   r   ABS_TOLr'   r   r(   r   	magnituderL   rH   r7   all)r   rm   deltadistancer#   r$   p3p4s    `      r    	is_insidezConstructionBox.is_inside   s    Ue#tz??W$$uw<<DK#$56 3uw<<s"<  H$222uT111t "&BB   &("XBx"bB8$L    r"   otherc                D     t           fd|j        D                       S )zAReturns ``True`` if any corner of `other` box is inside this box.c              3  B   K   | ]}                     |          V  d S )N)r{   )rq   pr   s     r    rs   z7ConstructionBox.is_any_corner_inside.<locals>.<genexpr>   s/      <<4>>!$$<<<<<<r"   )anyr7   )r   r|   s   ` r    is_any_corner_insidez$ConstructionBox.is_any_corner_inside   s(    <<<<em<<<<<<r"   c                F   | j         |j         z
  j        }| j        |j        z   }||k    rdS | j        |j        z   }||k    rdS |                     |          rdS |                    |           rdS | j        \  }}}}t          ||          }	t          ||          }
|j        \  }}}}t          ||          }|                    |	          s|                    |
          rdS t          ||          }|                    |	          s|                    |
          rdS dS )z8Returns ``True`` if this box and `other` box do overlap.FT)r   ru   rL   rH   r   r7   r
   has_intersection)r   r|   rx   max_distancemin_distancec1c2c3c4diag1diag2t1t2t3t4	test_diags                   r    is_overlappingzConstructionBox.is_overlapping   sX   K%,.9/%2KKl""5+e.CC|##4$$U++ 	4%%d++ 	4 BB R(( R((BB$R,,	%%e,, 		0J0J1
 1
 	 4$R,,	%%e,, 		0J0J1
 1
 	 4ur"   Sequence[ConstructionLine]c                    | j         \  }}}}t          ||          t          ||          t          ||          t          ||          fS )zDReturns borderlines of box as sequence of :class:`ConstructionLine`.)r7   r
   )r   r#   r$   ry   rz   s        r    border_lineszConstructionBox.border_lines   sO    BBR$$R$$R$$R$$	
 	
r"   liner
   
list[Vec2]c                    t                      }|                                 D ].}|                    |          }||                    |           /t	          |          S )a?  Returns 0, 1 or 2 intersection points between `line` and box
        borderlines.

        Args:
            line: line to intersect with borderlines

        Returns:
            list of intersection points

            =========== ==================================
            list size   Description
            =========== ==================================
            0           no intersection
            1           line touches box at one corner
            2           line intersects with box
            =========== ==================================

        )setr   	intersectaddsorted)r   r   resultborder_liner   s        r    r   zConstructionBox.intersect   sZ    & ,,.. 	 	K{++A}

1f~~r"   N)r   r   r   r   )r   r   r   r   r   r   r   r   )r#   r   r$   r   r%   r   )r%   r.   )r%   r	   )r%   r   )r<   r   r%   r.   )r%   r   )r@   r   r%   r.   )rC   r   r%   r.   )rN   r   r%   r.   )r%   rP   )r%   rR   )r%   rY   )r]   r   r^   r   r%   r.   )ra   r   rb   r   r%   r.   )rg   r   rh   r   r%   r.   )r   r   r%   r.   )rm   r   r%   rn   )r|   r   r%   rn   )r%   r   )r   r
   r%   r   )__name__
__module____qualname____doc__r!   classmethodr-   r5   propertyr9   r   setterr   r   rH   rL   r   r7   rU   rX   r\   r`   re   rj   rl   r{   r   r   r   r    r"   r    r   r      s         # # # # # > > > [>     + + + X+    X ]   ]    X \   \    X ]   ] 4 4 4 X4 ; ; ; X;    X \   \    X
" " " "$ $ $ $\ \ \ \
& & & &   
   
      0= = = =       D
 
 
 
     r"   )
__future__r   typingr   r   rJ   
ezdxf.mathr   r   bboxr	   r   r
   construct2dr   rt   __all__r   r   r"   r    <module>r      s    # " " " " " % % % % % % % %  ! ! ! ! ! ! ! !       " " " " " " / / / / / / 
{ { { { { { { { { {r"   