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