mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Initial refactoring of vector and matrix classes
This commit is contained in:
@@ -48,6 +48,7 @@ equals(WITH_SAMPLES, ON) {
|
||||
SUBDIRS += samples/interpolator/sample_interpolator.pro
|
||||
SUBDIRS += samples/logging/sample_logging.pro
|
||||
SUBDIRS += samples/blackmiscquantities/sample_quantities_avionics.pro
|
||||
SUBDIRS += samples/blackmiscvectorgeo/sample_vector_geo.pro
|
||||
}
|
||||
|
||||
equals(WITH_UNITTESTS, ON) {
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
#include <QCoreApplication>
|
||||
/* 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 "samplesphysicalquantities.h"
|
||||
#include "samplesaviation.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMiscTest;
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
/* 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 "samplesaviation.h"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
#ifndef BLACKMISC_SAMPLESAVIATION_H
|
||||
#define BLACKMISC_SAMPLESAVIATION_H
|
||||
/* 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/. */
|
||||
|
||||
#ifndef BLACKMISCTEST_SAMPLESAVIATION_H
|
||||
#define BLACKMISCTEST_SAMPLESAVIATION_H
|
||||
|
||||
#include "blackmisc/pqconstants.h"
|
||||
#include "blackmisc/avheading.h"
|
||||
#include "blackmisc/avverticalpositions.h"
|
||||
#include "blackmisc/pqconstants.h"
|
||||
#include "blackmisc/aviocomsystem.h"
|
||||
#include "blackmisc/avionavsystem.h"
|
||||
#include "blackmisc/aviotransponder.h"
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
/* 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 "samplesphysicalquantities.h"
|
||||
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#ifndef BLACKMISC_SAMPLESPHYSICALQUANTITIES_H
|
||||
#define BLACKMISC_SAMPLESPHYSICALQUANTITIES_H
|
||||
/* 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/. */
|
||||
|
||||
#ifndef BLACKMISCTEST_SAMPLESPHYSICALQUANTITIES_H
|
||||
#define BLACKMISCTEST_SAMPLESPHYSICALQUANTITIES_H
|
||||
|
||||
#include "blackmisc/pqconstants.h"
|
||||
#include "blackmisc/debug.h"
|
||||
@@ -20,4 +25,4 @@ public:
|
||||
};
|
||||
}
|
||||
|
||||
#endif // BLACKMISC_SAMPLESPHYSICALQUANTITIES_H
|
||||
#endif // guard
|
||||
|
||||
17
samples/blackmiscvectorgeo/main.cpp
Normal file
17
samples/blackmiscvectorgeo/main.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "samplesvectormatrix.h"
|
||||
#include "samplesgeo.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
/*!
|
||||
* \brief Main entry
|
||||
* \param argc
|
||||
* \param argv
|
||||
* \return
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
BlackMiscTest::CSamplesVectorMatrix::samples();
|
||||
BlackMiscTest::CSamplesGeo::samples();
|
||||
return a.exec();
|
||||
}
|
||||
30
samples/blackmiscvectorgeo/sample_vector_geo.pro
Normal file
30
samples/blackmiscvectorgeo/sample_vector_geo.pro
Normal file
@@ -0,0 +1,30 @@
|
||||
QT += core
|
||||
|
||||
TARGET = sample_vector_geo
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
DEPENDPATH += . ../../src
|
||||
INCLUDEPATH += . ../../src
|
||||
|
||||
win32-msvc* {
|
||||
PRE_TARGETDEPS += ../../lib/blackmisc.lib
|
||||
LIBS += ../../lib/blackmisc.lib
|
||||
}
|
||||
|
||||
!win32-msvc* {
|
||||
PRE_TARGETDEPS += ../../lib/libblackmisc.a
|
||||
LIBS += ../../lib/libblackmisc.a
|
||||
}
|
||||
|
||||
DESTDIR = ../../bin
|
||||
|
||||
SOURCES += main.cpp \
|
||||
samplesvectormatrix.cpp \
|
||||
samplesgeo.cpp
|
||||
|
||||
HEADERS += \
|
||||
samplesvectormatrix.h \
|
||||
samplesgeo.h
|
||||
38
samples/blackmiscvectorgeo/samplesgeo.cpp
Normal file
38
samples/blackmiscvectorgeo/samplesgeo.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "samplesgeo.h"
|
||||
|
||||
using namespace BlackMisc::Geo;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackMiscTest
|
||||
{
|
||||
|
||||
/*
|
||||
* Samples
|
||||
*/
|
||||
int CSamplesGeo::samples()
|
||||
{
|
||||
CGeoLatitude lat1(20.0, CAngleUnit::deg());
|
||||
CGeoLatitude lat2 = lat1;
|
||||
CGeoLatitude lat3 = lat1 - lat2;
|
||||
|
||||
qDebug() << lat1 << lat2 << lat3;
|
||||
qDebug() << (lat1 + lat2) << (lat1 - lat2);
|
||||
|
||||
lat3 += lat1;
|
||||
CGeoLongitude lon1(33.0, CAngleUnit::deg());
|
||||
qDebug() << lon1 << lat3;
|
||||
|
||||
// lat3 += lon1; // must not work
|
||||
// lat3 = lon1; //must not work
|
||||
// CGeoLongitude lonx(lat2); // must notwork
|
||||
|
||||
CCoordinateGeodetic gc(10.0, 20.0, 1000);
|
||||
qDebug() << gc;
|
||||
|
||||
// bye
|
||||
qDebug() << "-----------------------------------------------";
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
} // namespace
|
||||
33
samples/blackmiscvectorgeo/samplesgeo.h
Normal file
33
samples/blackmiscvectorgeo/samplesgeo.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/* 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/. */
|
||||
|
||||
#ifndef BLACKMISCTEST_SAMPLESGEO_H
|
||||
#define BLACKMISCTEST_SAMPLESGEO_H
|
||||
#include "blackmisc/coordinategeodetic.h"
|
||||
|
||||
namespace BlackMiscTest
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief Samples for vector / matrix
|
||||
*/
|
||||
class CSamplesGeo
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* \brief Run the samples
|
||||
*/
|
||||
static int samples();
|
||||
|
||||
private:
|
||||
/*!
|
||||
* \brief Avoid init
|
||||
*/
|
||||
CSamplesGeo();
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
||||
#endif // guard
|
||||
29
samples/blackmiscvectorgeo/samplesvectormatrix.cpp
Normal file
29
samples/blackmiscvectorgeo/samplesvectormatrix.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#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.magnitude();
|
||||
v2 *= v2; // v2 * v2
|
||||
qDebug() << v2;
|
||||
// v2 = v1 * v1;
|
||||
|
||||
CMatrix3x3 m;
|
||||
CMatrix3x3 mr = m;
|
||||
qDebug() << m << mr;
|
||||
mr.setRandom();
|
||||
CMatrix3x3 mi = mr.inverse();
|
||||
CMatrix3x3 mid = mr * mi;
|
||||
qDebug() << mr << mi << mid;
|
||||
|
||||
// bye
|
||||
qDebug() << "-----------------------------------------------";
|
||||
return 0;
|
||||
|
||||
}
|
||||
29
samples/blackmiscvectorgeo/samplesvectormatrix.h
Normal file
29
samples/blackmiscvectorgeo/samplesvectormatrix.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#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
|
||||
@@ -27,6 +27,19 @@ template <class UsingClass> class CBaseStreamStringifier
|
||||
return debug;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Stream operator << for QDataStream
|
||||
* \param stream
|
||||
* \param uc
|
||||
* \return
|
||||
*/
|
||||
friend QDataStream operator<<(QDataStream stream, const UsingClass &uc)
|
||||
{
|
||||
const CBaseStreamStringifier &s = uc;
|
||||
stream << s.stringForStreaming();
|
||||
return stream;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Stream operator << for log messages
|
||||
* \param log
|
||||
|
||||
@@ -9,11 +9,26 @@
|
||||
* \brief Base and utility classes available in all other projects.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \namespace BlackMisctest
|
||||
* \brief Tests and samples for namespace BlackMisc.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \namespace BlackMisc::Aviation
|
||||
* \brief Aviation and Avionics classes such as CHeading or CTransponder .
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \namespace BlackMisc::Math
|
||||
* \brief Math classes such as vectors, matrices, and utility methods.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \namespace BlackMisc::GeoPosition
|
||||
* \brief Position handling as geo locations and coordinates systems.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \namespace BlackMisc::PhysicalQuantities
|
||||
* \brief Classes for physical quantities and units such as length, mass, speed.
|
||||
|
||||
@@ -10,8 +10,8 @@ DEPENDPATH += . ..
|
||||
#PRECOMPILED_HEADER = stdpch.h
|
||||
|
||||
precompile_header:!isEmpty(PRECOMPILED_HEADER) {
|
||||
DEFINES += USING_PCH
|
||||
}
|
||||
DEFINES += USING_PCH
|
||||
}
|
||||
|
||||
DEFINES += LOG_IN_FILE
|
||||
|
||||
@@ -60,7 +60,19 @@ HEADERS += \
|
||||
aviotransponder.h \
|
||||
avioadfsystem.h \
|
||||
aviation.h \
|
||||
basestreamstringifier.h
|
||||
basestreamstringifier.h \
|
||||
mathvector3dbase.h \
|
||||
mathvector3d.h \
|
||||
mathmatrixbase.h \
|
||||
mathmatrix3x3.h \
|
||||
mathmatrix3x1.h \
|
||||
mathematics.h \
|
||||
geolatitude.h \
|
||||
geolongitude.h \
|
||||
coordinategeodetic.h \
|
||||
coordinateecef.h \
|
||||
coordinatened.h \
|
||||
geoearthangle.h
|
||||
|
||||
SOURCES += \
|
||||
logmessage.cpp \
|
||||
@@ -88,6 +100,10 @@ SOURCES += \
|
||||
avaltitude.cpp \
|
||||
avverticalpositions.cpp \
|
||||
aviomodulator.cpp \
|
||||
aviotransponder.cpp
|
||||
aviotransponder.cpp \
|
||||
mathvector3dbase.cpp \
|
||||
mathmatrixbase.cpp \
|
||||
mathmatrix3x3.cpp \
|
||||
mathematics.cpp
|
||||
|
||||
DESTDIR = ../../lib
|
||||
|
||||
92
src/blackmisc/coordinateecef.h
Normal file
92
src/blackmisc/coordinateecef.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/* 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/. */
|
||||
|
||||
#ifndef BLACKMISC_COORDINATEECEF_H
|
||||
#define BLACKMISC_COORDINATEECEF_H
|
||||
#include "blackmisc/mathvector3dbase.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Geo
|
||||
{
|
||||
/*!
|
||||
* \brief Earth centered, earth fixed position
|
||||
*/
|
||||
class CCoordinateEcef : public BlackMisc::Math::CVector3DBase<CCoordinateEcef>
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* \brief Default constructor
|
||||
*/
|
||||
CCoordinateEcef() : CVector3DBase() {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor by values
|
||||
* \param x
|
||||
* \param y
|
||||
* \param z
|
||||
*/
|
||||
CCoordinateEcef(qreal x, qreal y, qreal z) : CVector3DBase(x, y, z) {}
|
||||
|
||||
/*!
|
||||
* \brief x
|
||||
* \return
|
||||
*/
|
||||
qreal x() const
|
||||
{
|
||||
return this->m_vector.x();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief y
|
||||
* \return
|
||||
*/
|
||||
qreal y() const
|
||||
{
|
||||
return this->m_vector.y();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief z
|
||||
* \return
|
||||
*/
|
||||
qreal z() const
|
||||
{
|
||||
return this->m_vector.z();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Set x
|
||||
* \param x
|
||||
*/
|
||||
void setX(qreal x)
|
||||
{
|
||||
this->m_vector.setX(x);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Set y
|
||||
* \param y
|
||||
*/
|
||||
void setY(qreal y)
|
||||
{
|
||||
this->m_vector.setY(y);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Set z
|
||||
* \param z
|
||||
*/
|
||||
void setZ(qreal z)
|
||||
{
|
||||
this->m_vector.setZ(z);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
|
||||
#endif // guard
|
||||
168
src/blackmisc/coordinategeodetic.h
Normal file
168
src/blackmisc/coordinategeodetic.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/* 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/. */
|
||||
|
||||
#ifndef BLACKMISC_COORDINATEGEODETIC_H
|
||||
#define BLACKMISC_COORDINATEGEODETIC_H
|
||||
#include "blackmisc/mathvector3dbase.h"
|
||||
#include "blackmisc/geolatitude.h"
|
||||
#include "blackmisc/geolongitude.h"
|
||||
#include "blackmisc/pqlength.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Geo
|
||||
{
|
||||
/*!
|
||||
* \brief Geodetic coordinate
|
||||
*/
|
||||
class CCoordinateGeodetic : public CBaseStreamStringifier<CCoordinateGeodetic>
|
||||
{
|
||||
|
||||
private:
|
||||
CGeoLatitude m_latitude; //!< Latitude
|
||||
CGeoLongitude m_longitude; //!< Longitude
|
||||
BlackMisc::PhysicalQuantities::CLength m_height; //!< height
|
||||
|
||||
protected:
|
||||
|
||||
/*!
|
||||
* \brief String for converter
|
||||
* \return
|
||||
*/
|
||||
virtual QString stringForConverter() const
|
||||
{
|
||||
QString s = "{%1, %2, %3}";
|
||||
return s.arg(this->m_latitude).arg(this->m_longitude).arg(this->height());
|
||||
}
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief Default constructor
|
||||
*/
|
||||
CCoordinateGeodetic() : m_latitude(), m_longitude(), m_height() {}
|
||||
|
||||
/*!
|
||||
* \brief Copy constructor
|
||||
*/
|
||||
CCoordinateGeodetic(const CCoordinateGeodetic &geoCoordinate) :
|
||||
m_latitude(geoCoordinate.m_latitude), m_longitude(geoCoordinate.m_longitude), m_height(geoCoordinate.m_height) {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor by values
|
||||
* \param latitude
|
||||
* \param longitude
|
||||
* \param height
|
||||
*/
|
||||
CCoordinateGeodetic(CGeoLatitude latitude, CGeoLongitude longitude, BlackMisc::PhysicalQuantities::CLength height) :
|
||||
m_latitude(latitude), m_longitude(longitude), m_height(height) {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor by values
|
||||
* \param latitudeDegrees
|
||||
* \param longitudeDegrees
|
||||
* \param heightMeters
|
||||
*/
|
||||
CCoordinateGeodetic(qreal latitudeDegrees, qreal longitudeDegrees, qreal heightMeters) :
|
||||
m_latitude(latitudeDegrees, BlackMisc::PhysicalQuantities::CAngleUnit::deg()), m_longitude(longitudeDegrees, BlackMisc::PhysicalQuantities::CAngleUnit::deg()), m_height(heightMeters, BlackMisc::PhysicalQuantities::CLengthUnit::m()) {}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Latitude
|
||||
* \return
|
||||
*/
|
||||
CGeoLatitude latitude() const
|
||||
{
|
||||
return this->m_latitude;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Longitude
|
||||
* \return
|
||||
*/
|
||||
CGeoLongitude longitude() const
|
||||
{
|
||||
return this->m_longitude;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Height
|
||||
* \return
|
||||
*/
|
||||
BlackMisc::PhysicalQuantities::CLength height() const
|
||||
{
|
||||
return this->m_height;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Set latitude
|
||||
* \param latitude
|
||||
*/
|
||||
void setLatitude(CGeoLatitude latitude)
|
||||
{
|
||||
this->m_latitude = latitude;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Set longitude
|
||||
* \param latitude
|
||||
*/
|
||||
void setLongitude(CGeoLongitude longitude)
|
||||
{
|
||||
this->m_longitude = longitude;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Set height
|
||||
* \param height
|
||||
*/
|
||||
void setHeight(BlackMisc::PhysicalQuantities::CLength height)
|
||||
{
|
||||
this->m_height = height;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Equal operator ==
|
||||
* \param otherGeodetic
|
||||
* \return
|
||||
*/
|
||||
bool operator ==(const CCoordinateGeodetic &otherGeodetic) const
|
||||
{
|
||||
if (this == &otherGeodetic) return true;
|
||||
return this->m_height == otherGeodetic.m_height &&
|
||||
this->m_latitude == otherGeodetic.m_latitude &&
|
||||
this->m_longitude == otherGeodetic.m_longitude;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Unequal operator !=
|
||||
* \param otherGeodetic
|
||||
* \return
|
||||
*/
|
||||
bool operator !=(const CCoordinateGeodetic &otherGeodetic) const
|
||||
{
|
||||
if (this == &otherGeodetic) return false;
|
||||
return !((*this) == otherGeodetic);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Assigment operator =
|
||||
* \param otherGeodetic
|
||||
* \return
|
||||
*/
|
||||
CCoordinateGeodetic &operator =(const CCoordinateGeodetic &otherGeodetic)
|
||||
{
|
||||
if (this == &otherGeodetic) return *this; // Same object?
|
||||
this->m_height = otherGeodetic.m_height;
|
||||
this->m_latitude = otherGeodetic.m_latitude;
|
||||
this->m_longitude = otherGeodetic.m_longitude;
|
||||
return (*this);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
|
||||
#endif // guard
|
||||
92
src/blackmisc/coordinatened.h
Normal file
92
src/blackmisc/coordinatened.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/* 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/. */
|
||||
|
||||
#ifndef BLACKMISC_COORDINATENED_H
|
||||
#define BLACKMISC_COORDINATENED_H
|
||||
#include "blackmisc/mathvector3dbase.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Geo
|
||||
{
|
||||
/*!
|
||||
* \brief North, East, Down
|
||||
*/
|
||||
class CCoordinateNed : public BlackMisc::Math::CVector3DBase<CCoordinateNed>
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* \brief Default constructor
|
||||
*/
|
||||
CCoordinateNed() : CVector3DBase() {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor by values
|
||||
* \param north
|
||||
* \param east
|
||||
* \param down
|
||||
*/
|
||||
CCoordinateNed(qreal north, qreal east, qreal down) : CVector3DBase(north, east, down) {}
|
||||
|
||||
/*!
|
||||
* \brief North
|
||||
* \return
|
||||
*/
|
||||
qreal north() const
|
||||
{
|
||||
return this->m_vector.x();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief East
|
||||
* \return
|
||||
*/
|
||||
qreal east() const
|
||||
{
|
||||
return this->m_vector.y();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Down
|
||||
* \return
|
||||
*/
|
||||
qreal down() const
|
||||
{
|
||||
return this->m_vector.z();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Set north
|
||||
* \param north
|
||||
*/
|
||||
void setNorth(qreal north)
|
||||
{
|
||||
this->m_vector.setX(north);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Set east
|
||||
* \param east
|
||||
*/
|
||||
void setEast(qreal east)
|
||||
{
|
||||
this->m_vector.setY(east);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Set down
|
||||
* \param down
|
||||
*/
|
||||
void setDown(qreal down)
|
||||
{
|
||||
this->m_vector.setZ(down);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
|
||||
#endif // guard
|
||||
168
src/blackmisc/geoearthangle.h
Normal file
168
src/blackmisc/geoearthangle.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/* 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/. */
|
||||
|
||||
#ifndef BLACKMISC_GEOLATLONBASE_H
|
||||
#define BLACKMISC_GEOLATLONBASE_H
|
||||
#include "blackmisc/pqangle.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Geo
|
||||
{
|
||||
/*!
|
||||
* \brief Base class for latitude / longitude
|
||||
*/
|
||||
template <class LATorLON> class CGeoEarthAngle : public BlackMisc::PhysicalQuantities::CAngle
|
||||
{
|
||||
protected:
|
||||
/*!
|
||||
* \brief Default constructor
|
||||
*/
|
||||
CGeoEarthAngle() : CAngle() {}
|
||||
|
||||
/*!
|
||||
* \brief Copy constructor
|
||||
* \param latOrLon
|
||||
*/
|
||||
CGeoEarthAngle(const LATorLON &latOrLon) : CAngle(latOrLon) { }
|
||||
|
||||
/*!
|
||||
* \brief Init by double value
|
||||
* \param value
|
||||
* \param unit
|
||||
*/
|
||||
CGeoEarthAngle(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit): CAngle(value, unit) {}
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
* \brief Virtual destructor
|
||||
*/
|
||||
virtual ~CGeoEarthAngle() {}
|
||||
|
||||
/*!
|
||||
* \brief Equal operator ==
|
||||
* \param latOrLon
|
||||
* \return
|
||||
*/
|
||||
bool operator==(const LATorLON &latOrLon) const
|
||||
{
|
||||
return CAngle::operator ==(latOrLon);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Not equal operator !=
|
||||
* \param latOrLon
|
||||
* \return
|
||||
*/
|
||||
bool operator!=(const LATorLON &latOrLon) const
|
||||
{
|
||||
return CAngle::operator !=(latOrLon);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Plus operator +=
|
||||
* \param latOrLon
|
||||
* \return
|
||||
*/
|
||||
CGeoEarthAngle &operator +=(const CGeoEarthAngle &latOrLon)
|
||||
{
|
||||
CAngle::operator +=(latOrLon);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Minus operator-=
|
||||
* \param latOrLon
|
||||
* \return
|
||||
*/
|
||||
CGeoEarthAngle &operator -=(const CGeoEarthAngle &latOrLon)
|
||||
{
|
||||
CAngle::operator -=(latOrLon);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Greater operator >
|
||||
* \param latOrLon
|
||||
* \return
|
||||
*/
|
||||
bool operator >(const LATorLON &latOrLon) const
|
||||
{
|
||||
return CAngle::operator >(latOrLon);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Less operator <
|
||||
* \param latOrLon
|
||||
* \return
|
||||
*/
|
||||
bool operator <(const LATorLON &latOrLon) const
|
||||
{
|
||||
return CAngle::operator >(latOrLon);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Less equal operator <=
|
||||
* \param latOrLon
|
||||
* \return
|
||||
*/
|
||||
bool operator <=(const LATorLON &latOrLon) const
|
||||
{
|
||||
return CAngle::operator <=(latOrLon);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Greater equal operator >=
|
||||
* \param latOrLon
|
||||
* \return
|
||||
*/
|
||||
bool operator >=(const LATorLON &latOrLon) const
|
||||
{
|
||||
return CAngle::operator >=(latOrLon);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Assignment operator =
|
||||
* \param latOrLon
|
||||
* \return
|
||||
*/
|
||||
CGeoEarthAngle &operator =(const LATorLON &latOrLon)
|
||||
{
|
||||
CAngle::operator =(latOrLon);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Plus operator +
|
||||
* \param latOrLon
|
||||
* \return
|
||||
*/
|
||||
LATorLON operator +(const LATorLON &latOrLon) const
|
||||
{
|
||||
LATorLON l(0.0, this->getUnit());
|
||||
l += (*this);
|
||||
l += latOrLon;
|
||||
return l;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Minus operator -
|
||||
* \param latOrLon
|
||||
* \return
|
||||
*/
|
||||
LATorLON operator -(const LATorLON &latOrLon) const
|
||||
{
|
||||
LATorLON l(0.0, this->getUnit());
|
||||
l += (*this);
|
||||
l -= latOrLon;
|
||||
return l;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
54
src/blackmisc/geolatitude.h
Normal file
54
src/blackmisc/geolatitude.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef BLACKMISC_GEOLATITUDE_H
|
||||
#define BLACKMISC_GEOLATITUDE_H
|
||||
#include "blackmisc/geoearthangle.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Geo
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief Latitude
|
||||
*/
|
||||
class CGeoLatitude : public CGeoEarthAngle<CGeoLatitude>
|
||||
{
|
||||
protected:
|
||||
/*!
|
||||
* \brief Specific string representation
|
||||
*/
|
||||
virtual QString stringForConverter() const
|
||||
{
|
||||
QString s = "latitude ";
|
||||
return s.append(CGeoEarthAngle::stringForConverter());
|
||||
}
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief Default constructor
|
||||
*/
|
||||
CGeoLatitude() : CGeoEarthAngle() {}
|
||||
|
||||
/*!
|
||||
* \brief Copy constructor
|
||||
* \param latitude
|
||||
*/
|
||||
CGeoLatitude(const CGeoLatitude &latitude) : CGeoEarthAngle(latitude) {}
|
||||
|
||||
/*!
|
||||
* \brief Init by double value
|
||||
* \param value
|
||||
* \param unit
|
||||
*/
|
||||
CGeoLatitude(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit): CGeoEarthAngle(value, unit) {}
|
||||
|
||||
/*!
|
||||
* \brief Virtual destructor
|
||||
*/
|
||||
virtual ~CGeoLatitude() {}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
|
||||
#endif // guard
|
||||
15
src/blackmisc/geolatlonbase.cpp
Normal file
15
src/blackmisc/geolatlonbase.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "geolatitude.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Geo
|
||||
{
|
||||
|
||||
|
||||
// see here for the reason of thess forward instantiations
|
||||
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
|
||||
// template class CGeoLatLonBase<CGeoLatitude>;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
53
src/blackmisc/geolongitude.h
Normal file
53
src/blackmisc/geolongitude.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef BLACKMISC_GEOLONGITUDE_H
|
||||
#define BLACKMISC_GEOLONGITUDE_H
|
||||
#include "blackmisc/geoearthangle.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Geo
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief Longitude
|
||||
*/
|
||||
class CGeoLongitude : public CGeoEarthAngle<CGeoLongitude>
|
||||
{
|
||||
protected:
|
||||
/*!
|
||||
* \brief Specific string representation
|
||||
*/
|
||||
virtual QString stringForConverter() const
|
||||
{
|
||||
QString s = "longitude ";
|
||||
return s.append(CGeoEarthAngle::stringForConverter());
|
||||
}
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief Default constructor
|
||||
*/
|
||||
CGeoLongitude() : CGeoEarthAngle() {}
|
||||
|
||||
/*!
|
||||
* \brief Copy constructor
|
||||
* \param Longitude
|
||||
*/
|
||||
CGeoLongitude(const CGeoLongitude &Longitude) : CGeoEarthAngle(Longitude) {}
|
||||
|
||||
/*!
|
||||
* \brief Init by double value
|
||||
* \param value
|
||||
* \param unit
|
||||
*/
|
||||
CGeoLongitude(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit): CGeoEarthAngle(value, unit) {}
|
||||
|
||||
/*!
|
||||
* \brief Virtual destructor
|
||||
*/
|
||||
virtual ~CGeoLongitude() {}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
38
src/blackmisc/mathematics.cpp
Normal file
38
src/blackmisc/mathematics.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/* 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/mathematics.h"
|
||||
#include <algorithm> // std::max
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Math
|
||||
{
|
||||
|
||||
/*
|
||||
* Hypotenuse
|
||||
*/
|
||||
double CMath::hypot(double x, double y)
|
||||
{
|
||||
x = abs(x);
|
||||
y = abs(y);
|
||||
double max = std::max(x, y);
|
||||
double min = std::min(x, y);
|
||||
double r = min / max;
|
||||
return max * sqrt(1 + r * r);
|
||||
}
|
||||
|
||||
/*
|
||||
* Real part of cubic root
|
||||
*/
|
||||
double CMath::cubicRootReal(const double x)
|
||||
{
|
||||
double result;
|
||||
result = std::pow(std::abs(x), (double)1 / 3);
|
||||
return x < 0 ? -result : result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
64
src/blackmisc/mathematics.h
Normal file
64
src/blackmisc/mathematics.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/* 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/. */
|
||||
|
||||
#ifndef BLACKMISC_MATHEMATICS_H
|
||||
#define BLACKMISC_MATHEMATICS_H
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Math
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief Math utils
|
||||
*/
|
||||
class CMath
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* \brief Calculates the hypotenuse of x and y without overflow
|
||||
* \param x
|
||||
* \param y
|
||||
* \return
|
||||
*/
|
||||
static double hypot(double x, double y);
|
||||
|
||||
/*!
|
||||
* \brief Calculates the square of x
|
||||
* \param x
|
||||
* \return
|
||||
*/
|
||||
static inline double square(const double x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Calculates x to the power of three
|
||||
* \param x
|
||||
* \return
|
||||
*/
|
||||
static inline double cubic(const double x)
|
||||
{
|
||||
return x * x * x;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Calculates the real cubic root
|
||||
* \param x
|
||||
* \return
|
||||
*/
|
||||
static double cubicRootReal(const double x);
|
||||
|
||||
private:
|
||||
/*!
|
||||
* \brief Avoid object init
|
||||
*/
|
||||
CMath() {}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
#endif // guard
|
||||
65
src/blackmisc/mathmatrix3x1.h
Normal file
65
src/blackmisc/mathmatrix3x1.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/* 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/. */
|
||||
|
||||
#ifndef BLACKMISC_POSMATRIX3X1_H
|
||||
#define BLACKMISC_POSMATRIX3X1_H
|
||||
|
||||
#include "blackmisc/mathmatrixbase.h"
|
||||
#include "blackmisc/mathvector3d.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Math
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief 3D matrix
|
||||
*/
|
||||
class CMatrix3x1 : public CMatrixBase<CMatrix3x1, 3, 1>
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* \brief CMatrix3D
|
||||
*/
|
||||
CMatrix3x1() : CMatrixBase() {}
|
||||
|
||||
/*!
|
||||
* \brief init with value
|
||||
* \param fillValue
|
||||
*/
|
||||
CMatrix3x1(qreal fillValue) : CMatrixBase(fillValue) {}
|
||||
|
||||
/*!
|
||||
* \brief Copy constructor
|
||||
* \param other
|
||||
*/
|
||||
CMatrix3x1(const CMatrix3x1 &otherMatrix) : CMatrixBase(otherMatrix) {}
|
||||
|
||||
/*!
|
||||
* \brief Convert to vector
|
||||
* \return
|
||||
*/
|
||||
CVector3D toVector3D() const
|
||||
{
|
||||
return CVector3D(this->getElement(0, 0), this->getElement(1, 0), this->getElement(2, 0));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Convert from vector
|
||||
* \return
|
||||
*/
|
||||
void fromVector3D(const CVector3D &vector)
|
||||
{
|
||||
this->m_matrix[0][0] = vector.x();
|
||||
this->m_matrix[1][0] = vector.y();
|
||||
this->m_matrix[2][0] = vector.z();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
57
src/blackmisc/mathmatrix3x3.cpp
Normal file
57
src/blackmisc/mathmatrix3x3.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/* 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"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Math
|
||||
{
|
||||
|
||||
/*
|
||||
* Determinant
|
||||
*/
|
||||
qreal CMatrix3x3::determinant() const
|
||||
{
|
||||
qreal determinant =
|
||||
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);
|
||||
|
||||
return determinant;
|
||||
}
|
||||
|
||||
/*
|
||||
* Determinant
|
||||
*/
|
||||
CMatrix3x3 CMatrix3x3::inverse() const
|
||||
{
|
||||
CMatrix3x3 inverse;
|
||||
qreal det = determinant();
|
||||
|
||||
// should we throw an assert / error here?
|
||||
if (det == 0) return inverse;
|
||||
|
||||
qreal 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;
|
||||
|
||||
return inverse;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace
|
||||
57
src/blackmisc/mathmatrix3x3.h
Normal file
57
src/blackmisc/mathmatrix3x3.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* 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/. */
|
||||
|
||||
#ifndef BLACKMISC_POSMATRIX3X3_H
|
||||
#define BLACKMISC_POSMATRIX3X3_H
|
||||
|
||||
#include "blackmisc/mathmatrixbase.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Math
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief 3x1 matrix
|
||||
*/
|
||||
class CMatrix3x3 : public CMatrixBase<CMatrix3x3, 3, 3>
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* \brief CMatrix3D
|
||||
*/
|
||||
CMatrix3x3() : CMatrixBase() {}
|
||||
|
||||
/*!
|
||||
* \brief init with value
|
||||
* \param fillValue
|
||||
*/
|
||||
CMatrix3x3(qreal fillValue) : CMatrixBase(fillValue) {}
|
||||
|
||||
/*!
|
||||
* \brief Copy constructor
|
||||
* \param other
|
||||
*/
|
||||
CMatrix3x3(const CMatrix3x3 &otherMatrix) : CMatrixBase(otherMatrix) {}
|
||||
|
||||
/*!
|
||||
* \brief Calculates the determinant of the matrix
|
||||
* \return
|
||||
*/
|
||||
qreal determinant() const;
|
||||
|
||||
/*!
|
||||
* \brief Calculate the inverse
|
||||
* \return
|
||||
*/
|
||||
CMatrix3x3 inverse() const;
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // BLACKMISC_POSMATRIX3X3_H
|
||||
71
src/blackmisc/mathmatrixbase.cpp
Normal file
71
src/blackmisc/mathmatrixbase.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/* 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"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Math
|
||||
{
|
||||
|
||||
/*
|
||||
* Get element by column / row
|
||||
*/
|
||||
template<class ImplMatrix, int Rows, int Columns> double CMatrixBase<ImplMatrix, Rows, Columns>::getElement(size_t row, size_t column) const
|
||||
{
|
||||
bool valid = (row >= 0 && column >= 0 && row < Rows && column < Columns);
|
||||
Q_ASSERT_X(valid, "getElement()", "Row or column invalid");
|
||||
std::range_error("Row or column invalid");
|
||||
return this->m_matrix(row, column);
|
||||
}
|
||||
|
||||
/*
|
||||
* All values to random value
|
||||
*/
|
||||
template<class ImplMatrix, int Rows, int Columns> void CMatrixBase<ImplMatrix, Rows, Columns>::setRandom()
|
||||
{
|
||||
for (int r = 0; r < Rows; r++)
|
||||
{
|
||||
for (int c = 0; c < Columns; c++)
|
||||
{
|
||||
this->m_matrix(r, c) = (qrand() % 101); // 0...100
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert to string
|
||||
*/
|
||||
template <class ImplMatrix, int Rows, int Columns> QString CMatrixBase<ImplMatrix, Rows, Columns>::stringForConverter() 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;
|
||||
}
|
||||
|
||||
|
||||
// see here for the reason of thess forward instantiations
|
||||
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
|
||||
template class CMatrixBase<CMatrix3x3, 3, 3>;
|
||||
template class CMatrixBase<CMatrix3x1, 3, 1>;
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace
|
||||
|
||||
#include "mathmatrixbase.h"
|
||||
|
||||
267
src/blackmisc/mathmatrixbase.h
Normal file
267
src/blackmisc/mathmatrixbase.h
Normal file
@@ -0,0 +1,267 @@
|
||||
/* 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/. */
|
||||
|
||||
#ifndef BLACKMISC_MATHMATRIXBASE_H
|
||||
#define BLACKMISC_MATHMATRIXBASE_H
|
||||
|
||||
#include "blackmisc/basestreamstringifier.h"
|
||||
#include <QGenericMatrix>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Math
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief Base functionality of a matrix
|
||||
*/
|
||||
template<class ImplMatrix, int Rows, int Columns> class CMatrixBase :
|
||||
public BlackMisc::CBaseStreamStringifier<ImplMatrix>
|
||||
{
|
||||
protected:
|
||||
QGenericMatrix<Rows, Columns, qreal> m_matrix; //!< backing data
|
||||
|
||||
/*!
|
||||
* \brief Conversion to string
|
||||
* \return
|
||||
*/
|
||||
QString stringForConverter() const;
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief Default constructor
|
||||
*/
|
||||
CMatrixBase() : m_matrix() {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor with init value
|
||||
* \param fillValue
|
||||
*/
|
||||
CMatrixBase(qreal fillValue) : m_matrix() { this->m_matrix.fill(fillValue);}
|
||||
|
||||
/*!
|
||||
* \brief Copy constructor
|
||||
* \param other
|
||||
*/
|
||||
CMatrixBase(const CMatrixBase &otherMatrix) : m_matrix(otherMatrix.m_matrix) {}
|
||||
|
||||
/*!
|
||||
* \brief Virtual destructor
|
||||
*/
|
||||
virtual ~CMatrixBase() {}
|
||||
|
||||
/*!
|
||||
* \brief Equal operator ==
|
||||
* \param otherMatrix
|
||||
* \return
|
||||
*/
|
||||
bool operator ==(const ImplMatrix &otherMatrix) const
|
||||
{
|
||||
if (this == &otherMatrix) return true;
|
||||
return this->m_matrix == otherMatrix.m_matrix;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Unequal operator !=
|
||||
* \param otherMatrix
|
||||
* \return
|
||||
*/
|
||||
bool operator !=(const ImplMatrix &otherMatrix) const
|
||||
{
|
||||
if (this == &otherMatrix) return false;
|
||||
return !((*this) == otherMatrix);
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Assigment operator =
|
||||
* \param multiply
|
||||
* \return
|
||||
*/
|
||||
CMatrixBase &operator =(const CMatrixBase &otherMatrix)
|
||||
{
|
||||
if (this == &otherMatrix) return *this; // Same object?
|
||||
this->m_matrix = otherMatrix.m_matrix;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator *=
|
||||
* \param multiply
|
||||
* \return
|
||||
*/
|
||||
CMatrixBase &operator *=(const CMatrixBase &otherMatrix)
|
||||
{
|
||||
this->m_matrix = this->m_matrix * otherMatrix.m_matrix;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator *
|
||||
* \param multiply
|
||||
* \return
|
||||
*/
|
||||
ImplMatrix operator *(const ImplMatrix &otherMatrix) const
|
||||
{
|
||||
ImplMatrix m(0.0);
|
||||
m += (*this);
|
||||
m *= otherMatrix;
|
||||
return m;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator *=
|
||||
* \param factor
|
||||
* \return
|
||||
*/
|
||||
CMatrixBase &operator *=(qreal factor)
|
||||
{
|
||||
this->m_matrix *= factor;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator *
|
||||
* \param factor
|
||||
* \return
|
||||
*/
|
||||
CMatrixBase &operator *(qreal factor)
|
||||
{
|
||||
ImplMatrix m(0.0);
|
||||
m += (*this);
|
||||
m *= factor;
|
||||
return m;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator /=
|
||||
* \param factor
|
||||
* \return
|
||||
*/
|
||||
CMatrixBase &operator /=(qreal factor)
|
||||
{
|
||||
this->m_matrix /= factor;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator /
|
||||
* \param factor
|
||||
* \return
|
||||
*/
|
||||
CMatrixBase &operator /(qreal factor)
|
||||
{
|
||||
ImplMatrix m(0.0);
|
||||
m += (*this);
|
||||
m /= factor;
|
||||
return m;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator +=
|
||||
* \param otherMatrix
|
||||
* \return
|
||||
*/
|
||||
CMatrixBase &operator +=(const CMatrixBase &otherMatrix)
|
||||
{
|
||||
this->m_matrix += otherMatrix.m_matrix;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator +
|
||||
* \param otherMatrix
|
||||
* \return
|
||||
*/
|
||||
ImplMatrix operator +(const ImplMatrix &otherMatrix) const
|
||||
{
|
||||
ImplMatrix m(0.0);
|
||||
m += (*this);
|
||||
m += otherMatrix;
|
||||
return m;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator -=
|
||||
* \param otherMatrix
|
||||
* \return
|
||||
*/
|
||||
CMatrixBase &operator -=(const CMatrixBase &otherMatrix)
|
||||
{
|
||||
this->m_matrix -= otherMatrix.m_matrix;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator -
|
||||
* \param otherMatrix
|
||||
* \return
|
||||
*/
|
||||
ImplMatrix operator -(const ImplMatrix &otherMatrix) const
|
||||
{
|
||||
ImplMatrix m(0.0);
|
||||
m += (*this);
|
||||
m -= otherMatrix;
|
||||
return m;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Transposed matrix
|
||||
* \return
|
||||
*/
|
||||
ImplMatrix transposed() const
|
||||
{
|
||||
ImplMatrix m(0.0);
|
||||
m.m_matrix = this->m_matrix.transposed();
|
||||
return m;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Is identity matrix?
|
||||
* \return
|
||||
*/
|
||||
bool isIdentity() const
|
||||
{
|
||||
return this->m_matrix.isIdentity();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Set as identity matrix
|
||||
* \return
|
||||
*/
|
||||
void setToIdentity()
|
||||
{
|
||||
this->m_matrix.setToIdentity();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Fills the matrix with random elements
|
||||
*/
|
||||
void setRandom();
|
||||
|
||||
/*!
|
||||
* \brief All values to zero
|
||||
*/
|
||||
void setZero() { this->m_matrix.fill(0.0); }
|
||||
|
||||
/*!
|
||||
* \brief Set a dedicated value
|
||||
* \param value
|
||||
*/
|
||||
void fill(qreal value) { this->m_matrix.fill(value); }
|
||||
|
||||
/*!
|
||||
* \brief Get element
|
||||
* \param row
|
||||
* \return
|
||||
*/
|
||||
double getElement(size_t row, size_t column) const;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
94
src/blackmisc/mathvector3d.h
Normal file
94
src/blackmisc/mathvector3d.h
Normal file
@@ -0,0 +1,94 @@
|
||||
#ifndef BLACKMISC_MATHVECTOR3D_H
|
||||
#define BLACKMISC_MATHVECTOR3D_H
|
||||
|
||||
#include "blackmisc/mathvector3dbase.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Math
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief Concrete vector implementation
|
||||
*/
|
||||
class CVector3D : public CVector3DBase<CVector3D>
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* \brief Default constructor
|
||||
*/
|
||||
CVector3D() : CVector3DBase() {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor by value
|
||||
* \param i
|
||||
* \param j
|
||||
* \param k
|
||||
*/
|
||||
CVector3D(qreal i, qreal j, qreal k) : CVector3DBase(i, j, k) {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor by value
|
||||
* \param value
|
||||
*/
|
||||
CVector3D(qreal value) : CVector3DBase(value) {}
|
||||
|
||||
/*!
|
||||
* \brief i
|
||||
* \return
|
||||
*/
|
||||
qreal i() const
|
||||
{
|
||||
return this->m_vector.x();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief j
|
||||
* \return
|
||||
*/
|
||||
qreal j() const
|
||||
{
|
||||
return this->m_vector.y();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief k
|
||||
* \return
|
||||
*/
|
||||
qreal k() const
|
||||
{
|
||||
return this->m_vector.z();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Set i
|
||||
* \param i
|
||||
*/
|
||||
void setI(qreal i)
|
||||
{
|
||||
this->m_vector.setX(i);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Set j
|
||||
* \param j
|
||||
*/
|
||||
void setJ(qreal j)
|
||||
{
|
||||
this->m_vector.setY(j);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Set k
|
||||
* \param k
|
||||
*/
|
||||
void setK(qreal k)
|
||||
{
|
||||
this->m_vector.setZ(k);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
#endif // guard
|
||||
80
src/blackmisc/mathvector3dbase.cpp
Normal file
80
src/blackmisc/mathvector3dbase.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/* 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/mathvector3dbase.h"
|
||||
#include "blackmisc/mathvector3d.h"
|
||||
#include "blackmisc/coordinateecef.h"
|
||||
#include "blackmisc/coordinatened.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Math
|
||||
{
|
||||
|
||||
/*
|
||||
* Convert to string
|
||||
*/
|
||||
template <class ImplClass> QString CVector3DBase<ImplClass>::stringForConverter() const
|
||||
{
|
||||
QString s = ("{%1, %2, %3}");
|
||||
s = s.arg(this->m_vector.x()).arg(this->m_vector.y()).arg(this->m_vector.z());
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* Vector to zero
|
||||
*/
|
||||
template <class ImplClass> void CVector3DBase<ImplClass>::setZero()
|
||||
{
|
||||
this->fill(0.0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Vector to zero
|
||||
*/
|
||||
template <class ImplClass> void CVector3DBase<ImplClass>::fill(qreal value)
|
||||
{
|
||||
this->m_vector.setX(value);
|
||||
this->m_vector.setY(value);
|
||||
this->m_vector.setZ(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Element
|
||||
*/
|
||||
template <class ImplClass> qreal CVector3DBase<ImplClass>::getElement(size_t row) const
|
||||
{
|
||||
bool validIndex = (row < 3 && row >= 0);
|
||||
Q_ASSERT_X(validIndex, "getElement", "Wrong index");
|
||||
if (!validIndex) throw std::range_error("Invalid index vor 3D vector");
|
||||
double d;
|
||||
switch (row)
|
||||
{
|
||||
case 0:
|
||||
d = this->m_vector.x();
|
||||
break;
|
||||
case 1:
|
||||
d = this->m_vector.y();
|
||||
break;
|
||||
case 2:
|
||||
d = this->m_vector.z();
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT_X(true, "getElement", "Detected invalid index in 3D vector");
|
||||
throw std::range_error("Detected invalid index in 3D vector");
|
||||
break;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
// 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<CVector3D>;
|
||||
template class CVector3DBase<BlackMisc::Geo::CCoordinateEcef>;
|
||||
template class CVector3DBase<BlackMisc::Geo::CCoordinateNed>;
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace
|
||||
283
src/blackmisc/mathvector3dbase.h
Normal file
283
src/blackmisc/mathvector3dbase.h
Normal file
@@ -0,0 +1,283 @@
|
||||
/* 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/. */
|
||||
|
||||
#ifndef BLACKMISC_MATHVECTOR3DBASE_H
|
||||
#define BLACKMISC_MATHVECTOR3DBASE_H
|
||||
|
||||
#include "blackmisc/basestreamstringifier.h"
|
||||
#include <QVector3D>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Math
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief 3D vector base (x, y, z)
|
||||
*/
|
||||
template <class ImplClass> class CVector3DBase : public CBaseStreamStringifier<ImplClass>
|
||||
{
|
||||
protected:
|
||||
|
||||
QVector3D m_vector; //!< Vector data
|
||||
|
||||
/*!
|
||||
* \brief Default constructor
|
||||
*/
|
||||
CVector3DBase() : m_vector() {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor by values
|
||||
* \param i
|
||||
* \param j
|
||||
* \param k
|
||||
*/
|
||||
CVector3DBase(qreal i, qreal j, qreal k) : m_vector(i, j, k) {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor by value
|
||||
* \param value
|
||||
*/
|
||||
CVector3DBase(qreal value) : m_vector(value, value, value) {}
|
||||
|
||||
/*!
|
||||
* \brief String for converter
|
||||
* \return
|
||||
*/
|
||||
virtual QString stringForConverter() const;
|
||||
|
||||
public:
|
||||
|
||||
// getter and setters are implemented in the derived classes
|
||||
// as they have different names (x, i, north)
|
||||
|
||||
/*!
|
||||
* \brief Virtual destructor
|
||||
*/
|
||||
virtual ~CVector3DBase() {}
|
||||
|
||||
/*!
|
||||
* \brief Set zeros
|
||||
*/
|
||||
void setZero();
|
||||
|
||||
/*!
|
||||
* \brief Set zeros
|
||||
*/
|
||||
void fill(qreal value);
|
||||
|
||||
/*!
|
||||
* \brief Get element
|
||||
* \param row
|
||||
* \return
|
||||
*/
|
||||
qreal getElement(size_t row) const;
|
||||
|
||||
/*!
|
||||
* \brief Operator []
|
||||
* \param row
|
||||
* \return
|
||||
*/
|
||||
qreal operator[](size_t row) const { return this->getElement(row); }
|
||||
|
||||
/*!
|
||||
* \brief Equal operator ==
|
||||
* \param otherVector
|
||||
* \return
|
||||
*/
|
||||
bool operator ==(const CVector3DBase &otherVector) const
|
||||
{
|
||||
if (this == &otherVector) return true;
|
||||
return this->m_vector == otherVector.m_vector;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Unequal operator !=
|
||||
* \param otherVector
|
||||
* \return
|
||||
*/
|
||||
bool operator !=(const CVector3DBase &otherVector) const
|
||||
{
|
||||
if (this == &otherVector) return false;
|
||||
return !((*this) == otherVector);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Assigment operator =
|
||||
* \param multiply
|
||||
* \return
|
||||
*/
|
||||
CVector3DBase &operator =(const CVector3DBase &otherVector)
|
||||
{
|
||||
if (this == &otherVector) return *this; // Same object?
|
||||
this->m_vector = otherVector.m_vector;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator +=
|
||||
* \param otherVector
|
||||
* \return
|
||||
*/
|
||||
CVector3DBase &operator +=(const CVector3DBase &otherVector)
|
||||
{
|
||||
this->m_vector += otherVector.m_vector;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator +
|
||||
* \param otherVector
|
||||
* \return
|
||||
*/
|
||||
ImplClass operator +(const ImplClass &otherVector) const
|
||||
{
|
||||
ImplClass v;
|
||||
v += (*this);
|
||||
v += otherVector;
|
||||
return v;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator -=
|
||||
* \param otherVector
|
||||
* \return
|
||||
*/
|
||||
CVector3DBase &operator -=(const CVector3DBase &otherVector)
|
||||
{
|
||||
this->m_vector -= otherVector.m_vector;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator +
|
||||
* \param otherVector
|
||||
* \return
|
||||
*/
|
||||
ImplClass operator -(const ImplClass &otherVector) const
|
||||
{
|
||||
ImplClass v;
|
||||
v += (*this);
|
||||
v -= otherVector;
|
||||
return v;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator *=, just x*x, y*y, z*z neither vector nor dot product
|
||||
* \param otherVector
|
||||
* \return
|
||||
*/
|
||||
CVector3DBase &operator *=(const CVector3DBase &otherVector)
|
||||
{
|
||||
this->m_vector *= otherVector.m_vector;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator, just x*x, y*y, z*z neither vector nor dot product
|
||||
* \param otherVector
|
||||
* \return
|
||||
*/
|
||||
ImplClass operator *(const ImplClass &otherVector) const
|
||||
{
|
||||
ImplClass v;
|
||||
v += (*this);
|
||||
v *= otherVector;
|
||||
return v;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator /=, just x/x, y/y, z/z
|
||||
* \param otherVector
|
||||
* \return
|
||||
*/
|
||||
CVector3DBase &operator /=(const CVector3DBase &otherVector)
|
||||
{
|
||||
this->m_vector *= otherVector.reciprocalValues().m_vector;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator, just x/x, y/y, z/z
|
||||
* \param otherVector
|
||||
* \return
|
||||
*/
|
||||
ImplClass operator /(const ImplClass &otherVector) const
|
||||
{
|
||||
ImplClass v;
|
||||
v += (*this);
|
||||
v /= otherVector;
|
||||
return v;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Dot product
|
||||
* \param otherVector
|
||||
* \return
|
||||
*/
|
||||
qreal dotProduct(const ImplClass &otherVector) const
|
||||
{
|
||||
return QVector3D::dotProduct(this->m_vector, otherVector.m_vector);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Dot product
|
||||
* \param otherVector
|
||||
* \return
|
||||
*/
|
||||
ImplClass crossProduct(const ImplClass &otherVector) const
|
||||
{
|
||||
ImplClass v;
|
||||
v.m_vector = QVector3D::crossProduct(this->m_vector, otherVector.m_vector);
|
||||
return v;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Dot product
|
||||
* \param otherVector
|
||||
* \return
|
||||
*/
|
||||
ImplClass reciprocalValues() const
|
||||
{
|
||||
ImplClass v;
|
||||
v.m_vector.setX(1 / this->m_vector.x());
|
||||
v.m_vector.setY(1 / this->m_vector.y());
|
||||
v.m_vector.setZ(1 / this->m_vector.z());
|
||||
return v;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Length
|
||||
* \return
|
||||
*/
|
||||
qreal length()const
|
||||
{
|
||||
return this->m_vector.length();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Length squared
|
||||
* \return
|
||||
*/
|
||||
qreal lengthSquared()const
|
||||
{
|
||||
return this->m_vector.lengthSquared();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Magnitude
|
||||
* \return
|
||||
*/
|
||||
qreal magnitude() const
|
||||
{
|
||||
return sqrt(this->lengthSquared());
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
@@ -79,7 +79,7 @@ template <class MU, class PQ> bool CPhysicalQuantity<MU, PQ>::operator ==(const
|
||||
template <class MU, class PQ> bool CPhysicalQuantity<MU, PQ>::operator !=(const CPhysicalQuantity<MU, PQ> &otherQuantity) const
|
||||
{
|
||||
if (this == &otherQuantity) return false;
|
||||
return !(*this == otherQuantity);
|
||||
return !((*this) == otherQuantity);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 VATSIM Community
|
||||
/* 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/. */
|
||||
@@ -143,7 +143,7 @@ public:
|
||||
/*!
|
||||
* \brief Value in given unit
|
||||
* \param unit
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
double value(const MU &unit) const;
|
||||
|
||||
@@ -151,7 +151,7 @@ public:
|
||||
* \brief Rounded value in unit
|
||||
* \param unit
|
||||
* \param digits
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
double valueRounded(const MU &unit, int digits = -1) const;
|
||||
|
||||
@@ -159,13 +159,13 @@ public:
|
||||
* \brief Value to QString with unit, e.g. "5.00m"
|
||||
* \param unit
|
||||
* \param digits
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
QString valueRoundedWithUnit(const MU &unit, int digits = -1) const;
|
||||
|
||||
/*!
|
||||
* \brief Value a int
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
qint32 unitValueToInteger() const
|
||||
{
|
||||
@@ -174,7 +174,7 @@ public:
|
||||
|
||||
/*!
|
||||
* \brief Value a double
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
double unitValueToDouble() const
|
||||
{
|
||||
@@ -184,13 +184,13 @@ public:
|
||||
/*!
|
||||
* \brief Value to QString with unit, e.g. "5.00m"
|
||||
* \param digits
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
QString unitValueRoundedWithUnit(int digits = -1) const;
|
||||
|
||||
/*!
|
||||
* \brief SI value to integer
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
qint32 siBaseUnitValueToInteger() const
|
||||
{
|
||||
@@ -199,7 +199,7 @@ public:
|
||||
|
||||
/*!
|
||||
* \brief SI value to double
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
double siBaseUnitValueToDouble() const
|
||||
{
|
||||
@@ -209,14 +209,14 @@ public:
|
||||
/*!
|
||||
* \brief Rounded value by n digits
|
||||
* \param digits
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
double unitValueToDoubleRounded(int digits = -1) const;
|
||||
|
||||
/*!
|
||||
* \brief Rounded value by n digits
|
||||
* \param digits if no value is provided, unit rounding is taken
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
QString unitValueToQStringRounded(int digits = -1) const;
|
||||
|
||||
@@ -241,21 +241,21 @@ public:
|
||||
/*!
|
||||
* \brief Rounded SI value by n digits
|
||||
* \param digits
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
double convertedSiValueToDoubleRounded(int digits = -1) const;
|
||||
|
||||
/*!
|
||||
* \brief Rounded value by n digits
|
||||
* \param digits if no value is provided, unit rounding is taken
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
QString convertedSiValueToQStringRounded(int digits = -1) const;
|
||||
|
||||
/*!
|
||||
* \brief SI Base unit value rounded
|
||||
* \param digits
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
QString convertedSiValueRoundedWithUnit(int digits = -1) const;
|
||||
|
||||
@@ -291,98 +291,98 @@ public:
|
||||
/*!
|
||||
* \brief Divide operator /=
|
||||
* \param divide
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
CPhysicalQuantity &operator /=(double divide);
|
||||
|
||||
/*!
|
||||
* \brief Operator *
|
||||
* \param multiply
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
PQ operator *(double multiply) const;
|
||||
|
||||
/*!
|
||||
* \brief Operator /
|
||||
* \param divide
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
PQ operator /(double divide) const;
|
||||
|
||||
/*!
|
||||
* \brief Equal operator ==
|
||||
* \param otherQuantity
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
bool operator==(const CPhysicalQuantity &otherQuantity) const;
|
||||
|
||||
/*!
|
||||
* \brief Not equal operator !=
|
||||
* \param otherQuantity
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
bool operator!=(const CPhysicalQuantity &otherQuantity) const;
|
||||
|
||||
/*!
|
||||
* \brief Plus operator +=
|
||||
* \param otherQuantity
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
CPhysicalQuantity &operator +=(const CPhysicalQuantity &otherQuantity);
|
||||
|
||||
/*!
|
||||
* \brief Minus operator-=
|
||||
* \param otherQuantity
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
CPhysicalQuantity &operator -=(const CPhysicalQuantity &otherQuantity);
|
||||
|
||||
/*!
|
||||
* \brief Greater operator >
|
||||
* \param otherQuantity
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
bool operator >(const CPhysicalQuantity &otherQuantity) const;
|
||||
|
||||
/*!
|
||||
* \brief Less operator <
|
||||
* \param otherQuantity
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
bool operator <(const CPhysicalQuantity &otherQuantity) const;
|
||||
|
||||
/*!
|
||||
* \brief Less equal operator <=
|
||||
* \param otherQuantity
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
bool operator <=(const CPhysicalQuantity &otherQuantity) const;
|
||||
|
||||
/*!
|
||||
* \brief Greater equal operator >=
|
||||
* \param otherQuantity
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
bool operator >=(const CPhysicalQuantity &otherQuantity) const;
|
||||
|
||||
/*!
|
||||
* \brief Assignment operator =
|
||||
* \param otherQuantity
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
CPhysicalQuantity &operator =(const CPhysicalQuantity &otherQuantity);
|
||||
|
||||
/*!
|
||||
* \brief Plus operator +
|
||||
* \param otherQuantity
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
PQ operator +(const PQ &otherQuantity) const;
|
||||
|
||||
/*!
|
||||
* \brief Minus operator -
|
||||
* \param otherQuantity
|
||||
* @return
|
||||
* \return
|
||||
*/
|
||||
PQ operator -(const PQ &otherQuantity) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user