+
    åûjÙl  ã                   ó¶   € R t ^ RIHtHtHtHt ^ RIt^ RIHt ^ RIH	t	H
t
 R R ltR R ltR	 R
 ltR R ltR R ltRR R lltR R ltR R ltR R ltR# )z Utilities for drawing on images.)ÚListÚOptionalÚTupleÚUnionN©ÚTensor)ÚKORNIA_CHECKÚKORNIA_CHECK_SHAPEc                ó0   € V ^8„  d   QhR\         R\         /# )é   ÚcoordsÚreturnr   )Úformats   "ÚMC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\image\draw.pyÚ__annotate__r      s   € ÷ 	"ñ 	"œFð 	"¤vñ 	"ó    c                ó"  € V P                  4       '       d\   V P                  \        P                  ! V P                  \        P
                  4      4      p \        P                  ! V R,           4      p V P                  \        P                  4      # )zÌReturn the int64 pixel whose centre is nearest to each coordinate; a coordinate exactly halfway rounds up.

Pixel ``i`` covers ``[i - 0.5, i + 0.5)``, so ``-0.5`` lands on pixel 0 and ``2.5`` on pixel 3.
g      à?)Úis_floating_pointÚtoÚtorchÚpromote_typesÚdtypeÚfloat32ÚfloorÚint64)r   s   &r   Ú_round_to_pixelr      s[   € ð
 ×Ñ×!Ò!à—‘œ5×.Ò.¨v¯|©|¼U¿]¹]ÓKÓLˆÜ—’˜V c�\Ó*ˆØ�9‰9”U—[‘[Ó!Ð!r   c                ó„   € V ^8„  d   QhR\         R\         R\         R\         R\        R\        R\        R\        R	\         /	# )
r   Úx1Úy1Úx2Úy2ÚhÚwÚ
line_widthÚfillr   )r   ÚintÚbool)r   s   "r   r   r   )   s_   € ÷ oñ oÜðoÜðoÜ &ðoÜ,2ðoÜ7:ðoÜ?BðoÜPSðoÜ[_ðoäñor   c           
     óÐ  € V'       d   WW3.pMšV\         P                  ! W,           ^,
          V4      W3\         P                  ! W6,
          ^,           V4      W0V3WV \         P                  ! W,           ^,
          V4      3W\         P                  ! W&,
          ^,           V 4      V3.p\         P                  ! V U	u. uF  q™^ ,          NK  	  up	R4      p
\         P                  ! V U	u. uF  q™^,          NK  	  up	R4      p\         P                  ! V U	u. uF  q™^,          NK  	  up	R4      p\         P                  ! V U	u. uF  q™^,          NK  	  up	R4      p\         P                  ! V
P	                  ^ V4      VP	                  RV^,
          4      ^,           VP	                  ^ V4      VP	                  RV^,
          4      ^,           .R4      # u up	i u up	i u up	i u up	i )a  Return the row and column slices ``[r0, r1, c0, c1]`` of each rectangle's bands, clipped to a ``h x w`` image.

The corners are inclusive and ordered (``x1 <= x2``, ``y1 <= y2``) and share any leading shape. The outline is four
bands ``line_width`` pixels thick, inside the box; a fill is one band. Each band is drawn as
``image[..., r0:r1, c0:c1]``. Its bounds are clamped to the image, so the part of a band outside the image is an
empty slice: a one-pixel side outside the image disappears instead of being moved onto the border. Clamping instead
of testing the bounds in Python keeps every corner a tensor until the one ``tolist`` in ``draw_rectangle``, so the
function exports to ONNX.

Returns:
    an int64 tensor of shape ``(*, K, 4)``: ``K`` is 1 for a fill and 4 for an outline.
