
    'j@                        d dl mZ d dlmZmZmZmZmZ d dlm	Z	m
Z
mZmZmZmZ d dlmZ erd dlmZ g dZ eddd	          fddZdZ G d d          Z G d d          Z G d de          ZdS )    )annotations)TYPE_CHECKINGSequenceIterableOptionalIterator)Vec3UVecX_AXISY_AXISZ_AXISMatrix44)RGB)
BaseLayout)OCSUCSPassTroughUCS         layoutr   startr
   pointsSequence[UVec]colorsr   returnNonec                f    t          ||          D ]\  }}|                     ||d|i            d S )Ncolor)
dxfattribs)zipadd_line)r   r   r   r   pointr   s         H/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/math/ucs.pyrender_axisr%      sO     FF++ C Cuu'51ABBBBC C    g      ?c                      e Zd ZdZefddZedd            Zedd            Zedd	            Z	d dZ
d!dZd dZd!dZd eddd          fd"dZdS )#r   zkEstablish an :ref:`OCS` for a given extrusion vector.

    Args:
        extrusion: extrusion vector.

    	extrusionr
   c                   t          |                                          }|                    t                     | _        | j        rt          |j                  t          k     r2t          |j                  t          k     rt          j
        |          }nt          j
        |          }|                                }|
                    |                                          }t          j        |||          | _        d S d S N)r	   	normalizeiscloser   	transformabsx
_1_OVER_64yr   crossr   ucsmatrix)selfr(   AzAxAys        r$   __init__zOCS.__init__#   s    )__&&((ZZ///> 	3BD		J&&SYY-C-C\"%%\"%%B"''))B",r2r22DKKK	3 	3r&   r   r	   c                6    | j         r| j        j        nt          S zx-axis unit vector)r-   r4   uxr   r5   s    r$   r<   zOCS.ux/        "&;t{~~V;r&   c                6    | j         r| j        j        nt          S zy-axis unit vector)r-   r4   uyr   r=   s    r$   rA   zOCS.uy4   r>   r&   c                6    | j         r| j        j        nt          S zz-axis unit vector)r-   r4   uzr   r=   s    r$   rD   zOCS.uz9   r>   r&   r#   c                f    t          |          }| j        r| j                            |          S |S )z#Returns OCS vector for WCS `point`.)r	   r-   r4   ocs_from_wcs)r5   r#   p3s      r$   from_wcszOCS.from_wcs>   s2    %[[> 	;++B///Ir&   r   Iterable[UVec]Iterator[Vec3]c              #     K   t          j        |          }| j        r | j        j        }|D ]} ||          V  dS |E d{V  dS )z2Returns iterable of OCS vectors from WCS `points`.N)r	   generater-   r4   rF   )r5   r   _pointsrH   r#   s        r$   points_from_wcszOCS.points_from_wcsF   sy      -''> 	{/H  & &huoo%%%%& & r&   c                b    | j         r| j                            |          S t          |          S )z#Returns WCS vector for OCS `point`.)r-   r4   
ocs_to_wcsr	   r5   r#   s     r$   to_wcsz
OCS.to_wcsP   s.    > 	;))%000;;r&   c              #     K   t          j        |          }| j        r | j        j        }|D ]} ||          V  dS |E d{V  dS )z1Returns iterable of WCS vectors for OCS `points`.N)r	   rL   r-   r4   rP   )r5   r   rM   rR   r#   s        r$   points_to_wcszOCS.points_to_wcsW   sy      -''> 	[+F  $ $fUmm####$ $ r&   r   r   r   r   r   lengthfloatr   r   r   c           
         t          |d|                     t          |z            |                     t          |z            |                     t          |z            f|           dS )(Render axis as 3D lines into a `layout`.r   r   r   r   r   r   N)r%   rR   r   r   r   r5   r   rU   r   s       r$   r%   zOCS.render_axisa   sn     	FVO,,FVO,,FVO,,
 		
 		
 		
 		
 		
 		
r&   N)r(   r
   r   r	   )r#   r
   r   r	   )r   rI   r   rJ   )r   r   rU   rV   r   r   r   r   )__name__
__module____qualname____doc__r   r9   propertyr<   rA   rD   rH   rN   rR   rT   r   r%    r&   r$   r   r      s         *0 
3 
3 
3 
3 
3 < < < X< < < < X< < < < X<             c!Qll	
 
 
 
 
 
 
r&   r   c                  
   e Zd ZdZ	 	 	 	 dEdFd
