Операция, описанная в комментарии к коду, занимает слишком много времени, как я ее реализовал. Как я могу оптимизировать процесс? Списки состоят из строк из 6 чисел, то есть [[float] * 6, ...]. Числа являются противоположными углами каждого куба в формате [x1, x2, y1, y2, z1, z2].
# Merging by creating a list with the first cube and another with the rest.
# If the cube in the first list can be merged with a cube in the second list,
# the cube in the second list is removed and the cube in the first list is
# replaced with the merged shape.
# If there is no suitable merge to be done, the lowest positioned cube in
# the second list is moved to the first list and then we check if
# anything in the second list can be merged with it and so on.
# loops until qbs has been emptied into css
# the condition for merging is matching faces
def xmerge(qbs, css):
tot = len(qbs)
j = 0
while len(qbs) > 0:
i = 0
k = 0
printProgressBar(tot - len(qbs)+1, tot, prefix = ' Merging along x:',
length = 50)
while i < len(qbs):
# first check if faces are touching
if (abs(css[j][0] - css[j][3]) == abs(css[j][0] - qbs[i][0])
and css[j][1] == qbs[i][1]
and css[j][2] == qbs[i][2]
# if true up to here then corners are touching
# below we check if the faces match (same size)
and abs(css[j][1] - css[j][4]) == abs(qbs[i][1] - qbs[i][4])
and abs(css[j][2] - css[j][5]) == abs(qbs[i][2] - qbs[i][5])):
css[j] = [css[j][0],css[j][1],css[j][2],
qbs[i][3],qbs[i][4],qbs[i][5]]
qbs = np.delete(qbs, i, axis=0)
k = 1
i += 1
if k == 0:
css = np.vstack([css, qbs[np.argmin(qbs[:,0])]])
qbs = np.delete(qbs, np.argmin(qbs[:,0]), axis=0)
j += 1
print("")
return css