NumCpp  2.11.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
wrap2Pi.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <cmath>
31 
33 
34 namespace nc
35 {
42  template<typename dtype>
43  double wrap2Pi(dtype inAngle) noexcept
44  {
46 
47  auto angle = std::fmod(static_cast<double>(inAngle), constants::twoPi);
48  if (angle < 0.)
49  {
51  }
52 
53  return angle;
54  }
55 
62  template<typename dtype>
63  NdArray<double> wrap2Pi(const NdArray<dtype>& inAngles) noexcept
64  {
65  NdArray<double> returnArray(inAngles.size());
66  stl_algorithms::transform(inAngles.begin(),
67  inAngles.end(),
68  returnArray.begin(),
69  [](const auto angle) noexcept -> double { return wrap2Pi(angle); });
70  return returnArray;
71  }
72 } // namespace nc
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:39
iterator begin() noexcept
Definition: NdArrayCore.hpp:1268
constexpr double twoPi
2Pi
Definition: Core/Constants.hpp:40
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:775
Definition: Cartesian.hpp:40
double wrap2Pi(dtype inAngle) noexcept
Wrap the input angle to [0, 2*pi].
Definition: wrap2Pi.hpp:43
auto angle(const std::complex< dtype > &inValue)
Definition: angle.hpp:48
dtype fmod(dtype inValue1, dtype inValue2) noexcept
Definition: fmod.hpp:52