ZedGd            ZedGd            ZedGd            ZedGd            Z	e	j
        dHd            Z	dIdZdJdZdKdZdLdZdJdZdKdZdLdZdJd ZdKd!ZdMd$ZdMd%ZdNd'ZdOd)ZdPd*ZdPd+ZdPd,ZdQd.ZdRd0ZdSd3ZedTd5            ZedUd6            Z edUd7            Z!edUd8            Z"edUd9            Z#edUd:            Z$edUd;            Z%d< e&d<d=d>          fdVdDZ'dS )Wr   a  Establish a user coordinate system (:ref:`UCS`). The UCS is defined by
    the origin and two unit vectors for the x-, y- or z-axis, all axis in
    :ref:`WCS`. The missing axis is the cross product of the given axis.

    If x- and y-axis are ``None``: ux = ``(1, 0, 0)``, uy = ``(0, 1, 0)``,
    uz = ``(0, 0, 1)``.

    Unit vectors don't have to be normalized, normalization is done at
    initialization, this is also the reason why scaling gets lost by copying or
    rotating.

    Args:
        origin: defines the UCS origin in world coordinates
        ux: defines the UCS x-axis as vector in :ref:`WCS`
        uy: defines the UCS y-axis as vector in :ref:`WCS`
        uz: defines the UCS z-axis as vector in :ref:`WCS`

    rY   Noriginr
   r<   Optional[UVec]rA   rD   c                ,   ||t           }t          }t          }n|xt          |                                          }t          |                                          }t          |                              |                                          }nU|wt          |                                          }t          |                                          }t          |                              |                                          }n|wt          |                                          }t          |                                          }t          |                              |                                          }nct          |                                          }t          |                                          }t          |                                          }t          j        |||t          |                    | _        d S r*   )	r   r   r   r	   r+   r2   r   r3   r4   )r5   rd   r<   rA   rD   _ux_uy_uzs           r$   r9   zUCS.__init__   s    :"*CCCCZr(($$&&Cr(($$&&Cr((..$$..00CCZr(($$&&Cr(($$&&Cr((..$$..00CCZr(($$&&Cr(($$&&Cr((..$$..00CCr(($$&&Cr(($$&&Cr(($$&&C (S#sDLL I Ir&   r   r	   c                    | j         j        S r;   )r4   r<   r=   s    r$   r<   zUCS.ux        {~r&   c                    | j         j        S r@   )r4   rA   r=   s    r$   rA   zUCS.uy   rk   r&   c                    | j         j        S rC   )r4   rD   r=   s    r$   rD   zUCS.uz   rk   r&   c                    | j         j        S )zReturns the originr4   rd   r=   s    r$   rd   z
UCS.origin   s     {!!r&   vr   c                    || j         _        dS )zSet origin.Nro   )r5   rp   s     r$   rd   z
UCS.origin   s     r&   c                N    t          | j        | j        | j        | j                  S )zReturns a copy of this UCS.)r   rd   r<   rA   rD   r=   s    r$   copyzUCS.copy   s    4;$':::r&   r#   c                6    | j                             |          S )z"Returns WCS point for UCS `point`.)r4   r-   rQ   s     r$   rR   z
UCS.to_wcs   s    {$$U+++r&   r   Iterable[Vec3]rJ   c                6    | j                             |          S )z1Returns iterable of WCS vectors for UCS `points`.)r4   transform_verticesr5   r   s     r$   rT   zUCS.points_to_wcs   s    {--f555r&   vectorc                6    | j                             |          S )zAReturns WCS direction for UCS `vector` without origin adjustment.)r4   transform_directionr5   ry   s     r$   direction_to_wcszUCS.direction_to_wcs   s    {..v666r&   c                6    | j                             |          S )z"Returns UCS point for WCS `point`.)r4   ucs_vertex_from_wcsrQ   s     r$   rH   zUCS.from_wcs   s    {..u555r&   c              #  <   K   | j         }|D ]} ||          V  dS )z2Returns iterable of UCS vectors from WCS `points`.N)rH   )r5   r   rH   r#   s       r$   rN   zUCS.points_from_wcs   s=      = 	" 	"E(5//!!!!	" 	"r&   c                6    | j                             |          S )z>Returns UCS vector for WCS `vector` without origin adjustment.)r4   ucs_direction_from_wcsr|   s     r$   direction_from_wcszUCS.direction_from_wcs   s    {11&999r&   c                z    |                      |          }t          | j                                      |          S )zuReturns OCS vector for UCS `point`.

        The :class:`OCS` is defined by the z-axis of the :class:`UCS`.

        rR   r   rD   rH   )r5   r#   wpoints      r$   to_ocsz
