Changeset ef9df36


Ignore:
Timestamp:
Aug 19, 2009, 12:23:05 PM (15 years ago)
Author:
Frederik Heber <heber@…>
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:
99c484
Parents:
658efb
Message:

VectorUnitTest extended to Projections and Line intersection, some subsequent bug fixes.

Note: VectorUnitTest is running fine.

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Makefile.am

    r658efb ref9df36  
    22HEADER = atom.hpp bond.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp helpers.hpp leastsquaremin.hpp linkedcell.hpp molecules.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp
    33
    4 bin_PROGRAMS = molecuilder joiner analyzer VectorUnitTest
     4noinst_PROGRAMS =  VectorUnitTest
     5
     6bin_PROGRAMS = molecuilder joiner analyzer
    57molecuilderdir = ${bindir}
    68molecuilder_DATA = elements.db valence.db orbitals.db Hbonddistance.db Hbondangle.db
  • src/vector.cpp

    r658efb ref9df36  
    212212 * \param *PlaneNormal Plane's normal vector
    213213 * \param *PlaneOffset Plane's offset vector
    214  * \param *LineVector first vector of line
    215  * \param *LineVector2 second vector of line
     214 * \param *Origin first vector of line
     215 * \param *LineVector second vector of line
    216216 * \return true -  \a this contains intersection point on return, false - line is parallel to plane
    217217 */
     
    224224  Direction.CopyVector(LineVector);
    225225  Direction.SubtractVector(Origin);
     226  //*out << Verbose(4) << "INFO: Direction is " << Direction << "." << endl;
    226227  factor = Direction.ScalarProduct(PlaneNormal);
    227228  if (factor < MYEPSILON) { // Uniqueness: line parallel to plane?
     
    230231  }
    231232  helper.CopyVector(PlaneOffset);
    232   helper.SubtractVector(LineVector);
     233  helper.SubtractVector(Origin);
    233234  factor = helper.ScalarProduct(PlaneNormal)/factor;
    234235  //factor = Origin->ScalarProduct(PlaneNormal)*(-PlaneOffset->ScalarProduct(PlaneNormal))/(Direction.ScalarProduct(PlaneNormal));
    235236  Direction.Scale(factor);
    236   CopyVector(LineVector);
     237  CopyVector(Origin);
     238  //*out << Verbose(4) << "INFO: Scaled direction is " << Direction << "." << endl;
    237239  AddVector(&Direction);
    238240
     
    241243  helper.SubtractVector(PlaneOffset);
    242244  if (helper.ScalarProduct(PlaneNormal) < MYEPSILON) {
    243     *out << Verbose(2) << "INFO: Intersection at " << *this << " is good." << endl;
     245    //*out << Verbose(2) << "INFO: Intersection at " << *this << " is good." << endl;
    244246    return true;
    245247  } else {
     
    250252
    251253/** Calculates the intersection of the two lines that are both on the same plane.
    252  * Note that we do not check whether they are on the same plane. Vector is calculated with respecy to second line.
     254 * We construct auxiliary plane with its vector normal to one line direction and the PlaneNormal, then a vector
     255 * from the first line's offset onto the plane. Finally, scale by factor is 1/cos(angle(line1,line2..)) = 1/SP(...), and
     256 * project onto the first line's direction and add its offset.
    253257 * \param *out output stream for debugging
    254258 * \param *Line1a first vector of first line
     
    261265bool Vector::GetIntersectionOfTwoLinesOnPlane(ofstream *out, Vector *Line1a, Vector *Line1b, Vector *Line2a, Vector *Line2b, const Vector *PlaneNormal)
    262266{
    263   double factor1, factor2;
    264   Vector helper, Line, LineNormal, *OtherNormal = NULL;
    265   const Vector *Normal;
    266   bool result = false;
    267 
    268   // create Plane normal vector
    269   if (PlaneNormal == NULL) {
    270     OtherNormal = new Vector(0.,0.,0.);
    271     if (!OtherNormal->MakeNormalVector(Line1a, Line1b, Line2a))
    272       if (!OtherNormal->MakeNormalVector(Line1a, Line1b, Line2b)) {
    273         *out << Verbose(1) << "ERROR: GetIntersectionOfTwoLinesOnPlane() cannot create a normal of the plane, everything is linear dependent." << endl;
    274         return false;
    275       }
    276     Normal = OtherNormal;
    277   } else
    278     Normal = PlaneNormal;
    279   *out << Verbose(3) << "INFO: Normal of plane is " << *Normal << "." << endl;
    280 
    281   // check if lines are parallel
    282   helper.CopyVector(Line2b);
    283   helper.SubtractVector(Line2a);
    284   if (fabs(helper.ScalarProduct(Normal)) < MYEPSILON) {
    285     *out << Verbose(1) << "Lines " << helper << " and " << Line << " are parallel, no cross point!" << endl;
    286     result = false;
    287   } else { 
    288     helper.CopyVector(Line2a);
    289     helper.SubtractVector(Line1a);
    290     factor1 = helper.ScalarProduct(Normal);
    291     helper.CopyVector(Line2b);
    292     helper.SubtractVector(Line1a);
    293     factor2 = helper.ScalarProduct(Normal);
    294     if (fabs(factor2) > MYEPSILON) {
    295       CopyVector(Line2a);
    296       helper.Scale(factor1/factor2);
    297       AddVector(&helper);
     267  bool result = true;
     268  Vector Direction, OtherDirection;
     269  Vector AuxiliaryNormal;
     270  Vector Distance;
     271  const Vector *Normal = NULL;
     272  Vector *ConstructedNormal = NULL;
     273  bool FreeNormal = false;
     274
     275  // construct both direction vectors
     276  Zero();
     277  Direction.CopyVector(Line1b);
     278  Direction.SubtractVector(Line1a);
     279  if (Direction.IsZero())
     280    return false;
     281  OtherDirection.CopyVector(Line2b);
     282  OtherDirection.SubtractVector(Line2a);
     283  if (OtherDirection.IsZero())
     284    return false;
     285
     286  Direction.Normalize();
     287  OtherDirection.Normalize();
     288
     289  //*out << Verbose(4) << "INFO: Normalized Direction " << Direction << " and OtherDirection " << OtherDirection << "." << endl;
     290
     291  if (fabs(OtherDirection.ScalarProduct(&Direction) - 1.) < MYEPSILON) { // lines are parallel
     292    if ((Line1a == Line2a) || (Line1a == Line2b))
     293      CopyVector(Line1a);
     294    else if ((Line1b == Line2b) || (Line1b == Line2b))
     295        CopyVector(Line1b);
     296    else
     297      return false;
     298    *out << Verbose(4) << "INFO: Intersection is " << *this << "." << endl;
     299    return true;
     300  } else {
     301    // check whether we have a plane normal vector
     302    if (PlaneNormal == NULL) {
     303      ConstructedNormal = new Vector;
     304      ConstructedNormal->MakeNormalVector(&Direction, &OtherDirection);
     305      Normal = ConstructedNormal;
     306      FreeNormal = true;
     307    } else
     308      Normal = PlaneNormal;
     309
     310    AuxiliaryNormal.MakeNormalVector(&OtherDirection, Normal);
     311    //*out << Verbose(4) << "INFO: PlaneNormal is " << *Normal << " and AuxiliaryNormal " << AuxiliaryNormal << "." << endl;
     312
     313    Distance.CopyVector(Line2a);
     314    Distance.SubtractVector(Line1a);
     315    //*out << Verbose(4) << "INFO: Distance is " << Distance << "." << endl;
     316    if (Distance.IsZero()) {
     317      // offsets are equal, match found
     318      CopyVector(Line1a);
    298319      result = true;
    299320    } else {
    300       Zero();
    301       result = false;
     321      CopyVector(Distance.Projection(&AuxiliaryNormal));
     322      //*out << Verbose(4) << "INFO: Projected Distance is " << *this << "." << endl;
     323      double factor = Direction.ScalarProduct(&AuxiliaryNormal);
     324      //*out << Verbose(4) << "INFO: Scaling factor is " << factor << "." << endl;
     325      Scale(1./(factor*factor));
     326      //*out << Verbose(4) << "INFO: Scaled Distance is " << *this << "." << endl;
     327      CopyVector(Projection(&Direction));
     328      //*out << Verbose(4) << "INFO: Distance, projected into Direction, is " << *this << "." << endl;
     329      if (this->IsZero())
     330        result = false;
     331      else
     332        result = true;
     333      AddVector(Line1a);
    302334    }
    303   }
    304 
    305   if (OtherNormal != NULL)
    306     delete(OtherNormal);
     335
     336    if (FreeNormal)
     337      delete(ConstructedNormal);
     338  }
     339  if (result)
     340    *out << Verbose(4) << "INFO: Intersection is " << *this << "." << endl;
    307341
    308342  return result;
     
    311345/** Calculates the projection of a vector onto another \a *y.
    312346 * \param *y array to second vector
    313  * \return \f$\langle x, y \rangle\f$
    314  */
    315 double Vector::Projection(const Vector *y) const
    316 {
    317   return (ScalarProduct(y));
     347 */
     348void Vector::ProjectIt(const Vector *y)
     349{
     350  Vector helper(*y);
     351  helper.Scale(-(ScalarProduct(y)));
     352  AddVector(&helper);
     353};
     354
     355/** Calculates the projection of a vector onto another \a *y.
     356 * \param *y array to second vector
     357 * \return Vector
     358 */
     359Vector Vector::Projection(const Vector *y) const
     360{
     361  Vector helper(*y);
     362  helper.Scale((ScalarProduct(y)/y->NormSquared()));
     363
     364  return helper;
    318365};
    319366
     
    390437};
    391438
     439/** Checks whether vector is normal to \a *normal.
     440 * @return true - vector is normalized, false - vector is not
     441 */
     442bool Vector::IsNormalTo(const Vector *normal) const
     443{
     444  if (ScalarProduct(normal) < MYEPSILON)
     445    return true;
     446  else
     447    return false;
     448};
     449
    392450/** Calculates the angle between this and another vector.
    393451 * \param *y array to second vector
     
    397455{
    398456  double norm1 = Norm(), norm2 = y->Norm();
    399   double angle = 1;
     457  double angle = -1;
    400458  if ((fabs(norm1) > MYEPSILON) && (fabs(norm2) > MYEPSILON))
    401459    angle = this->ScalarProduct(y)/norm1/norm2;
     
    418476  // normalise this vector with respect to axis
    419477  a.CopyVector(this);
    420   a.Scale(Projection(axis));
    421   SubtractVector(&a);
     478  a.ProjectOntoPlane(axis);
    422479  // construct normal vector
    423480  y.MakeNormalVector(axis,this);
     
    430487  // add part in axis direction
    431488  AddVector(&a);
     489};
     490
     491/** Compares vector \a to vector \a b component-wise.
     492 * \param a base vector
     493 * \param b vector components to add
     494 * \return a == b
     495 */
     496bool operator==(const Vector& a, const Vector& b)
     497{
     498  bool status = true;
     499  for (int i=0;i<NDIM;i++)
     500    status = status && (fabs(a.x[i] - b.x[i]) < MYEPSILON);
     501  return status;
    432502};
    433503
     
    703773  x2.SubtractVector(y2);
    704774  if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) {
    705     cout << Verbose(4) << "Given vectors are linear dependent." << endl;
     775    cout << Verbose(4) << "WARNING: Given vectors are linear dependent." << endl;
    706776    return false;
    707777  }
     
    737807  Zero();
    738808  if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) {
    739     cout << Verbose(4) << "Given vectors are linear dependent." << endl;
     809    cout << Verbose(4) << "WARNING: Given vectors are linear dependent." << endl;
    740810    return false;
    741811  }
     
    757827/** Calculates orthonormal vector to one given vectors.
    758828 * Just subtracts the projection onto the given vector from this vector.
     829 * The removed part of the vector is Vector::Projection()
    759830 * \param *x1 vector
    760831 * \return true - success, false - vector is zero
     
    763834{
    764835  bool result = false;
    765   double factor = y1->Projection(this)/y1->Norm()/y1->Norm();
     836  double factor = y1->ScalarProduct(this)/y1->NormSquared();
    766837  Vector x1;
    767838  x1.CopyVector(y1);
     
    820891};
    821892
    822 /** Determines paramter needed to multiply this vector to obtain intersection point with plane defined by \a *A, \a *B and \a *C.
     893/** Determines parameter needed to multiply this vector to obtain intersection point with plane defined by \a *A, \a *B and \a *C.
    823894 * \param *A first plane vector
    824895 * \param *B second plane vector
     
    833904//  cout << "C " << C->Projection(this) << "\t";
    834905//  cout << endl;
    835   return A->Projection(this);
     906  return A->ScalarProduct(this);
    836907};
    837908
     
    9451016  for (int i=NDIM;i--;)
    9461017    this->x[i] = y->x[i];
     1018}
     1019
     1020/** Copy vector \a y componentwise.
     1021 * \param y vector
     1022 */
     1023void Vector::CopyVector(const Vector y)
     1024{
     1025  for (int i=NDIM;i--;)
     1026    this->x[i] = y.x[i];
    9471027}
    9481028
  • src/vector.hpp

    r658efb ref9df36  
    2727  double PeriodicDistanceSquared(const Vector *y, const double *cell_size) const;
    2828  double ScalarProduct(const Vector *y) const;
    29   double Projection(const Vector *y) const;
    3029  double Norm() const;
    3130  double NormSquared() const;
     
    3332  bool IsZero() const;
    3433  bool IsOne() const;
     34  bool IsNormalTo(const Vector *normal) const;
    3535
    3636  void AddVector(const Vector *y);
    3737  void SubtractVector(const Vector *y);
    3838  void CopyVector(const Vector *y);
     39  void CopyVector(const Vector y);
    3940  void RotateVector(const Vector *y, const double alpha);
    4041  void VectorProduct(const Vector *y);
    4142  void ProjectOntoPlane(const Vector *y);
     43  void ProjectIt(const Vector *y);
     44  Vector Projection(const Vector *y) const;
    4245  void Zero();
    4346  void One(double one);
     
    6871
    6972ostream & operator << (ostream& ost, const Vector &m);
     73bool operator==(const Vector& a, const Vector& b);
    7074Vector& operator+=(Vector& a, const Vector& b);
    7175Vector& operator-=(Vector& a, const Vector& b);
  • src/vectorunittest.cpp

    r658efb ref9df36  
    2525void VectorTest::setUp()
    2626{
     27  zero.Init(0.,0.,0.);
     28  unit.Init(1.,0.,0.);
     29  otherunit.Init(0.,1.,0.);
     30  notunit.Init(0.,1.,1.);
     31  two.Init(2.,1.,0.);
    2732};
    2833
     
    3641void VectorTest::UnityTest()
    3742{
    38   Vector zero(0.,0.,0.);
    39   Vector unit(1.,0.,0.);
    40   Vector otherunit(1./sqrt(2.),0.,1./sqrt(2.));
    41   Vector notunit(0.,1.,1.);
    42 
    4343  // unity and zero tests
    4444  CPPUNIT_ASSERT_EQUAL( true, zero.IsZero() );
     
    5555void VectorTest::SimpleAlgebraTest()
    5656{
    57   Vector zero(0.,0.,0.);
    58   Vector unit(1.,0.,0.);
    59   Vector otherunit(0.,1.,0.);
    60   Vector notunit(0.,1.,1.);
    6157  Vector helper;
    6258  double factor;
    63 
    6459  // summation and scaling
    6560  helper.CopyVector(&zero);
     
    10499void VectorTest::OperatorAlgebraTest()
    105100{
    106   Vector zero(0.,0.,0.);
    107   Vector unit(1.,0.,0.);
    108   Vector otherunit(0.,1.,0.);
    109   Vector notunit(0.,1.,1.);
    110 
    111101  // summation and scaling
     102  CPPUNIT_ASSERT_EQUAL( true, (zero+unit).IsOne() );
    112103  CPPUNIT_ASSERT_EQUAL( true, (zero+unit).IsOne() );
    113104  CPPUNIT_ASSERT_EQUAL( true, (zero-unit).IsOne() );
     
    119110  CPPUNIT_ASSERT_EQUAL( false, (unit*0.98).IsOne() );
    120111  CPPUNIT_ASSERT_EQUAL( true, (unit*1.).IsOne() );
    121 };
    122 
    123 /** UnitTest for scalar products, norms, distances and angles.
    124  */
    125 void VectorTest::EuclidianTest()
    126 {
    127   Vector zero(0.,0.,0.);
    128   Vector unit(1.,0.,0.);
    129   Vector otherunit(0.,1.,0.);
    130   Vector notunit(0.,1.,1.);
    131   Vector two(2.,1.,0.);
    132 
    133   // SCP
     112
     113  CPPUNIT_ASSERT_EQUAL( unit, (zero+unit) );
     114  CPPUNIT_ASSERT_EQUAL( Vector(0.,0.,1.), (notunit-otherunit) );
     115  CPPUNIT_ASSERT_EQUAL( Vector(-1, 0., 1.), (notunit-unit-otherunit) );
     116};
     117
     118/** UnitTest for scalar products.
     119 */
     120void VectorTest::EuclidianScalarProductTest()
     121{
    134122  CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(&zero) );
    135123  CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(&unit) );
     
    143131  CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(&otherunit) );
    144132  CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(&notunit) );
    145 
    146   // Norms
     133}
     134
     135/** UnitTest for norms.
     136 */
     137void VectorTest::EuclidianNormTest()
     138{
    147139  CPPUNIT_ASSERT_EQUAL( 0., zero.Norm() );
    148140  CPPUNIT_ASSERT_EQUAL( 0., zero.NormSquared() );
     
    153145  CPPUNIT_ASSERT_EQUAL( 2., notunit.NormSquared() );
    154146  CPPUNIT_ASSERT_EQUAL( sqrt(2.), notunit.Norm() );
    155 
    156   // distances
     147}
     148
     149/** UnitTest for distances.
     150 */
     151void VectorTest::EuclidianDistancesTest()
     152{
    157153  CPPUNIT_ASSERT_EQUAL( 1., zero.Distance(&unit) );
    158154  CPPUNIT_ASSERT_EQUAL( sqrt(2.), otherunit.Distance(&unit) );
     
    160156  CPPUNIT_ASSERT_EQUAL( 1., otherunit.Distance(&notunit) );
    161157  CPPUNIT_ASSERT_EQUAL( sqrt(5.), two.Distance(&notunit) );
    162 
    163   // Angles
     158}
     159
     160/** UnitTest for angles.
     161 */
     162void VectorTest::EuclidianAnglesTest()
     163{
    164164  CPPUNIT_ASSERT_EQUAL( M_PI, zero.Angle(&unit) );
    165 };
    166 
     165  CPPUNIT_ASSERT_EQUAL( 0., unit.Angle(&unit) );
     166  CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - otherunit.Angle(&unit)) < MYEPSILON );
     167  CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - unit.Angle(&notunit)) < MYEPSILON );
     168  CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/4. - otherunit.Angle(&notunit)) < MYEPSILON );
     169};
     170
     171/** UnitTest for projections.
     172 */
     173void VectorTest::ProjectionTest()
     174{
     175  CPPUNIT_ASSERT_EQUAL( zero, zero.Projection(&unit) );
     176  CPPUNIT_ASSERT_EQUAL( zero, otherunit.Projection(&unit) );
     177  CPPUNIT_ASSERT_EQUAL( Vector(0.4,0.2,0.),  otherunit.Projection(&two) );
     178  CPPUNIT_ASSERT_EQUAL( Vector(0.,1.,0.),  two.Projection(&otherunit) );
     179};
     180
     181/** UnitTest for line intersections.
     182 */
     183void VectorTest::LineIntersectionTest()
     184{
     185  Vector helper;
     186  // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ???
     187  CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionWithPlane((ofstream *)&cout, &unit, &zero, &zero, &two) );
     188  CPPUNIT_ASSERT_EQUAL( zero, helper );
     189
     190  // plane at (2,1,0) normal to (0,1,0) cuts line from (1,0,0) to (0,1,1) at ???
     191  CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionWithPlane((ofstream *)&cout, &otherunit, &two, &unit, &notunit) );
     192  CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), helper );
     193
     194  // four vectors equal to zero
     195  CPPUNIT_ASSERT_EQUAL( false, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &zero, &zero, &zero, &zero, NULL) );
     196  CPPUNIT_ASSERT_EQUAL( zero, helper );
     197
     198  // four vectors equal to unit
     199  CPPUNIT_ASSERT_EQUAL( false, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &unit, &unit, &unit, NULL) );
     200  CPPUNIT_ASSERT_EQUAL( zero, helper );
     201
     202  // two equal lines
     203  CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &unit, &two, NULL) );
     204  CPPUNIT_ASSERT_EQUAL( unit, helper );
     205
     206  // line from (1,0,0) to (2,1,0) cuts line from (1,0,0) to (0,1,0) at ???
     207  CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &unit, &otherunit, NULL) );
     208  CPPUNIT_ASSERT_EQUAL( unit, helper );
     209
     210  // line from (1,0,0) to (0,0,0) cuts line from (0,0,0) to (2,1,0) at ???
     211  CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &zero, &zero, &two, NULL) );
     212  CPPUNIT_ASSERT_EQUAL( zero, helper );
     213
     214  // line from (1,0,0) to (2,1,0) cuts line from (0,0,0) to (0,1,0) at ???
     215  CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &zero, &otherunit, NULL) );
     216  CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), helper );
     217};
    167218
    168219/********************************************** Main routine **************************************/
  • src/vectorunittest.hpp

    r658efb ref9df36  
    1111#include <cppunit/extensions/HelperMacros.h>
    1212
     13#include "vector.hpp"
    1314
    1415/********************************************** Test classes **************************************/
     
    2021    CPPUNIT_TEST ( SimpleAlgebraTest );
    2122    CPPUNIT_TEST ( OperatorAlgebraTest );
    22     CPPUNIT_TEST ( EuclidianTest );
     23    CPPUNIT_TEST ( EuclidianScalarProductTest );
     24    CPPUNIT_TEST ( EuclidianNormTest );
     25    CPPUNIT_TEST ( EuclidianDistancesTest );
     26    CPPUNIT_TEST ( EuclidianAnglesTest );
     27    CPPUNIT_TEST ( ProjectionTest );
     28    CPPUNIT_TEST ( LineIntersectionTest );
    2329    CPPUNIT_TEST_SUITE_END();
    2430
     
    3036     void OperatorAlgebraTest();
    3137     void SimpleAlgebraTest();
    32      void EuclidianTest();
     38     void EuclidianScalarProductTest();
     39     void EuclidianNormTest();
     40     void EuclidianDistancesTest();
     41     void EuclidianAnglesTest();
     42     void ProjectionTest();
     43     void LineIntersectionTest();
     44
     45private:
     46     Vector zero;
     47     Vector unit;
     48     Vector otherunit;
     49     Vector notunit;
     50     Vector two;
    3351};
    3452
Note: See TracChangeset for help on using the changeset viewer.