mirror of https://github.com/OpenMW/openmw.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
166 lines
6.8 KiB
C++
166 lines
6.8 KiB
C++
12 months ago
|
#include <components/detournavigator/debug.hpp>
|
||
2 years ago
|
#include <components/detournavigator/gettilespositions.hpp>
|
||
3 years ago
|
#include <components/detournavigator/settings.hpp>
|
||
7 years ago
|
|
||
|
#include <gmock/gmock.h>
|
||
2 years ago
|
#include <gtest/gtest.h>
|
||
7 years ago
|
|
||
|
namespace
|
||
|
{
|
||
|
using namespace testing;
|
||
|
using namespace DetourNavigator;
|
||
|
|
||
|
struct CollectTilesPositions
|
||
|
{
|
||
|
std::vector<TilePosition>& mTilesPositions;
|
||
|
|
||
2 years ago
|
void operator()(const TilePosition& value) { mTilesPositions.push_back(value); }
|
||
7 years ago
|
};
|
||
|
|
||
|
struct DetourNavigatorGetTilesPositionsTest : Test
|
||
|
{
|
||
3 years ago
|
RecastSettings mSettings;
|
||
7 years ago
|
std::vector<TilePosition> mTilesPositions;
|
||
2 years ago
|
CollectTilesPositions mCollect{ mTilesPositions };
|
||
7 years ago
|
|
||
|
DetourNavigatorGetTilesPositionsTest()
|
||
|
{
|
||
|
mSettings.mBorderSize = 0;
|
||
|
mSettings.mCellSize = 0.5;
|
||
|
mSettings.mRecastScaleFactor = 1;
|
||
|
mSettings.mTileSize = 64;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
TEST_F(DetourNavigatorGetTilesPositionsTest, for_object_in_single_tile_should_return_one_tile)
|
||
|
{
|
||
3 years ago
|
getTilesPositions(makeTilesPositionsRange(osg::Vec2f(2, 2), osg::Vec2f(31, 31), mSettings), mCollect);
|
||
7 years ago
|
|
||
|
EXPECT_THAT(mTilesPositions, ElementsAre(TilePosition(0, 0)));
|
||
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorGetTilesPositionsTest, for_object_with_x_bounds_in_two_tiles_should_return_two_tiles)
|
||
|
{
|
||
3 years ago
|
getTilesPositions(makeTilesPositionsRange(osg::Vec2f(0, 0), osg::Vec2f(32, 31), mSettings), mCollect);
|
||
7 years ago
|
|
||
|
EXPECT_THAT(mTilesPositions, ElementsAre(TilePosition(0, 0), TilePosition(1, 0)));
|
||
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorGetTilesPositionsTest, for_object_with_y_bounds_in_two_tiles_should_return_two_tiles)
|
||
|
{
|
||
3 years ago
|
getTilesPositions(makeTilesPositionsRange(osg::Vec2f(0, 0), osg::Vec2f(31, 32), mSettings), mCollect);
|
||
7 years ago
|
|
||
|
EXPECT_THAT(mTilesPositions, ElementsAre(TilePosition(0, 0), TilePosition(0, 1)));
|
||
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorGetTilesPositionsTest, tiling_works_only_for_x_and_y_coordinates)
|
||
|
{
|
||
3 years ago
|
getTilesPositions(makeTilesPositionsRange(osg::Vec2f(0, 0), osg::Vec2f(31, 31), mSettings), mCollect);
|
||
7 years ago
|
|
||
|
EXPECT_THAT(mTilesPositions, ElementsAre(TilePosition(0, 0)));
|
||
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorGetTilesPositionsTest, tiling_should_work_with_negative_coordinates)
|
||
|
{
|
||
3 years ago
|
getTilesPositions(makeTilesPositionsRange(osg::Vec2f(-31, -31), osg::Vec2f(31, 31), mSettings), mCollect);
|
||
7 years ago
|
|
||
2 years ago
|
EXPECT_THAT(mTilesPositions,
|
||
|
ElementsAre(TilePosition(-1, -1), TilePosition(-1, 0), TilePosition(0, -1), TilePosition(0, 0)));
|
||
7 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorGetTilesPositionsTest, border_size_should_extend_tile_bounds)
|
||
|
{
|
||
|
mSettings.mBorderSize = 1;
|
||
|
|
||
3 years ago
|
getTilesPositions(makeTilesPositionsRange(osg::Vec2f(0, 0), osg::Vec2f(31.5, 31.5), mSettings), mCollect);
|
||
7 years ago
|
|
||
2 years ago
|
EXPECT_THAT(mTilesPositions,
|
||
|
ElementsAre(TilePosition(-1, -1), TilePosition(-1, 0), TilePosition(-1, 1), TilePosition(0, -1),
|
||
|
TilePosition(0, 0), TilePosition(0, 1), TilePosition(1, -1), TilePosition(1, 0), TilePosition(1, 1)));
|
||
7 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorGetTilesPositionsTest, should_apply_recast_scale_factor)
|
||
|
{
|
||
|
mSettings.mRecastScaleFactor = 0.5;
|
||
|
|
||
3 years ago
|
getTilesPositions(makeTilesPositionsRange(osg::Vec2f(0, 0), osg::Vec2f(32, 32), mSettings), mCollect);
|
||
7 years ago
|
|
||
|
EXPECT_THAT(mTilesPositions, ElementsAre(TilePosition(0, 0)));
|
||
|
}
|
||
12 months ago
|
|
||
|
struct TilesPositionsRangeParams
|
||
|
{
|
||
|
TilesPositionsRange mA;
|
||
|
TilesPositionsRange mB;
|
||
|
TilesPositionsRange mResult;
|
||
|
};
|
||
|
|
||
|
struct DetourNavigatorGetIntersectionTest : TestWithParam<TilesPositionsRangeParams>
|
||
|
{
|
||
|
};
|
||
|
|
||
|
TEST_P(DetourNavigatorGetIntersectionTest, should_return_expected_result)
|
||
|
{
|
||
|
EXPECT_EQ(getIntersection(GetParam().mA, GetParam().mB), GetParam().mResult);
|
||
|
EXPECT_EQ(getIntersection(GetParam().mB, GetParam().mA), GetParam().mResult);
|
||
|
}
|
||
|
|
||
|
const TilesPositionsRangeParams getIntersectionParams[] = {
|
||
|
{ .mA = TilesPositionsRange{}, .mB = TilesPositionsRange{}, .mResult = TilesPositionsRange{} },
|
||
|
{
|
||
|
.mA = TilesPositionsRange{ .mBegin = TilePosition{ 0, 0 }, .mEnd = TilePosition{ 2, 2 } },
|
||
|
.mB = TilesPositionsRange{ .mBegin = TilePosition{ 1, 1 }, .mEnd = TilePosition{ 3, 3 } },
|
||
|
.mResult = TilesPositionsRange{ .mBegin = TilePosition{ 1, 1 }, .mEnd = TilePosition{ 2, 2 } },
|
||
|
},
|
||
|
{
|
||
|
.mA = TilesPositionsRange{ .mBegin = TilePosition{ 0, 0 }, .mEnd = TilePosition{ 1, 1 } },
|
||
|
.mB = TilesPositionsRange{ .mBegin = TilePosition{ 2, 2 }, .mEnd = TilePosition{ 3, 3 } },
|
||
|
.mResult = TilesPositionsRange{},
|
||
|
},
|
||
|
{
|
||
|
.mA = TilesPositionsRange{ .mBegin = TilePosition{ 0, 0 }, .mEnd = TilePosition{ 1, 1 } },
|
||
|
.mB = TilesPositionsRange{ .mBegin = TilePosition{ 1, 1 }, .mEnd = TilePosition{ 2, 2 } },
|
||
|
.mResult = TilesPositionsRange{ .mBegin = TilePosition{ 1, 1 }, .mEnd = TilePosition{ 1, 1 } },
|
||
|
},
|
||
|
{
|
||
|
.mA = TilesPositionsRange{ .mBegin = TilePosition{ 0, 0 }, .mEnd = TilePosition{ 1, 1 } },
|
||
|
.mB = TilesPositionsRange{ .mBegin = TilePosition{ 0, 2 }, .mEnd = TilePosition{ 3, 3 } },
|
||
|
.mResult = TilesPositionsRange{},
|
||
|
},
|
||
|
{
|
||
|
.mA = TilesPositionsRange{ .mBegin = TilePosition{ 0, 0 }, .mEnd = TilePosition{ 1, 1 } },
|
||
|
.mB = TilesPositionsRange{ .mBegin = TilePosition{ 2, 0 }, .mEnd = TilePosition{ 3, 3 } },
|
||
|
.mResult = TilesPositionsRange{},
|
||
|
},
|
||
|
};
|
||
|
|
||
|
INSTANTIATE_TEST_SUITE_P(
|
||
|
GetIntersectionParams, DetourNavigatorGetIntersectionTest, ValuesIn(getIntersectionParams));
|
||
|
|
||
|
struct DetourNavigatorGetUnionTest : TestWithParam<TilesPositionsRangeParams>
|
||
|
{
|
||
|
};
|
||
|
|
||
|
TEST_P(DetourNavigatorGetUnionTest, should_return_expected_result)
|
||
|
{
|
||
|
EXPECT_EQ(getUnion(GetParam().mA, GetParam().mB), GetParam().mResult);
|
||
|
EXPECT_EQ(getUnion(GetParam().mB, GetParam().mA), GetParam().mResult);
|
||
|
}
|
||
|
|
||
|
const TilesPositionsRangeParams getUnionParams[] = {
|
||
|
{ .mA = TilesPositionsRange{}, .mB = TilesPositionsRange{}, .mResult = TilesPositionsRange{} },
|
||
|
{
|
||
|
.mA = TilesPositionsRange{ .mBegin = TilePosition{ 0, 0 }, .mEnd = TilePosition{ 2, 2 } },
|
||
|
.mB = TilesPositionsRange{ .mBegin = TilePosition{ 1, 1 }, .mEnd = TilePosition{ 3, 3 } },
|
||
|
.mResult = TilesPositionsRange{ .mBegin = TilePosition{ 0, 0 }, .mEnd = TilePosition{ 3, 3 } },
|
||
|
},
|
||
|
{
|
||
|
.mA = TilesPositionsRange{ .mBegin = TilePosition{ 0, 0 }, .mEnd = TilePosition{ 1, 1 } },
|
||
|
.mB = TilesPositionsRange{ .mBegin = TilePosition{ 1, 1 }, .mEnd = TilePosition{ 2, 2 } },
|
||
|
.mResult = TilesPositionsRange{ .mBegin = TilePosition{ 0, 0 }, .mEnd = TilePosition{ 2, 2 } },
|
||
|
},
|
||
|
};
|
||
|
|
||
|
INSTANTIATE_TEST_SUITE_P(GetUnionParams, DetourNavigatorGetUnionTest, ValuesIn(getUnionParams));
|
||
7 years ago
|
}
|