Ë
    :vžjxo  ã                   ó˜   — d Z ddlZddl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	„Zd
„ Zdd„Z	 	 dd„Z	 	 	 dd„Z	 	 	 dd„Zy)zT
intersections.py
------------------

Primarily mesh-plane intersections (slicing).
é    Né   )ÚgeometryÚgroupingÚutil)Útransformations)Ú	triangles)Útol)Úpoints_to_barycentricc                 óH  ‡‡— d„ }ˆˆfd„}d„ }ˆˆfd„}	t        j                  ‰t         j                  ¬«      Št        j                  ‰t         j                  ¬«      Š‰j                  dk7  s‰j                  dk7  rt	        d«      ‚|€| j
                  }
n4t        j                  |t         j                  ¬«      }| j
                  |   }
|�|}n#t        j                  | j                  ‰z
  ‰«      }t        j                  t        | j                  «      t         j                  ¬«      }d||t        j                   k  <   d	||t        j                  kD  <   ||
   } ||«      }|	||f}t        j                  t        ||«      D ��cg c]  \  }} |||   |
|   | j                  «      ‘Œ! c}}«      }|rat        j                   |D �cg c]  }t        j"                  |«      d
   ‘Œ c}«      }|j$                  j&                  dk(  sJ ‚|€||fS |||   fS |S c c}}w c c}w )aH  
    Find a the intersections between a mesh and a plane,
    returning a set of line segments on that plane.

    Parameters
    ---------
    mesh : Trimesh object
      Source mesh to slice
    plane_normal : (3,) float
      Normal vector of plane to intersect with mesh
    plane_origin : (3,) float
      Point on plane to intersect with mesh
    return_faces : bool
      If True return face index each line is from
    local_faces : None or (m,) int
      Limit section to just these faces.
    cached_dots : (n, 3) float
      If an external function has stored dot
      products pass them here to avoid recomputing.

    Returns
    ----------
    lines :  (m, 2, 3) float
      List of 3D line segments in space.
    face_index : (m,) int
      Index of mesh.faces for each line
      Only returned if return_faces was True
    c                 ój  — t        j                  | d¬«      }t        j                  t        |«      t         j                  ¬«      dz   }t        d«      D ]  }||dd…|f   d|z
  z  z  }Œ t        j                  dt        ¬«      }d|d	<   ||   }d
|dd d|d<   ||   }d
|dd d|ddg<   ||   }|||fS )aÁ  
        Figure out which faces correspond to which intersection
        case from the signs of the dot product of each vertex.
        Does this by bitbang each row of signs into an 8 bit
        integer.

        code : signs      : intersects
        0    : [-1 -1 -1] : No
        2    : [-1 -1  0] : No
        4    : [-1 -1  1] : Yes; 2 on one side, 1 on the other
        6    : [-1  0  0] : Yes; one edge fully on plane
        8    : [-1  0  1] : Yes; one vertex on plane 2 on different sides
        12   : [-1  1  1] : Yes; 2 on one side, 1 on the other
        14   : [0 0 0]    : No (on plane fully)
        16   : [0 0 1]    : Yes; one edge fully on plane
        20   : [0 1 1]    : No
        28   : [1 1 1]    : No

        Parameters
        ----------
        signs: (n,3) int, all values are -1,0, or 1
          Each row contains the dot product of all three vertices
          in a face with respect to the plane

        Returns
        ---------
        basic : (n,) bool
          Which faces are in the basic intersection case
        one_vertex : (n,) bool
          Which faces are in the one vertex case
        one_edge : (n,) bool
          Which faces are in the one edge case
        r   ©Úaxis©Údtypeé   é   Né   Té   Fé   é   é   )ÚnpÚsortÚzerosÚlenÚint8ÚrangeÚbool)ÚsignsÚsigns_sortedÚcodedÚiÚkeyÚone_edgeÚ