éÿÿÿÿ)r   ÚminimumÚmaximumÚstackÚclamp)r   r   r   r    r!   r"   r#   r$   ÚbandsÚbandÚr0Úr1Úc0Úc1s   &&&&&&&&      r   Ú_rectangle_bandsr3   )   sˆ  € ÷ Ø˜"Ð!Ð"‰ð ”—’˜r�°Õ2°BÓ7¸Ð@Ü�]Š]˜2�?¨QÕ.°Ó3°R¸RÐ@Ø�RœŸš r¥¸Õ':¸BÓ?Ð@Ø”U—]’] 2¥?°QÕ#6¸Ó;¸RÐ@ð	
ˆô 
�Š©%Ó0©% $˜1—g�g©%Ñ0°"Ó	5€BÜ	�Š©%Ó0©% $˜1—g�g©%Ñ0°"Ó	5€BÜ	�Š©%Ó0©% $˜1—g�g©%Ñ0°"Ó	5€BÜ	�Š©%Ó0©% $˜1—g�g©%Ñ0°"Ó	5€Bä�;Š;˜Ÿ™  A›¨¯©°°Q¸µUÓ(;¸aÕ(?ÀÇÁÈ!ÈQÃÐQS×QYÑQYÐZ\Ð^_ÐbcÕ^cÓQdÐghÕQhÐiÐkmÓnÐnùò 1ùÚ0ùÚ0ùÚ0s   Â=GÃ*GÄGÅG#c                óH   € V ^8„  d   QhR\         R\         R\         R\         /# )r   ÚimageÚpointsÚcolorr   r   )r   s   "r   r   r   J   s.   € ÷ Kñ Kœð K¬ð K´vð KÄ&ñ Kr   c                ó¦  € V P                  4       R9  d   \        R4      hVP                  ^ 8X  d   VP                  ^ 4      pV P                  4       ^8X  d   ^MV P                  ^ ,          pVP                  ^ ,          p\        V^V39   RV RV 24       \        V4      P                  V P                  4      pVP                  ^8X  d/   \        VP                  4       ^8H  R4       VP                  ^ 4      p\        VP                  ^8H  ;'       d    VP                  R,          ^8H  R4       VR,          pVR,          pV P                  RR w  rxV^ 8  WX8¬  ,          V^ 8  ,          Wg8¬  ,          P                  4       '       d'   \        RV R	V R
V^,
           RV^,
           R2	4      h\        VP                  4      ^8X  d   \        P                  ! V^R7      pVP                  V P                  V P                  R7      p\        V P                  4      ^8X  d   W We3&   V # VP                  V P                  ^ ,          R4      V RWe3&   V # )a|  Color the pixels at a set of (x, y) points of one image, in place.

``image = draw_point2d(image, points, color)`` writes ``color`` into the pixel nearest to each :math:`(x, y)`
point of ``points``, ``(N, 2)`` or ``(2,)``, in one ``(C, H, W)`` or ``(H, W)`` image, and returns the same tensor.

Convention:
    See the Convention block of :func:`draw_line` for the coordinates, the rounding, the color and the in-place
    drawing.

Args:
    image: the input image on which to draw the points with shape ``(C,H,W)`` or ``(H,W)``.
    points: the [x, y] points to be drawn on the image with shape ``(N, 2)``, a single
        point with shape ``(2,)``, or an empty tensor with shape ``(0, 2)``.
    color: the color of the pixel with ``(C)`` where :math:`C` is the number of channels of the image,
        or a single value with shape ``(1)`` or 0-d.

Return:
    The image with points set to the color. This operation modifies image inplace but also
    returns the drawn tensor for convenience. An empty point set leaves the image unchanged.

Raises:
    ValueError: if the image is not ``(C, H, W)`` or ``(H, W)``, or a point lies outside the image after rounding.
    BaseError: if ``color`` has neither 1 nor ``C`` values (an ``(H, W)`` image has one channel), or ``points``
        is not ``(2,)`` or ``(N, 2)``.

See Also:
    - :func:`draw_line`: draws the pixels between two points, and states the rules both functions follow.

Example:
    >>> image = torch.zeros(1, 3, 4)
    >>> draw_point2d(image, torch.tensor([[0, 1], [3, 2]]), torch.tensor([1.0]))
    tensor([[[0., 0., 0., 0.],
             [1., 0., 0., 0.],
             [0., 0., 0., 1.]]])

z*image must have shape (C, H, W) or (H, W).úXColor dim must match the channel dims of the provided image: expected a single value or ú (one per channel), got z1A 1D points tensor must have shape (2,) as [x, y]zpoints must have shape (N, 2)ºNNNNzpoints must lie inside the Úxz< image after rounding to the nearest pixel centre: x in [0, z], y in [0, z].©Údim©r   Údevice)r   é   r(   )r;   é    )r;   é   éþÿÿÿ)r>   Ú
ValueErrorÚndimÚ	unsqueezeÚshaper   r   r   r@   ÚnumelÚanyÚlenr   r   Úexpand)	r5   r6   r7   ÚchannelsÚcolor_lengthr<   ÚyÚheightÚwidths	   &&&      r   Údraw_point2drR   J   s  € ðJ ‡y�yƒ{˜&Ô ÜÐEÓFÐFà‡z�z�Q„Ø—‘ Ó"ˆð —I‘I“K 1Ô$‰q¨%¯+©+°a­.€HØ—;‘;˜q•>€LÜØ˜˜H˜Ñ%ð&Ø&. ZÐ/GÈÀ~ð	Wôô ˜VÓ$×'Ñ'¨¯©Ó5€Fð ‡{�{�aÔÜ�V—\‘\“^ qÑ(Ð*]Ô^Ø×!Ñ! !Ó$ˆÜ�—‘ Ñ!×;Ð; f§l¡l°2Õ&6¸!Ñ&;Ð=\Ô]Øˆt�€AØˆt�€AØ—K‘K  Ð$�M€FØ	
ˆQ‰�1‘:Õ ! a¡%Õ(¨A©KÕ8×=Ñ=×?Ò?ÜØ)¨&¨°°5°'ð :Ø �	�{ ,¨v¸­z¨l¸"ð>ó
ð 	
ô ˆ5�;‰;Ó˜1ÔÜ—’ ¨1Ô-ˆØ�H‰H˜5Ÿ;™;¨u¯|©|ˆHÓ<€EÜ
ˆ5�;‰;Ó˜1ÔØˆaˆd‰ð €Lð Ÿ™ e§k¡k°!¥n°bÓ9ˆˆa�ˆg‰Ø€Lr   c          
      ót   € V ^8„  d   QhR\         P                  R\        R\        R\         P                  RR/# )r   r5   r<   rO   r7   r   N)r   r   r%   )r   s   "r   r   r   ˜   s7   € ÷ ñ ”u—|‘|ð ¬ð ´ð ¼E¿L¹Lð ÈTñ r   c                ó   € W0RW!3&   R# )aG  Draw a pixel into an image.

Args:
    image: the input image to where to draw the lines with shape ``(C,H,W)``.
    x: the x coordinate of the pixel.
    y: the y coordinate of the pixel.
    color: the color of the pixel with ``(C)`` where :math:`C` is the number of channels of the image.

Return:
    Nothing is returned.

r;   N© )r5   r<   rO   r7   s   &&&&r   Ú_draw_pixelrV   ˜   s   € ð ˆ!ˆQˆ'ƒNr   c          
      ó¸   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\         P                  R\         P                  /# )r   r5   Úp1Úp2r7   r   )r   r   )r   s   "r   r   r   ¨   sM   € ÷ qñ q”U—\‘\ð q¤u§|¡|ð q¼¿¹ð qÌeÏlÉlð qÔ_d×_kÑ_kñ qr   c                óÊ	  € VP                   VP                   8w  g   VP                   R,          ^8w  d   \        R4      h\        V4      P                  V P                  4      p\        V4      P                  V P                  4      pRV3RV33 Fˆ  w  rEVR,          ^ 8  VR,          V P                   R,          8¬  ,          VR,          ^ 8  ,          VR,          V P                   R,          8¬  ,          P                  4       '       g   K|  \        V R24      h	  \        V P                  4       4      ^8w  d   \        R4      hVP                  ^ 8X  d   VP                  ^ 4      pVP                  ^ 4      ^V P                  ^ 4      39  d   \        R4      hVP                  V 4      pVP                  R^4      pVP                  R^4      pVR,          VR,          rvVR,          V,
          pVR,          V,
          p	\        P                  ! V4      p
