
    h              	          S r SSKJr  SSKJr  SSKJrJrJrJ	r	  SSK
Jr  SSKJr  SSKJr  SS jrSS	 jrSS
 jr\\\\\4   \4   \" \5      \" \5      4   r\\\\\4   \4   \" \5      \" \5      \" \5      4   r\	SS j5       r\	SS j5       rSS jr\\\\\4   \4   \" \5      4   rSS jrSS jrSS jr\" S\\5      r   S         SS jjr\\\\\4   \4   \" \5      \" \" SS5      5      \" \5      4   r\\\\\4   \4   \" \5      \" \" SS5      5      4   r \\\\\4   \4   \" \5      \" \" SS5      5      \" \5      4   r!\\\\4   \" \" SS5      5      \" \5      \" \5      4   r"g)a  Module containing Pydantic validation utilities for Albumentations.

This module provides a collection of validators and utility functions used for validating
parameters in the Pydantic models throughout the Albumentations library. It includes
functions for ensuring numeric ranges are valid, handling type conversions, and creating
standardized validation patterns that are reused across the codebase.
    )annotations)Callable)	AnnotatedTypeVarUnionoverload)AfterValidator)Numberto_tuplec                <    U S   U S   ::  d  [        SU  S35      eU $ )a  Ensure a tuple of two numbers is in non-decreasing order.

Args:
    value (tuple[Number, Number]): Tuple of two numeric values to validate.

Returns:
    tuple[Number, Number]: The original tuple if valid.

Raises:
    ValueError: If the first value is greater than the second value.

r      z6First value should be less than the second value, got z instead)
ValueErrorvalues    V/var/www/fran/franai/venv/lib/python3.13/site-packages/albumentations/core/pydantic.pynondecreasingr      s1     8uQxQRWQXX`abbL    c                p    [        U b  U OSS5      n[        S U 5       5      (       d  Sn[        U5      eU$ )aw  Process and validate a non-negative range.

Args:
    value (tuple[float, float] | float | None): Value to process. Can be:
        - A tuple of two floats
        - A single float (converted to symmetric range)
        - None (defaults to 0)

Returns:
    tuple[float, float]: Validated non-negative range.

Raises:
    ValueError: If any values in the range are negative.

r   c              3  *   #    U  H	  oS :  v   M     g7f)r   N ).0xs     r   	<genexpr>-process_non_negative_range.<locals>.<genexpr>7   s     &v!Avvs   z;All values in the non negative range should be non negative)r   allr   )r   resultmsgs      r   process_non_negative_ranger   &   s<      u0ea;F&v&&&KoMr   c                :    [        U S   5      [        U S   5      4$ )zConvert a tuple of floats to a tuple of integers.

Args:
    value (tuple[float, float]): Tuple of two float values.

Returns:
    tuple[int, int]: Tuple of two integer values.

r   r   )intr   s    r   	float2intr"   =   s     uQx=#eAh-''r   c                    g Nr   r   s    r   create_symmetric_ranger%   X   s    MPr   c                    g r$   r   r   s    r   r%   r%   \   s    WZr   c                    [        U 5      $ )a  Create a symmetric range around zero or use provided range.

Args:
    value (tuple[float, float] | float): Input value, either:
        - A tuple of two floats (used directly)
        - A single float (converted to (-value, value))

Returns:
    tuple[float, float]: Symmetric range.

r   r   s    r   r%   r%   `   s     E?r   c                    [        U SS9$ )zConvert value to a range with lower bound of 1.

Args:
    value (tuple[float, float] | float): Input value.

Returns:
    tuple[float, float]: Range with minimum value of at least 1.

r   lowr   r   s    r   convert_to_1plus_ranger+   r        Eq!!r   c                    [        U SS9$ )zConvert value to a range with lower bound of 0.

Args:
    value (tuple[float, float] | float): Input value.

Returns:
    tuple[float, float]: Range with minimum value of at least 0.

