From e1e2cdfedd447db2d1fb2b0945604790c018e0f8 Mon Sep 17 00:00:00 2001 From: schodet Date: Tue, 18 Jan 2005 21:17:23 +0000 Subject: Nettoyages, distTo, et sqDistTo --- 2005/i/robert/src/geometry/vector.hh | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to '2005/i/robert/src/geometry/vector.hh') diff --git a/2005/i/robert/src/geometry/vector.hh b/2005/i/robert/src/geometry/vector.hh index a54de2a..089656e 100644 --- a/2005/i/robert/src/geometry/vector.hh +++ b/2005/i/robert/src/geometry/vector.hh @@ -27,16 +27,18 @@ namespace geometry { -/// Vecteur 2d en coordonées carthésiennes. +/// 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_; } - VectorT (T v) { x = v; y = v; } - VectorT (const VectorT &v) { x = v.x; y = v.y; } - VectorT &operator= (const VectorT &v); + //@{ + /// Opérations. VectorT &operator+= (const VectorT &v); VectorT &operator-= (const VectorT &v); VectorT &operator*= (T scalar); @@ -44,13 +46,25 @@ struct VectorT VectorT operator+ (const VectorT &v) const; VectorT operator- (const VectorT &v) const; VectorT operator* (T scalar) const; - T operator* (const VectorT &v) 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); + /// 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); @@ -58,6 +72,7 @@ operator* (T scalar, const VectorT &v); template std::ostream &operator<< (std::ostream &os, const VectorT &v); +/// Vecteur de doubles. typedef VectorT Vector; } // namespace geometry -- cgit v1.2.3