\        P                  ! V	4      p\        P                  ! V4      \        P                  ! V	4      r˜W‰8„  p\        P                  ! WÈV	4      p\        P                  ! WÉV4      pVP                  4       '       d!   \!        VP#                  4       4      ^,           M^p\        P$                  ! WðP                  R7      P                  ^ 4      pVV8*  P'                  R	R
7      w  ppVV^ 3,          P)                  ^4      pVV^ 3,          p\        P                  ! VVV^ 3,          VV^ 3,          4      p\        P                  ! VVV^ 3,          V
V^ 3,          4      p\        P*                  ! ^V,          V,          ^V,          V,          VV^ 3,          ,          ,           V,           ^V,          RR7      p\        P                  ! VVV^ 3,          V
V^ 3,          V,          ,           V4      p\        P                  ! VVVV^ 3,          VV^ 3,          V,          ,           4      p\        P,                  ! V^ V P                   R,          ^,
          R7      p\        P,                  ! V^ V P                   R,          ^,
          R7      pVP/                  R^4      P1                  V P                  ^ 4      R4      V RVV3&   V # )aD  Draw one-pixel segments between pairs of (x, y) points into one image, in place.

``image = draw_line(image, p1, p2, color)`` draws the segment from ``p1`` to ``p2``, two :math:`(x, y)` points of
shape ``(2,)``, or one segment per row of ``(B, 2)`` endpoints, into one ``(C, H, W)`` image and returns the same
tensor. For a box outline thicker than one pixel, use :func:`draw_rectangle` with ``line_width``.

Convention:
    - Points are :math:`(x, y)`, x the column and y the row, with pixel centres at integer coordinates, as in
      :ref:`Coordinates and sizes <coordinate-conventions>`. A fractional endpoint goes to the pixel whose centre
      is nearest, a coordinate exactly halfway rounding up.
    - A line has one pixel per step along its longer axis: the pixel whose centre is nearest to the segment
      between the two endpoint pixels, a tie going to the larger coordinate. The line is therefore the same from
      ``p1`` to ``p2`` as from ``p2`` to ``p1``, and both endpoints are drawn.
    - Nothing is clipped: an endpoint must lie in the image after rounding.
    - The color is cast to the image's dtype without rescaling or a range check, and a single value is written
      to every channel.
    - The image is drawn in place and returned.
    - :ref:`Drawing <drawing-conventions>` compares these rules with OpenCV, Pillow and torchvision.

