Changes in / [2ad482:a7b777c]


Ignore:
Location:
src
Files:
11 deleted
26 edited

Legend:

Unmodified
Added
Removed
  • src/Box.cpp

    r2ad482 ra7b777c  
    1414#include "Matrix.hpp"
    1515#include "vector.hpp"
    16 #include "Shapes/BaseShapes.hpp"
    17 #include "Shapes/ShapeOps.hpp"
    1816
    1917#include "Helpers/Assert.hpp"
     
    141139}
    142140
    143 Shape Box::getShape() const{
    144   return transform(Cuboid(Vector(0,0,0),Vector(1,1,1)),(*M));
    145 
    146 }
    147 
    148141Box &Box::operator=(const Box &src){
    149142  if(&src!=this){
  • src/Box.hpp

    r2ad482 ra7b777c  
    1111class Matrix;
    1212class Vector;
    13 class Shape;
    1413
    1514#include <list>
     
    9089  double periodicDistance(const Vector &point1,const Vector &point2) const;
    9190
    92   Shape getShape() const;
    93 
    9491private:
    9592  Matrix *M;    //!< Defines the layout of the box
  • src/Line.cpp

    r2ad482 ra7b777c  
    3737Line::~Line()
    3838{}
    39 
    40 Line &Line::operator=(const Line& rhs){
    41   if(this!=&rhs){
    42     origin.reset(new Vector(*rhs.origin));
    43     direction.reset(new Vector(*rhs.direction));
    44   }
    45   return *this;
    46 }
    4739
    4840
     
    219211}
    220212
    221 Line Line::rotateLine(const Line &rhs, double alpha) const{
    222   Vector lineOrigin = rotateVector(rhs.getOrigin(),alpha);
    223   Vector helper = rhs.getDirection();
    224   // rotate the direction without considering the ofset
    225   pair<Vector,Vector> parts = helper.partition(*direction);
    226   Vector lineDirection = parts.first;
    227   Vector a = parts.second;
    228   if(!a.IsZero()){
    229     // construct a vector that is orthogonal to a and direction and has length |a|
    230     Vector y = a;
    231     // direction is normalized, so the result has length |a|
    232     y.VectorProduct(*direction);
    233 
    234     lineDirection += cos(alpha) * a + sin(alpha) * y;
    235   }
    236   return Line(lineOrigin,lineDirection);
    237 }
    238 
    239 Plane Line::rotatePlane(const Plane &rhs, double alpha) const{
    240   vector<Vector> points = rhs.getPointsOnPlane();
    241   transform(points.begin(),
    242             points.end(),
    243             points.begin(),
    244             boost::bind(&Line::rotateVector,this,_1,alpha));
    245   return Plane(points[0],points[1],points[2]);
    246 }
    247 
    248213Plane Line::getOrthogonalPlane(const Vector &origin) const{
    249214  return Plane(getDirection(),origin);
     
    269234}
    270235
    271 LinePoint Line::getLinePoint(const Vector &point) const{
    272   ASSERT(isContained(point),"Line point queried for point not on line");
    273   Vector helper = point - (*origin);
    274   double param = helper.ScalarProduct(*direction);
    275   return LinePoint(*this,param);
    276 }
    277 
    278 LinePoint Line::posEndpoint() const{
    279   return LinePoint(*this, numeric_limits<double>::infinity());
    280 }
    281 LinePoint Line::negEndpoint() const{
    282   return LinePoint(*this,-numeric_limits<double>::infinity());
    283 }
    284 
    285 bool operator==(const Line &x,const Line &y){
    286   return *x.origin == *y.origin && *x.direction == *y.direction;
    287 }
    288 
    289236Line makeLineThrough(const Vector &x1, const Vector &x2){
    290237  if(x1==x2){
     
    293240  return Line(x1,x1-x2);
    294241}
    295 
    296 
    297 /******************************** Points on the line ********************/
    298 
    299 LinePoint::LinePoint(const LinePoint &src) :
    300   line(src.line),param(src.param)
    301 {}
    302 
    303 LinePoint::LinePoint(const Line &_line, double _param) :
    304   line(_line),param(_param)
    305 {}
    306 
    307 LinePoint& LinePoint::operator=(const LinePoint &src){
    308   line=src.line;
    309   param=src.param;
    310   return *this;
    311 }
    312 
    313 Vector LinePoint::getPoint() const{
    314   ASSERT(!isInfinite(),"getPoint() on infinite LinePoint called");
    315   return (*line.origin)+param*(*line.direction);
    316 }
    317 
    318 Line LinePoint::getLine() const{
    319   return line;
    320 }
    321 
    322 bool LinePoint::isInfinite() const{
    323   return isPosInfinity() || isNegInfinity();
    324 }
    325 bool LinePoint::isPosInfinity() const{
    326   return param == numeric_limits<double>::infinity();
    327 }
    328 bool LinePoint::isNegInfinity() const{
    329   return param ==-numeric_limits<double>::infinity();
    330 }
    331 
    332 bool operator==(const LinePoint &x, const LinePoint &y){
    333   ASSERT(x.line==y.line,"Operation on two points of different lines");
    334   return x.param == y.param;
    335 
    336 }
    337 bool operator<(const LinePoint &x, const LinePoint &y){
    338   ASSERT(x.line==y.line,"Operation on two points of different lines");
    339   return x.param<y.param;
    340 }
  • src/Line.hpp

    r2ad482 ra7b777c  
    1616class Vector;
    1717class Plane;
    18 class LinePoint;
    1918
    2019class Line : public Space
    2120{
    22   friend bool operator==(const Line&,const Line&);
    23   friend class LinePoint;
    2421public:
    2522  Line(const Vector &_origin, const Vector &_direction);
    2623  Line(const Line& _src);
    2724  virtual ~Line();
    28 
    29   Line &operator=(const Line& rhs);
    3025
    3126  virtual double distance(const Vector &point) const;
     
    4035
    4136  Vector rotateVector(const Vector &rhs, double alpha) const;
    42   Line rotateLine(const Line &rhs, double alpha) const;
    43   Plane rotatePlane(const Plane &rhs, double alpha) const;
    4437
    4538  Plane getOrthogonalPlane(const Vector &origin) const;
    4639
    4740  std::vector<Vector> getSphereIntersections() const;
    48 
    49   LinePoint getLinePoint(const Vector&) const;
    50   LinePoint posEndpoint() const;
    51   LinePoint negEndpoint() const;
    52 
    53 
    5441
    5542private:
     
    5845};
    5946
    60 bool operator==(const Line&,const Line&);
    61 
    6247/**
    6348 * Named constructor to make a line through two points
     
    6550Line makeLineThrough(const Vector &x1, const Vector &x2);
    6651
    67 /**
    68  * Class for representing points on a line
    69  * These objects allow comparison of points on the same line as well as specifying the
    70  * infinite "endpoints" of a line.
    71  */
    72 class LinePoint{
    73   friend class Line;
    74   friend bool operator==(const LinePoint&, const LinePoint&);
    75   friend bool operator<(const LinePoint&, const LinePoint&);
    76 public:
    77   LinePoint(const LinePoint&);
    78   LinePoint& operator=(const LinePoint&);
    79   Vector getPoint() const;
    80   Line getLine() const;
    81   bool isInfinite() const;
    82   bool isPosInfinity() const;
    83   bool isNegInfinity() const;
    84 
    85 private:
    86   LinePoint(const Line&,double);
    87   Line line;
    88   double param;
    89 };
    90 
    91 bool operator==(const LinePoint&, const LinePoint&);
    92 bool operator<(const LinePoint&, const LinePoint&);
    93 
    94 inline bool operator!= (const LinePoint& x, const LinePoint& y) { return !(x==y); }
    95 inline bool operator>  (const LinePoint& x, const LinePoint& y) { return y<x; }
    96 inline bool operator<= (const LinePoint& x, const LinePoint& y) { return !(y<x); }
    97 inline bool operator>= (const LinePoint& x, const LinePoint& y) { return !(x<y); }
    98 
    99 
    10052#endif /* LINE_HPP_ */
  • src/Makefile.am

    r2ad482 ra7b777c  
    8484  Exceptions/MissingValueException.cpp \
    8585  Exceptions/NotInvertibleException.cpp \
    86   Exceptions/NotOnSurfaceException.cpp \
    87   Exceptions/ShapeException.cpp \
    8886  Exceptions/ParseError.cpp \
    8987  Exceptions/SkewException.cpp \
     
    9795  Exceptions/MissingValueException.hpp \
    9896  Exceptions/NotInvertibleException.hpp \
    99   Exceptions/NotOnSurfaceException.hpp \
    100   Exceptions/ShapeException.hpp \
    10197  Exceptions/ParseError.hpp \
    10298  Exceptions/SkewException.hpp \
     
    157153  Descriptors/AtomIdDescriptor.cpp \
    158154  Descriptors/AtomSelectionDescriptor.cpp \
    159   Descriptors/AtomShapeDescriptor.cpp \
    160155  Descriptors/AtomTypeDescriptor.cpp \
    161156  Descriptors/MoleculeDescriptor.cpp \
     
    170165  Descriptors/AtomIdDescriptor.hpp \
    171166  Descriptors/AtomSelectionDescriptor.hpp \
    172   Descriptors/AtomShapeDescriptor.hpp \
    173167  Descriptors/AtomTypeDescriptor.hpp \
    174168  Descriptors/MoleculeDescriptor.hpp \
     
    220214  leastsquaremin.cpp \
    221215  Line.cpp \
    222   LineSegment.cpp \
    223   LineSegmentSet.cpp \
    224216  linkedcell.cpp \
    225217  log.cpp \
     
    273265  leastsquaremin.hpp \
    274266  Line.hpp \
    275   LineSegment.hpp \
    276   LineSegmentSet.hpp \
    277267  linkedcell.hpp \
    278268  lists.hpp \
  • src/Matrix.cpp

    r2ad482 ra7b777c  
    213213}
    214214
    215 Matrix Matrix::transpose() const{
    216   MatrixContent *newContent = new MatrixContent();
    217   gsl_matrix_transpose_memcpy(newContent->content, content->content);
    218   Matrix res = Matrix(newContent);
    219   return res;
    220 }
    221 
    222215Matrix &Matrix::operator*=(const double factor){
    223216  gsl_matrix_scale(content->content, factor);
  • src/Matrix.hpp

    r2ad482 ra7b777c  
    9696  Matrix invert() const;
    9797
    98   Matrix transpose() const;
    99 
    10098  // operators
    10199  Matrix &operator=(const Matrix&);
  • src/Plane.cpp

    r2ad482 ra7b777c  
    1515#include "verbose.hpp"
    1616#include "Helpers/Assert.hpp"
    17 #include "helpers.hpp"
    1817#include <cmath>
    1918#include "Line.hpp"
     
    107106Plane::~Plane()
    108107{}
    109 
    110 Plane &Plane::operator=(const Plane &rhs){
    111   if(&rhs!=this){
    112     normalVector.reset(new Vector(*rhs.normalVector));
    113     offset = rhs.offset;
    114   }
    115   return *this;
    116 }
    117108
    118109
     
    197188}
    198189
    199 bool Plane::onSameSide(const Vector &point1,const Vector &point2) const{
    200   return sign(point1.ScalarProduct(*normalVector)-offset) ==
    201          sign(point2.ScalarProduct(*normalVector)-offset);
    202 }
    203 
    204190/************ Methods inherited from Space ****************/
    205191
     
    221207// Operators
    222208
    223 bool operator==(const Plane &x,const Plane &y){
    224   return *x.normalVector == *y.normalVector && x.offset == y.offset;
    225 }
    226 
    227209ostream &operator << (ostream &ost,const Plane &p){
    228210  ost << "<" << p.getNormal() << ";x> - " << p.getOffset() << "=0";
  • src/Plane.hpp

    r2ad482 ra7b777c  
    2121class Plane : public Space
    2222{
    23   friend bool operator==(const Plane&,const Plane&);
    2423  typedef std::auto_ptr<Vector> vec_ptr;
    2524public:
     
    3029  Plane(const Plane& plane);
    3130  virtual ~Plane();
    32 
    33   Plane &operator=(const Plane&);
    3431
    3532  // Accessor Functions
     
    6663  Line getOrthogonalLine(const Vector &origin) const;
    6764
    68   /**
    69    * Test if two points are on the same side of the plane
    70    */
    71   bool onSameSide(const Vector&,const Vector&) const;
    72 
    7365  /****** Methods inherited from Space ***********/
    7466
     
    8173};
    8274
    83 bool operator==(const Plane&,const Plane&);
    84 
    8575std::ostream &operator<< (std::ostream &ost,const Plane& p);
    8676
  • src/Shapes/BaseShapes.cpp

    r2ad482 ra7b777c  
    88#include "Shapes/BaseShapes.hpp"
    99#include "Shapes/BaseShapes_impl.hpp"
    10 #include "Shapes/ShapeOps.hpp"
    1110
    1211#include "vector.hpp"
    13 #include "Helpers/Assert.hpp"
    14 
    15 #include "Line.hpp"
    16 #include "Plane.hpp"
    17 #include "LineSegment.hpp"
    18 #include "LineSegmentSet.hpp"
    19 
    20 #include <cmath>
    21 #include <algorithm>
    2212
    2313bool Sphere_impl::isInside(const Vector &point){
    2414  return point.NormSquared()<=1;
    25 }
    26 
    27 bool Sphere_impl::isOnSurface(const Vector &point){
    28   return fabs(point.NormSquared()-1)<MYEPSILON;
    29 }
    30 
    31 Vector Sphere_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){
    32   if(!isOnSurface(point)){
    33     throw NotOnSurfaceException(__FILE__,__LINE__);
    34   }
    35   return point;
    36 }
    37 
    38 LineSegmentSet Sphere_impl::getLineIntersections(const Line &line){
    39   LineSegmentSet res(line);
    40   std::vector<Vector> intersections = line.getSphereIntersections();
    41   if(intersections.size()==2){
    42     res.insert(LineSegment(intersections[0],intersections[1]));
    43   }
    44   return res;
    45 }
    46 
    47 string Sphere_impl::toString(){
    48   return "Sphere()";
    4915}
    5016
     
    5420}
    5521
    56 Shape Sphere(const Vector &center,double radius){
    57   return translate(resize(Sphere(),radius),center);
    58 }
    59 
    60 Shape Ellipsoid(const Vector &center, const Vector &radius){
    61   return translate(stretch(Sphere(),radius),center);
    62 }
    63 
    6422bool Cuboid_impl::isInside(const Vector &point){
    65   return fabs(point[0])<=1 && fabs(point[1])<=1 && fabs(point[2])<=1;
    66 }
    67 
    68 bool Cuboid_impl::isOnSurface(const Vector &point){
    69   bool retVal = isInside(point);
    70   // test all borders of the cuboid
    71   // double fabs
    72   retVal = retVal &&
    73            ((fabs(fabs(point[0])-1)  < MYEPSILON) ||
    74             (fabs(fabs(point[1])-1)  < MYEPSILON) ||
    75             (fabs(fabs(point[2])-1)  < MYEPSILON));
    76   return retVal;
    77 }
    78 
    79 Vector Cuboid_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){
    80   if(!isOnSurface(point)){
    81     throw NotOnSurfaceException(__FILE__,__LINE__);
    82   }
    83   Vector res;
    84   // figure out on which sides the Vector lies (maximum 3, when it is in a corner)
    85   for(int i=NDIM;i--;){
    86     if(fabs(fabs(point[i])-1)<MYEPSILON){
    87       // add the scaled (-1/+1) Vector to the set of surface vectors
    88       res[i] = point[i];
    89     }
    90   }
    91   ASSERT(res.NormSquared()>=1 && res.NormSquared()<=3,"To many or to few sides found for this Vector");
    92 
    93   res.Normalize();
    94   return res;
    95 }
    96 
    97 LineSegmentSet Cuboid_impl::getLineIntersections(const Line &line){
    98   LineSegmentSet res(line);
    99   // get the intersection on each of the six faces
    100   vector<Vector> intersections;
    101   intersections.resize(2);
    102   int c=0;
    103   int x[2]={-1,+1};
    104   for(int i=NDIM;i--;){
    105     for(int p=0;p<2;++p){
    106       if(c==2) goto end; // I know this sucks, but breaking two loops is stupid
    107       Vector base;
    108       base[i]=x[p];
    109       // base now points to the surface and is normal to it at the same time
    110       Plane p(base,base);
    111       Vector intersection = p.GetIntersection(line);
    112       if(isInside(intersection)){
    113         // if we have a point on the edge it might already be contained
    114         if(c==1 && intersections[0]==intersection)
    115           continue;
    116         intersections[c++]=intersection;
    117       }
    118     }
    119   }
    120   end:
    121   if(c==2){
    122     res.insert(LineSegment(intersections[0],intersections[1]));
    123   }
    124   return res;
    125 }
    126 
    127 string Cuboid_impl::toString(){
    128   return "Cuboid()";
     23  return point[0]<=1 && point[1]<=1 && point[2]<=1;
    12924}
    13025
    13126Shape Cuboid(){
    132   Shape::impl_ptr impl = Shape::impl_ptr(new Cuboid_impl());
     27  Shape::impl_ptr impl = Shape::impl_ptr(new Sphere_impl());
    13328  return Shape(impl);
    13429}
    135 
    136 Shape Cuboid(const Vector &corner1, const Vector &corner2){
    137   // make sure the two edges are upper left front and lower right back
    138   Vector sortedC1;
    139   Vector sortedC2;
    140   for(int i=NDIM;i--;){
    141     sortedC1[i] = min(corner1[i],corner2[i]);
    142     sortedC2[i] = max(corner1[i],corner2[i]);
    143     ASSERT(corner1[i]!=corner2[i],"Given points for cuboid edges did not define a valid space");
    144   }
    145   // get the middle point
    146   Vector middle = (1./2.)*(sortedC1+sortedC2);
    147   Vector factors = sortedC2-middle;
    148   return translate(stretch(Cuboid(),factors),middle);
    149 }
  • src/Shapes/BaseShapes.hpp

    r2ad482 ra7b777c  
    1212
    1313Shape Sphere();
    14 Shape Sphere(const Vector &center,double radius);
    15 Shape Ellipsoid(const Vector &center, const Vector &radius);
    1614Shape Cuboid();
    17 Shape Cuboid(const Vector &corner1, const Vector &corner2);
    1815
    1916#endif /* BASESHAPES_HPP_ */
  • src/Shapes/BaseShapes_impl.hpp

    r2ad482 ra7b777c  
    1313class Sphere_impl : public Shape_impl {
    1414  virtual bool isInside(const Vector &point);
    15   virtual bool isOnSurface(const Vector &point);
    16   virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
    17   virtual LineSegmentSet getLineIntersections(const Line&);
    18   virtual std::string toString();
    1915};
    2016
    2117class Cuboid_impl : public Shape_impl {
    2218  virtual bool isInside(const Vector &point);
    23   virtual bool isOnSurface(const Vector &point);
    24   virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
    25   virtual LineSegmentSet getLineIntersections(const Line&);
    26   virtual std::string toString();
    2719};
    2820
  • src/Shapes/Shape.cpp

    r2ad482 ra7b777c  
    88#include "Shape.hpp"
    99#include "Shape_impl.hpp"
    10 
    11 #include "Helpers/Assert.hpp"
    12 
    13 #include <string>
    14 
    15 using namespace std;
    1610
    1711Shape::Shape(const Shape& src) :
     
    2519}
    2620
    27 bool Shape::isOnSurface(const Vector &point) const{
    28   return impl->isOnSurface(point);
    29 }
    30 
    31 Vector Shape::getNormal(const Vector &point) const throw (NotOnSurfaceException){
    32   return impl->getNormal(point);
    33 }
    34 
    35 LineSegmentSet Shape::getLineIntersections(const Line &line){
    36   return impl->getLineIntersections(line);
    37 }
    38 
    3921Shape::Shape(Shape::impl_ptr _impl) :
    4022    impl(_impl)
     
    4628  }
    4729  return *this;
    48 }
    49 
    50 std::string Shape::toString() const{
    51   return impl->toString();
    5230}
    5331
     
    8765}
    8866
    89 bool AndShape_impl::isOnSurface(const Vector &point){
    90   // check the number of surfaces that this point is on
    91   int surfaces =0;
    92   surfaces += lhs->isOnSurface(point);
    93   surfaces += rhs->isOnSurface(point);
    94 
    95   switch(surfaces){
    96     case 0:
    97       return false;
    98       // no break necessary
    99     case 1:
    100       // if it is inside for the object where it does not lie on
    101       // the surface the whole point lies inside
    102       return (lhs->isOnSurface(point) && rhs->isInside(point)) ||
    103              (rhs->isOnSurface(point) && lhs->isInside(point));
    104       // no break necessary
    105     case 2:
    106       {
    107         // it lies on both Shapes... could be an edge or an inner point
    108         // test the direction of the normals
    109         Vector direction=lhs->getNormal(point)+rhs->getNormal(point);
    110         // if the directions are opposite we lie on the inside
    111         return !direction.IsZero();
    112       }
    113       // no break necessary
    114     default:
    115       // if this happens there is something wrong
    116       ASSERT(0,"Default case should have never been used");
    117   }
    118   return false; // never reached
    119 }
    120 
    121 Vector AndShape_impl::getNormal(const Vector &point) throw (NotOnSurfaceException){
    122   Vector res;
    123   if(!isOnSurface(point)){
    124     throw NotOnSurfaceException(__FILE__,__LINE__);
    125   }
    126   res += lhs->isOnSurface(point)?lhs->getNormal(point):zeroVec;
    127   res += rhs->isOnSurface(point)?rhs->getNormal(point):zeroVec;
    128   res.Normalize();
    129   return res;
    130 }
    131 
    132 LineSegmentSet AndShape_impl::getLineIntersections(const Line &line){
    133   return intersect(lhs->getLineIntersections(line),rhs->getLineIntersections(line));
    134 }
    135 
    136 string AndShape_impl::toString(){
    137   return string("(") + lhs->toString() + string("&&") + rhs->toString() + string(")");
    138 }
    139 
    14067Shape operator&&(const Shape &lhs,const Shape &rhs){
    14168  Shape::impl_ptr newImpl = Shape::impl_ptr(new AndShape_impl(getShapeImpl(lhs),getShapeImpl(rhs)));
     
    15380bool OrShape_impl::isInside(const Vector &point){
    15481  return rhs->isInside(point) || lhs->isInside(point);
    155 }
    156 
    157 bool OrShape_impl::isOnSurface(const Vector &point){
    158   // check the number of surfaces that this point is on
    159   int surfaces =0;
    160   surfaces += lhs->isOnSurface(point);
    161   surfaces += rhs->isOnSurface(point);
    162 
    163   switch(surfaces){
    164     case 0:
    165       return false;
    166       // no break necessary
    167     case 1:
    168       // if it is inside for the object where it does not lie on
    169       // the surface the whole point lies inside
    170       return (lhs->isOnSurface(point) && !rhs->isInside(point)) ||
    171              (rhs->isOnSurface(point) && !lhs->isInside(point));
    172       // no break necessary
    173     case 2:
    174       {
    175         // it lies on both Shapes... could be an edge or an inner point
    176         // test the direction of the normals
    177         Vector direction=lhs->getNormal(point)+rhs->getNormal(point);
    178         // if the directions are opposite we lie on the inside
    179         return !direction.IsZero();
    180       }
    181       // no break necessary
    182     default:
    183       // if this happens there is something wrong
    184       ASSERT(0,"Default case should have never been used");
    185   }
    186   return false; // never reached
    187 }
    188 
    189 Vector OrShape_impl::getNormal(const Vector &point) throw (NotOnSurfaceException){
    190   Vector res;
    191   if(!isOnSurface(point)){
    192     throw NotOnSurfaceException(__FILE__,__LINE__);
    193   }
    194   res += lhs->isOnSurface(point)?lhs->getNormal(point):zeroVec;
    195   res += rhs->isOnSurface(point)?rhs->getNormal(point):zeroVec;
    196   res.Normalize();
    197   return res;
    198 }
    199 
    200 LineSegmentSet OrShape_impl::getLineIntersections(const Line &line){
    201   return merge(lhs->getLineIntersections(line),rhs->getLineIntersections(line));
    202 }
    203 
    204 string OrShape_impl::toString(){
    205   return string("(") + lhs->toString() + string("||") + rhs->toString() + string(")");
    20682}
    20783
     
    22399}
    224100
    225 bool NotShape_impl::isOnSurface(const Vector &point){
    226   return arg->isOnSurface(point);
    227 }
    228 
    229 Vector NotShape_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){
    230   return -1*arg->getNormal(point);
    231 }
    232 
    233 LineSegmentSet NotShape_impl::getLineIntersections(const Line &line){
    234   return invert(arg->getLineIntersections(line));
    235 }
    236 
    237 string NotShape_impl::toString(){
    238   return string("!") + arg->toString();
    239 }
    240 
    241101Shape operator!(const Shape &arg){
    242102  Shape::impl_ptr newImpl = Shape::impl_ptr(new NotShape_impl(getShapeImpl(arg)));
    243103  return Shape(newImpl);
    244104}
    245 
    246 /**************** global operations *********************************/
    247 ostream &operator<<(ostream &ost,const Shape &shape){
    248   ost << shape.toString();
    249   return ost;
    250 }
  • src/Shapes/Shape.hpp

    r2ad482 ra7b777c  
    1010
    1111#include <boost/shared_ptr.hpp>
    12 #include <iosfwd>
    13 
    14 #include "Exceptions/NotOnSurfaceException.hpp"
    1512
    1613class Vector;
    1714class Shape_impl;
    18 class LineSegmentSet;
    19 class Line;
    2015
    2116class Shape
     
    3025
    3126  bool isInside(const Vector &point) const;
    32   bool isOnSurface(const Vector &point) const;
    33   Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
    34 
    35   LineSegmentSet getLineIntersections(const Line&);
    3627
    3728  Shape &operator=(const Shape& rhs);
    3829
    39   std::string toString() const;
    4030protected:
    4131  impl_ptr getImpl() const;
     
    5242Shape operator!(const Shape&);
    5343
    54 std::ostream &operator<<(std::ostream&,const Shape&);
    55 
    5644#endif /* SHAPE_HPP_ */
  • src/Shapes/ShapeOps.cpp

    r2ad482 ra7b777c  
    1111#include "Helpers/Assert.hpp"
    1212
    13 /*************** Base case ***********************/
    14 
    15 ShapeOpsBase_impl::ShapeOpsBase_impl(const Shape::impl_ptr &_arg) :
    16   arg(_arg){}
    17 
    18 ShapeOpsBase_impl::~ShapeOpsBase_impl(){}
    19 
    20 bool ShapeOpsBase_impl::isInside(const Vector &point){
    21   return arg->isInside(translateIn(point));
    22 }
    23 
    24 bool ShapeOpsBase_impl::isOnSurface(const Vector &point){
    25   return arg->isOnSurface(translateIn(point));
    26 }
    27 
    28 Vector ShapeOpsBase_impl::getNormal(const Vector &point) throw (NotOnSurfaceException){
    29   Vector helper = translateIn(point);
    30   if(!arg->isOnSurface(helper)){
    31     throw NotOnSurfaceException(__FILE__,__LINE__);
    32   }
    33   Vector res = translateOutNormal(arg->getNormal(helper));
    34   res.Normalize();
    35   return res;
    36 }
    37 
    38 LineSegmentSet ShapeOpsBase_impl::getLineIntersections(const Line &line){
    39   Line newLine(translateIn(line.getOrigin()),translateIn(line.getDirection()));
    40   LineSegmentSet res(line);
    41   LineSegmentSet helper = getArg()->getLineIntersections(newLine);
    42   for(LineSegmentSet::iterator iter = helper.begin();iter!=helper.end();++iter){
    43     LinePoint lpBegin = iter->getBegin();
    44     LinePoint lpEnd = iter->getBegin();
    45     // translate both linepoints
    46     lpBegin = lpBegin.isNegInfinity()?
    47                 line.negEndpoint():
    48                 line.getLinePoint(translateOutPos(lpBegin.getPoint()));
    49     lpEnd = lpEnd.isPosInfinity()?
    50               line.posEndpoint():
    51               line.getLinePoint(translateOutPos(lpEnd.getPoint()));
    52     res.insert(LineSegment(lpBegin,lpEnd));
    53   }
    54   return res;
    55 }
    56 
    57 Shape::impl_ptr ShapeOpsBase_impl::getArg(){
    58   return arg;
    59 }
    60 
    6113/********************* Resize ********************/
    6214
    6315Resize_impl::Resize_impl(const Shape::impl_ptr &_arg,double _size) :
    64   ShapeOpsBase_impl(_arg), size(_size)
     16  arg(_arg), size(_size)
    6517{
    6618  ASSERT(size>0,"Cannot resize a Shape to size zero or below");
     
    6921Resize_impl::~Resize_impl(){}
    7022
    71 Vector Resize_impl::translateIn(const Vector& point){
    72   return (1/size) * point;
    73 }
    74 
    75 Vector Resize_impl::translateOutPos(const Vector& point){
    76   return size * point;
    77 }
    78 
    79 Vector Resize_impl::translateOutNormal(const Vector& point){
    80   return point;
    81 }
    82 
    83 string Resize_impl::toString(){
    84   stringstream sstr;
    85   sstr << "resize(" << getArg()->toString() << "," << size << ")";
    86   return sstr.str();
     23bool Resize_impl::isInside(const Vector& point){
     24  return arg->isInside((1/size) * point);
    8725}
    8826
     
    9533
    9634Translate_impl::Translate_impl(const Shape::impl_ptr &_arg, const Vector &_offset) :
    97   ShapeOpsBase_impl(_arg),offset(_offset)
     35  arg(_arg),offset(_offset)
    9836{}
    9937
    10038Translate_impl::~Translate_impl(){}
    10139
    102 Vector Translate_impl::translateIn(const Vector& point){
    103   return point-offset;
    104 }
    105 
    106 Vector Translate_impl::translateOutPos(const Vector& point){
    107   return point+offset;
    108 }
    109 
    110 Vector Translate_impl::translateOutNormal(const Vector& point){
    111   return point;
    112 }
    113 
    114 string Translate_impl::toString(){
    115   stringstream sstr;
    116   sstr << "translate(" << getArg()->toString() << "," << offset << ")";
    117   return sstr.str();
     40bool Translate_impl::isInside(const Vector& point){
     41  return arg->isInside(point-offset);
    11842}
    11943
     
    12650
    12751Stretch_impl::Stretch_impl(const Shape::impl_ptr &_arg, const Vector &_factors) :
    128   ShapeOpsBase_impl(_arg),factors(_factors)
     52  arg(_arg),factors(_factors)
    12953{
    13054  ASSERT(factors[0]>0,"cannot stretch a shape by a negative amount");
     
    13862Stretch_impl::~Stretch_impl(){}
    13963
    140 Vector Stretch_impl::translateIn(const Vector& point){
     64bool Stretch_impl::isInside(const Vector& point){
    14165  Vector helper=point;
    14266  helper.ScaleAll(reciFactors);
    143   return helper;
    144 }
    145 
    146 Vector Stretch_impl::translateOutPos(const Vector& point){
    147   Vector helper=point;
    148   helper.ScaleAll(factors);
    149   return helper;
    150 }
    151 
    152 Vector Stretch_impl::translateOutNormal(const Vector& point){
    153   Vector helper=point;
    154   // the normalFactors are derived from appearances of the factors
    155   // with in the vectorproduct
    156   Vector normalFactors;
    157   normalFactors[0]=factors[1]*factors[2];
    158   normalFactors[1]=factors[0]*factors[2];
    159   normalFactors[2]=factors[0]*factors[1];
    160   helper.ScaleAll(normalFactors);
    161   return helper;
    162 }
    163 
    164 string Stretch_impl::toString(){
    165   stringstream sstr;
    166   sstr << "stretch(" << getArg()->toString() << "," << factors << ")";
    167   return sstr.str();
     67  return arg->isInside(helper);
    16868}
    16969
     
    17676
    17777Transform_impl::Transform_impl(const Shape::impl_ptr &_arg, const Matrix &_transformation) :
    178   ShapeOpsBase_impl(_arg),transformation(_transformation)
     78  arg(_arg),transformation(_transformation)
    17979{
    18080  transformationInv = transformation.invert();
     
    18383Transform_impl::~Transform_impl(){}
    18484
    185 Vector Transform_impl::translateIn(const Vector& point){
    186   return transformationInv * point;
    187 }
    188 
    189 Vector Transform_impl::translateOutPos(const Vector& point){
    190   return transformation * point;
    191 }
    192 
    193 Vector Transform_impl::translateOutNormal(const Vector& point){
    194   Matrix mat = transformation.invert().transpose();
    195   return mat * point;
    196 }
    197 
    198 string Transform_impl::toString(){
    199   stringstream sstr;
    200   sstr << "transform(" << getArg()->toString() << "," << transformation << ")";
    201   return sstr.str();
     85bool Transform_impl::isInside(const Vector& point){
     86  return arg->isInside(transformationInv * point);
    20287}
    20388
  • src/Shapes/ShapeOps_impl.hpp

    r2ad482 ra7b777c  
    1313#include "Matrix.hpp"
    1414
    15 class ShapeOpsBase_impl : public Shape_impl{
    16 public:
    17   ShapeOpsBase_impl(const Shape::impl_ptr&);
    18   virtual ~ShapeOpsBase_impl();
    19   virtual bool isInside(const Vector &point);
    20   virtual bool isOnSurface(const Vector &point);
    21   virtual Vector getNormal(const Vector &point) throw (NotOnSurfaceException);
    22   virtual LineSegmentSet getLineIntersections(const Line&);
    23 protected:
    24   virtual Vector translateIn(const Vector &point)=0;
    25   virtual Vector translateOutPos(const Vector &point)=0;
    26   virtual Vector translateOutNormal(const Vector &point)=0;
    27   Shape::impl_ptr getArg();
    28 private:
    29   Shape::impl_ptr arg;
    30 };
    31 
    32 class Resize_impl :  public ShapeOpsBase_impl
     15class Resize_impl :  public Shape_impl
    3316{
    3417public:
    3518  Resize_impl(const Shape::impl_ptr&,double);
    3619  virtual ~Resize_impl();
    37 protected:
    38   virtual Vector translateIn(const Vector &point);
    39   virtual Vector translateOutPos(const Vector &point);
    40   virtual Vector translateOutNormal(const Vector &point);
    41   virtual std::string toString();
     20  virtual bool isInside(const Vector& point);
    4221private:
     22  Shape::impl_ptr arg;
    4323  double size;
    4424};
    4525
    46 class Translate_impl :  public ShapeOpsBase_impl
     26class Translate_impl :  public Shape_impl
    4727{
    4828public:
    4929  Translate_impl(const Shape::impl_ptr&, const Vector&);
    5030  virtual ~Translate_impl();
    51 protected:
    52   virtual Vector translateIn(const Vector &point);
    53   virtual Vector translateOutPos(const Vector &point);
    54   virtual Vector translateOutNormal(const Vector &point);
    55   virtual std::string toString();
     31  virtual bool isInside(const Vector& point);
    5632private:
     33  Shape::impl_ptr arg;
    5734  Vector offset;
    5835};
    5936
    60 class Stretch_impl : public ShapeOpsBase_impl
     37class Stretch_impl : public Shape_impl
    6138{
    6239public:
    6340  Stretch_impl(const Shape::impl_ptr&, const Vector&);
    6441  virtual ~Stretch_impl();
    65 protected:
    66   virtual Vector translateIn(const Vector &point);
    67   virtual Vector translateOutPos(const Vector &point);
    68   virtual Vector translateOutNormal(const Vector &point);
    69   virtual std::string toString();
     42  virtual bool isInside(const Vector& point);
    7043private:
     44  Shape::impl_ptr arg;
    7145  Vector factors;
    7246  Vector reciFactors;
    7347};
    7448
    75 class Transform_impl : public ShapeOpsBase_impl
     49class Transform_impl : public Shape_impl
    7650{
    7751public:
    7852  Transform_impl(const Shape::impl_ptr&, const Matrix&);
    7953  virtual ~Transform_impl();
    80 protected:
    81   virtual Vector translateIn(const Vector &point);
    82   virtual Vector translateOutPos(const Vector &point);
    83   virtual Vector translateOutNormal(const Vector &point);
    84   virtual std::string toString();
     54  virtual bool isInside(const Vector& point);
    8555private:
     56  Shape::impl_ptr arg;
    8657  Matrix transformation;
    8758  Matrix transformationInv;
  • src/Shapes/Shape_impl.hpp

    r2ad482 ra7b777c  
    1010
    1111#include "Shapes/Shape.hpp"
    12 #include "vector.hpp"
    13 #include "Line.hpp"
    14 #include "LineSegment.hpp"
    15 #include "LineSegmentSet.hpp"
    16 
    1712
    1813class Shape_impl {
     
    2116  virtual ~Shape_impl(){};
    2217  virtual bool isInside(const Vector &point)=0;
    23   virtual bool isOnSurface(const Vector &point)=0;
    24   virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException)=0;
    25   virtual LineSegmentSet getLineIntersections(const Line&)=0;
    26   virtual std::string toString()=0;
    2718};
    2819
     
    3223    return true;
    3324  }
    34   virtual bool isOnSurface(const Vector &point){
    35     return false;
    36   }
    37   virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException){
    38     throw NotOnSurfaceException(__FILE__,__LINE__);
    39   }
    40   virtual LineSegmentSet getLineIntersections(const Line &line){
    41     LineSegmentSet res(line);
    42     res.insert(LineSegment(line.negEndpoint(),line.posEndpoint()));
    43     return res;
    44   }
    45   virtual std::string toString(){
    46     return "Everywhere()";
    47   }
    4825};
    4926
     
    5128  virtual bool isInside(const Vector &point){
    5229    return false;
    53   }
    54   virtual bool isOnSurface(const Vector &point){
    55     return false;
    56   }
    57   virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException){
    58     throw NotOnSurfaceException(__FILE__,__LINE__);
    59   }
    60   virtual LineSegmentSet getLineIntersections(const Line &line){
    61     return LineSegmentSet(line);
    62   }
    63   virtual std::string toString(){
    64     return "Nowhere()";
    6530  }
    6631};
     
    7136  virtual ~AndShape_impl();
    7237  virtual bool isInside(const Vector &point);
    73   virtual bool isOnSurface(const Vector &point);
    74   virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
    75   virtual LineSegmentSet getLineIntersections(const Line&);
    76   virtual std::string toString();
    7738private:
    7839  Shape::impl_ptr lhs;
     
    8546  virtual ~OrShape_impl();
    8647  virtual bool isInside(const Vector &point);
    87   virtual bool isOnSurface(const Vector &point);
    88   virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
    89   virtual LineSegmentSet getLineIntersections(const Line&);
    90   virtual std::string toString();
    9148private:
    9249  Shape::impl_ptr lhs;
     
    9956  virtual ~NotShape_impl();
    10057  virtual bool isInside(const Vector &point);
    101   virtual bool isOnSurface(const Vector &point);
    102   virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
    103   virtual LineSegmentSet getLineIntersections(const Line&);
    104   virtual std::string toString();
    10558private:
    10659  Shape::impl_ptr arg;
  • src/helpers.cpp

    r2ad482 ra7b777c  
    141141  exit(255);
    142142}
    143 
    144 sign_t sign(double value){
    145   if(fabs(value)<MYEPSILON){
    146     return Zero;
    147   }
    148   if(value<0)
    149     return Minus;
    150   else
    151     return Plus;
    152 }
  • src/helpers.hpp

    r2ad482 ra7b777c  
    4444  //__attribute__ ((__return__));
    4545
    46 typedef enum {
    47   Minus = -1,
    48   Zero = 0,
    49   Plus = +1
    50 } sign_t;
    51 
    5246double ask_value(const char *text);
    5347bool check_bounds(double *x, double *cell_size);
     
    5852int CompareDoubles (const void * a, const void * b);
    5953void performCriticalExit();
    60 sign_t sign(double value);
    6154
    6255/********************************************** helpful template functions *********************************/
  • src/unittests/LineUnittest.cpp

    r2ad482 ra7b777c  
    2929void LineUnittest::setUp(){
    3030  // three lines along the axes
    31   la1 = new Line(zeroVec,unitVec[0]);
    32   la2 = new Line(zeroVec,unitVec[1]);
    33   la3 = new Line(zeroVec,unitVec[2]);
     31  la1 = new Line(zeroVec,e1);
     32  la2 = new Line(zeroVec,e2);
     33  la3 = new Line(zeroVec,e3);
    3434
    3535  // the lines along the planes defined by two coordinate axes
    36   lp1 = new Line(unitVec[0],unitVec[0]-unitVec[1]);
    37   lp2 = new Line(unitVec[1],unitVec[1]-unitVec[2]);
    38   lp3 = new Line(unitVec[2],unitVec[2]-unitVec[0]);
     36  lp1 = new Line(e1,e1-e2);
     37  lp2 = new Line(e2,e2-e3);
     38  lp3 = new Line(e3,e3-e1);
    3939}
    4040void LineUnittest::tearDown(){
     
    5252
    5353  // direction+origin should never fail
    54   CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,unitVec[0]));
    55   CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,unitVec[1]));
    56   CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,unitVec[2]));
     54  CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,e1));
     55  CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,e2));
     56  CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,e3));
    5757
    5858  // two points fails if both points are the same
    59   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[0],unitVec[1]));
    60   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[1],unitVec[2]));
    61   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[2],unitVec[0]));
     59  CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e1,e2));
     60  CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e2,e3));
     61  CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e3,e1));
    6262  // for zerovectors
    63   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[0],zeroVec));
    64   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[1],zeroVec));
    65   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[2],zeroVec));
     63  CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e1,zeroVec));
     64  CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e2,zeroVec));
     65  CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e3,zeroVec));
    6666  // now we pass two times the same point
    6767  CPPUNIT_ASSERT_THROW(makeLineThrough(zeroVec,zeroVec),LinearDependenceException);
    68   CPPUNIT_ASSERT_THROW(makeLineThrough(unitVec[0],unitVec[0]),LinearDependenceException);
    69   CPPUNIT_ASSERT_THROW(makeLineThrough(unitVec[1],unitVec[1]),LinearDependenceException);
    70   CPPUNIT_ASSERT_THROW(makeLineThrough(unitVec[2],unitVec[2]),LinearDependenceException);
     68  CPPUNIT_ASSERT_THROW(makeLineThrough(e1,e1),LinearDependenceException);
     69  CPPUNIT_ASSERT_THROW(makeLineThrough(e2,e2),LinearDependenceException);
     70  CPPUNIT_ASSERT_THROW(makeLineThrough(e3,e3),LinearDependenceException);
    7171
    7272}
     
    7878void LineUnittest::constructionResultTest(){
    7979  // test all directions
    80   CPPUNIT_ASSERT(testDirection(la1->getDirection(),unitVec[0]));
    81   CPPUNIT_ASSERT(testDirection(la2->getDirection(),unitVec[1]));
    82   CPPUNIT_ASSERT(testDirection(la3->getDirection(),unitVec[2]));
     80  CPPUNIT_ASSERT(testDirection(la1->getDirection(),e1));
     81  CPPUNIT_ASSERT(testDirection(la2->getDirection(),e2));
     82  CPPUNIT_ASSERT(testDirection(la3->getDirection(),e3));
    8383
    8484  // test origins
     
    9292  CPPUNIT_ASSERT(la3->isContained(zeroVec));
    9393
    94   CPPUNIT_ASSERT(la1->isContained(unitVec[0]));
    95   CPPUNIT_ASSERT(la2->isContained(unitVec[1]));
    96   CPPUNIT_ASSERT(la3->isContained(unitVec[2]));
    97 
    98   CPPUNIT_ASSERT(lp1->isContained(unitVec[0]));
    99   CPPUNIT_ASSERT(lp2->isContained(unitVec[1]));
    100   CPPUNIT_ASSERT(lp3->isContained(unitVec[2]));
    101 
    102   CPPUNIT_ASSERT(lp1->isContained(unitVec[1]));
    103   CPPUNIT_ASSERT(lp2->isContained(unitVec[2]));
    104   CPPUNIT_ASSERT(lp3->isContained(unitVec[0]));
     94  CPPUNIT_ASSERT(la1->isContained(e1));
     95  CPPUNIT_ASSERT(la2->isContained(e2));
     96  CPPUNIT_ASSERT(la3->isContained(e3));
     97
     98  CPPUNIT_ASSERT(lp1->isContained(e1));
     99  CPPUNIT_ASSERT(lp2->isContained(e2));
     100  CPPUNIT_ASSERT(lp3->isContained(e3));
     101
     102  CPPUNIT_ASSERT(lp1->isContained(e2));
     103  CPPUNIT_ASSERT(lp2->isContained(e3));
     104  CPPUNIT_ASSERT(lp3->isContained(e1));
    105105}
    106106
     
    112112
    113113  // multiples of the second support vector
    114   CPPUNIT_ASSERT(la1->isContained(unitVec[0]));
    115   CPPUNIT_ASSERT(la2->isContained(unitVec[1]));
    116   CPPUNIT_ASSERT(la3->isContained(unitVec[2]));
    117 
    118   CPPUNIT_ASSERT(la1->isContained(2*unitVec[0]));
    119   CPPUNIT_ASSERT(la2->isContained(2*unitVec[1]));
    120   CPPUNIT_ASSERT(la3->isContained(2*unitVec[2]));
    121 
    122   CPPUNIT_ASSERT(la1->isContained(3*unitVec[0]));
    123   CPPUNIT_ASSERT(la2->isContained(3*unitVec[1]));
    124   CPPUNIT_ASSERT(la3->isContained(3*unitVec[2]));
     114  CPPUNIT_ASSERT(la1->isContained(e1));
     115  CPPUNIT_ASSERT(la2->isContained(e2));
     116  CPPUNIT_ASSERT(la3->isContained(e3));
     117
     118  CPPUNIT_ASSERT(la1->isContained(2*e1));
     119  CPPUNIT_ASSERT(la2->isContained(2*e2));
     120  CPPUNIT_ASSERT(la3->isContained(2*e3));
     121
     122  CPPUNIT_ASSERT(la1->isContained(3*e1));
     123  CPPUNIT_ASSERT(la2->isContained(3*e2));
     124  CPPUNIT_ASSERT(la3->isContained(3*e3));
    125125
    126126  // negative multiples
    127   CPPUNIT_ASSERT(la1->isContained(-1*unitVec[0]));
    128   CPPUNIT_ASSERT(la2->isContained(-1*unitVec[1]));
    129   CPPUNIT_ASSERT(la3->isContained(-1*unitVec[2]));
    130 
    131   CPPUNIT_ASSERT(la1->isContained(-2*unitVec[0]));
    132   CPPUNIT_ASSERT(la2->isContained(-2*unitVec[1]));
    133   CPPUNIT_ASSERT(la3->isContained(-2*unitVec[2]));
     127  CPPUNIT_ASSERT(la1->isContained(-1*e1));
     128  CPPUNIT_ASSERT(la2->isContained(-1*e2));
     129  CPPUNIT_ASSERT(la3->isContained(-1*e3));
     130
     131  CPPUNIT_ASSERT(la1->isContained(-2*e1));
     132  CPPUNIT_ASSERT(la2->isContained(-2*e2));
     133  CPPUNIT_ASSERT(la3->isContained(-2*e3));
    134134
    135135  // points that should not be on the lines
    136   CPPUNIT_ASSERT(!la1->isContained(unitVec[1]));
    137   CPPUNIT_ASSERT(!la2->isContained(unitVec[2]));
    138   CPPUNIT_ASSERT(!la3->isContained(unitVec[0]));
    139 
    140   CPPUNIT_ASSERT(!la1->isContained(2*unitVec[1]));
    141   CPPUNIT_ASSERT(!la2->isContained(2*unitVec[2]));
    142   CPPUNIT_ASSERT(!la3->isContained(2*unitVec[0]));
    143 
    144   CPPUNIT_ASSERT(!la1->isContained(-1*unitVec[1]));
    145   CPPUNIT_ASSERT(!la2->isContained(-1*unitVec[2]));
    146   CPPUNIT_ASSERT(!la3->isContained(-1*unitVec[0]));
     136  CPPUNIT_ASSERT(!la1->isContained(e2));
     137  CPPUNIT_ASSERT(!la2->isContained(e3));
     138  CPPUNIT_ASSERT(!la3->isContained(e1));
     139
     140  CPPUNIT_ASSERT(!la1->isContained(2*e2));
     141  CPPUNIT_ASSERT(!la2->isContained(2*e3));
     142  CPPUNIT_ASSERT(!la3->isContained(2*e1));
     143
     144  CPPUNIT_ASSERT(!la1->isContained(-1*e2));
     145  CPPUNIT_ASSERT(!la2->isContained(-1*e3));
     146  CPPUNIT_ASSERT(!la3->isContained(-1*e1));
    147147
    148148  // For the plane lines
    149   CPPUNIT_ASSERT(lp1->isContained(unitVec[0]));
    150   CPPUNIT_ASSERT(lp2->isContained(unitVec[1]));
    151   CPPUNIT_ASSERT(lp3->isContained(unitVec[2]));
    152 
    153   CPPUNIT_ASSERT(lp1->isContained(unitVec[1]));
    154   CPPUNIT_ASSERT(lp2->isContained(unitVec[2]));
    155   CPPUNIT_ASSERT(lp3->isContained(unitVec[0]));
    156 
    157   CPPUNIT_ASSERT(lp1->isContained(unitVec[0]+2*(unitVec[0]-unitVec[1])));
    158   CPPUNIT_ASSERT(lp2->isContained(unitVec[1]+2*(unitVec[1]-unitVec[2])));
    159   CPPUNIT_ASSERT(lp3->isContained(unitVec[2]+2*(unitVec[2]-unitVec[0])));
    160 
    161   CPPUNIT_ASSERT(lp1->isContained(unitVec[0]-2*(unitVec[0]-unitVec[1])));
    162   CPPUNIT_ASSERT(lp2->isContained(unitVec[1]-2*(unitVec[1]-unitVec[2])));
    163   CPPUNIT_ASSERT(lp3->isContained(unitVec[2]-2*(unitVec[2]-unitVec[0])));
     149  CPPUNIT_ASSERT(lp1->isContained(e1));
     150  CPPUNIT_ASSERT(lp2->isContained(e2));
     151  CPPUNIT_ASSERT(lp3->isContained(e3));
     152
     153  CPPUNIT_ASSERT(lp1->isContained(e2));
     154  CPPUNIT_ASSERT(lp2->isContained(e3));
     155  CPPUNIT_ASSERT(lp3->isContained(e1));
     156
     157  CPPUNIT_ASSERT(lp1->isContained(e1+2*(e1-e2)));
     158  CPPUNIT_ASSERT(lp2->isContained(e2+2*(e2-e3)));
     159  CPPUNIT_ASSERT(lp3->isContained(e3+2*(e3-e1)));
     160
     161  CPPUNIT_ASSERT(lp1->isContained(e1-2*(e1-e2)));
     162  CPPUNIT_ASSERT(lp2->isContained(e2-2*(e2-e3)));
     163  CPPUNIT_ASSERT(lp3->isContained(e3-2*(e3-e1)));
    164164}
    165165
     
    177177  // axes and plane lines
    178178  fixture = la1->getIntersection(*lp1);
    179   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
     179  CPPUNIT_ASSERT_EQUAL(fixture,e1);
    180180  fixture = la2->getIntersection(*lp2);
    181   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
     181  CPPUNIT_ASSERT_EQUAL(fixture,e2);
    182182  fixture = la3->getIntersection(*lp3);
    183   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
     183  CPPUNIT_ASSERT_EQUAL(fixture,e3);
    184184
    185185  fixture = la1->getIntersection(*lp3);
    186   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
     186  CPPUNIT_ASSERT_EQUAL(fixture,e1);
    187187  fixture = la2->getIntersection(*lp1);
    188   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
     188  CPPUNIT_ASSERT_EQUAL(fixture,e2);
    189189  fixture = la3->getIntersection(*lp2);
    190   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
     190  CPPUNIT_ASSERT_EQUAL(fixture,e3);
    191191
    192192  // two plane lines
    193193  fixture = lp1->getIntersection(*lp2);
    194   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
     194  CPPUNIT_ASSERT_EQUAL(fixture,e2);
    195195  fixture = lp2->getIntersection(*lp3);
    196   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
     196  CPPUNIT_ASSERT_EQUAL(fixture,e3);
    197197  fixture = lp3->getIntersection(*lp1);
    198   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
     198  CPPUNIT_ASSERT_EQUAL(fixture,e1);
    199199
    200200  // When we have two times the same line, we check if the point is on the line
     
    242242
    243243  // rotate vectors on the axis around their lines
    244   fixture = la1->rotateVector(unitVec[0],1.);
    245   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
    246   fixture = la2->rotateVector(unitVec[1],1.);
    247   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
    248   fixture = la3->rotateVector(unitVec[2],1.);
    249   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    250 
    251   fixture = la1->rotateVector(unitVec[0],2.);
    252   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
    253   fixture = la2->rotateVector(unitVec[1],2.);
    254   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
    255   fixture = la3->rotateVector(unitVec[2],2.);
    256   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
     244  fixture = la1->rotateVector(e1,1.);
     245  CPPUNIT_ASSERT_EQUAL(fixture,e1);
     246  fixture = la2->rotateVector(e2,1.);
     247  CPPUNIT_ASSERT_EQUAL(fixture,e2);
     248  fixture = la3->rotateVector(e3,1.);
     249  CPPUNIT_ASSERT_EQUAL(fixture,e3);
     250
     251  fixture = la1->rotateVector(e1,2.);
     252  CPPUNIT_ASSERT_EQUAL(fixture,e1);
     253  fixture = la2->rotateVector(e2,2.);
     254  CPPUNIT_ASSERT_EQUAL(fixture,e2);
     255  fixture = la3->rotateVector(e3,2.);
     256  CPPUNIT_ASSERT_EQUAL(fixture,e3);
    257257
    258258  // more vectors on the axis
    259   fixture = la1->rotateVector(2*unitVec[0],1.);
    260   CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[0]);
    261   fixture = la2->rotateVector(2*unitVec[1],1.);
    262   CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[1]);
    263   fixture = la3->rotateVector(2*unitVec[2],1.);
    264   CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[2]);
    265 
    266   fixture = la1->rotateVector(2*unitVec[0],2.);
    267   CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[0]);
    268   fixture = la2->rotateVector(2*unitVec[1],2.);
    269   CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[1]);
    270   fixture = la3->rotateVector(2*unitVec[2],2.);
    271   CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[2]);
     259  fixture = la1->rotateVector(2*e1,1.);
     260  CPPUNIT_ASSERT_EQUAL(fixture,2*e1);
     261  fixture = la2->rotateVector(2*e2,1.);
     262  CPPUNIT_ASSERT_EQUAL(fixture,2*e2);
     263  fixture = la3->rotateVector(2*e3,1.);
     264  CPPUNIT_ASSERT_EQUAL(fixture,2*e3);
     265
     266  fixture = la1->rotateVector(2*e1,2.);
     267  CPPUNIT_ASSERT_EQUAL(fixture,2*e1);
     268  fixture = la2->rotateVector(2*e2,2.);
     269  CPPUNIT_ASSERT_EQUAL(fixture,2*e2);
     270  fixture = la3->rotateVector(2*e3,2.);
     271  CPPUNIT_ASSERT_EQUAL(fixture,2*e3);
    272272
    273273  // negative factors
    274   fixture = la1->rotateVector(-1*unitVec[0],1.);
    275   CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
    276   fixture = la2->rotateVector(-1*unitVec[1],1.);
    277   CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
    278   fixture = la3->rotateVector(-1*unitVec[2],1.);
    279   CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
    280 
    281   fixture = la1->rotateVector(-1*unitVec[0],2.);
    282   CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
    283   fixture = la2->rotateVector(-1*unitVec[1],2.);
    284   CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
    285   fixture = la3->rotateVector(-1*unitVec[2],2.);
    286   CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
     274  fixture = la1->rotateVector(-1*e1,1.);
     275  CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
     276  fixture = la2->rotateVector(-1*e2,1.);
     277  CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
     278  fixture = la3->rotateVector(-1*e3,1.);
     279  CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
     280
     281  fixture = la1->rotateVector(-1*e1,2.);
     282  CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
     283  fixture = la2->rotateVector(-1*e2,2.);
     284  CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
     285  fixture = la3->rotateVector(-1*e3,2.);
     286  CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
    287287
    288288
    289289
    290290  // now the real rotations
    291   // unitVec[1] around unitVec[0]
    292   fixture = la1->rotateVector(unitVec[1],0);
    293   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
    294   fixture = la1->rotateVector(unitVec[1],1./2.*M_PI);
    295   CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
    296   fixture = la1->rotateVector(unitVec[1],M_PI);
    297   CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
    298   fixture = la1->rotateVector(unitVec[1],2*M_PI);
    299   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
    300 
    301   // unitVec[2] around unitVec[1]
    302   fixture = la2->rotateVector(unitVec[2],0);
    303   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    304   fixture = la2->rotateVector(unitVec[2],1./2.*M_PI);
    305   CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
    306   fixture = la2->rotateVector(unitVec[2],M_PI);
    307   CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
    308   fixture = la2->rotateVector(unitVec[2],2*M_PI);
    309   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    310 
    311   // unitVec[0] around unitVec[2]
    312   fixture = la3->rotateVector(unitVec[0],0);
    313   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
    314   fixture = la3->rotateVector(unitVec[0],1./2.*M_PI);
    315   CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
    316   fixture = la3->rotateVector(unitVec[0],M_PI);
    317   CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
    318   fixture = la3->rotateVector(unitVec[0],2*M_PI);
    319   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
     291  // e2 around e1
     292  fixture = la1->rotateVector(e2,0);
     293  CPPUNIT_ASSERT_EQUAL(fixture,e2);
     294  fixture = la1->rotateVector(e2,1./2.*M_PI);
     295  CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
     296  fixture = la1->rotateVector(e2,M_PI);
     297  CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
     298  fixture = la1->rotateVector(e2,2*M_PI);
     299  CPPUNIT_ASSERT_EQUAL(fixture,e2);
     300
     301  // e3 around e2
     302  fixture = la2->rotateVector(e3,0);
     303  CPPUNIT_ASSERT_EQUAL(fixture,e3);
     304  fixture = la2->rotateVector(e3,1./2.*M_PI);
     305  CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
     306  fixture = la2->rotateVector(e3,M_PI);
     307  CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
     308  fixture = la2->rotateVector(e3,2*M_PI);
     309  CPPUNIT_ASSERT_EQUAL(fixture,e3);
     310
     311  // e1 around e3
     312  fixture = la3->rotateVector(e1,0);
     313  CPPUNIT_ASSERT_EQUAL(fixture,e1);
     314  fixture = la3->rotateVector(e1,1./2.*M_PI);
     315  CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
     316  fixture = la3->rotateVector(e1,M_PI);
     317  CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
     318  fixture = la3->rotateVector(e1,2*M_PI);
     319  CPPUNIT_ASSERT_EQUAL(fixture,e1);
    320320
    321321
     
    323323
    324324  // Vectors on the line
    325   fixture = lp1->rotateVector(unitVec[0],1.);
    326   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
    327   fixture = lp1->rotateVector(unitVec[1],1.);
    328   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
    329 
    330   fixture = lp2->rotateVector(unitVec[1],1.);
    331   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
    332   fixture = lp2->rotateVector(unitVec[2],1.);
    333   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    334 
    335   fixture = lp3->rotateVector(unitVec[2],1.);
    336   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    337   fixture = lp3->rotateVector(unitVec[0],1.);
    338   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
     325  fixture = lp1->rotateVector(e1,1.);
     326  CPPUNIT_ASSERT_EQUAL(fixture,e1);
     327  fixture = lp1->rotateVector(e2,1.);
     328  CPPUNIT_ASSERT_EQUAL(fixture,e2);
     329
     330  fixture = lp2->rotateVector(e2,1.);
     331  CPPUNIT_ASSERT_EQUAL(fixture,e2);
     332  fixture = lp2->rotateVector(e3,1.);
     333  CPPUNIT_ASSERT_EQUAL(fixture,e3);
     334
     335  fixture = lp3->rotateVector(e3,1.);
     336  CPPUNIT_ASSERT_EQUAL(fixture,e3);
     337  fixture = lp3->rotateVector(e1,1.);
     338  CPPUNIT_ASSERT_EQUAL(fixture,e1);
    339339
    340340  // the real stuff
     
    358358    std::vector<Vector> res = la1->getSphereIntersections();
    359359    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
    360     CPPUNIT_ASSERT(testDirection(res[0],unitVec[0]));
    361     CPPUNIT_ASSERT(testDirection(res[1],unitVec[0]));
     360    CPPUNIT_ASSERT(testDirection(res[0],e1));
     361    CPPUNIT_ASSERT(testDirection(res[1],e1));
    362362    CPPUNIT_ASSERT(res[0]!=res[1]);
    363363  }
     
    366366    std::vector<Vector> res = la2->getSphereIntersections();
    367367    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
    368     CPPUNIT_ASSERT(testDirection(res[0],unitVec[1]));
    369     CPPUNIT_ASSERT(testDirection(res[1],unitVec[1]));
     368    CPPUNIT_ASSERT(testDirection(res[0],e2));
     369    CPPUNIT_ASSERT(testDirection(res[1],e2));
    370370    CPPUNIT_ASSERT(res[0]!=res[1]);
    371371  }
     
    374374    std::vector<Vector> res = la3->getSphereIntersections();
    375375    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
    376     CPPUNIT_ASSERT(testDirection(res[0],unitVec[2]));
    377     CPPUNIT_ASSERT(testDirection(res[1],unitVec[2]));
     376    CPPUNIT_ASSERT(testDirection(res[0],e3));
     377    CPPUNIT_ASSERT(testDirection(res[1],e3));
    378378    CPPUNIT_ASSERT(res[0]!=res[1]);
    379379  }
     
    382382    std::vector<Vector> res = lp1->getSphereIntersections();
    383383    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
    384     CPPUNIT_ASSERT((res[0]==unitVec[0]) || (res[0]==unitVec[1]));
    385     CPPUNIT_ASSERT((res[1]==unitVec[0]) || (res[1]==unitVec[1]));
     384    CPPUNIT_ASSERT((res[0]==e1) || (res[0]==e2));
     385    CPPUNIT_ASSERT((res[1]==e1) || (res[1]==e2));
    386386    CPPUNIT_ASSERT(res[0]!=res[1]);
    387387  }
     
    390390    std::vector<Vector> res = lp2->getSphereIntersections();
    391391    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
    392     CPPUNIT_ASSERT((res[0]==unitVec[1]) || (res[0]==unitVec[2]));
    393     CPPUNIT_ASSERT((res[1]==unitVec[1]) || (res[1]==unitVec[2]));
     392    CPPUNIT_ASSERT((res[0]==e2) || (res[0]==e3));
     393    CPPUNIT_ASSERT((res[1]==e2) || (res[1]==e3));
    394394    CPPUNIT_ASSERT(res[0]!=res[1]);
    395395  }
     
    398398    std::vector<Vector> res = lp3->getSphereIntersections();
    399399    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
    400     CPPUNIT_ASSERT((res[0]==unitVec[2]) || (res[0]==unitVec[0]));
    401     CPPUNIT_ASSERT((res[1]==unitVec[2]) || (res[1]==unitVec[0]));
    402     CPPUNIT_ASSERT(res[0]!=res[1]);
    403   }
    404 }
     400    CPPUNIT_ASSERT((res[0]==e3) || (res[0]==e1));
     401    CPPUNIT_ASSERT((res[1]==e3) || (res[1]==e1));
     402    CPPUNIT_ASSERT(res[0]!=res[1]);
     403  }
     404}
  • src/unittests/MatrixUnittest.cpp

    r2ad482 ra7b777c  
    3939  }
    4040  perm1 = new Matrix();
    41   perm1->column(0) = unitVec[0];
    42   perm1->column(1) = unitVec[2];
    43   perm1->column(2) = unitVec[1];
     41  perm1->column(0) = e1;
     42  perm1->column(1) = e3;
     43  perm1->column(2) = e2;
    4444
    4545
    4646  perm2 = new Matrix();
    47   perm2->column(0) = unitVec[1];
    48   perm2->column(1) = unitVec[0];
    49   perm2->column(2) = unitVec[2];
     47  perm2->column(0) = e2;
     48  perm2->column(1) = e1;
     49  perm2->column(2) = e3;
    5050
    5151  perm3 = new Matrix();
    52   perm3->column(0) = unitVec[1];
    53   perm3->column(1) = unitVec[2];
    54   perm3->column(2) = unitVec[0];
     52  perm3->column(0) = e2;
     53  perm3->column(1) = e3;
     54  perm3->column(2) = e1;
    5555
    5656  perm4 = new Matrix();
    57   perm4->column(0) = unitVec[2];
    58   perm4->column(1) = unitVec[1];
    59   perm4->column(2) = unitVec[0];
     57  perm4->column(0) = e3;
     58  perm4->column(1) = e2;
     59  perm4->column(2) = e1;
    6060
    6161  perm5 = new Matrix();
    62   perm5->column(0) = unitVec[2];
    63   perm5->column(1) = unitVec[0];
    64   perm5->column(2) = unitVec[1];
     62  perm5->column(0) = e3;
     63  perm5->column(1) = e1;
     64  perm5->column(2) = e2;
    6565
    6666}
     
    108108
    109109  mat.one();
    110   CPPUNIT_ASSERT_EQUAL(mat.row(0),unitVec[0]);
    111   CPPUNIT_ASSERT_EQUAL(mat.row(1),unitVec[1]);
    112   CPPUNIT_ASSERT_EQUAL(mat.row(2),unitVec[2]);
    113   CPPUNIT_ASSERT_EQUAL(mat.column(0),unitVec[0]);
    114   CPPUNIT_ASSERT_EQUAL(mat.column(1),unitVec[1]);
    115   CPPUNIT_ASSERT_EQUAL(mat.column(2),unitVec[2]);
     110  CPPUNIT_ASSERT_EQUAL(mat.row(0),e1);
     111  CPPUNIT_ASSERT_EQUAL(mat.row(1),e2);
     112  CPPUNIT_ASSERT_EQUAL(mat.row(2),e3);
     113  CPPUNIT_ASSERT_EQUAL(mat.column(0),e1);
     114  CPPUNIT_ASSERT_EQUAL(mat.column(1),e2);
     115  CPPUNIT_ASSERT_EQUAL(mat.column(2),e3);
    116116
    117117  Vector t1=Vector(1.,1.,1.);
     
    204204
    205205  res = (*diagonal)*(*perm1);
    206   CPPUNIT_ASSERT_EQUAL(res.column(0),unitVec[0]);
    207   CPPUNIT_ASSERT_EQUAL(res.column(1),3*unitVec[2]);
    208   CPPUNIT_ASSERT_EQUAL(res.column(2),2*unitVec[1]);
     206  CPPUNIT_ASSERT_EQUAL(res.column(0),e1);
     207  CPPUNIT_ASSERT_EQUAL(res.column(1),3*e3);
     208  CPPUNIT_ASSERT_EQUAL(res.column(2),2*e2);
    209209  res = (*diagonal)*(*perm2);
    210   CPPUNIT_ASSERT_EQUAL(res.column(0),2*unitVec[1]);
    211   CPPUNIT_ASSERT_EQUAL(res.column(1),unitVec[0]);
    212   CPPUNIT_ASSERT_EQUAL(res.column(2),3*unitVec[2]);
     210  CPPUNIT_ASSERT_EQUAL(res.column(0),2*e2);
     211  CPPUNIT_ASSERT_EQUAL(res.column(1),e1);
     212  CPPUNIT_ASSERT_EQUAL(res.column(2),3*e3);
    213213  res = (*diagonal)*(*perm3);
    214   CPPUNIT_ASSERT_EQUAL(res.column(0),2*unitVec[1]);
    215   CPPUNIT_ASSERT_EQUAL(res.column(1),3*unitVec[2]);
    216   CPPUNIT_ASSERT_EQUAL(res.column(2),unitVec[0]);
     214  CPPUNIT_ASSERT_EQUAL(res.column(0),2*e2);
     215  CPPUNIT_ASSERT_EQUAL(res.column(1),3*e3);
     216  CPPUNIT_ASSERT_EQUAL(res.column(2),e1);
    217217  res = (*diagonal)*(*perm4);
    218   CPPUNIT_ASSERT_EQUAL(res.column(0),3*unitVec[2]);
    219   CPPUNIT_ASSERT_EQUAL(res.column(1),2*unitVec[1]);
    220   CPPUNIT_ASSERT_EQUAL(res.column(2),unitVec[0]);
     218  CPPUNIT_ASSERT_EQUAL(res.column(0),3*e3);
     219  CPPUNIT_ASSERT_EQUAL(res.column(1),2*e2);
     220  CPPUNIT_ASSERT_EQUAL(res.column(2),e1);
    221221  res = (*diagonal)*(*perm5);
    222   CPPUNIT_ASSERT_EQUAL(res.column(0),3*unitVec[2]);
    223   CPPUNIT_ASSERT_EQUAL(res.column(1),unitVec[0]);
    224   CPPUNIT_ASSERT_EQUAL(res.column(2),2*unitVec[1]);
     222  CPPUNIT_ASSERT_EQUAL(res.column(0),3*e3);
     223  CPPUNIT_ASSERT_EQUAL(res.column(1),e1);
     224  CPPUNIT_ASSERT_EQUAL(res.column(2),2*e2);
    225225}
    226226
     
    261261
    262262void MatrixUnittest::VecMultTest(){
    263   CPPUNIT_ASSERT_EQUAL((*zero)*unitVec[0],zeroVec);
    264   CPPUNIT_ASSERT_EQUAL((*zero)*unitVec[1],zeroVec);
    265   CPPUNIT_ASSERT_EQUAL((*zero)*unitVec[2],zeroVec);
     263  CPPUNIT_ASSERT_EQUAL((*zero)*e1,zeroVec);
     264  CPPUNIT_ASSERT_EQUAL((*zero)*e2,zeroVec);
     265  CPPUNIT_ASSERT_EQUAL((*zero)*e3,zeroVec);
    266266  CPPUNIT_ASSERT_EQUAL((*zero)*zeroVec,zeroVec);
    267267
    268   CPPUNIT_ASSERT_EQUAL((*one)*unitVec[0],unitVec[0]);
    269   CPPUNIT_ASSERT_EQUAL((*one)*unitVec[1],unitVec[1]);
    270   CPPUNIT_ASSERT_EQUAL((*one)*unitVec[2],unitVec[2]);
     268  CPPUNIT_ASSERT_EQUAL((*one)*e1,e1);
     269  CPPUNIT_ASSERT_EQUAL((*one)*e2,e2);
     270  CPPUNIT_ASSERT_EQUAL((*one)*e3,e3);
    271271  CPPUNIT_ASSERT_EQUAL((*one)*zeroVec,zeroVec);
    272272
    273   CPPUNIT_ASSERT_EQUAL((*diagonal)*unitVec[0],unitVec[0]);
    274   CPPUNIT_ASSERT_EQUAL((*diagonal)*unitVec[1],2*unitVec[1]);
    275   CPPUNIT_ASSERT_EQUAL((*diagonal)*unitVec[2],3*unitVec[2]);
     273  CPPUNIT_ASSERT_EQUAL((*diagonal)*e1,e1);
     274  CPPUNIT_ASSERT_EQUAL((*diagonal)*e2,2*e2);
     275  CPPUNIT_ASSERT_EQUAL((*diagonal)*e3,3*e3);
    276276  CPPUNIT_ASSERT_EQUAL((*diagonal)*zeroVec,zeroVec);
    277277
    278   CPPUNIT_ASSERT_EQUAL((*perm1)*unitVec[0],unitVec[0]);
    279   CPPUNIT_ASSERT_EQUAL((*perm1)*unitVec[1],unitVec[2]);
    280   CPPUNIT_ASSERT_EQUAL((*perm1)*unitVec[2],unitVec[1]);
     278  CPPUNIT_ASSERT_EQUAL((*perm1)*e1,e1);
     279  CPPUNIT_ASSERT_EQUAL((*perm1)*e2,e3);
     280  CPPUNIT_ASSERT_EQUAL((*perm1)*e3,e2);
    281281  CPPUNIT_ASSERT_EQUAL((*perm1)*zeroVec,zeroVec);
    282282
    283   CPPUNIT_ASSERT_EQUAL((*perm2)*unitVec[0],unitVec[1]);
    284   CPPUNIT_ASSERT_EQUAL((*perm2)*unitVec[1],unitVec[0]);
    285   CPPUNIT_ASSERT_EQUAL((*perm2)*unitVec[2],unitVec[2]);
     283  CPPUNIT_ASSERT_EQUAL((*perm2)*e1,e2);
     284  CPPUNIT_ASSERT_EQUAL((*perm2)*e2,e1);
     285  CPPUNIT_ASSERT_EQUAL((*perm2)*e3,e3);
    286286  CPPUNIT_ASSERT_EQUAL((*perm2)*zeroVec,zeroVec);
    287287
    288   CPPUNIT_ASSERT_EQUAL((*perm3)*unitVec[0],unitVec[1]);
    289   CPPUNIT_ASSERT_EQUAL((*perm3)*unitVec[1],unitVec[2]);
    290   CPPUNIT_ASSERT_EQUAL((*perm3)*unitVec[2],unitVec[0]);
     288  CPPUNIT_ASSERT_EQUAL((*perm3)*e1,e2);
     289  CPPUNIT_ASSERT_EQUAL((*perm3)*e2,e3);
     290  CPPUNIT_ASSERT_EQUAL((*perm3)*e3,e1);
    291291  CPPUNIT_ASSERT_EQUAL((*perm3)*zeroVec,zeroVec);
    292292
    293   CPPUNIT_ASSERT_EQUAL((*perm4)*unitVec[0],unitVec[2]);
    294   CPPUNIT_ASSERT_EQUAL((*perm4)*unitVec[1],unitVec[1]);
    295   CPPUNIT_ASSERT_EQUAL((*perm4)*unitVec[2],unitVec[0]);
     293  CPPUNIT_ASSERT_EQUAL((*perm4)*e1,e3);
     294  CPPUNIT_ASSERT_EQUAL((*perm4)*e2,e2);
     295  CPPUNIT_ASSERT_EQUAL((*perm4)*e3,e1);
    296296  CPPUNIT_ASSERT_EQUAL((*perm4)*zeroVec,zeroVec);
    297297
    298   CPPUNIT_ASSERT_EQUAL((*perm5)*unitVec[0],unitVec[2]);
    299   CPPUNIT_ASSERT_EQUAL((*perm5)*unitVec[1],unitVec[0]);
    300   CPPUNIT_ASSERT_EQUAL((*perm5)*unitVec[2],unitVec[1]);
     298  CPPUNIT_ASSERT_EQUAL((*perm5)*e1,e3);
     299  CPPUNIT_ASSERT_EQUAL((*perm5)*e2,e1);
     300  CPPUNIT_ASSERT_EQUAL((*perm5)*e3,e2);
    301301  CPPUNIT_ASSERT_EQUAL((*perm5)*zeroVec,zeroVec);
    302302
  • src/unittests/PlaneUnittest.cpp

    r2ad482 ra7b777c  
    2424
    2525void PlaneUnittest::setUp(){
    26   p1 = new Plane(unitVec[0],unitVec[1],unitVec[2]);
    27   p2 = new Plane(unitVec[0],unitVec[1],zeroVec);
    28   p3 = new Plane(unitVec[0],zeroVec,unitVec[2]);
    29   p4 = new Plane(zeroVec,unitVec[1],unitVec[2]);
     26  p1 = new Plane(e1,e2,e3);
     27  p2 = new Plane(e1,e2,zeroVec);
     28  p3 = new Plane(e1,zeroVec,e3);
     29  p4 = new Plane(zeroVec,e2,e3);
    3030}
    3131
     
    4242
    4343  // three points
    44   CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],unitVec[1],unitVec[2]));
     44  CPPUNIT_ASSERT_NO_THROW(Plane(e1,e2,e3));
    4545  // when only two points are differnt this gives an error
    46   CPPUNIT_ASSERT_THROW(Plane(unitVec[0],unitVec[1],unitVec[1]),LinearDependenceException);
     46  CPPUNIT_ASSERT_THROW(Plane(e1,e2,e2),LinearDependenceException);
    4747  // same with only one point
    48   CPPUNIT_ASSERT_THROW(Plane(unitVec[0],unitVec[0],unitVec[0]),LinearDependenceException);
     48  CPPUNIT_ASSERT_THROW(Plane(e1,e1,e1),LinearDependenceException);
    4949
    5050  // use two vector giving two directions
    51   CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],unitVec[1],0));
     51  CPPUNIT_ASSERT_NO_THROW(Plane(e1,e2,0));
    5252  // and again this is actually only one vector
    53   CPPUNIT_ASSERT_THROW(Plane(unitVec[0],unitVec[0],0),LinearDependenceException);
     53  CPPUNIT_ASSERT_THROW(Plane(e1,e1,0),LinearDependenceException);
    5454  // Zero vector does not give a good direction
    55   CPPUNIT_ASSERT_THROW(Plane(unitVec[0],zeroVec,0),ZeroVectorException);
     55  CPPUNIT_ASSERT_THROW(Plane(e1,zeroVec,0),ZeroVectorException);
    5656
    5757  // use a normalvector and an scalar offset
    58   CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],0));
     58  CPPUNIT_ASSERT_NO_THROW(Plane(e1,0));
    5959  // The zero vector is no good as a normalvector
    6060  CPPUNIT_ASSERT_THROW(Plane(zeroVec,0),ZeroVectorException);
    6161
    6262  // use a normalvector and an offset vector
    63   CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],zeroVec));
     63  CPPUNIT_ASSERT_NO_THROW(Plane(e1,zeroVec));
    6464  // and the bad zeroVector again
    6565  CPPUNIT_ASSERT_THROW(Plane(zeroVec,zeroVec),ZeroVectorException);
     
    7575  {
    7676    // construct with three points on plane
    77     Plane p1(unitVec[0],unitVec[1],zeroVec);
    78     CPPUNIT_ASSERT(testNormal(unitVec[2],p1.getNormal()));
     77    Plane p1(e1,e2,zeroVec);
     78    CPPUNIT_ASSERT(testNormal(e3,p1.getNormal()));
    7979    CPPUNIT_ASSERT_EQUAL(0.,p1.getOffset());
    8080
    81     Plane p2(unitVec[0],unitVec[2],zeroVec);
    82     CPPUNIT_ASSERT(testNormal(unitVec[1],p2.getNormal()));
     81    Plane p2(e1,e3,zeroVec);
     82    CPPUNIT_ASSERT(testNormal(e2,p2.getNormal()));
    8383    CPPUNIT_ASSERT_EQUAL(0.,p2.getOffset());
    8484
    85     Plane p3(unitVec[1],unitVec[2],zeroVec);
    86     CPPUNIT_ASSERT(testNormal(unitVec[0],p3.getNormal()));
     85    Plane p3(e2,e3,zeroVec);
     86    CPPUNIT_ASSERT(testNormal(e1,p3.getNormal()));
    8787    CPPUNIT_ASSERT_EQUAL(0.,p3.getOffset());
    8888  }
    8989  {
    9090    // construct with two directions + offset
    91     Plane p1(unitVec[0],unitVec[1],0);
    92     CPPUNIT_ASSERT(testNormal(unitVec[2],p1.getNormal()));
     91    Plane p1(e1,e2,0);
     92    CPPUNIT_ASSERT(testNormal(e3,p1.getNormal()));
    9393    CPPUNIT_ASSERT_EQUAL(0.,p1.getOffset());
    9494
    95     Plane p2(unitVec[0],unitVec[2],0);
    96     CPPUNIT_ASSERT(testNormal(unitVec[1],p2.getNormal()));
     95    Plane p2(e1,e3,0);
     96    CPPUNIT_ASSERT(testNormal(e2,p2.getNormal()));
    9797    CPPUNIT_ASSERT_EQUAL(0.,p2.getOffset());
    9898
    99     Plane p3(unitVec[1],unitVec[2],0);
    100     CPPUNIT_ASSERT(testNormal(unitVec[0],p3.getNormal()));
     99    Plane p3(e2,e3,0);
     100    CPPUNIT_ASSERT(testNormal(e1,p3.getNormal()));
    101101    CPPUNIT_ASSERT_EQUAL(0.,p3.getOffset());
    102102  }
     
    145145void PlaneUnittest::operationsTest(){
    146146  {
    147     Vector t = (1./3.)*(unitVec[0]+unitVec[1]+unitVec[2]);
     147    Vector t = (1./3.)*(e1+e2+e3);
    148148    CPPUNIT_ASSERT(fabs(p1->distance(zeroVec)-t.Norm()) < MYEPSILON);
    149149    CPPUNIT_ASSERT_EQUAL(t,p1->getClosestPoint(zeroVec));
    150150  }
    151151
    152   CPPUNIT_ASSERT(fabs(p2->distance(unitVec[2])-1) < MYEPSILON);
    153   CPPUNIT_ASSERT_EQUAL(zeroVec,p2->getClosestPoint(unitVec[2]));
    154   CPPUNIT_ASSERT(fabs(p3->distance(unitVec[1])-1) < MYEPSILON);
    155   CPPUNIT_ASSERT_EQUAL(zeroVec,p3->getClosestPoint(unitVec[1]));
    156   CPPUNIT_ASSERT(fabs(p4->distance(unitVec[0])-1) < MYEPSILON);
    157   CPPUNIT_ASSERT_EQUAL(zeroVec,p4->getClosestPoint(unitVec[0]));
     152  CPPUNIT_ASSERT(fabs(p2->distance(e3)-1) < MYEPSILON);
     153  CPPUNIT_ASSERT_EQUAL(zeroVec,p2->getClosestPoint(e3));
     154  CPPUNIT_ASSERT(fabs(p3->distance(e2)-1) < MYEPSILON);
     155  CPPUNIT_ASSERT_EQUAL(zeroVec,p3->getClosestPoint(e2));
     156  CPPUNIT_ASSERT(fabs(p4->distance(e1)-1) < MYEPSILON);
     157  CPPUNIT_ASSERT_EQUAL(zeroVec,p4->getClosestPoint(e1));
    158158}
    159159
     
    162162
    163163  // some Vectors that lie on the planes
    164   fixture = p1->mirrorVector(unitVec[0]);
    165   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
    166   fixture = p1->mirrorVector(unitVec[1]);
    167   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
    168   fixture = p1->mirrorVector(unitVec[2]);
    169   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
     164  fixture = p1->mirrorVector(e1);
     165  CPPUNIT_ASSERT_EQUAL(fixture,e1);
     166  fixture = p1->mirrorVector(e2);
     167  CPPUNIT_ASSERT_EQUAL(fixture,e2);
     168  fixture = p1->mirrorVector(e3);
     169  CPPUNIT_ASSERT_EQUAL(fixture,e3);
    170170
    171171  fixture = p2->mirrorVector(zeroVec);
    172172  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
    173   fixture = p2->mirrorVector(unitVec[0]);
    174   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
    175   fixture = p2->mirrorVector(unitVec[1]);
    176   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
     173  fixture = p2->mirrorVector(e1);
     174  CPPUNIT_ASSERT_EQUAL(fixture,e1);
     175  fixture = p2->mirrorVector(e2);
     176  CPPUNIT_ASSERT_EQUAL(fixture,e2);
    177177
    178178  fixture = p3->mirrorVector(zeroVec);
    179179  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
    180   fixture = p3->mirrorVector(unitVec[0]);
    181   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
    182   fixture = p3->mirrorVector(unitVec[2]);
    183   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
     180  fixture = p3->mirrorVector(e1);
     181  CPPUNIT_ASSERT_EQUAL(fixture,e1);
     182  fixture = p3->mirrorVector(e3);
     183  CPPUNIT_ASSERT_EQUAL(fixture,e3);
    184184
    185185  fixture = p4->mirrorVector(zeroVec);
    186186  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
    187   fixture = p4->mirrorVector(unitVec[1]);
    188   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
    189   fixture = p4->mirrorVector(unitVec[2]);
    190   CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
     187  fixture = p4->mirrorVector(e2);
     188  CPPUNIT_ASSERT_EQUAL(fixture,e2);
     189  fixture = p4->mirrorVector(e3);
     190  CPPUNIT_ASSERT_EQUAL(fixture,e3);
    191191
    192192  // some Vectors outside of the planes
    193193  {
    194     Vector t = (2./3.)*(unitVec[0]+unitVec[1]+unitVec[2]);
     194    Vector t = (2./3.)*(e1+e2+e3);
    195195    fixture = p1->mirrorVector(zeroVec);
    196196    CPPUNIT_ASSERT_EQUAL(fixture,t);
    197197  }
    198198
    199   fixture = p2->mirrorVector(unitVec[2]);
    200   CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
    201   fixture = p3->mirrorVector(unitVec[1]);
    202   CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
    203   fixture = p4->mirrorVector(unitVec[0]);
    204   CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
     199  fixture = p2->mirrorVector(e3);
     200  CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
     201  fixture = p3->mirrorVector(e2);
     202  CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
     203  fixture = p4->mirrorVector(e1);
     204  CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
    205205}
    206206
     
    209209  // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ???
    210210  Line l1 = makeLineThrough(zeroVec,Vector(2,1,0));
    211   CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unitVec[0], zeroVec).GetIntersection(l1) );
     211  CPPUNIT_ASSERT_NO_THROW(fixture = Plane(e1, zeroVec).GetIntersection(l1) );
    212212  CPPUNIT_ASSERT_EQUAL( zeroVec, fixture );
    213213
    214214  // plane at (2,1,0) normal to (0,1,0) cuts line from (1,0,0) to (0,1,1) at ???
    215   Line l2 = makeLineThrough(unitVec[0],Vector(0,1,1));
    216   CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unitVec[1], Vector(2,1,0)).GetIntersection(l2) );
     215  Line l2 = makeLineThrough(e1,Vector(0,1,1));
     216  CPPUNIT_ASSERT_NO_THROW(fixture = Plane(e2, Vector(2,1,0)).GetIntersection(l2) );
    217217  CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture );
    218218}
  • src/unittests/ShapeUnittest.cpp

    r2ad482 ra7b777c  
    1717
    1818#include "Shapes/Shape.hpp"
    19 #include "Shapes/BaseShapes.hpp"
    2019#include "vector.cpp"
    2120
     
    2524void ShapeUnittest::setUp()
    2625{
    27   v000 =  0*unitVec[0]+0*unitVec[1]+0*unitVec[2];
    28   v100 =  1*unitVec[0]+0*unitVec[1]+0*unitVec[2];
    29   v200 = -1*unitVec[0]+0*unitVec[1]+0*unitVec[2];
    30   v010 =  0*unitVec[0]+1*unitVec[1]+0*unitVec[2];
    31   v110 =  1*unitVec[0]+1*unitVec[1]+0*unitVec[2];
    32   v210 = -1*unitVec[0]+1*unitVec[1]+0*unitVec[2];
    33   v020 =  0*unitVec[0]-1*unitVec[1]+0*unitVec[2];
    34   v120 =  1*unitVec[0]-1*unitVec[1]+0*unitVec[2];
    35   v220 = -1*unitVec[0]-1*unitVec[1]+0*unitVec[2];
    36   v001 =  0*unitVec[0]+0*unitVec[1]+1*unitVec[2];
    37   v101 =  1*unitVec[0]+0*unitVec[1]+1*unitVec[2];
    38   v201 = -1*unitVec[0]+0*unitVec[1]+1*unitVec[2];
    39   v011 =  0*unitVec[0]+1*unitVec[1]+1*unitVec[2];
    40   v111 =  1*unitVec[0]+1*unitVec[1]+1*unitVec[2];
    41   v211 = -1*unitVec[0]+1*unitVec[1]+1*unitVec[2];
    42   v021 =  0*unitVec[0]-1*unitVec[1]+1*unitVec[2];
    43   v121 =  1*unitVec[0]-1*unitVec[1]+1*unitVec[2];
    44   v221 = -1*unitVec[0]-1*unitVec[1]+1*unitVec[2];
    45   v002 =  0*unitVec[0]+0*unitVec[1]-1*unitVec[2];
    46   v102 =  1*unitVec[0]+0*unitVec[1]-1*unitVec[2];
    47   v202 = -1*unitVec[0]+0*unitVec[1]-1*unitVec[2];
    48   v012 =  0*unitVec[0]+1*unitVec[1]-1*unitVec[2];
    49   v112 =  1*unitVec[0]+1*unitVec[1]-1*unitVec[2];
    50   v212 = -1*unitVec[0]+1*unitVec[1]-1*unitVec[2];
    51   v022 =  0*unitVec[0]-1*unitVec[1]-1*unitVec[2];
    52   v122 =  1*unitVec[0]-1*unitVec[1]-1*unitVec[2];
    53   v222 = -1*unitVec[0]-1*unitVec[1]-1*unitVec[2];
     26  v000 =  0*e1+0*e2+0*e3;
     27  v100 =  1*e1+0*e2+0*e3;
     28  v200 = -1*e1+0*e2+0*e3;
     29  v010 =  0*e1+1*e2+0*e3;
     30  v110 =  1*e1+1*e2+0*e3;
     31  v210 = -1*e1+1*e2+0*e3;
     32  v020 =  0*e1-1*e2+0*e3;
     33  v120 =  1*e1-1*e2+0*e3;
     34  v220 = -1*e1-1*e2+0*e3;
     35  v001 =  0*e1+0*e2+1*e3;
     36  v101 =  1*e1+0*e2+1*e3;
     37  v201 = -1*e1+0*e2+1*e3;
     38  v011 =  0*e1+1*e2+1*e3;
     39  v111 =  1*e1+1*e2+1*e3;
     40  v211 = -1*e1+1*e2+1*e3;
     41  v021 =  0*e1-1*e2+1*e3;
     42  v121 =  1*e1-1*e2+1*e3;
     43  v221 = -1*e1-1*e2+1*e3;
     44  v002 =  0*e1+0*e2-1*e3;
     45  v102 =  1*e1+0*e2-1*e3;
     46  v202 = -1*e1+0*e2-1*e3;
     47  v012 =  0*e1+1*e2-1*e3;
     48  v112 =  1*e1+1*e2-1*e3;
     49  v212 = -1*e1+1*e2-1*e3;
     50  v022 =  0*e1-1*e2-1*e3;
     51  v122 =  1*e1-1*e2-1*e3;
     52  v222 = -1*e1-1*e2-1*e3;
    5453}
    5554
     
    114113  CPPUNIT_ASSERT(Everywhere().isInside(v122));
    115114  CPPUNIT_ASSERT(Everywhere().isInside(v222));
    116 
    117   CPPUNIT_ASSERT(Cuboid().isInside(v000));
    118   CPPUNIT_ASSERT(Cuboid().isInside(v100));
    119   CPPUNIT_ASSERT(Cuboid().isInside(v200));
    120   CPPUNIT_ASSERT(Cuboid().isInside(v010));
    121   CPPUNIT_ASSERT(Cuboid().isInside(v110));
    122   CPPUNIT_ASSERT(Cuboid().isInside(v210));
    123   CPPUNIT_ASSERT(Cuboid().isInside(v020));
    124   CPPUNIT_ASSERT(Cuboid().isInside(v120));
    125   CPPUNIT_ASSERT(Cuboid().isInside(v220));
    126   CPPUNIT_ASSERT(Cuboid().isInside(v001));
    127   CPPUNIT_ASSERT(Cuboid().isInside(v101));
    128   CPPUNIT_ASSERT(Cuboid().isInside(v201));
    129   CPPUNIT_ASSERT(Cuboid().isInside(v011));
    130   CPPUNIT_ASSERT(Cuboid().isInside(v111));
    131   CPPUNIT_ASSERT(Cuboid().isInside(v211));
    132   CPPUNIT_ASSERT(Cuboid().isInside(v021));
    133   CPPUNIT_ASSERT(Cuboid().isInside(v121));
    134   CPPUNIT_ASSERT(Cuboid().isInside(v221));
    135   CPPUNIT_ASSERT(Cuboid().isInside(v002));
    136   CPPUNIT_ASSERT(Cuboid().isInside(v102));
    137   CPPUNIT_ASSERT(Cuboid().isInside(v202));
    138   CPPUNIT_ASSERT(Cuboid().isInside(v012));
    139   CPPUNIT_ASSERT(Cuboid().isInside(v112));
    140   CPPUNIT_ASSERT(Cuboid().isInside(v212));
    141   CPPUNIT_ASSERT(Cuboid().isInside(v022));
    142   CPPUNIT_ASSERT(Cuboid().isInside(v122));
    143   CPPUNIT_ASSERT(Cuboid().isInside(v222));
    144 
    145   CPPUNIT_ASSERT(Sphere().isInside(v000));
    146   CPPUNIT_ASSERT(Sphere().isInside(v100));
    147   CPPUNIT_ASSERT(Sphere().isInside(v200));
    148   CPPUNIT_ASSERT(Sphere().isInside(v010));
    149   CPPUNIT_ASSERT(!Sphere().isInside(v110));
    150   CPPUNIT_ASSERT(!Sphere().isInside(v210));
    151   CPPUNIT_ASSERT(Sphere().isInside(v020));
    152   CPPUNIT_ASSERT(!Sphere().isInside(v120));
    153   CPPUNIT_ASSERT(!Sphere().isInside(v220));
    154   CPPUNIT_ASSERT(Sphere().isInside(v001));
    155   CPPUNIT_ASSERT(!Sphere().isInside(v101));
    156   CPPUNIT_ASSERT(!Sphere().isInside(v201));
    157   CPPUNIT_ASSERT(!Sphere().isInside(v011));
    158   CPPUNIT_ASSERT(!Sphere().isInside(v111));
    159   CPPUNIT_ASSERT(!Sphere().isInside(v211));
    160   CPPUNIT_ASSERT(!Sphere().isInside(v021));
    161   CPPUNIT_ASSERT(!Sphere().isInside(v121));
    162   CPPUNIT_ASSERT(!Sphere().isInside(v221));
    163   CPPUNIT_ASSERT(Sphere().isInside(v002));
    164   CPPUNIT_ASSERT(!Sphere().isInside(v102));
    165   CPPUNIT_ASSERT(!Sphere().isInside(v202));
    166   CPPUNIT_ASSERT(!Sphere().isInside(v012));
    167   CPPUNIT_ASSERT(!Sphere().isInside(v112));
    168   CPPUNIT_ASSERT(!Sphere().isInside(v212));
    169   CPPUNIT_ASSERT(!Sphere().isInside(v022));
    170   CPPUNIT_ASSERT(!Sphere().isInside(v122));
    171   CPPUNIT_ASSERT(!Sphere().isInside(v222));
    172 }
    173 
    174 void ShapeUnittest::surfaceTest(){
    175   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v000));
    176   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v100));
    177   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v200));
    178   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v010));
    179   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v110));
    180   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v210));
    181   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v020));
    182   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v120));
    183   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v220));
    184   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v001));
    185   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v101));
    186   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v201));
    187   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v011));
    188   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v111));
    189   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v211));
    190   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v021));
    191   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v121));
    192   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v221));
    193   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v002));
    194   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v102));
    195   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v202));
    196   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v012));
    197   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v112));
    198   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v212));
    199   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v022));
    200   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v122));
    201   CPPUNIT_ASSERT(!Nowhere().isOnSurface(v222));
    202 
    203   CPPUNIT_ASSERT(!Cuboid().isOnSurface(v000));
    204   CPPUNIT_ASSERT(Cuboid().isOnSurface(v100));
    205   CPPUNIT_ASSERT(Cuboid().isOnSurface(v200));
    206   CPPUNIT_ASSERT(Cuboid().isOnSurface(v010));
    207   CPPUNIT_ASSERT(Cuboid().isOnSurface(v110));
    208   CPPUNIT_ASSERT(Cuboid().isOnSurface(v210));
    209   CPPUNIT_ASSERT(Cuboid().isOnSurface(v020));
    210   CPPUNIT_ASSERT(Cuboid().isOnSurface(v120));
    211   CPPUNIT_ASSERT(Cuboid().isOnSurface(v220));
    212   CPPUNIT_ASSERT(Cuboid().isOnSurface(v001));
    213   CPPUNIT_ASSERT(Cuboid().isOnSurface(v101));
    214   CPPUNIT_ASSERT(Cuboid().isOnSurface(v201));
    215   CPPUNIT_ASSERT(Cuboid().isOnSurface(v011));
    216   CPPUNIT_ASSERT(Cuboid().isOnSurface(v111));
    217   CPPUNIT_ASSERT(Cuboid().isOnSurface(v211));
    218   CPPUNIT_ASSERT(Cuboid().isOnSurface(v021));
    219   CPPUNIT_ASSERT(Cuboid().isOnSurface(v121));
    220   CPPUNIT_ASSERT(Cuboid().isOnSurface(v221));
    221   CPPUNIT_ASSERT(Cuboid().isOnSurface(v002));
    222   CPPUNIT_ASSERT(Cuboid().isOnSurface(v102));
    223   CPPUNIT_ASSERT(Cuboid().isOnSurface(v202));
    224   CPPUNIT_ASSERT(Cuboid().isOnSurface(v012));
    225   CPPUNIT_ASSERT(Cuboid().isOnSurface(v112));
    226   CPPUNIT_ASSERT(Cuboid().isOnSurface(v212));
    227   CPPUNIT_ASSERT(Cuboid().isOnSurface(v022));
    228   CPPUNIT_ASSERT(Cuboid().isOnSurface(v122));
    229   CPPUNIT_ASSERT(Cuboid().isOnSurface(v222));
    230 
    231   CPPUNIT_ASSERT(!Sphere().isOnSurface(v000));
    232   CPPUNIT_ASSERT(Sphere().isOnSurface(v100));
    233   CPPUNIT_ASSERT(Sphere().isOnSurface(v200));
    234   CPPUNIT_ASSERT(Sphere().isOnSurface(v010));
    235   CPPUNIT_ASSERT(!Sphere().isOnSurface(v110));
    236   CPPUNIT_ASSERT(!Sphere().isOnSurface(v210));
    237   CPPUNIT_ASSERT(Sphere().isOnSurface(v020));
    238   CPPUNIT_ASSERT(!Sphere().isOnSurface(v120));
    239   CPPUNIT_ASSERT(!Sphere().isOnSurface(v220));
    240   CPPUNIT_ASSERT(Sphere().isOnSurface(v001));
    241   CPPUNIT_ASSERT(!Sphere().isOnSurface(v101));
    242   CPPUNIT_ASSERT(!Sphere().isOnSurface(v201));
    243   CPPUNIT_ASSERT(!Sphere().isOnSurface(v011));
    244   CPPUNIT_ASSERT(!Sphere().isOnSurface(v111));
    245   CPPUNIT_ASSERT(!Sphere().isOnSurface(v211));
    246   CPPUNIT_ASSERT(!Sphere().isOnSurface(v021));
    247   CPPUNIT_ASSERT(!Sphere().isOnSurface(v121));
    248   CPPUNIT_ASSERT(!Sphere().isOnSurface(v221));
    249   CPPUNIT_ASSERT(Sphere().isOnSurface(v002));
    250   CPPUNIT_ASSERT(!Sphere().isOnSurface(v102));
    251   CPPUNIT_ASSERT(!Sphere().isOnSurface(v202));
    252   CPPUNIT_ASSERT(!Sphere().isOnSurface(v012));
    253   CPPUNIT_ASSERT(!Sphere().isOnSurface(v112));
    254   CPPUNIT_ASSERT(!Sphere().isOnSurface(v212));
    255   CPPUNIT_ASSERT(!Sphere().isOnSurface(v022));
    256   CPPUNIT_ASSERT(!Sphere().isOnSurface(v122));
    257   CPPUNIT_ASSERT(!Sphere().isOnSurface(v222));
    258115}
    259116
     
    503360  }
    504361
    505   {
    506     Shape s1 = Sphere() && Cuboid(); // should be the same as Sphere
    507 
    508     CPPUNIT_ASSERT(s1.isInside(v000));
    509     CPPUNIT_ASSERT(s1.isInside(v100));
    510     CPPUNIT_ASSERT(s1.isInside(v200));
    511     CPPUNIT_ASSERT(s1.isInside(v010));
    512     CPPUNIT_ASSERT(!s1.isInside(v110));
    513     CPPUNIT_ASSERT(!s1.isInside(v210));
    514     CPPUNIT_ASSERT(s1.isInside(v020));
    515     CPPUNIT_ASSERT(!s1.isInside(v120));
    516     CPPUNIT_ASSERT(!s1.isInside(v220));
    517     CPPUNIT_ASSERT(s1.isInside(v001));
    518     CPPUNIT_ASSERT(!s1.isInside(v101));
    519     CPPUNIT_ASSERT(!s1.isInside(v201));
    520     CPPUNIT_ASSERT(!s1.isInside(v011));
    521     CPPUNIT_ASSERT(!s1.isInside(v111));
    522     CPPUNIT_ASSERT(!s1.isInside(v211));
    523     CPPUNIT_ASSERT(!s1.isInside(v021));
    524     CPPUNIT_ASSERT(!s1.isInside(v121));
    525     CPPUNIT_ASSERT(!s1.isInside(v221));
    526     CPPUNIT_ASSERT(s1.isInside(v002));
    527     CPPUNIT_ASSERT(!s1.isInside(v102));
    528     CPPUNIT_ASSERT(!s1.isInside(v202));
    529     CPPUNIT_ASSERT(!s1.isInside(v012));
    530     CPPUNIT_ASSERT(!s1.isInside(v112));
    531     CPPUNIT_ASSERT(!s1.isInside(v212));
    532     CPPUNIT_ASSERT(!s1.isInside(v022));
    533     CPPUNIT_ASSERT(!s1.isInside(v122));
    534     CPPUNIT_ASSERT(!s1.isInside(v222));
    535 
    536     CPPUNIT_ASSERT(!s1.isOnSurface(v000));
    537     CPPUNIT_ASSERT(s1.isOnSurface(v100));
    538     CPPUNIT_ASSERT(s1.isOnSurface(v200));
    539     CPPUNIT_ASSERT(s1.isOnSurface(v010));
    540     CPPUNIT_ASSERT(!s1.isOnSurface(v110));
    541     CPPUNIT_ASSERT(!s1.isOnSurface(v210));
    542     CPPUNIT_ASSERT(s1.isOnSurface(v020));
    543     CPPUNIT_ASSERT(!s1.isOnSurface(v120));
    544     CPPUNIT_ASSERT(!s1.isOnSurface(v220));
    545     CPPUNIT_ASSERT(s1.isOnSurface(v001));
    546     CPPUNIT_ASSERT(!s1.isOnSurface(v101));
    547     CPPUNIT_ASSERT(!s1.isOnSurface(v201));
    548     CPPUNIT_ASSERT(!s1.isOnSurface(v011));
    549     CPPUNIT_ASSERT(!s1.isOnSurface(v111));
    550     CPPUNIT_ASSERT(!s1.isOnSurface(v211));
    551     CPPUNIT_ASSERT(!s1.isOnSurface(v021));
    552     CPPUNIT_ASSERT(!s1.isOnSurface(v121));
    553     CPPUNIT_ASSERT(!s1.isOnSurface(v221));
    554     CPPUNIT_ASSERT(s1.isOnSurface(v002));
    555     CPPUNIT_ASSERT(!s1.isOnSurface(v102));
    556     CPPUNIT_ASSERT(!s1.isOnSurface(v202));
    557     CPPUNIT_ASSERT(!s1.isOnSurface(v012));
    558     CPPUNIT_ASSERT(!s1.isOnSurface(v112));
    559     CPPUNIT_ASSERT(!s1.isOnSurface(v212));
    560     CPPUNIT_ASSERT(!s1.isOnSurface(v022));
    561     CPPUNIT_ASSERT(!s1.isOnSurface(v122));
    562     CPPUNIT_ASSERT(!s1.isOnSurface(v222));
    563 
    564 
    565     Shape s2 = Sphere() || Cuboid(); // Should be same as Cuboid
    566 
    567     CPPUNIT_ASSERT(s2.isInside(v000));
    568     CPPUNIT_ASSERT(s2.isInside(v100));
    569     CPPUNIT_ASSERT(s2.isInside(v200));
    570     CPPUNIT_ASSERT(s2.isInside(v010));
    571     CPPUNIT_ASSERT(s2.isInside(v110));
    572     CPPUNIT_ASSERT(s2.isInside(v210));
    573     CPPUNIT_ASSERT(s2.isInside(v020));
    574     CPPUNIT_ASSERT(s2.isInside(v120));
    575     CPPUNIT_ASSERT(s2.isInside(v220));
    576     CPPUNIT_ASSERT(s2.isInside(v001));
    577     CPPUNIT_ASSERT(s2.isInside(v101));
    578     CPPUNIT_ASSERT(s2.isInside(v201));
    579     CPPUNIT_ASSERT(s2.isInside(v011));
    580     CPPUNIT_ASSERT(s2.isInside(v111));
    581     CPPUNIT_ASSERT(s2.isInside(v211));
    582     CPPUNIT_ASSERT(s2.isInside(v021));
    583     CPPUNIT_ASSERT(s2.isInside(v121));
    584     CPPUNIT_ASSERT(s2.isInside(v221));
    585     CPPUNIT_ASSERT(s2.isInside(v002));
    586     CPPUNIT_ASSERT(s2.isInside(v102));
    587     CPPUNIT_ASSERT(s2.isInside(v202));
    588     CPPUNIT_ASSERT(s2.isInside(v012));
    589     CPPUNIT_ASSERT(s2.isInside(v112));
    590     CPPUNIT_ASSERT(s2.isInside(v212));
    591     CPPUNIT_ASSERT(s2.isInside(v022));
    592     CPPUNIT_ASSERT(s2.isInside(v122));
    593     CPPUNIT_ASSERT(s2.isInside(v222));
    594 
    595     CPPUNIT_ASSERT(!s2.isOnSurface(v000));
    596     CPPUNIT_ASSERT(s2.isOnSurface(v100));
    597     CPPUNIT_ASSERT(s2.isOnSurface(v200));
    598     CPPUNIT_ASSERT(s2.isOnSurface(v010));
    599     CPPUNIT_ASSERT(s2.isOnSurface(v110));
    600     CPPUNIT_ASSERT(s2.isOnSurface(v210));
    601     CPPUNIT_ASSERT(s2.isOnSurface(v020));
    602     CPPUNIT_ASSERT(s2.isOnSurface(v120));
    603     CPPUNIT_ASSERT(s2.isOnSurface(v220));
    604     CPPUNIT_ASSERT(s2.isOnSurface(v001));
    605     CPPUNIT_ASSERT(s2.isOnSurface(v101));
    606     CPPUNIT_ASSERT(s2.isOnSurface(v201));
    607     CPPUNIT_ASSERT(s2.isOnSurface(v011));
    608     CPPUNIT_ASSERT(s2.isOnSurface(v111));
    609     CPPUNIT_ASSERT(s2.isOnSurface(v211));
    610     CPPUNIT_ASSERT(s2.isOnSurface(v021));
    611     CPPUNIT_ASSERT(s2.isOnSurface(v121));
    612     CPPUNIT_ASSERT(s2.isOnSurface(v221));
    613     CPPUNIT_ASSERT(s2.isOnSurface(v002));
    614     CPPUNIT_ASSERT(s2.isOnSurface(v102));
    615     CPPUNIT_ASSERT(s2.isOnSurface(v202));
    616     CPPUNIT_ASSERT(s2.isOnSurface(v012));
    617     CPPUNIT_ASSERT(s2.isOnSurface(v112));
    618     CPPUNIT_ASSERT(s2.isOnSurface(v212));
    619     CPPUNIT_ASSERT(s2.isOnSurface(v022));
    620     CPPUNIT_ASSERT(s2.isOnSurface(v122));
    621     CPPUNIT_ASSERT(s2.isOnSurface(v222));
    622   }
    623 
    624362}
  • src/unittests/ShapeUnittest.hpp

    r2ad482 ra7b777c  
    2020  CPPUNIT_TEST_SUITE( ShapeUnittest) ;
    2121  CPPUNIT_TEST ( baseShapesTest );
    22   CPPUNIT_TEST ( surfaceTest );
    2322  CPPUNIT_TEST ( assignmentTest );
    2423  CPPUNIT_TEST ( operatorTest );
     
    3029
    3130  void baseShapesTest();
    32   void surfaceTest();
    3331  void assignmentTest();
    3432  void operatorTest();
  • src/vector.cpp

    r2ad482 ra7b777c  
    193193  (*this) *= 1/factor;
    194194};
    195 
    196 Vector Vector::getNormalized() const{
    197   Vector res= *this;
    198   res.Normalize();
    199   return res;
    200 }
    201195
    202196/** Zeros all components of this vector.
     
    540534// some comonly used vectors
    541535const Vector zeroVec(0,0,0);
    542 const Vector unitVec[NDIM]={Vector(1,0,0),Vector(0,1,0),Vector(0,0,1)};
     536const Vector e1(1,0,0);
     537const Vector e2(0,1,0);
     538const Vector e3(0,0,1);
  • src/vector.hpp

    r2ad482 ra7b777c  
    8080  double NormSquared() const;
    8181  void Normalize();
    82   Vector getNormalized() const;
    8382  void Zero();
    8483  void One(const double one);
     
    107106// some commonly used and fixed vectors
    108107const extern Vector zeroVec;
    109 const extern Vector unitVec[NDIM];
     108const extern Vector e1;
     109const extern Vector e2;
     110const extern Vector e3;
    110111
    111112ostream & operator << (ostream& ost, const Vector &m);
Note: See TracChangeset for help on using the changeset viewer.