File: tfacetutil.cpp

package info (click to toggle)
wsclean 3.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,296 kB
  • sloc: cpp: 129,246; python: 22,066; sh: 360; ansic: 230; makefile: 185
file content (66 lines) | stat: -rw-r--r-- 2,295 bytes parent folder | download | duplicates (2)
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
#include "../../structures/facetutil.h"

#include <boost/test/unit_test.hpp>

using schaapcommon::facets::BoundingBox;
using schaapcommon::facets::Facet;

namespace wsclean {

BOOST_AUTO_TEST_SUITE(facet_util)

BOOST_AUTO_TEST_CASE(create_grid_single_facet) {
  const size_t kImageWidth = 100;
  const size_t kImageHeight = 142;
  Facet::InitializationData facet_data(0.01, 0.01, kImageWidth, kImageHeight);

  const std::vector<std::shared_ptr<schaapcommon::facets::Facet>> facets =
      CreateFacetGrid(facet_data, 1, 1);

  BOOST_TEST_REQUIRE(facets.size() == 1);
  const BoundingBox& box = facets.front()->GetTrimmedBoundingBox();
  BOOST_TEST(box.Min().x == 0);
  BOOST_TEST(box.Min().y == 0);
  BOOST_TEST(box.Max().x == kImageWidth);
  BOOST_TEST(box.Max().y == kImageHeight);

  BOOST_TEST(facets.front()->DirectionLabel() == "0, 0");
}

BOOST_AUTO_TEST_CASE(create_grid_multiple_facets) {
  const size_t kImageSize = 100;
  const size_t kGridWidth = 4;
  const size_t kGridHeight = 5;
  Facet::InitializationData facet_data(0.01, kImageSize);
  const std::vector<std::shared_ptr<schaapcommon::facets::Facet>> facets =
      CreateFacetGrid(facet_data, kGridWidth, kGridHeight);

  BOOST_TEST(facets.size() == kGridWidth * kGridHeight);

  std::set<std::pair<int, int>> grid_cells;
  for (const std::shared_ptr<Facet>& facet : facets) {
    const BoundingBox& box = facet->GetTrimmedBoundingBox();
    const int grid_x = box.Centre().x / box.Width();
    const int grid_y = box.Centre().y / box.Height();
    BOOST_TEST(grid_x >= 0);
    BOOST_TEST(grid_y >= 0);
    BOOST_TEST(grid_x < static_cast<int>(kGridWidth));
    BOOST_TEST(grid_y < static_cast<int>(kGridHeight));
    grid_cells.emplace(grid_x, grid_y);

    BOOST_TEST(box.Min().x == grid_x * kImageSize / kGridWidth);
    BOOST_TEST(box.Min().y == grid_y * kImageSize / kGridHeight);
    BOOST_TEST(box.Max().x == (grid_x + 1) * kImageSize / kGridWidth);
    BOOST_TEST(box.Max().y == (grid_y + 1) * kImageSize / kGridHeight);

    BOOST_TEST(facet->DirectionLabel() ==
               std::to_string(grid_x) + ", " + std::to_string(grid_y));
  }

  // Check that the generated grid contains all grid cells.
  BOOST_TEST(grid_cells.size() == kGridWidth * kGridHeight);
}

BOOST_AUTO_TEST_SUITE_END()

}  // namespace wsclean