Changes in / [a7b777c:2ad482]


Ignore:
Location:
src
Files:
11 added
26 edited

Legend:

Unmodified
Added
Removed
  • src/Box.cpp

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

    ra7b777c r2ad482  
    1111class Matrix;
    1212class Vector;
     13class Shape;
    1314
    1415#include <list>
     
    8990  double periodicDistance(const Vector &point1,const Vector &point2) const;
    9091
     92  Shape getShape() const;
     93
    9194private:
    9295  Matrix *M;    //!< Defines the layout of the box
  • src/Line.cpp

    ra7b777c r2ad482  
    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
     
    211219}
    212220
     221Line 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
     239Plane 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
    213248Plane Line::getOrthogonalPlane(const Vector &origin) const{
    214249  return Plane(getDirection(),origin);
     
    234269}
    235270
     271LinePoint 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
     278LinePoint Line::posEndpoint() const{
     279  return LinePoint(*this, numeric_limits<double>::infinity());
     280}
     281LinePoint Line::negEndpoint() const{
     282  return LinePoint(*this,-numeric_limits<double>::infinity());
     283}
     284
     285bool operator==(const Line &x,const Line &y){
     286  return *x.origin == *y.origin && *x.direction == *y.direction;
     287}
     288
    236289Line makeLineThrough(const Vector &x1, const Vector &x2){
    237290  if(x1==x2){
     
    240293  return Line(x1,x1-x2);
    241294}
     295
     296
     297/******************************** Points on the line ********************/
     298
     299LinePoint::LinePoint(const LinePoint &src) :
     300  line(src.line),param(src.param)
     301{}
     302
     303LinePoint::LinePoint(const Line &_line, double _param) :
     304  line(_line),param(_param)
     305{}
     306
     307LinePoint& LinePoint::operator=(const LinePoint &src){
     308  line=src.line;
     309  param=src.param;
     310  return *this;
     311}
     312
     313Vector LinePoint::getPoint() const{
     314  ASSERT(!isInfinite(),"getPoint() on infinite LinePoint called");
     315  return (*line.origin)+param*(*line.direction);
     316}
     317
     318Line LinePoint::getLine() const{
     319  return line;
     320}
     321
     322bool LinePoint::isInfinite() const{
     323  return isPosInfinity() || isNegInfinity();
     324}
     325bool LinePoint::isPosInfinity() const{
     326  return param == numeric_limits<double>::infinity();
     327}
     328bool LinePoint::isNegInfinity() const{
     329  return param ==-numeric_limits<double>::infinity();
     330}
     331
     332bool 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}
     337bool 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

    ra7b777c r2ad482  
    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;
     
    3540
    3641  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;
    3744
    3845  Plane getOrthogonalPlane(const Vector &origin) const;
    3946
    4047  std::vector<Vector> getSphereIntersections() const;
     48
     49  LinePoint getLinePoint(const Vector&) const;
     50  LinePoint posEndpoint() const;
     51  LinePoint negEndpoint() const;
     52
     53
    4154
    4255private:
     
    4558};
    4659
     60bool operator==(const Line&,const Line&);
     61
    4762/**
    4863 * Named constructor to make a line through two points
     
    5065Line makeLineThrough(const Vector &x1, const Vector &x2);
    5166
     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 */
     72class LinePoint{
     73  friend class Line;
     74  friend bool operator==(const LinePoint&, const LinePoint&);
     75  friend bool operator<(const LinePoint&, const LinePoint&);
     76public:
     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
     85private:
     86  LinePoint(const Line&,double);
     87  Line line;
     88  double param;
     89};
     90
     91bool operator==(const LinePoint&, const LinePoint&);
     92bool operator<(const LinePoint&, const LinePoint&);
     93
     94inline bool operator!= (const LinePoint& x, const LinePoint& y) { return !(x==y); }
     95inline bool operator>  (const LinePoint& x, const LinePoint& y) { return y<x; }
     96inline bool operator<= (const LinePoint& x, const LinePoint& y) { return !(y<x); }
     97inline bool operator>= (const LinePoint& x, const LinePoint& y) { return !(x<y); }
     98
     99
    52100#endif /* LINE_HPP_ */
  • src/Makefile.am

    ra7b777c r2ad482  
    8484  Exceptions/MissingValueException.cpp \
    8585  Exceptions/NotInvertibleException.cpp \
     86  Exceptions/NotOnSurfaceException.cpp \
     87  Exceptions/ShapeException.cpp \
    8688  Exceptions/ParseError.cpp \
    8789  Exceptions/SkewException.cpp \
     
    9597  Exceptions/MissingValueException.hpp \
    9698  Exceptions/NotInvertibleException.hpp \
     99  Exceptions/NotOnSurfaceException.hpp \
     100  Exceptions/ShapeException.hpp \
    97101  Exceptions/ParseError.hpp \
    98102  Exceptions/SkewException.hpp \
     
    153157  Descriptors/AtomIdDescriptor.cpp \
    154158  Descriptors/AtomSelectionDescriptor.cpp \
     159  Descriptors/AtomShapeDescriptor.cpp \
    155160  Descriptors/AtomTypeDescriptor.cpp \
    156161  Descriptors/MoleculeDescriptor.cpp \
     
    165170  Descriptors/AtomIdDescriptor.hpp \
    166171  Descriptors/AtomSelectionDescriptor.hpp \
     172  Descriptors/AtomShapeDescriptor.hpp \
    167173  Descriptors/AtomTypeDescriptor.hpp \
    168174  Descriptors/MoleculeDescriptor.hpp \
     
    214220  leastsquaremin.cpp \
    215221  Line.cpp \
     222  LineSegment.cpp \
     223  LineSegmentSet.cpp \
    216224  linkedcell.cpp \
    217225  log.cpp \
     
    265273  leastsquaremin.hpp \
    266274  Line.hpp \
     275  LineSegment.hpp \
     276  LineSegmentSet.hpp \
    267277  linkedcell.hpp \
    268278  lists.hpp \
  • src/Matrix.cpp

    ra7b777c r2ad482  
    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

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

    ra7b777c r2ad482  
    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

    ra7b777c r2ad482  
    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

    ra7b777c r2ad482  
    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 "Line.hpp"
     16#include "Plane.hpp"
     17#include "LineSegment.hpp"
     18#include "LineSegmentSet.hpp"
     19
     20#include <cmath>
     21#include <algorithm>
    1222
    1323bool Sphere_impl::isInside(const Vector &point){
    1424  return point.NormSquared()<=1;
     25}
     26
     27bool Sphere_impl::isOnSurface(const Vector &point){
     28  return fabs(point.NormSquared()-1)<MYEPSILON;
     29}
     30
     31Vector Sphere_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){
     32  if(!isOnSurface(point)){
     33    throw NotOnSurfaceException(__FILE__,__LINE__);
     34  }
     35  return point;
     36}
     37
     38LineSegmentSet 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
     47string Sphere_impl::toString(){
     48  return "Sphere()";
    1549}
    1650
     
    2054}
    2155
     56Shape Sphere(const Vector &center,double radius){
     57  return translate(resize(Sphere(),radius),center);
     58}
     59
     60Shape Ellipsoid(const Vector &center, const Vector &radius){
     61  return translate(stretch(Sphere(),radius),center);
     62}
     63
    2264bool Cuboid_impl::isInside(const Vector &point){
    23   return point[0]<=1 && point[1]<=1 && point[2]<=1;
     65  return fabs(point[0])<=1 && fabs(point[1])<=1 && fabs(point[2])<=1;
     66}
     67
     68bool 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
     79Vector 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
     97LineSegmentSet 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
     127string Cuboid_impl::toString(){
     128  return "Cuboid()";
    24129}
    25130
    26131Shape Cuboid(){
    27   Shape::impl_ptr impl = Shape::impl_ptr(new Sphere_impl());
     132  Shape::impl_ptr impl = Shape::impl_ptr(new Cuboid_impl());
    28133  return Shape(impl);
    29134}
     135
     136Shape 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

    ra7b777c r2ad482  
    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

    ra7b777c r2ad482  
    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();
    1519};
    1620
    1721class Cuboid_impl : public Shape_impl {
    1822  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();
    1927};
    2028
  • src/Shapes/Shape.cpp

    ra7b777c r2ad482  
    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);
     33}
     34
     35LineSegmentSet Shape::getLineIntersections(const Line &line){
     36  return impl->getLineIntersections(line);
    1937}
    2038
     
    3048}
    3149
     50std::string Shape::toString() const{
     51  return impl->toString();
     52}
     53
    3254Shape::impl_ptr Shape::getImpl() const{
    3355  return impl;
     
    6587}
    6688
     89bool 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
     121Vector 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
     132LineSegmentSet AndShape_impl::getLineIntersections(const Line &line){
     133  return intersect(lhs->getLineIntersections(line),rhs->getLineIntersections(line));
     134}
     135
     136string AndShape_impl::toString(){
     137  return string("(") + lhs->toString() + string("&&") + rhs->toString() + string(")");
     138}
     139
    67140Shape operator&&(const Shape &lhs,const Shape &rhs){
    68141  Shape::impl_ptr newImpl = Shape::impl_ptr(new AndShape_impl(getShapeImpl(lhs),getShapeImpl(rhs)));
     
    82155}
    83156
     157bool 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
     189Vector 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
     200LineSegmentSet OrShape_impl::getLineIntersections(const Line &line){
     201  return merge(lhs->getLineIntersections(line),rhs->getLineIntersections(line));
     202}
     203
     204string OrShape_impl::toString(){
     205  return string("(") + lhs->toString() + string("||") + rhs->toString() + string(")");
     206}
     207
    84208Shape operator||(const Shape &lhs,const Shape &rhs){
    85209  Shape::impl_ptr newImpl = Shape::impl_ptr(new OrShape_impl(getShapeImpl(lhs),getShapeImpl(rhs)));
     
    99223}
    100224
     225bool NotShape_impl::isOnSurface(const Vector &point){
     226  return arg->isOnSurface(point);
     227}
     228
     229Vector NotShape_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){
     230  return -1*arg->getNormal(point);
     231}
     232
     233LineSegmentSet NotShape_impl::getLineIntersections(const Line &line){
     234  return invert(arg->getLineIntersections(line));
     235}
     236
     237string NotShape_impl::toString(){
     238  return string("!") + arg->toString();
     239}
     240
    101241Shape operator!(const Shape &arg){
    102242  Shape::impl_ptr newImpl = Shape::impl_ptr(new NotShape_impl(getShapeImpl(arg)));
    103243  return Shape(newImpl);
    104244}
     245
     246/**************** global operations *********************************/
     247ostream &operator<<(ostream &ost,const Shape &shape){
     248  ost << shape.toString();
     249  return ost;
     250}
  • src/Shapes/Shape.hpp

    ra7b777c r2ad482  
    1010
    1111#include <boost/shared_ptr.hpp>
     12#include <iosfwd>
     13
     14#include "Exceptions/NotOnSurfaceException.hpp"
    1215
    1316class Vector;
    1417class Shape_impl;
     18class LineSegmentSet;
     19class Line;
    1520
    1621class Shape
     
    2530
    2631  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&);
    2736
    2837  Shape &operator=(const Shape& rhs);
    2938
     39  std::string toString() const;
    3040protected:
    3141  impl_ptr getImpl() const;
     
    4252Shape operator!(const Shape&);
    4353
     54std::ostream &operator<<(std::ostream&,const Shape&);
     55
    4456#endif /* SHAPE_HPP_ */
  • src/Shapes/ShapeOps.cpp

    ra7b777c r2ad482  
    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  Vector res = translateOutNormal(arg->getNormal(helper));
     34  res.Normalize();
     35  return res;
     36}
     37
     38LineSegmentSet 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
     57Shape::impl_ptr ShapeOpsBase_impl::getArg(){
     58  return arg;
     59}
     60
    1361/********************* Resize ********************/
    1462
    1563Resize_impl::Resize_impl(const Shape::impl_ptr &_arg,double _size) :
    16   arg(_arg), size(_size)
     64  ShapeOpsBase_impl(_arg), size(_size)
    1765{
    1866  ASSERT(size>0,"Cannot resize a Shape to size zero or below");
     
    2169Resize_impl::~Resize_impl(){}
    2270
    23 bool Resize_impl::isInside(const Vector& point){
    24   return arg->isInside((1/size) * point);
     71Vector Resize_impl::translateIn(const Vector& point){
     72  return (1/size) * point;
     73}
     74
     75Vector Resize_impl::translateOutPos(const Vector& point){
     76  return size * point;
     77}
     78
     79Vector Resize_impl::translateOutNormal(const Vector& point){
     80  return point;
     81}
     82
     83string Resize_impl::toString(){
     84  stringstream sstr;
     85  sstr << "resize(" << getArg()->toString() << "," << size << ")";
     86  return sstr.str();
    2587}
    2688
     
    3395
    3496Translate_impl::Translate_impl(const Shape::impl_ptr &_arg, const Vector &_offset) :
    35   arg(_arg),offset(_offset)
     97  ShapeOpsBase_impl(_arg),offset(_offset)
    3698{}
    3799
    38100Translate_impl::~Translate_impl(){}
    39101
    40 bool Translate_impl::isInside(const Vector& point){
    41   return arg->isInside(point-offset);
     102Vector Translate_impl::translateIn(const Vector& point){
     103  return point-offset;
     104}
     105
     106Vector Translate_impl::translateOutPos(const Vector& point){
     107  return point+offset;
     108}
     109
     110Vector Translate_impl::translateOutNormal(const Vector& point){
     111  return point;
     112}
     113
     114string Translate_impl::toString(){
     115  stringstream sstr;
     116  sstr << "translate(" << getArg()->toString() << "," << offset << ")";
     117  return sstr.str();
    42118}
    43119
     
    50126
    51127Stretch_impl::Stretch_impl(const Shape::impl_ptr &_arg, const Vector &_factors) :
    52   arg(_arg),factors(_factors)
     128  ShapeOpsBase_impl(_arg),factors(_factors)
    53129{
    54130  ASSERT(factors[0]>0,"cannot stretch a shape by a negative amount");
     
    62138Stretch_impl::~Stretch_impl(){}
    63139
    64 bool Stretch_impl::isInside(const Vector& point){
     140Vector Stretch_impl::translateIn(const Vector& point){
    65141  Vector helper=point;
    66142  helper.ScaleAll(reciFactors);
    67   return arg->isInside(helper);
     143  return helper;
     144}
     145
     146Vector Stretch_impl::translateOutPos(const Vector& point){
     147  Vector helper=point;
     148  helper.ScaleAll(factors);
     149  return helper;
     150}
     151
     152Vector 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
     164string Stretch_impl::toString(){
     165  stringstream sstr;
     166  sstr << "stretch(" << getArg()->toString() << "," << factors << ")";
     167  return sstr.str();
    68168}
    69169
     
    76176
    77177Transform_impl::Transform_impl(const Shape::impl_ptr &_arg, const Matrix &_transformation) :
    78   arg(_arg),transformation(_transformation)
     178  ShapeOpsBase_impl(_arg),transformation(_transformation)
    79179{
    80180  transformationInv = transformation.invert();
     
    83183Transform_impl::~Transform_impl(){}
    84184
    85 bool Transform_impl::isInside(const Vector& point){
    86   return arg->isInside(transformationInv * point);
     185Vector Transform_impl::translateIn(const Vector& point){
     186  return transformationInv * point;
     187}
     188
     189Vector Transform_impl::translateOutPos(const Vector& point){
     190  return transformation * point;
     191}
     192
     193Vector Transform_impl::translateOutNormal(const Vector& point){
     194  Matrix mat = transformation.invert().transpose();
     195  return mat * point;
     196}
     197
     198string Transform_impl::toString(){
     199  stringstream sstr;
     200  sstr << "transform(" << getArg()->toString() << "," << transformation << ")";
     201  return sstr.str();
    87202}
    88203
  • src/Shapes/ShapeOps_impl.hpp

    ra7b777c r2ad482  
    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);
     22  virtual LineSegmentSet getLineIntersections(const Line&);
     23protected:
     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();
     28private:
     29  Shape::impl_ptr arg;
     30};
     31
     32class Resize_impl :  public ShapeOpsBase_impl
    1633{
    1734public:
    1835  Resize_impl(const Shape::impl_ptr&,double);
    1936  virtual ~Resize_impl();
    20   virtual bool isInside(const Vector& point);
     37protected:
     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();
    2142private:
    22   Shape::impl_ptr arg;
    2343  double size;
    2444};
    2545
    26 class Translate_impl :  public Shape_impl
     46class Translate_impl :  public ShapeOpsBase_impl
    2747{
    2848public:
    2949  Translate_impl(const Shape::impl_ptr&, const Vector&);
    3050  virtual ~Translate_impl();
    31   virtual bool isInside(const Vector& point);
     51protected:
     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();
    3256private:
    33   Shape::impl_ptr arg;
    3457  Vector offset;
    3558};
    3659
    37 class Stretch_impl : public Shape_impl
     60class Stretch_impl : public ShapeOpsBase_impl
    3861{
    3962public:
    4063  Stretch_impl(const Shape::impl_ptr&, const Vector&);
    4164  virtual ~Stretch_impl();
    42   virtual bool isInside(const Vector& point);
     65protected:
     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();
    4370private:
    44   Shape::impl_ptr arg;
    4571  Vector factors;
    4672  Vector reciFactors;
    4773};
    4874
    49 class Transform_impl : public Shape_impl
     75class Transform_impl : public ShapeOpsBase_impl
    5076{
    5177public:
    5278  Transform_impl(const Shape::impl_ptr&, const Matrix&);
    5379  virtual ~Transform_impl();
    54   virtual bool isInside(const Vector& point);
     80protected:
     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();
    5585private:
    56   Shape::impl_ptr arg;
    5786  Matrix transformation;
    5887  Matrix transformationInv;
  • src/Shapes/Shape_impl.hpp

    ra7b777c r2ad482  
    1010
    1111#include "Shapes/Shape.hpp"
     12#include "vector.hpp"
     13#include "Line.hpp"
     14#include "LineSegment.hpp"
     15#include "LineSegmentSet.hpp"
     16
    1217
    1318class Shape_impl {
     
    1621  virtual ~Shape_impl(){};
    1722  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;
    1827};
    1928
     
    2332    return true;
    2433  }
     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  }
    2548};
    2649
     
    2851  virtual bool isInside(const Vector &point){
    2952    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()";
    3065  }
    3166};
     
    3671  virtual ~AndShape_impl();
    3772  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();
    3877private:
    3978  Shape::impl_ptr lhs;
     
    4685  virtual ~OrShape_impl();
    4786  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();
    4891private:
    4992  Shape::impl_ptr lhs;
     
    5699  virtual ~NotShape_impl();
    57100  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();
    58105private:
    59106  Shape::impl_ptr arg;
  • src/helpers.cpp

    ra7b777c r2ad482  
    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

    ra7b777c r2ad482  
    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

    ra7b777c r2ad482  
    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

    ra7b777c r2ad482  
    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

    ra7b777c r2ad482  
    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

    ra7b777c r2ad482  
    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

    ra7b777c r2ad482  
    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

    ra7b777c r2ad482  
    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

    ra7b777c r2ad482  
    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.