Compare commits
7 Commits
92a87a0c64
...
9f1d23ad8e
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f1d23ad8e | |||
| 7cd2f7a310 | |||
| 7209eec012 | |||
| 992f59904a | |||
| 9dbd7210cb | |||
| 28f3471036 | |||
| d3d7235338 |
@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.0)
|
||||
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
||||
project(PIP)
|
||||
set(PIP_MAJOR 4)
|
||||
set(PIP_MINOR 2)
|
||||
set(PIP_REVISION 0)
|
||||
set(PIP_MINOR 3)
|
||||
set(PIP_REVISION 1)
|
||||
set(PIP_SUFFIX )
|
||||
set(PIP_COMPANY SHS)
|
||||
set(PIP_DOMAIN org.SHS)
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
#define PIAPPLICATIONMODULE_H
|
||||
|
||||
#include "picli.h"
|
||||
#include "pilog.h"
|
||||
#include "pisingleapplication.h"
|
||||
#include "pisystemmonitor.h"
|
||||
|
||||
|
||||
@@ -30,44 +30,10 @@
|
||||
//! \~english \section PILog_sec0 Synopsis
|
||||
//! \~russian \section PILog_sec0 Краткий обзор
|
||||
//! \~english
|
||||
//! This class provide handy parsing of command-line arguments. First you should add
|
||||
//! arguments to %PICLI with function \a addArgument(). Then you can check if there
|
||||
//! is some argument in application command-line with function \a hasArgument(),
|
||||
//! or obtain argument value by \a argumentValue().
|
||||
//! This class provides log with optional file and console output.
|
||||
//!
|
||||
//! \~russian
|
||||
//! Этот класс предоставляет удобный механизм для разбора аргументов командной строки.
|
||||
//! Сперва необходимо добавить аргументы в %PICLI с помощью методов \a addArgument().
|
||||
//! Далее можно проверять аргументы на наличие в командной строке методом \a hasArgument(),
|
||||
//! а также получать их значения при помощи \a argumentValue().
|
||||
//!
|
||||
//! \~english \section PICLI_sec1 Example
|
||||
//! \~russian \section PICLI_sec1 Пример
|
||||
//! \~\code
|
||||
//! int main(int argc, char ** argv) {
|
||||
//! PICLI cli(argc, argv);
|
||||
//! cli.addArgument("console");
|
||||
//! cli.addArgument("debug");
|
||||
//! cli.addArgument("Value", "v", "value", true);
|
||||
//! if (cli.hasArgument("console"))
|
||||
//! piCout << "console active";
|
||||
//! if (cli.hasArgument("debug"))
|
||||
//! piCout << "debug active";
|
||||
//! piCout << "Value =" << cli.argumentValue("Value");
|
||||
//! return 0;
|
||||
//! }
|
||||
//! \endcode
|
||||
//!
|
||||
//! \~english These executions are similar:
|
||||
//! \~russian Эти вызовы будут идентичны:
|
||||
//!
|
||||
//! \~\code
|
||||
//! a.out -cd -v 10
|
||||
//! a.out --value 10 -dc
|
||||
//! a.out -c -v 10 -d
|
||||
//! a.out --console -d -v 10
|
||||
//! a.out --debug -c --value 10
|
||||
//! \endcode
|
||||
//! Этот класс предоставляет лог с опциональным выводом в файл и консоль.
|
||||
//!
|
||||
|
||||
|
||||
|
||||
@@ -41,82 +41,107 @@ public:
|
||||
PILog();
|
||||
~PILog();
|
||||
|
||||
//! \~english Message category
|
||||
//! \~russian Категория сообщения
|
||||
enum class Level {
|
||||
Error,
|
||||
Warning,
|
||||
Info,
|
||||
Debug,
|
||||
Error /** \~english Error \~russian Ошибка */,
|
||||
Warning /** \~english Warning \~russian Предупреждение */,
|
||||
Info /** \~english Information \~russian Информация */,
|
||||
Debug /** \~english Debug \~russian Отладка */,
|
||||
};
|
||||
|
||||
//! \~english Output channel
|
||||
//! \~russian Канал вывода
|
||||
enum Output {
|
||||
File = 0x1,
|
||||
Console = 0x2,
|
||||
All = 0xFF,
|
||||
File /** \~english File \~russian Файл */ = 0x1,
|
||||
Console /** \~english Console \~russian Консоль */ = 0x2,
|
||||
All /** \~english All \~russian Все */ = 0xFF,
|
||||
};
|
||||
|
||||
//! \~english Set output target \"o\" to \"on\".
|
||||
//! \~english Set output channel \"o\" to \"on\".
|
||||
//! \~russian Установить канал вывода \"o\" в \"on\".
|
||||
void setOutput(Output o, bool on = true) { output.setFlag(o, on); }
|
||||
|
||||
//! \~english Returns prefix for filename.
|
||||
//! \~russian Возвращает префикс имени файла.
|
||||
PIString logName() const { return log_name; }
|
||||
|
||||
//! \~english Set prefix for filename. Should be set \b before \a setDir()!
|
||||
//! \~russian Устанавливает префикс имени файла. Должен быть установлен \b до вызова \a setDir()!
|
||||
void setLogName(const PIString & n) { log_name = n; }
|
||||
|
||||
//! \~english Returns if color for console output enabled.
|
||||
//! \~russian Возвращает использовать ли цвет для вывода в консоль.
|
||||
bool colorConsole() const { return color_console; }
|
||||
|
||||
//! \~english Set color for console output enabled. True by default.
|
||||
//! \~russian Устанавливает использовать ли цвет для вывода в консоль. Включено по умолчанию.
|
||||
void setColorConsole(bool yes) { color_console = yes; }
|
||||
|
||||
|
||||
//! \~english Returns directory for log files.
|
||||
//! \~russian Возвращает директорию для файлов.
|
||||
PIString dir() const { return log_dir; }
|
||||
|
||||
//! \~english Set directory for log files. Should be set \b after \a setApplicationName()!
|
||||
//! \~russian Устанавливает директорию для файлов. Должна быть установлена \b после вызова \a setApplicationName()!
|
||||
void setDir(const PIString & d);
|
||||
|
||||
|
||||
//! \~english Returns lifetime for file.
|
||||
//! \~russian Возвращает время жизни файла.
|
||||
PISystemTime fileSplitTime() const { return split_time; }
|
||||
|
||||
//! \~english Set lifetime for file. Each "st" interval new file will be created.
|
||||
//! \~russian Устанавливает время жизни файла. Каждый интервал "st" будет создан новый файл.
|
||||
void setFileSplitTime(PISystemTime st) { split_time = st; }
|
||||
|
||||
|
||||
//! \~english Returns timestamp format for line.
|
||||
//! \~russian Возвращает формат метки времени для строки.
|
||||
PIString timestampFormat() const { return timestamp_format; }
|
||||
|
||||
//! \~english Set timestamp format for line. Default is "yyyy-MM-dd hh:mm:ss.zzz".
|
||||
//! \~russian Устанавливает формат метки времени для строки. По умолчанию "yyyy-MM-dd hh:mm:ss.zzz".
|
||||
void setTimestampFormat(const PIString & f) { timestamp_format = f; }
|
||||
|
||||
|
||||
//! \~english Returns line format.
|
||||
//! \~russian Возвращает формат строки.
|
||||
PIString lineFormat() const { return line_format; }
|
||||
|
||||
//! \~english Set line format. "t" is timestamp, "c" is category and "m" is message. Default is "t - c: m".
|
||||
//! \~russian Устанавливает формат строки. "t" - метка времени, "c" - категория и "m" - сообщение. По умолчанию "t - c: m".
|
||||
void setLineFormat(const PIString & f);
|
||||
|
||||
|
||||
//! \~english Returns maximum level.
|
||||
//! \~russian Возвращает максимальную категорию.
|
||||
Level level() const { return max_level; }
|
||||
|
||||
//! \~english Set maximum level. All levels greater than \"l\" will be ignored. Default if \a Level::Debug.
|
||||
//! \~english Set maximum level. All levels greater than \"l\" will be ignored. Default is \a Level::Debug.
|
||||
//! \~russian Устанавливает максимальную категорию. Все сообщения с большей категорией, чем \"l\", будут игнорироваться. По умолчанию \a
|
||||
//! Level::Debug.
|
||||
void setLevel(Level l);
|
||||
|
||||
//! \~english Returns PICout for Level::Error level.
|
||||
//! \~english Returns \a PICout for \a Level::Error level.
|
||||
//! \~russian Возвращает \a PICout для категории \a Level::Error.
|
||||
PICout error(PIObject * context = nullptr);
|
||||
|
||||
//! \~english Returns PICout for Level::Warning level.
|
||||
//! \~english Returns \a PICout for \a Level::Warning level.
|
||||
//! \~russian Возвращает \a PICout для категории \a Level::Warning.
|
||||
PICout warning(PIObject * context = nullptr);
|
||||
|
||||
//! \~english Returns PICout for Level::Info level.
|
||||
//! \~english Returns \a PICout for \a Level::Info level.
|
||||
//! \~russian Возвращает \a PICout для категории \a Level::Info.
|
||||
PICout info(PIObject * context = nullptr);
|
||||
|
||||
//! \~english Returns PICout for Level::Debug level.
|
||||
//! \~english Returns \a PICout for \a Level::Debug level.
|
||||
//! \~russian Возвращает \a PICout для категории \a Level::Debug.
|
||||
PICout debug(PIObject * context = nullptr);
|
||||
|
||||
//! \~english Write all queued lines and stop. Also called in destructor.
|
||||
//! \~russian Записывает все строки из очереди и останавливается. Также вызывается в деструкторе.
|
||||
void stop();
|
||||
|
||||
private:
|
||||
|
||||
57
libs/main/client_server/piclientservermodule.h
Normal file
57
libs/main/client_server/piclientservermodule.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Module includes
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
//! \defgroup ClientServer ClientServer
|
||||
//! \~\brief
|
||||
//! \~english TCP Client-Server
|
||||
//! \~russian TCP Клиент-Сервер
|
||||
//!
|
||||
//! \~\details
|
||||
//! \~english \section cmake_module_ClientServer Building with CMake
|
||||
//! \~russian \section cmake_module_ClientServer Сборка с использованием CMake
|
||||
//!
|
||||
//! \~\code
|
||||
//! find_package(PIP REQUIRED)
|
||||
//! target_link_libraries([target] PIP::ClientServer)
|
||||
//! \endcode
|
||||
//!
|
||||
//! \~english \par Common
|
||||
//! \~russian \par Общее
|
||||
//!
|
||||
//! \~english
|
||||
//! These files provides server with clients dispatching for server-side and client for client-side.
|
||||
//!
|
||||
//! \~russian
|
||||
//! Эти файлы предоставляют сервер с диспетчеризацией клиентов для серверной стороны и клиента для клиентской стороны.
|
||||
//!
|
||||
//! \~\authors
|
||||
//! \~english
|
||||
//! Ivan Pelipenko peri4ko@yandex.ru;
|
||||
//! Andrey Bychkov work.a.b@yandex.ru;
|
||||
//! \~russian
|
||||
//! Иван Пелипенко peri4ko@yandex.ru;
|
||||
//! Андрей Бычков work.a.b@yandex.ru;
|
||||
//!
|
||||
|
||||
#ifndef PICLIENTSERVERMODULE_H
|
||||
#define PICLIENTSERVERMODULE_H
|
||||
|
||||
#include "piclientserver_client.h"
|
||||
#include "piclientserver_server.h"
|
||||
|
||||
#endif
|
||||
@@ -343,6 +343,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
static const PIString s_typedef = PIStringAscii("typedef");
|
||||
static const PIString s_namespace = PIStringAscii("namespace");
|
||||
static const PIString s_template = PIStringAscii("template");
|
||||
static const PIString s_L = PIStringAscii("$L");
|
||||
|
||||
bool mlc = false, cc = false;
|
||||
int mls = 0, ole = -1, /*ccs = 0,*/ end = 0;
|
||||
@@ -365,8 +366,9 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
}
|
||||
if (i > 0)
|
||||
if (c == '\\' && fc[i - 1].toAscii() != '\\') {
|
||||
fc.cutMid(i, 2);
|
||||
--i;
|
||||
fc.cutMid(i, 1);
|
||||
fc.replace(i, 1, s_L);
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
if (cc) continue;
|
||||
@@ -390,6 +392,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
}
|
||||
}
|
||||
pfc = procMacros(fc);
|
||||
pfc.removeAll(s_L);
|
||||
|
||||
if (main) return true;
|
||||
|
||||
@@ -1248,6 +1251,7 @@ PIString PICodeParser::procMacros(PIString fc) {
|
||||
static const PIString s_elif = PIStringAscii("elif");
|
||||
static const PIString s_else = PIStringAscii("else");
|
||||
static const PIString s_endif = PIStringAscii("endif");
|
||||
static const PIString s_L = PIStringAscii("$L");
|
||||
if (fc.isEmpty()) return PIString();
|
||||
int ifcnt = 0;
|
||||
bool grab = false, skip = false, cond_ok = false;
|
||||
@@ -1337,7 +1341,9 @@ bool PICodeParser::parseDirective(PIString d) {
|
||||
static const PIString s_define = PIStringAscii("define");
|
||||
static const PIString s_undef = PIStringAscii("undef");
|
||||
static const PIString s_PIMETA = PIStringAscii("PIMETA");
|
||||
static const PIString s_L = PIStringAscii("$L");
|
||||
if (d.isEmpty()) return true;
|
||||
d.replaceAll(s_L, '\n');
|
||||
PIString dname = d.takeCWord();
|
||||
// piCout << "parseDirective" << d;
|
||||
if (dname == s_include) {
|
||||
|
||||
@@ -37,6 +37,10 @@
|
||||
template<typename T>
|
||||
class PISet: public PIMap<T, uchar> {
|
||||
typedef PIMap<T, uchar> _CSet;
|
||||
template<typename P, typename T1>
|
||||
friend PIBinaryStream<P> & operator<<(PIBinaryStream<P> & s, const PISet<T1> & v);
|
||||
template<typename P, typename T1>
|
||||
friend PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PISet<T1> & v);
|
||||
|
||||
public:
|
||||
//! Contructs an empty set
|
||||
|
||||
@@ -36,6 +36,12 @@
|
||||
|
||||
using std::complex;
|
||||
|
||||
template<typename T>
|
||||
struct is_complex: std::false_type {};
|
||||
|
||||
template<typename T>
|
||||
struct is_complex<std::complex<T>>: std::true_type {};
|
||||
|
||||
typedef complex<int> complexi;
|
||||
typedef complex<short> complexs;
|
||||
typedef complex<float> complexf;
|
||||
|
||||
@@ -63,7 +63,7 @@ class PIP_EXPORT PIMathMatrixT {
|
||||
typedef PIMathMatrixT<Cols, Rows, Type> _CMatrixI;
|
||||
typedef PIMathVectorT<Rows, Type> _CMCol;
|
||||
typedef PIMathVectorT<Cols, Type> _CMRow;
|
||||
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
|
||||
static_assert(std::is_arithmetic<Type>::value || is_complex<Type>::value, "Type must be arithmetic or complex");
|
||||
static_assert(Rows > 0, "Row count must be > 0");
|
||||
static_assert(Cols > 0, "Column count must be > 0");
|
||||
|
||||
@@ -386,7 +386,7 @@ public:
|
||||
//! \brief Деление с присваиванием с матрицей `v`.
|
||||
//! \param sm матрица для деления с присваиванием.
|
||||
void operator/=(const Type & v) {
|
||||
assert(piAbs<Type>(v) > PIMATHVECTOR_ZERO_CMP);
|
||||
assert(std::abs(v) > PIMATHVECTOR_ZERO_CMP);
|
||||
PIMM_FOR m[r][c] /= v;
|
||||
}
|
||||
|
||||
@@ -453,7 +453,7 @@ public:
|
||||
//! \param v делитель.
|
||||
//! \return результат деления.
|
||||
PIMathMatrixT<Rows, Cols, Type> operator/(const Type & v) const {
|
||||
assert(piAbs<Type>(v) > PIMATHVECTOR_ZERO_CMP);
|
||||
assert(std::abs(v) > PIMATHVECTOR_ZERO_CMP);
|
||||
PIMathMatrixT<Rows, Cols, Type> tm = PIMathMatrixT<Rows, Cols, Type>(*this);
|
||||
PIMM_FOR tm.m[r][c] /= v;
|
||||
return tm;
|
||||
@@ -517,7 +517,7 @@ public:
|
||||
for (uint i = 0; i < Cols; ++i) {
|
||||
ndet = true;
|
||||
for (uint j = 0; j < Rows; ++j)
|
||||
if (smat.m[i][j] != 0) ndet = false;
|
||||
if (smat.m[i][j] != Type{}) ndet = false;
|
||||
if (ndet) {
|
||||
if (ok != 0) *ok = false;
|
||||
return *this;
|
||||
@@ -525,15 +525,16 @@ public:
|
||||
}
|
||||
for (uint i = 0; i < Cols; ++i) {
|
||||
crow = i;
|
||||
while (smat.m[i][i] == Type(0))
|
||||
while (smat.m[i][i] == Type{}) {
|
||||
smat.swapRows(i, ++crow);
|
||||
}
|
||||
for (uint j = i + 1; j < Rows; ++j) {
|
||||
mul = smat.m[i][j] / smat.m[i][i];
|
||||
for (uint k = i; k < Cols; ++k)
|
||||
smat.m[k][j] -= mul * smat.m[k][i];
|
||||
}
|
||||
if (i < Cols - 1) {
|
||||
if (piAbs<Type>(smat.m[i + 1][i + 1]) < Type(1E-200)) {
|
||||
if (std::abs(smat.m[i + 1][i + 1]) < PIMATHVECTOR_ZERO_CMP) {
|
||||
if (ok != 0) *ok = false;
|
||||
return *this;
|
||||
}
|
||||
@@ -562,8 +563,9 @@ public:
|
||||
Type mul, iddiv;
|
||||
for (uint i = 0; i < Cols; ++i) {
|
||||
ndet = true;
|
||||
for (uint j = 0; j < Rows; ++j)
|
||||
if (smat.m[i][j] != 0) ndet = false;
|
||||
for (uint j = 0; j < Rows; ++j) {
|
||||
if (std::abs(smat.m[i][j]) >= PIMATHVECTOR_ZERO_CMP) ndet = false;
|
||||
}
|
||||
if (ndet) {
|
||||
if (ok != 0) *ok = false;
|
||||
return *this;
|
||||
@@ -571,7 +573,7 @@ public:
|
||||
}
|
||||
for (uint i = 0; i < Cols; ++i) {
|
||||
crow = i;
|
||||
while (smat.m[i][i] == Type(0)) {
|
||||
while (std::abs(smat.m[i][i]) < PIMATHVECTOR_ZERO_CMP) {
|
||||
++crow;
|
||||
smat.swapRows(i, crow);
|
||||
mtmp.swapRows(i, crow);
|
||||
@@ -584,7 +586,7 @@ public:
|
||||
mtmp.m[k][j] -= mul * mtmp.m[k][i];
|
||||
}
|
||||
if (i < Cols - 1) {
|
||||
if (piAbs<Type>(smat.m[i + 1][i + 1]) < Type(1E-200)) {
|
||||
if (std::abs(smat.m[i + 1][i + 1]) < PIMATHVECTOR_ZERO_CMP) {
|
||||
if (ok != 0) *ok = false;
|
||||
return *this;
|
||||
}
|
||||
@@ -650,7 +652,7 @@ public:
|
||||
static_assert(Rows == 2 && Cols == 2, "Works only with 2x2 matrix");
|
||||
Type c = std::cos(angle);
|
||||
Type s = std::sin(angle);
|
||||
PIMathMatrixT<2u, 2u> tm;
|
||||
PIMathMatrixT<2u, 2u, Type> tm;
|
||||
tm[0][0] = tm[1][1] = c;
|
||||
tm[0][1] = -s;
|
||||
tm[1][0] = s;
|
||||
@@ -671,7 +673,7 @@ public:
|
||||
PIMathMatrixT<Cols, Rows, Type> outm;
|
||||
Type c = std::cos(angle);
|
||||
Type s = std::sin(angle);
|
||||
PIMathMatrixT<2u, 2u> tm;
|
||||
PIMathMatrixT<2u, 2u, Type> tm;
|
||||
tm[0][0] = tm[1][1] = c;
|
||||
tm[0][1] = -s;
|
||||
tm[1][0] = s;
|
||||
|
||||
@@ -27,12 +27,13 @@
|
||||
#define PIMATHVECTOR_H
|
||||
|
||||
#include "pimathbase.h"
|
||||
#include "pimathcomplex.h"
|
||||
|
||||
|
||||
template<uint Cols, uint Rows, typename Type>
|
||||
class PIMathMatrixT;
|
||||
|
||||
#define PIMATHVECTOR_ZERO_CMP Type(1E-100)
|
||||
#define PIMATHVECTOR_ZERO_CMP (1E-100)
|
||||
|
||||
|
||||
/// Vector templated
|
||||
@@ -42,7 +43,7 @@ class PIMathMatrixT;
|
||||
template<uint Size, typename Type = double>
|
||||
class PIP_EXPORT PIMathVectorT {
|
||||
typedef PIMathVectorT<Size, Type> _CVector;
|
||||
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
|
||||
static_assert(std::is_arithmetic<Type>::value || is_complex<Type>::value, "Type must be arithmetic or complex");
|
||||
static_assert(Size > 0, "Size must be > 0");
|
||||
|
||||
public:
|
||||
@@ -83,35 +84,71 @@ public:
|
||||
PIMV_FOR tv += c[i] * c[i];
|
||||
return tv;
|
||||
}
|
||||
Type length() const { return std::sqrt(lengthSqr()); }
|
||||
|
||||
Type length() const {
|
||||
static_assert(std::is_arithmetic<Type>::value, "Unavailable for complex");
|
||||
if (std::is_arithmetic<Type>::value) return std::sqrt(lengthSqr());
|
||||
// if (is_complex<Type>::value) return 1000.; // std::sqrt(lengthSqr());
|
||||
}
|
||||
|
||||
Type manhattanLength() const {
|
||||
Type tv(0);
|
||||
PIMV_FOR tv += piAbs<Type>(c[i]);
|
||||
return tv;
|
||||
static_assert(std::is_arithmetic<Type>::value, "Unavailable for complex");
|
||||
if (std::is_arithmetic<Type>::value) {
|
||||
Type tv(0);
|
||||
PIMV_FOR tv += piAbs<Type>(c[i]);
|
||||
return tv;
|
||||
}
|
||||
}
|
||||
Type angleCos(const _CVector & v) const {
|
||||
Type tv = v.length() * length();
|
||||
assert(piAbs<Type>(tv) > PIMATHVECTOR_ZERO_CMP);
|
||||
return dot(v) / tv;
|
||||
static_assert(std::is_arithmetic<Type>::value, "Unavailable for complex");
|
||||
if (std::is_arithmetic<Type>::value) {
|
||||
Type tv = v.length() * length();
|
||||
assert(piAbs<Type>(tv) > PIMATHVECTOR_ZERO_CMP);
|
||||
return dot(v) / tv;
|
||||
}
|
||||
}
|
||||
Type angleSin(const _CVector & v) const {
|
||||
Type tv = angleCos(v);
|
||||
return std::sqrt(Type(1) - tv * tv);
|
||||
static_assert(std::is_arithmetic<Type>::value, "Unavailable for complex");
|
||||
if (std::is_arithmetic<Type>::value) {
|
||||
Type tv = angleCos(v);
|
||||
return std::sqrt(Type(1) - tv * tv);
|
||||
}
|
||||
}
|
||||
Type angleRad(const _CVector & v) const {
|
||||
static_assert(std::is_arithmetic<Type>::value, "Unavailable for complex");
|
||||
if (std::is_arithmetic<Type>::value) {
|
||||
return std::acos(angleCos(v));
|
||||
}
|
||||
}
|
||||
Type angleDeg(const _CVector & v) const {
|
||||
static_assert(std::is_arithmetic<Type>::value, "Unavailable for complex");
|
||||
if (std::is_arithmetic<Type>::value) {
|
||||
return toDeg(angleRad(v));
|
||||
}
|
||||
}
|
||||
Type angleElevation(const _CVector & v) const {
|
||||
static_assert(std::is_arithmetic<Type>::value, "Unavailable for complex");
|
||||
if (std::is_arithmetic<Type>::value) {
|
||||
return 90.0 - angleDeg(v - *this);
|
||||
}
|
||||
}
|
||||
Type angleRad(const _CVector & v) const { return std::acos(angleCos(v)); }
|
||||
Type angleDeg(const _CVector & v) const { return toDeg(angleRad(v)); }
|
||||
Type angleElevation(const _CVector & v) const { return 90.0 - angleDeg(v - *this); }
|
||||
_CVector projection(const _CVector & v) {
|
||||
Type tv = v.length();
|
||||
assert(piAbs<Type>(tv) > PIMATHVECTOR_ZERO_CMP);
|
||||
return v * (dot(v) / tv);
|
||||
static_assert(std::is_arithmetic<Type>::value, "Unavailable for complex");
|
||||
if (std::is_arithmetic<Type>::value) {
|
||||
Type tv = v.length();
|
||||
assert(piAbs<Type>(tv) > PIMATHVECTOR_ZERO_CMP);
|
||||
return v * (dot(v) / tv);
|
||||
}
|
||||
}
|
||||
_CVector & normalize() {
|
||||
Type tv = length();
|
||||
assert(piAbs<Type>(tv) > PIMATHVECTOR_ZERO_CMP);
|
||||
if (tv == Type(1)) return *this;
|
||||
PIMV_FOR c[i] /= tv;
|
||||
return *this;
|
||||
static_assert(std::is_arithmetic<Type>::value, "Unavailable for complex");
|
||||
if (std::is_arithmetic<Type>::value) {
|
||||
Type tv = length();
|
||||
assert(piAbs<Type>(tv) > PIMATHVECTOR_ZERO_CMP);
|
||||
if (tv == Type(1)) return *this;
|
||||
PIMV_FOR c[i] /= tv;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
_CVector normalized() {
|
||||
_CVector tv(*this);
|
||||
@@ -119,10 +156,10 @@ public:
|
||||
return tv;
|
||||
}
|
||||
bool isNull() const {
|
||||
PIMV_FOR if (c[i] != Type(0)) return false;
|
||||
PIMV_FOR if (c[i] != Type{}) return false;
|
||||
return true;
|
||||
}
|
||||
bool isOrtho(const _CVector & v) const { return ((*this) ^ v) == Type(0); }
|
||||
bool isOrtho(const _CVector & v) const { return ((*this) ^ v) == Type{}; }
|
||||
|
||||
Type & operator[](uint index) { return c[index]; }
|
||||
const Type & operator[](uint index) const { return c[index]; }
|
||||
@@ -145,7 +182,7 @@ public:
|
||||
void operator-=(const _CVector & v) { PIMV_FOR c[i] -= v[i]; }
|
||||
void operator*=(const Type & v) { PIMV_FOR c[i] *= v; }
|
||||
void operator/=(const Type & v) {
|
||||
assert(piAbs<Type>(v) > PIMATHVECTOR_ZERO_CMP);
|
||||
assert(std::abs(v) > PIMATHVECTOR_ZERO_CMP);
|
||||
PIMV_FOR c[i] /= v;
|
||||
}
|
||||
_CVector operator-() const {
|
||||
@@ -169,7 +206,7 @@ public:
|
||||
return tv;
|
||||
}
|
||||
_CVector operator/(const Type & v) const {
|
||||
assert(piAbs<Type>(v) > PIMATHVECTOR_ZERO_CMP);
|
||||
assert(std::abs(v) > PIMATHVECTOR_ZERO_CMP);
|
||||
_CVector tv = _CVector(*this);
|
||||
PIMV_FOR tv[i] /= v;
|
||||
return tv;
|
||||
@@ -184,7 +221,7 @@ public:
|
||||
return tv;
|
||||
}
|
||||
Type dot(const _CVector & v) const {
|
||||
Type tv(0);
|
||||
Type tv{};
|
||||
PIMV_FOR tv += c[i] * v[i];
|
||||
return tv;
|
||||
}
|
||||
@@ -197,7 +234,7 @@ public:
|
||||
_CVector div(const _CVector & v) const {
|
||||
_CVector tv(*this);
|
||||
PIMV_FOR {
|
||||
assert(piAbs<Type>(v[i]) > PIMATHVECTOR_ZERO_CMP);
|
||||
assert(std::abs(v[i]) > PIMATHVECTOR_ZERO_CMP);
|
||||
tv[i] /= v[i];
|
||||
}
|
||||
return tv;
|
||||
@@ -211,11 +248,14 @@ public:
|
||||
}
|
||||
|
||||
Type distToLine(const _CVector & lp0, const _CVector & lp1) {
|
||||
_CVector a(lp0, lp1);
|
||||
Type tv = a.length();
|
||||
assert(piAbs<Type>(tv) > PIMATHVECTOR_ZERO_CMP);
|
||||
_CVector b(lp0, *this);
|
||||
return piAbs<Type>(a[0] * b[1] - a[1] * b[0]) / tv;
|
||||
static_assert(std::is_arithmetic<Type>::value, "Unavailable for complex");
|
||||
if (std::is_arithmetic<Type>::value) {
|
||||
_CVector a(lp0, lp1);
|
||||
Type tv = a.length();
|
||||
assert(std::abs(tv) > PIMATHVECTOR_ZERO_CMP);
|
||||
_CVector b(lp0, *this);
|
||||
return piAbs<Type>(a[0] * b[1] - a[1] * b[0]) / tv;
|
||||
}
|
||||
}
|
||||
|
||||
template<uint Size1, typename Type1> /// vector {Size, Type} to vector {Size1, Type1}
|
||||
@@ -394,7 +434,7 @@ public:
|
||||
Type angleCos(const _CVector & v) const {
|
||||
assert(c.size() == v.size());
|
||||
Type tv = v.length() * length();
|
||||
assert(piAbs<Type>(tv) > PIMATHVECTOR_ZERO_CMP);
|
||||
assert(std::abs(tv) > PIMATHVECTOR_ZERO_CMP);
|
||||
return dot(v) / tv;
|
||||
}
|
||||
Type angleSin(const _CVector & v) const {
|
||||
@@ -407,12 +447,12 @@ public:
|
||||
_CVector projection(const _CVector & v) {
|
||||
assert(c.size() == v.size());
|
||||
Type tv = v.length();
|
||||
assert(piAbs<Type>(tv) > PIMATHVECTOR_ZERO_CMP);
|
||||
assert(std::abs(tv) > PIMATHVECTOR_ZERO_CMP);
|
||||
return v * (dot(v) / tv);
|
||||
}
|
||||
_CVector & normalize() {
|
||||
Type tv = length();
|
||||
assert(piAbs<Type>(tv) > PIMATHVECTOR_ZERO_CMP);
|
||||
assert(std::abs(tv) > PIMATHVECTOR_ZERO_CMP);
|
||||
if (tv == Type(1)) return *this;
|
||||
PIMV_FOR c[i] /= tv;
|
||||
return *this;
|
||||
@@ -451,7 +491,7 @@ public:
|
||||
}
|
||||
void operator*=(const Type & v) { PIMV_FOR c[i] *= v; }
|
||||
void operator/=(const Type & v) {
|
||||
assert(piAbs<Type>(v) > PIMATHVECTOR_ZERO_CMP);
|
||||
assert(std::abs(v) > PIMATHVECTOR_ZERO_CMP);
|
||||
PIMV_FOR c[i] /= v;
|
||||
}
|
||||
_CVector operator-() const {
|
||||
@@ -477,7 +517,7 @@ public:
|
||||
return tv;
|
||||
}
|
||||
_CVector operator/(const Type & v) const {
|
||||
assert(piAbs<Type>(v) > PIMATHVECTOR_ZERO_CMP);
|
||||
assert(std::abs(v) > PIMATHVECTOR_ZERO_CMP);
|
||||
_CVector tv(*this);
|
||||
PIMV_FOR tv[i] /= v;
|
||||
return tv;
|
||||
@@ -508,7 +548,7 @@ public:
|
||||
assert(c.size() == v.size());
|
||||
_CVector tv(*this);
|
||||
PIMV_FOR {
|
||||
assert(piAbs<Type>(v[i]) > PIMATHVECTOR_ZERO_CMP);
|
||||
assert(std::abs(v[i]) > PIMATHVECTOR_ZERO_CMP);
|
||||
tv[i] /= v[i];
|
||||
}
|
||||
return tv;
|
||||
@@ -520,7 +560,7 @@ public:
|
||||
assert(c.size() == lp1.size());
|
||||
_CVector a = _CVector::fromTwoPoints(lp0, lp1);
|
||||
Type tv = a.length();
|
||||
assert(piAbs<Type>(tv) > PIMATHVECTOR_ZERO_CMP);
|
||||
assert(std::abs(tv) > PIMATHVECTOR_ZERO_CMP);
|
||||
_CVector b = _CVector::fromTwoPoints(lp0, *this);
|
||||
return piAbs<Type>(a[0] * b[1] - a[1] * b[0]) / tv;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "pibitarray.h"
|
||||
#include "pimap.h"
|
||||
#include "pimemoryblock.h"
|
||||
#include "piset.h"
|
||||
#include "pivector2d.h"
|
||||
|
||||
#define PIP_BINARY_STREAM
|
||||
@@ -655,6 +656,46 @@ inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIMap<Key, T> & v)
|
||||
}
|
||||
|
||||
|
||||
//! \~english Store operator
|
||||
//! \~russian Оператор сохранения
|
||||
template<typename P, typename Key>
|
||||
inline PIBinaryStream<P> & operator<<(PIBinaryStream<P> & s, const PISet<Key> & v) {
|
||||
s.binaryStreamAppend((int)v.pim_index.size_s());
|
||||
for (uint i = 0; i < v.size(); ++i) {
|
||||
s.binaryStreamAppend((int)v.pim_index[i].index);
|
||||
s << v.pim_index[i].key;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
//! \~english Restore operator
|
||||
//! \~russian Оператор извлечения
|
||||
template<typename P, typename Key>
|
||||
inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PISet<Key> & v) {
|
||||
int sz = s.binaryStreamTakeInt();
|
||||
if (s.wasReadError()) {
|
||||
fprintf(stderr, "error with PISet<%s>\n", __PIP_TYPENAME__(Key));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
v.pim_index.resize(sz);
|
||||
v.pim_content.resize(sz, 0);
|
||||
int ind = 0;
|
||||
for (int i = 0; i < sz; ++i) {
|
||||
ind = s.binaryStreamTakeInt();
|
||||
s >> v.pim_index[i].key;
|
||||
if (s.wasReadError()) {
|
||||
fprintf(stderr, "error with PISet<%s>\n", __PIP_TYPENAME__(Key));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
v.pim_index[i].index = ind;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
// non-defined complex types
|
||||
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
|
||||
const uint rows = 3;
|
||||
const uint cols = 3;
|
||||
using Type = double;
|
||||
|
||||
bool cmpSquareMatrixWithValue(PIMathMatrixT<rows, cols, double> matrix, double val, int num) {
|
||||
bool cmpSquareMatrixWithValue(PIMathMatrixT<rows, cols, Type> matrix, Type val, int num) {
|
||||
for (int i = 0; i < num; i++) {
|
||||
for (int j = 0; j < num; j++) {
|
||||
if (matrix.at(i, j) != val) {
|
||||
@@ -17,50 +18,50 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT<rows, cols, double> matrix, double v
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, identity) {
|
||||
auto matrix = PIMathMatrixT<rows, cols, double>::identity();
|
||||
auto matrix = PIMathMatrixT<rows, cols, Type>::identity();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
if (i != j) {
|
||||
if (matrix[i][j] != 0.0) {
|
||||
ASSERT_TRUE(false);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
} else {
|
||||
if (matrix[i][i] != 1.0) {
|
||||
ASSERT_TRUE(false);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, at) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::identity();
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, Type>::identity();
|
||||
for (uint i = 0; i < rows; i++) {
|
||||
if (matrix1.at(i, i) != 1.0) {
|
||||
ASSERT_TRUE(false);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
TEST(PIMathMatrixT_Test, filled) {
|
||||
auto matr = PIMathMatrixT<rows, cols, double>(1.0);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matr, 1.0, rows));
|
||||
auto matr = PIMathMatrixT<rows, cols, Type>(1.0);
|
||||
EXPECT_TRUE(cmpSquareMatrixWithValue(matr, 1.0, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, cols) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
ASSERT_EQ(cols, matr.cols());
|
||||
PIMathMatrixT<rows, cols, Type> matr;
|
||||
EXPECT_EQ(cols, matr.cols());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, rows) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
ASSERT_EQ(rows, matr.rows());
|
||||
PIMathMatrixT<rows, cols, Type> matr;
|
||||
EXPECT_EQ(rows, matr.rows());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, col) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathVectorT<rows, double> vect;
|
||||
PIMathMatrixT<rows, cols, Type> matr;
|
||||
PIMathVectorT<rows, Type> vect;
|
||||
uint g = 2;
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
@@ -74,15 +75,15 @@ TEST(PIMathMatrixT_Test, col) {
|
||||
vect = matr.col(g);
|
||||
for (uint i = 0; i < matr.cols(); i++) {
|
||||
if (matr.element(i, g) != vect[i]) {
|
||||
ASSERT_TRUE(false);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, row) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathVectorT<rows, double> vect;
|
||||
PIMathMatrixT<rows, cols, Type> matr;
|
||||
PIMathVectorT<rows, Type> vect;
|
||||
uint g = 2;
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
@@ -96,15 +97,15 @@ TEST(PIMathMatrixT_Test, row) {
|
||||
vect = matr.row(g);
|
||||
for (uint i = 0; i < matr.rows(); i++) {
|
||||
if (matr.element(g, i) != vect[i]) {
|
||||
ASSERT_TRUE(false);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, setCol) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathVectorT<rows, double> vect;
|
||||
PIMathMatrixT<rows, cols, Type> matr;
|
||||
PIMathVectorT<rows, Type> vect;
|
||||
vect[0] = 1.0;
|
||||
vect[1] = 3.0;
|
||||
vect[2] = 5.0;
|
||||
@@ -112,15 +113,15 @@ TEST(PIMathMatrixT_Test, setCol) {
|
||||
matr.setCol(g, vect);
|
||||
for (uint i = 0; i < vect.size(); i++) {
|
||||
if (matr.element(i, g) != vect[i]) {
|
||||
ASSERT_TRUE(false);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, setRow) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathVectorT<rows, double> vect;
|
||||
PIMathMatrixT<rows, cols, Type> matr;
|
||||
PIMathVectorT<rows, Type> vect;
|
||||
vect[0] = 1.0;
|
||||
vect[1] = 3.0;
|
||||
vect[2] = 5.0;
|
||||
@@ -128,114 +129,114 @@ TEST(PIMathMatrixT_Test, setRow) {
|
||||
matr.setRow(g, vect);
|
||||
for (uint i = 0; i < vect.size(); i++) {
|
||||
if (matr.element(g, i) != vect[i]) {
|
||||
ASSERT_TRUE(false);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, swapCols) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathMatrixT<rows, cols, Type> matr;
|
||||
int g1 = 1, g2 = 2;
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
matr.element(1, 0) = 2;
|
||||
matr.element(1, 1) = 1;
|
||||
matr.element(1, 2) = 4;
|
||||
matr.element(2, 0) = 6;
|
||||
matr.element(2, 1) = 2;
|
||||
matr.element(2, 2) = 5;
|
||||
const PIMathVectorT<rows, double> before_Vect1 = matr.col(g1);
|
||||
const PIMathVectorT<rows, double> before_Vect2 = matr.col(g2);
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
matr.element(1, 0) = 2;
|
||||
matr.element(1, 1) = 1;
|
||||
matr.element(1, 2) = 4;
|
||||
matr.element(2, 0) = 6;
|
||||
matr.element(2, 1) = 2;
|
||||
matr.element(2, 2) = 5;
|
||||
const PIMathVectorT<rows, Type> before_Vect1 = matr.col(g1);
|
||||
const PIMathVectorT<rows, Type> before_Vect2 = matr.col(g2);
|
||||
matr.swapCols(g1, g2);
|
||||
const PIMathVectorT<rows, double> after_Vect1 = matr.col(g1);
|
||||
const PIMathVectorT<rows, double> after_Vect2 = matr.col(g2);
|
||||
const PIMathVectorT<rows, Type> after_Vect1 = matr.col(g1);
|
||||
const PIMathVectorT<rows, Type> after_Vect2 = matr.col(g2);
|
||||
if ((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) {
|
||||
ASSERT_TRUE(true);
|
||||
EXPECT_TRUE(true);
|
||||
} else {
|
||||
ASSERT_TRUE(false);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, swapRows) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathMatrixT<rows, cols, Type> matr;
|
||||
int g1 = 1, g2 = 2;
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
matr.element(1, 0) = 2;
|
||||
matr.element(1, 1) = 1;
|
||||
matr.element(1, 2) = 4;
|
||||
matr.element(2, 0) = 6;
|
||||
matr.element(2, 1) = 2;
|
||||
matr.element(2, 2) = 5;
|
||||
const PIMathVectorT<rows, double> before_Vect1 = matr.row(g1);
|
||||
const PIMathVectorT<rows, double> before_Vect2 = matr.row(g2);
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
matr.element(1, 0) = 2;
|
||||
matr.element(1, 1) = 1;
|
||||
matr.element(1, 2) = 4;
|
||||
matr.element(2, 0) = 6;
|
||||
matr.element(2, 1) = 2;
|
||||
matr.element(2, 2) = 5;
|
||||
const PIMathVectorT<rows, Type> before_Vect1 = matr.row(g1);
|
||||
const PIMathVectorT<rows, Type> before_Vect2 = matr.row(g2);
|
||||
matr.swapRows(g1, g2);
|
||||
const PIMathVectorT<rows, double> after_Vect1 = matr.row(g1);
|
||||
const PIMathVectorT<rows, double> after_Vect2 = matr.row(g2);
|
||||
const PIMathVectorT<rows, Type> after_Vect1 = matr.row(g1);
|
||||
const PIMathVectorT<rows, Type> after_Vect2 = matr.row(g2);
|
||||
if ((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) {
|
||||
ASSERT_TRUE(true);
|
||||
EXPECT_TRUE(true);
|
||||
} else {
|
||||
ASSERT_TRUE(false);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, fill) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
double g = 1.0;
|
||||
PIMathMatrixT<rows, cols, Type> matr;
|
||||
PIMathMatrixT<rows, cols, Type> matrix1;
|
||||
Type g = 1.0;
|
||||
matr.fill(g);
|
||||
for (uint i = 0; i < cols; i++) {
|
||||
for (uint j = 0; j < rows; j++) {
|
||||
matrix1.element(j, i) = g;
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(matr == matrix1);
|
||||
EXPECT_TRUE(matr == matrix1);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, isSquareTrue) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
ASSERT_TRUE(matrix1.isSquare());
|
||||
PIMathMatrixT<rows, cols, Type> matrix1;
|
||||
EXPECT_TRUE(matrix1.isSquare());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, isSquareFalse) {
|
||||
const uint new_Cols = 4;
|
||||
PIMathMatrixT<rows, new_Cols, double> matrix2;
|
||||
ASSERT_FALSE(matrix2.isSquare());
|
||||
PIMathMatrixT<rows, new_Cols, Type> matrix2;
|
||||
EXPECT_FALSE(matrix2.isSquare());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, isIdentityTrue) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::identity();
|
||||
ASSERT_TRUE(matrix1.isIdentity());
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, Type>::identity();
|
||||
EXPECT_TRUE(matrix1.isIdentity());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, isIdentityFalse) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(2.5);
|
||||
ASSERT_FALSE(matrix1.isIdentity());
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, Type>(2.5);
|
||||
EXPECT_FALSE(matrix1.isIdentity());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, isNullTrue) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
ASSERT_TRUE(matrix1.isNull());
|
||||
PIMathMatrixT<rows, cols, Type> matrix1;
|
||||
EXPECT_TRUE(matrix1.isNull());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, isNullFalse) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::identity();
|
||||
ASSERT_FALSE(matrix1.isNull());
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, Type>::identity();
|
||||
EXPECT_FALSE(matrix1.isNull());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Assignment) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>(6.72);
|
||||
PIMathMatrixT<rows, cols, Type> matrix1;
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, Type>(6.72);
|
||||
matrix1 = matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows));
|
||||
EXPECT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_EqualTrue) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
PIMathMatrixT<rows, cols, Type> matrix1;
|
||||
PIMathMatrixT<rows, cols, Type> matrix2;
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
@@ -244,12 +245,12 @@ TEST(PIMathMatrixT_Test, operator_EqualTrue) {
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 0.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_TRUE(matrix1 == matrix2);
|
||||
EXPECT_TRUE(matrix1 == matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_EqualFalse) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
PIMathMatrixT<rows, cols, Type> matrix1;
|
||||
PIMathMatrixT<rows, cols, Type> matrix2;
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
@@ -258,12 +259,12 @@ TEST(PIMathMatrixT_Test, operator_EqualFalse) {
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 665.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_FALSE(matrix1 == matrix2);
|
||||
EXPECT_FALSE(matrix1 == matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
PIMathMatrixT<rows, cols, Type> matrix1;
|
||||
PIMathMatrixT<rows, cols, Type> matrix2;
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
@@ -272,12 +273,12 @@ TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) {
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 665.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_TRUE(matrix1 != matrix2);
|
||||
EXPECT_TRUE(matrix1 != matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
PIMathMatrixT<rows, cols, Type> matrix1;
|
||||
PIMathMatrixT<rows, cols, Type> matrix2;
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
@@ -286,60 +287,60 @@ TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) {
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 0.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_FALSE(matrix1 != matrix2);
|
||||
EXPECT_FALSE(matrix1 != matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Addition_Assignment) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(6.72);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>(1.0);
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, Type>(6.72);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, Type>(1.0);
|
||||
matrix1 += matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows));
|
||||
EXPECT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(1.0);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>(6.72);
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, Type>(1.0);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, Type>(6.72);
|
||||
matrix1 -= matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows));
|
||||
EXPECT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(6.72);
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, Type>(6.72);
|
||||
matrix1 *= 2.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows));
|
||||
EXPECT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Division_Assignment) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(6.72);
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, Type>(6.72);
|
||||
matrix1 /= 2.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows));
|
||||
EXPECT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Addition) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(6.72);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>(8.28);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows));
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, Type>(6.72);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, Type>(8.28);
|
||||
EXPECT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Subtraction) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(6.0);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>(5.0);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows));
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, Type>(6.0);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, Type>(5.0);
|
||||
EXPECT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Multiplication) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(6.72);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows));
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, Type>(6.72);
|
||||
EXPECT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows));
|
||||
}
|
||||
TEST(PIMathMatrixT_Test, operator_Division) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(6.72);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows));
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, Type>(6.72);
|
||||
EXPECT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, determinantIfSquare) {
|
||||
double d;
|
||||
double i = 59.0;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
Type d;
|
||||
Type i = 59.0;
|
||||
PIMathMatrixT<rows, cols, Type> matr;
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
@@ -350,15 +351,15 @@ TEST(PIMathMatrixT_Test, determinantIfSquare) {
|
||||
matr.element(2, 1) = 2;
|
||||
matr.element(2, 2) = 5;
|
||||
d = matr.determinant();
|
||||
ASSERT_DOUBLE_EQ(i, d);
|
||||
EXPECT_DOUBLE_EQ(std::abs(i - d), 0.);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, invert) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
PIMathMatrixT<rows, cols, double> matrix3;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
double d1, d2;
|
||||
PIMathMatrixT<rows, cols, Type> matrix1;
|
||||
PIMathMatrixT<rows, cols, Type> matrix2;
|
||||
PIMathMatrixT<rows, cols, Type> matrix3;
|
||||
PIMathMatrixT<rows, cols, Type> matr;
|
||||
Type d1, d2;
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
@@ -374,15 +375,16 @@ TEST(PIMathMatrixT_Test, invert) {
|
||||
d2 = matrix2.determinant();
|
||||
matrix3 = matrix1;
|
||||
matrix1.invert();
|
||||
ASSERT_TRUE((matrix1 == matrix3) && piCompare(d1, 1 / d2));
|
||||
EXPECT_EQ(matrix1, matrix3);
|
||||
EXPECT_DOUBLE_EQ(std::abs(d1 - (1. / d2)), 0.);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, inverted) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
PIMathMatrixT<rows, cols, double> matrix3;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
double d1, d2;
|
||||
PIMathMatrixT<rows, cols, Type> matrix1;
|
||||
PIMathMatrixT<rows, cols, Type> matrix2;
|
||||
PIMathMatrixT<rows, cols, Type> matrix3;
|
||||
PIMathMatrixT<rows, cols, Type> matr;
|
||||
Type d1, d2;
|
||||
matrix1 = matr.identity();
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
@@ -397,13 +399,14 @@ TEST(PIMathMatrixT_Test, inverted) {
|
||||
d1 = matr.determinant();
|
||||
d2 = matrix2.determinant();
|
||||
matrix3 = matrix1.inverted();
|
||||
ASSERT_TRUE((matrix1 == matrix3) && (round((1 / d1) * 10000) / 10000 == round(d2 * 10000) / 10000));
|
||||
EXPECT_EQ(matrix1, matrix3);
|
||||
EXPECT_DOUBLE_EQ(std::abs(d1 - (1. / d2)), 0.);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, toUpperTriangular) {
|
||||
PIMathMatrixT<rows, cols, double> matrix;
|
||||
double d1, d2 = 1;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathMatrixT<rows, cols, Type> matrix;
|
||||
Type d1, d2 = 1;
|
||||
PIMathMatrixT<rows, cols, Type> matr;
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
@@ -418,14 +421,14 @@ TEST(PIMathMatrixT_Test, toUpperTriangular) {
|
||||
for (uint i = 0; i < cols; i++) {
|
||||
d2 = d2 * matrix.at(i, i);
|
||||
}
|
||||
ASSERT_DOUBLE_EQ(d1, d2);
|
||||
EXPECT_LE(std::abs(d1 - d2), PIMATHVECTOR_ZERO_CMP);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, transposed) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
double d1, d2;
|
||||
PIMathMatrixT<rows, cols, Type> matrix1;
|
||||
PIMathMatrixT<rows, cols, Type> matrix2;
|
||||
PIMathMatrixT<rows, cols, Type> matr;
|
||||
Type d1, d2;
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
@@ -439,46 +442,46 @@ TEST(PIMathMatrixT_Test, transposed) {
|
||||
matrix1 = matr.transposed();
|
||||
d2 = matrix1.determinant();
|
||||
matrix2 = matrix1.transposed();
|
||||
ASSERT_TRUE((d1 == d2) && (matr == matrix2));
|
||||
EXPECT_TRUE((d1 == d2) && (matr == matrix2));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, rotation_2x2) {
|
||||
double angle = 1.0;
|
||||
auto matrix = PIMathMatrixT<2u, 2u, double>::identity();
|
||||
Type angle = 1.0;
|
||||
auto matrix = PIMathMatrixT<2u, 2u, Type>::identity();
|
||||
matrix.rotate(angle);
|
||||
double c = cos(angle);
|
||||
double s = sin(angle);
|
||||
ASSERT_TRUE((c == matrix.at(1u, 1u)) && (c == matrix.at(0u, 0u)) && (-s == matrix.at(0u, 1u)) && (s == matrix.at(1u, 0u)));
|
||||
Type c = cos(angle);
|
||||
Type s = sin(angle);
|
||||
EXPECT_TRUE((c == matrix.at(1u, 1u)) && (c == matrix.at(0u, 0u)) && (-s == matrix.at(0u, 1u)) && (s == matrix.at(1u, 0u)));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, matrixMultiplication) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(1.5);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>(2.5);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 11.25, 3));
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, Type>(1.5);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, Type>(2.5);
|
||||
EXPECT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 11.25, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(1.5);
|
||||
auto vector = PIMathVectorT<rows, double>(2.5);
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, Type>(1.5);
|
||||
auto vector = PIMathVectorT<rows, Type>(2.5);
|
||||
for (uint i = 0; i < 2; i++) {
|
||||
if ((matrix1 * vector)[i] != 11.25) {
|
||||
ASSERT_TRUE(false);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(1.5);
|
||||
auto vector = PIMathVectorT<rows, double>(2.5);
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, Type>(1.5);
|
||||
auto vector = PIMathVectorT<rows, Type>(2.5);
|
||||
for (uint i = 0; i < 2; i++) {
|
||||
if ((vector * matrix1)[i] != 11.25) {
|
||||
ASSERT_TRUE(false);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(1.5);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(25.0 * matrix1, 37.5, 3));
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, Type>(1.5);
|
||||
EXPECT_TRUE(cmpSquareMatrixWithValue(Type(25.) * matrix1, 37.5, 3));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user