Changes in / [fd4905:6c438f]


Ignore:
Location:
src
Files:
8 added
2 deleted
31 edited

Legend:

Unmodified
Added
Removed
  • src/Box.cpp

    rfd4905 r6c438f  
    2929#include "LinearAlgebra/Vector.hpp"
    3030#include "LinearAlgebra/Plane.hpp"
     31#include "Shapes/BaseShapes.hpp"
     32#include "Shapes/ShapeOps.hpp"
    3133
    3234#include "Helpers/Assert.hpp"
     
    218220}
    219221
     222Shape Box::getShape() const{
     223  return transform(Cuboid(Vector(0,0,0),Vector(1,1,1)),(*M));
     224}
     225
    220226const Box::Conditions_t Box::getConditions(){
    221227  return conditions;
  • src/Box.hpp

    rfd4905 r6c438f  
    1111class Matrix;
    1212class Vector;
     13class Shape;
    1314class Plane;
    1415
     
    99100  double periodicDistance(const Vector &point1,const Vector &point2) const;
    100101
     102  Shape getShape() const;
    101103  const Conditions_t getConditions();
    102104  void setCondition(int,BoundaryCondition_t);
  • src/Descriptors/AtomShapeDescriptor.cpp

    rfd4905 r6c438f  
    99 * AtomShapeDescriptor.cpp
    1010 *
    11  *  Created on: Aug 9, 2010
    12  *      Author: heber
     11 *  Created on: Jul 22, 2010
     12 *      Author: crueger
    1313 */
    1414
     
    2424
    2525#include "atom.hpp"
    26 #include "Patterns/ObservedContainer_impl.hpp"
    27 #include "Shapes/Shape.hpp"
    2826
    29 using namespace std;
    30 
    31 
    32 AtomShapeDescriptor_impl::AtomShapeDescriptor_impl(Shape _shape) :
     27AtomShapeDescriptor_impl::AtomShapeDescriptor_impl(const Shape &_shape) :
    3328  shape(_shape)
    3429{}
    3530
    36 AtomShapeDescriptor_impl::~AtomShapeDescriptor_impl()
    37 {}
     31AtomShapeDescriptor_impl::~AtomShapeDescriptor_impl(){}
    3832
    39 bool AtomShapeDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom) {
     33bool AtomShapeDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom){
    4034  return shape.isInside(atom.second->getPosition());
    4135}
    4236
    43 AtomDescriptor AtomByShape(Shape &_shape){
    44   return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomShapeDescriptor_impl(_shape)));
     37
     38AtomDescriptor AtomByShape(const Shape &shape){
     39  return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomShapeDescriptor_impl(shape)));
    4540}
  • src/Descriptors/AtomShapeDescriptor.hpp

    rfd4905 r6c438f  
    22 * AtomShapeDescriptor.hpp
    33 *
    4  *  Created on: Aug 9, 2010
    5  *      Author: heber
     4 *  Created on: Jul 22, 2010
     5 *      Author: crueger
    66 */
    77
     
    1414class Shape;
    1515
    16 AtomDescriptor AtomByShape(Shape &_shape);
     16AtomDescriptor AtomByShape(const Shape &shape);
    1717
    1818#endif /* ATOMSHAPEDESCRIPTOR_HPP_ */
  • src/Descriptors/AtomShapeDescriptor_impl.hpp

    rfd4905 r6c438f  
    22 * AtomShapeDescriptor_impl.hpp
    33 *
    4  *  Created on: Aug 9, 2010
    5  *      Author: heber
     4 *  Created on: Jul 22, 2010
     5 *      Author: crueger
    66 */
    77
    8 #ifndef ATOMSHAPEDESCRIPTOR_IMPL_HPP
    9 #define ATOMSHAPEDESCRIPTOR_IMPL_HPP
     8#ifndef ATOMSHAPEDESCRIPTOR_IMPL_HPP_
     9#define ATOMSHAPEDESCRIPTOR_IMPL_HPP_
    1010
    1111#include "Descriptors/AtomDescriptor_impl.hpp"
     12
    1213#include "Shapes/Shape.hpp"
    1314
     
    1516{
    1617public:
    17   AtomShapeDescriptor_impl(Shape _shape);
    18   virtual ~AtomShapeDescriptor_impl();
     18  AtomShapeDescriptor_impl(const Shape&);
     19  virtual  ~AtomShapeDescriptor_impl();
    1920
    2021  bool predicate(std::pair<atomId_t,atom*> atom);
    21 
    2222private:
    2323  Shape shape;
    2424};
    2525
    26 #endif //ATOMSHAPEDESCRIPTOR_IMPL_HPP
     26#endif /* ATOMSHAPEDESCRIPTOR_IMPL_HPP_ */
  • src/Exceptions/Makefile.am

    rfd4905 r6c438f  
    1515  MissingValueException.cpp \
    1616  NotInvertibleException.cpp \
     17  NotOnSurfaceException.cpp \
     18  ShapeException.cpp \
    1719  ParseError.cpp \
    1820  SkewException.cpp \
    1921  ZeroVectorException.cpp
     22       
    2023                                 
    2124EXCEPTIONHEADER = \
     
    2629  MissingValueException.hpp \
    2730  NotInvertibleException.hpp \
     31  NotInvertibleException.hpp \
     32  NotOnSurfaceException.hpp \
    2833  ParseError.hpp \
    2934  SkewException.hpp \
  • src/Helpers/helpers.cpp

    rfd4905 r6c438f  
    153153  exit(255);
    154154}
     155
     156sign_t sign(double value){
     157  if(fabs(value)<MYEPSILON){
     158    return Zero;
     159  }
     160  if(value<0)
     161    return Minus;
     162  else
     163    return Plus;
     164}
  • src/Helpers/helpers.hpp

    rfd4905 r6c438f  
    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/LinearAlgebra/Line.cpp

    rfd4905 r6c438f  
    5050Line::~Line()
    5151{}
     52
     53Line &Line::operator=(const Line& rhs){
     54  if(this!=&rhs){
     55    origin.reset(new Vector(*rhs.origin));
     56    direction.reset(new Vector(*rhs.direction));
     57  }
     58  return *this;
     59}
    5260
    5361
     
    224232}
    225233
     234Line Line::rotateLine(const Line &rhs, double alpha) const{
     235  Vector lineOrigin = rotateVector(rhs.getOrigin(),alpha);
     236  Vector helper = rhs.getDirection();
     237  // rotate the direction without considering the ofset
     238  pair<Vector,Vector> parts = helper.partition(*direction);
     239  Vector lineDirection = parts.first;
     240  Vector a = parts.second;
     241  if(!a.IsZero()){
     242    // construct a vector that is orthogonal to a and direction and has length |a|
     243    Vector y = a;
     244    // direction is normalized, so the result has length |a|
     245    y.VectorProduct(*direction);
     246
     247    lineDirection += cos(alpha) * a + sin(alpha) * y;
     248  }
     249  return Line(lineOrigin,lineDirection);
     250}
     251
     252Plane Line::rotatePlane(const Plane &rhs, double alpha) const{
     253  vector<Vector> points = rhs.getPointsOnPlane();
     254  transform(points.begin(),
     255            points.end(),
     256            points.begin(),
     257            boost::bind(&Line::rotateVector,this,_1,alpha));
     258  return Plane(points[0],points[1],points[2]);
     259}
     260
    226261Plane Line::getOrthogonalPlane(const Vector &origin) const{
    227262  return Plane(getDirection(),origin);
     
    247282}
    248283
     284LinePoint Line::getLinePoint(const Vector &point) const{
     285  ASSERT(isContained(point),"Line point queried for point not on line");
     286  Vector helper = point - (*origin);
     287  double param = helper.ScalarProduct(*direction);
     288  return LinePoint(*this,param);
     289}
     290
     291LinePoint Line::posEndpoint() const{
     292  return LinePoint(*this, numeric_limits<double>::infinity());
     293}
     294LinePoint Line::negEndpoint() const{
     295  return LinePoint(*this,-numeric_limits<double>::infinity());
     296}
     297
     298bool operator==(const Line &x,const Line &y){
     299  return *x.origin == *y.origin && *x.direction == *y.direction;
     300}
     301
    249302Line makeLineThrough(const Vector &x1, const Vector &x2){
    250303  if(x1==x2){
     
    252305  }
    253306  return Line(x1,x1-x2);
     307}
     308
     309/******************************** Points on the line ********************/
     310
     311LinePoint::LinePoint(const LinePoint &src) :
     312  line(src.line),param(src.param)
     313{}
     314
     315LinePoint::LinePoint(const Line &_line, double _param) :
     316  line(_line),param(_param)
     317{}
     318
     319LinePoint& LinePoint::operator=(const LinePoint &src){
     320  line=src.line;
     321  param=src.param;
     322  return *this;
     323}
     324
     325Vector LinePoint::getPoint() const{
     326  ASSERT(!isInfinite(),"getPoint() on infinite LinePoint called");
     327  return (*line.origin)+param*(*line.direction);
     328}
     329
     330Line LinePoint::getLine() const{
     331  return line;
     332}
     333
     334bool LinePoint::isInfinite() const{
     335  return isPosInfinity() || isNegInfinity();
     336}
     337bool LinePoint::isPosInfinity() const{
     338  return param == numeric_limits<double>::infinity();
     339}
     340bool LinePoint::isNegInfinity() const{
     341  return param ==-numeric_limits<double>::infinity();
     342}
     343
     344bool operator==(const LinePoint &x, const LinePoint &y){
     345  ASSERT(x.line==y.line,"Operation on two points of different lines");
     346  return x.param == y.param;
     347
     348}
     349bool operator<(const LinePoint &x, const LinePoint &y){
     350  ASSERT(x.line==y.line,"Operation on two points of different lines");
     351  return x.param<y.param;
    254352}
    255353
  • src/LinearAlgebra/Line.hpp

    rfd4905 r6c438f  
    1717class Vector;
    1818class Plane;
     19class LinePoint;
    1920
    2021class Line : public Space
    2122{
     23  friend bool operator==(const Line&,const Line&);
     24  friend class LinePoint;
    2225public:
    2326  Line(const Vector &_origin, const Vector &_direction);
    2427  Line(const Line& _src);
    2528  virtual ~Line();
     29
     30  Line &operator=(const Line& rhs);
    2631
    2732  virtual double distance(const Vector &point) const;
     
    3641
    3742  Vector rotateVector(const Vector &rhs, double alpha) const;
     43  Line rotateLine(const Line &rhs, double alpha) const;
     44  Plane rotatePlane(const Plane &rhs, double alpha) const;
    3845
    3946  Plane getOrthogonalPlane(const Vector &origin) const;
     
    4148  std::vector<Vector> getSphereIntersections() const;
    4249
     50  LinePoint getLinePoint(const Vector&) const;
     51  LinePoint posEndpoint() const;
     52  LinePoint negEndpoint() const;
     53
     54
     55
    4356private:
    4457  std::auto_ptr<Vector> origin;
    4558  std::auto_ptr<Vector> direction;
    4659};
     60
     61bool operator==(const Line&,const Line&);
    4762
    4863std::ostream & operator << (std::ostream& ost, const Line &m);
     
    5368Line makeLineThrough(const Vector &x1, const Vector &x2);
    5469
     70/**
     71 * Class for representing points on a line
     72 * These objects allow comparison of points on the same line as well as specifying the
     73 * infinite "endpoints" of a line.
     74 */
     75class LinePoint{
     76  friend class Line;
     77  friend bool operator==(const LinePoint&, const LinePoint&);
     78  friend bool operator<(const LinePoint&, const LinePoint&);
     79public:
     80  LinePoint(const LinePoint&);
     81  LinePoint& operator=(const LinePoint&);
     82  Vector getPoint() const;
     83  Line getLine() const;
     84  bool isInfinite() const;
     85  bool isPosInfinity() const;
     86  bool isNegInfinity() const;
     87
     88private:
     89  LinePoint(const Line&,double);
     90  Line line;
     91  double param;
     92};
     93
     94bool operator==(const LinePoint&, const LinePoint&);
     95bool operator<(const LinePoint&, const LinePoint&);
     96
     97inline bool operator!= (const LinePoint& x, const LinePoint& y) { return !(x==y); }
     98inline bool operator>  (const LinePoint& x, const LinePoint& y) { return y<x; }
     99inline bool operator<= (const LinePoint& x, const LinePoint& y) { return !(y<x); }
     100inline bool operator>= (const LinePoint& x, const LinePoint& y) { return !(x<y); }
     101
     102
    55103#endif /* LINE_HPP_ */
  • src/LinearAlgebra/Makefile.am

    rfd4905 r6c438f  
    1414  gslvector.cpp \
    1515  Line.cpp \
     16  LineSegment.cpp \
     17  LineSegmentSet.cpp \
    1618  linearsystemofequations.cpp \
    1719  Matrix.cpp \
     
    2729  gslvector.hpp \
    2830  Line.hpp \
     31  LineSegment.hpp \
     32  LineSegmentSet.hpp \
    2933  linearsystemofequations.hpp \
    3034  Matrix.hpp \
  • src/LinearAlgebra/Matrix.cpp

    rfd4905 r6c438f  
    230230       - at(2,1)*at(1,2)*at(0,0)
    231231       - at(2,2)*at(1,0)*at(0,1);
    232 }
    233 
    234 Matrix Matrix::transpose() const
    235 {
    236   Matrix copy(*this);
    237   copy.transpose();
    238   return copy;
    239 }
    240 
    241 
    242 Matrix &Matrix::transpose()
    243 {
    244   double tmp;
    245   for (int i=0;i<NDIM;i++)
    246     for (int j=i+1;j<NDIM;j++) {
    247       tmp = at(j,i);
    248       at(j,i) = at(i,j);
    249       at(i,j) = tmp;
    250     }
    251   return *this;
    252232}
    253233
     
    273253}
    274254
     255Matrix Matrix::transpose() const{
     256  MatrixContent *newContent = new MatrixContent();
     257  newContent->content = gsl_matrix_alloc(NDIM, NDIM);
     258  gsl_matrix_transpose_memcpy(newContent->content, content->content);
     259  Matrix res = Matrix(newContent);
     260  return res;
     261}
     262
     263Matrix &Matrix::transpose()
     264{
     265  double tmp;
     266  for (int i=0;i<NDIM;i++)
     267    for (int j=i+1;j<NDIM;j++) {
     268      tmp = at(j,i);
     269      at(j,i) = at(i,j);
     270      at(i,j) = tmp;
     271    }
     272  return *this;
     273}
     274
     275
    275276Vector Matrix::transformToEigenbasis()
    276277{
  • src/LinearAlgebra/Plane.cpp

    rfd4905 r6c438f  
    2727#include "Helpers/Verbose.hpp"
    2828#include "Helpers/Assert.hpp"
     29#include "Helpers/helpers.hpp"
    2930#include <cmath>
    3031#include "LinearAlgebra/Line.hpp"
     
    118119Plane::~Plane()
    119120{}
     121
     122Plane &Plane::operator=(const Plane &rhs){
     123  if(&rhs!=this){
     124    normalVector.reset(new Vector(*rhs.normalVector));
     125    offset = rhs.offset;
     126  }
     127  return *this;
     128}
    120129
    121130
     
    200209}
    201210
     211bool Plane::onSameSide(const Vector &point1,const Vector &point2) const{
     212  return sign(point1.ScalarProduct(*normalVector)-offset) ==
     213         sign(point2.ScalarProduct(*normalVector)-offset);
     214}
     215
    202216/************ Methods inherited from Space ****************/
    203217
     
    219233// Operators
    220234
     235bool operator==(const Plane &x,const Plane &y){
     236  return *x.normalVector == *y.normalVector && x.offset == y.offset;
     237}
     238
    221239ostream &operator << (ostream &ost,const Plane &p){
    222240  ost << "<" << p.getNormal() << ";x> - " << p.getOffset() << "=0";
  • src/LinearAlgebra/Plane.hpp

    rfd4905 r6c438f  
    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/LinearAlgebra/Vector.cpp

    rfd4905 r6c438f  
    237237  (*this) *= 1/factor;
    238238};
     239
     240Vector Vector::getNormalized() const{
     241  Vector res= *this;
     242  res.Normalize();
     243  return res;
     244}
    239245
    240246/** Zeros all components of this vector.
     
    578584// some comonly used vectors
    579585const Vector zeroVec(0,0,0);
    580 const Vector e1(1,0,0);
    581 const Vector e2(0,1,0);
    582 const Vector e3(0,0,1);
     586const Vector unitVec[NDIM]={Vector(1,0,0),Vector(0,1,0),Vector(0,0,1)};
  • src/LinearAlgebra/Vector.hpp

    rfd4905 r6c438f  
    8383  double NormSquared() const;
    8484  void Normalize();
     85  Vector getNormalized() const;
    8586  void Zero();
    8687  void One(const double one);
     
    109110// some commonly used and fixed vectors
    110111const extern Vector zeroVec;
    111 const extern Vector e1;
    112 const extern Vector e2;
    113 const extern Vector e3;
     112const extern Vector unitVec[NDIM];
    114113
    115114ostream & operator << (ostream& ost, const Vector &m);
  • src/Makefile.am

    rfd4905 r6c438f  
    5858  Actions/MethodAction.hpp \
    5959  Actions/Process.hpp
     60
    6061
    6162PATTERNSOURCE = \
     
    227228  lists.hpp \
    228229  molecule.hpp \
    229   molecule_template.hpp \
    230230  parser.hpp \
    231231  periodentafel.hpp \
  • src/Shapes/BaseShapes.cpp

    rfd4905 r6c438f  
    2222#include "Shapes/BaseShapes.hpp"
    2323#include "Shapes/BaseShapes_impl.hpp"
    24 
    25 #include <cmath>
     24#include "Shapes/ShapeOps.hpp"
     25
     26#include "defs.hpp"
    2627
    2728#include "Helpers/Assert.hpp"
    2829#include "LinearAlgebra/Vector.hpp"
     30#include "LinearAlgebra/Line.hpp"
     31#include "LinearAlgebra/Plane.hpp"
     32#include "LinearAlgebra/LineSegment.hpp"
     33#include "LinearAlgebra/LineSegmentSet.hpp"
     34
     35#include <cmath>
     36#include <algorithm>
    2937
    3038bool Sphere_impl::isInside(const Vector &point){
     
    3240}
    3341
     42bool Sphere_impl::isOnSurface(const Vector &point){
     43  return fabs(point.NormSquared()-1)<MYEPSILON;
     44}
     45
     46Vector Sphere_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){
     47  if(!isOnSurface(point)){
     48    throw NotOnSurfaceException(__FILE__,__LINE__);
     49  }
     50  return point;
     51}
     52
     53LineSegmentSet Sphere_impl::getLineIntersections(const Line &line){
     54  LineSegmentSet res(line);
     55  std::vector<Vector> intersections = line.getSphereIntersections();
     56  if(intersections.size()==2){
     57    res.insert(LineSegment(intersections[0],intersections[1]));
     58  }
     59  return res;
     60}
     61
     62string Sphere_impl::toString(){
     63  return "Sphere()";
     64}
    3465
    3566/**
     
    6697}
    6798
     99Shape Sphere(const Vector &center,double radius){
     100  return translate(resize(Sphere(),radius),center);
     101}
     102
     103Shape Ellipsoid(const Vector &center, const Vector &radius){
     104  return translate(stretch(Sphere(),radius),center);
     105}
     106
    68107bool Cuboid_impl::isInside(const Vector &point){
    69108  return (point[0]>=0 && point[0]<=1) && (point[1]>=0 && point[1]<=1) && (point[2]>=0 && point[2]<=1);
     109}
     110
     111bool Cuboid_impl::isOnSurface(const Vector &point){
     112  bool retVal = isInside(point);
     113  // test all borders of the cuboid
     114  // double fabs
     115  retVal = retVal &&
     116           (((fabs(point[0]-1.)  < MYEPSILON) || (fabs(point[0])  < MYEPSILON)) ||
     117            ((fabs(point[1]-1.)  < MYEPSILON) || (fabs(point[1])  < MYEPSILON)) ||
     118            ((fabs(point[2]-1.)  < MYEPSILON) || (fabs(point[2])  < MYEPSILON)));
     119  return retVal;
     120}
     121
     122Vector Cuboid_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){
     123  if(!isOnSurface(point)){
     124    throw NotOnSurfaceException(__FILE__,__LINE__);
     125  }
     126  Vector res;
     127  // figure out on which sides the Vector lies (maximum 3, when it is in a corner)
     128  for(int i=NDIM;i--;){
     129    if(fabs(fabs(point[i])-1)<MYEPSILON){
     130      // add the scaled (-1/+1) Vector to the set of surface vectors
     131      res[i] = point[i];
     132    }
     133  }
     134  ASSERT(res.NormSquared()>=1 && res.NormSquared()<=3,"To many or to few sides found for this Vector");
     135
     136  res.Normalize();
     137  return res;
     138}
     139
     140LineSegmentSet Cuboid_impl::getLineIntersections(const Line &line){
     141  LineSegmentSet res(line);
     142  // get the intersection on each of the six faces
     143  vector<Vector> intersections;
     144  intersections.resize(2);
     145  int c=0;
     146  int x[2]={-1,+1};
     147  for(int i=NDIM;i--;){
     148    for(int p=0;p<2;++p){
     149      if(c==2) goto end; // I know this sucks, but breaking two loops is stupid
     150      Vector base;
     151      base[i]=x[p];
     152      // base now points to the surface and is normal to it at the same time
     153      Plane p(base,base);
     154      Vector intersection = p.GetIntersection(line);
     155      if(isInside(intersection)){
     156        // if we have a point on the edge it might already be contained
     157        if(c==1 && intersections[0]==intersection)
     158          continue;
     159        intersections[c++]=intersection;
     160      }
     161    }
     162  }
     163  end:
     164  if(c==2){
     165    res.insert(LineSegment(intersections[0],intersections[1]));
     166  }
     167  return res;
     168}
     169
     170string Cuboid_impl::toString(){
     171  return "Cuboid()";
    70172}
    71173
     
    83185  return Shape(impl);
    84186}
     187
     188Shape Cuboid(const Vector &corner1, const Vector &corner2){
     189  // make sure the two edges are upper left front and lower right back
     190  Vector sortedC1;
     191  Vector sortedC2;
     192  for(int i=NDIM;i--;){
     193    sortedC1[i] = min(corner1[i],corner2[i]);
     194    sortedC2[i] = max(corner1[i],corner2[i]);
     195    ASSERT(corner1[i]!=corner2[i],"Given points for cuboid edges did not define a valid space");
     196  }
     197  // get the middle point
     198  Vector middle = (1./2.)*(sortedC1+sortedC2);
     199  Vector factors = sortedC2-middle;
     200  return translate(stretch(Cuboid(),factors),middle);
     201}
  • src/Shapes/BaseShapes.hpp

    rfd4905 r6c438f  
    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

    rfd4905 r6c438f  
    99#define BASESHAPES_IMPL_HPP_
    1010
     11class Vector;
     12class LineSegmentSet;
     13
    1114#include "Shapes/Shape_impl.hpp"
    1215
    1316class Sphere_impl : public Shape_impl {
    1417  virtual bool isInside(const Vector &point);
     18  virtual bool isOnSurface(const Vector &point);
     19  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
     20  virtual LineSegmentSet getLineIntersections(const Line&);
     21  virtual std::string toString();
    1522  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    1623};
     
    1825class Cuboid_impl : public Shape_impl {
    1926  virtual bool isInside(const Vector &point);
     27  virtual bool isOnSurface(const Vector &point);
     28  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
     29  virtual LineSegmentSet getLineIntersections(const Line&);
     30  virtual std::string toString();
    2031  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    2132};
  • src/Shapes/Shape.cpp

    rfd4905 r6c438f  
    2020#include "Helpers/MemDebug.hpp"
    2121
     22#include "Helpers/Assert.hpp"
     23#include "LinearAlgebra/Vector.hpp"
     24
    2225#include "Shape.hpp"
    2326#include "Shape_impl.hpp"
    2427
    25 
    26 #include "Helpers/Assert.hpp"
    27 #include "LinearAlgebra/Vector.hpp"
     28#include <string>
     29
    2830
    2931Shape::Shape(const Shape& src) :
     
    3537bool Shape::isInside(const Vector &point) const{
    3638  return impl->isInside(point);
     39}
     40
     41bool Shape::isOnSurface(const Vector &point) const{
     42  return impl->isOnSurface(point);
     43}
     44
     45Vector Shape::getNormal(const Vector &point) const throw (NotOnSurfaceException){
     46  return impl->getNormal(point);
     47}
     48
     49LineSegmentSet Shape::getLineIntersections(const Line &line){
     50  return impl->getLineIntersections(line);
    3751}
    3852
     
    5266}
    5367
     68std::string Shape::toString() const{
     69  return impl->toString();
     70}
     71
    5472Shape::impl_ptr Shape::getImpl() const{
    5573  return impl;
     
    85103bool AndShape_impl::isInside(const Vector &point){
    86104  return lhs->isInside(point) && rhs->isInside(point);
     105}
     106
     107bool AndShape_impl::isOnSurface(const Vector &point){
     108  // check the number of surfaces that this point is on
     109  int surfaces =0;
     110  surfaces += lhs->isOnSurface(point);
     111  surfaces += rhs->isOnSurface(point);
     112
     113  switch(surfaces){
     114    case 0:
     115      return false;
     116      // no break necessary
     117    case 1:
     118      // if it is inside for the object where it does not lie on
     119      // the surface the whole point lies inside
     120      return (lhs->isOnSurface(point) && rhs->isInside(point)) ||
     121             (rhs->isOnSurface(point) && lhs->isInside(point));
     122      // no break necessary
     123    case 2:
     124      {
     125        // it lies on both Shapes... could be an edge or an inner point
     126        // test the direction of the normals
     127        Vector direction=lhs->getNormal(point)+rhs->getNormal(point);
     128        // if the directions are opposite we lie on the inside
     129        return !direction.IsZero();
     130      }
     131      // no break necessary
     132    default:
     133      // if this happens there is something wrong
     134      ASSERT(0,"Default case should have never been used");
     135  }
     136  return false; // never reached
     137}
     138
     139Vector AndShape_impl::getNormal(const Vector &point) throw (NotOnSurfaceException){
     140  Vector res;
     141  if(!isOnSurface(point)){
     142    throw NotOnSurfaceException(__FILE__,__LINE__);
     143  }
     144  res += lhs->isOnSurface(point)?lhs->getNormal(point):zeroVec;
     145  res += rhs->isOnSurface(point)?rhs->getNormal(point):zeroVec;
     146  res.Normalize();
     147  return res;
     148}
     149
     150LineSegmentSet AndShape_impl::getLineIntersections(const Line &line){
     151  return intersect(lhs->getLineIntersections(line),rhs->getLineIntersections(line));
     152}
     153
     154string AndShape_impl::toString(){
     155  return string("(") + lhs->toString() + string("&&") + rhs->toString() + string(")");
    87156}
    88157
     
    122191}
    123192
     193bool OrShape_impl::isOnSurface(const Vector &point){
     194  // check the number of surfaces that this point is on
     195  int surfaces =0;
     196  surfaces += lhs->isOnSurface(point);
     197  surfaces += rhs->isOnSurface(point);
     198
     199  switch(surfaces){
     200    case 0:
     201      return false;
     202      // no break necessary
     203    case 1:
     204      // if it is inside for the object where it does not lie on
     205      // the surface the whole point lies inside
     206      return (lhs->isOnSurface(point) && !rhs->isInside(point)) ||
     207             (rhs->isOnSurface(point) && !lhs->isInside(point));
     208      // no break necessary
     209    case 2:
     210      {
     211        // it lies on both Shapes... could be an edge or an inner point
     212        // test the direction of the normals
     213        Vector direction=lhs->getNormal(point)+rhs->getNormal(point);
     214        // if the directions are opposite we lie on the inside
     215        return !direction.IsZero();
     216      }
     217      // no break necessary
     218    default:
     219      // if this happens there is something wrong
     220      ASSERT(0,"Default case should have never been used");
     221  }
     222  return false; // never reached
     223}
     224
     225Vector OrShape_impl::getNormal(const Vector &point) throw (NotOnSurfaceException){
     226  Vector res;
     227  if(!isOnSurface(point)){
     228    throw NotOnSurfaceException(__FILE__,__LINE__);
     229  }
     230  res += lhs->isOnSurface(point)?lhs->getNormal(point):zeroVec;
     231  res += rhs->isOnSurface(point)?rhs->getNormal(point):zeroVec;
     232  res.Normalize();
     233  return res;
     234}
     235
     236LineSegmentSet OrShape_impl::getLineIntersections(const Line &line){
     237  return merge(lhs->getLineIntersections(line),rhs->getLineIntersections(line));
     238}
     239
     240string OrShape_impl::toString(){
     241  return string("(") + lhs->toString() + string("||") + rhs->toString() + string(")");
     242}
     243
    124244std::vector<Vector> OrShape_impl::getHomogeneousPointsOnSurface(const size_t N) const {
    125245  std::vector<Vector> PointsOnSurface_lhs = lhs->getHomogeneousPointsOnSurface(N);
     
    156276}
    157277
     278bool NotShape_impl::isOnSurface(const Vector &point){
     279  return arg->isOnSurface(point);
     280}
     281
     282Vector NotShape_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){
     283  return -1*arg->getNormal(point);
     284}
     285
     286LineSegmentSet NotShape_impl::getLineIntersections(const Line &line){
     287  return invert(arg->getLineIntersections(line));
     288}
     289
     290string NotShape_impl::toString(){
     291  return string("!") + arg->toString();
     292}
     293
    158294std::vector<Vector> NotShape_impl::getHomogeneousPointsOnSurface(const size_t N) const {
    159295  // surfaces are the same, only normal direction is different
     
    165301  return Shape(newImpl);
    166302}
     303
     304/**************** global operations *********************************/
     305ostream &operator<<(ostream &ost,const Shape &shape){
     306  ost << shape.toString();
     307  return ost;
     308}
  • src/Shapes/Shape.hpp

    rfd4905 r6c438f  
    1010
    1111#include <boost/shared_ptr.hpp>
     12#include <iosfwd>
     13
     14#include "Exceptions/NotOnSurfaceException.hpp"
    1215
    1316#include <vector>
     
    1518class Vector;
    1619class Shape_impl;
     20class LineSegmentSet;
     21class Line;
    1722
    1823class Shape
     
    2732
    2833  bool isInside(const Vector &point) const;
     34  bool isOnSurface(const Vector &point) const;
     35  Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
     36
     37  LineSegmentSet getLineIntersections(const Line&);
    2938  std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    3039
    3140  Shape &operator=(const Shape& rhs);
    3241
     42  std::string toString() const;
    3343protected:
    3444  impl_ptr getImpl() const;
     
    4555Shape operator!(const Shape&);
    4656
     57std::ostream &operator<<(std::ostream&,const Shape&);
     58
    4759#endif /* SHAPE_HPP_ */
  • src/Shapes/ShapeOps.cpp

    rfd4905 r6c438f  
    2323#include "Shapes/ShapeOps_impl.hpp"
    2424
     25#include "LinearAlgebra/Vector.hpp"
    2526#include "Helpers/Assert.hpp"
    2627
     28/*************** Base case ***********************/
     29
     30ShapeOpsBase_impl::ShapeOpsBase_impl(const Shape::impl_ptr &_arg) :
     31  arg(_arg){}
     32
     33ShapeOpsBase_impl::~ShapeOpsBase_impl(){}
     34
     35bool ShapeOpsBase_impl::isInside(const Vector &point){
     36  return arg->isInside(translateIn(point));
     37}
     38
     39bool ShapeOpsBase_impl::isOnSurface(const Vector &point){
     40  return arg->isOnSurface(translateIn(point));
     41}
     42
     43Vector ShapeOpsBase_impl::getNormal(const Vector &point) throw (NotOnSurfaceException){
     44  Vector helper = translateIn(point);
     45  if(!arg->isOnSurface(helper)){
     46    throw NotOnSurfaceException(__FILE__,__LINE__);
     47  }
     48  Vector res = translateOutNormal(arg->getNormal(helper));
     49  res.Normalize();
     50  return res;
     51}
     52
     53LineSegmentSet ShapeOpsBase_impl::getLineIntersections(const Line &line){
     54  Line newLine(translateIn(line.getOrigin()),translateIn(line.getDirection()));
     55  LineSegmentSet res(line);
     56  LineSegmentSet helper = getArg()->getLineIntersections(newLine);
     57  for(LineSegmentSet::iterator iter = helper.begin();iter!=helper.end();++iter){
     58    LinePoint lpBegin = iter->getBegin();
     59    LinePoint lpEnd = iter->getBegin();
     60    // translate both linepoints
     61    lpBegin = lpBegin.isNegInfinity()?
     62                line.negEndpoint():
     63                line.getLinePoint(translateOutPos(lpBegin.getPoint()));
     64    lpEnd = lpEnd.isPosInfinity()?
     65              line.posEndpoint():
     66              line.getLinePoint(translateOutPos(lpEnd.getPoint()));
     67    res.insert(LineSegment(lpBegin,lpEnd));
     68  }
     69  return res;
     70}
     71
     72std::vector<Vector> ShapeOpsBase_impl::getHomogeneousPointsOnSurface(const size_t N) const {
     73  return getArg()->getHomogeneousPointsOnSurface(N);;
     74}
     75
     76Shape::impl_ptr ShapeOpsBase_impl::getArg() const{
     77  return arg;
     78}
     79
    2780/********************* Resize ********************/
    2881
    2982Resize_impl::Resize_impl(const Shape::impl_ptr &_arg,double _size) :
    30   arg(_arg), size(_size)
     83  ShapeOpsBase_impl(_arg), size(_size)
    3184{
    3285  ASSERT(size>0,"Cannot resize a Shape to size zero or below");
     
    3689
    3790bool Resize_impl::isInside(const Vector& point){
    38   return arg->isInside((1/size) * point);
     91  return getArg()->isInside((1/size) * point);
     92}
     93
     94Vector Resize_impl::translateIn(const Vector& point){
     95  return (1/size) * point;
     96}
     97
     98Vector Resize_impl::translateOutPos(const Vector& point){
     99  return size * point;
     100}
     101
     102Vector Resize_impl::translateOutNormal(const Vector& point){
     103  return point;
     104}
     105
     106string Resize_impl::toString(){
     107  stringstream sstr;
     108  sstr << "resize(" << getArg()->toString() << "," << size << ")";
     109  return sstr.str();
    39110}
    40111
    41112std::vector<Vector> Resize_impl::getHomogeneousPointsOnSurface(const size_t N) const {
    42   std::vector<Vector> PointsOnSurface = arg->getHomogeneousPointsOnSurface(N);
     113  std::vector<Vector> PointsOnSurface = getArg()->getHomogeneousPointsOnSurface(N);
    43114  for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) {
    44115    *iter *= size;
     
    56127
    57128Translate_impl::Translate_impl(const Shape::impl_ptr &_arg, const Vector &_offset) :
    58   arg(_arg),offset(_offset)
     129  ShapeOpsBase_impl(_arg),offset(_offset)
    59130{}
    60131
     
    62133
    63134bool Translate_impl::isInside(const Vector& point){
    64   return arg->isInside(point-offset);
     135  return getArg()->isInside(point-offset);
     136}
     137
     138Vector Translate_impl::translateIn(const Vector& point){
     139  return point-offset;
     140}
     141
     142Vector Translate_impl::translateOutPos(const Vector& point){
     143  return point+offset;
     144}
     145
     146Vector Translate_impl::translateOutNormal(const Vector& point){
     147  return point;
     148}
     149
     150string Translate_impl::toString(){
     151  stringstream sstr;
     152  sstr << "translate(" << getArg()->toString() << "," << offset << ")";
     153  return sstr.str();
    65154}
    66155
    67156std::vector<Vector> Translate_impl::getHomogeneousPointsOnSurface(const size_t N) const {
    68   std::vector<Vector> PointsOnSurface = arg->getHomogeneousPointsOnSurface(N);
     157  std::vector<Vector> PointsOnSurface = getArg()->getHomogeneousPointsOnSurface(N);
    69158  for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) {
    70159    *iter += offset;
     
    81170
    82171Stretch_impl::Stretch_impl(const Shape::impl_ptr &_arg, const Vector &_factors) :
    83   arg(_arg),factors(_factors)
     172  ShapeOpsBase_impl(_arg),factors(_factors)
    84173{
    85174  ASSERT(factors[0]>0,"cannot stretch a shape by a negative amount");
     
    96185  Vector helper=point;
    97186  helper.ScaleAll(reciFactors);
    98   return arg->isInside(helper);
     187  return getArg()->isInside(helper);
     188}
     189
     190Vector Stretch_impl::translateIn(const Vector& point){
     191  Vector helper=point;
     192  helper.ScaleAll(reciFactors);
     193  return helper;
     194}
     195
     196Vector Stretch_impl::translateOutPos(const Vector& point){
     197  Vector helper=point;
     198  helper.ScaleAll(factors);
     199  return helper;
     200}
     201
     202Vector Stretch_impl::translateOutNormal(const Vector& point){
     203  Vector helper=point;
     204  // the normalFactors are derived from appearances of the factors
     205  // with in the vectorproduct
     206  Vector normalFactors;
     207  normalFactors[0]=factors[1]*factors[2];
     208  normalFactors[1]=factors[0]*factors[2];
     209  normalFactors[2]=factors[0]*factors[1];
     210  helper.ScaleAll(normalFactors);
     211  return helper;
     212}
     213
     214string Stretch_impl::toString(){
     215  stringstream sstr;
     216  sstr << "stretch(" << getArg()->toString() << "," << factors << ")";
     217  return sstr.str();
    99218}
    100219
    101220std::vector<Vector> Stretch_impl::getHomogeneousPointsOnSurface(const size_t N) const {
    102   std::vector<Vector> PointsOnSurface = arg->getHomogeneousPointsOnSurface(N);
     221  std::vector<Vector> PointsOnSurface = getArg()->getHomogeneousPointsOnSurface(N);
    103222  for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) {
    104223    (*iter).ScaleAll(reciFactors);
     
    115234
    116235Transform_impl::Transform_impl(const Shape::impl_ptr &_arg, const Matrix &_transformation) :
    117   arg(_arg),transformation(_transformation)
     236  ShapeOpsBase_impl(_arg),transformation(_transformation)
    118237{
    119238  transformationInv = transformation.invert();
     
    123242
    124243bool Transform_impl::isInside(const Vector& point){
    125   return arg->isInside(transformationInv * point);
     244  return getArg()->isInside(transformationInv * point);
     245}
     246
     247Vector Transform_impl::translateIn(const Vector& point){
     248  return transformationInv * point;
     249}
     250
     251Vector Transform_impl::translateOutPos(const Vector& point){
     252  return transformation * point;
     253}
     254
     255Vector Transform_impl::translateOutNormal(const Vector& point){
     256  Matrix mat = transformation.invert().transpose();
     257  return mat * point;
     258}
     259
     260string Transform_impl::toString(){
     261  stringstream sstr;
     262  sstr << "transform(" << getArg()->toString() << "," << transformation << ")";
     263  return sstr.str();
    126264}
    127265
    128266std::vector<Vector> Transform_impl::getHomogeneousPointsOnSurface(const size_t N) const {
    129   std::vector<Vector> PointsOnSurface = arg->getHomogeneousPointsOnSurface(N);
     267  std::vector<Vector> PointsOnSurface = getArg()->getHomogeneousPointsOnSurface(N);
    130268  for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) {
    131269    *iter = transformation * (*iter);
  • src/Shapes/ShapeOps_impl.hpp

    rfd4905 r6c438f  
    1313#include "LinearAlgebra/Matrix.hpp"
    1414
    15 class Resize_impl :  public Shape_impl
     15#include <vector>
     16
     17class LineSegment;
     18
     19class ShapeOpsBase_impl : public Shape_impl{
     20public:
     21  ShapeOpsBase_impl(const Shape::impl_ptr&);
     22  virtual ~ShapeOpsBase_impl();
     23  virtual bool isInside(const Vector &point);
     24  virtual bool isOnSurface(const Vector &point);
     25  virtual Vector getNormal(const Vector &point) throw (NotOnSurfaceException);
     26  virtual LineSegmentSet getLineIntersections(const Line&);
     27  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
     28protected:
     29  virtual Vector translateIn(const Vector &point)=0;
     30  virtual Vector translateOutPos(const Vector &point)=0;
     31  virtual Vector translateOutNormal(const Vector &point)=0;
     32  Shape::impl_ptr getArg() const;
     33private:
     34  Shape::impl_ptr arg;
     35};
     36
     37class Resize_impl :  public ShapeOpsBase_impl
    1638{
    1739public:
    1840  Resize_impl(const Shape::impl_ptr&,double);
    1941  virtual ~Resize_impl();
     42protected:
     43  virtual Vector translateIn(const Vector &point);
     44  virtual Vector translateOutPos(const Vector &point);
     45  virtual Vector translateOutNormal(const Vector &point);
     46  virtual std::string toString();
    2047  virtual bool isInside(const Vector& point);
    2148  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    2249private:
    23   Shape::impl_ptr arg;
    2450  double size;
    2551};
    2652
    27 class Translate_impl :  public Shape_impl
     53class Translate_impl :  public ShapeOpsBase_impl
    2854{
    2955public:
    3056  Translate_impl(const Shape::impl_ptr&, const Vector&);
    3157  virtual ~Translate_impl();
     58protected:
     59  virtual Vector translateIn(const Vector &point);
     60  virtual Vector translateOutPos(const Vector &point);
     61  virtual Vector translateOutNormal(const Vector &point);
     62  virtual std::string toString();
    3263  virtual bool isInside(const Vector& point);
    3364  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    3465private:
    35   Shape::impl_ptr arg;
    3666  Vector offset;
    3767};
    3868
    39 class Stretch_impl : public Shape_impl
     69class Stretch_impl : public ShapeOpsBase_impl
    4070{
    4171public:
    4272  Stretch_impl(const Shape::impl_ptr&, const Vector&);
    4373  virtual ~Stretch_impl();
     74protected:
     75  virtual Vector translateIn(const Vector &point);
     76  virtual Vector translateOutPos(const Vector &point);
     77  virtual Vector translateOutNormal(const Vector &point);
     78  virtual std::string toString();
    4479  virtual bool isInside(const Vector& point);
    4580  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    4681private:
    47   Shape::impl_ptr arg;
    4882  Vector factors;
    4983  Vector reciFactors;
    5084};
    5185
    52 class Transform_impl : public Shape_impl
     86class Transform_impl : public ShapeOpsBase_impl
    5387{
    5488public:
    5589  Transform_impl(const Shape::impl_ptr&, const Matrix&);
    5690  virtual ~Transform_impl();
     91protected:
     92  virtual Vector translateIn(const Vector &point);
     93  virtual Vector translateOutPos(const Vector &point);
     94  virtual Vector translateOutNormal(const Vector &point);
     95  virtual std::string toString();
    5796  virtual bool isInside(const Vector& point);
    5897  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    5998private:
    60   Shape::impl_ptr arg;
    6199  Matrix transformation;
    62100  Matrix transformationInv;
  • src/Shapes/Shape_impl.hpp

    rfd4905 r6c438f  
    1212
    1313#include "Shapes/Shape.hpp"
     14#include "LinearAlgebra/Line.hpp"
     15#include "LinearAlgebra/LineSegment.hpp"
     16#include "LinearAlgebra/LineSegmentSet.hpp"
     17#include "LinearAlgebra/Vector.hpp"
    1418
    15 class Vector;
    1619
    1720class Shape_impl {
     
    2023  virtual ~Shape_impl(){};
    2124  virtual bool isInside(const Vector &point)=0;
     25  virtual bool isOnSurface(const Vector &point)=0;
     26  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException)=0;
     27  virtual LineSegmentSet getLineIntersections(const Line&)=0;
     28  virtual std::string toString()=0;
    2229  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const=0;
    2330};
     
    2734  virtual bool isInside(const Vector &point){
    2835    return true;
     36  }
     37  virtual bool isOnSurface(const Vector &point){
     38    return false;
     39  }
     40  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException){
     41    throw NotOnSurfaceException(__FILE__,__LINE__);
     42  }
     43  virtual LineSegmentSet getLineIntersections(const Line &line){
     44    LineSegmentSet res(line);
     45    res.insert(LineSegment(line.negEndpoint(),line.posEndpoint()));
     46    return res;
     47  }
     48  virtual std::string toString(){
     49    return "Everywhere()";
    2950  }
    3051  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const {
     
    3758  virtual bool isInside(const Vector &point){
    3859    return false;
     60  }
     61  virtual bool isOnSurface(const Vector &point){
     62    return false;
     63  }
     64  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException){
     65    throw NotOnSurfaceException(__FILE__,__LINE__);
     66  }
     67  virtual LineSegmentSet getLineIntersections(const Line &line){
     68    return LineSegmentSet(line);
     69  }
     70  virtual std::string toString(){
     71    return "Nowhere()";
    3972  }
    4073  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const {
     
    4982  virtual ~AndShape_impl();
    5083  virtual bool isInside(const Vector &point);
     84  virtual bool isOnSurface(const Vector &point);
     85  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
     86  virtual LineSegmentSet getLineIntersections(const Line&);
     87  virtual std::string toString();
    5188  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    5289private:
     
    6097  virtual ~OrShape_impl();
    6198  virtual bool isInside(const Vector &point);
     99  virtual bool isOnSurface(const Vector &point);
     100  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
     101  virtual LineSegmentSet getLineIntersections(const Line&);
     102  virtual std::string toString();
    62103  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    63104private:
     
    71112  virtual ~NotShape_impl();
    72113  virtual bool isInside(const Vector &point);
     114  virtual bool isOnSurface(const Vector &point);
     115  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
     116  virtual LineSegmentSet getLineIntersections(const Line&);
     117  virtual std::string toString();
    73118  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    74119private:
  • src/unittests/LineUnittest.cpp

    rfd4905 r6c438f  
    4141void LineUnittest::setUp(){
    4242  // three lines along the axes
    43   la1 = new Line(zeroVec,e1);
    44   la2 = new Line(zeroVec,e2);
    45   la3 = new Line(zeroVec,e3);
     43  la1 = new Line(zeroVec,unitVec[0]);
     44  la2 = new Line(zeroVec,unitVec[1]);
     45  la3 = new Line(zeroVec,unitVec[2]);
    4646
    4747  // the lines along the planes defined by two coordinate axes
    48   lp1 = new Line(e1,e1-e2);
    49   lp2 = new Line(e2,e2-e3);
    50   lp3 = new Line(e3,e3-e1);
     48  lp1 = new Line(unitVec[0],unitVec[0]-unitVec[1]);
     49  lp2 = new Line(unitVec[1],unitVec[1]-unitVec[2]);
     50  lp3 = new Line(unitVec[2],unitVec[2]-unitVec[0]);
    5151}
    5252void LineUnittest::tearDown(){
     
    6464
    6565  // direction+origin should never fail
    66   CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,e1));
    67   CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,e2));
    68   CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,e3));
     66  CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,unitVec[0]));
     67  CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,unitVec[1]));
     68  CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,unitVec[2]));
    6969
    7070  // two points fails if both points are the same
    71   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e1,e2));
    72   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e2,e3));
    73   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e3,e1));
     71  CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[0],unitVec[1]));
     72  CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[1],unitVec[2]));
     73  CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[2],unitVec[0]));
    7474  // for zerovectors
    75   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e1,zeroVec));
    76   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e2,zeroVec));
    77   CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e3,zeroVec));
     75  CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[0],zeroVec));
     76  CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[1],zeroVec));
     77  CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[2],zeroVec));
    7878  // now we pass two times the same point
    7979  CPPUNIT_ASSERT_THROW(makeLineThrough(zeroVec,zeroVec),LinearDependenceException);
    80   CPPUNIT_ASSERT_THROW(makeLineThrough(e1,e1),LinearDependenceException);
    81   CPPUNIT_ASSERT_THROW(makeLineThrough(e2,e2),LinearDependenceException);
    82   CPPUNIT_ASSERT_THROW(makeLineThrough(e3,e3),LinearDependenceException);
     80  CPPUNIT_ASSERT_THROW(makeLineThrough(unitVec[0],unitVec[0]),LinearDependenceException);
     81  CPPUNIT_ASSERT_THROW(makeLineThrough(unitVec[1],unitVec[1]),LinearDependenceException);
     82  CPPUNIT_ASSERT_THROW(makeLineThrough(unitVec[2],unitVec[2]),LinearDependenceException);
    8383
    8484}
     
    9090void LineUnittest::constructionResultTest(){
    9191  // test all directions
    92   CPPUNIT_ASSERT(testDirection(la1->getDirection(),e1));
    93   CPPUNIT_ASSERT(testDirection(la2->getDirection(),e2));
    94   CPPUNIT_ASSERT(testDirection(la3->getDirection(),e3));
     92  CPPUNIT_ASSERT(testDirection(la1->getDirection(),unitVec[0]));
     93  CPPUNIT_ASSERT(testDirection(la2->getDirection(),unitVec[1]));
     94  CPPUNIT_ASSERT(testDirection(la3->getDirection(),unitVec[2]));
    9595
    9696  // test origins
     
    104104  CPPUNIT_ASSERT(la3->isContained(zeroVec));
    105105
    106   CPPUNIT_ASSERT(la1->isContained(e1));
    107   CPPUNIT_ASSERT(la2->isContained(e2));
    108   CPPUNIT_ASSERT(la3->isContained(e3));
    109 
    110   CPPUNIT_ASSERT(lp1->isContained(e1));
    111   CPPUNIT_ASSERT(lp2->isContained(e2));
    112   CPPUNIT_ASSERT(lp3->isContained(e3));
    113 
    114   CPPUNIT_ASSERT(lp1->isContained(e2));
    115   CPPUNIT_ASSERT(lp2->isContained(e3));
    116   CPPUNIT_ASSERT(lp3->isContained(e1));
     106  CPPUNIT_ASSERT(la1->isContained(unitVec[0]));
     107  CPPUNIT_ASSERT(la2->isContained(unitVec[1]));
     108  CPPUNIT_ASSERT(la3->isContained(unitVec[2]));
     109
     110  CPPUNIT_ASSERT(lp1->isContained(unitVec[0]));
     111  CPPUNIT_ASSERT(lp2->isContained(unitVec[1]));
     112  CPPUNIT_ASSERT(lp3->isContained(unitVec[2]));
     113
     114  CPPUNIT_ASSERT(lp1->isContained(unitVec[1]));
     115  CPPUNIT_ASSERT(lp2->isContained(unitVec[2]));
     116  CPPUNIT_ASSERT(lp3->isContained(unitVec[0]));
    117117}
    118118
     
    124124
    125125  // multiples of the second support vector
    126   CPPUNIT_ASSERT(la1->isContained(e1));
    127   CPPUNIT_ASSERT(la2->isContained(e2));
    128   CPPUNIT_ASSERT(la3->isContained(e3));
    129 
    130   CPPUNIT_ASSERT(la1->isContained(2*e1));
    131   CPPUNIT_ASSERT(la2->isContained(2*e2));
    132   CPPUNIT_ASSERT(la3->isContained(2*e3));
    133 
    134   CPPUNIT_ASSERT(la1->isContained(3*e1));
    135   CPPUNIT_ASSERT(la2->isContained(3*e2));
    136   CPPUNIT_ASSERT(la3->isContained(3*e3));
     126  CPPUNIT_ASSERT(la1->isContained(unitVec[0]));
     127  CPPUNIT_ASSERT(la2->isContained(unitVec[1]));
     128  CPPUNIT_ASSERT(la3->isContained(unitVec[2]));
     129
     130  CPPUNIT_ASSERT(la1->isContained(2*unitVec[0]));
     131  CPPUNIT_ASSERT(la2->isContained(2*unitVec[1]));
     132  CPPUNIT_ASSERT(la3->isContained(2*unitVec[2]));
     133
     134  CPPUNIT_ASSERT(la1->isContained(3*unitVec[0]));
     135  CPPUNIT_ASSERT(la2->isContained(3*unitVec[1]));
     136  CPPUNIT_ASSERT(la3->isContained(3*unitVec[2]));
    137137
    138138  // negative multiples
    139   CPPUNIT_ASSERT(la1->isContained(-1*e1));
    140   CPPUNIT_ASSERT(la2->isContained(-1*e2));
    141   CPPUNIT_ASSERT(la3->isContained(-1*e3));
    142 
    143   CPPUNIT_ASSERT(la1->isContained(-2*e1));
    144   CPPUNIT_ASSERT(la2->isContained(-2*e2));
    145   CPPUNIT_ASSERT(la3->isContained(-2*e3));
     139  CPPUNIT_ASSERT(la1->isContained(-1*unitVec[0]));
     140  CPPUNIT_ASSERT(la2->isContained(-1*unitVec[1]));
     141  CPPUNIT_ASSERT(la3->isContained(-1*unitVec[2]));
     142
     143  CPPUNIT_ASSERT(la1->isContained(-2*unitVec[0]));
     144  CPPUNIT_ASSERT(la2->isContained(-2*unitVec[1]));
     145  CPPUNIT_ASSERT(la3->isContained(-2*unitVec[2]));
    146146
    147147  // points that should not be on the lines
    148   CPPUNIT_ASSERT(!la1->isContained(e2));
    149   CPPUNIT_ASSERT(!la2->isContained(e3));
    150   CPPUNIT_ASSERT(!la3->isContained(e1));
    151 
    152   CPPUNIT_ASSERT(!la1->isContained(2*e2));
    153   CPPUNIT_ASSERT(!la2->isContained(2*e3));
    154   CPPUNIT_ASSERT(!la3->isContained(2*e1));
    155 
    156   CPPUNIT_ASSERT(!la1->isContained(-1*e2));
    157   CPPUNIT_ASSERT(!la2->isContained(-1*e3));
    158   CPPUNIT_ASSERT(!la3->isContained(-1*e1));
     148  CPPUNIT_ASSERT(!la1->isContained(unitVec[1]));
     149  CPPUNIT_ASSERT(!la2->isContained(unitVec[2]));
     150  CPPUNIT_ASSERT(!la3->isContained(unitVec[0]));
     151
     152  CPPUNIT_ASSERT(!la1->isContained(2*unitVec[1]));
     153  CPPUNIT_ASSERT(!la2->isContained(2*unitVec[2]));
     154  CPPUNIT_ASSERT(!la3->isContained(2*unitVec[0]));
     155
     156  CPPUNIT_ASSERT(!la1->isContained(-1*unitVec[1]));
     157  CPPUNIT_ASSERT(!la2->isContained(-1*unitVec[2]));
     158  CPPUNIT_ASSERT(!la3->isContained(-1*unitVec[0]));
    159159
    160160  // For the plane lines
    161   CPPUNIT_ASSERT(lp1->isContained(e1));
    162   CPPUNIT_ASSERT(lp2->isContained(e2));
    163   CPPUNIT_ASSERT(lp3->isContained(e3));
    164 
    165   CPPUNIT_ASSERT(lp1->isContained(e2));
    166   CPPUNIT_ASSERT(lp2->isContained(e3));
    167   CPPUNIT_ASSERT(lp3->isContained(e1));
    168 
    169   CPPUNIT_ASSERT(lp1->isContained(e1+2*(e1-e2)));
    170   CPPUNIT_ASSERT(lp2->isContained(e2+2*(e2-e3)));
    171   CPPUNIT_ASSERT(lp3->isContained(e3+2*(e3-e1)));
    172 
    173   CPPUNIT_ASSERT(lp1->isContained(e1-2*(e1-e2)));
    174   CPPUNIT_ASSERT(lp2->isContained(e2-2*(e2-e3)));
    175   CPPUNIT_ASSERT(lp3->isContained(e3-2*(e3-e1)));
     161  CPPUNIT_ASSERT(lp1->isContained(unitVec[0]));
     162  CPPUNIT_ASSERT(lp2->isContained(unitVec[1]));
     163  CPPUNIT_ASSERT(lp3->isContained(unitVec[2]));
     164
     165  CPPUNIT_ASSERT(lp1->isContained(unitVec[1]));
     166  CPPUNIT_ASSERT(lp2->isContained(unitVec[2]));
     167  CPPUNIT_ASSERT(lp3->isContained(unitVec[0]));
     168
     169  CPPUNIT_ASSERT(lp1->isContained(unitVec[0]+2*(unitVec[0]-unitVec[1])));
     170  CPPUNIT_ASSERT(lp2->isContained(unitVec[1]+2*(unitVec[1]-unitVec[2])));
     171  CPPUNIT_ASSERT(lp3->isContained(unitVec[2]+2*(unitVec[2]-unitVec[0])));
     172
     173  CPPUNIT_ASSERT(lp1->isContained(unitVec[0]-2*(unitVec[0]-unitVec[1])));
     174  CPPUNIT_ASSERT(lp2->isContained(unitVec[1]-2*(unitVec[1]-unitVec[2])));
     175  CPPUNIT_ASSERT(lp3->isContained(unitVec[2]-2*(unitVec[2]-unitVec[0])));
    176176}
    177177
     
    189189  // axes and plane lines
    190190  fixture = la1->getIntersection(*lp1);
    191   CPPUNIT_ASSERT_EQUAL(fixture,e1);
     191  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
    192192  fixture = la2->getIntersection(*lp2);
    193   CPPUNIT_ASSERT_EQUAL(fixture,e2);
     193  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
    194194  fixture = la3->getIntersection(*lp3);
    195   CPPUNIT_ASSERT_EQUAL(fixture,e3);
     195  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    196196
    197197  fixture = la1->getIntersection(*lp3);
    198   CPPUNIT_ASSERT_EQUAL(fixture,e1);
     198  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
    199199  fixture = la2->getIntersection(*lp1);
    200   CPPUNIT_ASSERT_EQUAL(fixture,e2);
     200  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
    201201  fixture = la3->getIntersection(*lp2);
    202   CPPUNIT_ASSERT_EQUAL(fixture,e3);
     202  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    203203
    204204  // two plane lines
    205205  fixture = lp1->getIntersection(*lp2);
    206   CPPUNIT_ASSERT_EQUAL(fixture,e2);
     206  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
    207207  fixture = lp2->getIntersection(*lp3);
    208   CPPUNIT_ASSERT_EQUAL(fixture,e3);
     208  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    209209  fixture = lp3->getIntersection(*lp1);
    210   CPPUNIT_ASSERT_EQUAL(fixture,e1);
     210  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
    211211
    212212  // When we have two times the same line, we check if the point is on the line
     
    254254
    255255  // rotate vectors on the axis around their lines
    256   fixture = la1->rotateVector(e1,1.);
    257   CPPUNIT_ASSERT_EQUAL(fixture,e1);
    258   fixture = la2->rotateVector(e2,1.);
    259   CPPUNIT_ASSERT_EQUAL(fixture,e2);
    260   fixture = la3->rotateVector(e3,1.);
    261   CPPUNIT_ASSERT_EQUAL(fixture,e3);
    262 
    263   fixture = la1->rotateVector(e1,2.);
    264   CPPUNIT_ASSERT_EQUAL(fixture,e1);
    265   fixture = la2->rotateVector(e2,2.);
    266   CPPUNIT_ASSERT_EQUAL(fixture,e2);
    267   fixture = la3->rotateVector(e3,2.);
    268   CPPUNIT_ASSERT_EQUAL(fixture,e3);
     256  fixture = la1->rotateVector(unitVec[0],1.);
     257  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
     258  fixture = la2->rotateVector(unitVec[1],1.);
     259  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
     260  fixture = la3->rotateVector(unitVec[2],1.);
     261  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
     262
     263  fixture = la1->rotateVector(unitVec[0],2.);
     264  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
     265  fixture = la2->rotateVector(unitVec[1],2.);
     266  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
     267  fixture = la3->rotateVector(unitVec[2],2.);
     268  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    269269
    270270  // more vectors on the axis
    271   fixture = la1->rotateVector(2*e1,1.);
    272   CPPUNIT_ASSERT_EQUAL(fixture,2*e1);
    273   fixture = la2->rotateVector(2*e2,1.);
    274   CPPUNIT_ASSERT_EQUAL(fixture,2*e2);
    275   fixture = la3->rotateVector(2*e3,1.);
    276   CPPUNIT_ASSERT_EQUAL(fixture,2*e3);
    277 
    278   fixture = la1->rotateVector(2*e1,2.);
    279   CPPUNIT_ASSERT_EQUAL(fixture,2*e1);
    280   fixture = la2->rotateVector(2*e2,2.);
    281   CPPUNIT_ASSERT_EQUAL(fixture,2*e2);
    282   fixture = la3->rotateVector(2*e3,2.);
    283   CPPUNIT_ASSERT_EQUAL(fixture,2*e3);
     271  fixture = la1->rotateVector(2*unitVec[0],1.);
     272  CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[0]);
     273  fixture = la2->rotateVector(2*unitVec[1],1.);
     274  CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[1]);
     275  fixture = la3->rotateVector(2*unitVec[2],1.);
     276  CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[2]);
     277
     278  fixture = la1->rotateVector(2*unitVec[0],2.);
     279  CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[0]);
     280  fixture = la2->rotateVector(2*unitVec[1],2.);
     281  CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[1]);
     282  fixture = la3->rotateVector(2*unitVec[2],2.);
     283  CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[2]);
    284284
    285285  // negative factors
    286   fixture = la1->rotateVector(-1*e1,1.);
    287   CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
    288   fixture = la2->rotateVector(-1*e2,1.);
    289   CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
    290   fixture = la3->rotateVector(-1*e3,1.);
    291   CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
    292 
    293   fixture = la1->rotateVector(-1*e1,2.);
    294   CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
    295   fixture = la2->rotateVector(-1*e2,2.);
    296   CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
    297   fixture = la3->rotateVector(-1*e3,2.);
    298   CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
     286  fixture = la1->rotateVector(-1*unitVec[0],1.);
     287  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
     288  fixture = la2->rotateVector(-1*unitVec[1],1.);
     289  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
     290  fixture = la3->rotateVector(-1*unitVec[2],1.);
     291  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
     292
     293  fixture = la1->rotateVector(-1*unitVec[0],2.);
     294  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
     295  fixture = la2->rotateVector(-1*unitVec[1],2.);
     296  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
     297  fixture = la3->rotateVector(-1*unitVec[2],2.);
     298  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
    299299
    300300
    301301
    302302  // now the real rotations
    303   // e2 around e1
    304   fixture = la1->rotateVector(e2,0);
    305   CPPUNIT_ASSERT_EQUAL(fixture,e2);
    306   fixture = la1->rotateVector(e2,1./2.*M_PI);
    307   CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
    308   fixture = la1->rotateVector(e2,M_PI);
    309   CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
    310   fixture = la1->rotateVector(e2,2*M_PI);
    311   CPPUNIT_ASSERT_EQUAL(fixture,e2);
    312 
    313   // e3 around e2
    314   fixture = la2->rotateVector(e3,0);
    315   CPPUNIT_ASSERT_EQUAL(fixture,e3);
    316   fixture = la2->rotateVector(e3,1./2.*M_PI);
    317   CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
    318   fixture = la2->rotateVector(e3,M_PI);
    319   CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
    320   fixture = la2->rotateVector(e3,2*M_PI);
    321   CPPUNIT_ASSERT_EQUAL(fixture,e3);
    322 
    323   // e1 around e3
    324   fixture = la3->rotateVector(e1,0);
    325   CPPUNIT_ASSERT_EQUAL(fixture,e1);
    326   fixture = la3->rotateVector(e1,1./2.*M_PI);
    327   CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
    328   fixture = la3->rotateVector(e1,M_PI);
    329   CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
    330   fixture = la3->rotateVector(e1,2*M_PI);
    331   CPPUNIT_ASSERT_EQUAL(fixture,e1);
     303  // unitVec[1] around unitVec[0]
     304  fixture = la1->rotateVector(unitVec[1],0);
     305  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
     306  fixture = la1->rotateVector(unitVec[1],1./2.*M_PI);
     307  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
     308  fixture = la1->rotateVector(unitVec[1],M_PI);
     309  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
     310  fixture = la1->rotateVector(unitVec[1],2*M_PI);
     311  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
     312
     313  // unitVec[2] around unitVec[1]
     314  fixture = la2->rotateVector(unitVec[2],0);
     315  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
     316  fixture = la2->rotateVector(unitVec[2],1./2.*M_PI);
     317  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
     318  fixture = la2->rotateVector(unitVec[2],M_PI);
     319  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
     320  fixture = la2->rotateVector(unitVec[2],2*M_PI);
     321  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
     322
     323  // unitVec[0] around unitVec[2]
     324  fixture = la3->rotateVector(unitVec[0],0);
     325  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
     326  fixture = la3->rotateVector(unitVec[0],1./2.*M_PI);
     327  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
     328  fixture = la3->rotateVector(unitVec[0],M_PI);
     329  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
     330  fixture = la3->rotateVector(unitVec[0],2*M_PI);
     331  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
    332332
    333333
     
    335335
    336336  // Vectors on the line
    337   fixture = lp1->rotateVector(e1,1.);
    338   CPPUNIT_ASSERT_EQUAL(fixture,e1);
    339   fixture = lp1->rotateVector(e2,1.);
    340   CPPUNIT_ASSERT_EQUAL(fixture,e2);
    341 
    342   fixture = lp2->rotateVector(e2,1.);
    343   CPPUNIT_ASSERT_EQUAL(fixture,e2);
    344   fixture = lp2->rotateVector(e3,1.);
    345   CPPUNIT_ASSERT_EQUAL(fixture,e3);
    346 
    347   fixture = lp3->rotateVector(e3,1.);
    348   CPPUNIT_ASSERT_EQUAL(fixture,e3);
    349   fixture = lp3->rotateVector(e1,1.);
    350   CPPUNIT_ASSERT_EQUAL(fixture,e1);
     337  fixture = lp1->rotateVector(unitVec[0],1.);
     338  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
     339  fixture = lp1->rotateVector(unitVec[1],1.);
     340  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
     341
     342  fixture = lp2->rotateVector(unitVec[1],1.);
     343  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
     344  fixture = lp2->rotateVector(unitVec[2],1.);
     345  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
     346
     347  fixture = lp3->rotateVector(unitVec[2],1.);
     348  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
     349  fixture = lp3->rotateVector(unitVec[0],1.);
     350  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
    351351
    352352  // the real stuff
     
    370370    std::vector<Vector> res = la1->getSphereIntersections();
    371371    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
    372     CPPUNIT_ASSERT(testDirection(res[0],e1));
    373     CPPUNIT_ASSERT(testDirection(res[1],e1));
     372    CPPUNIT_ASSERT(testDirection(res[0],unitVec[0]));
     373    CPPUNIT_ASSERT(testDirection(res[1],unitVec[0]));
    374374    CPPUNIT_ASSERT(res[0]!=res[1]);
    375375  }
     
    378378    std::vector<Vector> res = la2->getSphereIntersections();
    379379    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
    380     CPPUNIT_ASSERT(testDirection(res[0],e2));
    381     CPPUNIT_ASSERT(testDirection(res[1],e2));
     380    CPPUNIT_ASSERT(testDirection(res[0],unitVec[1]));
     381    CPPUNIT_ASSERT(testDirection(res[1],unitVec[1]));
    382382    CPPUNIT_ASSERT(res[0]!=res[1]);
    383383  }
     
    386386    std::vector<Vector> res = la3->getSphereIntersections();
    387387    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
    388     CPPUNIT_ASSERT(testDirection(res[0],e3));
    389     CPPUNIT_ASSERT(testDirection(res[1],e3));
     388    CPPUNIT_ASSERT(testDirection(res[0],unitVec[2]));
     389    CPPUNIT_ASSERT(testDirection(res[1],unitVec[2]));
    390390    CPPUNIT_ASSERT(res[0]!=res[1]);
    391391  }
     
    394394    std::vector<Vector> res = lp1->getSphereIntersections();
    395395    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
    396     CPPUNIT_ASSERT((res[0]==e1) || (res[0]==e2));
    397     CPPUNIT_ASSERT((res[1]==e1) || (res[1]==e2));
     396    CPPUNIT_ASSERT((res[0]==unitVec[0]) || (res[0]==unitVec[1]));
     397    CPPUNIT_ASSERT((res[1]==unitVec[0]) || (res[1]==unitVec[1]));
    398398    CPPUNIT_ASSERT(res[0]!=res[1]);
    399399  }
     
    402402    std::vector<Vector> res = lp2->getSphereIntersections();
    403403    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
    404     CPPUNIT_ASSERT((res[0]==e2) || (res[0]==e3));
    405     CPPUNIT_ASSERT((res[1]==e2) || (res[1]==e3));
     404    CPPUNIT_ASSERT((res[0]==unitVec[1]) || (res[0]==unitVec[2]));
     405    CPPUNIT_ASSERT((res[1]==unitVec[1]) || (res[1]==unitVec[2]));
    406406    CPPUNIT_ASSERT(res[0]!=res[1]);
    407407  }
     
    410410    std::vector<Vector> res = lp3->getSphereIntersections();
    411411    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
    412     CPPUNIT_ASSERT((res[0]==e3) || (res[0]==e1));
    413     CPPUNIT_ASSERT((res[1]==e3) || (res[1]==e1));
    414     CPPUNIT_ASSERT(res[0]!=res[1]);
    415   }
    416 }
     412    CPPUNIT_ASSERT((res[0]==unitVec[2]) || (res[0]==unitVec[0]));
     413    CPPUNIT_ASSERT((res[1]==unitVec[2]) || (res[1]==unitVec[0]));
     414    CPPUNIT_ASSERT(res[0]!=res[1]);
     415  }
     416}
  • src/unittests/Makefile.am

    rfd4905 r6c438f  
    1616  atomsCalculationTest \
    1717  AtomDescriptorTest \
    18   BaseShapesUnitTest \
    1918  BondGraphUnitTest \
    2019  BoxUnittest \
     
    7574  AtomDescriptorTest.cpp \
    7675  atomsCalculationTest.cpp \
    77   BaseShapesUnittest.cpp \
    7876  bondgraphunittest.cpp \
    7977  BoxUnittest.cpp \
     
    114112  AtomDescriptorTest.hpp \
    115113  atomsCalculationTest.hpp \
    116   BaseShapesUnittest.hpp \
    117114  bondgraphunittest.hpp \
    118115  BoxUnittest.hpp \
     
    168165AtomDescriptorTest_LDADD = ${ALLLIBS}
    169166
    170 BaseShapesUnitTest_SOURCES = UnitTestMain.cpp BaseShapesUnittest.cpp BaseShapesUnittest.hpp
    171 BaseShapesUnitTest_LDADD = ${ALLLIBS}
    172 
    173167BondGraphUnitTest_SOURCES = UnitTestMain.cpp bondgraphunittest.cpp bondgraphunittest.hpp
    174168BondGraphUnitTest_LDADD = ${ALLLIBS}
  • src/unittests/MatrixUnittest.cpp

    rfd4905 r6c438f  
    2525
    2626#include "MatrixUnittest.hpp"
     27#include "LinearAlgebra/Vector.hpp"
    2728#include "LinearAlgebra/Matrix.hpp"
    28 #include "LinearAlgebra/Vector.hpp"
    2929#include "Exceptions/NotInvertibleException.hpp"
    3030
     
    5353  }
    5454  perm1 = new Matrix();
    55   perm1->column(0) = e1;
    56   perm1->column(1) = e3;
    57   perm1->column(2) = e2;
     55  perm1->column(0) = unitVec[0];
     56  perm1->column(1) = unitVec[2];
     57  perm1->column(2) = unitVec[1];
    5858
    5959
    6060  perm2 = new Matrix();
    61   perm2->column(0) = e2;
    62   perm2->column(1) = e1;
    63   perm2->column(2) = e3;
     61  perm2->column(0) = unitVec[1];
     62  perm2->column(1) = unitVec[0];
     63  perm2->column(2) = unitVec[2];
    6464
    6565  perm3 = new Matrix();
    66   perm3->column(0) = e2;
    67   perm3->column(1) = e3;
    68   perm3->column(2) = e1;
     66  perm3->column(0) = unitVec[1];
     67  perm3->column(1) = unitVec[2];
     68  perm3->column(2) = unitVec[0];
    6969
    7070  perm4 = new Matrix();
    71   perm4->column(0) = e3;
    72   perm4->column(1) = e2;
    73   perm4->column(2) = e1;
     71  perm4->column(0) = unitVec[2];
     72  perm4->column(1) = unitVec[1];
     73  perm4->column(2) = unitVec[0];
    7474
    7575  perm5 = new Matrix();
    76   perm5->column(0) = e3;
    77   perm5->column(1) = e1;
    78   perm5->column(2) = e2;
     76  perm5->column(0) = unitVec[2];
     77  perm5->column(1) = unitVec[0];
     78  perm5->column(2) = unitVec[1];
    7979
    8080}
     
    122122
    123123  mat.one();
    124   CPPUNIT_ASSERT_EQUAL(mat.row(0),e1);
    125   CPPUNIT_ASSERT_EQUAL(mat.row(1),e2);
    126   CPPUNIT_ASSERT_EQUAL(mat.row(2),e3);
    127   CPPUNIT_ASSERT_EQUAL(mat.column(0),e1);
    128   CPPUNIT_ASSERT_EQUAL(mat.column(1),e2);
    129   CPPUNIT_ASSERT_EQUAL(mat.column(2),e3);
     124  CPPUNIT_ASSERT_EQUAL(mat.row(0),unitVec[0]);
     125  CPPUNIT_ASSERT_EQUAL(mat.row(1),unitVec[1]);
     126  CPPUNIT_ASSERT_EQUAL(mat.row(2),unitVec[2]);
     127  CPPUNIT_ASSERT_EQUAL(mat.column(0),unitVec[0]);
     128  CPPUNIT_ASSERT_EQUAL(mat.column(1),unitVec[1]);
     129  CPPUNIT_ASSERT_EQUAL(mat.column(2),unitVec[2]);
    130130
    131131  Vector t1=Vector(1.,1.,1.);
     
    232232
    233233  res = (*diagonal)*(*perm1);
    234   CPPUNIT_ASSERT_EQUAL(res.column(0),e1);
    235   CPPUNIT_ASSERT_EQUAL(res.column(1),3*e3);
    236   CPPUNIT_ASSERT_EQUAL(res.column(2),2*e2);
     234  CPPUNIT_ASSERT_EQUAL(res.column(0),unitVec[0]);
     235  CPPUNIT_ASSERT_EQUAL(res.column(1),3*unitVec[2]);
     236  CPPUNIT_ASSERT_EQUAL(res.column(2),2*unitVec[1]);
    237237  res = (*diagonal)*(*perm2);
    238   CPPUNIT_ASSERT_EQUAL(res.column(0),2*e2);
    239   CPPUNIT_ASSERT_EQUAL(res.column(1),e1);
    240   CPPUNIT_ASSERT_EQUAL(res.column(2),3*e3);
     238  CPPUNIT_ASSERT_EQUAL(res.column(0),2*unitVec[1]);
     239  CPPUNIT_ASSERT_EQUAL(res.column(1),unitVec[0]);
     240  CPPUNIT_ASSERT_EQUAL(res.column(2),3*unitVec[2]);
    241241  res = (*diagonal)*(*perm3);
    242   CPPUNIT_ASSERT_EQUAL(res.column(0),2*e2);
    243   CPPUNIT_ASSERT_EQUAL(res.column(1),3*e3);
    244   CPPUNIT_ASSERT_EQUAL(res.column(2),e1);
     242  CPPUNIT_ASSERT_EQUAL(res.column(0),2*unitVec[1]);
     243  CPPUNIT_ASSERT_EQUAL(res.column(1),3*unitVec[2]);
     244  CPPUNIT_ASSERT_EQUAL(res.column(2),unitVec[0]);
    245245  res = (*diagonal)*(*perm4);
    246   CPPUNIT_ASSERT_EQUAL(res.column(0),3*e3);
    247   CPPUNIT_ASSERT_EQUAL(res.column(1),2*e2);
    248   CPPUNIT_ASSERT_EQUAL(res.column(2),e1);
     246  CPPUNIT_ASSERT_EQUAL(res.column(0),3*unitVec[2]);
     247  CPPUNIT_ASSERT_EQUAL(res.column(1),2*unitVec[1]);
     248  CPPUNIT_ASSERT_EQUAL(res.column(2),unitVec[0]);
    249249  res = (*diagonal)*(*perm5);
    250   CPPUNIT_ASSERT_EQUAL(res.column(0),3*e3);
    251   CPPUNIT_ASSERT_EQUAL(res.column(1),e1);
    252   CPPUNIT_ASSERT_EQUAL(res.column(2),2*e2);
     250  CPPUNIT_ASSERT_EQUAL(res.column(0),3*unitVec[2]);
     251  CPPUNIT_ASSERT_EQUAL(res.column(1),unitVec[0]);
     252  CPPUNIT_ASSERT_EQUAL(res.column(2),2*unitVec[1]);
    253253}
    254254
     
    310310
    311311void MatrixUnittest::VecMultTest(){
    312   CPPUNIT_ASSERT_EQUAL((*zero)*e1,zeroVec);
    313   CPPUNIT_ASSERT_EQUAL((*zero)*e2,zeroVec);
    314   CPPUNIT_ASSERT_EQUAL((*zero)*e3,zeroVec);
     312  CPPUNIT_ASSERT_EQUAL((*zero)*unitVec[0],zeroVec);
     313  CPPUNIT_ASSERT_EQUAL((*zero)*unitVec[1],zeroVec);
     314  CPPUNIT_ASSERT_EQUAL((*zero)*unitVec[2],zeroVec);
    315315  CPPUNIT_ASSERT_EQUAL((*zero)*zeroVec,zeroVec);
    316316
    317   CPPUNIT_ASSERT_EQUAL((*one)*e1,e1);
    318   CPPUNIT_ASSERT_EQUAL((*one)*e2,e2);
    319   CPPUNIT_ASSERT_EQUAL((*one)*e3,e3);
     317  CPPUNIT_ASSERT_EQUAL((*one)*unitVec[0],unitVec[0]);
     318  CPPUNIT_ASSERT_EQUAL((*one)*unitVec[1],unitVec[1]);
     319  CPPUNIT_ASSERT_EQUAL((*one)*unitVec[2],unitVec[2]);
    320320  CPPUNIT_ASSERT_EQUAL((*one)*zeroVec,zeroVec);
    321321
    322   CPPUNIT_ASSERT_EQUAL((*diagonal)*e1,e1);
    323   CPPUNIT_ASSERT_EQUAL((*diagonal)*e2,2*e2);
    324   CPPUNIT_ASSERT_EQUAL((*diagonal)*e3,3*e3);
     322  CPPUNIT_ASSERT_EQUAL((*diagonal)*unitVec[0],unitVec[0]);
     323  CPPUNIT_ASSERT_EQUAL((*diagonal)*unitVec[1],2*unitVec[1]);
     324  CPPUNIT_ASSERT_EQUAL((*diagonal)*unitVec[2],3*unitVec[2]);
    325325  CPPUNIT_ASSERT_EQUAL((*diagonal)*zeroVec,zeroVec);
    326326
    327   CPPUNIT_ASSERT_EQUAL((*perm1)*e1,e1);
    328   CPPUNIT_ASSERT_EQUAL((*perm1)*e2,e3);
    329   CPPUNIT_ASSERT_EQUAL((*perm1)*e3,e2);
     327  CPPUNIT_ASSERT_EQUAL((*perm1)*unitVec[0],unitVec[0]);
     328  CPPUNIT_ASSERT_EQUAL((*perm1)*unitVec[1],unitVec[2]);
     329  CPPUNIT_ASSERT_EQUAL((*perm1)*unitVec[2],unitVec[1]);
    330330  CPPUNIT_ASSERT_EQUAL((*perm1)*zeroVec,zeroVec);
    331331
    332   CPPUNIT_ASSERT_EQUAL((*perm2)*e1,e2);
    333   CPPUNIT_ASSERT_EQUAL((*perm2)*e2,e1);
    334   CPPUNIT_ASSERT_EQUAL((*perm2)*e3,e3);
     332  CPPUNIT_ASSERT_EQUAL((*perm2)*unitVec[0],unitVec[1]);
     333  CPPUNIT_ASSERT_EQUAL((*perm2)*unitVec[1],unitVec[0]);
     334  CPPUNIT_ASSERT_EQUAL((*perm2)*unitVec[2],unitVec[2]);
    335335  CPPUNIT_ASSERT_EQUAL((*perm2)*zeroVec,zeroVec);
    336336
    337   CPPUNIT_ASSERT_EQUAL((*perm3)*e1,e2);
    338   CPPUNIT_ASSERT_EQUAL((*perm3)*e2,e3);
    339   CPPUNIT_ASSERT_EQUAL((*perm3)*e3,e1);
     337  CPPUNIT_ASSERT_EQUAL((*perm3)*unitVec[0],unitVec[1]);
     338  CPPUNIT_ASSERT_EQUAL((*perm3)*unitVec[1],unitVec[2]);
     339  CPPUNIT_ASSERT_EQUAL((*perm3)*unitVec[2],unitVec[0]);
    340340  CPPUNIT_ASSERT_EQUAL((*perm3)*zeroVec,zeroVec);
    341341
    342   CPPUNIT_ASSERT_EQUAL((*perm4)*e1,e3);
    343   CPPUNIT_ASSERT_EQUAL((*perm4)*e2,e2);
    344   CPPUNIT_ASSERT_EQUAL((*perm4)*e3,e1);
     342  CPPUNIT_ASSERT_EQUAL((*perm4)*unitVec[0],unitVec[2]);
     343  CPPUNIT_ASSERT_EQUAL((*perm4)*unitVec[1],unitVec[1]);
     344  CPPUNIT_ASSERT_EQUAL((*perm4)*unitVec[2],unitVec[0]);
    345345  CPPUNIT_ASSERT_EQUAL((*perm4)*zeroVec,zeroVec);
    346346
    347   CPPUNIT_ASSERT_EQUAL((*perm5)*e1,e3);
    348   CPPUNIT_ASSERT_EQUAL((*perm5)*e2,e1);
    349   CPPUNIT_ASSERT_EQUAL((*perm5)*e3,e2);
     347  CPPUNIT_ASSERT_EQUAL((*perm5)*unitVec[0],unitVec[2]);
     348  CPPUNIT_ASSERT_EQUAL((*perm5)*unitVec[1],unitVec[0]);
     349  CPPUNIT_ASSERT_EQUAL((*perm5)*unitVec[2],unitVec[1]);
    350350  CPPUNIT_ASSERT_EQUAL((*perm5)*zeroVec,zeroVec);
    351351
  • src/unittests/PlaneUnittest.cpp

    rfd4905 r6c438f  
    3636
    3737void PlaneUnittest::setUp(){
    38   p1 = new Plane(e1,e2,e3);
    39   p2 = new Plane(e1,e2,zeroVec);
    40   p3 = new Plane(e1,zeroVec,e3);
    41   p4 = new Plane(zeroVec,e2,e3);
     38  p1 = new Plane(unitVec[0],unitVec[1],unitVec[2]);
     39  p2 = new Plane(unitVec[0],unitVec[1],zeroVec);
     40  p3 = new Plane(unitVec[0],zeroVec,unitVec[2]);
     41  p4 = new Plane(zeroVec,unitVec[1],unitVec[2]);
    4242}
    4343
     
    5454
    5555  // three points
    56   CPPUNIT_ASSERT_NO_THROW(Plane(e1,e2,e3));
     56  CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],unitVec[1],unitVec[2]));
    5757  // when only two points are differnt this gives an error
    58   CPPUNIT_ASSERT_THROW(Plane(e1,e2,e2),LinearDependenceException);
     58  CPPUNIT_ASSERT_THROW(Plane(unitVec[0],unitVec[1],unitVec[1]),LinearDependenceException);
    5959  // same with only one point
    60   CPPUNIT_ASSERT_THROW(Plane(e1,e1,e1),LinearDependenceException);
     60  CPPUNIT_ASSERT_THROW(Plane(unitVec[0],unitVec[0],unitVec[0]),LinearDependenceException);
    6161
    6262  // use two vector giving two directions
    63   CPPUNIT_ASSERT_NO_THROW(Plane(e1,e2,0));
     63  CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],unitVec[1],0));
    6464  // and again this is actually only one vector
    65   CPPUNIT_ASSERT_THROW(Plane(e1,e1,0),LinearDependenceException);
     65  CPPUNIT_ASSERT_THROW(Plane(unitVec[0],unitVec[0],0),LinearDependenceException);
    6666  // Zero vector does not give a good direction
    67   CPPUNIT_ASSERT_THROW(Plane(e1,zeroVec,0),ZeroVectorException);
     67  CPPUNIT_ASSERT_THROW(Plane(unitVec[0],zeroVec,0),ZeroVectorException);
    6868
    6969  // use a normalvector and an scalar offset
    70   CPPUNIT_ASSERT_NO_THROW(Plane(e1,0));
     70  CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],0));
    7171  // The zero vector is no good as a normalvector
    7272  CPPUNIT_ASSERT_THROW(Plane(zeroVec,0),ZeroVectorException);
    7373
    7474  // use a normalvector and an offset vector
    75   CPPUNIT_ASSERT_NO_THROW(Plane(e1,zeroVec));
     75  CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],zeroVec));
    7676  // and the bad zeroVector again
    7777  CPPUNIT_ASSERT_THROW(Plane(zeroVec,zeroVec),ZeroVectorException);
     
    8787  {
    8888    // construct with three points on plane
    89     Plane p1(e1,e2,zeroVec);
    90     CPPUNIT_ASSERT(testNormal(e3,p1.getNormal()));
     89    Plane p1(unitVec[0],unitVec[1],zeroVec);
     90    CPPUNIT_ASSERT(testNormal(unitVec[2],p1.getNormal()));
    9191    CPPUNIT_ASSERT_EQUAL(0.,p1.getOffset());
    9292
    93     Plane p2(e1,e3,zeroVec);
    94     CPPUNIT_ASSERT(testNormal(e2,p2.getNormal()));
     93    Plane p2(unitVec[0],unitVec[2],zeroVec);
     94    CPPUNIT_ASSERT(testNormal(unitVec[1],p2.getNormal()));
    9595    CPPUNIT_ASSERT_EQUAL(0.,p2.getOffset());
    9696
    97     Plane p3(e2,e3,zeroVec);
    98     CPPUNIT_ASSERT(testNormal(e1,p3.getNormal()));
     97    Plane p3(unitVec[1],unitVec[2],zeroVec);
     98    CPPUNIT_ASSERT(testNormal(unitVec[0],p3.getNormal()));
    9999    CPPUNIT_ASSERT_EQUAL(0.,p3.getOffset());
    100100  }
    101101  {
    102102    // construct with two directions + offset
    103     Plane p1(e1,e2,0);
    104     CPPUNIT_ASSERT(testNormal(e3,p1.getNormal()));
     103    Plane p1(unitVec[0],unitVec[1],0);
     104    CPPUNIT_ASSERT(testNormal(unitVec[2],p1.getNormal()));
    105105    CPPUNIT_ASSERT_EQUAL(0.,p1.getOffset());
    106106
    107     Plane p2(e1,e3,0);
    108     CPPUNIT_ASSERT(testNormal(e2,p2.getNormal()));
     107    Plane p2(unitVec[0],unitVec[2],0);
     108    CPPUNIT_ASSERT(testNormal(unitVec[1],p2.getNormal()));
    109109    CPPUNIT_ASSERT_EQUAL(0.,p2.getOffset());
    110110
    111     Plane p3(e2,e3,0);
    112     CPPUNIT_ASSERT(testNormal(e1,p3.getNormal()));
     111    Plane p3(unitVec[1],unitVec[2],0);
     112    CPPUNIT_ASSERT(testNormal(unitVec[0],p3.getNormal()));
    113113    CPPUNIT_ASSERT_EQUAL(0.,p3.getOffset());
    114114  }
     
    157157void PlaneUnittest::operationsTest(){
    158158  {
    159     Vector t = (1./3.)*(e1+e2+e3);
     159    Vector t = (1./3.)*(unitVec[0]+unitVec[1]+unitVec[2]);
    160160    CPPUNIT_ASSERT(fabs(p1->distance(zeroVec)-t.Norm()) < MYEPSILON);
    161161    CPPUNIT_ASSERT_EQUAL(t,p1->getClosestPoint(zeroVec));
    162162  }
    163163
    164   CPPUNIT_ASSERT(fabs(p2->distance(e3)-1) < MYEPSILON);
    165   CPPUNIT_ASSERT_EQUAL(zeroVec,p2->getClosestPoint(e3));
    166   CPPUNIT_ASSERT(fabs(p3->distance(e2)-1) < MYEPSILON);
    167   CPPUNIT_ASSERT_EQUAL(zeroVec,p3->getClosestPoint(e2));
    168   CPPUNIT_ASSERT(fabs(p4->distance(e1)-1) < MYEPSILON);
    169   CPPUNIT_ASSERT_EQUAL(zeroVec,p4->getClosestPoint(e1));
     164  CPPUNIT_ASSERT(fabs(p2->distance(unitVec[2])-1) < MYEPSILON);
     165  CPPUNIT_ASSERT_EQUAL(zeroVec,p2->getClosestPoint(unitVec[2]));
     166  CPPUNIT_ASSERT(fabs(p3->distance(unitVec[1])-1) < MYEPSILON);
     167  CPPUNIT_ASSERT_EQUAL(zeroVec,p3->getClosestPoint(unitVec[1]));
     168  CPPUNIT_ASSERT(fabs(p4->distance(unitVec[0])-1) < MYEPSILON);
     169  CPPUNIT_ASSERT_EQUAL(zeroVec,p4->getClosestPoint(unitVec[0]));
    170170}
    171171
     
    174174
    175175  // some Vectors that lie on the planes
    176   fixture = p1->mirrorVector(e1);
    177   CPPUNIT_ASSERT_EQUAL(fixture,e1);
    178   fixture = p1->mirrorVector(e2);
    179   CPPUNIT_ASSERT_EQUAL(fixture,e2);
    180   fixture = p1->mirrorVector(e3);
    181   CPPUNIT_ASSERT_EQUAL(fixture,e3);
     176  fixture = p1->mirrorVector(unitVec[0]);
     177  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
     178  fixture = p1->mirrorVector(unitVec[1]);
     179  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
     180  fixture = p1->mirrorVector(unitVec[2]);
     181  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    182182
    183183  fixture = p2->mirrorVector(zeroVec);
    184184  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
    185   fixture = p2->mirrorVector(e1);
    186   CPPUNIT_ASSERT_EQUAL(fixture,e1);
    187   fixture = p2->mirrorVector(e2);
    188   CPPUNIT_ASSERT_EQUAL(fixture,e2);
     185  fixture = p2->mirrorVector(unitVec[0]);
     186  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
     187  fixture = p2->mirrorVector(unitVec[1]);
     188  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
    189189
    190190  fixture = p3->mirrorVector(zeroVec);
    191191  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
    192   fixture = p3->mirrorVector(e1);
    193   CPPUNIT_ASSERT_EQUAL(fixture,e1);
    194   fixture = p3->mirrorVector(e3);
    195   CPPUNIT_ASSERT_EQUAL(fixture,e3);
     192  fixture = p3->mirrorVector(unitVec[0]);
     193  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
     194  fixture = p3->mirrorVector(unitVec[2]);
     195  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    196196
    197197  fixture = p4->mirrorVector(zeroVec);
    198198  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
    199   fixture = p4->mirrorVector(e2);
    200   CPPUNIT_ASSERT_EQUAL(fixture,e2);
    201   fixture = p4->mirrorVector(e3);
    202   CPPUNIT_ASSERT_EQUAL(fixture,e3);
     199  fixture = p4->mirrorVector(unitVec[1]);
     200  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
     201  fixture = p4->mirrorVector(unitVec[2]);
     202  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    203203
    204204  // some Vectors outside of the planes
    205205  {
    206     Vector t = (2./3.)*(e1+e2+e3);
     206    Vector t = (2./3.)*(unitVec[0]+unitVec[1]+unitVec[2]);
    207207    fixture = p1->mirrorVector(zeroVec);
    208208    CPPUNIT_ASSERT_EQUAL(fixture,t);
    209209  }
    210210
    211   fixture = p2->mirrorVector(e3);
    212   CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
    213   fixture = p3->mirrorVector(e2);
    214   CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
    215   fixture = p4->mirrorVector(e1);
    216   CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
     211  fixture = p2->mirrorVector(unitVec[2]);
     212  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
     213  fixture = p3->mirrorVector(unitVec[1]);
     214  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
     215  fixture = p4->mirrorVector(unitVec[0]);
     216  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
    217217}
    218218
     
    221221  // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ???
    222222  Line l1 = makeLineThrough(zeroVec,Vector(2,1,0));
    223   CPPUNIT_ASSERT_NO_THROW(fixture = Plane(e1, zeroVec).GetIntersection(l1) );
     223  CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unitVec[0], zeroVec).GetIntersection(l1) );
    224224  CPPUNIT_ASSERT_EQUAL( zeroVec, fixture );
    225225
    226226  // plane at (2,1,0) normal to (0,1,0) cuts line from (1,0,0) to (0,1,1) at ???
    227   Line l2 = makeLineThrough(e1,Vector(0,1,1));
    228   CPPUNIT_ASSERT_NO_THROW(fixture = Plane(e2, Vector(2,1,0)).GetIntersection(l2) );
     227  Line l2 = makeLineThrough(unitVec[0],Vector(0,1,1));
     228  CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unitVec[1], Vector(2,1,0)).GetIntersection(l2) );
    229229  CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture );
    230230}
  • src/unittests/ShapeUnittest.cpp

    rfd4905 r6c438f  
    4040void ShapeUnittest::setUp()
    4141{
    42   v000 =  0*e1+0*e2+0*e3;
    43   v100 =  1*e1+0*e2+0*e3;
    44   v200 = -1*e1+0*e2+0*e3;
    45   v010 =  0*e1+1*e2+0*e3;
    46   v110 =  1*e1+1*e2+0*e3;
    47   v210 = -1*e1+1*e2+0*e3;
    48   v020 =  0*e1-1*e2+0*e3;
    49   v120 =  1*e1-1*e2+0*e3;
    50   v220 = -1*e1-1*e2+0*e3;
    51   v001 =  0*e1+0*e2+1*e3;
    52   v101 =  1*e1+0*e2+1*e3;
    53   v201 = -1*e1+0*e2+1*e3;
    54   v011 =  0*e1+1*e2+1*e3;
    55   v111 =  1*e1+1*e2+1*e3;
    56   v211 = -1*e1+1*e2+1*e3;
    57   v021 =  0*e1-1*e2+1*e3;
    58   v121 =  1*e1-1*e2+1*e3;
    59   v221 = -1*e1-1*e2+1*e3;
    60   v002 =  0*e1+0*e2-1*e3;
    61   v102 =  1*e1+0*e2-1*e3;
    62   v202 = -1*e1+0*e2-1*e3;
    63   v012 =  0*e1+1*e2-1*e3;
    64   v112 =  1*e1+1*e2-1*e3;
    65   v212 = -1*e1+1*e2-1*e3;
    66   v022 =  0*e1-1*e2-1*e3;
    67   v122 =  1*e1-1*e2-1*e3;
    68   v222 = -1*e1-1*e2-1*e3;
     42  v000 =  0*unitVec[0]+0*unitVec[1]+0*unitVec[2];
     43  v100 =  1*unitVec[0]+0*unitVec[1]+0*unitVec[2];
     44  v200 = -1*unitVec[0]+0*unitVec[1]+0*unitVec[2];
     45  v010 =  0*unitVec[0]+1*unitVec[1]+0*unitVec[2];
     46  v110 =  1*unitVec[0]+1*unitVec[1]+0*unitVec[2];
     47  v210 = -1*unitVec[0]+1*unitVec[1]+0*unitVec[2];
     48  v020 =  0*unitVec[0]-1*unitVec[1]+0*unitVec[2];
     49  v120 =  1*unitVec[0]-1*unitVec[1]+0*unitVec[2];
     50  v220 = -1*unitVec[0]-1*unitVec[1]+0*unitVec[2];
     51  v001 =  0*unitVec[0]+0*unitVec[1]+1*unitVec[2];
     52  v101 =  1*unitVec[0]+0*unitVec[1]+1*unitVec[2];
     53  v201 = -1*unitVec[0]+0*unitVec[1]+1*unitVec[2];
     54  v011 =  0*unitVec[0]+1*unitVec[1]+1*unitVec[2];
     55  v111 =  1*unitVec[0]+1*unitVec[1]+1*unitVec[2];
     56  v211 = -1*unitVec[0]+1*unitVec[1]+1*unitVec[2];
     57  v021 =  0*unitVec[0]-1*unitVec[1]+1*unitVec[2];
     58  v121 =  1*unitVec[0]-1*unitVec[1]+1*unitVec[2];
     59  v221 = -1*unitVec[0]-1*unitVec[1]+1*unitVec[2];
     60  v002 =  0*unitVec[0]+0*unitVec[1]-1*unitVec[2];
     61  v102 =  1*unitVec[0]+0*unitVec[1]-1*unitVec[2];
     62  v202 = -1*unitVec[0]+0*unitVec[1]-1*unitVec[2];
     63  v012 =  0*unitVec[0]+1*unitVec[1]-1*unitVec[2];
     64  v112 =  1*unitVec[0]+1*unitVec[1]-1*unitVec[2];
     65  v212 = -1*unitVec[0]+1*unitVec[1]-1*unitVec[2];
     66  v022 =  0*unitVec[0]-1*unitVec[1]-1*unitVec[2];
     67  v122 =  1*unitVec[0]-1*unitVec[1]-1*unitVec[2];
     68  v222 = -1*unitVec[0]-1*unitVec[1]-1*unitVec[2];
    6969}
    7070
     
    129129  CPPUNIT_ASSERT(Everywhere().isInside(v122));
    130130  CPPUNIT_ASSERT(Everywhere().isInside(v222));
     131
     132  Shape s1 = Sphere();
     133
     134  CPPUNIT_ASSERT(s1.isInside(v000));
     135  CPPUNIT_ASSERT(s1.isInside(v100));
     136  CPPUNIT_ASSERT(s1.isInside(v200));
     137  CPPUNIT_ASSERT(s1.isInside(v010));
     138  CPPUNIT_ASSERT(!s1.isInside(v110));
     139  CPPUNIT_ASSERT(!s1.isInside(v210));
     140  CPPUNIT_ASSERT(s1.isInside(v020));
     141  CPPUNIT_ASSERT(!s1.isInside(v120));
     142  CPPUNIT_ASSERT(!s1.isInside(v220));
     143  CPPUNIT_ASSERT(s1.isInside(v001));
     144  CPPUNIT_ASSERT(!s1.isInside(v101));
     145  CPPUNIT_ASSERT(!s1.isInside(v201));
     146  CPPUNIT_ASSERT(!s1.isInside(v011));
     147  CPPUNIT_ASSERT(!s1.isInside(v111));
     148  CPPUNIT_ASSERT(!s1.isInside(v211));
     149  CPPUNIT_ASSERT(!s1.isInside(v021));
     150  CPPUNIT_ASSERT(!s1.isInside(v121));
     151  CPPUNIT_ASSERT(!s1.isInside(v221));
     152  CPPUNIT_ASSERT(s1.isInside(v002));
     153  CPPUNIT_ASSERT(!s1.isInside(v102));
     154  CPPUNIT_ASSERT(!s1.isInside(v202));
     155  CPPUNIT_ASSERT(!s1.isInside(v012));
     156  CPPUNIT_ASSERT(!s1.isInside(v112));
     157  CPPUNIT_ASSERT(!s1.isInside(v212));
     158  CPPUNIT_ASSERT(!s1.isInside(v022));
     159  CPPUNIT_ASSERT(!s1.isInside(v122));
     160  CPPUNIT_ASSERT(!s1.isInside(v222));
     161
     162  Shape s2 = Cuboid();
     163
     164  CPPUNIT_ASSERT(s2.isInside(v000));
     165  CPPUNIT_ASSERT(s2.isInside(v100));
     166  CPPUNIT_ASSERT(!s2.isInside(v200));
     167  CPPUNIT_ASSERT(s2.isInside(v010));
     168  CPPUNIT_ASSERT(s2.isInside(v110));
     169  CPPUNIT_ASSERT(!s2.isInside(v210));
     170  CPPUNIT_ASSERT(!s2.isInside(v020));
     171  CPPUNIT_ASSERT(!s2.isInside(v120));
     172  CPPUNIT_ASSERT(!s2.isInside(v220));
     173  CPPUNIT_ASSERT(s2.isInside(v001));
     174  CPPUNIT_ASSERT(s2.isInside(v101));
     175  CPPUNIT_ASSERT(!s2.isInside(v201));
     176  CPPUNIT_ASSERT(s2.isInside(v011));
     177  CPPUNIT_ASSERT(s2.isInside(v111));
     178  CPPUNIT_ASSERT(!s2.isInside(v211));
     179  CPPUNIT_ASSERT(!s2.isInside(v021));
     180  CPPUNIT_ASSERT(!s2.isInside(v121));
     181  CPPUNIT_ASSERT(!s2.isInside(v221));
     182  CPPUNIT_ASSERT(!s2.isInside(v002));
     183  CPPUNIT_ASSERT(!s2.isInside(v102));
     184  CPPUNIT_ASSERT(!s2.isInside(v202));
     185  CPPUNIT_ASSERT(!s2.isInside(v012));
     186  CPPUNIT_ASSERT(!s2.isInside(v112));
     187  CPPUNIT_ASSERT(!s2.isInside(v212));
     188  CPPUNIT_ASSERT(!s2.isInside(v022));
     189  CPPUNIT_ASSERT(!s2.isInside(v122));
     190  CPPUNIT_ASSERT(!s2.isInside(v222));
     191}
     192
     193void ShapeUnittest::surfaceTest(){
     194  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v000));
     195  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v100));
     196  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v200));
     197  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v010));
     198  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v110));
     199  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v210));
     200  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v020));
     201  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v120));
     202  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v220));
     203  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v001));
     204  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v101));
     205  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v201));
     206  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v011));
     207  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v111));
     208  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v211));
     209  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v021));
     210  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v121));
     211  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v221));
     212  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v002));
     213  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v102));
     214  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v202));
     215  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v012));
     216  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v112));
     217  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v212));
     218  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v022));
     219  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v122));
     220  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v222));
     221
     222  CPPUNIT_ASSERT(Cuboid().isOnSurface(v000));
     223  CPPUNIT_ASSERT(Cuboid().isOnSurface(v100));
     224  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v200));
     225  CPPUNIT_ASSERT(Cuboid().isOnSurface(v010));
     226  CPPUNIT_ASSERT(Cuboid().isOnSurface(v110));
     227  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v210));
     228  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v020));
     229  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v120));
     230  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v220));
     231  CPPUNIT_ASSERT(Cuboid().isOnSurface(v001));
     232  CPPUNIT_ASSERT(Cuboid().isOnSurface(v101));
     233  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v201));
     234  CPPUNIT_ASSERT(Cuboid().isOnSurface(v011));
     235  CPPUNIT_ASSERT(Cuboid().isOnSurface(v111));
     236  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v211));
     237  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v021));
     238  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v121));
     239  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v221));
     240  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v002));
     241  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v102));
     242  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v202));
     243  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v012));
     244  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v112));
     245  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v212));
     246  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v022));
     247  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v122));
     248  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v222));
     249
     250  CPPUNIT_ASSERT(!Sphere().isOnSurface(v000));
     251  CPPUNIT_ASSERT(Sphere().isOnSurface(v100));
     252  CPPUNIT_ASSERT(Sphere().isOnSurface(v200));
     253  CPPUNIT_ASSERT(Sphere().isOnSurface(v010));
     254  CPPUNIT_ASSERT(!Sphere().isOnSurface(v110));
     255  CPPUNIT_ASSERT(!Sphere().isOnSurface(v210));
     256  CPPUNIT_ASSERT(Sphere().isOnSurface(v020));
     257  CPPUNIT_ASSERT(!Sphere().isOnSurface(v120));
     258  CPPUNIT_ASSERT(!Sphere().isOnSurface(v220));
     259  CPPUNIT_ASSERT(Sphere().isOnSurface(v001));
     260  CPPUNIT_ASSERT(!Sphere().isOnSurface(v101));
     261  CPPUNIT_ASSERT(!Sphere().isOnSurface(v201));
     262  CPPUNIT_ASSERT(!Sphere().isOnSurface(v011));
     263  CPPUNIT_ASSERT(!Sphere().isOnSurface(v111));
     264  CPPUNIT_ASSERT(!Sphere().isOnSurface(v211));
     265  CPPUNIT_ASSERT(!Sphere().isOnSurface(v021));
     266  CPPUNIT_ASSERT(!Sphere().isOnSurface(v121));
     267  CPPUNIT_ASSERT(!Sphere().isOnSurface(v221));
     268  CPPUNIT_ASSERT(Sphere().isOnSurface(v002));
     269  CPPUNIT_ASSERT(!Sphere().isOnSurface(v102));
     270  CPPUNIT_ASSERT(!Sphere().isOnSurface(v202));
     271  CPPUNIT_ASSERT(!Sphere().isOnSurface(v012));
     272  CPPUNIT_ASSERT(!Sphere().isOnSurface(v112));
     273  CPPUNIT_ASSERT(!Sphere().isOnSurface(v212));
     274  CPPUNIT_ASSERT(!Sphere().isOnSurface(v022));
     275  CPPUNIT_ASSERT(!Sphere().isOnSurface(v122));
     276  CPPUNIT_ASSERT(!Sphere().isOnSurface(v222));
    131277}
    132278
     
    377523  }
    378524
     525  {
     526    Shape s1 = Sphere() && Cuboid(); // Sphere in upper place
     527
     528    CPPUNIT_ASSERT(s1.isInside(v000));
     529    CPPUNIT_ASSERT(s1.isInside(v100));
     530    CPPUNIT_ASSERT(!s1.isInside(v200));
     531    CPPUNIT_ASSERT(s1.isInside(v010));
     532    CPPUNIT_ASSERT(!s1.isInside(v110));
     533    CPPUNIT_ASSERT(!s1.isInside(v210));
     534    CPPUNIT_ASSERT(!s1.isInside(v020));
     535    CPPUNIT_ASSERT(!s1.isInside(v120));
     536    CPPUNIT_ASSERT(!s1.isInside(v220));
     537    CPPUNIT_ASSERT(s1.isInside(v001));
     538    CPPUNIT_ASSERT(!s1.isInside(v101));
     539    CPPUNIT_ASSERT(!s1.isInside(v201));
     540    CPPUNIT_ASSERT(!s1.isInside(v011));
     541    CPPUNIT_ASSERT(!s1.isInside(v111));
     542    CPPUNIT_ASSERT(!s1.isInside(v211));
     543    CPPUNIT_ASSERT(!s1.isInside(v021));
     544    CPPUNIT_ASSERT(!s1.isInside(v121));
     545    CPPUNIT_ASSERT(!s1.isInside(v221));
     546    CPPUNIT_ASSERT(!s1.isInside(v002));
     547    CPPUNIT_ASSERT(!s1.isInside(v102));
     548    CPPUNIT_ASSERT(!s1.isInside(v202));
     549    CPPUNIT_ASSERT(!s1.isInside(v012));
     550    CPPUNIT_ASSERT(!s1.isInside(v112));
     551    CPPUNIT_ASSERT(!s1.isInside(v212));
     552    CPPUNIT_ASSERT(!s1.isInside(v022));
     553    CPPUNIT_ASSERT(!s1.isInside(v122));
     554    CPPUNIT_ASSERT(!s1.isInside(v222));
     555
     556    CPPUNIT_ASSERT(s1.isOnSurface(v000));
     557    CPPUNIT_ASSERT(s1.isOnSurface(v100));
     558    CPPUNIT_ASSERT(!s1.isOnSurface(v200));
     559    CPPUNIT_ASSERT(s1.isOnSurface(v010));
     560    CPPUNIT_ASSERT(!s1.isOnSurface(v110));
     561    CPPUNIT_ASSERT(!s1.isOnSurface(v210));
     562    CPPUNIT_ASSERT(!s1.isOnSurface(v020));
     563    CPPUNIT_ASSERT(!s1.isOnSurface(v120));
     564    CPPUNIT_ASSERT(!s1.isOnSurface(v220));
     565    CPPUNIT_ASSERT(s1.isOnSurface(v001));
     566    CPPUNIT_ASSERT(!s1.isOnSurface(v101));
     567    CPPUNIT_ASSERT(!s1.isOnSurface(v201));
     568    CPPUNIT_ASSERT(!s1.isOnSurface(v011));
     569    CPPUNIT_ASSERT(!s1.isOnSurface(v111));
     570    CPPUNIT_ASSERT(!s1.isOnSurface(v211));
     571    CPPUNIT_ASSERT(!s1.isOnSurface(v021));
     572    CPPUNIT_ASSERT(!s1.isOnSurface(v121));
     573    CPPUNIT_ASSERT(!s1.isOnSurface(v221));
     574    CPPUNIT_ASSERT(!s1.isOnSurface(v002));
     575    CPPUNIT_ASSERT(!s1.isOnSurface(v102));
     576    CPPUNIT_ASSERT(!s1.isOnSurface(v202));
     577    CPPUNIT_ASSERT(!s1.isOnSurface(v012));
     578    CPPUNIT_ASSERT(!s1.isOnSurface(v112));
     579    CPPUNIT_ASSERT(!s1.isOnSurface(v212));
     580    CPPUNIT_ASSERT(!s1.isOnSurface(v022));
     581    CPPUNIT_ASSERT(!s1.isOnSurface(v122));
     582    CPPUNIT_ASSERT(!s1.isOnSurface(v222));
     583
     584
     585    Shape s2 = Sphere() || Cuboid(); // Should be same as Cuboid
     586
     587    CPPUNIT_ASSERT(s2.isInside(v000));
     588    CPPUNIT_ASSERT(s2.isInside(v100));
     589    CPPUNIT_ASSERT(s2.isInside(v200));
     590    CPPUNIT_ASSERT(s2.isInside(v010));
     591    CPPUNIT_ASSERT(s2.isInside(v110));
     592    CPPUNIT_ASSERT(!s2.isInside(v210));
     593    CPPUNIT_ASSERT(s2.isInside(v020));
     594    CPPUNIT_ASSERT(!s2.isInside(v120));
     595    CPPUNIT_ASSERT(!s2.isInside(v220));
     596    CPPUNIT_ASSERT(s2.isInside(v001));
     597    CPPUNIT_ASSERT(s2.isInside(v101));
     598    CPPUNIT_ASSERT(!s2.isInside(v201));
     599    CPPUNIT_ASSERT(s2.isInside(v011));
     600    CPPUNIT_ASSERT(s2.isInside(v111));
     601    CPPUNIT_ASSERT(!s2.isInside(v211));
     602    CPPUNIT_ASSERT(!s2.isInside(v021));
     603    CPPUNIT_ASSERT(!s2.isInside(v121));
     604    CPPUNIT_ASSERT(!s2.isInside(v221));
     605    CPPUNIT_ASSERT(s2.isInside(v002));
     606    CPPUNIT_ASSERT(!s2.isInside(v102));
     607    CPPUNIT_ASSERT(!s2.isInside(v202));
     608    CPPUNIT_ASSERT(!s2.isInside(v012));
     609    CPPUNIT_ASSERT(!s2.isInside(v112));
     610    CPPUNIT_ASSERT(!s2.isInside(v212));
     611    CPPUNIT_ASSERT(!s2.isInside(v022));
     612    CPPUNIT_ASSERT(!s2.isInside(v122));
     613    CPPUNIT_ASSERT(!s2.isInside(v222));
     614
     615    CPPUNIT_ASSERT(!s2.isOnSurface(v000));
     616    CPPUNIT_ASSERT(s2.isOnSurface(v100));
     617    CPPUNIT_ASSERT(s2.isOnSurface(v200));
     618    CPPUNIT_ASSERT(s2.isOnSurface(v010));
     619    CPPUNIT_ASSERT(s2.isOnSurface(v110));
     620    CPPUNIT_ASSERT(!s2.isOnSurface(v210));
     621    CPPUNIT_ASSERT(s2.isOnSurface(v020));
     622    CPPUNIT_ASSERT(!s2.isOnSurface(v120));
     623    CPPUNIT_ASSERT(!s2.isOnSurface(v220));
     624    CPPUNIT_ASSERT(s2.isOnSurface(v001));
     625    CPPUNIT_ASSERT(s2.isOnSurface(v101));
     626    CPPUNIT_ASSERT(!s2.isOnSurface(v201));
     627    CPPUNIT_ASSERT(s2.isOnSurface(v011));
     628    CPPUNIT_ASSERT(s2.isOnSurface(v111));
     629    CPPUNIT_ASSERT(!s2.isOnSurface(v211));
     630    CPPUNIT_ASSERT(!s2.isOnSurface(v021));
     631    CPPUNIT_ASSERT(!s2.isOnSurface(v121));
     632    CPPUNIT_ASSERT(!s2.isOnSurface(v221));
     633    CPPUNIT_ASSERT(s2.isOnSurface(v002));
     634    CPPUNIT_ASSERT(!s2.isOnSurface(v102));
     635    CPPUNIT_ASSERT(!s2.isOnSurface(v202));
     636    CPPUNIT_ASSERT(!s2.isOnSurface(v012));
     637    CPPUNIT_ASSERT(!s2.isOnSurface(v112));
     638    CPPUNIT_ASSERT(!s2.isOnSurface(v212));
     639    CPPUNIT_ASSERT(!s2.isOnSurface(v022));
     640    CPPUNIT_ASSERT(!s2.isOnSurface(v122));
     641    CPPUNIT_ASSERT(!s2.isOnSurface(v222));
     642  }
     643
    379644}
     645
     646void ShapeUnittest::PointsOnSurfaceTest(){
     647  Shape s = Sphere();
     648  const size_t N = 200;
     649  std::vector<Vector> PointsOnSurface = s.getHomogeneousPointsOnSurface(N);
     650  for (std::vector<Vector>::const_iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) {
     651    CPPUNIT_ASSERT(fabs(1. - (*iter).NormSquared()) < MYEPSILON);
     652  }
     653  CPPUNIT_ASSERT_EQUAL(N, PointsOnSurface.size());
     654}
     655
  • src/unittests/ShapeUnittest.hpp

    rfd4905 r6c438f  
    2020  CPPUNIT_TEST_SUITE( ShapeUnittest) ;
    2121  CPPUNIT_TEST ( baseShapesTest );
     22  CPPUNIT_TEST ( surfaceTest );
    2223  CPPUNIT_TEST ( assignmentTest );
    2324  CPPUNIT_TEST ( operatorTest );
     25  CPPUNIT_TEST ( PointsOnSurfaceTest );
    2426  CPPUNIT_TEST_SUITE_END();
    2527
     
    2931
    3032  void baseShapesTest();
     33  void surfaceTest();
    3134  void assignmentTest();
    3235  void operatorTest();
     36  void PointsOnSurfaceTest();
    3337
    3438  // a lot of vectors.
Note: See TracChangeset for help on using the changeset viewer.