Skip to content

Commit 0622e21

Browse files
add test to_point methods and test functions
1 parent c3fc48c commit 0622e21

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

src/compas/datastructures/cell_network/cell_network.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,17 @@ def faces_to_mesh(self, faces, data=False):
11711171
mesh.add_face(vertices, fkey=fkey)
11721172
return mesh
11731173

1174+
def vertices_to_points(self):
1175+
"""Convert the vertices of the cell network to a collection of points.
1176+
1177+
Returns
1178+
-------
1179+
list[list[float]]
1180+
The points representing the vertices of the cell network.
1181+
1182+
"""
1183+
return [self.vertex_coordinates(vertex) for vertex in self.vertices()]
1184+
11741185
# --------------------------------------------------------------------------
11751186
# General
11761187
# --------------------------------------------------------------------------

src/compas/datastructures/volmesh/volmesh.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,17 @@ def to_vertices_and_cells(self):
559559
cells.append(faces)
560560
return vertices, cells
561561

562+
def to_points(self):
563+
"""Convert the volmesh to a collection of points.
564+
565+
Returns
566+
-------
567+
list[float[float]]
568+
The points representing the vertices of the volmesh.
569+
570+
"""
571+
return [self.vertex_coordinates(vertex) for vertex in self.vertices()]
572+
562573
def cell_to_mesh(self, cell):
563574
# type: (int) -> Mesh
564575
"""Construct a mesh object from from a cell of a volmesh.

tests/compas/datastructures/test_cell_network.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,14 @@ def test_cell_network_boundary(example_cell_network):
8383
assert set(ds.faces_without_cell()) == {11}
8484
assert set(ds.edges_without_face()) == {(15, 13), (14, 12)}
8585
assert set(ds.nonmanifold_edges()) == {(6, 7), (4, 5), (5, 6), (7, 4)}
86+
87+
88+
# ==============================================================================
89+
# Conversion
90+
# ==============================================================================
91+
92+
93+
def test_vertices_to_points(example_cell_network):
94+
ds = example_cell_network
95+
points = ds.vertices_to_points()
96+
assert len(points) == ds.number_of_vertices()

tests/compas/datastructures/test_graph.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,20 @@ def test_graph_to_networkx():
276276
# assert g2.attributes["val"] == (0, 0, 0), "Graph attributes must be preserved"
277277

278278

279+
@pytest.mark.parametrize(
280+
"filepath",
281+
[
282+
compas.get("lines.obj"),
283+
compas.get("grid_irregular.obj"),
284+
],
285+
)
286+
def test_to_points(filepath):
287+
graph = Graph.from_obj(filepath)
288+
points = graph.to_points()
289+
290+
assert len(points) == graph.number_of_nodes(), "Number of points must match number of nodes"
291+
292+
279293
# ==============================================================================
280294
# Methods
281295
# ==============================================================================

tests/compas/datastructures/test_volmesh.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,13 @@ def test_cells_where_predicate():
346346
# Conversion
347347
# ==============================================================================
348348

349+
350+
def test_to_points():
351+
vmesh = VolMesh.from_obj(compas.get("boxes.obj"))
352+
points = vmesh.to_points()
353+
assert len(points) == 27
354+
355+
349356
# ==============================================================================
350357
# Methods
351358
# ==============================================================================

0 commit comments

Comments
 (0)