
    h                       S SK Jr  S SKJrJrJrJrJrJrJ	r	  S SK
Jr  S SKJr  S SKJrJrJr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JrJrJr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K*J+r+  S SK,J-r-  SSK.J/r/J0r0  SSK1J2r2J3r3J4r4  SSK5J6r6  SSK7J8r8  \(       a$  S SK,J9r9  S SK*J:r:J;r;J<r<J=r=  S SK>J?r?  S SK@JArA  S SKBJCrC  / SQrD\" S\" S\R                  \S9\" SS S9\" SS S S!9\" S"S S S!9\" S#S S \R                  \S$9\" S%S S \R                  \S$9\" S&S S S!9\" S'S S S!9\" S(S S \R                  " 1 S)k5      \S$9\" S*S S S!9\" S+\R                  \S \R                  \S,9S-.5      rI\" \IS.S/9rJ\" \4\J5      rK\+R                   " S0 S1\85      5       rM " S2 S3\M5      rN " S4 S55      rO " S6 S75      rP " S8 S9\M5      rQ " S: S;5      rR\" S<\" S\R                  S=9\" SS S S!9\" S"S S S!9\" S>S S S!9\" SS S9\" S?S S@9\" S#S S@9\" S%S S@9\" S&S S@9\" S'S S@9\" SAS S@9SB.5      rS\" \S5      rT\" \4\T5      rU\+R                   " SC SD\25      5       rVSGSHSE jjrWgF)I    )annotations)TYPE_CHECKINGIterableIteratorUnioncastSequenceOptional)chain)	validator)DXFAttrDXFAttributesDefSubclassXTypeRETURN_DEFAULTgroup_code_mappingmerge_group_code_mappings)DXF12SUBCLASS_MARKERVERTEXNAMES)const)Vec3Matrix44NULLVECZ_AXISUVec)OCSTransformNonUniformScalingError)virtual_polyline_entitiesexplode_entity)EntityQuery)factory)
AuditError   )
base_classSubclassProcessor)
DXFGraphicacdb_entityacdb_entity_group_codes)FORMAT_CODES)LinkedEntities)Auditor)DXFNamespaceLineArcFace3d)
BaseLayout)AbstractTagWriter)FaceType)PolylinePolyfacePolymeshAcDbPolylineDummy
   )xtypedefaultF   )r;   (   T)r;   optional)   G   )r;   r>   r   fixerH   I   J   K   >   r            '      )r:   r;   r>   r   rA   	elevationflagsdefault_start_widthdefault_end_widthm_countn_countm_smooth_densityn_smooth_densitysmooth_type	thickness	extrusion)B   )ignorec                    ^  \ rS rSrSrSr\" \\\	5      r
Sr\rSrSrSrSrS	rS
rSrSrSrSrSr\\-  \-  r\S3S j5       r S4   S5U 4S jjjrS6U 4S jjrS7U 4S jjrS8S jrS9S jrS:S 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%\S<S j5       r&\S<S j5       r'\S<S j5       r(\S<S j5       r)\S<S j5       r*S=S>S  jjr+S=S>S! jjr,S?S>S" jjr-S:S# jr.S@S$ jr/SAS% jr0SAS& jr1SBS' jr2S4SCS( jjr3  SD     SES) jjr4S4SFS* jjr5 S4     SGS+ jjr6      SHS, jr7SIS- jr8SJS. jr9S4SKS/ jjr:SLS0 jr;SMS1 jr<S2r=U =r>$ )Nr5   }   zDXF POLYLINE entity

The POLYLINE entity is hard owner of its VERTEX entities and the SEQEND entity:

   VERTEX.dxf.owner == POLYLINE.dxf.handle
   SEQEND.dxf.owner == POLYLINE.dxf.handle

