a
    ×¶îaÑ  ã                   @   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	   úo/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/fontTools/feaLib/variableScalar.pyÚLocation   s    r   c                   @   sŒ   e Zd Z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 | _ i | _| ¡ D ]\}}|  ||¡ qd S r   )ÚvaluesÚaxesr   Ú	add_value)ÚselfZlocation_valueÚlocationÚvaluer	   r	   r
   Ú__init__   s    zVariableScalar.__init__c                 C   sP   g }| j  ¡ D ].\}}d dd„ |D ƒ¡}| d||f ¡ qdd |¡ d S )Nú,c                 S   s   g | ]\}}d ||f ‘qS )z%s=%ir	   )Ú.0Úaxr   r	   r	   r
   Ú
<listcomp>   ó    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>   r   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>#   r   z,VariableScalar.axes_dict.<locals>.<dictcomp>)r   Ú
ValueErrorr%   r	   r	   r
   Ú	axes_dict   s
    ÿzVariableScalar.axes_dictc                 C   sf   |   |¡}i }| ¡ D ]F}|| jvr4td||f ƒ‚| j| }t|| |j|j|jfƒ||< q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   s2   t |ƒ}| j ¡ D ]\}}||vr|j||< q|S r   )Údictr+   r   r.   )r   r   Útagr/   r	   r	   r
   r,   2   s
    zVariableScalar.fix_locationc                 C   s"   | j r|  |¡}|| jt|ƒ< d S r   )r   r,   r   r   )r   r   r   r	   r	   r
   r   9   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)   @   s   z4VariableScalar.fix_all_locations.<locals>.<dictcomp>)r   r   r%   r	   r%   r
   Úfix_all_locations?   s    
ÿz VariableScalar.fix_all_locationsc                 C   s8   |   ¡  tdd„ | jD ƒƒ}|| jvr.tdƒ‚| j| S )Nc                 S   s   i | ]}|j |j“qS r	   )r'   r.   r(   r	   r	   r
   r)   G   r   z*VariableScalar.default.<locals>.<dictcomp>z Default value could not be found)r4   r   r   r   r*   )r   Úkeyr	   r	   r
   ÚdefaultD   s
    
zVariableScalar.defaultc                 C   s8   |}|| j  ¡ v r| j | S t| j   ¡ ƒ}| j ||¡S r   )r   r-   r#   ÚmodelZinterpolateFromMasters)r   r   r   r   r	   r	   r
   Úvalue_at_locationM   s
    
z VariableScalar.value_at_locationc                    s    ‡ fdd„ˆ j  ¡ D ƒ}t|ƒS )Nc                    s   g | ]}t ˆ  |¡ƒ‘qS r	   )r1   r0   )r   Úkr%   r	   r
   r   V   r   z(VariableScalar.model.<locals>.<listcomp>)r   r-   r   )r   Ú	locationsr	   r%   r
   r7   T   s    zVariableScalar.modelc                 C   s   t | j ¡ ƒ}| j |¡S r   )r#   r   r7   ZgetDeltasAndSupports)r   r   r	   r	   r
   Úget_deltas_and_supportsY   s    z&VariableScalar.get_deltas_and_supportsc                 C   s.   |   ¡ \}}| |¡ | |¡}t| jƒ|fS r   )r;   ZsetSupportsZstoreDeltasÚintr6   )r   Zstore_builderZdeltasZsupportsÚindexr	   r	   r
   Úadd_to_variation_store]   s    

z%VariableScalar.add_to_variation_storeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úpropertyr&   r+   r0   r,   r   r4   r6   r8   r7   r;   r>   r	   r	   r	   r
   r      s$   



r   N)ZfontTools.varLib.modelsr   r   r   r   r	   r	   r	   r
   Ú<module>   s   