2
0

graph_edit_arranger.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. /**************************************************************************/
  2. /* graph_edit_arranger.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "graph_edit_arranger.h"
  31. #include "scene/gui/graph_edit.h"
  32. void GraphEditArranger::arrange_nodes() {
  33. ERR_FAIL_NULL(graph_edit);
  34. if (!arranging_graph) {
  35. arranging_graph = true;
  36. } else {
  37. return;
  38. }
  39. Dictionary node_names;
  40. HashSet<StringName> selected_nodes;
  41. bool arrange_entire_graph = true;
  42. for (int i = graph_edit->get_child_count() - 1; i >= 0; i--) {
  43. GraphNode *graph_element = Object::cast_to<GraphNode>(graph_edit->get_child(i));
  44. if (!graph_element) {
  45. continue;
  46. }
  47. node_names[graph_element->get_name()] = graph_element;
  48. if (graph_element->is_selected()) {
  49. arrange_entire_graph = false;
  50. }
  51. }
  52. HashMap<StringName, HashSet<StringName>> upper_neighbours;
  53. HashMap<StringName, Pair<int, int>> port_info;
  54. Vector2 origin(FLT_MAX, FLT_MAX);
  55. float gap_v = 100.0f;
  56. float gap_h = 100.0f;
  57. const Vector<Ref<GraphEdit::Connection>> connection_list = graph_edit->get_connections();
  58. for (int i = graph_edit->get_child_count() - 1; i >= 0; i--) {
  59. GraphNode *graph_element = Object::cast_to<GraphNode>(graph_edit->get_child(i));
  60. if (!graph_element) {
  61. continue;
  62. }
  63. if (graph_element->is_selected() || arrange_entire_graph) {
  64. selected_nodes.insert(graph_element->get_name());
  65. HashSet<StringName> s;
  66. for (const Ref<GraphEdit::Connection> &connection : connection_list) {
  67. GraphNode *p_from = Object::cast_to<GraphNode>(node_names[connection->from_node]);
  68. if (!p_from) {
  69. continue;
  70. }
  71. if (connection->to_node == graph_element->get_name() && (p_from->is_selected() || arrange_entire_graph) && connection->to_node != connection->from_node) {
  72. if (!s.has(p_from->get_name())) {
  73. s.insert(p_from->get_name());
  74. }
  75. String s_connection = String(p_from->get_name()) + " " + String(connection->to_node);
  76. StringName _connection(s_connection);
  77. Pair<int, int> ports(connection->from_port, connection->to_port);
  78. port_info.insert(_connection, ports);
  79. }
  80. }
  81. upper_neighbours.insert(graph_element->get_name(), s);
  82. }
  83. }
  84. if (!selected_nodes.size()) {
  85. arranging_graph = false;
  86. return;
  87. }
  88. HashMap<int, Vector<StringName>> layers = _layering(selected_nodes, upper_neighbours);
  89. _crossing_minimisation(layers, upper_neighbours);
  90. Dictionary root, align, sink, shift;
  91. _horizontal_alignment(root, align, layers, upper_neighbours, selected_nodes);
  92. HashMap<StringName, Vector2> new_positions;
  93. Vector2 default_position(FLT_MAX, FLT_MAX);
  94. Dictionary inner_shift;
  95. HashSet<StringName> block_heads;
  96. for (const StringName &E : selected_nodes) {
  97. inner_shift[E] = 0.0f;
  98. sink[E] = E;
  99. shift[E] = FLT_MAX;
  100. new_positions.insert(E, default_position);
  101. if ((StringName)root[E] == E) {
  102. block_heads.insert(E);
  103. }
  104. }
  105. _calculate_inner_shifts(inner_shift, root, node_names, align, block_heads, port_info);
  106. for (const StringName &E : block_heads) {
  107. _place_block(E, gap_v, layers, root, align, node_names, inner_shift, sink, shift, new_positions);
  108. }
  109. origin.y = Object::cast_to<GraphNode>(node_names[layers[0][0]])->get_position_offset().y - (new_positions[layers[0][0]].y + (float)inner_shift[layers[0][0]]);
  110. origin.x = Object::cast_to<GraphNode>(node_names[layers[0][0]])->get_position_offset().x;
  111. for (const StringName &E : block_heads) {
  112. StringName u = E;
  113. float start_from = origin.y + new_positions[E].y;
  114. do {
  115. Vector2 cal_pos;
  116. cal_pos.y = start_from + (real_t)inner_shift[u];
  117. new_positions.insert(u, cal_pos);
  118. u = align[u];
  119. } while (u != E);
  120. }
  121. // Compute horizontal coordinates individually for layers to get uniform gap.
  122. float start_from = origin.x;
  123. float largest_node_size = 0.0f;
  124. for (unsigned int i = 0; i < layers.size(); i++) {
  125. Vector<StringName> layer = layers[i];
  126. for (int j = 0; j < layer.size(); j++) {
  127. float current_node_size = Object::cast_to<GraphNode>(node_names[layer[j]])->get_size().x;
  128. largest_node_size = MAX(largest_node_size, current_node_size);
  129. }
  130. for (int j = 0; j < layer.size(); j++) {
  131. float current_node_size = Object::cast_to<GraphNode>(node_names[layer[j]])->get_size().x;
  132. Vector2 cal_pos = new_positions[layer[j]];
  133. if (current_node_size == largest_node_size) {
  134. cal_pos.x = start_from;
  135. } else {
  136. float current_node_start_pos = start_from;
  137. if (current_node_size < largest_node_size / 2) {
  138. if (!(i || j)) {
  139. start_from -= (largest_node_size - current_node_size);
  140. }
  141. current_node_start_pos = start_from + largest_node_size - current_node_size;
  142. }
  143. cal_pos.x = current_node_start_pos;
  144. }
  145. new_positions.insert(layer[j], cal_pos);
  146. }
  147. start_from += largest_node_size + gap_h;
  148. largest_node_size = 0.0f;
  149. }
  150. graph_edit->emit_signal(SNAME("begin_node_move"));
  151. for (const StringName &E : selected_nodes) {
  152. GraphNode *graph_node = Object::cast_to<GraphNode>(node_names[E]);
  153. graph_node->set_drag(true);
  154. Vector2 pos = (new_positions[E]);
  155. if (graph_edit->is_snapping_enabled()) {
  156. float snapping_distance = graph_edit->get_snapping_distance();
  157. pos = pos.snappedf(snapping_distance);
  158. }
  159. graph_node->set_position_offset(pos);
  160. graph_node->set_drag(false);
  161. }
  162. graph_edit->emit_signal(SNAME("end_node_move"));
  163. arranging_graph = false;
  164. }
  165. int GraphEditArranger::_set_operations(SET_OPERATIONS p_operation, HashSet<StringName> &r_u, const HashSet<StringName> &r_v) {
  166. switch (p_operation) {
  167. case GraphEditArranger::IS_EQUAL: {
  168. for (const StringName &E : r_u) {
  169. if (!r_v.has(E)) {
  170. return 0;
  171. }
  172. }
  173. return r_u.size() == r_v.size();
  174. } break;
  175. case GraphEditArranger::IS_SUBSET: {
  176. if (r_u.size() == r_v.size() && !r_u.size()) {
  177. return 1;
  178. }
  179. for (const StringName &E : r_u) {
  180. if (!r_v.has(E)) {
  181. return 0;
  182. }
  183. }
  184. return 1;
  185. } break;
  186. case GraphEditArranger::DIFFERENCE: {
  187. Vector<StringName> common;
  188. for (const StringName &E : r_u) {
  189. if (r_v.has(E)) {
  190. common.append(E);
  191. }
  192. }
  193. for (const StringName &E : common) {
  194. r_u.erase(E);
  195. }
  196. return r_u.size();
  197. } break;
  198. case GraphEditArranger::UNION: {
  199. for (const StringName &E : r_v) {
  200. if (!r_u.has(E)) {
  201. r_u.insert(E);
  202. }
  203. }
  204. return r_u.size();
  205. } break;
  206. default:
  207. break;
  208. }
  209. return -1;
  210. }
  211. HashMap<int, Vector<StringName>> GraphEditArranger::_layering(const HashSet<StringName> &r_selected_nodes, const HashMap<StringName, HashSet<StringName>> &r_upper_neighbours) {
  212. HashMap<int, Vector<StringName>> l;
  213. HashSet<StringName> p = r_selected_nodes, q = r_selected_nodes, u, z;
  214. int current_layer = 0;
  215. bool selected = false;
  216. while (!_set_operations(GraphEditArranger::IS_EQUAL, q, u)) {
  217. _set_operations(GraphEditArranger::DIFFERENCE, p, u);
  218. for (const StringName &E : p) {
  219. HashSet<StringName> n = r_upper_neighbours[E];
  220. if (_set_operations(GraphEditArranger::IS_SUBSET, n, z)) {
  221. Vector<StringName> t;
  222. t.push_back(E);
  223. if (!l.has(current_layer)) {
  224. l.insert(current_layer, Vector<StringName>{});
  225. }
  226. selected = true;
  227. t.append_array(l[current_layer]);
  228. l.insert(current_layer, t);
  229. u.insert(E);
  230. }
  231. }
  232. if (!selected) {
  233. current_layer++;
  234. uint32_t previous_size_z = z.size();
  235. _set_operations(GraphEditArranger::UNION, z, u);
  236. if (z.size() == previous_size_z) {
  237. WARN_PRINT("Graph contains cycle(s). The cycle(s) will not be rearranged accurately.");
  238. Vector<StringName> t;
  239. if (l.has(0)) {
  240. t.append_array(l[0]);
  241. }
  242. for (const StringName &E : p) {
  243. t.push_back(E);
  244. }
  245. l.insert(0, t);
  246. break;
  247. }
  248. }
  249. selected = false;
  250. }
  251. return l;
  252. }
  253. Vector<StringName> GraphEditArranger::_split(const Vector<StringName> &r_layer, const HashMap<StringName, Dictionary> &r_crossings) {
  254. if (!r_layer.size()) {
  255. return Vector<StringName>();
  256. }
  257. const StringName &p = r_layer[Math::random(0, r_layer.size() - 1)];
  258. Vector<StringName> left;
  259. Vector<StringName> right;
  260. for (int i = 0; i < r_layer.size(); i++) {
  261. if (p != r_layer[i]) {
  262. const StringName &q = r_layer[i];
  263. int cross_pq = r_crossings[p][q];
  264. int cross_qp = r_crossings[q][p];
  265. if (cross_pq > cross_qp) {
  266. left.push_back(q);
  267. } else {
  268. right.push_back(q);
  269. }
  270. }
  271. }
  272. left.push_back(p);
  273. left.append_array(right);
  274. return left;
  275. }
  276. void GraphEditArranger::_horizontal_alignment(Dictionary &r_root, Dictionary &r_align, const HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, HashSet<StringName>> &r_upper_neighbours, const HashSet<StringName> &r_selected_nodes) {
  277. for (const StringName &E : r_selected_nodes) {
  278. r_root[E] = E;
  279. r_align[E] = E;
  280. }
  281. if (r_layers.size() == 1) {
  282. return;
  283. }
  284. for (unsigned int i = 1; i < r_layers.size(); i++) {
  285. Vector<StringName> lower_layer = r_layers[i];
  286. Vector<StringName> upper_layer = r_layers[i - 1];
  287. int r = -1;
  288. for (int j = 0; j < lower_layer.size(); j++) {
  289. Vector<Pair<int, StringName>> up;
  290. const StringName &current_node = lower_layer[j];
  291. for (int k = 0; k < upper_layer.size(); k++) {
  292. const StringName &adjacent_neighbour = upper_layer[k];
  293. if (r_upper_neighbours[current_node].has(adjacent_neighbour)) {
  294. up.push_back(Pair<int, StringName>(k, adjacent_neighbour));
  295. }
  296. }
  297. int start = (up.size() - 1) / 2;
  298. int end = (up.size() - 1) % 2 ? start + 1 : start;
  299. for (int p = start; p <= end; p++) {
  300. StringName Align = r_align[current_node];
  301. if (Align == current_node && r < up[p].first) {
  302. r_align[up[p].second] = lower_layer[j];
  303. r_root[current_node] = r_root[up[p].second];
  304. r_align[current_node] = r_root[up[p].second];
  305. r = up[p].first;
  306. }
  307. }
  308. }
  309. }
  310. }
  311. void GraphEditArranger::_crossing_minimisation(HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, HashSet<StringName>> &r_upper_neighbours) {
  312. if (r_layers.size() == 1) {
  313. return;
  314. }
  315. for (unsigned int i = 1; i < r_layers.size(); i++) {
  316. Vector<StringName> upper_layer = r_layers[i - 1];
  317. Vector<StringName> lower_layer = r_layers[i];
  318. HashMap<StringName, Dictionary> c;
  319. for (int j = 0; j < lower_layer.size(); j++) {
  320. const StringName &p = lower_layer[j];
  321. Dictionary d;
  322. for (int k = 0; k < lower_layer.size(); k++) {
  323. unsigned int crossings = 0;
  324. const StringName &q = lower_layer[k];
  325. if (j != k) {
  326. for (int h = 1; h < upper_layer.size(); h++) {
  327. if (r_upper_neighbours[p].has(upper_layer[h])) {
  328. for (int g = 0; g < h; g++) {
  329. if (r_upper_neighbours[q].has(upper_layer[g])) {
  330. crossings++;
  331. }
  332. }
  333. }
  334. }
  335. }
  336. d[q] = crossings;
  337. }
  338. c.insert(p, d);
  339. }
  340. r_layers.insert(i, _split(lower_layer, c));
  341. }
  342. }
  343. void GraphEditArranger::_calculate_inner_shifts(Dictionary &r_inner_shifts, const Dictionary &r_root, const Dictionary &r_node_names, const Dictionary &r_align, const HashSet<StringName> &r_block_heads, const HashMap<StringName, Pair<int, int>> &r_port_info) {
  344. for (const StringName &E : r_block_heads) {
  345. real_t left = 0;
  346. StringName u = E;
  347. StringName v = r_align[u];
  348. while (u != v && (StringName)r_root[u] != v) {
  349. String _connection = String(u) + " " + String(v);
  350. GraphNode *gnode_from = Object::cast_to<GraphNode>(r_node_names[u]);
  351. GraphNode *gnode_to = Object::cast_to<GraphNode>(r_node_names[v]);
  352. Pair<int, int> ports = r_port_info[_connection];
  353. int port_from = ports.first;
  354. int port_to = ports.second;
  355. Vector2 pos_from = gnode_from->get_output_port_position(port_from) * graph_edit->get_zoom();
  356. Vector2 pos_to = gnode_to->get_input_port_position(port_to) * graph_edit->get_zoom();
  357. real_t s = (real_t)r_inner_shifts[u] + (pos_from.y - pos_to.y) / graph_edit->get_zoom();
  358. r_inner_shifts[v] = s;
  359. left = MIN(left, s);
  360. u = v;
  361. v = (StringName)r_align[v];
  362. }
  363. u = E;
  364. do {
  365. r_inner_shifts[u] = (real_t)r_inner_shifts[u] - left;
  366. u = (StringName)r_align[u];
  367. } while (u != E);
  368. }
  369. }
  370. float GraphEditArranger::_calculate_threshold(const StringName &p_v, const StringName &p_w, const Dictionary &r_node_names, const HashMap<int, Vector<StringName>> &r_layers, const Dictionary &r_root, const Dictionary &r_align, const Dictionary &r_inner_shift, real_t p_current_threshold, const HashMap<StringName, Vector2> &r_node_positions) {
  371. #define MAX_ORDER 2147483647
  372. #define ORDER(node, layers) \
  373. for (unsigned int i = 0; i < layers.size(); i++) { \
  374. int index = layers[i].find(node); \
  375. if (index > 0) { \
  376. order = index; \
  377. break; \
  378. } \
  379. order = MAX_ORDER; \
  380. }
  381. int order = MAX_ORDER;
  382. float threshold = p_current_threshold;
  383. if (p_v == p_w) {
  384. int min_order = MAX_ORDER;
  385. Ref<GraphEdit::Connection> incoming;
  386. const Vector<Ref<GraphEdit::Connection>> connection_list = graph_edit->get_connections();
  387. for (const Ref<GraphEdit::Connection> &connection : connection_list) {
  388. if (connection->to_node == p_w) {
  389. ORDER(connection->from_node, r_layers);
  390. if (min_order > order) {
  391. min_order = order;
  392. incoming = connection;
  393. }
  394. }
  395. }
  396. if (incoming.is_valid()) {
  397. GraphNode *gnode_from = Object::cast_to<GraphNode>(r_node_names[incoming->from_node]);
  398. GraphNode *gnode_to = Object::cast_to<GraphNode>(r_node_names[p_w]);
  399. Vector2 pos_from = gnode_from->get_output_port_position(incoming->from_port) * graph_edit->get_zoom();
  400. Vector2 pos_to = gnode_to->get_input_port_position(incoming->to_port) * graph_edit->get_zoom();
  401. // If connected block node is selected, calculate threshold or add current block to list.
  402. if (gnode_from->is_selected()) {
  403. Vector2 connected_block_pos = r_node_positions[r_root[incoming->from_node]];
  404. if (connected_block_pos.y != FLT_MAX) {
  405. //Connected block is placed, calculate threshold.
  406. threshold = connected_block_pos.y + (real_t)r_inner_shift[incoming->from_node] - (real_t)r_inner_shift[p_w] + pos_from.y - pos_to.y;
  407. }
  408. }
  409. }
  410. }
  411. if (threshold == FLT_MIN && (StringName)r_align[p_w] == p_v) {
  412. // This time, pick an outgoing edge and repeat as above!
  413. int min_order = MAX_ORDER;
  414. Ref<GraphEdit::Connection> outgoing;
  415. const Vector<Ref<GraphEdit::Connection>> connection_list = graph_edit->get_connections();
  416. for (const Ref<GraphEdit::Connection> &connection : connection_list) {
  417. if (connection->from_node == p_w) {
  418. ORDER(connection->to_node, r_layers);
  419. if (min_order > order) {
  420. min_order = order;
  421. outgoing = connection;
  422. }
  423. }
  424. }
  425. if (outgoing.is_valid()) {
  426. GraphNode *gnode_from = Object::cast_to<GraphNode>(r_node_names[p_w]);
  427. GraphNode *gnode_to = Object::cast_to<GraphNode>(r_node_names[outgoing->to_node]);
  428. Vector2 pos_from = gnode_from->get_output_port_position(outgoing->from_port) * graph_edit->get_zoom();
  429. Vector2 pos_to = gnode_to->get_input_port_position(outgoing->to_port) * graph_edit->get_zoom();
  430. // If connected block node is selected, calculate threshold or add current block to list.
  431. if (gnode_to->is_selected()) {
  432. Vector2 connected_block_pos = r_node_positions[r_root[outgoing->to_node]];
  433. if (connected_block_pos.y != FLT_MAX) {
  434. //Connected block is placed. Calculate threshold
  435. threshold = connected_block_pos.y + (real_t)r_inner_shift[outgoing->to_node] - (real_t)r_inner_shift[p_w] + pos_from.y - pos_to.y;
  436. }
  437. }
  438. }
  439. }
  440. #undef MAX_ORDER
  441. #undef ORDER
  442. return threshold;
  443. }
  444. void GraphEditArranger::_place_block(const StringName &p_v, float p_delta, const HashMap<int, Vector<StringName>> &r_layers, const Dictionary &r_root, const Dictionary &r_align, const Dictionary &r_node_name, const Dictionary &r_inner_shift, Dictionary &r_sink, Dictionary &r_shift, HashMap<StringName, Vector2> &r_node_positions) {
  445. #define PRED(node, layers) \
  446. for (unsigned int i = 0; i < layers.size(); i++) { \
  447. int index = layers[i].find(node); \
  448. if (index > 0) { \
  449. predecessor = layers[i][index - 1]; \
  450. break; \
  451. } \
  452. predecessor = StringName(); \
  453. }
  454. StringName predecessor;
  455. StringName successor;
  456. Vector2 pos = r_node_positions[p_v];
  457. if (pos.y == FLT_MAX) {
  458. pos.y = 0;
  459. bool initial = false;
  460. StringName w = p_v;
  461. real_t threshold = FLT_MIN;
  462. do {
  463. PRED(w, r_layers);
  464. if (predecessor != StringName()) {
  465. StringName u = r_root[predecessor];
  466. _place_block(u, p_delta, r_layers, r_root, r_align, r_node_name, r_inner_shift, r_sink, r_shift, r_node_positions);
  467. threshold = _calculate_threshold(p_v, w, r_node_name, r_layers, r_root, r_align, r_inner_shift, threshold, r_node_positions);
  468. if ((StringName)r_sink[p_v] == p_v) {
  469. r_sink[p_v] = r_sink[u];
  470. }
  471. Vector2 predecessor_root_pos = r_node_positions[u];
  472. Vector2 predecessor_node_size = Object::cast_to<GraphNode>(r_node_name[predecessor])->get_size();
  473. if (r_sink[p_v] != r_sink[u]) {
  474. real_t sc = pos.y + (real_t)r_inner_shift[w] - predecessor_root_pos.y - (real_t)r_inner_shift[predecessor] - predecessor_node_size.y - p_delta;
  475. r_shift[r_sink[u]] = MIN(sc, (real_t)r_shift[r_sink[u]]);
  476. } else {
  477. real_t sb = predecessor_root_pos.y + (real_t)r_inner_shift[predecessor] + predecessor_node_size.y - (real_t)r_inner_shift[w] + p_delta;
  478. sb = MAX(sb, threshold);
  479. if (initial) {
  480. pos.y = sb;
  481. } else {
  482. pos.y = MAX(pos.y, sb);
  483. }
  484. initial = false;
  485. }
  486. }
  487. threshold = _calculate_threshold(p_v, w, r_node_name, r_layers, r_root, r_align, r_inner_shift, threshold, r_node_positions);
  488. w = r_align[w];
  489. } while (w != p_v);
  490. r_node_positions.insert(p_v, pos);
  491. }
  492. #undef PRED
  493. }