
    Og"                        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   zConstruction 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      V/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/math/circle.py__init__zConstructionCircle.__init__   s5    6lFm;;#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DKK=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    
 2h2h2hsC(sC(oochhsm4oochhsm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[[$++./dkkD0$++2DEFFr   c                D    | xj                   t        ||f      z  c_         y)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   dxdys      r   	translatezConstructionCircle.translate<   s     	tRH~%r   c                \    | 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   angles     r   point_atzConstructionCircle.point_atF   s"     {{T__UDKK@@@r   c              #     K   | j                   }| j                  }|D ]  }|t        j                  ||      z     yw)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   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)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)arcr;   r   mathtaur9   nplinspace)r   sagittar;   counts       r   
flatteningzConstructionCircle.flattening]   sH      	+!$++txxA==S$((EAI!FGGGs   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$    {{dkk224;???r   c                r    | j                  |      }t        | j                  |      }|j                  |      S )zReturns 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     --.dkk?;~~o..r   c                   t        |t              sJ |j                  | j                        }|j	                  |      }| j                  j                  |      }g }|| j                  k  rt        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%   , #///NN4;;/	 ]]95{{##$67$++||D#w7! ,dkk9@@		&//<t{{J MM$--67MM$--67
 V} \\$W=MM,-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   s_    , $ 0111 ++DHHg+F
%djj$((EB 
 	
 
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  rn 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[[\\KK  .w;7NR		"r'"A w \\DKK/66E||Aug6e,..||Aug68 MM%022edggo688 		27R"W#4q1u#<Q"OPT]]EEM55=+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;    Ek$$F  6)CK""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   