summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/geometry/vector.hh
diff options
context:
space:
mode:
Diffstat (limited to '2005/i/robert/src/geometry/vector.hh')
-rw-r--r--2005/i/robert/src/geometry/vector.hh25
1 files changed, 20 insertions, 5 deletions
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<typename T>
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<T> &v) { x = v.x; y = v.y; }
- VectorT<T> &operator= (const VectorT<T> &v);
+ //@{
+ /// Opérations.
VectorT<T> &operator+= (const VectorT<T> &v);
VectorT<T> &operator-= (const VectorT<T> &v);
VectorT<T> &operator*= (T scalar);
@@ -44,13 +46,25 @@ struct VectorT
VectorT<T> operator+ (const VectorT<T> &v) const;
VectorT<T> operator- (const VectorT<T> &v) const;
VectorT<T> operator* (T scalar) const;
- T operator* (const VectorT<T> &v) const;
VectorT<T> operator/ (T scalar) const;
+ //@}
+ /// Produit scalaire.
+ T operator* (const VectorT<T> &v) const;
+ /// Calcule la norme.
+ T norm (void) const;
+ /// Normalise.
VectorT<T> &normalize (void);
+ /// Rotation de pi/2.
VectorT<T> &rotate (void);
+ /// Rotation.
VectorT<T> &rotate (T angle);
+ /// Distance à un autre point.
+ T distTo (const VectorT<T> &v) const;
+ /// Distance à un autre point au carré.
+ T sqDistTo (const VectorT<T> &v) const;
};
+/// Multiplication.
template<typename T>
VectorT<T>
operator* (T scalar, const VectorT<T> &v);
@@ -58,6 +72,7 @@ operator* (T scalar, const VectorT<T> &v);
template<typename T>
std::ostream &operator<< (std::ostream &os, const VectorT<T> &v);
+/// Vecteur de doubles.
typedef VectorT<double> Vector;
} // namespace geometry