Ë
    \;j@¡ ã                   ó  — d Z ddlmZmZmZ ddlZddlZddlZddl	Z
ddlmZ ddlZddlZddlmZ ddlmZ ddlmZ dd	lmZmZmZmZmZ d
„ Z G d„ de«      Z  G d„ de«      Z!	 	 dd„Z" G d„ de«      Z# G d„ de«      Z$y)zClasses dealing with polygons.é    )Úprint_functionÚdivisionÚabsolute_importNé   )Úimgaug)Úrandomé   )ÚIAugmentable)Únormalize_shapeÚinterpolate_pointsÚ_remove_out_of_image_fraction_Úproject_coords_Ú_normalize_shift_argsc                 ó$  — d}t        | t        «      sd}| g} |g}t        | «      D ]`  \  }}t        |j                  «      D ]C  \  }}|j	                  |j
                  ||   j                  |   |«      }	|	j
                  |_        ŒE Œb |s| d   S | S )a?  Apply a polygon recoverer to input polygons in-place.

    Parameters
    ----------
    psois : list of imgaug.augmentables.polys.PolygonsOnImage or imgaug.augmentables.polys.PolygonsOnImage
        The possibly broken polygons, e.g. after augmentation.
        The `recoverer` is applied to them.

    psois_orig : list of imgaug.augmentables.polys.PolygonsOnImage or imgaug.augmentables.polys.PolygonsOnImage
        Original polygons that were later changed to `psois`.
        They are an extra input to `recoverer`.

    recoverer : imgaug.augmentables.polys._ConcavePolygonRecoverer
        The polygon recoverer used to repair broken input polygons.

    random_state : None or int or RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState
        An RNG to use during the polygon recovery.

    Returns
    -------
    list of imgaug.augmentables.polys.PolygonsOnImage or imgaug.augmentables.polys.PolygonsOnImage
        List of repaired polygons. Note that this is `psois`, which was
        changed in-place.

    TFr   )Ú
isinstanceÚlistÚ	enumerateÚpolygonsÚrecover_fromÚexterior)
ÚpsoisÚ
psois_origÚ	recovererÚrandom_stateÚinput_was_listÚiÚpsoiÚjÚpolygonÚpoly_recs
             úbG:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\imgaug/augmentables/polys.pyÚrecover_psois_r"      s    € ð4 €NÜ�eœTÔ"ØˆØ�ˆØ �\ˆ
ä˜UÖ#‰ˆˆ4Ü# D§M¡MÖ2‰JˆAˆwØ ×-Ñ-Ø× Ñ  *¨Q¡-×"8Ñ"8¸Ñ";ØóˆHð  (×0Ñ0ˆGÕñ 3ð $ñ Ø�Q‰xˆØ€Ló    c                   óÚ  — e Zd ZdZd1d„Zed„ «       Zed„ «       Zed„ «       Zed„ «       Z	ed„ «       Z
ed	„ «       Zed
„ «       Zed„ «       Zed„ «       Zd„ Zd„ Zd2d„Zd„ Zd„ Zd„ Zd„ Zd3d„Z ej0                  dd¬«      d„ «       Zd„ Zd4d„Zd5d„Z	 	 	 	 	 	 d6d„Zd„ Z	 	 d7d„Zd„ Z d „ Z!d!„ Z"d"„ Z#d8d#„Z$d$„ Z%d%„ Z&d9d&„Z'e(d1d'„«       Z)	 	 d:d(„Z*	 	 d:d)„Z+d:d*„Z,d;d+„Z-d;d,„Z.d-„ Z/d.„ Z0d/„ Z1d0„ Z2y)<ÚPolygonaÒ  Class representing polygons.

    Each polygon is parameterized by its corner points, given as absolute
    x- and y-coordinates with sub-pixel accuracy.

    Parameters
    ----------
    exterior : list of imgaug.augmentables.kps.Keypoint or list of tuple of float or (N,2) ndarray
        List of points defining the polygon. May be either a ``list`` of
        :class:`~imgaug.augmentables.kps.Keypoint` objects or a ``list`` of
        ``tuple`` s in xy-form or a numpy array of shape (N,2) for ``N``
        points in xy-form.
        All coordinates are expected to be the absolute subpixel-coordinates
        on the image, given as ``float`` s, e.g. ``x=10.7`` and ``y=3.4`` for a
        point at coordinates ``(10.7, 3.4)``. Their order is expected to be
        clock-wise. They are expected to not be closed (i.e. first and last
        coordinate differ).

    label : None or str, optional
        Label of the polygon, e.g. a string representing the class.

    Nc                 óV  — ddl m} t        |t        «      r¬|s+t	        j
                  dt        j                  ¬«      | _        nít        |d   |«      r?t	        j                  |D �cg c]  }|j                  |j                  g‘Œ c}«      | _        nŸt	        j                  |D �cg c]  }|d   |d   g‘Œ c}«      | _        nnt        j                  |«      s
J d|›�«       ‚|j                  dk(  r|j                  d   dk(  sJ d|j                  ›�«       ‚t	        j                  |«      | _        t        | j                  «      dk\  xr8 t	        j                  | j                  dd	d	…f   | j                  d
d	d	…f   «      }|r| j                  d	d
 | _        || _        y	c c}w c c}w )zCreate a new Polygon instance.r   ©ÚKeypoint©r   r   ©Údtyper	   zMExpected exterior to be a list of tuples (x, y) or an (N, 2) array, got type r   zZExpected exterior to be a list of tuples (x, y) or an (N, 2) array, got an array of shape Néÿÿÿÿ)Úimgaug.augmentables.kpsr(   r   r   ÚnpÚzerosÚfloat32r   ÚxÚyÚiaÚis_np_arrayÚndimÚshapeÚlenÚallcloseÚlabel)Úselfr   r9   r(   ÚpointÚ	is_closeds         r!   Ú__init__zPolygon.__init__e   s�  € õ 	5ä�h¤Ô%Ùô !#§¡¨´r·z±zÔ B�•Ü˜H Q™K¨Ô2ä "§
¡
Ù9Aó,CÙ9A°ð .3¯W©W°e·g±gÒ,>Ø9Añ,Có !D�•ô
 !#§
¡
Ù9Aó,CÙ9A°ð .3°1©X°u¸Q±xÒ,@Ø9Añ,Có !D�•ô —>‘> (Ô+ñ >á2:ð=ó>Ð+ð —=‘= AÒ%¨(¯.©.¸Ñ*;¸qÒ*@ñ &ð —N’Nð%ó&Ð@ô
 ŸJ™J xÓ0ˆDŒMô �—‘Ó !Ñ#ò GÜ—‘˜DŸM™M¨!ªQ¨$Ñ/°·±¸rÂ1¸uÑ1EÓFð 	ñ Ø ŸM™M¨#¨2Ð.ˆDŒMàˆ�
ùò9,Cùò
,Cs   Á&F!Â%F&c                 ó   — | j                   S )a	  Alias for attribute ``exterior``.

        Added in 0.4.0.

        Returns
        -------
        ndarray
            An ``(N, 2)`` ``float32`` ndarray containing the coordinates of
            this polygon. This identical to the attribute ``exterior``.

        ©r   ©r:   s    r!   ÚcoordszPolygon.coords�   s   € ð �}‰}Ðr#   c                 ó(   — | j                   dd…df   S )zÀGet the x-coordinates of all points on the exterior.

        Returns
        -------
        (N,2) ndarray
            ``float32`` x-coordinates array of all points on the exterior.

        Nr   r?   r@   s    r!   Úxxz
Polygon.xxŸ   ó   € ð �}‰}šQ ˜TÑ"Ð"r#   c                 ó(   — | j                   dd…df   S )zÀGet the y-coordinates of all points on the exterior.

        Returns
        -------
        (N,2) ndarray
            ``float32`` y-coordinates array of all points on the exterior.

        Nr	   r?   r@   s    r!   Úyyz
Polygon.yy«   rD   r#   c                 óf   — t        j                  t        j                  | j                  «      «      S )a�  Get the discretized x-coordinates of all points on the exterior.

        The conversion from ``float32`` coordinates to ``int32`` is done
        by first rounding the coordinates to the closest integer and then
        removing everything after the decimal point.

        Returns
        -------
        (N,2) ndarray
            ``int32`` x-coordinates of all points on the exterior.

        )r.   Úint32ÚroundrC   r@   s    r!   Úxx_intzPolygon.xx_int·   ó    € ô �x‰xœŸ™ §¡Ó)Ó*Ð*r#   c                 óf   — t        j                  t        j                  | j                  «      «      S )a�  Get the discretized y-coordinates of all points on the exterior.

        The conversion from ``float32`` coordinates to ``int32`` is done
        by first rounding the coordinates to the closest integer and then
        removing everything after the decimal point.

        Returns
        -------
        (N,2) ndarray
            ``int32`` y-coordinates of all points on the exterior.

        )r.   rH   rI   rF   r@   s    r!   Úyy_intzPolygon.yy_intÇ   rK   r#   c                 óh   — t        | j                  «      dk  ry| j                  «       j                  S )a×  Estimate whether the polygon has a valid geometry.

        To to be considered valid, the polygon must be made up of at
        least ``3`` points and have a concave shape, i.e. line segments may
        not intersect or overlap. Multiple consecutive points are allowed to
        have the same coordinates.

        Returns
        -------
        bool
            ``True`` if polygon has at least ``3`` points and is concave,
            otherwise ``False``.

        é   F)r7   r   Úto_shapely_polygonÚis_validr@   s    r!   rQ   zPolygon.is_valid×   s-   € ô  ˆt�}‰}Ó Ò!ØØ×&Ñ&Ó(×1Ñ1Ð1r#   c                 ól   — t        | j                  «      dk  ry| j                  «       }|j                  S )z{Compute the area of the polygon.

        Returns
        -------
        number
            Area of the polygon.

        rO   g        )r7   r   rP   Úarea©r:   Úpolys     r!   rS   zPolygon.areaë   s0   € ô ˆt�}‰}Ó Ò!ØØ×&Ñ&Ó(ˆØ�y‰yÐr#   c                 óH   — | j                   }t        |«      t        |«      z
  S )a  Compute the height of a bounding box encapsulating the polygon.

        The height is computed based on the two exterior coordinates with
        lowest and largest x-coordinates.

        Returns
        -------
        number
            Height of the polygon.

        )rF   ÚmaxÚmin)r:   rF   s     r!   ÚheightzPolygon.heightú   ó    € ð �W‰WˆÜ�2‹wœ˜R›Ñ Ð r#   c                 óH   — | j                   }t        |«      t        |«      z
  S )a  Compute the width of a bounding box encapsulating the polygon.

        The width is computed based on the two exterior coordinates with
        lowest and largest x-coordinates.

        Returns
        -------
        number
            Width of the polygon.

        )rC   rW   rX   )r:   rC   s     r!   ÚwidthzPolygon.width
  rZ   r#   c                 ó>   — t        | j                  ||«      | _        | S )ay  Project the polygon onto an image with different shape in-place.

        The relative coordinates of all points remain the same.
        E.g. a point at ``(x=20, y=20)`` on an image
        ``(width=100, height=200)`` will be projected on a new
        image ``(width=200, height=100)`` to ``(x=40, y=10)``.

        This is intended for cases where the original image is resized.
        It cannot be used for more complex changes (e.g. padding, cropping).

        Added in 0.4.0.

        Parameters
        ----------
        from_shape : tuple of int
            Shape of the original image. (Before resize.)

        to_shape : tuple of int
            Shape of the new image. (After resize.)

        Returns
        -------
        imgaug.augmentables.polys.Polygon
            Polygon object with new coordinates.
            The object may have been modified in-place.

        )r   rA   r   ©r:   Ú
from_shapeÚto_shapes      r!   Úproject_zPolygon.project_  s   € ô8 (¨¯©°ZÀÓJˆŒØˆr#   c                 óB   — | j                  «       j                  ||«      S )a  Project the polygon onto an image with different shape.

        The relative coordinates of all points remain the same.
        E.g. a point at ``(x=20, y=20)`` on an image
        ``(width=100, height=200)`` will be projected on a new
        image ``(width=200, height=100)`` to ``(x=40, y=10)``.

        This is intended for cases where the original image is resized.
        It cannot be used for more complex changes (e.g. padding, cropping).

        Parameters
        ----------
        from_shape : tuple of int
            Shape of the original image. (Before resize.)

        to_shape : tuple of int
            Shape of the new image. (After resize.)

        Returns
        -------
        imgaug.augmentables.polys.Polygon
            Polygon object with new coordinates.

        )Údeepcopyra   r^   s      r!   ÚprojectzPolygon.project9  s   € ð2 �}‰}‹×'Ñ'¨
°HÓ=Ð=r#   c                 ó  — t        | j                  «      dkD  sJ d«       ‚g }| j                  D ]'  \  }}||z
  dz  ||z
  dz  z   }|j                  |«       Œ) t        j                  |«      }t        j
                  |«      }|r|||   fS |S )a)  Find the index of the exterior point closest to given coordinates.

        "Closeness" is here defined based on euclidean distance.
        This method will raise an ``AssertionError`` if the exterior contains
        no points.

        Parameters
        ----------
        x : number
            X-coordinate around which to search for close points.

        y : number
            Y-coordinate around which to search for close points.

        return_distance : bool, optional
            Whether to also return the distance of the closest point.

        Returns
        -------
        int
            Index of the closest point.

        number
            Euclidean distance to the closest point.
            This value is only returned if `return_distance` was set
            to ``True``.

        r   zOCannot find the closest point on a polygon which's exterior contains no points.r   )r7   r   Úappendr.   ÚsqrtÚargmin)	r:   r1   r2   Úreturn_distanceÚ	distancesÚx2Úy2ÚdistÚclosest_idxs	            r!   Úfind_closest_point_indexz Polygon.find_closest_point_indexT  sŸ   € ô: �4—=‘=Ó! AÒ%ð 	#ð"ó	#Ð%ð ˆ	Ø—m”m‰FˆB�Ø˜‘F˜q‘= B¨¡F¨q¡=Ñ0ˆDØ×Ñ˜TÕ"ð $ô —G‘G˜IÓ&ˆ	Ü—i‘i 	Ó*ˆÙØ 	¨+Ñ 6Ð6Ð6ØÐr#   c                 óÂ   — | j                  |«      }t        |«      dk(  r| j                  S | j                  t        |D �cg c]  }|j                  ‘Œ c}«      z
  S c c}w )a+  Compute the area of the BB that is outside of the image plane.

        Added in 0.4.0.

        Parameters
        ----------
        image : (H,W,...) ndarray or tuple of int
            Image dimensions to use.
            If an ``ndarray``, its shape will be used.
            If a ``tuple``, it is assumed to represent the image shape
            and must contain at least two integers.

        Returns
        -------
        float
            Total area of the bounding box that is outside of the image plane.
            Can be ``0.0``.

        r   )Úclip_out_of_imager7   rS   Úsum)r:   ÚimageÚpolys_clippedrU   s       r!   Úcompute_out_of_image_areaz!Polygon.compute_out_of_image_area~  sU   € ð( ×.Ñ.¨uÓ5ˆÜˆ}Ó Ò"Ø—9‘9ÐØ�y‰yœ3±mÓD±m¨d §	£	°mÑDÓEÑEÐEùÒDs   Á A