POLYLINEr%         rH          @      r   rF   rG   c                    U R                   $ N_sub_entitiesselfs    I/var/www/html/env/lib/python3.13/site-packages/ezdxf/entities/polyline.pyverticesPolyline.vertices   s    !!!    c                h   > [         [        U ]  U5      nU(       a  UR                  U[        5        U$ z!Loading interface. (internal API))superr(   load_dxf_attribssimple_dxfattribs_loadermerged_polyline_group_codesrg   	processordxf	__class__s      rh   ro   Polyline.load_dxf_attribs   s/    
 J6yA..s4OP
rk   c                P   >^ [         TU ]  T5        U R                  U4S j5        g)z?Export POLYLINE entity and all linked entities: VERTEX, SEQEND.c                &   > U R                  T5      $ rc   )
export_dxf)e	tagwriters    rh   <lambda>%Polyline.export_dxf.<locals>.<lambda>   s    ALL,Crk   N)rn   ry   process_sub_entitiesrg   r{   ru   s    `rh   ry   Polyline.export_dxf   s    9%!!"CDrk   c                   > [         TU ]  U5        UR                  [        :  a$  UR	                  [
        U R                  5       5        UR	                  SS5        U R                  R                  U/ SQ5        g)z*Export POLYLINE specific data as DXF tags.rW   r%   rK   N)	rn   export_entity
dxfversionr   
write_tag2r   get_modert   export_dxf_attribsr   s     rh   r   Polyline.export_entity   s^    i(%'  $--/BR###	
rk   c                J    U R                    H  nXR                  l        M     g)zoEvent handler for layer change. Changes also the layer of all vertices.

Args:
    layer: new layer as string

N)ri   rt   layer)rg   r   vs      rh   on_layer_changePolyline.on_layer_change   s     AEEK rk   c                J    U R                    H  nXR                  l        M     g)z{Event handler for linetype change. Changes also the linetype of all
vertices.

Args:
    linetype: new linetype as string

N)ri   rt   linetype)rg   r   r   s      rh   on_linetype_changePolyline.on_linetype_change   s     A%EEN rk   c                D    [         R                  U R                  5          $ rc   )r   VERTEX_FLAGSr   rf   s    rh   get_vertex_flagsPolyline.get_vertex_flags   s    !!$--/22rk   c                p    U R                   (       a  gU R                  (       a  gU R                  (       a  gg)zrReturns POLYLINE type as string:

- "AcDb2dPolyline"
- "AcDb3dPolyline"
- "AcDbPolygonMesh"
- "AcDbPolyFaceMesh"

AcDb3dPolylineAcDbPolygonMeshAcDbPolyFaceMeshAcDb2dPolyline)is_3d_polylineis_polygon_meshis_poly_face_meshrf   s    rh   r   Polyline.get_mode   s+     #!!$##%#rk   c                N    U R                   R                  U R                  -  S:H  $ )z&``True`` if POLYLINE is a 2D polyline.r   )rt   rM   ANY3Drf   s    rh   is_2d_polylinePolyline.is_2d_polyline   s      xx~~

*a//rk   c                Z    [        U R                  R                  U R                  -  5      $ )z&``True`` if POLYLINE is a 3D polyline.)boolrt   rM   POLYLINE_3Drf   s    rh   r   Polyline.is_3d_polyline   s"     DHHNNT%5%5566rk   c                Z    [        U R                  R                  U R                  -  5      $ )z=``True`` if POLYLINE is a polygon mesh, see :class:`Polymesh`)r   rt   rM   POLYMESHrf   s    rh   r   Polyline.is_polygon_mesh         DHHNNT]]233rk   c                Z    [        U R                  R                  U R                  -  5      $ )z?``True`` if POLYLINE is a poly face mesh, see :class:`Polyface`)r   rt   rM   POLYFACErf   s    rh   r   Polyline.is_poly_face_mesh   r   rk   c                Z    [        U R                  R                  U R                  -  5      $ )z``True`` if POLYLINE is closed.)r   rt   rM   CLOSEDrf   s    rh   	is_closedPolyline.is_closed  s      DHHNNT[[011rk   c                Z    [        U R                  R                  U R                  -  5      $ )zF``True`` if POLYLINE (as :class:`Polymesh`) is closed in m
direction.
)r   rt   rM   MESH_CLOSED_M_DIRECTIONrf   s    rh   is_m_closedPolyline.is_m_closed
  "    
 DHHNNT%A%AABBrk   c                Z    [        U R                  R                  U R                  -  5      $ )zF``True`` if POLYLINE (as :class:`Polymesh`) is closed in n
direction.
)r   rt   rM   MESH_CLOSED_N_DIRECTIONrf   s    rh   is_n_closedPolyline.is_n_closed  r   rk   c                ^    U R                   (       a  [        S U R                   5       5      $ g)z3Returns ``True`` if 2D POLYLINE has an arc segment.c              3     #    U  HE  oR                   R                  S 5      =(       a    [        UR                   R                  5      v   MG     g7f)bulgeN)rt   hasattrr   r   ).0r   s     rh   	<genexpr>#Polyline.has_arc.<locals>.<genexpr>  s3      FSg&<4+<<ms   AAF)r   anyri   rf   s    rh   has_arcPolyline.has_arc  s0      FJmm   rk   c                ~   U R                   (       Ga+  U R                  R                  S5      (       a%  [        U R                  R                  5      (       a  gU R                  R                  S5      (       a%  [        U R                  R
                  5      (       a  gU R                   H  nUR                  R                  S5      (       a&  [        UR                  R                  5      (       a    gUR                  R                  S5      (       d  Mk  [        UR                  R                  5      (       d  M    g   g)z_Returns ``True`` if 2D POLYLINE has default width values or any
segment with width attributes.
rN   TrO   start_width	end_widthF)	r   rt   r   r   rN   rO   ri   r   r   )rg   r   s     rh   	has_widthPolyline.has_width"  s    
 xx 5664,,< < xx 344**: : ]]55==//D9J9J4K4K55==--$quu2G2G	 #
 rk   c                :    U R                  U R                  USS9  g)z|Close POLYMESH in m direction if `status` is ``True`` (also closes
POLYLINE), clears closed state if `status` is ``False``.
rM   nameN)set_flag_stater   rg   statuss     rh   m_closePolyline.m_close7       	D88&wOrk   c                :    U R                  U R                  USS9  g)zeClose POLYMESH in n direction if `status` is ``True``, clears closed
state if `status` is ``False``.
rM   r   N)r   r   r   s     rh   n_closePolyline.n_close=  r   rk   c                H    U R                  U5        U R                  U5        g)zSet closed state of POLYMESH and POLYLINE in m direction and n
direction. ``True`` set closed flag, ``False`` clears closed flag.
N)r   r   )rg   r   r   s      rh   closePolyline.closeC  s     	WWrk   c                ,    [        U R                  5      $ )z*Returns count of :class:`Vertex` entities.lenri   rf   s    rh   __len__Polyline.__len__J      4==!!rk   c                     U R                   U   $ )zIGet :class:`Vertex` entity at position `pos`, supports list-like slicing.ri   rg   poss     rh   __getitem__Polyline.__getitem__N  s    }}S!!rk   c                (    S U R                    5       $ )aU  Returns all polyline points in :ref:`OCS` or :ref:`WCS` coordinates as
:class:`~ezdxf.math.Vec3`.

These are the raw location coordinates stored in the :class:`Vertex` entities.
A separately stored elevation value will not be applied. The points of
2D polylines are :ref:`OCS` coordinates other polyline types return :ref:`WCS`
coordinates.
c              3  L   #    U  H  oR                   R                  v   M     g 7frc   rt   locationr   vertexs     rh   r   "Polyline.points.<locals>.<genexpr>[  s     @-

##-   "$r   rf   s    rh   pointsPolyline.pointsR  s     A$--@@rk   c                T  ^ U R                  5       nU R                  (       d  U$ U R                  R                  R                  mT(       a  U4S jU 5       n[
        R                  " U R                  R                  5      (       a  U$ U R                  5       nUR                  U5      $ )zlReturns all polyline points in :ref:`WCS` coordinates as
:class:`~ezdxf.math.Vec3`.

.. versionadded:: 1.4

c              3  @   >#    U  H  oR                  TS 9v   M     g7f)zN)replace)r   prL   s     rh   r   )Polyline.points_in_wcs.<locals>.<genexpr>j  s     =fii)i,fs   )
r   r   rt   rL   r   r   iscloserV   ocspoints_to_wcs)rg   r   r   rL   s      @rh   points_in_wcsPolyline.points_in_wcs]  sz     ""M88--//	=f=F>>$((,,--Mhhj  ((rk   c                :    U R                   R                  U5        g rc   )ri   append)rg   r   s     rh   _append_vertexPolyline._append_vertexr  s    V$rk   c                ~    [        U=(       d    0 5      nU R                  X5       H  nU R                  U5        M     g)zAppend multiple :class:`Vertex` entities at location `points`.

Args:
    points: iterable of (x, y[, z]) tuples
    dxfattribs: dict of DXF attributes for the VERTEX objects

Ndict_build_dxf_verticesr   )rg   r   
dxfattribsr   s       rh   append_verticesPolyline.append_verticesu  s7     **+
..vBF' Crk   c                   [        U=(       d    0 5      nUR                  SS5      U R                  5       -  US'   U R                  R                  US'   U R                  R
                  US'   U R                  R                  S5      (       a  U R                  R                  US'   U HP  n[        XB5      nUR                  U5        [        [        U R                  SU5      5      nU R                  U5        MR     g)a   Append multiple :class:`Vertex` entities at location `points`.

Args:
    points: iterable of (x, y, [start_width, [end_width, [bulge]]])
            tuple
    format: format string, default is "xy", see: :ref:`format codes`
    dxfattribs: dict of DXF attributes for the VERTEX objects

rM   r   ownerr   r   VERTEXN)r   getr   rt   r  r   r   r   vertex_attribsupdater   	DXFVertex_new_compound_entityr   )rg   r   formatr  pointattribsr   s          rh   append_formatted_vertices"Polyline.append_formatted_vertices  s     **+
(nnWa84;P;P;RR
7 #hhnn
7"hhnn
788J''%)XX%6%6Jz"E$U3GNN:&)T%>%>x%QRF'	 rk   c                    [        U=(       d    0 5      nU R                  U/U5       H  nU R                  U5        M     g)zAppend a single :class:`Vertex` entity at location `point`.

Args:
    point: as (x, y[, z]) tuple
    dxfattribs: dict of DXF attributes for :class:`Vertex` class

Nr   )rg   r  r  r   s       rh   append_vertexPolyline.append_vertex  s;     **+
..w
CF' Drk   c                x    [        U=(       d    0 5      n[        U R                  X#5      5      U R                  X& g)a	  Insert vertices `points` into :attr:`Polyline.vertices` list
at insertion location `pos` .

Args:
    pos: insertion position of list :attr:`Polyline.vertices`
    points: list of (x, y[, z]) tuples
    dxfattribs: dict of DXF attributes for :class:`Vertex` class

N)r   listr  ri   )rg   r   r   r  s       rh   insert_verticesPolyline.insert_vertices  s1     **+
!%d&>&>v&R!Scrk   c              #    #    UR                  SS5      U R                  5       -  US'   U R                  R                  US'   U R                  R                  US'   U R                  R                  S5      (       a  U R                  R                  US'   U H3  n[        U5      US'   [        [        U R                  SU5      5      v   M5     g7f)	zConverts point (x, y, z) tuples into DXFVertex objects.

Args:
    points: list of (x, y, z)-tuples
    dxfattribs: dict of DXF attributes
rM   r   r  r   r   r   r  N)r  r   rt   handler   r   r   r   r   r  r  )rg   r   r  r  s       rh   r  Polyline._build_dxf_vertices  s      )nnWa84;P;P;RR
7 #hhoo
7"hhnn
788J''%)XX%6%6Jz"E%)%[Jz"y$";";Hj"QRR s   CCc                    U R                  5       nUS:X  a  [        R                  U 5      $ US:X  a  [        R                  U 5      $ U $ )Nr   r   )r   r6   from_polyliner7   )rg   modes     rh   r   Polyline.cast  sF    }}%%))$//&&))$//Krk   c                  ^  U 4S jnT R                   (       Ga   T R                  n[        T R                  R                  U5      nUR                  (       d  T R
                  (       a  [        S5      eUR                  S5      (       a  UR                  R                  nOSnU" U5       Vs/ s H  odR                  U5      PM     nnU(       a  US   R                  SSS9Ul        [        T R                  U5       H  u  phUR                  n	Xl        U	R                  S5      (       a   UR                  U	R                   5      U	l        U	R                  S	5      (       d  Me  UR                  U	R"                  5      U	l        M     UR                  S
5      (       a   UR                  UR$                  5      Ul        UR                  S5      (       a   UR                  UR&                  5      Ul        UR                  S5      (       a   UR)                  UR*                  5      Ul        UR,                  Ul        O$T R                   H  nUR/                  U5        M     T R1                  U5        T $ s  snf )a`  Transform the POLYLINE entity by transformation matrix `m` inplace.

A non-uniform scaling is not supported if a 2D POLYLINE contains
circular arc segments (bulges).

Args:
    m: transformation :class:`~ezdxf.math.Matrix44`

Raises:
    NonUniformScalingError: for non-uniform scaling of 2D POLYLINE
        containing circular arc segments (bulges)

c              3     >#    TR                    H/  nUR                  R                  nU b  UR                  U S9nUv   M1     g 7f)Nr   )ri   rt   r   r   )rL   r   r   rg   s      rh   _ocs_locations*Polyline.transform.<locals>._ocs_locations  sC     --!::..(  (//)/<H (s   AAzI2D POLYLINE containing arcs (bulges) does not support non uniform scalingrL   Nr   g        )xyr   r   rN   rO   rU   )r   rt   r   rV   scale_uniformr   r   r   rL   r   transform_vertexr   zipri   r   transform_widthr   r   rN   rO   transform_thicknessrU   new_extrusion	transformpost_transform)
rg   mr"  rt   r   z_axisr   ri   r   vdxfs
   `         rh   r,  Polyline.transform  s   	 ((Ctxx1115C$$,_ 
 {{;'';I&;Q;Q$$V,;Q    ( 3 3cS 3 A$'x$@ zz (<<..'*':':4;K;K'LD$<<,,%(%8%8%HDN %A {{011*-*=*=c>U>U*V'{{.//(+(;(;C<Q<Q(R%{{;'' # 7 7 F--CM--  # (A;s   ,I1c                    [        X5      $ )a~  Explode the POLYLINE entity as DXF primitives (LINE, ARC or 3DFACE)
into the target layout, if the target layout is ``None``, the target
layout is the layout of the POLYLINE entity.

Returns an :class:`~ezdxf.query.EntityQuery` container referencing all
DXF primitives.

Args:
    target_layout: target layout for DXF primitives, ``None`` for same
        layout as source entity.

r    )rg   target_layouts     rh   explodePolyline.explode  s     d22rk   c              #  Z   #    [        U 5       H  nUR                  U 5        Uv   M     g7f)zYields the graphical representation of POLYLINE as virtual DXF
primitives (LINE, ARC or 3DFACE).

These virtual entities are located at the original location, but are not
stored in the entity database, have no handle and are not assigned to
any layout.

N)r   set_source_of_copy)rg   rz   s     rh   virtual_entitiesPolyline.virtual_entities*  s)      +40A  &G 1s   )+c                  ^^^ UUU4S jnU R                   mU R                  R                  mU R                  R                  mU R                   H  nU" U5        M     U R
                  nU(       a	  U" U5        gT(       a=  U R                  5         UR                  [        R                  S[        U 5       S3U S9  gg)z%Audit and repair the POLYLINE entity.c                   > TU l         U R                  nUR                  T:w  a  TUl        UR                  T:w  a  TUl        g g rc   )docrt   r  r   )entityrt   r<  r   r  s     rh   audit_sub_entity(Polyline.audit.<locals>.audit_sub_entity:  s>    FJ**CyyE!!	yyE!!	 "rk   z#Created required SEQEND entity for .)codemessage
dxf_entityN)r<  rt   r  r   ri   seqend
new_seqendfixed_errorr$   MISSING_REQUIRED_SEQENDstr)rg   auditorr>  r   rD  r<  r   r  s        @@@rh   auditPolyline.audit7  s    	" hhmmFV$ $ V$OO77=c$i[J    rk    returnlist[DXFVertex]rc   rs   zOptional[SubclassProcessor]rN  r.   )r{   r3   r{   r3   rN  None)r   rH  )r   rH  rN  int)rN  rH  rN  r   )T)rN  rR  )TF)rN  r  )rN  zIterator[Vec3])r   r  rN  rR  )r   Iterable[UVec]rN  rR  )xyN)r   zIterable[Sequence]r  rH  rN  rR  )r  r   rN  rR  )r   rT  r   rV  rN  rR  )r   rV  r  r   rN  zIterator[DXFVertex])rN  z#Union[Polyline, Polymesh, Polyface])r.  r   rN  r5   )r3  zOptional[BaseLayout]rN  r"   )rN  z"Iterator[Union[Line, Arc, Face3d]])rI  r-   rN  rR  )?__name__
__module____qualname____firstlineno____doc__DXFTYPEr   r&   r)   acdb_polyline
DXFATTRIBSr   r   CURVE_FIT_VERTICES_ADDEDSPLINE_FIT_VERTICES_ADDEDr   r   r   r   GENERATE_LINETYPE_PATTERN	NO_SMOOTHQUADRATIC_BSPLINECUBIC_BSPLINEBEZIER_SURFACEr   propertyri   ro   ry   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,  r4  r8  rJ  __static_attributes____classcell__ru   s   @rh   r5   r5   }   sA    Gz;FJF$  !KH H #IMN("X-E" " 8<4	 E
0 	&3$$ 0 0 7 7 4 4 4 4 2 2 C C C C    (PP""	A)*%
( 	("( (
 
(<
( <@TT .T	TS$S26S	S(BH3 rk   r5   c                      \ rS rSrSr\SS j5       rSSS jjr    SS jrSSS jjr	SSS jjr
SS	 jrSSS
 jjrSS jrSS jrSrg)r6   iT  am  
PolyFace structure:

POLYLINE
  AcDbEntity
  AcDbPolyFaceMesh
VERTEX - Vertex
  AcDbEntity
  AcDbVertex
  AcDbPolyFaceMeshVertex
VERTEX - Face
  AcDbEntity
  AcDbFaceRecord
SEQEND

Order of mesh_vertices and face_records is important (DXF R2010):

    1. mesh_vertices: the polyface mesh vertex locations
    2. face_records: indices of the face forming vertices

c                l    U R                  U5      nUR                  Ul        UR                  Ul        U$ rc   shallow_copyre   rD  )clspolylinepolyfaces      rh   r  Polyface.from_polylinek  s0    ##H-!)!7!7"//rk   Nc                *    U R                  U/U5        g)zAppend a single face. A `face` is a sequence of (x, y, z) tuples.

Args:
    face: sequence of (x, y, z) tuples
    dxfattribs: dict of DXF attributes for the VERTEX objects

N)append_faces)rg   facer  s      rh   append_facePolyface.append_faces  s     	4&*-rk   c           
         UR                  SS5      U R                  5       -  US'   U R                  SS5      US'   / nU H2  nXBS'   UR                  [	        SU R                  SU5      5      5        M4     U$ )zConvert (x, y, z) tuples into DXFVertex objects.

Args:
    points: sequence of (x, y, z) tuples
    dxfattribs: dict of DXF attributes for the VERTEX entity

rM   r   r   0r   r  r  )r  r   get_dxf_attribr   r   r  )rg   r   r  ri   r  s        rh   _points_to_dxf_vertices Polyface._points_to_dxf_vertices}  s     )nnWa84;P;P;RR
7 #11'3?
7$&E%*z"OO[$";";Hj"QR 
 rk   c           
       ^ ^ UU 4S jn[        T=(       d    0 5      mT R                  5       u  pE/ nU Hx  nT R                  U0 5      n[        U5      n	UR	                  U5        [        U" 5       U5      n
[        [        X[        U5      -   5      5      U
l        UR                  U
5        Mz     T R                  [        XV5      5        g)zAppend multiple `faces`. `faces` is a list of single faces and a
single face is a sequence of (x, y, z) tuples.

Args:
    faces: iterable of sequences of (x, y, z) tuples
    dxfattribs: dict of DXF attributes for the VERTEX entity

c                    > [         R                  T S'   [        5       T S'   [        [        TR                  ST 5      5      $ )NrM   r   r  )r   VTX_3D_POLYFACE_MESH_VERTEXr   r   r  r  )r  rg   s   rh   new_face_record.Polyface.append_faces.<locals>.new_face_record  s9    "'"C"CJw%)VJz"	4#<#<Xz#RSSrk   N)r   indexed_facesr{  r   extend	FaceProxytuplerangeindicesr   _rebuildr   )rg   facesr  r  existing_verticesexisting_faces	new_facesru  face_mesh_verticesindexface_records   ` `        rh   rt  Polyface.append_faces  s    	T **+
,0,>,>,@)%'	D!%!=!=dB!G)*E$$%78#O$57HIK #(eSAS=T5T(U"VK[)  	eN67rk   c                    [        XS9nUR                  5       U l        U R                  UR                  UR
                  5        g)zaBuild a valid POLYFACE structure from `faces`.

Args:
    faces: iterable of FaceProxy objects.

)	precisionN)PolyfaceBuilderget_verticesre   update_count	nverticesnfaces)rg   r  r  polyface_builders       rh   r  Polyface._rebuild  s@     +5F .::<*446F6M6MNrk   c                D    XR                   l        X R                   l        g rc   )rt   rP   rQ   )rg   r  r  s      rh   r  Polyface.update_count  s    $!rk   c                J    U R                  5       u  p#U R                  X15        g)zRebuilds the :class:`Polyface` by merging vertices with nearly same vertex
locations.

Args:
    precision: floating point precision for determining identical
        vertex locations

N)r  r  )rg   r  ri   r  s       rh   optimizePolyface.optimize  s      ,,.e'rk   c              #     #    U R                  5       u  pU H-  n[        U5      nUR                  UR                  5        Uv   M/     g7f)z~Iterable of all faces, a face is a tuple of vertices.

Returns:
     list of [vertex, vertex, vertex, [vertex,] face_record]

N)r  r  r   r  )rg   _r  ru  face_verticess        rh   r  Polyface.faces  sD      %%'D JM  !1!12 s   AA	c                   ^ / m/ nU R                    H'  nUR                  (       a  TOUR                  U5        M)     U4S jU 5       nTU4$ )zWReturns a list of all vertices and a generator of FaceProxy()
objects.

(internal API)
c              3  <   >#    U  H  n[        UT5      v   M     g 7frc   )r  )r   r  ri   s     rh   r   )Polyface.indexed_faces.<locals>.<genexpr>  s     R\k;11\s   )ri   is_poly_face_mesh_vertexr   )rg   face_recordsr   r  ri   s       @rh   r  Polyface.indexed_faces  sO     %'(*mmF88XlRR $
 S\Rrk   rd   )rp  r5   rN  r6   rc   )ru  r4   rN  rR  )r   rV  rN  rO  )r  zIterable[FaceType]rN  rR  rG   )r  Iterable[FaceProxy]r  rT  rN  rR  )r  rT  r  rT  rN  rR  )r  rT  rN  rR  )rN  zIterator[list[DXFVertex]])rN  z+tuple[list[DXFVertex], Iterator[FaceProxy]])rX  rY  rZ  r[  r\  classmethodr  rv  r{  rt  r  r  r  r  r  rh  rL  rk   rh   r6   r6   T  sU    ,  .$	,8@O"
( rk   r6   c                  l    \ rS 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rg)r  i  a:  Represents a single face of a polyface structure. (internal class)

vertices:

    List of all polyface vertices.

face_record:

    The face forming vertex of type ``AcDbFaceRecord``, contains the indices
    to the face building vertices. Indices of the DXF structure are 1-based
    and a negative index indicates the beginning of an invisible edge.
    Face.face_record.dxf.color determines the color of the face.

indices:

    Indices to the face building vertices as tuple. This indices are 0-base
    and are used to get vertices from the list `Face.vertices`.

)ri   r  r  c                F    X l         Xl        U R                  5       U l        g)zBReturns iterable of all face vertices as :class:`Vertex` entities.N)ri   r  _indicesr  )rg   r  ri   s      rh   __init__FaceProxy.__init__  s    -5&1&*mmork   c                ,    [        U R                  5      $ )z5Returns count of face vertices (without face_record).)r   r  rf   s    rh   r   FaceProxy.__len__  s    4<<  rk   c                :    U R                   U R                  U      $ )zTReturns :class:`Vertex` at position `pos`.

Args:
    pos: vertex position 0-based

)ri   r  r   s     rh   r   FaceProxy.__getitem__  s     }}T\\#.//rk   c                0   ^  U 4S jT R                    5       $ )Nc              3  B   >#    U  H  nTR                   U   v   M     g 7frc   r   )r   r  rg   s     rh   r   %FaceProxy.__iter__.<locals>.<genexpr>  s     ?,e$,s   )r  rf   s   `rh   __iter__FaceProxy.__iter__  s    ?$,,??rk   c                    S U  5       $ )zBReturns iterable of all face vertex locations as (x, y, z)-tuples.c              3  L   #    U  H  oR                   R                  v   M     g 7frc   r   r   s     rh   r   #FaceProxy.points.<locals>.<genexpr>  s     7$

