
    h9I                    6   S SK Jr  S SKJrJrJrJrJr  S SK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S	KJrJr  SS
KJr  \(       a  S SKJr  S SKJr  / SQrS \R<                  S-  \R<                  \R<                  S-  /r " S S5      r SS jr!SS jr"g)    )annotations)TYPE_CHECKINGIterableSequenceIteratorOptionalN)Vec2UVec   )BoundingBox2d)enclosing_angles)ConstructionCircle)ConstructionRayConstructionLine)UCS)Arc)
BaseLayout)ConstructionArcarc_chord_lengtharc_segment_count      ?g      ?c                  h   \ rS rSrSr     S          S!S jjr\S"S j5       r\S"S j5       r\S#S j5       r	\S$S j5       r
\S%S j5       rS&S	 j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S,S jrS-S jr\S'S j5       r\S'S j5       r\      S.S j5       r\ S/         S0S jj5       r\  S1           S2S jj5       r\ S/         S3S jj5       r S4     S5S jjr S6     S7S jjr S6     S8S jjr S6     S9S jjr  S6     S:S jjr!S;S jr"Sr#g)<r      a   Construction tool for 2D arcs.

:class:`ConstructionArc` represents a 2D arc in the xy-plane, use an
:class:`UCS` to place a DXF :class:`~ezdxf.entities.Arc` entity in 3D space,
see method :meth:`add_to_layout`.

Implements the 2D transformation tools: :meth:`translate`,
:meth:`scale_uniform` and :meth:`rotate_z`

Args:
    center: center point as :class:`Vec2` compatible object
    radius: radius
    start_angle: start angle in degrees
    end_angle: end angle in degrees
    is_counter_clockwise: swaps start- and end angle if ``False``

c                p    [        U5      U l        X l        U(       a  X0l        X@l        g X@l        X0l        g N)r	   centerradiusstart_angle	end_angle)selfr   r   r   r   is_counter_clockwises         @/var/www/html/env/lib/python3.13/site-packages/ezdxf/math/arc.py__init__ConstructionArc.__init__+   s-     6l*&N((N    c                r    U R                   [        R                  " U R                  U R                  5      -   $ )z$start point of arc as :class:`Vec2`.)r   r	   from_deg_angler   r   r    s    r"   start_pointConstructionArc.start_point=   s*     {{T001A1A4;;OOOr%   c                r    U R                   [        R                  " U R                  U R                  5      -   $ )z"end point of arc as :class:`Vec2`.)r   r	   r'   r   r   r(   s    r"   	end_pointConstructionArc.end_pointB   s(     {{T00MMMr%   c                4    U R                   U R                  :  $ )z<Returns ``True`` if the arc passes the x-axis (== 0 degree).r   r   r(   s    r"   is_passing_zeroConstructionArc.is_passing_zeroG   s     $..00r%   c                B    [        U R                  U R                  5      $ r   )r   r   r   r(   s    r"   circleConstructionArc.circleL   s    !$++t{{;;r%   c                    [        U R                  U R                  45      nUR                  U R	                  5       5        U$ )z.bounding box of arc as :class:`BoundingBox2d`.)r   r)   r,   extendmain_axis_points)r    bboxs     r"   bounding_boxConstructionArc.bounding_boxP   s7     d..?@D))+,r%   c              #     #    US:  a  [        S5      eU R                  S-  nU R                  S-  nX2::  a  US-  n[        R                  " X#USS9 H
  nUS-  v   M     g7f)zReturns `num` angles from start- to end angle in degrees in
counter-clockwise order.

All angles are normalized in the range from [0, 360).

   znum >= 2h  T)numendpointN)
ValueErrorr   r   nplinspace)r    r>   startstopangles        r"   anglesConstructionArc.anglesW   sg      7Z((''#-nns*=CKD[[#EE#+ Fs   AA!c                ^    U R                   nXR                  :  a  US-  nXR                  -
  $ )z3Returns angle span of arc from start- to end param.     v@)r   r   )r    ends     r"   
