From 95b421fce009aee6687bfc508e5fc6826f06d83d Mon Sep 17 00:00:00 2001 From: Sebastian Eibl <sebastian.eibl@fau.de> Date: Fri, 18 Dec 2020 16:41:28 +0100 Subject: [PATCH] [ADD] radians <-> degree conversion functions --- src/core/math/Angles.h | 34 +++++++++++++++++++++++++++++ tests/core/Angles.test.cpp | 44 ++++++++++++++++++++++++++++++++++++++ tests/core/CMakeLists.txt | 3 +++ 3 files changed, 81 insertions(+) create mode 100644 src/core/math/Angles.h create mode 100644 tests/core/Angles.test.cpp diff --git a/src/core/math/Angles.h b/src/core/math/Angles.h new file mode 100644 index 000000000..3294d892b --- /dev/null +++ b/src/core/math/Angles.h @@ -0,0 +1,34 @@ +//====================================================================================================================== +// +// This file is part of waLBerla. waLBerla is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// waLBerla 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 General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file +//! \author Sebastian Eibl <sebastian.eibl@fau.de> +// +//====================================================================================================================== + +#pragma once + +#include "Constants.h" + +namespace walberla +{ +namespace math +{ +///Converts a degrees angle to radians. +constexpr real_t degToRad(real_t deg) {return deg * (pi / real_t(180));} +///Converts a radians angle to degrees. +constexpr real_t radToDeg(real_t rad) {return rad * (real_t(180) / pi);} +} // namespace math +} // namespace walberla diff --git a/tests/core/Angles.test.cpp b/tests/core/Angles.test.cpp new file mode 100644 index 000000000..6190dc41b --- /dev/null +++ b/tests/core/Angles.test.cpp @@ -0,0 +1,44 @@ +//====================================================================================================================== +// +// This file is part of waLBerla. waLBerla is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// waLBerla 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 General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file +//! \author Sebastian Eibl <sebastian.eibl@fau.de> +// +//====================================================================================================================== + +#include "core/DataTypes.h" +#include "core/math/Angles.h" +#include "core/debug/TestSubsystem.h" + +namespace walberla{ + +int main( int /*argc*/, char** /*argv*/ ) +{ + using namespace walberla::math; + + debug::enterTestMode(); + + WALBERLA_CHECK_FLOAT_EQUAL( radToDeg(half_pi), 90_r ); + WALBERLA_CHECK_FLOAT_EQUAL( half_pi, degToRad(90_r) ); + + return EXIT_SUCCESS; +} + +} //namespace walberla + +int main( int argc, char** argv ) +{ + return walberla::main(argc, argv); +} diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index df07f5c8f..992b516f4 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -186,6 +186,9 @@ else() endif() waLBerla_execute_test( NAME AllHeaderTest ) +waLBerla_compile_test( FILES Angles.test.cpp ) +waLBerla_execute_test( NAME Angles ) + waLBerla_compile_test( FILES ConcatIterator.cpp ) waLBerla_execute_test( NAME ConcatIterator ) -- GitLab