Ë
    £èh¯#  ã                  ó    — d dl mZ d dlmZmZmZ d dlZd dlZd dl	m
Z
mZ ddlmZmZ ddlmZ ej"                  dz  Zd	gZ G d
„ d	«      Zdd„Zy)é    )Úannotations)ÚSequenceÚIteratorÚIterableN)ÚVec2ÚUVecé   )ÚConstructionRayÚConstructionLine)ÚBoundingBox2dg       @ÚConstructionCirclec                  ó¸   — e Zd ZdZddd„Zdd„Ze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d„Z	 d	 	 	 	 	 dd„Z	 d	 	 	 	 	 dd„Zy)r   z–Construction tool for 2D circles.

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

    c                óx   — t        |«      | _        t        |«      | _        | j                  dk  rt	        d«      ‚y )Nç        zRadius has to be > 0.)r   ÚcenterÚfloatÚradiusÚ
ValueError)Úselfr   r   s      ú1lib/python3.12/site-packages/ezdxf/math/circle.pyÚ__init__zConstructionCircle.__init__   s5   € Ü˜6“lˆŒÜ˜F“mˆŒØ�;‰;˜#ÒÜÐ4Ó5Ð5ð ó    c                ó<   — d| j                   › d| j                  › d�S )z^Returns string representation of circle
        "ConstructionCircle(center, radius)".
        zConstructionCircle(z, Ú))r   r   )r   s    r   Ú__str__zConstructionCircle.__str__!   s!   € ð % T§[¡[ M°°D·K±K°=ÀÐBÐBr   c                óL  — t        | «      }t        |«      }t        |«      }t        ||«      }t        ||«      }|j                  |j                  |«      «      }|j                  |j                  |«      «      }	|j	                  |	«      }
t        |
|
j                  |«      «      S )zmCreates 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_3pzConstructionCircle.from_3p'   s‰   € ô
 �2‹hˆÜ�2‹hˆÜ�2‹hˆÜ˜s CÓ(ˆÜ˜s CÓ(ˆØ—o‘o c§h¡h¨s£mÓ4ˆØ—o‘o c§h¡h¨s£mÓ4ˆØ×&Ñ& {Ó3ˆÜ! &¨&¯/©/¸#Ó*>Ó?Ð?r   c                ó’   — t        | j                  | j                  f«      }t        | j                  |z
  | j                  |z   f«      S )z<2D bounding box of circle as  :class:`BoundingBox2d` object.)r   r   r   r   )r   Úrvecs     r   Úbounding_boxzConstructionCircle.bounding_box6   s=   € ô �T—[‘[ $§+¡+Ð.Ó/ˆÜ˜dŸk™k¨DÑ0°$·+±+ÀÑ2DÐEÓFÐFr   c                óD   — | xj                   t        ||f«      z  c_         y)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   Ú	translatezConstructionCircle.translate<   s   € ð 	�Š”t˜R ˜H“~Ñ%Žr   c                ó\   — | j                   t        j                  || j                  «      z   S )zÉReturns 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_atzConstructionCircle.point_atF   s"   € ð �{‰{œTŸ_™_¨U°D·K±KÓ@Ñ@Ð@r   c              #  ó€   K  — | j                   }| j                  }|D ]  }|t        j                  ||«      z   –— Œ y­w)zÐYields 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   r4   )r   Úanglesr   r   r5   s        r   ÚverticeszConstructionCircle.verticesP   s:   è ø€ ð —‘ˆØ—‘ˆÛˆEØœ4Ÿ?™?¨5°&Ó9Ñ9Ó9ñ ùs   ‚<>c              #  óÞ   K  — ddl m}  || j                  t        j                  |«      }| j                  t        j                  dt        j                  |dz   «      «      E d{  –—†  y7 Œ­w)zýApproximate 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)Úarcr;   r   ÚmathÚtaur9   ÚnpÚlinspace)r   Úsagittar;   Úcounts       r   Ú
