Ë
    £èhö-  ã                  ó°   — d dl mZ d dlmZm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mZ ddlmZ ddlmZ dd	lmZ  G d
„ d«      Zdd„Zdd„Zdd„Zdd„Zy)é    )Úannotations)ÚSequenceÚIteratorNé   )ÚVec2ÚPathÚNULLVEC2ÚConstructionCircleÚBezier4P)ÚRGBÚ
PropertiesÚFillType)ÚBackend)ÚPolygonBuffer)ÚPagec                  ó´  — e Zd ZdZd-d„Zed.d„«       Zed.d„«       Zd/d„Zd0d„Z	d1d„Z
	 	 	 	 	 	 	 	 	 	 d2d„Zd3d	„Zd4d
„Z	 	 d5	 	 	 	 	 	 	 	 	 d6d„Z	 	 	 	 	 	 	 	 	 	 d6d„Zd7d„Zd3d„Zd3d„Zd3d„Zd3d„Zd8d„Zd9d„Zd9d„Zd3d„Zd3d„Zd:d„Zd:d„Zd;d„Zd<d„Zd=d„Zd>d„Zd3d„Z d?d„Z!d3d„Z"d@d „Z#d@d!„Z$d@d"„Z%dAd#„Z&dBd$„Z'dCd%„Z(dDd&„Z)dDd'„Z*dEd(„Z+dEd)„Z,dFd*„Z-dFd+„Z.y,)GÚPlotteraï  
    The :class:`Plotter` class represents a virtual plotter device.

    The HPGL/2 commands send by the :class:`Interpreter` are processed into simple
    polylines and filled polygons and send to low level :class:`Backend`.

    HPGL/2 uses a units system called "Plot Units":

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

    The Plotter device does not support font rendering and page rotation (RO).
    The scaling commands IP, RP, SC are supported.

    c                óÚ   — || _         || _        t        «       | _        t	        dd«      | _        t        «       | _        d| _        d| _	        d| _
        d| _        t        | _        g | _        y )Ni¥  iI  FT)ÚbackendÚ_output_backendr   Ú_polygon_bufferr   Úpager   Ú
