Skip to content

Commit 516ac1c

Browse files
committed
explicit check for sequence is not a good idea as it excludes many other iterable types such as numpy arrays
1 parent 2e25b9f commit 516ac1c

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/compas/datastructures/mesh/_mesh.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,11 @@ def from_vertices_and_faces(cls, vertices, faces):
621621
Parameters
622622
----------
623623
vertices : list, dict
624-
A list of vertices, represented by their XYZ coordinates, or a dictionary of vertex keys pointing to their XYZ coordinates.
624+
A list of vertices, represented by their XYZ coordinates,
625+
or a dictionary of vertex keys pointing to their XYZ coordinates.
625626
faces : list, dict
626-
A list of faces, represented by a list of indices referencing the list of vertex coordinates, or a dictionary of face keys pointing to a list of indices referencing the list of vertex coordinates.
627+
A list of faces, represented by a list of indices referencing the list of vertex coordinates,
628+
or a dictionary of face keys pointing to a list of indices referencing the list of vertex coordinates.
627629
628630
Returns
629631
-------
@@ -645,19 +647,19 @@ def from_vertices_and_faces(cls, vertices, faces):
645647
"""
646648
mesh = cls()
647649

648-
if isinstance(vertices, collections.Sequence):
649-
for x, y, z in iter(vertices):
650-
mesh.add_vertex(x=x, y=y, z=z)
651-
elif isinstance(vertices, collections.Mapping):
650+
if isinstance(vertices, collections.Mapping):
652651
for key, xyz in vertices.items():
653652
mesh.add_vertex(key = key, attr_dict = {i: j for i, j in zip(['x', 'y', 'z'], xyz)})
654-
655-
if isinstance(faces, collections.Sequence):
656-
for face in iter(faces):
657-
mesh.add_face(face)
658-
elif isinstance(faces, collections.Mapping):
653+
else:
654+
for x, y, z in iter(vertices):
655+
mesh.add_vertex(x=x, y=y, z=z)
656+
657+
if isinstance(faces, collections.Mapping):
659658
for fkey, vertices in faces.items():
660659
mesh.add_face(vertices, fkey)
660+
else:
661+
for face in iter(faces):
662+
mesh.add_face(face)
661663

662664
return mesh
663665

@@ -2310,7 +2312,7 @@ def face_adjacency_vertices(self, f1, f2):
23102312
If the faces are not adjacent.
23112313
23122314
"""
2313-
2315+
23142316
return [vkey for vkey in self.face_vertices(f1) if vkey in self.face_vertices(f2)]
23152317

23162318
def is_face_on_boundary(self, key):
@@ -2362,7 +2364,7 @@ def centroid(self):
23622364
list
23632365
The coordinates of the mesh centroid.
23642366
"""
2365-
2367+
23662368
return scale_vector(sum_vectors([scale_vector(self.face_centroid(fkey), self.face_area(fkey)) for fkey in self.faces()]), 1. / self.area())
23672369

23682370
def normal(self):
@@ -2671,7 +2673,7 @@ def face_aspect_ratio(self, fkey):
26712673
-------
26722674
float
26732675
The aspect ratio.
2674-
2676+
26752677
References
26762678
----------
26772679
.. [1] Wikipedia. *Types of mesh*.
@@ -2694,7 +2696,7 @@ def face_skewness(self, fkey):
26942696
-------
26952697
float
26962698
The skewness.
2697-
2699+
26982700
References
26992701
----------
27002702
.. [1] Wikipedia. *Types of mesh*.
@@ -2703,7 +2705,7 @@ def face_skewness(self, fkey):
27032705
"""
27042706

27052707
ideal_angle = 180 * (1 - 2 / float(len(self.face_vertices(fkey))))
2706-
2708+
27072709
angles = [angle_points(self.vertex_coordinates(v), self.vertex_coordinates(u), self.vertex_coordinates(w), deg = True) for u, v, w in window(self.face_vertices(fkey) + self.face_vertices(fkey)[:2], n = 3)]
27082710

27092711
return max((max(angles) - ideal_angle) / (180 - ideal_angle), (ideal_angle - min(angles)) / ideal_angle)
@@ -3168,7 +3170,7 @@ def plot(self,
31683170
from compas.plotters import MeshPlotter
31693171

31703172
mesh = Mesh.from_obj(compas.get('faces.obj'))
3171-
3173+
31723174
mesh.update_default_edge_attributes({'q': 1.0})
31733175

31743176
# vertices = [

0 commit comments

Comments
 (0)