)Ej ~dZddlZddlZddlZejeZgdZdZdZ e fdZ e fdZ de d e d e fd ZdS) z# Various round-to-integer helpers. N)noRoundotRound maybeRound roundFuncnearestMultipleShortestReprc|SNvalues KC:\PYTHON\MyICR_Suite\python\Lib\site-packages\fontTools/misc/roundTools.pyrrs LcJttj|dzS)aRound float value to nearest integer towards ``+Infinity``. The OpenType spec (in the section on `"normalization" of OpenType Font Variations `_) 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. ?)intmathfloorr s r rrs * tz%#+&& ' ''rcL||}t||z |kr|n|Sr )abs)v toleranceroundroundeds r rr0s/eAhhG'A+&&)3377:rc|dkrtd|dkrtS|dkr|Stjt||S)Nrz#Rounding tolerance must be positiverrr) ValueErrorr functoolspartialrrs r rr5sP1}}>???A~~C  Z9E J J JJrr factorreturnc|sdSt||z |z}d|z}||z }||z}t|t|kr)ttt |Sd}||z}||z}t |t |kr||ksJt t |D]}||||krn|d}||ksJd||z z}||zS)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.0rz%.8f.z%%.%df)rrstrfloatrlenrangefind)r repslohifmtiperiods r rrBs. u EFN # #f ,E ,C B B 2ww#b''5u&&''' C rB rB r77c"gg  "((( * 3r77^^ a5BqE>> E  WWS\\F A:::: a&j !C ;r)__doc__rrlogging getLogger__name__log__all__rrrrr$r#rr rr r4s g!!   (((0$+;;;; ' K K K K,u,e,,,,,,,r