propertiesÚis_pen_downÚis_absolute_modeÚis_polygon_modeÚhas_merge_controlr	   Ú_user_locationÚ_pen_state_stack)Úselfr   s     ú:lib/python3.12/site-packages/ezdxf/addons/hpgl2/plotter.pyÚ__init__zPlotter.__init__%   sa   € ØˆŒØ&ˆÔÜ,›ˆÔÜ˜˜s“OˆŒ	Ü$›,ˆŒØ ˆÔØ $ˆÔØ$ˆÔØ!&ˆÔÜ&ˆÔØ,.ˆÕó    c                ó   — | j                   S )zHReturns the current pen location as point in the user coordinate system.©r   ©r    s    r!   Úuser_locationzPlotter.user_location2   s   € ð ×"Ñ"Ð"r#   c                óz   — | j                   }| j                  j                  |j                  |j                  «      S )z@Returns the current pen location as page point in plotter units.)r'   r   Ú
page_pointÚxÚy©r    Úlocations     r!   Úpage_locationzPlotter.page_location7   s.   € ð ×%Ñ%ˆØ�y‰y×#Ñ# H§J¡J°·
±
Ó;Ð;r#   c                ó&   — t        ||«      | _        y ©N)r   r   )r    Úsize_xÚsize_ys      r!   Ú
setup_pagezPlotter.setup_page=   s   € Ü˜ Ó(ˆ�	r#   c                ó<   — | j                   j                  ||«       y r0   )r   Úset_scaling_points)r    Úp1Úp2s      r!   r5   zPlotter.set_scaling_points@   s   € Ø�	‰	×$Ñ$ R¨Õ,r#   c                ó<   — | j                   j                  ||«       y r0   )r   Úset_scaling_points_relative_1)r    Úxp1Úyp1s      r!   r9   z%Plotter.set_scaling_points_relative_1C   s   € Ø�	‰	×/Ñ/°°SÕ9r#   c                ó@   — | j                   j                  ||||«       y r0   )r   Úset_scaling_points_relative_2)r    r:   r;   Úxp2Úyp2s        r!   r=   z%Plotter.set_scaling_points_relative_2F   s   € ð 	�	‰	×/Ñ/°°S¸#¸sÕCr#   c                ó8   — | j                   j                  «        y r0   )r   Úreset_scalingr&   s    r!   rA   zPlotter.reset_scalingK   s   € Ø�	‰	×ÑÕ!r#   c                ó>   — | j                   j                  |||«       y r0   )r   Úset_ucs)r    ÚoriginÚscale_xÚscale_ys       r!   Úset_point_factorzPlotter.set_point_factorN   s   € Ø�	‰	×Ñ˜& '¨7Õ3r#   c                óD   — | j                   j                  ||||||«       y r0   )r   Úset_isotropic_scaling)r    Úx_minÚx_maxÚy_minÚy_maxÚleftÚbottoms          r!   rI   zPlotter.set_isotropic_scalingQ   s    € ð 	�	‰	×'Ñ'¨¨u°e¸UÀDÈ&ÕQr#   c                ó@   — | j                   j                  ||||«       y r0   )r   Úset_anisotropic_scaling)r    rJ   rK   rL   rM   s        r!   rQ   zPlotter.set_anisotropic_scaling\   s   € ð 	�	‰	×)Ñ)¨%°¸¸uÕEr#   c                ó   — || _         y r0   )r   ©r    Ústatuss     r!   Úset_merge_controlzPlotter.set_merge_controla   s
   € Ø!'ˆÕr#   c                ó   — d| _         y ©NF©r   r&   s    r!   Úpen_upzPlotter.pen_upd   s
   € Ø ˆÕr#   c                ó   — d| _         y ©NTrX   r&   s    r!   Úpen_downzPlotter.pen_downg   s
   € ØˆÕr#   c                óN   — | j                   j                  | j                  «       y r0   )r   Úappendr   r&   s    r!   Úpush_pen_statezPlotter.push_pen_statej   s   € Ø×Ñ×$Ñ$ T×%5Ñ%5Õ6r#   c                ón   — t        | j                  «      r | j                  j                  «       | _        y y r0   )Úlenr   Úpopr   r&   s    r!   Úpop_pen_statezPlotter.pop_pen_statem   s,   € Üˆt×$Ñ$Ô%Ø#×4Ñ4×8Ñ8Ó:ˆDÕð &r#   c                ób   — | j                   r| j                  |«       y | j                  |«       y r0   )r   Úmove_to_absÚmove_to_relr,   s     r!   Úmove_tozPlotter.move_toq   s'   € Ø× Ò Ø×Ñ˜XÕ&à×Ñ˜XÕ&r#   c                ó   — || _         y r0   r%   ©r    r'   s     r!   re   zPlotter.move_to_absw   s
   € Ø+ˆÕr#   c                ó.   — | xj                   |z  c_         y r0   r%   ri   s     r!   rf   zPlotter.move_to_relz   s   € Ø×Ò˜}Ñ,Ör#   c                ó   — d| _         y r[   ©r   r&   s    r!   Úset_absolute_modezPlotter.set_absolute_mode}   s
   € Ø $ˆÕr#   c                ó   — d| _         y rW   rl   r&   s    r!   Úset_relative_modezPlotter.set_relative_mode€   s
   € Ø %ˆÕr#   c                ó:   — | j                   j                  |«       y r0   )r   Úset_current_pen©r    Úindexs     r!   rq   zPlotter.set_current_penƒ   s   € Ø�‰×'Ñ'¨Õ.r#   c                ó:   — | j                   j                  |«       y r0   )r   Úset_max_pen_countrr   s     r!   ru   zPlotter.set_max_pen_count†   s   € Ø�‰×)Ñ)¨%Õ0r#   c                ó<   — | j                   j                  ||«       y r0   )r   Úset_pen_width)r    rs   Úwidths      r!   rw   zPlotter.set_pen_width‰   ó   € Ø�‰×%Ñ% e¨UÕ3r#   c                ó<   — | j                   j                  ||«       y r0   )r   Úset_pen_color)r    rs   Úcolors      r!   r{   zPlotter.set_pen_colorŒ   ry   r#   c                óŽ   — |dv r$t        | j                  j                  |«      «      }| j                  j	                  |||«       y )N)é   é   )Úmaxr   Úscale_lengthr   Úset_fill_type)r    Ú	fill_typeÚspacingÚangles       r!   r‚   zPlotter.set_fill_type�   s9   € Ø˜ÑÜ˜$Ÿ)™)×0Ñ0°Ó9Ó:ˆGØ�‰×%Ñ% i°¸%Õ@r#   c                óÊ   — d| _         | j                  | _        |dk(  r&| j                  j                  | j                  «       y |dk(  r| j                  j                  «        y y )NTr   r   )r   r   r   Úresetr.   Ú
close_pathrS   s     r!   Úenter_polygon_modezPlotter.enter_polygon_mode”   sV   € Ø#ˆÔØ×+Ñ+ˆŒØ�QŠ;Ø× Ñ ×&Ñ& t×'9Ñ'9Õ:Ø�qŠ[Ø× Ñ ×+Ñ+Õ-ð r#   c                óh   — d| _         | j                  j                  «        | j                  | _        y rW   )r   r   rˆ   r   r   r&   s    r!   Úexit_polygon_modezPlotter.exit_polygon_modeœ   s)   € Ø$ˆÔØ×Ñ×'Ñ'Ô)Ø×+Ñ+ˆ�r#   c                óŒ   — | j                   j                  |«       | j                  | j                  j	                  «       «       y r0   )r   Úset_fill_methodÚplot_filled_polygon_bufferr   Ú	get_paths)r    Úfill_methods     r!   Úfill_polygonzPlotter.fill_polygon¡   s1   € Ø�‰×'Ñ'¨Ô4Ø×'Ñ'¨×(<Ñ(<×(FÑ(FÓ(HÕIr#   c                óV   — | j                  | j                  j                  «       «       y r0   )Úplot_outline_polygon_bufferr   r�   r&   s    r!   Úedge_polygonzPlotter.edge_polygon¥   s   € Ø×(Ñ(¨×)=Ñ)=×)GÑ)GÓ)IÕJr#   c                óh   — |sy | j                   r| j                  |«       y | j                  |«       y r0   )r   Úplot_abs_polylineÚplot_rel_polyline©r    Úpointss     r!   Úplot_polylinezPlotter.plot_polyline¨   s-   € ÙØØ× Ò Ø×"Ñ" 6Õ*à×"Ñ" 6Õ*r#   c                ó
  — |sy | j                   }| j                  |d   «       | j                  rT| j                  j	                  |«      }|j                  d|«       | j                  j                  | j                  |«       y y )Néÿÿÿÿr   )	r.   re   r   r   Úpage_pointsÚinsertr   Údraw_polyliner   )r    r™   Úcurrent_page_locations      r!   r–   zPlotter.plot_abs_polyline°   so   € áØØ $× 2Ñ 2ÐØ×Ñ˜ ™Ô$Ø×Òà—Y‘Y×*Ñ*¨6Ó2ˆFà�M‰M˜!Ð2Ô3à�L‰L×&Ñ& t§¡¸Õ?ð r#   c                óf   — |sy | j                  t        t        | j                  |«      «      «       y r0   )r–   ÚtupleÚrel_to_abs_points_dynamicr'   r˜   s     r!   r—   zPlotter.plot_rel_polyline¾   s,   € áØà×ÑÜÔ+¨D×,>Ñ,>ÀÓGÓHõ	
