
    'j_&                        d dl mZ d dlZd dlmZmZmZmZmZ d dl	m
Z
 ddlmZ ddlmZ g dZd ej        ddfd0dZ	 	 d1d0dZ	 	 	 	 d2d3dZ	 d4d5dZ	 	 	 d6d7d#Zd8d9d&Z	 d8d:d*Z	 	 d;d<d/ZdS )=    )annotationsN)cubic_bezier_arc_parametersMatrix44UVecbasic_transformationVec3)forms   )Path)	converter)unit_circleelliptic_transformationrectngonwedgestargearhelixstart_anglefloat	end_anglesegmentsint	transformMatrix44 | Nonereturnr   c                    t                      }d}t          | ||          D ])\  }}}}	|r	||_        d}|                    |	||           *||S |                    |          S )ui  Returns a unit circle as a :class:`Path` object, with the center at
    (0, 0, 0) and the radius of 1 drawing unit.

    The arc spans from the start- to the end angle in counter-clockwise
    orientation. The end angle has to be greater than the start angle and the
    angle span has to be greater than 0.

    Args:
        start_angle: start angle in radians
        end_angle: end angle in radians (end_angle > start_angle!)
        segments: count of Bèzier-curve segments, default is one segment for
            each arc quarter (π/2)
        transform: transformation Matrix applied to the unit circle

    TF)r   r   start	curve4_tor   
r   r   r   r   path
start_flagr   ctrl1ctrl2ends
             K/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/path/shapes.pyr   r      s    * 66DJ$?Y% % * * ueS  	DJJsE5))))~~i(((    c                   t                      }d}t          | ||          D ]7\  }}}}	|r|                    |           d}|                    |	||           8|                    d           ||S |                    |          S )u]  Returns a wedge as a :class:`Path` object, with the center at
    (0, 0, 0) and the radius of 1 drawing unit.

    The arc spans from the start- to the end angle in counter-clockwise
    orientation. The end angle has to be greater than the start angle and the
    angle span has to be greater than 0.

    Args:
        start_angle: start angle in radians
        end_angle: end angle in radians (end_angle > start_angle!)
        segments: count of Bèzier-curve segments, default is one segment for
            each arc quarter (π/2)
        transform: transformation Matrix applied to the wedge

    TFr   r   r   )r   r   line_tor   r   r    s
             r&   r   r   @   s    * 66DJ$?Y% % * * ueS  	LLJsE5))))LL~~i(((r'   r)   centerr   radiusratiorotationr   c                    |dk     rt          d|           |dk     rt          d|           |}||z  }t          | ||df|          S )uF  Returns the transformation matrix to transform a unit circle into
    an arbitrary circular- or elliptic arc.

    Example how to create an ellipse with a major axis length of 3, a minor
    axis length 1.5 and rotated about 90°::

        m = elliptic_transformation(radius=3, ratio=0.5, rotation=math.pi / 2)
        ellipse = shapes.unit_circle(transform=m)

    Args:
        center: curve center in WCS
        radius: radius of the major axis in drawing units
        ratio: ratio of minor axis to major axis
        rotation: rotation angle about the z-axis in radians

    ư>zinvalid radius: zinvalid ratio: r
   )
ValueErrorr   )r+   r,   r-   r.   scale_xscale_ys         r&   r   r   e   sk    , }}4F44555t||2522333GunG'1(=xHHHr'   widthheightc                (   | dk     rt          d|            |dk     rt          d|           t          |           dz  }t          |          dz  }t          j        ||f| |f| | f|| fgd          }||S |                    |          S )ae  Returns a closed rectangle as a :class:`Path` object, with the center at
    (0, 0, 0) and the given `width` and `height` in drawing units.

    Args:
        width: width of the rectangle in drawing units, width > 0
        height: height of the rectangle in drawing units, height > 0
        transform: transformation Matrix applied to the rectangle

    g&.>zinvalid width: zinvalid height: g       @Tclose)r1   r   r   from_verticesr   )r4   r5   r   w2h2r!   s         r&   r   r      s     t||2522333}}4F44555	u	B	v	B"