angle_spanConstructionArc.angle_spang   s1     ^^!!!5LC%%%%r%   c              #     #    U R                   nU R                  nU H  nU[        R                  " XC5      -   v   M      g7f)zYields vertices on arc for angles in iterable `a` in WCS as location
vectors.

Args:
    a: angles in the range from 0 to 360 in degrees, arc goes
        counter clockwise around the z-axis, WCS x-axis = 0 deg.

N)r   r   r	   r'   )r    ar   r   rE   s        r"   verticesConstructionArc.verticeso   s9      E4..u=== s   >A c              #    #    [        U R                  5      nUS:  a  U R                  nU R                  n[        R
                  " X45      (       a  gUS-  nUS-  nXC::  a  US-  n[        R                  " XC-
  5      n[        X%U5      nU R                  [        R                  " X4US-   5      5       Sh  vN   gg N7f)zApproximate the arc by vertices in WCS, argument `sagitta` is the
max. distance from the center of an arc segment to the center of its
chord.

r   Nr=   r   )absr   r   r   mathiscloseradiansr   rO   rA   rB   )r    sagittar   rC   rD   rK   counts          r"   
flatteningConstructionArc.flattening~   s      DKK(A:++E..D||E((SLECKD} $T\ :J%f'BE}}R[[eai%HIII  Js   B4B?6B=7B?c              #     #    U HQ  n[         R                  " U5      n[        [         R                  " U5      * [         R                  " U5      45      v   MS     g7f)zYields tangents on arc for angles in iterable `a` in WCS as
direction vectors.

Args:
    a: angles in the range from 0 to 360 in degrees, arc goes
        counter-clockwise around the z-axis, WCS x-axis = 0 deg.

N)rS   rU   r	   sincos)r    rN   rE   rs       r"   tangentsConstructionArc.tangents   sA      E||E*A!dhhqk233 s   AAc              #  2  #    U R                   nU R                  n[        R                  " U R                  5      n[        R                  " U R
                  5      n[         H1  n[        XSU5      (       d  M  U[        R                  " XR5      -   v   M3     g 7fr   )
r   r   rS   rU   r   r   QUARTER_ANGLESr   r	   
from_angle)r    r   r   rC   rJ   rE   s         r"   r7    ConstructionArc.main_axis_points   sh     {{||D$4$45\\$..1#Ec22tu=== $s   A1B7 Bc                B    U =R                   [        X5      -  sl         U $ )zMove arc about `dx` in x-axis and about `dy` in y-axis, returns
`self` (floating interface).

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

)r   r	   )r    dxdys      r"   	translateConstructionArc.translate   s     	tB|#r%   c                B    U =R                   [        U5      -  sl         U $ )z[Scale arc inplace uniform about `s` in x- and y-axis, returns
`self` (floating interface).
)r   float)r    ss     r"   scale_uniformConstructionArc.scale_uniform   s     	uQxr%   c                Z    U =R                   U-  sl         U =R                  U-  sl        U $ )zsRotate arc inplace about z-axis, returns `self`
(floating interface).

Args:
    angle: rotation angle in degrees

r/   )r    rE   s     r"   rotate_zConstructionArc.rotate_z   s(     	E!%r%   c                B    [         R                  " U R                  5      $ )z#Returns the start angle in radians.)rS   rU   r   r(   s    r"   start_angle_radConstructionArc.start_angle_rad   s     ||D,,--r%   c                B    [         R                  " U R                  5      $ )z!Returns the end angle in radians.)rS   rU   r   r(   s    r"   end_angle_radConstructionArc.end_angle_rad   s     ||DNN++r%   c                T    [        U 5      n [        U5      nX:X  a  [        S5      eX4$ )Nz1Start- and end point have to be different points.)r	   r@   )r)   r,   s     r"   validate_start_and_end_point,ConstructionArc.validate_start_and_end_point   s2     ;'O	#PQQ%%r%   c                   U R                  X5      u  pV[        R                  " U5      nUS:X  a  [        S5      eUSL a  XepeUS-  nUR	                  U5      nUS-  n	U	[        R
                  " U5      -  n
