
    Tij                     t   d dl mZ d dl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 ddlmZ d	d
lmZ d	dlmZmZmZmZ i ddd	dddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/Zd0 e                                D             Zd1Zd2Zd3Zd4Zd5Zd6 Zd=d8Zd>d9Z d?d:Z!d; Z"d<eiZ#dS )@    )defaultdictN   )grouping	resourcesutil)transformations)log)tol_path)
multi_dict   )to_threepoint)ArcBSplineLineText   inchesfeetmiles   millimeters   centimeters   meters   
kilometers   microinches	   mils
   yards   	angstroms   
nanometers   microns   
decimeters   
decameters   hectometers   
gigametersAUzlight yearsparsecs)         c                     i | ]\  }}||	S  r8   .0kvs      S/DATA/AppData/hermes/venv/lib/python3.11/site-packages/trimesh/path/exchange/dxf.py
<dictcomp>r>   %   s    555$!QA555    z|<^>|   zTRIMESH_METADATA:   ip  c                 b   |                                  }t          |d          rG|dd                             d          dk    rt          d          |                    dd	          }t          |                                          }|                    d
d                                                                          }t          j
        t
                              |                                        d          }t          j
        t
                              |                                        d          }t          j        |dddf         dk              d         }i }t          j        |dddf         dk              d         }t          |          dk    r|t          j        ||d                            }	||d         |	         }
i |d<   dD ]#\  }}t!          |
||          }|||d         |<   $dD ]<\  }}t!          |
|d          }||||<   ||z  }|t"          v rt"          |         |d<   =d|vrt%          j        d           t          j        |dddf         dk              d         d         }|t          j        ||                   }d}|||         dddf         }d|v sd|v r?	 t          j        |dddf         dk              d         d         }|t          j        ||                   }|||         }|||         }t          j        |ddgk                        d                    d         }i }t          j        t          j        t          |                    |          D ]O}	 t/          ||         ||         d          \  }}}t          |          dk    r||f||<   @# t0          $ r Y Lw xY wn&# t0          $ r t%          j        dd            Y nw xY wt/          |||         |||         |!          \  }}|||d"}|S )#a  
    Load a DXF file to a dictionary containing vertices and
    entities.

    Parameters
    ----------
    file_obj: file or file- like object (has object.read method)

    Returns
    ----------
    result: dict, keys are  entities, vertices and metadata
    decodeN   s   AutoCAD Binary DXFzBinary DXF is not supported!zutf-8ignoreerrors  )rE   r   r   ENDSECr   HEADER
