Ë
    :vžjõ  ã                   ó®   — d Z ddlZddlmZ ddlmZ 	 ddlmZ d„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Zy# e$ r"Z	ddlm
Z
  e
j                  e	«      ZY dZ	[	Œ5dZ	[	ww xY w)z5
curvature.py
---------------

Query mesh curvature.
é    Né   )Úutil)Údiagonal_dot)Ú
coo_matrix)Ú
exceptionsc                 óÎ   — t        | j                  j                  «       | j                  j                  | j                  j
                  ff| j                  j                  «      }|S )z¶
    A sparse matrix representation of the face angles.

    Returns
    ----------
    sparse : scipy.sparse.coo_matrix
      matrix is float shaped (len(vertices), len(faces))
    )r   Úface_anglesÚflattenÚfaces_sparseÚrowÚcolÚshape)ÚmeshÚmatrixs     úb/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/trimesh/curvature.pyÚface_angles_sparser      sX   € ô Ø	×	Ñ	×	!Ñ	!Ó	# d×&7Ñ&7×&;Ñ&;¸T×=NÑ=N×=RÑ=RÐ%SÐTØ×Ñ×Ñó€Fð €Mó    c                 ó¬   — t        j                  | j                  j                  d¬«      «      j	                  «       }dt         j
                  z  |z
  }|S )aˆ  
    Return the vertex defects, or (2*pi) minus the sum of the
    angles of every face that includes that vertex.

    If a vertex is only included by coplanar triangles, this
    will be zero. For convex regions this is positive, and
    concave negative.

    Returns
    --------
    vertex_defect : (len(self.vertices), ) float
                     Vertex defect at the every vertex
    r   )Úaxisé   )ÚnpÚarrayr   Úsumr
   Úpi)r   Ú	angle_sumÚdefects      r   Úvertex_defectsr   %   sF   € ô —‘˜×0Ñ0×4Ñ4¸!Ð4Ó<Ó=×EÑEÓG€IØ”"—%‘%‰i˜9Ñ$€FØ€Mr   c                 óN  — t        j                  |t         j                  ¬«      }t        j                  |d«      st        d«      ‚| j                  j                  ||«      }|D �cg c]  }| j                  |   j                  «       ‘Œ! }}t        j                  |«      S c c}w )a>  
    Return the discrete gaussian curvature measure of a sphere
    centered at a point as detailed in 'Restricted Delaunay
    triangulations and normal cycle'- Cohen-Steiner and Morvan.

    This is the sum of the vertex defects at all vertices
    within the radius for each point.

    Parameters
    ----------
    points : (n, 3) float
      Points in space
    radius : float ,
      The sphere radius, which can be zero if vertices
      passed are points.

    Returns
    --------
    gaussian_curvature:  (n,) float
      Discrete gaussian curvature measure.
    ©Údtype©éÿÿÿÿé   úpoints must be (n,3)!)r   Ú
asanyarrayÚfloat64r   Úis_shapeÚ
ValueErrorÚkdtreeÚquery_ball_pointr   r   Úasarray)r   ÚpointsÚradiusÚnearestÚverticesÚ
gauss_curvs         r   Ú#discrete_gaussian_curvature_measurer1   8   s…   € ô. �]‰]˜6¬¯©Ô4€FÜ�=‰=˜ Ô)ÜÐ0Ó1Ð1à�k‰k×*Ñ*¨6°6Ó:€GÙFMÓNÁg¸(�$×%Ñ% hÑ/×3Ñ3Õ5Àg€JÐNä�:‰:�jÓ!Ð!ùò Os   Á'$B"c           	      ó¼  — t        j                  |t         j                  ¬«      }t        j                  |d«      st        d«      ‚t        j                  | j                  «      }t        j                  | j                  «      }t        j                  | j                  «      }t        j                  | j                  «      }| j                  }||z
  }||z   }		 |j                  ||	«      \  }
}t        j                  |
t         j                  ¬«      }t        j                  |t         j                  ¬«      }t'        |«      dk(  rt        j.                  t'        |«      «      S t        j0                  t        j2                  t'        |«      «      |«      }|||      }t5        |dd…df   |dd…df   ||   |¬	«      }t        j6                  ||   dd
«      }t        j8                  ||||   z  |z  t'        |«      ¬«      dz  S # t        $ rÌ t        j                  ||	f«      D �cg c]  }t!        |j#                  |«      «      ‘Œ nc c}w }}t        j$                  |D �cg c]  }t'        |«      ‘Œ nc c}w c}t         j                  ¬«      }t        j(                  d„ |D «       t         j                  t+        |j-                  «       «      ¬«      }Y �Œ¡w xY w)a  
    Return the discrete mean curvature measure of a sphere
    centered at a point as detailed in 'Restricted Delaunay
    triangulations and normal cycle'- Cohen-Steiner and Morvan.

    This is the sum of the angle at all edges contained in the
    sphere for each point.

    Parameters
    ----------
    points : (n, 3) float
      Points in space
    radius : float
      Sphere radius which should typically be greater than zero

    Returns
    --------
    mean_curvature : (n,) float
      Discrete mean curvature measure.
    r   r!   r$   c              3   ó.   K  — | ]  }|D ]  }|–— Œ Œ y ­w)N© )Ú.0ÚcÚis      r   Ú	<genexpr>z2discrete_mean_curvature_measure.<locals>.<genexpr>ˆ   s   è ø€ Ð-™	�1«1 aŒQ¨1ˆQ™	ùs   ‚)r    Úcountr   Nr   )Úcenterr-   r"   )ÚweightsÚ	minlengthr   )r   r%   r&   r   r'   r(   r+   r/   Úface_adjacency_edgesÚface_adjacency_anglesÚface_adjacency_convexÚface_adjacency_treeÚintersection_vÚint64ÚBaseExceptionÚcolumn_stackÚlistÚintersectionr   ÚlenÚfromiterÚintr   ÚzerosÚrepeatÚarangeÚline_ball_intersectionÚwhereÚbincount)r   r,   r-   r/   Úadjacency_edgesÚadjacency_anglesÚadjacency_convexÚtreeÚminsÚmaxsÚhit_idsÚ
