Ignore:
Timestamp:
Apr 7, 2010, 3:45:38 PM (16 years ago)
Author:
Tillmann Crueger <crueger@…>
Children:
0f55b2
Parents:
770138
Message:

Made data internal data-structure of vector class private

  • Replaced occurences of access to internals with operator
  • moved Vector-class into LinAlg-Module
  • Reworked Vector to allow clean modularization
  • Added Plane class to describe arbitrary planes in 3d space
File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/unittests/vectorunittest.cpp

    r770138 r71910a  
    1717#include "memoryusageobserver.hpp"
    1818#include "vector.hpp"
     19#include "vector_ops.hpp"
    1920#include "vectorunittest.hpp"
     21#include "Plane.hpp"
     22#include "Exceptions/LinearDependenceException.hpp"
    2023
    2124#ifdef HAVE_TESTRUNNER
     
    195198{
    196199  // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ???
    197   CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionWithPlane(&unit, &zero, &zero, &two) );
     200  CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unit, zero).GetIntersection(zero, two) );
    198201  CPPUNIT_ASSERT_EQUAL( zero, fixture );
    199202
    200203  // plane at (2,1,0) normal to (0,1,0) cuts line from (1,0,0) to (0,1,1) at ???
    201   CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionWithPlane(&otherunit, &two, &unit, &notunit) );
     204  CPPUNIT_ASSERT_NO_THROW(fixture = Plane(otherunit, two).GetIntersection( unit, notunit) );
    202205  CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture );
    203206
    204207  // four vectors equal to zero
    205   CPPUNIT_ASSERT_EQUAL( false, fixture.GetIntersectionOfTwoLinesOnPlane(&zero, &zero, &zero, &zero, NULL) );
     208  CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(zero, zero, zero, zero), LinearDependenceException);
     209  //CPPUNIT_ASSERT_EQUAL( zero, fixture );
     210
     211  // four vectors equal to unit
     212  CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, unit, unit, unit), LinearDependenceException);
     213  //CPPUNIT_ASSERT_EQUAL( zero, fixture );
     214
     215  // two equal lines
     216  CPPUNIT_ASSERT_NO_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, unit, two));
     217  CPPUNIT_ASSERT_EQUAL( unit, fixture );
     218
     219  // line from (1,0,0) to (2,1,0) cuts line from (1,0,0) to (0,1,0) at ???
     220  CPPUNIT_ASSERT_NO_THROW( fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, unit, otherunit) );
     221  CPPUNIT_ASSERT_EQUAL( unit, fixture );
     222
     223  // line from (1,0,0) to (0,0,0) cuts line from (0,0,0) to (2,1,0) at ???
     224  CPPUNIT_ASSERT_NO_THROW( fixture = GetIntersectionOfTwoLinesOnPlane(unit, zero, zero, two) );
    206225  CPPUNIT_ASSERT_EQUAL( zero, fixture );
    207226
    208   // four vectors equal to unit
    209   CPPUNIT_ASSERT_EQUAL( false, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &unit, &unit, &unit, NULL) );
     227  // line from (1,0,0) to (2,1,0) cuts line from (0,0,0) to (0,1,0) at ???
     228  CPPUNIT_ASSERT_NO_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, zero, otherunit) );
     229  CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), fixture );
     230};
     231
     232/** UnitTest for vector rotations.
     233 */
     234void VectorTest::VectorRotationTest()
     235{
     236  fixture.Init(-1.,0.,0.);
     237
     238  // zero vector does not change
     239  fixture = RotateVector(zero,unit, 1.);
    210240  CPPUNIT_ASSERT_EQUAL( zero, fixture );
    211241
    212   // two equal lines
    213   CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &two, &unit, &two, NULL) );
     242  fixture = RotateVector(zero, two, 1.);
     243  CPPUNIT_ASSERT_EQUAL( zero,  fixture);
     244
     245  // vector on axis does not change
     246  fixture = RotateVector(unit,unit, 1.);
    214247  CPPUNIT_ASSERT_EQUAL( unit, fixture );
    215248
    216   // line from (1,0,0) to (2,1,0) cuts line from (1,0,0) to (0,1,0) at ???
    217   CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &two, &unit, &otherunit, NULL) );
    218   CPPUNIT_ASSERT_EQUAL( unit, fixture );
    219 
    220   // line from (1,0,0) to (0,0,0) cuts line from (0,0,0) to (2,1,0) at ???
    221   CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &zero, &zero, &two, NULL) );
    222   CPPUNIT_ASSERT_EQUAL( zero, fixture );
    223 
    224   // line from (1,0,0) to (2,1,0) cuts line from (0,0,0) to (0,1,0) at ???
    225   CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &two, &zero, &otherunit, NULL) );
    226   CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), fixture );
    227 };
    228 
    229 /** UnitTest for vector rotations.
    230  */
    231 void VectorTest::VectorRotationTest()
    232 {
    233   fixture.Init(-1.,0.,0.);
    234 
    235   // zero vector does not change
    236   fixture.CopyVector(&zero);
    237   fixture.RotateVector(&unit, 1.);
    238   CPPUNIT_ASSERT_EQUAL( zero, fixture );
    239 
    240   fixture.RotateVector(&two, 1.);
    241   CPPUNIT_ASSERT_EQUAL( zero,  fixture);
    242 
    243   // vector on axis does not change
    244   fixture.CopyVector(&unit);
    245   fixture.RotateVector(&unit, 1.);
    246   CPPUNIT_ASSERT_EQUAL( unit, fixture );
    247 
    248   fixture.RotateVector(&unit, 1.);
    249   CPPUNIT_ASSERT_EQUAL( unit, fixture );
    250 
    251249  // rotations
    252   fixture.CopyVector(&otherunit);
    253   fixture.RotateVector(&unit, M_PI);
     250  fixture = RotateVector(otherunit, unit, M_PI);
    254251  CPPUNIT_ASSERT_EQUAL( Vector(0.,-1.,0.), fixture );
    255252
    256   fixture.CopyVector(&otherunit);
    257   fixture.RotateVector(&unit, 2. * M_PI);
     253  fixture = RotateVector(otherunit, unit, 2. * M_PI);
    258254  CPPUNIT_ASSERT_EQUAL( otherunit, fixture );
    259255
    260   fixture.CopyVector(&otherunit);
    261   fixture.RotateVector(&unit, 0);
     256  fixture = RotateVector(otherunit,unit, 0);
    262257  CPPUNIT_ASSERT_EQUAL( otherunit, fixture );
    263258
    264   fixture.Init(0.,0.,1.);
    265   fixture.RotateVector(&notunit, M_PI);
     259  fixture = RotateVector(Vector(0.,0.,1.), notunit, M_PI);
    266260  CPPUNIT_ASSERT_EQUAL( otherunit, fixture );
    267261}
Note: See TracChangeset for help on using the changeset viewer.