• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 Hans Dembinski
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6 
7 //[ guide_axis_circular
8 
9 #include <boost/histogram/axis.hpp>
10 #include <limits>
11 
main()12 int main() {
13   using namespace boost::histogram;
14 
15   // make a circular regular axis ... [0, 180), [180, 360), [0, 180) ....
16   using opts = decltype(axis::option::overflow | axis::option::circular);
17   auto r = axis::regular<double, use_default, use_default, opts>{2, 0., 360.};
18   assert(r.index(-180) == 1);
19   assert(r.index(0) == 0);
20   assert(r.index(180) == 1);
21   assert(r.index(360) == 0);
22   assert(r.index(540) == 1);
23   assert(r.index(720) == 0);
24   // special values are mapped to the overflow bin index
25   assert(r.index(std::numeric_limits<double>::infinity()) == 2);
26   assert(r.index(-std::numeric_limits<double>::infinity()) == 2);
27   assert(r.index(std::numeric_limits<double>::quiet_NaN()) == 2);
28 
29   // since the regular axis is the most common circular axis, there exists an alias
30   auto c = axis::circular<>{2, 0., 360.};
31   assert(r == c);
32 
33   // make a circular integer axis
34   auto i = axis::integer<int, use_default, axis::option::circular_t>{1, 4};
35   assert(i.index(0) == 2);
36   assert(i.index(1) == 0);
37   assert(i.index(2) == 1);
38   assert(i.index(3) == 2);
39   assert(i.index(4) == 0);
40   assert(i.index(5) == 1);
41 }
42 
43 //]
44