U	[        R                  " U5      -  nUR                  USS9nXe-
  nUR                  5       R                  U5      nX-   n[        UU
X_-
  R                  Xo-
  R                  SS9$ )	a  Create arc from two points and enclosing angle. Additional
precondition: arc goes by default in counter-clockwise orientation from
`start_point` to `end_point`, can be changed by `ccw` = ``False``.

Args:
    start_point: start point as :class:`Vec2` compatible object
    end_point: end point as :class:`Vec2` compatible object
    angle: enclosing angle in degrees
    ccw: counter-clockwise direction if ``True``

r   zAngle can not be 0.F       @r   factorTr   r   r   r   r!   )rx   rS   rU   r@   distancer[   tanlerp
orthogonal	normalizer   	angle_deg)clsr)   r,   rE   ccw_start_point
_end_pointalpha2r   	distance2r   height	mid_pointdistance_vectorheight_vectorr   s                   r"   from_2p_angleConstructionArc.from_2p_angle   s    & $'#C#C$
  U#A:233%<'1*$--l;#c>	!DHHV$44!DHHV$44$//,s/C	 * 9-88:DDVL 0%.99!*55!%
 	
r%   c                   U R                  X5      u  pg[        U5      nUS::  a  [        S5      eUSL a  XvpvUR                  USS9nUR	                  U5      n	U	S-  n
[
        R                  " US-  U
S-  -
  5      nXU-
  R                  US9R                  U5      -   n[        UUXl-
  R                  X|-
  R                  S	S
9$ )a  Create arc from two points and arc radius.
Additional precondition: arc goes by default in counter-clockwise
orientation from `start_point` to `end_point` can be changed
by `ccw` = ``False``.

The parameter `center_is_left` defines if the center of the arc is
left or right of the line from `start_point` to `end_point`.
Parameter `ccw` = ``False`` swaps start- and end point, which also
inverts the meaning of ``center_is_left``.

Args:
    start_point: start point as :class:`Vec2` compatible object
    end_point: end point as :class:`Vec2` compatible object
    radius: arc radius
    ccw: counter-clockwise direction if ``True``
    center_is_left: center point of arc is left of line from start- to
        end point if ``True``

r   zRadius has to be > 0.Fr   r|   r{   r<   )r   Tr~   )rx   rj   r@   r   r   rS   sqrtr   r   r   r   )r   r)   r,   r   r   center_is_leftr   r   r   r   r   r   r   s                r"   from_2p_radiusConstructionArc.from_2p_radius	  s    8 $'#C#C$
  vQ;455%<'1*$//,s/C	$--l;#c>			&!)il":; $=#I#I $J $

)F
 %.99!*55!%
 	
r%   c                   U R                  X5      u  p[        U5      nX1:X  d  X2:X  a  [        S5      e[        R                  " XU5      n[        UR
                  5      n[        UUR                  X-
  R                  X&-
  R                  US9$ )a  Create arc from three points.
Additional precondition: arc goes in counter-clockwise
orientation from `start_point` to `end_point`.

Args:
    start_point: start point as :class:`Vec2` compatible object
    end_point: end point as :class:`Vec2` compatible object
    def_point: additional definition point as :class:`Vec2` compatible
        object
    ccw: counter-clockwise direction if ``True``

z5def_point has to be different to start- and end pointr~   )	rx   r	   r@   r   from_3pr   r   r   r   )r   r)   r,   	def_pointr   r3   r   s          r"   r   ConstructionArc.from_3p>  s    ( "%!A!A"
 O	#y'=TUU#++KINfmm$==$-88 )44!$
 	
