/
combinatorics.py
76 lines (56 loc) · 1.69 KB
/
combinatorics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
from compas.topology import breadth_first_traverse
__all__ = [
'mesh_is_connected'
]
def mesh_is_connected(mesh):
"""Verify that the mesh is connected.
Parameters
----------
mesh : compas.datastructures.Mesh
A mesh data structure.
Returns
-------
bool
True, if the mesh is connected.
False, otherwise.
Notes
-----
A mesh is connected if for every two vertices a path exists connecting them.
Examples
--------
>>> mesh_is_connected(m1)
True
>>> mesh_is_connected(m2)
True
>>> mesh_is_connected(m3)
False
"""
if not mesh.vertex:
return False
nodes = breadth_first_traverse(mesh.adjacency, mesh.get_any_vertex())
return len(nodes) == mesh.number_of_vertices()
# ==============================================================================
# Main
# ==============================================================================
if __name__ == "__main__":
import doctest
import compas
from compas.datastructures import Mesh
from compas.datastructures import meshes_join
from compas.geometry import translate_points_xy
m1 = Mesh.from_obj(compas.get('faces.obj'))
m2 = m1.copy()
points = m2.get_vertices_attributes('xyz')
x, y, z = zip(*points)
xmin = min(x)
xmax = max(x)
points = translate_points_xy(points, [1.5 * (xmax - xmin), 0, 0])
for key, attr in m2.vertices(True):
attr['x'] = points[key][0]
attr['y'] = points[key][1]
attr['z'] = points[key][2]
m3 = meshes_join([m1, m2])
doctest.testmod()