
    he                         S r SSKrSSKrSSKr\R                  " \5      r/ SQrS rS r	\	4S jr
\	4S jrS\S	\S
\4S jrg)z#
Various round-to-integer helpers.
    N)noRoundotRound
maybeRound	roundFuncnearestMultipleShortestReprc                     U $ N values    K/var/www/html/env/lib/python3.13/site-packages/fontTools/misc/roundTools.pyr   r      s    L    c                 F    [        [        R                  " U S-   5      5      $ )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
        float: The rounded value.
      ?)intmathfloorr   s    r   r   r      s    * tzz%#+&''r   c                 <    U" U 5      n[        X0-
  5      U::  a  U$ U $ r	   )abs)v	toleranceroundroundeds       r   r   r   0   s$    AhG'+&)37::r   c                 ~    U S:  a  [        S5      eU S:X  a  [        $ U S:  a  U$ [        R                  " [        XS9$ )Nr   z#Rounding tolerance must be positiver   r   r   )
ValueErrorr   	functoolspartialr   r   s     r   r   r   5   sA    1}>??A~CZ9JJr   r   factorreturnc                    U (       d  g[        X-  5      U-  n SU-  nX-
  nX-   n[        U5      [        U5      :w  a  [        [        [	        U 5      5      5      $ SnXS-  nXT-  n[        U5      [        U5      :X  a  X4:w  d   e[        [        U5      5       H  nX6   XF   :w  d  M    O   UR                  S5      nUW:  d   eSXg-
  -  nXP-  $ )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   B   s    . EN#f,E
,C	B	B
2w#b'5u&''
C	B	Br7c"g"(**3r7^5BE>  WWS\FA::
aj
!C;r   )__doc__r   r   logging	getLogger__name__log__all__r   r   r   r   r$   r#   r   r
   r   r   <module>r4      se      !(0 $+ ;
  ' 
K,u ,e , ,r   