
    Og8                        d dl mZ d dlmZ d dlZd dlmZmZ g dZddZ	ddZ
	 	 	 	 	 	 	 	 	 	 ddZdd	Z	 	 	 	 	 	 	 	 dd
ZddZ	 	 	 	 	 	 	 	 ddZddZddZddZy)    )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    t        |       t        j                  ||      z   S )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      U/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/math/bulge.pypolarr      s     7T__UH555    c                D    t        |      t        |       z
  j                  S )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                    t        | ||      }t        | ||      }t        j                  dz  }t        j                  |||z
  z   |      dz  }t        j                  |      t        j
                  |      z  }|||fS )a4  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   -   ss     V4Kfi0I
''A+C		3)k12S9C?AHHQK$((1+%E	5((r   c                    t         j                  t        ||       z
  t        ||      z   dz  }t        j                  |      t        j                  |      z  S )a2  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   sE     
5,	,uUI/F	F!KA88A;!$$r   c                >   t        | ||      }t        | |      t        j                  dz  t        j                  |      dz  z
  z   }t        | ||      }|dk  r#|t        ||      t        ||       t        |      fS |t        ||       t        ||      t        |      fS )a4  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 	KE:Ak9%1tyy7G!7K)KLAk1a Aqy%9%uQ'<c!fDD%;'q))<c!fDDr   c           	         t        |       } t        | |      t        j                  dz  t        j                  |      dz  z
  z   }| t        j
                  |t        | ||            z   S )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   sa     {#Kk9%359IC9O)OPA	{Iu=  r   c                f    t        |       j                  t        |            d||z  z   z  dz  |z  S )N      ?r   )r   r   r%   r&   r)   s      r   r-   r-      sC     	[""4	?3%%- 	"
	 	r   c                .    t        t        | ||            S )a  Returns 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                    	 |d| z  z  }	 |dt        j                  d||z  z
        z   z  S # t         $ r Y yw xY w# t        $ r Y yw xY w)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      sb    S6\"C$))C!a%K0011    s   ,  ; 	88	AAc                2    t        j                  | dz        S )zeReturns 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   