Args:
    image: the input image to where to draw the lines with shape ``(C,H,W)``.
    p1: the start point [x y] of the line with shape (2, ) or (B, 2).
    p2: the end point [x y] of the line, with the same shape as ``p1``.
    color: the color of the line with shape ``(C)`` where :math:`C` is the number of channels
        of the image, or a single value with shape ``(1)`` or 0-d.

Return:
    The image containing the line.

Raises:
    ValueError: if ``p1`` and ``p2`` differ in shape, or their last dimension is not 2.
    ValueError: if an endpoint lies outside the image after rounding, or the image is not ``(C, H, W)``.
    ValueError: if ``color`` has neither 1 nor ``C`` values.

See Also:
    - :func:`draw_point2d`: colors the given points only, also in an ``(H, W)`` image.
    - :func:`draw_convex_polygon`: fills a polygon instead of drawing its edges.

Examples:
    >>> image = torch.zeros(1, 8, 8)
    >>> draw_line(image, torch.tensor([6, 4]), torch.tensor([1, 4]), torch.tensor([255]))
    tensor([[[  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.],
             [  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.],
             [  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.],
             [  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.],
             [  0., 255., 255., 255., 255., 255., 255.,   0.],
             [  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.],
             [  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.],
             [  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.]]])

z]Input points must be 2D points with shape (2, ) or (B, 2) and must have the same batch sizes.rX   rY   z is out of bounds.z%image must have 3 dimensions (C,H,W).z9color must have the same number of channels as the image.r;   )r@   T)Úas_tupler   )Úrounding_mode)ÚminÚmaxr(   ©.rB   ©.rC   rD   )r;   :rB   rC   N)r;   :rC   r   N)rH   rE   r   r   r@   rJ   rK   ÚsizerF   rG   Úreshaper   ÚsignÚabsÚwhererI   r%   r^   ÚarangeÚnonzeroÚ	clamp_minÚdivr,   ÚviewrL   )r5   rX   rY   r7   ÚnameÚpr   r   ÚdxÚdyÚdx_signÚdy_signÚx_majorÚmajorÚminorÚ	num_stepsÚstepsÚlineÚtÚdivisorÚx_majÚm1Ús_minorÚm_coordsÚx_coordsÚy_coordss   &&&&                      r   Ú	draw_liner   ¨   sÚ  € ðj 	�‰�B—H‘HÔ "§(¡(¨2¥,°!Ô"3ÜØkó
ð 	
ô 
˜Ó	×	Ñ	 §¡Ó	-€BÜ	˜Ó	×	Ñ	 §¡Ó	-€BØ˜2�J  r 
Ó+‰ˆØˆv�Y˜‰]˜q �y¨E¯K©K¸­OÑ;Õ<ÀÀ&Å	ÈAÁÕNÐRSÐTZÕR[Ð_d×_jÑ_jÐkmÕ_nÑRnÕo×tÑt×vÔvÜ ˜vÐ%7Ð8Ó9Ð9ñ ,ô ˆ5�:‰:‹<Ó˜AÔÜÐ@ÓAÐAð ‡z�z�Q„Ø—‘ Ó"ˆà‡z�z�!ƒ}˜Q §
¡
¨1£Ð.Ô.ÜÐTÓUÐUð �H‰H�U‹O€Eà	�‰�B˜Ó	€BØ	�‰�B˜Ó	€BØ��Z˜˜F�ˆØ	ˆF��b�€BØ	ˆF��b�€BÜ�jŠj˜‹n€GÜ�jŠj˜‹n€GÜ�YŠY�r‹]œEŸIšI b›Mˆð ‰g€GÜ�KŠK˜ RÓ(€EÜ�KŠK˜ RÓ(€EØ(-¯©¯ª”�E—I‘I“KÓ  1Ö$¸1€IÜ�LŠL˜¯<©<Ô8×BÑBÀ1ÓE€EØ˜‰~×&Ñ&°Ð&Ó5�G€Dˆ!Ø�D˜!�G�n×&Ñ& qÓ)€GØ�D˜!�GÕ€EÜ	�Š�U˜B˜t Q˜w�K¨¨D°!¨G­Ó	5€BÜ�kŠk˜% ¨¨q¨Õ!1°7¸4À¸7Õ3CÓD€Gä�yŠyØ	ˆB��Õ˜1˜w�;¨�?¨U°4¸°7­^Õ;Õ;¸gÕEÀqÈ7Å{Ðbiô€Hô �{Š{˜5 " T¨1 W¥+°¸¸a¸Õ0@À1Õ0DÕ"DÀhÓO€HÜ�{Š{˜5 (¨B¨t°Q¨w­K¸'À$ÈÀ'Õ:JÈQÕ:NÕ,NÓO€Hä�{Š{˜8¨°·±¸BµÀ!Õ0CÔD€HÜ�{Š{˜8¨°·±¸BµÀ!Õ0CÔD€HØ#(§:¡:¨b°!Ó#4×#;Ñ#;¸E¿J¹JÀq»MÈ2Ó#N€Eˆ!ˆX�xÐ
Ñ Ø€Lr   c                óÜ   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  ,          R\        \        ,          R\        R\         P                  /# )r   r5   Ú	rectangler7   r$   r#   r   )r   r   r   r&   r%   )r   s   "r   r   r     se   € ÷ iñ iÜ�<‰<ðiä�|‰|ðiô ”E—L‘LÕ!ðiô ”4�.ð	iô
 ðiô ‡\�\ñir   c                ó6  € \        V\        4      '       d   \        V\        4      '       g   V^8  d   \        R4      h\	        V . R
O4       V P
                  w  rVrxVP
                  w  ršpWY8w  d   \        R4      hV^8w  d   \        R4      h\        V4      p\        P                  ! VR,          VR,          4      p\        P                  ! VR,          VR,          4      p\        P                  ! VR,          VR,          4      p\        P                  ! VR,          VR,          4      pVf/   \        P                  ! R.V,          4      P                  WZV4      pVP                  ^ 8X  d   VP                  4       MVP
                  R,          p\        V^V39   RV RV 24       Vf   Rp\        VP
                  4      ^8:  d   VP                  WZV4      pVP
                  w  pppV^8X  d   V^8X  d   VP                  WZV4      p\!        WßVVWxWC4      P#                  4       p\%        V4       Fa  p\%        V
4       FO  pVV,          V,           F8  pVVVR	RR3,          V VR	V^ ,          V^,          1V^,          V^,          13&   K:  	  KQ  	  Kc  	  V # )aS  Draw or fill axis-aligned rectangles on a batch of images, in place.

``image = draw_rectangle(image, rectangle, color)`` draws ``N`` rectangles per image, ``(B, N, 4)`` as
``[x1, y1, x2, y2]``, on ``(B, C, H, W)`` images and returns the same tensor: outlines ``line_width`` pixels thick,
or filled boxes with ``fill=True``. A rectangle that leaves the image is clipped instead of raising.

Convention:
    - A rectangle is ``[x1, y1, x2, y2]``, its two corners in either order and both included, with the
      coordinates rounded as in :func:`~kornia.image.draw_line`. Each side of the outline is ``line_width`` pixels
      thick and grows inward, so the outline stays inside the rectangle; a side thicker than the rectangle covers
      it. The outline and a fill are clipped to the image: the part of a side that lies outside the image is not
      drawn.
    - The corners are rounded and the vertices of :func:`~kornia.image.draw_convex_polygon` are not, so a filled
      rectangle and the same polygon always agree for integer corners; for fractional ones each side can be one
      row or column apart, so a polygon thinner than a pixel can fill nothing.
    - The color and the in-place drawing follow :func:`~kornia.image.draw_line`.

Args:
    image: the images, ``(B, C, H, W)``.
    rectangle: the rectangles, ``(B, N, 4)``: ``N`` per image, each ``[x1, y1, x2, y2]``.
    color: the color, ``(C)`` or ``(B, N, C)``, or a single value (0-d, ``(1)`` or
        ``(B, N, 1)``). Black by default.
    fill: whether to fill the rectangles instead of drawing their outlines.
    line_width: the thickness of each side of the outline in pixels, a positive integer. Ignored when
        ``fill=True``.

Raises:
    ShapeError: if the image is not ``(B, C, H, W)``. It is also a ``ValueError``.
    ValueError: if ``rectangle`` is not ``(B, N, 4)``, or its batch size differs from the image's.
    ValueError: if ``line_width`` is not a positive ``int``.
    BaseError: if ``color`` has neither 1 nor ``C`` values per rectangle.

Returns:
    This operation modifies image inplace but also returns the drawn tensor for
    convenience, with the shape of the input ``(B, C, H, W)``.

See Also:
    - :func:`draw_convex_polygon`: fills any convex shape, one per image, with unrounded vertices.
    - :func:`draw_line`: draws one-pixel segments, whose endpoints must lie in the image.

Note:
    The rectangle coordinates are read back to the host once, and ``torch.compile`` breaks the graph there: a
    default ``torch.compile`` compiles the code on either side of that read and matches eager. It is outside the
    :ref:`torch.compile promise <export-support-promise>`.

Example:
    >>> img = torch.rand(2, 3, 10, 12)
    >>> rect = torch.tensor([[[0, 0, 4, 4]], [[4, 4, 11, 9]]])
    >>> out = draw_rectangle(img, rect)
    >>> thick_out = draw_rectangle(img.clone(), rect, line_width=2)

z%line_width must be a positive integerz-Image batch and rectangle batch must be equalz'Number of points in rectangle must be 4Ng        r9   r:   Fr;   ©ÚBÚCÚHÚWr_   ).r   r`   ).rA   r(   )Ú
isinstancer%   r&   rE   r	   rH   r   r   r)   r*   ÚtensorrL   rF   rI   r   rK   r3   ÚtolistÚrange)r5   r�   r7   r$   r#   ÚbatchÚcr!   r"   Ú
batch_rectÚnum_rectangleÚ
num_pointsÚrectr   r   r   r    rN   ÚbÚnÚcolor_channelsr-   r.   s   &&&&&                  r   Údraw_rectangler•     sI  € ôv �j¤#×&Ò&¬*°ZÄ×*FÒ*FÈ*ÐWXÌ.ÜÐ@ÓAÐAä�uÒ2Ô3Ø—[‘[�N€EˆaØ,5¯O©OÑ)€J˜zØÔÜÐHÓIÐIØ�Q„ÜÐBÓCÐCä˜9Ó%€DÜ	�Š�t˜F•| T¨&¥\Ó	2€BÜ	�Š�t˜F•| T¨&¥\Ó	2€BÜ	�Š�t˜F•| T¨&¥\Ó	2€BÜ	�Š�t˜F•| T¨&¥\Ó	2€Bà‚}Ü—’˜c˜U Q�YÓ'×.Ñ.¨uÀQÓGˆð %*§J¡J°!¤O�5—;‘;”=¸¿¹ÀR½€LÜØ˜˜A˜Ñð&Ø&' SÐ(@ÀÀð	Pôð ‚|Øˆä
ˆ5�;‰;Ó˜1ÔØ—‘˜U°1Ó5ˆØ Ÿ;™;Ñ€A€qˆ.à˜Ô˜q AœvØ—‘˜U°1Ó5ˆô *:¸"À"ÀbÈ!ÐPZÓ)a×)hÑ)hÓ)j€EÜ�5Ž\ˆÜ�}Ö%ˆAØ˜a� Ÿ˜�ØDIÈ!ÈQÐPQÐSWÐY]ÐJ]ÕD^��a˜˜D �G d¨1¥gÐ-¨t°A­w¸¸a½Ð/@Ð@ÓAó $ó &ñ ð
 €Lr   c          
      ój   € V ^8„  d   QhR\         R\        R\        R\        \         \         3,          /# )r   Úpolygonr!   r"   r   )r   r%   r   )r   s   "r   r   r   ˆ  s1   € ÷ 9ñ 9œvð 9¬#ð 9´#ð 9¼%ÄÌÀÕ:Oñ 9r   c                ó  € \         P                  ! V P                  \         P                  4      pV P	                  V4      p V P
                  R,          ^8X  d   \         P                  ! W 3RR7      p \         P                  ! V R,          V R,          4      '       g!   \         P                  ! W R	,          3RR7      p V RRR1^ 3,          V RRR1^3,          rTV R
,          V R,          rv\         P                  ! WP                  VR7      pWu,
          p	Wd,
          p
\         P                  ! V	^ 8H  \         P                  ! V	4      V	4      p\         P                  ! V	R,          ^ 8H  VR,          VR,          VR,          ,
          V
R,          ,          VR,          ,          VR,          ,           4      pVR,          VR,          8*  P                  VR,          VR,          8*  4      pWÕR,          VR,          8¬  P                  VR,          VR,          8¬  4      ,          pVP                  4       pW.V( &   VP                  4       pRWý( &   VP                  RR7      P                  pVP!                  RR7      P                  pVV3# )a‰  Get the left and right edges of a polygon for each y-coordinate y \in [0, h).

Args:
    polygon: represents polygons to draw in BxNx2
        N is the number of points
        2 is (x, y).
    h: bottom most coordinate (top coordinate is assumed to be 0)
    w: right most coordinate (left coordinate is assumed to be 0)

Returns:
    The left and right edges of the polygon of shape (B,B).

r=   .N©r@   r   rD   r(   ).r(   r;   ).rB   r;   ).:NrC   Nr;   ).ºrC   NNrB   ).rš   rC   ).Nr;   ©.r;   N)r   r   r   r   r   rH   ÚcatÚequalrf   r@   re   Ú	ones_likeÚlogical_andÚcloner]   Úvaluesr^   )r—   r!   r"   r   Úx_startÚy_startÚx_endÚy_endÚysrn   rm   Úsafe_dyÚxsÚvalid_edgesÚx_left_edgesÚx_right_edgesÚx_leftÚx_rights   &&&               r   Ú_get_convex_edgesr®   ˆ  s'  € ô ×Ò §¡¬u¯}©}Ó=€EØ�j‰j˜Ó€Gð ‡}�}�RÕ˜AÔÜ—)’)˜WÐ.°BÔ7ˆô �;Š;�w˜zÕ*¨G°IÕ,>×?Ò?Ü—)’)˜W¨jÕ&9Ð:ÀÔCˆð ˜s C R C¨˜{Õ+¨W°S¸#¸2¸#¸q°[Õ-AˆWØ˜:Õ&¨°
Õ(;ˆ5ô 
�Š�a§¡°eÔ	<€Bð 
�€BØ	�€Bä�kŠk˜" ™'¤5§?¢?°2Ó#6¸Ó;€GÜ	�ŠØ
ˆ<Õ˜AÑØ�ÕØ	ˆLÕ	˜G LÕ1Õ	1°R¸Õ5EÕEÈÐP\ÕH]Õ]Ð`gÐhtÕ`uÕuó
€Bð ˜<Õ(¨B¨|Õ,<Ñ<×IÑIÈ"È\ÕJZÐ^cÐdpÕ^qÑJqÓr€KØ˜LÕ)¨R°Õ-=Ñ=×JÑJÈ2ÈlÕK[Ð_dÐeqÕ_rÑKrÓsÕs€KØ—8‘8“:€LØ!"�+�ÑØ—H‘H“J€MØ"$€M�,Ñð ×Ñ "ÐÓ%×,Ñ,€FØ×Ñ BÐÓ'×.Ñ.€GØ�7ˆ?Ðr   c                óF   € V ^8„  d   QhR\         \        ,          R\        /# )r   Úpolygonsr   )r   r   )r   s   "r   r   r   Ä  s   € ÷ ñ œd¤6�lð ¬vñ r   c           
     ó®  € \        V 4      \        \        V \         R7      4      r!\        P                  ! W^V ^ ,          P                  V ^ ,          P
                  R7      p\        V 4       Fe  w  rE\        V4      ^ 8X  d   K  \        V4      V8  d;   \        P                  ! WURR P                  V\        V4      ,
          ^4      34      MTW4&   Kg  	  V# )a”  Convert a List of variable length polygons into a fixed size tensor.

Works by repeating the last element in the tensor.

Args:
    polygons: List of variable length polygons of shape [N_1 x 2, N_2 x 2, ..., N_B x 2].
                B is the batch size,
                N_i is the number of points,
                2 is (x, y).

Returns:
    A fixed size tensor of shape (B, N, 2) where N = max_i(N_i)

)Úkeyr?   Nr(   )	rK   r^   r   Úzerosr   r@   Ú	enumeraterœ   rL   )r°   r„   ÚNÚbatched_polygonsr’   rl   s   &     r   Ú_batch_polygonsr·   Ä  s©   € ô ˆx‹=œ#œc (´Ô4Ó5€qÜ—{’{ 1¨°(¸1µ+×2CÑ2CÈHÐUVÍK×L^ÑL^Ô_ÐÜ˜(Ö#‰ˆÜˆq‹6�QŒ;áÜNQÐRSËfÐWXÌjœeŸiši¨¨b¨c¨F¯M©M¸!¼cÀ!»f½*ÀaÓ,HÐ(IÔJÐ^_ÐÓñ	 $ð
 Ðr   c                ó€   € V ^8„  d   QhR\         R\        \         \        \         ,          3,          R\         R\         /# )r   Úimagesr°   Úcolorsr   )r   r   r   )r   s   "r   r   r   Ý  s>   € ÷ Rñ R¤ð R´%¼ÄÄVÅÐ8LÕ2Mð RÔW]ð RÔbhñ Rr   c                ó  aa€ \        V . RO4       . V P                  OV P                  N5w  porEpRp\        V\        4      '       dj   \
        P                  ! V Uu. uF  p\        V4      ^ 8H  NK  	  up\
        P                  VR7      pV'       d   \        V4      MV P                  ^ ^ ^4      p. VP                  OVP                  N5w  ršr¼VP                  ^ 8X  d   VP                  4       MVP                  R	,          o\        S^S39   VV3R l4       \        VP                  4      ^8:  d   VP                  VS4      p. VP                  OVP                  N5w  rÚp\        V^8H  R4       \        Y9u;8H  ;'       d    V8H  Mu R4       \        Ylu;8H  ;'       d    V8H  Mu R4       VP                  ^,          ^ 8X  d   V # \        WV4      w  pp\
        P                   ! WVVP"                  R7      R
