U
    P’“e)
  ã                   @   s(   d Z dZddlmZ G dd„ deƒZdS )a«  
Dejitter
========

Prevent blob jittering.

A problem that is often faced (esp. in optical MT setups) is that of
jitterish BLOBs caused by bad camera characteristics. With this module
you can get rid of that jitter. You just define a threshold
`jitter_distance` in your config, and all touch movements that move
the touch by less than the jitter distance are considered 'bad'
movements caused by jitter and will be discarded.
)ÚInputPostprocDejitteré    )ÚConfigc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	r   a¸  
    Get rid of jitterish BLOBs.
    Example::

        [postproc]
        jitter_distance = 0.004
        jitter_ignore_devices = mouse,mactouch

    :Configuration:
        `jitter_distance`: float
            A float in range 0-1.
        `jitter_ignore_devices`: string
            A comma-separated list of device identifiers that
            should not be processed by dejitter (because they're
            very precise already).
    c                 C   s0   t  dd¡| _t  dd¡}| d¡| _i | _d S )NZpostprocZjitter_distanceZjitter_ignore_devicesú,)r   ÚgetfloatÚ
jitterdistÚgetÚsplitÚignore_devicesÚlast_touches)Úselfr	   © r   ú@/tmp/pip-unpacked-wheel-xzebddm3/kivy/input/postproc/dejitter.pyÚ__init__&   s    zInputPostprocDejitter.__init__c                 C   s(   t |d |d  ƒt |d |d  ƒ S )Nr   é   )Úabs)r   ÚpÚqr   r   r   Útaxicab_distance,   s    z&InputPostprocDejitter.taxicab_distancec                 C   sÐ   | j s
|S g }|D ]¸\}}|js"q|j| jkr>| ||f¡ q|dkrT|j| j|j< |dkrr|j| jkrr| j|j= |dkrŠ| ||f¡ q| j|j }|  ||j¡}|| j kr|j| j|j< | ||f¡ q|S )NÚbeginÚendÚupdate)	r   Zis_touchZdevicer	   ÚappendÚsposr
   Úidr   )r   ÚeventsÚ	processedÚetypeÚtouchZ	last_sposÚdistr   r   r   Úprocess0   s.    

zInputPostprocDejitter.processN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r      s   r   N)r#   Ú__all__Zkivy.configr   Úobjectr   r   r   r   r   Ú<module>   s   