
    OgZ                       U d dl mZ d dlmZmZmZmZmZmZm	Z	 d dl
mZmZ d dlZd dlZd dlmZ d dlmZ d dlmZmZmZmZmZmZ d dlmZmZmZmZ d d	lm Z m!Z! d d
l"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2m3Z3m4Z4 ddl5m6Z6m7Z7 ddl8m9Z9 ddlm:Z: erd dl;m<Z<m=Z= d dl>m?Z? d dlm@Z@ dgZA ed edd        eddej                         edej                  d       edej                  d       edej                  d        ed!d"d#$       ed%d"d#$       ed&d"d#$       ed'ej                  d#ej                  (       ed)ej                  d#ej                  (       ed*ej                  e'd#ej                  e+      d,      ZF eeF      ZG G d- d.      ZHh d/ZIeeeJ      ZKd0eLd1<   e9 G d2 de6             ZMy)3    )annotations)TYPE_CHECKINGListIterableSequencecastIteratorOptional)	TypeAliasSelfN)
AuditError)	validator)DXFAttrDXFAttributesDefSubclassXTypeRETURN_DEFAULTgroup_code_mapping)SUBCLASS_MARKERDXF2000DXFValueErrorDXFStructureError)VertexArrayTags)Vec3UVecMatrix44ConstructionEllipseZ_AXISNULLVECOCSuniform_knot_vectoropen_uniform_knot_vectorBSplinerequired_knot_valuesrequired_fit_pointsrequired_control_pointsfit_points_to_cad_cv   )
base_classSubclassProcessor	DXFEntity)
DXFGraphicacdb_entity)register_entity)default_copy)DXFNamespaceEllipse)AbstractTagWriter)AuditorSpline
AcDbSplineF   )defaultG      )r8   r   H   
knot_count)xtypegetterI   control_point_countJ   fit_point_count*   g|=T)r8   optional+   ,      )r=   rD   r         )r=   r8   rD   r   fixer)flagsdegreen_knotsn_control_pointsn_fit_pointsknot_tolerancecontrol_point_tolerancefit_tolerancestart_tangentend_tangent	extrusionc                      e Zd ZddZy)
SplineDatac                    |j                   | _         |j                  | _        |j                  | _        |j                  | _        y N)
fit_pointscontrol_pointsknotsweights)selfsplines     Z/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/entities/spline.py__init__zSplineData.__init__   s3     ++$33\\
~~    N)r_   r5   )__name__
__module____qualname__ra    rb   r`   rW   rW      s    &rb   rW   >   
      (   )   r;   r?   rA   r   Verticesc                      e Zd ZdZdZ eeee      Z	e
ZdZdZdZdZdZ fdZefd*d	Z	 d+	 	 	 d, fd
Zd-dZd. fdZd/dZed0d       Zej4                  d1d       Zed2d       Zej4                  d3d       Zd4dZed2d       Zej4                  d3d       Zed5d       Zej4                  d6d       Zd4dZed5d       Z e j4                  d6d       Z d4dZ!d7dZ"d8dZ#d9d:dZ$e%d;d       Z&d<d=dZ'd<d=d Z(d<d>d!Z)	 d<	 	 	 	 	 	 	 d?d"Z*	 d<	 	 	 	 	 	 	 d?d#Z+	 d<	 	 	 	 	 	 	 d?d$Z,d@d%Z-dA fd&Z.dBd'Z/dBd(Z0dCd)Z1 xZ2S )Dr5   zDXF SPLINE entitySPLINEr)               c                z    t         |           t               | _        t               | _        g | _        g | _        y rY   )superra   r   rZ   r[   r\   r]   )r^   	__class__s    r`   ra   zSpline.__init__   s/    %-)m
rb   c                H   t        |t              sJ t        j                  | j                        |_        t        j                  | j
                        |_        t        j                  | j                        |_        t        j                  | j                        |_        y)z<Copy data: control_points, fit_points, weights, knot_values.N)
