
     #e5                        d dl mZ d dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZ d dlmZmZ d dlmZ d dlmZmZ d dlmZmZmZ d d	lmZ d d
lmZ d dlmZ eree   ZneZee G d de                    Zy)    )annotationsN)MutableSequence)TYPE_CHECKINGIterableIteratorListOptionaloverload)definefield)AbstractPen)AbstractPointPenPointToSegmentPen)BoundingBox	getBoundsgetControlBounds)Point)serde)GlyphSetc                     e Zd ZU dZ ee      Zded<   	  edd      Zded	<   	 dd
Z	e
dd       Ze
dd       ZddZ	 	 	 	 	 	 ddZddZd dZd!dZed"d       Zd#dZd$d%dZed&d       Zd$d%dZed&d       Zd'dZd(dZy))ContouraS  Represents a contour as a list of points.

    Behavior:
        The Contour object has list-like behavior. This behavior allows you to interact
        with point data directly. For example, to get a particular point::

            point = contour[0]

        To iterate over all points::

            for point in contour:
                ...

        To get the number of points::

            pointCount = len(contour)

        To delete a particular point::

            del contour[0]

        To set a particular point to another Point object::

            contour[0] = anotherPoint
    )factoryzList[Point]pointsNF)defaultreprzOptional[str]
identifierc                    | j                   |= y Nr   selfindexs     9/usr/lib/python3/dist-packages/ufoLib2/objects/contour.py__delitem__zContour.__delitem__<   s    KK    c                     y r    r    s     r#   __getitem__zContour.__getitem__?       r%   c                     y r   r'   r    s     r#   r(   zContour.__getitem__C   r)   r%   c                     | j                   |   S r   r   r    s     r#   r(   zContour.__getitem__G   s    {{5!!r%   c                *   t        |t              r t        |t              r|| j                  |<   y t        |t              r2t        |t
              r"t        d |D              r|| j                  |<   y t        dt        |      j                   d      )Nc              3  <   K   | ]  }t        |t                y wr   )
isinstancer   ).0ps     r#   	<genexpr>z&Contour.__setitem__.<locals>.<genexpr>R   s     8QJq%(8s   z)Expected Point or Iterable[Point], found .)
r.   intr   r   slicer   all	TypeErrortype__name__)r!   r"   points      r#   __setitem__zContour.__setitem__J   sz     eS!j&>!&DKKue$5(+8%88!&DKK;DK<P<P;QQRS r%   c                ,    t        | j                        S r   )iterr   r!   s    r#   __iter__zContour.__iter__Z   s    DKK  r%   c                ,    t        | j                        S r   )lenr   r=   s    r#   __len__zContour.__len__]   s    4;;r%   c                    t        |t              s"t        dt        |      j                   d      | j
                  j                  ||       y)z<Insert Point object ``value`` into the contour at ``index``.zExpected Point, found r2   N)r.   r   r6   r7   r8   r   insert)r!   r"   values      r#   rC   zContour.insert`   s@    %'4T%[5I5I4J!LMM5%(r%   c                T    | j                   sy| j                   d   j                  dk(  S )z.Returns whether the contour is open or closed.Tr   move)r   r7   r=   s    r#   openzContour.openh   s'     {{{{1~""f,,r%   c                H    | j                   D ]  }|j                  |        y)z#Moves contour by (x, y) font units.N)r   rF   )r!   deltar9   s      r#   rF   zContour.moveo   s!    [[ 	EJJu	r%   c                    t        | |      S )zReturns the (xMin, yMin, xMax, yMax) bounding box of the glyph,
        taking the actual contours into account.

        Args:
            layer: Not applicable to contours, here for API symmetry.
        r   r!   layers     r#   r   zContour.getBoundst   s     u%%r%   c                "    | j                         S )zReturns the (xMin, yMin, xMax, yMax) bounding box of the glyph,
        taking the actual contours into account.

        |defcon_compat|
        rK   r=   s    r#   boundszContour.bounds}   s     ~~r%   c                    t        | |      S )zReturns the (xMin, yMin, xMax, yMax) bounding box of the glyph,
        taking only the control points into account.

        Args:
            layer: Not applicable to contours, here for API symmetry.
        r   rL   s     r#   r   zContour.getControlBounds   s      e,,r%   c                "    | j                         S )zReturns the (xMin, yMin, xMax, yMax) bounding box of the glyph,
        taking only the control points into account.

        |defcon_compat|
        rQ   r=   s    r#   controlPointBoundszContour.controlPointBounds   s     $$&&r%   c                <    t        |      }| j                  |       y)zDraws contour into given pen.N)r   
drawPoints)r!   penpointPens      r#   drawzContour.draw   s    $S)!r%   c                P   	 |j                  | j                         | j                  D ]V  }|j                  |j                  |j
                  f|j                  |j                  |j                  |j                         X 	 |j                          y# t        $ r |j                          | j                  D ]K  }|j                  |j                  |j
                  f|j                  |j                  |j                         M t        j                  dt               Y w xY w)z-Draws points of contour into given point pen.)r   )segmentTypesmoothnamer   )rZ   r[   r\   zHThe pointPen needs an identifier kwarg. Identifiers have been discarded.N)	beginPathr   r   addPointxyr7   r[   r\   r6   warningswarnUserWarningendPath)r!   rW   r0   s      r#   rU   zContour.drawPoints   s    	$//:[[ !!SS!##J !88 || " & 	  
	 [[ !!SS!##JAFF188!&& "  MM3
	s   BB BD%$D%)r"   int | slicereturnNone)r"   r3   rf   r   )r"   r4   rf   zlist[Point])r"   re   rf   zPoint | list[Point])r"   re   r9   zPoint | Iterable[Point]rf   rg   )rf   zIterator[Point])rf   r3   )r"   r3   rD   r   rf   rg   )rf   bool)rI   ztuple[float, float]rf   rg   r   )rM   zGlyphSet | Nonerf   BoundingBox | None)rf   ri   )rV   r   rf   rg   )rW   r   rf   rg   )r8   
__module____qualname____doc__r   listr   __annotations__r   r$   r
   r(   r:   r>   rA   rC   propertyrG   rF   r   rO   r   rS   rX   rU   r'   r%   r#   r   r      s    4  -FK-, %d ?J?8    " )@	 ! ) - -
&    - ' '"
r%   r   ) 
__future__r   ra   collections.abcr   typingr   r   r   r   r	   r
   attrsr   r   fontTools.pens.basePenr   fontTools.pens.pointPenr   r   ufoLib2.objects.miscr   r   r   ufoLib2.objects.pointr   ufoLib2.serder   ufoLib2.typingr   ContourMappingr   r'   r%   r#   <module>r{      sf    "  + N N  . G I I '  # $U+N$N _n _  _r%   