one_vertexÚbasics           úf/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/trimesh/intersections.pyÚtriangle_casesz"mesh_plane.<locals>.triangle_cases6   sÌ   € ôF —w‘w˜u¨1Ô-ˆÜ—‘œ˜\Ó*´"·'±'Ô:¸RÑ?ˆÜ�q–ˆAØ�\¢! Q $Ñ'¨1¨q©5Ñ0Ñ0‰Eð ô �h‰h�r¤Ô&ˆØˆˆB‰Ø�u‘:ˆð ˆ‰AˆØˆˆA‰Ø˜‘Zˆ
ð ˆ‰AˆØˆˆQ�ˆG‰Ø�E‘
ˆà�j (Ð*Ð*ó    c                 óÜ   •— || dk(     }|| dk7     j                  d«      }t        ‰	‰||j                     d¬«      \  }}t        j                  |||      |f«      j                  d«      }|S )Nr   ©éÿÿÿÿé   F©Úline_segments©r,   r-   r   )ÚreshapeÚplane_linesÚTr   Úcolumn_stack)
r   ÚfacesÚverticesÚvertex_planeÚ	edge_thruÚpoint_intersectÚvalidÚlinesÚplane_normalÚplane_origins
           €€r'   Úhandle_on_vertexz$mesh_plane.<locals>.handle_on_vertext   s�   ø€ ð ˜U a™ZÑ(ˆØ˜% 1™*Ñ%×-Ñ-¨gÓ6ˆ	Ü!,Ø˜,¨°·±Ñ(=ÈUô"
Ñˆ˜ô —‘ ¨,°uÑ*=Ñ!>ÀÐ PÓQ×YÑYØó
ˆð ˆr)   c                 ó>   — || dk(     j                  d«      }||   }|S )Nr   r+   )r1   )r   r5   r6   ÚedgesÚpointss        r'   Úhandle_on_edgez"mesh_plane.<locals>.handle_on_edge�   s)   € à�e˜q‘jÑ!×)Ñ)¨'Ó2ˆØ˜%‘ˆØˆr)   c                 óz  •— t        j                  | ddg¬«      }t        j                  ||   |t        j                  |dd¬«         ||   |t        j                  |dd¬«         f«      j                  d«      }t        ‰‰||j                     d¬«      \  }}|j                  «       sJ ‚|j                  d	«      S )
Nr,   r   )Úuniquer   r-   r+   Fr.   r0   )	r   Úunique_value_in_rowr   r4   Úrollr1   r2   r3   Úall)	r   r5   r6   Úunique_elementr@   Úintersectionsr:   r<   r=   s	          €€r'   Úhandle_basicz mesh_plane.<locals>.handle_basic‡   s¹   ø€ ä!×5Ñ5°eÀRÈÀGÔLˆÜ—‘à�nÑ%Ø”b—g‘g˜n¨a°aÔ8Ñ9Ø�nÑ%Ø”b—g‘g˜n¨a°aÔ8Ñ9ð	ó
÷ ‰'�'Ó
ð 	ô  +Ø˜,¨°·±Ñ(9Èô 
Ñˆ�uð
 �y‰yŒ{Ðˆ{Ø×$Ñ$ ZÓ0Ð0r)   r   ©r   z%Plane origin and normal must be (3,)!r,   r   r   r"   )r   Ú
asanyarrayÚfloat64ÚshapeÚ
ValueErrorr5   Úint64Údotr6   r   r   r   r	   ÚmergeÚvstackÚzipÚhstackÚnonzeror   Úkind)Úmeshr<   r=   Úreturn_facesÚlocal_facesÚcached_dotsr(   r>   rB   rJ   r5   Údotsr   ÚcasesÚhandlersÚcÚhr;   Úindexs    ``                r'   Ú
mesh_planerb      sç  ù€ òJ<+õ|òõ1ô( —=‘= ´R·Z±ZÔ@€LÜ—=‘= ´R·Z±ZÔ@€LØ×Ñ˜TÒ! \×%7Ñ%7¸4Ò%?ÜÐ@ÓAÐAàÐà—
‘
‰ä—m‘m K´r·x±xÔ@ˆà—
‘
˜;Ñ'ˆàÐØ‰ô
 �v‰v�d—m‘m lÑ2°LÓAˆô �H‰H”S˜Ÿ™Ó'¬r¯w©wÔ7€EØ!€Eˆ$”#—)‘)�Ñ
ÑØ€Eˆ$”—‘Ñ
ÑØ�%‰L€Eñ ˜5Ó!€EàÐ.°Ð?€Hô �I‰IÜ:=¸eÀXÔ:NÔOÑ:N±$°!°Q‰ˆ5�‰8�U˜1‘X˜tŸ}™}Õ	-Ð:NÒOó€Eñ ä—	‘	±UÓ;±U°œ2Ÿ:™: a›=¨Ó+°UÑ;Ó<ˆØ�{‰{×Ñ 3Ò&Ð&Ð&ØÐØ˜%�<Ðð �k %Ñ(Ð(Ð(Ø€Lùó 	Pùò
 <s   Æ$H
Ç	Hc                 ó¶  — t        j                  |«      }t        j                  |t        j                  ¬«      }t        j                  |t        j                  ¬«      }t        j
                  || j                  |z
  j                  «      }t        j                  ||¬«      }t        j                  j                  |«      }t        j                  d«      }g }g }g }	|D ]Î  }
