test_regular_grid.cpp
Go to the documentation of this file.
1 // Copyright 2023 Ekumen, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <gtest/gtest.h>
16 
17 #include <vector>
18 
19 #include <range/v3/range/conversion.hpp>
20 
22 
23 namespace {
24 
25 class TestRegularGrid2 : public beluga::BaseRegularGrid2<TestRegularGrid2> {
26  public:
27  [[nodiscard]] static double resolution() { return 1.; }
28 };
29 
30 class TestRegularGrid3 : public beluga::BaseRegularGrid3<TestRegularGrid3> {
31  public:
32  [[nodiscard]] static double resolution() { return 1.; }
33 };
34 
35 TEST(RegularGrid2, NearestCells) {
36  const auto grid = TestRegularGrid2{};
37 
38  EXPECT_EQ(grid.cell_near(Eigen::Vector2d(0, 0)), Eigen::Vector2i(0, 0));
39  EXPECT_EQ(grid.cell_near(Eigen::Vector2d(1.5, 0.5)), Eigen::Vector2i(1, 0));
40 }
41 
42 TEST(RegularGrid2, CoordinatesAtCell) {
43  const auto grid = TestRegularGrid2{};
44 
45  EXPECT_TRUE(grid.coordinates_at(Eigen::Vector2i(0, 0)).isApprox(Eigen::Vector2d(0.5, 0.5)));
46  EXPECT_TRUE(grid.coordinates_at(Eigen::Vector2i(1, 0)).isApprox(Eigen::Vector2d(1.5, 0.5)));
47 }
48 
49 TEST(RegularGrid2, CoordinatesForCells) {
50  const auto grid = TestRegularGrid2{};
51 
52  const auto cells = std::vector{Eigen::Vector2i(1, 0), Eigen::Vector2i(4, 1)};
53  const auto coordinates = grid.coordinates_for(cells) | ranges::to<std::vector>;
54  EXPECT_EQ(coordinates.size(), 2);
55  EXPECT_TRUE(coordinates[0].isApprox(Eigen::Vector2d(1.5, 0.5)));
56  EXPECT_TRUE(coordinates[1].isApprox(Eigen::Vector2d(4.5, 1.5)));
57 }
58 
59 TEST(RegularGrid3, CoordinatesForCells) {
60  const auto grid = TestRegularGrid3{};
61 
62  const auto cells = std::vector{Eigen::Vector3i(1, 0, 0), Eigen::Vector3i(4, 1, -1)};
63  const auto coordinates = grid.coordinates_for(cells) | ranges::to<std::vector>;
64  EXPECT_EQ(coordinates.size(), 2);
65  EXPECT_TRUE(coordinates[0].isApprox(Eigen::Vector3d(1.5, 0.5, 0.5)));
66  EXPECT_TRUE(coordinates[1].isApprox(Eigen::Vector3d(4.5, 1.5, -0.5)));
67 }
68 
69 } // namespace
beluga::BaseRegularGrid
Regularly spaced N dimensional grid base type.
Definition: regular_grid.hpp:65
regular_grid.hpp
Concepts and abstract implementations of regular grids.
beluga::TEST
TEST(Bresenham, MultiPassGuarantee)
Definition: test_bresenham.cpp:27


beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53