
    h"                        S SK Jr  S SK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Jr  SSKJr  \R"                  S-  rS	/r " S
 S	5      rSS jrg)    )annotations)SequenceIteratorIterableN)Vec2UVec   )ConstructionRayConstructionLine)BoundingBox2dg       @ConstructionCirclec                      \ rS rSrSrSSS jjrSS j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SS jr S     SS jjr S     SS jjr S     S S jjrSrg)!r      zConstruction tool for 2D circles.

Args:
    center: center point as :class:`Vec2` compatible object
    radius: circle radius > `0`

c                z    [        U5      U l        [        U5      U l        U R                  S::  a  [	        S5      eg )N        zRadius has to be > 0.)r   centerfloatradius
ValueError)selfr   r   s      C/var/www/html/env/lib/python3.13/site-packages/ezdxf/math/circle.py__init__ConstructionCircle.__init__   s5    6lFm;;#455     c                <    SU R                    SU R                   S3$ )zNReturns string representation of circle
"ConstructionCircle(center, radius)".
zConstructionCircle(z, )r   r   )r   s    r   __str__ConstructionCircle.__str__!   s!     %T[[MDKK=BBr   c                F   [        U 5      n[        U5      n[        U5      n[        X45      n[        X55      nUR                  UR                  U5      5      nUR                  UR                  U5      5      n	UR	                  U	5      n
[        XR                  U5      5      $ )z]Creates a circle from three points, all points have to be compatible
to :class:`Vec2` class.
)r   r
   
orthogonallerp	intersectr   distance)p1p2p3_p1_p2_p3ray1ray2center_ray1center_ray2r   s              r   from_3pConstructionCircle.from_3p'   s    
 2h2h2hs(s(oochhsm4oochhsm4&&{3!&//#*>??r   c                    [        U R                  U R                  45      n[        U R                  U-
  U R                  U-   45      $ )z<2D bounding box of circle as  :class:`BoundingBox2d` object.)r   r   r   r   )r   rvecs     r   bounding_boxConstructionCircle.bounding_box6   s=     T[[$++./dkkD0$++2DEFFr   c                B    U =R                   [        X45      -  sl         g)zMove circle 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ConstructionCircle.translate<   s     	tRH~%r   c                \    U R                   [        R                  " XR                  5      -   $ )zReturns point on circle at `angle` as :class:`Vec2` object.

Args:
    angle: angle in radians, angle goes counter
        clockwise around the z-axis, x-axis = 0 deg.

)r   r   
from_angler   )r   angles     r   point_atConstructionCircle.point_atF   s      {{T__UKK@@@r   c              #     #    U R                   nU R                  nU H  nU[        R                  " XC5      -   v   M      g7f)zYields vertices of the circle for iterable `angles`.

Args:
    angles: iterable of angles as radians, angle goes counter-clockwise
        around the z-axis, x-axis = 0 deg.

N)r   r   r   r;   )r   anglesr   r   r<   s        r   verticesConstructionCircle.verticesP   s7      E4??5999 s   >A c              #     #    SSK Jn  U" U R                  [        R                  U5      nU R                  [        R                  " S[        R                  US-   5      5       Sh  vN   g N7f)zApproximate the circle by vertices, argument `sagitta` is the
max. distance from the center of an arc segment to the center of its
chord. Returns a closed polygon where the start vertex is coincident
with the end vertex!
r	   )arc_segment_countr   N)arcrD   r   mathtaurA   nplinspace)r   sagittarD   counts       r   
flatteningConstructionCircle.flattening]   sG      	+!$++txxA==S$((EAI!FGGGs   A$A.&A,'A.c                d    U R                   U R                  R                  [        U5      5      :  $ )z-Returns ``True`` if `point` is inside circle.)r   r   r$   r   )r   points     r   insideConstructionCircle.insideh   s$    {{dkk224;???r   c                r    U R                  U5      n[        U R                  U5      nUR                  U5      $ )zmReturns tangent to circle at `angle` as :class:`ConstructionRay`
object.

Args:
    angle: angle in radians

)r=   r
   r   r!   )r   r<   point_on_circlerays       r   tangentConstructionCircle.tangentl   s1     --.dkk?;~~o..r   c                   [        U[        5      (       d   eUR                  U R                  5      nUR	                  U5      nU R                  R                  U5      n/ nXPR                  :  a  [        R                  " USUS9(       a  UR                  n[        nOTX@R                  -
  R                  n[        R                  " UR                  U R                  5      U R                  -  5      nUR                  U R                  Xx-   5      5        UR                  U R                  Xx-
  5      5        O5[        R                  " XPR                  US9(       a  UR                  U5        [        U5      $ )a  Returns intersection points of circle 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           ray is a tangent to circle
    2           ray intersects with the circle
    =========== ==================================

r   abs_tol)
isinstancer
   r!   r   r#   r$   r   rF   iscloser<   HALF_PIacosappendr=   tuple)	r   rT   rY   	ortho_rayintersection_pointdistresultr<   alphas	            r   intersect_ray ConstructionCircle.intersect_rayx   s   , #////NN4;;/	 ]]95{{##$67++||D#w7! ,kk9@@		&//<t{{J MM$--67MM$--67\\$W=MM,-V}r   c                    [        U[        5      (       d   eU R                  UR                  US9 Vs/ s H-  n[	        UR
                  UR                  U5      (       d  M+  UPM/     sn$ s  snf )a=  Returns intersection points of circle 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 circle at one point
    2           line intersects the circle at two points
    =========== ==================================

rX   )rZ   r   re   rT   is_point_in_line_rangestartend)r   linerY   rO   s       r   intersect_line!ConstructionCircle.intersect_line   sg    , $ 01111 ++DHHg+F
F%djj$((EB F
 	
 
s   *A+"A+c                    [        U[        5      (       d   eU R                  nUR                  nU R                  R	                  UR                  5      nXR:  a
  [        5       $ X4-   n[        R                  " X4-
  5      nXus=::  a  U::  a  O  [        5       $ UR                  U R                  -
  R                  n[        R                  " XVUS9(       a  U R                  U5      4$ [        R                  " XWUS9(       a:  X4:  a  U R                  U5      4$ U R                  U[        R                  -   5      4$ [        R                  " XD-  X3-  -
  XU-  -
  SU-  U-  -  5      n	[        U R                  X-   X-
  45      5      $ [        5       $ )a  Returns intersection points of two circles as sequence of
:class:`Vec2` objects.

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

Returns:
    tuple of :class:`Vec2` objects

    =========== ==================================
    tuple size  Description
    =========== ==================================
    0           no intersection
    1           circle touches the `other` circle at one point
    2           circle intersects with the `other` circle
    =========== ==================================

rX   g       )rZ   r   r   r   r$   r_   rF   fabsr<   r[   r=   pir]   rA   )
r   otherrY   r1r2dd_maxd_minr<   rd   s
             r   intersect_circle#ConstructionCircle.intersect_circle   sC   , %!34444[[\\KK  .;7N		"'" w \\DKK/66E||Ag6e,..||Ag68 MM%022edggo688 		27RW#4qu#<Q"OPT]]EM5=+IJKKwr   r   N)g      ?)r   r   r   r   )returnstr)r%   r   r&   r   r'   r   ry   r   )ry   r   )r6   r   r7   r   ry   None)r<   r   ry   r   )r@   zIterable[float]ry   zIterable[Vec2])rJ   r   ry   zIterator[Vec2])rO   r   ry   bool)r<   r   ry   r
   )g|=)rT   r
   rY   r   ry   Sequence[Vec2])rk   r   rY   r   ry   r}   )rq   z'ConstructionCircle'rY   r   ry   r}   )__name__
__module____qualname____firstlineno____doc__r   r   staticmethodr/   propertyr3   r8   r=   rA   rL   rP   rU   re   rl   rw   __static_attributes__ r   r   r   r      s    6C @ @ G G
&A:	H@
/ 6;.".-2.	.b 8=
$
/4
	
< =B-)-49-	- -r   c                f    X-
  R                   nX -
  R                   U:  a  gX!-
  R                   U:*  $ )NF)	magnitude)ri   rj   rO   lengths       r   rh   rh      s5    k$$F  6)K""f,,r   )ri   r   rj   r   rO   r   ry   r|   )
__future__r   typingr   r   r   rF   numpyrH   
ezdxf.mathr   r   rk   r
   r   bboxr   rp   r\   __all__r   rh   r   r   r   <module>r      sH    # / /   ! 3  ''C-
 ` `F-r   