ó
    oñ:iÛ,  ã                   óB  • S r SSKJr  SSKJr  SSKrSSKrS r\4S jr	\
\4S jrS rS	 rS
 rS rS rS rS rS rS rS rS rS rS rSS jr " S S\5      rSS jrS r\S:X  a4  SSKrSSKr\R@                  " \RB                  " 5       RD                  5        gg)zTRoutines for calculating bounding boxes, point in rectangle calculations and
so on.
é    )ÚotRound)ÚVectorNc                 óÖ   • U (       d  gU  VVs/ s H  u  pUPM	     nnnU  VVs/ s H  u  pUPM	     nnn[        U5      [        U5      [        U5      [        U5      4$ s  snnf s  snnf )zÄCalculate the bounding rectangle of a 2D points array.

Args:
    array: A sequence of 2D tuples.

Returns:
    A four-item tuple representing the bounding rectangle ``(xMin, yMin, xMax, yMax)``.
©r   r   r   r   ©ÚminÚmax)ÚarrayÚxÚyÚxsÚyss        Ú\/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/fontTools/misc/arrayTools.pyÚ
calcBoundsr      s]   € ö ØÙÔ	š‘�‹!™€BÑ	ÙÔ	š‘�‹!™€BÑ	Üˆr‹7”C˜“GœS ›W¤c¨"£gÐ-Ð-ùó 
ùÛ	s
   ŽA¤A%c                 ó@   ^• [        U4S j[        U 5       5       5      $ )aÓ  Calculate the integer bounding rectangle of a 2D points array.

Values are rounded to closest integer towards ``+Infinity`` using the
:func:`fontTools.misc.fixedTools.otRound` function by default, unless
an optional ``round`` function is passed.

Args:
    array: A sequence of 2D tuples.
    round: A rounding function of type ``f(x: float) -> int``.

Returns:
    A four-item tuple of integers representing the bounding rectangle:
    ``(xMin, yMin, xMax, yMax)``.
c              3   ó4   >#   • U  H  nT" U5      v •  M     g 7f)N© )Ú.0ÚvÚrounds     €r   Ú	<genexpr>Ú calcIntBounds.<locals>.<genexpr>*   s   øé € Ð5Ò#4˜a‘�q—�Ò#4ùs   ƒ)Útupler   )r
   r   s    `r   ÚcalcIntBoundsr      s   ø€ ô Ô5¤:¨eÔ#4Ó5Ó5Ð5ó    c                 ó^   • Uu  pEU c  XEXE4$ U u  pgp‰U" Xd5      U" Xu5      U" X„5      U" X•5      4$ )a?  Add a point to a bounding rectangle.

Args:
    bounds: A bounding rectangle expressed as a tuple
        ``(xMin, yMin, xMax, yMax), or None``.
    p: A 2D tuple representing a point.
    min,max: functions to compute the minimum and maximum.

Returns:
    The updated bounding rectangle ``(xMin, yMin, xMax, yMax)``.
r   )
ÚboundsÚpr   r	   r   r   ÚxMinÚyMinÚxMaxÚyMaxs
             r   ÚupdateBoundsr#   -   sC   € ð �F€QØ�~Ø�QˆzÐØ#Ñ€D�Ùˆt‹<™˜T›¡s¨4£|±S¸³\ÐAÐAr   c                 ór   • U u  p#Uu  pEpgXBs=:*  =(       a    U:*  Os  =(       a    XSs=:*  =(       a    U:*  $ s  $ )a  Test if a point is inside a bounding rectangle.

Args:
    p: A 2D tuple representing a point.
    rect: A bounding rectangle expressed as a tuple
        ``(xMin, yMin, xMax, yMax)``.

Returns:
    ``True`` if the point is inside the rectangle, ``False`` otherwise.
r   )r   Úrectr   r   r   r    r!   r"   s           r   ÚpointInRectr&   @   s<   € ð �F€QØ!Ñ€D�Ø×Ó˜Ô×6 D×$5Ó$5°Ñ$5Ð6Ñ$5Ð6r   c                 óÂ   • [        U 5      S:  a  / $ Uu  p#pEU  VVs/ s H4  u  pgX&s=:*  =(       a    U:*  Os  =(       a    X7s=:*  =(       a    U:*  Os  PM6     snn$ s  snnf )zþDetermine which points are inside a bounding rectangle.

Args:
    array: A sequence of 2D tuples.
    rect: A bounding rectangle expressed as a tuple
        ``(xMin, yMin, xMax, yMax)``.

Returns:
    A list containing the points inside the rectangle.
é   )Úlen)r
   r%   r   r    r!   r"   r   r   s           r   ÚpointsInRectr*   P   sV   € ô ˆ5ƒz�Aƒ~Øˆ	Ø!Ñ€D�ÙDIÔJÂE¹D¸AˆT×Ó˜$Ô×7 T×%6Ó%6°$Ô%6Ò7ÁEÒJÐJùÓJs   œ;Ac                 óH   • U u  p[         R                  " US-  US-  -   5      $ )z{Calculate the length of the given vector.

Args:
    vector: A 2D tuple.

Returns:
    The Euclidean length of the vector.
é   )ÚmathÚsqrt)Úvectorr   r   s      r   ÚvectorLengthr0   a   s&   € ð �D€AÜ�9Š9�Q˜‘T˜A˜q™D‘[Ó!Ð!r   c           	      ór   • U  Vs/ s H%  n[        [        R                  " US-   5      5      PM'     sn$ s  snf )z„Round a list of floats to 16-bit signed integers.

Args:
    array: List of float values.

Returns:
    A list of rounded integers.
g      à?)Úintr-   Úfloor)r
   Úis     r   ÚasInt16r5   n   s.   € ñ /4Ó4ªe¨ŒC”—
’
˜1˜s™7Ó#Ö$©eÑ4Ð4ùÒ4s   …,4c                 ó`   • U u  pp4[        X5      [        X$5      [        X5      [        X$5      4$ )a,  Normalize a bounding box rectangle.

This function "turns the rectangle the right way up", so that the following
holds::

    xMin <= xMax and yMin <= yMax

Args:
    rect: A bounding rectangle expressed as a tuple
        ``(xMin, yMin, xMax, yMax)``.

Returns:
    A normalized bounding rectangle.
r   ©r%   r   r    r!   r"   s        r   ÚnormRectr8   z   s-   € ð  $Ñ€T�Üˆt‹?œC ›O¬S°«_¼cÀ$»oÐMÐMr   c                 ó(   • U u  p4pVX1-  XB-  XQ-  Xb-  4$ )a  Scale a bounding box rectangle.

Args:
    rect: A bounding rectangle expressed as a tuple
        ``(xMin, yMin, xMax, yMax)``.
    x: Factor to scale the rectangle along the X axis.
    Y: Factor to scale the rectangle along the Y axis.

Returns:
    A scaled bounding rectangle.
r   )r%   r   r   r   r    r!   r"   s          r   Ú	scaleRectr:   �   s%   € ð  $Ñ€T�Ø‰8�T‘X˜t™x¨©Ð1Ð1r   c                 ó(   • U u  p4pVX1-   XB-   XQ-   Xb-   4$ )a   Offset a bounding box rectangle.

Args:
    rect: A bounding rectangle expressed as a tuple
        ``(xMin, yMin, xMax, yMax)``.
    dx: Amount to offset the rectangle along the X axis.
    dY: Amount to offset the rectangle along the Y axis.

Returns:
    An offset bounding rectangle.
r   ©r%   ÚdxÚdyr   r    r!   r"   s          r   Ú
offsetRectr?   �   ó%   € ð  $Ñ€T�Ø‰9�d‘i ¡¨D©IÐ5Ð5r   c                 ó(   • U u  p4pVX1-   XB-   XQ-
  Xb-
  4$ )a)  Inset a bounding box rectangle on all sides.

Args:
    rect: A bounding rectangle expressed as a tuple
        ``(xMin, yMin, xMax, yMax)``.
    dx: Amount to inset the rectangle along the X axis.
    dY: Amount to inset the rectangle along the Y axis.

Returns:
    An inset bounding rectangle.
r   r<   s          r   Ú	insetRectrB   ­   r@   r   c                 ó’   • U u  p#pEUu  pgp‰[        X&5      [        X75      [        XH5      [        XY5      4u  p«pÍX¬:¼  d  X½:¼  a  gSX«XÍ44$ )a�  Test for rectangle-rectangle intersection.

Args:
    rect1: First bounding rectangle, expressed as tuples
        ``(xMin, yMin, xMax, yMax)``.
    rect2: Second bounding rectangle.

Returns:
    A boolean and a rectangle.
    If the input rectangles intersect, returns ``True`` and the intersecting
    rectangle. Returns ``False`` and ``(0, 0, 0, 0)`` if the input
    rectangles don't intersect.
)Fr   T)r	   r   ©Úrect1Úrect2ÚxMin1ÚyMin1ÚxMax1ÚyMax1ÚxMin2ÚyMin2ÚxMax2ÚyMax2r   r    r!   r"   s                 r   ÚsectRectrO   ½   sb   € ð $)Ñ €U�5Ø#(Ñ €U�5äˆEÓÜˆEÓÜˆEÓÜˆEÓð	Ñ€D�ð ƒ|�t“|Ø"Ø�$˜dÐ)Ð)Ð)r   c                 óx   • U u  p#pEUu  pgp‰[        X&5      [        X75      [        XH5      [        XY5      4u  p«pÍX«XÍ4$ )a  Determine union of bounding rectangles.

