
    hs>                       % S SK Jr  S SKJrJrJrJrJrJr  S SK	J
r
Jr  S SKrS SKrS SKJrJrJrJr  S SKJrJrJr  S SKJr  S SKJr  S	S
KJrJr  S	SKJr  S	SK J!r!  S	SK"J#r#   " S S\RH                  5      r% " S S\%5      r& " S S\%5      r' " S S\%5      r( " S S\%5      r) " S S\%5      r* " S S\5      r+ " S S\5      r,\\!/\,4   r-S\.S'    " S  S!5      r/        S#S" jr0g)$    )annotations)IterableIteratorSequenceCallableOptional
NamedTuple)Self	TypeAliasN)BoundingBox2dMatrix44Vec2UVec)NumpyPath2dNumpyPoints2dEmptyShapeError)take2)ClippingRect   )BackendInterface	ImageData)Configuration)BackendProperties)Colorc                  n    \ rS rSrSS jr\R                  SS j5       r\R                  S	S j5       rSr	g)

DataRecord   c                     SU l         SU l        g )Nr    )property_hashhandleselfs    O/var/www/html/env/lib/python3.13/site-packages/ezdxf/addons/drawing/recorder.py__init__DataRecord.__init__   s    "#    c                    g N r"   s    r$   bboxDataRecord.bbox        r'   c                    g r)   r*   r#   ms     r$   transform_inplaceDataRecord.transform_inplace$   r-   r'   )r!   r    NreturnNoner4   r   r0   r   r4   r5   )
__name__
__module____qualname____firstlineno__r%   abcabstractmethodr+   r1   __static_attributes__r*   r'   r$   r   r      s;     	  	 r'   r   c                  @   ^  \ rS rSrSU 4S jjrSS jrSS jrSrU =r$ )	PointsRecord)   c                .   > [         TU ]  5         Xl        g r)   )superr%   points)r#   rD   	__class__s     r$   r%   PointsRecord.__init__+   s    %+r'   c                j     U R                   R                  5       $ ! [         a     [        5       $ f = fr)   )rD   r+   r   r   r"   s    r$   r+   PointsRecord.bbox/   s4    	;;##%% 		    
22c                :    U R                   R                  U5        g r)   )rD   r1   r/   s     r$   r1   PointsRecord.transform_inplace6   s    %%a(r'   )rD   )rD   r   r4   r5   r6   r7   	r8   r9   r:   r;   r%   r+   r1   r>   __classcell__rE   s   @r$   r@   r@   )   s    ,) )r'   r@   c                  @   ^  \ rS rSrSU 4S jjrSS jrSS jrSrU =r$ )	SolidLinesRecord:   c                .   > [         TU ]  5         Xl        g r)   )rC   r%   lines)r#   rS   rE   s     r$   r%   SolidLinesRecord.__init__;   s    $)
r'   c                j     U R                   R                  5       $ ! [         a     [        5       $ f = fr)   )rS   r+   r   r   r"   s    r$   r+   SolidLinesRecord.bbox?   s2    	::??$$ 		rI   c                :    U R                   R                  U5        g r)   )rS   r1   r/   s     r$   r1   "SolidLinesRecord.transform_inplaceF   s    