|||
z  z   }||
z
  }t        | ||d|¬«      \  }}|
|d<   t        j
                  ||«      }t        j                  j                  |«      }|j                  |«       t        j                   |j#                  d«      |«      }|dd…dd	…f   j#                  d
«      }|	j                  |«       |j                  |«       ŒÐ t        j$                  |t        j                  ¬«      }|	||fS )aí  
    A utility function for slicing a mesh by multiple
    parallel planes which caches the dot product operation.

    Parameters
    -------------
    mesh : trimesh.Trimesh
        Geometry to be sliced by planes
    plane_origin : (3,) float
        Point on a plane
    plane_normal : (3,) float
        Normal vector of plane
    heights : (m,) float
      Offset distances from plane to slice at:
      at `height=0` it will be exactly on the passed plane.

    Returns
    --------------
    lines : (m,) sequence of (n, 2, 2) float
        Lines in space for m planes
    to_3D : (m, 4, 4) float
        Transform to move each section back to 3D
    face_index : (m,) sequence of (n,) int
        Indexes of mesh.faces for each segment
    r   ©ÚoriginÚnormalr   T)rX   r=   r<   rY   r[   )r-   r   ©r,   r   Nr-   )r,   r-   r-   )r   Úunitizer   rL   rM   rQ   r6   r3   r   Úplane_transformÚlinalgÚinvÚeyerb   ÚappendÚtfÚtransform_pointsr1   Úarray)rX   r=   r<   ÚheightsÚvertex_dotsÚbase_transformÚtranslationÚ
transformsÚ
face_indexÚsegmentsÚheightÚ
new_originÚnew_dotsr;   ra   Úto_3DÚto_2DÚlines_2Ds                     r'   Úmesh_multiplaner~   Î   s™  € ô6 —<‘< Ó-€LÜ—=‘= ´R·Z±ZÔ@€LÜ�m‰m˜G¬2¯:©:Ô6€Gô —&‘&˜¨¯©¸Ñ(D×'GÑ'GÓH€Kô ×-Ñ-°\È,ÔW€NÜ—Y‘Y—]‘] >Ó2€Nô —&‘&˜“)€Kð €JØ€JØ€Hó ˆà! \°FÑ%:Ñ;ˆ
à Ñ'ˆä!ØØ#Ø%ØØ ô
‰ˆˆuð #ˆ�DÑÜ—‘�~ {Ó3ˆÜ—	‘	—‘˜eÓ$ˆØ×Ñ˜%Ô ô ×&Ñ& u§}¡}°WÓ'=¸uÓEˆð šA˜r ˜r˜E‘?×*Ñ*¨:Ó6ˆà�‰˜Ô!à×Ñ˜%Õ ðA ôF —‘˜*¬B¯J©JÔ7€Jà�Z Ð+Ð+r)   c                 óP  — t        j                  |«      }t        j                  | «      j                  d«      } t        j                  |d   |d   z
  «      }t        j                  t        j                  |«      j                  d«      «      }t        j
                  || |d   z
  j                  «      }t        j
                  ||j                  «      }t        j                  |«      t        j                  kD  }|rät        j
                  |t        j                  | |d   z
  «      «      }t        j                  |«      t        j                  |«      k7  }	t        j                  t        j                  |«      t        j                  kD  t        j                  |«      t        j                  kD  «      }
t        j                  ||	«      }t        j                  ||
«      }t        j                  ||   ||   «      }|d   |   }|t        j                  |d«      ||   z  z   }||fS )au  
    Calculate plane-line intersections

    Parameters
    ---------
    plane_origin : (3,) float
        Point on plane
    plane_normal : (3,) float
        Plane normal vector
    endpoints : (2, n, 3) float
        Points defining lines to be tested
    line_segments : bool
        If True, only returns intersections as valid if
        vertices from endpoints are on different sides
        of the plane.

    Returns
    ---------
    intersections : (m, 3) float
        Cartesian intersection points
    valid : (n, 3) bool
        Indicate whether a valid intersection exists
        for each input line segment
    r   r   r   ©r,   r   )r   rL   r1   r   rh   rQ   r3   Úabsr	   ÚzeroÚ	transposeÚsignÚ
