U
    Dvf                     @   sN   d dl mZ d dlZd dlZd dlZdgZG dd deZdd Zdd Z	dS )	    )NumberNVectorc                       s  e Zd ZdZdZd7 fdd	Z fddZdd	 Zd
d Zdd Z	dd Z
e
Zdd Zdd Zdd ZeZdd Zdd Zdd Zdd Zeddd Z fd!d"Zd#d$ Zd%d& ZeZd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zed1d2 Z e j!d3d2 Z d e"d4d5d6Z#  Z$S )8r   zA math-like vector.

    Represents an n-dimensional numeric vector. ``Vector`` objects support
    vector addition and subtraction, scalar multiplication and division,
    negation, rounding, and comparison tests.
     Fc                    s2   |dk	rt dt t|tkr$|S t | |S )NFz'the 'keep' argument has been deprecated)warningswarnDeprecationWarningtyper   super__new__)clsvaluesZkeep	__class__r   9/tmp/pip-unpacked-wheel-qlge9rch/fontTools/misc/vector.pyr
      s    zVector.__new__c                    s   | j j dt   dS )N())r   __name__r	   __repr__selfr   r   r   r      s    zVector.__repr__c                    sj   t tr<t| tkst|  fddt| D S t tr`|  fdd| D S t d S )Nc                 3   s   | ]\}} ||V  qd S Nr   .0abopr   r   	<genexpr>%   s     z#Vector._vectorOp.<locals>.<genexpr>c                 3   s   | ]} |V  qd S r   r   r   vr   otherr   r   r   '   s     )
isinstancer   lenAssertionErrorr   zipr   NotImplementedErrorr   r!   r   r   r    r   	_vectorOp"   s    

zVector._vectorOpc                    s.   t tr$|  fdd| D S t d S )Nc                 3   s   | ]} |V  qd S r   r   r   r    r   r   r   ,   s     z#Vector._scalarOp.<locals>.<genexpr>)r"   r   r   r&   r'   r   r    r   	_scalarOp*   s    
zVector._scalarOpc                    s   |   fdd| D S )Nc                 3   s   | ]} |V  qd S r   r   r   r   r   r   r   0   s     z"Vector._unaryOp.<locals>.<genexpr>r   )r   r   r   r   r   _unaryOp/   s    zVector._unaryOpc                 C   s   |  |tjS r   )r(   operatoraddr   r!   r   r   r   __add__2   s    zVector.__add__c                 C   s   |  |tjS r   )r(   r+   subr-   r   r   r   __sub__7   s    zVector.__sub__c                 C   s   |  |tS r   )r(   _operator_rsubr-   r   r   r   __rsub__:   s    zVector.__rsub__c                 C   s   |  |tjS r   )r)   r+   mulr-   r   r   r   __mul__=   s    zVector.__mul__c                 C   s   |  |tjS r   )r)   r+   truedivr-   r   r   r   __truediv__B   s    zVector.__truediv__c                 C   s   |  |tS r   )r)   _operator_rtruedivr-   r   r   r   __rtruediv__E   s    zVector.__rtruediv__c                 C   s   |  tjS r   )r*   r+   posr   r   r   r   __pos__H   s    zVector.__pos__c                 C   s   |  tjS r   )r*   r+   negr   r   r   r   __neg__K   s    zVector.__neg__)roundc                C   s
   |  |S r   )r*   )r   r=   r   r   r   	__round__N   s    zVector.__round__c                    s   t |trt|}t |S r   )r"   listtupler	   __eq__r-   r   r   r   rA   Q   s    
zVector.__eq__c                 C   s   |  | S r   )rA   r-   r   r   r   __ne__W   s    zVector.__ne__c                 C   s   t | S r   )anyr   r   r   r   __bool__Z   s    zVector.__bool__c                 C   s   t tdd | D S )Nc                 s   s   | ]}|| V  qd S r   r   )r   xr   r   r   r   `   s     z!Vector.__abs__.<locals>.<genexpr>)mathsqrtsumr   r   r   r   __abs___   s    zVector.__abs__c                 C   s   t | S )z;Return the length of the vector. Equivalent to abs(vector).absr   r   r   r   lengthb   s    zVector.lengthc                 C   s   | t |  S )z+Return the normalized vector of the vector.rJ   r   r   r   r   
normalizedf   s    zVector.normalizedc                 C   s,   t | t |ksttdd t| |D S )z[Performs vector dot product, returning the sum of
        ``a[0] * b[0], a[1] * b[1], ...``c                 s   s   | ]\}}|| V  qd S r   r   r   r   r   r   r   n   s     zVector.dot.<locals>.<genexpr>)r#   r$   rH   r%   r-   r   r   r   dotj   s    z
Vector.dotc                 C   s   t dt |  S )NzAthe 'toInt' method has been deprecated, use round(vector) instead)r   r   r   r>   r   r   r   r   toIntr   s
    zVector.toIntc                 C   s   t dt t| S )NzPthe 'values' attribute has been deprecated, use the vector object itself instead)r   r   r   r?   r   r   r   r   r   y   s
    zVector.valuesc                 C   s   t dd S )Nz?can't set attribute, the 'values' attribute has been deprecated)AttributeError)r   r   r   r   r   r      s    )r!   returnc                    s0   t | t |kstt fddt| |D S )z5Return True if the vector is close to another Vector.c                 3   s"   | ]\}}t j||f V  qd S r   )rF   iscloser   kwargsr   r   r      s     z!Vector.isclose.<locals>.<genexpr>)r#   r$   allr%   )r   r!   rT   r   rS   r   rR      s    zVector.isclose)F)%r   
__module____qualname____doc__	__slots__r
   r   r(   r)   r*   r.   __radd__r0   r2   r4   __rmul__r6   r8   r:   r<   r=   r>   rA   rB   rD   __nonzero__rI   rL   rM   rN   rO   propertyr   setterboolrR   __classcell__r   r   r   r   r   
   s@   

c                 C   s   t || S r   )r+   r/   r   r   r   r   r   r1      s    r1   c                 C   s   t || S r   )r+   r5   ra   r   r   r   r7      s    r7   )
Znumbersr   rF   r+   r   __all__r@   r   r1   r7   r   r   r   r   <module>   s    