Skip to content

Commit 3f2f924

Browse files
committed
polygon centroid
1 parent e80f3db commit 3f2f924

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/compas_rhino/utilities/drawing.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import compas_rhino
88

99
from compas.geometry import centroid_polygon
10-
from compas.geometry import centroid_points
1110
from compas.utilities import pairwise
1211

1312
from compas_rhino.utilities import create_layers_from_path
@@ -792,7 +791,7 @@ def draw_mesh(vertices, faces, name=None, color=None, disjoint=False, **kwargs):
792791
else:
793792
if MeshNgon:
794793
points = [vertices[vertex] for vertex in face]
795-
centroid = centroid_points(points)
794+
centroid = centroid_polygon(points)
796795
indices = []
797796
for point in points:
798797
indices.append(mesh.Vertices.Add(* point))
@@ -815,7 +814,7 @@ def draw_mesh(vertices, faces, name=None, color=None, disjoint=False, **kwargs):
815814
mesh.Faces.AddFace(*face)
816815
else:
817816
if MeshNgon:
818-
centroid = centroid_points([vertices[index] for index in face])
817+
centroid = centroid_polygon([vertices[index] for index in face])
819818
c = mesh.Vertices.Add(* centroid)
820819
facets = []
821820
for i, j in pairwise(face + face[:1]):
@@ -878,18 +877,18 @@ def draw_faces(faces, **kwargs):
878877

879878
if v < 3:
880879
continue
881-
if v == 3:
880+
elif v == 3:
882881
mfaces = [[0, 1, 2, 2]]
882+
elif v == 4:
883+
mfaces = [[0, 1, 2, 3]]
883884
else:
884-
mfaces = [list(range(v))]
885-
# else:
886-
# mfaces = _face_to_max_quad(points, range(v))
887-
# if vertexcolors:
888-
# r, g, b = [sum(component) / v for component in zip(*vertexcolors)]
889-
# r = int(min(max(0, r), 255))
890-
# g = int(min(max(0, g), 255))
891-
# b = int(min(max(0, b), 255))
892-
# vertexcolors.append((r, g, b))
885+
mfaces = _face_to_max_quad(points, range(v))
886+
if vertexcolors:
887+
r, g, b = [sum(component) / v for component in zip(*vertexcolors)]
888+
r = int(min(max(0, r), 255))
889+
g = int(min(max(0, g), 255))
890+
b = int(min(max(0, b), 255))
891+
vertexcolors.append((r, g, b))
893892

894893
guid = draw_mesh(points, mfaces, color=color, name=name, clear=False, redraw=False, layer=None)
895894

0 commit comments

Comments
 (0)