degate 0.1.1
Circle.cc
Go to the documentation of this file.
00001 /*
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 #include "globals.h"
00023 
00024 #include "Circle.h"
00025 #include "BoundingBox.h"
00026 #include <math.h>
00027 
00028 using namespace degate;
00029 
00030 Circle::Circle() {
00031   x = y = diameter = 0;
00032   calculate_bounding_box();
00033 }
00034 
00035 Circle::Circle(int x, int y, unsigned int diameter) {
00036   this->x = x;
00037   this->y = y;
00038   this->diameter = diameter;
00039   calculate_bounding_box();
00040 }
00041 
00042 
00043 bool Circle::in_shape(int x, int y, int max_distance) const {
00044   int delta_x = this->x - x;
00045   int delta_y = this->y - y;
00046   return sqrt((double)(delta_x * delta_x + delta_y * delta_y)) <= diameter + max_distance;
00047 }
00048 
00049 bool Circle::in_bounding_box(BoundingBox const& bbox) const {
00050   return bounding_box.in_bounding_box(bbox);
00051 }
00052 
00053 BoundingBox const& Circle::get_bounding_box() const {
00054   return bounding_box;
00055 }
00056 
00057 
00058 bool Circle::operator==(const Circle& other) const {
00059     return (x == other.x && y == other.y && diameter == other.diameter);
00060 }
00061 
00062 bool Circle::operator!=(const Circle& other) const {
00063     return !(*this == other);
00064 }
00065 
00066 int Circle::get_x() const {
00067   return x;
00068 }
00069 
00070 int Circle::get_y() const {
00071   return y;
00072 }
00073 
00074 
00075 unsigned int Circle::get_diameter() const {
00076   return diameter;
00077 }
00078 
00079 void Circle::set_x(int x) {
00080   this->x = x;
00081   calculate_bounding_box();
00082 }
00083 
00084 void Circle::set_y(int y) {
00085   this->y = y;
00086   calculate_bounding_box();
00087 }
00088 
00089 void Circle::set_diameter(unsigned int diameter) {
00090   this->diameter = diameter;
00091   calculate_bounding_box();
00092 }
00093 
00094 void Circle::shift_y(int delta_y) {
00095   y += delta_y;
00096   calculate_bounding_box();
00097 }
00098 
00099 void Circle::shift_x(int delta_x) {
00100   x += delta_x;
00101   calculate_bounding_box();
00102 }
00103 
00104 
00105 void Circle::calculate_bounding_box() {
00106   unsigned int radius = diameter / 2;
00107   bounding_box = BoundingBox(x - radius, x + radius,
00108                              y - radius, y + radius);
00109 
00110 }