NumCpp  2.11.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
wrap.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <cmath>
31 
35 
36 namespace nc
37 {
44  template<typename dtype>
45  double wrap(dtype inAngle) noexcept
46  {
48 
49  auto angle = std::fmod(static_cast<double>(inAngle) + constants::pi, constants::twoPi);
50  if (angle < 0.)
51  {
53  }
54 
55  return angle - constants::pi;
56  }
57 
64  template<typename dtype>
65  NdArray<double> wrap(const NdArray<dtype>& inAngles) noexcept
66  {
67  NdArray<double> returnArray(inAngles.size());
68  stl_algorithms::transform(inAngles.begin(),
69  inAngles.end(),
70  returnArray.begin(),
71  [](const auto angle) noexcept -> double { return wrap(angle); });
72  return returnArray;
73  }
74 } // namespace nc
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:39
iterator begin() noexcept
Definition: NdArrayCore.hpp:1268
constexpr double pi
Pi.
Definition: Core/Constants.hpp:39
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
auto angle(const std::complex< dtype > &inValue)
Definition: angle.hpp:48
dtype fmod(dtype inValue1, dtype inValue2) noexcept
Definition: fmod.hpp:52
double wrap(dtype inAngle) noexcept
Wrap the input angle to [-pi, pi].
Definition: wrap.hpp:45