
    Og@                        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y)    )annotations)TYPE_CHECKINGSequenceIterableOptionalIterator)Vec3UVecX_AXISY_AXISZ_AXISMatrix44)RGB)
BaseLayout)OCSUCSPassTroughUCS         c                X    t        ||      D ]  \  }}| j                  ||d|i        y )Ncolor)
dxfattribs)zipadd_line)layoutstartpointscolorspointr   s         S/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/math/ucs.pyrender_axisr"      s7     FF+ Cuu'51AB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y)r   zkEstablish an :ref:`OCS` for a given extrusion vector.

    Args:
        extrusion: extrusion vector.

    c                   t        |      j                         }|j                  t               | _        | j                  rt        |j                        t        k  r2t        |j                        t        k  rt        j                  |      }nt        j                  |      }|j                         }|j                  |      j                         }t        j                  |||      | _        y y N)r	   	normalizeiscloser   	transformabsx
_1_OVER_64yr   crossr   ucsmatrix)self	extrusionAzAxAys        r!   __init__zOCS.__init__#   s    )_&&(ZZ//>>BDD	J&SY-C\\"%\\"%B"'')B",,r2r2DK r#   c                R    | j                   r| j                  j                  S t        S zx-axis unit vector)r)   r0   uxr   r1   s    r!   r9   zOCS.ux/        "&t{{~~;V;r#   c                R    | j                   r| j                  j                  S t        S zy-axis unit vector)r)   r0   uyr   r:   s    r!   r>   zOCS.uy4   r;   r#   c                R    | j                   r| j                  j                  S t        S zz-axis unit vector)r)   r0   uzr   r:   s    r!   rA   zOCS.uz9   r;   r#   c                j    t        |      }| j                  r| j                  j                  |      S |S )z#Returns OCS vector for WCS `point`.)r	   r)   r0   ocs_from_wcs)r1   r    p3s      r!   from_wcszOCS.from_wcs>   s,    %[>>;;++B//Ir#   c              #     K   t        j                  |      }| j                  r(| j                  j                  }|D ]  } ||        y|E d{    y7 w)z2Returns iterable of OCS vectors from WCS `points`.N)r	   generater)   r0   rC   )r1   r   _pointsrE   r    s        r!   points_from_wcszOCS.points_from_wcsF   sN     --'>>{{//H  &uo%&    AAAAc                f    | j                   r| j                  j                  |      S t        |      S )z#Returns WCS vector for OCS `point`.)r)   r0   
ocs_to_wcsr	   r1   r    s     r!   to_wcsz
OCS.to_wcsP   s(    >>;;))%00;r#   c              #     K   t        j                  |      }| j                  r(| j                  j                  }|D ]  } ||        y|E d{    y7 w)z1Returns iterable of WCS vectors for OCS `points`.N)r	   rG   r)   r0   rL   )r1   r   rH   rN   r    s        r!   points_to_wcszOCS.points_to_wcsW   sN     --'>>[[++F  $Um#$ rJ   r   r   r   c           
         t        |d| j                  t        |z        | j                  t        |z        | j                  t        |z        f|       y)(Render axis as 3D lines into a `layout`.r   r   r   r   r   r   N)r"   rN   r   r   r   r1   r   lengthr   s       r!   r"   zOCS.render_axisa   sL     	FVO,FVO,FVO,
 		
r#   N)r2   r
   returnr	   )r    r
   rX   r	   )r   zIterable[UVec]rX   Iterator[Vec3])r   r   rV   floatr   r   rX   None)__name__
__module____qualname____doc__r   r6   propertyr9   r>   rA   rE   rI   rN   rP   r   r"    r#   r!   r   r      s     *0 
3 < < < < < < !Ql	

 
 	

 

