coordinate_2d.tpp

Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2008 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023   contact: julien_jorge@yahoo.fr
00024 */
00030 #include <cmath>
00031 
00032 /*----------------------------------------------------------------------------*/
00036 template<typename T>
00037 claw::math::coordinate_2d<T>::coordinate_2d()
00038 {
00039 
00040 } // coordinate_2d::coordinate_2d() [constructor]
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 } // coordinate_2d::coordinate_2d() [copy constructor]
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 } // coordinate_2d::coordinate_2d() [constructor whit values]
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 } // coordinate_2d::cast_value_type_to()
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 } // coordinate_2d::set()
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 } // coordinate_2d::distance()
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 } // coordinate_2d::operator==()
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 } // coordinate_2d::operator!=()
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 } // coordinate_2d::operator+()
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 } // coordinate_2d::operator-()
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 } // coordinate_2d::operator+=()
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 } // coordinate_2d::operator-=()
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 } // coordinate_2d::operator*()
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 } // coordinate_2d::operator/()
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 } // coordinate_2d::operator*=()
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 } // coordinate_2d::operator/=()
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 } // operator-() [coordinate_2d]
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 } // operator*() [coordinate_2d]

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1