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

@@ -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;
}
};