@@ -260,6 +260,51 @@ def get_any_face_vertex(self, fkey):
260260 """
261261 return self .face_vertices (fkey )[0 ]
262262
263+ def vertex_sample (self , size = 1 ):
264+ """A random sample of the vertices.
265+
266+ Parameters
267+ ----------
268+ size : int, optional
269+ The number of vertices in the random sample.
270+
271+ Returns
272+ -------
273+ list
274+ The identifiers of the vertices.
275+ """
276+ return sample (list (self .vertices ()), size )
277+
278+ def edge_sample (self , size = 1 ):
279+ """A random sample of the edges.
280+
281+ Parameters
282+ ----------
283+ size : int, optional
284+ The number of edges in the random sample.
285+
286+ Returns
287+ -------
288+ list
289+ The identifiers of the edges.
290+ """
291+ return sample (list (self .edges ()), size )
292+
293+ def face_sample (self , size = 1 ):
294+ """A random sample of the faces.
295+
296+ Parameters
297+ ----------
298+ size : int, optional
299+ The number of faces in the random sample.
300+
301+ Returns
302+ -------
303+ list
304+ The identifiers of the faces.
305+ """
306+ return sample (list (self .faces ()), size )
307+
263308 def key_index (self ):
264309 """Returns a dictionary that maps vertex dictionary keys to the
265310 corresponding index in a vertex list or array.
@@ -2471,10 +2516,27 @@ def is_face_on_boundary(self, key):
24712516
24722517 def halfedge_after (self , u , v ):
24732518 face = self .halfedge_face (u , v )
2474- w = self .face_vertex_after (face , v )
2519+ if face is not None :
2520+ w = self .face_vertex_after (face , v )
2521+ return v , w
2522+ nbrs = self .vertex_neighbors (u , ordered = True )
2523+ w = nbrs [0 ]
24752524 return v , w
24762525
24772526 def halfedge_before (self , u , v ):
24782527 face = self .halfedge_face (u , v )
2479- t = self .face_vertex_before (face , u )
2528+ if face is not None :
2529+ t = self .face_vertex_before (face , u )
2530+ return t , u
2531+ nbrs = self .vertex_neighbors (u , ordered = True )
2532+ t = nbrs [- 1 ]
24802533 return t , u
2534+
2535+ def vertex_edges (self , vertex ):
2536+ edges = []
2537+ for nbr in self .vertex_neighbors (vertex ):
2538+ if self .has_edge ((vertex , nbr )):
2539+ edges .append ((vertex , nbr ))
2540+ else :
2541+ edges .append ((nbr , vertex ))
2542+ return edges
0 commit comments