
    vj                     z   d dl mZmZmZ d dlmZmZmZmZm	Z	m
Z
mZ d dl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 d dlmZ d dlmZ d dl m!Z! d dl"m#Z# d d	l$m%Z% d d
l&m'Z' ddl(m)Z) ddl*m+Z+ dZ,edee)e)f   ee)e)e)f   f   Z- G d de.      Z/ G d d      Z0 G d de.      Z1 G d de.      Z2 G d de.      Z3y)    )piradiansdegrees)overloadSequenceUnionTupleTypeOptionalIterator)BytesIO)gp_Vecgp_Ax1gp_Ax3gp_Pntgp_Dirgp_Plngp_Trsfgp_GTrsfgp_XYZgp_EulerSequencegpgp_Quaterniongp_Extrinsic_XYZ)Bnd_Box)
BRepBndLib)BRepMesh_IncrementalMesh)TopoDS_Shape)TopLoc_Location)BinTools_LocationSet   )Real)multidispatchg{Gz?Vectorc            	       @   e Zd ZU dZeed<   ededededdfd       Zedededdfd	       Zed;d       Zed
e	e   ddfd       Zed
e
eeeef   ddfd       Zed<d       Zd Zedefd       Zej                   deddfd       Zedefd       Zej                   deddfd       Zedefd       Zej                   deddfd       Zedefd       Zedefd       Zdeeeef   fdZd=dZd
d defdZd=dZd=dZd=dZd=dZd edd fd!Zd edd fd"Zd#edd fd$Zd edd fd%Z d>d&Z!d>d'Z"d
d defd(Z#d
d defd)Z$d* Z%d?d+Z&d, Z'd@d-Z(d>d.Z)defd/Z*de+fd0Z,de+fd1Z-d2d de.fd3Z/de0e   fd4Z1defd5Z2defd6Z3dAd7Z4de5eeef   fd8Z6d9e5eeef   fd:Z7y)Br$   aw  Create a 3-dimensional vector

    :param args: a 3D vector, with x-y-z parts.

    you can either provide:
        * nothing (in which case the null vector is return)
        * a gp_Vec
        * a vector ( in which case it is copied )
        * a 3-tuple
        * a 2-tuple (z assumed to be 0)
        * three float values: x, y, and z
        * two float values: x,y
    _wrappedxyzreturnNc                      y N )selfr'   r(   r)   s       C/DATA/.local/lib/python3.12/site-packages/cadquery/occ_impl/geom.py__init__zVector.__init__6           c                      y r,   r-   r.   r'   r(   s      r/   r0   zVector.__init__:   r1   r2   vc                      y r,   r-   r.   r5   s     r/   r0   zVector.__init__>   r1   r2   c                      y r,   r-   r7   s     r/   r0   zVector.__init__B   r1   r2   c                      y r,   r-   r7   s     r/   r0   zVector.__init__F   r1   r2   c                      y r,   r-   r.   s    r/   r0   zVector.__init__J   r1   r2   c                 :   t        |      dk(  rt        | }|| _        y t        |      dk(  rt        g |d }|| _        y t        |      dk(  rt        |d   t              r.t        |d   j                  j                               }|| _        y t        |d   t        t        f      rF|d   }t        |      dk(  rt        | }|| _        y t        |      dk(  rt        g |d }|| _        y t        |d   t        t        t        f      r$t        |d   j                               }|| _        y t        |d   t              rt        |d         }|| _        y t        d      t        |      dk(  rt        ddd      }|| _        y t        d      | _        y )N   r!   r      z*Expected three floats, OCC gp_, or 3-tuple)lenr   
