B
    Sc                 @   s*   d dl mZmZ dd ZG dd dZdS )    )VariationModelnormalizeValuec             C   s   t t|  S )N)tuplesorteditems)loc r   >lib/python3.7/site-packages/fontTools/feaLib/variableScalar.pyLocation   s    r
   c               @   s   e Zd ZdZi Zedd Zi fddZdd Ze	dd	 Z
e	d
d Zdd Zdd Zdd Zdd Ze	dd Zdd Ze	dd Zdd Zdd ZdS )VariableScalarzFA scalar with different values at different points in the designspace.c             C   s
   i | _ d S )N)
model_pool)clsr   r   r	   clear_cache   s    zVariableScalar.clear_cachec             C   s2   i | _ i | _x | D ]\}}| || qW d S )N)valuesaxesr   	add_value)selfZlocation_valuelocationvaluer   r   r	   __init__   s    zVariableScalar.__init__c             C   sT   g }x<| j  D ].\}}ddd |D }|d||f  qW dd| d S )N,c             S   s   g | ]\}}d ||f qS )z%s=%ir   ).0axr   r   r   r	   
<listcomp>   s    z+VariableScalar.__repr__.<locals>.<listcomp>z%s:%i( ))r   r   joinappend)r   r   r   r   r   r   r   r	   __repr__   s
    zVariableScalar.__repr__c                s,   t | j  t fdd dd  D S )Nc             3   s   | ]}| d  kV  qdS )r   Nr   )r   v)r   r   r	   	<genexpr>$   s    z+VariableScalar.does_vary.<locals>.<genexpr>   )listr   any)r   r   )r   r	   	does_vary!   s    zVariableScalar.does_varyc             C   s   | j stddd | j D S )Nz=.axes must be defined on variable scalar before interpolatingc             S   s   i | ]}||j qS r   )axisTag)r   r   r   r   r	   
<dictcomp>,   s    z,VariableScalar.axes_dict.<locals>.<dictcomp>)r   
ValueError)r   r   r   r	   	axes_dict&   s    zVariableScalar.axes_dictc             C   sj   |  |}i }xR| D ]F}|| jkr6td||f | j| }t|| |j|j|jf||< qW t|S )NzUnknown axis %s in %s)	fix_locationkeysr)   r(   r   ZminValuedefaultValueZmaxValuer
   )r   r   Znormalized_locationZaxtagaxisr   r   r	   _normalized_location.   s    


 z#VariableScalar._normalized_locationc             C   s6   t |}x(| j D ]\}}||kr|j||< qW |S )N)dictr)   r   r,   )r   r   tagr-   r   r   r	   r*   ;   s
    zVariableScalar.fix_locationc             C   s"   | j r| |}|| jt|< d S )N)r   r*   r   r
   )r   r   r   r   r   r	   r   B   s    
zVariableScalar.add_valuec                s    fdd j  D  _ d S )Nc                s    i | ]\}}|t  |qS r   )r
   r*   )r   lr    )r   r   r	   r'   I   s   z4VariableScalar.fix_all_locations.<locals>.<dictcomp>)r   r   )r   r   )r   r	   fix_all_locationsH   s    
z VariableScalar.fix_all_locationsc             C   s8   |    tdd | jD }|| jkr.td| j| S )Nc             S   s   i | ]}|j |jqS r   )r,   r&   )r   r   r   r   r	   r'   P   s    z*VariableScalar.default.<locals>.<dictcomp>z Default value could not be found)r2   r
   r   r   r(   )r   keyr   r   r	   defaultM   s
    
zVariableScalar.defaultc             C   s8   |}|| j  kr| j | S t| j   }| j||S )N)r   r+   r#   modelZinterpolateFromMasters)r   r   r   r   r   r   r	   value_at_locationV   s
    
z VariableScalar.value_at_locationc                sP   t  j }| jkr" j| S  fdd j D }t|}| j|< |S )Nc                s   g | ]}t  |qS r   )r/   r.   )r   k)r   r   r	   r   b   s    z(VariableScalar.model.<locals>.<listcomp>)r   r   r+   r   r   )r   r3   Z	locationsmr   )r   r	   r5   ]   s    


zVariableScalar.modelc             C   s   t | j }| j|S )N)r#   r   r5   ZgetDeltasAndSupports)r   r   r   r   r	   get_deltas_and_supportsg   s    z&VariableScalar.get_deltas_and_supportsc             C   s.   |   \}}|| ||}t| j|fS )N)r9   ZsetSupportsZstoreDeltasintr4   )r   Zstore_builderZdeltasZsupportsindexr   r   r	   add_to_variation_storek   s    

z%VariableScalar.add_to_variation_storeN)__name__
__module____qualname____doc__r   classmethodr   r   r   propertyr%   r)   r.   r*   r   r2   r4   r6   r5   r9   r<   r   r   r   r	   r      s    	
r   N)ZfontTools.varLib.modelsr   r   r
   r   r   r   r   r	   <module>   s   