
    )+Ci                     h    S SK Jr  S SKJr  S SKJr  / SQr\" SSS/5      r\" S/ S	Q5      rS
 r	S r
g)    )
namedtuple)chain)
itemgetter)bounding_boxconvex_hullPointRectr   xyr	   )lefttopwidthheightc                     [        [        [        S5      U 5      5      n[        U5      [	        U5      p2[        [        [        S5      U 5      5      n[        U5      [	        U5      pe[        X%X2-
  Xe-
  5      $ )zComputes the bounding box of an iterable of (x, y) coordinates.

Args:
    locations: iterable of (x, y) tuples.

Returns:
    `Rect`: Coordinates of the bounding box.
r      )listmapr   minmaxr	   )	locationsx_valuesx_minx_maxy_valuesy_miny_maxs          J/home/james-whalen/.local/lib/python3.13/site-packages/pyzbar/locations.pyr   r      s_     C
1y12Hx=#h-5C
1y12Hx=#h-5emU];;    c                    ^ S mU4S jn[        [        U 5      5      n [        U 5      S:  a  U O [        U" U 5      U" [	        U 5      5      5      n[        [        [        R                  U5      5      $ )a  Computes the convex hull of an iterable of (x, y) coordinates.

Args:
    points: iterable of (x, y) tuples.

Returns:
    `list`: instances of `Point` - vertices of the convex hull in
    counter-clockwise order, starting from the vertex with the
    lexicographically smallest coordinates.

Andrew's monotone chain algorithm. O(n log n) complexity.
https://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain
c                 f    SUS   U S   -
  US   U S   -
  -  US   U S   -
  US   U S   -
  -  -
  :*  $ )Nr   r    )p0p1p2s      r   is_not_clockwise%convex_hull.<locals>.is_not_clockwise,   sT    URU]r!ur!u}-URU]r!ur!u}-.
 	
r   c                   > / nU  Hn  nS[        U5      :  aK  T" US   US   U5      (       a6  UR                  5         S[        U5      :  a  T" US   US   U5      (       a  M6  UR                  U5        Mp     UR                  5         U$ )Nr   )lenpopappend)points_respr%   s      r   goconvex_hull.<locals>.go2   s|    Ac#h,#3CGSWa#H#H	 c#h,#3CGSWa#H#HJJqM  		
r      )	sortedsetr*   r   reversedr   r   r   _make)pointsr0   hullr%   s      @r   r   r      s`    

 CK F f+/uRZHV<L9M'N 	 EKK&''r   N)collectionsr   	itertoolsr   operatorr   __all__r   r	   r   r   r!   r   r   <module>r=      s>    "   ; 	7S#J'&<=< )(r   