isinstancer$   wrappedXYZtuplelistr   r   r   	TypeErrorr&   )r.   argsfVargs       r/   r0   zVector.__init__N   s   t9>B. - Y!^!!q!B* ) Y!^$q'6*DGOO//12$ # DGeT]31gs8q=B  X]aB  DGfff%=>DGKKM*  DGV,DG_    LMMY!^1aB  HIIr2   c                 6    | j                   j                         S r,   )rA   Xr;   s    r/   r'   zVector.xi       ||~~r2   valuec                 :    | j                   j                  |       y r,   )rA   SetXr.   rL   s     r/   r'   zVector.xm       % r2   c                 6    | j                   j                         S r,   )rA   Yr;   s    r/   r(   zVector.yq   rK   r2   c                 :    | j                   j                  |       y r,   )rA   SetYrO   s     r/   r(   zVector.yu   rP   r2   c                 6    | j                   j                         S r,   )rA   Zr;   s    r/   r)   zVector.zy   rK   r2   c                 :    | j                   j                  |       y r,   )rA   SetZrO   s     r/   r)   zVector.z}   rP   r2   c                 6    | j                   j                         S r,   )rA   	Magnituder;   s    r/   LengthzVector.Length   s    ||%%''r2   c                     | j                   S r,   )r&   r;   s    r/   rA   zVector.wrapped   s    }}r2   c                 H    | j                   | j                  | j                  fS r,   r'   r(   r)   r;   s    r/   toTuplezVector.toTuple   s    ''r2   c                 ^    t        | j                  j                  |j                              S r,   )r$   rA   Crossedr7   s     r/   crosszVector.cross   s     dll**199566r2   c                 L    | j                   j                  |j                         S r,   )rA   Dotr7   s     r/   dotz
Vector.dot   s    ||		**r2   c                 ^    t        | j                  j                  |j                              S r,   )r$   rA   
Subtractedr7   s     r/   subz
Vector.sub   s     dll--aii899r2   c                 $    | j                  |      S r,   )rh   r7   s     r/   __sub__zVector.__sub__       xx{r2   c                 ^    t        | j                  j                  |j                              S r,   )r$   rA   Addedr7   s     r/   addz
Vector.add   s     dll((344r2   c                 $    | j                  |      S r,   )rn   r7   s     r/   __add__zVector.__add__   rk   r2   scalec                 J    t        | j                  j                  |            S )z/Return a copy multiplied by the provided scalar)r$   rA   
Multipliedr.   rq   s     r/   multiplyzVector.multiply   s    dll--e455r2   c                 $    | j                  |      S r,   ru   rt   s     r/   __mul__zVector.__mul__       }}U##r2   denomc                 *    | j                  d|z        S )N      ?rw   )r.   rz   s     r/   __truediv__zVector.__truediv__   s    }}S5[))r2   c                 $    | j                  |      S r,   rw   rt   s     r/   __rmul__zVector.__rmul__   ry   r2   c                 H    t        | j                  j                               S )z*Return a normalized version of this vector)r$   rA   
Normalizedr;   s    r/   
normalizedzVector.normalized   s    dll--/00r2   c                     | S )zReturn the vector itself

        The center of myself is myself.
        Provided so that vectors, vertices, and other shapes all support a
        common interface, when Center() is requested for all objects on the
        stack.
        r-   r;   s    r/   CenterzVector.Center   s	     r2   c                 L    | j                   j                  |j                         S r,   )rA   Angler7   s     r/   getAnglezVector.getAngle   s    ||!!!)),,r2   c                 d    | j                   j                  |j                   t        ddd            S )Nr   )rA   AngleWithRefr   r7   s     r/   getSignedAnglezVector.getSignedAngle   s&    ||((F1a4DEEr2   c                     t        d      Nz/Have not needed this yet, but OCCT supports it!NotImplementedErrorr;   s    r/   distanceToLinezVector.distanceToLine       !"STTr2   c                 N    |j                   }|| j                  |      ||z  z  z  S )z
        Returns a new vector equal to the projection of this Vector onto the line
        represented by Vector <line>

        :param args: Vector

        Returns the projected vector.
        )r[   re   )r.   line
lineLengths      r/   projectToLinezVector.projectToLine   s*     [[
txx~j)@ABBr2   c                     t        d      r   r   r;   s    r/   distanceToPlanezVector.distanceToPlane   r   r2   c                     |j                   }|j                  }| || |z
  j                  |      |j                  dz  z  z  z
  S )z
        Vector is projected onto the plane provided as input.

        :param args: Plane object

        Returns the projected vector.
        r!   )originzDirre   r[   )r.   planebasenormals       r/   projectToPlanezVector.projectToPlane   sC     ||f$+!2!26!:fmmq>P PQQQr2   c                     | dz  S )Nr   r-   r;   s    r/   __neg__zVector.__neg__   s    byr2   c                     | j                   S r,   )r[   r;   s    r/   __abs__zVector.__abs__   s    {{r2   c                 `    dt        | j                  | j                  | j                  f      z   S NzVector: strr'   r(   r)   r;   s    r/   __repr__zVector.__repr__   %    C 8999r2   c                 `    dt        | j                  | j                  | j                  f      z   S r   r   r;   s    r/   __str__zVector.__str__   r   r2   otherc                 t    t        |t              r'| j                  j                  |j                  dd      S dS )Ngh㈵>F)r@   r$   rA   IsEqualr.   r   s     r/   __eq__zVector.__eq__   s9     %( LL  A	
 	
r2   c              #   f   K   | j                   | j                  | j                  fE d {    y 7 wr,   r^   r;   s    r/   __iter__zVector.__iter__   s"     FFDFFDFF+++s   '1/1c                 H    t        | j                  j                               S r,   )r   rA   rB   r;   s    r/   toPntzVector.toPnt       dll&&())r2   c                 H    t        | j                  j                               S r,   )r   rA   rB   r;   s    r/   toDirzVector.toDir   r   r2   c                     | j                         }|j                  |j                  j                               }t	        t        |j                                     S r,   )r   TransformedrA   Trsfr$   r   rB   )r.   Tpntpnt_ts       r/   	transformzVector.transform   s>     jjl		 01fUYY[)**r2   c                 H    | j                   | j                  | j                  fS r,   r^   r;   s    r/   __getstate__zVector.__getstate__  s    ''r2   statec                 L    t               | _        |\  | _        | _        | _        y r,   )r   r&   r'   r(   r)   )r.   r   s     r/   __setstate__zVector.__setstate__
  s    !&r2   )r5   r$   r*   Nr*   N)r5   r$   r*   r$   )r*   r$   )r   r$   r*   r$   )r   Planer*   r$   )r   Matrixr*   r$   )8__name__
__module____qualname____doc__r   __annotations__r   floatr0   r   r   r   r   r   propertyr'   setterr(   r)   r[   rA   r	   r_   rb   re   rh   rj   rn   rp   ru   rx   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   boolr   r   r   r   r   r   rC   r   r   r-   r2   r/   r$   r$   %   sV    % E e    % E d     (5/ d   % >? D    6  5     XX!u ! ! !  5     XX!u ! ! !  5     XX!u ! ! ! ( ( (   (ueU23 (7+X +% +:56e 6 6$U $x $* *8 *$e $ $1-( -u -F FU FUCUR :# :: :
H 
 