##$r   rL  rf   s    rh   r   FaceProxy.points  s    7$77rk   c                8   ^  U 4S j[         R                   5       $ )Nc              3  \   >#    U  H!  nTR                   R                  US 5      v   M#     g7f)r   N)r  rz  )r   r   rg   s     rh   r   )FaceProxy._raw_indices.<locals>.<genexpr>   s)     WEVT  //a88EVs   ),)r   r   rf   s   `rh   _raw_indicesFaceProxy._raw_indices  s    WUEVEVWWrk   c                B    [        S U R                  5        5       5      $ )Nc              3  L   #    U  H  oS :w  d  M
  [        U5      S-
  v   M     g7f)r   r%   N)abs)r   r  s     rh   r   %FaceProxy._indices.<locals>.<genexpr>#  s!     S1DQR
^SZ!^1Ds   	$$)r  r  rf   s    rh   r  FaceProxy._indices"  s    S1B1B1DSSSrk   c                d    [         R                  U   nU R                  R                  U5      S:  $ )zgReturns ``True`` if edge starting at vertex `pos` is visible.

Args:
    pos: vertex position 0-based

r   )r   r   r  rz  )rg   r   r   s      rh   is_edge_visibleFaceProxy.is_edge_visible%  s0       %..t4q88rk   )r  r  ri   N)r  r  ri   zSequence[DXFVertex]rS  )r   rT  rN  r  )rN  zIterator['DXFVertex'])rN  zIterator[UVec])rN  zIterable[int])rN  zSequence[int])r   rT  rN  r   )rX  rY  rZ  r[  r\  	__slots__r  r   r   r  r   r  r  r  rh  rL  rk   rh   r  r    s9    ( 7I6!0@8XT9rk   r  c                  l    \ rS rSrSrSSS jjr\SS j5       r\SS j5       rSS jr	SS jr
SS jrS	rg
)r  i0  z,Optimized POLYFACE builder. (internal class)c                \    X l         / U l        / U l        0 U l        U R	                  U5        g rc   )r  r  ri   index_mappingbuild)rg   r  r  s      rh   r  PolyfaceBuilder.__init__3  s)    '&(
)+;=

