Standard Masala Plugins
Loading...
Searching...
No Matches
angle_util.hh
Go to the documentation of this file.
1/*
2 Masala
3 Copyright (C) 2025 Vikram K. Mulligan
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Affero General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19/// @file src/numeric_api/utility/angles/angle_util.hh
20/// @brief Inlined functions for manipulating angles.
21/// @author Vikram K. Mulligan (vmulligan@flatironinstitute.org).
22
23#ifndef Masala_src_numeric_api_utility_angles_angle_util_hh
24#define Masala_src_numeric_api_utility_angles_angle_util_hh
25
26#include <cmath>
27
28namespace masala {
29namespace numeric_api {
30namespace utility {
31namespace angles {
32
33 /// @brief Convert an angle, in degrees, to the equivalent angle, in degrees, in the range [0, 360).
34 /// @tparam T The type of the angle (e.g. float, double, masala::base::Real).
35 /// @param angle_in The input angle, in degrees.
36 /// @return An angle, in degrees, in the range [0, 360).
37 template < typename T >
38 inline
39 T
41 T angle_in
42 ) {
43 T const fmod_result( std::fmod( angle_in, T(360) ) );
44 return (fmod_result < 0 ? fmod_result + T(360) : fmod_result);
45 }
46
47 /// @brief Convert an angle, in degrees, to the equivalent angle, in degrees, in the range [-180, 180).
48 /// @tparam T The type of the angle (e.g. float, double, masala::base::Real).
49 /// @param angle_in The input angle, in degrees.
50 /// @return An angle, in degrees, in the range [-180, 180).
51 template < typename T >
52 inline
53 T
55 T angle_in
56 ) {
57 return ( positive_angle_degrees( angle_in + T(180) ) - T(180) );
58 }
59
60} // namespace angles
61} // namespace utility
62} // namespace numeric_api
63} // namespace masala
64
65#endif // Masala_src_numeric_api_utility_angles_angle_util_hh
T positive_angle_degrees(T angle_in)
Convert an angle, in degrees, to the equivalent angle, in degrees, in the range [0,...
Definition angle_util.hh:40
T zero_centred_angle_degrees(T angle_in)
Convert an angle, in degrees, to the equivalent angle, in degrees, in the range [-180,...
Definition angle_util.hh:54
Forward declarations.