logical_orÚlogical_andÚdivide)r=   r<   Ú	endpointsr/   Úline_dirÚtÚbr:   ÚtestÚdifferent_sidesrV   ÚdÚintersections                r'   r2   r2   %  s“  € ô2 —‘˜iÓ(€IÜ—=‘= Ó.×6Ñ6°qÓ9€LÜ�|‰|˜I a™L¨9°Q©<Ñ7Ó8€HÜ—<‘<¤§¡¨lÓ ;× CÑ CÀAÓ FÓG€Lä
�‰ˆ|˜l¨Y°q©\Ñ9×<Ñ<Ó=€AÜ
�‰ˆ|˜XŸZ™ZÓ(€Aô
 �F‰F�1‹IœŸ™Ñ €EÙÜ�v‰v�l¤B§L¡L°À	È!ÁÑ1LÓ$MÓNˆÜŸ'™' !›*¬¯©°«Ñ5ˆÜ—-‘-¤§¡ q£	¬C¯H©HÑ 4´b·f±f¸T³lÄSÇXÁXÑ6MÓNˆÜ—‘˜u oÓ6ˆÜ—‘˜u gÓ.ˆä
�	‰	�!�E‘(˜A˜e™HÓ%€AØ˜Q‘< Ñ&€LØ¤"§*¡*¨Q°Ó"8¸8ÀE¹?Ñ"JÑJ€Là˜ÐÐr)   c                 óŠ  — t        j                  | t         j                  ¬«      } t        j                  |t         j                  ¬«      }t        j                  |t         j                  ¬«      }t        j                  |t         j                  ¬«      }| |z
  }t        j                  ||«      }t        j                  ||«      }t        j
                  |«      dkD  }	t        j                  ||	   ||	   «      }
||	   |
j                  d«      z  }|||	   z  }||	g}|r|j                  |
«       |r|j                  |«       |S )a  
    Given one line per plane find the intersection points.

    Parameters
    -----------
    plane_origins : (n,3) float
        Point on each plane
    plane_normals : (n,3) float
        Normal vector of each plane
    line_origins : (n,3) float
        Point at origin of each line
    line_directions : (n,3) float
        Direction vector of each line
    return_distance : bool
      Return distance from origin to point also
    return_denom : bool
      Return denominator, so you can check for small values

    Returns
    ----------
    on_plane : (n,3) float
      Points on specified planes
    valid : (n,) bool
      Did plane intersect line or not
    distance : (n,) float
      [OPTIONAL] Distance from point
    denom : (n,) float
      [OPTIONAL] Denominator
    r   gñhãˆµøä>r€   )	r   rL   rM   r   Údiagonal_dotr�   r‡   r1   rm   )Úplane_originsÚplane_normalsÚline_originsÚline_directionsÚreturn_distanceÚreturn_denomÚorigin_vectorsÚprojection_oriÚprojection_dirr:   ÚdistanceÚon_planeÚresults                r'   Úplanes_linesrž   X  s  € ôN —M‘M -´r·z±zÔB€MÜ—M‘M -´r·z±zÔB€MÜ—=‘= ´R·Z±ZÔ@€LÜ—m‘m O¼2¿:¹:ÔF€Oð # \Ñ1€Nä×&Ñ& ~°}ÓE€NÜ×&Ñ& ¸ÓF€Nä�F‰F�>Ó" TÑ)€Eä�y‰y˜¨Ñ.°¸uÑ0EÓF€Hà˜uÑ%¨×(8Ñ(8¸Ó(AÑA€HØ�˜UÑ#Ñ#€Hà˜Ð€FáØ�‰�hÔÙØ�‰�nÔ%à€Mr)   c           	      óV  — t        | «      dk(  r| ||fS |du}|�||   }|�|}nt        j                  | |z
  |«      }t        j                  t        | «      t        j                  ¬«      }	d|	|t
        j                   k  <   d|	|t
        j                  kD  <   |	|   }	|	j                  dt        j                  ¬«      }
