[bcf653] | 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 |
|
---|
[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 |
|
---|
[57f243] | 21 | #include "LinearAlgebra/Vector.hpp"
|
---|
[45ef76] | 22 | #include "Exceptions/LinearDependenceException.hpp"
|
---|
| 23 | #include "Exceptions/SkewException.hpp"
|
---|
| 24 |
|
---|
| 25 | #include <cppunit/CompilerOutputter.h>
|
---|
| 26 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 27 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 28 |
|
---|
| 29 | #include <iostream>
|
---|
[3dcb1f] | 30 | #include <cmath>
|
---|
[45ef76] | 31 |
|
---|
[f89024] | 32 | #include "LineUnitTest.hpp"
|
---|
[45ef76] | 33 |
|
---|
| 34 | #ifdef HAVE_TESTRUNNER
|
---|
| 35 | #include "UnitTestMain.hpp"
|
---|
| 36 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 37 |
|
---|
| 38 | CPPUNIT_TEST_SUITE_REGISTRATION( LineUnittest );
|
---|
| 39 |
|
---|
| 40 | void LineUnittest::setUp(){
|
---|
| 41 | // three lines along the axes
|
---|
[407782] | 42 | la1 = new Line(zeroVec,unitVec[0]);
|
---|
| 43 | la2 = new Line(zeroVec,unitVec[1]);
|
---|
| 44 | la3 = new Line(zeroVec,unitVec[2]);
|
---|
[45ef76] | 45 |
|
---|
| 46 | // the lines along the planes defined by two coordinate axes
|
---|
[407782] | 47 | lp1 = new Line(unitVec[0],unitVec[0]-unitVec[1]);
|
---|
| 48 | lp2 = new Line(unitVec[1],unitVec[1]-unitVec[2]);
|
---|
| 49 | lp3 = new Line(unitVec[2],unitVec[2]-unitVec[0]);
|
---|
[45ef76] | 50 | }
|
---|
| 51 | void LineUnittest::tearDown(){
|
---|
| 52 | delete la1;
|
---|
| 53 | delete la2;
|
---|
| 54 | delete la3;
|
---|
| 55 |
|
---|
| 56 | delete lp1;
|
---|
| 57 | delete lp2;
|
---|
| 58 | delete lp3;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | void LineUnittest::constructionErrorTest(){
|
---|
| 62 | // test some constructions
|
---|
| 63 |
|
---|
| 64 | // direction+origin should never fail
|
---|
[407782] | 65 | CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,unitVec[0]));
|
---|
| 66 | CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,unitVec[1]));
|
---|
| 67 | CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,unitVec[2]));
|
---|
[45ef76] | 68 |
|
---|
| 69 | // two points fails if both points are the same
|
---|
[407782] | 70 | CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[0],unitVec[1]));
|
---|
| 71 | CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[1],unitVec[2]));
|
---|
| 72 | CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[2],unitVec[0]));
|
---|
[45ef76] | 73 | // for zerovectors
|
---|
[407782] | 74 | CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[0],zeroVec));
|
---|
| 75 | CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[1],zeroVec));
|
---|
| 76 | CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[2],zeroVec));
|
---|
[45ef76] | 77 | // now we pass two times the same point
|
---|
| 78 | CPPUNIT_ASSERT_THROW(makeLineThrough(zeroVec,zeroVec),LinearDependenceException);
|
---|
[407782] | 79 | CPPUNIT_ASSERT_THROW(makeLineThrough(unitVec[0],unitVec[0]),LinearDependenceException);
|
---|
| 80 | CPPUNIT_ASSERT_THROW(makeLineThrough(unitVec[1],unitVec[1]),LinearDependenceException);
|
---|
| 81 | CPPUNIT_ASSERT_THROW(makeLineThrough(unitVec[2],unitVec[2]),LinearDependenceException);
|
---|
[45ef76] | 82 |
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | bool testDirection(const Vector &dir1,const Vector &dir2){
|
---|
| 86 | return (dir1==dir2) || (dir1==-1*dir2);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | void LineUnittest::constructionResultTest(){
|
---|
| 90 | // test all directions
|
---|
[407782] | 91 | CPPUNIT_ASSERT(testDirection(la1->getDirection(),unitVec[0]));
|
---|
| 92 | CPPUNIT_ASSERT(testDirection(la2->getDirection(),unitVec[1]));
|
---|
| 93 | CPPUNIT_ASSERT(testDirection(la3->getDirection(),unitVec[2]));
|
---|
[45ef76] | 94 |
|
---|
| 95 | // test origins
|
---|
| 96 | CPPUNIT_ASSERT_EQUAL(la1->getOrigin(),zeroVec);
|
---|
| 97 | CPPUNIT_ASSERT_EQUAL(la2->getOrigin(),zeroVec);
|
---|
| 98 | CPPUNIT_ASSERT_EQUAL(la2->getOrigin(),zeroVec);
|
---|
| 99 |
|
---|
| 100 | // test if desired points are on the lines
|
---|
| 101 | CPPUNIT_ASSERT(la1->isContained(zeroVec));
|
---|
| 102 | CPPUNIT_ASSERT(la2->isContained(zeroVec));
|
---|
| 103 | CPPUNIT_ASSERT(la3->isContained(zeroVec));
|
---|
| 104 |
|
---|
[407782] | 105 | CPPUNIT_ASSERT(la1->isContained(unitVec[0]));
|
---|
| 106 | CPPUNIT_ASSERT(la2->isContained(unitVec[1]));
|
---|
| 107 | CPPUNIT_ASSERT(la3->isContained(unitVec[2]));
|
---|
[45ef76] | 108 |
|
---|
[407782] | 109 | CPPUNIT_ASSERT(lp1->isContained(unitVec[0]));
|
---|
| 110 | CPPUNIT_ASSERT(lp2->isContained(unitVec[1]));
|
---|
| 111 | CPPUNIT_ASSERT(lp3->isContained(unitVec[2]));
|
---|
[45ef76] | 112 |
|
---|
[407782] | 113 | CPPUNIT_ASSERT(lp1->isContained(unitVec[1]));
|
---|
| 114 | CPPUNIT_ASSERT(lp2->isContained(unitVec[2]));
|
---|
| 115 | CPPUNIT_ASSERT(lp3->isContained(unitVec[0]));
|
---|
[45ef76] | 116 | }
|
---|
| 117 |
|
---|
| 118 | void LineUnittest::isContainedTest(){
|
---|
| 119 | // Zerovector on the axes lines
|
---|
| 120 | CPPUNIT_ASSERT(la1->isContained(zeroVec));
|
---|
| 121 | CPPUNIT_ASSERT(la2->isContained(zeroVec));
|
---|
| 122 | CPPUNIT_ASSERT(la3->isContained(zeroVec));
|
---|
| 123 |
|
---|
| 124 | // multiples of the second support vector
|
---|
[407782] | 125 | CPPUNIT_ASSERT(la1->isContained(unitVec[0]));
|
---|
| 126 | CPPUNIT_ASSERT(la2->isContained(unitVec[1]));
|
---|
| 127 | CPPUNIT_ASSERT(la3->isContained(unitVec[2]));
|
---|
[45ef76] | 128 |
|
---|
[407782] | 129 | CPPUNIT_ASSERT(la1->isContained(2*unitVec[0]));
|
---|
| 130 | CPPUNIT_ASSERT(la2->isContained(2*unitVec[1]));
|
---|
| 131 | CPPUNIT_ASSERT(la3->isContained(2*unitVec[2]));
|
---|
[45ef76] | 132 |
|
---|
[407782] | 133 | CPPUNIT_ASSERT(la1->isContained(3*unitVec[0]));
|
---|
| 134 | CPPUNIT_ASSERT(la2->isContained(3*unitVec[1]));
|
---|
| 135 | CPPUNIT_ASSERT(la3->isContained(3*unitVec[2]));
|
---|
[45ef76] | 136 |
|
---|
| 137 | // negative multiples
|
---|
[407782] | 138 | CPPUNIT_ASSERT(la1->isContained(-1*unitVec[0]));
|
---|
| 139 | CPPUNIT_ASSERT(la2->isContained(-1*unitVec[1]));
|
---|
| 140 | CPPUNIT_ASSERT(la3->isContained(-1*unitVec[2]));
|
---|
[45ef76] | 141 |
|
---|
[407782] | 142 | CPPUNIT_ASSERT(la1->isContained(-2*unitVec[0]));
|
---|
| 143 | CPPUNIT_ASSERT(la2->isContained(-2*unitVec[1]));
|
---|
| 144 | CPPUNIT_ASSERT(la3->isContained(-2*unitVec[2]));
|
---|
[45ef76] | 145 |
|
---|
| 146 | // points that should not be on the lines
|
---|
[407782] | 147 | CPPUNIT_ASSERT(!la1->isContained(unitVec[1]));
|
---|
| 148 | CPPUNIT_ASSERT(!la2->isContained(unitVec[2]));
|
---|
| 149 | CPPUNIT_ASSERT(!la3->isContained(unitVec[0]));
|
---|
[45ef76] | 150 |
|
---|
[407782] | 151 | CPPUNIT_ASSERT(!la1->isContained(2*unitVec[1]));
|
---|
| 152 | CPPUNIT_ASSERT(!la2->isContained(2*unitVec[2]));
|
---|
| 153 | CPPUNIT_ASSERT(!la3->isContained(2*unitVec[0]));
|
---|
[45ef76] | 154 |
|
---|
[407782] | 155 | CPPUNIT_ASSERT(!la1->isContained(-1*unitVec[1]));
|
---|
| 156 | CPPUNIT_ASSERT(!la2->isContained(-1*unitVec[2]));
|
---|
| 157 | CPPUNIT_ASSERT(!la3->isContained(-1*unitVec[0]));
|
---|
[45ef76] | 158 |
|
---|
| 159 | // For the plane lines
|
---|
[407782] | 160 | CPPUNIT_ASSERT(lp1->isContained(unitVec[0]));
|
---|
| 161 | CPPUNIT_ASSERT(lp2->isContained(unitVec[1]));
|
---|
| 162 | CPPUNIT_ASSERT(lp3->isContained(unitVec[2]));
|
---|
[45ef76] | 163 |
|
---|
[407782] | 164 | CPPUNIT_ASSERT(lp1->isContained(unitVec[1]));
|
---|
| 165 | CPPUNIT_ASSERT(lp2->isContained(unitVec[2]));
|
---|
| 166 | CPPUNIT_ASSERT(lp3->isContained(unitVec[0]));
|
---|
[45ef76] | 167 |
|
---|
[407782] | 168 | CPPUNIT_ASSERT(lp1->isContained(unitVec[0]+2*(unitVec[0]-unitVec[1])));
|
---|
| 169 | CPPUNIT_ASSERT(lp2->isContained(unitVec[1]+2*(unitVec[1]-unitVec[2])));
|
---|
| 170 | CPPUNIT_ASSERT(lp3->isContained(unitVec[2]+2*(unitVec[2]-unitVec[0])));
|
---|
[45ef76] | 171 |
|
---|
[407782] | 172 | CPPUNIT_ASSERT(lp1->isContained(unitVec[0]-2*(unitVec[0]-unitVec[1])));
|
---|
| 173 | CPPUNIT_ASSERT(lp2->isContained(unitVec[1]-2*(unitVec[1]-unitVec[2])));
|
---|
| 174 | CPPUNIT_ASSERT(lp3->isContained(unitVec[2]-2*(unitVec[2]-unitVec[0])));
|
---|
[45ef76] | 175 | }
|
---|
| 176 |
|
---|
| 177 | void LineUnittest::intersectionTest(){
|
---|
| 178 | Vector fixture;
|
---|
| 179 |
|
---|
| 180 | // intersection of the axis lines
|
---|
| 181 | fixture = la1->getIntersection(*la2);
|
---|
| 182 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 183 | fixture = la2->getIntersection(*la3);
|
---|
| 184 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 185 | fixture = la3->getIntersection(*la1);
|
---|
| 186 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 187 |
|
---|
| 188 | // axes and plane lines
|
---|
| 189 | fixture = la1->getIntersection(*lp1);
|
---|
[407782] | 190 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
[45ef76] | 191 | fixture = la2->getIntersection(*lp2);
|
---|
[407782] | 192 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
[45ef76] | 193 | fixture = la3->getIntersection(*lp3);
|
---|
[407782] | 194 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
[45ef76] | 195 |
|
---|
| 196 | fixture = la1->getIntersection(*lp3);
|
---|
[407782] | 197 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
[45ef76] | 198 | fixture = la2->getIntersection(*lp1);
|
---|
[407782] | 199 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
[45ef76] | 200 | fixture = la3->getIntersection(*lp2);
|
---|
[407782] | 201 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
[45ef76] | 202 |
|
---|
| 203 | // two plane lines
|
---|
| 204 | fixture = lp1->getIntersection(*lp2);
|
---|
[407782] | 205 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
[45ef76] | 206 | fixture = lp2->getIntersection(*lp3);
|
---|
[407782] | 207 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
[45ef76] | 208 | fixture = lp3->getIntersection(*lp1);
|
---|
[407782] | 209 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
[45ef76] | 210 |
|
---|
| 211 | // When we have two times the same line, we check if the point is on the line
|
---|
| 212 | fixture = la1->getIntersection(*la1);
|
---|
| 213 | CPPUNIT_ASSERT(la1->isContained(fixture));
|
---|
| 214 | fixture = la2->getIntersection(*la2);
|
---|
| 215 | CPPUNIT_ASSERT(la2->isContained(fixture));
|
---|
| 216 | fixture = la3->getIntersection(*la3);
|
---|
| 217 | CPPUNIT_ASSERT(la3->isContained(fixture));
|
---|
| 218 |
|
---|
| 219 | fixture = lp1->getIntersection(*lp1);
|
---|
| 220 | CPPUNIT_ASSERT(lp1->isContained(fixture));
|
---|
| 221 | fixture = lp2->getIntersection(*lp2);
|
---|
| 222 | CPPUNIT_ASSERT(lp2->isContained(fixture));
|
---|
| 223 | fixture = lp3->getIntersection(*lp3);
|
---|
| 224 | CPPUNIT_ASSERT(lp3->isContained(fixture));
|
---|
| 225 |
|
---|
| 226 | // lines that are askew should produce an Error
|
---|
| 227 | CPPUNIT_ASSERT_THROW(lp1->getIntersection(*la3),SkewException);
|
---|
| 228 | CPPUNIT_ASSERT_THROW(lp2->getIntersection(*la1),SkewException);
|
---|
| 229 | CPPUNIT_ASSERT_THROW(lp3->getIntersection(*la2),SkewException);
|
---|
| 230 |
|
---|
| 231 | CPPUNIT_ASSERT_THROW(la1->getIntersection(*lp2),SkewException);
|
---|
| 232 | CPPUNIT_ASSERT_THROW(la2->getIntersection(*lp3),SkewException);
|
---|
| 233 | CPPUNIT_ASSERT_THROW(la3->getIntersection(*lp1),SkewException);
|
---|
| 234 | }
|
---|
[42a101] | 235 |
|
---|
| 236 | void LineUnittest::rotationTest(){
|
---|
| 237 | Vector fixture;
|
---|
| 238 |
|
---|
| 239 | // rotate zero Vector along the axes lines by various degrees
|
---|
| 240 | fixture = la1->rotateVector(zeroVec,1.);
|
---|
| 241 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 242 | fixture = la2->rotateVector(zeroVec,1.);
|
---|
| 243 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 244 | fixture = la3->rotateVector(zeroVec,1.);
|
---|
| 245 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 246 |
|
---|
| 247 | fixture = la1->rotateVector(zeroVec,2.);
|
---|
| 248 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 249 | fixture = la2->rotateVector(zeroVec,2.);
|
---|
| 250 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 251 | fixture = la3->rotateVector(zeroVec,2.);
|
---|
| 252 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 253 |
|
---|
| 254 | // rotate vectors on the axis around their lines
|
---|
[407782] | 255 | fixture = la1->rotateVector(unitVec[0],1.);
|
---|
| 256 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
| 257 | fixture = la2->rotateVector(unitVec[1],1.);
|
---|
| 258 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
| 259 | fixture = la3->rotateVector(unitVec[2],1.);
|
---|
| 260 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
| 261 |
|
---|
| 262 | fixture = la1->rotateVector(unitVec[0],2.);
|
---|
| 263 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
| 264 | fixture = la2->rotateVector(unitVec[1],2.);
|
---|
| 265 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
| 266 | fixture = la3->rotateVector(unitVec[2],2.);
|
---|
| 267 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
[42a101] | 268 |
|
---|
| 269 | // more vectors on the axis
|
---|
[407782] | 270 | fixture = la1->rotateVector(2*unitVec[0],1.);
|
---|
| 271 | CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[0]);
|
---|
| 272 | fixture = la2->rotateVector(2*unitVec[1],1.);
|
---|
| 273 | CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[1]);
|
---|
| 274 | fixture = la3->rotateVector(2*unitVec[2],1.);
|
---|
| 275 | CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[2]);
|
---|
| 276 |
|
---|
| 277 | fixture = la1->rotateVector(2*unitVec[0],2.);
|
---|
| 278 | CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[0]);
|
---|
| 279 | fixture = la2->rotateVector(2*unitVec[1],2.);
|
---|
| 280 | CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[1]);
|
---|
| 281 | fixture = la3->rotateVector(2*unitVec[2],2.);
|
---|
| 282 | CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[2]);
|
---|
[42a101] | 283 |
|
---|
| 284 | // negative factors
|
---|
[407782] | 285 | fixture = la1->rotateVector(-1*unitVec[0],1.);
|
---|
| 286 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
|
---|
| 287 | fixture = la2->rotateVector(-1*unitVec[1],1.);
|
---|
| 288 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
|
---|
| 289 | fixture = la3->rotateVector(-1*unitVec[2],1.);
|
---|
| 290 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
|
---|
[42a101] | 291 |
|
---|
[407782] | 292 | fixture = la1->rotateVector(-1*unitVec[0],2.);
|
---|
| 293 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
|
---|
| 294 | fixture = la2->rotateVector(-1*unitVec[1],2.);
|
---|
| 295 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
|
---|
| 296 | fixture = la3->rotateVector(-1*unitVec[2],2.);
|
---|
| 297 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
|
---|
[42a101] | 298 |
|
---|
| 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 |
|
---|
| 367 | void LineUnittest::sphereIntersectionTest(){
|
---|
| 368 | {
|
---|
| 369 | std::vector<Vector> res = la1->getSphereIntersections();
|
---|
| 370 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 371 | CPPUNIT_ASSERT(testDirection(res[0],unitVec[0]));
|
---|
| 372 | CPPUNIT_ASSERT(testDirection(res[1],unitVec[0]));
|
---|
[f932b7] | 373 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 374 | }
|
---|
| 375 |
|
---|
| 376 | {
|
---|
| 377 | std::vector<Vector> res = la2->getSphereIntersections();
|
---|
| 378 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 379 | CPPUNIT_ASSERT(testDirection(res[0],unitVec[1]));
|
---|
| 380 | CPPUNIT_ASSERT(testDirection(res[1],unitVec[1]));
|
---|
[f932b7] | 381 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 382 | }
|
---|
| 383 |
|
---|
| 384 | {
|
---|
| 385 | std::vector<Vector> res = la3->getSphereIntersections();
|
---|
| 386 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 387 | CPPUNIT_ASSERT(testDirection(res[0],unitVec[2]));
|
---|
| 388 | CPPUNIT_ASSERT(testDirection(res[1],unitVec[2]));
|
---|
[f932b7] | 389 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 390 | }
|
---|
| 391 |
|
---|
| 392 | {
|
---|
| 393 | std::vector<Vector> res = lp1->getSphereIntersections();
|
---|
| 394 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 395 | CPPUNIT_ASSERT((res[0]==unitVec[0]) || (res[0]==unitVec[1]));
|
---|
| 396 | CPPUNIT_ASSERT((res[1]==unitVec[0]) || (res[1]==unitVec[1]));
|
---|
[f932b7] | 397 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 398 | }
|
---|
| 399 |
|
---|
| 400 | {
|
---|
| 401 | std::vector<Vector> res = lp2->getSphereIntersections();
|
---|
| 402 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 403 | CPPUNIT_ASSERT((res[0]==unitVec[1]) || (res[0]==unitVec[2]));
|
---|
| 404 | CPPUNIT_ASSERT((res[1]==unitVec[1]) || (res[1]==unitVec[2]));
|
---|
[f932b7] | 405 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 | {
|
---|
| 409 | std::vector<Vector> res = lp3->getSphereIntersections();
|
---|
| 410 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 411 | CPPUNIT_ASSERT((res[0]==unitVec[2]) || (res[0]==unitVec[0]));
|
---|
| 412 | CPPUNIT_ASSERT((res[1]==unitVec[2]) || (res[1]==unitVec[0]));
|
---|
[f932b7] | 413 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 414 | }
|
---|
| 415 | }
|
---|