diff --git a/src/core/math/Angles.h b/src/core/math/Angles.h new file mode 100644 index 0000000000000000000000000000000000000000..3294d892b299db83b8455d05226060b850287c82 --- /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 0000000000000000000000000000000000000000..6190dc41bdaf36fd3c177ac9201614ad57a293b4 --- /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 df07f5c8f875f049eda973f5cbaa0a46baf6a927..992b516f4b55412222fc66c2ca4043f1d9fca05e 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 )