DXF_HEADER))z$ACADVER1)z	$DIMSCALE40)z$DIMALT70)z$DIMALTFrO   )z$DIMUNITrP   )	$INSUNITSrP   )$LUNITSrP   ))rE   rR   )r   rQ   rP   unitsz!DXF doesn't have units specified!ENTITIESINSERTBLOCKBLOCKS0axisT)return_namezfailed to parse blocks!exc_info)blocks)verticesentitiesmetadata)readhasattrfindNotImplementedErrorrC   strstripreplaceuppernparray
splitlinesreshapenonzerolensearchsortedget_key
_DXF_UNITSr	   debugallarray_splitarangeconvert_entitiesBaseExceptionerror) file_objkwargsrawcleanedblob_rawblobendsecra   header_start
header_endheader_blobkeygroupvalueoffsetrS   entity_start
entity_endr^   check_entityblock_start	block_end
blob_blockblob_block_raw
block_inflindexr<   enamer_   r`   results                                    r=   load_dxfr   6   s   $ --//CsH 	7 ss8==.//255%&DEEE **WX*66C c((..

Ckk#r""((**0022G xs++,,44W==H8CNN7++,,44W==D ZQQQT
h.//2F H :d111a4jH455a8L
<1BOFLODDE
<?Z78 "$
 	4 	4JC Ke44E .3&s+ ? 
	6 
	6KFCKd33E}!HSMVOE
""$.u$5!(""I9::: :d111a4jJ677:1=L==>JFZ/0A6L<7l#:#:	@*T!!!Q$Z8%;<<Q?BKrv{CCDIk)34J%k)&;<NZC>%A$F$FA$F$N$NOOPQRJ F	#j//(B(BJOO  !1"5)>%+@d" " "JAq$ 1vvzz()1vt$   D  	@ 	@ 	@I/$??????	@ *\*$%xZ0G'HQW  Hh
 #hOOFMs7   C	O <OO 
OO OO  P PFc           	      	   !" || }d ! !"fd} !"fd} !"fd} !"fd} !"fd} "fd}	 "fd	}
t           |ft          |ft           |ft           |ft          |ft           |
ft           |
fd
}g "g  d}t          j        | dddf         dk              d         }t	          d           }t          j        t          j        t          |                     |          D ]}t          |          dk     r| |         d         d         }|dv rU	 t          d t                    D                       }||         |         d         |         d<   n# t          $ r Y nw xY w|dk    rt                    g}|)|dk    r#|                    t                               |f|dk    r_t          j        d |dd         D             t          j                  }d}d|d         v rMt          |d         d                   }t          |dz            }|rt          j        ||dd         f          }t          j        d t          |          D             t          j                  }t          j        d t          |          D             t          j                  }t%          ||||          \  }}|D ]}|xj        t          "          z  c_         "                    |                                |           d}1|dk    rc||         }| |         dddf         |dddf<   	  |	t          |                     s# t*          $ r t-          j        dd           Y w xY w||v r#||         \  }} |          } ||           |dk    r||xx         dz  cc<   t          |          dk    rVt-          j        d                     d!                    d" |                                D                                            t7          j        "                              t          j                  "|r'|| dddf         d#k             d         d         }" |fS " fS )$av  
    Convert a chunk of entities into trimesh entities.

    Parameters
    ------------
    blob : (n, 2) str
      Blob of entities uppercased
    blob_raw : (n, 2) str
      Blob of entities not uppercased
    blocks : None or dict
      Blocks referenced by INSERT entities
    return_name : bool
      If True return the first '2' value

    Returns
    ----------
    Nc                 R    dddfd|                                  D             }|S )zJ
        Pull metadata based on group code, and return as a dict.
        layerr   )82c                 `    i | ]*\  }}|v 	|         t          j        |          d          +S )r   )r   make_sequence)r:   r;   r<   gets      r=   r>   z2convert_entities.<locals>.info.<locals>.<dictcomp>   s9    VVV1QRUXX3q64-a003XXXr?   )items)r   renamedr   s     @r=   infozconvert_entities.<locals>.info   s;     &)) WVVV		VVVr?   c           
      B                        t          d	dt                    t          j        d          z   i |                                          t          j        | d         | d         g| d         | d         ggt          j                             dS )
zG
        Convert DXF LINE entities into trimesh Line entities.
        pointsr   10201121dtypeNr8   )appendr   ro   rj   rv   extendrk   float64)r   r`   r   r_   s    r=   convert_linez&convert_entities.<locals>.convert_line   s    
 	LLCMMBIaLL$@LDDGGLLMMMHqw$(1T7AdG*<=RZPPP	
 	
 	
 	
 	
r?   c           	         t          | d                   }t          j        | d         | d         g                              t          j                  }t          |dd         |          }                    t          d
t                    t          j	        d          z   dd	 |                      
                    |           dS )zJ
        Convert DXF CIRCLE entities into trimesh Circle entities
        rO   r   r   Nr   )centerradiusr   Tr   closedr8   )floatrj   rk   astyper   r   r   r   ro   rv   r   )r   RCr   r`   r   r_   s       r=   convert_circlez(convert_entities.<locals>.convert_circle   s     !D'NNHagqw'((//
;;aeA666NH	!4dNNdd1ggNN	
 	
 	
 	r?   c           	         t          | d                   }t          j        | d         | d         gt          j                  }t          j        t          j        | d         | d         gt          j                            }t          |dd         ||	          }                    t          dt                    t          j	        d
          z   dd |                      
                    |           dS )zJ
        Convert DXF ARC entities into into trimesh Arc entities.
        rO   r   r   r   5051Nr   )r   r   anglesr   Fr   r8   )r   rj   rk   r   radiansr   r   r   ro   rv   r   )r   r   r   Ar   r`   r   r_   s        r=   convert_arcz%convert_entities.<locals>.convert_arc   s    
 !D'NNHagqw'rz::: Jrx4!D' 2"*EEEFF aeAa@@@Y3x==29Q<<#?YYQUQUVWQXQXYYZZZr?   c                 &   t          j        | d         | d         f                              t           j                  } |           }d| v ot	          | d         d                   dz  }|rt          j        ||dd         f          }d| v rt          j        | d         t           j                  }t          j        dddf         dk              d         }t          j        dddf         dk              d         }|s(||                                k     }||         }||         }t          j	        ||          }t          ||||	          \  }	} | D ]}
|
xj        t                    z  c_                             |	                               |            dS                     t          dd
t          j        t          |                    t                    z   i|                               |           dS )zM
        Convert DXF LWPOLYLINE entities into trimesh Line entities.
        r   r   rP   r   r   N42r   linesbulge	bulge_idx	is_closedr   r8   )rj   column_stackr   r   intvstackrk   rn   maxrp   bulge_to_arcsr   ro   r   r   r   rv   )r   r   polyinfor   r   vidbidbid_okr   r<   ichunkr`   r   r_   s              r=   convert_polylinez*convert_entities.<locals>.convert_polyline  s   
 4!D' 233::2:FF 477 AI5#agaj//A"5	 	2IueBQBi011E 199HQtWBJ777E*U111a4[D011!4C*U111a4[D011!4C &swwyy&kfS11I 5I  DAq  * *CMM)OOAOOAF 	VVBIc%jj$9$9CMM$IVXVVWWWr?   c           
      8   t          j        | d         | d         f                              t           j                  }t          j        | d                                       t           j                  }t          |          dk    rc                    t          d
