
    h!                    z    S SK Jr  S SKJrJr  S SKrS SKJrJr  SSK	J
r
  SSKJr  SSKJr  S	rS
/r " S S
5      rg)    )annotations)SequenceIterableN)Vec2UVec   )BoundingBox2d)ConstructionLinepoint_to_line_relationg-q=ConstructionBoxc                     \ 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5       r
\	S%S j5       r\R                  S&S j5       r\	S'S	 j5       r\R                  S(S
 j5       r\	S'S j5       r\R                  S)S j5       r\	S'S j5       r\	S'S j5       r\	S'S j5       r\R                  S*S j5       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S0S jrS1S jrS2S jrS3S jrS3S jrS4S jrS5S jrSrg)6r      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                    [        U5      U l        [        U5      U l        [        U5      U l        X@l        [        5       U l        SU l        g NT)	r   _centerabs_width_height_angletuple_corners_tainted)selfcenterwidthheightangles        @/var/www/html/env/lib/python3.13/site-packages/ezdxf/math/box.py__init__ConstructionBox.__init__   s:     F| Z!&k"(-"    c                    [        U5      n[        U5      n[        UR                  UR                  -
  5      n[        UR                  UR                  -
  5      nUR	                  U5      nU " XuUS9$ )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_pointsConstructionBox.from_points+   s\     2h2h355355=)CEECEEM*xx}&f==r"   c                J   U R                   (       d  g U R                  n[        R                  " U R                  U R
                  S-  5      n[        R                  " U R                  S-   U R                  S-  5      nX-
  U-
  X-   U-
  X-   U-   X-
  U-   4U l        SU l         g )N       @Z   F)r   r   r   from_deg_angler   r   r   r   )r   r   w2h2s       r   updateConstructionBox.update<   s    }}  dkkC.?@  r!14<<#3EFK"K"K"K"	
 r"   c                ,    [        U R                  5      $ )z:class:`BoundingBox2d`)r	   cornersr   s    r   bounding_boxConstructionBox.bounding_boxJ   s     T\\**r"   c                    U R                   $ )z
box center)r   r8   s    r   r   ConstructionBox.centerO        ||r"   c                2    [        U5      U l        SU l        g r   )r   r   r   )r   cs     r   r   r<   T   s    Awr"   c                    U R                   $ )z	box width)r   r8   s    r   r   ConstructionBox.widthY        {{r"   c                2    [        U5      U l        SU l        g r   )r   r   r   )r   ws     r   r   rA   ^   s    !fr"   c                    U R                   $ )z
box height)r   r8   s    r   r   ConstructionBox.heightc   r=   r"   c                2    [        U5      U l        SU l        g r   )r   r   r   )r   hs     r   r   rF   h   s    1vr"   c                H    [        U R                  U R                  5      S-  $ )zincircle radius      ?)minr   r   r8   s    r   incircle_radiusConstructionBox.incircle_radiusm   s     4;;-33r"   c                ^    [         R                  " U R                  U R                  5      S-  $ )zcircum circle radiusrJ   )mathhypotr   r   r8   s    r   circumcircle_radius#ConstructionBox.circumcircle_radiusr   s"     zz$++t||4s::r"   c                    U R                   $ )zrotation angle in degrees)r   r8   s    r   r   ConstructionBox.anglew   rB   r"   c                    Xl         SU l        g r   )r   r   )r   as     r   r   rT   |   s    r"   c                :    U R                  5         U R                  $ )z1box corners as sequence of :class:`Vec2` objects.)r4   r   r8   s    r   r7   ConstructionBox.corners   s     	}}r"   c                ,    [        U R                  5      $ )z1Iterable of box corners as :class:`Vec2` objects.)iterr7   r8   s    r   __iter__ConstructionBox.__iter__   s    DLL!!r"   c                     U R                   U   $ )zAGet corner by index `corner`, ``list`` like slicing is supported.)r7   )r   corners     r   __getitem__ConstructionBox.__getitem__   s    ||F##r"   c           	     p    SU R                    SU R                   SU R                   SU R                   S3	$ )zYReturns string representation of box as
``ConstructionBox(center, width, height, angle)``zConstructionBox(z, ))r   r   r   r   r8   s    r   __repr__ConstructionBox.__repr__   s6     "$++bBt{{m2djj\YZ[[r"   c                B    U =R                   [        X45      -  sl         g)z|Move 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   	translateConstructionBox.translate   s     	tRH~%r"   c                X    U =R                   U-  sl         U =R                  U-  sl        g)z2Expand box: `dw` expand width, `dh` expand height.Nr   r   )r   dwdhs      r   expandConstructionBox.expand       