,(5/ ,*v **v *+(eE5%$78 ('%ue(;"< 'r2   c                   V   e Zd ZU dZeed<   edd       Zedeee	f   ddfd       Zede
e
e      ddfd       Zdd	Zd
efdZd
efdZd
efdZded
efdZddZededefd       Zedd       Zd Zde
e   fdZdeeef   defdZdefdZdeee      fdZdeee      fdZy) r   a  A 3d , 4x4 transformation matrix.

    Used to move geometry in space.

    The provided "matrix" parameter may be None, a gp_GTrsf, or a nested list of
    values.

    If given a nested list, it is expected to be of the form:

        [[m11, m12, m13, m14],
         [m21, m22, m23, m24],
         [m31, m32, m33, m34]]

    A fourth row may be given, but it is expected to be: [0.0, 0.0, 0.0, 1.0]
    since this is a transform matrix.
    rA   r*   Nc                      y r,   r-   r;   s    r/   r0   zMatrix.__init__%  r1   r2   matrixc                      y r,   r-   r.   r   s     r/   r0   zMatrix.__init__)  r1   r2   c                      y r,   r-   r   s     r/   r0   zMatrix.__init__-  r1   r2   c                    |t               | _        y t        |t               r|| _        y t        |t              rt        |      | _        y t        |t        t
        f      rt        d |D              xr t        |      dv }|st        dj                  |            t        |      dk(  r.t        |d         dk7  rt        dj                  |d               t               | _        t        |d d       D cg c];  \  }}t        |      D ](  \  }}| j                  j                  |dz   |dz   |      * = c}}}} y t        d	j                  |            c c}}}}w )
Nc              3   h   K   | ]*  }t        |t        t        f      xr t        |      d k(   , yw)   N)r@   rD   rC   r?   ).0rows     r/   	<genexpr>z"Matrix.__init__.<locals>.<genexpr>;  s0      PVC$/CSX]CPVs   02)r=   r   z@Matrix constructor requires 2d list of 4x3 or 4x4, but got: {!r}r   r=   )r   r   r   r>   z4Expected the last row to be [0,0,0,1], but got: {!r}r>   z'Invalid param to matrix constructor: {})r   rA   r@   r   rD   rC   allr?   rE   format
ValueError	enumerateSetValue)r.   r   valid_sizesir   jes          r/   r0   zMatrix.__init__1  sX   >#:DL)!DL(#F+DLu. PV  (f+'  V]] 
 f+"vay)9\)I JQQq	  $:DL (r
33FAs%cNDAq %%a!eQUA6* 73 ELLVTUUs   =A E
anglec                 L    | j                  t        j                         |       y r,   )_rotater   OX_sr.   r   s     r/   rotateXzMatrix.rotateXV      RWWY&r2   c                 L    | j                  t        j                         |       y r,   )r   r   OY_sr   s     r/   rotateYzMatrix.rotateYZ  r   r2   c                 L    | j                  t        j                         |       y r,   )r   r   OZ_sr   s     r/   rotateZzMatrix.rotateZ^  r   r2   	directionc                 v    t               }|j                  ||       | j                  t        |      z  | _        y r,   )r   SetRotationrA   r   )r.   r   r   news       r/   r   zMatrix._rotateb  s+    i	5)||hsm3r2   c                 H    t        | j                  j                               S r,   )r   rA   Invertedr;   s    r/   inversezMatrix.inversei  s    dll++-..r2   r   c                      y r,   r-   r   s     r/   ru   zMatrix.multiplym  r1   r2   c                      y r,   r-   r   s     r/   ru   zMatrix.multiplyq  r1   r2   c                     t        |t              r|j                  |       S t        | j                  j                  |j                              S r,   )r@   r$   r   r   rA   rs   r   s     r/   ru   zMatrix.multiplyu  s9    eV$??4((dll--emm<==r2   c                 2   | j                   }t        dd      D cg c],  }t        dd      D cg c]  }|j                  ||       c}. c}}g dgz   }t        d      D cg c]  }t        d      D ]
  }||   |     c}}S c c}w c c}}w c c}}w )z#Needed by the cqparts gltf exporterr>   r              r   r   r|   rA   rangeValue)r.   trsfr   r   datas        r/   transposed_listzMatrix.transposed_list|  s     ||AFq!MA5A;7;aAq!;7M Q
 
 %*!H?HqeAhQ
h
H??	 8M @s   BBB%BBrcc                 &   t        |t              rt        |      dk7  rt        d      |\  }}d|cxk  rdk  r?n n<d|cxk  rdk  r1n n.|dk  r"| j                  j                  |dz   |dz         S g d|   S t        dj                  |            )zProvide Matrix[r, c] syntax for accessing individual values. The row
        and column parameters start at zero, which is consistent with most
        python libraries, but is counter to gp_GTrsf(), which is 1-indexed.
        r!   z+Matrix subscript must provide (row, column)r   r=   r>   r   z*Out of bounds access into 4x4 matrix: {!r})r@   rC   r?   
IndexErrorrA   r  r   )r.   r  rcs       r/   __getitem__zMatrix.__getitem__  s    
 "e$RAJKKAKaKa1kk1u||))!a%Q77 ,A..IPPQSTUUr2   c                 v    | j                         dj                  fdt        d      D              }d| dS )zM
        Generate a valid python expression representing this Matrix
        z
