
    'jZ                       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/m0Z0m1Z1 ddl2m3Z3m4Z4 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jB                   edejC        d           edejC        d           edejC        d            ed!d"d#$           ed%d"d#$           ed&d"d#$           ed'ejD        d#ejE        (           ed)ejD        d#ejE        (           ed*ejD        e'd#ejE        e+          d,          ZF eeF          ZG G d- d.          ZHh d/ZIeeeJ                  ZKd0eLd1<   e9 G d2 de6                      ZMdS )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round_knots   )
base_classSubclassProcessor)
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dS )
SplineDataspliner5   c                f    |j         | _         |j        | _        |j        | _        |j        | _        d S N)
fit_pointscontrol_pointsknotsweights)selfrX   s     O/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/entities/spline.py__init__zSplineData.__init__   s-     +$3\
~    N)rX   r5   )__name__
__module____qualname__ra    rb   r`   rW   rW      s(        & & & & & &rb   rW   >   
      (   )   r;   r?   rA   r   Verticesc                  j    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dOdZ	 dPdQ fdZdRdZdS fdZdTdZedUd            Zej        dVd            ZedWd            Zej        dXd!            ZdYd#ZedWd$            Zej        dXd%            ZedZd'            Zej        d[d*            ZdYd+ZedZd,            Z e j        d[d-            Z dYd.Z!d\d0Z"d]d1Z#d^d_d6Z$e%d`d8            Z&dadbd=Z'dadbd>Z(dadcd?Z)	 dadddBZ*	 dadddCZ+	 dadddDZ,dedGZ-df fdJZ.dgdKZ/dgdLZ0dhdNZ1 xZ2S )ir5   zDXF SPLINE entitySPLINEr*               c                    t                                                       t                      | _        t                      | _        g | _        g | _        d S rZ   )superra   r   r[   r\   r]   r^   )r_   	__class__s    r`   ra   zSpline.__init__   sB    %--)mm
