From 19aff9eb166fc6647fd571eef79eda06efda1596 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Wed, 23 Oct 2019 19:44:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BC?= =?UTF-8?q?=D0=B0=D1=82=D0=B5=D0=BC=D0=B0=D1=82=D0=B8=D1=87=D0=B5=D1=81?= =?UTF-8?q?=D0=BA=D0=B8=D1=85=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + src/myx/math/CMakeLists.txt | 57 +++++++++++++++++++++++++ src/myx/math/all.hpp | 4 ++ src/myx/math/constants.cpp | 9 ++++ src/myx/math/constants.hpp | 18 ++++++++ src/myx/math/functions.hpp | 28 +++++++++++++ src/myx/math/radar.hpp | 46 ++++++++++++++++++++ src/myx/math/units.hpp | 84 +++++++++++++++++++++++++++++++++++++ 8 files changed, 247 insertions(+) create mode 100644 src/myx/math/CMakeLists.txt create mode 100644 src/myx/math/all.hpp create mode 100644 src/myx/math/constants.cpp create mode 100644 src/myx/math/constants.hpp create mode 100644 src/myx/math/functions.hpp create mode 100644 src/myx/math/radar.hpp create mode 100644 src/myx/math/units.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e76128c..2732240 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ add_subdirectory(src/myx/base) add_subdirectory(src/myx/filesystem) add_subdirectory(src/myx/log) add_subdirectory(src/myx/qt) +add_subdirectory(src/myx/math) # Примеры if (BUILD_EXAMPLES) diff --git a/src/myx/math/CMakeLists.txt b/src/myx/math/CMakeLists.txt new file mode 100644 index 0000000..ad61fe9 --- /dev/null +++ b/src/myx/math/CMakeLists.txt @@ -0,0 +1,57 @@ +# Название основной цели и имя библиотеки в текущем каталоге +set(current_target math) + +# Список файлов исходных текстов +set(current_target_sources + ${CMAKE_CURRENT_SOURCE_DIR}/constants.cpp +) + +# Список заголовочных файлов (используется для установки) +set(current_target_headers + ${CMAKE_CURRENT_SOURCE_DIR}/all.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/constants.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/functions.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/radar.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/units.hpp +) + +add_common_library(TARGET ${current_target} + OUTPUT_NAME myx-${current_target} + SOURCES ${current_target_sources}) +common_target_properties(${current_target}) + +add_clang_tidy_check(${current_target} ${current_target_sources}) +add_clang_analyze_check(${current_target} ${current_target_sources}) +add_clazy_check(${current_target} ${current_target_sources}) +add_pvs_check(${current_target}) + +add_uncrustify_format(${current_target} ${current_target_sources} ${current_target_headers}) + +target_include_directories(${current_target} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) +target_include_directories(${current_target} SYSTEM PUBLIC ${FMT_INCLUDE_DIRS}) +target_include_directories(${current_target} SYSTEM PUBLIC ${SPDLOG_INCLUDE_DIRS}) +target_include_directories(${current_target} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) +target_include_directories(${current_target} PRIVATE ${CMAKE_BINARY_DIR}/include) + +# Цель, используемая только для установки заголовочных файлов без компиляции проекта +add_custom_target(${current_target}-install-headers + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=headers -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" + ) + +set_target_properties(${current_target} + PROPERTIES + OUTPUT_NAME myx-math + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR} + ) + +# Правила для установки +install(TARGETS ${current_target}_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +if(BUILD_SHARED_LIBS) + install(TARGETS ${current_target}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) +endif() +install(FILES ${current_target_headers} + COMPONENT headers + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${current_target}) +install(FILES ${CMAKE_BINARY_DIR}/${current_target}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + diff --git a/src/myx/math/all.hpp b/src/myx/math/all.hpp new file mode 100644 index 0000000..0efc6e5 --- /dev/null +++ b/src/myx/math/all.hpp @@ -0,0 +1,4 @@ +#include +#include +#include +#include diff --git a/src/myx/math/constants.cpp b/src/myx/math/constants.cpp new file mode 100644 index 0000000..0d35cd7 --- /dev/null +++ b/src/myx/math/constants.cpp @@ -0,0 +1,9 @@ +#include + +namespace myx { + +namespace math { + +} // namespace math + +} // namespace myx diff --git a/src/myx/math/constants.hpp b/src/myx/math/constants.hpp new file mode 100644 index 0000000..dfa822c --- /dev/null +++ b/src/myx/math/constants.hpp @@ -0,0 +1,18 @@ +#ifndef MYX_MATH_CONSTANTS_HPP_ +#define MYX_MATH_CONSTANTS_HPP_ + +#include +#include + +namespace myx { + +namespace math { + +const auto ImpedanceOfFreeSpace = 376.7303136675757; + +} // namespace math + +} // namespace myx + + +#endif // MYX_MATH_CONSTANTS_HPP_ diff --git a/src/myx/math/functions.hpp b/src/myx/math/functions.hpp new file mode 100644 index 0000000..cb8d347 --- /dev/null +++ b/src/myx/math/functions.hpp @@ -0,0 +1,28 @@ +#ifndef MYX_MATH_FUNCTIONS_HPP_ +#define MYX_MATH_FUNCTIONS_HPP_ + +#include +#include +#include + +namespace myx { + +namespace math { + +/*! + * \brief pow2 Возведение в квадрат + * \param value Значение + * \return Квадрат значения + */ +template < typename T > +auto pow2( T const& value )->decltype( boost::math::pow< 2 >( value ) ) +{ + return( boost::math::pow< 2 >( value ) ); +} + +} // namespace math + +} // namespace myx + + +#endif // MYX_MATH_FUNCTIONS_HPP_ diff --git a/src/myx/math/radar.hpp b/src/myx/math/radar.hpp new file mode 100644 index 0000000..e1ded9c --- /dev/null +++ b/src/myx/math/radar.hpp @@ -0,0 +1,46 @@ +#ifndef MYX_MATH_RADAR_HPP_ +#define MYX_MATH_RADAR_HPP_ + +#include +#include + +namespace myx { + +namespace math { + +/*! + * \brief geometric_target_visibility Геометрическая видимость цели + * \param earthRadius Радиус Земли + * \param antennaHeight Высота антенны + * \param targetHeight Высота цели + * \return Максимальная дальность видимости цели + */ +template < typename T > +T geometric_target_visibility( const T& earthRadius, const T& antennaHeight, const T& targetHeight ) +{ +// static_assert( std::is_arithmetic< T >::value || std::is_same< T, quantity< length_d > >::value, "Arithmetic type is required." ); + static_assert( std::is_arithmetic< T >::value, "Arithmetic type is required." ); + return ( sqrt( 2 * earthRadius * antennaHeight ) + sqrt( 2 * earthRadius * targetHeight ) ); +} + + +/*! + * \brief radar_target_visibility Видимость цели по лучу + * \param earthRadius Радиус Земли + * \param antennaHeight Высота антенны + * \param targetHeight Высота цели + * \return Максимальная дальность видимости цели + */ +template < typename T > +T radar_target_visibility( T effectiveEarthRadius, T antennaHeight, T targetHeight ) +{ +// static_assert( std::is_arithmetic< T >::value || std::is_same< T, quantity< length_d > >::value, "Arithmetic type is required." ); + static_assert( std::is_arithmetic< T >::value, "Arithmetic type is required." ); + return ( sqrt( 2 * effectiveEarthRadius * antennaHeight ) + sqrt( 2 * effectiveEarthRadius * targetHeight ) ); +} + +} // namespace math + +} // namespace myx + +#endif // MYX_MATH_RADAR_HPP_ diff --git a/src/myx/math/units.hpp b/src/myx/math/units.hpp new file mode 100644 index 0000000..fdff7a0 --- /dev/null +++ b/src/myx/math/units.hpp @@ -0,0 +1,84 @@ +#ifndef MYX_MATH_UNITS_HPP_ +#define MYX_MATH_UNITS_HPP_ + +#include +#include + +namespace myx { + +namespace math { + +/*! + * \brief radiansToDegrees Перевод из радиан в градусы + * \param radians Значение в радианах + * \return Значение в градусах + */ +template < typename T > +T radians_to_degrees( const T& radians, typename std::enable_if< std::is_floating_point< T >::value >::type* = 0 ) +{ + static_assert( std::is_arithmetic< T >::value, "Arithmetic type is required." ); + return( radians * M_1_PI * 180.0 ); +} + + +/*! + * \brief degreesToRadians Перевод из градусов в радианы + * \param degrees Значение в градусах + * \return Значение в радианах + */ +template < typename T > +T degrees_to_radians( const T& degrees, typename std::enable_if< std::is_floating_point< T >::value >::type* = 0 ) +{ + static_assert( std::is_arithmetic< T >::value, "Arithmetic type is required." ); + return( degrees * M_PI / 180.0 ); +} + + +/*! + * \brief decibel_to_power Перевод из децибелов в мощности + * \param degrees Значение в градусах + * \return Значение в радианах + */ + + +// y = 10^{x / 10} +template < typename T > +T decibel_to_power( T const& db ) +{ + static_assert( std::is_arithmetic< T >::value, "Arithmetic type is required." ); + return( std::pow( 10, db / 10.0 ) ); +} + + +// y = 10 * \log(x) +template < typename T > +T power_to_decibel( T const& power ) +{ + static_assert( std::is_arithmetic< T >::value, "Arithmetic type is required." ); + return( 10 * std::log( power ) ); +} + + +// y = 10^{x / 20} +template < typename T > +T decibel_to_magnitude( T const& value ) +{ + static_assert( std::is_arithmetic< T >::value, "Arithmetic type is required." ); + return( std::pow( 10, value / 20.0 ) ); +} + + +// y = 10^{x / 20} +template < typename T > +T decibel_to_magnitude( T const& value ) +{ + static_assert( std::is_arithmetic< T >::value, "Arithmetic type is required." ); + return( std::pow( 10, value / 20.0 ) ); +} + +} // namespace math + +} // namespace myx + + +#endif // MYX_MATH_UNITS_HPP_