§
    ¢”jÛ,  ã                   ó2  — d Z ddlmZ ddlmZ ddlZddlZd„ Zefd„Z	e
efd„Zd„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zdd„Z G d„ de¦  «        Zdd„Zd„ Zedk    r,ddlZddlZ ej          ej!        ¦   «         j"        ¦  «         dS dS )zTRoutines for calculating bounding boxes, point in rectangle calculations and
so on.
é    )ÚotRound)ÚVectorNc                 ó®   — | sdS d„ | D ¦   «         }d„ | D ¦   «         }t          |¦  «        t          |¦  «        t          |¦  «        t          |¦  «        fS )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   c                 ó   — g | ]\  }}|‘ŒS © r   ©Ú.0ÚxÚys      úh/var/www/finuniver-perm.ru/html/portfolio/venv/lib/python3.11/site-packages/fontTools/misc/arrayTools.pyú
<listcomp>zcalcBounds.<locals>.<listcomp>   ó   € Ð	Ð	Ð	‘��1ˆ!Ð	Ð	Ð	ó    c                 ó   — g | ]\  }}|‘ŒS r   r   r	   s      r   r   zcalcBounds.<locals>.<listcomp>   r   r   ©ÚminÚmax)ÚarrayÚxsÚyss      r   Ú
calcBoundsr      s^   € ð ð ØˆzØ	Ð	˜Ð	Ñ	Ô	€BØ	Ð	˜Ð	Ñ	Ô	€BÝˆr‰7Œ7•C˜‘G”G�S ™WœW¥c¨"¡g¤gÐ-Ð-r   c                 óT   ‡— t          ˆfd„t          | ¦  «        D ¦   «         ¦  «        S )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   ó.   •K  — | ]} ‰|¦  «        V — Œd S )Nr   )r
   ÚvÚrounds     €r   ú	<genexpr>z calcIntBounds.<locals>.<genexpr>*   s+   øè è € Ð5Ð5˜a���q‘”Ð5Ð5Ð5Ð5Ð5Ð5r   )Útupler   )r   r   s    `r   ÚcalcIntBoundsr      s0   ø€ õ Ð5Ð5Ð5Ð5¥:¨eÑ#4Ô#4Ð5Ñ5Ô5Ñ5Ô5Ð5r   c                 ó†   — |\  }}| €||||fS | \  }}}}	 |||¦  «         |||¦  «         |||¦  «         ||	|¦  «        fS )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'   -   se   € ð �F€QˆØ€~Ø�!�Q˜ˆzÐØ#Ñ€Dˆ$��dØˆ3ˆt�Q‰<Œ<˜˜˜T 1™œ s s¨4°¡|¤|°S°S¸¸q±\´\ÐAÐAr   c                 óZ   — | \  }}|\  }}}}||cxk    o|k    nc o||cxk    o|k    nc 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ˆ$��dØ�AÐÐÒÐ˜ÒÐÐÐÐ6 D¨AÐ$5Ð$5Ò$5Ð$5°Ò$5Ð$5Ð$5Ð$5Ð6r   c                 ód   ‡‡‡‡— t          | ¦  «        dk     rg S |\  ŠŠŠŠˆˆˆˆfd„| D ¦   «         S )a  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.
    é   c                 óV   •— g | ]%\  }}‰|cxk    o‰k    nc o‰|cxk    o‰k    nc ‘Œ&S r   r   )r
   r   r   r%   r#   r&   r$   s      €€€€r   r   z pointsInRect.<locals>.<listcomp>^   sZ   ø€ ÐJÐJÐJ¹D¸A¸qˆT�QÐÐÒÐ˜$ÒÐÐÐÐ7 T¨QÐ%6Ð%6Ò%6Ð%6°$Ò%6Ð%6Ð%6Ð%6ÐJÐJÐJr   )Úlen)r   r)   r%   r#   r&   r$   s     @@@@r   ÚpointsInRectr/   P   sM   øøøø€ õ ˆ5�z„z�A‚~€~Øˆ	Ø!Ñ€Dˆ$��dØJÐJÐJÐJÐJÐJÐJÀEÐJÑJÔJÐJr   c                 óF   — | \  }}t          j        |dz  |dz  z   ¦  «        S )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   ÚvectorLengthr5   a   s)   € ð �D€A€qÝŒ9�Q˜‘T˜A˜q™D‘[Ñ!Ô!Ð!r   c                 ó   — d„ | D ¦   «         S )z˜Round a list of floats to 16-bit signed integers.

    Args:
        array: List of float values.

    Returns:
        A list of rounded integers.
    c                 óV   — g | ]&}t          t          j        |d z   ¦  «        ¦  «        ‘Œ'S )g      à?)Úintr2   Úfloor)r
   Úis     r   r   zasInt16.<locals>.<listcomp>w   s.   € Ð4Ð4Ð4¨�C•”
˜1˜s™7Ñ#Ô#Ñ$Ô$Ð4Ð4Ð4r   r   )r   s    r   ÚasInt16r;   n   s   € ð 5Ð4¨eÐ4Ñ4Ô4Ð4r   c                 óŒ   — | \  }}}}t          ||¦  «        t          ||¦  «        t          ||¦  «        t          ||¦  «        fS )aP  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   ÚnormRectr>   z   sA   € ð  $Ñ€Tˆ4��tÝˆt�T‰?Œ?�C  d™OœO­S°°t©_¬_½cÀ$È¹o¼oÐMÐMr   c                 ó4   — | \  }}}}||z  ||z  ||z  ||z  fS )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@   �   s1   € ð  $Ñ€Tˆ4��tØ�!‰8�T˜A‘X˜t a™x¨°©Ð1Ð1r   c                 ó4   — | \  }}}}||z   ||z   ||z   ||z   fS )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   Ú
offsetRectrE   �   ó1   € ð  $Ñ€Tˆ4��tØ�"‰9�d˜R‘i ¨¡¨D°2©IÐ5Ð5r   c                 ó4   — | \  }}}}||z   ||z   ||z
  ||z
  fS )aI  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   rB   s          r   Ú	insetRectrH   ­   rF   r   c                 óÐ   — | \  }}}}|\  }}}}	t          ||¦  «        t          ||¦  «        t          ||¦  «        t          ||	¦  «        f\  }
}}}|
|k    s||k    rdS d|
|||ffS )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   ÚsectRectrU   ½   s‘   € ð $)Ñ €UˆE�5˜%Ø#(Ñ €UˆE�5˜%åˆE�5ÑÔÝˆE�5ÑÔÝˆE�5ÑÔÝˆE�5ÑÔð	Ñ€Dˆ$��dð ˆt‚|€|�t˜t’|�|Ø"Ð"Ø�$˜˜d DÐ)Ð)Ð)r   c                 ó°   — | \  }}}}|\  }}}}	t          ||¦  «        t          ||¦  «        t          ||¦  «        t          ||	¦  «        f\  }
}}}|
|||fS )a0  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   rJ   s                 r   Ú	unionRectrW   Ø   su   € ð $)Ñ €UˆE�5˜%Ø#(Ñ €UˆE�5˜%åˆE�5ÑÔÝˆE�5ÑÔÝˆE�5ÑÔÝˆE�5ÑÔð	Ñ€Dˆ$��dð �$˜˜dÐ#Ð#r   c                 ó0   — | \  }}}}||z   dz  ||z   dz  fS )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.
    r1   r   r=   s        r   Ú
rectCenterrY   ï   s/   € ð  $Ñ€Tˆ4��tØ�4‰K˜1Ñ˜t d™{¨aÑ/Ð/Ð/r   c                 ó&   — | \  }}}}||z
  ||z
  z  S )zºDetermine rectangle area.

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

    Returns:
        The area of the rectangle.
    r   r=   s        r   ÚrectArear[   ý   s%   € ð  $Ñ€Tˆ4��tØ�4‰K˜D 4™KÑ(Ð(r   c                 ó$  — | \  }}}}t          t          j        |¦  «        ¦  «        }t          t          j        |¦  «        ¦  «        }t          t          j        |¦  «        ¦  «        }t          t          j        |¦  «        ¦  «        }||||fS )a  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.
    )r8   r2   r9   Úceilr=   s        r   ÚintRectr^     sy   € ð  $Ñ€Tˆ4��tÝ�tŒz˜$ÑÔÑ Ô €DÝ�tŒz˜$ÑÔÑ Ô €DÝ�tŒy˜‰ŒÑÔ€DÝ�tŒy˜‰ŒÑÔ€DØ�$˜˜dÐ#Ð#r   r,   c           	      óŽ  — |dk     rt          d|›�¦  «        ‚t          | ¦  «        \  }}}}t          t          j        ||z  ¦  «        |z  ¦  «        t          t          j        ||z  ¦  «        |z  ¦  «        t          t          j        ||z  ¦  «        |z  ¦  «        t          t          j        ||z  ¦  «        |z  ¦  «        fS )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: )Ú
ValueErrorr>   r8   r2   r9   r]   )r)   Úfactorr#   r$   r%   r&   s         r   ÚquantizeRectrb     sº   € ð �‚z€zÝÐPÀfÐPÐPÑQÔQÐQÝ% d™^œ^Ñ€Dˆ$��då�DŒJ�t˜f‘}Ñ%Ô%¨Ñ.Ñ/Ô/Ý�DŒJ�t˜f‘}Ñ%Ô%¨Ñ.Ñ/Ô/Ý�DŒI�d˜V‘mÑ$Ô$ vÑ-Ñ.Ô.Ý�DŒI�d˜V‘mÑ$Ô$ vÑ-Ñ.Ô.ð	ð r   c                   ó   — e Zd Zd„ ZdS )r   c                 ó:   — t          j        dt          ¦  «         d S )NzffontTools.misc.arrayTools.Vector has been deprecated, please use fontTools.misc.vector.Vector instead.)ÚwarningsÚwarnÚDeprecationWarning)ÚselfÚargsÚkwargss      r   Ú__init__zVector.__init__5  s(   € ÝŒð4åñ	
ô 	
ð 	
ð 	
ð 	
r   N)Ú__name__Ú
__module__Ú__qualname__rk   r   r   r   r   r   4  s#   € € € € € ð
ð 
ð 
ð 
ð 
r   r   Fc              #   óž   K  — | sdS |rt          | ¦  «        }nt          | ¦  «        }t          |d¦  «        }|}|D ]
}||fV — |}Œ||fV — dS )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   Úpairwisery   =  sƒ   è è € ðB ð ØˆØð Ý�hÑÔˆˆå�(‰^Œ^ˆÝ��T‰NŒN€EØ€AØð ð ˆØ�!ˆfˆˆˆØˆˆØˆeˆ*ÐÐÐÐÐr   c                  ó   — dS )a  
    >>> 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   Ú_testr{   l  s   € € € r   Ú__main__)r,   )F)#Ú__doc__ÚfontTools.misc.roundToolsr   ÚfontTools.misc.vectorr   Ú_Vectorr2   re   r   r   r   r   r'   r*   r/   r5   r;   r>   r@   rE   rH   rU   rW   rY   r[   r^   rb   ry   r{   rl   ÚsysÚdoctestÚexitÚtestmodÚfailedr   r   r   ú<module>r†      s  ððð ð .Ð -Ð -Ð -Ð -Ð -Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø €€€Ø €€€ð.ð .ð .ð   'ð 6ð 6ð 6ð 6ð$ !$¨ð Bð Bð Bð Bð&7ð 7ð 7ð Kð Kð Kð"
"ð 
"ð 
"ð	5ð 	5ð 	5ðNð Nð Nð&2ð 2ð 2ð 6ð 6ð 6ð 6ð 6ð 6ð *ð *ð *ð6$ð $ð $ð.0ð 0ð 0ð)ð )ð )ð$ð $ð $ð(ð ð ð ð*
ð 
ð 
ð 
ð 
ˆWñ 
ô 
ð 
ð,ð ,ð ,ð ,ð^5ð 5ð 5ðp ˆzÒÐØ€J€J€JØ€N€N€Nà€C„Hˆ_ˆWŒ_ÑÔÔ%Ñ&Ô&Ð&Ð&Ð&ð	 Ðr   