rb   entityr   returnNonec                $   t          |t                    sJ t          j        | j                  |_        t          j        | j                  |_        t          j        | j                  |_        t          j        | j                  |_        dS )z<Copy data: control_points, fit_points, weights, knot_values.N)
isinstancer5   copydeepcopy_control_points_fit_points_knots_weights)r_   ru   copy_strategys      r`   	copy_datazSpline.copy_data   sl    &&)))))!%t/C!D!D!]4+;<<dk22-66rb   N	processorOptional[SubclassProcessor]r1   c                .   t                                          |          }|rp|                    d          }|rAt          |                     |                    }|                    |t          |d           n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_   r   dxftagsrt   s       r`   r   zSpline.load_dxf_attribs   s     gg&&y11 
	..q11D D11$7788..04 /     (M
MMM   
rb   r	   c              #    K   g }g }g }g }|D ]}|\  }}|dk    r|                     |           #|dk    r|                     |           ?|dk    r|                     |           [|dk    r|                     |           w|dv rt          j        |          r|V  || _        || _        || _        || _        dS )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\   r[   r]   r^   )	r_   r   r\   r[   r]   r^   tagcodevalues	            r`   r   zSpline.load_spline_data   s      
 
 	 	CKD%rzz%%e,,,,!!%((((U####u%%%%!!goe&<&<! 				,$
rb   	tagwriterr3   c                "   t                                          |           |                    t          t          j                   | j                            |g d           |                    d|                                            |                    d| 	                                           |                    d| 
                                           | j                            |g d           |                     |           dS )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_   r   rt   s     r`   r   zSpline.export_entity   s    i(((_k.>???##I/O/O/OPPPR!2!2333R!9!9!;!;<<<R!5!5!7!7888##  		
 		
 		
 		*****rb   c                   | j         D ]}|                    d|           t          | j                  r | j        D ]}|                    d|           | j                            |d           | j                            |d           d S )Nri   rj   rg   )r   rh   )r~   r   lenr   r|   
export_dxfr}   )r_   r   r   s      r`   r   zSpline.export_spline_data   s    [ 	, 	,E  U++++t} 	0 0 0$$R////''	';;;##IB#77777rb   boolc                :    |                      | 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   statusc                @    |                      | j        |d           d S )NrK   )stater   )set_flag_stater   )r_   r   s     r`   r   zSpline.closed  s%    DKvGDDDDDrb   list[float]c                    | j         S )z(Knot values as :code:`array.array('d')`.)r~   r   s    r`   r]   zSpline.knots  s     {rb   valuesIterable[float]c                v    t          t          t                   t          j        d|                    | _        d S Nd)r   r   floatarrayr~   r_   r   s     r`   r]   zSpline.knots  s'    #'UU[f5M5M#N#Nrb   intc                *    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                v    t          t          t                   t          j        d|                    | _        d S r   )r   r   r   r   r   r   s     r`   r^   zSpline.weights  s'    %)$u+u{37O7O%P%Prb   rk   c                    | j         S )z^:class:`~ezdxf.lldxf.packedtags.VertexArray` of control points in
        :ref:`WCS`.
        )r|   r   s    r`   r\   zSpline.control_points  s    
 ##rb   pointsIterable[UVec]c                x    t          t          t          t          j        |                              | _        d S rZ   )r   rk   r   r   listr|   r_   r   s     r`   r\   zSpline.control_points&  s,    )-hDIfDUDU8V8V)W)W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`.
        )r}   r   s    r`   r[   zSpline.fit_points/  s    
 rb   c                x    t          t          t          t          j        |                              | _        d S rZ   )r   rk   r   r   r   r}   r   s     r`   r[   zSpline.fit_points6  s2    %)	&))**&
 &
rb   c                *    t          | j                  S )zCount of fit points.)r   r[   r   s    r`   rB   zSpline.fit_point_count>  s    4?###rb   r$   c                (   |                                  rxt          | j                  r| j        nd}t          | j                  r t	          | j        | j        j                  }nd}t          | j        | j        j	        dz   ||          S | 
                                rdd}| j                            d          r2| 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   rP   r$   r\   rL   rB   hasattrrS   rT   r(   r[   
ValueError)r_   r^   r]   r   s       r`   construction_toolzSpline.construction_toolB  s   ##%% 	S&)$,&7&7AdllTG4: #DJ0GHH#2ho)	    !!## 
	SHx00 JTX5E5Em5T5T J H2DH4HI'!   
 QRRRrb   c                   	 |j         | _         n0# t          $ r# t          j        |          }|j         | _         Y nw xY w|j        | j        _        g | _        |                                | _        |                                | _        | 	                    t          j        t          t          | j                                       | S )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   r[   r]   r^   r   r5   RATIONALr   r   )r_   ss     r`   apply_construction_toolzSpline.apply_construction_tool]  s    
	3"#"2D 	3 	3 	3/22A"#"2D	3 (WWYY
yy{{FO4DL8I8I3J3JKKKs    *<<distancer   segmentsIterator[Vec3]c                R    |                                                      ||          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_   r   r   s      r`   r   zSpline.flatteningo  s&     %%''228XFFFrb   r-   c           
     `   |                                 }|dk    r$t          d|                                          }nC|dk    rzt          j        |j                            dt                    t          |j                            dd                    |j                            dt                              }n|d	k    rt          j        |j                            dt                    t          |j                            dd                    |j                            dt                    |j                            d