isinstancer5   copydeepcopy_control_points_fit_points_knots_weights)r^   entitycopy_strategys      r`   	copy_datazSpline.copy_data   sh    &&)))!%t/C/C!D!]]4+;+;<dkk2--6rb   c                    t         |   |      }|ra|j                  d      }|r5t        | j	                  |            }|j                  |t        |d       |S t        d|j                   d      |S )Nrn   T)subclassrecoverz)missing 'AcDbSpline' subclass in SPLINE(#))	rs   load_dxf_attribssubclass_by_indexr   load_spline_datafast_load_dxfattribsacdb_spline_group_codesr   handle)r^   	processordxftagsrt   s       r`   r   zSpline.load_dxf_attribs   s     g&y1..q1DD11$78..04 /  
 (?

|1M  
rb   c              #  `  K   g }g }g }g }|D ]  }|\  }}|dk(  r|j                  |       |dk(  r|j                  |       6|dk(  r|j                  |       M|dk(  r|j                  |       d|dv rt        j                  |      r~|  || _        || _        || _        || _        yw)zLoad and set spline data (fit points, control points, weights,
        knots) and remove invalid start- and end tangents.
        Yields the remaining unprocessed tags.
        rg   rh   ri   rj   )rG   rH   N)appendr    iscloser[   rZ   r\   r]   )	r^   r   r[   rZ   r\   r]   tagcodevalues	            r`   r   zSpline.load_spline_data   s     
 
 	CKD%rz%%e,!!%(U#u%!gooe&< 		  -$
s   B,B.c                   t         |   |       |j                  t        t        j
                         | j                  j                  |g d       |j                  d| j                                |j                  d| j                                |j                  d| j                                | j                  j                  |g d       | j                  |       y)z(Export entity specific data as DXF tags.)rU   rK   rL   r;   r?   rA   )rP   rQ   rR   rS   rT   N)rs   export_entity
write_tag2r   acdb_splinenamer   export_dxf_attribsr<   r@   rB   export_spline_data)r^   	tagwriterrt   s     r`   r   zSpline.export_entity   s    i(_k.>.>?##I/OPR!23R!9!9!;<R!5!5!78##		
 		*rb   c                .   | j                   D ]  }|j                  d|        t        | j                        r#| j                  D ]  }|j                  d|        | j                  j                  |d       | j                  j                  |d       y )Nri   rj   rg   )r   rh   )r{   r   lenr|   ry   