c                 óŠ   — | j                   }|dk(  r| j                  «       j                  |«      S | j                  |«      |z  S )a  Compute fraction of polygon area outside of the image plane.

        This estimates ``f = A_ooi / A``, where ``A_ooi`` is the area of the
        polygon that is outside of the image plane, while ``A`` is the
        total area of the bounding box.

        Added in 0.4.0.

        Parameters
        ----------
        image : (H,W,...) ndarray or tuple of int
            Image dimensions to use.
            If an ``ndarray``, its shape will be used.
            If a ``tuple``, it is assumed to represent the image shape
            and must contain at least two integers.

        Returns
        -------
        float
            Fraction of the polygon area that is outside of the image
            plane. Returns ``0.0`` if the polygon is fully inside of
            the image plane or has zero points. If the polygon has an area
            of zero, the polygon is treated similarly to a :class:`LineString`,
            i.e. the fraction of the line that is outside the image plane is
            returned.

        r   )rS   Úto_line_stringÚcompute_out_of_image_fractionru   )r:   rs   rS   s      r!   rx   z%Polygon.compute_out_of_image_fraction—  sD   € ð8 �y‰yˆØ�1Š9Ø×&Ñ&Ó(×FÑFÀuÓMÐMØ×-Ñ-¨eÓ4°tÑ;Ð;r#   c                 ó,   — | j                  |dd¬«       S )a
  Estimate whether the polygon is fully inside an image plane.

        Parameters
        ----------
        image : (H,W,...) ndarray or tuple of int
            Image dimensions to use.
            If an ``ndarray``, its shape will be used.
            If a ``tuple``, it is assumed to represent the image shape and
            must contain at least two ``int`` s.

        Returns
        -------
        bool
            ``True`` if the polygon is fully inside the image area.
            ``False`` otherwise.

        T©ÚfullyÚpartly©Úis_out_of_image©r:   rs   s     r!   Úis_fully_within_imagezPolygon.is_fully_within_image¹  s   € ð$ ×'Ñ'¨°TÀ$Ð'ÓGÐGÐGr#   c                 ó,   — | j                  |dd¬«       S )a  Estimate whether the polygon is at least partially inside an image.

        Parameters
        ----------
        image : (H,W,...) ndarray or tuple of int
            Image dimensions to use.
            If an ``ndarray``, its shape will be used.
            If a ``tuple``, it is assumed to represent the image shape and
            must contain at least two ``int`` s.

        Returns
        -------
        bool
            ``True`` if the polygon is at least partially inside the image area.
            ``False`` otherwise.

        TFrz   r}   r   s     r!   Úis_partly_within_imagezPolygon.is_partly_within_imageÎ  s   € ð$ ×'Ñ'¨°TÀ%Ð'ÓHÐHÐHr#   c                 óþ   — t        | j                  «      dk(  rt        d«      ‚| j                  «       }|j	                  |«      ry|j                  |dd¬«      r|S | j                  |«      }t        |«      dkD  r|S |S )ag  Estimate whether the polygon is partially/fully outside of an image.

        Parameters
        ----------
        image : (H,W,...) ndarray or tuple of int
            Image dimensions to use.
            If an ``ndarray``, its shape will be used.
            If a ``tuple``, it is assumed to represent the image shape and
            must contain at least two ``int`` s.

        fully : bool, optional
            Whether to return ``True`` if the polygon is fully outside of the
            image area.

        partly : bool, optional
            Whether to return ``True`` if the polygon is at least partially
            outside fo the image area.

        Returns
        -------
        bool
            ``True`` if the polygon is partially/fully outside of the image
            area, depending on defined parameters.
            ``False`` otherwise.

        r   zXCannot determine whether the polygon is inside the image, because it contains no points.FTrz   )r7   r   Ú	Exceptionrw   r€   r~   rq   )r:   rs   r{   r|   ÚlsÚpolyss         r!   r~   zPolygon.is_out_of_imageâ  sŒ   € ô: ˆt�}‰}Ó Ò"Üð Hó Ið Ið × Ñ Ó"ˆØ×#Ñ# EÔ*ØØ×Ñ˜e¨5¸ÐÔ>ØˆMð ×&Ñ& uÓ-ˆÜˆu‹:˜Š>ØˆMØˆr#   zPolygon.clip_out_of_image()z3clip_out_of_image() has the exactly same interface.)Úalt_funcÚcommentc                 ó$   — | j                  |«      S )z>Cut off all parts of the polygon that are outside of an image.)rq   r   s     r!   Úcut_out_of_imagezPolygon.cut_out_of_image  s   € ð
 ×%Ñ% eÓ,Ð,r#   c                 ó  — ddl }t        | j                  «      dk(  rg S t        | j                  «      dv rc| j                  d¬«      }|j	                  |«      }t        |«      dk  sJ ‚t        |«      dk(  rg S | j                  |d   j                  ¬«      gS t        j                  |«      r|j                  dd n|dd \  }}| j                  «       }|j                  j                  d	|df||fd|fg«      }|j                  |«      }	|j                  j                  |j                  j                  |j                  j                   j"                  |j                  j$                  f}
t'        |	|j                  j                  «      r|j                  j)                  |	g«      }	nµt'        |	|j                  j(                  «      rn”t'        |	|
«      r|j                  j)                  g «      }	nlt'        |	|j                  j*                  «      r|	j,                  sJ ‚g S t/        |	|| j                  «       t1        d
t3        |	«      ||| j                  fz  «      ‚g }|	j4                  D ]2  }|j7                  t        j9                  || j:                  ¬«      «       Œ4 g }|D ]b  }d}d}| j                  D ](  \  }}|j=                  ||d¬«      \  }}|�||k  sŒ%|}|}Œ* |€ŒA|j?                  |«      }|j7                  |«       Œd |S )aF  Cut off all parts of the polygon that are outside of an image.

        This operation may lead to new points being created.
        As a single polygon may be split into multiple new polygons, the result
        is always a list, which may contain more than one output polygon.

        This operation will return an empty list if the polygon is completely
        outside of the image plane.

        Parameters
        ----------
        image : (H,W,...) ndarray or tuple of int
            Image dimensions to use for the clipping of the polygon.
            If an ``ndarray``, its shape will be used.
            If a ``tuple``, it is assumed to represent the image shape and must
            contain at least two ``int`` s.

        Returns
        -------
        list of imgaug.augmentables.polys.Polygon
            Polygon, clipped to fall within the image dimensions.
            Returned as a ``list``, because the clipping can split the polygon
            into multiple parts. The list may also be empty, if the polygon was
            fully outside of the image plane.

        r   N)r	   r   F©Úclosedr	   r?   r   ©r   r   z}Got an unexpected result of type %s from Shapely for image (%d, %d) and polygon %s. This is an internal error. Please report.©r9   T©r1   r2   ri   ) Úshapely.geometryr7   r   rw   rq   rc   rA   r3   r4   r6   rP   Úgeometryr%   ÚintersectionÚ
LineStringÚMultiLineStringr;   ÚPointÚ
MultiPointr   ÚMultiPolygonÚGeometryCollectionÚis_emptyÚprintr„   ÚtypeÚgeomsrf   Úfrom_shapelyr9   ro   Úchange_first_point_by_index)r:   rs   Úshapelyr…   Ú
ls_clippedÚhÚwÚpoly_shapelyÚ
poly_imageÚmultipoly_inter_shapelyÚignore_typesr   Úpoly_inter_shapelyÚpolygons_reorderedr   Úbest_idxÚ	best_distr1   r2   Ú	point_idxrm   Úpolygon_reordereds                         r!   rq   zPolygon.clip_out_of_image#  s  € ó8 	 ô ˆt�}‰}Ó Ò"ØˆIÜˆt�}‰}Ó Ñ'Ø×$Ñ$¨EÐ$Ó2ˆBØ×-Ñ-¨eÓ4ˆJÜ�z“? aÒ'Ð'Ð'Ü�:‹ !Ò#Ø�	Ø—M‘M¨:°a©=×+?Ñ+?�MÓ@ÐAÐAä#%§>¡>°%Ô#8ˆu�{‰{˜1˜QÑ¸eÀAÀa¸j‰ˆˆ1Ø×.Ñ.Ó0ˆØ×%Ñ%×-Ñ-¨v¸¸1°vÀÀ1¸vÈÈ1ÀvÐ.NÓOˆ
Ø".×";Ñ";¸JÓ"GÐØ×(Ñ(×3Ñ3Ø×(Ñ(×8Ñ8Ø×(Ñ(×.Ñ.×4Ñ4Ø×(Ñ(×3Ñ3ð5ˆô Ð-¨w×/?Ñ/?×/GÑ/GÔHØ&-×&6Ñ&6×&CÑ&CØ(Ð)ó'+Ñ#äÐ/Ø×(Ñ(×5Ñ5ô7ð ÜÐ/°Ô>ð '.×&6Ñ&6×&CÑ&CÀBÓ&GÑ#ÜÐ/Ø×(Ñ(×;Ñ;ô=ð +×3Ò3Ð3Ð3ØˆIäÐ)¨5°$·-±-Ô@Üð!ô Ð0Ó1°1°a¸¿¹ð$HñHóð ð ˆØ"9×"?Ô"?ÐØ�O‰OœG×0Ñ0Ð1CØ7;·z±zð 1ó Cõ Dð #@ð  ÐÛˆGØˆHØˆIØŸœ‘��1Ø")×"BÑ"BØ˜1¨dð #Có #4‘�	˜4àÐ# t¨iÓ'7Ø(�HØ $‘Ið &ð Ñ#à×7Ñ7¸ÓAð "à"×)Ñ)Ð*;Õ<ð  ð "Ð!r#   c                 ór   — | j                   dd…dfxx   |z  cc<   | j                   dd…dfxx   |z  cc<   | S )at  Move this polygon along the x/y-axis in-place.

        The origin ``(0, 0)`` is at the top left of the image.

        Added in 0.4.0.

        Parameters
        ----------
        x : number, optional
            Value to be added to all x-coordinates. Positive values shift
            towards the right images.

        y : number, optional
            Value to be added to all y-coordinates. Positive values shift
            towards the bottom images.

        Returns
        -------
        imgaug.augmentables.polys.Polygon
            Shifted polygon.
            The object may have been modified in-place.

        Nr   r	   r?   )r:   r1   r2   s      r!   Úshift_zPolygon.shift_Œ  s9   € ð0 	�‰’a˜�dÓ˜qÑ ÓØ�‰’a˜�dÓ˜qÑ ÓØˆr#   c                 ól   — t        ||||||¬«      \  }}| j                  «       j                  ||¬«      S )aô  Move this polygon along the x/y-axis.

        The origin ``(0, 0)`` is at the top left of the image.

        Parameters
        ----------
        x : number, optional
            Value to be added to all x-coordinates. Positive values shift
            towards the right images.

        y : number, optional
            Value to be added to all y-coordinates. Positive values shift
            towards the bottom images.

        top : None or int, optional
            Deprecated since 0.4.0.
            Amount of pixels by which to shift this object *from* the
            top (towards the bottom).

        right : None or int, optional
            Deprecated since 0.4.0.
            Amount of pixels by which to shift this object *from* the
            right (towards the left).

        bottom : None or int, optional
            Deprecated since 0.4.0.
            Amount of pixels by which to shift this object *from* the
            bottom (towards the top).

        left : None or int, optional
            Deprecated since 0.4.0.
            Amount of pixels by which to shift this object *from* the
            left (towards the right).

        Returns
        -------
        imgaug.augmentables.polys.Polygon
            Shifted polygon.

        ©ÚtopÚrightÚbottomÚleft©r1   r2   ©r   rc   r¯   ©r:   r1   r2   r²   r³   r´   rµ   s          r!   ÚshiftzPolygon.shift¨  ó=   € ôR %Øˆq�c ¨v¸DôB‰ˆˆ1à�}‰}‹×%Ñ%¨¨QÐ%Ó/Ð/r#   c                 óè  — d„ }d„ } |d|«        |d|«        |d|
«        ||t        j                  |«      «      } ||t        j                  |«      dz  «      } ||t        j                  |«      dz  «      } |||dz  «      } |||«      } ||	|«      }	 |||
«      } |||
dz  «      }|j                  dk(  r-t        j                  |«      sJ d	t        |«      ›d
�«       ‚|g}n7|j                  dk(  r(t        j                  |«      r|g|j                  d   z  }|dk  rd}n|dkD  rd}|r6| j                  |«      r%t        dt        | «      ›d|j                  ›d
�«      ‚|j                  }|j                  t         j                  «      }t        j                  j                  | j                  | j                   |j                  ¬«      \  }}t#        |«      dkD  rT|dk(  rt        j                  |«      |||f<   n4|dk(  rn.d|z
  |||dd…f   z  |t        j                  |«      z  z   |||f<   | j%                  d¬«      }| j%                  d¬«      }|j'                  |||||¬«      }|j)                  |||	||¬«      }|j*                  t         j,                  k(  r;t        j.                  t        j0                  |«      dd«      j                  |«      }|S |j                  |«      }|S )aï  Draw the polygon on an image.

        Parameters
        ----------
        image : (H,W,C) ndarray
            The image onto which to draw the polygon. Usually expected to be
            of dtype ``uint8``, though other dtypes are also handled.

        color : iterable of int, optional
            The color to use for the whole polygon.
            Must correspond to the channel layout of the image. Usually RGB.
            The values for `color_face`, `color_lines` and `color_points`
            will be derived from this color if they are set to ``None``.
            This argument has no effect if `color_face`, `color_lines`
            and `color_points` are all set anything other than ``None``.

        color_face : None or iterable of int, optional
            The color to use for the inner polygon area (excluding perimeter).
            Must correspond to the channel layout of the image. Usually RGB.
            If this is ``None``, it will be derived from ``color * 1.0``.

        color_lines : None or iterable of int, optional
            The color to use for the line (aka perimeter/border) of the
            polygon.
            Must correspond to the channel layout of the image. Usually RGB.
            If this is ``None``, it will be derived from ``color * 0.5``.

        color_points : None or iterable of int, optional
            The color to use for the corner points of the polygon.
            Must correspond to the channel layout of the image. Usually RGB.
            If this is ``None``, it will be derived from ``color * 0.5``.

        alpha : float, optional
            The opacity of the whole polygon, where ``1.0`` denotes a
            completely visible polygon and ``0.0`` an invisible one.
            The values for `alpha_face`, `alpha_lines` and `alpha_points`
            will be derived from this alpha value if they are set to ``None``.
            This argument has no effect if `alpha_face`, `alpha_lines`
            and `alpha_points` are all set anything other than ``None``.

        alpha_face : None or number, optional
            The opacity of the polygon's inner area (excluding the perimeter),
            where ``1.0`` denotes a completely visible inner area and ``0.0``
            an invisible one.
            If this is ``None``, it will be derived from ``alpha * 0.5``.

        alpha_lines : None or number, optional
            The opacity of the polygon's line (aka perimeter/border),
            where ``1.0`` denotes a completely visible line and ``0.0`` an
            invisible one.
            If this is ``None``, it will be derived from ``alpha * 1.0``.

        alpha_points : None or number, optional
            The opacity of the polygon's corner points, where ``1.0`` denotes
            completely visible corners and ``0.0`` invisible ones.
            If this is ``None``, it will be derived from ``alpha * 1.0``.

        size : int, optional
            Size of the polygon.
            The sizes of the line and points are derived from this value,
            unless they are set.

        size_lines : None or int, optional
            Thickness of the polygon's line (aka perimeter/border).
            If ``None``, this value is derived from `size`.

        size_points : int, optional
            Size of the points in pixels.
            If ``None``, this value is derived from ``3 * size``.

        raise_if_out_of_image : bool, optional
            Whether to raise an error if the polygon is fully
            outside of the image. If set to ``False``, no error will be
            raised and only the parts inside the image will be drawn.

        Returns
        -------
        (H,W,C) ndarray
            Image with the polygon drawn on it. Result dtype is the same as the
            input dtype.

        c                 ó6   — |€J d| ›dt        |«      ›d�«       ‚y )Nz