,
        c              3   @   K   | ]  }t        |d d           y w)Nr   )r   )r   r   matrix_transposeds     r/   r   z"Matrix.__repr__.<locals>.<genexpr>  s#     'Wh,=add,C(Dhs   r   zMatrix([z]))r  joinr   )r.   
matrix_strr  s     @r/   r   zMatrix.__repr__  s>     !002"'''WeTUh'WW
*R((r2   c                     | j                   }t        dd      D cg c],  }t        dd      D cg c]  }|j                  ||       c}. c}}S c c}w c c}}w )Nr>   r   r   r   )r.   r  r   r   s       r/   r   zMatrix.__getstate__  sL    ||AFq!MA5A;7;aAq!;7MM7Ms   AAAAr   c                     t               x}| _        t        d      D ]1  }t        d      D ]!  }|j                  |dz   |dz   ||   |          # 3 y )Nr=   r   r>   )r   rA   r   r   )r.   r   r  r   r   s        r/   r   zMatrix.__setstate__  sL    &j(t|qA1Xa!eQUE!HQK8  r2   r   r,   )r*   r   )r   r   r*   r   )r   r   r   r   r   r   r   r0   r   r   r   r   r   r   r   r   r   r   r$   ru   r  r	   intr
  r   r   rD   r   r   r-   r2   r/   r   r     s^   "   uXw%67 D   x8 T  #VJ'U ''U ''U '4 4 4/ f     >@% @VeCHo V% V$)# )Nd4;/ N
9$tE{"3 9r2   r   c                      e Zd ZU dZeed<   eed<   eed<   eed<   eed<   eed<   eed<   d	Zd	Z	e
d5ded    dedd fd       Ze
d
 eddd      fd       Ze
d
 eddd      fd       Ze
d
 eddd      fd       Ze
d
 eddd      fd       Ze
d
 eddd      fd       Ze
d
 eddd      fd       Ze
d
 eddd      fd       Ze
d
 eddd      fd       Ze
d
 eddd      fd       Ze
d
 eddd      fd       Ze
d
 eddd      fd       Ze
d
 eddd      fd       Ze	 	 d6deeeeef   ef   deeeeeef   ef      d eeeeef   ef   fd!       Ze	 	 d7d"       Zd# Z d$ Z!d% Z"d& Z#e$defd'       Z%e%jL                  d(        Z%d) Z'd* Z(defd+Z)d5d,Z*d8d-Z+d. Z,d/ Z-e$d9d0       Z.de/fd1Z0deeeeef   fd2Z1d3eeeeef   fd4Z2y):r   a  A 2D coordinate system in space

    A 2D coordinate system in space, with the x-y axes on the plane, and a
    particular point as the origin.

    A plane allows the use of 2D coordinates, which are later converted to
    global, 3d coordinates when the operations are complete.

    Frequently, it is not necessary to create work planes, as they can be
    created automatically from faces.
    xDiryDirr   _originlcsrGfGgư>r   r   r   clsstdNamer*   c                    t        |dd      t        |dd      t        |dd      t        |dd      t        |dd      t        |dd      t        |dd      t        |dd      t        |dd      t        |dd      t        |dd      t        |dd      d}	 ||   S # t        $ r2 t        dj                  t	        |j                                           w xY w)	aB  Create a predefined Plane based on the conventional names.

        :param stdName: one of (XY|YZ|ZX|XZ|YX|ZY|front|back|left|right|top|bottom)
        :type stdName: string
        :param origin: the desired origin, specified in global coordinates
        :type origin: 3-tuple of the origin of the new plane, in global coordinates.

        Available named planes are as follows. Direction references refer to
        the global directions.

        =========== ======= ======= ======
        Name        xDir    yDir    zDir
        =========== ======= ======= ======
        XY          +x      +y      +z
        YZ          +y      +z      +x
        ZX          +z      +x      +y
        XZ          +x      +z      -y
        YX          +y      +x      -z
        ZY          +z      +y      -x
        front       +x      +y      +z
        back        -x      +y      -z
        left        +z      +y      -x
        right       -z      +y      +x
        top         +x      -z      +y
        bottom      +x      +z      -y
        =========== ======= ======= ======
        r>   r   r   r   r   r>   )r   r>   r   )r   r   r   )r   r   r   )r   r   r   )XYYZZXXZYXZYfrontbackleftrighttopbottomzSupported names are {})r   KeyErrorr   r   rD   keys)r  r  r   namedPlaness       r/   namedzPlane.named  s    @ 	95	95	95	:6	:6	:669i8&*j9&)Z86:y9I6FIz:
 	Xw'' 	X5<<T+BRBRBT=UVWW	Xs   B ;Cr>   r   c                 T    t         j                  d|      }|j                  |       |S )Nr   r   r/  _setPlaneDirr  r   r  r   s       r/   r   zPlane.XY  %    D&)4 r2   c                 T    t         j                  d|      }|j                  |       |S )Nr!  r1  r3  s       r/   r!  zPlane.YZ  r4  r2   c                 T    t         j                  d|      }|j                  |       |S )Nr"  r1  r3  s       r/   r"  zPlane.ZX  r4  r2   c                 T    t         j                  d|      }|j                  |       |S )Nr#  r1  r3  s       r/   r#  zPlane.XZ  r4  r2   c                 T    t         j                  d|      }|j                  |       |S )Nr$  r1  r3  s       r/   r$  zPlane.YX  r4  r2   c                 T    t         j                  d|      }|j                  |       |S )Nr%  r1  r3  s       r/   r%  zPlane.ZY  r4  r2   c                 T    t         j                  d|      }|j                  |       |S )Nr&  r1  r3  s       r/   r&  zPlane.front  %    GV,4 r2   r   c                 T    t         j                  d|      }|j                  |       |S )Nr'  r1  r3  s       r/   r'  z