r#   r   c                  <   e Zd ZdZ	 	 	 	 d'	 	 	 	 	 	 	 d(dZed)d       Zed)d       Zed)d       Zed)d       Z	e	j                  d*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d-dZd/dZd/dZd0dZd1dZd2dZd2dZd2dZd3dZd4dZd5dZed6d       Ze	 	 	 	 	 	 	 	 d7d       Z e	 	 	 	 	 	 	 	 d7d       Z!e	 	 	 	 	 	 	 	 d7d       Z"e	 	 	 	 	 	 	 	 d7d        Z#e	 	 	 	 	 	 	 	 d7d!       Z$e	 	 	 	 	 	 	 	 d7d"       Z%d# e&d#d$d%      f	 	 	 	 	 d8d&Z'y)9r   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`

    Nc                F   ||t         }t        }t        }nc|\t        |      j	                         }t        |      j	                         }t        |      j                  |      j	                         }n|[t        |      j	                         }t        |      j	                         }t        |      j                  |      j	                         }n|[t        |      j	                         }t        |      j	                         }t        |      j                  |      j	                         }nKt        |      j	                         }t        |      j	                         }t        |      j	                         }t        j                  |||t        |            | _        y r&   )	r   r   r   r	   r'   r.   r   r/   r0   )r1   originr9   r>   rA   _ux_uy_uzs           r!   r6   zUCS.__init__   s8    :"*CCCZr($$&Cr($$&Cr(..$..0CZr($$&Cr($$&Cr(..$..0CZr($$&Cr($$&Cr(..$..0Cr($$&Cr($$&Cr($$&C (S#sDL Ir#   c                .    | j                   j                  S r8   )r0   r9   r:   s    r!   r9   zUCS.ux        {{~~r#   c                .    | j                   j                  S r=   )r0   r>   r:   s    r!   r>   zUCS.uy   ri   r#   c                .    | j                   j                  S r@   )r0   rA   r:   s    r!   rA   zUCS.uz   ri   r#   c                .    | j                   j                  S )zReturns the originr0   rd   r:   s    r!   rd   z
UCS.origin   s     {{!!!r#   c                &    || j                   _        y)zSet origin.Nrm   )r1   vs     r!   rd   z
UCS.origin   s     r#   c                n    t        | j                  | j                  | j                  | j                        S )zReturns a copy of this UCS.)r   rd   r9   r>   rA   r:   s    r!   copyzUCS.copy   s#    4;;$''::r#   c                8    | j                   j                  |      S )z"Returns WCS point for UCS `point`.)r0   r)   rM   s     r!   rN   z
UCS.to_wcs   s    {{$$U++r#   c                8    | j                   j                  |      S )z1Returns iterable of WCS vectors for UCS `points`.)r0   transform_verticesr1   r   s     r!   rP   zUCS.points_to_wcs   s    {{--f55r#   c                8    | j                   j                  |      S )zAReturns WCS direction for UCS `vector` without origin adjustment.)r0   transform_directionr1   vectors     r!   direction_to_wcszUCS.direction_to_wcs   s    {{..v66r#   c                8    | j                   j                  |      S )z"Returns UCS point for WCS `point`.)r0   ucs_vertex_from_wcsrM   s     r!   rE   zUCS.from_wcs   s    {{..u55r#   c              #  F   K   | j                   }|D ]  } ||        yw)z2Returns iterable of UCS vectors from WCS `points`.N)rE   )r1   r   rE   r    s       r!   rI   zUCS.points_from_wcs   s(     == 	"E5/!	"s   !c                8    | j                   j                  |      S )z>Returns UCS vector for WCS `vector` without origin adjustment.)r0   ucs_direction_from_wcsrx   s     r!   direction_from_wcszUCS.direction_from_wcs   s    {{11&99r#   c                l    | j                  |      }t        | j                        j                  |      S )zuReturns OCS vector for UCS `point`.

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

        rN   r   rA   rE   )r1   r    wpoints      r!   to_ocsz
UCS.to_ocs   s+     U#477|$$V,,r#   c              #     K   | j                   }t        | j                        }|D ]  }|j                   ||              yw)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   )r1   r   wcsocsr    s        r!   points_to_ocszUCS.points_to_ocs   s@      kk$''l 	+E,,s5z**	+s   AAc                ^    | j                  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r1   angles     r!   to_ocs_angle_degzUCS.to_ocs_angle_deg   s*     22&

)	r#   c                ^    | j                  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??53IJPPPr#   c                h    t        | j                        j                  | 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   rA   rE   rz   )r1   	directions     r!   r   z"UCS.ucs_direction_to_ocs_direction  s(    
 477|$$T%:%:9%EFFr#   c                    t        j                  t        |      |      }|j                  | 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   r9   r>   rA   )	r   axis_rotater	   rt   r9   r>   rA   r   rd   )r1   axisr   tr9   r>   rA   s          r!   rotatez
UCS.rotate  sX       dU3))477DGGTWW*EF
B$++";;r#   c                    t        j                  | 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   r9   rt   r>   rA   r   rd   )r1   r   r   r>   rA   s        r!   rotate_local_xzUCS.rotate_local_x!  sT       %0%%tww&89B$++$''bR@@r#   c                    t        j                  | 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   r>   rt   r9   rA   r   rd   )r1   r   r   r9   rA   s        r!   rotate_local_yzUCS.rotate_local_y,  sT       %0%%tww&89B$++"R@@r#   c                    t        j                  | 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   rA   rt   r9   r>   r   rd   )r1   r   r   r9   r>   s        r!   rotate_local_zzUCS.rotate_local_z7  sT       %0%%tww&89B$++"@@r#   c                B    | xj                   t        |      z  c_         | S )ztShifts current UCS by `delta` vector and returns `self`.

        Args:
            delta: shifting vector

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

        Args:
            location: new origin in WCS

        )r	   rd   )r1   locations     r!   movetoz
