Ë
    ^ãj  ã            	       óê   — U d Z ddlZddlZddlZddlmZ ddlmZ  ej                  e	«      Z
g d¢Zeegef   Zeed<   	 dedefd	„Zdedefd
„Zefdedededefd„Zefdededefd„Zdededefd„Zy)z#
Various round-to-integer helpers.
é    N)ÚCallable)Ú	TypeAlias)ÚnoRoundÚotRoundÚ
maybeRoundÚ	roundFuncÚnearestMultipleShortestReprÚRoundingFunctionÚvalueÚreturnc                 ó   — | S )z§Return float value unmodified; do not round.

    Args:
            value (float): The input floating-point value.

    Returns
            float: The same value.
    © ©r   s    ú[/var/www/html/metafoliadorv2/venv/lib/python3.12/site-packages/fontTools/misc/roundTools.pyr   r      s	   € ð €Ló    c                 óD   — t        t        j                  | dz   «      «      S )a  Round float value to nearest integer towards ``+Infinity``.

    The OpenType spec (in the section on `"normalization" of OpenType Font Variations <https://docs.microsoft.com/en-us/typography/opentype/spec/otvaroverview#coordinate-scales-and-normalization>`_)
    defines the required method for converting floating point values to
    fixed-point. In particular it specifies the following rounding strategy:

            for fractional values of 0.5 and higher, take the next higher integer;
            for other fractional values, truncate.

    This function rounds the floating-point value according to this strategy
    in preparation for conversion to fixed-point.

    Args:
            value (float): The input floating-point value.

    Returns
            int: The rounded value.
    ç      à?)ÚintÚmathÚfloorr   s    r   r   r   &   s   € ô* Œt�z‰z˜% #™+Ó&Ó'Ð'r   ÚvÚ	toleranceÚroundc                 ó<   —  || «      }t        || z
  «      |k  r|S | S )aŠ  Round only if rounding changes the value by no more than a given amount.

    Args:
            value (float): The input floating-point value.
            tolerance (float): The maximum absolute difference permitted.
            round (function): The rounding strategy, taking and giving a float.

    Returns
            float: A rounded value if within tolerance, otherwise the original.
    )Úabs)r   r   r   Úroundeds       r   r   r   >   s(   € ñ �A‹h€GÜ˜' A™+Ó&¨)Ò3ˆ7Ð:¸Ð:r   c                 ó~   — | dk  rt        d«      ‚| dk(  rt        S | dk\  r|S t        j                  t        | |¬«      S )aä  Make a conditional rounding strategy from a base strategy and tolerance.

    This preconfigures :func:`maybeRound` with fixed arguments, allowing it to be
    used anywhere a simple rounding function is accepted.

    The tolerance is validated to ensure it is absolute, and the cases where
    rounding would never or always occur are optimized. Rounding must never
    change a value by more than 0.5 for this to be sound (e.g.  :py:func:`ceil`
    could change by too much).

    Args:
            tolerance (float): The maximum absolute difference permitted.
            round (function): The rounding strategy, taking and giving a float.

    Returns
            function: A strategy that conditionally rounds based on tolerance.
    r   z#Rounding tolerance must be positiver   ©r   r   )Ú
ValueErrorr   Ú	functoolsÚpartialr   r   s     r   r   r   M   sE   € ð$ �1‚}ÜÐ>Ó?Ð?à�A‚~Üˆà�CÒØˆä×ÑœZ°9ÀEÔJÐJr   Úfactorc                 óš  — | syt        | |z  «      |z  } d|z  }| |z
  }| |z   }t        |«      t        |«      k7  rt        t        t	        | «      «      «      S d}||z  }||z  }t        |«      t        |«      k(  r||k7  sJ ‚t        t        |«      «      D ]  }||   ||   k7  sŒ n |j                  d«      }|k  sJ ‚d||z
  z  }|| z  S )a"  Round to nearest multiple of factor and return shortest decimal representation.

    This chooses the float that is closer to a multiple of the given factor while
    having the shortest decimal representation (the least number of fractional decimal
    digits).

    For example, given the following:

    >>> nearestMultipleShortestRepr(-0.61883544921875, 1.0/(1<<14))
    '-0.61884'

    Useful when you need to serialize or print a fixed-point number (or multiples
    thereof, such as F2Dot14 fractions of 180 degrees in COLRv1 PaintRotate) in
    a human-readable form.

    Args:
        value (value): The value to be rounded and serialized.
        factor (float): The value which the result is a close multiple of.

    Returns:
        str: A compact string representation of the value.
    z0.0r   z%.8fú.z%%.%df)r   r   ÚstrÚfloatr   ÚlenÚrangeÚfind)r   r"   ÚepsÚloÚhiÚfmtÚiÚperiods           r   r	   r	   k   së   € ñ. Øä�E˜F‘NÓ# fÑ,€EØ
�‰,€CØ	�‰€BØ	�‰€Bä
ˆ2ƒw”#�b“'ÒÜ”5œ˜u›Ó&Ó'Ð'à
€CØ	ˆr‰€BØ	ˆr‰€BÜˆr‹7”c˜"“gÒ "¨¢(Ð*Ð*Ü”3�r“7‹^ò ˆØˆa‰5�B�q‘E‹>Ùðð �W‰W�S‹\€FØ�AŠ:Ðˆ:Ø
�a˜&‘jÑ
!€CØ�‰;Ðr   )Ú__doc__r   r    ÚloggingÚcollections.abcr   Útypingr   Ú	getLoggerÚ__name__ÚlogÚ__all__r&   r
   Ú__annotations__r   r   r   r   r   r%   r	   r   r   r   ú<module>r9      sá   ðòó Û Û Ý $Ý à€g×Ñ˜Ó!€ò€ð '¨ w° ~Ñ6Ð �)Ó 6ð,ð	�5ð 	˜Uó 	ð(�5ð (˜Só (ð0 FMñ ;�%ð ; Eð ;Ð2Bð ;ÐQVó ;ð ;Bñ K˜ð KÐ'7ð KÐFVó Kð<, uð ,°eð ,Àô ,r   