Expected 'z' to not be None, got type Ú.)rœ   )Úarg_nameÚ	arg_values     r!   Ú_assert_not_nonez/Polygon.draw_on_image.<locals>._assert_not_none2  s#   € ØÐ(ñ 1âœd 9�oð0ó1Ñ(r#   c                 ó   — | €|S | S ©N© )ÚvarÚdefaults     r!   Ú_default_toz*Polygon.draw_on_image.<locals>._default_to7  s   € Øˆ{Ø�ØˆJr#   ÚcolorÚalphaÚsizeg      à?rO   r   zJGot a 2D image. Expected then 'color_face' to be a single number, but got r½   r,   ç{®Gáz„?r   g®Gáz®ï?r	   zCannot draw polygon z on image with shape ©r6   NFrŒ   T)rÇ   rÈ   rÉ   Úraise_if_out_of_imageéÿ   )r.   Úarrayr5   r3   Úis_single_numberÚstrr6   r~   r„   r+   Úastyper0   ÚskimageÚdrawr   rM   rJ   r7   rw   Údraw_lines_on_imageÚdraw_points_on_imagerœ   Úuint8ÚcliprI   )r:   rs   rÇ   Ú
color_faceÚcolor_linesÚcolor_pointsrÈ   Ú
alpha_faceÚalpha_linesÚalpha_pointsrÉ   Ú
size_linesÚsize_pointsrÌ   rÀ   rÆ   Úinput_dtypeÚresultÚrrÚccÚls_openÚ	ls_closeds                         r!   Údraw_on_imagezPolygon.draw_on_image×  sí  € òv	1ò
	ñ
 	˜ %Ô(Ù˜ %Ô(Ù˜ Ô&ñ ! ¬R¯X©X°e«_Ó=ˆ
Ù! +¬r¯x©x¸«ÀÑ/DÓEˆÙ" <´·±¸%³À3Ñ1FÓGˆá  ¨U°S©[Ó9ˆ
Ù! +¨uÓ5ˆÙ" <°Ó7ˆá  ¨TÓ2ˆ
Ù! +¨t°a©xÓ8ˆà�:‰:˜Š?Ü×&Ñ& zÔ2ñ <ä),¨Z­ð;ó<Ð2ð %˜‰JØ�Z‰Z˜1Š_¤×!4Ñ!4°ZÔ!@Ø$˜¨¯©°B©Ñ7ˆJà˜ÒØ‰JØ˜$ÒØˆJá  T×%9Ñ%9¸%Ô%@ÝÜ+.¨t­9°e·k³kðCó Dð Dð —k‘kˆØ—‘œbŸj™jÓ)ˆÜ—‘×%Ñ%Ø�K‰K˜Ÿ™¨E¯K©Kð &ó 9‰ˆˆBäˆr‹7�QŠ;Ø˜QŠÜ!#§¡¨JÓ!7��r˜2�v’Ø˜q’Øð ˜‘^ v¨b°"²a¨iÑ'8Ñ8Ø ¤2§:¡:¨jÓ#9Ñ9ñ:ð �r˜2�v‘ð
 ×%Ñ%¨UÐ%Ó3ˆØ×'Ñ'¨tÐ'Ó4ˆ	Ø×.Ñ.Ø˜+¨[ØÐ3Hð /ó Jˆð ×-Ñ-Ø˜,¨lØÐ4Ið .ó Kˆð ×ÑœrŸx™xÒ'ä—W‘WœRŸX™X fÓ-¨q°#Ó6×=Ñ=¸kÓJˆFð ˆð —]‘] ;Ó/ˆFàˆr#   c                 ó.  — |j                   dv sJ d|j                  ›d�«       ‚t        | j                  «      dk  rt	        d«      ‚| j                  «       }|j                  |«      }| j                  |dd¬«      r|S | j                  }| j                  }|t        j                  |«      z
  }|t        j                  |«      z
  }t        j                  |«      }t        j                  |«      }	t        j                  j                  ||||	f¬	«      \  }
}t        j                   ||	ft        j"                  ¬
«      }d||
|f<   |j                   dk(  r>t        j$                  |dd…dd…t        j&                  f   dd|j                  d   f«      }||z  S )aØ  Extract all image pixels within the polygon area.

        This method returns a rectangular image array. All pixels within
        that rectangle that do not belong to the polygon area will be filled
        with zeros (i.e. they will be black).
        The method will also zero-pad the image if the polygon is
        partially/fully outside of the image.

        Parameters
        ----------
        image : (H,W) ndarray or (H,W,C) ndarray
            The image from which to extract the pixels within the polygon.

        Returns
        -------
        (H',W') ndarray or (H',W',C) ndarray
            Pixels within the polygon. Zero-padded if the polygon is
            partially/fully outside of the image.

        )r   rO   z-Expected image of shape (H,W,[C]), got shape r½   r   zOPolygon must be made up of at least 3 points to extract its area from an image.TFrz   rË   r*   rO   Nr	   )r5   r6   r7   r   r„   Úto_bounding_boxÚextract_from_imager~   rJ   rM   r.   rX   rW   rÒ   rÓ   r   r/   ÚboolÚtileÚnewaxis)r:   rs   ÚbbÚbb_arearC   rF   Úxx_maskÚyy_maskÚheight_maskÚ
width_maskÚrr_faceÚcc_faceÚmasks                r!   ré   zPolygon.extract_from_image‹  sn  € ð* �z‰z˜VÑ#ñ 	à—“ðó	Ð#ô ˆt�}‰}Ó Ò"Üð >ó ?ð ?ð ×!Ñ!Ó#ˆØ×'Ñ'¨Ó.ˆØ×Ñ ¨T¸%ÐÔ@ØˆNà�[‰[ˆØ�[‰[ˆØ”r—v‘v˜b“z‘/ˆØ”r—v‘v˜b“z‘/ˆÜ—f‘f˜W“oˆÜ—V‘V˜G“_ˆ
ä"Ÿ<™<×/Ñ/Ø�W [°*Ð$=ð 0ó ?Ñˆ�ô �x‰x˜ jÐ1¼¿¹ÔAˆØ!%ˆˆW�gÐÑà�:‰:˜Š?Ü—7‘7˜4¢¢1¤b§j¡jÐ 0Ñ1°A°q¸%¿+¹+Àa¹.Ð3IÓJˆDà˜‰~Ðr#   c                 ó  — t        | j                  «      dk(  rt        d«      ‚| j                  ||d¬«      \  }}|�A||kD  r<|s| j	                  «       S | j                  |dd…f   }t        d|d   |d   |fz  «      ‚| j                  |«      S )a4  
        Reorder exterior points so that the point closest to given x/y is first.

        This method takes a given ``(x,y)`` coordinate, finds the closest
        corner point on the exterior and reorders all exterior corner points
        so that the found point becomes the first one in the array.

        If no matching points are found, an exception is raised.

        Parameters
        ----------
        x : number
            X-coordinate of the point.

        y : number
            Y-coordinate of the point.

        max_distance : None or number, optional
            Maximum distance past which possible matches are ignored.
            If ``None`` the distance limit is deactivated.

        raise_if_too_far_away : bool, optional
            Whether to raise an exception if the closest found point is too
            far away (``True``) or simply return an unchanged copy if this
            object (``False``).

        Returns
        -------
        imgaug.augmentables.polys.Polygon
            Copy of this polygon with the new point order.

        r   z=Cannot reorder polygon points, because it contains no points.Tr�   NzFClosest found point (%.9f, %.9f) exceeds max_distance of %.9f exceededr	   )r7   r   r„   ro   rc   rŸ   )r:   r1   r2   Úmax_distanceÚraise_if_too_far_awayrn   Úclosest_distÚclosest_points           r!   Úchange_first_point_by_coordsz$Polygon.change_first_point_by_coords¿  s¾   € ôD ˆt�}‰}Ó Ò"Üð 2ó 3ð 3ð %)×$AÑ$AØ�1 dð %Bó %,Ñ!ˆ�\àÐ#¨°|Ò(CÙ(Ø—}‘}“Ð&à ŸM™M¨+²q¨.Ñ9ˆMÜð à! !Ñ$ m°AÑ&6¸ð#FñFóGð Gð ×/Ñ/°Ó<Ð<r#   c                 óL  — d|cxk  rt        | j                  «      k  s!n J dt        | j                  «      |fz  «       ‚|dk(  r| j                  «       S t        j                  | j                  |d…dd…f   | j                  d|…dd…f   fd¬«      }| j                  |¬«      S )a†  
        Reorder exterior points so that the point with given index is first.

        This method takes a given index and reorders all exterior corner points
        so that the point with that index becomes the first one in the array.

        An ``AssertionError`` will be raised if the index does not match
        any exterior point's index or the exterior does not contain any points.

        Parameters
        ----------
        point_idx : int
            Index of the desired starting point.

        Returns
        -------
        imgaug.augmentables.polys.Polygon
            Copy of this polygon with the new point order.

        r   zWExpected index of new first point to be in the discrete interval [0..%d). Got index %d.N©Úaxisr?   )r7   r   rc   r.   Úconcatenate)r:   r¬   r   s      r!   rŸ   z#Polygon.change_first_point_by_indexò  s¦   € ð* �IÔ2¤ D§M¡MÓ 2Ô2ð 	Hð%Ü(+¨D¯M©MÓ(:¸IÐ'FñGó	HÐ2ð ˜Š>Ø—=‘=“?Ð"Ü—>‘>Ø�]‰]˜9™:¢q˜=Ñ)¨4¯=©=¸¸)¸ÂQ¸Ñ+GÐHØô
ˆð �}‰} hˆ}Ó/Ð/r#   c                 ó¬   — t        | j                  «      dk(  r| S | j                  d¬«      }|j                  |«      }|j                  dd }|| _        | S )aå  Derive a new poly with ``N`` interpolated points per edge in-place.

        See :func:`~imgaug.augmentables.lines.LineString.subdivide` for details.

        Added in 0.4.0.

        Parameters
        ----------
        points_per_edge : int
            Number of points to interpolate on each edge.

        Returns
        -------
        imgaug.augmentables.polys.Polygon
            Polygon with subdivided edges.
            The object may have been modified in-place.

        r	   TrŒ   Nr,   )r7   r   rw   Ú	subdividerA   )r:   Úpoints_per_edger…   Úls_subÚexterior_subdivideds        r!   Ú
subdivide_zPolygon.subdivide_  sX   € ô& ˆt�}‰}Ó Ò"ØˆKØ× Ñ ¨Ð Ó-ˆØ—‘˜oÓ.ˆà$Ÿm™m¨C¨RÐ0ÐØ+ˆŒØˆr#   c                 ó@   — | j                  «       j                  |«      S )a§  Derive a new polygon with ``N`` interpolated points per edge.

        See :func:`~imgaug.augmentables.lines.LineString.subdivide` for details.

        Added in 0.4.0.

        Parameters
        ----------
        points_per_edge : int
            Number of points to interpolate on each edge.

        Returns
        -------
        imgaug.augmentables.polys.Polygon
            Polygon with subdivided edges.

        ©rc   r  ©r:   r  s     r!   r  zPolygon.subdivide/  s   € ð$ �}‰}‹×)Ñ)¨/Ó:Ð:r#   c                 óŠ   — ddl }|j                  j                  | j                  D �cg c]  }|d   |d   f‘Œ c}«      S c c}w )zÈConvert this polygon to a ``Shapely`` ``Polygon``.

        Returns
        -------
        shapely.geometry.Polygon
            The ``Shapely`` ``Polygon`` matching this polygon's exterior.

        r   Nr	   )r‘   r’   r%   r   )r:   r    r;   s      r!   rP   zPolygon.to_shapely_polygonC  sF   € ó 	 à×Ñ×'Ñ'Ø/3¯}ª}Ó=©} eˆe�A‰h˜˜a™Ò!¨}Ñ=ó?ð 	?ùÚ=s   ¨A c                 ó2   — t        | j                  ||¬«      S )aJ  Convert this polygon to a ``Shapely`` ``LineString`` object.

        Parameters
        ----------
        closed : bool, optional
            Whether to return the line string with the last point being
            identical to the first point.

        interpolate : int, optional
            Number of points to interpolate between any pair of two
            consecutive points. These points are added to the final line string.

        Returns
        -------
        shapely.geometry.LineString
            The ``Shapely`` ``LineString`` matching the polygon's exterior.

        )r�   Úinterpolate)Ú&_convert_points_to_shapely_line_stringr   )r:   r�   r  s      r!   Úto_shapely_line_stringzPolygon.to_shapely_line_stringR  s   € ô& 6Ø�M‰M &°kôCð 	Cr#   c                 ó´   — ddl m} | j                  }| j                  } |t	        |«      t        |«      t	        |«      t        |«      | j                  ¬«      S )zÕConvert this polygon to a bounding box containing the polygon.

        Returns
        -------
        imgaug.augmentables.bbs.BoundingBox
            Bounding box that tightly encapsulates the polygon.

        r   )ÚBoundingBox)Úx1rk   Úy1rl   r9   )Úimgaug.augmentables.bbsr  rC   rF   rX   rW   r9   )r:   r  rC   rF   s       r!   rè   zPolygon.to_bounding_boxh  sF   € õ 	8à�W‰WˆØ�W‰WˆÙœc "›g¬#¨b«'Ü! "›g¬#¨b«'Ø!%§¡ô-ð 	-r#   c                 óh   — ddl m} | j                  D �cg c]  } ||d   |d   ¬«      ‘Œ c}S c c}w )zùConvert this polygon's exterior to ``Keypoint`` instances.

        Returns
        -------
        list of imgaug.augmentables.kps.Keypoint
            Exterior vertices as :class:`~imgaug.augmentables.kps.Keypoint`
            instances.

        r   r'   r	   r¶   )r-   r(   r   )r:   r(   r;   s      r!   Úto_keypointszPolygon.to_keypointsz  s2   € õ 	5à>B¿mºmÓL¹m°U‘˜5 ™8 u¨Q¡xÖ0¸mÑLÐLùÒLs   •/c           	      ó  — ddl m} |rt        | j                  «      dk  r || j                  | j                  ¬«      S  |t        j                  | j                  | j                  dd…dd…f   gd¬«      | j                  ¬«      S )a  Convert this polygon's exterior to a ``LineString`` instance.

        Parameters
        ----------
        closed : bool, optional
            Whether to close the line string, i.e. to add the first point of
            the `exterior` also as the last point at the end of the line string.
            This has no effect if the polygon has a single point or zero
            points.

        Returns
        -------
        imgaug.augmentables.lines.LineString
            Exterior of the polygon as a line string.

        r   )r”   r	   r�   Nrý   )Úimgaug.augmentables.linesr”   r7   r   r9   r.   rÿ   )r:   r�   r”   s      r!   rw   zPolygon.to_line_string‰  sk   € õ" 	9Ùœ˜TŸ]™]Ó+¨qÒ0Ù˜dŸm™m°4·:±:Ô>Ð>ÙÜ�N‰N˜DŸM™M¨4¯=©=¸¸1¸ºa¸Ñ+@ÐAÈÔJØ—*‘*ôð 	r#   c                 ó–  — ddl }t        | |j                  j                  «      sJ dt	        | «      ›d�«       ‚| j
                  du xs" t        | j
                  j                  «      dk(  }|rt        g |¬«      S t        j                  | j
                  j                  D ��cg c]	  \  }}||g‘Œ c}}«      }t        ||¬«      S c c}}w )aò  Create a polygon from a ``Shapely`` ``Polygon``.

        .. note::

            This will remove any holes in the shapely polygon.

        Parameters
        ----------
        polygon_shapely : shapely.geometry.Polygon
             The shapely polygon.

        label : None or str, optional
            The label of the new polygon.

        Returns
        -------
        imgaug.augmentables.polys.Polygon
            A polygon with the same exterior as the ``Shapely`` ``Polygon``.

        r   NzAExpected the input to be a shapely.geometry.Polgon instance. Got r½   r�   )