UCS.to_ocs   s1     U##47||$$V,,,r&   c              #     K   | j         }t          | j                  }|D ]"}|                     ||                    V  #dS )zReturns iterable of OCS vectors for UCS `points`.

        The :class:`OCS` is defined by the z-axis of the :class:`UCS`.

        Args:
            points: iterable of UCS vertices

        Nr   )r5   r   wcsocsr#   s        r$   points_to_ocszUCS.points_to_ocs   sX       k$'ll 	+ 	+E,,ss5zz******	+ 	+r&   anglerV   c                Z    |                      t          j        |                    j        S )a  Transforms `angle` from current UCS to the parent coordinate system
        (most likely the WCS) including the transformation to the OCS
        established by the extrusion vector :attr:`UCS.uz`.

        Args:
            angle: in UCS in degrees

        )ucs_direction_to_ocs_directionr	   from_deg_angle	angle_degr5   r   s     r$   to_ocs_angle_degzUCS.to_ocs_angle_deg   s-     22&&
 

	r&   c                Z    |                      t          j        |                    j        S )a  Transforms `angle` from current UCS to the parent coordinate system
        (most likely the WCS) including the transformation to the OCS
        established by the extrusion vector :attr:`UCS.uz`.

        Args:
            angle: in UCS in radians

        )r   r	   
from_angler   r   s     r$   to_ocs_angle_radzUCS.to_ocs_angle_rad  s%     224?53I3IJJPPr&   	directionc                v    t          | j                                      |                     |                    S )zTransforms UCS `direction` vector into OCS direction vector of the
        parent coordinate system (most likely the WCS), target OCS is defined by
        the UCS z-axis.
        )r   rD   rH   r}   )r5   r   s     r$   r   z"UCS.ucs_direction_to_ocs_direction  s.    
 47||$$T%:%:9%E%EFFFr&   axisc                    t          j        t          |          |          }|                    | j        | j        | j        g          \  }}}t          | j        |||          S )a[  Returns a new rotated UCS, with the same origin as the source UCS.
        The rotation vector is located in the origin and has :ref:`WCS`
        coordinates e.g. (0, 0, 1) is the WCS z-axis as rotation vector.

        Args:
            axis: arbitrary rotation axis as vector in :ref:`WCS`
            angle: rotation angle in radians

        rd   r<   rA   rD   )	r   axis_rotater	   rw   r<   rA   rD   r   rd   )r5   r   r   tr<   rA   rD   s          r$   rotatez
UCS.rotate  s[      dU33))47DGTW*EFF
B$+";;;;r&   c                    t          j        | j        |          }|                    | j        | j        g          \  }}t          | j        | j        ||          S )zReturns a new rotated UCS, rotation axis is the local x-axis.

        Args:
             angle: rotation angle in radians

        r   )r   r   r<   rw   rA   rD   r   rd   )r5   r   r   rA   rD   s        r$   rotate_local_xzUCS.rotate_local_x!  sS      %00%%tw&899B$+$'bR@@@@r&   c                    t          j        | j        |          }|                    | j        | j        g          \  }}t          | j        || j        |          S )zReturns a new rotated UCS, rotation axis is the local y-axis.

        Args:
             angle: rotation angle in radians

        r   )r   r   rA   rw   r<   rD   r   rd   )r5   r   r   r<   rD   s        r$   rotate_local_yzUCS.rotate_local_y,  sS      %00%%tw&899B$+"R@@@@r&   c                    t          j        | j        |          }|                    | j        | j        g          \  }}t          | j        ||| j                  S )zReturns a new rotated UCS, rotation axis is the local z-axis.

        Args:
             angle: rotation angle in radians

        r   )r   r   rD   rw   r<   rA   r   rd   )r5   r   r   r<   rA   s        r$   rotate_local_zzUCS.rotate_local_z7  sS      %00%%tw&899B$+"@@@@r&   deltac                @    | xj         t          |          z  c_         | S )ztShifts current UCS by `delta` vector and returns `self`.

        Args:
            delta: shifting vector

        )rd   r	   )r5   r   s     r$   shiftz	UCS.shiftB  s     	tE{{"r&   locationc                .    t          |          | _        | S )zPlace current UCS at new origin `location` and returns `self`.

        Args:
            location: new origin in WCS

        )r	   rd   )r5   r   s     r$   movetoz