t        j                  |	«      j                  dt        j                  ¬«      }t        j                  |dk\  t        j                  |
«      dk  «      }|
| k(  }|dk(  }|j                  «       rFt        j                  | ||      «      \  }}t        j                  ||«      }|||<   |||<   |dk  ||<   ||   }| |   }||   }|t        j                  ||
dk  «         }|t        j                  ||
dk\  «         }|	t        j                  ||
dk  «         }|	t        j                  ||
dk\  «         }t        |«      t        |«      z   dk(  rÜt        |«      dk(  rwt        j                  d	t        j                  ¬«      t        j                  d	t        j                  ¬«      |r(t        j                  d
t        j                  ¬«      f}|S df}|S t        j                   |j#                  d«      t        | «      d¬«      \  }}| |   }|j#                  d«      }|r||   nd}|||fS |}t        j$                  |dd¬«      |z
  } ||z
  j                  |«      }!t        j                  | |«      }"d|"|"dk(  <   t        j&                  |!|"«      }#|#dd…dd…df   | z  |z   }$| }%t        j                  d	«      }&t        j                  d	«      }'|$|
dk  |   dd…dd…f   }(t        |(«      })|)dkD  �r~t        j(                  |dk(  «      d   }*|t        j*                  t-        |)«      t-        |)«      fd¬«      t        j*                  |*dz   dz  |*dz   dz  fd¬«      f   }+t        j.                  |+t        j0                  t        |%«      t        |%«      d|)z  z   «      j#                  |)d«      d¬«      },|(t        j*                  t-        |)«      t-        |)«      fd¬«      t        j*                  |*dz   dz  j2                  |*j2                  fd¬«      dd…f   j#                  d|)z  d«      }&t        j.                  |%|&d¬«      }%t5        j6                  |,«      }-t        j.                  ||-d¬«      }|$|
dk\  |   dd…dd…f   }.t        |.«      }/|/dkD  �r6t        j(                  |dk(  «      d   }0|t-        |/«      |0f   j#                  |/d«      }1t        j.                  |1t        j0                  t        |%«      t        |%«      d|/z  z   «      j#                  |/d«      d¬«      }2|.t        j*                  t-        |/«      t-        |/«      fd¬«      t        j*                  |0j2                  |0dz   dz  j2                  fd¬«      dd…f   j#                  d|/z  d«      }'t        j.                  |%|'d¬«      }%t        j.                  ||2d¬«      }t        j                   |j#                  d«      t        |%«      d¬«      \  }}|%|   }|j#                  d«      }d}|rÅt9        t        j:                  | |   dd¬«      |&«      }3t9        t        j:                  | |   dd¬«      |'«      }4t        j<                  |3|4g«      }5t        j<                  ||   ||   g«      }6t        j>                  dt        j:                  |6dd¬«      |5«      }7t        j<                  ||7g«      |   }|||fS )aS  
    Slice a mesh (given as a set of faces and vertices) with a plane, returning a
    new mesh (again as a set of faces and vertices) that is the
    portion of the original mesh to the positive normal side of the plane.

    Parameters
    ---------
    vertices : (n, 3) float
        Vertices of source mesh to slice
    faces : (n, 3) int
        Faces of source mesh to slice
    plane_normal : (3,) float
        Normal vector of plane to intersect with mesh
    plane_origin :  (3,) float
        Point on plane to intersect with mesh
    uv : (n, 2) float, optional
        UV coordinates of source mesh to slice
    face_index : ((m,) int)
        Indexes of faces to slice. When no mask is provided, the
        default is to slice all faces.
    cached_dots : (n, 3) float
        If an external function has stored dot
        products pass them here to avoid recomputing

    Returns
    ----------
    new_vertices : (n, 3) float
        Vertices of sliced mesh
    new_faces : (n, 3) int
        Faces of sliced mesh
    new_uv : (n, 2) int or None
        UV coordinates of sliced mesh
    r   Nr   r   r,   )r   r   r-   g        )r   r   )r   r-   T)Ú	minlengthÚreturn_inverserg   r   gê-�™—q=r   z
