[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[6d608d] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[bcf653] | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[45ef76] | 8 | /*
|
---|
| 9 | * LineUnittest.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: May 27, 2010
|
---|
| 12 | * Author: crueger
|
---|
| 13 | */
|
---|
| 14 |
|
---|
[bf3817] | 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
[45ef76] | 20 |
|
---|
[bf4b9f] | 21 | #include "Exceptions.hpp"
|
---|
| 22 | #include "Vector.hpp"
|
---|
[45ef76] | 23 |
|
---|
| 24 | #include <cppunit/CompilerOutputter.h>
|
---|
| 25 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 26 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 27 |
|
---|
| 28 | #include <iostream>
|
---|
[3dcb1f] | 29 | #include <cmath>
|
---|
[45ef76] | 30 |
|
---|
[f89024] | 31 | #include "LineUnitTest.hpp"
|
---|
[45ef76] | 32 |
|
---|
[50c35d] | 33 | #include "RealSpaceMatrix.hpp"
|
---|
| 34 |
|
---|
[45ef76] | 35 | #ifdef HAVE_TESTRUNNER
|
---|
| 36 | #include "UnitTestMain.hpp"
|
---|
| 37 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 38 |
|
---|
| 39 | CPPUNIT_TEST_SUITE_REGISTRATION( LineUnittest );
|
---|
| 40 |
|
---|
| 41 | void LineUnittest::setUp(){
|
---|
| 42 | // three lines along the axes
|
---|
[407782] | 43 | la1 = new Line(zeroVec,unitVec[0]);
|
---|
| 44 | la2 = new Line(zeroVec,unitVec[1]);
|
---|
| 45 | la3 = new Line(zeroVec,unitVec[2]);
|
---|
[45ef76] | 46 |
|
---|
| 47 | // the lines along the planes defined by two coordinate axes
|
---|
[407782] | 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]);
|
---|
[45ef76] | 51 | }
|
---|
| 52 | void LineUnittest::tearDown(){
|
---|
| 53 | delete la1;
|
---|
| 54 | delete la2;
|
---|
| 55 | delete la3;
|
---|
| 56 |
|
---|
| 57 | delete lp1;
|
---|
| 58 | delete lp2;
|
---|
| 59 | delete lp3;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | void LineUnittest::constructionErrorTest(){
|
---|
| 63 | // test some constructions
|
---|
| 64 |
|
---|
| 65 | // direction+origin should never fail
|
---|
[407782] | 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]));
|
---|
[45ef76] | 69 |
|
---|
| 70 | // two points fails if both points are the same
|
---|
[407782] | 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]));
|
---|
[45ef76] | 74 | // for zerovectors
|
---|
[407782] | 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));
|
---|
[45ef76] | 78 | // now we pass two times the same point
|
---|
| 79 | CPPUNIT_ASSERT_THROW(makeLineThrough(zeroVec,zeroVec),LinearDependenceException);
|
---|
[407782] | 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);
|
---|
[45ef76] | 83 |
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | bool testDirection(const Vector &dir1,const Vector &dir2){
|
---|
| 87 | return (dir1==dir2) || (dir1==-1*dir2);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | void LineUnittest::constructionResultTest(){
|
---|
| 91 | // test all directions
|
---|
[407782] | 92 | CPPUNIT_ASSERT(testDirection(la1->getDirection(),unitVec[0]));
|
---|
| 93 | CPPUNIT_ASSERT(testDirection(la2->getDirection(),unitVec[1]));
|
---|
| 94 | CPPUNIT_ASSERT(testDirection(la3->getDirection(),unitVec[2]));
|
---|
[45ef76] | 95 |
|
---|
| 96 | // test origins
|
---|
| 97 | CPPUNIT_ASSERT_EQUAL(la1->getOrigin(),zeroVec);
|
---|
| 98 | CPPUNIT_ASSERT_EQUAL(la2->getOrigin(),zeroVec);
|
---|
| 99 | CPPUNIT_ASSERT_EQUAL(la2->getOrigin(),zeroVec);
|
---|
| 100 |
|
---|
| 101 | // test if desired points are on the lines
|
---|
| 102 | CPPUNIT_ASSERT(la1->isContained(zeroVec));
|
---|
| 103 | CPPUNIT_ASSERT(la2->isContained(zeroVec));
|
---|
| 104 | CPPUNIT_ASSERT(la3->isContained(zeroVec));
|
---|
| 105 |
|
---|
[407782] | 106 | CPPUNIT_ASSERT(la1->isContained(unitVec[0]));
|
---|
| 107 | CPPUNIT_ASSERT(la2->isContained(unitVec[1]));
|
---|
| 108 | CPPUNIT_ASSERT(la3->isContained(unitVec[2]));
|
---|
[45ef76] | 109 |
|
---|
[407782] | 110 | CPPUNIT_ASSERT(lp1->isContained(unitVec[0]));
|
---|
| 111 | CPPUNIT_ASSERT(lp2->isContained(unitVec[1]));
|
---|
| 112 | CPPUNIT_ASSERT(lp3->isContained(unitVec[2]));
|
---|
[45ef76] | 113 |
|
---|
[407782] | 114 | CPPUNIT_ASSERT(lp1->isContained(unitVec[1]));
|
---|
| 115 | CPPUNIT_ASSERT(lp2->isContained(unitVec[2]));
|
---|
| 116 | CPPUNIT_ASSERT(lp3->isContained(unitVec[0]));
|
---|
[45ef76] | 117 | }
|
---|
| 118 |
|
---|
| 119 | void LineUnittest::isContainedTest(){
|
---|
| 120 | // Zerovector on the axes lines
|
---|
| 121 | CPPUNIT_ASSERT(la1->isContained(zeroVec));
|
---|
| 122 | CPPUNIT_ASSERT(la2->isContained(zeroVec));
|
---|
| 123 | CPPUNIT_ASSERT(la3->isContained(zeroVec));
|
---|
| 124 |
|
---|
| 125 | // multiples of the second support vector
|
---|
[407782] | 126 | CPPUNIT_ASSERT(la1->isContained(unitVec[0]));
|
---|
| 127 | CPPUNIT_ASSERT(la2->isContained(unitVec[1]));
|
---|
| 128 | CPPUNIT_ASSERT(la3->isContained(unitVec[2]));
|
---|
[45ef76] | 129 |
|
---|
[407782] | 130 | CPPUNIT_ASSERT(la1->isContained(2*unitVec[0]));
|
---|
| 131 | CPPUNIT_ASSERT(la2->isContained(2*unitVec[1]));
|
---|
| 132 | CPPUNIT_ASSERT(la3->isContained(2*unitVec[2]));
|
---|
[45ef76] | 133 |
|
---|
[407782] | 134 | CPPUNIT_ASSERT(la1->isContained(3*unitVec[0]));
|
---|
| 135 | CPPUNIT_ASSERT(la2->isContained(3*unitVec[1]));
|
---|
| 136 | CPPUNIT_ASSERT(la3->isContained(3*unitVec[2]));
|
---|
[45ef76] | 137 |
|
---|
| 138 | // negative multiples
|
---|
[407782] | 139 | CPPUNIT_ASSERT(la1->isContained(-1*unitVec[0]));
|
---|
| 140 | CPPUNIT_ASSERT(la2->isContained(-1*unitVec[1]));
|
---|
| 141 | CPPUNIT_ASSERT(la3->isContained(-1*unitVec[2]));
|
---|
[45ef76] | 142 |
|
---|
[407782] | 143 | CPPUNIT_ASSERT(la1->isContained(-2*unitVec[0]));
|
---|
| 144 | CPPUNIT_ASSERT(la2->isContained(-2*unitVec[1]));
|
---|
| 145 | CPPUNIT_ASSERT(la3->isContained(-2*unitVec[2]));
|
---|
[45ef76] | 146 |
|
---|
| 147 | // points that should not be on the lines
|
---|
[407782] | 148 | CPPUNIT_ASSERT(!la1->isContained(unitVec[1]));
|
---|
| 149 | CPPUNIT_ASSERT(!la2->isContained(unitVec[2]));
|
---|
| 150 | CPPUNIT_ASSERT(!la3->isContained(unitVec[0]));
|
---|
[45ef76] | 151 |
|
---|
[407782] | 152 | CPPUNIT_ASSERT(!la1->isContained(2*unitVec[1]));
|
---|
| 153 | CPPUNIT_ASSERT(!la2->isContained(2*unitVec[2]));
|
---|
| 154 | CPPUNIT_ASSERT(!la3->isContained(2*unitVec[0]));
|
---|
[45ef76] | 155 |
|
---|
[407782] | 156 | CPPUNIT_ASSERT(!la1->isContained(-1*unitVec[1]));
|
---|
| 157 | CPPUNIT_ASSERT(!la2->isContained(-1*unitVec[2]));
|
---|
| 158 | CPPUNIT_ASSERT(!la3->isContained(-1*unitVec[0]));
|
---|
[45ef76] | 159 |
|
---|
| 160 | // For the plane lines
|
---|
[407782] | 161 | CPPUNIT_ASSERT(lp1->isContained(unitVec[0]));
|
---|
| 162 | CPPUNIT_ASSERT(lp2->isContained(unitVec[1]));
|
---|
| 163 | CPPUNIT_ASSERT(lp3->isContained(unitVec[2]));
|
---|
[45ef76] | 164 |
|
---|
[407782] | 165 | CPPUNIT_ASSERT(lp1->isContained(unitVec[1]));
|
---|
| 166 | CPPUNIT_ASSERT(lp2->isContained(unitVec[2]));
|
---|
| 167 | CPPUNIT_ASSERT(lp3->isContained(unitVec[0]));
|
---|
[45ef76] | 168 |
|
---|
[407782] | 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])));
|
---|
[45ef76] | 172 |
|
---|
[407782] | 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])));
|
---|
[45ef76] | 176 | }
|
---|
| 177 |
|
---|
| 178 | void LineUnittest::intersectionTest(){
|
---|
| 179 | Vector fixture;
|
---|
| 180 |
|
---|
| 181 | // intersection of the axis lines
|
---|
| 182 | fixture = la1->getIntersection(*la2);
|
---|
| 183 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 184 | fixture = la2->getIntersection(*la3);
|
---|
| 185 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 186 | fixture = la3->getIntersection(*la1);
|
---|
| 187 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 188 |
|
---|
| 189 | // axes and plane lines
|
---|
| 190 | fixture = la1->getIntersection(*lp1);
|
---|
[407782] | 191 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
[45ef76] | 192 | fixture = la2->getIntersection(*lp2);
|
---|
[407782] | 193 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
[45ef76] | 194 | fixture = la3->getIntersection(*lp3);
|
---|
[407782] | 195 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
[45ef76] | 196 |
|
---|
| 197 | fixture = la1->getIntersection(*lp3);
|
---|
[407782] | 198 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
[45ef76] | 199 | fixture = la2->getIntersection(*lp1);
|
---|
[407782] | 200 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
[45ef76] | 201 | fixture = la3->getIntersection(*lp2);
|
---|
[407782] | 202 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
[45ef76] | 203 |
|
---|
| 204 | // two plane lines
|
---|
| 205 | fixture = lp1->getIntersection(*lp2);
|
---|
[407782] | 206 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
[45ef76] | 207 | fixture = lp2->getIntersection(*lp3);
|
---|
[407782] | 208 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
[45ef76] | 209 | fixture = lp3->getIntersection(*lp1);
|
---|
[407782] | 210 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
[45ef76] | 211 |
|
---|
| 212 | // When we have two times the same line, we check if the point is on the line
|
---|
| 213 | fixture = la1->getIntersection(*la1);
|
---|
| 214 | CPPUNIT_ASSERT(la1->isContained(fixture));
|
---|
| 215 | fixture = la2->getIntersection(*la2);
|
---|
| 216 | CPPUNIT_ASSERT(la2->isContained(fixture));
|
---|
| 217 | fixture = la3->getIntersection(*la3);
|
---|
| 218 | CPPUNIT_ASSERT(la3->isContained(fixture));
|
---|
| 219 |
|
---|
| 220 | fixture = lp1->getIntersection(*lp1);
|
---|
| 221 | CPPUNIT_ASSERT(lp1->isContained(fixture));
|
---|
| 222 | fixture = lp2->getIntersection(*lp2);
|
---|
| 223 | CPPUNIT_ASSERT(lp2->isContained(fixture));
|
---|
| 224 | fixture = lp3->getIntersection(*lp3);
|
---|
| 225 | CPPUNIT_ASSERT(lp3->isContained(fixture));
|
---|
| 226 |
|
---|
| 227 | // lines that are askew should produce an Error
|
---|
| 228 | CPPUNIT_ASSERT_THROW(lp1->getIntersection(*la3),SkewException);
|
---|
| 229 | CPPUNIT_ASSERT_THROW(lp2->getIntersection(*la1),SkewException);
|
---|
| 230 | CPPUNIT_ASSERT_THROW(lp3->getIntersection(*la2),SkewException);
|
---|
| 231 |
|
---|
| 232 | CPPUNIT_ASSERT_THROW(la1->getIntersection(*lp2),SkewException);
|
---|
| 233 | CPPUNIT_ASSERT_THROW(la2->getIntersection(*lp3),SkewException);
|
---|
| 234 | CPPUNIT_ASSERT_THROW(la3->getIntersection(*lp1),SkewException);
|
---|
| 235 | }
|
---|
[42a101] | 236 |
|
---|
| 237 | void LineUnittest::rotationTest(){
|
---|
| 238 | Vector fixture;
|
---|
| 239 |
|
---|
| 240 | // rotate zero Vector along the axes lines by various degrees
|
---|
| 241 | fixture = la1->rotateVector(zeroVec,1.);
|
---|
| 242 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 243 | fixture = la2->rotateVector(zeroVec,1.);
|
---|
| 244 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 245 | fixture = la3->rotateVector(zeroVec,1.);
|
---|
| 246 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 247 |
|
---|
| 248 | fixture = la1->rotateVector(zeroVec,2.);
|
---|
| 249 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 250 | fixture = la2->rotateVector(zeroVec,2.);
|
---|
| 251 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 252 | fixture = la3->rotateVector(zeroVec,2.);
|
---|
| 253 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 254 |
|
---|
| 255 | // rotate vectors on the axis around their lines
|
---|
[407782] | 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]);
|
---|
[42a101] | 269 |
|
---|
| 270 | // more vectors on the axis
|
---|
[407782] | 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]);
|
---|
[42a101] | 284 |
|
---|
| 285 | // negative factors
|
---|
[407782] | 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]);
|
---|
[42a101] | 292 |
|
---|
[407782] | 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]);
|
---|
[42a101] | 299 |
|
---|
| 300 |
|
---|
| 301 | // now the real rotations
|
---|
[407782] | 302 | // unitVec[1] around unitVec[0]
|
---|
| 303 | fixture = la1->rotateVector(unitVec[1],0);
|
---|
| 304 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
| 305 | fixture = la1->rotateVector(unitVec[1],1./2.*M_PI);
|
---|
| 306 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
|
---|
| 307 | fixture = la1->rotateVector(unitVec[1],M_PI);
|
---|
| 308 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
|
---|
| 309 | fixture = la1->rotateVector(unitVec[1],2*M_PI);
|
---|
| 310 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
| 311 |
|
---|
| 312 | // unitVec[2] around unitVec[1]
|
---|
| 313 | fixture = la2->rotateVector(unitVec[2],0);
|
---|
| 314 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
| 315 | fixture = la2->rotateVector(unitVec[2],1./2.*M_PI);
|
---|
| 316 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
|
---|
| 317 | fixture = la2->rotateVector(unitVec[2],M_PI);
|
---|
| 318 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
|
---|
| 319 | fixture = la2->rotateVector(unitVec[2],2*M_PI);
|
---|
| 320 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
| 321 |
|
---|
| 322 | // unitVec[0] around unitVec[2]
|
---|
| 323 | fixture = la3->rotateVector(unitVec[0],0);
|
---|
| 324 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
| 325 | fixture = la3->rotateVector(unitVec[0],1./2.*M_PI);
|
---|
| 326 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
|
---|
| 327 | fixture = la3->rotateVector(unitVec[0],M_PI);
|
---|
| 328 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
|
---|
| 329 | fixture = la3->rotateVector(unitVec[0],2*M_PI);
|
---|
| 330 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
[42a101] | 331 |
|
---|
| 332 |
|
---|
| 333 | // and some rotation around the plane lines
|
---|
| 334 |
|
---|
| 335 | // Vectors on the line
|
---|
[407782] | 336 | fixture = lp1->rotateVector(unitVec[0],1.);
|
---|
| 337 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
| 338 | fixture = lp1->rotateVector(unitVec[1],1.);
|
---|
| 339 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
[42a101] | 340 |
|
---|
[407782] | 341 | fixture = lp2->rotateVector(unitVec[1],1.);
|
---|
| 342 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
| 343 | fixture = lp2->rotateVector(unitVec[2],1.);
|
---|
| 344 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
[42a101] | 345 |
|
---|
[407782] | 346 | fixture = lp3->rotateVector(unitVec[2],1.);
|
---|
| 347 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
| 348 | fixture = lp3->rotateVector(unitVec[0],1.);
|
---|
| 349 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
[42a101] | 350 |
|
---|
| 351 | // the real stuff
|
---|
| 352 | fixture = lp1->rotateVector(zeroVec,M_PI);
|
---|
| 353 | CPPUNIT_ASSERT_EQUAL(fixture,Vector(1,1,0));
|
---|
| 354 | fixture = lp2->rotateVector(zeroVec,M_PI);
|
---|
| 355 | CPPUNIT_ASSERT_EQUAL(fixture,Vector(0,1,1));
|
---|
| 356 | fixture = lp3->rotateVector(zeroVec,M_PI);
|
---|
| 357 | CPPUNIT_ASSERT_EQUAL(fixture,Vector(1,0,1));
|
---|
| 358 |
|
---|
| 359 | fixture = lp1->rotateVector(zeroVec,2*M_PI);
|
---|
| 360 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 361 | fixture = lp2->rotateVector(zeroVec,2*M_PI);
|
---|
| 362 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 363 | fixture = lp3->rotateVector(zeroVec,2*M_PI);
|
---|
| 364 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 365 | }
|
---|
[f932b7] | 366 |
|
---|
[50c35d] | 367 | void LineUnittest::getRotationMatrixTest()
|
---|
| 368 | {
|
---|
| 369 | RealSpaceMatrix M;
|
---|
| 370 | Vector fixture;
|
---|
| 371 |
|
---|
| 372 | // check getRotationMatrix;
|
---|
| 373 | M = la1->getRotationMatrix(1.);
|
---|
| 374 | fixture = M * unitVec[0];
|
---|
| 375 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
| 376 | M = la2->getRotationMatrix(1.);
|
---|
| 377 | fixture = M * unitVec[1];
|
---|
| 378 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
| 379 | M = la3->getRotationMatrix(1.);
|
---|
| 380 | fixture = M * unitVec[2];
|
---|
| 381 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
| 382 |
|
---|
| 383 | // unitVec[1] around unitVec[0]
|
---|
| 384 | fixture = la1->rotateVector(unitVec[1],0);
|
---|
| 385 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
| 386 | fixture = la1->rotateVector(unitVec[1],1./2.*M_PI);
|
---|
| 387 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
|
---|
| 388 | fixture = la1->rotateVector(unitVec[1],M_PI);
|
---|
| 389 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
|
---|
| 390 | fixture = la1->rotateVector(unitVec[1],2*M_PI);
|
---|
| 391 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
| 392 |
|
---|
| 393 | // unitVec[2] around unitVec[1]
|
---|
| 394 | fixture = la2->rotateVector(unitVec[2],0);
|
---|
| 395 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
| 396 | fixture = la2->rotateVector(unitVec[2],1./2.*M_PI);
|
---|
| 397 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
|
---|
| 398 | fixture = la2->rotateVector(unitVec[2],M_PI);
|
---|
| 399 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
|
---|
| 400 | fixture = la2->rotateVector(unitVec[2],2*M_PI);
|
---|
| 401 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
| 402 |
|
---|
| 403 | // unitVec[0] around unitVec[2]
|
---|
| 404 | fixture = la3->rotateVector(unitVec[0],0);
|
---|
| 405 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
| 406 | fixture = la3->rotateVector(unitVec[0],1./2.*M_PI);
|
---|
| 407 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
|
---|
| 408 | fixture = la3->rotateVector(unitVec[0],M_PI);
|
---|
| 409 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
|
---|
| 410 | fixture = la3->rotateVector(unitVec[0],2*M_PI);
|
---|
| 411 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
| 412 | }
|
---|
| 413 |
|
---|
[f932b7] | 414 | void LineUnittest::sphereIntersectionTest(){
|
---|
| 415 | {
|
---|
| 416 | std::vector<Vector> res = la1->getSphereIntersections();
|
---|
| 417 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 418 | CPPUNIT_ASSERT(testDirection(res[0],unitVec[0]));
|
---|
| 419 | CPPUNIT_ASSERT(testDirection(res[1],unitVec[0]));
|
---|
[f932b7] | 420 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 421 | }
|
---|
| 422 |
|
---|
| 423 | {
|
---|
| 424 | std::vector<Vector> res = la2->getSphereIntersections();
|
---|
| 425 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 426 | CPPUNIT_ASSERT(testDirection(res[0],unitVec[1]));
|
---|
| 427 | CPPUNIT_ASSERT(testDirection(res[1],unitVec[1]));
|
---|
[f932b7] | 428 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 429 | }
|
---|
| 430 |
|
---|
| 431 | {
|
---|
| 432 | std::vector<Vector> res = la3->getSphereIntersections();
|
---|
| 433 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 434 | CPPUNIT_ASSERT(testDirection(res[0],unitVec[2]));
|
---|
| 435 | CPPUNIT_ASSERT(testDirection(res[1],unitVec[2]));
|
---|
[f932b7] | 436 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 437 | }
|
---|
| 438 |
|
---|
| 439 | {
|
---|
| 440 | std::vector<Vector> res = lp1->getSphereIntersections();
|
---|
| 441 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 442 | CPPUNIT_ASSERT((res[0]==unitVec[0]) || (res[0]==unitVec[1]));
|
---|
| 443 | CPPUNIT_ASSERT((res[1]==unitVec[0]) || (res[1]==unitVec[1]));
|
---|
[f932b7] | 444 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 445 | }
|
---|
| 446 |
|
---|
| 447 | {
|
---|
| 448 | std::vector<Vector> res = lp2->getSphereIntersections();
|
---|
| 449 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 450 | CPPUNIT_ASSERT((res[0]==unitVec[1]) || (res[0]==unitVec[2]));
|
---|
| 451 | CPPUNIT_ASSERT((res[1]==unitVec[1]) || (res[1]==unitVec[2]));
|
---|
[f932b7] | 452 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 453 | }
|
---|
| 454 |
|
---|
| 455 | {
|
---|
| 456 | std::vector<Vector> res = lp3->getSphereIntersections();
|
---|
| 457 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 458 | CPPUNIT_ASSERT((res[0]==unitVec[2]) || (res[0]==unitVec[0]));
|
---|
| 459 | CPPUNIT_ASSERT((res[1]==unitVec[2]) || (res[1]==unitVec[0]));
|
---|
[f932b7] | 460 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 461 | }
|
---|
| 462 | }
|
---|