Ë
    £èhj!  ã                  óB  — d dl mZ d dlmZmZmZmZ d dlmZ d dl	Z	d dl
Z
d dlZd dlZddlmZmZmZmZmZ ddlmZmZ d dlmZmZ  G d	„ d
e	j2                  «      Z G d„ dej6                  «      Z G d„ de«      Z G d„ de«      Z G d„ d«      Z	 d	 	 	 	 	 	 	 	 	 dd„Z y)é    )Úannotations)ÚSequenceÚ
NamedTupleÚAnyÚIterator)ÚSelfNé   )ÚVec2ÚPathÚcolorsÚMatrix44ÚBoundingBox2d)Ú
PropertiesÚPen)ÚNumpyPath2dÚNumpyPoints2dc                  ól   — e Zd ZdZej
                  dd„«       Zej
                  	 	 	 	 	 	 	 	 dd„«       Zy)ÚBackendzAAbstract base class for implementing a low level output backends.c                 ó   — y)aI  Draws a polyline from a sequence `points`. The input coordinates are page
        coordinates in plot units. The `points` sequence can contain 0 or more
        points!

        Args:
            properties: display :class:`Properties` for the polyline
            points: sequence of :class:`ezdxf.math.Vec2` instances

        N© ©ÚselfÚ
propertiesÚpointss      ú:lib/python3.12/site-packages/ezdxf/addons/hpgl2/backend.pyÚdraw_polylinezBackend.draw_polyline    s   € ð 	ó    c                 ó   — y)a*  Draws filled or outline paths from the sequence of `paths`. The input coordinates
        are page coordinates in plot units. The `paths` sequence can contain 0 or more
        single :class:`~ezdxf.path.Path` instances. Draws outline paths if
        Properties.FillType is NONE and filled paths otherwise.

        Args:
            properties: display :class:`Properties` for the filled polygon
            paths: sequence of single :class:`ezdxf.path.Path` instances
            filled: draw filled paths if ``True`` otherwise outline paths

        Nr   )r   r   ÚpathsÚfilleds       r   Ú
draw_pathszBackend.draw_paths-   s   € ð 	r   N©r   r   r   zSequence[Vec2]ÚreturnÚNone©r   r   r   zSequence[Path]r    Úboolr#   r$   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚabcÚabstractmethodr   r!   r   r   r   r   r      sW   „ ÙKà×Ñò
ó ð
ð 	×ÑðØ$ðØ-;ðØEIðà	òó ñr   r   c                  ór   — e Zd Z ej                  «       Z ej                  «       Z ej                  «       Zy)Ú
RecordTypeN)r'   r(   r)   ÚenumÚautoÚPOLYLINEÚFILLED_PATHSÚOUTLINE_PATHSr   r   r   r.   r.   ?   s)   „ Øˆt�y‰y‹{€HØ�4—9‘9“;€LØ�D—I‘I“K�Mr   r.   c                  ó,   — e Zd ZU ded<   ded<   ded<   y)Ú
DataRecordr.   ÚtypeÚintÚproperty_hashr   ÚdataN)r'   r(   r)   Ú__annotations__r   r   r   r5   r5   E   s   … Ø
ÓØÓØ
„Ir   r5   c                  óH   — e Zd ZdZdd„Zd	d„Zd
d„Z	 	 	 	 	 	 	 	 dd„Zdd„Zy)ÚRecorderzÓThe :class:`Recorder` class records the output of the :class:`Plotter` class.

    All input coordinates are page coordinates:

    - 1 plot unit (plu) = 0.025mm
    - 40 plu = 1 mm
    - 1016 plu = 1 inch

    c                ó.   — g | _         i | _        g | _        y ©N)Ú_recordsÚ_propertiesÚ_pens©r   s    r   Ú__init__zRecorder.__init__V   s   € Ø*,ˆŒØ24ˆÔØ$&ˆ�
r   c                óB   — t        | j                  | j                  «      S )zÚReturns a :class:`Player` instance with the original recordings. Make a copy
        of this player to protect the original recordings from being modified::

            safe_player = recorder.player().copy()

        )ÚPlayerr?   r@   rB   s    r   ÚplayerzRecorder.player[   s   € ô �d—m‘m T×%5Ñ%5Ó6Ð6r   c                óX   — | j                  t        j                  |t        |«      «       y r>   )Ústorer.   r1   r   r   s      r   r   zRecorder.draw_polylined   s   € Ø�
‰
”:×&Ñ&¨
´MÀ&Ó4IÕJr   c                ó    — t        t        t        |«      «      }|rt        j                  nt        j
                  }| j                  |||«       y r>   )ÚtupleÚmapr   r.   r2   r3   rH   )r   r   r   r    r9   Úrecord_types         r   r!   zRecorder.draw_pathsg   s:   € ô ”Sœ eÓ,Ó-ˆÙ17”j×-Ò-¼Z×=UÑ=UˆØ�
‰
�; 
¨DÕ1r   c                ón  — |j                  «       }|| j                  vr|j                  «       | j                  |<   | j                  j	                  t        |||«      «       t        | j                  «      t        |j                  «      k7  r)t        |j                  j                  «       «      | _        y y r>   )Úhashr@   Úcopyr?   Úappendr5   ÚlenrA   Ú	pen_tableÚlistÚvalues)r   rL   r   ÚargsÚ	prop_hashs        r   rH   zRecorder.storen   s‰   € Ø—O‘OÓ%ˆ	Ø˜D×,Ñ,Ñ,Ø*4¯/©/Ó*;ˆD×Ñ˜YÑ'Ø�‰×ÑœZ¨°YÀÓEÔFÜˆt�z‰z‹?œc *×"6Ñ"6Ó7Ò7Ü˜j×2Ñ2×9Ñ9Ó;Ó<ˆD�Jð 8r   N©r#   r$   )r#   rE   r"   r%   )rL   r.   r   r   r#   r$   )	r'   r(   r)   r*   rC   rF   r   r!   rH   r   r   r   r<   r<   K   sA   „ ñó'ó
7óKð2Ø$ð2Ø-;ð2ØEIð2à	ó2ô=r   r<   c                  óT   — e Zd ZdZdd„Zdd„ZeZdd„Zdd„Zdd„Z	dd„Z
dd„Zdd	„Zy
)rE   z‡This class replays the recordings of the :class:`Recorder` class on another
    backend. The class can modify the recorded output.
    c                ó>   — || _         || _        t        «       | _        y r>   )r?   r@   r   Ú_bbox)r   Úrecordsr   s      r   rC   zPlayer.__init__|   s   € Ø*1ˆŒØ2<ˆÔÜ"“_ˆ�
r   c                óº   — t        j                  | j                  «      }| j                  || j                  «      }| j
                  j                  «       |_        |S )zAReturns a new :class:`Player` instance with a copy of recordings.)rO   Údeepcopyr?   Ú	__class__r@   rZ   )r   r[   rF   s      r   Ú__copy__zPlayer.__copy__�   sA   € ä—-‘- §¡Ó.ˆØ—‘ ¨×)9Ñ)9Ó:ˆØ—z‘z—‘Ó(ˆŒØˆr   c              #  ó–   K  — | j                   }| j                  D ]*  }|j                  ||j                     |j                  f–— Œ, y­w)aR  Yields all recordings as `(RecordType, Properties, Data)` tuples.

        The content of the `Data` field is determined by the enum :class:`RecordType`:

        - :attr:`RecordType.POLYLINE` returns a :class:`NumpyPoints2d` instance
        - :attr:`RecordType.FILLED_POLYGON` returns a tuple of :class:`NumpyPath2d` instances

        N)r@   r?   r6   r8   r9   )r   ÚpropsÚrecords      r   Ú
recordingszPlayer.recordingsŠ   sA   è ø€ ð × Ñ ˆØ—m”mˆFØ—+‘+˜u V×%9Ñ%9Ñ:¸F¿K¹KÐGÓGñ $ùs   ‚AA	c                óf   — | j                   j                  s| j                  «        | j                   S )zwReturns the bounding box of all recorded polylines and polygons as
        :class:`~ezdxf.math.BoundingBox2d`.
        )rZ   Úhas_dataÚupdate_bboxrB   s    r   ÚbboxzPlayer.bbox—   s'   € ð �z‰z×"Ò"Ø×ÑÔØ�z‰zÐr   c                ó8  — g }| j                   D ]y  }|j                  t        j                  k(  r*|j	                  |j
                  j                  «       «       ŒJ|j
                  D ]!  }|j	                  |j                  «       «       Œ# Œ{ t        |«      | _        y r>   )	r?   r6   r.   r1   Úextendr9   Úextentsr   rZ   )r   r   rb   Úpaths       r   rf   zPlayer.update_bboxŸ   sn   € ØˆØ—m”mˆFØ�{‰{œj×1Ñ1Ò1Ø—‘˜fŸk™k×1Ñ1Ó3Õ4à"ŸKœK�DØ—M‘M $§,¡,£.Õ1ñ (ð	 $ô # 6Ó*ˆ�
r   c                óÐ  — t        «       }| j                  }| j                  D ]¼  }|j                  |j                  |«      }|j
                  t        j                  k(  r+|j                  ||j                  j                  «       «       Œg|j                  D �cg c]  }|j                  «       ‘Œ }}|j                  |||j
                  t        j                  k(  ¬«       Œ¾ yc c}w )z(Replay the recording on another backend.)r    N)r   r@   r?   Úgetr8   r6   r.   r1   r   r9   ÚverticesÚ	to_path2dr!   r2   )r   ÚbackendÚcurrent_propsra   rb   Úpr   s          r   ÚreplayzPlayer.replay©   s³   € ä"›ˆØ× Ñ ˆØ—m”mˆFØ!ŸI™I f×&:Ñ&:¸MÓJˆMØ�{‰{œj×1Ñ1Ò1Ø×%Ñ% m°V·[±[×5IÑ5IÓ5KÕLà06·²Ó<±¨1˜Ÿ™�°�Ð<Ø×"Ñ"Ø! 5°·±Ä