r‘   r   r’   r%   rœ   r   r7   rA   r.   r0   )Úpolygon_shapelyr9   r    Úhas_no_exteriorr1   r2   r   s          r!   rž   zPolygon.from_shapely¡  sÔ   € ó. 	 ä˜/¨7×+;Ñ+;×+CÑ+CÔDñ 	2ä˜oÕ.ð1ó	2ÐDð ×$Ñ$¨Ð,ò 9Ü�?×+Ñ+×2Ñ2Ó3°qÑ8ð 	ñ Ü˜2 UÔ+Ð+Ü—:‘:à"1×":Ñ":×"AÒ"AôCá"Añ $* A qð !" 1švà"AòCó Dˆô �x uÔ-Ð-ùóCs   Â"C
c                 ó*   — | j                  |||¬«      S )aº  Alias for :func:`Polygon.exterior_almost_equals`.

        Parameters
        ----------
        other : imgaug.augmentables.polys.Polygon or (N,2) ndarray or list of tuple
            See
            :func:`~imgaug.augmentables.polys.Polygon.exterior_almost_equals`.

        max_distance : number, optional
            See
            :func:`~imgaug.augmentables.polys.Polygon.exterior_almost_equals`.

        points_per_edge : int, optional
            See
            :func:`~imgaug.augmentables.polys.Polygon.exterior_almost_equals`.

        Returns
        -------
        bool
            Whether the two polygon's exteriors can be viewed as equal
            (approximate test).

        ©r÷   r  )Úexterior_almost_equals©r:   Úotherr÷   r  s       r!   Úcoords_almost_equalszPolygon.coords_almost_equalsÉ  s%   € ð2 ×*Ñ*Ø ¸oð +ó Oð 	Or#   c                 óR  — t        |t        «      rt        t        j                  |«      «      }nEt        j                  |«      rt        |«      }n$t        |t        «      sJ dt        |«      ›d�«       ‚| j                  d¬«      j                  |j                  d¬«      ||¬«      S )a”  Estimate if this and another polygon's exterior are almost identical.

        The two exteriors can have different numbers of points, but any point
        randomly sampled on the exterior of one polygon should be close to the
        closest point on the exterior of the other polygon.

        .. note::

            This method works in an approximative way. One can come up with
            polygons with fairly different shapes that will still be estimated
            as equal by this method. In practice however this should be
            unlikely to be the case. The probability for something like that
            goes down as the interpolation parameter is increased.

        Parameters
        ----------
        other : imgaug.augmentables.polys.Polygon or (N,2) ndarray or list of tuple
            The other polygon with which to compare the exterior.
            If this is an ``ndarray``, it is assumed to represent an exterior.
            It must then have dtype ``float32`` and shape ``(N,2)`` with the
            second dimension denoting xy-coordinates.
            If this is a ``list`` of ``tuple`` s, it is assumed to represent
            an exterior. Each tuple then must contain exactly two ``number`` s,
            denoting xy-coordinates.

        max_distance : number, optional
            The maximum euclidean distance between a point on one polygon and
            the closest point on the other polygon. If the distance is exceeded
            for any such pair, the two exteriors are not viewed as equal. The
            points are either the points contained in the polygon's exterior
            ndarray or interpolated points between these.

        points_per_edge : int, optional
            How many points to interpolate on each edge.

        Returns
        -------
        bool
            Whether the two polygon's exteriors can be viewed as equal
            (approximate test).

        z_Expected 'other' to be a list of coordinates, a coordinate array or a single Polygon. Got type r½   TrŒ   r  )
r   r   r%   r.   r0   r3   r4   rœ   rw   r  r  s       r!   r  zPolygon.exterior_almost_equalså  s�   € ôX �eœTÔ"ÜœBŸJ™J uÓ-Ó.‰EÜ�^‰^˜EÔ"Ü˜E“N‰Eä˜e¤WÔ-ñ Lä=AÀ%½[ðKóLÐ-ð ×"Ñ"¨$Ð"Ó/×DÑDØ× Ñ ¨Ð Ó-Ø%Ø+ð Eó 
ð 	
r#   c                 ó^   — | j                   |j                   k7  ry| j                  |||¬«      S )aS  
        Estimate if this polygon's and another's geometry/labels are similar.

        This is the same as
        :func:`~imgaug.augmentables.polys.Polygon.exterior_almost_equals` but
        additionally compares the labels.

        Parameters
        ----------
        other : imgaug.augmentables.polys.Polygon
            The other object to compare against. Expected to be a ``Polygon``.

        max_distance : float, optional
            See
            :func:`~imgaug.augmentables.polys.Polygon.exterior_almost_equals`.

        points_per_edge : int, optional
            See
            :func:`~imgaug.augmentables.polys.Polygon.exterior_almost_equals`.

        Returns
        -------
        bool
            ``True`` if the coordinates are almost equal and additionally
            the labels are equal. Otherwise ``False``.

        Fr  )r9   r  r  s       r!   Úalmost_equalszPolygon.almost_equals   s8   € ð8 �:‰:˜Ÿ™Ò$ØØ×*Ñ*Ø ¸oð +ó Oð 	Or#   c                 ó(   — | j                  ||¬«      S )a3  Create a shallow copy of this object.

        Parameters
        ----------
        exterior : list of imgaug.augmentables.kps.Keypoint or list of tuple or (N,2) ndarray, optional
            List of points defining the polygon. See
            :func:`~imgaug.augmentables.polys.Polygon.__init__` for details.

        label : None or str, optional
            If not ``None``, the ``label`` of the copied object will be set
            to this value.

        Returns
        -------
        imgaug.augmentables.polys.Polygon
            Shallow copy.

        ©r   r9   )rc   ©r:   r   r9   s      r!   ÚcopyzPolygon.copyA  s   € ð& �}‰} h°eˆ}Ó<Ð<r#   c                 ó„   — t        |€t        j                  | j                  «      n||€| j                  ¬«      S |¬«      S )a  Create a deep copy of this object.

        Parameters
        ----------
        exterior : list of Keypoint or list of tuple or (N,2) ndarray, optional
            List of points defining the polygon. See
            `imgaug.augmentables.polys.Polygon.__init__` for details.

        label : None or str
            If not ``None``, the ``label`` of the copied object will be set
            to this value.

        Returns
        -------
        imgaug.augmentables.polys.Polygon
            Deep copy.

        r$  )r%   r.   r&  r   r9   r%  s      r!   rc   zPolygon.deepcopyV  s@   € ô& Ø/7Ð/?”R—W‘W˜TŸ]™]Ô+ÀXØ % �$—*‘*ô:ð 	:à38ô:ð 	:r#   c                 ó    — | j                   |   S )zªGet the coordinate(s) with given indices.

        Added in 0.4.0.

        Returns
        -------
        ndarray
            xy-coordinate(s) as ``ndarray``.

        r?   ©r:   Úindicess     r!   Ú__getitem__zPolygon.__getitem__m  ó   € ð �}‰}˜WÑ%Ð%r#   c                 ó,   — t        | j                  «      S )zÄIterate over the coordinates of this instance.

        Added in 0.4.0.

        Yields
        ------
        ndarray
            An ``(2,)`` ``ndarray`` denoting an xy-coordinate pair.

        )Úiterr   r@   s    r!   Ú__iter__zPolygon.__iter__z  s   € ô �D—M‘MÓ"Ð"r#   c                 ó"   — | j                  «       S rÂ   ©Ú__str__r@   s    r!   Ú__repr__zPolygon.__repr__‡  ó   € Ø�|‰|‹~Ðr#   c           	      ó¾   — dj                  | j                  D �cg c]  }d|d   |d   fz  ‘Œ c}«      }d|t        | j                  «      | j                  fz  S c c}w )Nú, z(x=%.3f, y=%.3f)r   r	   z#Polygon([%s] (%d points), label=%s))Újoinr   r7   r9   )r:   r;   Ú
points_strs      r!   r2  zPolygon.__str__Š  su   € Ø—Y‘Yð �}Š}ó ñ ð ð  %¨¡(¨E°!©HÐ!5Ó5àñ ó ˆ
ð 5Øœ˜DŸM™MÓ*¨D¯J©Jð88ñ 8ð 	8ùò	 s   šArÂ   )F©TFrŽ   ©r   r   NNNN©)r   rÍ   r   NNNç      ð?NNNr	   NNF)ç-Cëâ6?T©Fr   )T)r=  é   ©NN)3Ú__name__Ú
__module__Ú__qualname__Ú__doc__r=   ÚpropertyrA   rC   rF   rJ   rM   rQ   rS   rY   r\   ra   rd   ro   ru   rx   r€   r‚   r~   r3   Ú
deprecatedrŠ   rq   r¯   r¹   ræ   ré   rû   rŸ   r  r  rP   r  rè   r  rw   Ústaticmethodrž   r  r  r"  r&  rc   r+  r/  r3  r2  rÃ   r#   r!   r%   r%   M   sÙ  „ ñó.)ðV ñó ðð ñ	#ó ð	#ð ñ	#ó ð	#ð ñ+ó ð+ð ñ+ó ð+ð ñ2ó ð2ð& ñó ðð ñ!ó ð!ð ñ!ó ð!òò>>ó6(òTFò2<òDHò*Ió(6ðp €R‡]�]Ð9ð(ô)ñ-ó)ð-òg"óRó8+0ðb 59Ø59Ø,0Ø59Ø;?Ø,1óoòh2ðh ?CØ;?ó1=òf0òBò8;ò(?óCò,-ò$Móð0 ò%.ó ð%.ðN 8<Ø-.óOð8 :>Ø/0ó9
óvOóB=ó*:ò.&ò#òó8r#   r%   c                   ó  — e Zd ZdZd„ Zed„ «       Zej                  d„ «       Zed„ «       Zd„ Z	d„ Z
	 	 	 	 	 	 dd	„Zd d
„Zd d„Zd„ Zd„ Zd„ Zd„ Zd!d„Zd"d„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd#d„Zd#d„Zd„ Zd„ Zd„ Zd„ Zd„ Z y)$ÚPolygonsOnImagea  Container for all polygons on a single image.

    Parameters
    ----------
    polygons : list of imgaug.augmentables.polys.Polygon
        List of polygons on the image.

    shape : tuple of int or ndarray
        The shape of the image on which the objects are placed.
        Either an image with shape ``(H,W,[C])`` or a ``tuple`` denoting
        such an image shape.

    Examples
    --------
    >>> import numpy as np
    >>> from imgaug.augmentables.polys import Polygon, PolygonsOnImage
    >>> image = np.zeros((100, 100))
    >>> polys = [
    >>>     Polygon([(0.5, 0.5), (100.5, 0.5), (100.5, 100.5), (0.5, 100.5)]),
    >>>     Polygon([(50.5, 0.5), (100.5, 50.5), (50.5, 100.5), (0.5, 50.5)])
    >>> ]
    >>> polys_oi = PolygonsOnImage(polys, shape=image.shape)

    c                 ó2   — || _         t        |«      | _        y rÂ   )r   r   r6   ©r:   r   r6   s      r!   r=   zPolygonsOnImage.__init__®  s   € Ø ˆŒÜ$ UÓ+ˆ�
r#   c                 ó   — | j                   S )z«Get the polygons in this container.

        Added in 0.4.0.

        Returns
        -------
        list of Polygon
            Polygons within this container.

        ©r   r@   s    r!   ÚitemszPolygonsOnImage.items²  s   € ð �}‰}Ðr#   c                 ó   — || _         y)z¹Set the polygons in this container.

        Added in 0.4.0.

        Parameters
        ----------
        value : list of Polygon
            Polygons within this container.

        NrM  )r:   Úvalues     r!   rN  zPolygonsOnImage.itemsÀ  s   € ð ˆ�r#   c                 ó2   — t        | j                  «      dk(  S )z¨Estimate whether this object contains zero polygons.

        Returns
        -------
        bool
            ``True`` if this object contains zero polygons.

        r   )r7   r   r@   s    r!   ÚemptyzPolygonsOnImage.emptyÎ  s   € ô �4—=‘=Ó! QÑ&Ð&r#   c                 óò   — t        |«      }|dd | j                  dd k(  r	|| _        | S t        | j                  «      D ].  \  }}|j	                  | j                  |«      | j
                  |<   Œ0 || _        | S )a  Project all polygons from one image shape to a new one in-place.

        Added in 0.4.0.

        Parameters
        ----------
        image : ndarray or tuple of int
            New image onto which the polygons are to be projected.
            May also simply be that new image's shape ``tuple``.

        Returns
        -------
        imgaug.augmentables.polys.PolygonsOnImage
            Object containing all projected polygons.
            The object and its items may have been modified in-place.

        r   r   )r   r6   r   rN  ra   r   )r:   rs   Úon_shaper   Úitems        r!   Úon_zPolygonsOnImage.on_Ú  sr   € ô& # 5Ó)ˆØ�A�aˆ=˜DŸJ™J q¨˜OÒ+Ø!ˆDŒJØˆKä  §¡Ö,‰GˆAˆtØ#Ÿ}™}¨T¯Z©Z¸ÓBˆD�M‰M˜!Òð -àˆŒ
Øˆr#   c                 ó@   — | j                  «       j                  |«      S )a�  Project all polygons from one image shape to a new one.

        Parameters
        ----------
        image : ndarray or tuple of int
            New image onto which the polygons are to be projected.
            May also simply be that new image's shape ``tuple``.

        Returns
        -------
        imgaug.augmentables.polys.PolygonsOnImage
            Object containing all projected polygons.

        )rc   rV  r   s     r!   ÚonzPolygonsOnImage.on÷  s   € ð  �}‰}‹×"Ñ" 5Ó)Ð)r#   Nc                 ód   — | j                   D ]   }|j                  |||||||||	|