UCS.movetoL  s     8nr#   c                0    | xj                   |z  c_         | S )zGeneral inplace transformation interface, returns `self` (floating
        interface).

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

        )r0   )r1   ms     r!   r)   zUCS.transformV  s     	qr#   c                .    | j                   j                  S )z0Returns ``True`` if cartesian coordinate system.)r0   is_cartesianr:   s    r!   r   zUCS.is_cartesiana  s     {{'''r#   c                n    t        |      }|j                  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   r9   rA   r	   r.   r   )rd   r   r    x_axisz_axiss        r!   from_x_axis_and_point_in_xyzUCS.from_x_axis_and_point_in_xyf  3     dd5kF23&V77r#   c                r    t        |      }t        |      | z
  }|j                  |      }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   r9   r>   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  8     dK&(	(&V77r#   c                r    t        |      }t        |      | z
  }|j                  |      }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   r>   rA   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                r    t        |      }t        |      | z
  }|j                  |      }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                n    t        |      }|j                  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                r    t        |      }t        |      | z
  }|j                  |      }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   c           
         t        || j                  | j                  t        |z        | j                  t        |z        | j                  t
        |z        f|       y)rR   rT   N)r"   rd   rN   r   r   r   rU   s       r!   r"   zUCS.render_axis  sP     	++FVO,FVO,FVO,
 		
r#   )rS   NNN)rd   r
   r9   Optional[UVec]r>   r   rA   r   rW   )ro   r
   rX   r[   )rX   r   r    r	   rX   r	   r   zIterable[Vec3]rX   rY   )ry   r	   rX   r	   r   rZ   rX   rZ   )r   r	   rX   r	   )r   r
   r   rZ   rX   r   )r   rZ   rX   r   )r   r
   rX   r   )r   r
   rX   r   )r   r   rX   r   )rX   bool)rd   r
   r   r
   r    r
   rX   r   )r   r   rV   rZ   r   r   )(r\   r]   r^   r_   r6   r`   r9   r>   rA   rd   setterrq   rN   rP   rz   rE   rI   r   r   r   r   r   r   r   r   r   r   r   r   r)   r   staticmethodr   r   r   r   r   r   r   r"   ra   r#   r!   r   r   t   s   * !!!!JJ J 	J
 J<       " " ]] ;,676":-+	QG<	A	A	A	 ( ( 88 8)-8	8 8" 88 8)-8	8 8$ 88 8)-8	8 8$ 88 8)-8	8 8$ 88 8)-8	8 8" 88 8)-8	8 8* !Ql	

 
 	
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                "    t         |           y r&   )superr6   )r1   	__class__s    r!   r6   zPassTroughUCS.__init__  s    r#   c                    |S r&   ra   rM   s     r!   rN   zPassTroughUCS.to_wcs      r#   c                    t        |      S r&   iterru   s     r!   rP   zPassTroughUCS.points_to_wcs      F|r#   c                    |S r&   ra   rM   s     r!   r   zPassTroughUCS.to_ocs  r   r#   c                    t        |      S r&   r   ru   s     r!   r   zPassTroughUCS.points_to_ocs  r   r#   c                    |S r&   ra   r   s     r!   r   zPassTroughUCS.to_ocs_angle_deg  r   r#   c                    |S r&   ra   r   s     r!   r   zPassTroughUCS.to_ocs_angle_rad  r   r#   c                    |S r&   ra   rM   s     r!   rE   zPassTroughUCS.from_wcs  r   r#   c                    t        |      S r&   r   ru   s     r!   rI   zPassTroughUCS.points_from_wcs  r   r#   r   r   r   )r\   r]   r^   r_   r6   rN   rP   r   r   r   r   rE   rI   __classcell__)r   s   @r!   r   r     s3    ?r#   r   N)
r   r   r   r
   r   zSequence[UVec]r   r   rX   r[   )
__future__r   typingr   r   r   r   r   
ezdxf.mathr	   r
   r   r   r   r   ezdxf.colorsr   ezdxf.layoutsr   __all__r"   r,   r   r   r   ra   r#   r!   <module>r      s    # H H C C (
) aA,	CCC C 	C
 
C 
V
 V
rr
 r
jC r#   