[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 | #include "LineUnittest.hpp"
|
---|
| 21 |
|
---|
[57f243] | 22 | #include "LinearAlgebra/Vector.hpp"
|
---|
[45ef76] | 23 | #include "Exceptions/LinearDependenceException.hpp"
|
---|
| 24 | #include "Exceptions/SkewException.hpp"
|
---|
| 25 |
|
---|
| 26 | #include <cppunit/CompilerOutputter.h>
|
---|
| 27 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 28 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 29 |
|
---|
| 30 | #include <iostream>
|
---|
[3dcb1f] | 31 | #include <cmath>
|
---|
[45ef76] | 32 |
|
---|
| 33 | using namespace std;
|
---|
| 34 |
|
---|
| 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 |
|
---|
| 302 | // now the real rotations
|
---|
[407782] | 303 | // unitVec[1] around unitVec[0]
|
---|
| 304 | fixture = la1->rotateVector(unitVec[1],0);
|
---|
| 305 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
| 306 | fixture = la1->rotateVector(unitVec[1],1./2.*M_PI);
|
---|
| 307 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
|
---|
| 308 | fixture = la1->rotateVector(unitVec[1],M_PI);
|
---|
| 309 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
|
---|
| 310 | fixture = la1->rotateVector(unitVec[1],2*M_PI);
|
---|
| 311 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
| 312 |
|
---|
| 313 | // unitVec[2] around unitVec[1]
|
---|
| 314 | fixture = la2->rotateVector(unitVec[2],0);
|
---|
| 315 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
| 316 | fixture = la2->rotateVector(unitVec[2],1./2.*M_PI);
|
---|
| 317 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
|
---|
| 318 | fixture = la2->rotateVector(unitVec[2],M_PI);
|
---|
| 319 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
|
---|
| 320 | fixture = la2->rotateVector(unitVec[2],2*M_PI);
|
---|
| 321 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
| 322 |
|
---|
| 323 | // unitVec[0] around unitVec[2]
|
---|
| 324 | fixture = la3->rotateVector(unitVec[0],0);
|
---|
| 325 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
| 326 | fixture = la3->rotateVector(unitVec[0],1./2.*M_PI);
|
---|
| 327 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
|
---|
| 328 | fixture = la3->rotateVector(unitVec[0],M_PI);
|
---|
| 329 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
|
---|
| 330 | fixture = la3->rotateVector(unitVec[0],2*M_PI);
|
---|
| 331 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
[42a101] | 332 |
|
---|
| 333 |
|
---|
| 334 | // and some rotation around the plane lines
|
---|
| 335 |
|
---|
| 336 | // Vectors on the line
|
---|
[407782] | 337 | fixture = lp1->rotateVector(unitVec[0],1.);
|
---|
| 338 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
| 339 | fixture = lp1->rotateVector(unitVec[1],1.);
|
---|
| 340 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
[42a101] | 341 |
|
---|
[407782] | 342 | fixture = lp2->rotateVector(unitVec[1],1.);
|
---|
| 343 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
| 344 | fixture = lp2->rotateVector(unitVec[2],1.);
|
---|
| 345 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
[42a101] | 346 |
|
---|
[407782] | 347 | fixture = lp3->rotateVector(unitVec[2],1.);
|
---|
| 348 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
| 349 | fixture = lp3->rotateVector(unitVec[0],1.);
|
---|
| 350 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
[42a101] | 351 |
|
---|
| 352 | // the real stuff
|
---|
| 353 | fixture = lp1->rotateVector(zeroVec,M_PI);
|
---|
| 354 | CPPUNIT_ASSERT_EQUAL(fixture,Vector(1,1,0));
|
---|
| 355 | fixture = lp2->rotateVector(zeroVec,M_PI);
|
---|
| 356 | CPPUNIT_ASSERT_EQUAL(fixture,Vector(0,1,1));
|
---|
| 357 | fixture = lp3->rotateVector(zeroVec,M_PI);
|
---|
| 358 | CPPUNIT_ASSERT_EQUAL(fixture,Vector(1,0,1));
|
---|
| 359 |
|
---|
| 360 | fixture = lp1->rotateVector(zeroVec,2*M_PI);
|
---|
| 361 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 362 | fixture = lp2->rotateVector(zeroVec,2*M_PI);
|
---|
| 363 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 364 | fixture = lp3->rotateVector(zeroVec,2*M_PI);
|
---|
| 365 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
| 366 | }
|
---|
[f932b7] | 367 |
|
---|
| 368 | void LineUnittest::sphereIntersectionTest(){
|
---|
| 369 | {
|
---|
| 370 | std::vector<Vector> res = la1->getSphereIntersections();
|
---|
| 371 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 372 | CPPUNIT_ASSERT(testDirection(res[0],unitVec[0]));
|
---|
| 373 | CPPUNIT_ASSERT(testDirection(res[1],unitVec[0]));
|
---|
[f932b7] | 374 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 375 | }
|
---|
| 376 |
|
---|
| 377 | {
|
---|
| 378 | std::vector<Vector> res = la2->getSphereIntersections();
|
---|
| 379 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 380 | CPPUNIT_ASSERT(testDirection(res[0],unitVec[1]));
|
---|
| 381 | CPPUNIT_ASSERT(testDirection(res[1],unitVec[1]));
|
---|
[f932b7] | 382 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | {
|
---|
| 386 | std::vector<Vector> res = la3->getSphereIntersections();
|
---|
| 387 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 388 | CPPUNIT_ASSERT(testDirection(res[0],unitVec[2]));
|
---|
| 389 | CPPUNIT_ASSERT(testDirection(res[1],unitVec[2]));
|
---|
[f932b7] | 390 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 391 | }
|
---|
| 392 |
|
---|
| 393 | {
|
---|
| 394 | std::vector<Vector> res = lp1->getSphereIntersections();
|
---|
| 395 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 396 | CPPUNIT_ASSERT((res[0]==unitVec[0]) || (res[0]==unitVec[1]));
|
---|
| 397 | CPPUNIT_ASSERT((res[1]==unitVec[0]) || (res[1]==unitVec[1]));
|
---|
[f932b7] | 398 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 399 | }
|
---|
| 400 |
|
---|
| 401 | {
|
---|
| 402 | std::vector<Vector> res = lp2->getSphereIntersections();
|
---|
| 403 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 404 | CPPUNIT_ASSERT((res[0]==unitVec[1]) || (res[0]==unitVec[2]));
|
---|
| 405 | CPPUNIT_ASSERT((res[1]==unitVec[1]) || (res[1]==unitVec[2]));
|
---|
[f932b7] | 406 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 | {
|
---|
| 410 | std::vector<Vector> res = lp3->getSphereIntersections();
|
---|
| 411 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
[407782] | 412 | CPPUNIT_ASSERT((res[0]==unitVec[2]) || (res[0]==unitVec[0]));
|
---|
| 413 | CPPUNIT_ASSERT((res[1]==unitVec[2]) || (res[1]==unitVec[0]));
|
---|
[f932b7] | 414 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
| 415 | }
|
---|
| 416 | }
|
---|