5rk   c                ,    [        U R                  5      $ rc   r   rf   s    rh   r  PolyfaceBuilder.nvertices:  r   rk   c                ,    [        U R                  5      $ rc   )r   r  rf   s    rh   r  PolyfaceBuilder.nfaces>  s    4::rk   c                Z    U R                   S S  nUR                  U R                  5        U$ rc   )ri   r  r  )rg   ri   s     rh   r  PolyfaceBuilder.get_verticesB  s%    ==#

#rk   c                B   U H  nUR                   n[        U[        5       H[  u  pEU R                  U5      nUR                  R                  US5      S:  a  SOSnUR                  R                  XVS-   U-  5        M]     U R                  R                  U5        M     g )Nr   r%   )	r  r(  r   addrt   r  setr  r   )rg   r  ru  r  r   r   r  signs           rh   r  PolyfaceBuilder.buildG  s    D**K #D+ 6((__00q9A=r2##D19*<=	 !7
 JJk* rk   c                
  ^  U 4S jnU" UR                   R                  5      n T R                  U   $ ! [         aD    [	        T R
                  5      nUT R                  U'   T R
                  R                  U5        Us $ f = f)Nc                .   > [        U4S jU  5       5      $ )Nc              3  P   >#    U  H  n[        UTR                  5      v   M     g 7frc   )roundr  )r   coordrg   s     rh   r   3PolyfaceBuilder.add.<locals>.key.<locals>.<genexpr>S  s     JE5%t~~66Es   #&)r  )r  rg   s    rh   key PolyfaceBuilder.add.<locals>.keyR  s    JEJKKrk   )rt   r   r  KeyErrorr   ri   r   )rg   r   r  r   r  s   `    rh   r  PolyfaceBuilder.addQ  sy    	L vzz**+	%%h// 	&E+0Dx(MM  (L		s   4 ABB)r  r  r  ri   Nr  )r  r  r  rT  rS  rM  )r  r  rN  rR  )r   r  rN  rT  )rX  rY  rZ  r[  r\  r  rg  r  r  r  r  r  rh  rL  rk   rh   r  r  0  sA    6 " "  
