00001 #ifndef QRK_POSITION_H
00002 #define QRK_POSITION_H
00003
00015 #include "Angle.h"
00016 #include <iostream>
00017
00018
00019 namespace qrk
00020 {
00024 template<class T>
00025 class Position
00026 {
00027 public:
00028 T x;
00029 T y;
00030 Angle angle;
00031
00032
00033 Position(void) : x(0), y(0)
00034 {
00035 }
00036
00037
00038 Position(const Position& rhs) : x(rhs.x), y(rhs.y), angle(rhs.angle)
00039 {
00040 }
00041
00042
00043 Position(T x_, T y_, const Angle& angle_) : x(x_), y(y_), angle(angle_)
00044 {
00045 }
00046
00047
00048 int to_deg(void) const
00049 {
00050 return angle.to_deg();
00051 }
00052
00053
00054 double to_rad(void) const
00055 {
00056 return angle.to_rad();
00057 }
00058
00059
00060 bool operator == (const Position& rhs) const
00061 {
00062 if ((this->x == rhs.x) && (this->y == rhs.y) &&
00063 (this->angle.to_rad() == rhs.angle.to_rad())) {
00064 return true;
00065 } else {
00066 return false;
00067 }
00068 }
00069
00070
00071 Position& operator = (const Position<T>& rhs)
00072 {
00073 this->x = rhs.x;
00074 this->y = rhs.y;
00075 this->angle = rhs.angle;
00076
00077 return *this;
00078 }
00079
00080 Position<T>& operator += (const Position<T>& rhs)
00081 {
00082 this->x += rhs.x;
00083 this->y += rhs.y;
00084 this->angle += rhs.angle;
00085
00086 return *this;
00087 }
00088
00089
00090 const Position<T> operator + (const Position<T>& rhs) const
00091 {
00092 return Position<T>(*this) += rhs;
00093 }
00094
00095
00096 Position<T>& operator -= (const Position<T>& rhs)
00097 {
00098 this->x -= rhs.x;
00099 this->y -= rhs.y;
00100 this->angle -= rhs.angle;
00101
00102 return *this;
00103 }
00104
00105
00106 const Position<T> operator - (const Position<T>& rhs) const
00107 {
00108 return Position<T>(*this) -= rhs;
00109 }
00110
00111
00112 Position<T>& operator *= (const T& rhs)
00113 {
00114 this->x *= rhs;
00115 this->y *= rhs;
00116 this->angle *= rhs;
00117
00118 return *this;
00119 }
00120
00121
00122 Position<T> operator * (const T& rhs) const
00123 {
00124 Position<T> ret(*this);
00125 return ret *= rhs;
00126 }
00127
00128
00129 friend const Position<T> operator * (const T& lhs, const Position<T>& rhs)
00130 {
00131 return Position<T>(rhs) * lhs;
00132 }
00133
00134
00135 friend std::ostream& operator << (std::ostream& out,
00136 const Position<T>& rhs)
00137 {
00138 out << '(' << rhs.x << ", " << rhs.y
00139 << ", deg(" << rhs.angle.to_deg() << "))";
00140
00141 return out;
00142 }
00143 };
00144 }
00145
00146 #endif