Plane.back%  %    FF+4 r2   c                 T    t         j                  d|      }|j                  |       |S )Nr(  r1  r3  s       r/   r(  z
Plane.left+  r=  r2   c                 T    t         j                  d|      }|j                  |       |S )Nr)  r1  r3  s       r/   r)  zPlane.right1  r;  r2   c                 T    t         j                  d|      }|j                  |       |S )Nr*  r1  r3  s       r/   r*  z	Plane.top7  s%    E6*4 r2   c                 T    t         j                  d|      }|j                  |       |S )Nr+  r1  r3  s       r/   r+  zPlane.bottom=  s%    Hf-4 r2   Nr   r   c                    t        |      }|j                  dk(  rt        d      |j                         | _        |Tt        t        |      j                         t        |      j                               }t        |j                               }n%t        |      }|j                  dk(  rt        d      | j                  |       t        |      | _
        y)zbCreate a Plane from origin in global coordinates, vector xDir, and normal direction for the plane.r   znormal should be non nullNzxDir should be non null)r$   r[   r   r   r   r   r   r   
XDirectionr2  r   )r.   r   r  r   r   ax3s         r/   r0   zPlane.__init__F  s     f~;;#899OO%	<--/1E1E1GHC#..*+D$<D{{c! !:;;$Vnr2   c                 V   |j                         \  }}t               j                  |d   t        z  dz         j	                  |d   t        z  dz         j                  |d   t        z  dz         d}fd|D        }|\  }}|| _        | j                  |       || _        y)z!Create a Plane from Location loc.r!        f@r>   r   )r  r  c              3   L   K   | ]  }t        | j                          y wr,   )r$   r   )r   r   transformations     r/   r   z!Plane.__init__.<locals>.<genexpr>  s!     N:aVQZ)).9:s   !$N)	r_   r   r   r   r   r   r   r2  r   )	r.   locr   	rotations
globaldirs	localdirsr  r   rH  s	           @r/   r0   zPlane.__init___  s      KKM	$  y|b0589y|b0589y|b0589 ,
N:N	 !f 	$r2   c              #     K   t        |       }t        |t               t        | j                  |j                  z
        |j
                  k   t        | j                  j                  |j                        dz
        |j                  k   t        | j                  j                  |j                        dz
        |j                  k   yw)z&Iterator to successively test equalityr>   N)
typer@   r   absr   _eq_tolerance_originr   re   _eq_tolerance_dotr  )r.   r   r  s      r/   _eq_iterzPlane._eq_iter  s     4j&&$++,-0H0HHH$))--

+a/033H3HHH$))--

+a/033H3HHHs   CCc                 6    t        | j                  |            S r,   )r   rR  r   s     r/   r   zPlane.__eq__  s    4=='((r2   c                 &    | j                  |       S r,   )r   r   s     r/   __ne__zPlane.__ne__  s    ;;u%%%r2   c           	          dt        | j                  j                                dt        | j                  j                                dt        | j                  j                                dS )NzPlane(origin=z, xDir=z	, normal=))r   r   r_   r  r   r;   s    r/   r   zPlane.__repr__  sb    s4;;#6#6#89:'#diiFWFWFYBZA[[dehimiririzizi|e}d~~  A  	Ar2   c                     | j                   S r,   )r  r;   s    r/   r   zPlane.origin  s    ||r2   c                 D    t        |      | _        | j                          y r,   )r$   r  _calcTransformsrO   s     r/   r   zPlane.origin  s    e}r2   c                 4    | j                  ||f      | _        y)az  
        Set a new origin in the plane itself

        Set a new origin in the plane itself. The plane's orientation and
        xDrection are unaffected.

        :param float x: offset in the x direction
        :param float y: offset in the y direction
        :return: void

        The new coordinates are specified in terms of the current 2D system.
        As an example:

        p = Plane.XY()
        p.setOrigin2d(2, 2)
        p.setOrigin2d(2, 2)

        results in a plane with its origin at (x, y) = (4, 4) in global
        coordinates. Both operations were relative to local coordinates of the
        plane.
        N)toWorldCoordsr   r4   s      r/   setOrigin2dzPlane.setOrigin2d  s    , ((!Q0r2   c                     ddl m} t        |t              r|j	                  | j
                        S t        ||      r|j                  | j
                        S t        dj                  t        |                  )aK  Project the provided coordinates onto this plane

        :param obj: an object or vector to convert
        :type vector: a vector or shape
        :return: an object of the same type, but converted to local coordinates


        Most of the time, the z-coordinate returned will be zero, because most
        operations based on a plane are all 2D. Occasionally, though, 3D
        points outside of the current plane are transformed. One such example is
        :py:meth:`Workplane.box`, where 3D corners of a box are transformed to
        orient the box in space correctly.

        r>   )Shapez6Don't know how to convert type {} to local coordinates)