UCS.movetoL  s     8nnr&   mr   c                &    | xj         |z  c_         | S )zGeneral inplace transformation interface, returns `self` (floating
        interface).

        Args:
             m: 4x4 transformation matrix (:class:`ezdxf.math.Matrix44`)

        )r4   )r5   r   s     r$   r-   zUCS.transformV  s     	qr&   boolc                    | j         j        S )z0Returns ``True`` if cartesian coordinate system.)r4   is_cartesianr=   s    r$   r   zUCS.is_cartesiana  s     {''r&   c                    t          |          }|                    t          |          | z
            }t          | ||          S )a  Returns a new :class:`UCS` defined by the origin, the x-axis vector
        and an arbitrary point in the xy-plane.

        Args:
            origin: UCS origin as (x, y, z) tuple in :ref:`WCS`
            axis: x-axis vector as (x, y, z) tuple in :ref:`WCS`
            point: arbitrary point unlike the origin in the xy-plane as
                (x, y, z) tuple in :ref:`WCS`

        rd   r<   rD   r	   r2   r   )rd   r   r#   x_axisz_axiss        r$   from_x_axis_and_point_in_xyzUCS.from_x_axis_and_point_in_xyf  @     dd5kkF233&V7777r&   c                    t          |          }t          |          | z
  }|                    |          }t          | ||          S )a  Returns a new :class:`UCS` defined by the origin, the x-axis vector
        and an arbitrary point in the xz-plane.

        Args:
            origin: UCS origin as (x, y, z) tuple in :ref:`WCS`
            axis: x-axis vector as (x, y, z) tuple in :ref:`WCS`
            point: arbitrary point unlike the origin in the xz-plane as
                (x, y, z) tuple in :ref:`WCS`

        rd   r<   rA   r   )rd   r   r#   r   	xz_vectory_axiss         r$   from_x_axis_and_point_in_xzzUCS.from_x_axis_and_point_in_xzx  E     dKK&(	((&V7777r&   c                    t          |          }t          |          | z
  }|                    |          }t          | ||          S )a  Returns a new :class:`UCS` defined by the origin, the y-axis vector
        and an arbitrary point in the xy-plane.

        Args:
            origin: UCS origin as (x, y, z) tuple in :ref:`WCS`
            axis: y-axis vector as (x, y, z) tuple in :ref:`WCS`
            point: arbitrary point unlike the origin in the xy-plane as
                (x, y, z) tuple in :ref:`WCS`

        rd   rA   rD   r   )rd   r   r#   r   	xy_vectorr   s         r$   from_y_axis_and_point_in_xyzUCS.from_y_axis_and_point_in_xy  r   r&   c                    t          |          }t          |          | z
  }|                    |          }t          | ||          S )a  Returns a new :class:`UCS` defined by the origin, the y-axis vector
        and an arbitrary point in the yz-plane.

        Args:
            origin: UCS origin as (x, y, z) tuple in :ref:`WCS`
            axis: y-axis vector as (x, y, z) tuple in :ref:`WCS`
            point: arbitrary point unlike the origin in the yz-plane as
                (x, y, z) tuple in :ref:`WCS`

        r   r   )rd   r   r#   r   	yz_vectorr   s         r$   from_y_axis_and_point_in_yzzUCS.from_y_axis_and_point_in_yz  r   r&   c                    t          |          }|                    t          |          | z
            }t          | ||          S )a  Returns a new :class:`UCS` defined by the origin, the z-axis vector
        and an arbitrary point in the xz-plane.

        Args:
            origin: UCS origin as (x, y, z) tuple in :ref:`WCS`
            axis: z-axis vector as (x, y, z) tuple in :ref:`WCS`
            point: arbitrary point unlike the origin in the xz-plane as
                (x, y, z) tuple in :ref:`WCS`

        r   r   )rd   r   r#   r   r   s        r$   from_z_axis_and_point_in_xzzUCS.from_z_axis_and_point_in_xz  r   r&   c                    t          |          }t          |          | z
  }|                    |          }t          | ||          S )a  Returns a new :class:`UCS` defined by the origin, the z-axis vector
        and an arbitrary point in the yz-plane.

        Args:
            origin: UCS origin as (x, y, z) tuple in :ref:`WCS`
            axis: z-axis vector as (x, y, z) tuple in :ref:`WCS`
            point: arbitrary point unlike the origin in the yz-plane as
                (x, y, z) tuple in :ref:`WCS`

        r   r   )rd   r   r#   r   r   r   s         r$   from_z_axis_and_point_in_yzzUCS.from_z_axis_and_point_in_yz  r   r&   r   r   r   r   r   rU   r   r   c           
         t          || j        |                     t          |z            |                     t          |z            |                     t
          |z            f|           dS )rX   rZ   N)r%   rd   rR   r   r   r   r[   s       r$   r%   zUCS.render_axis  sp     	+FVO,,FVO,,FVO,,
 		
 		
 		
 		
 		
 		
r&   )rY   NNN)rd   r
   r<   re   rA   re   rD   re   r\   )rp   r
   r   r   )r   r   r#   r	   r   r	   r   ru   r   rJ   )ry   r	   r   r	   r   rV   r   rV   )r   r	   r   r	   )r   r
   r   rV   r   r   )r   rV   r   r   )r   r
   r   r   )r   r
   r   r   )r   r   r   r   )r   r   )rd   r
   r   r
   r#   r
   r   r   )r   r   rU   rV   r   r   )(r]   r^   r_   r`   r9   ra   r<   rA   rD   rd   setterrs   rR   rT   r}   rH   rN   r   r   r   r   r   r   r   r   r   r   r   r   r-   r   staticmethodr   r   r   r   r   r   r   r%   rb   r&   r$   r   r   t   s        * !!!!J J J J J<    X    X    X " " " X" ]   ]; ; ; ;, , , ,6 6 6 67 7 7 76 6 6 6" " " ": : : :- - - -+ + + +   	Q 	Q 	Q 	QG G G G< < < <	A 	A 	A 	A	A 	A 	A 	A	A 	A 	A 	A      	 	 	 	 ( ( ( X( 8 8 8 \8" 8 8 8 \8$ 8 8 8 \8$ 8 8 8 \8$ 8 8 8 \8" 8 8 8 \8* c!Qll	
 
 
 
 
 
 
r&   r   c                  b     e Zd ZdZ fdZddZdd
ZddZddZddZ	ddZ
ddZddZ xZS )r   z5UCS is equal to the WCS and OCS (extrusion = 0, 0, 1)c                H    t                                                       d S r*   )superr9   )r5   	__class__s    r$   r9   zPassTroughUCS.__init__  s    r&   r#   r	   r   c                    |S r*   rb   rQ   s     r$   rR   zPassTroughUCS.to_wcs      r&   r   ru   rJ   c                     t          |          S r*   iterrx   s     r$   rT   zPassTroughUCS.points_to_wcs      F||r&   c                    |S r*   rb   rQ   s     r$   r   zPassTroughUCS.to_ocs  r   r&   c                     t          |          S r*   r   rx   s     r$   r   zPassTroughUCS.points_to_ocs  r   r&   r   rV   c                    |S r*   rb   r   s     r$   r   zPassTroughUCS.to_ocs_angle_deg  r   r&   c                    |S r*   rb   r   s     r$   r   zPassTroughUCS.to_ocs_angle_rad  r   r&   c                    |S r*   rb   rQ   s     r$   rH   zPassTroughUCS.from_wcs  r   r&   c                     t          |          S r*   r   rx   s     r$   rN   zPassTroughUCS.points_from_wcs  r   r&   r   r   r   )r]   r^   r_   r`   r9   rR   rT   r   r   r   r   rH   rN   __classcell__)r   s   @r$   r   r     s        ??                                r&   r   N)
r   r   r   r
   r   r   r   r   r   r   )
__future__r   typingr   r   r   r   r   
ezdxf.mathr	   r
   r   r   r   r   ezdxf.colorsr   ezdxf.layoutsr   __all__r%   r0   r   r   r   rb   r&   r$   <module>r      sv   # " " " " " H H H H H H H H H H H H H H C C C C C C C C C C C C C C C C       )((((((
)
)
) #aA,,	C C C C C 
V
 V
 V
 V
 V
 V
 V
 V
rr
 r
 r
 r
 r
 r
 r
 r
j    C     r&   