$$Q'r'   )rS   )rS   r   r4   r5   r6   r7   rL   rN   s   @r$   rP   rP   :   s    *( (r'   rP   c                  @   ^  \ rS rSrSU 4S jjrSS jrSS jrSrU =r$ )	
PathRecordJ   c                .   > [         TU ]  5         Xl        g r)   )rC   r%   path)r#   r]   rE   s     r$   r%   PathRecord.__init__K   s    !%	r'   c                j     U R                   R                  5       $ ! [         a     [        5       $ f = fr)   )r]   r+   r   r   r"   s    r$   r+   PathRecord.bboxO   s2    	99>>## 		rI   c                :    U R                   R                  U5        g r)   )r]   r1   r/   s     r$   r1   PathRecord.transform_inplaceV   s    		##A&r'   )r]   )r]   r   r4   r5   r6   r7   rL   rN   s   @r$   rZ   rZ   J   s    &' 'r'   rZ   c                  @   ^  \ rS rSrSU 4S jjrSS jrSS jrSrU =r$ )	FilledPathsRecordZ   c                .   > [         TU ]  5         Xl        g r)   )rC   r%   paths)r#   rg   rE   s     r$   r%   FilledPathsRecord.__init__[   s    ,1
r'   c                    [        5       nU R                   H4  n[        U5      (       d  M  UR                  UR	                  5       5        M6     U$ r)   )r   rg   lenextendextents)r#   r+   r]   s      r$   r+   FilledPathsRecord.bbox_   s9    JJD4yyDLLN+  r'   c                L    U R                    H  nUR                  U5        M     g r)   )rg   r1   )r#   r0   r]   s      r$   r1   #FilledPathsRecord.transform_inplacef   s    JJD""1% r'   )rg   )rg   Sequence[NumpyPath2d]r4   r5   r6   r7   rL   rN   s   @r$   rd   rd   Z   s    2& &r'   rd   c                  @   ^  \ rS rSrSU 4S jjrSS jrSS jrSrU =r$ )	ImageRecordk   c                :   > [         TU ]  5         Xl        X l        g r)   )rC   r%   boundary
image_data)r#   ru   rv   rE   s      r$   r%   ImageRecord.__init__l   s    '/%/r'   c                j     U R                   R                  5       $ ! [         a     [        5       $ f = fr)   )ru   r+   r   r   r"   s    r$   r+   ImageRecord.bboxq   s4    	==%%'' 		rI   c                x    U R                   R                  U5        U R                  =R                  U-  sl        g r)   )ru   r1   rv   	transformr/   s     r$   r1   ImageRecord.transform_inplacex   s)    ''*!!Q&!r'   )ru   rv   )ru   r   rv   r   r4   r5   r6   r7   rL   rN   s   @r$   rr   rr   k   s    0
' 'r'   rr   c                      \ 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S j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S jrSS jrSS jrSS jrSrg)!Recorder}   z)Records the output of the Frontend class.c                \    [        5       U l        SU l        / U l        [	        5       U l        g )N#000000)r   config
backgroundrecordsdict
propertiesr"   s    r$   r%   Recorder.__init__   s"    #o!*)+8<r'   c                    [        5       nU R                  Ul        U R                  Ul        U R                  Ul        U R                  Ul        SUl        U$ )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()

T)Playerr   r   r   r   has_shared_recordingsr#   players     r$   r   Recorder.player   sF      OO OO'+$r'   c                    Xl         g r)   )r   )r#   r   s     r$   	configureRecorder.configure   s    r'   c                    Xl         g r)   )r   )r#   colors     r$   set_backgroundRecorder.set_background   s    r'   c                    [        US S 5      nX1l        UR                  Ul        U R                  R	                  U5        X R
                  U'   g )N   )hashr    r!   r   appendr   )r#   recordr   	prop_hashs       r$   storeRecorder.store   sE     BQ(	("))F#%/	"r'   c                N    U R                  [        [        U45      5      U5        g r)   r   r@   r   )r#   posr   s      r$   
draw_pointRecorder.draw_point   s    

<sf 56
Cr'   c                N    U R                  [        [        X45      5      U5        g r)   r   )r#   startendr   s       r$   	draw_lineRecorder.draw_line   s    

<ul ;<jIr'   c                h   ^ SU4S jjnU R                  [        [        U" 5       5      5      U5        g )Nc               3  4   >#    T H  u  pU v   Uv   M     g 7fr)   r*   )serS   s     r$   flatten*Recorder.draw_solid_lines.<locals>.flatten   s      s   )r4   zIterator[Vec2])r   rP   r   )r#   rS   r   r   s    `  r$   draw_solid_linesRecorder.draw_solid_lines   s%    	
 	

