degate  0.1.2
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  Copyright 2012 Robert Nitsch
00007 
00008  Degate is free software: you can redistribute it and/or modify
00009  it under the terms of the GNU General Public License as published by
00010  the Free Software Foundation, either version 3 of the License, or
00011  any later version.
00012 
00013  Degate is distributed in the hope that it will be useful,
00014  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  GNU General Public License for more details.
00017 
00018  You should have received a copy of the GNU General Public License
00019  along with degate. If not, see <http://www.gnu.org/licenses/>.
00020 
00021  */
00022 
00023 #include "globals.h"
00024 
00025 #include "Circle.h"
00026 #include "BoundingBox.h"
00027 #include <math.h>
00028 
00029 using namespace degate;
00030 
00031 Circle::Circle() {
00032   x = y = diameter = 0;
00033   calculate_bounding_box();
00034 }
00035 
00036 Circle::Circle(int x, int y, unsigned int diameter) {
00037   this->x = x;
00038   this->y = y;
00039   this->diameter = diameter;
00040   calculate_bounding_box();
00041 }
00042 
00043 void Circle::cloneDeepInto(DeepCopyable_shptr dest, oldnew_t *oldnew) const {
00044   auto clone = std::dynamic_pointer_cast<Circle>(dest);
00045   clone->x = x;
00046   clone->y = y;
00047   clone->diameter = diameter;
00048   clone->bounding_box = bounding_box;
00049 }
00050 
00051 bool Circle::in_shape(int x, int y, int max_distance) const {
00052   int delta_x = this->x - x;
00053   int delta_y = this->y - y;
00054   return sqrt((double)(delta_x * delta_x + delta_y * delta_y)) <= diameter + max_distance;
00055 }
00056 
00057 bool Circle::in_bounding_box(BoundingBox const& bbox) const {
00058   return bounding_box.in_bounding_box(bbox);
00059 }
00060 
00061 BoundingBox const& Circle::get_bounding_box() const {
00062   return bounding_box;
00063 }
00064 
00065 
00066 bool Circle::operator==(const Circle& other) const {
00067     return (x == other.x && y == other.y && diameter == other.diameter);
00068 }
00069 
00070 bool Circle::operator!=(const Circle& other) const {
00071     return !(*this == other);
00072 }
00073 
00074 int Circle::get_x() const {
00075   return x;
00076 }
00077 
00078 int Circle::get_y() const {
00079   return y;
00080 }
00081 
00082 
00083 unsigned int Circle::get_diameter() const {
00084   return diameter;
00085 }
00086 
00087 void Circle::set_x(int x) {
00088   this->x = x;
00089   calculate_bounding_box();
00090 }
00091 
00092 void Circle::set_y(int y) {
00093   this->y = y;
00094   calculate_bounding_box();
00095 }
00096 
00097 void Circle::set_diameter(unsigned int diameter) {
00098   this->diameter = diameter;
00099   calculate_bounding_box();
00100 }
00101 
00102 void Circle::shift_y(int delta_y) {
00103   y += delta_y;
00104   calculate_bounding_box();
00105 }
00106 
00107 void Circle::shift_x(int delta_x) {
00108   x += delta_x;
00109   calculate_bounding_box();
00110 }
00111 
00112 
00113 void Circle::calculate_bounding_box() {
00114   unsigned int radius = diameter / 2;
00115   bounding_box = BoundingBox(x - radius, x + radius,
00116                              y - radius, y + radius);
00117 
00118 }