summaryrefslogtreecommitdiff
path: root/2005/i/robert
diff options
context:
space:
mode:
Diffstat (limited to '2005/i/robert')
-rw-r--r--2005/i/robert/src/geometry/Makefile.defs5
-rw-r--r--2005/i/robert/src/geometry/test_vector.cc136
-rw-r--r--2005/i/robert/src/geometry/vector.hh3
-rw-r--r--2005/i/robert/src/geometry/vector.tcc21
4 files changed, 154 insertions, 11 deletions
diff --git a/2005/i/robert/src/geometry/Makefile.defs b/2005/i/robert/src/geometry/Makefile.defs
new file mode 100644
index 0000000..cfe9cd4
--- /dev/null
+++ b/2005/i/robert/src/geometry/Makefile.defs
@@ -0,0 +1,5 @@
+PROGRAMS += test_vector
+
+test_vector_OBJECTS = test_vector.o
+
+test_vector: $(test_vector_OBJECTS)
diff --git a/2005/i/robert/src/geometry/test_vector.cc b/2005/i/robert/src/geometry/test_vector.cc
new file mode 100644
index 0000000..bc7420c
--- /dev/null
+++ b/2005/i/robert/src/geometry/test_vector.cc
@@ -0,0 +1,136 @@
+// test_vector.cc
+// robert - programme du robot 2005 {{{
+//
+// Copyright (C) 2005 Nicolas Haller
+//
+// Robot APB Team/Efrei 2005.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// 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.
+//
+// }}}
+
+///Programme de test de la classe Vector
+
+#include "geometry/vector.hh"
+#include <iostream>
+
+int main(void)
+{
+ geometry::VectorT<int> vecInt (12,42);
+ geometry::Vector vecDouble(12.12, 42.42);
+
+ geometry::VectorT<int> testInt (12,42);
+ geometry::Vector testDouble(12.12, 42.42);
+
+ // Affichage des valeur actuelle
+
+ std::cout << "Affichage des valeurs actuelle" << std::endl;
+ std::cout << "vecInt:" << std::endl;
+ std::cout << vecInt << std::endl;
+ std::cout << "vecDouble:" << std::endl;
+ std::cout << vecDouble << std::endl;
+
+ std::cout << "Operator +=" << std::endl;
+ std::cout << "vecInt:" << std::endl;
+ std::cout << (vecInt += testInt) << std::endl;
+ std::cout << "vecDouble:" << std::endl;
+ std::cout << (vecDouble += testDouble) << std::endl;
+
+ std::cout << "Operator -=" << std::endl;
+ std::cout << "vecInt:" << std::endl;
+ std::cout << (vecInt -= testInt) << std::endl;
+ std::cout << "vecDouble:" << std::endl;
+ std::cout << (vecDouble -= testDouble) << std::endl;
+
+ std::cout << "Operator *=" << std::endl;
+ std::cout << "vecInt:" << std::endl;
+ std::cout << (vecInt *= 2) << std::endl;
+ std::cout << "vecDouble:" << std::endl;
+ std::cout << (vecDouble *= 2.0) << std::endl;
+
+ std::cout << "Operator /=" << std::endl;
+ std::cout << "vecInt:" << std::endl;
+ std::cout << (vecInt /= 2) << std::endl;
+ std::cout << "vecDouble:" << std::endl;
+ std::cout << (vecDouble /= 2.0) << std::endl;
+
+ std::cout << "Operator +" << std::endl;
+ std::cout << "vecInt:" << std::endl;
+ std::cout << (vecInt + testInt) << std::endl;
+ std::cout << "vecDouble:" << std::endl;
+ std::cout << (vecDouble + testDouble) << std::endl;
+
+ std::cout << "Operator -" << std::endl;
+ std::cout << "vecInt:" << std::endl;
+ std::cout << vecInt - testInt << std::endl;
+ std::cout << "vecDouble:" << std::endl;
+ std::cout << vecDouble - testDouble << std::endl;
+
+ std::cout << "Operator *" << std::endl;
+ std::cout << "vecInt:" << std::endl;
+ std::cout << vecInt * 2 << std::endl;
+ std::cout << "vecDouble:" << std::endl;
+ std::cout << vecDouble * 2.0 << std::endl;
+
+ std::cout << "Operator /" << std::endl;
+ std::cout << "vecInt:" << std::endl;
+ std::cout << vecInt / 2 << std::endl;
+ std::cout << "vecDouble:" << std::endl;
+ std::cout << vecDouble / 2.0 << std::endl;
+
+ std::cout << "Operator / (produit scalaire)" << std::endl;
+ std::cout << "vecInt:" << std::endl;
+ std::cout << vecInt * testInt << std::endl;
+ std::cout << "vecDouble:" << std::endl;
+ std::cout << vecDouble * testDouble << std::endl;
+
+ std::cout << "Norme" << std::endl;
+ std::cout << "vecInt:" << std::endl;
+ std::cout << vecInt.norm() << std::endl;
+ std::cout << "vecDouble:" << std::endl;
+ std::cout << vecDouble.norm() << std::endl;
+
+ std::cout << "Normalisation" << std::endl;
+ std::cout << "vecInt:" << std::endl;
+ std::cout << vecInt.normalize() << std::endl;
+ std::cout << "vecDouble:" << std::endl;
+ std::cout << vecDouble.normalize() << std::endl;
+
+ std::cout << "Rotation pi/2" << std::endl;
+ std::cout << "vecInt:" << std::endl;
+ std::cout << vecInt.rotate() << std::endl;
+ std::cout << "vecDouble:" << std::endl;
+ std::cout << vecDouble.rotate() << std::endl;
+
+ std::cout << "Rotation 2pi" << std::endl;
+ std::cout << "vecInt:" << std::endl;
+ std::cout << vecInt.rotate(static_cast<int>(2 * M_PI)) << std::endl;
+ std::cout << "vecDouble:" << std::endl;
+ std::cout << vecDouble.rotate(2 * M_PI) << std::endl;
+
+ std::cout << " distance to" << std::endl;
+ std::cout << "vecInt:" << std::endl;
+ std::cout << vecInt.distTo(testInt) << std::endl;
+ std::cout << "vecDouble:" << std::endl;
+ std::cout << vecDouble.distTo(testDouble) << std::endl;
+
+ std::cout << "sqDistTo" << std::endl;
+ std::cout << "vecInt:" << std::endl;
+ std::cout << vecInt.sqDistTo(testInt) << std::endl;
+ std::cout << "vecDouble:" << std::endl;
+ std::cout << vecDouble.sqDistTo(testDouble) << std::endl;
+}
diff --git a/2005/i/robert/src/geometry/vector.hh b/2005/i/robert/src/geometry/vector.hh
index e32f57a..6805159 100644
--- a/2005/i/robert/src/geometry/vector.hh
+++ b/2005/i/robert/src/geometry/vector.hh
@@ -24,6 +24,7 @@
// Email: <contact@ni.fr.eu.org>
// }}}
#include <cmath>
+#include <iosfwd>
namespace geometry {
@@ -57,7 +58,7 @@ struct VectorT
/// Rotation de pi/2.
VectorT<T> &rotate (void);
/// Rotation.
- VectorT<T> &rotate (T angle);
+ VectorT<T> &rotate (T angle); /// XXX L'argument angle est vraiment T??
/// Distance à un autre point.
T distTo (const VectorT<T> &v) const;
/// Distance à un autre point au carré.
diff --git a/2005/i/robert/src/geometry/vector.tcc b/2005/i/robert/src/geometry/vector.tcc
index 12120b0..7b6fa86 100644
--- a/2005/i/robert/src/geometry/vector.tcc
+++ b/2005/i/robert/src/geometry/vector.tcc
@@ -107,9 +107,9 @@ VectorT<T>::operator* (const VectorT<T> &v) const
/// Calcule la norme.
template<typename T>
T
-VectorT::norm (void)
+VectorT<T>::norm (void) const
{
- return sqrt (x * x + y * y);
+ return static_cast<T>(sqrt (x * x + y * y)); // XXX Il est propre le static_cast??
}
/// Normalise.
@@ -140,28 +140,29 @@ VectorT<T> &
VectorT<T>::rotate (T angle)
{
T tx = x;
- T c, s;
- sincos (angle, *s, *c);
- x = tx * c - y * s;
- y = tx * s + y * c;
+ double c, s;
+ sincos (angle, &s, &c);
+ x = static_cast<T>(tx * c - y * s); // XXX C'est propre ça?
+ y = static_cast<T>(tx * s + y * c);
+ return *this;
}
/// Distance à un autre point.
template<typename T>
T
-VectorT::distTo (const VectorT<T> &v) const
+VectorT<T>::distTo (const VectorT<T> &v) const
{
- return sqrt (sqDistTo (v));
+ return static_cast<T>(sqrt (sqDistTo (v))); // XXX propre??
}
/// Distance à un autre point au carré.
template<typename T>
T
-VectorT::sqDistTo (const VectorT<T> &v) const
+VectorT<T>::sqDistTo (const VectorT<T> &v) const
{
double dx = x - v.x;
double dy = y - v.y;
- return dx * dx + dy * dy;
+ return static_cast<T>(dx * dx + dy * dy);
}
/// Multiplication.