Implemented commutative multiplications as friends in the templates, further test cases (unit tests), fixed Doxygen attributes, renamed test classes

This commit is contained in:
Klaus Basan
2013-04-25 01:56:18 +02:00
parent 919913dd95
commit a31e405b6b
22 changed files with 197 additions and 88 deletions

View File

@@ -124,7 +124,7 @@ public:
/*!
* \brief Set longitude
* \param latitude
* \param longitude
*/
void setLongitude(CLongitude longitude)
{

View File

@@ -70,29 +70,24 @@ CCoordinateEcef CCoordinateTransformation::toEcef(const CCoordinateGeodetic &geo
CLatitude lat = geo.latitude();
CLongitude lon = geo.longitude();
double latDeg = lat.value(CAngleUnit::deg());
double lonDeg = lon.value(CAngleUnit::deg());
double phi = lat.value(CAngleUnit::rad());
double lambdaRad = lon.value(CAngleUnit::rad());
double sphi = sin(phi);
double cphi = 0;
if (abs(latDeg) != 90) cphi = cos(phi);
double cphi = cos(phi);
double n = EarthRadiusMeters() / sqrt(1 - e2() * CMath::square(sphi));
double slambda = 0;
if (lonDeg != -180) slambda = sin(lambdaRad);
double slambda = sin(lambdaRad);
double clambda = 0;
if (abs(lonDeg) != 90) clambda = cos(lambdaRad);
double clambda = cos(lambdaRad);
double h = geo.height().convertedSiValueToDouble();
double X = (n + h) * cphi;
double Y = X * slambda;
X *= clambda;
double Z = (e2m() * n + h) * sphi;
CCoordinateEcef result(X, Y, Z);
double x = (n + h) * cphi;
double y = x * slambda;
x *= clambda;
double z = (e2m() * n + h) * sphi;
CCoordinateEcef result(x, y, z);
return result;
}

View File

@@ -121,7 +121,7 @@ public:
/*!
* \brief ECEF to Geodetic
* \param geo
* \param ecef
* \return
*/
static CCoordinateGeodetic toGeodetic(const CCoordinateEcef &ecef);

View File

@@ -27,7 +27,7 @@ public:
/*!
* \brief Copy constructor
* \param other
* \param otherMatrix
*/
CMatrix1x3(const CMatrix1x3 &otherMatrix) : CMatrixBase(otherMatrix) {}

View File

@@ -42,7 +42,7 @@ public:
/*!
* \brief Copy constructor
* \param other
* \param otherMatrix
*/
CMatrix3x1(const CMatrix3x1 &otherMatrix) : CMatrixBase(otherMatrix) {}

View File

@@ -26,7 +26,7 @@ public:
/*!
* \brief Copy constructor
* \param other
* \param otherMatrix
*/
CMatrix3x3(const CMatrix3x3 &otherMatrix) : CMatrixBase(otherMatrix) {}
@@ -101,7 +101,7 @@ public:
/*!
* \brief Operator *
* \param multiply
* \param otherMatrix
* \return
*/
CMatrix3x3 operator *(const CMatrix3x3 &otherMatrix) const

View File

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

View File

@@ -39,7 +39,7 @@ public:
/*!
* \brief Copy constructor
* \param other
* \param otherMatrix
*/
CMatrixBase(const CMatrixBase &otherMatrix) : m_matrix(otherMatrix.m_matrix) {}
@@ -81,7 +81,7 @@ public:
/*!
* \brief Assigment operator =
* \param multiply
* \param otherMatrix
* \return
*/
CMatrixBase &operator =(const CMatrixBase &otherMatrix)
@@ -116,11 +116,22 @@ public:
}
/*!
* \brief Multiply with 3D vector operator *
* \param vector
* \brief Operator to support commutative multiplication
* \param factor
* \param otherMatrix
* \return
*/
template<class ImplVector> ImplVector operator*(const ImplVector vector) const;
friend ImplMatrix operator *(double factor, const ImplMatrix &otherMatrix)
{
return otherMatrix * factor;
}
/*!
* \brief Multiply with 3D vector operator *
* \param matrix
* \return
*/
template<class ImplVector> ImplVector operator*(const ImplVector matrix) const;
/*!
* \brief Operator /=
@@ -267,7 +278,7 @@ public:
/*!
* \brief Round all values
*/
void round();
ImplMatrix &round();
/*!
* \brief Get element
@@ -286,7 +297,8 @@ public:
void setElement(size_t row, size_t column, double value);
/*!
* \brief Get element by ()
* \brief Get element by operator () modifying
* \param row
* \param column
* \return
*/
@@ -297,7 +309,8 @@ public:
}
/*!
* \brief Get element by ()
* \brief Get element by operator () read only
* \param row
* \param column
* \return
*/

View File

@@ -33,7 +33,7 @@ protected:
/*!
* \brief Default constructor
*/
CVector3DBase() {}
CVector3DBase() : m_i(0.0), m_j(0.0), m_k(0.0) {}
/*!
* \brief Constructor by values
@@ -124,8 +124,8 @@ public:
/*!
* \brief Get element by ()
* \param column
* \brief Get row element by ()
* \param row
* \return
*/
double operator()(size_t row) const { return this->getElement(row); }
@@ -272,6 +272,17 @@ public:
return v;
}
/*!
* \brief Operator to support commutative multiplication
* \param factor
* \param otherVector
* \return
*/
friend ImplClass operator *(double factor, const ImplClass &otherVector)
{
return otherVector * factor;
}
/*!
* \brief Divide by scalar
* \param divisor
@@ -346,8 +357,7 @@ public:
void matrixMultiplication(const CMatrix3x3 &matrix);
/*!
* \brief Reciporcal value
* \param otherVector
* \brief Reciprocal value
* \return
*/
ImplClass reciprocalValues() const
@@ -394,15 +404,16 @@ public:
/*!
* \brief Round this vector
* \return
*/
void round()
ImplClass &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 static_cast<ImplClass &>(*this);
}
};
} // namespace

View File

@@ -219,7 +219,7 @@ public:
qint32 convertedSiValueToInteger() const
{
return static_cast<qint32>(
BlackMisc::Math::CMath::round(this->m_convertedSiUnitValueD, 0));
BlackMisc::Math::CMath::round(this->m_convertedSiUnitValueD, 0));
}
/*!
@@ -257,11 +257,11 @@ public:
*/
void substractUnitValue(double value);
/*!
* \brief Multiply operator *=
* \param multiply
* \return
*/
/*!
* \brief Multiply operator *=
* \param multiply
* \return
*/
CPhysicalQuantity &operator *=(double multiply);
/*!
@@ -278,6 +278,17 @@ public:
*/
PQ operator *(double multiply) const;
/*!
* \brief Operator to support commutative multiplication
* \param factor
* \param otherQuantity
* \return
*/
friend PQ operator *(double factor, const PQ &otherQuantity)
{
return otherQuantity * factor;
}
/*!
* \brief Operator /
* \param divide