#M')$<=zJr'   c                h    [        U[        5      (       d   eU R                  [        U5      U5        g r)   )
isinstancer   r   rZ   )r#   r]   r   s      r$   	draw_pathRecorder.draw_path   s(    $,,,,

:d#Z0r'   c                h    [        U[        5      (       d   eU R                  [        U5      U5        g r)   )r   r   r   r@   )r#   rD   r   s      r$   draw_filled_polygonRecorder.draw_filled_polygon   s*     &-0000

<'4r'   c                    [        U5      n[        U5      S:X  a  g [        US   [        5      (       d   eU R	                  [        U5      U5        g )Nr   )tuplerj   r   r   r   rd   )r#   rg   r   s      r$   draw_filled_pathsRecorder.draw_filled_paths   sF     eu:?%(K0000

$U+Z8r'   c                    [         R                  " UR                  5      nUR                  UR                  5        U R                  [        X15      U5        g r)   )copydeepcopypixel_boundary_pathr1   r{   r   rr   )r#   rv   r   ru   s       r$   
draw_imageRecorder.draw_image   s=    ==!?!?@"":#7#78

;x4jAr'   c                    g r)   r*   )r#   entityr   s      r$   enter_entityRecorder.enter_entity       r'   c                    g r)   r*   )r#   r   s     r$   exit_entityRecorder.exit_entity   r   r'   c                    [        5       er)   )NotImplementedErrorr"   s    r$   clearRecorder.clear   s    !##r'   c                    g r)   r*   r"   s    r$   finalizeRecorder.finalize   r   r'   )r   r   r   r   Nr3   )r4   r   )r   r   r4   r5   )r   r   r4   r5   )r   r   r   r   r4   r5   )r   r   r   r   r4   r5   )r   r   r   r   r   r   r4   r5   )rS   zIterable[tuple[Vec2, Vec2]]r   r   r4   r5   )r]   r   r   r   r4   r5   )rD   r   r   r   r4   r5   )rg   zIterable[NumpyPath2d]r   r   r4   r5   )rv   r   r   r   r4   r5   )r8   r9   r:   r;   __doc__r%   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r>   r*   r'   r$   r~   r~   }   s    3? 0DJK0K>OK	K15#51B5	59*98I9	9B$r'   r~   c                  2    \ rS rSr% SrS\S'   SrS\S'   Srg	)
Override   zRepresents the override state for a data record.

Attributes:
    properties: original or modified :class:`BackendProperties`
    is_visible: override visibility e.g. switch layers on/off

r   r   Tbool
is_visibler*   N)r8   r9   r:   r;   r   __annotations__r   r>   r*   r'   r$   r   r      s     "!Jr'   r   r   OverrideFuncc                  |    \ rS rSrSrSS jrSS jr\rSS jr S     SS jjr	SS jr
SS	 jrSS
 jrSS jrSrg)r      zIPlays the recordings of the :class:`Recorder` backend on another backend.c                    [        5       U l        SU l        / U l        [	        5       U l        [        5       U l        SU l        g )Nr   F)	r   r   r   r   r   r   r   _bboxr   r"   s    r$   r%   Player.__init__   s3    #o!*)+8<"_
+0"r'   c                    U R                  5       nU R                  Ul        U R                  Ul        [        R                  " U R
                  5      Ul        U R                  Ul        SUl        U$ )z8Returns a copy of the player with non-shared recordings.F)rE   r   r   r   r   r   r   r   r   s     r$   __copy__Player.__copy__   sR    ! OOt||4 OO',$r'   c              #     #    U R                   nU R                   H.  n[        / XR                     SS QUR                  P76 nX#4v   M0     g7f)zBYields all recordings as `(DataRecord, BackendProperties)` tuples.Nr   )r   r   r   r    r!   )r#   propsr   r   s       r$   
