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