
    'j"                        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dS )    )annotations)SequenceIteratorIterableN)Vec2UVec   )ConstructionRayConstructionLine)BoundingBox2dg       @ConstructionCirclec                      e Zd ZdZd0d1dZd2d
Zed3d            Zed4d            Z	d5dZ
d6dZd7dZd8dZd9d!Zd:d#Z	 d;d<d(Z	 d;d=d+Z	 d;d>d.Zd/S )?r   zConstruction tool for 2D circles.

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

          ?centerr   radiusfloatc                    t          |          | _        t          |          | _        | j        dk    rt	          d          d S )N        zRadius has to be > 0.)r   r   r   r   
ValueError)selfr   r   s      K/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/math/circle.py__init__zConstructionCircle.__init__   s@    6llFmm;#4555     returnstrc                (    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"     CT[BBDKBBBBr   p1p2p3c                   t          |           }t          |          }t          |          }t          ||          }t          ||          }|                    |                    |                    }|                    |                    |                    }	|                    |	          }
t          |
|
                    |                    S )zmCreates a circle from three points, all points have to be compatible
        to :class:`Vec2` class.
        )r   r
   
orthogonallerp	intersectr   distance)r   r    r!   _p1_p2_p3ray1ray2center_ray1center_ray2r   s              r   from_3pzConstructionCircle.from_3p'   s    
 2hh2hh2hhsC((sC((oochhsmm44oochhsmm44&&{33!&&//#*>*>???r   r   c                z    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[$+.//dkD0$+2DEFFFr   dxdyNonec                D    | xj         t          ||f          z  c_         dS )zMove 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   r2   r3   s      r   	translatezConstructionCircle.translate<   s"     	tRH~~%r   angler   c                F    | j         t          j        || j                  z   S )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   r7   s     r   point_atzConstructionCircle.point_atF   s     {T_UDK@@@@r   anglesIterable[float]Iterable[Vec2]c              #  d   K   | j         }| j        }|D ]}|t          j        ||          z   V  dS )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   r9   )r   r;   r   r   r7   s        r   verticeszConstructionCircle.verticesP   sO        	: 	:E4?5&9999999	: 	:r   sagittaIterator[Vec2]c              #     K   ddl m}  || j        t          j        |          }|                     t          j        dt          j        |dz                       E d{V  dS )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)arcrC   r   mathtaur?   nplinspace)r   r@   rC   counts       r   
flatteningzConstructionCircle.flattening]   sp       	+*****!!$+txAA==S$(EAI!F!FGGGGGGGGGGGr   pointboolc                b    | j         | j                            t          |                    k    S )z-Returns ``True`` if `point` is inside circle.)r   r   r&   r   )r   rK   s     r   insidezConstructionCircle.insideh   s%    {dk224;;????r   r
   c                    |                      |          }t          | j        |          }|                    |          S )zReturns tangent to circle at `angle` as :class:`ConstructionRay`
        object.

        Args:
            angle: angle in radians

        )r:   r
   r   r#   )r   r7   point_on_circlerays       r   tangentzConstructionCircle.tangentl   s8     --..dk?;;~~o...r   绽|=rQ   abs_tolSequence[Vec2]c                   t          |t                    sJ |                    | j                  }|                    |          }| j                            |          }g }|| j        k     rt          j        |d|          r|j	        }t          }nC|| j        z
  j	        }t          j        |                    | j                  | j        z            }|                    |                     ||z                        |                    |                     ||z
                       n1t          j        || j        |          r|                    |           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   rT   )
isinstancer
   r#   r   r%   r&   r   rE   iscloser7   HALF_PIacosappendr:   tuple)	r   rQ   rT   	ortho_rayintersection_pointdistresultr7   alphas	            r   intersect_rayz ConstructionCircle.intersect_rayx   sM   , #/////NN4;//	 ]]955{##$677$+|D#w777 	! ,dk9@	&//<<t{J  MM$--66777MM$--667777\$W=== 	.MM,---V}}r   liner   c                    t          t                    sJ fd|                     j        |          D             S )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
            =========== ==================================

        c                J    g | ]}t          j        j        |          | S  )is_point_in_line_rangestartend).0rK   rd   s     r   
<listcomp>z5ConstructionCircle.intersect_line.<locals>.<listcomp>   s?     
 
 
%dj$(EBB

 
 
r   rW   )rX   r   rc   rQ   )r   rd   rT   s    ` r   intersect_linez!ConstructionCircle.intersect_line   s\    , $ 011111
 
 
 
++DHg+FF
 
 
 	
r   other'ConstructionCircle'c                    t          |t                    sJ | j        }|j        }| j                            |j                  }||k     rt                      S ||z   }t          j        ||z
            }||cxk    r|k    rn n|j        | j        z
  j        }t          j	        |||          r| 
                    |          fS t          j	        |||          r?||k    r| 
                    |          fS | 
                    |t          j        z             fS t          j        ||z  ||z  z
  ||z  z
  d|z  |z  z            }	t          |                     ||	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
            =========== ==================================

        rW   g       )rX   r   r   r   r&   r]   rE   fabsr7   rY   r:   pir[   r?   )
r   rn   rT   r1r2dd_maxd_minr7   rb   s
             r   intersect_circlez#ConstructionCircle.intersect_circle   s   , %!344444[\K  ..w;;77NR	"r'""A\DK/6E|Aug666 /e,,..|Aug666 L88 MM%0022edgo6688 	27R"W#4q1u#<Q"OPPT]]EEM55=+IJJKKKwwr   N)r   )r   r   r   r   )r   r   )r   r   r    r   r!   r   r   r   )r   r   )r2   r   r3   r   r   r4   )r7   r   r   r   )r;   r<   r   r=   )r@   r   r   rA   )rK   r   r   rL   )r7   r   r   r
   )rS   )rQ   r
   rT   r   r   rU   )rd   r   rT   r   r   rU   )rn   ro   rT   r   r   rU   )__name__
__module____qualname____doc__r   r   staticmethodr.   propertyr1   r6   r:   r?   rJ   rN   rR   rc   rm   rx   rg   r   r   r   r      sw        6 6 6 6 6C C C C @ @ @ \@ G G G XG
& & & &A A A A: : : :	H 	H 	H 	H@ @ @ @
/ 
/ 
/ 
/ 6;. . . . .b 8=
 
 
 
 
< =B- - - - - - -r   ri   r   rj   rK   r   rL   c                R    || z
  j         }|| z
  j         |k    rdS ||z
  j         |k    S )NF)	magnitude)ri   rj   rK   lengths       r   rh   rh      s7    Ek$F 6))uCK"f,,r   )ri   r   rj   r   rK   r   r   rL   )
__future__r   typingr   r   r   rE   numpyrG   
ezdxf.mathr   r   rd   r
   r   bboxr   rr   rZ   __all__r   rh   rg   r   r   <module>r      s    # " " " " " / / / / / / / / / /      ! ! ! ! ! ! ! ! 3 3 3 3 3 3 3 3       'C-
 ` ` ` ` ` ` ` `F- - - - - -r   