# Python list operation – merge adjacent cubes into minimum number of shapes

I am hoping to find a way to make the process a lot faster. The lists are made of rows of 6 numbers, i.e. [[float] * 6, …]. The intent is to pass a list of cube co-ordinates (only two 3D co-ordinates, which are opposite corners) and get a shorter list of co-ordinates of 3D quadrilaterals.

``# 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] - css[j]) == abs(css[j] - qbs[i])             and css[j] == qbs[i]             and css[j] == qbs[i]             # if true up to here then corners are touching             # below we check if the faces match (same size)             and abs(css[j] - css[j]) == abs(qbs[i] - qbs[i])             and abs(css[j] - css[j]) == abs(qbs[i] - qbs[i])):                 css[j] = [css[j],css[j],css[j],                 qbs[i],qbs[i],qbs[i]]                 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 ``
Posted on Categories buy elite proxies