
    'j8                        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dS ).    )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_anglepr   anglefloatdistancereturnr   c                L    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)r   r   r   s      J/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/math/bulge.pypolarr      s!     77T_UH5555    p1p2c                J    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   )r   r   s     r   r   r   "   s     HHtBxx&&r   centerr   start_angle	end_angleradiustuple[Vec2, Vec2, float]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)	r   r   r   r   start_point	end_pointpi2abulges	            r   r   r   -   sx     V44Kfi00I
'A+C	3)k12S99C?AHQKK$(1++%E	5((r   r(   r)   pointc                    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)   r-   r+   s       r   r   r   D   sI     
5,,	,uUI/F/F	F!KA8A;;!$$r   r,    tuple[Vec2, float, float, float]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ty7G7G!7K)KLAk1a  Aqyy%9%%uQ'<'<c!ffDD%;''q))<)<c!ff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$   r2   r   r1   )r(   r)   r,   r+   s       r   r	   r	   v   sl     {##Kk9%%359I9IC9O)OPA	{Iu==   r   c                ~    t          |                               t          |                    d||z  z   z  dz  |z  S )N      ?r"   )r   r   r(   r)   r,   s      r   r1   r1      sK     	[""4	??3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

    )r3   r1   r:   s      r   r
   r
      s     ";	5AABBBr   chordc                    	 |d| z  z  }n# t           $ r Y dS w xY w	 |dt          j        d||z  z
            z   z  S # t          $ r Y dS 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

    r7   g        r9   )ZeroDivisionErrorr#   sqrt
ValueError)r   r<   xs      r   r   r      s    S6\"   ssC$)C!a%K00011   sss    
= 
A
Ac                0    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     8ECK   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   )
r   r   r   r   r   r   r   r   r   r   )r(   r   r)   r   r-   r   r   r   )r(   r   r)   r   r,   r   r   r/   )r(   r   r)   r   r,   r   r   r   )r(   r   r)   r   r,   r   r   r   )r   r   r<   r   r   r   )r   r   r   r   )
__future__r   typingr   r#   
ezdxf.mathr   r   __all__r   r   r   r   r   r	   r1   r
   r   r    r   r   <module>rI      s8  
 # " " " " "        ! ! ! ! ! ! ! !  	6 	6 	6 	6' ' ' ') ) ) ).% % % % E  E  E  EF   &   C C C C   *! ! ! ! ! !r   