Drop unused resource strings
[TortoiseGit.git] / ext / OGDF / src / energybased / Attraction.cpp
blob39847dc086d85a5757a2e282d81ec4e7dbabded6
1 /*
2 * $Revision: 2552 $
4 * last checkin:
5 * $Author: gutwenger $
6 * $Date: 2012-07-05 16:45:20 +0200 (Do, 05. Jul 2012) $
7 ***************************************************************/
9 /** \file
10 * \brief Implements class Attraction.
12 * \author Rene Weiskircher
14 * \par License:
15 * This file is part of the Open Graph Drawing Framework (OGDF).
17 * \par
18 * Copyright (C)<br>
19 * See README.txt in the root directory of the OGDF installation for details.
21 * \par
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * Version 2 or 3 as published by the Free Software Foundation;
25 * see the file LICENSE.txt included in the packaging of this file
26 * for details.
28 * \par
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * \par
35 * You should have received a copy of the GNU General Public
36 * License along with this program; if not, write to the Free
37 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
38 * Boston, MA 02110-1301, USA.
40 * \see http://www.gnu.org/copyleft/gpl.html
41 ***************************************************************/
43 #include <ogdf/internal/energybased/Attraction.h>
45 namespace ogdf {
47 const double Attraction::MULTIPLIER = 2.0;
50 //initializes internal data, like name and layout
51 Attraction::Attraction(GraphAttributes &AG) : NodePairEnergy("Attraction", AG) {
53 reinitializeEdgeLength(MULTIPLIER);
57 //computes preferred edge length as the average of all widths and heights of the vertices
58 //multiplied by the multiplier
59 void Attraction::reinitializeEdgeLength(double multi)
61 double lengthSum(0.0);
62 node v;
63 forall_nodes(v,m_G) {
64 const IntersectionRectangle &i = shape(v);
65 lengthSum += i.width();
66 lengthSum += i.height();
68 lengthSum /= (2*m_G.numberOfNodes());
69 // lengthSum is now the average of all lengths and widths
70 m_preferredEdgeLength = multi * lengthSum;
72 }//reinitializeEdgeLength
75 //the energy of a pair of vertices is computed as the square of the difference between the
76 //actual distance and the preferred edge length
77 double Attraction::computeCoordEnergy(node v1, node v2, const DPoint &p1, const DPoint &p2)
78 const
80 double energy = 0.0;
81 if(adjacent(v1,v2)) {
82 IntersectionRectangle i1(shape(v1)), i2(shape(v2));
83 i1.move(p1);
84 i2.move(p2);
85 energy = i1.distance(i2) - m_preferredEdgeLength;
86 energy *= energy;
88 return energy;
92 #ifdef OGDF_DEBUG
93 void Attraction::printInternalData() const {
94 NodePairEnergy::printInternalData();
95 cout << "\nPreferred edge length: " << m_preferredEdgeLength;
97 #endif
99 }// namespace ogdf