o
     Pjl                     @   sR   d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	m
Z
mZ G dd dZdS )	z8Random vector generator used for weighting perlin noise.    )reduce)mul)ListTuple)dotfadesample_vectorc                   @   st   e Zd ZdZdeedf defddZdee deedf fdd	Z	dee defd
dZ
dee defddZdS )RandVecz6Vectors to give weights and contribute in final value.coordinates.seedc                 C   s   || _ tt| j |d| _dS )zVector initializer in specified coordinates.

        Parameters:
            coordinates: Tuple[int] - vector coordinates
            seed: int - random init seed
        )
dimensionsr   N)r
   r   lenvec)selfr
   r    r   J/home/thesage/.local/lib/python3.10/site-packages/perlin_noise/rand_vec.py__init__   s   zRandVec.__init__returnc                 C   s   t dd t|| jD S )zCalculate distance to given coordinates.

        Parameters:
            coordinates: Tuplie[int] - coordinates to calculate distance

        Returns:
            distance

        c                 s   s    | ]	\}}|| V  qd S )Nr   ).0coor1coor2r   r   r   	<genexpr>!   s    
z#RandVec.dists_to.<locals>.<genexpr>)tuplezipr
   r   r
   r   r   r   dists_to   s   

zRandVec.dists_toc                 C   s   dd |  |D }tt|S )zCalculate this vector weights to given coordinates.

        Parameters:
            coordinates: Tuple[int] - target coordinates

        Returns:
            weight
        c                 S   s   g | ]
}t d t| qS )   )r   abs)r   distr   r   r   
<listcomp>/   s    z%RandVec.weight_to.<locals>.<listcomp>)r   r   r   )r   r
   weighted_distsr   r   r   	weight_to%   s   

zRandVec.weight_toc                 C   s   |  |t| j| | S )zCalculate weighted contribution of this vec to final result.

        Parameters:
            coordinates: calculate weighted relative to this coordinates

        Returns:
            weighted contribution
        )r!   r   r   r   r   r   r   r   get_weighted_val3   s   
	zRandVec.get_weighted_valN)__name__
__module____qualname____doc__r   intr   r   floatr   r!   r"   r   r   r   r   r	   
   s    
r	   N)r&   	functoolsr   operatorr   typingr   r   perlin_noise.toolsr   r   r   r	   r   r   r   r   <module>   s    