
    h}                     F   S SK Jr  S SKJrJrJrJr  S SKJr  S SK	r	S SK
r
S SKrS SKrSSKJrJrJrJrJr  SSKJrJr  S SKJrJr   " S	 S
\	R2                  5      r " S S\R6                  5      r " S S\5      r " S S\5      r " S S5      r S         SS jjr g)    )annotations)Sequence
NamedTupleAnyIterator)SelfN   )Vec2PathcolorsMatrix44BoundingBox2d)
PropertiesPen)NumpyPath2dNumpyPoints2dc                  x    \ rS rSrSr\R                  SS j5       r\R                          SS j5       rSr	g)	Backend   zAAbstract base class for implementing a low level output backends.c                    g)a  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      L/var/www/html/env/lib/python3.13/site-packages/ezdxf/addons/hpgl2/backend.pydraw_polylineBackend.draw_polyline    s     	    c                    g)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_pathsBackend.draw_paths-   s     	r   r   Nr   r   r   zSequence[Vec2]returnNoner   r   r!   zSequence[Path]r"   boolr&   r'   )
__name__
__module____qualname____firstlineno____doc__abcabstractmethodr   r#   __static_attributes__r   r   r   r   r      sW    K
 
 	$-;EI	 r   r   c                  z    \ rS rSr\R
                  " 5       r\R
                  " 5       r\R
                  " 5       rSr	g)
RecordType?   r   N)
r*   r+   r,   r-   enumautoPOLYLINEFILLED_PATHSOUTLINE_PATHSr1   r   r   r   r3   r3   ?   s#    yy{H99;LIIKMr   r3   c                  4    \ rS rSr% S\S'   S\S'   S\S'   Srg	)

DataRecordE   r3   typeintproperty_hashr   datar   N)r*   r+   r,   r-   __annotations__r1   r   r   r   r;   r;   E   s    

