orca-robotics INTRODUCTION Overview Download and Install Documentation REPOSITORY Interfaces Drivers Libraries Utilities Software Map DEVELOPER Dashboard PEOPLE Contributors Users Project Download Mailing lists
|
cell2d.h00001 /* 00002 * Orca-Robotics Project: Components for robotics 00003 * http://orca-robotics.sf.net/ 00004 * Copyright (c) 2004-2008 Alex Brooks, Alexei Makarenko, Tobias Kaupp 00005 * 00006 * This copy of Orca is licensed to you under the terms described in 00007 * the LICENSE file included in this distribution. 00008 * 00009 */ 00010 00011 #ifndef ORCA2_CELL2D_H 00012 #define ORCA2_CELL2D_H 00013 00014 #include <iostream> 00015 #include <vector> 00016 #include <list> 00017 00018 namespace hydropathplan 00019 { 00020 00024 class Cell2D 00025 { 00026 public: 00027 Cell2D( int x=0, int y=0); 00028 ~Cell2D() {}; 00029 00031 int x() const; 00033 int y() const; 00034 00036 void setX( const int x); 00038 void setY( const int y); 00040 void set( const int x, const int y); 00041 00043 Cell2D & operator= ( const Cell2D & p );// { x_=p.x_; y_=p.y_; return *this; }; 00045 Cell2D & operator+= ( const Cell2D & ); 00047 Cell2D & operator-= ( const Cell2D & ); 00049 Cell2D & operator*= ( int ); 00051 Cell2D & operator/= ( int ); 00052 00054 friend inline bool operator== ( const Cell2D &, const Cell2D & ); 00056 friend inline bool operator!= ( const Cell2D &, const Cell2D & ); 00058 friend inline const Cell2D operator+ ( const Cell2D &, const Cell2D & ); 00060 friend inline const Cell2D operator- ( const Cell2D &, const Cell2D & ); 00062 friend inline const Cell2D operator* ( const Cell2D &, int ); 00064 friend inline const Cell2D operator* ( int, const Cell2D & ); 00066 friend inline const Cell2D operator- ( const Cell2D & ); 00067 private: 00068 int x_; 00069 int y_; 00070 }; 00071 00073 typedef std::vector<hydropathplan::Cell2D> Cell2DVector; 00075 typedef std::list<hydropathplan::Cell2D> Cell2DList; 00076 00078 bool isIncluded( const Cell2DVector & C, const Cell2D & c ); 00080 bool isIncluded( const Cell2DList & C, const Cell2D & c ); 00081 00082 00083 /***************************************************************************** 00084 * Cell2D utility functions 00085 *****************************************************************************/ 00086 00089 double euclideanDistance( const Cell2D c1, const Cell2D c2 ); 00090 00093 int manhattanDistance( const Cell2D c1, const Cell2D c2 ); 00094 00097 bool isAdjacentN( const Cell2D c1, const Cell2D c2, unsigned int N ); 00098 00101 bool isNull( const Cell2D c ); 00102 00103 /* 00104 index for adjacentCell and diagonalCell 00105 00106 0 0 1 00107 00108 3 [c] 1 00109 00110 3 2 2 00111 00112 index for surroundCell 00113 00114 7 0 4 00115 00116 3 [c] 1 00117 00118 6 2 5 00119 */ 00120 00125 Cell2D adjacentCell( const Cell2D & cell, const int i ); 00126 00131 Cell2D diagonalCell( const Cell2D & cell, const int i ); 00132 00137 Cell2D surroundCell( const Cell2D & cell, const int i ); 00138 00141 std::ostream& operator<<( std::ostream &s, const Cell2D &obj ); 00142 00143 /***************************************************************************** 00144 * Cell2D inline member functions 00145 *****************************************************************************/ 00146 00147 inline Cell2D::Cell2D( int x, int y ) 00148 { x_ = x; y_ = y; } 00149 00150 inline int Cell2D::Cell2D::x() const 00151 { return x_; } 00152 00153 inline int Cell2D::Cell2D::y() const 00154 { return y_; } 00155 00156 inline void Cell2D::setX( const int x ) 00157 { x_ = x; } 00158 00159 inline void Cell2D::setY( const int y ) 00160 { y_ = y; } 00161 00162 inline void Cell2D::set( const int x, const int y ) 00163 { x_ = x; y_ = y; } 00164 00165 /***************************************************************************** 00166 * Cell2D arithmetic operator 00167 *****************************************************************************/ 00168 00169 //members 00170 inline Cell2D & Cell2D::operator= ( const Cell2D & p ) 00171 { x_=p.x_; y_=p.y_; return *this; } 00172 00173 inline Cell2D & Cell2D::operator+= ( const Cell2D &p ) 00174 { x_+=p.x_; y_+=p.y_; return *this; } 00175 00176 inline Cell2D & Cell2D::operator-= ( const Cell2D &p ) 00177 { x_-=p.x_; y_-=p.y_; return *this; } 00178 00179 inline Cell2D & Cell2D::operator*= ( int c ) 00180 { x_*=c; y_*=c; return *this; } 00181 00182 inline Cell2D & Cell2D::operator/= (int c) 00183 { if(c==0) return *this; x_/=c; y_/=c; return *this; } 00184 00185 //friends 00186 inline bool operator==( const Cell2D &p1, const Cell2D &p2 ) 00187 { return p1.x_ == p2.x_ && p1.y_ == p2.y_; } 00188 00189 inline bool operator!=( const Cell2D &p1, const Cell2D &p2 ) 00190 { return p1.x_ != p2.x_ || p1.y_ != p2.y_; } 00191 00192 inline const Cell2D operator+( const Cell2D &p1, const Cell2D &p2 ) 00193 { return Cell2D(p1.x_+p2.x_, p1.y_+p2.y_); } 00194 00195 inline const Cell2D operator-( const Cell2D &p1, const Cell2D &p2 ) 00196 { return Cell2D(p1.x_-p2.x_, p1.y_-p2.y_); } 00197 00198 inline const Cell2D operator*( const Cell2D &p, int c ) 00199 { return Cell2D(p.x_*c, p.y_*c); } 00200 00201 inline const Cell2D operator*( int c, const Cell2D &p ) 00202 { return Cell2D(p.x_*c, p.y_*c); } 00203 00204 inline const Cell2D operator-( const Cell2D &p ) 00205 { return Cell2D(-p.x_, -p.y_); } 00206 } 00207 00208 #endif 00209 00210 00211 |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)