Ignore:
Timestamp:
Aug 18, 2009, 8:48:06 AM (16 years ago)
Author:
Frederik Heber <heber@…>
Children:
66ce7a
Parents:
3de1d2
git-author:
Frederik Heber <heber@…> (08/18/09 08:38:46)
git-committer:
Frederik Heber <heber@…> (08/18/09 08:48:06)
Message:

Incorporation of Unit test on class Vector.

  • new file leastsquaremin.[ch]pp has least square minimisation which is otherwise unclean between classes molecules and Vector

Unit test (later tests rely on good results of earlier ones)

changes to class Vector:

  • Vector::IsNull() -> IsZero()
  • new function Vector::IsOne() similar to IsZero()
  • BUGFIX: Vector::IsNULL() (thx to unit test :)
  • Tesselation::getAngle() changed due to above rename
File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/vector.cpp

    r3de1d2 rda84d6  
    66
    77
    8 #include "molecules.hpp"
    9 
     8#include "defs.hpp"
     9#include "helpers.hpp"
     10#include "leastsquaremin.hpp"
     11#include "vector.hpp"
     12#include "verbose.hpp"
    1013
    1114/************************************ Functions for class vector ************************************/
     
    247250
    248251/** Calculates the intersection of the two lines that are both on the same plane.
    249  * Note that we do not check whether they are 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.
    250253 * \param *out output stream for debugging
    251254 * \param *Line1a first vector of first line
     
    276279  *out << Verbose(3) << "INFO: Normal of plane is " << *Normal << "." << endl;
    277280
    278   // create normal vector to one line
    279   Line.CopyVector(Line1b);
    280   Line.SubtractVector(Line1a);
    281   LineNormal.MakeNormalVector(&Line, Normal);
    282   *out << Verbose(3) << "INFO: Normal of first line is " << LineNormal << "." << endl;
    283 
    284281  // check if lines are parallel
    285282  helper.CopyVector(Line2b);
    286283  helper.SubtractVector(Line2a);
    287   if (fabs(helper.ScalarProduct(&LineNormal)) < MYEPSILON) {
     284  if (fabs(helper.ScalarProduct(Normal)) < MYEPSILON) {
    288285    *out << Verbose(1) << "Lines " << helper << " and " << Line << " are parallel, no cross point!" << endl;
    289286    result = false;
     
    291288    helper.CopyVector(Line2a);
    292289    helper.SubtractVector(Line1a);
    293     factor1 = helper.ScalarProduct(&LineNormal);
     290    factor1 = helper.ScalarProduct(Normal);
    294291    helper.CopyVector(Line2b);
    295292    helper.SubtractVector(Line1a);
    296     factor2 = helper.ScalarProduct(&LineNormal);
     293    factor2 = helper.ScalarProduct(Normal);
    297294    if (fabs(factor2) > MYEPSILON) {
    298295      CopyVector(Line2a);
     
    380377 * @return true - vector is zero, false - vector is not
    381378 */
    382 bool Vector::IsNull() const
    383 {
    384   return (fabs(x[0]+x[1]+x[2]) < MYEPSILON);
     379bool Vector::IsZero() const
     380{
     381  return (fabs(x[0])+fabs(x[1])+fabs(x[2]) < MYEPSILON);
     382};
     383
     384/** Checks whether vector has length of 1.
     385 * @return true - vector is normalized, false - vector is not
     386 */
     387bool Vector::IsOne() const
     388{
     389  return (fabs(Norm() - 1.) < MYEPSILON);
    385390};
    386391
     
    437442  return a;
    438443};
     444
     445/** Subtracts vector \a from this lhs component-wise.
     446 * \param a base vector
     447 * \param b vector components to add
     448 * \return lhs - a
     449 */
     450Vector& operator-=(Vector& a, const Vector& b)
     451{
     452  a.SubtractVector(&b);
     453  return a;
     454};
     455
    439456/** factor each component of \a a times a double \a m.
    440457 * \param a base vector
     
    461478};
    462479
     480/** Subtracts vector \a from \b component-wise.
     481 * \param a first vector
     482 * \param b second vector
     483 * \return a - b
     484 */
     485Vector& operator-(const Vector& a, const Vector& b)
     486{
     487  Vector *x = new Vector;
     488  x->CopyVector(&a);
     489  x->SubtractVector(&b);
     490  return *x;
     491};
     492
    463493/** Factors given vector \a a times \a m.
    464494 * \param a vector
    465495 * \param m factor
    466  * \return a + b
     496 * \return m * a
    467497 */
    468498Vector& operator*(const Vector& a, const double m)
     499{
     500  Vector *x = new Vector;
     501  x->CopyVector(&a);
     502  x->Scale(m);
     503  return *x;
     504};
     505
     506/** Factors given vector \a a times \a m.
     507 * \param m factor
     508 * \param a vector
     509 * \return m * a
     510 */
     511Vector& operator*(const double m, const Vector& a )
    469512{
    470513  Vector *x = new Vector;
Note: See TracChangeset for help on using the changeset viewer.