graph_edit_arranger.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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. List<Ref<GraphEdit::Connection>> connection_list = graph_edit->get_connection_list();
  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 (connection->to_node == graph_element->get_name() && (p_from->is_selected() || arrange_entire_graph) && connection->to_node != connection->from_node) {
  69. if (!s.has(p_from->get_name())) {
  70. s.insert(p_from->get_name());
  71. }
  72. String s_connection = String(p_from->get_name()) + " " + String(connection->to_node);
  73. StringName _connection(s_connection);
  74. Pair<int, int> ports(connection->from_port, connection->to_port);
  75. port_info.insert(_connection, ports);
  76. }
  77. }
  78. upper_neighbours.insert(graph_element->get_name(), s);
  79. }
  80. }
  81. if (!selected_nodes.size()) {
  82. arranging_graph = false;
  83. return;
  84. }
  85. HashMap<int, Vector<StringName>> layers = _layering(selected_nodes, upper_neighbours);
  86. _crossing_minimisation(layers, upper_neighbours);
  87. Dictionary root, align, sink, shift;
  88. _horizontal_alignment(root, align, layers, upper_neighbours, selected_nodes);
  89. HashMap<StringName, Vector2> new_positions;
  90. Vector2 default_position(FLT_MAX, FLT_MAX);
  91. Dictionary inner_shift;
  92. HashSet<StringName> block_heads;
  93. for (const StringName &E : selected_nodes) {
  94. inner_shift[E] = 0.0f;
  95. sink[E] = E;
  96. shift[E] = FLT_MAX;
  97. new_positions.insert(E, default_position);
  98. if ((StringName)root[E] == E) {
  99. block_heads.insert(E);
  100. }
  101. }
  102. _calculate_inner_shifts(inner_shift, root, node_names, align, block_heads, port_info);
  103. for (const StringName &E : block_heads) {
  104. _place_block(E, gap_v, layers, root, align, node_names, inner_shift, sink, shift, new_positions);
  105. }
  106. 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]]);
  107. origin.x = Object::cast_to<GraphNode>(node_names[layers[0][0]])->get_position_offset().x;
  108. for (const StringName &E : block_heads) {
  109. StringName u = E;
  110. float start_from = origin.y + new_positions[E].y;
  111. do {
  112. Vector2 cal_pos;
  113. cal_pos.y = start_from + (real_t)inner_shift[u];
  114. new_positions.insert(u, cal_pos);
  115. u = align[u];
  116. } while (u != E);
  117. }
  118. // Compute horizontal coordinates individually for layers to get uniform gap.
  119. float start_from = origin.x;
  120. float largest_node_size = 0.0f;
  121. for (unsigned int i = 0; i < layers.size(); i++) {
  122. Vector<StringName> layer = layers[i];
  123. for (int j = 0; j < layer.size(); j++) {
  124. float current_node_size = Object::cast_to<GraphNode>(node_names[layer[j]])->get_size().x;
  125. largest_node_size = MAX(largest_node_size, current_node_size);
  126. }
  127. for (int j = 0; j < layer.size(); j++) {
  128. float current_node_size = Object::cast_to<GraphNode>(node_names[layer[j]])->get_size().x;
  129. Vector2 cal_pos = new_positions[layer[j]];
  130. if (current_node_size == largest_node_size) {
  131. cal_pos.x = start_from;
  132. } else {
  133. float current_node_start_pos = start_from;
  134. if (current_node_size < largest_node_size / 2) {
  135. if (!(i || j)) {
  136. start_from -= (largest_node_size - current_node_size);
  137. }
  138. current_node_start_pos = start_from + largest_node_size - current_node_size;
  139. }
  140. cal_pos.x = current_node_start_pos;
  141. }
  142. new_positions.insert(layer[j], cal_pos);
  143. }
  144. start_from += largest_node_size + gap_h;
  145. largest_node_size = 0.0f;
  146. }
  147. graph_edit->emit_signal(SNAME("begin_node_move"));
  148. for (const StringName &E : selected_nodes) {
  149. GraphNode *graph_node = Object::cast_to<GraphNode>(node_names[E]);
  150. graph_node->set_drag(true);
  151. Vector2 pos = (new_positions[E]);
  152. if (graph_edit->is_snapping_enabled()) {
  153. float snapping_distance = graph_edit->get_snapping_distance();
  154. pos = pos.snappedf(snapping_distance);
  155. }
  156. graph_node->set_position_offset(pos);
  157. graph_node->set_drag(false);
  158. }
  159. graph_edit->emit_signal(SNAME("end_node_move"));
  160. arranging_graph = false;
  161. }
  162. int GraphEditArranger::_set_operations(SET_OPERATIONS p_operation, HashSet<StringName> &r_u, const HashSet<StringName> &r_v) {
  163. switch (p_operation) {
  164. case GraphEditArranger::IS_EQUAL: {
  165. for (const StringName &E : r_u) {
  166. if (!r_v.has(E)) {
  167. return 0;
  168. }
  169. }
  170. return r_u.size() == r_v.size();
  171. } break;
  172. case GraphEditArranger::IS_SUBSET: {
  173. if (r_u.size() == r_v.size() && !r_u.size()) {
  174. return 1;
  175. }
  176. for (const StringName &E : r_u) {
  177. if (!r_v.has(E)) {
  178. return 0;
  179. }
  180. }
  181. return 1;
  182. } break;
  183. case GraphEditArranger::DIFFERENCE: {
  184. Vector<StringName> common;
  185. for (const StringName &E : r_u) {
  186. if (r_v.has(E)) {
  187. common.append(E);
  188. }
  189. }
  190. for (const StringName &E : common) {
  191. r_u.erase(E);
  192. }
  193. return r_u.size();
  194. } break;
  195. case GraphEditArranger::UNION: {
  196. for (const StringName &E : r_v) {
  197. if (!r_u.has(E)) {
  198. r_u.insert(E);
  199. }
  200. }
  201. return r_u.size();
  202. } break;
  203. default:
  204. break;
  205. }
  206. return -1;
  207. }
  208. HashMap<int, Vector<StringName>> GraphEditArranger::_layering(const HashSet<StringName> &r_selected_nodes, const HashMap<StringName, HashSet<StringName>> &r_upper_neighbours) {
  209. HashMap<int, Vector<StringName>> l;
  210. HashSet<StringName> p = r_selected_nodes, q = r_selected_nodes, u, z;
  211. int current_layer = 0;
  212. bool selected = false;
  213. while (!_set_operations(GraphEditArranger::IS_EQUAL, q, u)) {
  214. _set_operations(GraphEditArranger::DIFFERENCE, p, u);
  215. for (const StringName &E : p) {
  216. HashSet<StringName> n = r_upper_neighbours[E];
  217. if (_set_operations(GraphEditArranger::IS_SUBSET, n, z)) {
  218. Vector<StringName> t;
  219. t.push_back(E);
  220. if (!l.has(current_layer)) {
  221. l.insert(current_layer, Vector<StringName>{});
  222. }
  223. selected = true;
  224. t.append_array(l[current_layer]);
  225. l.insert(current_layer, t);
  226. u.insert(E);
  227. }
  228. }
  229. if (!selected) {
  230. current_layer++;
  231. uint32_t previous_size_z = z.size();
  232. _set_operations(GraphEditArranger::UNION, z, u);
  233. if (z.size() == previous_size_z) {
  234. WARN_PRINT("Graph contains cycle(s). The cycle(s) will not be rearranged accurately.");
  235. Vector<StringName> t;
  236. if (l.has(0)) {
  237. t.append_array(l[0]);
  238. }
  239. for (const StringName &E : p) {
  240. t.push_back(E);
  241. }
  242. l.insert(0, t);
  243. break;
  244. }
  245. }
  246. selected = false;
  247. }
  248. return l;
  249. }
  250. Vector<StringName> GraphEditArranger::_split(const Vector<StringName> &r_layer, const HashMap<StringName, Dictionary> &r_crossings) {
  251. if (!r_layer.size()) {
  252. return Vector<StringName>();
  253. }
  254. const StringName &p = r_layer[Math::random(0, r_layer.size() - 1)];
  255. Vector<StringName> left;
  256. Vector<StringName> right;
  257. for (int i = 0; i < r_layer.size(); i++) {
  258. if (p != r_layer[i]) {
  259. const StringName &q = r_layer[i];
  260. int cross_pq = r_crossings[p][q];
  261. int cross_qp = r_crossings[q][p];
  262. if (cross_pq > cross_qp) {
  263. left.push_back(q);
  264. } else {
  265. right.push_back(q);
  266. }
  267. }
  268. }
  269. left.push_back(p);
  270. left.append_array(right);
  271. return left;
  272. }
  273. 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) {
  274. for (const StringName &E : r_selected_nodes) {
  275. r_root[E] = E;
  276. r_align[E] = E;
  277. }
  278. if (r_layers.size() == 1) {
  279. return;
  280. }
  281. for (unsigned int i = 1; i < r_layers.size(); i++) {
  282. Vector<StringName> lower_layer = r_layers[i];
  283. Vector<StringName> upper_layer = r_layers[i - 1];
  284. int r = -1;
  285. for (int j = 0; j < lower_layer.size(); j++) {
  286. Vector<Pair<int, StringName>> up;
  287. const StringName &current_node = lower_layer[j];
  288. for (int k = 0; k < upper_layer.size(); k++) {
  289. const StringName &adjacent_neighbour = upper_layer[k];
  290. if (r_upper_neighbours[current_node].has(adjacent_neighbour)) {
  291. up.push_back(Pair<int, StringName>(k, adjacent_neighbour));
  292. }
  293. }
  294. int start = (up.size() - 1) / 2;
  295. int end = (up.size() - 1) % 2 ? start + 1 : start;
  296. for (int p = start; p <= end; p++) {
  297. StringName Align = r_align[current_node];
  298. if (Align == current_node && r < up[p].first) {
  299. r_align[up[p].second] = lower_layer[j];
  300. r_root[current_node] = r_root[up[p].second];
  301. r_align[current_node] = r_root[up[p].second];
  302. r = up[p].first;
  303. }
  304. }
  305. }
  306. }
  307. }
  308. void GraphEditArranger::_crossing_minimisation(HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, HashSet<StringName>> &r_upper_neighbours) {
  309. if (r_layers.size() == 1) {
  310. return;
  311. }
  312. for (unsigned int i = 1; i < r_layers.size(); i++) {
  313. Vector<StringName> upper_layer = r_layers[i - 1];
  314. Vector<StringName> lower_layer = r_layers[i];
  315. HashMap<StringName, Dictionary> c;
  316. for (int j = 0; j < lower_layer.size(); j++) {
  317. const StringName &p = lower_layer[j];
  318. Dictionary d;
  319. for (int k = 0; k < lower_layer.size(); k++) {
  320. unsigned int crossings = 0;
  321. const StringName &q = lower_layer[k];
  322. if (j != k) {
  323. for (int h = 1; h < upper_layer.size(); h++) {
  324. if (r_upper_neighbours[p].has(upper_layer[h])) {
  325. for (int g = 0; g < h; g++) {
  326. if (r_upper_neighbours[q].has(upper_layer[g])) {
  327. crossings++;
  328. }
  329. }
  330. }
  331. }
  332. }
  333. d[q] = crossings;
  334. }
  335. c.insert(p, d);
  336. }
  337. r_layers.insert(i, _split(lower_layer, c));
  338. }
  339. }
  340. 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) {
  341. for (const StringName &E : r_block_heads) {
  342. real_t left = 0;
  343. StringName u = E;
  344. StringName v = r_align[u];
  345. while (u != v && (StringName)r_root[u] != v) {
  346. String _connection = String(u) + " " + String(v);
  347. GraphNode *gnode_from = Object::cast_to<GraphNode>(r_node_names[u]);
  348. GraphNode *gnode_to = Object::cast_to<GraphNode>(r_node_names[v]);
  349. Pair<int, int> ports = r_port_info[_connection];
  350. int port_from = ports.first;
  351. int port_to = ports.second;
  352. Vector2 pos_from = gnode_from->get_output_port_position(port_from) * graph_edit->get_zoom();
  353. Vector2 pos_to = gnode_to->get_input_port_position(port_to) * graph_edit->get_zoom();
  354. real_t s = (real_t)r_inner_shifts[u] + (pos_from.y - pos_to.y) / graph_edit->get_zoom();
  355. r_inner_shifts[v] = s;
  356. left = MIN(left, s);
  357. u = v;
  358. v = (StringName)r_align[v];
  359. }
  360. u = E;
  361. do {
  362. r_inner_shifts[u] = (real_t)r_inner_shifts[u] - left;
  363. u = (StringName)r_align[u];
  364. } while (u != E);
  365. }
  366. }
  367. 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) {
  368. #define MAX_ORDER 2147483647
  369. #define ORDER(node, layers) \
  370. for (unsigned int i = 0; i < layers.size(); i++) { \
  371. int index = layers[i].find(node); \
  372. if (index > 0) { \
  373. order = index; \
  374. break; \
  375. } \
  376. order = MAX_ORDER; \
  377. }
  378. int order = MAX_ORDER;
  379. float threshold = p_current_threshold;
  380. if (p_v == p_w) {
  381. int min_order = MAX_ORDER;
  382. Ref<GraphEdit::Connection> incoming;
  383. List<Ref<GraphEdit::Connection>> connection_list = graph_edit->get_connection_list();
  384. for (const Ref<GraphEdit::Connection> &connection : connection_list) {
  385. if (connection->to_node == p_w) {
  386. ORDER(connection->from_node, r_layers);
  387. if (min_order > order) {
  388. min_order = order;
  389. incoming = connection;
  390. }
  391. }
  392. }
  393. if (incoming.is_valid()) {
  394. GraphNode *gnode_from = Object::cast_to<GraphNode>(r_node_names[incoming->from_node]);
  395. GraphNode *gnode_to = Object::cast_to<GraphNode>(r_node_names[p_w]);
  396. Vector2 pos_from = gnode_from->get_output_port_position(incoming->from_port) * graph_edit->get_zoom();
  397. Vector2 pos_to = gnode_to->get_input_port_position(incoming->to_port) * graph_edit->get_zoom();
  398. // If connected block node is selected, calculate thershold or add current block to list.
  399. if (gnode_from->is_selected()) {
  400. Vector2 connected_block_pos = r_node_positions[r_root[incoming->from_node]];
  401. if (connected_block_pos.y != FLT_MAX) {
  402. //Connected block is placed, calculate threshold.
  403. 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;
  404. }
  405. }
  406. }
  407. }
  408. if (threshold == FLT_MIN && (StringName)r_align[p_w] == p_v) {
  409. // This time, pick an outgoing edge and repeat as above!
  410. int min_order = MAX_ORDER;
  411. Ref<GraphEdit::Connection> outgoing;
  412. List<Ref<GraphEdit::Connection>> connection_list = graph_edit->get_connection_list();
  413. for (const Ref<GraphEdit::Connection> &connection : connection_list) {
  414. if (connection->from_node == p_w) {
  415. ORDER(connection->to_node, r_layers);
  416. if (min_order > order) {
  417. min_order = order;
  418. outgoing = connection;
  419. }
  420. }
  421. }
  422. if (outgoing.is_valid()) {
  423. GraphNode *gnode_from = Object::cast_to<GraphNode>(r_node_names[p_w]);
  424. GraphNode *gnode_to = Object::cast_to<GraphNode>(r_node_names[outgoing->to_node]);
  425. Vector2 pos_from = gnode_from->get_output_port_position(outgoing->from_port) * graph_edit->get_zoom();
  426. Vector2 pos_to = gnode_to->get_input_port_position(outgoing->to_port) * graph_edit->get_zoom();
  427. // If connected block node is selected, calculate thershold or add current block to list.
  428. if (gnode_to->is_selected()) {
  429. Vector2 connected_block_pos = r_node_positions[r_root[outgoing->to_node]];
  430. if (connected_block_pos.y != FLT_MAX) {
  431. //Connected block is placed. Calculate threshold
  432. 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;
  433. }
  434. }
  435. }
  436. }
  437. #undef MAX_ORDER
  438. #undef ORDER
  439. return threshold;
  440. }
  441. 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) {
  442. #define PRED(node, layers) \
  443. for (unsigned int i = 0; i < layers.size(); i++) { \
  444. int index = layers[i].find(node); \
  445. if (index > 0) { \
  446. predecessor = layers[i][index - 1]; \
  447. break; \
  448. } \
  449. predecessor = StringName(); \
  450. }
  451. StringName predecessor;
  452. StringName successor;
  453. Vector2 pos = r_node_positions[p_v];
  454. if (pos.y == FLT_MAX) {
  455. pos.y = 0;
  456. bool initial = false;
  457. StringName w = p_v;
  458. real_t threshold = FLT_MIN;
  459. do {
  460. PRED(w, r_layers);
  461. if (predecessor != StringName()) {
  462. StringName u = r_root[predecessor];
  463. _place_block(u, p_delta, r_layers, r_root, r_align, r_node_name, r_inner_shift, r_sink, r_shift, r_node_positions);
  464. threshold = _calculate_threshold(p_v, w, r_node_name, r_layers, r_root, r_align, r_inner_shift, threshold, r_node_positions);
  465. if ((StringName)r_sink[p_v] == p_v) {
  466. r_sink[p_v] = r_sink[u];
  467. }
  468. Vector2 predecessor_root_pos = r_node_positions[u];
  469. Vector2 predecessor_node_size = Object::cast_to<GraphNode>(r_node_name[predecessor])->get_size();
  470. if (r_sink[p_v] != r_sink[u]) {
  471. 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;
  472. r_shift[r_sink[u]] = MIN(sc, (real_t)r_shift[r_sink[u]]);
  473. } else {
  474. 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;
  475. sb = MAX(sb, threshold);
  476. if (initial) {
  477. pos.y = sb;
  478. } else {
  479. pos.y = MAX(pos.y, sb);
  480. }
  481. initial = false;
  482. }
  483. }
  484. threshold = _calculate_threshold(p_v, w, r_node_name, r_layers, r_root, r_align, r_inner_shift, threshold, r_node_positions);
  485. w = r_align[w];
  486. } while (w != p_v);
  487. r_node_positions.insert(p_v, pos);
  488. }
  489. #undef PRED
  490. }