2015-08-19 19:06:58 +00:00
|
|
|
/* Copyright 2015, Michele Santullo
|
|
|
|
* This file is part of DoorKeeper.
|
|
|
|
*
|
|
|
|
* DoorKeeper is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* DoorKeeper is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with DoorKeeper. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-07-29 23:18:19 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "doorkeeper/components/tilecoords.hpp"
|
2015-08-14 16:18:43 +00:00
|
|
|
#include <limits>
|
2015-07-29 23:18:19 +00:00
|
|
|
|
2015-08-17 11:36:47 +00:00
|
|
|
TEST(tilecoords, increment) {
|
2015-07-29 23:18:19 +00:00
|
|
|
typedef dk::TileCoords<2> tcoords2;
|
|
|
|
typedef dk::TileCoords<2>::coords coords2;
|
2015-07-30 00:04:02 +00:00
|
|
|
typedef dk::TileCoords<5> tcoords5;
|
|
|
|
typedef dk::TileCoords<5>::coords coords5;
|
2015-07-29 23:18:19 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
const coords2 max_coords(150, 200);
|
|
|
|
tcoords2 test(max_coords);
|
|
|
|
EXPECT_EQ(tcoords2(coords2(0), max_coords), test);
|
|
|
|
|
2015-07-30 00:04:02 +00:00
|
|
|
for (auto z = coords2(0).x(); z <= max_coords.x(); ++z) {
|
2015-07-29 23:18:19 +00:00
|
|
|
EXPECT_EQ(tcoords2(coords2(z, 0), max_coords), test);
|
|
|
|
++test;
|
|
|
|
}
|
|
|
|
auto test_old = test++;
|
|
|
|
EXPECT_EQ(tcoords2(coords2(1, 1), max_coords), test);
|
|
|
|
EXPECT_EQ(tcoords2(coords2(0, 1), max_coords), test_old);
|
|
|
|
}
|
2015-07-30 00:04:02 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
const coords5 max_coords(3);
|
|
|
|
tcoords5 test(max_coords);
|
|
|
|
for (int z = 0; z < 4 * 4 * 4 * 4 * 4 - 1; ++z) {
|
|
|
|
++test;
|
|
|
|
}
|
|
|
|
EXPECT_EQ(tcoords5(max_coords, max_coords), test);
|
|
|
|
}
|
2015-07-29 23:18:19 +00:00
|
|
|
}
|
2015-08-14 16:18:43 +00:00
|
|
|
|
2015-08-17 11:36:47 +00:00
|
|
|
TEST(tilecoords, advance) {
|
2015-08-14 16:18:43 +00:00
|
|
|
typedef dk::TileCoords<4> tcoords4;
|
|
|
|
typedef dk::TileCoords<4>::coords coords4;
|
|
|
|
|
|
|
|
{
|
|
|
|
const coords4 max_coords(3);
|
|
|
|
tcoords4 test(max_coords);
|
|
|
|
|
|
|
|
EXPECT_EQ(0, test[0]);
|
|
|
|
EXPECT_EQ(0, test[1]);
|
|
|
|
EXPECT_EQ(0, test[2]);
|
|
|
|
EXPECT_EQ(0, test[3]);
|
|
|
|
|
|
|
|
test += 3;
|
|
|
|
EXPECT_EQ(3, test[0]);
|
|
|
|
EXPECT_EQ(0, test[1]);
|
|
|
|
EXPECT_EQ(0, test[2]);
|
|
|
|
EXPECT_EQ(0, test[3]);
|
|
|
|
|
|
|
|
test += 3;
|
|
|
|
EXPECT_EQ(2, test[0]);
|
|
|
|
EXPECT_EQ(1, test[1]);
|
|
|
|
EXPECT_EQ(0, test[2]);
|
|
|
|
EXPECT_EQ(0, test[3]);
|
|
|
|
|
|
|
|
test += 20;
|
|
|
|
EXPECT_EQ(2, test[0]);
|
|
|
|
EXPECT_EQ(2, test[1]);
|
|
|
|
EXPECT_EQ(1, test[2]);
|
|
|
|
EXPECT_EQ(0, test[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto max_scalar = std::numeric_limits<dk::CoordinateScalarType>::max();
|
|
|
|
ASSERT_EQ(std::numeric_limits<int32_t>::max(), max_scalar);
|
|
|
|
{
|
|
|
|
coords4 max_coords(max_scalar - 10);
|
|
|
|
max_coords[1] -= 1;
|
|
|
|
max_coords[2] -= 2;
|
|
|
|
max_coords[3] -= 3;
|
|
|
|
|
|
|
|
tcoords4 test(coords4(540, 800, 1200, 710), max_coords);
|
|
|
|
test += max_scalar;
|
|
|
|
EXPECT_EQ(549, test[0]);
|
|
|
|
EXPECT_EQ(801, test[1]);
|
|
|
|
EXPECT_EQ(1200, test[2]);
|
|
|
|
EXPECT_EQ(710, test[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2015-08-14 20:13:14 +00:00
|
|
|
const coords4 max_coords(max_scalar - 1, 800, max_scalar - 1, max_scalar - 1);
|
2015-08-14 16:18:43 +00:00
|
|
|
|
2015-08-14 20:13:14 +00:00
|
|
|
tcoords4 test(coords4(max_scalar - 1, 800, 1200, 710), max_coords);
|
2015-08-14 16:18:43 +00:00
|
|
|
test += max_scalar;
|
|
|
|
EXPECT_EQ(2147483646, test[0]);
|
|
|
|
EXPECT_EQ(0, test[1]);
|
|
|
|
EXPECT_EQ(1201, test[2]);
|
|
|
|
EXPECT_EQ(710, test[3]);
|
|
|
|
}
|
2015-08-16 14:34:32 +00:00
|
|
|
}
|
|
|
|
|
2015-08-17 11:36:47 +00:00
|
|
|
TEST(tilecoords, back_forward) {
|
2015-08-16 14:34:32 +00:00
|
|
|
typedef dk::TileCoords<4> tcoords4;
|
|
|
|
typedef dk::TileCoords<4>::coords coords4;
|
2015-08-15 21:52:37 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
const coords4 max_coords(32);
|
|
|
|
tcoords4 test(max_coords);
|
|
|
|
|
|
|
|
test += 33 * 33 * 2;
|
|
|
|
EXPECT_EQ(0, test[0]);
|
|
|
|
EXPECT_EQ(0, test[1]);
|
|
|
|
EXPECT_EQ(2, test[2]);
|
|
|
|
EXPECT_EQ(0, test[3]);
|
|
|
|
|
|
|
|
test += -1;
|
|
|
|
EXPECT_EQ(32, test[0]);
|
|
|
|
EXPECT_EQ(32, test[1]);
|
|
|
|
EXPECT_EQ(1, test[2]);
|
|
|
|
EXPECT_EQ(0, test[3]);
|
|
|
|
|
|
|
|
test++;
|
|
|
|
test += -33 * 33 * 2;
|
|
|
|
EXPECT_EQ(tcoords4(max_coords), test);
|
|
|
|
}
|
2015-08-16 14:34:32 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
const coords4 max_coords(5300, 2499, 12631, 171244);
|
|
|
|
tcoords4 test(max_coords);
|
|
|
|
|
|
|
|
test += 5000000;
|
|
|
|
EXPECT_EQ(coords4(1157, 943, 0, 0), test.position());
|
|
|
|
|
|
|
|
test -= 3350000;
|
|
|
|
EXPECT_EQ(coords4(1389, 311, 0, 0), test.position());
|
|
|
|
|
|
|
|
test += 50000000 - 5000000 + 3350000;
|
|
|
|
EXPECT_EQ(coords4(968, 1932, 3, 0), test.position());
|
|
|
|
|
|
|
|
test -= 900;
|
|
|
|
EXPECT_EQ(coords4(68, 1932, 3, 0), test.position());
|
|
|
|
|
|
|
|
test += 5300 + 1;
|
|
|
|
EXPECT_EQ(coords4(68, 1933, 3, 0), test.position());
|
|
|
|
|
|
|
|
test -= -5302;
|
|
|
|
EXPECT_EQ(coords4(69, 1934, 3, 0), test.position());
|
|
|
|
}
|
2015-08-14 16:18:43 +00:00
|
|
|
}
|
2015-08-16 18:32:58 +00:00
|
|
|
|
2015-08-17 11:36:47 +00:00
|
|
|
TEST(tilecoords, to_index) {
|
2015-08-16 18:32:58 +00:00
|
|
|
typedef dk::TileCoords<2> tcoords2;
|
|
|
|
typedef dk::TileCoords<2>::coords coords2;
|
|
|
|
|
|
|
|
{
|
|
|
|
const coords2 max_coords(1000);
|
|
|
|
tcoords2 test(max_coords);
|
|
|
|
|
|
|
|
EXPECT_EQ(0, dk::to_index(test));
|
|
|
|
|
|
|
|
++test;
|
|
|
|
EXPECT_EQ(1, dk::to_index(test));
|
|
|
|
|
|
|
|
--test;
|
|
|
|
EXPECT_EQ(0, dk::to_index(test));
|
|
|
|
|
|
|
|
test += 1;
|
|
|
|
EXPECT_EQ(1, dk::to_index(test));
|
|
|
|
|
|
|
|
test += 1;
|
|
|
|
EXPECT_EQ(2, dk::to_index(test));
|
|
|
|
|
|
|
|
test += 1501;
|
|
|
|
EXPECT_EQ(1503, dk::to_index(test));
|
|
|
|
}
|
|
|
|
}
|