
    2h                     |    d Z ddlmZmZmZmZmZ ddlmZ d Z	d Z
d ZdZ edez        Zd	 Z G d
 d      Zd Zy)z=Helpers for manipulating 2D points and vectors in COLR table.    )copysigncoshypotisclosepiotRoundc                 .    |d   | d   z
  |d   | d   z
  fS Nr       )origintargets     @D:\jyotish\venv\Lib\site-packages\fontTools/colorLib/geometry.py_vector_betweenr      s'    1Iq	!6!9vay#899    c                 :    t        | d         t        | d         fS r   r   )pts    r   _round_pointr      s    BqENGBqEN++r   c                 >    t        |  }|dk(  ry | d   |z  | d   |z  fS r   )r   )veclengths     r   _unit_vectorr      s0    C[F{FVOSVf_--r   g-C6?g      ?c                     t        |       }|syg }|D ]F  }t         |cxk  r	t        k  rn n|j                  d       ,|j                  t        d|             H t	        |      S )N)r   r   r         ?)r   _UNIT_VECTOR_THRESHOLDappendr   tuple)	directionuvresultuv_components       r   _rounding_offsetr#      sc     
i	 BF""lK5KK MM! MM(356  =r   c                   4    e Zd Zd Zd Zd ZefdZd Zd Z	y)Circlec                      || _         || _        y Ncentreradius)selfr)   r*   s      r   __init__zCircle.__init__7   s    r   c                 <    d| j                    d| j                   dS )NzCircle(centre=z	, radius=)r(   r+   s    r   __repr__zCircle.__repr__;   s    }Idkk]!DDr   c                 f    t        t        | j                        t        | j                              S r'   )r%   r   r)   r	   r*   r/   s    r   roundzCircle.round>   s!    l4;;/1EFFr   c                     | j                   t        t        | j                  |j                         z   }t	        |j                   |t
              xs |j                   |kD  S )N)rel_tol)r*   r   r   r)   r   _CIRCLE_INSIDE_TOLERANCE)r+   outer_circle	tolerancedists       r   insidezCircle.insideA   sQ    {{UODKKATAT$UVVL''7OP *""T)	
r   c                 4    | j                   |j                   k(  S r'   r)   )r+   others     r   
concentriczCircle.concentricH   s    {{ell**r   c                 V    | j                   d   |z   | j                   d   |z   f| _         y r   r;   )r+   dxdys      r   movezCircle.moveK   s(    {{1~*DKKNR,?@r   N)
__name__
__module____qualname__r,   r0   r2   r5   r9   r=   rA   r   r   r   r%   r%   6   s)    EG .F 
+Ar   r%   c                    t        | |      t        ||      }}|j                  |      }|j                         }|j                         }|j                  |      }	||	k(  r|S |	r#t        |j                  |j                        }
d}n"t        |j                  |j                        }
d}t        |
      \  }}d}t        |      D ]b  }|j                  |      r&|xj                  |z  c_        |j                  dk\  sJ |j                  ||       ||j                  |      k(  sa |S  t        d| d|rdnd d| d	| d
	      )a   Round start circle so that it stays inside/outside end circle after rounding.

    The rounding of circle coordinates to integers may cause an abrupt change
    if the start circle c0 is so close to the end circle c1's perimiter that
    it ends up falling outside (or inside) as a result of the rounding.
    To keep the gradient unchanged, we nudge it in the right direction.

    See:
    https://github.com/googlefonts/colr-gradients-spec/issues/204
    https://github.com/googlefonts/picosvg/issues/158
    r   g         r   zRounding circle  r9   outsidez failed after z
 attempts!)r%   r9   r2   r   r)   r#   ranger=   r*   rA   AssertionError)c0r0c1r1startendinside_before_roundround_start	round_endinside_after_roundr   radius_deltar?   r@   max_attempts_s                   r   %round_start_circle_stable_containmentrX   O   sX    BB3E,,s+++-K		I$++I600	#I$4$4k6H6HI	 $K$6$6	8H8HI	i(FB" L< !!),,.%%***R$+"4"4Y"?? ! ! ugQ.xI>ae>,z;
 	
r   N)__doc__mathr   r   r   r   r   fontTools.misc.roundToolsr	   r   r   r   r5   r   r#   r%   rX   r   r   r   <module>r\      sO    C 2 2 -:,.    URZ .A A2@r   