shapesr_  r@   r$   r   r  transformShaper   r   rN  )r.   objr_  s      r/   toLocalCoordszPlane.toLocalCoords  se     	"c6"==))U#%%dgg..HOOI r2   c                     t        |t              r|}n-t        |      dk(  rt        |d   |d   d      }nt        |      }|j                  | j                        S )a"  Convert a point in local coordinates to global coordinates

        :param tuplePoint: point in local coordinates to convert.
        :type tuplePoint: a 2 or three tuple of float. The third value is taken to be zero if not supplied.
        :return: a Vector in global coordinates
        r!   r   r>   )r@   r$   r?   r   r  )r.   
tuplePointr5   s      r/   r\  zPlane.toWorldCoords  sR     j&)A_!z!}jmQ7Az"A{{477##r2   c           	         t        |      }|j                  t        dz        }t               }|j	                  t        t        d t        | j                  j                                |j                         t               }|j	                  t        t        d t        | j                  j                                |j                         t               }|j	                  t        t        d t        | j                  j                                |j                         t        t!        ||z  |z              }| j                  j#                  |      }| j                  j#                  |      }t%        | j&                  ||      S )a  Returns a copy of this plane, rotated about the specified axes

        Since the z axis is always normal the plane, rotating around Z will
        always produce a plane that is parallel to this one.

        The origin of the workplane is unaffected by the rotation.

        Rotations are done in order x, y, z. If you need a different order,
        manually chain together multiple rotate() commands.

        :param rotate: Vector [xDegrees, yDegrees, zDegrees]
        :return: a copy of this plane rotated as requested.
        rF  r  )r$   ru   r   r   r   r   r   r   r  r_   r'   r  r(   r   r)   r   r   r   r   r   )r.   rotateT1T2T3r   newXdirnewZdirs           r/   rotatedzPlane.rotated  s)    e, Y
69%vtyy/@/@/B'CDfhh	
 Y
69%vtyy/@/@/B'CDfhh	
 Y
69%vtyy/@/@/B'CDfhh	
 8BGbL)* ))%%a())%%a(T[['733r2   c                 T   t        | j                  j                         | j                  j	                         | j
                  j	                               }t               }|dk(  rB|j                  t        | j                  j                         |j                                      nM|dk(  rB|j                  t        | j                  j                         |j                                      nt        g }|D ]-  }|j                  t        |            }|j                  |       / |S )NrJ   rR   )r   r   r   r   r   r  r   	SetMirrorr   rC  
YDirectionr   ra  r   append)r.   listOfShapesaxislocal_coord_systemr   resultWireswmirroreds           r/   mirrorInPlanezPlane.mirrorInPlane  s    #KK!2DIIOO4E
 I3;KKt{{0024F4Q4Q4STUS[KKt{{0024F4Q4Q4STU%%A''q	2H x(	  r2   c                     t        |      }|j                         | _        | j                  j	                  | j                        j                         | _        y)z9Set the vectors parallel to the plane, i.e. xDir and yDirN)r$   r   r  r   rb   r  )r.   r  s     r/   r2  zPlane._setPlaneDir*  s:    d|OO%	IIOODII.99;	r2   c                    t               }t               }t               }t               }t               }t        t        | j                  j                          t        | j                  j                          t        | j                  j                                }|j                  ||       t        |      |_        |j                  ||       t        |      |_        || _        || _        || _        y)zComputes transformation matrices to convert between coordinates

        Computes transformation matrices to convert between local and global
        coordinates.
        N)r   r   r   r   r   r_   r   r   r  SetTransformationr   rA   r  r  r  )r.   forwardr   forwardTinverseTglobal_coord_systemrt  s          r/   rZ  zPlane._calcTransforms0  s     ((99$h#DKK'')*DII%%'(DII%%'(
 	""#68JK"8,""#57JK"8,%r2   c                     t        |       S r,   )Locationr;   s    r/   locationzPlane.locationQ  s     ~r2   c                     t        t        | j                  j                         | j                  j                         | j                  j                                     S r,   )r   r   r   r   r   r   r  r;   s    r/   toPlnzPlane.toPlnV  s9    fT[[..0$))//2CTYY__EVWXXr2   c                 ^    | j                   | j                  | j                  | j                  fS r,   )r  r  r   r  r;   s    r/   r   zPlane.__getstate__Z  s!    		499dii>>r2   r  c                 :    |\  | _         | _        | _        | _        y r,   )r  r  r   r   )r.   r  s     r/   r   zPlane.__setstate__^  s    7;4	49dir2   )r  )Nr  )rI  r  )rJ   r*   r  )3r   r   r   r   r$   r   r   r   rP  rQ  classmethodr
   r   r/  r   r!  r"  r#  r$  r%  r&  r'  r(  r)  r*  r+  r#   r   r	   r"   r   r0   rR  r   rU  r   r   r   r   r]  rc  r\  rm  rx  r2  rZ  r  r   r  r   r   r-   r2   r/   r   r     sb   
 L
L
LO	KJJ  0X4= 0X3 0XW 0X 0Xd  vaA  
  vaA  
  vaA  
  vaA  
  vaA  
  vaA  
 #&Aq/  
 "Aq)9  
 "1a  
 #&Ar*:  
 !q!Q  
 $6!Q?    BF9B	%eD$,-v56% uU4t#34f<=>% eD$,-v56	% %0 )) )V	I)&A    ]] 108$6 $&4P.<B  Yv Y?eFFFF$BC ?<vvvv'E!F <r2   r   c            
       H   e Zd ZU dZeed<   eed<   eed<   eed<   eed<   eed<   eed<   eed	<   eed
<   eed<   eed<   eed<   deddfdZ	 dde	e
eeef   ed f   dee   dd fdZdedd fdZedd dd ded    fd       Ze	 	 d ded    dedee   defd       Zdd defdZy)!BoundBoxz@A BoundingBox for an object or set of objects. Wraps the OCP onerA   xminxmaxxlenyminymaxylenzminzmaxzlencenterDiagonalLengthbbr*   Nc                 \   || _         |j                         \  }}}}}}|| _        || _        ||z
  | _        || _        || _        ||z
  | _        || _        || _	        ||z
  | _
        t        ||z   dz  ||z   dz  ||z   dz        | _        | j                   j                         dz  | _        y )Nr!   g      ?)rA   Getr  r  r  r  r  r  r  r  r  r$   r  SquareExtentr  )r.   r  XMinYMinZMinXMaxYMaxZMaxs           r/   r0   zBoundBox.__init__w  s    -/VVX*dD$d		4K			4K			4K	dTkQ.0AD4KSTCTU"ll779S@r2   rb  tolc                    |t         n|}t               }|j                  |       |j                  | j                         t        |t              r |j                  |  t        |      S t        |t              r( |j                  |j                           t        |      S t        |t              r|j                  |j                         t        |      S )aq  Returns a modified (expanded) bounding box

        obj can be one of several things:
            1. a 3-tuple corresponding to x,y, and z amounts to add
            2. a vector, containing the x,y,z values to add
            3. another bounding box, where a new box will be created that
               encloses both.

        This bounding box is not changed.
        )TOLr   SetGapAddrA   r@   rC   Updater$   r_   r  )r.   rb  r  tmps       r/   rn   zBoundBox.add  s      [cci

3c5!CJJ } V$CJJ& } X&GGCKK }r2   c                     t               }|j                  | j                         |j                  | j                  j	                                |j                  |       t        |      S )a@  Returns a modified (expanded) bounding box, expanded in all
        directions by the tolerance value.

        This means that the minimum values of its X, Y and Z intervals
        of the bounding box are reduced by the absolute value of tol, while
        the maximum values are increased by the same amount.
        )r   r  rA   r  GetGapEnlarger  )r.   r  r  s      r/   enlargezBoundBox.enlarge  sJ     i

