Changes in / [fd4905:6c438f]
- Location:
- src
- Files:
-
- 8 added
- 2 deleted
- 31 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Box.cpp
rfd4905 r6c438f 29 29 #include "LinearAlgebra/Vector.hpp" 30 30 #include "LinearAlgebra/Plane.hpp" 31 #include "Shapes/BaseShapes.hpp" 32 #include "Shapes/ShapeOps.hpp" 31 33 32 34 #include "Helpers/Assert.hpp" … … 218 220 } 219 221 222 Shape Box::getShape() const{ 223 return transform(Cuboid(Vector(0,0,0),Vector(1,1,1)),(*M)); 224 } 225 220 226 const Box::Conditions_t Box::getConditions(){ 221 227 return conditions; -
src/Box.hpp
rfd4905 r6c438f 11 11 class Matrix; 12 12 class Vector; 13 class Shape; 13 14 class Plane; 14 15 … … 99 100 double periodicDistance(const Vector &point1,const Vector &point2) const; 100 101 102 Shape getShape() const; 101 103 const Conditions_t getConditions(); 102 104 void setCondition(int,BoundaryCondition_t); -
src/Descriptors/AtomShapeDescriptor.cpp
rfd4905 r6c438f 9 9 * AtomShapeDescriptor.cpp 10 10 * 11 * Created on: Aug 9, 201012 * Author: heber11 * Created on: Jul 22, 2010 12 * Author: crueger 13 13 */ 14 14 … … 24 24 25 25 #include "atom.hpp" 26 #include "Patterns/ObservedContainer_impl.hpp"27 #include "Shapes/Shape.hpp"28 26 29 using namespace std; 30 31 32 AtomShapeDescriptor_impl::AtomShapeDescriptor_impl(Shape _shape) : 27 AtomShapeDescriptor_impl::AtomShapeDescriptor_impl(const Shape &_shape) : 33 28 shape(_shape) 34 29 {} 35 30 36 AtomShapeDescriptor_impl::~AtomShapeDescriptor_impl() 37 {} 31 AtomShapeDescriptor_impl::~AtomShapeDescriptor_impl(){} 38 32 39 bool AtomShapeDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom) 33 bool AtomShapeDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom){ 40 34 return shape.isInside(atom.second->getPosition()); 41 35 } 42 36 43 AtomDescriptor AtomByShape(Shape &_shape){ 44 return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomShapeDescriptor_impl(_shape))); 37 38 AtomDescriptor AtomByShape(const Shape &shape){ 39 return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomShapeDescriptor_impl(shape))); 45 40 } -
src/Descriptors/AtomShapeDescriptor.hpp
rfd4905 r6c438f 2 2 * AtomShapeDescriptor.hpp 3 3 * 4 * Created on: Aug 9, 20105 * Author: heber4 * Created on: Jul 22, 2010 5 * Author: crueger 6 6 */ 7 7 … … 14 14 class Shape; 15 15 16 AtomDescriptor AtomByShape( Shape &_shape);16 AtomDescriptor AtomByShape(const Shape &shape); 17 17 18 18 #endif /* ATOMSHAPEDESCRIPTOR_HPP_ */ -
src/Descriptors/AtomShapeDescriptor_impl.hpp
rfd4905 r6c438f 2 2 * AtomShapeDescriptor_impl.hpp 3 3 * 4 * Created on: Aug 9, 20105 * Author: heber4 * Created on: Jul 22, 2010 5 * Author: crueger 6 6 */ 7 7 8 #ifndef ATOMSHAPEDESCRIPTOR_IMPL_HPP 9 #define ATOMSHAPEDESCRIPTOR_IMPL_HPP 8 #ifndef ATOMSHAPEDESCRIPTOR_IMPL_HPP_ 9 #define ATOMSHAPEDESCRIPTOR_IMPL_HPP_ 10 10 11 11 #include "Descriptors/AtomDescriptor_impl.hpp" 12 12 13 #include "Shapes/Shape.hpp" 13 14 … … 15 16 { 16 17 public: 17 AtomShapeDescriptor_impl( Shape _shape);18 virtual ~AtomShapeDescriptor_impl();18 AtomShapeDescriptor_impl(const Shape&); 19 virtual ~AtomShapeDescriptor_impl(); 19 20 20 21 bool predicate(std::pair<atomId_t,atom*> atom); 21 22 22 private: 23 23 Shape shape; 24 24 }; 25 25 26 #endif / /ATOMSHAPEDESCRIPTOR_IMPL_HPP26 #endif /* ATOMSHAPEDESCRIPTOR_IMPL_HPP_ */ -
src/Exceptions/Makefile.am
rfd4905 r6c438f 15 15 MissingValueException.cpp \ 16 16 NotInvertibleException.cpp \ 17 NotOnSurfaceException.cpp \ 18 ShapeException.cpp \ 17 19 ParseError.cpp \ 18 20 SkewException.cpp \ 19 21 ZeroVectorException.cpp 22 20 23 21 24 EXCEPTIONHEADER = \ … … 26 29 MissingValueException.hpp \ 27 30 NotInvertibleException.hpp \ 31 NotInvertibleException.hpp \ 32 NotOnSurfaceException.hpp \ 28 33 ParseError.hpp \ 29 34 SkewException.hpp \ -
src/Helpers/helpers.cpp
rfd4905 r6c438f 153 153 exit(255); 154 154 } 155 156 sign_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 43 43 const char *file, const int line); 44 44 //__attribute__ ((__return__)); 45 46 typedef enum { 47 Minus = -1, 48 Zero = 0, 49 Plus = +1 50 } sign_t; 45 51 46 52 double ask_value(const char *text); … … 52 58 int CompareDoubles (const void * a, const void * b); 53 59 void performCriticalExit(); 60 sign_t sign(double value); 54 61 55 62 /********************************************** helpful template functions *********************************/ -
src/LinearAlgebra/Line.cpp
rfd4905 r6c438f 50 50 Line::~Line() 51 51 {} 52 53 Line &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 } 52 60 53 61 … … 224 232 } 225 233 234 Line 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 252 Plane 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 226 261 Plane Line::getOrthogonalPlane(const Vector &origin) const{ 227 262 return Plane(getDirection(),origin); … … 247 282 } 248 283 284 LinePoint 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 291 LinePoint Line::posEndpoint() const{ 292 return LinePoint(*this, numeric_limits<double>::infinity()); 293 } 294 LinePoint Line::negEndpoint() const{ 295 return LinePoint(*this,-numeric_limits<double>::infinity()); 296 } 297 298 bool operator==(const Line &x,const Line &y){ 299 return *x.origin == *y.origin && *x.direction == *y.direction; 300 } 301 249 302 Line makeLineThrough(const Vector &x1, const Vector &x2){ 250 303 if(x1==x2){ … … 252 305 } 253 306 return Line(x1,x1-x2); 307 } 308 309 /******************************** Points on the line ********************/ 310 311 LinePoint::LinePoint(const LinePoint &src) : 312 line(src.line),param(src.param) 313 {} 314 315 LinePoint::LinePoint(const Line &_line, double _param) : 316 line(_line),param(_param) 317 {} 318 319 LinePoint& LinePoint::operator=(const LinePoint &src){ 320 line=src.line; 321 param=src.param; 322 return *this; 323 } 324 325 Vector LinePoint::getPoint() const{ 326 ASSERT(!isInfinite(),"getPoint() on infinite LinePoint called"); 327 return (*line.origin)+param*(*line.direction); 328 } 329 330 Line LinePoint::getLine() const{ 331 return line; 332 } 333 334 bool LinePoint::isInfinite() const{ 335 return isPosInfinity() || isNegInfinity(); 336 } 337 bool LinePoint::isPosInfinity() const{ 338 return param == numeric_limits<double>::infinity(); 339 } 340 bool LinePoint::isNegInfinity() const{ 341 return param ==-numeric_limits<double>::infinity(); 342 } 343 344 bool 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 } 349 bool 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; 254 352 } 255 353 -
src/LinearAlgebra/Line.hpp
rfd4905 r6c438f 17 17 class Vector; 18 18 class Plane; 19 class LinePoint; 19 20 20 21 class Line : public Space 21 22 { 23 friend bool operator==(const Line&,const Line&); 24 friend class LinePoint; 22 25 public: 23 26 Line(const Vector &_origin, const Vector &_direction); 24 27 Line(const Line& _src); 25 28 virtual ~Line(); 29 30 Line &operator=(const Line& rhs); 26 31 27 32 virtual double distance(const Vector &point) const; … … 36 41 37 42 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; 38 45 39 46 Plane getOrthogonalPlane(const Vector &origin) const; … … 41 48 std::vector<Vector> getSphereIntersections() const; 42 49 50 LinePoint getLinePoint(const Vector&) const; 51 LinePoint posEndpoint() const; 52 LinePoint negEndpoint() const; 53 54 55 43 56 private: 44 57 std::auto_ptr<Vector> origin; 45 58 std::auto_ptr<Vector> direction; 46 59 }; 60 61 bool operator==(const Line&,const Line&); 47 62 48 63 std::ostream & operator << (std::ostream& ost, const Line &m); … … 53 68 Line makeLineThrough(const Vector &x1, const Vector &x2); 54 69 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 */ 75 class LinePoint{ 76 friend class Line; 77 friend bool operator==(const LinePoint&, const LinePoint&); 78 friend bool operator<(const LinePoint&, const LinePoint&); 79 public: 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 88 private: 89 LinePoint(const Line&,double); 90 Line line; 91 double param; 92 }; 93 94 bool operator==(const LinePoint&, const LinePoint&); 95 bool operator<(const LinePoint&, const LinePoint&); 96 97 inline bool operator!= (const LinePoint& x, const LinePoint& y) { return !(x==y); } 98 inline bool operator> (const LinePoint& x, const LinePoint& y) { return y<x; } 99 inline bool operator<= (const LinePoint& x, const LinePoint& y) { return !(y<x); } 100 inline bool operator>= (const LinePoint& x, const LinePoint& y) { return !(x<y); } 101 102 55 103 #endif /* LINE_HPP_ */ -
src/LinearAlgebra/Makefile.am
rfd4905 r6c438f 14 14 gslvector.cpp \ 15 15 Line.cpp \ 16 LineSegment.cpp \ 17 LineSegmentSet.cpp \ 16 18 linearsystemofequations.cpp \ 17 19 Matrix.cpp \ … … 27 29 gslvector.hpp \ 28 30 Line.hpp \ 31 LineSegment.hpp \ 32 LineSegmentSet.hpp \ 29 33 linearsystemofequations.hpp \ 30 34 Matrix.hpp \ -
src/LinearAlgebra/Matrix.cpp
rfd4905 r6c438f 230 230 - at(2,1)*at(1,2)*at(0,0) 231 231 - at(2,2)*at(1,0)*at(0,1); 232 }233 234 Matrix Matrix::transpose() const235 {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;252 232 } 253 233 … … 273 253 } 274 254 255 Matrix 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 263 Matrix &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 275 276 Vector Matrix::transformToEigenbasis() 276 277 { -
src/LinearAlgebra/Plane.cpp
rfd4905 r6c438f 27 27 #include "Helpers/Verbose.hpp" 28 28 #include "Helpers/Assert.hpp" 29 #include "Helpers/helpers.hpp" 29 30 #include <cmath> 30 31 #include "LinearAlgebra/Line.hpp" … … 118 119 Plane::~Plane() 119 120 {} 121 122 Plane &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 } 120 129 121 130 … … 200 209 } 201 210 211 bool Plane::onSameSide(const Vector &point1,const Vector &point2) const{ 212 return sign(point1.ScalarProduct(*normalVector)-offset) == 213 sign(point2.ScalarProduct(*normalVector)-offset); 214 } 215 202 216 /************ Methods inherited from Space ****************/ 203 217 … … 219 233 // Operators 220 234 235 bool operator==(const Plane &x,const Plane &y){ 236 return *x.normalVector == *y.normalVector && x.offset == y.offset; 237 } 238 221 239 ostream &operator << (ostream &ost,const Plane &p){ 222 240 ost << "<" << p.getNormal() << ";x> - " << p.getOffset() << "=0"; -
src/LinearAlgebra/Plane.hpp
rfd4905 r6c438f 21 21 class Plane : public Space 22 22 { 23 friend bool operator==(const Plane&,const Plane&); 23 24 typedef std::auto_ptr<Vector> vec_ptr; 24 25 public: … … 29 30 Plane(const Plane& plane); 30 31 virtual ~Plane(); 32 33 Plane &operator=(const Plane&); 31 34 32 35 // Accessor Functions … … 63 66 Line getOrthogonalLine(const Vector &origin) const; 64 67 68 /** 69 * Test if two points are on the same side of the plane 70 */ 71 bool onSameSide(const Vector&,const Vector&) const; 72 65 73 /****** Methods inherited from Space ***********/ 66 74 … … 73 81 }; 74 82 83 bool operator==(const Plane&,const Plane&); 84 75 85 std::ostream &operator<< (std::ostream &ost,const Plane& p); 76 86 -
src/LinearAlgebra/Vector.cpp
rfd4905 r6c438f 237 237 (*this) *= 1/factor; 238 238 }; 239 240 Vector Vector::getNormalized() const{ 241 Vector res= *this; 242 res.Normalize(); 243 return res; 244 } 239 245 240 246 /** Zeros all components of this vector. … … 578 584 // some comonly used vectors 579 585 const 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); 586 const Vector unitVec[NDIM]={Vector(1,0,0),Vector(0,1,0),Vector(0,0,1)}; -
src/LinearAlgebra/Vector.hpp
rfd4905 r6c438f 83 83 double NormSquared() const; 84 84 void Normalize(); 85 Vector getNormalized() const; 85 86 void Zero(); 86 87 void One(const double one); … … 109 110 // some commonly used and fixed vectors 110 111 const extern Vector zeroVec; 111 const extern Vector e1; 112 const extern Vector e2; 113 const extern Vector e3; 112 const extern Vector unitVec[NDIM]; 114 113 115 114 ostream & operator << (ostream& ost, const Vector &m); -
src/Makefile.am
rfd4905 r6c438f 58 58 Actions/MethodAction.hpp \ 59 59 Actions/Process.hpp 60 60 61 61 62 PATTERNSOURCE = \ … … 227 228 lists.hpp \ 228 229 molecule.hpp \ 229 molecule_template.hpp \230 230 parser.hpp \ 231 231 periodentafel.hpp \ -
src/Shapes/BaseShapes.cpp
rfd4905 r6c438f 22 22 #include "Shapes/BaseShapes.hpp" 23 23 #include "Shapes/BaseShapes_impl.hpp" 24 25 #include <cmath> 24 #include "Shapes/ShapeOps.hpp" 25 26 #include "defs.hpp" 26 27 27 28 #include "Helpers/Assert.hpp" 28 29 #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> 29 37 30 38 bool Sphere_impl::isInside(const Vector &point){ … … 32 40 } 33 41 42 bool Sphere_impl::isOnSurface(const Vector &point){ 43 return fabs(point.NormSquared()-1)<MYEPSILON; 44 } 45 46 Vector Sphere_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){ 47 if(!isOnSurface(point)){ 48 throw NotOnSurfaceException(__FILE__,__LINE__); 49 } 50 return point; 51 } 52 53 LineSegmentSet 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 62 string Sphere_impl::toString(){ 63 return "Sphere()"; 64 } 34 65 35 66 /** … … 66 97 } 67 98 99 Shape Sphere(const Vector ¢er,double radius){ 100 return translate(resize(Sphere(),radius),center); 101 } 102 103 Shape Ellipsoid(const Vector ¢er, const Vector &radius){ 104 return translate(stretch(Sphere(),radius),center); 105 } 106 68 107 bool Cuboid_impl::isInside(const Vector &point){ 69 108 return (point[0]>=0 && point[0]<=1) && (point[1]>=0 && point[1]<=1) && (point[2]>=0 && point[2]<=1); 109 } 110 111 bool 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 122 Vector 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 140 LineSegmentSet 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 170 string Cuboid_impl::toString(){ 171 return "Cuboid()"; 70 172 } 71 173 … … 83 185 return Shape(impl); 84 186 } 187 188 Shape 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 12 12 13 13 Shape Sphere(); 14 Shape Sphere(const Vector ¢er,double radius); 15 Shape Ellipsoid(const Vector ¢er, const Vector &radius); 14 16 Shape Cuboid(); 17 Shape Cuboid(const Vector &corner1, const Vector &corner2); 15 18 16 19 #endif /* BASESHAPES_HPP_ */ -
src/Shapes/BaseShapes_impl.hpp
rfd4905 r6c438f 9 9 #define BASESHAPES_IMPL_HPP_ 10 10 11 class Vector; 12 class LineSegmentSet; 13 11 14 #include "Shapes/Shape_impl.hpp" 12 15 13 16 class Sphere_impl : public Shape_impl { 14 17 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(); 15 22 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 16 23 }; … … 18 25 class Cuboid_impl : public Shape_impl { 19 26 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(); 20 31 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 21 32 }; -
src/Shapes/Shape.cpp
rfd4905 r6c438f 20 20 #include "Helpers/MemDebug.hpp" 21 21 22 #include "Helpers/Assert.hpp" 23 #include "LinearAlgebra/Vector.hpp" 24 22 25 #include "Shape.hpp" 23 26 #include "Shape_impl.hpp" 24 27 25 26 #include "Helpers/Assert.hpp" 27 #include "LinearAlgebra/Vector.hpp" 28 #include <string> 29 28 30 29 31 Shape::Shape(const Shape& src) : … … 35 37 bool Shape::isInside(const Vector &point) const{ 36 38 return impl->isInside(point); 39 } 40 41 bool Shape::isOnSurface(const Vector &point) const{ 42 return impl->isOnSurface(point); 43 } 44 45 Vector Shape::getNormal(const Vector &point) const throw (NotOnSurfaceException){ 46 return impl->getNormal(point); 47 } 48 49 LineSegmentSet Shape::getLineIntersections(const Line &line){ 50 return impl->getLineIntersections(line); 37 51 } 38 52 … … 52 66 } 53 67 68 std::string Shape::toString() const{ 69 return impl->toString(); 70 } 71 54 72 Shape::impl_ptr Shape::getImpl() const{ 55 73 return impl; … … 85 103 bool AndShape_impl::isInside(const Vector &point){ 86 104 return lhs->isInside(point) && rhs->isInside(point); 105 } 106 107 bool 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 139 Vector 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 150 LineSegmentSet AndShape_impl::getLineIntersections(const Line &line){ 151 return intersect(lhs->getLineIntersections(line),rhs->getLineIntersections(line)); 152 } 153 154 string AndShape_impl::toString(){ 155 return string("(") + lhs->toString() + string("&&") + rhs->toString() + string(")"); 87 156 } 88 157 … … 122 191 } 123 192 193 bool 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 225 Vector 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 236 LineSegmentSet OrShape_impl::getLineIntersections(const Line &line){ 237 return merge(lhs->getLineIntersections(line),rhs->getLineIntersections(line)); 238 } 239 240 string OrShape_impl::toString(){ 241 return string("(") + lhs->toString() + string("||") + rhs->toString() + string(")"); 242 } 243 124 244 std::vector<Vector> OrShape_impl::getHomogeneousPointsOnSurface(const size_t N) const { 125 245 std::vector<Vector> PointsOnSurface_lhs = lhs->getHomogeneousPointsOnSurface(N); … … 156 276 } 157 277 278 bool NotShape_impl::isOnSurface(const Vector &point){ 279 return arg->isOnSurface(point); 280 } 281 282 Vector NotShape_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){ 283 return -1*arg->getNormal(point); 284 } 285 286 LineSegmentSet NotShape_impl::getLineIntersections(const Line &line){ 287 return invert(arg->getLineIntersections(line)); 288 } 289 290 string NotShape_impl::toString(){ 291 return string("!") + arg->toString(); 292 } 293 158 294 std::vector<Vector> NotShape_impl::getHomogeneousPointsOnSurface(const size_t N) const { 159 295 // surfaces are the same, only normal direction is different … … 165 301 return Shape(newImpl); 166 302 } 303 304 /**************** global operations *********************************/ 305 ostream &operator<<(ostream &ost,const Shape &shape){ 306 ost << shape.toString(); 307 return ost; 308 } -
src/Shapes/Shape.hpp
rfd4905 r6c438f 10 10 11 11 #include <boost/shared_ptr.hpp> 12 #include <iosfwd> 13 14 #include "Exceptions/NotOnSurfaceException.hpp" 12 15 13 16 #include <vector> … … 15 18 class Vector; 16 19 class Shape_impl; 20 class LineSegmentSet; 21 class Line; 17 22 18 23 class Shape … … 27 32 28 33 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&); 29 38 std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 30 39 31 40 Shape &operator=(const Shape& rhs); 32 41 42 std::string toString() const; 33 43 protected: 34 44 impl_ptr getImpl() const; … … 45 55 Shape operator!(const Shape&); 46 56 57 std::ostream &operator<<(std::ostream&,const Shape&); 58 47 59 #endif /* SHAPE_HPP_ */ -
src/Shapes/ShapeOps.cpp
rfd4905 r6c438f 23 23 #include "Shapes/ShapeOps_impl.hpp" 24 24 25 #include "LinearAlgebra/Vector.hpp" 25 26 #include "Helpers/Assert.hpp" 26 27 28 /*************** Base case ***********************/ 29 30 ShapeOpsBase_impl::ShapeOpsBase_impl(const Shape::impl_ptr &_arg) : 31 arg(_arg){} 32 33 ShapeOpsBase_impl::~ShapeOpsBase_impl(){} 34 35 bool ShapeOpsBase_impl::isInside(const Vector &point){ 36 return arg->isInside(translateIn(point)); 37 } 38 39 bool ShapeOpsBase_impl::isOnSurface(const Vector &point){ 40 return arg->isOnSurface(translateIn(point)); 41 } 42 43 Vector 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 53 LineSegmentSet 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 72 std::vector<Vector> ShapeOpsBase_impl::getHomogeneousPointsOnSurface(const size_t N) const { 73 return getArg()->getHomogeneousPointsOnSurface(N);; 74 } 75 76 Shape::impl_ptr ShapeOpsBase_impl::getArg() const{ 77 return arg; 78 } 79 27 80 /********************* Resize ********************/ 28 81 29 82 Resize_impl::Resize_impl(const Shape::impl_ptr &_arg,double _size) : 30 arg(_arg), size(_size)83 ShapeOpsBase_impl(_arg), size(_size) 31 84 { 32 85 ASSERT(size>0,"Cannot resize a Shape to size zero or below"); … … 36 89 37 90 bool Resize_impl::isInside(const Vector& point){ 38 return arg->isInside((1/size) * point); 91 return getArg()->isInside((1/size) * point); 92 } 93 94 Vector Resize_impl::translateIn(const Vector& point){ 95 return (1/size) * point; 96 } 97 98 Vector Resize_impl::translateOutPos(const Vector& point){ 99 return size * point; 100 } 101 102 Vector Resize_impl::translateOutNormal(const Vector& point){ 103 return point; 104 } 105 106 string Resize_impl::toString(){ 107 stringstream sstr; 108 sstr << "resize(" << getArg()->toString() << "," << size << ")"; 109 return sstr.str(); 39 110 } 40 111 41 112 std::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); 43 114 for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) { 44 115 *iter *= size; … … 56 127 57 128 Translate_impl::Translate_impl(const Shape::impl_ptr &_arg, const Vector &_offset) : 58 arg(_arg),offset(_offset)129 ShapeOpsBase_impl(_arg),offset(_offset) 59 130 {} 60 131 … … 62 133 63 134 bool Translate_impl::isInside(const Vector& point){ 64 return arg->isInside(point-offset); 135 return getArg()->isInside(point-offset); 136 } 137 138 Vector Translate_impl::translateIn(const Vector& point){ 139 return point-offset; 140 } 141 142 Vector Translate_impl::translateOutPos(const Vector& point){ 143 return point+offset; 144 } 145 146 Vector Translate_impl::translateOutNormal(const Vector& point){ 147 return point; 148 } 149 150 string Translate_impl::toString(){ 151 stringstream sstr; 152 sstr << "translate(" << getArg()->toString() << "," << offset << ")"; 153 return sstr.str(); 65 154 } 66 155 67 156 std::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); 69 158 for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) { 70 159 *iter += offset; … … 81 170 82 171 Stretch_impl::Stretch_impl(const Shape::impl_ptr &_arg, const Vector &_factors) : 83 arg(_arg),factors(_factors)172 ShapeOpsBase_impl(_arg),factors(_factors) 84 173 { 85 174 ASSERT(factors[0]>0,"cannot stretch a shape by a negative amount"); … … 96 185 Vector helper=point; 97 186 helper.ScaleAll(reciFactors); 98 return arg->isInside(helper); 187 return getArg()->isInside(helper); 188 } 189 190 Vector Stretch_impl::translateIn(const Vector& point){ 191 Vector helper=point; 192 helper.ScaleAll(reciFactors); 193 return helper; 194 } 195 196 Vector Stretch_impl::translateOutPos(const Vector& point){ 197 Vector helper=point; 198 helper.ScaleAll(factors); 199 return helper; 200 } 201 202 Vector 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 214 string Stretch_impl::toString(){ 215 stringstream sstr; 216 sstr << "stretch(" << getArg()->toString() << "," << factors << ")"; 217 return sstr.str(); 99 218 } 100 219 101 220 std::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); 103 222 for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) { 104 223 (*iter).ScaleAll(reciFactors); … … 115 234 116 235 Transform_impl::Transform_impl(const Shape::impl_ptr &_arg, const Matrix &_transformation) : 117 arg(_arg),transformation(_transformation)236 ShapeOpsBase_impl(_arg),transformation(_transformation) 118 237 { 119 238 transformationInv = transformation.invert(); … … 123 242 124 243 bool Transform_impl::isInside(const Vector& point){ 125 return arg->isInside(transformationInv * point); 244 return getArg()->isInside(transformationInv * point); 245 } 246 247 Vector Transform_impl::translateIn(const Vector& point){ 248 return transformationInv * point; 249 } 250 251 Vector Transform_impl::translateOutPos(const Vector& point){ 252 return transformation * point; 253 } 254 255 Vector Transform_impl::translateOutNormal(const Vector& point){ 256 Matrix mat = transformation.invert().transpose(); 257 return mat * point; 258 } 259 260 string Transform_impl::toString(){ 261 stringstream sstr; 262 sstr << "transform(" << getArg()->toString() << "," << transformation << ")"; 263 return sstr.str(); 126 264 } 127 265 128 266 std::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); 130 268 for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) { 131 269 *iter = transformation * (*iter); -
src/Shapes/ShapeOps_impl.hpp
rfd4905 r6c438f 13 13 #include "LinearAlgebra/Matrix.hpp" 14 14 15 class Resize_impl : public Shape_impl 15 #include <vector> 16 17 class LineSegment; 18 19 class ShapeOpsBase_impl : public Shape_impl{ 20 public: 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; 28 protected: 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; 33 private: 34 Shape::impl_ptr arg; 35 }; 36 37 class Resize_impl : public ShapeOpsBase_impl 16 38 { 17 39 public: 18 40 Resize_impl(const Shape::impl_ptr&,double); 19 41 virtual ~Resize_impl(); 42 protected: 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(); 20 47 virtual bool isInside(const Vector& point); 21 48 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 22 49 private: 23 Shape::impl_ptr arg;24 50 double size; 25 51 }; 26 52 27 class Translate_impl : public Shape _impl53 class Translate_impl : public ShapeOpsBase_impl 28 54 { 29 55 public: 30 56 Translate_impl(const Shape::impl_ptr&, const Vector&); 31 57 virtual ~Translate_impl(); 58 protected: 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(); 32 63 virtual bool isInside(const Vector& point); 33 64 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 34 65 private: 35 Shape::impl_ptr arg;36 66 Vector offset; 37 67 }; 38 68 39 class Stretch_impl : public Shape _impl69 class Stretch_impl : public ShapeOpsBase_impl 40 70 { 41 71 public: 42 72 Stretch_impl(const Shape::impl_ptr&, const Vector&); 43 73 virtual ~Stretch_impl(); 74 protected: 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(); 44 79 virtual bool isInside(const Vector& point); 45 80 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 46 81 private: 47 Shape::impl_ptr arg;48 82 Vector factors; 49 83 Vector reciFactors; 50 84 }; 51 85 52 class Transform_impl : public Shape _impl86 class Transform_impl : public ShapeOpsBase_impl 53 87 { 54 88 public: 55 89 Transform_impl(const Shape::impl_ptr&, const Matrix&); 56 90 virtual ~Transform_impl(); 91 protected: 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(); 57 96 virtual bool isInside(const Vector& point); 58 97 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 59 98 private: 60 Shape::impl_ptr arg;61 99 Matrix transformation; 62 100 Matrix transformationInv; -
src/Shapes/Shape_impl.hpp
rfd4905 r6c438f 12 12 13 13 #include "Shapes/Shape.hpp" 14 #include "LinearAlgebra/Line.hpp" 15 #include "LinearAlgebra/LineSegment.hpp" 16 #include "LinearAlgebra/LineSegmentSet.hpp" 17 #include "LinearAlgebra/Vector.hpp" 14 18 15 class Vector;16 19 17 20 class Shape_impl { … … 20 23 virtual ~Shape_impl(){}; 21 24 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; 22 29 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const=0; 23 30 }; … … 27 34 virtual bool isInside(const Vector &point){ 28 35 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()"; 29 50 } 30 51 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const { … … 37 58 virtual bool isInside(const Vector &point){ 38 59 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()"; 39 72 } 40 73 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const { … … 49 82 virtual ~AndShape_impl(); 50 83 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(); 51 88 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 52 89 private: … … 60 97 virtual ~OrShape_impl(); 61 98 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(); 62 103 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 63 104 private: … … 71 112 virtual ~NotShape_impl(); 72 113 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(); 73 118 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 74 119 private: -
src/unittests/LineUnittest.cpp
rfd4905 r6c438f 41 41 void LineUnittest::setUp(){ 42 42 // 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]); 46 46 47 47 // 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]); 51 51 } 52 52 void LineUnittest::tearDown(){ … … 64 64 65 65 // 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])); 69 69 70 70 // 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])); 74 74 // 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)); 78 78 // now we pass two times the same point 79 79 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); 83 83 84 84 } … … 90 90 void LineUnittest::constructionResultTest(){ 91 91 // 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])); 95 95 96 96 // test origins … … 104 104 CPPUNIT_ASSERT(la3->isContained(zeroVec)); 105 105 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])); 117 117 } 118 118 … … 124 124 125 125 // 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])); 137 137 138 138 // 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])); 146 146 147 147 // 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])); 159 159 160 160 // 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]))); 176 176 } 177 177 … … 189 189 // axes and plane lines 190 190 fixture = la1->getIntersection(*lp1); 191 CPPUNIT_ASSERT_EQUAL(fixture, e1);191 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]); 192 192 fixture = la2->getIntersection(*lp2); 193 CPPUNIT_ASSERT_EQUAL(fixture, e2);193 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]); 194 194 fixture = la3->getIntersection(*lp3); 195 CPPUNIT_ASSERT_EQUAL(fixture, e3);195 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]); 196 196 197 197 fixture = la1->getIntersection(*lp3); 198 CPPUNIT_ASSERT_EQUAL(fixture, e1);198 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]); 199 199 fixture = la2->getIntersection(*lp1); 200 CPPUNIT_ASSERT_EQUAL(fixture, e2);200 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]); 201 201 fixture = la3->getIntersection(*lp2); 202 CPPUNIT_ASSERT_EQUAL(fixture, e3);202 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]); 203 203 204 204 // two plane lines 205 205 fixture = lp1->getIntersection(*lp2); 206 CPPUNIT_ASSERT_EQUAL(fixture, e2);206 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]); 207 207 fixture = lp2->getIntersection(*lp3); 208 CPPUNIT_ASSERT_EQUAL(fixture, e3);208 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]); 209 209 fixture = lp3->getIntersection(*lp1); 210 CPPUNIT_ASSERT_EQUAL(fixture, e1);210 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]); 211 211 212 212 // When we have two times the same line, we check if the point is on the line … … 254 254 255 255 // 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]); 269 269 270 270 // 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]); 284 284 285 285 // 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]); 299 299 300 300 301 301 302 302 // now the real rotations 303 // e2 around e1304 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 e2314 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 e3324 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]); 332 332 333 333 … … 335 335 336 336 // 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]); 351 351 352 352 // the real stuff … … 370 370 std::vector<Vector> res = la1->getSphereIntersections(); 371 371 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])); 374 374 CPPUNIT_ASSERT(res[0]!=res[1]); 375 375 } … … 378 378 std::vector<Vector> res = la2->getSphereIntersections(); 379 379 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])); 382 382 CPPUNIT_ASSERT(res[0]!=res[1]); 383 383 } … … 386 386 std::vector<Vector> res = la3->getSphereIntersections(); 387 387 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])); 390 390 CPPUNIT_ASSERT(res[0]!=res[1]); 391 391 } … … 394 394 std::vector<Vector> res = lp1->getSphereIntersections(); 395 395 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])); 398 398 CPPUNIT_ASSERT(res[0]!=res[1]); 399 399 } … … 402 402 std::vector<Vector> res = lp2->getSphereIntersections(); 403 403 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])); 406 406 CPPUNIT_ASSERT(res[0]!=res[1]); 407 407 } … … 410 410 std::vector<Vector> res = lp3->getSphereIntersections(); 411 411 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 16 16 atomsCalculationTest \ 17 17 AtomDescriptorTest \ 18 BaseShapesUnitTest \19 18 BondGraphUnitTest \ 20 19 BoxUnittest \ … … 75 74 AtomDescriptorTest.cpp \ 76 75 atomsCalculationTest.cpp \ 77 BaseShapesUnittest.cpp \78 76 bondgraphunittest.cpp \ 79 77 BoxUnittest.cpp \ … … 114 112 AtomDescriptorTest.hpp \ 115 113 atomsCalculationTest.hpp \ 116 BaseShapesUnittest.hpp \117 114 bondgraphunittest.hpp \ 118 115 BoxUnittest.hpp \ … … 168 165 AtomDescriptorTest_LDADD = ${ALLLIBS} 169 166 170 BaseShapesUnitTest_SOURCES = UnitTestMain.cpp BaseShapesUnittest.cpp BaseShapesUnittest.hpp171 BaseShapesUnitTest_LDADD = ${ALLLIBS}172 173 167 BondGraphUnitTest_SOURCES = UnitTestMain.cpp bondgraphunittest.cpp bondgraphunittest.hpp 174 168 BondGraphUnitTest_LDADD = ${ALLLIBS} -
src/unittests/MatrixUnittest.cpp
rfd4905 r6c438f 25 25 26 26 #include "MatrixUnittest.hpp" 27 #include "LinearAlgebra/Vector.hpp" 27 28 #include "LinearAlgebra/Matrix.hpp" 28 #include "LinearAlgebra/Vector.hpp"29 29 #include "Exceptions/NotInvertibleException.hpp" 30 30 … … 53 53 } 54 54 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]; 58 58 59 59 60 60 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]; 64 64 65 65 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]; 69 69 70 70 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]; 74 74 75 75 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]; 79 79 80 80 } … … 122 122 123 123 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]); 130 130 131 131 Vector t1=Vector(1.,1.,1.); … … 232 232 233 233 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]); 237 237 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]); 241 241 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]); 245 245 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]); 249 249 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]); 253 253 } 254 254 … … 310 310 311 311 void 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); 315 315 CPPUNIT_ASSERT_EQUAL((*zero)*zeroVec,zeroVec); 316 316 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]); 320 320 CPPUNIT_ASSERT_EQUAL((*one)*zeroVec,zeroVec); 321 321 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]); 325 325 CPPUNIT_ASSERT_EQUAL((*diagonal)*zeroVec,zeroVec); 326 326 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]); 330 330 CPPUNIT_ASSERT_EQUAL((*perm1)*zeroVec,zeroVec); 331 331 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]); 335 335 CPPUNIT_ASSERT_EQUAL((*perm2)*zeroVec,zeroVec); 336 336 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]); 340 340 CPPUNIT_ASSERT_EQUAL((*perm3)*zeroVec,zeroVec); 341 341 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]); 345 345 CPPUNIT_ASSERT_EQUAL((*perm4)*zeroVec,zeroVec); 346 346 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]); 350 350 CPPUNIT_ASSERT_EQUAL((*perm5)*zeroVec,zeroVec); 351 351 -
src/unittests/PlaneUnittest.cpp
rfd4905 r6c438f 36 36 37 37 void 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]); 42 42 } 43 43 … … 54 54 55 55 // three points 56 CPPUNIT_ASSERT_NO_THROW(Plane( e1,e2,e3));56 CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],unitVec[1],unitVec[2])); 57 57 // 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); 59 59 // 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); 61 61 62 62 // 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)); 64 64 // 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); 66 66 // 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); 68 68 69 69 // use a normalvector and an scalar offset 70 CPPUNIT_ASSERT_NO_THROW(Plane( e1,0));70 CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],0)); 71 71 // The zero vector is no good as a normalvector 72 72 CPPUNIT_ASSERT_THROW(Plane(zeroVec,0),ZeroVectorException); 73 73 74 74 // use a normalvector and an offset vector 75 CPPUNIT_ASSERT_NO_THROW(Plane( e1,zeroVec));75 CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],zeroVec)); 76 76 // and the bad zeroVector again 77 77 CPPUNIT_ASSERT_THROW(Plane(zeroVec,zeroVec),ZeroVectorException); … … 87 87 { 88 88 // 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())); 91 91 CPPUNIT_ASSERT_EQUAL(0.,p1.getOffset()); 92 92 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())); 95 95 CPPUNIT_ASSERT_EQUAL(0.,p2.getOffset()); 96 96 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())); 99 99 CPPUNIT_ASSERT_EQUAL(0.,p3.getOffset()); 100 100 } 101 101 { 102 102 // 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())); 105 105 CPPUNIT_ASSERT_EQUAL(0.,p1.getOffset()); 106 106 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())); 109 109 CPPUNIT_ASSERT_EQUAL(0.,p2.getOffset()); 110 110 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())); 113 113 CPPUNIT_ASSERT_EQUAL(0.,p3.getOffset()); 114 114 } … … 157 157 void PlaneUnittest::operationsTest(){ 158 158 { 159 Vector t = (1./3.)*( e1+e2+e3);159 Vector t = (1./3.)*(unitVec[0]+unitVec[1]+unitVec[2]); 160 160 CPPUNIT_ASSERT(fabs(p1->distance(zeroVec)-t.Norm()) < MYEPSILON); 161 161 CPPUNIT_ASSERT_EQUAL(t,p1->getClosestPoint(zeroVec)); 162 162 } 163 163 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])); 170 170 } 171 171 … … 174 174 175 175 // 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]); 182 182 183 183 fixture = p2->mirrorVector(zeroVec); 184 184 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]); 189 189 190 190 fixture = p3->mirrorVector(zeroVec); 191 191 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]); 196 196 197 197 fixture = p4->mirrorVector(zeroVec); 198 198 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]); 203 203 204 204 // some Vectors outside of the planes 205 205 { 206 Vector t = (2./3.)*( e1+e2+e3);206 Vector t = (2./3.)*(unitVec[0]+unitVec[1]+unitVec[2]); 207 207 fixture = p1->mirrorVector(zeroVec); 208 208 CPPUNIT_ASSERT_EQUAL(fixture,t); 209 209 } 210 210 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]); 217 217 } 218 218 … … 221 221 // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ??? 222 222 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) ); 224 224 CPPUNIT_ASSERT_EQUAL( zeroVec, fixture ); 225 225 226 226 // 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) ); 229 229 CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture ); 230 230 } -
src/unittests/ShapeUnittest.cpp
rfd4905 r6c438f 40 40 void ShapeUnittest::setUp() 41 41 { 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]; 69 69 } 70 70 … … 129 129 CPPUNIT_ASSERT(Everywhere().isInside(v122)); 130 130 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 193 void 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)); 131 277 } 132 278 … … 377 523 } 378 524 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 379 644 } 645 646 void 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 20 20 CPPUNIT_TEST_SUITE( ShapeUnittest) ; 21 21 CPPUNIT_TEST ( baseShapesTest ); 22 CPPUNIT_TEST ( surfaceTest ); 22 23 CPPUNIT_TEST ( assignmentTest ); 23 24 CPPUNIT_TEST ( operatorTest ); 25 CPPUNIT_TEST ( PointsOnSurfaceTest ); 24 26 CPPUNIT_TEST_SUITE_END(); 25 27 … … 29 31 30 32 void baseShapesTest(); 33 void surfaceTest(); 31 34 void assignmentTest(); 32 35 void operatorTest(); 36 void PointsOnSurfaceTest(); 33 37 34 38 // a lot of vectors.
Note:
See TracChangeset
for help on using the changeset viewer.