bRC9sRCj2s)4D  D ~~i(((r'         ?countlengthfloat | Nonec                    t          j        | ||          }||                    |          }t          j        |d          S )a  Returns a `regular polygon <https://en.wikipedia.org/wiki/Regular_polygon>`_
    a :class:`Path` object, with the center at (0, 0, 0).
    The polygon size is determined by the edge `length` or the circum `radius`
    argument. If both are given `length` has higher priority. Default size is
    a `radius` of 1. The ngon starts with the first vertex is on the x-axis!
    The base geometry is created by function :func:`ezdxf.render.forms.ngon`.

    Args:
        count: count of polygon corners >= 3
        length: length of polygon side
        radius: circum radius, default is 1
        transform: transformation Matrix applied to the ngon

    )r>   r,   NTr7   )r	   r   transform_verticesr   r9   )r=   r>   r,   r   verticess        r&   r   r      sI    ( z%v>>>H//99"848888r'   r1r2c                    t          j        | ||          }||                    |          }t          j        |d          S )a  Returns a `star shape <https://en.wikipedia.org/wiki/Star_polygon>`_ as
    a :class:`Path` object, with the center at (0, 0, 0).

    Argument `count` defines the count of star spikes, `r1` defines the radius
    of the "outer" vertices and `r2` defines the radius of the "inner" vertices,
    but this does not mean that `r1` has to be greater than `r2`.
    The star shape starts with the first vertex is on the x-axis!
    The base geometry is created by function :func:`ezdxf.render.forms.star`.

    Args:
        count: spike count >= 3
        r1: radius 1
        r2: radius 2
        transform: transformation Matrix applied to the star

    )rC   rD   NTr7   )r	   r   rA   r   r9   )r=   rC   rD   r   rB   s        r&   r   r      sI    " z%B2...H//99"848888r'   	top_widthbottom_widthoutside_radiusc                    t          j        | ||||          }||                    |          }t          j        |d          S )a{  
    Returns a `gear <https://en.wikipedia.org/wiki/Gear>`_ (cogwheel) shape as
    a :class:`Path` object, with the center at (0, 0, 0).
    The base geometry is created by function :func:`ezdxf.render.forms.gear`.

    .. warning::

        This function does not create correct gears for mechanical engineering!

    Args:
        count: teeth count >= 3
        top_width: teeth width at outside radius
        bottom_width: teeth width at base radius
        height: teeth height; base radius = outside radius - height
        outside_radius: outside radius
        transform: transformation Matrix applied to the gear shape

    NTr7   )r	   r   rA   r   r9   )r=   rF   rG   r5   rH   r   rB   s          r&   r   r      sJ    4 z%L&.QQH//99"848888r'   T   pitchturnsc                    fd}d
fd}| | |s t          | ddf          }|t          j        z   |t          j        |z            }t	          t          j        |                    }	|	dk    rzt           ||t          j        |                    }
t          |	          D ]F}t          dd|j	        j
                  }|
D ]&\  }}}|                    ||z   ||z   ||z              'G||	z
  }|dk    rt          j        |d	z            } ||t          j        z  |z            }t          dd|j	        j
                  } ||t          j        |z  |          D ]&\  }}}|                    ||z   ||z   ||z              '|S )a  
    Returns a `helix <https://en.wikipedia.org/wiki/Helix>`_ as
    a :class:`Path` object.
    The center of the helix is always (0, 0, 0), a positive `pitch` value
    creates a helix along the +z-axis, a negative value along the -z-axis.

    Args:
        radius: helix radius
        pitch: the height of one complete helix turn
        turns: count of turns
        ccw: creates a counter-clockwise turning (right-handed) helix if ``True``
        segments: cubic Bezier segments per turn

    c           	   3  L  K   d}||z  
z  }|dz  }t          d||          D ]\  }}}}	t          |j        z  |j        z  ||z   | z
            t          |j        z  |j        z  ||z   | z             t          |	j        z  |	j        z  ||z             fV  ||z  }d S )Ng        g      ?r   )r   r   xy)bangler   zzz_stepz_step_2_v1v2v3prxrys             r&   bezier_ctrl_pointsz!helix.<locals>.bezier_ctrl_points  s      !A%C<8E8LL 	 	MAr2rRTBYr	2=1+<==RTBYr	2=1+<==RTBYr	2;77   
 &LBB	 	r'   alphar   r   c                    t          j        |           }d|z
  d|z
  z  | z  z  }t          j        |           d|z
  z  t          j        |           z  }||z  S )Nr<   g      @g      @)mathcossintan)r^   cos_ab_1b_2rZ   s       r&   param_bzhelix.<locals>.param_b  sY    U{sU{+e3a7huoou-?Syr'   r   )r   r0   rJ   )r^   r   r   r   )r   r`   taupir   floorlistranger   r%   zr   ceil)r,   rK   rL   ccwr   r]   rg   r!   rQ   
full_turnscurve_paramsrV   rm   rW   rX   rY   reminderrZ   r[   r\   s                    @@@r&   r   r      s   .
 
 
 
 
 
 
      
B	B Svq!n%%%DA("##ATZ&&''JA~~..q$(HEEFFz"" 	7 	7AQ48:&&A* 7 7
Bq2vq2vq2v66667 z!H$9X\**GHtw&122Atxz"",,Q80CXNN 	3 	3JBBNN1r61r61r62222Kr'   )
r   r   r   r   r   r   r   r   r   r   )r
   N)r)   r
   r
   r   )
r+   r   r,   r   r-   r   r.   r   r   r   )r
   r
   N)r4   r   r5   r   r   r   r   r   )Nr<   N)
r=   r   r>   r?   r,   r   r   r   r   r   )N)
r=   r   rC   r   rD   r   r   r   r   r   )r=   r   rF   r   rG   r   r5   r   rH   r   r   r   r   r   )TrJ   )
r,   r   rK   r   rL   r   r   r   r   r   )
__future__r   r`   
ezdxf.mathr   r   r   r   r   ezdxf.renderr	   r!   r    r   __all__rh   r   r   r   r   r   r   r   r    r'   r&   <module>ry      s   # " " " " "                                	 	 	 x!%	!) !) !) !) !)N !%	") ") ") ") ")L 	I I I I I@ GK) ) ) ) )<  !%	9 9 9 9 949 9 9 9 9: "&9 9 9 9 9H 	A A A A A A Ar'   