+rk   r  c                  N    \ rS rSrSr\S	S j5       rS
SS jjrSS jrSS jr	Sr
g)r7   i_  zw
PolyMesh structure:

POLYLINE
  AcDbEntity
  AcDbPolygonMesh
VERTEX
  AcDbEntity
  AcDbVertex
  AcDbPolygonMeshVertex
c                l    U R                  U5      nUR                  Ul        UR                  Ul        U$ rc   rm  )ro  rp  polymeshs      rh   r  Polymesh.from_polylinel  s0    ##H-!)!7!7"//rk   Nc                x    [        U=(       d    0 5      nX#S'   U R                  U5      nUR                  U5        g)zSet location and DXF attributes of a single mesh vertex.

Args:
    pos: 0-based (row, col) tuple, position of mesh vertex
    point: (x, y, z) tuple, new 3D coordinates of the mesh vertex
    dxfattribs: dict of DXF attributes

r   N)r   get_mesh_vertexupdate_dxf_attribs)rg   r   r  r  r   s        rh   set_mesh_vertexPolymesh.set_mesh_vertexs  s9     **+
!&:%%c*!!*-rk   c                   U R                   R                  nU R                   R                  nUu  pESUs=::  a  U:  a'  O  O$SUs=::  a  U:  a  O  OU R                  XC-  U-      $ [        R
                  " [        U5      5      e)ziGet location of a single mesh vertex.