dt                    t          j        d          z   i |                      	                    |           dS t           j
                            |d         |d         z
            t          j        k     }                    t          d
t          j        t          |                    t                    z   ||d	 |                      	                    |           dS )zL
        Convert DXF Spline entities into trimesh BSpline entities.
        r   r   rO   r   r   Nr   rE   )r   knotsr   r8   )rj   r   r   r   rk   ro   r   r   rv   r   linalgnormtolmerger   )r   r   r   r   r`   r   r_   s       r=   convert_bsplinez)convert_entities.<locals>.convert_bspline7  sf    !D'1T7!344;;BJGG4!!((44 v;;!OODPPH	!(DPQPPQQQOOF###F
 q	F2J 677#)C 	 yV--H=  $q''	 	
 	
 	
 	r?   c           	         | d                                          }	 t          | d                   }n# t          $ r d}Y nw xY w	 t          j        t          | d                             }n# t          $ r d}Y nw xY wt          j        | d         | d         gt          j                  }|t          j        |          t          j        |          gz   }d	d	g}	 g d
t          | d                            |d<   n# t          $ r Y nw xY w
                    t          t                    t                    dz   |||                     
                    |           
                    |           dS )zF
        Convert a DXF TEXT entity into a native text entity.
        rN   rO   Nr           r   r   r   r   )leftr   right72r   r   )originvectorheighttextalign)rg   r   rx   rj   r   rk   r   cossinr   r   r   ro   )	r   r   r   angler   r   r   r`   r_   s	          r=   convert_textz&convert_entities.<locals>.convert_textZ  s   
 v||~~	1T7^^FF 	 	 	FFF		JuQtW~~..EE 	 	 	EEE	 1T7AdG,BJ???26%=="&--888$	2223qw<<@E!HH 	 	 	D	 	8}}8}}q(  	
 	
 	
 	s3   3 AA'A. .A=<A= C? ?