export_dxfrz   )r^   r   r   s      r`   r   zSpline.export_spline_data   s    [[ 	,E  U+	, t}} 0$$R/0 	''	';##IB#7rb   c                <    | j                  | j                  d      S )z``True`` if spline is closed. A closed spline has a connection from
        the last control point to the first control point. (read/write)
        rK   )r   )get_flag_stateCLOSEDr^   s    r`   closedzSpline.closed   s    
 ""4;;W"==rb   c                @    | j                  | j                  |d       y )NrK   )stater   )set_flag_stater   )r^   statuss     r`   r   zSpline.closed  s    DKKvGDrb   c                    | j                   S )z(Knot values as :code:`array.array('d')`.)r{   r   s    r`   r\   zSpline.knots  s     {{rb   c                d    t        t        t           t        j                  d|            | _        y Nd)r   r   floatarrayr{   r^   valuess     r`   r\   zSpline.knots  s    #'UU[[f5M#Nrb   c                ,    t        | j                        S )zCount of knot values.)r   r{   r   s    r`   r<   zSpline.knot_count  s    4;;rb   c                    | j                   S )z2Control point weights as :code:`array.array('d')`.)r|   r   s    r`   r]   zSpline.weights  s     }}rb   c                d    t        t        t           t        j                  d|            | _        y r   )r   r   r   r   r|   r   s     r`   r]   zSpline.weights  s    %)$u+u{{37O%Prb   c                    | j                   S )z^:class:`~ezdxf.lldxf.packedtags.VertexArray` of control points in
        :ref:`WCS`.
        )ry   r   s    r`   r[   zSpline.control_points  s    
 ###rb   c                f    t        t        t        t        j                  |                  | _        y rY   )r   rk   r   r   listry   r^   pointss     r`   r[   zSpline.control_points%  s"    )-k$))F"34*
rb   c                ,    t        | j                        S )zCount of control points.)r   r[   r   s    r`   r@   zSpline.control_point_count,  s    4&&''rb   c                    | j                   S )zZ:class:`~ezdxf.lldxf.packedtags.VertexArray` of fit points in
        :ref:`WCS`.
        )rz   r   s    r`   rZ   zSpline.fit_points0  s    
 rb   c                f    t        t        t        t        j                  |                  | _        y rY   )r   rk   r   r   r   rz   r   s     r`   rZ   zSpline.fit_points7  s#    %)		&)*&
rb   c                ,    t        | j                        S )zCount of fit points.)r   rZ   r   s    r`   rB   zSpline.fit_point_count?  s    4??##rb   c                :   | j                         rvt        | j                        r| j                  nd}t        | j                        r| j                  nd}t	        | j
                  | j                  j                  dz   ||      S | j                         r{d}| j                  j                  d      rG| j                  j                  d      r,| j                  j                  | j                  j                  g}t        | j                  |      S t        d      )z:Returns the construction tool :class:`ezdxf.math.BSpline`.Nr)   )r[   orderr\   r]   rS   rT   tangentsz2Construction tool requires control- or fit points.)r@   r   r]   r\   r$   r[   r   rL   rB   hasattrrS   rT   r(   rZ   
ValueError)r^   r]   r\   r   s       r`   construction_toolzSpline.construction_toolC  s    ##%&)$,,&7dllTG"%djj/DJJtE#22hhoo)	  !!#Hxx0TXX5E5Em5T HH22DHH4H4HI'! 
 QRRrb   c                   	 |j                   | _         |j                  | j
                  _        g | _        |j                         | _        |j                         | _        | j                  t        j                  t        t        | j                                     | S # t        $ r) t        j                  |      }|j                   | _         Y w xY w)zApply SPLINE data from a :class:`~ezdxf.math.BSpline` construction
        tool or from a :class:`geomdl.BSpline.Curve` object.

        )r   )r[   AttributeErrorr$   from_nurbs_python_curverL   r   rZ   r\   r]   r   r5   RATIONALboolr   )r^   ss     r`   apply_construction_toolzSpline.apply_construction_toolZ  s    
	3"#"2"2D
 ((WWY
yy{FOO4DLL8I3JK  	3//2A"#"2"2D	3s   B /CCc                B    | j                         j                  ||      S )a  Adaptive recursive flattening. The argument `segments` is the
        minimum count of approximation segments between two knots, if the
        distance from the center of the approximation segment to the curve is
        bigger than `distance` the segment will be subdivided.

        Args:
            distance: maximum distance from the projected curve point onto the
                segment chord.
            segments: minimum segment count between two knots

        )r   
flattening)r^   distancesegmentss      r`   r   zSpline.flatteningl  s      %%'228XFFrb   c           
     P   |j                         }|dk(  rt        d|      j                         }n;|dk(  rxt        j                  |j
                  j                  dt              t        |j
                  j                  dd            |j
                  j                  dt                    }n|d	k(  rt        j                  |j
                  j                  dt              t        |j
                  j                  dd            |j
                  j                  dt              |j
                  j                  d
d      |j
                  j                  dd            }nt        d      t        j                  |j                         |j                        }t        j                   |      }|j"                  |j
                  _        t        j$                  |j
                  _        |j(                  |_        |j+                         |_        |j-                         |_        |S )zCreate a new SPLINE entity from a CIRCLE, ARC or ELLIPSE entity.

        The new SPLINE entity has no owner, no handle, is not stored in
        the entity database nor assigned to any layout!

        ELLIPSEr2   CIRCLEcenterradiusg      ?rU   )r   r   rU   ARCstart_angler   	end_angleih  )r   r   rU   r   r   z'CIRCLE, ARC or ELLIPSE entity required.)
dxfattribsdoc)dxftyper   r   r   from_arcr   getr    absr   	TypeErrorr5   newgraphic_propertiesr   r$   from_ellipserL   r   rK   r[   r\   r]   )clsr}   r   ellipser_   r   s         r`   r   zSpline.from_arcz  s    .."i9f-??AG )22zz~~h86::>>(C89 **..f=G
 )22zz~~h86::>>(C89 **..f="JJNN=!< **..c:G EFFv'@'@'B

S  )HH