Args:
    rect1: First bounding rectangle, expressed as tuples
        ``(xMin, yMin, xMax, yMax)``.
    rect2: Second bounding rectangle.

Returns:
    The smallest rectangle in which both input rectangles are fully
    enclosed.
r   rD   s                 r   Ú	unionRectrQ   Ø   sQ   € ð $)Ñ €U�5Ø#(Ñ €U�5äˆEÓÜˆEÓÜˆEÓÜˆEÓð	Ñ€D�ð ˜Ð#Ð#r   c                 ó(   • U u  pp4X-   S-  X$-   S-  4$ )zËDetermine rectangle center.

Args:
    rect: Bounding rectangle, expressed as tuples
        ``(xMin, yMin, xMax, yMax)``.

Returns:
    A 2D tuple representing the point at the center of the rectangle.
r,   r   r7   s        r   Ú
rectCenterrS   ï   s'   € ð  $Ñ€T�Ø‰K˜1Ñ˜t™{¨aÑ/Ð/Ð/r   c                 ó   • U u  pp4XB-
  X1-
  -  $ )z¢Determine rectangle area.

Args:
    rect: Bounding rectangle, expressed as tuples
        ``(xMin, yMin, xMax, yMax)``.

Returns:
    The area of the rectangle.
r   r7   s        r   ÚrectArearU   ý   s   € ð  $Ñ€T�Ø‰K˜D™KÑ(Ð(r   c                 ó  • U u  pp4[        [        R                  " U5      5      n[        [        R                  " U5      5      n[        [        R                  " U5      5      n[        [        R                  " U5      5      nXX44$ )zûRound a rectangle to integer values.

Guarantees that the resulting rectangle is NOT smaller than the original.

Args:
    rect: Bounding rectangle, expressed as tuples
        ``(xMin, yMin, xMax, yMax)``.

Returns:
    A rounded bounding rectangle.
)r2   r-   r3   Úceilr7   s        r   ÚintRectrX     sc   € ð  $Ñ€T�ÜŒt�zŠz˜$ÓÓ €DÜŒt�zŠz˜$ÓÓ €DÜŒt�yŠy˜‹Ó€DÜŒt�yŠy˜‹Ó€DØ˜Ð#Ð#r   c           	      ód  • US:  a  [        SU< 35      e[        U 5      u  p#pE[        [        R                  " X!-  5      U-  5      [        [        R                  " X1-  5      U-  5      [        [        R
                  " XA-  5      U-  5      [        [        R
                  " XQ-  5      U-  5      4$ )zÐ
>>> bounds = (72.3, -218.4, 1201.3, 919.1)
>>> quantizeRect(bounds)
(72, -219, 1202, 920)
>>> quantizeRect(bounds, factor=10)
(70, -220, 1210, 920)
>>> quantizeRect(bounds, factor=100)
(0, -300, 1300, 1000)
r(   z*Expected quantization factor >= 1, found: )Ú
ValueErrorr8   r2   r-   r3   rW   )r%   Úfactorr   r    r!   r"   s         r   ÚquantizeRectr\     s–   € ð �ƒzÜÐEÀfÁZÐPÓQÐQÜ% d›^Ñ€D�äŒD�JŠJ�t‘}Ó%¨Ñ.Ó/ÜŒD�JŠJ�t‘}Ó%¨Ñ.Ó/ÜŒD�IŠI�d‘mÓ$ vÑ-Ó.ÜŒD�IŠI�d‘mÓ$ vÑ-Ó.ð	ð r   c                   ó   • \ rS rSrS rSrg)r   i4  c                 ó:   • [         R                  " S[        5        g )NzffontTools.misc.arrayTools.Vector has been deprecated, please use fontTools.misc.vector.Vector instead.)ÚwarningsÚwarnÚDeprecationWarning)ÚselfÚargsÚkwargss      r   Ú__init__ÚVector.__init__5  s   € Ü�Šð4äõ	
r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__re   Ú__static_attributes__r   r   r   r   r   4  s   † õ
r   r   c              #   óž   #   • U (       d  gU(       a  [        U 5      nO[        U 5      n[        US5      nUnU H
  nXE4v •  UnM     XC4v •  g7f)a]  Iterate over current and next items in iterable.