,          pVVR,          8¬  VVR,          8*  ,          pVe   VVR,          ( ,          pVR,          pV P%                  \
        P&                  ! VVR,          P)                  V P"                  4      V 4      4       V # u upi )aå  Fill one convex polygon per image on a batch of images, in place.

``images = draw_convex_polygon(images, polygons, colors)`` fills polygon ``b`` on image ``b`` of a
``(B, C, H, W)`` batch and returns the same tensor. The :math:`(x, y)` vertices are a ``(B, N, 2)`` tensor or a list
of ``B`` tensors of shape ``(N_b, 2)``.

Convention:
    - Vertices are :math:`(x, y)` in the pixel frame of :func:`~kornia.image.draw_line`, used as given, without
      rounding. A pixel is filled when its centre lies inside the polygon or on its boundary, as
      ``skimage.draw.polygon`` fills; ``cv2.fillConvexPoly`` fills more. The part outside the image is clipped.
    - The polygon is taken to be convex: each row is filled from its leftmost to its rightmost edge crossing, so
      in a concave polygon a gap between two edges within a row is filled too.
    - The polygons and the colors must already be on the images' device; the other draw functions move theirs.
    - The color and the in-place drawing follow :func:`~kornia.image.draw_line`.

Args:
    images: is tensor of BxCxHxW.
    polygons: represents polygons as points, either BxNx2 or List of variable length polygons.
        N is the number of points.
        2 is (x, y).
    colors: the fill colors, ``(B, C)`` or ``(C)``, or a single value (0-d, ``(1)`` or
        ``(B, 1)``).