|||¬«      }Œ" |S )aQ  Draw all polygons onto a given image.

        Parameters
        ----------
        image : (H,W,C) ndarray
            The image onto which to draw the bounding boxes.
            This image should usually have the same shape as set in
            ``PolygonsOnImage.shape``.

        color : iterable of int, optional
            The color to use for the whole polygons.
            Must correspond to the channel layout of the image. Usually RGB.
            The values for `color_face`, `color_lines` and `color_points`
            will be derived from this color if they are set to ``None``.
            This argument has no effect if `color_face`, `color_lines`
            and `color_points` are all set anything other than ``None``.

        color_face : None or iterable of int, optional
            The color to use for the inner polygon areas (excluding perimeters).
            Must correspond to the channel layout of the image. Usually RGB.
            If this is ``None``, it will be derived from ``color * 1.0``.

        color_lines : None or iterable of int, optional
            The color to use for the lines (aka perimeters/borders) of the
            polygons. Must correspond to the channel layout of the image.
            Usually RGB. If this is ``None``, it will be derived
            from ``color * 0.5``.

        color_points : None or iterable of int, optional
            The color to use for the corner points of the polygons.
            Must correspond to the channel layout of the image. Usually RGB.
            If this is ``None``, it will be derived from ``color * 0.5``.

        alpha : float, optional
            The opacity of the whole polygons, where ``1.0`` denotes
            completely visible polygons and ``0.0`` invisible ones.
            The values for `alpha_face`, `alpha_lines` and `alpha_points`
            will be derived from this alpha value if they are set to ``None``.
            This argument has no effect if `alpha_face`, `alpha_lines`
            and `alpha_points` are all set anything other than ``None``.

        alpha_face : None or number, optional
            The opacity of the polygon's inner areas (excluding the perimeters),
            where ``1.0`` denotes completely visible inner areas and ``0.0``
            invisible ones.
            If this is ``None``, it will be derived from ``alpha * 0.5``.

        alpha_lines : None or number, optional
            The opacity of the polygon's lines (aka perimeters/borders),
            where ``1.0`` denotes completely visible perimeters and ``0.0``
            invisible ones.
            If this is ``None``, it will be derived from ``alpha * 1.0``.

        alpha_points : None or number, optional
            The opacity of the polygon's corner points, where ``1.0`` denotes
            completely visible corners and ``0.0`` invisible ones.
            Currently this is an on/off choice, i.e. only ``0.0`` or ``1.0``
            are allowed.
            If this is ``None``, it will be derived from ``alpha * 1.0``.

        size : int, optional
            Size of the polygons.
            The sizes of the line and points are derived from this value,
            unless they are set.

        size_lines : None or int, optional
            Thickness of the polygon lines (aka perimeter/border).
            If ``None``, this value is derived from `size`.

        size_points : int, optional
            The size of all corner points. If set to ``C``, each corner point
            will be drawn as a square of size ``C x C``.

        raise_if_out_of_image : bool, optional
            Whether to raise an error if any polygon is fully
            outside of the image. If set to False, no error will be raised and
            only the parts inside the image will be drawn.

        Returns
        -------
        (H,W,C) ndarray
            Image with drawn polygons.

        )rÇ   rØ   rÙ   rÚ   rÈ   rÛ   rÜ   rÝ   rÉ   rÞ   rß   rÌ   )r   ræ   )r:   rs   rÇ   rØ   rÙ   rÚ   rÈ   rÛ   rÜ   rÝ   rÉ   rÞ   rß   rÌ   rU   s                  r!   ræ   zPolygonsOnImage.draw_on_image	  sV   € ðx —M”MˆDØ×&Ñ&ØØØ%Ø'Ø)ØØ%Ø'Ø)ØØ%Ø'Ø&;ð 'ó ‰Eð "ð  ˆr#   c                 óŠ   — | j                   D �cg c]"  }|j                  | j                  ||¬«      s|‘Œ$ c}| _         | S c c}w )a®  Remove all polygons that are fully/partially OOI in-place.

        'OOI' is the abbreviation for 'out of image'.

        Added in 0.4.0.

        Parameters
        ----------
        fully : bool, optional
            Whether to remove polygons that are fully outside of the image.

        partly : bool, optional
            Whether to remove polygons that are partially outside of the image.

        Returns
        -------
        imgaug.augmentables.polys.PolygonsOnImage
            Reduced set of polygons. Those that are fully/partially
            outside of the given image plane are removed.
            The object and its items may have been modified in-place.

        rz   )r   r~   r6   )r:   r{   r|   rU   s       r!   Úremove_out_of_image_z$PolygonsOnImage.remove_out_of_image_w  sK   € ð0 "Ÿ]š]ó
Ù*�TØ×'Ñ'¨¯
©
¸%ÈÐ'ÔOò ˜]ñ
ˆŒð ˆùò	
s   �'A c                 óB   — | j                  «       j                  ||«      S )a  Remove all polygons that are fully/partially outside of an image.

        Parameters
        ----------
        fully : bool, optional
            Whether to remove polygons that are fully outside of the image.

        partly : bool, optional
            Whether to remove polygons that are partially outside of the image.

        Returns
        -------
        imgaug.augmentables.polys.PolygonsOnImage
            Reduced set of polygons. Those that are fully/partially
            outside of the given image plane are removed.

        )rc   r[  )r:   r{   r|   s      r!   Úremove_out_of_imagez#PolygonsOnImage.remove_out_of_image”  s   € ð$ �}‰}‹×3Ñ3°E¸6ÓBÐBr#   c                 ó   — t        | |«      S )aÅ  Remove all Polys with an OOI fraction of ``>=fraction`` in-place.

        Added in 0.4.0.

        Parameters
        ----------
        fraction : number
            Minimum out of image fraction that a polygon has to have in
            order to be removed. A fraction of ``1.0`` removes only polygons
            that are ``100%`` outside of the image. A fraction of ``0.0``
            removes all polygons.

        Returns
        -------
        imgaug.augmentables.polys.PolygonsOnImage
            Reduced set of polygons, with those that had an out of image
            fraction greater or equal the given one removed.
            The object and its items may have been modified in-place.

        )r   ©r:   Úfractions     r!   Úremove_out_of_image_fraction_z-PolygonsOnImage.remove_out_of_image_fraction_¨  s   € ô* .¨d°HÓ=Ð=r#   c                 ó@   — | j                  «       j                  |«      S )a  Remove all Polys with an out of image fraction of ``>=fraction``.

        Added in 0.4.0.

        Parameters
        ----------
        fraction : number
            Minimum out of image fraction that a polygon has to have in
            order to be removed. A fraction of ``1.0`` removes only polygons
            that are ``100%`` outside of the image. A fraction of ``0.0``
            removes all polygons.

        Returns
        -------
        imgaug.augmentables.polys.PolygonsOnImage
            Reduced set of polygons, with those that had an out of image
            fraction greater or equal the given one removed.

        )r&  ra  r_  s     r!   Úremove_out_of_image_fractionz,PolygonsOnImage.remove_out_of_image_fraction¿  s   € ð( �y‰y‹{×8Ñ8¸ÓBÐBr#   c                 ó”   — | j                   D ��cg c]$  }|j                  | j                  «      D ]  }|‘Œ Œ& c}}| _         | S c c}}w )aÔ  Clip off all parts from all polygons that are OOI in-place.

        'OOI' is the abbreviation for 'out of image'.

        .. note::

            The result can contain fewer polygons than the input did. That
            happens when a polygon is fully outside of the image plane.

        .. note::

            The result can also contain *more* polygons than the input
            did. That happens when distinct parts of a polygon are only
            connected by areas that are outside of the image plane and hence
            will be clipped off, resulting in two or more unconnected polygon
            parts that are left in the image plane.

        Added in 0.4.0.

        Returns
        -------
        imgaug.augmentables.polys.PolygonsOnImage
            Polygons, clipped to fall within the image dimensions.
            The count of output polygons may differ from the input count.
            The object and its items may have been modified in-place.

        )r   rq   r6   )r:   rU   Úpoly_clippeds      r!   Úclip_out_of_image_z"PolygonsOnImage.clip_out_of_image_Õ  sR   € ð< ŸšôDá%�Ø $× 6Ñ 6°t·z±zÖ B�ò à Bð Ø%òDˆŒð ˆùó	Ds   �)Ac                 ó>   — | j                  «       j                  «       S )aE  Clip off all parts from all polygons that are outside of an image.

        .. note::

            The result can contain fewer polygons than the input did. That
            happens when a polygon is fully outside of the image plane.

        .. note::

            The result can also contain *more* polygons than the input
            did. That happens when distinct parts of a polygon are only
            connected by areas that are outside of the image plane and hence
            will be clipped off, resulting in two or more unconnected polygon
            parts that are left in the image plane.

        Returns
        -------
        imgaug.augmentables.polys.PolygonsOnImage
            Polygons, clipped to fall within the image dimensions.
            The count of output polygons may differ from the input count.

        )r&  rf  r@   s    r!   rq   z!PolygonsOnImage.clip_out_of_image÷  s   € ð. �y‰y‹{×-Ñ-Ó/Ð/r#   c                 ó€   — t        | j                  «      D ]%  \  }}|j                  ||¬«      | j                  |<   Œ' | S )aE  Move the polygons along the x/y-axis in-place.

        The origin ``(0, 0)`` is at the top left of the image.

        Added in 0.4.0.

        Parameters
        ----------
        x : number, optional
            Value to be added to all x-coordinates. Positive values shift
            towards the right images.

        y : number, optional
            Value to be added to all y-coordinates. Positive values shift
            towards the bottom images.

        Returns
        -------
        imgaug.augmentables.polys.PolygonsOnImage
            Shifted polygons.

        r¶   )r   r   r¯   )r:   r1   r2   r   rU   s        r!   r¯   zPolygonsOnImage.shift_  s;   € ô. ! §¡Ö/‰GˆAˆtØ#Ÿ{™{¨Q°!˜{Ó4ˆD�M‰M˜!Òð 0àˆr#   c                 ól   — t        ||||||¬«      \  }}| j                  «       j                  ||¬«      S )aü  Move the polygons along the x/y-axis.

        The origin ``(0, 0)`` is at the top left of the image.

        Parameters
        ----------
        x : number, optional
            Value to be added to all x-coordinates. Positive values shift
            towards the right images.

        y : number, optional
            Value to be added to all y-coordinates. Positive values shift
            towards the bottom images.

        top : None or int, optional
            Deprecated since 0.4.0.
            Amount of pixels by which to shift all objects *from* the
            top (towards the bottom).

        right : None or int, optional
            Deprecated since 0.4.0.
            Amount of pixels by which to shift all objects *from* the
            right (towads the left).

        bottom : None or int, optional
            Deprecated since 0.4.0.
            Amount of pixels by which to shift all objects *from* the
            bottom (towards the top).

        left : None or int, optional
            Deprecated since 0.4.0.
            Amount of pixels by which to shift all objects *from* the
            left (towards the right).

        Returns
        -------
        imgaug.augmentables.polys.PolygonsOnImage
            Shifted polygons.

        r±   r¶   r·   r¸   s          r!   r¹   zPolygonsOnImage.shift+  rº   r#   c                 ó|   — t        | j                  «      D ]#  \  }}|j                  |«      | j                  |<   Œ% | S ©a?  Interpolate ``N`` points on each polygon.

        Added in 0.4.0.

        Parameters
        ----------
        points_per_edge : int
            Number of points to interpolate on each edge.

        Returns
        -------
        imgaug.augmentables.polys.PolygonsOnImage
            Subdivided polygons.

        )r   r   r  )r:   r  r   rU   s       r!   r  zPolygonsOnImage.subdivide_X  s7   € ô  ! §¡Ö/‰GˆAˆtØ#Ÿ™¨Ó?ˆD�M‰M˜!Òð 0àˆr#   c                 ó@   — | j                  «       j                  |«      S rk  r  r  s     r!   r  zPolygonsOnImage.subdividel  s   € ð  �}‰}‹×)Ñ)¨/Ó:Ð:r#   c                 óÜ   — | j                   r%t        j                  dt        j                  ¬«      S t        j                  | j
                  D �cg c]  }|j                  ‘Œ c}«      S c c}w )zýConvert all polygon coordinates to one array of shape ``(N,2)``.

        Added in 0.4.0.

        Returns
        -------
        (N, 2) ndarray
            Array containing all xy-coordinates of all polygons within this
            instance.

        r)   r*   )rR  r.   r/   r0   rÿ   r   r   rT   s     r!   Úto_xy_arrayzPolygonsOnImage.to_xy_array~  sI   € ð �:Š:Ü—8‘8˜F¬"¯*©*Ô5Ð5Ü�~‰~¸¿ºÓG¹°˜tŸ}›}¸ÑGÓHÐHùÒGs   ÁA)c                 óp  — t        j                  |t         j                  ¬«      }|j                  d   dk(  s6|j                  dk(  r|j                  d   dk(  sJ d|j                  ›d�«       ‚d}| j
                  D ]�  }t        |j                  «      }||z   t        |«      k  sIJ dt        |«      t        | j
                  D �cg c]  }t        |j                  «      ‘Œ c}«      fz  «       ‚||||z    |j                  dd…d	f<   ||z  }Œ‘ |t        |«      k(  sJ d
t        |«      |fz  «       ‚| S c c}w )aÐ  Modify the corner coordinates of all polygons in-place.

        .. note::

            This currently expects that `xy` contains exactly as many
            coordinates as the polygons within this instance have corner
            points. Otherwise, an ``AssertionError`` will be raised.

        .. warning::

            This does not validate the new coordinates or repair the resulting
            polygons. If bad coordinates are provided, the result will be
            invalid polygons (e.g. self-intersections).

        Added in 0.4.0.

        Parameters
        ----------
        xy : (N, 2) ndarray or iterable of iterable of number
            XY-Coordinates of ``N`` corner points. ``N`` must match the
            number of corner points in all polygons within this instance.

        Returns
        -------
        PolygonsOnImage
            This instance itself, with updated coordinates.
            Note that the instance was modified in-place.

        r*   r   r   r,   z4Expected input array to have shape (N,2), got shape r½   zpReceived fewer points than there are corner points in the exteriors of all polygons. Got %d points, expected %d.N.z¥Expected to get exactly as many xy-coordinates as there are points in the exteriors of all polygons within this instance. Got %d points, could only assign %d points.)	r.   rÎ   r0   r6   r5   r   r7   r   rr   )r:   ÚxyÚcounterrU   Ú	nb_pointsÚps         r!   Úfill_from_xy_array_z#PolygonsOnImage.fill_from_xy_array_Ž  sG  € ô< �X‰X�b¤§
