Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/PlaneUnittest.cpp

    r3dcb1f r407782  
    2424
    2525void PlaneUnittest::setUp(){
    26   p1 = new Plane(e1,e2,e3);
    27   p2 = new Plane(e1,e2,zeroVec);
    28   p3 = new Plane(e1,zeroVec,e3);
    29   p4 = new Plane(zeroVec,e2,e3);
     26  p1 = new Plane(unitVec[0],unitVec[1],unitVec[2]);
     27  p2 = new Plane(unitVec[0],unitVec[1],zeroVec);
     28  p3 = new Plane(unitVec[0],zeroVec,unitVec[2]);
     29  p4 = new Plane(zeroVec,unitVec[1],unitVec[2]);
    3030}
    3131
     
    4242
    4343  // three points
    44   CPPUNIT_ASSERT_NO_THROW(Plane(e1,e2,e3));
     44  CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],unitVec[1],unitVec[2]));
    4545  // when only two points are differnt this gives an error
    46   CPPUNIT_ASSERT_THROW(Plane(e1,e2,e2),LinearDependenceException);
     46  CPPUNIT_ASSERT_THROW(Plane(unitVec[0],unitVec[1],unitVec[1]),LinearDependenceException);
    4747  // same with only one point
    48   CPPUNIT_ASSERT_THROW(Plane(e1,e1,e1),LinearDependenceException);
     48  CPPUNIT_ASSERT_THROW(Plane(unitVec[0],unitVec[0],unitVec[0]),LinearDependenceException);
    4949
    5050  // use two vector giving two directions
    51   CPPUNIT_ASSERT_NO_THROW(Plane(e1,e2,0));
     51  CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],unitVec[1],0));
    5252  // and again this is actually only one vector
    53   CPPUNIT_ASSERT_THROW(Plane(e1,e1,0),LinearDependenceException);
     53  CPPUNIT_ASSERT_THROW(Plane(unitVec[0],unitVec[0],0),LinearDependenceException);
    5454  // Zero vector does not give a good direction
    55   CPPUNIT_ASSERT_THROW(Plane(e1,zeroVec,0),ZeroVectorException);
     55  CPPUNIT_ASSERT_THROW(Plane(unitVec[0],zeroVec,0),ZeroVectorException);
    5656
    5757  // use a normalvector and an scalar offset
    58   CPPUNIT_ASSERT_NO_THROW(Plane(e1,0));
     58  CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],0));
    5959  // The zero vector is no good as a normalvector
    6060  CPPUNIT_ASSERT_THROW(Plane(zeroVec,0),ZeroVectorException);
    6161
    6262  // use a normalvector and an offset vector
    63   CPPUNIT_ASSERT_NO_THROW(Plane(e1,zeroVec));
     63  CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],zeroVec));
    6464  // and the bad zeroVector again
    6565  CPPUNIT_ASSERT_THROW(Plane(zeroVec,zeroVec),ZeroVectorException);
     
    7575  {
    7676    // construct with three points on plane
    77     Plane p1(e1,e2,zeroVec);
    78     CPPUNIT_ASSERT(testNormal(e3,p1.getNormal()));
     77    Plane p1(unitVec[0],unitVec[1],zeroVec);
     78    CPPUNIT_ASSERT(testNormal(unitVec[2],p1.getNormal()));
    7979    CPPUNIT_ASSERT_EQUAL(0.,p1.getOffset());
    8080
    81     Plane p2(e1,e3,zeroVec);
    82     CPPUNIT_ASSERT(testNormal(e2,p2.getNormal()));
     81    Plane p2(unitVec[0],unitVec[2],zeroVec);
     82    CPPUNIT_ASSERT(testNormal(unitVec[1],p2.getNormal()));
    8383    CPPUNIT_ASSERT_EQUAL(0.,p2.getOffset());
    8484
    85     Plane p3(e2,e3,zeroVec);
    86     CPPUNIT_ASSERT(testNormal(e1,p3.getNormal()));
     85    Plane p3(unitVec[1],unitVec[2],zeroVec);
     86    CPPUNIT_ASSERT(testNormal(unitVec[0],p3.getNormal()));
    8787    CPPUNIT_ASSERT_EQUAL(0.,p3.getOffset());
    8888  }
    8989  {
    9090    // construct with two directions + offset
    91     Plane p1(e1,e2,0);
    92     CPPUNIT_ASSERT(testNormal(e3,p1.getNormal()));
     91    Plane p1(unitVec[0],unitVec[1],0);
     92    CPPUNIT_ASSERT(testNormal(unitVec[2],p1.getNormal()));
    9393    CPPUNIT_ASSERT_EQUAL(0.,p1.getOffset());
    9494
    95     Plane p2(e1,e3,0);
    96     CPPUNIT_ASSERT(testNormal(e2,p2.getNormal()));
     95    Plane p2(unitVec[0],unitVec[2],0);
     96    CPPUNIT_ASSERT(testNormal(unitVec[1],p2.getNormal()));
    9797    CPPUNIT_ASSERT_EQUAL(0.,p2.getOffset());
    9898
    99     Plane p3(e2,e3,0);
    100     CPPUNIT_ASSERT(testNormal(e1,p3.getNormal()));
     99    Plane p3(unitVec[1],unitVec[2],0);
     100    CPPUNIT_ASSERT(testNormal(unitVec[0],p3.getNormal()));
    101101    CPPUNIT_ASSERT_EQUAL(0.,p3.getOffset());
    102102  }
     
    145145void PlaneUnittest::operationsTest(){
    146146  {
    147     Vector t = (1./3.)*(e1+e2+e3);
     147    Vector t = (1./3.)*(unitVec[0]+unitVec[1]+unitVec[2]);
    148148    CPPUNIT_ASSERT(fabs(p1->distance(zeroVec)-t.Norm()) < MYEPSILON);
    149149    CPPUNIT_ASSERT_EQUAL(t,p1->getClosestPoint(zeroVec));
    150150  }
    151151
    152   CPPUNIT_ASSERT(fabs(p2->distance(e3)-1) < MYEPSILON);
    153   CPPUNIT_ASSERT_EQUAL(zeroVec,p2->getClosestPoint(e3));
    154   CPPUNIT_ASSERT(fabs(p3->distance(e2)-1) < MYEPSILON);
    155   CPPUNIT_ASSERT_EQUAL(zeroVec,p3->getClosestPoint(e2));
    156   CPPUNIT_ASSERT(fabs(p4->distance(e1)-1) < MYEPSILON);
    157   CPPUNIT_ASSERT_EQUAL(zeroVec,p4->getClosestPoint(e1));
     152  CPPUNIT_ASSERT(fabs(p2->distance(unitVec[2])-1) < MYEPSILON);
     153  CPPUNIT_ASSERT_EQUAL(zeroVec,p2->getClosestPoint(unitVec[2]));
     154  CPPUNIT_ASSERT(fabs(p3->distance(unitVec[1])-1) < MYEPSILON);
     155  CPPUNIT_ASSERT_EQUAL(zeroVec,p3->getClosestPoint(unitVec[1]));
     156  CPPUNIT_ASSERT(fabs(p4->distance(unitVec[0])-1) < MYEPSILON);
     157  CPPUNIT_ASSERT_EQUAL(zeroVec,p4->getClosestPoint(unitVec[0]));
    158158}
    159159
     
    162162
    163163  // some Vectors that lie on the planes
    164   fixture = p1->mirrorVector(e1);
    165   CPPUNIT_ASSERT_EQUAL(fixture,e1);
    166   fixture = p1->mirrorVector(e2);
    167   CPPUNIT_ASSERT_EQUAL(fixture,e2);
    168   fixture = p1->mirrorVector(e3);
    169   CPPUNIT_ASSERT_EQUAL(fixture,e3);
     164  fixture = p1->mirrorVector(unitVec[0]);
     165  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
     166  fixture = p1->mirrorVector(unitVec[1]);
     167  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
     168  fixture = p1->mirrorVector(unitVec[2]);
     169  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    170170
    171171  fixture = p2->mirrorVector(zeroVec);
    172172  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
    173   fixture = p2->mirrorVector(e1);
    174   CPPUNIT_ASSERT_EQUAL(fixture,e1);
    175   fixture = p2->mirrorVector(e2);
    176   CPPUNIT_ASSERT_EQUAL(fixture,e2);
     173  fixture = p2->mirrorVector(unitVec[0]);
     174  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
     175  fixture = p2->mirrorVector(unitVec[1]);
     176  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
    177177
    178178  fixture = p3->mirrorVector(zeroVec);
    179179  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
    180   fixture = p3->mirrorVector(e1);
    181   CPPUNIT_ASSERT_EQUAL(fixture,e1);
    182   fixture = p3->mirrorVector(e3);
    183   CPPUNIT_ASSERT_EQUAL(fixture,e3);
     180  fixture = p3->mirrorVector(unitVec[0]);
     181  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
     182  fixture = p3->mirrorVector(unitVec[2]);
     183  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    184184
    185185  fixture = p4->mirrorVector(zeroVec);
    186186  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
    187   fixture = p4->mirrorVector(e2);
    188   CPPUNIT_ASSERT_EQUAL(fixture,e2);
    189   fixture = p4->mirrorVector(e3);
    190   CPPUNIT_ASSERT_EQUAL(fixture,e3);
     187  fixture = p4->mirrorVector(unitVec[1]);
     188  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
     189  fixture = p4->mirrorVector(unitVec[2]);
     190  CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
    191191
    192192  // some Vectors outside of the planes
    193193  {
    194     Vector t = (2./3.)*(e1+e2+e3);
     194    Vector t = (2./3.)*(unitVec[0]+unitVec[1]+unitVec[2]);
    195195    fixture = p1->mirrorVector(zeroVec);
    196196    CPPUNIT_ASSERT_EQUAL(fixture,t);
    197197  }
    198198
    199   fixture = p2->mirrorVector(e3);
    200   CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
    201   fixture = p3->mirrorVector(e2);
    202   CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
    203   fixture = p4->mirrorVector(e1);
    204   CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
     199  fixture = p2->mirrorVector(unitVec[2]);
     200  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
     201  fixture = p3->mirrorVector(unitVec[1]);
     202  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
     203  fixture = p4->mirrorVector(unitVec[0]);
     204  CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
    205205}
    206206
     
    209209  // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ???
    210210  Line l1 = makeLineThrough(zeroVec,Vector(2,1,0));
    211   CPPUNIT_ASSERT_NO_THROW(fixture = Plane(e1, zeroVec).GetIntersection(l1) );
     211  CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unitVec[0], zeroVec).GetIntersection(l1) );
    212212  CPPUNIT_ASSERT_EQUAL( zeroVec, fixture );
    213213
    214214  // plane at (2,1,0) normal to (0,1,0) cuts line from (1,0,0) to (0,1,1) at ???
    215   Line l2 = makeLineThrough(e1,Vector(0,1,1));
    216   CPPUNIT_ASSERT_NO_THROW(fixture = Plane(e2, Vector(2,1,0)).GetIntersection(l2) );
     215  Line l2 = makeLineThrough(unitVec[0],Vector(0,1,1));
     216  CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unitVec[1], Vector(2,1,0)).GetIntersection(l2) );
    217217  CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture );
    218218}
Note: See TracChangeset for help on using the changeset viewer.