ijk,ij->ik) r   r   rQ   r   r   r	   rR   Úsumr�   r†   ÚanyÚtmÚnormalsrM   rP   r   Úunique_bincountr1   rF   r‡   ÚwhereÚstackr   rm   Úaranger3   r   Útriangulate_quadsr
   ÚrepeatÚconcatenateÚeinsum)8r6   r5   r<   r=   Úuvrv   r[   Úhave_uvr\   r   Ú	signs_sumÚ
signs_asumÚonedgeÚinsiderœ   Úcheckr:   Ú	dot_checkÚ	new_facesr   Úcut_trianglesÚcut_faces_quadÚcut_faces_triÚcut_signs_quadÚcut_signs_triÚemptyrD   ÚinverseÚ
final_vertÚ
final_faceÚfinal_uvÚorŽ   ÚnumÚdenomÚdistÚ
int_pointsÚnew_verticesÚnew_quad_verticesÚnew_tri_verticesÚquad_int_pointsÚ	num_quadsÚquad_int_indsÚquad_int_vertsÚnew_quad_facesÚnew_tri_faces_from_quadsÚtri_int_pointsÚnum_trisÚtri_int_indsÚtri_int_vertsÚnew_tri_facesÚquad_barycentricsÚtri_barycentricsÚall_barycentricsÚcut_uvÚnew_uvs8                                                           r'   Úslice_faces_planerÙ   ›  sW  € ôV ˆ8ƒ}˜ÒØ˜ Ð"Ð"à˜ˆn€Gð ÐØ�jÑ!ˆàÐØ‰ô
 �v‰v�h Ñ-¨|Ó<ˆô �H‰H”S˜“]¬"¯'©'Ô2€EØ €Eˆ$”#—)‘)�Ñ
ÑØ €Eˆ$”—‘Ñ
ÑØ�%‰L€Eð
 —	‘	˜q¬¯©�	Ó0€IÜ—‘˜“×"Ñ"¨´·±Ð"Ó9€Jô �^‰^˜J¨!™O¬R¯V©V°IÓ->À!Ñ-CÓD€Fà˜:˜+Ñ%€Fð
 ˜Q‰€HØ‡|�|„~ô —z‘z (¨5°©?Ñ";Ó<‰ˆˆuä—F‘F˜5 ,Ó/ˆ	à ˆˆxÑà"ˆ�Ñà$ s™?ˆˆxÑð �f‘€Ið
 ˜‘€IØ˜fÑ%€MØœ2Ÿ>™>¨&°)¸a±-Ó@ÑA€NØœ"Ÿ.™.¨°¸a±Ó@ÑA€MØœ2Ÿ>™>¨&°)¸a±-Ó@ÑA€NØœ"Ÿ.™.¨°¸a±Ó@ÑA€Mô ˆ>ÓœS Ó/Ñ/°1Ò4Üˆy‹>˜QÒô —‘˜¤r§z¡zÔ2Ü—‘˜¤r§x¡xÔ0Ù6=”—‘˜¤r§z¡zÔ2ðˆEð
 ˆLð DHðˆEð
 ˆLô #×2Ñ2Ø×Ñ˜bÓ!¬S°«]È4ô
‰ˆ�ð
 ˜fÑ%ˆ
Ø—_‘_ WÓ-ˆ
Ù!(�2�f’:¨dˆà˜: xÐ/Ð/ð 	€AÜ
�‰��2˜AÔ Ñ"€AØ˜!Ñ×
 Ñ
  Ó
.€CÜ�F‰F�1�lÓ#€EØ€Eˆ%�3‰,ÑÜ�9‰9�S˜%Ó €Dà’aš˜D�jÑ! AÑ%¨Ñ)€Jð €LÜŸ™ Ó(ÐÜ—x‘x Ó'Ðð ! )¨a¡-°Ñ!8º!ºQÐ!>Ñ?€OÜ�OÓ$€IØ�1ƒ}ô Ÿ™ °1Ñ!4Ó5°aÑ8ˆØ'Ü�H‰H”e˜IÓ&¬¨iÓ(8Ð9ÀÔBÜ�H‰H�} qÑ(¨AÑ-°ÀÑ0AÀQÑ/FÐGÈaÔPðRñ
ˆô Ÿ™ØÜ�I‰I”c˜,Ó'¬¨\Ó):¸QÀ¹]Ñ)JÓK×SÑSØ˜1óð ô
ˆð ,Ü�H‰H”e˜IÓ&¬¨iÓ(8Ð9ÀÔBÜ�H‰H˜¨Ñ)¨QÑ.×1Ñ1°=·?±?ÐCÈ!ÔLÚðñ
÷ ‰'�!�i‘- Ó
#ð	 	ô —y‘y Ð/@ÀqÔIˆÜ#+×#=Ñ#=¸nÓ#MÐ Ü—I‘I˜iÐ)AÈÔJˆ	ð   ¨a¡°Ñ 8º!ºQÐ >Ñ?€NÜ�>Ó"€HØ�!ƒ|ô —x‘x °Ñ 3Ó4°QÑ7ˆØ%¤e¨H£o°|Ð&CÑD×LÑLÈXÐWXÓYˆô Ÿ	™	ØÜ�I‰I”c˜,Ó'¬¨\Ó):¸QÀ¹\Ñ)IÓJ×RÑRØ˜!óð ô
ˆð *Ü�H‰H”e˜H“o¤u¨X£Ð7¸aÔ@Ü�H‰H�l—n‘n¨°qÑ(8¸AÑ'=×&@Ñ&@ÐAÈÔJÚðñ
÷ ‰'�!�h‘, Ó
"ð	 	ô —y‘y Ð/?ÀaÔHˆÜ—I‘I˜i¨¸QÔ?ˆ	ô ×.Ñ.Ø×Ñ˜"Ó¬¨\Ó):È4ô�O€FˆGð
 ˜fÑ%€JØ—‘ Ó)€Jà€HÙä1Ü�I‰I�h˜~Ñ.°¸Ô:Ð<Mó
