Changed round and renamed length in vector / matrix

This commit is contained in:
Klaus Basan
2013-05-01 00:00:03 +02:00
parent ad6ac0186b
commit 837809b96d
6 changed files with 38 additions and 38 deletions

View File

@@ -9,7 +9,7 @@ int BlackMiscTest::CSamplesVectorMatrix::samples()
{
CVector3D v1;
CVector3D v2(1, 2, 3);
qDebug() << v1 << "value:" << v2[2] << v2.magnitude();
qDebug() << v1 << "value:" << v2[2] << v2.length();
v2 *= v2; // v2 * v2
qDebug() << v2 << 2 * v1 << v1 *v1;

View File

@@ -88,7 +88,7 @@ template<class ImplMatrix, int Rows, int Columns> bool CMatrixBase<ImplMatrix, R
/*
* Round all values
*/
template<class ImplMatrix, int Rows, int Columns> ImplMatrix &CMatrixBase<ImplMatrix, Rows, Columns>::round()
template<class ImplMatrix, int Rows, int Columns> void CMatrixBase<ImplMatrix, Rows, Columns>::round()
{
for (int r = 0; r < Rows; r++)
{
@@ -97,7 +97,6 @@ template<class ImplMatrix, int Rows, int Columns> ImplMatrix &CMatrixBase<ImplMa
this->m_matrix(r, c) = CMath::roundEpsilon(this->m_matrix(r, c), 1E-10);
}
}
return *derived();
}
/*

View File

@@ -35,7 +35,7 @@ protected:
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
ImplMatrix const* derived() const
ImplMatrix const *derived() const
{
return static_cast<ImplMatrix const *>(this);
}
@@ -44,7 +44,7 @@ protected:
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
ImplMatrix* derived()
ImplMatrix *derived()
{
return static_cast<ImplMatrix *>(this);
}
@@ -235,7 +235,8 @@ public:
bool isIdentityEpsilon() const
{
ImplMatrix m = *derived();
return m.round().isIdentity();
m.round();
return m.isIdentity();
}
/*!
@@ -270,7 +271,8 @@ public:
bool isZeroEpsilon() const
{
ImplMatrix m = *derived();
return m.round().isZero();
m.round();
return m.isZero();
}
/*!
@@ -287,9 +289,19 @@ public:
/*!
* \brief Round all values
*/
void round();
/*!
* \brief Return a rounded matrix
* \return
*/
ImplMatrix &round();
ImplMatrix roundedMatrix() const
{
ImplMatrix m = *derived();
m.round();
return m;
}
/*!
* \brief Get element

View File

@@ -65,7 +65,7 @@ protected:
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
ImplVector const* derived() const
ImplVector const *derived() const
{
return static_cast<ImplVector const *>(this);
}
@@ -74,7 +74,7 @@ protected:
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
ImplVector* derived()
ImplVector *derived()
{
return static_cast<ImplVector *>(this);
}
@@ -378,24 +378,6 @@ public:
return v;
}
/*!
* \brief Length
* \return
*/
double length()const
{
return this->m_i + this->m_j + this->m_k;
}
/*!
* \brief Length squared
* \return
*/
double lengthSquared()const
{
return this->m_i * this->m_i + this->m_j * this->m_j + this->m_k * this->m_k;
}
/*!
* \brief Converted to matrix
* \return
@@ -403,25 +385,34 @@ public:
CMatrix3x1 toMatrix3x1() const;
/*!
* \brief Magnitude
* \brief length / magnitude
* \return
*/
double magnitude() const
double length() const
{
return sqrt(this->lengthSquared());
return sqrt(this->m_i * this->m_i + this->m_j * this->m_j + this->m_k * this->m_k);
}
/*!
* \brief Round this vector
* \return
*/
ImplVector &round()
void round()
{
const double epsilon = 1E-10;
this->m_i = BlackMisc::Math::CMath::roundEpsilon(this->m_i, epsilon);
this->m_j = BlackMisc::Math::CMath::roundEpsilon(this->m_j, epsilon);
this->m_k = BlackMisc::Math::CMath::roundEpsilon(this->m_k, epsilon);
return *derived();
}
/*!
* \brief Rounded vector
* \return
*/
ImplVector roundedVector() const
{
ImplVector v = *derived();
v.round();
return v;
}
};

View File

@@ -28,7 +28,7 @@ void CTestGeo::geoBasics()
CCoordinateEcef ecefReconvert = CCoordinateTransformation::toEcef(nedVec);
// check against rounded reconvert
QVERIFY2(mediumEcefVec.round() == ecefReconvert.round(), "Reconverted geo vector should be equal");
QVERIFY2(mediumEcefVec.roundedVector() == ecefReconvert.roundedVector(), "Reconverted geo vector should be equal");
}
} // namespace

View File

@@ -28,9 +28,7 @@ void CTestVectorMatrix::vectorBasics()
CVector3D v7(3, 4, 5);
QVERIFY2(v6.crossProduct(v7) == CVector3D(-2, 4, -2), "Cross product is wrong");
QVERIFY2(v6.dotProduct(v7) == 26, "Dot product is wrong, 26 expected");
QVERIFY2(v6.length() == (1 + 2 + 3), "Wrong vector length");
QVERIFY2(v6.lengthSquared() == (1 + 4 + 9), "Wrong squared vector length");
QVERIFY2(v6.magnitude() == sqrt(1.0 + 4.0 + 9.0), "Wrong vector magnitude");
QVERIFY2(v6.length() == sqrt(1.0 + 4.0 + 9.0), "Wrong vector magnitude");
}
/*