o
    b                     @  s   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 erSee ZneZeG dd deZdS )    )annotationsN)MutableSequence)TYPE_CHECKINGIterableIteratorListOptionaloverload)definefield)AbstractPen)AbstractPointPenPointToSegmentPen)BoundingBox	getBoundsgetControlBounds)Point)GlyphSetc                   @  s   e Zd ZU dZeedZded< 	 edddZded	< 	 d?ddZ	e
d@ddZe
dAddZdBddZdCddZdDddZdEd d!ZdFd#d$ZedGd&d'ZdHd*d+ZdIdJd/d0ZedKd1d2ZdIdJd3d4ZedKd5d6ZdLd9d:ZdMd=d>ZdS )N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]
identifierindexint | slicereturnNonec                 C  s   | j |= d S Nr   selfr    r"   9/usr/lib/python3/dist-packages/ufoLib2/objects/contour.py__delitem__:   s   zContour.__delitem__intr   c                 C     d S r   r"   r    r"   r"   r#   __getitem__=      zContour.__getitem__slicelist[Point]c                 C  r&   r   r"   r    r"   r"   r#   r'   A   r(   Point | list[Point]c                 C  s
   | j | S r   r   r    r"   r"   r#   r'   E      
pointPoint | Iterable[Point]c                 C  sl   t |trt |tr|| j|< d S t |tr+t |tr+tdd |D r+|| j|< d S tdt|j	 d)Nc                 s  s    | ]}t |tV  qd S r   )
isinstancer   ).0pr"   r"   r#   	<genexpr>P   s    z&Contour.__setitem__.<locals>.<genexpr>z)Expected Point or Iterable[Point], found .)
r/   r%   r   r   r)   r   all	TypeErrortype__name__)r!   r   r-   r"   r"   r#   __setitem__H   s   zContour.__setitem__Iterator[Point]c                 C  
   t | jS r   )iterr   r!   r"   r"   r#   __iter__X   r,   zContour.__iter__c                 C  r:   r   )lenr   r<   r"   r"   r#   __len__[   r,   zContour.__len__valuec                 C  s2   t |tstdt|j d| j|| dS )z<Insert Point object ``value`` into the contour at ``index``.zExpected Point, found r3   N)r/   r   r5   r6   r7   r   insert)r!   r   r@   r"   r"   r#   rA   ^   s   
zContour.insertboolc                 C  s   | j sdS | j d jdkS )z.Returns whether the contour is open or closed.Tr   move)r   r6   r<   r"   r"   r#   openf   s   zContour.opendeltatuple[float, float]c                 C  s   | j D ]}|| qdS )z#Moves contour by (x, y) font units.N)r   rC   )r!   rE   r-   r"   r"   r#   rC   m   s   
zContour.movelayerGlyphSet | NoneBoundingBox | Nonec                 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!   rG   r"   r"   r#   r   r      
zContour.getBoundsc                 C     |   S )zReturns the (xMin, yMin, xMax, yMax) bounding box of the glyph,
        taking the actual contours into account.

        |defcon_compat|
        rK   r<   r"   r"   r#   bounds{      zContour.boundsc                 C  rJ   )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   r"   r"   r#   r      rM   zContour.getControlBoundsc                 C  rN   )zReturns the (xMin, yMin, xMax, yMax) bounding box of the glyph,
        taking only the control points into account.

        |defcon_compat|
        rQ   r<   r"   r"   r#   controlPointBounds   rP   zContour.controlPointBoundspenr   c                 C  s   t |}| | dS )zDraws contour into given pen.N)r   
drawPoints)r!   rS   pointPenr"   r"   r#   draw   s   zContour.drawrU   r   c              
   C  s   z!|j | jd | jD ]}|j|j|jf|j|j|j|jd qW n) t	yJ   |   | jD ]}|j|j|jf|j|j|jd q/t
dt Y nw |  dS )z-Draws points of contour into given point pen.)r   )segmentTypesmoothnamer   )rW   rX   rY   zHThe pointPen needs an identifier kwarg. Identifiers have been discarded.N)Z	beginPathr   r   ZaddPointxyr6   rX   rY   r5   warningswarnUserWarningZendPath)r!   rU   r1   r"   r"   r#   rT      s.   


zContour.drawPoints)r   r   r   r   )r   r%   r   r   )r   r)   r   r*   )r   r   r   r+   )r   r   r-   r.   r   r   )r   r9   )r   r%   )r   r%   r@   r   r   r   )r   rB   )rE   rF   r   r   r   )rG   rH   r   rI   )r   rI   )rS   r   r   r   )rU   r   r   r   )r7   
__module____qualname____doc__r   listr   __annotations__r   r$   r	   r'   r8   r=   r?   rA   propertyrD   rC   r   rO   r   rR   rV   rT   r"   r"   r"   r#   r      s6   
 






		
r   )Z
__future__r   r\   Zcollections.abcr   typingr   r   r   r   r   r	   attrr
   r   ZfontTools.pens.basePenr   ZfontTools.pens.pointPenr   r   ZufoLib2.objects.miscr   r   r   ZufoLib2.objects.pointr   ZufoLib2.typingr   ZContourMappingr   r"   r"   r"   r#   <module>   s     