!??

 ! 0 0wwyrb   c                    d| j                   _        || j                   _        || _        t	        t        |      |dz         | _        y)zpOpen B-spline with a uniform knot vector, start and end at your first
        and last control points.

        r   r)   N)r   rK   rL   r[   r#   r   r\   r^   r[   rL   s      r`   set_open_uniformzSpline.set_open_uniform  s9    
  ,-c..A6A:N
rb   c                    d| j                   _        || j                   _        || _        t	        t        |      |dz         | _        y)ztB-spline with a uniform knot vector, does NOT start and end at your
        first and last control points.

        r   r)   N)r   rK   rL   r[   r"   r   r\   r   s      r`   set_uniformzSpline.set_uniform  s9    
  ,(^)<fqjI
rb   c                   | j                   | j                  z  | j                  _        || j                  _        || _        | j
                  j                  |d|        t        t        | j
                        |dz         | _	        y)zhClosed B-spline with a uniform knot vector, start and end at your
        first control point.

        Nr)   )
PERIODICr   r   rK   rL   r[   extendr"   r   r\   r   s      r`   
set_closedzSpline.set_closed  si    
 4 ,"">'6#:;
 )T-@-@)A6A:N
rb   c                    | j                  ||       | j                  j                  | j                  z  | j                  _        t	        |      t	        | j
                        k7  rt        d      || _        y)zOpen rational B-spline with a uniform knot vector, start and end at
        your first and last control points, and has additional control
        possibilities by weighting each control point.

        rL   3Control point count must be equal to weights count.N)r   r   rK   r   r   r[   r   r]   r^   r[   r]   rL   s       r`   set_open_rationalzSpline.set_open_rational  s]     	nV<$--7w<3t2233 UVVrb   c                    | j                  ||       | j                  j                  | j                  z  | j                  _        t	        |      t	        | j
                        k7  rt        d      || _        y)zRational B-spline with a uniform knot vector, does NOT start and end
        at your first and last control points, and has additional control
        possibilities by weighting each control point.

        r   r   N)r   r   rK   r   r   r[   r   r]   r   s       r`   set_uniform_rationalzSpline.set_uniform_rational  s]     	7$--7w<3t2233 UVVrb   c                2   | j                  ||       | j                  j                  | j                  z  | j                  _        t	        |      }|j                  |d|        t        |      t        | j                        k7  rt        d      || _	        y)zClosed rational B-spline with a uniform knot vector, start and end at
        your first control point, and has additional control possibilities by
        weighting each control point.

        r   Nr   )
