
    hT                       % 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  S SKrS SKrS SKJrJrJrJrJrJrJrJrJr  \(       a  S SKJr  S S	KJ r J!r!J"r"J#r#J$r$J%r%  / S
Qr&\" SS5      r'\" SS5      r(\\\\\4   r)S\*S'   \\   r+S\*S'   \S   r,S\*S'    " S S5      r- " S S\-5      r.          SS jr/\" S5      r0 " S S\-5      r1 " S S\5      r2g)    )annotations)TYPE_CHECKINGIterableTupleUnioncastSequenceOptional)	TypeAlias)abstractmethod)
namedtupleN)	Vec2Vec3UVecBSplineConstructionRayOCSParallelRaysErrorbulge_to_arcConstructionArc)Drawing)
DXFGraphicSolidTraceFace3d
LWPolylinePolyline)TraceBuilderLinearTraceCurvedTraceLinearStation)vertexstart_width	end_widthCurveStation)vertex0vertex1r   FacePolygon)r   r   r   Quadrilateralc                  H    \ rS rSr\SS j5       rSS jr S	   S
S jjrSrg)AbstractTrace0   c                    g N selfs    D/var/www/html/env/lib/python3.13/site-packages/ezdxf/render/trace.pyfacesAbstractTrace.faces1   s     	    c           	        SS jn/ n/ nU R                  5        H*  u  pEpgUR                  XV45        UR                  XG45        M,     [        U" U5      5      nUR                  [        [        U" U5      5      5      5        U$ )Nc              3     #    [        U 5      (       d  g [        U 5      n[        U5      nUv   U H!  nUR                  U5      (       a  M  Uv   UnM#     g 7fr/   )leniternextisclose)vertices	_verticesprevr"   s       r3   merge$AbstractTrace.polygon.<locals>.merge:   sK     x==XI	?DJ#||F++ L!D $s   AAA)r=   r)   returnzIterable[UVec])r4   extendlistreversed)	r2   r@   forward_contourbackward_contourup1down1down2up2contours	            r3   polygonAbstractTrace.polygon9   s{    
	" ')')&*jjl"C""E>2##SJ/ '3 u_-.xU+;%< =>?r6   Nc              #  Z  #    SSK Jn  US;  a  [        SU S35      e[        U=(       d    0 5      nU R	                  5        Hd  n[        S5       H  nXV   USU 3'   M     US:w  a  US	   US
'   US   US'   U" XU5      nU(       a  UR                  R                  U5        Uv   Mf     g7f)a  
Yields faces as SOLID, TRACE or 3DFACE entities with DXF attributes
given in `dxfattribs`.

If a document is given, the doc attribute of the new entities will be
set and the new entities will be automatically added to the entity
database of that document.

Args:
    dxftype: DXF type as string, "SOLID", "TRACE" or "3DFACE"
    dxfattribs: DXF attributes for SOLID, TRACE or 3DFACE entities
    doc: associated document