¡
Ô+ˆð �x‰x˜‰{˜aÒ B§G¡G¨q¢L°R·X±X¸b±\ÀQÒ5Fñ 	+à!Ÿx›xð*ó	+ÐGð ˆØ—M”MˆDÜ˜DŸM™MÓ*ˆIØ˜YÑ&¬#¨b«'Ò1ð MðIä˜“GœS¸4¿=º=Ó!I¹=°a¤# a§j¡j¥/¸=Ñ!IÓJðLLñLóMÐ1ð
 %' w¨w°yÑ/@Ð$AˆD�M‰Mš!˜S˜&Ñ!Ø�yÑ ‰Gð "ð œ#˜b›'Ò!ð 	$ð:ô �B“˜ð=#ñ#ó	$Ð!ð ˆùò "Js   ÃD3c                 ó  — ddl m} | j                  r |g | j                  ¬«      S t	        j
                  | j                  D �cg c]  }|j                  ‘Œ c}d¬«      }|j                  || j                  ¬«      S c c}w )a‚  Convert the polygons to one ``KeypointsOnImage`` instance.

        Added in 0.4.0.

        Returns
        -------
        imgaug.augmentables.kps.KeypointsOnImage
            A keypoints instance containing ``N`` coordinates for a total
            of ``N`` points in all exteriors of the polygons within this
            container. Order matches the order in ``polygons``.

        r	   )ÚKeypointsOnImagerË   r   rý   )	Ú rv  rR  r6   r.   rÿ   r   r   Úfrom_xy_array)r:   rv  rU   Ú	exteriorss       r!   Úto_keypoints_on_imagez%PolygonsOnImage.to_keypoints_on_imageÆ  sk   € õ 	'Ø�:Š:Ù# B¨d¯j©jÔ9Ð9Ü—N‘NØ'+§}¢}Ó5¡}˜tˆT�]‹] }Ñ5Øôˆ	ð  ×-Ñ-¨i¸t¿z¹zÐ-ÓJÐJùò 6s   ÁA=c                 óÞ  — | j                   }|D �cg c]  }|j                  ‘Œ }}t        |D �cg c]  }t        |«      ‘Œ c}«      }t        |j                  «      |k(  sJ d|t        |j                  «      fz  «       ‚|j                  «       }d}|D ]<  }|j                  }|||t        |«      z   …dd…f   |dd…dd…f<   |t        |«      z  }Œ> |j                  | _        | S c c}w c c}w )a4  Invert the output of ``to_keypoints_on_image()`` in-place.

        This function writes in-place into this ``PolygonsOnImage``
        instance.

        Added in 0.4.0.

        Parameters
        ----------
        kpsoi : imgaug.augmentables.kps.KeypointsOnImages
            Keypoints to convert back to polygons, i.e. the outputs
            of ``to_keypoints_on_image()``.

        Returns
        -------
        PolygonsOnImage
            Polygons container with updated coordinates.
            Note that the instance is also updated in-place.

        z Expected %d coordinates, got %d.r   N)r   r   rr   r7   Ú	keypointsrn  r6   )	r:   Úkpsoir†   rU   ry  r   Únb_points_expÚxy_arrrq  s	            r!   Úinvert_to_keypoints_on_image_z-PolygonsOnImage.invert_to_keypoints_on_image_Û  sð   € ð* —‘ˆÙ/4Ó5©u t�T—]“]¨uˆ	Ð5Ü¹9ÓE¹9¨xœS �]¸9ÑEÓFˆÜ�5—?‘?Ó# }Ò4ð 	6Ø.Øœs 5§?¡?Ó3ð25ñ 5ó	6Ð4ð ×"Ñ"Ó$ˆàˆÛˆDØ—}‘}ˆHØ# G¨G´C¸³MÑ,AÐ$AÂ1Ð$DÑEˆH’Qš�T‰NØ”s˜8“}Ñ$‰Gð ð —[‘[ˆŒ
Øˆùò 6ùÚEs
   ‘C%¯C*c                 ój   — |€| j                   dd }|€t        | j                  «      }t        ||«      S )a  Create a shallow copy of this object.

        Parameters
        ----------
        polygons : None or list of imgaug.augmentables.polys.Polygons, optional
            List of polygons on the image.
            If not ``None``, then the ``polygons`` attribute of the copied
            object will be set to this value.

        shape : None or tuple of int or ndarray, optional
            The shape of the image on which the objects are placed.
            Either an image with shape ``(H,W,[C])`` or a tuple denoting
            such an image shape.
            If not ``None``, then the ``shape`` attribute of the copied object
            will be set to this value.

        Returns
        -------
        imgaug.augmentables.polys.PolygonsOnImage
            Shallow copy.

        N)r   Útupler6   rI  rK  s      r!   r&  zPolygonsOnImage.copy  s8   € ð. ÐØ—}‘}¡QÐ'ˆHØˆ=ä˜$Ÿ*™*Ó%ˆEä˜x¨Ó/Ð/r#   c                 ó¤   — |€'| j                   D �cg c]  }|j                  «       ‘Œ }}|€t        | j                  «      }t	        ||«      S c c}w )a  Create a deep copy of this object.

        Parameters
        ----------
        polygons : None or list of imgaug.augmentables.polys.Polygons, optional
            List of polygons on the image.
            If not ``None``, then the ``polygons`` attribute of the copied
            object will be set to this value.

        shape : None or tuple of int or ndarray, optional
            The shape of the image on which the objects are placed.
            Either an image with shape ``(H,W,[C])`` or a tuple denoting
            such an image shape.
            If not ``None``, then the ``shape`` attribute of the copied object
            will be set to this value.

        Returns
        -------
        imgaug.augmentables.polys.PolygonsOnImage
            Deep copy.

        )r   rc   r‚  r6   rI  )r:   r   r6   rU   s       r!   rc   zPolygonsOnImage.deepcopy   sN   € ð0 ÐØ48·M²MÓB±M¨D˜Ÿ™�°MˆHÐBØˆ=ä˜$Ÿ*™*Ó%ˆEä˜x¨Ó/Ð/ùò Cs   ‘Ac                 ó    — | j                   |   S )zÇGet the polygon(s) with given indices.

        Added in 0.4.0.

        Returns
        -------
        list of imgaug.augmentables.polys.Polygon
            Polygon(s) with given indices.

        rM  r)  s     r!   r+  zPolygonsOnImage.__getitem__@  r,  r#   c                 ó,   — t        | j                  «      S )a  Iterate over the polygons in this container.

        Added in 0.4.0.

        Yields
        ------
        Polygon
            A polygon in this container.
            The order is identical to the order in the polygon list
            provided upon class initialization.

        )r.  r   r@   s    r!   r/  zPolygonsOnImage.__iter__M  s   € ô �D—M‘MÓ"Ð"r#   c                 ó,   — t        | j                  «      S )z§Get the number of items in this instance.

        Added in 0.4.0.

        Returns
        -------
        int
            Number of items in this instance.

        )r7   rN  r@   s    r!   Ú__len__zPolygonsOnImage.__len__\  s   € ô �4—:‘:‹Ðr#   c                 ó"   — | j                  «       S rÂ   r1  r@   s    r!   r3  zPolygonsOnImage.__repr__i  r4  r#   c                 óN   — dt        | j                  «      ›d| j                  ›d�S )NzPolygonsOnImage(z, shape=Ú))rÐ   r   r6   r@   s    r!   r2  zPolygonsOnImage.__str__l  s   � ä�—‘Õ §
£
ð,ð 	,r#   r;  r9  rŽ   r:  r@  )!rA  rB  rC  rD  r=   rE  rN  ÚsetterrR  rV  rX  ræ   r[  r]  ra  rc  rf  rq   r¯   r¹   r  r  rn  rt  rz  r€  r&  rc   r+  r/  r‡  r3  r2  rÃ   r#   r!   rI  rI  ”  sã   „ ñò2,ð ñó ðð ‡\�\ñó ðð ñ	'ó ð	'òò:*ð( 59Ø59Ø,0Ø59Ø;?Ø,1óló\ó:Cò(>ò.Cò, òD0ó2ó6+0òZò(;ò$Iò 6òpKò*$óL0ó>0ò@&ò#òòó,r#   rI  c                 ó.  — dd l }t        | «      dk  rt        dt        | «      fz  «      ‚| D �cg c]  }|d   |d   f‘Œ }}|dkD  rt        ||«      }|r"t        | «      dkD  r|j	                  |d   «       |j
                  j                  |«      S c c}w )Nr   r	   ziConversion to shapely line string requires at least two points, but points input contains only %d points.)r‘   r7   r„   r   rf   r’   r”   )Úpointsr�   r  r    r;   Úpoints_tupless         r!   r  r  q  s¬   € ó ä
ˆ6ƒ{�aÒÜð8Ü;>¸v»;¸.ñIóJð 	Jñ 8>Ó>±v¨e�e˜A‘h  a¡Ò)°v€MÐ>ð �Q‚Ü*¨=¸+ÓFˆñ ”#�f“+ ’/Ø×Ñ˜]¨1Ñ-Ô.à×Ñ×&Ñ& }Ó5Ð5ùò ?s   ¯Bc                   óz   — e Zd Z	 	 dd„Zdd„Zd„ Zd„ Zed„ «       Zd„ Z	ed„ «       Z
	 	 dd„Zd	„ Zed
„ «       Zd„ Zy)Ú_ConcavePolygonRecovererc                 ó¬   — || _         || _        || _        || _        d| _        d| _        d| _        d| _        d| _        d| _	        d| _
        d| _        y )NéK   éd   rO   r	   r   iPÃ  é   )Úthreshold_duplicate_pointsÚnoise_strengthÚoversamplingÚmax_segment_differenceÚoversample_up_to_n_points_maxÚfit_n_changes_maxÚfit_n_iters_maxÚfit_max_dist_first_iterÚfit_max_dist_other_itersÚ fit_n_candidates_before_sort_maxÚ$limit_coords_values_for_inter_searchÚdecimals)r:   r•  r–  r—  r˜  s        r!   r=   z!_ConcavePolygonRecoverer.__init__Š  so   € à*DˆÔ'Ø,ˆÔØ(ˆÔØ&<ˆÔ#ð
 .0ˆÔ*ð "%ˆÔð  !ˆÔð ()ˆÔ$Ø()ˆÔ%ð 14ˆÔ-ð 5:ˆÔ1ð
 ˆ�r#   c                 ó  — t        |t        «      sJt        j                  |«      r!|j                  dk(  r|j
                  d   dk(  sJ dt        |«      ›d�«       ‚t        |«      dk\  sJ d«       ‚|j                  |¬«      }|j                  r|S t        j                  |«      }|j                  d«      }| j                  |«      }| j                  ||d   «      }| j                  ||d   «      }| j!                  || j"                  ¬	«      }| j$                  �!| j$                  dkD  r| j'                  ||«      }| j)                  ||«      }| j+                  ||d   «      }|D �	cg c]  }	||	   ‘Œ	 }
}	|j                  |
¬«      S c c}	w )
Nr   r	   z5Expected exterior as list or (N,2) ndarray, got type r½   rO   z=Cannot recover a concave polygon from less than three points.r?   r   )r   )r   r   r3   r4   r5   r6   rœ   r7   rc   rQ   ÚiarandomÚRNGÚ	duplicateÚ$_remove_consecutive_duplicate_pointsÚ_fix_polygon_is_lineÚ_jitter_duplicate_pointsÚ_generate_intersection_pointsr   r—  Ú_oversample_intersection_pointsÚ_insert_intersection_pointsÚ_fit_best_valid_polygon)r:   Únew_exteriorÚold_polygonr   r   ÚrssÚsegment_add_pointsÚnew_exterior_interÚnew_exterior_concave_idsÚidxÚnew_exterior_concaves              r!   r   z%_ConcavePolygonRecoverer.recover_from¸  sÉ  € Ü˜,¬Ô-Ü�N‰N˜<Ô(Ø×!Ñ! QÒ&Ø×"Ñ" 1Ñ%¨Ò*ñ	*ô
 ˜Õ&ð)ó		*ð ,ô �<Ó  AÒ%ð 	LØKó	LÐ%ð
 ×&Ñ&°Ð&Ó=ˆØ×ÒØˆNä—|‘| LÓ1ˆØ×$Ñ$ QÓ'ˆð ×@Ñ@ÀÓNˆð ×0Ñ0°¸sÀ1¹vÓFˆð ×4Ñ4°\À3ÀqÁ6ÓJˆð "×?Ñ?Ø 4§=¡=ð @ó 2Ðð ×ÑÐ(¨T×->Ñ->ÀÒ-BØ!%×!EÑ!EØÐ0ó"2Ðð "×=Ñ=ØÐ,ó.Ðð $(×#?Ñ#?Ø  A¡ó$(Ð ñ 0Hó IÙ/G¨Ð˜sÓ#Ð/Gð 	ð  Ið
 ×#Ñ#Ð-AÐ#ÓBÐBùò Is   Å&Fc                 ó  — g }|D ]„  }|rot         j                  j                  t        j                  |«      t        j                  |d   «      z
  «      }|| j                  k  }|rŒb|j                  |«       Œt|j                  |«       Œ† t        |«      dk\  rft         j                  j                  t        j                  |d   «      t        j                  |d   «      z
  «      }|| j                  k  }|r|dd n|}|S )Nr,   r   r   )r.   ÚlinalgÚnormr0   r•  rf   r7   )r:   r�  rá   r;   rm   Úis_sames         r!   r¥  z=_ConcavePolygonRecoverer._remove_consecutive_duplicate_pointsë  s×   € ØˆÛˆEÙÜ—y‘y—~‘~Ü—J‘J˜uÓ%¬¯
©
°6¸"±:Ó(>Ñ>ó@�à $×"AÑ"AÑA�ÚØ—M‘M %Õ(à—‘˜eÕ$ð ô ˆv‹;˜!ÒÜ—9‘9—>‘>Ü—
‘
˜6 !™9Ó%¬¯
©
°6¸"±:Ó(>Ñ>ó@ˆDà˜d×=Ñ=Ñ=ˆGÙ%,�V˜A˜b‘\°&ˆFØˆr#   c                 ó¼  — t        |«      dk\  sJ dt        |«      fz  «       ‚| j                  }| j                  |«      r–|j                  | |t        |«      df¬«      j	                  t
        j                  «      }t        ||«      D ��cg c]  \  }}|d   |d   z   |d   |d   z   f‘Œ }}}|dz  }|dkD  sJ d|fz  «       ‚| j                  |«      rŒ–|S c c}}w )	NrO   zfCan only fix line-like polygons with an exterior containing at least 3 points. Got one with %d points.r   ©rÉ   r   r	   é
   ú+Expected noise strength to be >0, got %.4f.)r7   r–  Ú_is_polygon_lineÚuniformrÑ   r.   r0   Úzip)r:   r   r   r–  Únoiser;   Únoise_is          r!   r¦  z-_ConcavePolygonRecoverer._fix_polygon_is_lineþ  s   € Ü�8‹} Ò!ð 	Jð6Ü9<¸X»Ð8HñIó	JÐ!ð ×,Ñ,ˆØ×#Ñ# HÔ-Ø ×(Ñ(Ø� ´s¸8³}ÀaÐ6Hð )ó ç‰f”R—Z‘ZÓ ð ô /2°(¸EÔ.BôDÙ.B™N˜E 7ð ˜q™ G¨A¡JÑ.°°a±¸7À1¹:Ñ0EÒFØ.Bð ñ Dà+¨bÑ0ˆNØ! AÒ%ð &Ø=Ø"ðA%ñ %ó&Ð%ð ×#Ñ# HÕ-ð ˆùóDs   Â Cc                 ó:  — t        j                  ddg«      }|d   }t        «       }|dd  D ]`  }t        j                  |«      t        j                  |«      z
  }t        j                  ||«      }|j                  t        |dz  «      «       Œb t        |«      dk  S )Nr   r	   iè  )r.   r0   Úsetr3   Úangle_between_vectorsÚaddÚintr7   )Úclsr   Úvec_downÚpoint1ÚanglesÚpoint2ÚvecÚangles           r!   r¼  z)_ConcavePolygonRecoverer._is_polygon_line	  sˆ   € ä—:‘:˜q !˜fÓ%ˆØ˜!‘ˆÜ“ˆØ˜q˜r“lˆFÜ—*‘*˜VÓ$¤r§z¡z°&Ó'9Ñ9ˆCÜ×,Ñ,¨X°sÓ;ˆEØ�J‰J”s˜5 4™<Ó(Õ)ð #ô �6‹{˜aÑÐr#   c                 ó°  ‡ — ˆ fd„}‰ j                   }|dkD  sJ d|fz  «       ‚|d d  }d}|sª ||«      }t        |«      r’|j                  ‰ j                    ‰ j                   t        |«      df¬«      j	                  t
        j                  «      }t        |«      D ]-  \  }}	|	sŒ	||   d   ||   d   z   ||   d   ||   d   z   f||<   Œ/ |dz  }nd	}|sŒª|S )
