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