DDc                    dS | d         }|vrdS t          |                     dd                    }t          j        |                     dd          |                     dd          gt          j                  }t          j        |                     dd	          |                     d
d	          gt          j                  }|         \  }}|D ]L}	                    |                                           	d         xj        t          
          z  c_        M
	                    t          j        |t          j        |t          j        |          |                               dS )z
        Convert an INSERT entity, which inserts a named group of
        entities (i.e. a "BLOCK") at a specific location.
        Nr   r   r   r   r   r   41      ?r   rE   )r   thetascale)r   r   rj   rk   r   r   copyr   ro   r   tftransform_pointsplanar_matrixr   )r   r   r   r   r   cvcer   r^   r`   r_   s           r=   convert_insertz(convert_entities.<locals>.convert_insert  s^   
 >F vvFaeeD#&&''155s++QUU4-=-=>bjQQQ!%%c**AEE$,<,<=RZPPP B 	1 	1AOOAFFHH%%%RL3x==0B$F"*U:K:KSXYYY 	
 	
 	
 	
 	
r?   )LINE
LWPOLYLINEARCCIRCLESPLINErU   rV   r   rX   c                      dS )Nr   r8   r8   r?   r=   <lambda>z"convert_entities.<locals>.<lambda>  s    a r?   r   )rV   rU   c              3   8   K   | ]\  }}|d          dk    |V  dS )r   r   Nr8   )r:   r   r<   s      r=   	<genexpr>z#convert_entities.<locals>.<genexpr>  s.      !P!P1AaDCKK!KKKK!P!Pr?   POLYLINEVERTEXSEQENDc                 .    g | ]}|d          |d         gS )r   r   r8   r:   r   s     r=   
<listcomp>z$convert_entities.<locals>.<listcomp>  s%    GGGQqw$0GGGr?   r   FrP   c                      g | ]\  }}d |v 	|S r   r8   r:   r   r   s      r=   r   z$convert_entities.<locals>.<listcomp>  s!    @@@tq!daiiiiir?   c                 F    g | ]\  }}d |v 	t          |d                    S r  )r   r  s      r=   r   z$convert_entities.<locals>.<listcomp>  s+    MMMDAq4199qw999r?   r   TEXTzfailed to load text entity!Tr\   rT   zskipping dxf entities: {}z, c              3   *   K   | ]\  }}| d | V  dS )z: Nr8   r9   s      r=   r   z#convert_entities.<locals>.<genexpr>  s0      FF$!QQ++!++FFFFFFr?   r   )dictr   rj   rn   r   ru   rv   ro   next	enumerateStopIterationr   rk   r   r   boolr   int64r   r   r   rx   r	   rs   formatjoinr   r   vstack_emptyr   )#r   r~   r^   r[   r   r   r   r   r   r   r   loaderspolyline
inflectionunsupportedr   entity_type
index_namer   r   flagr   r   r   r   r   	chunk_rawchunkerloaderentity_datar   r   r`   r   r_   s#     `                            @@@@r=   rw   rw      s   & 
 
 
	
 	
 	
 	
 	
 	
 	

  
  
  
  
  
  
              &1 1 1 1 1 1 1 1f!  !  !  !  !  !  ! F'  '  '  '  '  ' R 
  
  
  
  
  
  
J |$!#34k"(/(' G HH HDAJ#-..q1Jii((K 	#d)) 4 4jAA R* R*u::>>UAhqk ---!!P!P	%0@0@!P!P!PPP
'/z'B1'Ej!!$$     *$$U}HH!kX&=&=OODKK((((!kX&=&=HGG(122,GGGrzZZZEIx{""8A;t,-- NN	 :IueBQBi&899E @@y22@@@  I HMMIh,?,?MMMj  E
 #5I  FB  * *CMM)OOBOOBHHF"" !I #5k!!!Q$/IaaadOHT)__----  H H H	7$GGGGGGH G##%k2OGV!'%..KF;J&&$$$)$$$
;!	'..		FF+2C2C2E2EFFFFF 	
 	
 	
  **11"*==H (QQQT
c)*1-a04''Xs%   AE!!
E.-E.M NNc           
         t          j        d          d dd fdfd}fd}fd	}fd
}t          j        d           ||||d}g }t	          | j        | j                  D ]\  }}	t          |          j        }
||	|vr |
|v rR ||
         || j	                  
                                }t          |          dk    r|                    |           vt          j        d|
           d                    |          }d t	          dt          j        | j        d         d                    D             }|                    d t	          dt          j        | j        d         d                    D                        t$                              | j        d          |d<    d         j        d!i |
                                g}|                    d                             |          
                                           |                    d         
                                           d                    |                              t.          d          }t0          j        rxt4                              t5          |                    }t          |          dz  dk    sJ t9          d |ddd         D                       sJ |                    d           |S )"a1  
    Export a 2D path object to a DXF file.

    Parameters
    ----------
    path : trimesh.path.path.Path2D
      Input geometry to export
    only_layers : None or set
      If passed only export the layers specified

    Returns
    ----------
    export : str
      Path formatted as a DXF file
    ztemplates/dxf.jsonFTc           	      h   t          j        | t           j                  } t          j        |           }|rTt          j        t          j        t          |          t           j                  	                    d          d          }n/t          j
        t          |          dft           j                  }|g dz  }|r|ddddf         }|ddddf         }d                    d	 t          |	                    d
          |	                    d
                    D                       }|S )a{  
        Format points into DXF- style point string.

        Parameters
        -----------
        points : (n,2) or (n,3) float
          Points in space
        as_2D : bool
          If True only output 2 points per vertex
        increment : bool
          If True increment group code per point
          Example:
            [[X0, Y0, Z0], [X1, Y1, Z1]]
          Result, new lines replaced with spaces:
            True  -> 10 X0 20 Y0 30 Z0 11 X1 21 Y1 31 Z1
            False -> 10 X0 20 Y0 30 Z0 10 X1 20 Y1 30 Z1

        Returns
        -----------
        packed : str
          Points formatted with group code
        r   rE   r   )r   r   r   )r"   r6      Nr   