r#   c                óî   — | j                   rd| j                  }t        dd|«      D �cg c]  }|t        j                  ||«      z   ‘Œ }}| j
                  j                  | j                  |«       y y c c}w )Nr   ç     €v@)r   r'   Ú
arc_anglesr   Úfrom_deg_angler   rŸ   r   )r    ÚradiusÚchord_angleÚcenterÚaÚverticess         r!   Úplot_abs_circlezPlotter.plot_abs_circleÇ   sw   € à×ÒØ×'Ñ'ˆFô $ A u¨kÔ:óá:�Að œ×,Ñ,¨Q°Ó7Ó7Ø:ð ð ð
 �L‰L×&Ñ& t§¡¸ÕAð ùòs   ¨ A2c                ó†  — | j                   }||z
  }|j                  }|j                  }||z   }|t        j                  ||«      z   }	| j                  |	«       | j                  rXt        |||«      D �
cg c]  }
|t        j                  |
|«      z   ‘Œ }}
| j                  j                  | j                  |«       y y c c}
w r0   )r'   Ú	magnitudeÚ	angle_degr   r§   re   r   r¦   r   rŸ   r   )r    rª   Úsweep_angler©   Ústart_pointÚ
radius_vecr¨   Ústart_angleÚ	end_angleÚ	end_pointr«   r¬   s               r!   Úplot_abs_arczPlotter.plot_abs_arcÒ   sÆ   € Ø×(Ñ(ˆØ  6Ñ)ˆ
Ø×%Ñ%ˆØ ×*Ñ*ˆØ +Ñ-ˆ	ØœT×0Ñ0°¸FÓCÑCˆ	à×Ñ˜Ô#Ø×Òô $ K°¸kÔJóáJ�Að œ×,Ñ,¨Q°Ó7Ó7ØJð ð ð �L‰L×&Ñ& t§¡¸ÕAð ùòs   Á4 B>c                óD   — | j                  || j                  z   ||«       y r0   )r·   r'   )r    Ú
center_relr±   r©   s       r!   Úplot_rel_arczPlotter.plot_rel_arcâ   s   € Ø×Ñ˜* t×'9Ñ'9Ñ9¸;ÈÕTr#   c                óü   — | j                   }t        j                  |||«      }|j                  }||z
  j                  }||z
  j                  }||z
  j                  }	t        ||	|«      }