Nc           	      óØ  •— t        j                  t        «      }t        | «      D ]‘  \  }}t	        t        j                  |d   d‰j                  z  z  «      «      }t	        t        j                  |d   d‰j                  z  z  «      «      }dD ]%  }dD ]  }|||z   ||z   f   j                  |«       Œ  Œ' Œ“ dgt        | «      z  }|D ]œ  }	||	   }
t        |
«      D ]‡  \  }}|
|   }| |   }||   rŒt        |dz   t        |
«      «      D ]W  }|
|   }| |   }||   rŒt        j                  |d   |d   z
  dz  |d   |d   z
  dz  z   «      }|‰j                  k  sŒSd||<   ŒY Œ‰ Œž |S )Nr   gš™™™™™¹?r	   )r,   r   r	   Fr   T)ÚcollectionsÚdefaultdictr   r   rÅ  r.   rI   r•  rf   r7   Úrangerg   )Úexterior_with_duplicatesÚ
points_mapr   r;   r1   r2   Ú
direction0Ú
direction1Ú
duplicatesÚkeyÚ
candidatesÚp0_idxÚpoint0r   Úp1_idxrÈ  rm   r:   s                    €r!   Ú_find_duplicateszK_ConcavePolygonRecoverer._jitter_duplicate_points.<locals>._find_duplicates	  s®  ø€ Ü$×0Ñ0´Ó6ˆJä%Ð&>Ö?‘��5ô œŸ™  q¡Ø%)¨T×-LÑ-LÑ$Lñ"Nó Oó P�äœŸ™  q¡Ø%)¨T×-LÑ-LÑ$Lñ"Nó Oó P�ã",�JÛ&0˜
Ø" A j¡L°!°J±,Ð#?Ñ@×GÑGÈÕJñ '1ñ #-ð @ð  ˜¤3Ð'?Ó#@Ñ@ˆJÛ!�Ø'¨™_�
Ü!*¨:Ö!6‘I�A�vØ'¨™]�FØ5°fÑ=�FØ! &Ò)Ø ä" 1 Q¡3¬¨J«Ö8˜Ø!+¨A¡˜Ø!9¸&Ñ!A˜Ø% fÒ-Ø$ä!Ÿw™wØ# A™Y¨°©Ñ2°QÑ6Ø% a™y¨6°!©9Ñ4°qÑ8ñ9ó :˜ð   $×"AÑ"AÓAØ15˜J vÒ.ñ 9ñ "7ð "ð( Ðr#   r   r»  Fr   r¹  r	   rº  T)r–  Úanyr½  r7   rÑ   r.   r0   r   )
r:   r   r   rÜ  r–  Ú	convergedrÖ  r¿  r   Úis_duplicates
   `         r!   r§  z1_ConcavePolygonRecoverer._jitter_duplicate_points	  s  ø€ ô#	ðJ ×,Ñ,ˆØ Ò!ð 	OØ9¸^Ð<MÑMó	OÐ!à™A�;ˆØˆ	ÙÙ)¨(Ó3ˆJÜ�:ŒØ$×,Ñ,Ø×(Ñ(Ð(Ø×'Ñ'Ü˜h›-¨Ð+ð -ó ÷ ‘&œŸ™Ó$ð	 ô (1°Ö'<‘O�A�|Ú#à$ Q™K¨™N¨U°1©X°a©[Ñ8Ø$ Q™K¨™N¨U°1©X°a©[Ñ8ð':˜ šð (=ð  "Ñ$‘à �	ò# ð& ˆr#   c                 óä  — t        |«      dk\  sJ dt        |«      fz  «       ‚t        j                  |t        j                  ¬«      }t        j                  t        |«      dft        j                  ¬«      }||d d …dd…f<   |dd …dd…f   |dd…dd…f<   |ddd…f   |ddd…f<   t        j
                  j                  |d d …dd…f   |d d …dd…f   z
  d¬	«      }t        j                  |«      S )
NrO   zLNeed at least 3 points on the exterior to compute the circumference. Got %d.r*   r”  r   r   r	   r,   rý   )r7   r.   rÎ   r0   r/   rµ  r¶  rr   )rÆ  r�  Úpoints_matrixrj   s       r!   Ú_calculate_circumferencez1_ConcavePolygonRecoverer._calculate_circumference[	  s  € ä�6‹{˜aÒð 	7ð%Ü(+¨F« ~ñ6ó	7Ðô —‘˜&¬¯
©
Ô3ˆÜŸ™¤# f£+¨qÐ!1¼¿¹ÔDˆØ &ˆ’a˜˜1˜�fÑØ#0°±°Q°q°S°Ñ#9ˆ�a˜�d˜A˜a˜C�iÑ Ø!.¨q°!°A°#¨vÑ!6ˆ�b˜!˜A˜#�gÑÜ—I‘I—N‘NØš!˜Q˜q˜S˜&Ñ! M²!°Q°q°S°&Ñ$9Ñ9Àð #ó Cˆ	ä�v‰v�iÓ Ð r#   c                 óà
  — t        j                  t        j                  t        j                  |t         j                  ¬«      «      «      }|| j
                  kD  }|rEt        j                  d| j
                  fz  «       t        t        |«      «      D �cg c]  }g ‘Œ c}S t        j                  |«      rt        |«      }t        |t        «      sJ dt        |«      ›d�«       ‚t        |D �cg c]  }t        |«      dk(  ‘Œ c}«      s9J ddj                  |D �cg c]  }t!        t        |«      «      ‘Œ c}«      z  «       ‚t        |«      dk  rg S t        t        |«      «      D �cg c]´  }t        j"                  t%        ||   d   «      |«      t        j"                  t%        ||   d	   «      |«      ft        j"                  t%        ||d	z   t        |«      z     d   «      |«      t        j"                  t%        ||d	z   t        |«      z     d	   «      |«      ff‘Œ¶ }	}dd
lm}
 	  |
|	«      }t        t        |	«      «      D �cg c]  }g ‘Œ }}|D �]Õ  \  }}|r|d   g}|D �]Á  \  }}g }g }|	D �]?  \  }}t         j0                  j3                  |t        j                  |«      z
  «      }t         j0                  j3                  |t        j                  |«      z
  «      }t         j0                  j3                  |t        j                  |«      z
  «      }t         j0                  j3                  |t        j                  |«      z
  «      }t5        ||z   ||z   «      }|j7                  |«       |j7                  t         j0                  j3                  |d   |d   z
  |d	   |d	   z
  f«      «       �ŒB t        j4                  |«      }|| j8                  k  r9t;        t        j<                  |«      «      }||   j7                  |||   f«       �Œ­t        j                  d«       �ŒÄ �ŒØ g }t        t        |«      «      D ]ˆ  }||   D �cg c]  }|d   ‘Œ	 }}||   D �cg c]  }|d	   ‘Œ	 }}t        |«      dk  r|j7                  |«       ŒMt?        tA        ||«      d„ ¬«      }|j7                  |D � �!cg c]  \  } }!| ‘Œ	 c}!} «       ŒŠ |S c c}w c c}w c c}w c c}w # t*        $ rh}t        j                  dt!        |«      ›d�«       t-        j.                  «        t        t        |«      «      D �cg c]  }g ‘Œ nc c}w c}cY d }~S d }~ww xY wc c}w c c}w c c}w c c}!} w )Nr*   aw  Encountered during polygon repair a polygon with extremely large coordinate values beyond %d. Will skip intersection point computation for that polygon. This avoids exceptions and is -- due to the extreme distortion -- likely pointless anyways (i.e. the polygon is already broken beyond repair). Try using weaker augmentation parameters to avoid such large coordinate values.z8Expected 'exterior' to be a list or a ndarray. Got type r½   r   zFExpected 'exterior' to contain (x,y) coordinate pairs. Got lengths %s.r6  r   r	   )Úisect_segments_include_segmentszEncountered exception zP during polygon repair in segment intersection computation. Will skip that step.z^Couldn't find fitting segment in _generate_intersection_points(). Ignoring intersection point.c                 ó   — | d   S )Nr	   rÃ   )Úts    r!   Ú<lambda>zH_ConcavePolygonRecoverer._generate_intersection_points.<locals>.<lambda>Û	  s   € ÀÀ!Âr#   ©r×  )!r.   rW   ÚabsrÎ   r0   rŸ  r3   ÚwarnrÑ  r7   r4   r   r   rœ   Úallr7  rÐ   rI   ÚfloatÚ'imgaug.external.poly_point_isect_py2py3rä  r„   Ú	tracebackÚ	print_excrµ  r¶  rX   rf   r˜  rÅ  rh   Úsortedr¾  )"r:   r   Úone_point_per_intersectionr   Úlargest_valueÚtoo_large_valuesÚ_r;   r   Úsegmentsrä  ÚintersectionsÚexcÚsegments_add_pointsÚassociated_segmentsÚseg_inter_p0Úseg_inter_p1ÚdiffsÚdistsÚseg_p0Úseg_p1Ú	dist_p0p0Ú	dist_p1p1Ú	dist_p0p1Ú	dist_p1p0ÚdiffÚmin_diffr²  Úsegment_add_points_sortedræ  r�  ÚbothÚaÚ_bs"                                     r!   r¨  z6_ConcavePolygonRecoverer._generate_intersection_pointsi	  sô  € ô Ÿ™œrŸv™v¤b§h¡h¨x¼r¿z¹zÔ&JÓKÓLˆà˜D×EÑEÑEð 	áÜ�G‰Gð+ð ×=Ñ=ð.@ñ@ô	ô !&¤c¨(£mÔ 4Ó5Ñ 4˜1’BÐ 4Ñ5Ð5ä�>‰>˜(Ô#Ü˜H“~ˆHÜ˜(¤DÔ)ñ 	0ä" 8�nð/ó	0Ð)ô ±Ó:±¨”C˜“J !“O°Ñ:Ô;ð 	Eðà—	‘	¹ÓA¹¨uœ3œs 5›z�?¸ÑAÓBñDó	EÐ;ô ˆx‹=˜AÒØˆIô$ œ3˜x›=Ô)ó
ñ *�ô —H‘HœU 8¨A¡;¨q¡>Ó2°HÓ=Ü—H‘HœU 8¨A¡;¨q¡>Ó2°HÓ=ðô
 —H‘HœU 8¨Q°©U´c¸(³mÑ,CÑ#DÀQÑ#GÓHØ%ó'ä—H‘HœU 8¨Q°©U´c¸(³mÑ,CÑ#DÀQÑ#GÓHØ%ó'ðòð *ð 	ð 
õ"	-ð	6Ù;¸HÓEˆMô" ,1´°X³Ô+?Ó@Ñ+? ašrÐ+?ÐÐ@Ü*7Ñ&ˆEÐ&ñ *Ø':¸1Ñ'=Ð&>Ð#ä.AÑ*�˜lØ�Ø�Ü&.‘N�F˜FÜ "§	¡	§¡¨v¼¿¹ÀÓ8NÑ/NÓ O�IÜ "§	¡	§¡¨v¼¿¹ÀÓ8NÑ/NÓ O�IÜ "§	¡	§¡¨v¼¿¹ÀÓ8NÑ/NÓ O�IÜ "§	¡	§¡¨v¼¿¹ÀÓ8NÑ/NÓ O�IÜ˜y¨9Ñ4°iÀ)Ñ6KÓL�DØ—L‘L Ô&Ø—L‘L¤§¡§¡Ø ™ U¨1¡XÑ-¨v°a©y¸5À¹8Ñ/CÐDó"ö ð '/ô Ÿ6™6 %›=�Ø˜d×9Ñ9Ò9ÜœbŸi™i¨Ó.Ó/�CØ'¨Ñ,×3Ñ3°U¸EÀ#¹JÐ4GÖHä—G‘Gð.ö/ò' /Bð +8ðB %'Ð!ÜœÐ0Ó1Ö2ˆCØ$7¸Ò$<Ó=Ñ$<˜q�a˜“dÐ$<ˆFÐ=Ø#6°sÒ#;Ó<Ñ#;˜a�Q�q“TÐ#;ˆEÐ<Ü�6‹{˜QŠØ)×0Ñ0°Õ8äœc &¨%Ó0±nÔE�à)×0Ñ0ÁÔ1FÁ¹¸¸2²!ÀÒ1FÕGð 3ð )Ð(ùòG 6ùò ;ùò Bùò
øô, ò 	6ô �GŠGô ˜•Hðô ô ×ÑÔ!Ü %¤c¨(£mÔ 4Ó5Ñ 4˜1’BÑ 4ùÔ5Õ5ûð	6üò  AùòH >ùÚ<ùó 2Gs\   Â	SÃ/SÄSÅ*B9S"È,S' É
	UÑU Ñ%U%Ò;U*Ó'	UÓ0AUÔ<	UÕUÕUÕUc           	      ó„  — | j                   �| j                   dk  r|S t        t        |«      «      D �cg c]  }g ‘Œ }}t        |«      }t        |«      D �]b  \  }}t        ||   «      D �]J  \  }}	|	d   |d   z
  |	d   |d   z
  f}
|dk(  rd| j                   z
  g}n| j                   d| j                   z
  g}|D ]2  }|d   ||
d   z  z   |d   ||
d   z  z   f}||   j	                  |«       Œ4 ||   j	                  |	«       |	}|t        ||   «      dz
  k(  }|rt||dz   t        |«      z     }|d   |d   z
  |d   |d   z
  f}
||   j	                  |d   | j                   |
d   z  z   |d   | j                   |
d   z  z   f«       ||   d   }|t        ||   «      z  }|| j
                  kD  s�ŒG|c c S  �Œe |S c c}w )Nr   r	   r<  r,   )r—  rÑ  r7   r   rf   r™  )r:   r   r¯  rô  Úsegment_add_points_sorted_oversÚn_pointsr   Úlastr   Úp_interÚ	directionÚ
oversamplerm   Ú
point_overÚis_last_in_groupÚexterior_points                   r!   r©  z8_ConcavePolygonRecoverer._oversample_intersection_pointsà	  sA  € ð ×ÑÐ$¨×(9Ñ(9¸QÒ(>Ø%Ð%ô œcÐ"4Ó5Ô6ó+8Ù6�1ŠBÐ6ð 	(ð +8ô �x“=ˆÜ  ×*‰GˆAˆtÜ'Ð(:¸1Ñ(=×>‘
��7Ø$ Q™Z¨$¨q©'Ñ1°7¸1±:ÀÀQÁÑ3GÐH�	à˜’6à"%¨×(9Ñ(9Ñ"9Ð!:‘Jð #'×"3Ñ"3°S¸4×;LÑ;LÑ5LÐ!M�Jã&�DØ"& q¡'¨D°9¸Q±<Ñ,?Ñ"?Ø"& q¡'¨D°9¸Q±<Ñ,?Ñ"?ð"A�Jà3°AÑ6×=Ñ=¸jÕIð 'ð 0°Ñ2×9Ñ9¸'ÔBØ�à$%¬Ð-?ÀÑ-BÓ)CÀaÑ)GÑ$GÐ Ù#ð &.¨q°1©u¼¸H»Ñ.EÑ%F�NØ!/°Ñ!2°T¸!±WÑ!<Ø!/°Ñ!2°T¸!±WÑ!<ð!>�Ià3°AÑ6×=Ñ=Ø˜a™ 4×#4Ñ#4°yÀ±|Ñ#CÑCØ˜a™ 4×#4Ñ#4°yÀ±|Ñ#CÑCðEôð ;¸1Ñ=¸bÑA�DàœCÐ ?ÀÑ BÓCÑC�Ø˜d×@Ñ@Ô@Ø:Ô:òA ?ð +ðF /Ð.ùòO+8s   ´	F=c                 óü   — t        |«      t        |«      k(  sJ dt        |«      t        |«      fz  «       ‚g }t        |«      D ]6  \  }}||   }|j                  |«       ||   D ]  }|j                  |«       Œ Œ8 |S )NzŠExpected one entry in 'segment_add_points' for every point in the exterior. Got %d (segment_add_points) and %d (exterior) entries instead.)r7   r   rf   )rÆ  r   r¯  Úexterior_interpr   rÚ  r  s          r!   rª  z4_ConcavePolygonRecoverer._insert_intersection_points
  s˜   € ô �8‹}¤Ð$6Ó 7Ò7ð 	Kðä"%Ð&8Ó"9¼3¸x»=Ð!IñJó	KÐ7ð ˆÜ" 8Ö,‰IˆAˆvØ˜a‘[ˆFØ×"Ñ" 6Ô*Ø-¨aÔ0�Ø×&Ñ& wÕ/ñ 1ð -ð
 Ðr#   c                 ó6	  ‡%— t        |«      dk  ry d„ }t        |«      }|j                  rt        j                  t        |«      «      S t
        j                  j                  |«      }t        |j                  «      }t        t        |«      «      D �cg c]	  }||vsŒ|‘Œ }}d}	d}
d}|�sÒg Š%t        |«      D ��ci c]  \  }}||“Œ
 }}}t        j                  t        j                  t        j                  |«      t        t        j                  |«      «      «      t        j                   t        j                  |«      t        t        j                  |«      «      «      g«      }t        j"                  |t        j$                  |j&                  d   dft        j                  ¬«      fd¬«      }|d d …df   |d d …df   k  }|d d …dd…f   |d d …dd	…f<   ||df   ||df<   ||df   ||df<   t        j(                  |d d …df   |d d …df   z
  t        |«      |d d …df   z
  |d d …df   z   «      |d d …d	f<   | j*                  }|	dkD  r| j,                  }||d d …d	f   |k     }| j.                  d uxr t        |«      | j.                  kD  }|r |j1                  |«       |d| j.                   }|D ]^  }|d   }|d   }||   }|}||dz   t        |«      z     }||   }||   }|	dk(  rd}n |||   ||«      }‰%j3                  |||d	   |f«       Œ` t        j4                  t        ‰%«      «      }t7        |ˆ%fd