c              3   .   K   | ]\  }}|d d|dV  dS dr  .12gNr8   )r:   gr<   s      r=   r   z4export_dxf.<locals>.format_points.<locals>.<genexpr>Y  sK       
 
#'1aqa
 
 
 
 
 
r?   rE   )rj   
asanyarrayr   r   stack_3Dtilerv   ro   r  rm   zerosr  zip)r   as_2D	incrementthreer   packeds         r=   format_pointsz!export_dxf.<locals>.format_points3  s)   . vRZ888f%% 	>G	#e**BH555==gFF EE Hc%jj!_BH===E 	!!!!RaR%LE!!!RaR%LE 
 
+.u}}R/@/@%--PRBSBS+T+T
 
 
 
 
 r?   c                     ddt          t          |                     dd         d}t          | d          rt          j        | j                  |d<   |S )a  
        Pull layer, color, and name information about an entity

        Parameters
        -----------
        entity : entity object
          Source entity to pull metadata

        Returns
        ----------
        subs : dict
          Has keys 'COLOR', 'LAYER', 'NAME'
           r   Nr.   )COLORLAYERNAMEr   r1  )rf   idrc   r   to_asciir   )entitysubss     r=   entity_infozexport_dxf.<locals>.entity_info_  s\      6

OOCRC(
 

 67## 	8 M&,77DMr?   c                 0   |                      |          }t          |          dk    rdS  |           } |dd          |d<   d|d<   t          |          |d	<   t          t          | j                            |d
<    d         j        di |}|S )aB  
        Convert an entity to a discrete polyline

        Parameters
        -------------
        line : entity
          Entity which has 'e.discrete' method
        vertices : (n, 2) float
          Vertices in space

        Returns
        -----------
        as_dxf : str
          Entity exported as a DXF
        r   rJ   TF)r)  r*  POINTSr   TYPEVCOUNTFLAGliner8   )discretero   r   r
  r   r  )r=  r_   r   r6  r   r7  r-  templates        r=   r   z export_dxf.<locals>.convert_linex  s    " x((v;;!2 {4  &vTUKKKX#VVX 4,,--V(&!(00400r?   c                    |                      |dd          } |           }|j         }t          |          dk    rt          j        |d          } dj        | }|d|j        dz  }| j        rd	|d
<   n.d|d
<   |dz  }| dj        t          j        |j                   z  }||d<    d         j        di |}|S )NTF)return_anglereturn_normalr   r   z 10
{:.12g}
20
{:.12g}
30
{:.12g}z
40
r"  r   r:  r   z
100
AcDbArcz
50
{:.12g}
51
{:.12g}DATAarcr8   )	r   ro   rj   r   r  r   r   degreesr   )	rD  r_   r   r6  r   datar   r7  r?  s	          r=   r   zexport_dxf.<locals>.convert_arc  s    zz(UzKK{3v;;!Yvs++F=6=vF+++++: 	R#DLL DL $$D707DK9P9PQQDV'%'//$//r?   c                      || j                  d          } dt          | j                  z  j        | j         d d         }ddddd	d
}|d         }| j        r||d         z  }g d}g d}d                    d t          ||          D                       } |           }	|	                    d|||d|dt          | j                  t          | j                   d	            d         j        di |	}
|
S )NFr*  z40
{:.12g}
rE   r   r   r   r   r.   )r   periodicrationalplanarlinearrK  r   )r   r   r   )         r  c              3   .   K   | ]\  }}|d d|dV  dS r   r8   )r:   r   js      r=   r   z6export_dxf.<locals>.convert_bspline.<locals>.<genexpr>  s:      MMAQ,,,A,,,MMMMMMr?   r   r   r   )	r:  r9  KNOTSNORMALDEGREEr<  FCOUNTKCOUNTPCOUNTbspliner8   )r   ro   r   r  r   r  r(  update)spliner_   r   r   flagsr  normaln_coden_strr6  r   r7  r-  r?  s              r=   r   z#export_dxf.<locals>.convert_bspline  s>   x6%HHH =3v|#4#44<flKCRCP !aSUVVX= 	*%/)D  		MMVV9L9LMMMMM{6""  fl++fm,,
 
	
 	
 	
 ,)$+33d33r?   c                 z    |           } || j         g         d          |d<   t          j        |                     |                    |d<   | j                            dt                                        dd                              d          |d	<   | j	        |d