flatteningzConstructionCircle.flattening]   sH   è ø€ õ 	+á! $§+¡+¬t¯x©x¸ÓAˆØ—=‘=¤§¡¨S´$·(±(¸EÀA¹IÓ!FÓG×GÒGús   ‚A#A-Á%A+Á&A-c                ód   — | j                   | j                  j                  t        |«      «      k\  S )z-Returns ``True`` if `point` is inside circle.)r   r   r    r   )r   Úpoints     r   ÚinsidezConstructionCircle.insideh   s$   € à�{‰{˜dŸk™k×2Ñ2´4¸³;Ó?Ñ?Ð?r   c                ór   — | j                  |«      }t        | j                  |«      }|j                  |«      S )z�Returns tangent to circle at `angle` as :class:`ConstructionRay`
        object.

        Args:
            angle: angle in radians

        )r6   r
   r   r   )r   r5   Úpoint_on_circleÚrays       r   ÚtangentzConstructionCircle.tangentl   s1   € ð Ÿ-™-¨Ó.ˆÜ˜dŸk™k¨?Ó;ˆØ�~‰~˜oÓ.Ð.r   c                óò  — t        |t        «      sJ ‚|j                  | j                  «      }|j	                  |«      }| j                  j                  |«      }g }|| j                  k  rÐt        j                  |d|¬«      r|j                  }t        }nT|| j                  z
  j                  }t        j                  |j                  | j                  «      | j                  z  «      }|j                  | j                  ||z   «      «       |j                  | j                  ||z
  «      «       t        |«      S t        j                  || j                  |¬«      r|j                  |«       t        |«      S )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   r=   Úiscloser5   ÚHALF_PIÚacosÚappendr6   Útuple)	r   rI   rM   Ú	ortho_rayÚintersection_pointÚdistÚresultr5   Úalphas	            r   Úintersect_rayz ConstructionCircle.intersect_rayx   s%  € ô, ˜#œÔ/Ð/Ð/Ø—N‘N 4§;¡;Ó/ˆ	Ø Ÿ]™]¨9Ó5ÐØ�{‰{×#Ñ#Ð$6Ó7ˆØˆà�$—+‘+Òä�|‰|˜D #¨wÕ7Ø!Ÿ™�Ü‘ð ,¨d¯k©kÑ9×@Ñ@�ÜŸ	™	Ø&×/Ñ/°·±Ó<¸t¿{¹{ÑJó�ð �M‰M˜$Ÿ-™-¨°©Ó6Ô7Ø�M‰M˜$Ÿ-™-¨°©Ó6Ô7ô
 �V‹}Ðô �\‰\˜$ §¡°WÕ=Ø�M‰MÐ,Ô-ä�V‹}Ðr   c                óÈ   — t        |t        «      sJ ‚| j                  |j                  |¬«      D �cg c]%  }t	        |j
                  |j                  |«      r|‘Œ' c}S c c}w )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
            =========== ==================================

        rL   )rN   r   rY   rI   Úis_point_in_line_rangeÚstartÚend)r   ÚlinerM   rE   s       r   Úintersect_linez!ConstructionCircle.intersect_line¨   sd   € ô, ˜$Ô 0Ô1Ð1Ð1ð ×+Ñ+¨D¯H©H¸gÐ+ÔFó
áF�Ü% d§j¡j°$·(±(¸EÔBò ØFñ
ð 	
ùò 
s   ²*Ac                ó  — t        |t        «      sJ ‚| j                  }|j                  }| j                  j	                  |j                  «      }||k  r
t        «       S ||z   }t        j                  ||z
  «      }||cxk  r|k  rún t        «       S |j                  | j                  z
  j                  }t        j                  |||¬«      r| j                  |«      fS t        j                  |||¬«      r:||k\  r| j                  |«      fS | j                  |t        j                  z   «      fS t        j                  ||z  ||z  z
  ||z  z
  d|z  |z  z  «      }	t        | j                  ||	z   ||	z
  f«      «      S t        «       S )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
            =========== ==================================

        rL   g       À)rN   r   r   r   r    rS   r=   Úfabsr5   rO   r6   ÚpirQ   r9   )
r   ÚotherrM   Úr1Úr2ÚdÚd_maxÚd_minr5   rX   s
             r   Úintersect_circlez#ConstructionCircle.intersect_circleÅ   sX  € ô, ˜%Ô!3Ô4Ð4Ð4Ø�[‰[ˆØ�\‰\ˆØ�K‰K× Ñ  §¡Ó.ˆØˆwŠ;ä“7ˆNà�R‘ˆÜ—	‘	˜"˜r™'Ó"ˆØ�AÔ˜Ôô ‹wˆð —\‘\ D§K¡KÑ/×6Ñ6ˆEä�|‰|˜A˜u¨gÕ6ØŸ™ eÓ,Ð.Ð.Ü�|‰|˜A˜u¨gÕ6Ø˜’8Ø ŸM™M¨%Ó0Ð2Ð2ØŸ™ e¬d¯g©g¡oÓ6Ð8Ð8ô Ÿ	™	 2¨¡7¨R°"©WÑ#4°q¸1±uÑ#<ÀÈÁÈQÁÑ"OÓP�Ü˜TŸ]™]¨E°E©M¸5À5¹=Ð+IÓJÓKÐKÜ‹wˆr   N)g      ð?)r   r   r   r   )ÚreturnÚstr)r!   r   r"   r   r#   r   rj   r   )rj   r   )r0   r   r1   r   rj   ÚNone)r5   r   rj   r   )r8   zIterable[float]rj   zIterable[Vec2])rA   r   rj   zIterator[Vec2])rE   r   rj   Úbool)r5   r   rj   r
   )g»½×Ùß|Û=)rI   r
   rM   r   rj   úSequence[Vec2])r^   r   rM   r   rj   rn   )rc   z'ConstructionCircle'rM   r   rj   rn   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ústaticmethodr+   Úpropertyr.   r2   r6   r9   rC   rF   rJ   rY   r_   ri   © r   r   r   r      sÇ   „ ñô6óCð ò@ó ð@ð òGó ðGó
&óAó:ó	Hó@ó
/ð 6;ð.Ø"ð.Ø-2ð.à	ó.ðb 8=ð
Ø$ð
Ø/4ð
à	ó
ð< =Bð-Ø)ð-Ø49ð-à	ô-r   c                ój   — || z
  j                   }|| z
  j                   |kD  ry||z
  j                   |k  S )NF)Ú	magnitude)r\   r]   rE   Úlengths       r   r[   r[   õ   s;   € Ø�E‰k×$Ñ$€FØ�‰× Ñ  6Ò)ØØ�C‰K×"Ñ" fÑ,Ð,r   )r\   r   r]   r   rE   r   rj   rm   )Ú
__future__r   Útypingr   r   r   r=   Únumpyr?   Ú
ezdxf.mathr   r   r^   r
   r   Úbboxr   rb   rP   Ú__all__r   r[   ru   r   r   Ú<module>r      sH   ðõ #ß /Ñ /Û Û ç !ß 3Ý ð �'‰'�C‰-€àÐ
 €÷`ñ `ôF-r   