Args:
    pos: 0-based (row, col) tuple, position of mesh vertex

r   )rt   rP   rQ   ri   r   DXFIndexErrorrepr)rg   r   rP   rQ   r.  ns         rh   r  Polymesh.get_mesh_vertex  sl     ((""((""GQ 0 0==q11%%d3i00rk   c                    [        U 5      $ )zGet a :class:`MeshVertexCache` object for this POLYMESH.
The caching object provides fast access to the :attr:`location`
attribute of mesh vertices.

)MeshVertexCacherf   s    rh   get_mesh_vertex_cachePolymesh.get_mesh_vertex_cache  s     t$$rk   rL  )rp  r5   rN  r7   rc   )r   tuple[int, int]r  r   )r   r  rN  r  )rN  r  )rX  rY  rZ  r[  r\  r  r  r  r  r  rh  rL  rk   rh   r7   r7   _  s*    
  .1%rk   r7   c                  D    \ rS rSrSrSrS	S jrS
S jrSS jrSS jr	Sr
g)r  i  zCache mesh vertices in a dict, keys are 0-based (row, col)-tuples.

vertices:
    Dict of mesh vertices, keys are 0-based (row, col)-tuples. Writing to
    this dict doesn't change the DXF entity.

r   c                    U R                  XR                  R                  UR                  R                  5      U l        g rc   )_setuprt   rP   rQ   ri   )rg   meshs     rh   r  MeshVertexCache.__init__  s+    :>++((""DHH$4$4;
rk   c                    0 n[        UR                  5      n[        U5       H$  n[        U5       H  n[        U5      XFU4'   M     M&     U$ rc   )iterri   r  next)rg   r  rP   rQ   cacheri   r.  r  s           rh   r  MeshVertexCache._setup  sG    24&wA7^ $X!f $   rk   c                     U R                   U   R                  R                  $ ! [         a     [        R
                  " [        U5      5      ef = f)zXGet mesh vertex location as (x, y, z)-tuple.

Args:
    pos: 0-based (row, col)-tuple.

ri   rt   r   r  r   r  r  r   s     rh   r   MeshVertexCache.__getitem__  sF    	1==%))222 	1%%d3i00	1s	   "% *Ac                     X R                   U   R                  l        g! [         a     [        R
                  " [        U5      5      ef = f)zvGet mesh vertex location as (x, y, z)-tuple.

Args:
    pos: 0-based (row, col)-tuple.
    location: (x, y, z)-tuple

Nr  )rg   r   r   s      rh   __setitem__MeshVertexCache.__setitem__  s@    	1.6MM#""+ 	1%%d3i00	1s	     *A
N)r  r5   )r  r5   rP   rT  rQ   rT  rN  r   )r   r  rN  r   )r   r  r   r   rN  rR  )rX  rY  rZ  r[  r\  r  r  r  r   r  rh  rL  rk   rh   r  r    s"     I


11rk   r  
AcDbVertex)r:   *   2   )r>   [   r   r   r   r   rM   tangentvtx0vtx1vtx2vtx3vertex_identifierc                    ^  \ rS rSrSrSr\" \\\	5      r
SrSrSrSrSrS	rS
r\\-   r\\-   \-   r S   SU 4S jjjrSU 4S jjr\SS j5       r\SS j5       r\SS j5       r\SS j5       r\SS j5       rSS jrSSS jjrSrU =r$ )r  i  zDXF VERTEX entityr  r%   r\   rH   r^   r_   r`   ra   c                h   > [         [        U ]  U5      nU(       a  UR                  U[        5        U$ rm   )rn   r(   ro   rp   merged_vertex_group_codesrr   s      rh   ro   DXFVertex.load_dxf_attribs   s/    
 J6yA..s4MN
rk   c                   > [         TU ]  U5        UR                  [        :  a  U R                  (       a  UR                  [        S5        OUR                  [        S5        U R                  (       a  UR                  [        S5        OfU R                  (       a  UR                  [        S5        O>U R                  (       a  UR                  [        S5        OUR                  [        S5        U R                  R                  U/ SQ5        g)	z(Export entity specific data as DXF tags.AcDbFaceRecordr
  AcDb3dPolylineVertexAcDbPolyFaceMeshVertexAcDbPolygonMeshVertexAcDb2dVertexr  N)rn   r   r   r   is_face_recordr   r   is_3d_polyline_vertexr  is_polygon_mesh_vertexrt   r   r   s     rh   r   DXFVertex.export_entity
  s    
 	i(%'""$$_6FG$$_lC--((:PQ22((:RS00((:QR((.I##	
rk   c                N    U R                   R                  U R                  -  S:H  $ )Nr   )rt   rM   VTX3Drf   s    rh   is_2d_polyline_vertexDXFVertex.is_2d_polyline_vertex/  s    xx~~

*a//rk   c                H    U R                   R                  U R                  -  $ rc   )rt   rM   POLYLINE_3D_VERTEXrf   s    rh   r   DXFVertex.is_3d_polyline_vertex3  s    xx~~ 7 777rk   c                H    U R                   R                  U R                  -  $ rc   )rt   rM   POLYGON_MESH_VERTEXrf   s    rh   r!   DXFVertex.is_polygon_mesh_vertex7  s    xx~~ 8 888rk   c                b    U R                   R                  U R                  -  U R                  :H  $ rc   )rt   rM   
FACE_FLAGSrf   s    rh   r  "DXFVertex.is_poly_face_mesh_vertex;  s"    xx~~/4??BBrk   c                b    U R                   R                  U R                  -  U R                  :H  $ rc   )rt   rM   r.  POLYFACE_MESH_VERTEXrf   s    rh   r  DXFVertex.is_face_record?  s$    0T5N5NNNrk   c                    U R                   (       a  U $ UR                  U R                  R                  5      U R                  l        U $ )zATransform the VERTEX entity by transformation matrix `m` inplace.)r  r,  rt   r   )rg   r.  s     rh   r,  DXFVertex.transformC  s4    KKK(9(9:rk   c                  ^
 U R                   n[        UR                  5      nUR                  u  pEnUR                  nUR
                  nUR                  n	[        5       m
[        U
4S jUR                  5        5       5      $ )a/  Return formatted vertex components as tuple.

Format codes:

    - ``x`` = x-coordinate
    - ``y`` = y-coordinate
    - ``z`` = z-coordinate
    - ``s`` = start width
    - ``e`` = end width
    - ``b`` = bulge value
    - ``v`` = (x, y, z) as tuple

Args:
    format: format string, default is "xyz"

c              3  .   >#    U  H
  nTU   v   M     g 7frc   rL  )r   rA  varss     rh   r   #DXFVertex.format.<locals>.<genexpr>b  s     ;NDT$ZNs   )
rt   r   r   xyzr   r   r   localsr  lower)rg   r  rt   r   r$  r%  r   bsrz   r7  s             @rh   r  DXFVertex.formatJ  sb    " hh%%aIIOOMMx;FLLN;;;rk   rL  rc   rP  rQ  rU  )r.  r   rN  r  )r9  )rN  r	   ) rX  rY  rZ  r[  r\  r]  r   r&   r)   acdb_vertexr_  EXTRA_VERTEX_CREATEDCURVE_FIT_TANGENTSPLINE_VERTEX_CREATEDSPLINE_FRAME_CONTROL_POINTr(  r+  r1  r.  r$  ro   r   rg  r%  r   r!  r  r  r,  r  rh  ri  rj  s   @rh   r  r    s    Gz;DJ
  !#$';;J!447KKE 8<4	 #
J 0 0 8 8 9 9 C C O O< <rk   r  c                    [        5       nUR                  5        Vs/ s H  o3[        ;   d  M  UPM     nn[        5       n[	        X5       H  u  p5U[        ;  a  M  US:X  a  [        U5      nM$  US:X  a  [        U5      US'   M:  US:X  a  [        U5      US'   MP  US:X  a  [        U5      US'   Mf  US:X  a  UR                  [        U5      S	9nM  US
:X  d  M  UR                  [        U5      S9nM     XBS'   U$ s  snf )a  Create VERTEX attributes from input data.

Format codes:

    - ``x`` = x-coordinate
    - ``y`` = y-coordinate
    - ``s`` = start width
    - ``e`` = end width
    - ``b`` = bulge value
    - ``v`` = (x, y [,z]) tuple (z-axis is ignored)

Args:
    data: list or tuple of point components
    format: format string, default is 'xyseb'

Returns:
   dict with keys: 'location', 'bulge', 'start_width', 'end_width'

r   r<  r   r=  r   rz   r   r$  )r$  r%  )r%  r   )r   r;  r+   r   r(  floatr   )datar  r  rA  r   values         rh   r	  r	  e  s    ( fG%||~F~t1Ed~FFvH6(|#3;E{HS[$U|GGS[%*5\GM"S[#(<GK S[''%,'7HS[''%,'7H ) #JN% Gs
   C;C;N)xyseb)rF  r	   rN  r   )X
__future__r   typingr   r   r   r   r   r	   r
   	itertoolsr   ezdxf.lldxfr   ezdxf.lldxf.attributesr   r   r   r   r   r   r   ezdxf.lldxf.constr   r   r   r   
ezdxf.mathr   r   r   r   r   ezdxf.math.transformtoolsr   r   ezdxf.render.polyliner   ezdxf.exploder!   ezdxf.queryr"   ezdxf.entitiesr#   ezdxf.auditr$   	dxfentityr&   r'   dxfgfxr(   r)   r*   
lwpolyliner+   	subentityr,   r-   r.   r/   r0   r1   ezdxf.layoutsr2   ezdxf.lldxf.tagwriterr3   ezdxf.eztypesr4   __all__point3dis_greater_or_equal_zero	is_one_ofis_not_null_vectorr^  acdb_polyline_group_codesrq   register_entityr5   r6   r  r  r7   r  r?  acdb_vertex_group_codesr  r  r	  rL  rk   rh   <module>re     s   #    !   B A  < < J ; ( # " " 4 D D $ %#>>(7&
. Ru}}gF Q'&r1tD$RTB88 
 88 
 $BDA#BDA )),7 
 RT:--22 
_7:v /}UK 76 $ 	S~ S SlWx Wt?9 ?9D, ,^7%x 7%t/1 /1d  Bemm4r1t<RT:
 Q6Q'2-T*T*T*T*$R$7#, -[9 54 
 	z<
 z< z<z'rk   