r%   Nc                    UR                  U R                  U R                  U R                  U R                  US9nUc  U$ UR                  UR                  5      $ )a  Add arc as DXF :class:`~ezdxf.entities.Arc` entity to a layout.

Supports 3D arcs by using an :ref:`UCS`. An :class:`ConstructionArc` is
always defined in the xy-plane, but by using an arbitrary UCS, the arc
can be placed in 3D space, automatically OCS transformation included.

Args:
    layout: destination layout as :class:`~ezdxf.layouts.BaseLayout`
        object
    ucs: place arc in 3D space by :class:`~ezdxf.math.UCS` object
    dxfattribs: additional DXF attributes for the ARC entity

)r   r   r   r   
dxfattribs)add_arcr   r   r   r   	transformmatrix)r    layoutucsr   arcs        r"   add_to_layoutConstructionArc.add_to_layoutc  sV      nn;;;;((nn!  
 ks@s}}SZZ'@@r%   c                    [        U[        5      (       d   eU R                  R                  X5       Vs/ s H  nU R	                  U5      (       d  M  UPM     sn$ s  snf )a1  Returns intersection points of arc and `ray` as sequence of
:class:`Vec2` objects.

Args:
    ray: intersection ray
    abs_tol: absolute tolerance for tests (e.g. test for tangents)

Returns:
    tuple of :class:`Vec2` objects

    =========== ==================================
    tuple size  Description
    =========== ==================================
    0           no intersection
    1           line intersects or touches the arc at one point
    2           line intersects the arc at two points
    =========== ==================================

)
isinstancer   r3   intersect_ray_is_point_in_arc_range)r    rayabs_tolpoints       r"   r   ConstructionArc.intersect_ray|  s[    , #//// 223@
@**51 @
 	
 
   AAc                    [        U[        5      (       d   eU R                  R                  X5       Vs/ s H  nU R	                  U5      (       d  M  UPM     sn$ s  snf )a4  Returns intersection points of arc and `line` as sequence of
:class:`Vec2` objects.

Args:
    line: intersection line
    abs_tol: absolute tolerance for tests (e.g. test for tangents)

Returns:
    tuple of :class:`Vec2` objects

    =========== ==================================
    tuple size  Description
    =========== ==================================
    0           no intersection
    1           line intersects or touches the arc at one point
    2           line intersects the arc at two points
    =========== ==================================

)r   r   r3   intersect_liner   )r    liner   r   s       r"   r   ConstructionArc.intersect_line  s\    , $ 01111 33DB
B**51 B
 	
 
r   c                    [        U[        5      (       d   eU R                  R                  X5       Vs/ s H  nU R	                  U5      (       d  M  UPM     sn$ s  snf )a%  Returns intersection points of arc and `circle` as sequence of
:class:`Vec2` objects.

Args:
    circle: intersection circle
    abs_tol: absolute tolerance for tests

Returns:
    tuple of :class:`Vec2` objects

    =========== ==================================
    tuple size  Description
    =========== ==================================
    0           no intersection
    1           circle intersects or touches the arc at one point
    2           circle intersects the arc at two points
    =========== ==================================

)r   r   r3   intersect_circler   )r    r3   r   r   s       r"   r    ConstructionArc.intersect_circle  s\    , &"45555 55fF
F**51 F
 	
 
r   c                   [        U[        5      (       d   eU R                  R                  UR                  U5       Vs/ s H5  nU R	                  U5      (       d  M  UR	                  U5      (       d  M3  UPM7     sn$ s  snf )a%  Returns intersection points of two arcs as sequence of
:class:`Vec2` objects.

Args:
    other: other intersection arc
    abs_tol: absolute tolerance for tests

Returns:
    tuple of :class:`Vec2` objects

    =========== ==================================
    tuple size  Description
    =========== ==================================
    0           no intersection
    1           other arc intersects or touches the arc at one point
    2           other arc intersects the arc at two points
    =========== ==================================

)r   r   r3   r   r   )r    otherr   r   s       r"   intersect_arcConstructionArc.intersect_arc  sv    , %1111 55ellGL
L**51  ,,U3 L
 	
 
s    A?A?6A?c                    U R                   S-  nU R                  S-  nXR                  -
  R                  S-  nX#:  a  XB:  =(       d    XC:*  $ X$s=:*  =(       a    U:*  $ s  $ )NrI   )r   r   r   r   )r    r   rC   rJ   rE   s        r"   r   &ConstructionArc._is_point_in_arc_range  sd     ''%/^^e++66>;>1U\1$$$$$$r%   )r   r   r   r   ))r   r   g      ?        rI   T)
r   r
   r   rj   r   rj   r   rj   r!   zOptional[bool])returnr	   )r   bool)r   r   )r   r   )r>   intr   Iterable[float])r   rj   )rN   r   r   Iterable[Vec2])rV   rj   r   r   )r   zIterator[Vec2])re   rj   rf   rj   r   r   )rk   rj   r   r   )rE   rj   r   r   )r)   r
   r,   r
   r   ztuple[Vec2, Vec2])T)
