Node Wrangler: Improved accuracy on Align Nodes operator #104551
@ -2373,7 +2373,11 @@ class NWAlignNodes(Operator, NWBase):
|
|||||||
margin_x, margin_y = prefs.align_nodes_margin
|
margin_x, margin_y = prefs.align_nodes_margin
|
||||||
|
|
||||||
# Somehow hidden nodes would come out 10 units higher that non-hidden nodes when aligned, so this offset has to exist
|
# Somehow hidden nodes would come out 10 units higher that non-hidden nodes when aligned, so this offset has to exist
|
||||||
weird_offset = 10
|
weird_offset = 10
|
||||||
|
|
||||||
|
# node.dimensions for reroutes indicate (16.0, 16.0) but using that in calculations puts reroutes off-center
|
||||||
|
# At least on a purely visual basis, the dimensions of a reroute node seem to be closer to 10 units. (At least for 1.0 unit scale)
|
||||||
|
reroute_width = 10
|
||||||
|
|
||||||
with temporary_unframe(nodes=selection):
|
with temporary_unframe(nodes=selection):
|
||||||
active_loc = None
|
active_loc = None
|
||||||
@ -2390,10 +2394,6 @@ class NWAlignNodes(Operator, NWBase):
|
|||||||
y_range = max(y_locs) - min(y_locs)
|
y_range = max(y_locs) - min(y_locs)
|
||||||
horizontal = x_range > y_range
|
horizontal = x_range > y_range
|
||||||
|
|
||||||
# Undo corrective offsets for hidden nodes if alignment is horizontal
|
|
||||||
if not horizontal:
|
|
||||||
y_locs = [n.location.y - (0.5 * n.dimensions.y) for n in selection]
|
|
||||||
|
|
||||||
mid_x = 0.5 * (max(x_locs) + min(x_locs))
|
mid_x = 0.5 * (max(x_locs) + min(x_locs))
|
||||||
mid_y = 0.5 * (max(y_locs) + min(y_locs))
|
mid_y = 0.5 * (max(y_locs) + min(y_locs))
|
||||||
|
|
||||||
@ -2411,36 +2411,49 @@ class NWAlignNodes(Operator, NWBase):
|
|||||||
|
|
||||||
if horizontal:
|
if horizontal:
|
||||||
for node in selection:
|
for node in selection:
|
||||||
node.location.x = current_pos
|
if node.type != 'REROUTE':
|
||||||
node.location.y = (mid_y + weird_offset) if node.hide else mid_y + (0.5 * node.dimensions.y)
|
node.location.x = current_pos
|
||||||
|
node.location.y = (mid_y + weird_offset) if node.hide else mid_y + (0.5 * node.dimensions.y)
|
||||||
|
|
||||||
|
current_pos += margin_x + node.dimensions.x
|
||||||
|
else:
|
||||||
|
node.location.x = current_pos + (0.5 * reroute_width)
|
||||||
|
node.location.y = mid_y
|
||||||
|
|
||||||
|
current_pos += margin_x + reroute_width
|
||||||
|
|
||||||
current_pos += margin_x + node.dimensions.x
|
|
||||||
else:
|
else:
|
||||||
for node in selection:
|
for node in selection:
|
||||||
node.location.x = mid_x - (0.5 * node.dimensions.x)
|
if node.type != 'REROUTE':
|
||||||
node.location.y = (current_pos - (0.5 * node.dimensions.y) + weird_offset) if node.hide else current_pos
|
node.location.x = mid_x - (0.5 * node.dimensions.x)
|
||||||
|
node.location.y = (current_pos - (0.5 * node.dimensions.y) + weird_offset) if node.hide else current_pos
|
||||||
|
|
||||||
current_pos -= margin_y + node.dimensions.y
|
current_pos -= margin_y + node.dimensions.y
|
||||||
|
else:
|
||||||
|
node.location.x = mid_x
|
||||||
|
node.location.y = current_pos - (0.5 * reroute_width)
|
||||||
|
|
||||||
|
current_pos -= margin_y + reroute_width
|
||||||
|
|
||||||
|
|
||||||
# If active node is selected, center nodes around it
|
# If active node is selected, center nodes around it
|
||||||
if active_loc is not None:
|
if active_loc is not None:
|
||||||
active_loc_diff = active_loc - active_node.location
|
active_loc_diff = active_loc - active_node.location
|
||||||
for node in selection:
|
for node in selection:
|
||||||
node.location += active_loc_diff
|
node.location += active_loc_diff
|
||||||
|
else:
|
||||||
elif horizontal: # Position nodes centered around where they used to be
|
new_x_locs = [n.location.x + (0.5 * n.dimensions.x) for n in selection]
|
||||||
new_locs = [n.location.x + (0.5 * n.dimensions.x) for n in selection]
|
new_y_locs = [n.location.y - weird_offset if n.hide
|
||||||
new_mid = 0.5 * (max(new_locs) + min(new_locs))
|
else n.location.y - (0.5 * n.dimensions.y) for n in selection]
|
||||||
x_diff = mid_x - new_mid
|
|
||||||
|
new_x_mid = 0.5 * (max(new_x_locs) + min(new_x_locs))
|
||||||
|
new_y_mid = 0.5 * (max(new_y_locs) + min(new_y_locs))
|
||||||
|
|
||||||
|
x_diff = mid_x - new_x_mid
|
||||||
|
y_diff = mid_y - new_y_mid
|
||||||
|
|
||||||
for node in selection:
|
for node in selection:
|
||||||
node.location.x += x_diff
|
node.location.x += x_diff
|
||||||
else:
|
|
||||||
new_locs = [n.location.y - (0.5 * n.dimensions.y) for n in selection]
|
|
||||||
new_mid = 0.5 * (max(new_locs) + min(new_locs))
|
|
||||||
y_diff = mid_y - new_mid
|
|
||||||
|
|
||||||
for node in selection:
|
|
||||||
node.location.y += y_diff
|
node.location.y += y_diff
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
Loading…
Reference in New Issue
Block a user