Args:
    iterable: An iterable
    reverse: If true, iterate in reverse order.

Returns:
    A iterable yielding two elements per iteration.

Example:

    >>> tuple(pairwise([]))
    ()
    >>> tuple(pairwise([], reverse=True))
    ()
    >>> tuple(pairwise([0]))
    ((0, 0),)
    >>> tuple(pairwise([0], reverse=True))
    ((0, 0),)
    >>> tuple(pairwise([0, 1]))
    ((0, 1), (1, 0))
    >>> tuple(pairwise([0, 1], reverse=True))
    ((1, 0), (0, 1))
    >>> tuple(pairwise([0, 1, 2]))
    ((0, 1), (1, 2), (2, 0))
    >>> tuple(pairwise([0, 1, 2], reverse=True))
    ((2, 1), (1, 0), (0, 2))
    >>> tuple(pairwise(['a', 'b', 'c', 'd']))
    (('a', 'b'), ('b', 'c'), ('c', 'd'), ('d', 'a'))
    >>> tuple(pairwise(['a', 'b', 'c', 'd'], reverse=True))
    (('d', 'c'), ('c', 'b'), ('b', 'a'), ('a', 'd'))
N)ÚreversedÚiterÚnext)ÚiterableÚreverseÚitÚfirstÚaÚbs         r   Úpairwiserv   =  sT   é € öB ØÞÜ�hÓ‰ä�(‹^ˆÜ��T‹N€EØ€AÛˆØˆfŠØŠñ ð ˆ*Óùs   ‚AAc                  ó   • g)aM  
>>> import math
>>> calcBounds([])
(0, 0, 0, 0)
>>> calcBounds([(0, 40), (0, 100), (50, 50), (80, 10)])
(0, 10, 80, 100)
>>> updateBounds((0, 0, 0, 0), (100, 100))
(0, 0, 100, 100)
>>> pointInRect((50, 50), (0, 0, 100, 100))
True
>>> pointInRect((0, 0), (0, 0, 100, 100))
True
>>> pointInRect((100, 100), (0, 0, 100, 100))
True
>>> not pointInRect((101, 100), (0, 0, 100, 100))
True
>>> list(pointsInRect([(50, 50), (0, 0), (100, 100), (101, 100)], (0, 0, 100, 100)))
[True, True, True, False]
>>> vectorLength((3, 4))
5.0
>>> vectorLength((1, 1)) == math.sqrt(2)
True
>>> list(asInt16([0, 0.1, 0.5, 0.9]))
[0, 0, 1, 1]
>>> normRect((0, 10, 100, 200))
(0, 10, 100, 200)
>>> normRect((100, 200, 0, 10))
(0, 10, 100, 200)
>>> scaleRect((10, 20, 50, 150), 1.5, 2)
(15.0, 40, 75.0, 300)
>>> offsetRect((10, 20, 30, 40), 5, 6)
(15, 26, 35, 46)
>>> insetRect((10, 20, 50, 60), 5, 10)
(15, 30, 45, 50)
>>> insetRect((10, 20, 50, 60), -5, -10)
(5, 10, 55, 70)
>>> intersects, rect = sectRect((0, 10, 20, 30), (0, 40, 20, 50))
>>> not intersects
True
>>> intersects, rect = sectRect((0, 10, 20, 30), (5, 20, 35, 50))
>>> intersects
1
>>> rect
(5, 20, 20, 30)
>>> unionRect((0, 10, 20, 30), (0, 40, 20, 50))
(0, 10, 20, 50)
>>> rectCenter((0, 0, 100, 200))
(50.0, 100.0)
>>> rectCenter((0, 0, 100, 199.0))
(50.0, 99.5)
>>> intRect((0.9, 2.9, 3.1, 4.1))
(0, 2, 4, 5)
Nr   r   r   r   Ú_testrx   l  s   � r   Ú__main__)r(   )F)#Ú__doc__ÚfontTools.misc.roundToolsr   ÚfontTools.misc.vectorr   Ú_Vectorr-   r_   r   r   r   r	   r#   r&   r*   r0   r5   r8   r:   r?   rB   rO   rQ   rS   rU   rX   r\   rv   rx   rg   ÚsysÚdoctestÚexitÚtestmodÚfailedr   r   r   Ú<module>rƒ      sÂ   ðñõ .Ý 3Û Û ò.ð   'ô 6ð$ !$¨ô Bò&7ò Kò"
"ò	5òNò&2ò 6ò 6ò *ò6$ò.0ò)ò$ô(ô*
ˆWô 
ô,ò^5ðp ˆzÓÛÛà‡H‚HˆW�_Š_Ó×%Ñ%Õ&ð	 r   