degate  0.1.2
BoundingBox.h
Go to the documentation of this file.
00001 /* -*-c++-*-
00002 
00003  This file is part of the IC reverse engineering tool degate.
00004 
00005  Copyright 2008, 2009, 2010 by Martin Schobert
00006 
00007  Degate is free software: you can redistribute it and/or modify
00008  it under the terms of the GNU General Public License as published by
00009  the Free Software Foundation, either version 3 of the License, or
00010  any later version.
00011 
00012  Degate is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU General Public License for more details.
00016 
00017  You should have received a copy of the GNU General Public License
00018  along with degate. If not, see <http://www.gnu.org/licenses/>.
00019 
00020  */
00021 
00022 #ifndef __BOUNDINGBOX_H__
00023 #define __BOUNDINGBOX_H__
00024 
00025 #include <stdio.h>
00026 #include "globals.h"
00027 #include <iostream>
00028 
00029 namespace degate {
00030 class BoundingBox {
00031 
00032  private:
00033   int min_x, max_x, min_y, max_y;
00034 
00035  public:
00036   BoundingBox();
00037 
00038   BoundingBox(int min_x, int max_x, int min_y, int max_y);
00039   BoundingBox(int width, int height);
00040   BoundingBox(const BoundingBox&);
00041 
00042   virtual ~BoundingBox();
00043 
00044   BoundingBox const& get_bounding_box() const;
00045   bool in_shape(int x, int y, int max_distance = 0) const;
00046 
00047   /**
00048    * Check if this bounding box is completly within the bounding box given as parameter.
00049    */
00050 
00051   bool in_bounding_box(BoundingBox const& bbox) const;
00052   bool operator==(const BoundingBox& other) const;
00053   bool operator!=(const BoundingBox& other) const;
00054 
00055   bool intersects(BoundingBox const & rect) const;
00056   bool complete_within(BoundingBox const & rect) const;
00057 
00058   unsigned int get_width() const;
00059   unsigned int get_height() const;
00060 
00061   int get_min_x() const;
00062   int get_max_x() const;
00063   int get_min_y() const;
00064   int get_max_y() const;
00065 
00066   int get_center_x() const;
00067   int get_center_y() const;
00068 
00069   void set_min_x(int min_x);
00070   void set_min_y(int min_y);
00071   void set_max_x(int max_x);
00072   void set_max_y(int max_y);
00073 
00074   void set(int min_x, int max_x, int min_y, int max_y);
00075 
00076   void shift_x(int delta_x);
00077   void shift_y(int delta_y);
00078   void shift(int delta_x, int delta_y);
00079 
00080   void print(std::ostream & os = std::cout, int n_tabs = 0) const;
00081   std::string to_string() const;
00082 
00083 };
00084 
00085 }
00086 #endif