r   r)   r   r   s    r   convert_to_0plus_ranger.      r,   r   c                B    [        U [        [        45      (       a  X 4$ U $ )a  Convert a scalar value to a tuple by repeating it, or return the tuple as is.

Args:
    value (tuple[float, float] | float): Input value, either a scalar or tuple.

Returns:
    tuple[float, float]: If input is scalar, returns (value, value), otherwise returns input unchanged.

)
isinstancer!   floatr   s    r   repeat_if_scalarr2      s!     (U|<<E>G%Gr   TNc                $   ^ ^^^ SUUUU 4S jjnU$ )aL  Validates that all values in a tuple are within specified bounds.

Args:
    min_val (int | float):
        Minimum allowed value.
    max_val (int | float | None):
        Maximum allowed value. If None, only lower bound is checked.
    min_inclusive (bool):
        If True, min_val is inclusive (>=). If False, exclusive (>).
    max_inclusive (bool):
        If True, max_val is inclusive (<=). If False, exclusive (<).

Returns:
    Callable[[tuple[T, ...] | None], tuple[T, ...] | None]: Validator function that
        checks if all values in tuple are within bounds. Returns None if input is None.

Raises:
    ValueError: If any value in tuple is outside the allowed range

Examples:
    >>> validator = check_range_bounds(0, 1)  # For [0, 1] range
    >>> validator((0.1, 0.5))  # Valid 2D
    (0.1, 0.5)
    >>> validator((0.1, 0.5, 0.7))  # Valid 3D
    (0.1, 0.5, 0.7)
    >>> validator((1.1, 0.5))  # Raises ValueError - outside range
    >>> validator = check_range_bounds(0, 1, max_inclusive=False)  # For [0, 1) range
    >>> validator((0, 1))  # Raises ValueError - 1 not included

c                b  >^^ U c  g T(       a  S OS mT(       a  S OS mTc=  [        UU	4S jU  5       5      (       d  T(       a  SOSn[        SU  S	U S
T	 35      e U $ T(       a  SOSnT(       a  SOSn[        UUUU	4S jU  5       5      (       d  [        SU  S	U S
T	 SU S
T 3
5      eU $ )Nc                
    X:  $ r$   r   r   ys     r   <lambda>7check_range_bounds.<locals>.validator.<locals>.<lambda>       qvr   c                
    X:  $ r$   r   r7   s     r   r9   r:          15r   c                
    X:*  $ r$   r   r7   s     r   r9   r:      r;   r   c                
    X:  $ r$   r   r7   s     r   r9   r:      r=   r   c              3  6   >#    U  H  nT" UT5      v   M     g 7fr$   r   )r   r   min_opmin_vals     r   r   8check_range_bounds.<locals>.validator.<locals>.<genexpr>   s     95ava))5s   z>=>zAll values in z	 must be  z<=<c              3  V   >#    U  H  nT" UT5      =(       a	    T" UT5      v   M      g 7fr$   r   )r   r   max_opmax_valrA   rB   s     r   r   rC      s'     P%Qva)@fQ.@@%s   &)z and )r   r   )
r   	op_symbol
min_symbol
max_symbolrH   rA   max_inclusiverI   min_inclusiverB   s
       @@r   	validator%check_range_bounds.<locals>.validator   s    =*7%>P*7%>P?95999$1Ds	 >%	)AgY!WXX : 	 "/CJ!.CJP%PPP >%	*QwiW\]g\hhijqir!sttr   )r   tuple[T, ...] | NonereturnrQ   r   )rB   rI   rN   rM   rO   s   ```` r   check_range_boundsrS      s    J $ r   r   )r   tuple[Number, Number]rR   rT   )r   z"tuple[float, float] | float | NonerR   tuple[float, float])r   rU   rR   tuple[int, int])r   ztuple[int, int] | intrR   rV   )r   ztuple[float, float] | floatrR   rU   )NTT)
rB   r
   rI   zNumber | NonerN   boolrM   rW   rR   z6Callable[[tuple[T, ...] | None], tuple[T, ...] | None])#__doc__
__future__r   collections.abcr   typingr   r   r   r   pydantic.functional_validatorsr	   $albumentations.core.type_definitionsr
   albumentations.core.utilsr   r   r   r"   tupler1   NonNegativeFloatRangeTyper!   NonNegativeIntRangeTyper%   SymmetricRangeTyper+   r.   r2   r3   rS   ZeroOneRangeTypeOnePlusFloatRangeTypeOnePlusIntRangeType OnePlusIntNonDecreasingRangeTyper   r   r   <module>rg      sh   # $ 6 6 9 7 .$.
( &	%u
u
$%-.=!#  $	%S/3
-.=!9  
 P 
 P 
 Z 
 Z uU5%<%8%%?@.QgBhhi 
"
"
H Ce
 "	777 7 	7
 <7t 	%u
u
$%)*%a+,=!#  "	%u
u
$%)*%a./1 
  	%u
u
$%)*%a./9  $-	#s(O%a./=!9$  r   