recordingsPlayer.recordings  sU     llF* ++,Ra028--J $$	 #s   AANc                R   UR                  U R                  5        UR                  U R                  5        U R	                  5        GH  u  p4U(       a'  U" U5      nUR
                  (       d  M(  UR                  n[        U[        5      (       a  [        UR                  5      nUS:X  a  Mf  US:  a  UR                  UR                  U5        M  UR                  R                  5       n[        U5      S:X  a  UR                  US   U5        M  UR                  US   US   U5        M  [        U[        5      (       a6  UR!                  [#        UR$                  R                  5       5      U5        GM0  [        U[&        5      (       a  UR)                  UR*                  U5        GMd  [        U[,        5      (       a  UR/                  UR0                  U5        GM  [        U[2        5      (       d  GM  UR5                  UR6                  U5        GM     UR9                  5         g)a  Replay the recording on another backend that implements the
:class:`BackendInterface`. The optional `override` function can be used to
override the properties and state of data records, it gets the :class:`BackendProperties`
as input and must return an :class:`Override` instance.
r      r   N)r   r   r   r   r   r   r   r   r@   rj   rD   r   verticesr   r   rP   r   r   rS   rZ   r   r]   rd   r   rg   rr   r   rv   r   )r#   backendoverrider   r   statecountr   s           r$   replayPlayer.replay  s    	$++&t/"&//"3F ,''"--
&,//FMM*A:19//zJ!==113x=A%&&x{J?%%hqk8A;
KF$455((v||/D/D/F)GTFJ//!!&++z:F$566))&,,
CFK00""6#4#4jA3 #44 	r'   c                    U R                    H  nUR                  U5        M     U R                  R                  (       a8  [	        UR                  U R                  R                  5       5      5      U l        gg)zhTransforms the recordings inplace by a transformation matrix `m` of type
:class:`~ezdxf.math.Matrix44`.
N)r   r1   r   has_datar   fast_2d_transformrect_vertices)r#   r0   r   s      r$   r{   Player.transform5  sX     llF$$Q' # ::&q':':4::;S;S;U'VWDJ r'   c                p    U R                   R                  (       d  U R                  5         U R                   $ )zNReturns the bounding box of all records as :class:`~ezdxf.math.BoundingBox2d`.)r   r   update_bboxr"   s    r$   r+   Player.bbox@  s%    zz""zzr'   c                    [        5       nU R                   H"  nUR                  UR                  5       5        M$     Xl        g r)   )r   r   rk   r+   r   )r#   r+   r   s      r$   r   Player.update_bboxF  s.    llFKK& #
r'   c                    [        [        U5      [        U5      /5      n[        U R                  XC5      U l        [        5       U l        g)ai  Crop recorded shapes inplace by a rectangle defined by two points.

The argument `distance` defines the approximation precision for paths which have
to be approximated as polylines for cropping but only paths which are really get
cropped are approximated, paths that are fully inside the crop box will not be
approximated.

Args:
    p1: first corner of the clipping rectangle
    p2: second corner of the clipping rectangle
    distance: maximum distance from the center of the curve to the
        center of the line segment between two approximation points to
        determine if a segment should be subdivided.

N)r   r   crop_records_rectr   r   )r#   p1p2distance	crop_rects        r$   r   Player.crop_rectL  s6      "48T"X"67	(yK"_
r'   )r   r   r   r   r   r   r3   )r4   r
   )r4   z.Iterator[tuple[DataRecord, BackendProperties]]r)   )r   r   r   zOptional[OverrideFunc]r4   r5   r7   r6   )r   r   r   r   r   floatr4   r5   )r8   r9   r:   r;   r   r%   r   r   r   r   r{   r+   r   r   r>   r*   r'   r$   r   r      sU    S1 D% MQ%'%3I%	%N	X%r'   r   c                R  ^^^ SU4S jjn    SUU4S jjnTR                   (       d  U $ / nTR                  nUR                  S:  d  UR                  S:  a  U$ [	        TR                  5       5      mU  GH+  nUR                  5       nTR                  U5      (       d  M,  TR                  UR                  5      (       a3  TR                  UR                  5      (       a  UR                  U5        M  [        U[        5      (       aK  U" UR                  5      u  pU" U	5      U
-   nU(       a#  [        U5      Ul        UR                  U5        M  M  [        U[         5      (       ae  TR#                  UR$                  /T5       HA  n[!        U5      nUR&                  Ul        UR(                  Ul        UR                  U5        MC     GMY  [        U[*        5      (       Ga
  [-        UR.                  5      nUS:X  a  UR                  U5        GM  US:X  ay  UR.                  R1                  5       u  nnTR3                  UU5       HC  nU(       d  M  [4        R4                  " U5      n[7        U5      Ul        UR                  U5        ME     GM  TR9                  UR.                  5       H:  nU(       d  M  [4        R4                  " U5      nUUl        UR                  U5        M<     GMy  [        U[:        5      (       a}  / n[=        UR>                  R1                  5       5       H0  u  nnTR3                  UU5       H  nURA                  U5        M     M2     [7        U5      Ul        UR                  U5        GM  [        U[B        5      (       a  GM#  [E        S5      e   U$ )	z,Crop recorded shapes inplace by a rectangle.c                N  > / n/ nU  H  n[        UR                  5       5      nTR                  U5      (       d  M4  TR                  UR                  5      (       a3  TR                  UR
                  5      (       a  UR                  U5        M  UR                  U5        M     X!4$ r)   )r   rl   has_intersectioninsideextminextmaxr   )np_paths_inside_cropnp_pathr+   r   s        r$   
sort_paths%crop_records_rect.<locals>.sort_pathsf  s    %'#%G !23D--d33!!$++..93C3CDKK3P3Pw'W%   ~r'   c                :   > [        TR                  U T5      5      $ r)   )listclip_filled_paths)r  clipperr   s    r$   
crop_paths%crop_records_rect.<locals>.crop_pathsw  s     G--hABBr'   g-q=r   r   zinvalid record type)r  rp   )r  rp   r4   zlist[NumpyPath2d])#r   sizexyr   r   r+   r   r  r  r  r   r   rd   rg   r   rZ   
clip_pathsr]   r    r!   r@   rj   rD   r   	clip_liner   r   clip_polygonrP   r   rS   rk   rr   
ValueError)r   r   r   r  r  cropped_recordsr  r   
record_boxpaths_to_cropr  cropped_pathsppath_recordr   r   r   segment_recordpolygonrD   r  s    ``                  @r$   r   r   a  s   
"C'C	C C (*O>>Dvv~%92245G[[]
))*55J--..93C3CJDUDU3V3V""6*f/00$.v||$<!M&}5>M$]3&&v.  
++''x@(m,2,@,@)%+]]"&&{3	 A
 --&Ez&&v.!}}--/1&00A6G" "ii/G%27%;GN#**73  7  '33FMMBG" "ii/G%,GN#**73  C  011!#Ffll33561&00A6GMM'*  7 7 )0FL""6*,,
 233q r r'   )r   list[DataRecord]r   r   r   r   r4   r   )1
__future__r   typingr   r   r   r   r   r	   typing_extensionsr
   r   r   r<   
ezdxf.mathr   r   r   r   ezdxf.npshapesr   r   r   ezdxf.toolsr   ezdxf.tools.clipping_portalr   r   r   r   r   r   r   r   
type_hintsr   ABCr   r@   rP   rZ   rd   rr   r~   r   r   r   r   r   r*   r'   r$   <module>r*     s    #  .  
 : : F F  4 0 ! )  ): )"(z ( ' ' &
 &"'* '$[ [|
z 
 #$5#6#@Ai As% s%l^^*7^CH^^r'   