hit_countsÚ
candidatesÚcountsÚbÚ	per_pointr6   ÚownerÚ	endpointsÚlengthsÚsignss                        r   Údiscrete_mean_curvature_measurer`   Y   sI  € ô, �]‰]˜6¬¯©Ô4€FÜ�=‰=˜ Ô)ÜÐ0Ó1Ð1ô �z‰z˜$Ÿ-™-Ó(€HÜ—j‘j ×!:Ñ!:Ó;€OÜ—z‘z $×"<Ñ"<Ó=ÐÜ—z‘z $×"<Ñ"<Ó=Ðà×#Ñ#€Dà�F‰?€DØ�F‰?€Dð
à"×1Ñ1°$¸Ó=Ñˆ�Ü—Z‘Z ¬r¯x©xÔ8ˆ
Ü—‘˜J¬b¯h©hÔ7ˆô ˆ:ƒ˜!ÒÜ�x‰xœ˜F›Ó$Ð$ô �I‰I”b—i‘i¤ F£Ó,¨fÓ5€EØ˜¨Ñ4Ñ5€Iô %Ø’!�Q�$‰˜¢1 a 4™°¸±Àvô€Gô �H‰HÐ% jÑ1°1°bÓ9€Eô 	�‰ØØÐ.¨zÑ:Ñ:¸UÑBÜ˜&“kô	
ð
 ñ	ðøô- ò 
ä9;¿¹È$ÐPTÈÔ9VÓWÑ9V°A”T˜$×+Ñ+¨AÓ.Õ/Ñ9VùÒWˆ	ÐWÜ—‘©9Ó5©9 aœ3˜q�6©9ùÔ5¼R¿X¹XÔFˆÜ—[‘[Ù-™	Ó-´R·X±XÄSÈÏÉËÓEVô
‹
ð	
ús,   ÃAH È"KÈ(!I
É	KÉ$I7
É6A!KËKc                 ó   — || z
  }| |z
  }|}t        ||«      }t        ||«      }t        ||«      }	|dz  ||	|dz  z
  z  z
  }
t        j                  t        | «      «      }|
dkD  }||    t        j                  |
|   «      z
  ||   z  }||    t        j                  |
|   «      z   ||   z  }t        j
                  |dd«      }t        j
                  |dd«      }||z
  t        j                  ||   «      z  ||<   |S )a|  
    Compute the length of the intersection of a line segment with a ball.

    Parameters
    ----------
    start_points : (n,3) float, list of points in space
    end_points   : (n,3) float, list of points in space
    center       : (3,) float, the sphere center
    radius       : float, the sphere radius

    Returns
    --------
    lengths: (n,) float, the lengths.

    r   r   r   )r   r   rJ   rG   ÚsqrtÚclip)Ústart_pointsÚ
end_pointsr:   r-   ÚLÚocÚrÚldotlÚldotocÚocdotocÚdiscrimsr^   ÚmÚd1Úd2s                  r   rM   rM   £   s  € ð( 	�\Ñ!€AØ	˜Ñ	€BØ€AÜ˜˜AÓ€EÜ˜!˜RÓ €FÜ˜2˜rÓ"€GØ�q‰y˜5 G¨a°©d¡NÑ3Ñ3€Hô �h‰h”s˜<Ó(Ó)€Gà�1‰€AØ�!‰9ˆ*”r—w‘w˜x¨™{Ó+Ñ
+¨u°Q©xÑ	7€BØ�!‰9ˆ*”r—w‘w˜x¨™{Ó+Ñ
+¨u°Q©xÑ	7€Bô 
�‰��Q˜Ó	€BÜ	�‰��Q˜Ó	€Bð �r‘'œRŸW™W U¨1¡XÓ.Ñ.€GˆA�Jà€Nr   c                 ó®   — d| dz  z  |dz  z
  d| z  z  }||  k\  rdt         j                  z  | z  | |z
  z  S ||  k  rdt         j                  z  | dz  z  S y)a(  
    Compute the surface area of the intersection of sphere of radius R centered
    at (0, 0, 0) with a ball of radius r centered at (R, 0, 0).

    Parameters
    ----------
    R : float, sphere radius
    r : float, ball radius

    Returns
    --------
    area: float, the surface are.
    r   é   N)r   r   )ÚRrh   Úxs      r   Úsphere_ball_intersectionrt   Ð   sk   € ð 
ˆQ�‰T‰�A�q‘D‰˜Q ™UÑ#€AØˆQˆB‚wØ”2—5‘5‰y˜1‰}  A¡Ñ&Ð&ØˆAˆ2‚vØ”2—5‘5‰y˜1˜a™4ÑÐð r   )Ú__doc__Únumpyr   Ú r   r   Úscipy.sparser   ÚImportErrorÚEr   ÚExceptionWrapperr   r   r1   r`   rM   rt   r4   r   r   Ú<module>r|      sg   ðñó å Ý ð0Ý'òò ò&"òBGòT*óZ øðC ò 0Ýà,�×,Ñ,¨QÓ/…Jûð0ús   ”- ­A²AÁA