4<<&&()C}r2   bb1bb2c                    | j                   |j                   k  rM| j                  |j                  kD  r4| j                  |j                  k  r| j                  |j                  kD  r| S |j                   | j                   k  rM|j                  | j                  kD  r4|j                  | j                  k  r|j                  | j                  kD  r|S y)a  Compares bounding boxes

        Compares bounding boxes. Returns none if neither is inside the other.
        Returns the outer one if either is outside the other.

        BoundBox.isInside works in 3d, but this is a 2d bounding box, so it
        doesn't work correctly plus, there was all kinds of rounding error in
        the built-in implementation i do not understand.
        N)r  r  r  r  )r  r  s     r/   findOutsideBox2DzBoundBox.findOutsideBox2D  s     HHsxx388#388#388#J HHsxx388#388#388#Jr2   r  shapeoptimalc                     |t         n|}t               }|rt        j                  ||       n4t	        ||d      }|j                          t        j                  ||d        | |      S )z?
        Constructs a bounding box from a TopoDS_Shape
        T)r  r   r   AddOptimal_sr   PerformAdd_s)r  r  r  r  bboxmeshs         r/   _fromTopoDSzBoundBox._fromTopoDS  sa     [ccy##t ,E3=DLLNUD$/4yr2   b2c                 2   |j                   | j                   kD  r~|j                  | j                  kD  re|j                  | j                  kD  rL|j                  | j                  k  r3|j                  | j                  k  r|j
                  | j
                  k  ryy)z-Is the provided bounding box inside this one?TF)r  r  r  r  r  r  )r.   r  s     r/   isInsidezBoundBox.isInside  sj     GGdii$))#$))#$))#$))#$))#r2   r,   )NT)r   r   r   r   r   r   r   r$   r0   r   r	   r   rn   r  staticmethodr  r  r
   r   r   r  r  r-   r2   r/   r  r  c  s8   J
K
K
K
K
K
K
K
K
KNA7 At A*  $5u,-vzAB e_ 
	>5 Z   j z hz>R  :   $	* e_ 	 0: $ r2   r  c                      e Zd ZU dZeed<   ededdfd       Ze	 	 	 	 	 	 d"de	de	d	e	d
e	de	de	ddfd       Zede
ddfd       Zede
deddfd       Zededdfd       Zededdfd       Zededede	ddfd       Zededee	e	e	f   ddfd       Zed#d       Zd$dZdedd fdZdeeeeef   eeeef   f   fdZed%d       ZdefdZd efd!Zy)&r  a
  Location in 3D space. Depending on usage can be absolute or relative.

    This class wraps the TopLoc_Location class from OCCT. It can be used to move Shape
    objects in both relative and absolute manner. It is the preferred type to locate objects
    in CQ.
    rA   tr*   Nc                     t               }|j                  t        |      j                         t	        |      | _        y)zBLocation with translation t with respect to the original location.N)r   SetTranslationPartr$   rA   r   r.   r  r   s      r/   r0   zLocation.__init__  s/     I	VAY../&q)r2   r'   r(   r)   rxryrzc                 j   t        ||||||f      rt               }t               }|j                  t        t        |      t        |      t        |             |j                  |       |j                  t        |||      j                         t        |      }	|	| _	        yt               }	|	| _	        y)z8Location with translation (x,y,z) and 3 rotation angles.N)anyr   r   SetEulerAnglesr   r   r   r  r$   rA   r   )