r   r   rK   r   r   r   r   r[   r   r]   r   s       r`   set_closed_rationalzSpline.set_closed_rational  sv     	v6$--7w-ww'(w<3t2233 UVVrb   c           	     >   | j                   j                  |       | j                  j                  |       | j                  }dD ]D  }|j	                  |      s|j                  ||j                  |j                  |                   F | j                  |       | S )zATransform the SPLINE entity by transformation matrix `m` inplace.)rS   rT   rU   )	ry   	transformrz   r   r   settransform_directionr   post_transform)r^   mr   r   s       r`   r   zSpline.transform  s    &&q)""1%hhA 	DD{{4 a33CGGDMBC	D 	Arb   c                   t         |   |       | j                  j                  }t	        |       }|dk  r:|j                  t        j                  d| d| d       |j                  |        yt        | j                        }t        | j                        }|dk(  r<|dk(  r7|j                  t        j                  d| d       |j                  |        y|dkD  r| j                  |       y|dkD  r| j                  |       yy)	zAudit the SPLINE entity.r)   Removed z with invalid degree: z < 1.r   messageNr   z" without any points (no geometry).)rs   auditr   rL   strfixed_errorr   INVALID_SPLINE_DEFINITIONtrashr   r[   rZ   _audit_control_points_audit_fit_points)r^   auditorrL   r   rN   rO   rt   s         r`   r   zSpline.audit  s   g4yA:99"4&(>vheL    MM$t2234??+q \Q%699"4&(JK    MM$a&&w/A""7+ rb   c           	        t        |       }| j                  j                  dz   }t        | j                        }t        |      }||k  r<|j                  t        j                  d| d| d|        |j                  |        y t        | j                        }t        | j                        }t        ||      }||k  r<|j                  t        j                  d| d| d|        |j                  |        y |rB||k7  r<|j                  t        j                  d| d| d|        |j                  |        y y y )	Nr)   r   z# with invalid control point count:  < r   z  with invalid knot value count: z with invalid weight count: z != )r   r   rL   r   r[   r'   r   r   "INVALID_SPLINE_CONTROL_POINT_COUNTr  r]   r\   r%   INVALID_SPLINE_KNOT_VALUE_COUNTINVALID_SPLINE_WEIGHT_COUNT)	r^   r  r   r   rN   n_control_points_required	n_weightsrM   n_knots_requireds	            r`   r  zSpline._audit_control_points"  si   4y!#t223 %<E$B!77BB"4&(K#$C(A'BD   
 MM$%	djj//0@%H%% ??"4&(H)3/02   
 MM$&66 ;;"4&(D+T"2!35   
 MM$ 79rb   c           	        t        |       }| j                  j                  dz   }t        |d      }t	        | j
                        }||k  r<|j                  t        j                  d| d| d|        |j                  |        y t	        | j                        r,|j                  t        j                  d| d	       g | _
        t	        | j                        r-|j                  t        j                  d
| d	       g | _        y y )Nr)   Tr   r   z with invalid fit point count: r  r   zRemoved unused knot values for z defined by fit points.zRemoved unused weights for )r   r   rL   r&   r   rZ   r   r   INVALID_SPLINE_FIT_POINT_COUNTr  r\   r  r]   r	  )r^   r  r   r   n_fit_points_requiredrO   s         r`   r  zSpline._audit_fit_pointsL  s   4y!# !4ED I 4??+//>>"4&(G.$9#:<   
 MM$ tzz???9$ @) *   
 DJ t||;;5dV;VW    DL rb   c                    t               S rY   )r!   r   s    r`   ocsz
Spline.ocso  s     urb   )r}   r   returnNonerY   )r   zOptional[SubclassProcessor]r  r1   )r  r	   )r   r3   r  r  )r   r3   )r  r   )r   r   r  r  )r  zlist[float])r   zIterable[float]r  r  )r  int)r  rk   )r   zIterable[UVec]r  r  )r  r$   )r  r5   )ro   )r   r   r   r  r  zIterator[Vec3])r}   r-   r  r5   )r:   )r[   Sequence[UVec]rL   r  r  r  )r[   r  r  r  )r[   r  r]   zSequence[float]rL   r  r  r  )r   r   r  r5   )r  r4   r  r  )r  r4   )r  r!   )3rc   rd   re   __doc__DXFTYPEr   r*   r.   r   
DXFATTRIBSr   MIN_DXF_VERSION_FOR_EXPORTr   r   r   PLANARLINEARra   r0   r   r   r   r   r   propertyr   setterr\   r<   r]   r[   r@   rZ   rB   r   r   r   classmethodr   r   r   r   r   r   r   r   r   r  r  r  __classcell__)rt   s   @r`   r5   r5      sI   Gz;DJ!(FHHFF 5A 7 8<4	"<+*	8 > > ]]E E   \\O O    ^^Q Q $ $ 
 
(     
 
$S.$G " "HOJO& 	& ! 	
 
* 	& ! 	
 
* 	& ! 	
 
&
,>(T!Frb   )N
__future__r   typingr   r   r   r   r   r	   r
   typing_extensionsr   r   r   rw   ezdxf.auditr   ezdxf.lldxfr   ezdxf.lldxf.attributesr   r   r   r   r   r   ezdxf.lldxf.constr   r   r   r   ezdxf.lldxf.packedtagsr   r   
ezdxf.mathr   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   	dxfentityr*   r+   r,   dxfgfxr-   r.   factoryr/   r0   ezdxf.entitiesr1   r2   ezdxf.lldxf.tagwriterr3   r4   __all__is_positivecallbackpoint3dis_not_null_vectorr   r   rW   REMOVE_CODESr   rk   __annotations__r5   rf   rb   r`   <module>r5     s   #   .   " !   5     @ ? + $ 47#*&  Q' "a93H3HI2U^^LI#enn-B
  %..ARS!"edC#*2ut#L UTB !--22	
 --22	
 --22 
E/2f -[9 & & ,8E?+) + `Z ` `rb   