Returns:
    This operation modifies image inplace but also returns the drawn tensor for
    convenience, with the shape of the input ``(B, C, H, W)``.

Raises:
    ShapeError: if the images are not ``(B, C, H, W)``. It is also a ``ValueError``.
    ValueError: if ``polygons`` is a tensor that is not three dimensional.
    BaseError: if ``colors`` has neither 1 nor ``C`` values per polygon.
    BaseError: if the vertices are not ``(x, y)`` points.
    BaseError: if the images, polygons and colors differ in batch size or device.

See Also:
    - :func:`draw_rectangle`: draws outlines as well as fills, and several rectangles per image.
    - :func:`draw_line`: draws the edges of a polygon as one-pixel segments.

Example:
    >>> img = torch.rand(1, 3, 12, 16)
    >>> poly = torch.tensor([[[4, 4], [12, 4], [12, 8], [4, 8]]])
    >>> color = torch.tensor([[0.5, 0.5, 0.5]])
    >>> out = draw_convex_polygon(img, poly, color)

Nr?   c                  ó   <€ R S  RS 2# )r9   r:   rU   )Úc_irN   s   €€r   Ú<lambda>Ú%draw_convex_polygon.<locals>.<lambda>  s   ø€ ð*Ø*-¨Ð.FÀ|ÀnñVr   z/Polygon vertices must be xy, i.e. 2-dimensionalz8Image, polygon, and color must have same batch dimensionz/Image, polygon, and color must have same devicer™   rƒ   r(   )NNr;   r›   )r;   NN)r;   N).NN)r	   rH   r@   rˆ   r   r   r‰   rK   r&   r·   Ú	new_zerosrF   rI   r   rL   r®   rf   r   Úcopy_re   r   )r¹   r°   rº   Úb_iÚh_iÚw_ir@   Úempty_polygonsrl   Úb_pÚ_ÚxyÚdevice_pÚb_cÚdevice_cr¬   r­   ÚwsÚfill_regionr$   r½   rN   s   &&&                 @@r   Údraw_convex_polygonrÎ   Ý  s  ù€ ô^ �vÒ3Ô4Ø!= &§,¡,Ð!=°·±Ñ!=Ñ€Cˆˆc˜Ø€NÜ�(œD×!Ò!ÜŸš¹HÓ&E¹H°q¤s¨1£v°¤{¹HÑ&EÌUÏZÉZÐ`fÔgˆç08”? 8Ô,¸f×>NÑ>NÈqÐRSÐUVÓ>WˆØ;˜HŸN™NÐ;¨H¯O©OÑ;Ñ€CˆBð &,§[¡[°AÔ%5�6—<‘<”>¸6¿<¹<ÈÕ;K€LÜØ˜˜C˜Ñ õ	
ôô ˆ6�<‰<Ó˜AÔØ—‘˜s CÓ(ˆØ3˜Ÿ™Ð3 f§m¡mÑ3Ñ€CˆHÜ��q‘ÐKÔLÜ�×"Ô"˜sÔ"Ð$^Ô_Ü�×/Ô/ xÔ/Ð1bÔcà‡~�~�aÕ˜AÔØˆä'¨°sÓ;�O€FˆGÜ	�Š�c°·±Ô	=¸mÕ	L€BØ˜ Õ-Ñ-°"¸ÀÕ8MÑ2MÕN€KØÒ!Ø˜ }Õ5Ð5Õ5ˆØ�wÕ€DØ
‡L�L”—’˜T 6¨/Õ#:×#=Ñ#=¸f¿l¹lÓ#KÈVÓTÔUØ€Mùò? 'Fs   ÁJ)NNrC   )Ú__doc__Útypingr   r   r   r   r   r   Úkornia.core.checkr   r	   r   r3   rR   rV   r   r•   r®   r·   rÎ   rU   r   r   Ú<module>rÒ      sP   ðñ" 'ç /Ó /ã Ý ç >õ
	"õoõBKõ\õ q÷hiõX9õx÷2Rr   