
    >i                        d dl mZ d dlZd dlZ G d d      Zd	dZ	 	 	 	 	 	 	 	 	 	 	 	 d
dZ	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)    )annotationsNc                  B    e Zd ZdZd	dZd
dZd
dZd
dZdddZddZ	y)CubicBezierzCubic Bezier curve solver for smooth animation timing.

    Based on UnitBezier from WebKit/Chromium. Maps a time progress value
    to an eased progress value using a cubic Bezier curve.
    c                   d|z  | _         d||z
  z  | j                   z
  | _        d| j                   z
  | j                  z
  | _        d|z  | _        d||z
  z  | j                  z
  | _        d| j                  z
  | j                  z
  | _        y )N      @      ?)coefficient_c_xcoefficient_b_xcoefficient_a_xcoefficient_c_ycoefficient_b_ycoefficient_a_y)selfpoint1_xpoint1_ypoint2_xpoint2_ys        _/var/www/python/tenders/Scrapper/venv/lib/python3.12/site-packages/pydoll/interactions/utils.py__init__zCubicBezier.__init__   s    "X~"h&9:T=Q=QQ"T%9%99D<P<PP"X~"h&9:T=Q=QQ"T%9%99D<P<PP    c                `    | j                   |z  | j                  z   |z  | j                  z   |z  S Nr   r
   r	   r   time_progresss     r   sample_curve_xzCubicBezier.sample_curve_x   ;    !!M1D4H4HHMY""# 	r   c                `    | j                   |z  | j                  z   |z  | j                  z   |z  S r   )r   r   r   r   s     r   sample_curve_yzCubicBezier.sample_curve_y   r   r   c                f    d| j                   z  |z  d| j                  z  z   |z  | j                  z   S )Nr   g       @r   r   s     r   sample_curve_derivative_xz%CubicBezier.sample_curve_derivative_x#   s@    $&&&6t?S?S9SS 001 	1r   c                x   |}t        d      D ]Q  }| j                  |      |z
  }t        |      |k  r|c S | j                  |      }t        |      |k  r n
|||z  z  }S d}d}|}||k  r|S ||kD  r|S ||k  r?| j                  |      }t        ||z
        |k  r|S ||kD  r|}n|}||z
  dz  |z   }||k  r?|S )z1Given an x value, find the corresponding t value.   g        r   g      ?)ranger   absr!   )	r   target_xepsilonestimated_t_	current_x
derivativelower_boundupper_bounds	            r   solve_curve_xzCubicBezier.solve_curve_x(   s   q 	2A++K88CI9~'""77DJ:(9z11K	2 $$K'++K8I9x'(72"")#))&4;kIK K' r   c                B    | j                  | j                  |            S )z*Get y value for a given x (time progress).)r   r.   )r   input_xs     r   solvezCubicBezier.solveJ   s    ""4#5#5g#>??r   N)r   floatr   r2   r   r2   r   r2   )r   r2   returnr2   )gư>)r&   r2   r'   r2   r3   r2   )r0   r2   r3   r2   )
__name__
__module____qualname____doc__r   r   r   r!   r.   r1    r   r   r   r      s(    Q1
 D@r   r   c                D    | | z  }|| z  }d|z  d|z  | z  z
  d|z  |z  z   S )zMinimum jerk position at normalized time t in [0,1].

    Returns 10t^3 - 15t^4 + 6t^5 which produces a bell-shaped velocity
    profile: slow start, peak in middle, slow end.
    g      $@g      .@g      @r8   )tt2t3s      r   minimum_jerkr=   O   s:     
QB	aB"9tby1}$sRx"}44r   c                    d| z
  }||z  }||z  }| | z  }|| z  }	||d   z  d|z  | z  |d   z  z   d|z  |z  |d   z  z   |	|d   z  z   }
||d   z  d|z  | z  |d   z  z   d|z  |z  |d   z  z   |	|d   z  z   }|
|fS )zmEvaluate 2D cubic Bezier at parameter t.

    B(t) = (1-t)^3*P0 + 3(1-t)^2*t*P1 + 3(1-t)*t^2*P2 + t^3*P3
    r   r   r      r8   )r:   p0p1p2p3uu2u3r;   r<   xys               r   	bezier_2drI   Z   s     	aA	
QB	aB	
QB	aB
RU
S2X\BqE))C!GbL2a5,@@21:MA
RU
S2X\BqE))C!GbL2a5,@@21:MAq6Mr   c                R    | dk  r|S ||t        j                  | |z  dz         z  z   S )z(Fitts's Law: MT = a + b * log2(D/W + 1).r   r   )mathlog2)distancetarget_widthabs       r   fitts_durationrQ   o   s3     1}q499X4s:;;;;r   c                   |d   | d   z
  }|d   | d   z
  }t        j                  ||      }|dk  r| |fS | |z  ||z  f}	t        d||z        }
t        j                  ||      |z  |
z  t        j                  ||      |z  |
z  f}t        j
                  ddg      }t        j                  d|      }t        j                  |d      }| d   ||z  z   |	d   |d   z  |z  z   | d   ||z  z   |	d   |d   z  |z  z   f}t        j                  dd      }| d   ||z  z   |	d   |d   z  |z  |z  z   | d   ||z  z   |	d   |d   z  |z  |z  z   f}||fS )zGenerate randomized 2D Bezier control points for a curved mouse path.

    Control points are offset perpendicular to the start-end line.
    The first control point is biased earlier along the path
    (ballistic phase asymmetry).
    r   r?   r   g      g?g?g333333?)rK   hypotminrandomuniformchoice)startendcurvature_mincurvature_maxcurvature_asymmetryshort_distance_thresholddxdyrM   perpscaleoffsetssignt1r;   cp1countercp2s                     r   random_control_pointsrh   {   s    
Q%(	B	Q%(	Bzz"b!H#~s|C(NBM*DX 889E}m4x?%G}m4x?%GG
 ==$%D	0	1B	+S	1B 	a27T!Wwqz1D88a27T!Wwqz1D88C
 nnS#&Ga27T!Wwqz1D87BBa27T!Wwqz1D87BBC
 :r   )r:   r2   r3   r2   )r:   r2   r@   tuple[float, float]rA   ri   rB   ri   rC   ri   r3   ri   )
rM   r2   rN   r2   rO   r2   rP   r2   r3   r2   )rX   ri   rY   ri   rZ   r2   r[   r2   r\   r2   r]   r2   r3   z/tuple[tuple[float, float], tuple[float, float]])	
__future__r   rK   rU   r   r=   rI   rQ   rh   r8   r   r   <module>rk      s    "  E@ E@P5 	 		
 	 *	<	<	< 	< 		<
 	<,,	, , 	,
 , $, 5,r   