Ir   r;   c                  Z    \ rS rSrSrS
S jrSS jrSS jr        SS jrSS jr	Sr
g	)RecorderK   zThe :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                .    / U l         0 U l        / U l        g N)_records_properties_pensr   s    r   __init__Recorder.__init__V   s    *,24$&
r   c                B    [        U R                  U R                  5      $ )zReturns 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()

)PlayerrG   rH   rJ   s    r   playerRecorder.player[   s     dmmT%5%566r   c                X    U R                  [        R                  U[        U5      5        g rF   )storer3   r7   r   r   s      r   r   Recorder.draw_polylined   s    

:&&
M&4IJr   c                    [        [        [        U5      5      nU(       a  [        R                  O[        R
                  nU R                  XQU5        g rF   )tuplemapr   r3   r8   r9   rR   )r   r   r!   r"   r@   record_types         r   r#   Recorder.draw_pathsg   s8     Se,-17j--Z=U=U

;D1r   c                p   UR                  5       nX@R                  ;  a  UR                  5       U R                  U'   U R                  R	                  [        XU5      5        [        U R                  5      [        UR                  5      :w  a)  [        UR                  R                  5       5      U l        g g rF   )hashrH   copyrG   appendr;   lenrI   	pen_tablelistvalues)r   rW   r   args	prop_hashs        r   rR   Recorder.storen   s    OO%	,,,*4//*;DY'ZEFtzz?c*"6"677j2299;<DJ 8r   )rI   rH   rG   Nr&   r'   )r&   rN   r%   r(   )rW   r3   r   r   r&   r'   )r*   r+   r,   r-   r.   rK   rO   r   r#   rR   r1   r   r   r   rC   rC   K   sA    '
7K2$2-;2EI2	2=r   rC   c                  l    \ rS rSrSrSS jrSS jr\rSS jrSS jr	SS jr
SS jrSS	 jrSS
 jrSrg)rN   w   zThis class replays the recordings of the :class:`Recorder` class on another
backend. The class can modify the recorded output.
c                :    Xl         X l        [        5       U l        g rF   )rG   rH   r   _bbox)r   recordsr   s      r   rK   Player.__init__|   s    *12<"_
r   c                    [         R                  " U R                  5      nU R                  XR                  5      nU R
                  R                  5       Ul        U$ )zAReturns a new :class:`Player` instance with a copy of recordings.)r[   deepcopyrG   	__class__rH   rh   )r   ri   rO   s      r   __copy__Player.__copy__   s?    --.)9)9:zz(r   c              #     #    U R                   nU R                   H*  nUR                  XR                     UR                  4v   M,     g7f)a2  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)rH   rG   r=   r?   r@   )r   propsrecords      r   
recordingsPlayer.recordings   s>        mmF++u%9%9:FKKGG $s   AA
c                p    U R                   R                  (       d  U R                  5         U R                   $ )zgReturns the bounding box of all recorded polylines and polygons as
:class:`~ezdxf.math.BoundingBox2d`.
)rh   has_dataupdate_bboxrJ   s    r   bboxPlayer.bbox   s'     zz""zzr   c                D   / nU R                    H~  nUR                  [        R                  :X  a+  UR	                  UR
                  R                  5       5        ML  UR
                   H"  nUR	                  UR                  5       5        M$     M     [        U5      U l        g rF   )	rG   r=   r3   r7   extendr@   extentsr   rh   )r   r   rr   paths       r   rw   Player.update_bbox   sn    mmF{{j111fkk1134"KKDMM$,,.1 (	 $ #6*
r   c                   [        5       nU R                  nU R                   H  nUR                  UR                  U5      nUR
                  [        R                  :X  a+  UR                  X$R                  R                  5       5        Mh  UR                   Vs/ s H  oUR                  5       PM     nnUR                  X&UR
                  [        R                  :H  S9  M     gs  snf )z(Replay the recording on another backend.)r"   N)r   rH   rG   getr?   r=   r3   r7   r   r@   vertices	to_path2dr#   r8   )r   backendcurrent_propsrq   rr   pr!   s          r   replayPlayer.replay   s    "  mmF!IIf&:&:MJM{{j111%%m[[5I5I5KL06<1<""!
@W@W1W #  $
 =s   C$c                   U R                    Hb  nUR                  [        R                  :X  a  UR                  R                  U5        M>  UR                   H  nUR                  U5        M     Md     U R                  R                  (       a8  [        UR                  U R                  R                  5       5      5      U l        gg)z`Transforms the recordings by a transformation matrix `m` of type
:class:`~ezdxf.math.Matrix44`.
N)rG   r=   r3   r7   r@   transform_inplacerh   rv   r   fast_2d_transformrect_vertices)r   mrr   r}   s       r   	transformPlayer.transform   s     mmF{{j111--a0"KKD**1- (	 $ ::&q':':4::;S;S;U'VWDJ r   c                   / n/ n[        5       nU R                  nU R                   H  nUR                  [        R
                  :X  aT  UR                  UR                  U5      n[        R                  " UR                  5       5      nUR                  Xe45        Mu  UR                  U5        M     UR                  S SS9  U Vs/ s H  owS   PM	     nnUR                  U5        Xl        gs  snf )zSort 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                    U S   $ )Nr   r   )rs    r   <lambda>*Player.sort_filled_paths.<locals>.<lambda>   s    AaDr   T)keyreverser	   N)r   rH   rG   r=   r3   r8   r   r?   r   	luminanceresolve_fill_colorr\   sortr{   )	r   fillingsoutlinescurrentrq   rr   r   sort_recri   s	            r   sort_filled_pathsPlayer.sort_filled_paths   s     ,  mmF{{j555))F$8$8'B&&w'A'A'CD.' $ 	.$7/78x8A;x8x  9s   C.)rh   rH   rG   N)ri   zlist[DataRecord]r   zdict[int, Properties])r&   r   )r&   z,Iterator[tuple[RecordType, Properties, Any]])r&   r   rd   )r   r   r&   r'   )r   r   r&   r'   )r*   r+   r,   r-   r.   rK   rn   r[   rs   rx   rw   r   r   r   r1   r   r   r   rN   rN   w   s8    %
 DH+X r   rN   c                   [        U5      S:  a  Sn[        U5      S:  a  Sn[        R                  " XS5      nU(       a-  U[        R                  " [        R
                  " U5      5      -  nUR                  U R                  5       5      n[        U5      R                  u  pgU[        R                  " U* U* S5      -  $ )z\Returns a matrix to place the bbox in the first quadrant of the coordinate
system (+x, +y).
g&.>      ?r   )absr   scalez_rotatemathradiansr   r   r   extmin	translate)rx   sxsyrotationr   cornerstxtys           r   placement_matrixr      s     2w~
2w~rs#A	Xt||H566!!$"4"4"67G7#**FBx!!2#sA...r   )r   r   g        )
rx   r   r   floatr   r   r   r   r&   r   )!
__future__r   typingr   r   r   r   typing_extensionsr   r/   r[   r5   r   depsr
   r   r   r   r   r   r   r   ezdxf.npshapesr   r   ABCr   Enumr3   r;   rC   rN   r   r   r   r   <module>r      s    # 6 6 " 
     ( 5cgg D    )=w )=Xd  d P NQ/
/"/.3/EJ//r   