1 /** \file
2  * \brief Auxiliary functions for FMMM to reduce code duplication
3  *
4  * \author Stephan Beyer
5  *
6  * \par License:
7  * This file is part of the Open Graph Drawing Framework (OGDF).
8  *
9  * \par
10  * Copyright (C)<br>
11  * See README.md in the OGDF root directory for details.
12  *
13  * \par
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * Version 2 or 3 as published by the Free Software Foundation;
17  * see the file LICENSE.txt included in the packaging of this file
18  * for details.
19  *
20  * \par
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * \par
27  * You should have received a copy of the GNU General Public
28  * License along with this program; if not, see
29  * http://www.gnu.org/copyleft/gpl.html
30  */
31 
32 #pragma once
33 
34 #include <ogdf/energybased/fmmm/NodeAttributes.h>
35 #include <ogdf/energybased/fmmm/numexcept.h>
36 
37 namespace ogdf {
38 namespace energybased {
39 namespace fmmm {
40 
calculate_forces_inside_contained_nodes(NodeArray<DPoint> & F_rep,const NodeArray<NodeAttributes> & A,const List<node> & contained_nodes)41 inline void calculate_forces_inside_contained_nodes(NodeArray<DPoint> &F_rep, const NodeArray<NodeAttributes> &A, const List<node> &contained_nodes) {
42 	int length = contained_nodes.size();
43 	Array<node> numbered_nodes(length+1);
44 	int i = 1;
45 	for (node v : contained_nodes) {
46 		numbered_nodes[i] = v;
47 		++i;
48 	}
49 
50 	for (i = 1; i < length; i++) {
51 		for (int j = i + 1; j <= length; j++) {
52 			node u = numbered_nodes[i];
53 			node v = numbered_nodes[j];
54 			DPoint f_rep_u_on_v = numexcept::f_rep_u_on_v(A[u].get_position(), A[v].get_position());
55 			F_rep[v] += f_rep_u_on_v;
56 			F_rep[u] -= f_rep_u_on_v;
57 		}
58 	}
59 }
60 
61 }
62 }
63 }
64