1 /** \file
2 * \brief implementation of class CCLayoutPackModule.
3 *
4 * \author Carsten Gutwenger
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 #include <ogdf/packing/CCLayoutPackModule.h>
33
34 namespace ogdf {
35
36 template<class POINT>
checkOffsetsTP(const Array<POINT> & box,const Array<POINT> & offset)37 bool CCLayoutPackModule::checkOffsetsTP(
38 const Array<POINT> &box,
39 const Array<POINT> &offset)
40 {
41 OGDF_ASSERT(box.size() == offset.size());
42 const int n = box.size();
43
44 for (int i = 0; i < n; ++i)
45 {
46 auto xl = offset[i].m_x;
47 auto xr = xl + box[i].m_x;
48 auto yb = offset[i].m_y;
49 auto yt = yb + box[i].m_y;
50
51 OGDF_ASSERT(xl <= xr);
52 OGDF_ASSERT(yb <= yt);
53
54 for (int j = i+1; j < n; ++j)
55 {
56 auto xl2 = offset[j].m_x;
57 auto xr2 = xl2 + box[j].m_x;
58 auto yb2 = offset[j].m_y;
59 auto yt2 = yb2 + box[j].m_y;
60
61 if (xr2 > xl && xl2 < xr && yt2 > yb && yb2 < yt)
62 return false;
63 }
64 }
65
66 return true;
67 }
68
checkOffsets(const Array<DPoint> & box,const Array<DPoint> & offset)69 bool CCLayoutPackModule::checkOffsets(const Array<DPoint> &box,
70 const Array<DPoint> &offset)
71 {
72 return checkOffsetsTP(box,offset);
73 }
74
checkOffsets(const Array<IPoint> & box,const Array<IPoint> & offset)75 bool CCLayoutPackModule::checkOffsets(const Array<IPoint> &box,
76 const Array<IPoint> &offset)
77 {
78 return checkOffsetsTP(box,offset);
79 }
80
81 }
82