From d45fcbc8bbfe22ffb997f9c09bd8e595bc7d75f1 Mon Sep 17 00:00:00 2001 From: schodet Date: Thu, 13 May 2004 19:15:02 +0000 Subject: Ajout d'operator. --- 2004/i/nono/src/utils/point.h | 74 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 14 deletions(-) (limited to '2004') diff --git a/2004/i/nono/src/utils/point.h b/2004/i/nono/src/utils/point.h index 28c1512..91307bc 100644 --- a/2004/i/nono/src/utils/point.h +++ b/2004/i/nono/src/utils/point.h @@ -43,15 +43,24 @@ struct Point Point operator- (void) const; Point &operator-= (const Point &rhs); Point operator- (const Point &rhs) const; - Point &operator*= (const Point &rhs); - Point operator* (const Point &rhs) const; Point &operator*= (double rhs); Point operator* (double rhs) const; + bool operator< (const Point &rhs) const; + bool operator<= (const Point &rhs) const; + bool operator== (const Point &rhs) const; //@} + /// Produit scalaire. + double operator* (const Point &rhs) const; + /// Norme. + double norm (void) const; + /// Normalise. + void normalise (void); /// Retourne la distance au carré à un autre point. double sqDistTo (const Point &rhs) const; /// Retourne la distance à un autre point. double distTo (const Point &rhs) const; + /// Fait tourner dans le sens trigo. + Point &ccw (void); }; /// Sort sur un ostream. @@ -96,31 +105,58 @@ Point::operator- (const Point &rhs) const } inline Point & -Point::operator*= (const Point &rhs) +Point::operator*= (double rhs) { - x *= rhs.x; - y *= rhs.y; + x *= rhs; + y *= rhs; return *this; } inline Point -Point::operator* (const Point &rhs) const +Point::operator* (double rhs) const { return Point (*this) *= rhs; } -inline Point & -Point::operator*= (double rhs) +inline bool +Point::operator< (const Point &rhs) const { - x *= rhs; - y *= rhs; - return *this; + return x < rhs.x && y < rhs.y; } -inline Point -Point::operator* (double rhs) const +inline bool +Point::operator<= (const Point &rhs) const { - return Point (*this) *= rhs; + return x <= rhs.x && y <= rhs.y; +} + +inline bool +Point::operator== (const Point &rhs) const +{ + return x == rhs.x && y == rhs.y; +} + +/// Produit scalaire. +inline double +Point::operator* (const Point &rhs) const +{ + return x * rhs.x + y * rhs.y; +} + +/// Norme. +inline double +Point::norm (void) const +{ + return sqrt (x * x + y * y); +} + +/// Normalise. +inline void +Point::normalise (void) +{ + double d = norm (); + x /= d; + y /= d; } /// Retourne la distance au carré à un autre point. @@ -139,6 +175,16 @@ Point::distTo (const Point &rhs) const return sqrt (sqDistTo (rhs)); } +/// Fait tourner dans le sens trigo. +inline Point & +Point::ccw (void) +{ + double t = x; + x = -y; + y = t; + return *this; +} + /// Sort sur un ostream. inline std::ostream & operator<< (std::ostream &os, const Point &p) -- cgit v1.2.3