b
rr"   c                X    U =R                   U-  sl         U =R                  U-  sl        g)z1Scale box: `sw` scales width, `sh` scales height.Nrk   )r   swshs      r   scaleConstructionBox.scale   rp   r"   c                .    U =R                   U-  sl         g)z!Rotate box by `angle` in degrees.N)r   )r   r   s     r   rotateConstructionBox.rotate   s    

e
r"   c                  ^ [        T5      mU R                  T-
  n[        U R                  5      [        :  aQ  [        UR
                  5      U R                  S-  :*  =(       a%    [        UR                  5      U R                  S-  :*  $ UR                  nX0R                  :  a  gX0R                  ::  a  gU R                  u  pEpg[        U4S jXE4XV4Xg4Xt44 5       5      $ )z-Returns ``True`` if `point` is inside of box.r/   FTc              3  F   >#    U  H  u  p[        TX5      S :  v   M     g7f)r   Nr   ).0rV   bpoints      r   	<genexpr>,ConstructionBox.is_inside.<locals>.<genexpr>   s&      $LDA /ua;a?$L   !)r   r   r   r   ABS_TOLr$   r   r%   r   	magnituderQ   rL   r7   all)r   r}   deltadistancer(   r)   p3p4s    `      r   	is_insideConstructionBox.is_inside   s    Ue#tzz?W$uww<DKK#$56 3uww<s"<  H222111 "&&(Xx"B8$L r"   c                B   ^  [        U 4S jUR                   5       5      $ )zAReturns ``True`` if any corner of `other` box is inside this box.c              3  F   >#    U  H  nTR                  U5      v   M     g 7f)N)r   )r{   pr   s     r   r~   7ConstructionBox.is_any_corner_inside.<locals>.<genexpr>   s     <m4>>!$$mr   )anyr7   )r   others   ` r   is_any_corner_inside$ConstructionBox.is_any_corner_inside   s    <emm<<<r"   c                j   U R                   UR                   -
  R                  nU R                  UR                  -   nX#:  a  gU R                  UR                  -   nX$::  a  gU R	                  U5      (       a  gUR	                  U 5      (       a  gU R
                  u  pVpx[        XW5      n	[        Xh5      n
UR
                  u  pp[        X5      nUR                  U	5      (       d  UR                  U
5      (       a  g[        X5      nUR                  U	5      (       d  UR                  U
5      (       a  gg)z8Returns ``True`` if this box and `other` box do overlap.FT)r   r   rQ   rL   r   r7   r
   has_intersection)r   r   r   max_distancemin_distancec1c2c3c4diag1diag2t1t2t3t4	test_diags                   r   is_overlappingConstructionBox.is_overlapping   s   KK%,,.99//%2K2KK"++e.C.CC#$$U++%%d++  ( ($R,	%%e,,	0J0J1
 1
 $R,	%%e,,	0J0J1
 1
 r"   c                t    U R                   u  pp4[        X5      [        X#5      [        X45      [        XA5      4$ )zDReturns borderlines of box as sequence of :class:`ConstructionLine`.)r7   r
   )r   r(   r)   r   r   s        r   border_linesConstructionBox.border_lines   s9    R$R$R$R$	
 	
r"   c                    [        5       nU R                  5        H*  nUR                  U5      nUc  M  UR                  U5        M,     [	        U5      $ )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_liner   s        r   r   ConstructionBox.intersect   sH    & ,,.K{+A}

1 / f~r"   )r   r   r   r   r   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   )r?   r   r   r   )r   r   )rD   r   r   r   )rH   r   r   r   )rV   r   r   r   )r   zSequence[Vec2])r   zIterable[Vec2])r   str)rf   r   rg   r   r   r   )rl   r   rm   r   r   r   )rr   r   rs   r   r   r   )r   r   r   r   )r}   r   r   bool)r   r   r   r   )r   zSequence[ConstructionLine])r   r
   r   z
list[Vec2]) __name__
__module____qualname____firstlineno____doc__r    classmethodr,   r4   propertyr9   r   setterr   r   rL   rQ   r   r7   r[   r_   rc   rh   rn   rt   rw   r   r   r   r   r   __static_attributes__ r"   r   r   r      s    ## # 	#
 # > >  + +   ]]    \\    ]]  4 4 ; ;   \\   
"$\
&

0= D
r"   )
__future__r   typingr   r   rO   
ezdxf.mathr   r   bboxr	   r   r
   construct2dr   r   __all__r   r   r"   r   <module>r      s7    # %  !  " / 
{ {r"   