
    h@                    ^   S SK Jr  S SKJrJrJrJrJr  S SKJ	r	  S SK
r
S SK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	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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)  \(       a  S SKJ*r*  \RV                  r+S/r,1 Skr-1 Skr. " S S\"5      r/g)    )annotations)SequenceOptionalUnionTYPE_CHECKINGIterator)SelfN)Auditor
AuditError)const)Tags)colors)pattern)Vec3Matrix44)OCSTransform   )BoundaryPaths)SubclassProcessorDXFNamespace)
DXFGraphic)Gradient)PatternPatternLine)	DXFEntity)default_copy)xref
DXFPolygon>   
            (   *   2   3   H   I   J   J  \   ]   ^   _   `   a   >   +   ,   -   .   1   5   O   c                  h  ^  \ rS rSr% Sr0 rS\S'   S"U 4S jjr\4S#S jjr	 S$   S%U 4S jjjr
S&S jrS&S	 jrS&S
 jrS'U 4S jjrS&S jr\S(S j5       r\S(S j5       r\S(S j5       r\S)S j5       r\R*                  S*S j5       r\R,                  S"S j5       r\" SSS5      \" SSS5      SSSSS4               S+S jjr       S,               S-S jjr S.       S/S jjrS0S jrS1S jrS2S jrS3S4S jjrS5S jr\ RB                  S6S7S jj5       r"S8U 4S  jjr#S!r$U =r%$ )9r   7   z1Base class for the HATCH and the MPOLYGON entity.z dict[int, Union[str, list[str]]]LOAD_GROUP_CODESc                j   > [         TU ]  5         [        5       U l        S U l        S U l        / U l        g N)super__init__r   pathsr   gradientseeds)self	__class__s    H/var/www/html/env/lib/python3.13/site-packages/ezdxf/entities/polygon.pyr>   DXFPolygon.__init__<   s,    "_
*.,002
    c                Z   [        U[        5      (       d   e[        R                  " U R                  5      Ul        [        R                  " U R
                  5      Ul        [        R                  " U R                  5      Ul        [        R                  " U R                  5      Ul        g)z%Copy paths, pattern, gradient, seeds.N)
isinstancer   copydeepcopyr?   r   r@   rA   )rB   entitycopy_strategys      rD   	copy_dataDXFPolygon.copy_dataC   se    &*----}}TZZ0t||4--6}}TZZ0rF   c                (  > [         TU ]  U5      nU(       az  [        UR                  S   SS  5      nU R	                  U5      nU R                  U5      nU R                  U5      nU R                  U5      nUR                  X R                  USS9  U$ )N   r   T)subclassrecover)
r=   load_dxf_attribsr   
subclasses
load_pathsload_gradientload_pattern
load_seedsfast_load_dxfattribsr:   )rB   	processordxftagsrC   s       rD   rS   DXFPolygon.load_dxf_attribsK   s     g&y1	,,Q/34D??4(D%%d+D$$T*D??4(D ****T4 +  
rF   c                V    UR                  S5      nUR                  [        US-   S9n[        U5      (       a  [        R                  " U5      U l
        U[        U5      -   S-   nXU2	 U$ ! [        R                   a(    [        R                  " U R	                  5        S35      ef = f)N[   zH: Missing required DXF tag 'Number of boundary paths (loops)' (code=91).r   start)	tag_indexr   DXFValueErrorDXFStructureErrordxftypecollect_consecutive_tags
PATH_CODESlenr   	load_tagsr?   )rB   r\   start_index	path_tags	end_indexs        rD   rU   DXFPolygon.load_pathsa   s    	..,K 11*KRSO1T	y>>&00;DJ#i.014	Y&' "" 	))<<>" #5 6 	s   A, ,<B(c                     UR                  S5      nUR                  [        US-   S9n[
        R                  " U5      U l        XU[        U5      -   S-   2	 U$ ! [        R                   a    Us $ f = f)NN   r   r`   )	rb   r   rc   rf   PATTERN_DEFINITION_LINE_CODESr   ri   r   rh   )rB   r\   indexpattern_tagss       rD   rW   DXFPolygon.load_patterns   s    	NN2&E
 44) 5 
 ((6 \!22Q667 "" 	K	s   A A32A3c                     UR                  S5      n[        R                  " XS  5      U l        XS 2	 U$ ! [        R                   a    Us $ f = f)Ni  )rb   r   rc   r   ri   r@   )rB   r\   rq   s      rD   rV   DXFPolygon.load_gradient   sU    	NN3'E !**4<8L "" 	K	s   6 AAc                h  > [        U[        5      (       d   eUR                  c   e[        TU ]  X5        UR                  R
                  nUR                   HL  nUR                   Vs/ s H  oRR                  U5      PM     nnU Vs/ s H  oUU;   d  M
  UPM     snUl        MN     gs  snf s  snf )z3Translate resources from self to the copied entity.N)	rH   r   docr=   map_resourcesentitydbr?   source_boundary_objects
get_handle)rB   clonemappingdbpathhhandlesrC   s          rD   rx   DXFPolygon.map_resources   s    %,,,,yy$$$e-YYKKD6:6R6RS6R))!,6RGS7>+Jw!r'Aw+JD(  S+Js   *B*
	B/B/c                    U$ r<    )rB   r\   s     rD   rX   DXFPolygon.load_seeds   s    rF   c                @    [        U R                  R                  5      $ )z0``True`` if entity has a solid fill. (read only)boolr[   
solid_fillrB   s    rD   has_solid_fillDXFPolygon.has_solid_fill   s     DHH''((rF   c                J    [        U R                  R                  5      (       + $ )z2``True`` if entity has a pattern fill. (read only)r   r   s    rD   has_pattern_fillDXFPolygon.has_pattern_fill   s     ++,,,rF   c                ,    [        U R                  5      $ )zf``True`` if entity has a gradient fill. A hatch with gradient fill
has also a solid fill. (read only)
)r   r@   r   s    rD   has_gradient_dataDXFPolygon.has_gradient_data   s    
 DMM""rF   c                     U R                  S5      nUR                  SS5      n [        R
                  " [        U5      5      $ ! [        R                   a     gf = f! [         a    [        SSS5      s $ f = f)a<  
Set pattern fill background color as (r, g, b)-tuple, rgb values
in the range [0, 255] (read/write/del)

usage::

    r, g, b = entity.bgcolor  # get pattern fill background color
    entity.bgcolor = (10, 20, 30)  # set pattern fill background color
    del entity.bgcolor  # delete pattern fill background color

HATCHBACKGROUNDCOLORN/  r   )		get_xdatar   rc   get_first_valuer   int2rgbint
ValueErrorRGB)rB   xdata_bgcolorcolors      rD   bgcolorDXFPolygon.bgcolor   sz    	 NN+ABM --dA6	 >>#e*--	 "" 		
  	 q!Q<	 s"   A A AAA98A9c                    [         R                  " U5      S-  nU R                  S5        U R                  SSU4/5        g )Ni   r   r   )r   rgb2intdiscard_xdata	set_xdata)rB   rgbcolor_values      rD   r   r      sC     NN3"CC 	 	12-{0C/DErF   c                &    U R                  S5        g )Nr   )r   r   s    rD   r   r      s    12rF   r              LINEARc                   U R                   b>  U R                   R                  [        R                  :  a  [        R                  " S5      eU(       a-  U[        R
                  ;  a  [        R                  " SU 35      eSU l        SU R                  l	        SU R                  l
        [        R                  U R                  l        [        5       nXl        X(l        XXl        X8l        XHl        Xhl        Xxl        Xl        g)ao  Sets the gradient fill mode and removes all pattern fill related data, requires
DXF R2004 or newer.  A gradient filled hatch is also a solid filled hatch.

Valid gradient type names are:

    - "LINEAR"
    - "CYLINDER"
    - "INVCYLINDER"
    - "SPHERICAL"
    - "INVSPHERICAL"
    - "HEMISPHERICAL"
    - "INVHEMISPHERICAL"
    - "CURVED"
    - "INVCURVED"

Args:
    color1: (r, g, b)-tuple for first color, rgb values as int in
        the range [0, 255]
    color2: (r, g, b)-tuple for second color, rgb values as int in
        the range [0, 255]
    rotation: rotation angle in degrees
    centered: determines whether the gradient is centered or not
    one_color: 1 for gradient from `color1` to tinted `color1`
    tint: determines the tinted target `color1` for a one color
        gradient. (valid range 0.0 to 1.0)
    name: name of gradient type, default "LINEAR"

Nz#Gradient support requires DXF R2004zInvalid gradient type name: r   SOLID)rw   
dxfversionr   DXF2004DXFVersionErrorGRADIENT_TYPESrc   r   r[   r   pattern_nameHATCH_TYPE_PREDEFINEDpattern_typer   color1color2	one_colorrotationcenteredtintnamer@   )	rB   r   r   r   r   r   r   r   r@   s	            rD   set_gradientDXFPolygon.set_gradient   s    L 88DHH$7$7%--$G''(MNND 4 44%%(DTF&KLL ' % ; ;:  &$$ rF   c	                   SU l         SU R                  l        XR                  l        X R                  l        [        U5      U R                  l        [        U5      U R                  l        [        U5      U R                  l	        X`R                  l
        XpR                  l        Uct  Sn	U R                  (       a&  U R                  R                  R                  SU	5      n	U	(       a  [        R                   O[        R"                  n
U
R                  XS   5      nU R%                  UU R                  R                  U R                  R                  S9  g)ar  Sets the pattern fill mode and removes all gradient related data.

The pattern definition should be designed for a scale factor 1 and a rotation
angle of 0 degrees.  The predefined hatch pattern like "ANSI33" are scaled
according to the HEADER variable $MEASUREMENT for ISO measurement (m, cm, ... ),
or imperial units (in, ft, ...), this replicates the behavior of BricsCAD.

Args:
    name: pattern name as string
    color: pattern color as :ref:`ACI`
    angle: pattern rotation angle in degrees
    scale: pattern scale factor
    double: double size flag
    style: hatch style (0 = normal; 1 = outer; 2 = ignore)
    pattern_type: pattern type (0 = user-defined;
        1 = predefined; 2 = custom)
    definition: list of definition lines and a definition line is a
        4-tuple [angle, base_point, offset, dash_length_items],
        see :meth:`set_pattern_definition`

Nr   r   z$MEASUREMENTANSI31factorangle)r@   r[   r   r   r   floatpattern_scalepattern_angler   pattern_doublehatch_styler   rw   headergetr   ISO_PATTERNIMPERIAL_PATTERNset_pattern_definition)rB   r   r   r   scaledoublestyler   
definitionmeasurementpredefined_patterns              rD   set_pattern_fillDXFPolygon.set_pattern_fill  s    @  $!&u!&u"%f+$ ,Kxx"hhoo11.+N'2##8P8P  ,//6RSJ##88))(((( 	$ 	
rF   c                    US:w  d  U(       a  [         R                  " XUS9n[        U Vs/ s H  n[        US   US   US   US   5      PM     sn5      U l         gs  snf )a@  Setup pattern definition by a list of definition lines and the
definition line is a 4-tuple (angle, base_point, offset, dash_length_items).
The pattern definition should be designed for a pattern scale factor of 1 and
a pattern rotation angle of 0.

    - angle: line angle in degrees
    - base-point: (x, y) tuple
    - offset: (dx, dy) tuple
    - dash_length_items: list of dash items (item > 0 is a line,
      item < 0 is a gap and item == 0.0 is a point)

Args:
    lines: list of definition lines
    factor: pattern scale factor
    angle: rotation angle in degrees

r   r   r   rP      N)r   scale_patternr   r   )rB   linesr   r   lines        rD   r   !DXFPolygon.set_pattern_definitionF  s[    ( Q;%))%eLEINO[a$q'47DG<O
Os   $Ac                    U R                   (       d  gU R                  nU R                  R                  SUR                  -  U-  S9  Xl        g)a  Sets the pattern scale factor and scales the pattern definition.

The method always starts from the original base scale, the
:code:`set_pattern_scale(1)` call resets the pattern scale to the original
appearance as defined by the pattern designer, but only if the pattern attribute
:attr:`dxf.pattern_scale` represents the actual scale, it cannot
restore the original pattern scale from the pattern definition itself.

Args:
    scale: pattern scale factor

N      ?)r   )r   r[   r   r   r   )rB   r   r[   s      rD   set_pattern_scaleDXFPolygon.set_pattern_scale`  sD     $$hh#(9(9"9E"AB!rF   c                    U R                   (       d  gU R                  nU R                  R                  XR                  -
  S9  US-  Ul        g)a  Sets the pattern rotation angle and rotates the pattern definition.

The method always starts from the original base rotation of 0, the
:code:`set_pattern_angle(0)` call resets the pattern rotation angle to the
original appearance as defined by the pattern designer, but only if the
pattern attribute :attr:`dxf.pattern_angle` represents the actual pattern
rotation, it cannot restore the original rotation angle from the
pattern definition itself.

Args:
    angle: pattern rotation angle in degrees

N)r   g     v@)r   r[   r   r   r   )rB   r   r[   s      rD   set_pattern_angleDXFPolygon.set_pattern_angles  sC     $$hh):):!:;!EMrF   c                   U R                   n[        UR                  U5      n[        UR                  5      R
                  nU R                  R                  X4S9  UR                  [        SSU5      5      R                  SSS9Ul        UR                  Ul        U R                  (       a  UR                  U R                   R                  SS45      nUR                  U R                   R                  5      nU R                  R!                  XV5        XPR                   l        X`R                   l        U R#                  U5        U $ )z6Transform entity by transformation matrix `m` inplace.)	elevationr   r   )xy)r[   r   	extrusionr   r   zr?   	transformtransform_vertexreplacenew_extrusionr   transform_lengthr   transform_deg_angler   r   post_transform)rB   mr[   ocsr   r   r   s          rD   r   DXFPolygon.transform  s   hh3==!,'))	

S6,,T!Q	-BCKKS L 
 ))<< ))488+A+A1a*HIF++DHH,B,BCELLv-%+HH"%*HH"ArF   c              #    ^#    SSK Jn  [        U R                  R                  5      mU R                  R                  S5      (       a"  T[        U R                  R                  5      -  mU R                   Vs/ s H  oCR                  U5      PM     nnUR                  XQU5       H  n[        U4S jU 5       5      v   M     gs  snf 7f)u  Triangulate the HATCH/MPOLYGON in OCS coordinates, Elevation and offset is
applied to all vertices.

Args:
    max_sagitta: 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.
    min_segments: minimum segment count per Bézier curve

.. versionadded:: 1.1

r   )r   offsetc              3  .   >#    U  H
  nTU-   v   M     g 7fr<   r   ).0vr   s     rD   	<genexpr>)DXFPolygon.triangulate.<locals>.<genexpr>  s     8x!	Axs   N)ezdxfr   r   r[   r   hasattrr   r?   from_hatch_boundary_pathtriangulatetuple)rB   max_sagittamin_segmentsr   pboundary_pathsverticesr   s          @rD   r   DXFPolygon.triangulate  s      	++,	88H%%dhhoo..IDHJJOJq77:JO((lSH8x888 T Ps   A6C9C8Cc              #     #    SSK Jn  U R                  (       a   UR                  U 5       Sh  vN   gg N! UR                   a     gf = f7f)zEYields the pattern lines in WCS coordinates.

.. versionadded:: 1.1

r   )hatchingN)ezdxf.renderr  r   hatch_entityHatchingError)rB   r  s     rD   render_pattern_linesDXFPolygon.render_pattern_lines  sK      	*  #00666 !6)) s1   A8 68 A8 AA
AAc                    g r<   r   )rB   r   r   r   s       rD   set_solid_fillDXFPolygon.set_solid_fill  s    rF   c                   > [         TU ]  U5        U R                  (       d  g U R                  R	                  5       (       d=  UR                  [        R                  S[        U 5       S3S9  UR                  U 5        g g )NzDeleted entity z# containing invalid boundary paths.)codemessage)
r=   auditis_aliver?   is_validfixed_errorr   INVALID_HATCH_BOUNDARY_PATHstrtrash)rB   auditorrC   s     rD   r  DXFPolygon.audit  sl    g}}zz""$$;;)#d)4WX    MM$ %rF   )r@   r?   r   rA   )returnNone)rK   r	   r  r  r<   )rZ   zOptional[SubclassProcessor]r  r   )r\   r   r  r   )r|   r	   r}   zxref.ResourceMapperr  r  )r  r   )r  Optional[RGB])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   N)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  r  )r   r   r  r  )r   r   r  r   )   )r  zIterator[Sequence[Vec3]])r  zIterator[tuple[Vec3, Vec3]])r  r   N)r   r   r   r   r   r  )r  r
   r  r  )&__name__
__module____qualname____firstlineno____doc__r:   __annotations__r>   r   rM   rS   rU   rW   rV   rx   rX   propertyr   r   r   r   setterdeleterr   r   r   r   r   r   r   r   r  abcabstractmethodr
  r  __static_attributes____classcell__)rC   s   @rD   r   r   7   s-   ;9;6;3 5A 1 8<4	 ,$"	K ) ) - - # #    , ^^F F __3 3
 !Ql#sC(8!8! 8! 	8!
 8! 8! 8! 8! 
8!z 6
6
 6
 	6

 6
 6
 6
 6
 
6
r BC

',
9>
	
4"&*(.9, 	 	  	 rF   )0
__future__r   typingr   r   r   r   r   typing_extensionsr	   r&  rI   ezdxf.auditr
   r   ezdxf.lldxfr   ezdxf.lldxf.tagsr   r   r   ezdxf.toolsr   
ezdxf.mathr   r   ezdxf.math.transformtoolsr   r   r   dxfnsr   r   dxfgfxr   r@   r   r   r   	dxfentityr   r   r   r   __all__rg   rp   r   r   rF   rD   <module>r7     sv    # E E " 
  +  !   % 2 ) 2   )   jj.
* != X  X rF   