Performance improvement for triangulation

This commit is contained in:
Grant Sanderson 2021-02-02 16:19:45 -08:00
parent 1097f0df96
commit 2fbe0c6ee6

View file

@ -366,16 +366,22 @@ def earclip_triangulation(verts, rings):
# Find the closet pair of points with the first # Find the closet pair of points with the first
# from the current ring, and the second from the # from the current ring, and the second from the
# next ring # next ring
index_pairs = [ filtered_i, filtered_j = [
(i, j) list(filter(
for i in range(0, end0) lambda i: i not in loop_connections,
for j in range(end0, end1) indices
if i not in loop_connections ))
if j not in loop_connections for indices in (range(0, end0), range(end0, end1))
] ]
i, j = index_pairs[np.argmin([
norm_squared(verts[i] - verts[j]) i = filtered_i[np.argmin([
for i, j in index_pairs # It's slightly faster to use L-infinity norm
max(abs(verts[i] - verts[end0]))
for i in filtered_i
])]
j = filtered_j[np.argmin([
max(abs(verts[i] - verts[j]))
for j in filtered_j
])] ])]
# Connect the polygon at these points so that # Connect the polygon at these points so that