Skip to content

Commit 175a442

Browse files
add Mesh.to_lines() function
1 parent e3c7f00 commit 175a442

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/compas/datastructures/mesh/mesh.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,15 @@ def from_lines(cls, lines, delete_boundary_face=False, precision=None):
377377
return mesh
378378

379379
def to_lines(self):
380-
"""Convert the mesh to a collection of lines.
380+
"""Return the lines of the mesh as pairs of start and end point coordinates.
381381
382382
Returns
383383
-------
384384
list[tuple[list[float], list[float]]]
385-
A list of lines each defined by a pair of points.
385+
A list of lines each defined by a pair of point coordinates.
386386
387387
"""
388-
raise NotImplementedError
388+
return [self.edge_coordinates(u, v) for u, v in self.edges()]
389389

390390
@classmethod
391391
def from_polylines(cls, boundary_polylines, other_polylines):

src/compas/datastructures/network/network.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def from_pointcloud(cls, cloud, degree=3):
221221
Returns
222222
-------
223223
:class:`~compas.datastructures.Network`
224+
A network object.
224225
225226
"""
226227
network = cls()
@@ -256,6 +257,7 @@ def to_points(self):
256257
Returns
257258
-------
258259
list[list[float]]
260+
A list with the coordinates of the vertices of the network.
259261
260262
"""
261263
return [self.node_coordinates(key) for key in self.nodes()]
@@ -266,6 +268,7 @@ def to_lines(self):
266268
Returns
267269
-------
268270
list[tuple[list[float], list[float]]]
271+
A list of lines each defined by a pair of point coordinates.
269272
270273
"""
271274
return [self.edge_coordinates(u, v) for u, v in self.edges()]

tests/compas/datastructures/test_mesh.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ def test_to_vertices_and_faces_triangulated():
203203
assert len(vertices) == 32
204204
assert len(faces) == 60
205205

206+
207+
def test_to_lines():
208+
lines = compas.json_load(compas.get('lines.json'))
209+
mesh = Mesh.from_lines(lines)
210+
lines = mesh.to_lines()
211+
assert len(lines) == mesh.number_of_edges()
212+
213+
206214
# --------------------------------------------------------------------------
207215
# helpers
208216
# --------------------------------------------------------------------------

0 commit comments

Comments
 (0)