00001 // 00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH) 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU General Public License 00006 // as published by the Free Software Foundation; either version 2 00007 // of the License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 // 00018 00025 #include <QuonHelper.h> 00026 00027 QuonAOI::QuonAOI(bool useSquareMetric) 00028 { 00029 this->useSquareMetric = useSquareMetric; 00030 radius = 0.0; 00031 } 00032 00033 QuonAOI::QuonAOI(Vector2D center, double radius, bool useSquareMetric) 00034 { 00035 this->useSquareMetric = useSquareMetric; 00036 this->center = center; 00037 this->radius = radius; 00038 } 00039 00040 void QuonAOI::resize(double radius) 00041 { 00042 this->radius = radius; 00043 } 00044 00045 bool QuonAOI::collide(const Vector2D p) const 00046 { 00047 if(!useSquareMetric && center.distanceSqr(p) < (radius*radius)) 00048 { 00049 return true; 00050 } 00051 else if(useSquareMetric && center.xyMaxDistance(p) < (radius)) 00052 { 00053 return true; 00054 } 00055 return false; 00056 } 00057 00058 std::ostream& operator<<(std::ostream& Stream, const QuonAOI& aoi) 00059 { 00060 return Stream << aoi.center << " - " << aoi.radius; 00061 } 00062 00063 QuonSite::QuonSite() 00064 { 00065 type = QUNDEFINED; 00066 dirty = false; 00067 alive = false; 00068 softNeighbor = false; 00069 address = NodeHandle::UNSPECIFIED_NODE; 00070 AOIwidth = 0.0; 00071 } 00072 00073 std::ostream& operator<<(std::ostream& Stream, const QuonSite& s) 00074 { 00075 Stream << s.address.getAddress() << ":" << s.address.getPort() << " Type: "; 00076 switch(s.type) { 00077 case QUNDEFINED: 00078 if( s.softNeighbor) { 00079 Stream << "\"Softstate Neighbor\""; 00080 } else { 00081 Stream << "\"Undefined\""; 00082 } 00083 break; 00084 case QTHIS: 00085 Stream << "\"Self\""; 00086 break; 00087 case QNEIGHBOR: 00088 Stream << "\"Direct Neighbor\""; 00089 break; 00090 case QBINDING: 00091 Stream << "\"Binding Neighbor\""; 00092 break; 00093 break; 00094 } 00095 Stream << " Position: " << s.position; 00096 return Stream; 00097 } 00098