Changes in / [7067bd6:49d3d39]


Ignore:
Location:
src
Files:
9 added
26 edited

Legend:

Unmodified
Added
Removed
  • src/Box.cpp

    r7067bd6 r49d3d39  
    1414#include "Matrix.hpp"
    1515#include "vector.hpp"
     16#include "Shapes/BaseShapes.hpp"
     17#include "Shapes/ShapeOps.hpp"
    1618
    1719#include "Helpers/Assert.hpp"
     
    127129}
    128130
     131Shape Box::getShape() const{
     132  return transform(Cuboid(Vector(0,0,0),Vector(1,1,1)),(*M));
     133
     134}
     135
    129136Box &Box::operator=(const Box &src){
    130137  if(&src!=this){
  • src/Box.hpp

    r7067bd6 r49d3d39  
    1111class Matrix;
    1212class Vector;
     13class Shape;
    1314
    1415#include <list>
     
    8485  double periodicDistance(const Vector &point1,const Vector &point2) const;
    8586
     87  Shape getShape() const;
     88
    8689private:
    8790  Matrix *M;    //!< Defines the layout of the box
  • src/Line.cpp

    r7067bd6 r49d3d39  
    3737Line::~Line()
    3838{}
     39
     40Line &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}
    3947
    4048
     
    234242}
    235243
     244LinePoint Line::getLinePoint(const Vector &point) const{
     245  ASSERT(isContained(point),"Line point queried for point not on line");
     246  Vector helper = point - (*origin);
     247  double param = helper.ScalarProduct(*direction);
     248  return LinePoint(*this,param);
     249}
     250
     251LinePoint Line::posEndpoint() const{
     252  return LinePoint(*this, numeric_limits<double>::infinity());
     253}
     254LinePoint Line::negEndpoint() const{
     255  return LinePoint(*this,-numeric_limits<double>::infinity());
     256}
     257
     258bool operator==(const Line &x,const Line &y){
     259  return *x.origin == *y.origin && *x.direction == *y.direction;
     260}
     261
    236262Line makeLineThrough(const Vector &x1, const Vector &x2){
    237263  if(x1==x2){
     
    240266  return Line(x1,x1-x2);
    241267}
     268
     269
     270/******************************** Points on the line ********************/
     271
     272LinePoint::LinePoint(const LinePoint &src) :
     273  line(src.line),param(src.param)
     274{}
     275
     276LinePoint::LinePoint(const Line &_line, double _param) :
     277  line(_line),param(_param)
     278{}
     279
     280LinePoint& LinePoint::operator=(const LinePoint &src){
     281  ASSERT(src.line==line,"Operation on two points of different lines");
     282  param=src.param;
     283  return *this;
     284}
     285
     286Vector LinePoint::getPoint() const{
     287  ASSERT(!isInfinite(),"getPoint() on infinite LinePoint called");
     288  return (*line.origin)+param*(*line.direction);
     289}
     290
     291Line LinePoint::getLine() const{
     292  return line;
     293}
     294
     295bool LinePoint::isInfinite() const{
     296  return isPosInfinity() || isNegInfinity();
     297}
     298bool LinePoint::isPosInfinity() const{
     299  return param == numeric_limits<double>::infinity();
     300}
     301bool LinePoint::isNegInfinity() const{
     302  return param ==-numeric_limits<double>::infinity();
     303}
     304
     305bool operator==(const LinePoint &x, const LinePoint &y){
     306  ASSERT(x.line==y.line,"Operation on two points of different lines");
     307  return x.param == y.param;
     308
     309}
     310bool operator<(const LinePoint &x, const LinePoint &y){
     311  ASSERT(x.line==y.line,"Operation on two points of different lines");
     312  return x.param<y.param;
     313}
  • src/Line.hpp

    r7067bd6 r49d3d39  
    1616class Vector;
    1717class Plane;
     18class LinePoint;
    1819
    1920class Line : public Space
    2021{
     22  friend bool operator==(const Line&,const Line&);
     23  friend class LinePoint;
    2124public:
    2225  Line(const Vector &_origin, const Vector &_direction);
    2326  Line(const Line& _src);
    2427  virtual ~Line();
     28
     29  Line &operator=(const Line& rhs);
    2530
    2631  virtual double distance(const Vector &point) const;
     
    4045  std::vector<Vector> getSphereIntersections() const;
    4146
     47  LinePoint getLinePoint(const Vector&) const;
     48  LinePoint posEndpoint() const;
     49  LinePoint negEndpoint() const;
     50
    4251private:
    4352  std::auto_ptr<Vector> origin;
    4453  std::auto_ptr<Vector> direction;
    4554};
     55
     56bool operator==(const Line&,const Line&);
    4657
    4758/**
     
    5061Line makeLineThrough(const Vector &x1, const Vector &x2);
    5162
     63/**
     64 * Class for representing points on a line
     65 * These objects allow comparison of points on the same line as well as specifying the
     66 * infinite "endpoints" of a line.
     67 */
     68class LinePoint{
     69  friend class Line;
     70  friend bool operator==(const LinePoint&, const LinePoint&);
     71  friend bool operator<(const LinePoint&, const LinePoint&);
     72public:
     73  LinePoint(const LinePoint&);
     74  LinePoint& operator=(const LinePoint&);
     75  Vector getPoint() const;
     76  Line getLine() const;
     77  bool isInfinite() const;
     78  bool isPosInfinity() const;
     79  bool isNegInfinity() const;
     80
     81private:
     82  LinePoint(const Line&,double);
     83  Line line;
     84  double param;
     85};
     86
     87bool operator==(const LinePoint&, const LinePoint&);
     88bool operator<(const LinePoint&, const LinePoint&);
     89
     90inline bool operator!= (const LinePoint& x, const LinePoint& y) { return !(x==y); }
     91inline bool operator>  (const LinePoint& x, const LinePoint& y) { return y<x; }
     92inline bool operator<= (const LinePoint& x, const LinePoint& y) { return !(y<x); }
     93inline bool operator>= (const LinePoint& x, const LinePoint& y) { return !(x<y); }
     94
     95
    5296#endif /* LINE_HPP_ */
  • src/Makefile.am

    r7067bd6 r49d3d39  
    8282  Exceptions/MathException.cpp \
    8383  Exceptions/NotInvertibleException.cpp \
     84  Exceptions/NotOnSurfaceException.cpp \
     85  Exceptions/ShapeException.cpp \
    8486  Exceptions/ParseError.cpp \
    8587  Exceptions/SkewException.cpp \
     
    9193  Exceptions/MathException.hpp \
    9294  Exceptions/NotInvertibleException.hpp \
     95  Exceptions/NotOnSurfaceException.hpp \
     96  Exceptions/ShapeException.hpp \
    9397  Exceptions/ParseError.hpp \
    9498  Exceptions/SkewException.hpp \
     
    149153  Descriptors/AtomIdDescriptor.cpp \
    150154  Descriptors/AtomSelectionDescriptor.cpp \
     155  Descriptors/AtomShapeDescriptor.cpp \
    151156  Descriptors/AtomTypeDescriptor.cpp \
    152157  Descriptors/MoleculeDescriptor.cpp \
     
    161166  Descriptors/AtomIdDescriptor.hpp \
    162167  Descriptors/AtomSelectionDescriptor.hpp \
     168  Descriptors/AtomShapeDescriptor.hpp \
    163169  Descriptors/AtomTypeDescriptor.hpp \
    164170  Descriptors/MoleculeDescriptor.hpp \
     
    210216  leastsquaremin.cpp \
    211217  Line.cpp \
     218  LineSegment.cpp \
    212219  linkedcell.cpp \
    213220  log.cpp \
     
    261268  leastsquaremin.hpp \
    262269  Line.hpp \
     270  LineSegment.hpp \
    263271  linkedcell.hpp \
    264272  lists.hpp \
  • src/Matrix.cpp

    r7067bd6 r49d3d39  
    213213}
    214214
     215Matrix 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
    215222Matrix &Matrix::operator*=(const double factor){
    216223  gsl_matrix_scale(content->content, factor);
  • src/Matrix.hpp

    r7067bd6 r49d3d39  
    9696  Matrix invert() const;
    9797
     98  Matrix transpose() const;
     99
    98100  // operators
    99101  Matrix &operator=(const Matrix&);
  • src/Plane.cpp

    r7067bd6 r49d3d39  
    1515#include "verbose.hpp"
    1616#include "Helpers/Assert.hpp"
     17#include "helpers.hpp"
    1718#include <cmath>
    1819#include "Line.hpp"
     
    106107Plane::~Plane()
    107108{}
     109
     110Plane &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}
    108117
    109118
     
    188197}
    189198
     199bool Plane::onSameSide(const Vector &point1,const Vector &point2) const{
     200  return sign(point1.ScalarProduct(*normalVector)-offset) ==
     201         sign(point2.ScalarProduct(*normalVector)-offset);
     202}
     203
    190204/************ Methods inherited from Space ****************/
    191205
     
    207221// Operators
    208222
     223bool operator==(const Plane &x,const Plane &y){
     224  return *x.normalVector == *y.normalVector && x.offset == y.offset;
     225}
     226
    209227ostream &operator << (ostream &ost,const Plane &p){
    210228  ost << "<" << p.getNormal() << ";x> - " << p.getOffset() << "=0";
  • src/Plane.hpp

    r7067bd6 r49d3d39  
    2121class Plane : public Space
    2222{
     23  friend bool operator==(const Plane&,const Plane&);
    2324  typedef std::auto_ptr<Vector> vec_ptr;
    2425public:
     
    2930  Plane(const Plane& plane);
    3031  virtual ~Plane();
     32
     33  Plane &operator=(const Plane&);
    3134
    3235  // Accessor Functions
     
    6366  Line getOrthogonalLine(const Vector &origin) const;
    6467
     68  /**
     69   * Test if two points are on the same side of the plane
     70   */
     71  bool onSameSide(const Vector&,const Vector&) const;
     72
    6573  /****** Methods inherited from Space ***********/
    6674
     
    7381};
    7482
     83bool operator==(const Plane&,const Plane&);
     84
    7585std::ostream &operator<< (std::ostream &ost,const Plane& p);
    7686
  • src/Shapes/BaseShapes.cpp

    r7067bd6 r49d3d39  
    88#include "Shapes/BaseShapes.hpp"
    99#include "Shapes/BaseShapes_impl.hpp"
     10#include "Shapes/ShapeOps.hpp"
    1011
    1112#include "vector.hpp"
     13#include "Helpers/Assert.hpp"
     14
     15#include <cmath>
     16#include <algorithm>
    1217
    1318bool Sphere_impl::isInside(const Vector &point){
    1419  return point.NormSquared()<=1;
     20}
     21
     22bool Sphere_impl::isOnSurface(const Vector &point){
     23  return fabs(point.NormSquared()-1)<MYEPSILON;
     24}
     25
     26Vector Sphere_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){
     27  if(!isOnSurface(point)){
     28    throw NotOnSurfaceException(__FILE__,__LINE__);
     29  }
     30  return point;
     31}
     32
     33string Sphere_impl::toString(){
     34  return "Sphere()";
    1535}
    1636
     
    2040}
    2141
     42Shape Sphere(const Vector &center,double radius){
     43  return translate(resize(Sphere(),radius),center);
     44}
     45
     46Shape Ellipsoid(const Vector &center, const Vector &radius){
     47  return translate(stretch(Sphere(),radius),center);
     48}
     49
    2250bool Cuboid_impl::isInside(const Vector &point){
    23   return point[0]<=1 && point[1]<=1 && point[2]<=1;
     51  return fabs(point[0])<=1 && fabs(point[1])<=1 && fabs(point[2])<=1;
     52}
     53
     54bool Cuboid_impl::isOnSurface(const Vector &point){
     55  bool retVal = isInside(point);
     56  // test all borders of the cuboid
     57  // double fabs
     58  retVal = retVal &&
     59           ((fabs(fabs(point[0])-1)  < MYEPSILON) ||
     60            (fabs(fabs(point[1])-1)  < MYEPSILON) ||
     61            (fabs(fabs(point[2])-1)  < MYEPSILON));
     62  return retVal;
     63}
     64
     65Vector Cuboid_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){
     66  if(!isOnSurface(point)){
     67    throw NotOnSurfaceException(__FILE__,__LINE__);
     68  }
     69  Vector res;
     70  // figure out on which sides the Vector lies (maximum 3, when it is in a corner)
     71  for(int i=NDIM;i--;){
     72    if(fabs(fabs(point[i])-1)<MYEPSILON){
     73      // add the scaled (-1/+1) Vector to the set of surface vectors
     74      res[i] = point[i];
     75    }
     76  }
     77  ASSERT(res.NormSquared()>=1 && res.NormSquared()<=3,"To many or to few sides found for this Vector");
     78
     79  res.Normalize();
     80  return res;
     81}
     82
     83string Cuboid_impl::toString(){
     84  return "Cuboid()";
    2485}
    2586
    2687Shape Cuboid(){
    27   Shape::impl_ptr impl = Shape::impl_ptr(new Sphere_impl());
     88  Shape::impl_ptr impl = Shape::impl_ptr(new Cuboid_impl());
    2889  return Shape(impl);
    2990}
     91
     92Shape Cuboid(const Vector &corner1, const Vector &corner2){
     93  // make sure the two edges are upper left front and lower right back
     94  Vector sortedC1;
     95  Vector sortedC2;
     96  for(int i=NDIM;i--;){
     97    sortedC1[i] = min(corner1[i],corner2[i]);
     98    sortedC2[i] = max(corner1[i],corner2[i]);
     99    ASSERT(corner1[i]!=corner2[i],"Given points for cuboid edges did not define a valid space");
     100  }
     101  // get the middle point
     102  Vector middle = (1./2.)*(sortedC1+sortedC2);
     103  Vector factors = sortedC2-middle;
     104  return translate(stretch(Cuboid(),factors),middle);
     105}
  • src/Shapes/BaseShapes.hpp

    r7067bd6 r49d3d39  
    1212
    1313Shape Sphere();
     14Shape Sphere(const Vector &center,double radius);
     15Shape Ellipsoid(const Vector &center, const Vector &radius);
    1416Shape Cuboid();
     17Shape Cuboid(const Vector &corner1, const Vector &corner2);
    1518
    1619#endif /* BASESHAPES_HPP_ */
  • src/Shapes/BaseShapes_impl.hpp

    r7067bd6 r49d3d39  
    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 std::string toString();
    1518};
    1619
    1720class Cuboid_impl : public Shape_impl {
    1821  virtual bool isInside(const Vector &point);
     22  virtual bool isOnSurface(const Vector &point);
     23  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
     24  virtual std::string toString();
    1925};
    2026
  • src/Shapes/Shape.cpp

    r7067bd6 r49d3d39  
    99#include "Shape_impl.hpp"
    1010
     11#include "Helpers/Assert.hpp"
     12
     13#include <string>
     14
     15using namespace std;
     16
    1117Shape::Shape(const Shape& src) :
    1218  impl(src.getImpl())
     
    1723bool Shape::isInside(const Vector &point) const{
    1824  return impl->isInside(point);
     25}
     26
     27bool Shape::isOnSurface(const Vector &point) const{
     28  return impl->isOnSurface(point);
     29}
     30
     31Vector Shape::getNormal(const Vector &point) const throw (NotOnSurfaceException){
     32  return impl->getNormal(point);
    1933}
    2034
     
    3044}
    3145
     46std::string Shape::toString() const{
     47  return impl->toString();
     48}
     49
    3250Shape::impl_ptr Shape::getImpl() const{
    3351  return impl;
     
    6583}
    6684
     85bool AndShape_impl::isOnSurface(const Vector &point){
     86  // check the number of surfaces that this point is on
     87  int surfaces =0;
     88  surfaces += lhs->isOnSurface(point);
     89  surfaces += rhs->isOnSurface(point);
     90
     91  switch(surfaces){
     92    case 0:
     93      return false;
     94      // no break necessary
     95    case 1:
     96      // if it is inside for the object where it does not lie on
     97      // the surface the whole point lies inside
     98      return (lhs->isOnSurface(point) && rhs->isInside(point)) ||
     99             (rhs->isOnSurface(point) && lhs->isInside(point));
     100      // no break necessary
     101    case 2:
     102      {
     103        // it lies on both Shapes... could be an edge or an inner point
     104        // test the direction of the normals
     105        Vector direction=lhs->getNormal(point)+rhs->getNormal(point);
     106        // if the directions are opposite we lie on the inside
     107        return !direction.IsZero();
     108      }
     109      // no break necessary
     110    default:
     111      // if this happens there is something wrong
     112      ASSERT(0,"Default case should have never been used");
     113  }
     114  return false; // never reached
     115}
     116
     117Vector AndShape_impl::getNormal(const Vector &point) throw (NotOnSurfaceException){
     118  Vector res;
     119  if(!isOnSurface(point)){
     120    throw NotOnSurfaceException(__FILE__,__LINE__);
     121  }
     122  res += lhs->isOnSurface(point)?lhs->getNormal(point):zeroVec;
     123  res += rhs->isOnSurface(point)?rhs->getNormal(point):zeroVec;
     124  res.Normalize();
     125  return res;
     126}
     127
     128string AndShape_impl::toString(){
     129  return string("(") + lhs->toString() + string("&&") + rhs->toString() + string(")");
     130}
     131
    67132Shape operator&&(const Shape &lhs,const Shape &rhs){
    68133  Shape::impl_ptr newImpl = Shape::impl_ptr(new AndShape_impl(getShapeImpl(lhs),getShapeImpl(rhs)));
     
    82147}
    83148
     149bool OrShape_impl::isOnSurface(const Vector &point){
     150  // check the number of surfaces that this point is on
     151  int surfaces =0;
     152  surfaces += lhs->isOnSurface(point);
     153  surfaces += rhs->isOnSurface(point);
     154
     155  switch(surfaces){
     156    case 0:
     157      return false;
     158      // no break necessary
     159    case 1:
     160      // if it is inside for the object where it does not lie on
     161      // the surface the whole point lies inside
     162      return (lhs->isOnSurface(point) && !rhs->isInside(point)) ||
     163             (rhs->isOnSurface(point) && !lhs->isInside(point));
     164      // no break necessary
     165    case 2:
     166      {
     167        // it lies on both Shapes... could be an edge or an inner point
     168        // test the direction of the normals
     169        Vector direction=lhs->getNormal(point)+rhs->getNormal(point);
     170        // if the directions are opposite we lie on the inside
     171        return !direction.IsZero();
     172      }
     173      // no break necessary
     174    default:
     175      // if this happens there is something wrong
     176      ASSERT(0,"Default case should have never been used");
     177  }
     178  return false; // never reached
     179}
     180
     181Vector OrShape_impl::getNormal(const Vector &point) throw (NotOnSurfaceException){
     182  Vector res;
     183  if(!isOnSurface(point)){
     184    throw NotOnSurfaceException(__FILE__,__LINE__);
     185  }
     186  res += lhs->isOnSurface(point)?lhs->getNormal(point):zeroVec;
     187  res += rhs->isOnSurface(point)?rhs->getNormal(point):zeroVec;
     188  res.Normalize();
     189  return res;
     190}
     191
     192string OrShape_impl::toString(){
     193  return string("(") + lhs->toString() + string("||") + rhs->toString() + string(")");
     194}
     195
    84196Shape operator||(const Shape &lhs,const Shape &rhs){
    85197  Shape::impl_ptr newImpl = Shape::impl_ptr(new OrShape_impl(getShapeImpl(lhs),getShapeImpl(rhs)));
     
    99211}
    100212
     213bool NotShape_impl::isOnSurface(const Vector &point){
     214  return arg->isOnSurface(point);
     215}
     216
     217Vector NotShape_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){
     218  return -1*arg->getNormal(point);
     219}
     220
     221string NotShape_impl::toString(){
     222  return string("!") + arg->toString();
     223}
     224
    101225Shape operator!(const Shape &arg){
    102226  Shape::impl_ptr newImpl = Shape::impl_ptr(new NotShape_impl(getShapeImpl(arg)));
    103227  return Shape(newImpl);
    104228}
     229
     230/**************** global operations *********************************/
     231ostream &operator<<(ostream &ost,const Shape &shape){
     232  ost << shape.toString();
     233  return ost;
     234}
  • src/Shapes/Shape.hpp

    r7067bd6 r49d3d39  
    1010
    1111#include <boost/shared_ptr.hpp>
     12#include <iosfwd>
     13
     14#include "Exceptions/NotOnSurfaceException.hpp"
    1215
    1316class Vector;
     
    2528
    2629  bool isInside(const Vector &point) const;
     30  bool isOnSurface(const Vector &point) const;
     31  Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
    2732
    2833  Shape &operator=(const Shape& rhs);
    2934
     35  std::string toString() const;
    3036protected:
    3137  impl_ptr getImpl() const;
     
    4248Shape operator!(const Shape&);
    4349
     50std::ostream &operator<<(std::ostream&,const Shape&);
     51
    4452#endif /* SHAPE_HPP_ */
  • src/Shapes/ShapeOps.cpp

    r7067bd6 r49d3d39  
    1111#include "Helpers/Assert.hpp"
    1212
     13/*************** Base case ***********************/
     14
     15ShapeOpsBase_impl::ShapeOpsBase_impl(const Shape::impl_ptr &_arg) :
     16  arg(_arg){}
     17
     18ShapeOpsBase_impl::~ShapeOpsBase_impl(){}
     19
     20bool ShapeOpsBase_impl::isInside(const Vector &point){
     21  return arg->isInside(translateIn(point));
     22}
     23
     24bool ShapeOpsBase_impl::isOnSurface(const Vector &point){
     25  return arg->isOnSurface(translateIn(point));
     26}
     27
     28Vector 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  return translateOutNormal(arg->getNormal(helper));
     34}
     35
     36Shape::impl_ptr ShapeOpsBase_impl::getArg(){
     37  return arg;
     38}
     39
    1340/********************* Resize ********************/
    1441
    1542Resize_impl::Resize_impl(const Shape::impl_ptr &_arg,double _size) :
    16   arg(_arg), size(_size)
     43  ShapeOpsBase_impl(_arg), size(_size)
    1744{
    1845  ASSERT(size>0,"Cannot resize a Shape to size zero or below");
     
    2148Resize_impl::~Resize_impl(){}
    2249
    23 bool Resize_impl::isInside(const Vector& point){
    24   return arg->isInside((1/size) * point);
     50Vector Resize_impl::translateIn(const Vector& point){
     51  return (1/size) * point;
     52}
     53
     54Vector Resize_impl::translateOutPos(const Vector& point){
     55  return size * point;
     56}
     57
     58Vector Resize_impl::translateOutNormal(const Vector& point){
     59  return point;
     60}
     61
     62string Resize_impl::toString(){
     63  stringstream sstr;
     64  sstr << "resize(" << getArg()->toString() << "," << size << ")";
     65  return sstr.str();
    2566}
    2667
     
    3374
    3475Translate_impl::Translate_impl(const Shape::impl_ptr &_arg, const Vector &_offset) :
    35   arg(_arg),offset(_offset)
     76  ShapeOpsBase_impl(_arg),offset(_offset)
    3677{}
    3778
    3879Translate_impl::~Translate_impl(){}
    3980
    40 bool Translate_impl::isInside(const Vector& point){
    41   return arg->isInside(point-offset);
     81Vector Translate_impl::translateIn(const Vector& point){
     82  return point-offset;
     83}
     84
     85Vector Translate_impl::translateOutPos(const Vector& point){
     86  return point+offset;
     87}
     88
     89Vector Translate_impl::translateOutNormal(const Vector& point){
     90  return point;
     91}
     92
     93string Translate_impl::toString(){
     94  stringstream sstr;
     95  sstr << "translate(" << getArg()->toString() << "," << offset << ")";
     96  return sstr.str();
    4297}
    4398
     
    50105
    51106Stretch_impl::Stretch_impl(const Shape::impl_ptr &_arg, const Vector &_factors) :
    52   arg(_arg),factors(_factors)
     107  ShapeOpsBase_impl(_arg),factors(_factors)
    53108{
    54109  ASSERT(factors[0]>0,"cannot stretch a shape by a negative amount");
     
    62117Stretch_impl::~Stretch_impl(){}
    63118
    64 bool Stretch_impl::isInside(const Vector& point){
     119Vector Stretch_impl::translateIn(const Vector& point){
    65120  Vector helper=point;
    66121  helper.ScaleAll(reciFactors);
    67   return arg->isInside(helper);
     122  return helper;
     123}
     124
     125Vector Stretch_impl::translateOutPos(const Vector& point){
     126  Vector helper=point;
     127  helper.ScaleAll(factors);
     128  return helper;
     129}
     130
     131Vector Stretch_impl::translateOutNormal(const Vector& point){
     132  Vector helper=point;
     133  // the normalFactors are derived from appearances of the factors
     134  // with in the vectorproduct
     135  Vector normalFactors;
     136  normalFactors[0]=factors[1]*factors[2];
     137  normalFactors[1]=factors[0]*factors[2];
     138  normalFactors[2]=factors[0]*factors[1];
     139  helper.ScaleAll(normalFactors);
     140  return helper;
     141}
     142
     143string Stretch_impl::toString(){
     144  stringstream sstr;
     145  sstr << "stretch(" << getArg()->toString() << "," << factors << ")";
     146  return sstr.str();
    68147}
    69148
     
    76155
    77156Transform_impl::Transform_impl(const Shape::impl_ptr &_arg, const Matrix &_transformation) :
    78   arg(_arg),transformation(_transformation)
     157  ShapeOpsBase_impl(_arg),transformation(_transformation)
    79158{
    80159  transformationInv = transformation.invert();
     
    83162Transform_impl::~Transform_impl(){}
    84163
    85 bool Transform_impl::isInside(const Vector& point){
    86   return arg->isInside(transformationInv * point);
     164Vector Transform_impl::translateIn(const Vector& point){
     165  return transformationInv * point;
     166}
     167
     168Vector Transform_impl::translateOutPos(const Vector& point){
     169  return transformation * point;
     170}
     171
     172Vector Transform_impl::translateOutNormal(const Vector& point){
     173  Matrix mat = transformation.determinant() * transformation.invert().transpose();
     174  return mat * point;
     175}
     176
     177string Transform_impl::toString(){
     178  stringstream sstr;
     179  sstr << "transform(" << getArg()->toString() << "," << transformation << ")";
     180  return sstr.str();
    87181}
    88182
  • src/Shapes/ShapeOps_impl.hpp

    r7067bd6 r49d3d39  
    1313#include "Matrix.hpp"
    1414
    15 class Resize_impl :  public Shape_impl
     15class ShapeOpsBase_impl : public Shape_impl{
     16public:
     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);
     22protected:
     23  virtual Vector translateIn(const Vector &point)=0;
     24  virtual Vector translateOutPos(const Vector &point)=0;
     25  virtual Vector translateOutNormal(const Vector &point)=0;
     26  Shape::impl_ptr getArg();
     27private:
     28  Shape::impl_ptr arg;
     29};
     30
     31class Resize_impl :  public ShapeOpsBase_impl
    1632{
    1733public:
    1834  Resize_impl(const Shape::impl_ptr&,double);
    1935  virtual ~Resize_impl();
    20   virtual bool isInside(const Vector& point);
     36protected:
     37  virtual Vector translateIn(const Vector &point);
     38  virtual Vector translateOutPos(const Vector &point);
     39  virtual Vector translateOutNormal(const Vector &point);
     40  virtual std::string toString();
    2141private:
    22   Shape::impl_ptr arg;
    2342  double size;
    2443};
    2544
    26 class Translate_impl :  public Shape_impl
     45class Translate_impl :  public ShapeOpsBase_impl
    2746{
    2847public:
    2948  Translate_impl(const Shape::impl_ptr&, const Vector&);
    3049  virtual ~Translate_impl();
    31   virtual bool isInside(const Vector& point);
     50protected:
     51  virtual Vector translateIn(const Vector &point);
     52  virtual Vector translateOutPos(const Vector &point);
     53  virtual Vector translateOutNormal(const Vector &point);
     54  virtual std::string toString();
    3255private:
    33   Shape::impl_ptr arg;
    3456  Vector offset;
    3557};
    3658
    37 class Stretch_impl : public Shape_impl
     59class Stretch_impl : public ShapeOpsBase_impl
    3860{
    3961public:
    4062  Stretch_impl(const Shape::impl_ptr&, const Vector&);
    4163  virtual ~Stretch_impl();
    42   virtual bool isInside(const Vector& point);
     64protected:
     65  virtual Vector translateIn(const Vector &point);
     66  virtual Vector translateOutPos(const Vector &point);
     67  virtual Vector translateOutNormal(const Vector &point);
     68  virtual std::string toString();
    4369private:
    44   Shape::impl_ptr arg;
    4570  Vector factors;
    4671  Vector reciFactors;
    4772};
    4873
    49 class Transform_impl : public Shape_impl
     74class Transform_impl : public ShapeOpsBase_impl
    5075{
    5176public:
    5277  Transform_impl(const Shape::impl_ptr&, const Matrix&);
    5378  virtual ~Transform_impl();
    54   virtual bool isInside(const Vector& point);
     79protected:
     80  virtual Vector translateIn(const Vector &point);
     81  virtual Vector translateOutPos(const Vector &point);
     82  virtual Vector translateOutNormal(const Vector &point);
     83  virtual std::string toString();
    5584private:
    56   Shape::impl_ptr arg;
    5785  Matrix transformation;
    5886  Matrix transformationInv;
  • src/Shapes/Shape_impl.hpp

    r7067bd6 r49d3d39  
    1010
    1111#include "Shapes/Shape.hpp"
     12#include "vector.hpp"
    1213
    1314class Shape_impl {
     
    1617  virtual ~Shape_impl(){};
    1718  virtual bool isInside(const Vector &point)=0;
     19  virtual bool isOnSurface(const Vector &point)=0;
     20  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException)=0;
     21  virtual std::string toString()=0;
    1822};
    1923
     
    2327    return true;
    2428  }
     29  virtual bool isOnSurface(const Vector &point){
     30    return false;
     31  }
     32  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException){
     33    throw NotOnSurfaceException(__FILE__,__LINE__);
     34  }
     35  virtual std::string toString(){
     36    return "Everywhere()";
     37  }
    2538};
    2639
     
    2841  virtual bool isInside(const Vector &point){
    2942    return false;
     43  }
     44  virtual bool isOnSurface(const Vector &point){
     45    return false;
     46  }
     47  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException){
     48    throw NotOnSurfaceException(__FILE__,__LINE__);
     49  }
     50  virtual std::string toString(){
     51    return "Nowhere()";
    3052  }
    3153};
     
    3658  virtual ~AndShape_impl();
    3759  virtual bool isInside(const Vector &point);
     60  virtual bool isOnSurface(const Vector &point);
     61  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
     62  virtual std::string toString();
    3863private:
    3964  Shape::impl_ptr lhs;
     
    4671  virtual ~OrShape_impl();
    4772  virtual bool isInside(const Vector &point);
     73  virtual bool isOnSurface(const Vector &point);
     74  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
     75  virtual std::string toString();
    4876private:
    4977  Shape::impl_ptr lhs;
     
    5684  virtual ~NotShape_impl();
    5785  virtual bool isInside(const Vector &point);
     86  virtual bool isOnSurface(const Vector &point);
     87  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
     88  virtual std::string toString();
    5889private:
    5990  Shape::impl_ptr arg;
  • src/helpers.cpp

    r7067bd6 r49d3d39  
    141141  exit(255);
    142142}
     143
     144sign_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

    r7067bd6 r49d3d39  
    4343    const char *file, const int line);
    4444  //__attribute__ ((__return__));
     45
     46typedef enum {
     47  Minus = -1,
     48  Zero = 0,
     49  Plus = +1
     50} sign_t;
    4551
    4652double ask_value(const char *text);
     
    5258int CompareDoubles (const void * a, const void * b);
    5359void performCriticalExit();
     60sign_t sign(double value);
    5461
    5562/********************************************** helpful template functions *********************************/
  • src/unittests/LineUnittest.cpp

    r7067bd6 r49d3d39  
    2929void LineUnittest::setUp(){
    3030  // three lines along the axes
    31   la1 = new Line(zeroVec,e1);
    32   la2 = new Line(zeroVec,e2);
    33   la3 = new Line(zeroVec,e3);
     31  la1 = new Line(zeroVec,unitVec[0]);
     32  la2 = new Line(zeroVec,unitVec[1]);
     33  la3 = new Line(zeroVec,unitVec[2]);
    3434
    3535  // the lines along the planes defined by two coordinate axes
    36   lp1 = new Line(e1,e1-e2);
    37   lp2 = new Line(e2,e2-e3);
    38   lp3 = new Line(e3,e3-e1);
     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]);
    3939}
    4040void LineUnittest::tearDown(){
     
    5252
    5353  // direction+origin should never fail
    54   CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,e1));
    55   CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,e2));
    56   CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,e3));
     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]));
    5757
    5858  // two points fails if both points are the same
    59   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e1,e2));
    60   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e2,e3));
    61   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e3,e1));
     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]));
    6262  // for zerovectors
    63   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e1,zeroVec));
    64   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e2,zeroVec));
    65   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e3,zeroVec));
     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));
    6666  // now we pass two times the same point
    6767  CPPUNIT_ASSERT_THROW(makeLineThrough(zeroVec,zeroVec),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);
     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);
    7171
    7272}
     
    7878void LineUnittest::constructionResultTest(){
    7979  // test all directions
    80   CPPUNIT_ASSERT(testDirection(la1->getDirection(),e1));
    81   CPPUNIT_ASSERT(testDirection(la2->getDirection(),e2));
    82   CPPUNIT_ASSERT(testDirection(la3->getDirection(),e3));
     80  CPPUNIT_ASSERT(testDirection(la1->getDirection(),unitVec[0]));
     81  CPPUNIT_ASSERT(testDirection(la2->getDirection(),unitVec[1]));
     82  CPPUNIT_ASSERT(testDirection(la3->getDirection(),unitVec[2]));
    8383
    8484  // test origins
     
    9292  CPPUNIT_ASSERT(la3->isContained(zeroVec));
    9393
    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));
     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]));
    105105}
    106106
     
    112112
    113113  // multiples of the second support vector
    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));
     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]));
    125125
    126126  // negative multiples
    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));
     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]));
    134134
    135135  // points that should not be on the lines
    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));
     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]));
    147147
    148148  // For the plane lines
    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)));
     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])));
    164164}
    165165
     
    177177  // axes and plane lines
    178178  fixture = la1->getIntersection(*lp1);
    179   CPPUNIT_ASSERT_EQUAL(fixture,e1);
     179  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
    180180  fixture = la2->getIntersection(*lp2);
    181   CPPUNIT_ASSERT_EQUAL(fixture,e2);
     181  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
    182182  fixture = la3->getIntersection(*lp3);
    183   CPPUNIT_ASSERT_EQUAL(fixture,e3);
     183  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    184184
    185185  fixture = la1->getIntersection(*lp3);
    186   CPPUNIT_ASSERT_EQUAL(fixture,e1);
     186  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
    187187  fixture = la2->getIntersection(*lp1);
    188   CPPUNIT_ASSERT_EQUAL(fixture,e2);
     188  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
    189189  fixture = la3->getIntersection(*lp2);
    190   CPPUNIT_ASSERT_EQUAL(fixture,e3);
     190  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    191191
    192192  // two plane lines
    193193  fixture = lp1->getIntersection(*lp2);
    194   CPPUNIT_ASSERT_EQUAL(fixture,e2);
     194  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
    195195  fixture = lp2->getIntersection(*lp3);
    196   CPPUNIT_ASSERT_EQUAL(fixture,e3);
     196  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    197197  fixture = lp3->getIntersection(*lp1);
    198   CPPUNIT_ASSERT_EQUAL(fixture,e1);
     198  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
    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(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);
     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]);
    257257
    258258  // more vectors on the axis
    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);
     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]);
    272272
    273273  // negative factors
    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);
     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]);
    287287
    288288
    289289
    290290  // now the real rotations
    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);
     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]);
    320320
    321321
     
    323323
    324324  // Vectors on the line
    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);
     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]);
    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],e1));
    361     CPPUNIT_ASSERT(testDirection(res[1],e1));
     360    CPPUNIT_ASSERT(testDirection(res[0],unitVec[0]));
     361    CPPUNIT_ASSERT(testDirection(res[1],unitVec[0]));
    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],e2));
    369     CPPUNIT_ASSERT(testDirection(res[1],e2));
     368    CPPUNIT_ASSERT(testDirection(res[0],unitVec[1]));
     369    CPPUNIT_ASSERT(testDirection(res[1],unitVec[1]));
    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],e3));
    377     CPPUNIT_ASSERT(testDirection(res[1],e3));
     376    CPPUNIT_ASSERT(testDirection(res[0],unitVec[2]));
     377    CPPUNIT_ASSERT(testDirection(res[1],unitVec[2]));
    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]==e1) || (res[0]==e2));
    385     CPPUNIT_ASSERT((res[1]==e1) || (res[1]==e2));
     384    CPPUNIT_ASSERT((res[0]==unitVec[0]) || (res[0]==unitVec[1]));
     385    CPPUNIT_ASSERT((res[1]==unitVec[0]) || (res[1]==unitVec[1]));
    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]==e2) || (res[0]==e3));
    393     CPPUNIT_ASSERT((res[1]==e2) || (res[1]==e3));
     392    CPPUNIT_ASSERT((res[0]==unitVec[1]) || (res[0]==unitVec[2]));
     393    CPPUNIT_ASSERT((res[1]==unitVec[1]) || (res[1]==unitVec[2]));
    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]==e3) || (res[0]==e1));
    401     CPPUNIT_ASSERT((res[1]==e3) || (res[1]==e1));
    402     CPPUNIT_ASSERT(res[0]!=res[1]);
    403   }
    404 }
     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}
  • src/unittests/MatrixUnittest.cpp

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

    r7067bd6 r49d3d39  
    2424
    2525void PlaneUnittest::setUp(){
    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);
     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]);
    3030}
    3131
     
    4242
    4343  // three points
    44   CPPUNIT_ASSERT_NO_THROW(Plane(e1,e2,e3));
     44  CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],unitVec[1],unitVec[2]));
    4545  // when only two points are differnt this gives an error
    46   CPPUNIT_ASSERT_THROW(Plane(e1,e2,e2),LinearDependenceException);
     46  CPPUNIT_ASSERT_THROW(Plane(unitVec[0],unitVec[1],unitVec[1]),LinearDependenceException);
    4747  // same with only one point
    48   CPPUNIT_ASSERT_THROW(Plane(e1,e1,e1),LinearDependenceException);
     48  CPPUNIT_ASSERT_THROW(Plane(unitVec[0],unitVec[0],unitVec[0]),LinearDependenceException);
    4949
    5050  // use two vector giving two directions
    51   CPPUNIT_ASSERT_NO_THROW(Plane(e1,e2,0));
     51  CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],unitVec[1],0));
    5252  // and again this is actually only one vector
    53   CPPUNIT_ASSERT_THROW(Plane(e1,e1,0),LinearDependenceException);
     53  CPPUNIT_ASSERT_THROW(Plane(unitVec[0],unitVec[0],0),LinearDependenceException);
    5454  // Zero vector does not give a good direction
    55   CPPUNIT_ASSERT_THROW(Plane(e1,zeroVec,0),ZeroVectorException);
     55  CPPUNIT_ASSERT_THROW(Plane(unitVec[0],zeroVec,0),ZeroVectorException);
    5656
    5757  // use a normalvector and an scalar offset
    58   CPPUNIT_ASSERT_NO_THROW(Plane(e1,0));
     58  CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],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(e1,zeroVec));
     63  CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],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(e1,e2,zeroVec);
    78     CPPUNIT_ASSERT(testNormal(e3,p1.getNormal()));
     77    Plane p1(unitVec[0],unitVec[1],zeroVec);
     78    CPPUNIT_ASSERT(testNormal(unitVec[2],p1.getNormal()));
    7979    CPPUNIT_ASSERT_EQUAL(0.,p1.getOffset());
    8080
    81     Plane p2(e1,e3,zeroVec);
    82     CPPUNIT_ASSERT(testNormal(e2,p2.getNormal()));
     81    Plane p2(unitVec[0],unitVec[2],zeroVec);
     82    CPPUNIT_ASSERT(testNormal(unitVec[1],p2.getNormal()));
    8383    CPPUNIT_ASSERT_EQUAL(0.,p2.getOffset());
    8484
    85     Plane p3(e2,e3,zeroVec);
    86     CPPUNIT_ASSERT(testNormal(e1,p3.getNormal()));
     85    Plane p3(unitVec[1],unitVec[2],zeroVec);
     86    CPPUNIT_ASSERT(testNormal(unitVec[0],p3.getNormal()));
    8787    CPPUNIT_ASSERT_EQUAL(0.,p3.getOffset());
    8888  }
    8989  {
    9090    // construct with two directions + offset
    91     Plane p1(e1,e2,0);
    92     CPPUNIT_ASSERT(testNormal(e3,p1.getNormal()));
     91    Plane p1(unitVec[0],unitVec[1],0);
     92    CPPUNIT_ASSERT(testNormal(unitVec[2],p1.getNormal()));
    9393    CPPUNIT_ASSERT_EQUAL(0.,p1.getOffset());
    9494
    95     Plane p2(e1,e3,0);
    96     CPPUNIT_ASSERT(testNormal(e2,p2.getNormal()));
     95    Plane p2(unitVec[0],unitVec[2],0);
     96    CPPUNIT_ASSERT(testNormal(unitVec[1],p2.getNormal()));
    9797    CPPUNIT_ASSERT_EQUAL(0.,p2.getOffset());
    9898
    99     Plane p3(e2,e3,0);
    100     CPPUNIT_ASSERT(testNormal(e1,p3.getNormal()));
     99    Plane p3(unitVec[1],unitVec[2],0);
     100    CPPUNIT_ASSERT(testNormal(unitVec[0],p3.getNormal()));
    101101    CPPUNIT_ASSERT_EQUAL(0.,p3.getOffset());
    102102  }
     
    145145void PlaneUnittest::operationsTest(){
    146146  {
    147     Vector t = (1./3.)*(e1+e2+e3);
     147    Vector t = (1./3.)*(unitVec[0]+unitVec[1]+unitVec[2]);
    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(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));
     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]));
    158158}
    159159
     
    162162
    163163  // some Vectors that lie on the planes
    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);
     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]);
    170170
    171171  fixture = p2->mirrorVector(zeroVec);
    172172  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
    173   fixture = p2->mirrorVector(e1);
    174   CPPUNIT_ASSERT_EQUAL(fixture,e1);
    175   fixture = p2->mirrorVector(e2);
    176   CPPUNIT_ASSERT_EQUAL(fixture,e2);
     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]);
    177177
    178178  fixture = p3->mirrorVector(zeroVec);
    179179  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
    180   fixture = p3->mirrorVector(e1);
    181   CPPUNIT_ASSERT_EQUAL(fixture,e1);
    182   fixture = p3->mirrorVector(e3);
    183   CPPUNIT_ASSERT_EQUAL(fixture,e3);
     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]);
    184184
    185185  fixture = p4->mirrorVector(zeroVec);
    186186  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
    187   fixture = p4->mirrorVector(e2);
    188   CPPUNIT_ASSERT_EQUAL(fixture,e2);
    189   fixture = p4->mirrorVector(e3);
    190   CPPUNIT_ASSERT_EQUAL(fixture,e3);
     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]);
    191191
    192192  // some Vectors outside of the planes
    193193  {
    194     Vector t = (2./3.)*(e1+e2+e3);
     194    Vector t = (2./3.)*(unitVec[0]+unitVec[1]+unitVec[2]);
    195195    fixture = p1->mirrorVector(zeroVec);
    196196    CPPUNIT_ASSERT_EQUAL(fixture,t);
    197197  }
    198198
    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);
     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]);
    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(e1, zeroVec).GetIntersection(l1) );
     211  CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unitVec[0], 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(e1,Vector(0,1,1));
    216   CPPUNIT_ASSERT_NO_THROW(fixture = Plane(e2, Vector(2,1,0)).GetIntersection(l2) );
     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) );
    217217  CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture );
    218218}
  • src/unittests/ShapeUnittest.cpp

    r7067bd6 r49d3d39  
    1717
    1818#include "Shapes/Shape.hpp"
     19#include "Shapes/BaseShapes.hpp"
    1920#include "vector.cpp"
    2021
     
    2425void ShapeUnittest::setUp()
    2526{
    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;
     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];
    5354}
    5455
     
    113114  CPPUNIT_ASSERT(Everywhere().isInside(v122));
    114115  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
     174void 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));
    115258}
    116259
     
    360503  }
    361504
     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
    362624}
  • src/unittests/ShapeUnittest.hpp

    r7067bd6 r49d3d39  
    2020  CPPUNIT_TEST_SUITE( ShapeUnittest) ;
    2121  CPPUNIT_TEST ( baseShapesTest );
     22  CPPUNIT_TEST ( surfaceTest );
    2223  CPPUNIT_TEST ( assignmentTest );
    2324  CPPUNIT_TEST ( operatorTest );
     
    2930
    3031  void baseShapesTest();
     32  void surfaceTest();
    3133  void assignmentTest();
    3234  void operatorTest();
  • src/vector.cpp

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

    r7067bd6 r49d3d39  
    8080  double NormSquared() const;
    8181  void Normalize();
     82  Vector getNormalized() const;
    8283  void Zero();
    8384  void One(const double one);
     
    106107// some commonly used and fixed vectors
    107108const extern Vector zeroVec;
    108 const extern Vector e1;
    109 const extern Vector e2;
    110 const extern Vector e3;
     109const extern Vector unitVec[NDIM];
    111110
    112111ostream & operator << (ostream& ost, const Vector &m);
Note: See TracChangeset for help on using the changeset viewer.