summaryrefslogtreecommitdiff
path: root/2004
diff options
context:
space:
mode:
authorschodet2004-05-13 19:15:02 +0000
committerschodet2004-05-13 19:15:02 +0000
commitd45fcbc8bbfe22ffb997f9c09bd8e595bc7d75f1 (patch)
treedf6778370702d8b64470ef1358f9621218b598c2 /2004
parent4db35babdd051cb1abebfd91f1c3cc0edd15974b (diff)
Ajout d'operator.
Diffstat (limited to '2004')
-rw-r--r--2004/i/nono/src/utils/point.h74
1 files changed, 60 insertions, 14 deletions
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)