r.   r'   r(   r)   r  r  r  r   qrI  s
             r/   r0   zLocation.__init__  s     1aR$%	AA-wr{GBKQSUMM!  1a!8!89!!$C
  "#Cr2   c                     t               }|j                  t        |j                  j	                         |j
                  j                         |j                  j                                      |j                          t        |      | _
        y)z6Location corresponding to the location of the Plane t.N)r   r{  r   r   r   r   r   r  Invertr   rA   r  s      r/   r0   zLocation.__init__.  sV     I	F188>>#3QVV\\^QVV\\^TU	
&q)r2   r5   c                    t               }|j                  t        t        |      j	                         |j
                  j                         |j                  j                                      |j                          t        |      | _
        y)zQLocation corresponding to the angular location of the Plane t with translation v.N)r   r{  r   r$   r   r   r   r  r  r   rA   )r.   r  r5   r   s       r/   r0   zLocation.__init__8  sV     I	F6!9??#4affllnaffllnUV	
&q)r2   r   c                     || _         y)z8Location wrapping the low-level TopLoc_Location object tN)rA   r.   r   s     r/   r0   zLocation.__init__B  s     r2   c                 $    t        |      | _        y)z0Location wrapping the low-level gp_Trsf object tN)r   rA   r  s     r/   r0   zLocation.__init__H  s     'q)r2   axr   c                 $   t               }|j                  t        t               j	                         t        |      j                               t        |             |j                  t        |      j                         t        |      | _        y)zjLocation with translation t and rotation around ax by angle
        with respect to the original location.N)
r   r   r   r$   r   r   r   r  rA   r   )r.   r  r  r   r   s        r/   r0   zLocation.__init__N  s^    
 I	fVX^^-vbz/?/?/ABGENS	VAY../&q)r2   anglesc                     t               }t               } |j                  t        gt	        t
        |        |j                  |       |j                  t        |      j                         t        |      | _	        y)z2Location with translation t and 3 rotation angles.N)r   r   r  r   mapr   r   r  r$   rA   r   )r.   r  r  r   r  s        r/   r0   zLocation.__init__Y  s_     IO)AC,@A	a	VAY../&q)r2   c                 H    t        | j                  j                               S r,   )r  rA   r   r;   s    r/   r   zLocation.inverseg  s     --/00r2   c                 F    t        | j                  |j                  z        S r,   )r  rA   r   s     r/   rx   zLocation.__mul__l  s    u}}455r2   exponentc                 J    t        | j                  j                  |            S r,   )r  rA   Powered)r.   r  s     r/   __pow__zLocation.__pow__p  s    ,,X677r2   c                 ^   | j                   j                         }|j                         }|j                         }|j	                         |j                         |j                         f}|j                  t        j                        \  }}}|t        |      t        |      t        |      ffS )z6Convert the location to a translation, rotation tuple.)rA   TransformationTranslationPartGetRotationrJ   rR   rV   GetEulerAnglesr   r   r   )r.   r   transrotrv_transr  r  r  s           r/   r_   zLocation.toTuplet  s     LL'')!!#mmoGGIuwwy%'')4''(8(I(IJ
B'"+wr{GBK@@@r2   c                     t        |       S r,   )r   r;   s    r/   r   zLocation.plane  s     T{r2   c                     t               }t               }|j                  | j                         |j	                  |       |j                  d       |S )Nr   )r   r    r  rA   Writeseek)r.   rvlss      r/   r   zLocation.__getstate__  s<    Y!#
t||


	r2   r  c                     t               }|j                  |       |j                         dkD  r|j                  d      | _        y t               | _        y )Nr   r>   )r    ReadNbLocationsr  rA   r   )r.   r  r  s      r/   r   zLocation.__setstate__  s=    !#
>>a;;q>DL*,DLr2   )r   r   r   r   r   r   r  )r   r  r*   r  )r*   r   )r   r   r   r   r   r   r#   
VectorLiker0   r"   r   r   r	   r   r   rx   r  r  r   r_   r   r   r   r   r-   r2   r/   r  r    s    ** * * *    	
    
 8 *% *D * * *% *J *4 * * / d  
 *' *d * *
 ** ** *T *d * * ** *eD$4D.E *$ * * 1 168 8
 8
AuUE5%895uAT;UUV 
A  
g 
- -r2   r  N)4mathr   r   r   typingr   r   r   r	   r
   r   r   ior   OCP.gpr   r   r   r   r   r   r   r   r   r   r   r   r   OCP.Bndr   OCP.BRepBndLibr   OCP.BRepMeshr   
OCP.TopoDSr   
OCP.TopLocr   OCP.BinToolsr    typesr"   utilsr#   r  r  objectr$   r   r   r  r  r-   r2   r/   <module>r     s    % % M M M      % 1 # & -  !
8U4:.dD$6F0GGH
i'V i'XZ9 Z9zr<F r<jXv Xv[-v [-r2   