Fix error after refactor, added comments

This commit is contained in:
Jack Ha 2017-04-04 09:52:07 +02:00
parent 1ebf947ff2
commit 1df9066340
3 changed files with 12 additions and 7 deletions

View file

@ -58,8 +58,10 @@ class Arrange:
for i in range(count): for i in range(count):
new_node = copy.deepcopy(node) new_node = copy.deepcopy(node)
x, y = self.bestSpot( best_spot = self.bestSpot(
offset_shape_arr, start_prio = start_prio, step = step) offset_shape_arr, start_prio = start_prio, step = step)
x, y = best_spot.x, best_spot.y
start_prio = best_spot.priority
transformation = new_node._transformation transformation = new_node._transformation
if x is not None: # We could find a place if x is not None: # We could find a place
transformation._data[0][3] = x transformation._data[0][3] = x

View file

@ -1031,20 +1031,24 @@ class CuraApplication(QtApplication):
min_offset = 8 min_offset = 8
arranger = Arrange.create(fixed_nodes = fixed_nodes) arranger = Arrange.create(fixed_nodes = fixed_nodes)
# Collect nodes to be placed
nodes_arr = [] # fill with (size, node, offset_shape_arr, hull_shape_arr) nodes_arr = [] # fill with (size, node, offset_shape_arr, hull_shape_arr)
for node in nodes: for node in nodes:
offset_shape_arr, hull_shape_arr = ShapeArray.fromNode(node, min_offset = min_offset) offset_shape_arr, hull_shape_arr = ShapeArray.fromNode(node, min_offset = min_offset)
nodes_arr.append((offset_shape_arr.arr.shape[0] * offset_shape_arr.arr.shape[1], node, offset_shape_arr, hull_shape_arr)) nodes_arr.append((offset_shape_arr.arr.shape[0] * offset_shape_arr.arr.shape[1], node, offset_shape_arr, hull_shape_arr))
# Sort nodes biggest area first
nodes_arr.sort(key = lambda item: item[0]) nodes_arr.sort(key = lambda item: item[0])
nodes_arr.reverse() nodes_arr.reverse()
# Place nodes one at a time
start_prio = 0 start_prio = 0
for size, node, offset_shape_arr, hull_shape_arr in nodes_arr: for size, node, offset_shape_arr, hull_shape_arr in nodes_arr:
# we assume that when a location does not fit, it will also not fit for the next # For performance reasons, we assume that when a location does not fit,
# object (while what can be untrue). That saves a lot of time. # it will also not fit for the next object (while what can be untrue).
best_spot = arranger.bestSpot( # We also skip possibilities by slicing through the possibilities (step = 10)
offset_shape_arr, start_prio = start_prio) best_spot = arranger.bestSpot(offset_shape_arr, start_prio = start_prio, step = 10)
x, y = best_spot.x, best_spot.y x, y = best_spot.x, best_spot.y
start_prio = best_spot.priority start_prio = best_spot.priority
if x is not None: # We could find a place if x is not None: # We could find a place

View file

@ -31,10 +31,9 @@ class ShapeArray:
arr = cls.arrayFromPolygon(shape, flip_vertices) arr = cls.arrayFromPolygon(shape, flip_vertices)
return cls(arr, offset_x, offset_y) return cls(arr, offset_x, offset_y)
## Return an offset and hull ShapeArray from a scenenode. ## Return an offset and hull ShapeArray from a scene node.
@classmethod @classmethod
def fromNode(cls, node, min_offset, scale = 0.5): def fromNode(cls, node, min_offset, scale = 0.5):
# hacky way to undo transformation
transform = node._transformation transform = node._transformation
transform_x = transform._data[0][3] transform_x = transform._data[0][3]
transform_y = transform._data[2][3] transform_y = transform._data[2][3]