File: timagecoordinates.cpp

package info (click to toggle)
wsclean 3.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,968 kB
  • sloc: cpp: 85,742; python: 3,526; sh: 245; makefile: 21
file content (97 lines) | stat: -rw-r--r-- 4,012 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <boost/test/unit_test.hpp>

#include <aocommon/imagecoordinates.h>

#include <cmath>

using aocommon::ImageCoordinates;

BOOST_AUTO_TEST_SUITE(image_coordinates)

BOOST_AUTO_TEST_CASE(mean_position) {
  std::pair<double, double> result =
      ImageCoordinates::MeanPosition(std::vector<std::pair<double, double>>{});
  BOOST_CHECK_EQUAL(result.first, 0.0);
  BOOST_CHECK_EQUAL(result.second, 0.0);

  result = ImageCoordinates::MeanPosition(
      std::vector<std::pair<double, double>>{{0.0, 0.0}});
  BOOST_CHECK_LT(std::abs(result.first), 1e-6);
  BOOST_CHECK_LT(std::abs(result.second), 1e-6);

  result = ImageCoordinates::MeanPosition(
      std::vector<std::pair<double, double>>{{1.0, 0.0}});
  BOOST_CHECK_CLOSE_FRACTION(result.first, 1.0, 1e-6);
  BOOST_CHECK_LT(std::abs(result.second), 1e-6);

  result = ImageCoordinates::MeanPosition(
      std::vector<std::pair<double, double>>{{1.0, 1.0}});
  BOOST_CHECK_CLOSE_FRACTION(result.first, 1.0, 1e-6);
  BOOST_CHECK_CLOSE_FRACTION(result.second, 1.0, 1e-6);

  result = ImageCoordinates::MeanPosition(
      std::vector<std::pair<double, double>>{{-1.0, 0.0}});
  BOOST_CHECK_CLOSE_FRACTION(result.first, -1.0, 1e-6);
  BOOST_CHECK_LT(std::abs(result.second), 1e-6);

  result = ImageCoordinates::MeanPosition(
      std::vector<std::pair<double, double>>{{-1.0, -1.0}});
  BOOST_CHECK_CLOSE_FRACTION(result.first, -1.0, 1e-6);
  BOOST_CHECK_CLOSE_FRACTION(result.second, -1.0, 1e-6);

  result = ImageCoordinates::MeanPosition(
      std::vector<std::pair<double, double>>{{0.0, M_PI * 0.5}});
  BOOST_CHECK_LT(std::abs(result.first), 1e-6);
  BOOST_CHECK_CLOSE_FRACTION(result.second, M_PI * 0.5, 1e-6);

  result = ImageCoordinates::MeanPosition(
      std::vector<std::pair<double, double>>{{0.0, 0.0}, {0.0, 0.0}});
  BOOST_CHECK_LT(std::abs(result.first), 1e-6);
  BOOST_CHECK_LT(std::abs(result.second), 1e-6);

  result = ImageCoordinates::MeanPosition(
      std::vector<std::pair<double, double>>{{1.0, 1.0}, {1.0, 1.0}});
  BOOST_CHECK_CLOSE_FRACTION(result.first, 1.0, 1e-6);
  BOOST_CHECK_CLOSE_FRACTION(result.second, 1.0, 1e-6);

  result = ImageCoordinates::MeanPosition(
      std::vector<std::pair<double, double>>{{0.0, 0.0}, {0.0, -0.5 * M_PI}});
  BOOST_CHECK_LT(std::abs(result.first), 1e-6);
  BOOST_CHECK_CLOSE_FRACTION(result.second, -0.25 * M_PI, 1e-6);

  result = ImageCoordinates::MeanPosition(
      std::vector<std::pair<double, double>>{{0.0, 0.0},
                                             {0.0, -0.25 * M_PI},
                                             {0.0, 0.25 * M_PI},
                                             {0.0, 0.0},
                                             {0.0, -0.25 * M_PI},
                                             {0.0, 0.25 * M_PI}});
  BOOST_CHECK_LT(std::abs(result.first), 1e-6);
  BOOST_CHECK_LT(std::abs(result.second), 1e-6);

  result = ImageCoordinates::MeanPosition(
      std::vector<std::pair<double, double>>{{0.0, 0.0}});
  BOOST_CHECK_LT(std::abs(result.first), 1e-6);
  BOOST_CHECK_LT(std::abs(result.second), 1e-6);

  // Positions around the pole
  std::vector<std::pair<float, float>> around_pole;
  for (size_t i = 0; i != 20; ++i) {
    around_pole.emplace_back(2.0 * M_PI * i / 20.0 + 0.03, 0.5 * M_PI - 0.07);
  }
  // Here we also test the span overload
  result = ImageCoordinates::MeanPosition(std::span(around_pole));
  BOOST_CHECK(std::isfinite(result.first));
  BOOST_CHECK_CLOSE_FRACTION(result.second, 0.5 * M_PI, 1e-6);

  const std::vector<std::pair<double, double>> origin_test{{1.0, -0.5 * M_PI},
                                                           {0.0, 0.5 * M_PI}};
  BOOST_CHECK_NO_THROW(ImageCoordinates::MeanPosition(std::span(origin_test)));

  std::array<float, 2> array_result = ImageCoordinates::MeanPosition(
      std::vector<std::array<float, 2>>{{1.0, 1.0}, {1.0, 1.0}});
  BOOST_CHECK_CLOSE_FRACTION(array_result[0], 1.0, 1e-6);
  BOOST_CHECK_CLOSE_FRACTION(array_result[1], 1.0, 1e-6);
}

BOOST_AUTO_TEST_SUITE_END()