1 /** \file
2  * \brief Declaration of class Rectangle.
3  *
4  * \author Stefan Hachul
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/basic/geometry.h>
35 #include <iostream>
36 
37 namespace ogdf {
38 namespace energybased {
39 namespace fmmm {
40 
41 //! Helping data structure for packing rectangles; The width, height and the position
42 //! of the down left corner of the tight surroundig rectangle is represented for each
43 //! connected component of the graph.
44 class Rectangle
45 {
46 	//! Outputstream for Rectangle.
47 	friend std::ostream &operator<< (std::ostream & output, const Rectangle & A)
48 	{
49 		output <<"width: "<< A.width<<" height: "<<A.height<<" old dlc_position: "
50 			<<A.old_down_left_corner_position<<" new dlc_position: "
51 			<<A.new_down_left_corner_position<<" coponenet_index: "<<A.component_index;
52 		if (A.tipped_over) {
53 			output << " is tipped_over";
54 		}
55 		return output;
56 	}
57 
58 	//! Inputstream for Rectangle.
59 	friend std::istream &operator>> (std::istream & input,  Rectangle & A)
60 	{
61 		input >>A.width;
62 		return input;
63 	}
64 
65 public:
66 
Rectangle()67 	Rectangle() //!< constructor
68 	{
69 		old_down_left_corner_position.m_x = 0;
70 		old_down_left_corner_position.m_y = 0;
71 		new_down_left_corner_position.m_x = 0;
72 		new_down_left_corner_position.m_y = 0;
73 		width = 0;
74 		height = 0;
75 		component_index = -1;
76 		tipped_over = false;
77 	}
78 
set_rectangle(double w,double h,double old_dlc_x_pos,double old_dlc_y_pos,int comp_index)79 	void set_rectangle (double w, double h, double old_dlc_x_pos,double
80 		old_dlc_y_pos,int comp_index)
81 	{
82 		width = w;
83 		height = h;
84 		old_down_left_corner_position.m_x = old_dlc_x_pos;
85 		old_down_left_corner_position.m_y = old_dlc_y_pos;
86 		component_index = comp_index;
87 		tipped_over = false;
88 	}
89 
set_old_dlc_position(DPoint dlc_pos)90 	void set_old_dlc_position(DPoint dlc_pos){old_down_left_corner_position = dlc_pos;}
set_new_dlc_position(DPoint dlc_pos)91 	void set_new_dlc_position(DPoint dlc_pos){new_down_left_corner_position = dlc_pos;}
set_width(double w)92 	void set_width(double w) {width = w;}
set_height(double h)93 	void set_height(double h) {height = h;}
set_component_index(int comp_index)94 	void set_component_index (int comp_index) {component_index = comp_index;}
tipp_over()95 	void tipp_over() { tipped_over = !tipped_over; }
96 
get_old_dlc_position()97 	DPoint get_old_dlc_position() const { return old_down_left_corner_position; }
get_new_dlc_position()98 	DPoint get_new_dlc_position() const { return new_down_left_corner_position; }
get_width()99 	double get_width() const {return width;}
get_height()100 	double get_height() const {return height;}
get_component_index()101 	int get_component_index() const {return component_index;}
is_tipped_over()102 	bool is_tipped_over() const {return tipped_over;}
103 
104 private:
105 	DPoint old_down_left_corner_position;//!< down left corner of the tight surround. rect.
106 	DPoint new_down_left_corner_position;//!< new calculated down left corner of ...
107 	double width;                     //!< width of the surround. rect.
108 	double height;                    //!< height of the surround. rect.
109 	int component_index;  //!< the index of the related connected component
110 	bool tipped_over;     //!< indicates if this rectangle has been tipped over in the
111 	//! packing step
112 
113 };
114 
115 }
116 }
117 }
118