
    Og!                    z    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y)    )annotations)SequenceIterableN)Vec2UVec   )BoundingBox2d)ConstructionLinepoint_to_line_relationg-q=ConstructionBoxc                     e Zd ZdZ	 	 	 	 d	 	 	 	 	 	 	 ddZed d       Zd!dZed"d       Z	ed#d       Z
e
j                  d$d       Z
ed%d       Zej                  d&d	       Zed%d
       Zej                  d'd       Zed%d       Zed%d       Zed%d       Zej                  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/dZd0dZd1dZd1dZd2dZd3dZy)4r   zConstruction tool for 2D rectangles.

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

    c                    t        |      | _        t        |      | _        t        |      | _        || _        t               | _        d| _        y NT)	r   _centerabs_width_height_angletuple_corners_tainted)selfcenterwidthheightangles        S/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/math/box.py__init__zConstructionBox.__init__   s<     F| Z!&k"(-"    c                    t        |      }t        |      }t        |j                  |j                  z
        }t        |j                  |j                  z
        }|j	                  |      } | |||      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)clsp1p2_p1_p2r   r   r   s           r   from_pointszConstructionBox.from_points+   s^     2h2h355355=)CEECEEM*xx}&f==r    c                D   | j                   sy | 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| _         y )N       @Z   F)r   r   r   from_deg_angler   r   r   r   )r   r   w2h2s       r   updatezConstructionBox.update<   s    }}  dkkC.?@  r!14<<#3EFRK"RK"RK"RK"	
 r    c                ,    t        | j                        S )z:class:`BoundingBox2d`)r	   cornersr   s    r   bounding_boxzConstructionBox.bounding_boxJ   s     T\\**r    c                    | j                   S )z
box center)r   r4   s    r   r   zConstructionBox.centerO        ||r    c                2    t        |      | _        d| _        y r   )r   r   r   )r   cs     r   r   zConstructionBox.centerT   s    Awr    c                    | j                   S )z	box width)r   r4   s    r   r   zConstructionBox.widthY        {{r    c                2    t        |      | _        d| _        y r   )r   r   r   )r   ws     r   r   zConstructionBox.width^   s    !fr    c                    | j                   S )z
box height)r   r4   s    r   r   zConstructionBox.heightc   r7   r    c                2    t        |      | _        d| _        y r   )r   r   r   )r   hs     r   r   zConstructionBox.heighth   s    1vr    c                H    t        | j                  | j                        dz  S )zincircle radius      ?)minr   r   r4   s    r   incircle_radiuszConstructionBox.incircle_radiusm   s     4;;-33r    c                \    t        j                  | j                  | j                        dz  S )zcircum circle radiusrB   )mathhypotr   r   r4   s    r   circumcircle_radiusz#ConstructionBox.circumcircle_radiusr   s"     zz$++t||4s::r    c                    | j                   S )zrotation angle in degrees)r   r4   s    r   r   zConstructionBox.anglew   r;   r    c                     || _         d| _        y r   )r   r   )r   as     r   r   zConstructionBox.angle|   s    r    c                :    | j                          | j                  S )z1box corners as sequence of :class:`Vec2` objects.)r1   r   r4   s    r   r3   zConstructionBox.corners   s     	}}r    c                ,    t        | j                        S )z1Iterable of box corners as :class:`Vec2` objects.)iterr3   r4   s    r   __iter__zConstructionBox.__iter__   s    DLL!!r    c                     | j                   |   S )zAGet corner by index `corner`, ``list`` like slicing is supported.)r3   )r   corners     r   __getitem__zConstructionBox.__getitem__   s    ||F##r    c           	     p    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   r4   s    r   __repr__zConstructionBox.__repr__   s6     "$++bBt{{m2djj\YZ[[r    c                D    | xj                   t        ||f      z  c_         y)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   dxdys      r   	translatezConstructionBox.translate   s     	tRH~%r    c                X    | xj                   |z  c_         | xj                  |z  c_        y)z2Expand box: `dw` expand width, `dh` expand height.Nr   r   )r   dwdhs      r   expandzConstructionBox.expand       

