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_