| j                  ||
|«       y r0   )r'   r
   Úfrom_3prª   r°   Úsweeping_angler·   )r    ÚinterÚendr©   ÚstartÚcirclerª   r´   rµ   Úinter_angler±   s              r!   Úplot_abs_arc_three_pointsz!Plotter.plot_abs_arc_three_pointså   sw   € à×"Ñ"ˆÜ#×+Ñ+¨E°5¸#Ó>ˆØ—‘ˆØ˜v‘~×0Ñ0ˆØ˜6‘\×,Ñ,ˆ	Ø˜v‘~×0Ñ0ˆÜ$ [°+¸yÓIˆØ×Ñ˜& +¨{Õ;r#   c                óN   — | j                   }| j                  ||z   ||z   |«       y r0   )r'   rÃ   )r    r¾   r¿   r©   Úcurrents        r!   Úplot_rel_arc_three_pointsz!Plotter.plot_rel_arc_three_pointsð   s'   € à×$Ñ$ˆØ×&Ñ& w°¡¸À#¹À{ÕSr#   c                ó*  — | j                   }| j                  |«       | j                  rj| j                  j	                  |||f«      \  }}}t        |«      }|j                  |||«       | j                  j                  | j                  |gd¬«       y y ©NF©Úfilled)
r.   re   r   r   r�   r   Ú	curve4_tor   Ú
draw_pathsr   )r    Úctrl1Úctrl2r¿   r    Úps         r!   Úplot_abs_cubic_bezierzPlotter.plot_abs_cubic_bezierõ   s†   € à $× 2Ñ 2ÐØ×Ñ˜ÔØ×Òà $§	¡	× 5Ñ 5°u¸eÀSÐ6IÓ JÑˆE�5˜#äÐ*Ó+ˆAØ�K‰K˜˜U EÔ*Ø�L‰L×#Ñ# D§O¡O°a°SÀÐ#ÕGð r#   c                ód   — t        | j                  |||f«      \  }}}| j                  |||«       y r0   )Úrel_to_abs_points_staticr'   rÐ   )r    rÍ   rÎ   r¿   s       r!   Úplot_rel_cubic_bezierzPlotter.plot_rel_cubic_bezier  s9   € ä4Ø×Ñ ¨¨sÐ 3ó
Ñˆˆu�cð 	×"Ñ" 5¨%°Õ5r#   c                óT   — | j                   j                  | j                  |d¬«       y )NTrÉ   ©r   rÌ   r   ©r    Úpathss     r!   rŽ   z"Plotter.plot_filled_polygon_buffer  s   € à�‰×Ñ §¡°¸tÐÕDr#   c                óT   — | j                   j                  | j                  |d¬«       y rÈ   rÕ   rÖ   s     r!   r“   z#Plotter.plot_outline_polygon_buffer  s   € à�‰×Ñ §¡°¸uÐÕEr#   N)r   r   ÚreturnÚNone)rÙ   r   )r1   Úintr2   rÛ   )r6   r   r7   r   rÙ   rÚ   )r:   Úfloatr;   rÜ   rÙ   rÚ   )
r:   rÜ   r;   rÜ   r>   rÜ   r?   rÜ   rÙ   rÚ   )rÙ   rÚ   )rD   r   rE   rÜ   rF   rÜ   rÙ   rÚ   )ç      à?rÝ   )
rJ   rÜ   rK   rÜ   rL   rÜ   rM   rÜ   rÙ   rÚ   )rT   ÚboolrÙ   rÚ   )r-   r   rÙ   rÚ   )r'   r   rÙ   rÚ   )rs   rÛ   rÙ   rÚ   )rs   rÛ   rx   rÜ   rÙ   rÚ   )rs   rÛ   r|   r   rÙ   rÚ   )rƒ   rÛ   r„   rÜ   r…   rÜ   rÙ   rÚ   )rT   rÛ   rÙ   rÚ   )r�   rÛ   rÙ   rÚ   )r™   úSequence[Vec2])r¨   rÜ   r©   rÜ   )rª   r   r±   rÜ   r©   rÜ   )r¹   r   r±   rÜ   r©   rÜ   )r¾   r   r¿   r   r©   rÜ   )rÍ   r   rÎ   r   r¿   r   )r×   zSequence[Path])/Ú__name__Ú
__module__Ú__qualname__Ú__doc__r"   Úpropertyr'   r.   r3   r5   r9   r=   rA   rG   rI   rQ   rU   rY   r\   r_   rc   rg   re   rf   rm   ro   rq   ru   rw   r{   r‚   r‰   r‹   r‘   r”   rš   r–   r—   r­   r·   rº   rÃ   rÆ   rÐ   rÓ   rŽ   r“   © r#   r!   r   r      sœ  „ ñó /ð ò#ó ð#ð ò<ó ð<ó
)ó-ó:ðDØðDØ$ðDØ+0ðDØ7<ðDà	óDó
"ó4ð Øð	Ràð	Rð ð	Rð ð		Rð
 ð	Rð 