r   )new>   SOLIDTRACE3DFACEzInvalid dxftype .   vtxrS      vtx2   vtx3N)ezdxf.entities.factoryrP   	TypeErrordictr4   rangeentitydbadd)r2   dxftype
dxfattribsdocrP   faceientitys           r3   virtual_entitiesAbstractTrace.virtual_entitiesP   s     " 	/66.wiq9::**+
JJLD1X(,
S9%  ("%)!W
6"%)!W
6"c2F  (L !s   B)B+r0   rB   zIterable[Face])rB   r)   rR   NNrc   zOptional[Drawing]rB   zIterable[Quadrilateral])	__name__
__module____qualname____firstlineno__r   r4   rM   rg   __static_attributes__r0   r6   r3   r,   r,   0   s:     0 JN!5F!	 ! !r6   r,   c                  j    \ rS rSrSrSS jrS rS r\SS j5       r	 S       SS jjr
SS	 jrS
rg)r   t   zlLinear 2D banded lines like polylines with start- and end width.

Accepts 3D input, but z-axis is ignored.

c                     / U l         SU l        g Ng-q=	_stationsabs_tolr1   s    r3   __init__LinearTrace.__init__{   s    .0r6   c                ,    [        U R                  5      $ r/   r9   rv   r1   s    r3   __len__LinearTrace.__len__       4>>""r6   c                     U R                   U   $ r/   rv   r2   items     r3   __getitem__LinearTrace.__getitem__       ~~d##r6   c                ,    [        U R                  5      $ )z%`True` if at least one station exist.)boolrv   r1   s    r3   
is_startedLinearTrace.is_started   s     DNN##r6   Nc           	     .   Uc  Un[        U5      nU R                  n[        U5      (       a;  US   R                  R	                  XR
                  S9(       a  UR                  5         UR                  [        U[        U5      [        U5      5      5        g)a  Add a trace station (like a vertex) at location `point`,
`start_width` is the width of the next segment starting at this station,
`end_width` is the end width of the next segment.

Adding the last location again, replaces the actual last location e.g.
adding lines (a, b), (b, c), creates only 3 stations (a, b, c), this is
very important to connect to/from splines.

Args:
    point: 2D location (vertex), z-axis of 3D vertices is ignored.
    start_width: start width of next segment
    end_width:  end width of next segment

N)rw   )
r   rv   r   r"   r<   rw   popappendr!   float)r2   pointr#   r$   stationss        r3   add_stationLinearTrace.add_station   sp    " #IU>>>>hrl1199%9VLLNeU;-?yAQRSr6   c           	   #  (  ^^ #    U R                   m [        T 5      nUS:  a  g    SUU 4S jjn        S	S jnT S   R                  R                  T S   R                  5      n/ m[	        US-
  5       H8  nT U   u  pgnT US-      R                  n	TR                  [        XiXx5      5        M:     U" S5      u  pSnSnTS   u  pnn[	        [        T5      5       H  nTU   u  nnnnUS:X  a@  U(       a0  U" [        T5      S-
  5      u  nnU" UU
U5      nU" UUU5      nUnUnOUnUnU
nUnOU" XU5      nU" XU5      nU[        T5      S-
  :  a+  U" US-   5      u  nnU" UUU5      nU" UU
U5      nU
nUnUn
UnOUnUnUUUU4v   M     g7f)
a  Yields all faces as 4-tuples of :class:`~ezdxf.math.Vec2` objects.

First and last miter is 90 degrees if the path is not closed, otherwise
the intersection of first and last segment is taken into account,
a closed path has to have explicit the same last and first vertex.

rY   Nc                D   >^  U U4S jnTT    u  p#pEU" X#5      U" XE5      4$ )z0Create offset rays from segment offset vertices.c                   > U R                  U5      (       a7  TT   R                  TTS-      R                  -
  R                  n[        X5      $ [        X5      $ )N   )r<   r"   angler   )v1v2r   segmentr   s      r3   ray3LinearTrace.faces.<locals>.offset_rays.<locals>.ray   sV    ::b>> !)008GaK3H3O3OOe  +255*222r6   r0   )r   r   left1left2right1right2segmentsr   s   `     r3   offset_rays&LinearTrace.faces.<locals>.offset_rays   s.    
3 ,4G+<(E&u$c&&999r6   c                    [        U R                  R                  UR                  5      5      nUS:  d   [        [        R                  U-
  5      S:  a  U$  U R                  U5      $ ! [         a    Us $ f = f)z7Intersect two rays but take parallel rays into account.g*5{?)abs	directionangle_betweenmathpi	intersectr   )ray1ray2defaultr   s       r3   r   $LinearTrace.faces.<locals>.intersect   sj    
 44T^^DEEx3tww#7(#B~~d++$ s   A) )A87A8r   r   r   )r   intrB   z'tuple[ConstructionRay, ConstructionRay])r   r   r   r   r   r   rB   r   )rv   r9   r"   r<   r^   r   _normal_offset_points)!r2   countr   r   	is_closedstationstart_vertexr#   r$   
end_vertexoffset_ray1offset_ray2prev_offset_ray1prev_offset_ray2last_up1last_up2
last_down1
last_down2re   rH   rK   rI   rJ   last_offset_ray1last_offset_ray2vtx0vtx1next_offset_ray1next_offset_ray2rX   rZ   r   r   s!                                  @@r3   r4   LinearTrace.faces   s+     >>H19	:	:4	: 	:$	!	)8	CG		 QK&&..x|/B/BC	 UQY'G3;G3D0Ly!'A+.55J OO%lW ( $/q>  6>b\2J
s8}%A%-a["CeUAv :ES]UVEV9W6$&6$%5{CHD$%5{EJD  $H!%J D D#. #.  !!1D !1F3x=1$$5@Q5G2 "2 !1;F !1;D#. #. .. "dD((M &s   FFru   rB   None)rB   r   r/   )r   r   r#   r   r$   zOptional[float]rB   r   ri   )rl   rm   rn   ro   __doc__rx   r|   r   propertyr   r   r4   rp   r0   r6   r3   r   r   t   sa    #$ $ $
 MQTT(-T:IT	T6o)r6   r   c                    X-
  R                  5       nUR                  S5      nUR                  US-  5      nUR                  US-  5      nX-   X-   X-
  X-
  4$ )NTrY   )	normalize
orthogonal)startendr#   r$   
dir_vectororthooffset_start
offset_ends           r3   r   r     sj     +((*J!!$'E??;?3LQ/J	 r6   )r   r   c                      \ rS rSrSrSS jrS rS r\          SS j5       r	\ S         SS jj5       r
SS jrSS	 jrS
rg)r    i)  z2D banded curves like arcs or splines with start- and end width.

Represents always only one curved entity and all miter of curve segments
are perpendicular to curve tangents.

Accepts 3D input, but z-axis is ignored.

c                    / U l         g r/   r   r1   s    r3   rx   CurvedTrace.__init__3  s	    -/r6   c                ,    [        U R                  5      $ r/   r{   r1   s    r3   r|   CurvedTrace.__len__6  r~   r6   c                     U R                   U   $ r/   r   r   s     r3   r   CurvedTrace.__getitem__9  r   r6   c                B   U " 5       nUS-   n[         R                  " SUR                  U5      n[        UR	                  USS9[         R                  " X#U5      5       H=  u  u  pn
[        U	5      R                  S5      nUR                  [        U5      X5        M?     U$ )z
Create curved trace from a B-spline.

Args:
    spline: :class:`~ezdxf.math.BSpline` object
    start_width: start width
    end_width: end width
    segments: count of segments for approximation

r   r   )nT)nplinspacemax_tzipderivativesr   r   _append)clsspliner#   r$   r   curve_tracer   tr   
derivativewidthnormals               r3   from_splineCurvedTrace.from_spline<  s    $ e1KK6<</*-qA&KE(R+
&U *%006FUV;	+

 r6   c                   UR                   S::  a  [        SUR                    S35      eU " 5       n[        [        R                  " UR
                  S-  U-  5      S5      S-   n[        UR                  5      n[        UR                  UR                  U5      5      [        R                  " X#U5      5       H  u  pUR                  XU-
  U	5        M     U$ )aZ  
Create curved trace from an arc.

Args:
    arc: :class:`~ezdxf.math.ConstructionArc` object
    start_width: start width
    end_width: end width
    segments: count of segments for full circle (360 degree)
        approximation, partial arcs have proportional less segments,
        but at least 3

Raises:
    ValueError: if arc.radius <= 0

r   zInvalid radius: rT   g     v@rW   r   )radius
ValueErrormaxr   ceil
angle_spanr   centerr   r=   anglesr   r   r   )
r   arcr#   r$   r   r   r   r   r   r   s
             r3   from_arcCurvedTrace.from_arcX  s    . ::?/

|1=>>eDIIcnnu4x?@!DqHcjj!LLE*+KK6
LE v~u=	

 r6   c                    [         R                  U5      (       a  [         nOUR                  US-  5      nU R                  R	                  [        X-   X-
  5      5        g)z
Add a curve trace station (like a vertex) at location `point`.

Args:
    point: 2D curve location (vertex), z-axis of 3D vertices is ignored.
    normal: curve normal
    width:  width of station

rY   N)	_NULLVEC2r<   r   rv   r   r%   )r2   r   r   r   s       r3   r   CurvedTrace._append{  sK     V$$F%%eai0Fl5>5>JKr6   c              #     #    [        U R                  5      nUS:  a  gSnSnU R                   H  u  pEUc  UnUnM  X#XE4v   UnUnM     g7f)zBYields all faces as 4-tuples of :class:`~ezdxf.math.Vec2` objects.rY   Nr{   )r2   r   r   r   rX   rZ   s         r3   r4   CurvedTrace.faces  s^     DNN#19..JD|d((DD )s   A
Ar   Nr   )
r   r   r#   r   r$   r   r   r   rB   r    @   )
r   r   r#   r   r$   r   r   r   rB   r    )r   r   r   r   r   r   rB   r   ri   )rl   rm   rn   ro   r   rx   r|   r   classmethodr   r   r   r4   rp   r0   r6   r3   r    r    )  s    0#$   	
  
 6       	 
   
   DL r6   r    c                      \ rS rSrSrSS j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S jjrS r\SSS jj5       rSrg)r   i  a  Sequence of 2D banded lines like polylines with start- and end width or
curves with start- and end width.


.. note::

    Accepts 3D input, but z-axis is ignored. The :class:`TraceBuilder` is a
    2D only object and uses only the :ref:`OCS` coordinates!

c                     / U l         SU l        g rt   _tracesrw   r1   s    r3   rx   TraceBuilder.__init__  s    ,.r6   c                ,    [        U R                  5      $ r/   )r9   r   r1   s    r3   r|   TraceBuilder.__len__  s    4<<  r6   c                     U R                   U   $ r/   )r   r   s     r3   r   TraceBuilder.__getitem__  s    ||D!!r6   c                :    U R                   R                  U5        g)zAppend a new trace.N)r   r   r2   traces     r3   r   TraceBuilder.append  s    E"r6   c              #  f   #    U R                    H  nUR                  5        Sh  vN   M     g N	7f)zQYields all faces as 4-tuples of :class:`~ezdxf.math.Vec2` objects
in :ref:`OCS`.
N)r   r4   r  s     r3   r4   TraceBuilder.faces  s'      \\E{{}$$ "$s   #1/
1c              #     ^#    U R                  5        H)  n[        UR                  U4S jU 5       5      5      v   M+     g7f)zQYields all faces as 4-tuples of :class:`~ezdxf.math.Vec3` objects
in :ref:`WCS`.
c              3  f   >#    U  H&  n[        UR                  UR                  T5      v   M(     g 7fr/   r   xy.0v	elevations     r3   	<genexpr>)TraceBuilder.faces_wcs.<locals>.<genexpr>  s%     )RT$qssACC*C*CT   .1N)r4   tuplepoints_to_wcs)r2   ocsr  rd   s     ` r3   	faces_wcsTraceBuilder.faces_wcs  s4      JJLD)))RT)RRSS !s   ?Ac              #  V   #    U R                    H  nUR                  5       v   M     g7f)zkYields for each sub-trace a single polygon as sequence of
:class:`~ezdxf.math.Vec2` objects in :ref:`OCS`.
N)r   rM   r  s     r3   polygonsTraceBuilder.polygons  s!      \\E--/! "s   ')c              #     ^#    U R                    H7  n[        UR                  U4S jUR                  5        5       5      5      v   M9     g7f)zkYields for each sub-trace a single polygon as sequence of
:class:`~ezdxf.math.Vec3` objects in :ref:`WCS`.
c              3  f   >#    U  H&  n[        UR                  UR                  T5      v   M(     g 7fr/   r  r  s     r3   r  ,TraceBuilder.polygons_wcs.<locals>.<genexpr>  s%     !U_$qssACC";";_r  N)r   r  r  rM   )r2   r  r  r  s     ` r3   polygons_wcsTraceBuilder.polygons_wcs  s=      \\E!!!UU]]_!UU  "s   A	ANc              #  j   #    U R                    H  nUR                  XU5       Sh  vN   M     g N	7f)a  Yields faces as SOLID, TRACE or 3DFACE entities with DXF attributes
given in `dxfattribs`.

If a document is given, the doc attribute of the new entities will be
set and the new entities will be automatically added to the entity
database of that document.

.. note::

    The :class:`TraceBuilder` is a 2D only object and uses only the
    :ref:`OCS` coordinates!

Args:
    dxftype: DXF type as string, "SOLID", "TRACE" or "3DFACE"
    dxfattribs: DXF attributes for SOLID, TRACE or 3DFACE entities
    doc: associated document

N)r   rg   )r2   ra   rb   rc   r  s        r3   rg   TraceBuilder.virtual_entities  s.     * \\E--g3GGG "Gs   %31
3c                @   U R                   n[        U5      S:  a  g[        US   [        5      (       aj  [        US   [        5      (       aQ  [	        [        UR                  S5      5      n[	        [        US   5      nU H  u  pEnUR                  XEU5        M     ggg)zEClose multi traces by merging first and last trace, if linear traces.rY   Nr   r   )r   r9   
isinstancer   r   r   r   )r2   tracesfirstlastr   r#   r$   s          r3   closeTraceBuilder.close  s    v;?fQi--*VBZ2U2Ufjjm4EVBZ0D16-I  Y? 27 3V-r6   c           	        UR                  5       nUS:X  ar  [        SU5      nUR                  R                  n/ nUR                   H0  u  pgpn
[        Xg5      nU(       a  UnUn	UR                  XX45        M2     UR                  nGOEUS:X  Ga0  [        SU5      nUR                  (       d  [        S5      eUR                  nUR                  R                  nUR                  R                  n/ nUR                   H  n[        UR                  R                  5      nUR                  R                  S5      (       a  UR                  R                   nOUnUR                  R                  S5      (       a  UR                  R"                  n	OUn	UR                  R$                  n
UR                  XX45        M     O[        SU 35      eU(       a6  US	   S	   R'                  US
   S	   5      (       d  UR                  US	   5        U " 5       nSnSnSnSn[)        5       nU GH  u  npn
US:w  a  [+        UUU5      u  nnnnUS	:  a  [-        UU[.        R0                  " U5      [.        R0                  " U5      SS9nUR2                  R'                  U5      (       a  UnUnOUnUnUR                  [4        R7                  UUUU5      5        SnU
S:w  aH  UR8                  (       a-  UR;                  UX5        UR                  U5        [)        5       nU
nUnU	nUnM  UR;                  UX5        GM     UR8                  (       a  UR                  U5        U(       a  [=        U5      S:  a  UR?                  5         U$ )a  
Create a complete trace from a LWPOLYLINE or a 2D POLYLINE entity, the
trace consist of multiple sub-traces if :term:`bulge` values are
present. Uses only the :ref:`OCS` coordinates!

Args:
    polyline: :class:`~ezdxf.entities.LWPolyline` or 2D
        :class:`~ezdxf.entities.Polyline`
    segments: count of segments for bulge approximation, given count is
        for a full circle, partial arcs have proportional less segments,
        but at least 3


LWPOLYLINEr   POLYLINEr   z2D POLYLINE requiredr#   r$   zInvalid DXF type r   r   g        NT)is_counter_clockwiser   ) ra   r   dxfconst_widthlwpointsr   r   closedis_2d_polyliner\   r   default_start_widthdefault_end_widthr=   locationhasattrr#   r$   bulger<   r   r   r   r   degreesstart_pointr    r   r   r   r9   r,  )r   polyliner   ra   r3  pointsr  r  r#   r$   r;  r9  r5  r7  r8  r"   r  store_bulgestore_start_widthstore_end_widthstore_pointlinear_tracer   r   start_angle	end_angler   r   swews                                 r3   from_polylineTraceBuilder.from_polyline  s%    ""$l"L(3H",,22KF7?7H7H3ke: #.K +IxiGH 8I __F
"J1H** 677''F"*,,"B"B ( > >F"++

 3 34::%%m44"(**"8"8K"5K::%%k22 &

 4 4I 1I

((xiGH , /y9::&)A,..vbz!}==MM&)$#'"}4:0E;5c!9E:6Y A:)[1Y/-1C ..u55,.,.LL!5!5c2r8!LM!|** ,,UKKLL.#.=L#$/!"+#$$UKCC 5;D ""LL&c%j1n KKMr6   r   r   )r  r,   rB   r   ri   )r  r   r  r   rB   zIterable[Sequence[Vec3]])rB   zIterable[Polygon]rj   rk   r   )r>  r   r   r   rB   r   )rl   rm   rn   ro   r   rx   r|   r   r   r4   r  r  r#  rg   r,  r   rI  rp   r0   r6   r3   r   r     sk    	!"#%T" JNH5FH	 H0	@ g gr6   r   )
r   r   r   r   r#   r   r$   r   rB   r(   )3
__future__r   typingr   r   r   r   r   r	   r
   typing_extensionsr   abcr   collectionsr   r   numpyr   
ezdxf.mathr   r   r   r   r   r   r   r   r   ezdxf.documentr   ezdxf.entitiesr   r   r   r   r   r   __all__r!   r%   r(   __annotations__r)   r*   r,   r   r   r   r    r   r0   r6   r3   <module>rV     s   #   (  "  
 
 
 &UU
8?,RS .*@AdD$./i /d^ # !;<y <A AH`)- `)F).;@	 L	q- qhC8 Cr6   