1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
|
/*
* $Revision: 2559 $
*
* last checkin:
* $Author: gutwenger $
* $Date: 2012-07-06 15:04:28 +0200 (Fr, 06. Jul 2012) $
***************************************************************/
/** \file
* \brief Declaration of class Rectangle.
*
* \author Stefan Hachul
*
* \par License:
* This file is part of the Open Graph Drawing Framework (OGDF).
*
* \par
* Copyright (C)<br>
* See README.txt in the root directory of the OGDF installation for details.
*
* \par
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* Version 2 or 3 as published by the Free Software Foundation;
* see the file LICENSE.txt included in the packaging of this file
* for details.
*
* \par
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* \par
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* \see http://www.gnu.org/copyleft/gpl.html
***************************************************************/
#ifdef _MSC_VER
#pragma once
#endif
#ifndef OGDF_RECTANGLE_H
#define OGDF_RECTANGLE_H
#include "../basic/geometry.h"
#include <iostream>
namespace ogdf {
class Rectangle
{
//Helping data structure for packing rectangles; The width, height and the position
//of the down left corner of the tight surroundig rectangle is represented for each
//connected component of the graph.
//Outputstream for Rectangle.
friend ostream &operator<< (ostream & output, const Rectangle & A)
{
output <<"width: "<< A.width<<" height: "<<A.height<<" old dlc_position: "
<<A.old_down_left_corner_position<<" new dlc_position: "
<<A.new_down_left_corner_position<<" coponenet_index: "<<A.component_index;
if(A.tipped_over == true)
output<<" is tipped_over";
return output;
}
//Inputstream for Rectangle.
friend istream &operator>> (istream & input, Rectangle & A)
{
input >>A.width;
return input;
}
public:
Rectangle() //constructor
{
old_down_left_corner_position.m_x = 0;
old_down_left_corner_position.m_y = 0;
new_down_left_corner_position.m_x = 0;
new_down_left_corner_position.m_y = 0;
width = 0;
height = 0;
component_index = -1;
tipped_over = false;
}
~Rectangle() { } //destructor
void set_rectangle (double w, double h, double old_dlc_x_pos,double
old_dlc_y_pos,int comp_index)
{
width = w;
height = h;
old_down_left_corner_position.m_x = old_dlc_x_pos;
old_down_left_corner_position.m_y = old_dlc_y_pos;
component_index = comp_index;
tipped_over = false;
}
void set_old_dlc_position(DPoint dlc_pos){old_down_left_corner_position = dlc_pos;}
void set_new_dlc_position(DPoint dlc_pos){new_down_left_corner_position = dlc_pos;}
void set_width(double w) {width = w;}
void set_height(double h) {height = h;}
void set_component_index (int comp_index) {component_index = comp_index;}
void tipp_over()
{
if(tipped_over == false)
tipped_over = true;
else
tipped_over = false;
}
DPoint get_old_dlc_position() const { return old_down_left_corner_position; }
DPoint get_new_dlc_position() const { return new_down_left_corner_position; }
double get_width() const {return width;}
double get_height() const {return height;}
int get_component_index() const {return component_index;}
bool is_tipped_over() const {return tipped_over;}
private:
DPoint old_down_left_corner_position;//down left corner of the tight surround. rect.
DPoint new_down_left_corner_position;//new calculated down left corner of ...
double width; //width of the surround. rect.
double height; //height of the surround. rect.
int component_index; //the index of the related connected component
bool tipped_over; //indicates if this rectangle has been tipped over in the
//packing step
};
//Needed for sorting algorithms in ogdf/List and ogdf/Array.
class RectangleComparerHeight
{
public:
RectangleComparerHeight() { }
~RectangleComparerHeight() { }
bool less(const Rectangle& A,const Rectangle & B) const
{
if(A.get_height() > B.get_height() )
return true;
else
return false;
}
bool leq(const Rectangle& A,const Rectangle & B) const
{
if(A.get_height() >= B.get_height() )
return true;
else
return false;
}
bool equal(const Rectangle& A,const Rectangle & B) const
{
if(A.get_height() == B.get_height() )
return true;
else
return false;
}
};
class RectangleComparerWidth
{
public:
RectangleComparerWidth() { }
~RectangleComparerWidth() { }
bool less(const Rectangle& A,const Rectangle & B) const
{
if(A.get_width() > B.get_width() )
return true;
else
return false;
}
bool leq(const Rectangle& A,const Rectangle & B) const
{
if(A.get_width() >= B.get_width() )
return true;
else
return false;
}
bool equal(const Rectangle& A,const Rectangle & B) const
{
if(A.get_width() == B.get_width() )
return true;
else
return false;
}
};
class RectangleComparerArea
{
public:
RectangleComparerArea() { }
~RectangleComparerArea() { }
bool less(const Rectangle& A,const Rectangle & B) const
{
if(A.get_height() * A.get_width() > B.get_height() * B.get_width() )
return true;
else
return false;
}
bool leq(const Rectangle& A,const Rectangle & B) const
{
if(A.get_height() * A.get_width() >= B.get_height() * B.get_width() )
return true;
else
return false;
}
bool equal(const Rectangle& A,const Rectangle & B) const
{
if(A.get_height() * A.get_width() == B.get_height() * B.get_width() )
return true;
else
return false;
}
};
}//namespace ogdf
#endif
|