r)   r
   r,   r
   rE   rj   r   r   r   r   )TT)r)   r
   r,   r
   r   rj   r   r   r   r   r   r   )
r)   r
   r,   r
   r   r
   r   r   r   r   )NN)r   r   r   zOptional[UCS]r   r   )g|=)r   r   r   rj   r   Sequence[Vec2])r   r   r   rj   r   r   )r3   r   r   rj   r   r   )r   r   r   rj   r   r   )r   r	   r   r   )$__name__
__module____qualname____firstlineno____doc__r#   propertyr)   r,   r0   r3   r9   rF   rK   rO   rX   r^   r7   rg   rl   ro   rr   ru   staticmethodrx   classmethodr   r   r   r   r   r   r   r   r   __static_attributes__ r%   r"   r   r      s   (   /3)) ) 	)
 ) -)$ P P N N 1 1 < <    & &>J(4>

 . . , , &&&*&	& &  +
+
 +
 	+

 +
 
+
 +
Z  #2
2
 2
 	2

 2
 2
 
2
 2
h  "
"
 "
 	"

 "
 
"
 "
J IMA A'4A	A4 6;
"
-2
	
< 8=
$
/4
	
< <A
(
38
	
< 8=
$
/4
	
<%r%   r   c                l     S[         R                  " SU -  U-  X-  -
  5      -  $ ! [         a     gf = f)zReturns the chord length for an arc defined by `radius` and
the `sagitta`_.

Args:
    radius: arc radius
    sagitta: distance from the center of the arc to the center of its base

r{   r   )rS   r   r@   )r   rV   s     r"   r   r     s>    TYYsV|g58IIJJJ s   #& 
33c                     [        X5      n[        R                  " US-  U -  5      S-  n[        R                  " X-  5      $ ! [        [
        4 a     gf = f)a  Returns the count of required segments for the approximation
of an arc for a given maximum `sagitta`_.

Args:
    radius: arc radius
    angle: angle span of the arc in radians
    sagitta: max. distance from the center of an arc segment to the
        center of its chord

r{   r   )r   rS   asinceilr@   ZeroDivisionError)r   rE   rV   chord_lengthalphas        r"   r   r     sW    .v?yy!3f!<=Cyy'')* s   AA AA)r   rj   rV   rj   r   rj   )r   rj   rE   rj   rV   rj   r   r   )#
__future__r   typingr   r   r   r   r   rS   numpyrA   
ezdxf.mathr	   r
   r8   r   construct2dr   r3   r   r   r   r   r   r   ezdxf.entitiesr   ezdxf.layoutsr   __all__pira   r   r   r   r   r%   r"   <module>r      so    # H H   !  ) & 3 "(
FTWWs]DGGTWWs];a% a%Hr%   