Ðô 1Ü�I‰I�h˜}Ñ-¨q°qÔ9Ð;Kó
Ðô Ÿ>™>Ð+<Ð>NÐ*OÓPÐô —‘  NÑ!3°R¸Ñ5FÐ GÓHˆÜ—‘˜<¬¯©°6¸1À1Ô)EÐGWÓXˆÜ—>‘> 2 v ,Ó/°Ñ7ˆà�z 8Ð+Ð+r)   c           	      ó	  — | €yddl m} ddlm} ddlm}	 ddlm}
 ddlm	} t        j                  |t        j                  ¬	«      }t        j                  |t        j                  ¬	«      }|j                  d
k(  xs t        j                  |d«      xrB |j                  d
k(  xs t        j                  |d«      xr |j                  |j                  k(  }|st!        d«      ‚| j"                  j%                  «       }| j&                  j%                  «       }t)        | j                  d«      xrA t        j                  | j                  j*                  «      t-        | j"                  «      dfk(  xr | }|r$| j                  j*                  j%                  «       nd}d|vrd|d<   t/        |j1                  d«      |j1                  d«      «      D �]s  \  }}t3        ||||||¬«      \  }}}|sŒ|rt5        d«      ‚t7        j8                  |«      \  }}||   }||   }||dd…dd…f   |dd…dd…f   k7  j;                  d¬«         }t=        j>                  || ¬«      }t        j@                  jC                  |«      }tE        jF                  ||«      }t=        jH                  |«      }|jK                  d¬«       t        jL                  |dd…df   «      dk  }|||   j;                  d¬«         }||dd…df   |dd…df   k7     }t7        jN                  |d¬«      }t-        |«      dk  r�Œ` ||«      }|g}|
jQ                  ||   |dd…dd…f   «      D ]Ó  } |	||d¬«      \  }}tE        jF                  t        jR                  |«      |«      } |jU                  | «      \  }!}"|!jW                  «       dkD  rt        jX                  j[                  d«       |"|   }#|#dd…dd…f   |#dd…dd…f   k7  j;                  d¬«      |#dd…df   |#dd…df   k7  z  }$|j]                  |#|$   «       ŒÕ t        j^                  |«      }�Œv |r, ||| j                  j`                  j%                  «       ¬«      nd}% |d|||%dœ|¤ŽS )a°  
    Slice a mesh with a plane returning a new mesh that is the
    portion of the original mesh to the positive normal side
    of the plane.

    Parameters
    ---------
    mesh : Trimesh object
      Source mesh to slice
    plane_normal : (3,) float
      Normal vector of plane to intersect with mesh
    plane_origin :  (3,) float
      Point on plane to intersect with mesh
    cap : bool
      If True, cap the result with a triangulated polygon
    face_index : ((m,) int)
      Indexes of mesh.faces to slice. When no mask is provided, the
      default is to slice all faces.
    cached_dots : (n, 3) float
      If an external function has stored dot
      products pass them here to avoid recomputing
    engine : None or str
      Triangulation engine passed to `triangulate_polygon`
    kwargs : dict
      Passed to the newly created sliced mesh

    Returns
    ----------
    new_mesh : Trimesh object
      Sliced mesh
    Nr   )ÚcKDTreer   )ÚTrimesh)Útriangulate_polygon)Úpolygons)ÚTextureVisualsr   rK   rg   z)plane origins and normals must be (n, 3)!r®   r-   ÚprocessF)r6   r5   r®   r<   r=   rv   z)face_index and cap can't be used togetherr   rd   g:Œ0âŽyE>)Úrequire_countr   T)ÚengineÚforce_verticesz%triangulate may have inserted vertex!)r®   Úmaterial)r6   r5   Úvisual© )1Úscipy.spatialrÛ   ÚbaserÜ   ÚcreationrÝ   ÚpathrÞ   rå   rß   r   rL   rM   rN   r   Úis_shaperO   r6   Úcopyr5   Úhasattrr®   r   rT   r1   rÙ   ÚNotImplementedErrorr   Úunique_rowsrG   r   ri   rj   rk   rn   ro   Úfaces_to_edgesr   r�   Ú
