OverSim
QuonHelper.cc
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
25 #include <QuonHelper.h>
26 
27 QuonAOI::QuonAOI(bool useSquareMetric)
28 {
29  this->useSquareMetric = useSquareMetric;
30  radius = 0.0;
31 }
32 
33 QuonAOI::QuonAOI(Vector2D center, double radius, bool useSquareMetric)
34 {
35  this->useSquareMetric = useSquareMetric;
36  this->center = center;
37  this->radius = radius;
38 }
39 
40 void QuonAOI::resize(double radius)
41 {
42  this->radius = radius;
43 }
44 
45 bool QuonAOI::collide(const Vector2D p) const
46 {
48  {
49  return true;
50  }
51  else if(useSquareMetric && center.xyMaxDistance(p) < (radius))
52  {
53  return true;
54  }
55  return false;
56 }
57 
58 std::ostream& operator<<(std::ostream& Stream, const QuonAOI& aoi)
59 {
60  return Stream << aoi.center << " - " << aoi.radius;
61 }
62 
64 {
65  type = QUNDEFINED;
66  dirty = false;
67  alive = false;
68  softNeighbor = false;
70  AOIwidth = 0.0;
71 }
72 
73 std::ostream& operator<<(std::ostream& Stream, const QuonSite& s)
74 {
75  Stream << s.address.getIp() << ":" << s.address.getPort() << " Type: ";
76  switch(s.type) {
77  case QUNDEFINED:
78  if( s.softNeighbor) {
79  Stream << "\"Softstate Neighbor\"";
80  } else {
81  Stream << "\"Undefined\"";
82  }
83  break;
84  case QTHIS:
85  Stream << "\"Self\"";
86  break;
87  case QNEIGHBOR:
88  Stream << "\"Direct Neighbor\"";
89  break;
90  case QBINDING:
91  Stream << "\"Binding Neighbor\"";
92  break;
93  break;
94  }
95  Stream << " Position: " << s.position;
96  return Stream;
97 }
98