+
    i,                     H   R t ^ RIHt ^ RIHt ^ RIt^ RItR t]3R lt	]
]3R ltR tR tR	 tR
 tR tR tR tR tR tR tR tR tR tRR lt ! R R]4      tRR ltR t]R8X  d6   ^ RIt^ RIt]P@                  ! ]PB                  ! 4       PD                  4       R# R# )zTRoutines for calculating bounding boxes, point in rectangle calculations and
so on.
)otRound)VectorNc                    V '       g   R# V  UUu. uF  w  rVNK	  	  pppV  UUu. uF  w  rVNK	  	  ppp\        V4      \        V4      \        V4      \        V4      3# u uppi u uppi )zCalculate 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   minmax)arrayxyxsyss   &    y/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/fontTools/misc/arrayTools.py
calcBoundsr      s`     	!B		!B	r7CGSWc"g-- 
	s
   AA%c                   a \         ;QJ d     . V3R l\        V 4       4       F  NK  	  5# ! V3R l\        V 4       4       4      # )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   <"   T F  pS! V4      x  K  	  R # 5i)N ).0vrounds   & r   	<genexpr> calcIntBounds.<locals>.<genexpr>*   s     5#4aq#4s   )tupler   )r
   r   s   &fr   calcIntBoundsr      s1     55:e#455555:e#4555    c                `    Vw  rEV f   WEWE3# V w  rgrV! Wd4      V! Wu4      V! W4      V! W4      3# )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     FQ~Qz#Dt<Ts4|S\AAr   c                x    V w  r#Vw  rErgYBu;8*  ;'       d    V8*  Mu ;'       d    YSu;8*  ;'       d    V8*  # u # )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?     FQ!D66D$5$5$56$56r   c                    \        V 4      ^8  d   . # Vw  r#rEV  UUu. uF7  w  rgY&u;8*  ;'       d    V8*  Mu ;'       d    Y7u;8*  ;'       d    V8*  Mu NK9  	  upp# u uppi )zDetermine 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   sY     5zA~	!DDIJEDAT$77T%6%6$%67EJJJs   "A Ac                `    V w  r\         P                  ! V^,          V^,          ,           4      # )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   vectorLengthr.   a   s&     DA99QTAqD[!!r   c           	     x    V  Uu. uF)  p\        \        P                  ! VR,           4      4      NK+  	  up# u upi )zRound 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   asInt16r3   n   s.     /44eC

1s7#$e444s   /7c                `    V w  rr4\        W4      \        W$4      \        W4      \        W$4      3# )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   normRectr6   z   s-      $Tt?COS_c$oMMr   c                H    V w  r4rVW1,          WB,          WQ,          Wb,          3# )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   	scaleRectr8      s%      $T8TXtx11r   c                H    V w  r4rVW1,           WB,           WQ,           Wb,           3# )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9diDI55r   c                H    V w  r4rVW1,           WB,           WQ,
          Wb,
          3# )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   	insetRectr@      r>   r   c                    V w  r#rEVw  rgr\        W&4      \        W74      \        WH4      \        WY4      3w  rrW8  g   W8  d   R# RWW33# )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.
T)Fr   )r	   r   rect1rect2xMin1yMin1xMax1yMax1xMin2yMin2xMax2yMax2r   r    r!   r"   s   &&            r   sectRectrM      se     $) U5#( U5EEEE	D |t|""$d)))r   c                x    V w  r#rEVw  rgr\        W&4      \        W74      \        WH4      \        WY4      3w  rrWW3# )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   rB   s   &&            r   	unionRectrO      sQ     $) U5#( U5EEEE	D ##r   c                H    V w  rr4W,           ^,          W$,           ^,          3# )zDetermine 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   r5   s   &    r   
rectCenterrQ      s'      $TK1t{a///r   c                6    V w  rr4WB,
          W1,
          ,          # )zDetermine rectangle area.

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

Returns:
    The area of the rectangle.
r   r5   s   &    r   rectArearS      s      $TKDK((r   c                   V w  rr4\        \        P                  ! V4      4      p\        \        P                  ! V4      4      p\        \        P                  ! V4      4      p\        \        P                  ! V4      4      pWW43# )zRound 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.
)r0   r+   r1   ceilr5   s   &    r   intRectrV     sc      $Ttzz$ Dtzz$ DtyyDtyyD##r   c           	        V^8  d   \        RV: 24      h\        V 4      w  r#rE\        \        P                  ! W!,          4      V,          4      \        \        P                  ! W1,          4      V,          4      \        \        P
                  ! WA,          4      V,          4      \        \        P
                  ! WQ,          4      V,          4      3# )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)
z*Expected quantization factor >= 1, found: )
ValueErrorr6   r0   r+   r1   rU   )r%   factorr   r    r!   r"   s   &&    r   quantizeRectrZ     s     zEfZPQQ%d^DDJJt}%./DJJt}%./DIIdm$v-.DIIdm$v-.	 r   c                   &   a  ] tR tRt o R tRtV tR# )r   i4  c                <    \         P                  ! R \        4       R# )zffontTools.misc.arrayTools.Vector has been deprecated, please use fontTools.misc.vector.Vector instead.N)warningswarnDeprecationWarning)selfargskwargss   &*,r   __init__Vector.__init__5  s    4	
r   r   N)__name__
__module____qualname____firstlineno__rc   __static_attributes____classdictcell__)__classdict__s   @r   r   r   4  s     
 
r   r   c              #     "   V '       g   R# V'       d   \        V 4      pM\        V 4      p\        VR4      pTpV F
  pWE3x  TpK  	  WC3x  R# 5i)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(^TNEAf  *s
   A<Ac                     R# )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__)   )F)#__doc__fontTools.misc.roundToolsr   fontTools.misc.vectorr   _Vectorr+   r]   r   r   r   r	   r#   r&   r)   r.   r3   r6   r8   r=   r@   rM   rO   rQ   rS   rV   rZ   rv   rx   re   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HHW__%%&	 r   