ó	RðFØðFØ#(ðFØ16ðFØ?DðFà	óFó
(ó!ó ó7ó;ó'ó,ó-ó%ó&ó/ó1ó4ó4óAó
.ó,ó
JóKó+ó@ó
ó	BóBó Uó	<óTó

Hó6óEôFr#   r   c              #  ó,   K  — |D ]  }| |z  } | –— Œ y­w)z’Returns the absolute location of increment points, each point is an increment
    of the previous point starting at the current pen location.
    Nrå   ©rÅ   r™   Úpoints      r!   r£   r£     s!   è ø€ ó ˆØ�5ÑˆØ‹ñ ùs   ‚c              #  ó(   K  — |D ]	  }| |z   –— Œ y­w)zpReturns the absolute location of increment points, all points are relative
    to the current pen location.
    Nrå   rç   s      r!   rÒ   rÒ     s   è ø€ ó ˆØ˜‰oÓñ ùs   ‚c              #  óª   K  — t        dt        d|«      «      }t        t        ||z  «      «      }||z  }t	        |dz   «      D ]  }| ||z  z   –— Œ y ­w)Ng     €f@rÝ   r   )Úminr€   ÚabsÚroundÚrange)rÀ   r±   r©   ÚcountÚdeltars   s         r!   r¦   r¦   "  sY   è ø€ ä�eœS  kÓ2Ó3€KÜ”�k KÑ/Ó0Ó1€EØ˜%Ñ€EÜ�u˜q‘yÖ!ˆØ�e˜e‘mÑ#Ó#ñ "ùs   ‚AAc                óÈ   — | dz  } |dz  }|dz  }|| z
  }| |z
  }||z
  }t        j                  t        |«      t        |«      z   t        |«      «      r|S |dk  rd|z   S |dz
  S )zaReturns the sweeping angle from start angle to end angle passing the
    intermediate angle.
    r¥   r   )ÚmathÚiscloserì   )rÀ   Úintermediater¿   r…   Úi_to_sÚi_to_es         r!   r½   r½   +  s|   € ð �E‰M€EØ %Ñ'€LØ
�‰+€CØ�%‰K€EØ�\Ñ!€FØ�<Ñ€FÜ‡|�|”C˜“K¤# f£+Ñ-¬s°5«zÔ:Øˆà�1Š9Ø˜5‘=Ð à˜5‘=Ð r#   )rÅ   r   r™   rß   rÙ   zIterator[Vec2])rÀ   rÜ   r±   rÜ   r©   rÜ   rÙ   zIterator[float])rÀ   rÜ   rô   rÜ   r¿   rÜ   rÙ   rÜ   )Ú
__future__r   Útypingr   r   rò   Údepsr   r   r	   r
   r   r   r   r   r   r   r   Úpolygon_bufferr   r   r   r   r£   rÒ   r¦   r½   rå   r#   r!   Ú<module>rû      sN   ðõ #ß %Û ÷õ ÷ 2Ñ 1Ý Ý )Ý ÷zFñ zFózóó$ô!r#   