From 41f53a65c75e5b68973848425394b4633c9b1f44 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Wed, 23 Mar 2011 14:46:29 +0000 Subject: Mofifie Straight et Curved en StraightElement et CurvedElement. --- reponses.lyx | 24 ++++++++++++------------ src/main/Curved.cc | 23 ----------------------- src/main/Curved.h | 45 --------------------------------------------- src/main/CurvedElement.cc | 23 +++++++++++++++++++++++ src/main/CurvedElement.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/main/Element.h | 3 ++- src/main/Makefile | 2 +- src/main/Straight.cc | 14 -------------- src/main/Straight.h | 42 ------------------------------------------ src/main/StraightElement.cc | 14 ++++++++++++++ src/main/StraightElement.h | 42 ++++++++++++++++++++++++++++++++++++++++++ src/test/BasicTest.cc | 8 ++++---- 12 files changed, 143 insertions(+), 142 deletions(-) delete mode 100644 src/main/Curved.cc delete mode 100644 src/main/Curved.h create mode 100644 src/main/CurvedElement.cc create mode 100644 src/main/CurvedElement.h delete mode 100644 src/main/Straight.cc delete mode 100644 src/main/Straight.h create mode 100644 src/main/StraightElement.cc create mode 100644 src/main/StraightElement.h diff --git a/reponses.lyx b/reponses.lyx index 37651ff..dff95eb 100644 --- a/reponses.lyx +++ b/reponses.lyx @@ -336,13 +336,13 @@ Element s \family typewriter \size small -[Magnetic (Straight +[Magnetic (StraightElement \family default \size default et \family typewriter \size small -Curved) +CurvedElement) \family default \size default et @@ -361,13 +361,13 @@ Element est la classe grand-mère, les trois classes filles sont les classes \family typewriter \size small - Straight + StraightElement \family default \size default , \family typewriter \size small -Curved +CurvedElement \family default \size default et @@ -380,13 +380,13 @@ Magnetic Les trois classes petites-filles sont \family typewriter \size small -MagneticStraight +MagneticStraightElement \family default \size default , \family typewriter \size small -MagneticCurved +MagneticCurvedElement \family default \size default et @@ -398,7 +398,7 @@ Electric , où \family typewriter \size small -MagneticStraight +MagneticStraightElement \family default \size default hérite à la fois de @@ -410,13 +410,13 @@ Magnetic et de \family typewriter \size small -Straight +StraightElement \family default \size default , et où \family typewriter \size small -MagneticCurved +MagneticCurvedElement \family default \size default hérite de @@ -428,7 +428,7 @@ Magnetic et de \family typewriter \size small -Curved +CurvedElement \family default \size default . @@ -441,7 +441,7 @@ Electric n'hérite 'que' de \family typewriter \size small -Straight +StraightElement \family default \size default . @@ -544,7 +544,7 @@ curved dans \family typewriter \size small -Curved.cc +CurvedElement.cc \family default \size default ). diff --git a/src/main/Curved.cc b/src/main/Curved.cc deleted file mode 100644 index f96ad6e..0000000 --- a/src/main/Curved.cc +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Curved.cc - * - * Created on: Mar 22, 2011 - * Author: jakob - */ - -#include -#include "Curved.h" - -namespace vhc { - -Curved::Curved(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double curvature, Element* next): - Element(entry, exit, sectionRadius, next), - curvature(curvature), - curvatureCenter(Vector3D::Null){} /*{ - - double k = curvature; - Vector3D midpoint = (getEntryPosition() + getExitPosition())/ 2; - curvatureCenter = midpoint + sqrt(1.0 - (k * k) / 4 * getDiagonal().normSquare()) * (getDiagonal().unit().cross(Vector3D::k)); -}*/ - -} diff --git a/src/main/Curved.h b/src/main/Curved.h deleted file mode 100644 index 8944864..0000000 --- a/src/main/Curved.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Curved.h - * - * Created on: Mar 22, 2011 - * Author: jakob - */ - -#ifndef CURVED_H_ -#define CURVED_H_ - -#include -//#include -#include "Element.h" -#include "Particle.h" -#include "Vector3D.h" - -namespace vhc { - -//TODO implement abstract methods of Element -class Curved: public Element { - -protected: - - Vector3D curvatureCenter; - double curvature; - -public: - - Curved(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double curvature, Element* next = NULL); - - virtual bool isOutside(const Particle& particle) const { - Vector3D x(particle.getPosition() - entryPosition); - return (x - Vector3D(x.getX(), x.getY(), 0).unit() / fabs(curvature)).norm() > sectionRadius; - } - - virtual bool isPast(const Particle& particle) const { - Vector3D out = (entryPosition - curvatureCenter).cross(exitPosition - curvatureCenter).cross(entryPosition - curvatureCenter); - return (particle.getPosition() - exitPosition).dot(out) > 0; - } - -}; - -} - -#endif /* CURVED_H_ */ diff --git a/src/main/CurvedElement.cc b/src/main/CurvedElement.cc new file mode 100644 index 0000000..188d042 --- /dev/null +++ b/src/main/CurvedElement.cc @@ -0,0 +1,23 @@ +/* + * CurvedElement.cc + * + * Created on: Mar 22, 2011 + * Author: jakob + */ + +#include +#include "CurvedElement.h" + +namespace vhc { + +CurvedElement::CurvedElement(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double curvature, Element* next): + Element(entry, exit, sectionRadius, next), + curvature(curvature), + curvatureCenter(Vector3D::Null){} /*{ + + double k = curvature; + Vector3D midpoint = (getEntryPosition() + getExitPosition())/ 2; + curvatureCenter = midpoint + sqrt(1.0 - (k * k) / 4 * getDiagonal().normSquare()) * (getDiagonal().unit().cross(Vector3D::k)); +}*/ + +} diff --git a/src/main/CurvedElement.h b/src/main/CurvedElement.h new file mode 100644 index 0000000..88f33b6 --- /dev/null +++ b/src/main/CurvedElement.h @@ -0,0 +1,45 @@ +/* + * CurvedElement.h + * + * Created on: Mar 22, 2011 + * Author: jakob + */ + +#ifndef CURVEDELEMENT_H_ +#define CURVEDELEMENT_H_ + +#include +//#include +#include "Element.h" +#include "Particle.h" +#include "Vector3D.h" + +namespace vhc { + +//TODO implement abstract methods of Element +class CurvedElement: public Element { + +protected: + + Vector3D curvatureCenter; + double curvature; + +public: + + CurvedElement(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double curvature, Element* next = NULL); + + virtual bool isOutside(const Particle& particle) const { + Vector3D x(particle.getPosition() - entryPosition); + return (x - Vector3D(x.getX(), x.getY(), 0).unit() / fabs(curvature)).norm() > sectionRadius; + } + + virtual bool isPast(const Particle& particle) const { + Vector3D out = (entryPosition - curvatureCenter).cross(exitPosition - curvatureCenter).cross(entryPosition - curvatureCenter); + return (particle.getPosition() - exitPosition).dot(out) > 0; + } + +}; + +} + +#endif /* CURVEDELEMENT_H_ */ diff --git a/src/main/Element.h b/src/main/Element.h index 9dfd12f..2dec462 100644 --- a/src/main/Element.h +++ b/src/main/Element.h @@ -17,6 +17,7 @@ namespace vhc { class Element { private: + /** Empêche la copie d'éléments et facilite ainsi la gestion de pointeurs. * Pourquoi aurait-on besoin de copier un élément? */ Element(const Element& e); @@ -85,7 +86,7 @@ public: /** Assigne un pointeur sur l'element suivant. */ //TODO use pointer? - void setNext(Element& n) {next = &n;} + void setNext(Element* n) {next = n;} }; diff --git a/src/main/Makefile b/src/main/Makefile index f488218..e9355bc 100644 --- a/src/main/Makefile +++ b/src/main/Makefile @@ -13,7 +13,7 @@ LOCALDIR = main # ==> Ajouter ici les objets à compiler # Si un objet nécessite une compilation non-standard (i.e. pas de règle du style Foo.o : Foo.cc Foo.h), rajouter # cette règle. -LOCALOBJS = Vector3D.o Particle.o Printable.o Element.o Curved.o Straight.o +LOCALOBJS = Vector3D.o Particle.o Printable.o Element.o CurvedElement.o StraightElement.o OBJS=$(addprefix $(BINDIR)/$(LOCALDIR)/,$(LOCALOBJS)) .PHONY = lib diff --git a/src/main/Straight.cc b/src/main/Straight.cc deleted file mode 100644 index 3a36c06..0000000 --- a/src/main/Straight.cc +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Straight.cc - * - * Created on: Mar 22, 2011 - * Author: jakob - */ - -#include "Straight.h" - -namespace vhc { - - - -} diff --git a/src/main/Straight.h b/src/main/Straight.h deleted file mode 100644 index a842b2f..0000000 --- a/src/main/Straight.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Straight.h - * - * Created on: Mar 22, 2011 - * Author: jakob - */ - -#ifndef STRAIGHT_H_ -#define STRAIGHT_H_ - -#include "Vector3D.h" -#include "Element.h" -#include "Particle.h" - -namespace vhc { - - -class Straight: public Element { - -public: - - Straight(const Vector3D& entry, const Vector3D& exit, double sectionRadius, Element* next = NULL): - Element(entry, exit, sectionRadius, next) - {}; - - //TODO ! why can't you access protected variables, i.e. entryPosition won't work?! - virtual bool isOutside(const Particle& particle) const { - Vector3D a(particle.getPosition() - entryPosition); - const Vector3D b = (particle.getPosition() - entryPosition); - return (a.cross(b)).norm() / getDiagonal().norm() > sectionRadius; - }; - - virtual bool isPast(const Particle& particle) const { - const Vector3D v(particle.getPosition() - entryPosition); - return getDiagonal().dot(v) > getDiagonal().dot(getDiagonal()); - } - -}; - -} - -#endif /* STRAIGHT_H_ */ diff --git a/src/main/StraightElement.cc b/src/main/StraightElement.cc new file mode 100644 index 0000000..d1540ec --- /dev/null +++ b/src/main/StraightElement.cc @@ -0,0 +1,14 @@ +/* + * StraightElement.cc + * + * Created on: Mar 22, 2011 + * Author: jakob + */ + +#include "StraightElement.h" + +namespace vhc { + + + +} diff --git a/src/main/StraightElement.h b/src/main/StraightElement.h new file mode 100644 index 0000000..5a1d944 --- /dev/null +++ b/src/main/StraightElement.h @@ -0,0 +1,42 @@ +/* + * StraightElement.h + * + * Created on: Mar 22, 2011 + * Author: jakob + */ + +#ifndef STRAIGHTELEMENT_H_ +#define STRAIGHTELEMENT_H_ + +#include "Vector3D.h" +#include "Element.h" +#include "Particle.h" + +namespace vhc { + + +class StraightElement: public Element { + +public: + + StraightElement(const Vector3D& entry, const Vector3D& exit, double sectionRadius, Element* next = NULL): + Element(entry, exit, sectionRadius, next) + {}; + + //TODO ! why can't you access protected variables, i.e. entryPosition won't work?! + virtual bool isOutside(const Particle& particle) const { + Vector3D a(particle.getPosition() - entryPosition); + const Vector3D b = (particle.getPosition() - entryPosition); + return (a.cross(b)).norm() / getDiagonal().norm() > sectionRadius; + }; + + virtual bool isPast(const Particle& particle) const { + const Vector3D v(particle.getPosition() - entryPosition); + return getDiagonal().dot(v) > getDiagonal().dot(getDiagonal()); + } + +}; + +} + +#endif /* STRAIGHTELEMENT_H_ */ diff --git a/src/test/BasicTest.cc b/src/test/BasicTest.cc index 7258b1c..6731675 100644 --- a/src/test/BasicTest.cc +++ b/src/test/BasicTest.cc @@ -6,17 +6,17 @@ */ #include "Element.h" -#include "Curved.h" -#include "Straight.h" +#include "CurvedElement.h" +#include "StraightElement.h" #include "Vector3D.h" using namespace vhc; int main() { - //Straight(Vector3D(0,0,0), Vector3D(1,2,0), 0.2); + //StraightElement(Vector3D(0,0,0), Vector3D(1,2,0), 0.2); - Curved(Vector3D(0,0,0), Vector3D(1,2,0), 2, 0.2); + CurvedElement(Vector3D(0,0,0), Vector3D(1,2,0), 2, 0.2); return 0; } -- cgit v1.2.3