From 8cee2782fd70e4c19196b5fdede00ffe92808b6b Mon Sep 17 00:00:00 2001 From: haller Date: Sun, 1 May 2005 00:34:40 +0000 Subject: Correction de bugs pour vector Ajout d'un programme de test pour vector Ajout du Makefile.defs dans le répertoire geometry Ca compile mais je soupçonne des erreurs --- 2005/i/robert/src/geometry/Makefile.defs | 5 ++ 2005/i/robert/src/geometry/test_vector.cc | 136 ++++++++++++++++++++++++++++++ 2005/i/robert/src/geometry/vector.hh | 3 +- 2005/i/robert/src/geometry/vector.tcc | 21 ++--- 4 files changed, 154 insertions(+), 11 deletions(-) create mode 100644 2005/i/robert/src/geometry/Makefile.defs create mode 100644 2005/i/robert/src/geometry/test_vector.cc 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 + +int main(void) +{ + geometry::VectorT vecInt (12,42); + geometry::Vector vecDouble(12.12, 42.42); + + geometry::VectorT 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(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: // }}} #include +#include namespace geometry { @@ -57,7 +58,7 @@ struct VectorT /// Rotation de pi/2. VectorT &rotate (void); /// Rotation. - VectorT &rotate (T angle); + VectorT &rotate (T angle); /// XXX L'argument angle est vraiment T?? /// Distance à un autre point. T distTo (const VectorT &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::operator* (const VectorT &v) const /// Calcule la norme. template T -VectorT::norm (void) +VectorT::norm (void) const { - return sqrt (x * x + y * y); + return static_cast(sqrt (x * x + y * y)); // XXX Il est propre le static_cast?? } /// Normalise. @@ -140,28 +140,29 @@ VectorT & VectorT::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(tx * c - y * s); // XXX C'est propre ça? + y = static_cast(tx * s + y * c); + return *this; } /// Distance à un autre point. template T -VectorT::distTo (const VectorT &v) const +VectorT::distTo (const VectorT &v) const { - return sqrt (sqDistTo (v)); + return static_cast(sqrt (sqDistTo (v))); // XXX propre?? } /// Distance à un autre point au carré. template T -VectorT::sqDistTo (const VectorT &v) const +VectorT::sqDistTo (const VectorT &v) const { double dx = x - v.x; double dy = y - v.y; - return dx * dx + dy * dy; + return static_cast(dx * dx + dy * dy); } /// Multiplication. -- cgit v1.2.3