관리-도구
편집 파일: shapes.cpython-37.pyc
B ��]; � @ sD d Z ddlZddd�Zddd�Zdd � Zd d� Zdd � Zdd� ZdS )z+ Extension to create and manipulate shapes � N� c c s� | dk rt d��|dk r2|d t�tj| � }n"|dk rL|dkrTt d��nt d��dtj | }|}x6t| �D ]*}|t�|� |t�|� fV ||7 }qpW dS )a� Returns the corners of a regular polygon as iterable of (x, y) tuples. The polygon size is determined by the `edge_length` or the `radius` argument. If both are given `edge_length` will be taken. Args: num_corners: count of polygon corners edge_length: length of polygon side radius: circum radius rotation: rotation angle in radians Returns: iterable of (x, y) tuples � z0Argument `num_corners` has to be greater than 2.Ng @g z+Argument `radius` has to be greater than 0.z,Argument `edge_length` or `radius` required.)� ValueError�math�sin�pi�range�cos)Znum_cornersZedge_length�radius�rotation�delta�angle�_� r �K/opt/alt/python37/lib/python3.7/site-packages/svgwrite/extensions/shapes.py�ngon s r c c s~ | dk rt d��|dkr t d��|dkr0t d��t| ||d�}t| |tj| | d�}x"t||�D ]\}}|V |V qbW dS )a� Create a star shape as iterable of (x, y) vertices. Argument `spikes` 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 greater than `r2`. Args: spikes: spike count r1: radius 1 r2: radius 2 rotation: rotation angle in radians Returns: iterable of (x, y) tuples r z+Argument `spikes` has to be greater than 2.g z'Argument `r1` has to be greater than 0.z'Argument `r2` has to be greater than 0.)r r N)r r r r �zip)ZspikesZr1Zr2r Zcorners1Zcorners2�s1�s2r r r �star( s r c c s( x"| D ]\}}|| || fV qW dS )z� Translates `vertices` about `delta_x` and `delta_y` Args: vertices: iterable of (x, y) tuples delta_x: translation in x axis delta_y: translation in y axis Returns: iterable of (x, y) tuples Nr )�verticesZdelta_xZdelta_y�x�yr r r � translateF s r c c s( x"| D ]\}}|| || fV qW dS )a Scales `vertices` about `scale_x` and `scale_y` Args: vertices: iterable of (x, y) tuples scale_x: scaling factor in x axis direction scale_y: scaling factor in y axis direction Returns: iterable of (x, y) tuples Nr )r Zscale_xZscale_yr r r r r �scaleV s r c c sP xJ| D ]B\}}t �||�}t �||�| }|t �|� |t �|� fV qW dS )z� Rotates `vertices` about `delta` degrees around the origin (0, 0). Args: vertices: iterable of (x, y) tuples delta: rotation angle in radians Returns: iterable of (x, y) tuples N)r �hypot�atan2r r )r r r r �rr r r r �rotatef s r c C sT d\}}}x(| D ] \}}||7 }||7 }|d7 }qW t || �}t || �}||fS )z: Returns the centroid of a series of `vertices`. )r r r � )�float)r �kZc_xZc_yr r r r r �centroidw s r"