<    d         j
        di |}|S )z6
        Convert a Text entity to DXF string.
        FrH  ORIGINANGLErI   asciirF   rG   r  HEIGHTr   r8   )r   rj   rE  r   r   rh   
_SAFESPACEencoderC   r   r  )txtr_   subr   r7  r-  r?  s       r=   r   z export_dxf.<locals>.convert_text  s    
 k#%h
|&<NNNHz#))H"5"566G HS*--VGHV--VG__ 	F 
H(&!(//3//r?   c                      | |          S )zl
        For entities we don't know how to handle, return their
        discrete form as a polyline
        r8   )r5  r_   r   s     r=   convert_genericz#export_dxf.<locals>.convert_generic  s    
 |FH---r?   r&   )	precision)r   r   r   Bezierr   Nr   zEntity type %s not exported!r  c                      i | ]\  }}d | |S )EXTMIN_r8   r9   s      r=   r>   zexport_dxf.<locals>.<dictcomp>  s$    TTTAMaMM1TTTr?   XYZr   c                      i | ]\  }}d | |S )EXTMAX_r8   r9   s      r=   r>   zexport_dxf.<locals>.<dictcomp>  s$    YYYda1YYYr?   r   LUNITSheaderr`   )rT   footerrI   r   c              3   <   K   | ]}t          |          d k    V  dS )r   N)r   r   s     r=   r   zexport_dxf.<locals>.<genexpr>(  s,      3313q66Q;333333r?   rb  )FTr8   )r   get_jsonrj   set_printoptionsr(  r`   layerstype__name__r_   rg   ro   r   r	   rs   r  boundsrY  _UNITS_TO_DXFr   rS   r  rh   rd  r   strictrf   rl   rt   re  )pathonly_layersr   r   r   ri  conversions	collectedr   r   r   	convertedentities_strhsubsectionsr   r   r   r7  r-  r?  s                    @@@@r=   
export_dxfr     s   " !"677H* * * *X  2             D     .# # # # # # #J      ,. . . . . "%%%% !" K It{33 < <5Aww"uK'?'?;)D)!T];;AACCI9~~!!  +++I4d;;;; 99Y''L UTUBIdk!nc4R4R)S)STTTDKKYYc%4;q>SV9W9W.X.XYYYZZZ"&&tz155DN)")11D117799:HOOHZ(///FFLLNNOOOOOHX&,,../// 99X&&z377D
z s4yy))E

Q1$$$$33ccc
33333333GKr?   c                 r	   t          j        | t           j                  } t          j        |t           j                  }t          j        |t           j                  }t          j        |          dk    }||         }||         }|i }t          |          dk    r3t          j        t          |                     }t          |fi |g}| |fS t          j        |          dz  }t          j	        ||dz
  f          }	|r|	t          |           z  }	| |	dddf                  | |	dddf                  z
  }
t           j
                            |
d          }t          j        t          j	        |
t          j        t          |
                    f          t          j        t          |
          df          g d	z            }t          j        |dddd
f                   }| |	                             d          }|dz  t          j        |dz            z  }|t          j        |d
z            |z  z
  }t          j	        | |	dddf                  |||                    d          z  z   | |	dddf                  f                              d          }t*          j        rd