×@WÑ@WÑ1Wð #õ ñ $ùò
 =s   ÂC#c                óx  — | j                   D ]]  }|j                  t        j                  k(  r|j                  j                  |«       Œ<|j                  D ]  }|j                  |«       Œ Œ_ | j                  j                  r8t        |j                  | j                  j                  «       «      «      | _        yy)zpTransforms the recordings by a transformation matrix `m` of type
        :class:`~ezdxf.math.Matrix44`.
        N)r?   r6   r.   r1   r9   Útransform_inplacerZ   re   r   Úfast_2d_transformÚrect_vertices)r   Úmrb   rk   s       r   Ú	transformzPlayer.transform·   sŠ   € ð —m”mˆFØ�{‰{œj×1Ñ1Ò1Ø—‘×-Ñ-¨aÕ0à"ŸKœK�DØ×*Ñ*¨1Õ-ñ (ð	 $ð �:‰:×Òä& q×':Ñ':¸4¿:¹:×;SÑ;SÓ;UÓ'VÓWˆD�Jð r   c                óâ  — g }g }t        «       }| j                  }| j                  D ]ƒ  }|j                  t        j
                  k(  rS|j                  |j                  |«      }t        j                  |j                  «       «      }|j                  ||f«       Œs|j                  |«       Œ… |j                  d„ d¬«       |D �cg c]  }|d   ‘Œ	 }}|j                  |«       || _        yc c}w )zËSort filled paths by descending luminance (from light to dark).

        This also changes the plot order in the way that all filled paths are plotted
        before polylines and outline paths.
        c                ó   — | d   S )Nr   r   )Úrs    r   Ú<lambda>z*Player.sort_filled_paths.<locals>.<lambda>Ø   s   €  A a¢Dr   T)ÚkeyÚreverser	   N)r   r@   r?   r6   r.   r2   rm   r8   r   Ú	luminanceÚresolve_fill_colorrP   Úsortri   )	r   ÚfillingsÚoutlinesÚcurrentra   rb   r~   Úsort_recr[   s	            r   Úsort_filled_pathszPlayer.sort_filled_pathsÆ   sÍ   € ð ˆØˆÜ“,ˆØ× Ñ ˆØ—m”mˆFØ�{‰{œj×5Ñ5Ò5ØŸ)™) F×$8Ñ$8¸'ÓB�Ü×&Ñ& w×'AÑ'AÓ'CÓD�Ø—‘  f Õ.à—‘ Õ'ð $ð 	�‰™.°$ˆÔ7Ù/7Ó8©x 8�8˜A“;¨xˆÐ8Ø�‰�xÔ Øˆ�ùò 9s   ÃC,N)r[   zlist[DataRecord]r   zdict[int, Properties])r#   r   )r#   z,Iterator[tuple[RecordType, Properties, Any]])r#   r   rW   )rp   r   r#   r$   )rx   r   r#   r$   )r'   r(   r)   r*   rC   r_   rO   rc   rg   rf   rs   ry   r‡   r   r   r   rE   rE   w   s8   „ ñó%ó
ð €DóHóó+óóXô r   rE   c                óp  — t        |«      dk  rd}t        |«      dk  rd}t        j                  ||d«      }|r+|t        j                  t	        j
                  |«      «      z  }|j                  | j                  «       «      }t        |«      j                  \  }}|t        j                  | | d«      z  S )zdReturns a matrix to place the bbox in the first quadrant of the coordinate
    system (+x, +y).
    g•Ö&è.>ç      ð?r   )Úabsr   ÚscaleÚz_rotateÚmathÚradiansrv   rw   r   ÚextminÚ	translate)rg   ÚsxÚsyÚrotationrx   ÚcornersÚtxÚtys           r   Úplacement_matrixr—   Þ   s¢   € ô ˆ2ƒw�‚~ØˆÜ
ˆ2ƒw�‚~ØˆÜ�‰�r˜2˜sÓ#€AÙØ	ŒX×ÑœtŸ|™|¨HÓ5Ó6Ñ6ˆØ×!Ñ! $×"4Ñ"4Ó"6Ó7€GÜ˜7Ó#×*Ñ*�F€BˆØŒx×!Ñ! 2 #¨ s¨AÓ.Ñ.Ð.r   )r‰   r‰   g        )
rg   r   r‘   Úfloatr’   r˜   r“   r˜   r#   r   )!Ú
__future__r   Útypingr   r   r   r   Útyping_extensionsr   r+   rO   r/   r�   Údepsr
   r   r   r   r   r   r   r   Úezdxf.npshapesr   r   ÚABCr   ÚEnumr.   r5   r<   rE   r—   r   r   r   Ú<module>r       s¬   ðõ #ß 6Ó 6Ý "Û 
Û Û Û ÷õ ÷ (ß 5ôˆc�g‰gô ôD �—‘ô  ô�ô ô)=ˆwô )=÷Xd ñ d ðP NQð/Ø
ð/Ø"ð/Ø.3ð/ØEJð/àô/r   