diff --git a/samples/blackmiscdbus/servicetool.cpp b/samples/blackmiscdbus/servicetool.cpp index 9de20dfe8..93d0e7f7f 100644 --- a/samples/blackmiscdbus/servicetool.cpp +++ b/samples/blackmiscdbus/servicetool.cpp @@ -345,12 +345,6 @@ namespace BlackMiscTest testserviceInterface.receiveAtcStation(station); qDebug() << "Send ATC" << station; - // Math - CMatrix3x3 m33; - m33.setCellIndex(); - testserviceInterface.receiveMatrix(m33); - qDebug() << "Send matrix" << m33; - // Geo // EDDF: 50° 2′ 0″ N, 8° 34′ 14″ E, 100m MSL geoPos = CCoordinateGeodetic::fromWgs84("50° 2′ 1″ 23 N", "8° 34′ 14″ E", CLength(111, CLengthUnit::m())); diff --git a/samples/blackmiscdbus/testservice.cpp b/samples/blackmiscdbus/testservice.cpp index 12463442f..12c26d055 100644 --- a/samples/blackmiscdbus/testservice.cpp +++ b/samples/blackmiscdbus/testservice.cpp @@ -99,14 +99,6 @@ namespace BlackMiscTest qDebug() << "Pid:" << ServiceTool::getPid() << "Received altitude:" << altitude; } - /* - * Receive matrix - */ - void Testservice::receiveMatrix(const BlackMisc::Math::CMatrix3x3 &matrix) - { - qDebug() << "Pid:" << ServiceTool::getPid() << "Received matrix:" << matrix; - } - /* * Receive a list */ diff --git a/samples/blackmiscdbus/testservice.h b/samples/blackmiscdbus/testservice.h index 93c06c8b5..a153a6b74 100644 --- a/samples/blackmiscdbus/testservice.h +++ b/samples/blackmiscdbus/testservice.h @@ -67,9 +67,6 @@ namespace BlackMiscTest //! Receive altitude void receiveAltitude(const BlackMisc::Aviation::CAltitude &altitude); - //! Receive matrix - void receiveMatrix(const BlackMisc::Math::CMatrix3x3 &matrix); - //! Receive list void receiveList(const QList &list); diff --git a/samples/blackmiscdbus/testservice_interface.h b/samples/blackmiscdbus/testservice_interface.h index 754138f61..f30e4d5cc 100644 --- a/samples/blackmiscdbus/testservice_interface.h +++ b/samples/blackmiscdbus/testservice_interface.h @@ -242,13 +242,6 @@ namespace BlackMiscTest return asyncCallWithArgumentList(QLatin1String("receiveList"), argumentList); } - inline QDBusPendingReply<> receiveMatrix(BlackMisc::Math::CMatrix3x3 matrix) - { - QList argumentList; - argumentList << QVariant::fromValue(matrix); - return asyncCallWithArgumentList(QLatin1String("receiveMatrix"), argumentList); - } - inline QDBusPendingReply<> receiveSpeed(BlackMisc::PhysicalQuantities::CSpeed speed) { QList argumentList; diff --git a/samples/blackmiscvectorgeo/main.cpp b/samples/blackmiscvectorgeo/main.cpp index 8c5b53941..8418e457e 100644 --- a/samples/blackmiscvectorgeo/main.cpp +++ b/samples/blackmiscvectorgeo/main.cpp @@ -3,7 +3,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "samplesvectormatrix.h" #include "samplesgeo.h" #include "samplesgeodetictoecef.h" #include @@ -17,7 +16,6 @@ int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); - BlackMiscTest::CSamplesVectorMatrix::samples(); BlackMiscTest::CSamplesGeo::samples(); BlackMiscTest::CSamplesGeodeticToEcef::samples(); return a.exec(); diff --git a/samples/blackmiscvectorgeo/samplesvectormatrix.cpp b/samples/blackmiscvectorgeo/samplesvectormatrix.cpp deleted file mode 100644 index 2423da9a0..000000000 --- a/samples/blackmiscvectorgeo/samplesvectormatrix.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "samplesvectormatrix.h" - -using namespace BlackMisc::Math; - -/* - * Run the samples - */ -int BlackMiscTest::CSamplesVectorMatrix::samples() -{ - CVector3D v1; - CVector3D v2(1, 2, 3); - qDebug() << v1 << "value:" << v2[2] << v2.length(); - qDebug() << v2 << (2 * v1); - - CMatrix3x3 m; - CMatrix3x3 mr = m; - qDebug() << m << mr; - bool im; - CMatrix3x3 mi = mr.inverse(im); - CMatrix3x3 mid = mr * mi; - qDebug() << mr << mi << mid << im; - - // bye - qDebug() << "-----------------------------------------------"; - return 0; - -} diff --git a/samples/blackmiscvectorgeo/samplesvectormatrix.h b/samples/blackmiscvectorgeo/samplesvectormatrix.h deleted file mode 100644 index 2af44df54..000000000 --- a/samples/blackmiscvectorgeo/samplesvectormatrix.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef BLACKMISCTEST_SAMPLESVECTORMATRIX_H -#define BLACKMISCTEST_SAMPLESVECTORMATRIX_H - -#include "blackmisc/mathvector3d.h" -#include "blackmisc/mathmatrix3x3.h" - -namespace BlackMiscTest -{ - -/*! - * \brief Samples for vector / matrix - */ -class CSamplesVectorMatrix -{ -public: - /*! - * \brief Run the samples - */ - static int samples(); - -private: - /*! - * \brief Avoid init - */ - CSamplesVectorMatrix(); -}; -} // namespace - -#endif // guard diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index 049f6cc26..43d9246fe 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -34,10 +34,6 @@ */ void BlackMisc::Math::registerMetadata() { - CMatrix3x3::registerMetadata(); - CMatrix3x1::registerMetadata(); - CMatrix1x3::registerMetadata(); - CVector3D::registerMetadata(); } /* diff --git a/src/blackmisc/coordinategeodetic.h b/src/blackmisc/coordinategeodetic.h index 81b6a73a9..4ce5d4566 100644 --- a/src/blackmisc/coordinategeodetic.h +++ b/src/blackmisc/coordinategeodetic.h @@ -12,7 +12,6 @@ #ifndef BLACKMISC_COORDINATEGEODETIC_H #define BLACKMISC_COORDINATEGEODETIC_H -#include "blackmisc/mathvector3dbase.h" #include "blackmisc/geolatitude.h" #include "blackmisc/geolongitude.h" #include "blackmisc/pqlength.h" diff --git a/src/blackmisc/mathmatrix1x3.h b/src/blackmisc/mathmatrix1x3.h deleted file mode 100644 index 3432227e5..000000000 --- a/src/blackmisc/mathmatrix1x3.h +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKMISC_POSMATRIX1x3_H -#define BLACKMISC_POSMATRIX1x3_H - -#include "blackmisc/mathmatrixbase.h" -#include "blackmisc/mathvector3d.h" - -namespace BlackMisc -{ - namespace Math - { - - //! Matrix 1x3 - class CMatrix1x3 : public CValueObject> - { - public: - - //! Constructor - CMatrix1x3() = default; - - //! Init by fill value - explicit CMatrix1x3(double fillValue) : CValueObject(fillValue) {} - - //! Constructor - CMatrix1x3(double c1, double c2, double c3) - { - this->m_matrix(0, 0) = c1; - this->m_matrix(0, 1) = c2; - this->m_matrix(0, 2) = c3; - } - }; - - } -} - -Q_DECLARE_METATYPE(BlackMisc::Math::CMatrix1x3) - -#endif // guard diff --git a/src/blackmisc/mathmatrix3x1.h b/src/blackmisc/mathmatrix3x1.h deleted file mode 100644 index b002b986f..000000000 --- a/src/blackmisc/mathmatrix3x1.h +++ /dev/null @@ -1,65 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKMISC_POSMATRIX3X1_H -#define BLACKMISC_POSMATRIX3X1_H - -#include "blackmisc/mathmatrixbase.h" -#include "blackmisc/mathvector3d.h" - -namespace BlackMisc -{ - namespace Math - { - - class CMatrix3x3; - - //! Matrix 3x1 - class CMatrix3x1 : public CValueObject> - { - friend class CMatrix3x3; - - public: - //! Constructor - CMatrix3x1() = default; - - //! Constructor - CMatrix3x1(double r1, double r2, double r3) - { - this->m_matrix(0, 0) = r1; - this->m_matrix(1, 0) = r2; - this->m_matrix(2, 0) = r3; - } - - //! Init by fill value - explicit CMatrix3x1(double fillValue) : CValueObject(fillValue) {} - - //! Convert to vector - CVector3D toVector3D() const - { - return CVector3D(this->getElement(0, 0), this->getElement(1, 0), this->getElement(2, 0)); - } - - //! Convert from vector - void fromVector3D(const CVector3D &vector) - { - this->m_matrix(0, 0) = vector.i(); - this->m_matrix(1, 0) = vector.j(); - this->m_matrix(2, 0) = vector.k(); - } - }; - - } -} - -Q_DECLARE_METATYPE(BlackMisc::Math::CMatrix3x1) - -#endif // guard diff --git a/src/blackmisc/mathmatrix3x3.cpp b/src/blackmisc/mathmatrix3x3.cpp deleted file mode 100644 index 3f8e5e37a..000000000 --- a/src/blackmisc/mathmatrix3x3.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "blackmisc/mathmatrix3x3.h" - -namespace BlackMisc -{ - namespace Math - { - - /* - * Determinant - */ - double CMatrix3x3::determinant() const - { - return - this->m_matrix(0, 0) * this->m_matrix(1, 1) * this->m_matrix(2, 2) + - this->m_matrix(0, 1) * this->m_matrix(1, 2) * this->m_matrix(2, 0) + - this->m_matrix(0, 2) * this->m_matrix(1, 0) * this->m_matrix(2, 1) - - this->m_matrix(0, 1) * this->m_matrix(1, 0) * this->m_matrix(2, 2) - - this->m_matrix(0, 2) * this->m_matrix(1, 1) * this->m_matrix(2, 0) - - this->m_matrix(0, 0) * this->m_matrix(1, 2) * this->m_matrix(2, 1); - } - - /* - * Inverse - */ - CMatrix3x3 CMatrix3x3::inverse(bool &o_invertible) const - { - CMatrix3x3 inverse; - double det = this->determinant(); - if (det == 0) - { - o_invertible = false; - inverse.setZero(); - return inverse; - } - double invdet = 1.0 / det; - - inverse.m_matrix(0, 0) = (this->m_matrix(1, 1) * this->m_matrix(2, 2) - this->m_matrix(1, 2) * this->m_matrix(2, 1)) * invdet; - inverse.m_matrix(0, 1) = (- this->m_matrix(0, 1) * this->m_matrix(2, 2) + this->m_matrix(0, 2) * this->m_matrix(2, 1)) * invdet; - inverse.m_matrix(0, 2) = (this->m_matrix(0, 1) * this->m_matrix(1, 2) - this->m_matrix(0, 2) * this->m_matrix(1, 1)) * invdet; - inverse.m_matrix(1, 0) = (- this->m_matrix(1, 0) * this->m_matrix(2, 2) + this->m_matrix(1, 2) * this->m_matrix(2, 0)) * invdet; - inverse.m_matrix(1, 1) = (this->m_matrix(0, 0) * this->m_matrix(2, 2) - this->m_matrix(0, 2) * this->m_matrix(2, 0)) * invdet; - inverse.m_matrix(1, 2) = (- this->m_matrix(0, 0) * this->m_matrix(1, 2) + this->m_matrix(0, 2) * this->m_matrix(1, 0)) * invdet; - inverse.m_matrix(2, 0) = (this->m_matrix(1, 0) * this->m_matrix(2, 1) - this->m_matrix(1, 1) * this->m_matrix(2, 0)) * invdet; - inverse.m_matrix(2, 1) = (- this->m_matrix(0, 0) * this->m_matrix(2, 1) + this->m_matrix(0, 1) * this->m_matrix(2, 0)) * invdet; - inverse.m_matrix(2, 2) = (this->m_matrix(0, 0) * this->m_matrix(1, 1) - this->m_matrix(0, 1) * this->m_matrix(1, 0)) * invdet; - - o_invertible = true; - return inverse; - } - - /* - * Get a row - */ - CMatrix1x3 CMatrix3x3::getRow(int row) const - { - bool valid = row >= 0 && row <= 3; - Q_ASSERT_X(valid, "getRow", "invalid row"); - if (!valid) throw std::range_error("invalid row"); - return CMatrix1x3(this->getElement(row, 0), this->getElement(row, 1), this->getElement(row, 2)); - } - - /* - * Get a column - */ - CMatrix3x1 CMatrix3x3::getColumn(int column) const - { - bool valid = column >= 0 && column <= 3; - Q_ASSERT_X(valid, "getColumn", "invalid column"); - if (!valid) throw new std::range_error("invalid column"); - return CMatrix3x1(this->getElement(0, column), this->getElement(1, column), this->getElement(2, column)); - } - - - } // namespace -} // namespace diff --git a/src/blackmisc/mathmatrix3x3.h b/src/blackmisc/mathmatrix3x3.h deleted file mode 100644 index 1e71e553e..000000000 --- a/src/blackmisc/mathmatrix3x3.h +++ /dev/null @@ -1,120 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKMISC_POSMATRIX3X3_H -#define BLACKMISC_POSMATRIX3X3_H - -#include "blackmisc/mathmatrix1x3.h" -#include "blackmisc/mathmatrix3x1.h" -#include - -namespace BlackMisc -{ - namespace Math - { - - //! 3x3 matrix - class CMatrix3x3 : public CValueObject> - { - public: - //! Constructor - CMatrix3x3() = default; - - //! Init by fill value - explicit CMatrix3x3(double fillValue) : CValueObject(fillValue) {} - - //! Stupid, but handy constructor by single row column values - explicit CMatrix3x3(double r1c1, double r1c2, double r1c3, - double r2c1, double r2c2, double r2c3, - double r3c1, double r3c2, double r3c3) - { - this->setElement(0, 0, r1c1); - this->setElement(0, 1, r1c2); - this->setElement(0, 2, r1c3); - this->setElement(1, 0, r2c1); - this->setElement(1, 1, r2c2); - this->setElement(1, 2, r2c3); - this->setElement(2, 0, r3c1); - this->setElement(2, 1, r3c2); - this->setElement(2, 2, r3c3); - } - - //! Calculates the determinant of the matrix - double determinant() const; - - //! Calculate the inverse and mark flag if successful - CMatrix3x3 inverse(bool &o_isInvertible) const; - - //! Operator *= - CMatrix3x3 &operator *=(const CMatrix3x3 &other) - { - this->m_matrix = this->m_matrix * other.m_matrix; - return *this; - } - - //! Operator * - CMatrix3x3 operator *(const CMatrix3x3 &other) const - { - CMatrix3x3 m(*this); - m *= other; - return m; - } - - //! Operator * - CMatrix3x1 operator *(const CMatrix3x1 &other) const - { - CMatrix3x1 m; - m.m_matrix = this->m_matrix * other.m_matrix; - return m; - } - - //! Multiply this matrix with vector - CVector3D operator *(const CVector3D &vector) const - { - return ((*this) * CMatrix3x1(vector.toMatrix3x1())).toVector3D(); - } - - //! Multiply with factor - CMatrix3x3 &operator *=(double factor) - { - this->CMatrixBase::operator *=(factor); - return *this; - } - - //! Multiply with factor - CMatrix3x3 operator *(double factor) const - { - CMatrix3x3 m(*this); - m *= factor; - return m; - } - - //! Transposed matrix - CMatrix3x3 transposed() const - { - CMatrix3x3 m(0); - m.m_matrix = this->m_matrix.transposed(); - return m; - } - - //! Get column - CMatrix3x1 getColumn(int column) const; - - //! Get row - CMatrix1x3 getRow(int row) const; - }; - - } -} - -Q_DECLARE_METATYPE(BlackMisc::Math::CMatrix3x3) - -#endif // guard diff --git a/src/blackmisc/mathmatrixbase.cpp b/src/blackmisc/mathmatrixbase.cpp deleted file mode 100644 index e7d739a95..000000000 --- a/src/blackmisc/mathmatrixbase.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / authors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "blackmisc/mathmatrix3x3.h" -#include "blackmisc/mathmatrix3x1.h" -#include "blackmisc/blackmiscfreefunctions.h" -#include -#include - -namespace BlackMisc -{ - namespace Math - { - - /* - * Get element by column / row - */ - template double CMatrixBase::getElement(int row, int column) const - { - this->checkRange(row, column); - return this->m_matrix(row, column); - } - - /* - * Set element by column / row - */ - template void CMatrixBase::setElement(int row, int column, double value) - { - this->checkRange(row, column); - this->m_matrix(row, column) = value; - } - - /* - * Check range - */ - template void CMatrixBase::checkRange(int row, int column) const - { - bool valid = (row < Rows && column < Columns); - Q_ASSERT_X(valid, "getElement()", "Row or column invalid"); - if (!valid) throw std::range_error("Row or column invalid"); - } - - /* - * All values zero? - */ - template bool CMatrixBase::isZero() const - { - for (int r = 0; r < Rows; r++) - { - for (int c = 0; c < Columns; c++) - { - if (this->m_matrix(r, c) != 0) return false; - } - } - return true; - } - - - /* - * Set cell index - */ - template void CMatrixBase::setCellIndex() - { - for (int r = 0; r < Rows; r++) - { - for (int c = 0; c < Columns; c++) - { - this->m_matrix(r, c) = r + 0.1 * c; - } - } - } - - /* - * To list - */ - template QList CMatrixBase::toList() const - { - QList list; - for (int r = 0; r < Rows; r++) - { - for (int c = 0; c < Columns; c++) - { - list.append(this->m_matrix(r, c)); - } - } - return list; - } - - /* - * From list - */ - template void CMatrixBase::fromList(const QList &list) - { - Q_ASSERT_X(Rows * Columns == list.count(), "fromList()", "Mismatch of elements in list"); - int ct = 0; - for (int r = 0; r < Rows; r++) - { - for (int c = 0; c < Columns; c++) - { - this->m_matrix(r, c) = list.at(ct++); - } - } - } - - /* - * Round all values - */ - template void CMatrixBase::round() - { - for (int r = 0; r < Rows; r++) - { - for (int c = 0; c < Columns; c++) - { - this->m_matrix(r, c) = CMath::roundEpsilon(this->m_matrix(r, c), 1E-10); - } - } - } - - /* - * Convert to string - */ - template QString CMatrixBase::convertToQString(bool /* i18n */) const - { - QString s = "{"; - for (int r = 0; r < Rows; r++) - { - s = s.append("{"); - for (int c = 0; c < Columns; c++) - { - QString n = QString::number(this->m_matrix(r, c), 'f', 2); - if (c > 0) s = s.append(","); - s = s.append(n); - } - s = s.append("}"); - } - s = s.append("}"); - return s; - } - - /* - * Compare - */ - template int CMatrixBase::compareImpl(const ImplMatrix &a, const ImplMatrix &b) - { - for (int r = 0; r < Rows; ++r) - { - for (int c = 0; c < Columns; ++c) - { - if (a.m_matrix(r, c) < b.m_matrix(r, c)) { return -1; } - if (a.m_matrix(r, c) > b.m_matrix(r, c)) { return 1; } - } - } - return 0; - } - - /* - * Hash - */ - template uint CMatrixBase::getValueHash() const - { - const QList l = this->toList(); - QList hashs; - - // there is an issue with the signature of QList, so I use - // individual values - foreach(double v, l) - { - hashs << qHash(static_cast(v)); - } - return BlackMisc::calculateHash(hashs, "CMatrixBase"); - } - - /* - * To DBus - */ - template void CMatrixBase::marshallToDbus(QDBusArgument &argument) const - { - const QList l = this->toList(); - - // there is an issue with the signature of QList, so I use - // individual values - foreach(double v, l) - { - argument << v; - } - } - - /* - * From DBus - */ - template void CMatrixBase::unmarshallFromDbus(const QDBusArgument &argument) - { - QList list; - double v; - while (!argument.atEnd()) - { - argument >> v; - list.append(v); - } - this->fromList(list); - } - - /* - * To JSON - */ - template QJsonObject CMatrixBase::toJson() const - { - QJsonObject json; - QJsonArray jsonArray; - foreach(double v, this->toList()) - { - jsonArray.append(QJsonValue(v)); - } - json.insert("matrix", QJsonValue(jsonArray)); - return json; - } - - /* - * From Json - */ - template void CMatrixBase::convertFromJson(const QJsonObject &json) - { - QJsonArray jsonArray = json.value("matrix").toArray(); - QList list; - for (auto i = jsonArray.begin(); i != jsonArray.end(); ++i) - { - list.append((*i).toDouble()); - } - this->fromList(list); - } - - // see here for the reason of these forward instantiations - // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html - template class CMatrixBase; - template class CMatrixBase; - template class CMatrixBase; - - } // namespace -} // namespace diff --git a/src/blackmisc/mathmatrixbase.h b/src/blackmisc/mathmatrixbase.h deleted file mode 100644 index c13d0d449..000000000 --- a/src/blackmisc/mathmatrixbase.h +++ /dev/null @@ -1,252 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BLACKMISC_MATHMATRIXBASE_H -#define BLACKMISC_MATHMATRIXBASE_H - -//! \file - -#include "blackmisc/valueobject.h" -#include "blackmisc/mathvector3dbase.h" -#include "blackmisc/blackmiscfreefunctions.h" -#include - -namespace BlackMisc -{ - namespace Math { template class CMatrixBase; } - - //! \private - template struct CValueObjectPolicy> : public CValueObjectPolicy<> - { - using Equals = Policy::Equals::None; - using LessThan = Policy::LessThan::None; - using Compare = Policy::Compare::None; - using Hash = Policy::Hash::Own; - using DBus = Policy::DBus::Own; - using Json = Policy::Json::Own; - }; - - namespace Math - { - - /*! - * \brief Base functionality of a matrix - */ - template class CMatrixBase : public CValueObject> - { - //! \copydoc CValueObject::compare - friend int compare(const ImplMatrix &a, const ImplMatrix &b) { return compareImpl(a, b); } - - public: - //! \brief Default constructor - CMatrixBase() = default; - - //! \brief Fill with value - explicit CMatrixBase(double fillValue) - { - this->fill(fillValue); - } - - //! \brief List of values - QList toList() const; - - //! \brief List of values - void fromList(const QList &list); - - //! \copydoc CValueObject::getValueHash - virtual uint getValueHash() const override; - - //! \brief Equal operator == - bool operator ==(const ImplMatrix &other) const - { - if (this == &other) return true; - return this->m_matrix == other.m_matrix; - } - - //! \brief Unequal operator != - bool operator !=(const ImplMatrix &other) const - { - return !((*this) == other); - } - - //! \brief Operator *= - CMatrixBase &operator *=(double factor) - { - this->m_matrix *= factor; - return *this; - } - - //! \brief Operator * - ImplMatrix operator *(double factor) const - { - ImplMatrix m = *derived(); - m *= factor; - return m; - } - - //! \brief Operator to support commutative scalar multiplication - friend ImplMatrix operator *(double factor, const ImplMatrix &other) - { - return other * factor; - } - - //! \brief Operator /= - CMatrixBase &operator /=(double factor) - { - this->m_matrix /= factor; - return *this; - } - - //! \brief Operator / - ImplMatrix operator /(double factor) const - { - ImplMatrix m = *derived(); - m /= factor; - return m; - } - - //! \brief Operator += - CMatrixBase &operator +=(const CMatrixBase &other) - { - this->m_matrix += other.m_matrix; - return *this; - } - - //! \brief Operator + - ImplMatrix operator +(const ImplMatrix &other) const - { - ImplMatrix m = *derived(); - m += other; - return m; - } - - //! \brief Operator -= - CMatrixBase &operator -=(const CMatrixBase &other) - { - this->m_matrix -= other.m_matrix; - return *this; - } - - //! \brief Operator - - ImplMatrix operator -(const ImplMatrix &other) const - { - ImplMatrix m = *derived(); - m -= other; - return m; - } - - //! \brief Is identity matrix? - bool isIdentity() const - { - return this->m_matrix.isIdentity(); - } - - //! \brief Is identity matrix? Epsilon considered. - bool isIdentityEpsilon() const - { - ImplMatrix m = *derived(); - m.round(); - return m.isIdentity(); - } - - //! \brief Set as identity matrix - void setToIdentity() - { - this->m_matrix.setToIdentity(); - } - - //! \brief All values to zero - void setZero() { this->m_matrix.fill(0.0); } - - //! \brief Is zero? - bool isZero() const; - - //! \brief Is zero matrix? Epsilon considered. - bool isZeroEpsilon() const - { - ImplMatrix m = *derived(); - m.round(); - return m.isZero(); - } - - //! \brief Each cell gets a unique index (used primarily for testing) - void setCellIndex(); - - //! \brief Set all elements the same - void fill(double value) { this->m_matrix.fill(value); } - - //! \brief Round all values - void round(); - - //! \brief Return a rounded matrix - ImplMatrix roundedMatrix() const - { - ImplMatrix m = *derived(); - m.round(); - return m; - } - - //! \brief Get element - double getElement(int row, int column) const; - - //! \brief Set element - void setElement(int row, int column, double value); - - //! \brief Get element by operator () modifying - double &operator()(int row, int column) - { - this->checkRange(row, column); - return this->m_matrix(row, column); - } - - //! \brief Get element by operator () read only - double operator()(int row, int column) const - { - return this->getElement(row, column); - } - - //! \copydoc CValueObject::toJson - virtual QJsonObject toJson() const override; - - //! \copydoc CValueObject::convertFromJson - virtual void convertFromJson(const QJsonObject &json) override; - - protected: - // no bug, Qt expects columns rows - QGenericMatrix m_matrix; //!< backing data - - //! \copydoc CValueObject::marshallToDbus - virtual void marshallToDbus(QDBusArgument &argument) const override; - - //! \copydoc CValueObject::unmarshallFromDbus - virtual void unmarshallFromDbus(const QDBusArgument &argument) override; - - //! \copydoc CValueObject::convertToQString - virtual QString convertToQString(bool i18n = false) const override; - - private: - //! \brief Easy access to derived class (CRTP template parameter) - ImplMatrix const *derived() const - { - return static_cast(this); - } - - //! \brief Easy access to derived class (CRTP template parameter) - ImplMatrix *derived() - { - return static_cast(this); - } - - //! \brief Check range of row / column - void checkRange(int row, int column) const; - - //! Implementation of compare - static int compareImpl(const ImplMatrix &, const ImplMatrix &); - }; - - } // namespace -} // namespace - -#endif // guard diff --git a/src/blackmisc/mathvector3d.h b/src/blackmisc/mathvector3d.h deleted file mode 100644 index b52eac867..000000000 --- a/src/blackmisc/mathvector3d.h +++ /dev/null @@ -1,108 +0,0 @@ -/* Copyright (C) 2013 - * swift project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#ifndef BLACKMISC_MATHVECTOR3D_H -#define BLACKMISC_MATHVECTOR3D_H - -//! \file - -#include "blackmisc/mathvector3dbase.h" - -namespace BlackMisc -{ - namespace Math { class CVector3D; } - - //! \private - template <> struct CValueObjectPolicy : public CValueObjectPolicy<> - { - using Compare = Policy::Compare::None; - using Hash = Policy::Hash::Own; - using DBus = Policy::DBus::Own; - using Json = Policy::Json::Own; - }; - - namespace Math - { - - /*! - * \brief Concrete vector implementation - */ - class CVector3D : public CValueObject> - { - public: - /*! - * \brief Default constructor - */ - CVector3D() = default; - - /*! - * \brief Constructor by value - */ - CVector3D(double i, double j, double k) : CValueObject(i, j, k) {} - - /*! - * \brief Constructor by value - */ - explicit CVector3D(double value) : CValueObject(value) {} - - /*! - * \brief i - */ - double i() const - { - return this->m_i; - } - - /*! - * \brief j - */ - double j() const - { - return this->m_j; - } - - /*! - * \brief k - */ - double k() const - { - return this->m_k; - } - - /*! - * \brief Set i - */ - void setI(double i) - { - this->m_i = i; - } - - /*! - * \brief Set j - */ - void setJ(double j) - { - this->m_j = j; - } - - /*! - * \brief Set k - */ - void setK(double k) - { - this->m_k = k; - } - }; - - } -} - -Q_DECLARE_METATYPE(BlackMisc::Math::CVector3D) - -#endif // guard diff --git a/src/blackmisc/mathvector3dbase.cpp b/src/blackmisc/mathvector3dbase.cpp deleted file mode 100644 index e5e601506..000000000 --- a/src/blackmisc/mathvector3dbase.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* Copyright (C) 2013 - * swift project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackmisc/mathvector3d.h" -#include "blackmisc/mathmatrix3x3.h" -#include "blackmisc/coordinateecef.h" -#include "blackmisc/coordinatened.h" -#include "blackmisc/blackmiscfreefunctions.h" - -namespace BlackMisc -{ - namespace Math - { - - /* - * Convert to string - */ - template QString CVector3DBase::convertToQString(bool /* i18n */) const - { - QString s = ("{%1, %2, %3}"); - s = s.arg(QString::number(this->m_i, 'f')). - arg(QString::number(this->m_j, 'f')). - arg(QString::number(this->m_k, 'f')); - return s; - } - - /* - * Vector to zero - */ - template void CVector3DBase::setZero() - { - this->fill(0.0); - } - - /* - * Vector to zero - */ - template void CVector3DBase::fill(double value) - { - this->m_i = value; - this->m_j = value; - this->m_k = value; - } - - /* - * Element (return by reference) - */ - template double &CVector3DBase::getElement(int row) - { - switch (row) - { - case 0: - return this->m_i; - case 1: - return this->m_j; - case 2: - return this->m_k; - default: - Q_ASSERT_X(true, "getElement", "Detected invalid index in 3D vector"); - throw std::range_error("Detected invalid index in 3D vector"); - } - } - - /* - * Element - */ - template double CVector3DBase::getElement(int row) const - { - return const_cast*>(this)->getElement(row); - } - - /* - * Set given element - */ - template void CVector3DBase::setElement(int row, double value) - { - switch (row) - { - case 0: - this->m_i = value; - break; - case 1: - this->m_j = value; - break; - case 2: - this->m_k = value; - break; - default: - Q_ASSERT_X(true, "setElement", "Detected invalid index in 3D vector"); - throw std::range_error("Detected invalid index in 3D vector"); - break; - } - } - - /* - * Cross product - */ - template ImplVector CVector3DBase::crossProduct(const ImplVector &other) const - { - ImplVector v(other); - v.m_i = this->m_j * other.m_k - this->m_k * other.m_j; - v.m_j = this->m_k * other.m_i - this->m_i * other.m_k; - v.m_k = this->m_i * other.m_j - this->m_j * other.m_i; - return v; - } - - /* - * Cross product - */ - template double CVector3DBase::dotProduct(const ImplVector &other) const - { - return this->m_i * other.m_i + this->m_j * other.m_j + this->m_k * other.m_k; - } - - /* - * Convert to matrix - */ - template CMatrix3x1 CVector3DBase::toMatrix3x1() const - { - return CMatrix3x1(this->m_i, this->m_j, this->m_k); - } - - /* - * getValueHash() - */ - template uint CVector3DBase::getValueHash() const - { - QList hashs; - hashs << qHash(static_cast(this->m_i)); - hashs << qHash(static_cast(this->m_j)); - hashs << qHash(static_cast(this->m_k)); - return BlackMisc::calculateHash(hashs, "CVector3DBase"); - } - - /* - * To JSON - */ - template QJsonObject CVector3DBase::toJson() const - { - QJsonObject json; - QJsonArray jsonArray; - jsonArray.append(QJsonValue(this->m_i)); - jsonArray.append(QJsonValue(this->m_j)); - jsonArray.append(QJsonValue(this->m_k)); - json.insert("vector", QJsonValue(jsonArray)); - return json; - } - - /* - * From Json - */ - template void CVector3DBase::convertFromJson(const QJsonObject &json) - { - QJsonArray jsonArray = json.value("vector").toArray(); - this->m_i = jsonArray.at(0).toDouble(); - this->m_i = jsonArray.at(1).toDouble(); - this->m_i = jsonArray.at(2).toDouble(); - } - - // see here for the reason of thess forward instantiations - // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html - template class CVector3DBase; - template class CVector3DBase; - template class CVector3DBase; - - } // namespace -} // namespace diff --git a/src/blackmisc/mathvector3dbase.h b/src/blackmisc/mathvector3dbase.h deleted file mode 100644 index 77e6e8dc6..000000000 --- a/src/blackmisc/mathvector3dbase.h +++ /dev/null @@ -1,257 +0,0 @@ -/* Copyright (C) 2013 - * swift project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKMISC_MATHVECTOR3DBASE_H -#define BLACKMISC_MATHVECTOR3DBASE_H - -#include "blackmisc/valueobject.h" -#include "blackmisc/mathematics.h" -#include "blackmisc/blackmiscfreefunctions.h" - -namespace BlackMisc -{ - namespace Math { template class CVector3DBase; } - - //! \private - template struct CValueObjectPolicy> : public CValueObjectPolicy<> - { - using Equals = Policy::Equals::None; - using LessThan = Policy::LessThan::None; - using Hash = Policy::Hash::Own; - using Json = Policy::Json::Own; - }; - - namespace Math - { - class CMatrix3x1; - - //! 3D vector base (x, y, z) - template class CVector3DBase : public CValueObject> - { - public: - // getter and setters are implemented in the derived classes - // as they have different names (x, i, north) - - //! Set zeros - void setZero(); - - //! Is zero? - bool isZero() const - { - return this->m_i == 0 && this->m_j == 0 && this->m_k == 0; - } - - //! Is zero, epsilon considered. - bool isZeroEpsilon() const - { - ImplVector v; - v += *this; - v.round(); - return v.isZero(); - } - - //! Set all elements the same - void fill(double value); - - //! Get element - double getElement(int row) const; - - //! Set element - void setElement(int row, double value); - - //! Operator [] - double operator[](int row) const { return this->getElement(row); } - - //! Operator [], mutable reference - double &operator[](int row) { return this->getElement(row); } - - //! Equal operator == - bool operator ==(const CVector3DBase &other) const - { - if (this == &other) return true; - return - CMath::epsilonEqual(this->m_i, other.m_i, 1E-9) && - CMath::epsilonEqual(this->m_j, other.m_j, 1E-9) && - CMath::epsilonEqual(this->m_k, other.m_k, 1E-9); - } - - //! Unequal operator != - bool operator !=(const CVector3DBase &other) const - { - return !((*this) == other); - } - - //! Operator += - CVector3DBase &operator +=(const CVector3DBase &other) - { - this->m_i += other.m_i; - this->m_j += other.m_j; - this->m_k += other.m_k; - return *this; - } - - //! Operator + - ImplVector operator +(const ImplVector &other) const - { - ImplVector v = *derived(); - v += other; - return v; - } - - //! Operator -= - CVector3DBase &operator -=(const CVector3DBase &other) - { - this->m_i -= other.m_i; - this->m_j -= other.m_j; - this->m_k -= other.m_k; - return *this; - } - - //! Operator - - ImplVector operator -(const ImplVector &other) const - { - ImplVector v = *derived(); - v -= other; - return v; - } - - //! Multiply with scalar - CVector3DBase &operator *=(double factor) - { - this->m_i *= factor; - this->m_j *= factor; - this->m_k *= factor; - return *this; - } - - //! Multiply with scalar - ImplVector operator *(double factor) const - { - ImplVector v = *derived(); - v *= factor; - return v; - } - - //! Operator to support commutative multiplication - friend ImplVector operator *(double factor, const ImplVector &other) - { - return other * factor; - } - - //! Divide by scalar - CVector3DBase &operator /=(double divisor) - { - this->m_i /= divisor; - this->m_j /= divisor; - this->m_k /= divisor; - return *this; - } - - //! Divide by scalar - ImplVector operator /(double divisor) const - { - ImplVector v = *derived(); - v /= divisor; - return v; - } - - //! Dot product - double dotProduct(const ImplVector &other) const; - - //! Cross product - ImplVector crossProduct(const ImplVector &other) const; - - //! Reciprocal value - ImplVector reciprocalValues() const - { - ImplVector v(1 / this->m_i, 1 / this->m_j, 1 / this->m_j); - return v; - } - - //! Converted to matrix - CMatrix3x1 toMatrix3x1() const; - - //! \copydoc CValueObject::getValueHash - virtual uint getValueHash() const override; - - //! length / magnitude - double length() const - { - return sqrt(this->m_i * this->m_i + this->m_j * this->m_j + this->m_k * this->m_k); - } - - //! Round this vector - 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); - } - - //! Rounded vector - ImplVector rounded() const - { - ImplVector v = *derived(); - v.round(); - return v; - } - - //! \copydoc CValueObject::toJson - virtual QJsonObject toJson() const override; - - //! \copydoc CValueObject::convertFromJson - virtual void convertFromJson(const QJsonObject &json) override; - - protected: - // using own value since Qt QVector3D stores internally as float - double m_i; //!< Vector data i - double m_j; //!< Vector data j - double m_k; //!< Vector data k - - //! Default constructor - CVector3DBase() : m_i(0.0), m_j(0.0), m_k(0.0) {} - - //! Constructor by values - CVector3DBase(double i, double j, double k) : m_i(i), m_j(j), m_k(k) {} - - //! Constructor by value - explicit CVector3DBase(double value) : m_i(value), m_j(value), m_k(value) {} - - //! Get mutable element - double &getElement(int row); - - //! \copydoc CValueObject::convertToQString - virtual QString convertToQString(bool i18n = false) const override; - - private: - BLACK_ENABLE_TUPLE_CONVERSION(CVector3DBase) - - //! Easy access to derived class (CRTP template parameter) - ImplVector const *derived() const - { - return static_cast(this); - } - - //! Easy access to derived class (CRTP template parameter) - ImplVector *derived() - { - return static_cast(this); - } - - }; - - } -} - -BLACK_DECLARE_TUPLE_CONVERSION_TEMPLATE(BlackMisc::Math::CVector3DBase, (o.m_i, o.m_j, o.m_k)) - -#endif // guard diff --git a/tests/blackmisc/testblackmiscmain.cpp b/tests/blackmisc/testblackmiscmain.cpp index 432eb59cc..458596365 100644 --- a/tests/blackmisc/testblackmiscmain.cpp +++ b/tests/blackmisc/testblackmiscmain.cpp @@ -5,7 +5,6 @@ #include "testphysicalquantities.h" #include "testaviation.h" -#include "testvectormatrix.h" #include "testgeo.h" #include "testcontainers.h" #include "testvariantandmap.h" @@ -23,14 +22,12 @@ namespace BlackMiscTest { CTestPhysicalQuantities pqBaseTests ; CTestAviation avBaseTests; - CTestVectorMatrix vmTests; CTestGeo geoTests; CTestContainers containerTests; CTestVariantAndMap variantAndMap; CTestHardware hardwareTests; status |= QTest::qExec(&pqBaseTests, argc, argv); status |= QTest::qExec(&avBaseTests, argc, argv); - status |= QTest::qExec(&vmTests, argc, argv); status |= QTest::qExec(&geoTests, argc, argv); status |= QTest::qExec(&containerTests, argc, argv); status |= QTest::qExec(&variantAndMap, argc, argv); diff --git a/tests/blackmisc/testvectormatrix.cpp b/tests/blackmisc/testvectormatrix.cpp deleted file mode 100644 index e40134522..000000000 --- a/tests/blackmisc/testvectormatrix.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "testvectormatrix.h" - -using namespace BlackMisc::Math; - -namespace BlackMiscTest -{ - - /* - * Basic tests vector - */ - void CTestVectorMatrix::vectorBasics() - { - CVector3D v1(1); - v1 *= 2.0; - CVector3D v2(2); - QVERIFY2(v1 == v2, "Vectors should be equal"); - QVERIFY2(v1 * 2 == 2 * v2, "Commutative vector multiplication failed"); - CVector3D v3(1, 1, 1); - CVector3D v4(2, 2, 2); - CVector3D v5 = v3.crossProduct(v4); - QVERIFY2(v5.isZeroEpsilon(), "Cross product shall be {0, 0, 0}"); - CVector3D v6(1, 2, 3); - CVector3D v7(3, 4, 5); - QVERIFY2(v6.crossProduct(v7) == CVector3D(-2, 4, -2), "Cross product is wrong"); - QVERIFY2(CMath::epsilonEqual(v6.dotProduct(v7), 26), "Dot product is wrong, 26 expected"); - QVERIFY2(CMath::epsilonEqual(v6.length(), sqrt(1.0 + 4.0 + 9.0)), "Wrong vector magnitude"); - } - - /* - * Matrix tests - * http://www.bluebit.gr/matrix-calculator/ - */ - void CTestVectorMatrix::matrixBasics() - { - CMatrix3x3 m1; - CMatrix3x3 m2 = m1 - m1; - QVERIFY2(m1.isIdentity(), "Default matrix should be identity"); - QVERIFY2(m2.isZero(), "Matrix should be zero"); - - bool invertible; - CMatrix3x3 mr; - CMatrix3x3 msame(3.0); - mr = msame.inverse(invertible); - QVERIFY2(!invertible, "Matrix with sigular values cannot be inverted"); - - mr.setToIdentity(); - QVERIFY2(mr.determinant() == 1, "Identity matrix should have determinant 1"); - mr = mr.inverse(invertible); - QVERIFY2(invertible && mr.isIdentity() == 1, "Identity matrix should have inverse identity"); - - m1.setToIdentity(); - m2 = m1 + m1; - m1 = m1 * 2.0; - QVERIFY2(m1 == m2, "2* Identity should be Identity + Identity"); - QVERIFY2(m1 * 2 == 2 * m1, "Commutative matrix multiplication failed"); - - m1 /= 2.0; - m2 -= m1; - QVERIFY2(m1 == m2, "Identity should be Identity"); - - m1 = CMatrix3x3(1, 5, 3, 2, 4, 7, 4, 6, 2); - double det = m1.determinant(); - QVERIFY2(det == 74, qPrintable(QString("Determinant should be 74, but is: %1").arg(det))); - QVERIFY2(m1(0, 0) == 1 && m1(1, 0) == 2 && m1(0, 2) == 3, "Index error"); - CMatrix3x3 mi = m1.inverse(invertible); - CMatrix3x3 mid = m1 * mi; - QVERIFY2(mid.isIdentityEpsilon(), qPrintable(QString("Multiply with inverse should be identity: %1").arg(mid.toQString()))); - - m1.setToIdentity(); - CMatrix3x1 mc1 = m1.getColumn(0); - CMatrix1x3 mr2 = m1.getRow(1); - QVERIFY2(mc1 == CMatrix3x1(1, 0, 0), "Wrong column 0"); - QVERIFY2(mr2 == CMatrix1x3(0, 1, 0), "Wrong row 1"); - } - -} // namespace diff --git a/tests/blackmisc/testvectormatrix.h b/tests/blackmisc/testvectormatrix.h deleted file mode 100644 index 5f8eddc90..000000000 --- a/tests/blackmisc/testvectormatrix.h +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BLACKMISCTEST_TESTVECTORMATRIX_H -#define BLACKMISCTEST_TESTVECTORMATRIX_H - -#include "blackmisc/mathmatrix3x3.h" -#include - -namespace BlackMiscTest -{ - - /*! - * \brief Vector and Matrix classes tests - */ - class CTestVectorMatrix : public QObject - { - Q_OBJECT - - public: - //! Standard test case constructor - explicit CTestVectorMatrix(QObject *parent = nullptr) : QObject(parent) {} - - private slots: - //! Vector tests - void vectorBasics(); - - //! Matrix tests - void matrixBasics(); - }; - -} // namespace - -#endif // guard