dlm fd|D             }t          j        t          j        |          t          j        |                    sJ fd|D             }t          j        |t          j        |                    sJ g g }}|D ]Z}|                    t7          ddt          j        d          t          |          z   i|           |                    |           [t          |           dz
  t          |          k    rt          j        t          j        t          |                               }t=          j        |t          j         |	d          t           j!                  D ]r}|                    t          ddt          j        d
          t          |          z   i|           |                    | |         "                                           st          j#        |t           j                  }||fS )a  
    Polylines can have "vertex bulge" which means the polyline
    has an arc tangent to segments, rather than meeting at a
    vertex.

    From Autodesk reference:
    The bulge is the tangent of one fourth the included
    angle for an arc segment, made negative if the arc
    goes clockwise from the start point to the endpoint.
    A bulge of 0 indicates a straight segment, and a
    bulge of 1 is a semicircle.

    Parameters
    ----------------
    lines : (n, 2) float
      Polyline vertices in order
    bulge : (m,) float
      Vertex bulge value
    bulge_idx : (m,) float
      Which index of lines is bulge associated with
    is_closed : bool
      Is segment closed
    metadata : None, or dict
      Entity metadata to add

    Returns
    ---------------
    vertices : (a, 2) float
      New vertices for poly-arc
    entities : (b,) entities.Entity
      New entities, either line or arc
    r   gh㈵>Nr   g      @r   rY   r   )r   r   r   r   g       @r  )rE   r   r   )
arc_centerc                 0    g | ]} |          j         S r8   )spanr:   r   r  s     r=   r   z!bulge_to_arcs.<locals>.<listcomp>  s$    999azz!}})999r?   c                 0    g | ]} |          j         S r8   )r   r  s     r=   r   z!bulge_to_arcs.<locals>.<listcomp>  s$    ;;;zz!}}+;;;r?   r   r8   )$rj   r$  r   r  absro   rv   r   arctanr   r   r   crossr'  onesr   unitizemeanr   r   rm   r   r|  rD  r  allcloser   r   r   stack_linesr   boolean_rowssort	setdiff1dr   rk   )r   r   r   r   ra   okr   r`   r   tidr   lengthperpmidpointr   r   r+  check_anglecheck_radiir_   
arc_pointsexistingline_idxr  s                          @r=   r   r   /  s}   D M%rz222E M%rz222Eirx888I 
	B"IE"I  5zzQ	#e**%%++(++,h Ies"E
/9i!m4
5
5C s5zz 3qqq!t9c!!!Q$i 00F Y^^F^++F 8
#f++!6!6788
Va !!III- D
 <QQQU$$D SzA&&H slbfUS[111F bfUQY''&00F O	s111a4y	8dV^^G-D-D&DDeCPQPQPQSTPTIFVW gj 
 z 8$$$$$$99995999{26%=="&*=*=>>>>>;;;;U;;;{;v77777 RhH $ $
LL29Q<<#h--#?L8LLMMM
#### 	E

Q#e**$$#BIc%jj$9$9:: -bgc***BL
 
 	4 	4H OODQQ	!s8}}(DQQQRRROOE(O00223333 x
333HXr?   c                    	 | t          j        | dddf         |k              d         d         dz            }n# t          $ r Y dS w xY w|d         |k    r.	 t          |d                   S # t          $ r |d         cY S w xY wdS )zN
    Given a loaded (n, 2) blob and a field name
    get a value by code.
    Nr   r   )rj   rn   
IndexErrorr   
ValueError)r   fieldcoder=  s       r=   rq   rq     s    
BJtAAAqDzU233A6q9A=>   ttAw$	tAw<< 	 	 	7NNN	 ts!   7: 
AAA- -BBdxf)NNF)N)FN)$collectionsr   numpyrj   rJ   r   r   r   r   r   	constantsr	   r
   r   r   rD  r   r`   r   r   r   r   rr   r   r{  rd  XRECORD_METADATAXRECORD_SENTINELXRECORD_MAX_LINEXRECORD_MAX_INDEXr   rw   r  r   rq   _dxf_loadersr8   r?   r=   <module>r     si   # # # # # #     ) ) ) ) ) ) ) ) ) ) % % % % % %       ( ( ( ( ( (             / / / / / / / / / / / /xv w }	
 } x | } v    	    !" #$ 	)  
. 65*"2"2"4"4555 
   '     De e e ePL L L L^   D  & x r?   