
    h8                        S SK Jr  S SKJr  S SKrS SKJrJr  / SQ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rSS jrSS jrg)    )annotations)AnyN)Vec2UVec)bulge_to_arcbulge_3_pointsbulge_centerbulge_radiusarc_to_bulgebulge_from_radius_and_chordbulge_from_arc_anglec                F    [        U 5      [         R                  " X5      -   $ )zReturns the point at a specified `angle` and `distance` from point `p`.

Args:
    p: point as :class:`Vec2` compatible object
    angle: angle in radians
    distance: distance

)r   
from_angle)pangledistances      B/var/www/html/env/lib/python3.13/site-packages/ezdxf/math/bulge.pypolarr      s     7T__U555    c                D    [        U5      [        U 5      -
  R                  $ )zReturns angle a line defined by two endpoints and x-axis in radians.

Args:
    p1: start point as :class:`Vec2` compatible object
    p2: end point as :class:`Vec2` compatible object

)r   r   )p1p2s     r   r   r   "   s     HtBx&&&r   c                    [        XU5      n[        XU5      n[        R                  S-  n[        R                  " XbU-
  -   U5      S-  n[        R                  " U5      [        R
                  " U5      -  nXEU4$ )a  Returns bulge parameters from arc parameters.

Args:
    center: circle center point as :class:`Vec2` compatible object
    start_angle: start angle in radians
    end_angle: end angle in radians
    radius: circle radius

Returns:
    tuple: (start_point, end_point, bulge)

         @)r   mathpifmodsincos)	centerstart_angle	end_angleradiusstart_point	end_pointpi2abulges	            r   r   r   -   sk     V4Kf0I
''A+C		3k12S9C?AHHQK$((1+%E5((r   c                    [         R                  [        X 5      -
  [        X!5      -   S-  n[         R                  " U5      [         R                  " U5      -  $ )a  Returns bulge value defined by three points.

Based on 3-Points to Bulge by `Lee Mac`_.

Args:
    start_point: start point as :class:`Vec2` compatible object
    end_point: end point as :class:`Vec2` compatible object
    point: arbitrary point as :class:`Vec2` compatible object

r   )r   r   r   r   r    )r%   r&   pointr(   s       r   r   r   D   sA     
5,	,uU/F	F!KA88A;!$$r   c                4   [        XU5      n[        X5      [        R                  S-  [        R                  " U5      S-  -
  -   n[        XU5      nUS:  a!  U[        XQ5      [        XP5      [        U5      4$ U[        XP5      [        XQ5      [        U5      4$ )a  Returns arc parameters from bulge parameters.

The arcs defined by bulge values of :class:`~ezdxf.entities.LWPolyline`
and 2D :class:`~ezdxf.entities.Polyline` entities start at the vertex which
includes the bulge value and ends at the following vertex.

.. important::

    The return values always describe a counter-clockwise oriented arc, so for
    clockwise arcs (negative bulge values) the start and end angles are swapped and
    the arc starts at the `end_point` and ends at the `start_point`.

Based on Bulge to Arc by `Lee Mac`_.

Args:
    start_point: start vertex as :class:`Vec2` compatible object
    end_point: end vertex as :class:`Vec2` compatible object
    bulge: bulge value

Returns:
    Tuple: (center, start_angle, end_angle, radius)

r   r   )signed_bulge_radiusr   r   r   atanr   abs)r%   r&   r)   rr(   cs         r   r   r   S   s    4 	KE:Ak%1tyy7G!7K)KLAka Aqy%%uQ'<c!fDD%'q)<c!fDDr   c           	         [        U 5      n [        X5      [        R                  S-  [        R                  " U5      S-  -
  -   nU [         R
                  " U[        XU5      5      -   $ )a  Returns center of arc described by the given bulge parameters.

Based on  Bulge Center by `Lee Mac`_.

Args:
    start_point: start point as :class:`Vec2` compatible object
    end_point: end point as :class:`Vec2` compatible object
    bulge: bulge value as float


       @)r   r   r   r   r.   r   r-   )r%   r&   r)   r(   s       r   r	   r	   v   s]     {#Kk%359IC9O)OPA	{u=  r   c                d    [        U 5      R                  [        U5      5      SX"-  -   -  S-  U-  $ )N      ?r   )r   r   r%   r&   r)   s      r   r-   r-      sA     	[""4	?3%- 	"
	 	r   c                ,    [        [        XU5      5      $ )zReturns radius of arc defined by the given bulge parameters.

Based on Bulge Radius by `Lee Mac`_

Args:
    start_point: start point as :class:`Vec2` compatible object
    end_point: end point as :class:`Vec2` compatible object
    bulge: bulge value

)r/   r-   r6   s      r   r
   r
      s     ";5ABBr   c                     USU -  -  n US[        R                  " SX"-  -
  5      -   -  $ ! [          a     gf = f! [         a     gf = f)zReturns the bulge value for the given arc radius and chord length.
Returns 0 if the radius is zero or the radius is too small for the given
chord length to create an arc.

Args:
    radius: arc radius
    chord: chord length

r3   g        r5   )ZeroDivisionErrorr   sqrt
ValueError)r$   chordxs      r   r   r      s`    S6\"C$))C!%K0011    s   ,  < 
99
A	A	c                4    [         R                  " U S-  5      $ )zYReturns the bulge value for the given arc angle.

Args:
    angle: arc angle in radians

r   )r   tan)r   s    r   r   r      s     88ECK  r   )r   r   r   floatr   r@   returnr   )r   r   r   r   rA   r@   )
r!   r   r"   r@   r#   r@   r$   r@   rA   ztuple[Vec2, Vec2, float])r%   r   r&   r   r+   r   rA   r@   )r%   r   r&   r   r)   r@   rA   z tuple[Vec2, float, float, float])r%   r   r&   r   r)   r@   rA   r   )r%   r   r&   r   r)   r@   rA   r@   )r$   r@   r<   r@   rA   r@   )r   r@   rA   r@   )
__future__r   typingr   r   
ezdxf.mathr   r   __all__r   r   r   r   r   r	   r-   r
   r   r    r   r   <module>rG      s   
 #   !	6'))$)16)@E)).% E E"& E/4 E% EF&"&/4
C*!r   