Ë
    £èh1$  ã                  ó8  — U d dl mZ d dlmZmZmZ d dlmZmZ d dl	Z
d dlmZ d dlZd dlmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZmZ d dlmZmZmZ eZded<   eZ ded<   g d¢Z!ejD                   G d„ d«      «       Z# G d„ de«      Z$ G d„ de$e¬«      Z%dd„Z&y)é    )Úannotations)ÚABCÚabstractmethodÚABCMeta)ÚOptionalÚIterableN)Ú	TypeAlias)ÚConfiguration)Ú
PropertiesÚBackendProperties)ÚColor)Ú
DXFGraphic)ÚVec2ÚMatrix44)ÚNumpyPath2dÚNumpyPoints2dÚsingle_pathsr	   ÚBkPath2dÚ
BkPoints2d)ç      ð?ç        r   r   r   g      ð¿r   r   r   r   r   r   r   iç  r   r   c                  ó\   — e Zd ZU dZded<   ded<   ded<   dZd	ed
<   dZd	ed<   dd„Zdd„Zy)Ú	ImageDataa  Image data.

    Attributes:
        image: an array of RGBA pixels
        transform: the transformation to apply to the image when drawing
            (the transform from pixel coordinates to wcs)
        pixel_boundary_path: boundary path vertices in pixel coordinates, the image
            coordinate system has an inverted y-axis and the top-left corner is (0, 0)
        remove_outside: remove image outside the clipping boundary if ``True`` otherwise
            remove image inside the clipping boundary

    z
