� ��g�,��2�dZddlmZddlmZddlZddlZd�Zefd�Z e e fd�Z d�Z d �Zd �Zd �Zd �Zd �Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zdd�ZGd�de��Zdd�Zd�Zedkr,ddlZddlZej ej!��j"��dSdS)zTRoutines for calculating bounding boxes, point in rectangle calculations and so on. �)�otRound)�VectorNc��|sdSd�|D��}d�|D��}t|��t|��t|��t|��fS)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)``. �rrrrc��g|]\}}|��S�r��.0�x�ys �i/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/fontTools/misc/arrayTools.py� <listcomp>zcalcBounds.<locals>.<listcomp>��� � � ���1�!� � � �c��g|]\}}|��Srrr s r rzcalcBounds.<locals>.<listcomp>rr��min�max)�array�xs�yss r � calcBoundsr s^�� ���z� � �� � � �B� � �� � � �B� �r�7�7�C��G�G�S��W�W�c�"�g�g� -�-rc�T��t�fd�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)``. c3�.�K�|]}�|��V��dS)Nr)r �v�rounds �r � <genexpr>z calcIntBounds.<locals>.<genexpr>*s+�����5�5�a���q���5�5�5�5�5�5r)�tupler)rrs `r � calcIntBoundsrs0��� �5�5�5�5�:�e�#4�#4�5�5�5� 5� 5�5rc��|\}}|�||||fS|\}}}} |||��|||��|||��|| |��fS)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�prrr 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�Arc�Z�|\}}|\}}}}||cxko|knco||cxko|kncS)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�6rc�d�����t|��dkrgS|\��������fd�|D��S)aDetermine 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|]%\}}�|cxko�knco�|cxko�knc��&Srr)r r r r%r#r&r$s ����r rz 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)rr)r%r#r&r$s @@@@r � pointsInRectr/PsM������ �5�z�z�A�~�~�� �!��D�$��d� J� J� J� J� J� J� J�E� J� J� J�Jrc�F�|\}}tj|dz|dzz��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 � vectorLengthr5as)�� �D�A�q� �9�Q��T�A�q�D�[� !� !�!rc��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|]&}ttj|dz������'S)g�?)�intr2�floor)r �is r rzasInt16.<locals>.<listcomp>ws.�� 4� 4� 4��C�� �1�s�7�#�#� $� $� 4� 4� 4rr)rs r �asInt16r;ns�� 5� 4�e� 4� 4� 4�4rc��|\}}}}t||��t||��t||��t||��fS)aPNormalize 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>zsA�� $��T�4��t� �t�T�?�?�C��d�O�O�S��t�_�_�c�$��o�o� M�Mrc�4�|\}}}}||z||z||z||zfS)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�1rc�4�|\}}}}||z||z||z||zfS)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�5rc�4�|\}}}}||z||z||z ||z fS)aIInset 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. rrBs r � insetRectrH�rFrc���|\}}}}|\}}}} t||��t||��t||��t|| ��f\} } } } | | ks| | krdSd| | | | ffS)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. )FrT)rr��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�)� )�)rc��|\}}}}|\}}}} t||��t||��t||��t|| ��f\} } } } | | | | fS)a0Determine 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. rrJs r � unionRectrW�su��$)� �U�E�5�%�#(� �U�E�5�%� �E�5��� �E�5��� �E�5��� �E�5��� ��D�$��d� �$��d� #�#rc�0�|\}}}}||zdz ||zdz fS)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. r1rr=s r � rectCenterrY�s/�� $��T�4��t� �4�K�1� �t�d�{�a�/� /�/rc�&�|\}}}}||z ||z zS)z�Determine rectangle area. Args: rect: Bounding rectangle, expressed as tuples ``(xMin, yMin, xMax, yMax)``. Returns: The area of the rectangle. rr=s r �rectArear[�s%�� $��T�4��t� �4�K�D�4�K� (�(rc�$�|\}}}}ttj|����}ttj|����}ttj|����}ttj|����}||||fS)aRound 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. )r8r2r9�ceilr=s r �intRectr^ sy�� $��T�4��t� �t�z�$��� � �D� �t�z�$��� � �D� �t�y���� � �D� �t�y���� � �D� �$��d� #�#rr,c ��|dkrtd|�����t|��\}}}}ttj||z ��|z��ttj||z ��|z��ttj||z ��|z��ttj||z ��|z��fS)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>r8r2r9r])r)�factorr#r$r%r&s r � quantizeRectrbs�����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� -�.�.�  �rc��eZdZd�ZdS)rc�:�tjdt��dS)NzffontTools.misc.arrayTools.Vector has been deprecated, please use fontTools.misc.vector.Vector instead.)�warnings�warn�DeprecationWarning)�self�args�kwargss r �__init__zVector.__init__5s(��� � 4� � � � � � rN)�__name__� __module__� __qualname__rkrrr rr4s#������ � � � � rrFc#�K�|sdS|rt|��}nt|��}t|d��}|}|D] }||fV�|}� ||fV�dS)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�*�����rc��dS)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) Nrrrr �_testr{ls���r�__main__)r,)F)#�__doc__�fontTools.misc.roundToolsr�fontTools.misc.vectorr�_Vectorr2rerrrrr'r*r/r5r;r>r@rErHrUrWrYr[r^rbryr{rl�sys�doctest�exit�testmod�failedrrr �<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
Memory