b
rr    c                X    | xj                   |z  c_         | xj                  |z  c_        y)z1Scale box: `sw` scales width, `sh` scales height.Nr[   )r   swshs      r   scalezConstructionBox.scale   r_   r    c                .    | xj                   |z  c_         y)z!Rotate box by `angle` in degrees.N)r   )r   r   s     r   rotatezConstructionBox.rotate   s    

e
r    c                   t              | j                  z
  }t        | j                        t        k  rLt        |j
                        | j                  dz  k  xr% t        |j                        | j                  dz  k  S |j                  }|| j                  kD  ry|| j                  k  ry| j                  \  }}}}t        fd||f||f||f||ffD              S )z-Returns ``True`` if `point` is inside of box.r,   FTc              3  D   K   | ]  \  }}t        ||      d k    yw)r   Nr   ).0rK   bpoints      r   	<genexpr>z,ConstructionBox.is_inside.<locals>.<genexpr>   s+       Aq /ua;a?s    )r   r   r   r   ABS_TOLr"   r   r#   r   	magnituderH   rD   r3   all)r   rj   deltadistancer&   r'   p3p4s    `      r   	is_insidezConstructionBox.is_inside   s    Ue#tzz?W$uww<DKK#$56 3uww<s"<  H$222T111 "&BB&("XBx"bB8$L r    c                @     t         fd|j                  D              S )zAReturns ``True`` if any corner of `other` box is inside this box.c              3  @   K   | ]  }j                  |        y w)N)rs   )rh   pr   s     r   rk   z7ConstructionBox.is_any_corner_inside.<locals>.<genexpr>   s     <4>>!$<s   )anyr3   )r   others   ` r   is_any_corner_insidez$ConstructionBox.is_any_corner_inside   s    <emm<<<r    c                >   | j                   |j                   z
  j                  }| j                  |j                  z   }||kD  ry| j                  |j                  z   }||k  ry| j	                  |      ry|j	                  |       ry| j
                  \  }}}}t        ||      }	t        ||      }
|j
                  \  }}}}t        ||      }|j                  |	      s|j                  |
      ryt        ||      }|j                  |	      s|j                  |
      ryy)z8Returns ``True`` if this box and `other` box do overlap.FT)r   rm   rH   rD   ry   r3   r
   has_intersection)r   rx   rp   max_distancemin_distancec1c2c3c4diag1diag2t1t2t3t4	test_diags                   r   is_overlappingzConstructionBox.is_overlapping   s   KK%,,.99//%2K2KKl"++e.C.CC|#$$U+%%d+ BB R( R(BB$R,	%%e,	0J0J1
 $R,	%%e,	0J0J1
 r    c                    | j                   \  }}}}t        ||      t        ||      t        ||      t        ||      fS )zDReturns borderlines of box as sequence of :class:`ConstructionLine`.)r3   r
   )r   r&   r'   rq   rr   s        r   border_lineszConstructionBox.border_lines   sE    BBR$R$R$R$	
 	
r    c                    t               }| j                         D ]'  }|j                  |      }||j                  |       ) 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   lineresultborder_linerv   s        r   r   zConstructionBox.intersect   sM    & ,,. 	K{+A}

1	 f~r    N))r   r   r   r   r   )r   r   r   floatr   r   r   r   )r&   r   r'   r   returnr   )r   None)r   r	   )r   r   )r9   r   r   r   )r   r   )r=   r   r   r   )r@   r   r   r   )rK   r   r   r   )r   zSequence[Vec2])r   zIterable[Vec2])r   str)rW   r   rX   r   r   r   )r\   r   r]   r   r   r   )ra   r   rb   r   r   r   )r   r   r   r   )rj   r   r   bool)rx   r   r   r   )r   zSequence[ConstructionLine])r   r
   r   z
list[Vec2])__name__
__module____qualname____doc__r   classmethodr*   r1   propertyr5   r   setterr   r   rD   rH   r   r3   rO   rR   rU   rY   r^   rc   re   rs   ry   r   r   r    r    r   r   r      s    ## # 	#
 # > >  + +   ]]    \\    ]]  4 4 ; ;   \\   
"$\
&

0= D
r    )
__future__r   typingr   r   rF   
ezdxf.mathr   r   bboxr	   r   r
   construct2dr   rl   __all__r   r   r    r   <module>r      s7    # %  !  " / 
{ {r    