coordinate_2d.tpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00030 #include <cmath>
00031
00032
00036 template<typename T>
00037 claw::math::coordinate_2d<T>::coordinate_2d()
00038 {
00039
00040 }
00041
00042
00046 template<typename T>
00047 template<typename U>
00048 claw::math::coordinate_2d<T>::coordinate_2d(const coordinate_2d<U>& that)
00049 : x(that.x), y(that.y)
00050 {
00051
00052 }
00053
00054
00060 template<typename T>
00061 claw::math::coordinate_2d<T>::coordinate_2d
00062 (const value_type& _x, const value_type& _y)
00063 : x(_x), y(_y)
00064 {
00065
00066 }
00067
00068
00089 template<class T>
00090 template<typename U>
00091 claw::math::coordinate_2d<U>
00092 claw::math::coordinate_2d<T>::cast_value_type_to() const
00093 {
00094 return claw::math::coordinate_2d<U>( (U)x, (U)y );
00095 }
00096
00097
00103 template<typename T>
00104 void
00105 claw::math::coordinate_2d<T>::set(const value_type& _x, const value_type& _y)
00106 {
00107 x = _x;
00108 y = _y;
00109 }
00110
00111
00116 template<typename T>
00117 typename claw::math::coordinate_2d<T>::value_type
00118 claw::math::coordinate_2d<T>::distance(const self_type& p) const
00119 {
00120 return (value_type)sqrt( (p.x - x)*(p.x - x) + (p.y - y)*(p.y - y) );
00121 }
00122
00123
00128 template<typename T>
00129 bool claw::math::coordinate_2d<T>::operator==(const self_type& that) const
00130 {
00131 return (x == that.x) && (y == that.y);
00132 }
00133
00134
00139 template<typename T>
00140 bool claw::math::coordinate_2d<T>::operator!=(const self_type& that) const
00141 {
00142 return !(*this == that);
00143 }
00144
00145
00150 template<typename T>
00151 claw::math::coordinate_2d<T>
00152 claw::math::coordinate_2d<T>::operator+(const self_type& that) const
00153 {
00154 return self_type( x + that.x, y + that.y );
00155 }
00156
00157
00162 template<typename T>
00163 claw::math::coordinate_2d<T>
00164 claw::math::coordinate_2d<T>::operator-(const self_type& that) const
00165 {
00166 return self_type( x - that.x, y - that.y );
00167 }
00168
00169
00174 template<typename T>
00175 claw::math::coordinate_2d<T>&
00176 claw::math::coordinate_2d<T>::operator+=(const self_type& that)
00177 {
00178 x += that.x;
00179 y += that.y;
00180
00181 return *this;
00182 }
00183
00184
00189 template<typename T>
00190 claw::math::coordinate_2d<T>&
00191 claw::math::coordinate_2d<T>::operator-=(const self_type& that)
00192 {
00193 x -= that.x;
00194 y -= that.y;
00195
00196 return *this;
00197 }
00198
00199
00204 template<typename T>
00205 claw::math::coordinate_2d<T>
00206 claw::math::coordinate_2d<T>::operator*(const value_type& v) const
00207 {
00208 return self_type( x * v, y * v );
00209 }
00210
00211
00216 template<typename T>
00217 claw::math::coordinate_2d<T>
00218 claw::math::coordinate_2d<T>::operator/(const value_type& v) const
00219 {
00220 return self_type( x / v, y / v );
00221 }
00222
00223
00228 template<typename T>
00229 claw::math::coordinate_2d<T>&
00230 claw::math::coordinate_2d<T>::operator*=(const value_type& v)
00231 {
00232 x *= v;
00233 y *= v;
00234
00235 return *this;
00236 }
00237
00238
00243 template<typename T>
00244 claw::math::coordinate_2d<T>&
00245 claw::math::coordinate_2d<T>::operator/=(const value_type& v)
00246 {
00247 x /= v;
00248 y /= v;
00249
00250 return *this;
00251 }
00252
00253
00258 template<typename T>
00259 claw::math::coordinate_2d<T>
00260 claw::math::operator-( const claw::math::coordinate_2d<T>& that )
00261 {
00262 return claw::math::coordinate_2d<T>(-that.x, -that.y);
00263 }
00264
00265
00271 template<typename T, typename U>
00272 claw::math::coordinate_2d<T>
00273 claw::math::operator*( U v, const coordinate_2d<T>& self )
00274 {
00275 return self * v;
00276 }