np.ndarrayÚimager   Ú	transformr   Úpixel_boundary_pathFÚboolÚuse_clipping_boundaryTÚremove_outsidec                ó<   — | j                   j                  ^}}}||fS )z0Returns the image size as tuple (width, height).)r   Úshape)ÚselfÚimage_heightÚimage_widthÚ_s       ú<lib/python3.12/site-packages/ezdxf/addons/drawing/backend.pyÚ
image_sizezImageData.image_size4   s#   € à(,¯
©
×(8Ñ(8Ð%ˆ�k AØ˜LÐ(Ð(ó    c                óX   — | j                  «       \  }}|t        d<   t        t        «      S )zeReturns the transformation matrix to align the image coordinate system with
        the WCS.
        é   )r'   Ú_IMAGE_FLIP_MATRIXr   )r"   r%   r#   s      r&   Úflip_matrixzImageData.flip_matrix9   s+   € ð Ÿ/™/Ó+‰ˆˆ<Ø!-Ô˜2ÑÜÔ*Ó+Ð+r(   N)Úreturnztuple[int, int])r-   r   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   r'   r,   © r(   r&   r   r      s:   … ñð ÓØÓØ&Ó&Ø"'Ð˜4Ó'Ø€N�DÓó)ô
,r(   r   c                  ó  — e Zd ZdZedd„«       Zedd„«       Zedd„«       Zedd„«       Zedd„«       Z	edd„«       Z
e	 	 	 	 	 	 dd„«       Zedd	„«       Ze	 	 	 	 	 	 dd
„«       Ze	 	 	 	 	 	 dd„«       Zedd„«       Zedd„«       Zedd„«       Zy)ÚBackendInterfacez+Public interface for 2D rendering backends.c                ó   — t         ‚©N©ÚNotImplementedError©r"   Úconfigs     r&   Ú	configurezBackendInterface.configureE   ó   € ä!Ð!r(   c                ó   — t         ‚r7   r8   ©r"   ÚentityÚ
propertiess      r&   Úenter_entityzBackendInterface.enter_entityI   ó
   € ô "Ð!r(   c                ó   — t         ‚r7   r8   )r"   r@   s     r&   Úexit_entityzBackendInterface.exit_entityN   r=   r(   c                ó   — t         ‚r7   r8   ©r"   Úcolors     r&   Úset_backgroundzBackendInterface.set_backgroundR   r=   r(   c                ó   — t         ‚r7   r8   ©r"   ÚposrA   s      r&   Ú
draw_pointzBackendInterface.draw_pointV   r=   r(   c                ó   — t         ‚r7   r8   ©r"   ÚstartÚendrA   s       r&   Ú	draw_linezBackendInterface.draw_lineZ   r=   r(   c                ó   — t         ‚r7   r8   )r"   ÚlinesrA   s      r&   Údraw_solid_linesz!BackendInterface.draw_solid_lines^   ó
   € ô "Ð!r(   c                ó   — t         ‚r7   r8   )r"   ÚpathrA   s      r&   Ú	draw_pathzBackendInterface.draw_pathd   r=   r(   c                ó   — t         ‚r7   r8   )r"   ÚpathsrA   s      r&   Údraw_filled_pathsz"BackendInterface.draw_filled_pathsh   rV   r(   c                ó   — t         ‚r7   r8   ©r"   ÚpointsrA   s      r&   Údraw_filled_polygonz$BackendInterface.draw_filled_polygonn   rV   r(   c                ó   — t         ‚r7   r8   ©r"   Ú
image_datarA   s      r&   Ú
draw_imagezBackendInterface.draw_imaget   r=   r(   c                ó   — t         ‚r7   r8   ©r"   s    r&   ÚclearzBackendInterface.clearx   r=   r(   c                ó   — t         ‚r7   r8   rf   s    r&   ÚfinalizezBackendInterface.finalize|   r=   r(   N©r;   r
   r-   ÚNone©r@   r   rA   r   r-   rk   ©r@   r   r-   rk   ©rH   r   r-   rk   ©rL   r   rA   r   r-   rk   ©rP   r   rQ   r   rA   r   r-   rk   ©rT   zIterable[tuple[Vec2, Vec2]]rA   r   r-   rk   ©rX   r   rA   r   r-   rk   ©r[   úIterable[BkPath2d]rA   r   r-   rk   ©r_   r   rA   r   r-   rk   ©rc   r   rA   r   r-   rk   ©r-   rk   )r.   r/   r0   r1   r   r<   rB   rE   rI   rM   rR   rU   rY   r\   r`   rd   rg   ri   r3   r(   r&   r5   r5   B   sO  „ Ù5àò"ó ð"ð ò"ó ð"ð ò"ó ð"ð ò"ó ð"ð ò"ó ð"ð ò"ó ð"ð ð"Ø0ð"Ø>Oð"à	ò"ó ð"ð
 ò"ó ð"ð ð"Ø'ð"Ø5Fð"à	ò"ó ð"ð
 ð"Ø ð"Ø.?ð"à	ò"ó ð"ð
 ò"ó ð"ð ò"ó ð"ð ò"ó ñ"r(   r5   c                  óî   — e Zd Zdd„Zdd„Zdd„Zdd„Zedd„«       Ze	dd„«       Z
e	dd„«       Ze	dd„«       Z	 	 	 	 	 	 dd	„Zdd
„Z	 	 	 	 	 	 dd„Ze		 	 	 	 	 	 dd„«       Ze	dd„«       Ze	dd„«       Zdd„Zy)ÚBackendc                ó0   — g | _         t        «       | _        y r7   )Úentity_stackr
   r;   rf   s    r&   Ú__init__zBackend.__init__‚   s   € ØACˆÔÜ%2£_ˆ�r(   c                ó   — || _         y r7   )r;   r:   s     r&   r<   zBackend.configure†   s	   € Øˆ�r(   c                ó>   — | j                   j                  ||f«       y r7   )r{   Úappendr?   s      r&   rB   zBackend.enter_entity‰   s   € à×Ñ× Ñ  &¨*Ð!5Õ6r(   c                óT   — | j                   j                  «       \  }}||u sJ d«       ‚y )Nzentity stack mismatch)r{   Úpop)r"   r@   ÚeÚps       r&   rE   zBackend.exit_entity�   s,   € Ø× Ñ ×$Ñ$Ó&‰ˆˆ1Ø�F‰{Ð3Ð3Ó3‰{r(   c                óB   — | j                   r| j                   d   d   S dS )z%Obtain the current entity being drawnéÿÿÿÿr   N)r{   rf   s    r&   Úcurrent_entityzBackend.current_entity‘   s'   € ð ,0×+<Ò+<ˆt× Ñ  Ñ$ QÑ'ÐFÀ$ÐFr(   c                ó   — t         ‚r7   r8   rG   s     r&   rI   zBackend.set_background–   r=   r(   c                ó   — t         ‚)zeDraw a real dimensionless point, because not all backends support
        zero-length lines!
        r8   rK   s      r&   rM   zBackend.draw_pointš   s
   € ô
 "Ð!r(   c                ó   — t         ‚r7   r8   rO   s       r&   rR   zBackend.draw_line¡   r=   r(   c                ó†   — |D ]<  \  }}|j                  |«      r| j                  ||«       Œ*| j                  |||«       Œ> y)zDFast method to draw a bunch of solid lines with the same properties.N)ÚiscloserM   rR   )r"   rT   rA   Úsr‚   s        r&   rU   zBackend.draw_solid_lines¥   s;   € ó ‰DˆAˆqØ�y‰y˜Œ|Ø—‘  :Õ.à—‘˜q ! ZÕ0ñ	 r(   c                óÈ   — t        |«      rWt        |j                  | j                  j                  ¬«      «      }t        |«      }|D ]  }| j                  |||«       |}Œ yy)ah  Draw an outline path (connected string of line segments and Bezier
        curves).

        The :meth:`draw_path` implementation is a fall-back implementation
        which approximates Bezier curves by flattening as line segments.
        Backends can override this method if better path drawing functionality
        is available for that backend.

        ©ÚdistanceN)ÚlenÚiterÚ
flatteningr;   Úmax_flattening_distanceÚnextrR   )r"   rX   rA   ÚverticesÚprevÚvertexs         r&   rY   zBackend.draw_path²   s\   € ô ˆtŒ9ÜØ—‘¨¯©×)LÑ)L�ÓMóˆHô ˜“>ˆDÛ"�Ø—‘˜t V¨ZÔ8Ø‘ñ #ð r(   c                ó�   — |D ]A  }| j                  t        |j                  | j                  j                  ¬«      «      |«       ŒC y)ar  Draw multiple filled paths (connected string of line segments and
        Bezier curves).

        The current implementation passes these paths to the backend, all backends
        included in ezdxf handle holes by the even-odd method.  If a backend requires
        oriented paths (exterior paths in counter-clockwise and holes in clockwise
        orientation) use the function :func:`oriented_paths` to separate and orient the
        input paths.

        The default implementation draws all paths as filled polygons.

        Args:
            paths: sequence of paths
            properties: HATCH properties

        rŽ   N)r`   r   r’   r;   r“   )r"   r[   rA   rX   s       r&   r\   zBackend.draw_filled_pathsÅ   sA   € ó& ˆDØ×$Ñ$ÜØ—O‘O¨T¯[©[×-PÑ-P�OÓQóð õ	ñ r(   c                ó   — t         ‚)zÊFill a polygon whose outline is defined by the given points.
        Used to draw entities with simple outlines where :meth:`draw_path` may
        be an inefficient way to draw such a polygon.
        r8   r^   s      r&   r`   zBackend.draw_filled_polygonà   s
   € ô "Ð!r(   c                ó   — t         ‚)z$Draw an image with the given pixels.r8   rb   s      r&   rd   zBackend.draw_imageê   rC   r(   c                ó   — t         ‚)z–Clear the canvas. Does not reset the internal state of the backend.
        Make sure that the previous drawing is finished before clearing.

        r8   rf   s    r&   rg   zBackend.clearï   s
   € ô "Ð!r(   c                 ó   — y r7   r3   rf   s    r&   ri   zBackend.finalize÷   s   € Ør(   Nrw   rj   rl   rm   )r-   zOptional[DXFGraphic]rn   ro   rp   rq   rr   rs   ru   rv   )r.   r/   r0   r|   r<   rB   rE   Úpropertyr†   r   rI   rM   rR   rU   rY   r\   r`   rd   rg   ri   r3   r(   r&   ry   ry   �   s   „ ó5óó7ó4ð òGó ðGð ò"ó ð"ð ò"ó ð"ð ò"ó ð"ð1Ø0ð1Ø>Oð1à	ó1óð&Ø'ðØ5Fðà	óð6 ð"Ø ð"Ø.?ð"à	ò"ó ð"ð ò"ó ð"ð ò"ó ð"ôr(   ry   )Ú	metaclassc                ó®   — ddl m}m}  |t        | «      «      } ||«      \  }}|D ]  }|j	                  «        Œ |D ]  }|j                  «        Œ ||fS )zƒSeparate paths into exterior paths and holes. Exterior paths are oriented
    counter-clockwise, holes are oriented clockwise.
    r   )Úwinding_deconstructionÚmake_polygon_structure)Ú
ezdxf.pathr    r¡   r   Úcounter_clockwiseÚ	clockwise)r[   r    r¡   ÚpolygonsÚexternal_pathsÚholesrƒ   s          r&   Úoriented_pathsr¨   û   s\   € ÷ Já%¤l°5Ó&9Ó:€Hñ 3°8Ó<Ñ€N�EÛˆØ	×ÑÕð ãˆØ	�‰�ð à˜5Ð Ð r(   )r[   rt   r-   z%tuple[list[BkPath2d], list[BkPath2d]])'Ú
__future__r   Úabcr   r   r   Útypingr   r   ÚnumpyÚnpÚtyping_extensionsr	   ÚdataclassesÚezdxf.addons.drawing.configr
   Úezdxf.addons.drawing.propertiesr   r   Úezdxf.addons.drawing.type_hintsr   Úezdxf.entitiesr   Ú
ezdxf.mathr   r   Úezdxf.npshapesr   r   r   r   r2   r   r+   Ú	dataclassr   r5   ry   r¨   r3   r(   r&   Ú<module>r·      s‘   ðö #ß ,Ñ ,ß %ã Ý 'Û å 5ß IÝ 1Ý %ß %ß CÑ Cà!€ˆ)Ó !Ø%€
ˆIÓ %òÐ ð ×Ñ÷,ð ,ó ð,ôD<"�sô <"ô~wÐ¨'õ wôt!r(   