Ignore:
Timestamp:
Apr 29, 2010, 1:55:21 PM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
d79639
Parents:
632bc3 (diff), 753f02 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'VectorRefactoring' into StructureRefactoring

Conflicts:

molecuilder/src/Legacy/oldmenu.cpp
molecuilder/src/Makefile.am
molecuilder/src/analysis_correlation.cpp
molecuilder/src/boundary.cpp
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/ellipsoid.cpp
molecuilder/src/linkedcell.cpp
molecuilder/src/molecule.cpp
molecuilder/src/molecule_fragmentation.cpp
molecuilder/src/molecule_geometry.cpp
molecuilder/src/molecule_graph.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/tesselation.cpp
molecuilder/src/tesselationhelpers.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/vector.cpp
molecuilder/src/vector.hpp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/vectorunittest.cpp

    r632bc3 r8cbb97  
    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
     
    2326#endif /*HAVE_TESTRUNNER*/
    2427
     28#include <iostream>
     29
     30using namespace std;
     31
    2532/********************************************** Test classes **************************************/
    2633
     
    3138void VectorTest::setUp()
    3239{
    33   zero.Init(0.,0.,0.);
    34   unit.Init(1.,0.,0.);
    35   otherunit.Init(0.,1.,0.);
    36   notunit.Init(0.,1.,1.);
    37   two.Init(2.,1.,0.);
     40  zero  = Vector(0.,0.,0.);
     41  unit = Vector(1.,0.,0.);
     42  otherunit = Vector(0.,1.,0.);
     43  notunit = Vector(0.,1.,1.);
     44  two = Vector(2.,1.,0.);
    3845};
    3946
     
    6673  double factor;
    6774  // copy vector
    68   fixture.Init(2.,3.,4.);
     75  fixture = Vector(2.,3.,4.);
    6976  CPPUNIT_ASSERT_EQUAL( Vector(2.,3.,4.), fixture );
    7077  // summation and scaling
    71   fixture.CopyVector(&zero);
    72   fixture.AddVector(&unit);
    73   CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );
    74   fixture.CopyVector(&zero);
    75   fixture.SubtractVector(&unit);
     78  fixture = zero + unit;
     79  CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );
     80  fixture = zero - unit;
    7681  CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );
    7782  CPPUNIT_ASSERT_EQUAL( false, fixture.IsZero() );
    78   fixture.CopyVector(&zero);
    79   fixture.AddVector(&zero);
     83  fixture = zero + zero;
    8084  CPPUNIT_ASSERT_EQUAL( true, fixture.IsZero() );
    81   fixture.CopyVector(&notunit);
    82   fixture.SubtractVector(&otherunit);
    83   CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );
    84   fixture.CopyVector(&unit);
    85   fixture.AddVector(&otherunit);
     85  fixture = notunit - otherunit;
     86  CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );
     87  fixture = unit - otherunit;
    8688  CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() );
    87   fixture.CopyVector(&notunit);
    88   fixture.SubtractVector(&unit);
    89   fixture.SubtractVector(&otherunit);
     89  fixture = notunit - unit - otherunit;
    9090  CPPUNIT_ASSERT_EQUAL( false, fixture.IsZero() );
    91   fixture.CopyVector(&unit);
    92   fixture.Scale(0.98);
     91  fixture = 0.98 * unit;
    9392  CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() );
    94   fixture.CopyVector(&unit);
    95   fixture.Scale(1.);
    96   CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );
    97   fixture.CopyVector(&unit);
     93  fixture = 1. * unit;
     94  CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );
    9895  factor = 0.98;
    99   fixture.Scale(factor);
     96  fixture = factor * unit;
    10097  CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() );
    101   fixture.CopyVector(&unit);
    10298  factor = 1.;
    103   fixture.Scale(factor);
     99  fixture = factor * unit;
    104100  CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );
    105101};
     
    131127void VectorTest::EuclidianScalarProductTest()
    132128{
    133   CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(&zero) );
    134   CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(&unit) );
    135   CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(&otherunit) );
    136   CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(&notunit) );
    137   CPPUNIT_ASSERT_EQUAL( 1., unit.ScalarProduct(&unit) );
    138   CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct(&unit) );
    139   CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct(&unit) );
    140   CPPUNIT_ASSERT_EQUAL( 1., otherunit.ScalarProduct(&notunit) );
    141   CPPUNIT_ASSERT_EQUAL( 2., two.ScalarProduct(&unit) );
    142   CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(&otherunit) );
    143   CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(&notunit) );
     129  CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(zero) );
     130  CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(unit) );
     131  CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(otherunit) );
     132  CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(notunit) );
     133  CPPUNIT_ASSERT_EQUAL( 1., unit.ScalarProduct(unit) );
     134  CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct(unit) );
     135  CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct(unit) );
     136  CPPUNIT_ASSERT_EQUAL( 1., otherunit.ScalarProduct(notunit) );
     137  CPPUNIT_ASSERT_EQUAL( 2., two.ScalarProduct(unit) );
     138  CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(otherunit) );
     139  CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(notunit) );
    144140}
    145141
     
    162158void VectorTest::EuclidianDistancesTest()
    163159{
    164   CPPUNIT_ASSERT_EQUAL( 1., zero.Distance(&unit) );
    165   CPPUNIT_ASSERT_EQUAL( sqrt(2.), otherunit.Distance(&unit) );
    166   CPPUNIT_ASSERT_EQUAL( sqrt(2.), zero.Distance(&notunit) );
    167   CPPUNIT_ASSERT_EQUAL( 1., otherunit.Distance(&notunit) );
    168   CPPUNIT_ASSERT_EQUAL( sqrt(5.), two.Distance(&notunit) );
     160  CPPUNIT_ASSERT_EQUAL( 1., zero.Distance(unit) );
     161  CPPUNIT_ASSERT_EQUAL( sqrt(2.), otherunit.Distance(unit) );
     162  CPPUNIT_ASSERT_EQUAL( sqrt(2.), zero.Distance(notunit) );
     163  CPPUNIT_ASSERT_EQUAL( 1., otherunit.Distance(notunit) );
     164  CPPUNIT_ASSERT_EQUAL( sqrt(5.), two.Distance(notunit) );
    169165}
    170166
     
    173169void VectorTest::EuclidianAnglesTest()
    174170{
    175   CPPUNIT_ASSERT_EQUAL( M_PI, zero.Angle(&unit) );
    176   CPPUNIT_ASSERT_EQUAL( 0., unit.Angle(&unit) );
    177   CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - otherunit.Angle(&unit)) < MYEPSILON );
    178   CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - unit.Angle(&notunit)) < MYEPSILON );
    179   CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/4. - otherunit.Angle(&notunit)) < MYEPSILON );
     171  CPPUNIT_ASSERT_EQUAL( M_PI, zero.Angle(unit) );
     172  CPPUNIT_ASSERT_EQUAL( 0., unit.Angle(unit) );
     173  CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - otherunit.Angle(unit)) < MYEPSILON );
     174  CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - unit.Angle(notunit)) < MYEPSILON );
     175  CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/4. - otherunit.Angle(notunit)) < MYEPSILON );
    180176};
    181177
     
    184180void VectorTest::ProjectionTest()
    185181{
    186   CPPUNIT_ASSERT_EQUAL( zero, zero.Projection(&unit) );
    187   CPPUNIT_ASSERT_EQUAL( zero, otherunit.Projection(&unit) );
    188   CPPUNIT_ASSERT_EQUAL( Vector(0.4,0.2,0.),  otherunit.Projection(&two) );
    189   CPPUNIT_ASSERT_EQUAL( Vector(0.,1.,0.),  two.Projection(&otherunit) );
     182  CPPUNIT_ASSERT_EQUAL( zero, zero.Projection(unit) );
     183  CPPUNIT_ASSERT_EQUAL( zero, otherunit.Projection(unit) );
     184  CPPUNIT_ASSERT_EQUAL( Vector(0.4,0.2,0.),  otherunit.Projection(two) );
     185  CPPUNIT_ASSERT_EQUAL( Vector(0.,1.,0.),  two.Projection(otherunit) );
    190186};
    191187
     
    195191{
    196192  // 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) );
     193  CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unit, zero).GetIntersection(zero, two) );
    198194  CPPUNIT_ASSERT_EQUAL( zero, fixture );
    199195
    200196  // 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) );
     197  CPPUNIT_ASSERT_NO_THROW(fixture = Plane(otherunit, two).GetIntersection( unit, notunit) );
    202198  CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture );
    203199
    204200  // four vectors equal to zero
    205   CPPUNIT_ASSERT_EQUAL( false, fixture.GetIntersectionOfTwoLinesOnPlane(&zero, &zero, &zero, &zero, NULL) );
     201  CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(zero, zero, zero, zero), LinearDependenceException);
     202  //CPPUNIT_ASSERT_EQUAL( zero, fixture );
     203
     204  // four vectors equal to unit
     205  CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, unit, unit, unit), LinearDependenceException);
     206  //CPPUNIT_ASSERT_EQUAL( zero, fixture );
     207
     208  // two equal lines
     209  CPPUNIT_ASSERT_NO_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, unit, two));
     210  CPPUNIT_ASSERT_EQUAL( unit, fixture );
     211
     212  // line from (1,0,0) to (2,1,0) cuts line from (1,0,0) to (0,1,0) at ???
     213  CPPUNIT_ASSERT_NO_THROW( fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, unit, otherunit) );
     214  CPPUNIT_ASSERT_EQUAL( unit, fixture );
     215
     216  // line from (1,0,0) to (0,0,0) cuts line from (0,0,0) to (2,1,0) at ???
     217  CPPUNIT_ASSERT_NO_THROW( fixture = GetIntersectionOfTwoLinesOnPlane(unit, zero, zero, two) );
    206218  CPPUNIT_ASSERT_EQUAL( zero, fixture );
    207219
    208   // four vectors equal to unit
    209   CPPUNIT_ASSERT_EQUAL( false, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &unit, &unit, &unit, NULL) );
     220  // line from (1,0,0) to (2,1,0) cuts line from (0,0,0) to (0,1,0) at ???
     221  CPPUNIT_ASSERT_NO_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, zero, otherunit) );
     222  CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), fixture );
     223};
     224
     225/** UnitTest for vector rotations.
     226 */
     227void VectorTest::VectorRotationTest()
     228{
     229  fixture = Vector(-1.,0.,0.);
     230
     231  // zero vector does not change
     232  fixture = RotateVector(zero,unit, 1.);
    210233  CPPUNIT_ASSERT_EQUAL( zero, fixture );
    211234
    212   // two equal lines
    213   CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &two, &unit, &two, NULL) );
     235  fixture = RotateVector(zero, two, 1.);
     236  CPPUNIT_ASSERT_EQUAL( zero,  fixture);
     237
     238  // vector on axis does not change
     239  fixture = RotateVector(unit,unit, 1.);
    214240  CPPUNIT_ASSERT_EQUAL( unit, fixture );
    215241
    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 
    251242  // rotations
    252   fixture.CopyVector(&otherunit);
    253   fixture.RotateVector(&unit, M_PI);
     243  fixture = RotateVector(otherunit, unit, M_PI);
    254244  CPPUNIT_ASSERT_EQUAL( Vector(0.,-1.,0.), fixture );
    255245
    256   fixture.CopyVector(&otherunit);
    257   fixture.RotateVector(&unit, 2. * M_PI);
     246  fixture = RotateVector(otherunit, unit, 2. * M_PI);
    258247  CPPUNIT_ASSERT_EQUAL( otherunit, fixture );
    259248
    260   fixture.CopyVector(&otherunit);
    261   fixture.RotateVector(&unit, 0);
     249  fixture = RotateVector(otherunit,unit, 0);
    262250  CPPUNIT_ASSERT_EQUAL( otherunit, fixture );
    263251
    264   fixture.Init(0.,0.,1.);
    265   fixture.RotateVector(&notunit, M_PI);
     252  fixture = RotateVector(Vector(0.,0.,1.), notunit, M_PI);
    266253  CPPUNIT_ASSERT_EQUAL( otherunit, fixture );
    267254}
     
    283270  parallelepiped[8] = 1;
    284271
    285   fixture.CopyVector(zero);
    286   CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    287   fixture.Init(2.5,2.5,2.5);
     272  fixture = zero;
     273  CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
     274  fixture = Vector(2.5,2.5,2.5);
    288275  CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    289   fixture.Init(1.,1.,1.);
    290   CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    291   fixture.Init(3.5,3.5,3.5);
    292   CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    293   fixture.Init(2.,2.,2.);
     276  fixture = Vector(1.,1.,1.);
     277  CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
     278  fixture = Vector(3.5,3.5,3.5);
     279  CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
     280  fixture = Vector(2.,2.,2.);
    294281  CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    295   fixture.Init(2.,3.,2.);
     282  fixture = Vector(2.,3.,2.);
    296283  CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    297   fixture.Init(-2.,2.,-1.);
    298   CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    299 }
    300 
     284  fixture = Vector(-2.,2.,-1.);
     285  CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
     286}
     287
Note: See TracChangeset for help on using the changeset viewer.