d          |j                            dd                    }nt          d          t                              |                                |j                  }t          j        |          }|j        |j        _        t          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^   )clsru   r   ellipserX   r   s         r`   r   zSpline.from_arc}  s    ..""i9f--??AAGG  )2z~~h886:>>(C8899 *..f==  GG
 )2z~~h886:>>(C8899 *..f=="JNN=!<< *..c::  GG EFFFv'@'@'B'B
SS ))H
!?
 ! 0wwyyrb   r:   r\   Sequence[UVec]rL   c                    d| j         _        || j         _        || _        t	          t          |          |dz             | _        dS )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  s?    
  ,-c..A.A6A:NN


rb   c                    d| j         _        || j         _        || _        t	          t          |          |dz             | _        dS )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  s?    
  ,(^)<)<fqjII


rb   c                    | j         | j        z  | j        _        || j        _        || _        | j                            |d|                    t          t          | j                  |dz             | _	        dS )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  sm    
 4 ,"">'6'#:;;;
 )T-@)A)A6A:NN


rb   r^   Sequence[float]c                    |                      ||           | j        j        | j        z  | j        _        t	          |          t	          | j                  k    rt          d          || _        dS )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  sg     	nV<<<$-7w<<3t23333 UVVVrb   c                    |                      ||           | j        j        | j        z  | j        _        t	          |          t	          | j                  k    rt          d          || _        dS )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  sg     	777$-7w<<3t23333 UVVVrb   c                >   |                      ||           | j        j        | j        z  | j        _        t	          |          }|                    |d|                    t          |          t          | j                  k    rt          d          || _	        dS )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  s     	v666$-7w--www'(((w<<3t23333 UVVVrb   mr   c           	     R   | j                             |           | j                            |           | j        }dD ]S}|                    |          r<|                    ||                    |                    |                               T|                     |           | S )zATransform the SPLINE entity by transformation matrix `m` inplace.)rS   rT   rU   )	r|   	transformr}   r   r   settransform_directionr   post_transform)r_   r   r   r   s       r`   r   zSpline.transform  s    &&q)))""1%%%hA 	D 	DD{{4   Da33CGGDMMBBCCCArb   auditorr4   c                ^   t                                          |           | j        j        }t	          |           }|dk     r?|                    t          j        d| d| d           |                    |            dS t          | j
                  }t          | j                  }|dk    rB|dk    r<|                    t          j        d| d           |                    |            dS |dk    r|                     |           dS |dk    r|                     |           dS dS )	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\   r[   _audit_control_points_audit_fit_points)r_   r  rL   r   rN   rO   rt   s         r`   r  zSpline.audit  sY   g4yyA::9L4LLvLLL      MM$Ft2334?++q  \Q%6%69K4KKK      MM$Fa&&w/////A""7+++++ rb   c           	        t          |           }| j        j        dz   }t          | j                  }t          |          }||k     rA|                    t          j        d| d| d|            |	                    |            d S t          | j
                  }t          | j                  }t          ||          }||k     rA|                    t          j        d| d| d|            |	                    |            d S |rG||k    rC|                    t          j        d| d| d|            |	                    |            d S d S d S )	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%  s   4yy!#t233 %<E$B$B!777BD4 D D#D D(AD D     
 MM$F%%	dj///0@%HH%%% ?24 2 22 2/2 2     
 MM$F 		&666 ;54 5 55 5"25 5     
 MM$F		 		66rb   c           	        t          |           }| j        j        dz   }t          |d          }t	          | j                  }||k     rA|                    t          j        d| d| d|            |	                    |            d S t	          | j
                  r,|                    t          j        d| d	           g | _
        t	          | j                  r.|                    t          j        d
| d	           g | _        d S d S )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   r[   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_pointsO  sd   4yy!# !4ED I I I 4?++///><4 < << <$9< <     
 MM$F tz?? 	?*$ * * *     
 DJ t| 	;WdWWW      DLLL	 	rb   r!   c                    t                      S rZ   )r!   r   s    r`   ocsz
Spline.ocsr  s     uurb   )ru   r   rv   rw   rZ   )r   r   rv   r1   )rv   r	   )r   r3   rv   rw   )r   r3   )rv   r   )r   r   rv   rw   )rv   r   )r   r   rv   rw   )rv   r   )rv   rk   )r   r   rv   rw   )rv   r$   )rv   r5   )ro   )r   r   r   r   rv   r   )ru   r-   rv   r5   )r:   )r\   r   rL   r   rv   rw   )r\   r   rv   rw   )r\   r   r^   r   rL   r   rv   rw   )r   r   rv   r5   )r  r4   rv   rw   )r  r4   )rv   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@   r[   rB   r   r   r   classmethodr   r   r   r   r   r   r   r   r  r  r  r  __classcell__)rt   s   @r`   r5   r5      s+       Gz;DDJ!(FHHFF     5A 7 7 7 7 7 8<      "   <+ + + + + +*	8 	8 	8 	8 > > > X> ]E E E ]E    X \O O O \O           X ^Q Q Q ^Q $ $ $ X$ X X X X( ( ( (       X  
 
 
 
$ $ $ $S S S S6   $G G G G G " " " ["HO O O O OJ J J J JO O O O O& 	    * 	    * 	    &
 
 
 
, , , , , ,>( ( ( (T! ! ! !F       rb   )N
__future__r   typingr   r   r   r   r   r	   r
   typing_extensionsr   r   r   rz   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(   r)   	dxfentityr+   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>r;     s   # " " " " " "                  . - - - - - - -   " " " " " " ! ! ! ! ! !                           5 4 4 4 4 4 4 4                                 " 5 4 4 4 4 4 4 4 + + + + + + + + $ $ $ $ $ $       $44444444777777######*& k Q''' '"a93HIII72U^LIII#Gen-B
 
 
  %.ARSSS!'"edCCC#*72ut#L#L#L UTBBB !-2	
 
 
 w-2	
 
 
 W-2 
 
 
E/ /2 2f -,[99 & & & & & & & & ,++8E?+ + + + + b b b b bZ b b b b brb   