#ifndef vector_hh #define vector_hh // vector.hh // robert - programme du robot 2005. {{{ // // Copyright (C) 2005 Nicolas Schodet // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // // Contact : // Web: http://perso.efrei.fr/~schodet/ // Email: // }}} #include #include namespace geometry { /// Vecteur 2d en coordonnées carthésiennes. template struct VectorT { /// Coordonnées. T x, y; /// Constructeur par defaut. VectorT (void) { } /// Constructeur. VectorT (T x_, T y_) { x = x_; y = y_; } //@{ /// Opérations. VectorT &operator+= (const VectorT &v); VectorT &operator-= (const VectorT &v); VectorT &operator*= (T scalar); VectorT &operator/= (T scalar); VectorT operator+ (const VectorT &v) const; VectorT operator- (const VectorT &v) const; VectorT operator* (T scalar) const; VectorT operator/ (T scalar) const; //@} /// Produit scalaire. T operator* (const VectorT &v) const; /// Calcule la norme. T norm (void) const; /// Normalise. VectorT &normalize (void); /// Rotation de pi/2. VectorT &rotate (void); /// Rotation. VectorT &rotate (T angle); /// XXX L'argument angle est vraiment T?? /// Distance à un autre point. T distTo (const VectorT &v) const; /// Distance à un autre point au carré. T sqDistTo (const VectorT &v) const; }; /// Multiplication. template VectorT operator* (T scalar, const VectorT &v); /// Sortie sur un ostream. template std::ostream &operator<< (std::ostream &os, const VectorT &v); /// Vecteur de doubles. typedef VectorT Vector; } // namespace geometry #include "vector.tcc" #endif // vector_hh