„¬«      }| j8                  �|d | j8                   }d}t;        «       }|D ]×  }‰%|   d   }‰%|   d   }||f|vsŒt        |«      D ��cg c]  \  }}||k(  r|‘Œ c}}d   } |d d  }!|!j=                  | dz   |«       t        |!D �"cg c]  }"||"   ‘Œ	 c}"«      }#|#j                  r0d}|!}|D �cg c]	  }||k7  r|‘Œ }}|
dz  }
|
| j8                  k\  r|c S |j?                  ||f«       |j?                  ||f«       ŒÙ |s|	dkD  rd}|	dz  }	| j@                  d uxr |	| j@                  kD  }$|$r	 |S |s�ŒÒ|S c c}w c c}}w c c}}w c c}"w c c}w )Nr   c                 óB  — |d   |d   z
  }|d   |d   z
  }t        || d   z  || d   z  z
  |d   |d   z  z   |d   |d   z  z
  «      }t        j                  |dz  |dz  z   «      }|dk(  r0t        j                  | d   |d   z
  dz  | d   |d   z
  dz  z   «      S ||z  S )Nr   r	   r   )ré  r.   rg   )r;   Ú
line_startÚline_endÚx_diffÚy_diffÚnumÚdens          r!   Ú_compute_distance_point_to_linezY_ConcavePolygonRecoverer._fit_best_valid_polygon.<locals>._compute_distance_point_to_line#
  sã   € Ø˜a‘[ :¨a¡=Ñ0ˆFØ˜a‘[ :¨a¡=Ñ0ˆFÜØ�u˜Q‘x‘ &¨¨q©¡/Ñ1Ø˜1‘+˜j¨™mÑ+ñ,Ø.6°q©k¸*ÀQ¹-Ñ.GñHóˆCô —'‘'˜& !™) f¨a¡iÑ/Ó0ˆCØ�aŠxÜ—w‘wØ˜1‘X 
¨1¡Ñ-°Ñ1Ø˜Q‘x *¨Q¡-Ñ/°!Ñ3ñ4ó5ð 5ð ˜‘9Ðr#   r   FrO   r*   r	   rý   r”  c                 ó$   •— ‰|    d   ‰|    d   fS )Nr   rO   rÃ   )r²  rØ  s    €r!   rç  zB_ConcavePolygonRecoverer._fit_best_valid_polygon.<locals>.<lambda>�
  s   ø€  ¨C¡°Ñ!3°ZÀ±_ÀQÑ5GÑ Hr#   rè  T)!r7   r%   rQ   ÚsmÚxrangeÚscipyÚspatialÚ
ConvexHullr   ÚverticesrÑ  r   r.   Ú	transposerë   rH   Úrepeatrÿ   r/   r6   Úminimumr�  rœ  rž  Úshufflerf   Úarangerð  rš  rÂ  ÚinsertrÄ  r›  )&r:   r�  r   r  rU   ÚhullÚpoints_keptr   Úpoints_leftÚ	iterationÚ	n_changesrÞ  r¬   Úpoint_kept_idx_to_posÚcombosrõ   Úmax_distÚcandidate_rowsÚdo_limitÚrowÚpoint_left_idxÚpoint_kept_idxÚin_points_kept_posÚsegment_start_idxÚsegment_end_idxÚsegment_startÚsegment_endÚ	dist_euclÚcandidate_idsrQ   ÚdoneÚcandidate_idxÚin_points_kept_idxÚpoints_kept_hypothesisr²  Úpoly_hypothesisÚhas_reached_iters_maxrØ  s&                                        @r!   r«  z0_ConcavePolygonRecoverer._fit_best_valid_polygon
  s]  ø€ Üˆv‹;˜Š?Øò	ô �v‹ˆØ�=Š=Ü—9‘9œS ›[Ó)Ð)ä�}‰}×'Ñ'¨Ó/ˆÜ˜4Ÿ=™=Ó)ˆÜ"'¬¨F«Ô"4ÓMÑ"4˜Q¸ÀÒ8L’qÐ"4ˆÐMàˆ	Øˆ	Øˆ	ÚØˆJô" 2;¸;Ô1Gô%IÙ1G¡  I�	˜1‘Ð1Gð "ñ %Iô
 —\‘\Ü—‘Ü—H‘H˜[Ó)¬3¬r¯x©x¸Ó/DÓ+Eóô —	‘	Ü—H‘H˜[Ó)¬3¬r¯x©x¸Ó/DÓ+Eóð	#ó ˆFô —^‘^ØœŸ™ 6§<¡<°¡?°AÐ"6¼b¿h¹hÔGÐHØôˆFð
 š!˜Q˜$‘< &ª¨A¨¡,Ñ.ˆDØ#¢A q¨ s F™^ˆF’1�a˜�c�6‰NØ$ T¨1 W™oˆF�4˜�7‰OØ$ T¨1 W™oˆF�4˜�7‰Oô Ÿ:™:Ø’q˜!�t‘˜v¢a¨ d™|Ñ+Ü�F“˜f¢Q¨ T™lÑ*¨V²A°q°D©\Ñ9óˆF’1�a�4‰Lð ×4Ñ4ˆHØ˜1Š}Ø×7Ñ7�Ø# Fª1¨a¨4¡L°HÑ$<Ñ=ˆNà×5Ñ5¸TÐAò PÜ˜Ó'¨$×*OÑ*OÑOð ñ Ø×$Ñ$ ^Ô4Ø!/Ø�d×;Ñ;ð"=�ó &�Ø!$ Q¡�Ø!$ Q¡�Ø%:¸>Ñ%JÐ"Ø$2Ð!Ø"-Ø'¨Ñ)¬S°Ó-=Ñ=ñ#?�à &Ð'8Ñ 9�Ø$ _Ñ5�Ø ’>Ø !‘Iá ?Ø˜~Ñ.°¸{ó!L�Ià×!Ñ!Ø# ^°S¸±V¸YÐGõIð &ô( ŸI™I¤c¨*£oÓ6ˆMÜ"ØÛHôJˆMð ×%Ñ%Ð1Ø -Ð.E¨t×/EÑ/EÐ F�ð ˆHÜ“5ˆDÛ!.�Ø!+¨MÑ!:¸1Ñ!=�Ø!+¨MÑ!:¸1Ñ!=�Ø" NÐ3¸4Ò?ô % [Ô1ô*ñ 2ñ )˜A˜yà$¨Ò6ò à1ò*ð
 ñ*Ð&ð .9¹¨^Ð*Ø*×1Ñ1Ø*¨1Ñ,Ø&ô(ô '.Ù/Eó/GÙ/E¨˜˜s›Ð/Eñ/Gó 'H�Oà&×/Ò/Ø#'˜Ø&<˜ñ +6ó'Gá*5ð ,5à*3°~Ò*Eò (1à*5ð $ð 'Gð " Q™˜	Ø$¨×(>Ñ(>Ò>Ø#.Ò.Ø—H‘H˜n¨nÐ=Ô>Ø—H‘H˜n¨nÐ=Õ>ð7 "/ñ>  	¨A¢Ø �	à˜‰NˆIà×$Ñ$¨DÐ0ò 5Ø × 4Ñ 4Ñ4ð "ñ %ØàÐóY ðX Ðùòc Nùó,%Iùól*ùò/Gùò
'Gs$   Â	R ÂR Â<RÎRÏR
Ï8RN)r=  r=  rÊ   r=  )r   )Tr”  )rA  rB  rC  r=   r   r¥  r¦  Úclassmethodr¼  r§  râ  r¨  r©  rª  r«  rÃ   r#   r!   r�  r�  ‰  s~   „ ØGKØ;?ó,ó\1Còfò&ð" ñ ó ð ò>ðB ñ!ó ð!ð BFØ/0óu)òn-/ð^ ñó ðóir#   r�  c                   ó(   — e Zd ZdZd„ Zedd„«       Zy)r˜   z¥
    Class that represents several polygons.

    Parameters
    ----------
    geoms : list of imgaug.augmentables.polys.Polygon
        List of the polygons.

    c           
      óð   — t        |«      dk(  sWt        |D �cg c]  }t        |t        «      ‘Œ c}«      s0J ddj	                  |D �cg c]  }t        |«      ‘Œ c}«      z  «       ‚|| _        yc c}w c c}w )z#Create a new MultiPolygon instance.r   z>Expected 'geoms' to a list of Polygon instances. Got types %s.r6  N)r7   rë  r   r%   r7  rÐ   r�   )r:   r�   Úels      r!   r=   zMultiPolygon.__init__×
  sy   € ô �‹J˜!ŠOÜ±eÓ<±e°”J˜r¤7Õ+°eÑ<Ô=ð	Jð Ø#'§9¡9ÁÓ-FÁ¸"¬c°"­gÀÑ-FÓ#GñIó	Jð>ð ˆ�
ùò =ùâ-Fs   ˜A.ÁA3Nc                 ó`  — ddl }t        | |j                  j                  «      r8t        | j                  D �cg c]  }t
        j                  ||¬«      ‘Œ c}«      S t        | |j                  j
                  «      r!t        t
        j                  | |¬«      g«      S t        | |j                  j                  j                  «      r¼t        | j                  D �cg c]"  }t        ||j                  j
                  «      ‘Œ$ c}«      sCJ ddj                  | j                  D �cg c]  }t        t        |«      «      ‘Œ c}«      z  «       ‚t        | j                  D �cg c]  }t
        j                  ||¬«      ‘Œ c}«      S t        dt        | «      ›d�«      ‚c c}w c c}w c c}w c c}w )aW  Create a MultiPolygon from a shapely object.

        This also creates all necessary ``Polygon`` s contained in this
        ``MultiPolygon``.

        Parameters
        ----------
        geometry : shapely.geometry.MultiPolygon or shapely.geometry.Polygon or shapely.geometry.collection.GeometryCollection
            The object to convert to a MultiPolygon.

        label : None or str, optional
            A label assigned to all Polygons within the MultiPolygon.

        Returns
        -------
        imgaug.augmentables.polys.MultiPolygon
            The derived MultiPolygon.

        r   Nr�   zPExpected the geometry collection to only contain shapely polygons. Got types %s.r6  zUnknown datatype 'zy'. Expected shapely.geometry.Polygon or shapely.geometry.MultiPolygon or shapely.geometry.collections.GeometryCollection.)r‘   r   r’   r˜   r�   r%   rž   Ú
collectionr™   rë  r7  rÐ   rœ   r„   )r’   r9   r    rU   Úvs        r!   rž   zMultiPolygon.from_shapelyà
  s±  € ó, 	 ä�h × 0Ñ 0× =Ñ =Ô>Üð —>’>ó!#ñ "ð ô ×$Ñ$ T°Ð$Õ7à!ñ!#ó $ð $ô �h × 0Ñ 0× 8Ñ 8Ô9Ü¤×!5Ñ!5°hÀeÐ!5Ó!LÐ MÓNÐNÜ�hØ×&Ñ&×1Ñ1×DÑDôFäð —>’>ó#ñ "ð ô ˜4 ×!1Ñ!1×!9Ñ!9Õ:à!ñ#ô $ð Lð.àŸ	™	¸¿ºÓ"H¹°A¤3¤t¨A£w¥<¸Ñ"HÓIñKó	Lð $ô  ð —>’>ó!#ñ "ð ô ×$Ñ$ T°Ð$Õ7à!ñ!#ó $ð $õ
 ô �X•ð!ó"ð 	"ùò)!#ùò#ùò #Iùò!#s   ¸FÃ'F!Ä$F&ÅF+rÂ   )rA  rB  rC  rD  r=   rG  rž   rÃ   r#   r!   r˜   r˜   Í
  s    „ ñòð ò0"ó ñ0"r#   r˜   r>  )%rD  Ú
__future__r   r   r   rî  rÏ  Únumpyr.   Úscipy.spatial.distancer"  Ú	six.movesÚmovesr   Úskimage.drawrÒ   Úskimage.measurerw  r   r3   r   r¢  Úbaser
   Úutilsr   r   r   r   r   r"   Úobjectr%   rI  r  r�  r˜   rÃ   r#   r!   Ú<module>rW     s…   ðÙ $ß @Ñ @ã Û ã Û Ý Û Û å Ý !Ý ÷+õ +ò/ôlC8ˆfô C8ôN*Z,�lô Z,ðz ;@Ø78ó6ô0˜vô ôHD"�6õ D"r#   