�
��ge � �~ � d Z ddlZddlZddlZ ej e� � Zg d�Zd� Zd� Z e fd�Z
e fd�Zded ed
e
fd�ZdS )z#
Various round-to-integer helpers.
� N)�noRound�otRound�
maybeRound� roundFunc�nearestMultipleShortestReprc � � | S �N� ��values �i/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/fontTools/misc/roundTools.pyr r s � ��L� c �J � t t j | dz � � � � 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
float: The rounded value.
� �?)�int�math�floorr s r
r r s � �* �t�z�%�#�+�&�&�'�'�'r c �L � || � � }t || z
� � |k r|n| S r )�abs)�v� tolerance�round�roundeds r
r r 0 s/ � ��e�A�h�h�G��'�A�+�&�&�)�3�3�7�7��:r c � � | dk rt d� � �| dk rt S | dk r|S t j t | |�� � S )Nr z#Rounding tolerance must be positiver �r r )�
ValueErrorr � functools�partialr r s r
r r 5 sP � ��1�}�}��>�?�?�?��A�~�~����C�������Z�9�E�J�J�J�Jr r �factor�returnc � � | sdS t | |z � � |z } d|z }| |z
}| |z }t |� � t |� � k r)t t t | � � � � � � S d}||z }||z }t |� � t |� � k r||k sJ �t
t |� � � � D ]}|| || k r n�|� d� � }||k sJ �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.
z0.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 � �. � ��u��E�F�N�#�#�f�,�E�
��,�C� ���B� ���B�
�2�w�w�#�b�'�'����5��u���&�&�'�'�'�
�C� �r��B� �r��B��r�7�7�c�"�g�g���"��(�(�(�*�
�3�r�7�7�^�^� � ��
�a�5�B�q�E�>�>��E� �
�W�W�S�\�\�F��A�:�:�:�:�
�a�&�j�
!�C���;�r )�__doc__r r �logging� getLogger�__name__�log�__all__r r r r r$ r# r r
r r
�<module>r4 s� ��� � ���� � � � � �����g���!�!��� � ��� � �(� (� (�0 $+� ;� ;� ;� ;�
'�
K�
K�
K�
K�,�u� ,�e� ,�� ,� ,� ,� ,� ,� ,r