group_rowsÚedges_to_polygonsÚstack_3DÚqueryÚmaxÚlogÚdebugrm   rS   rä   )&rX   r<   r=   rv   Úcaprâ   ÚkwargsrÛ   rÜ   rÝ   rÞ   rß   Úshape_okr6   r5   Úhas_uvr®   re   rf   rD   r½   Úfr|   r{   Úvertices_2Dr@   rœ   Úunique_edgeÚtreeÚpÚvnÚfnÚvn3r›   ÚvidÚnfÚnf_okrå   s&                                         r'   Úslice_mesh_planer  ”  s>  € ðR €|Øõ &åÝ-ÝÝ&ô —=‘= ´R·Z±ZÔ@€LÜ—=‘= ´R·Z±ZÔ@€Lð 
×	Ñ	˜tÑ	#Ò	K¤t§}¡}°\À7Ó'Kò 	5Ø×Ñ 4Ñ'ÒO¬4¯=©=¸ÀwÓ+Oò	5à×Ñ ,×"4Ñ"4Ñ4ð ñ
 ÜÐDÓEÐEð �}‰}×!Ñ!Ó#€HØ�J‰J�O‰OÓ€Eô 	�—‘˜TÓ"ÒZ¤r§x¡x°·±·±Ó'?ÄCÈÏÉÓDVÐXYÐCZÑ'Zòàˆ'ð ñ #)ˆ�‰�‰×	Ñ	Ô	¨d€Bà˜ÑØ!ˆˆyÑô Ø×Ñ˜WÓ% |×';Ñ';¸GÓ'D÷‰ˆ�ô 0ØØØØØØ!ô
Ñˆ�%˜ò Ùä)Ð*UÓVÐVô '×2Ñ2°8Ó<‰OˆF�GØ Ñ'ˆHà˜‘ˆAð �1’Q˜˜˜�U‘8˜q¢ A¡B ™xÑ'×,Ñ,°!Ð,Ó4Ñ5ˆAä×,Ñ,°FÀFÀ7ÔKˆEÜ—I‘I—M‘M %Ó(ˆEä×-Ñ-¨h¸Ó>ˆKÜ×+Ñ+¨AÓ.ˆEØ�J‰J˜AˆJÔä—v‘v˜kª!¨Q¨$Ñ/Ó0°4Ñ7ˆHØ˜( 5™/×-Ñ-°1Ð-Ó5Ñ6ˆEØ˜%¢ 1 ™+¨ªq°!¨t©Ñ4Ñ5ˆEä"×-Ñ-¨eÀ1ÔEˆKÜ�6‹{˜QŠÙá˜8Ó$ˆDà�CˆEØ×/Ñ/°°kÑ0BÀKÒPQÐSUÐTUÐSUÐPUÑDVÖW�á,¨Q°vÈdÔS‘��Bä×)Ñ)¬$¯-©-¸Ó*;¸UÓC�Ø $§
¡
¨3£‘�˜#Ø—<‘<“> DÒ(Ü—H‘H—N‘NÐ#JÔKà˜‘W�àšA˜q™r˜E™ bª¨B¨Q¨B¨¡iÑ/×4Ñ4¸!Ð4Ó<ÀÂ1ÀaÀ4ÁÈBÊqÐRSÈtÉHÑ@TÑU�Ø—‘˜R ™YÕ'ð Xô —I‘I˜eÓ$ŠEðwñ| HN‰˜" t§{¡{×';Ñ';×'@Ñ'@Ó'BÕCÐSWð ñ
 ÐK˜H¨E¸&ÑKÀFÑKÐKr)   )FNN)T)FF)NNN)NFN)Ú__doc__Únumpyr   Ú r   r   r   r   rn   r   r¤   Ú	constantsr	   r
   rb   r~   r2   rž   rÙ   r  ræ   r)   r'   Ú<module>r     ss   ðñó ç &Ñ &Ý #Ý Ý Ý ,ð ØØózòzT,ón0ðp Øó@ðP ØØóv,ðz ØØôQLr)   